-
-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Move Foo.java and ToEvaluate.java to testclasses (#2164)
- Loading branch information
Showing
3 changed files
with
89 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/test/java/spoon/test/eval/Foo.java → ...java/spoon/test/eval/testclasses/Foo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 75 additions & 75 deletions
150
...test/java/spoon/test/eval/ToEvaluate.java → ...oon/test/eval/testclasses/ToEvaluate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,75 @@ | ||
package spoon.test.eval; | ||
|
||
import spoon.reflect.declaration.CtElement; | ||
|
||
public class ToEvaluate { | ||
|
||
static final String S1 = "S1"; | ||
static final String S2 = "S2"; | ||
static final String S1S2_1 = S1 + "S2"; | ||
static final String S1S2_2 = S1 + S2; | ||
static final int I1 = 10; | ||
|
||
public static void testStrings() { | ||
// all the following code will be removed by the partial evaluator | ||
if (!S1S2_1.equals(S1 + S2)) { | ||
System.out.println("dead code"); | ||
} | ||
if (!S1S2_1.equals("S1S2")) { | ||
System.out.println("dead code"); | ||
} | ||
if (!S1S2_2.equals("S1S2")) { | ||
System.out.println("dead code"); | ||
} | ||
if (!S1S2_1.equals(S1S2_2)) { | ||
System.out.println("dead code"); | ||
} | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static void testInts() { | ||
// all the following code will be removed by the partial evaluator | ||
if (I1 + 1 != 11) { | ||
System.out.println("dead code"); | ||
} | ||
} | ||
|
||
public static void testArray() { | ||
// all the following code will be removed by the partial evaluator | ||
if (new String[]{"a", null, "b"}.length == 11) { | ||
System.out.println("dead code"); | ||
} | ||
} | ||
|
||
public static void testDoNotSimplify(String className, String methodName) { | ||
// this code must not be simplified | ||
java.lang.System.out.println(((("enter: " + className) + " - ") + methodName)); | ||
} | ||
|
||
public static <U> U testDoNotSimplifyCasts(CtElement element) { | ||
// this code must not be simplified | ||
return ((U) ((Object) (castTarget(element).getClass()))); | ||
} | ||
|
||
private static <T> T castTarget(CtElement element) { | ||
return (T) element; | ||
} | ||
|
||
private static String tryCatchAndStatement(CtElement element) { | ||
try { | ||
element.getClass(); | ||
} catch (RuntimeException e) { | ||
throw e; | ||
} | ||
return "This must not be removed"; | ||
} | ||
|
||
private static String simplifyOnlyWhenPossible(CtElement element) { | ||
//this must not be simplified because literal is not a statement. | ||
ToEvaluate.class.getName(); | ||
//this must not be simplified because ClassLoader instance is not a literal | ||
System.out.println(ToEvaluate.class.getClassLoader()); | ||
//this can be simplified because return expects expression | ||
return ToEvaluate.class.getName(); | ||
} | ||
} | ||
package spoon.test.eval.testclasses; | ||
|
||
import spoon.reflect.declaration.CtElement; | ||
|
||
public class ToEvaluate { | ||
|
||
static final String S1 = "S1"; | ||
static final String S2 = "S2"; | ||
static final String S1S2_1 = S1 + "S2"; | ||
static final String S1S2_2 = S1 + S2; | ||
static final int I1 = 10; | ||
|
||
public static void testStrings() { | ||
// all the following code will be removed by the partial evaluator | ||
if (!S1S2_1.equals(S1 + S2)) { | ||
System.out.println("dead code"); | ||
} | ||
if (!S1S2_1.equals("S1S2")) { | ||
System.out.println("dead code"); | ||
} | ||
if (!S1S2_2.equals("S1S2")) { | ||
System.out.println("dead code"); | ||
} | ||
if (!S1S2_1.equals(S1S2_2)) { | ||
System.out.println("dead code"); | ||
} | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static void testInts() { | ||
// all the following code will be removed by the partial evaluator | ||
if (I1 + 1 != 11) { | ||
System.out.println("dead code"); | ||
} | ||
} | ||
|
||
public static void testArray() { | ||
// all the following code will be removed by the partial evaluator | ||
if (new String[]{"a", null, "b"}.length == 11) { | ||
System.out.println("dead code"); | ||
} | ||
} | ||
|
||
public static void testDoNotSimplify(String className, String methodName) { | ||
// this code must not be simplified | ||
java.lang.System.out.println(((("enter: " + className) + " - ") + methodName)); | ||
} | ||
|
||
public static <U> U testDoNotSimplifyCasts(CtElement element) { | ||
// this code must not be simplified | ||
return ((U) ((Object) (castTarget(element).getClass()))); | ||
} | ||
|
||
private static <T> T castTarget(CtElement element) { | ||
return (T) element; | ||
} | ||
|
||
private static String tryCatchAndStatement(CtElement element) { | ||
try { | ||
element.getClass(); | ||
} catch (RuntimeException e) { | ||
throw e; | ||
} | ||
return "This must not be removed"; | ||
} | ||
|
||
private static String simplifyOnlyWhenPossible(CtElement element) { | ||
//this must not be simplified because literal is not a statement. | ||
ToEvaluate.class.getName(); | ||
//this must not be simplified because ClassLoader instance is not a literal | ||
System.out.println(ToEvaluate.class.getClassLoader()); | ||
//this can be simplified because return expects expression | ||
return ToEvaluate.class.getName(); | ||
} | ||
} |