Skip to content

Commit

Permalink
Revert "fix: handling of String const in getCorrespondingRuntimeObjec…
Browse files Browse the repository at this point in the history
…t/convertElementToRuntimeObject (INRIA#2978)"

This reverts commit 0c26805.
  • Loading branch information
Egor18 committed May 23, 2019
1 parent eb47def commit 7f0b3e5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ public void visitField(Field field) {
try {
Set<ModifierKind> modifiers = RtHelper.getModifiers(field.getModifiers());
if (modifiers.contains(ModifierKind.STATIC)
&& modifiers.contains(ModifierKind.PUBLIC)
&& (field.getType().isPrimitive() || String.class.isAssignableFrom(field.getType()))
&& modifiers.contains(ModifierKind.PUBLIC)
&& field.getType().isPrimitive()
) {
CtLiteral<Object> defaultExpression = factory.createLiteral(field.get(null));
ctField.setDefaultExpression(defaultExpression);
Expand Down
15 changes: 6 additions & 9 deletions src/test/java/spoon/test/annotation/AnnotationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1556,15 +1556,12 @@ public void testAnnotationArray() throws Exception {
public void testGetValueAsObject() {
// contract: annot.getValueAsObject now handles static values in binary classes
CtClass<?> cl =
Launcher.parseClass("public class C { " +
" @SuppressWarnings(\"int\"+Integer.SIZE) void i() {} " +
" @SuppressWarnings(\"str\"+java.io.File.pathSeparator) void s() {} " +
"}");
CtAnnotation<?> annot_i = cl.getMethodsByName("i").get(0).getAnnotations().get(0);
CtAnnotation<?> annot_s = cl.getMethodsByName("s").get(0).getAnnotations().get(0);

assertEquals("[int" + Integer.SIZE + "]", Arrays.toString((Object[]) annot_i.getValueAsObject("value")));
assertEquals("[str" + File.pathSeparator + "]", Arrays.toString((Object[]) annot_s.getValueAsObject("value")));
Launcher.parseClass(
"public class C { @SuppressWarnings(\"a\"+Integer.SIZE) void m() {} }");
CtAnnotation<?> annot = cl.getMethodsByName("m").get(0).getAnnotations().get(0);

// this triggers an exception because "a"+Integer.SIZE is not known at runtime
assertEquals("[a32]", Arrays.toString((Object[]) annot.getValueAsObject("value")));
}

}
3 changes: 0 additions & 3 deletions src/test/java/spoon/test/eval/EvalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import spoon.support.reflect.eval.VisitorPartialEvaluator;
import spoon.test.eval.testclasses.Foo;

import java.io.File;
import java.util.List;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -233,8 +232,6 @@ public void testconvertElementToRuntimeObject() {
// also works for static runtime fields
assertEquals(Integer.MAX_VALUE, EvalHelper.convertElementToRuntimeObject(foo.getField("i1").getDefaultExpression()));
assertEquals(Integer.MAX_VALUE, EvalHelper.getCorrespondingRuntimeObject(foo.getField("i1").getDefaultExpression()));
assertEquals(File.pathSeparator, EvalHelper.convertElementToRuntimeObject(foo.getField("str1").getDefaultExpression()));
assertEquals(File.pathSeparator, EvalHelper.getCorrespondingRuntimeObject(foo.getField("str1").getDefaultExpression()));

}
}
4 changes: 1 addition & 3 deletions src/test/java/spoon/test/eval/testclasses/Foo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package spoon.test.eval.testclasses;

import java.io.File;

public class Foo {
final boolean b0 = true && false;
boolean b2 = true; // not final so not considered
Expand All @@ -10,7 +8,7 @@ public class Foo {
boolean b5 = true ^ false; // exec BITXOR
final boolean b6 = b0;
final int i1 = Integer.MAX_VALUE; // access to static field
final String str1 = File.pathSeparator;

void foo() {
boolean b1 = true ? false || b0 : b2; // will be simplified to "false"
}
Expand Down

0 comments on commit 7f0b3e5

Please sign in to comment.