Skip to content

Commit

Permalink
feat(objectionary#275): fix the rest of mistakes
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Aug 30, 2024
1 parent be70c75 commit cc0c08a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
11 changes: 6 additions & 5 deletions src/main/java/org/eolang/opeo/decompilation/agents/LdcAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ public void handle(final DecompilerState state) {
}

/**
* Determine value type.
* @param object Object value.
* Determine the value type.
* Since Java doesn't allow using primitive types for Object, we need to
* determine the type of the value.
* @param value Object value.
* @return Type.
* @todo #275:30min WTF?
*/
private static Type type(final Object object) {
final Class<?> clazz = object.getClass();
private static Type type(final Object value) {
final Class<?> clazz = value.getClass();
final Type result;
if (clazz == Integer.class) {
result = Type.INT_TYPE;
Expand Down
36 changes: 20 additions & 16 deletions src/test/java/org/eolang/opeo/ast/ConstTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,25 +191,10 @@ void constructsLongFromXmir(final String input, final int opcode, final String e
);
}

/**
* Test cases for {@link #generatesLdcInstruction(Object)} test.
* @return Different values that might be converted to LDC instruction.
*/
@SuppressWarnings("PMD.UnusedPrivateMethod")
private static Stream<Object> ldc() {
return Stream.of(
"Load string from constant pool",
29,
29L,
29.0f,
29.0d
);
}

@ParameterizedTest
@MethodSource("opcodes")
void generatesCorrectOpcodesForDifferentTypes(
final Const constant, final int expected, final Object[] params
final Const constant, final int expected, final Object... params
) {
final Opcode opcode = (Opcode) constant.opcodes().get(0);
MatcherAssert.assertThat(
Expand Down Expand Up @@ -239,6 +224,10 @@ void generatesCorrectOpcodesForDifferentTypes(
}
}

/**
* Test cases for {@link #generatesCorrectOpcodesForDifferentTypes(Const, int, Object[])} test.
* @return Different values that might be converted to opcodes.
*/
@SuppressWarnings("PMD.UnusedPrivateMethod")
private static Stream<Arguments> opcodes() {
return Stream.of(
Expand Down Expand Up @@ -275,4 +264,19 @@ private static Stream<Arguments> opcodes() {
Arguments.of(new Const(false), Opcodes.ICONST_0, ConstTest.EMPTY)
);
}

/**
* Test cases for {@link #generatesLdcInstruction(Object)} test.
* @return Different values that might be converted to LDC instruction.
*/
@SuppressWarnings("PMD.UnusedPrivateMethod")
private static Stream<Object> ldc() {
return Stream.of(
"Load string from constant pool",
29,
29L,
29.0f,
29.0d
);
}
}

0 comments on commit cc0c08a

Please sign in to comment.