remove codegen, classfile stuff, jarfile stuff
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.compiler/META-INF/MANIFEST.MF b/tests/org.eclipse.wst.jsdt.core.tests.compiler/META-INF/MANIFEST.MF
index 4737d63..c659474 100644
--- a/tests/org.eclipse.wst.jsdt.core.tests.compiler/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.wst.jsdt.core.tests.compiler/META-INF/MANIFEST.MF
@@ -12,7 +12,6 @@
Export-Package: org.eclipse.wst.jsdt.core.tests.compiler,
org.eclipse.wst.jsdt.core.tests.compiler.parser,
org.eclipse.wst.jsdt.core.tests.compiler.regression,
- org.eclipse.wst.jsdt.core.tests.eval,
org.eclipse.wst.jsdt.core.tests.eval.target,
org.eclipse.wst.jsdt.core.tests.interpret,
org.eclipse.wst.jsdt.core.tests.junit.extension,
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/JSDTTestAll.java b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/JSDTTestAll.java
index 7b9942b..5455ac7 100644
--- a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/JSDTTestAll.java
+++ b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/JSDTTestAll.java
@@ -15,6 +15,7 @@
import org.eclipse.wst.jsdt.core.tests.compiler.regression.BasicErrorTests;
import org.eclipse.wst.jsdt.core.tests.compiler.regression.BasicParserTests;
+import org.eclipse.wst.jsdt.core.tests.compiler.regression.BasicResolveTests;
import org.eclipse.wst.jsdt.core.tests.compiler.regression.InferTypesTests;
import org.eclipse.wst.jsdt.core.tests.junit.extension.TestCase;
import org.eclipse.wst.jsdt.core.tests.util.AbstractCompilerTest;
@@ -36,6 +37,7 @@
standardTests.add(BasicParserTests.class);
// standardTests.add(BasicErrorTests.class);
standardTests.add(InferTypesTests.class);
+ standardTests.add(BasicResolveTests.class);
// // add all javadoc tests
// for (int i=0, l=JavadocTest.ALL_CLASSES.size(); i<l; i++) {
// standardTests.add(JavadocTest.ALL_CLASSES.get(i));
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/AbstractRegressionTest.java b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/AbstractRegressionTest.java
index 68a38a8..0beda0f 100644
--- a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/AbstractRegressionTest.java
+++ b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/AbstractRegressionTest.java
@@ -13,7 +13,6 @@
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
@@ -48,7 +47,6 @@
import org.eclipse.wst.jsdt.internal.compiler.ast.CompilationUnitDeclaration;
import org.eclipse.wst.jsdt.internal.compiler.batch.CompilationUnit;
import org.eclipse.wst.jsdt.internal.compiler.batch.FileSystem;
-import org.eclipse.wst.jsdt.internal.compiler.classfmt.ClassFileReader;
import org.eclipse.wst.jsdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.wst.jsdt.internal.compiler.env.INameEnvironment;
import org.eclipse.wst.jsdt.internal.compiler.impl.CompilerOptions;
@@ -59,7 +57,7 @@
import org.eclipse.wst.jsdt.internal.compiler.problem.DefaultProblemFactory;
import org.eclipse.wst.jsdt.internal.compiler.problem.ProblemReporter;
import org.eclipse.wst.jsdt.internal.core.search.JavaSearchParticipant;
-import org.eclipse.wst.jsdt.internal.core.search.indexing.BinaryIndexer;
+import org.eclipse.wst.jsdt.internal.core.search.indexing.SourceIndexer;
import org.eclipse.wst.jsdt.internal.infer.InferEngine;
import org.eclipse.wst.jsdt.internal.infer.InferOptions;
@@ -335,7 +333,7 @@
}
};
SearchDocument document = participant.getDocument(new File(classFilePath).getPath());
- BinaryIndexer indexer = new BinaryIndexer(document) {
+ SourceIndexer indexer = new SourceIndexer(document) {
protected void addIndexEntry(char[] category, char[] key) {
references.append(category);
references.append('/');
@@ -348,25 +346,7 @@
return computedReferences;
}
- protected ClassFileReader getClassFileReader(String fileName, String className) {
- File classFile = new File(fileName);
- if (!classFile.exists()) {
- assertTrue(".class file doesn't exist", false);
- }
- try {
- FileInputStream stream = new FileInputStream(classFile);
- ClassFileReader reader = ClassFileReader.read(stream, className + ".class", true);
- stream.close();
- return reader;
- } catch (org.eclipse.wst.jsdt.internal.compiler.classfmt.ClassFormatException e) {
- e.printStackTrace();
- assertTrue("ClassFormatException", false);
- } catch (IOException e) {
- e.printStackTrace();
- assertTrue("IOException", false);
- }
- return null;
- }
+
protected INameEnvironment[] getClassLibs() {
String encoding = (String)getCompilerOptions().get(CompilerOptions.OPTION_Encoding);
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/AnnotationTest.java b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/AnnotationTest.java
index 506d7ea..632364d 100644
--- a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/AnnotationTest.java
+++ b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/AnnotationTest.java
@@ -11,7 +11,6 @@
package org.eclipse.wst.jsdt.core.tests.compiler.regression;
import java.io.File;
-import java.io.IOException;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
@@ -20,8 +19,6 @@
import org.eclipse.wst.jsdt.core.tests.util.Util;
import org.eclipse.wst.jsdt.internal.compiler.classfmt.ClassFileConstants;
-import org.eclipse.wst.jsdt.internal.compiler.classfmt.ClassFileReader;
-import org.eclipse.wst.jsdt.internal.compiler.classfmt.ClassFormatException;
import org.eclipse.wst.jsdt.internal.compiler.impl.CompilerOptions;
public class AnnotationTest extends AbstractComparableTest {
@@ -3265,52 +3262,6 @@
"");
}
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82136
- public void test105() {
- this.runConformTest(
- new String[] {
- "Property.java",
- "import java.lang.annotation.Documented;\n" +
- "import java.lang.annotation.Retention;\n" +
- "import java.lang.annotation.RetentionPolicy;\n" +
- "\n" +
- "@Documented\n" +
- "@Retention(RetentionPolicy.RUNTIME)\n" +
- "public @interface Property\n" +
- "{\n" +
- " String property();\n" +
- " String identifier() default \"\";\n" +
- "}",
- "Properties.java",
- "import java.lang.annotation.Documented;\n" +
- "import java.lang.annotation.Retention;\n" +
- "import java.lang.annotation.RetentionPolicy;\n" +
- "\n" +
- "@Documented\n" +
- "@Retention(RetentionPolicy.RUNTIME)\n" +
- "public @interface Properties {\n" +
- " Property[] value();\n" +
- "}",
- "X.java",
- "@Properties({\n" +
- " @Property(property = \"prop\", identifier = \"someIdentifier\"),\n" +
- " @Property(property = \"type\")\n" +
- "})\n" +
- "public interface X {\n" +
- " void setName();\n" +
- " String getName();\n" +
- "}"
- },
- "");
- try {
- byte[] classFileBytes = org.eclipse.wst.jsdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class"));
- new ClassFileReader(classFileBytes, "X.java".toCharArray(), true);
- } catch (ClassFormatException e) {
- assertTrue("ClassFormatException", false);
- } catch (IOException e) {
- assertTrue("IOException", false);
- }
- }
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=83939
public void test106() {
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/GenericTypeSignatureTest.java b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/GenericTypeSignatureTest.java
index 0e67c0f..a29f227 100644
--- a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/GenericTypeSignatureTest.java
+++ b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/GenericTypeSignatureTest.java
@@ -21,10 +21,6 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.wst.jsdt.core.tests.util.Util;
-import org.eclipse.wst.jsdt.internal.compiler.classfmt.ClassFileReader;
-import org.eclipse.wst.jsdt.internal.compiler.classfmt.ClassFormatException;
-import org.eclipse.wst.jsdt.internal.compiler.env.IBinaryField;
-import org.eclipse.wst.jsdt.internal.compiler.env.IBinaryMethod;
import org.eclipse.wst.jsdt.internal.compiler.impl.CompilerOptions;
public class GenericTypeSignatureTest extends AbstractRegressionTest {
@@ -292,235 +288,235 @@
}
- public void test006() {
- final String[] testsSource = new String[] {
- "X.java",
- "public class X <T> {\n" +
- " protected T t;\n" +
- " X(T t) {\n" +
- " this.t = t;\n" +
- " }\n" +
- " T foo(T t1) {\n" +
- " return t1;\n" +
- " }\n" +
- " T field;\n" +
- " public static void main(String[] args) {\n" +
- " System.out.print(\"SUCCESS\");\n" +
- " }\n" +
- "}",
- };
- this.runConformTest(
- testsSource,
- "SUCCESS");
-
- try {
- ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
- assertEquals("Wrong signature", "<T:Ljava/lang/Object;>Ljava/lang/Object;", new String(classFileReader.getGenericSignature()));
-
- IBinaryField[] fields = classFileReader.getFields();
- assertNotNull("No fields", fields);
- assertEquals("Wrong size", 2, fields.length);
- assertEquals("Wrong name", "field", new String(fields[1].getName()));
- char[] signature = fields[1].getGenericSignature();
- assertNotNull("No signature", signature);
- assertEquals("Wrong signature", "TT;", new String(signature));
-
- IBinaryMethod[] methods = classFileReader.getMethods();
- assertNotNull("No methods", methods);
- assertEquals("Wrong size", 3, methods.length);
- assertEquals("Wrong name", "foo", new String(methods[1].getSelector()));
- signature = methods[1].getGenericSignature();
- assertNotNull("No signature", signature);
- assertEquals("Wrong signature", "(TT;)TT;", new String(signature));
- } catch (ClassFormatException e) {
- assertTrue(false);
- } catch (IOException e) {
- assertTrue(false);
- }
- }
-
- public void test007() {
- final String[] testsSource = new String[] {
- "X.java",
- "public class X <T> {\n" +
- " protected T t;\n" +
- " X(T t) {\n" +
- " this.t = t;\n" +
- " }\n" +
- " T foo(X<T> x1) {\n" +
- " return x1.t;\n" +
- " }\n" +
- " X<T> field;\n" +
- " public static void main(String[] args) {\n" +
- " System.out.print(\"SUCCESS\");\n" +
- " }\n" +
- "}",
- };
- this.runConformTest(
- testsSource,
- "SUCCESS");
-
- try {
- ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
- assertEquals("Wrong signature", "<T:Ljava/lang/Object;>Ljava/lang/Object;", new String(classFileReader.getGenericSignature()));
-
- IBinaryField[] fields = classFileReader.getFields();
- assertNotNull("No fields", fields);
- assertEquals("Wrong size", 2, fields.length);
- assertEquals("Wrong name", "field", new String(fields[1].getName()));
- char[] signature = fields[1].getGenericSignature();
- assertNotNull("No signature", signature);
- assertEquals("Wrong signature", "LX<TT;>;", new String(signature));
-
- IBinaryMethod[] methods = classFileReader.getMethods();
- assertNotNull("No methods", methods);
- assertEquals("Wrong size", 3, methods.length);
- assertEquals("Wrong name", "foo", new String(methods[1].getSelector()));
- signature = methods[1].getGenericSignature();
- assertNotNull("No signature", signature);
- assertEquals("Wrong signature", "(LX<TT;>;)TT;", new String(signature));
- } catch (ClassFormatException e) {
- assertTrue(false);
- } catch (IOException e) {
- assertTrue(false);
- }
- }
-
- public void test008() {
- final String[] testsSource = new String[] {
- "X.java",
- "public class X <T> {\n" +
- " T newInstance() throws IllegalAccessException {\n" +
- " return null;\n" +
- " }\n" +
- " public static void main(String[] args) {\n" +
- " System.out.print(\"SUCCESS\");\n" +
- " }\n" +
- "}",
- };
- this.runConformTest(
- testsSource,
- "SUCCESS");
-
- try {
- ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
- IBinaryMethod[] methods = classFileReader.getMethods();
- assertNotNull("No methods", methods);
- assertEquals("Wrong size", 3, methods.length);
- assertEquals("Wrong name", "newInstance", new String(methods[1].getSelector()));
- char[] signature = methods[1].getGenericSignature();
- assertNotNull("No signature", signature);
- assertEquals("Wrong signature", "()TT;", new String(signature));
- } catch (ClassFormatException e) {
- assertTrue(false);
- } catch (IOException e) {
- assertTrue(false);
- }
- }
+// public void test006() {
+// final String[] testsSource = new String[] {
+// "X.java",
+// "public class X <T> {\n" +
+// " protected T t;\n" +
+// " X(T t) {\n" +
+// " this.t = t;\n" +
+// " }\n" +
+// " T foo(T t1) {\n" +
+// " return t1;\n" +
+// " }\n" +
+// " T field;\n" +
+// " public static void main(String[] args) {\n" +
+// " System.out.print(\"SUCCESS\");\n" +
+// " }\n" +
+// "}",
+// };
+// this.runConformTest(
+// testsSource,
+// "SUCCESS");
+//
+// try {
+// ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
+// assertEquals("Wrong signature", "<T:Ljava/lang/Object;>Ljava/lang/Object;", new String(classFileReader.getGenericSignature()));
+//
+// IBinaryField[] fields = classFileReader.getFields();
+// assertNotNull("No fields", fields);
+// assertEquals("Wrong size", 2, fields.length);
+// assertEquals("Wrong name", "field", new String(fields[1].getName()));
+// char[] signature = fields[1].getGenericSignature();
+// assertNotNull("No signature", signature);
+// assertEquals("Wrong signature", "TT;", new String(signature));
+//
+// IBinaryMethod[] methods = classFileReader.getMethods();
+// assertNotNull("No methods", methods);
+// assertEquals("Wrong size", 3, methods.length);
+// assertEquals("Wrong name", "foo", new String(methods[1].getSelector()));
+// signature = methods[1].getGenericSignature();
+// assertNotNull("No signature", signature);
+// assertEquals("Wrong signature", "(TT;)TT;", new String(signature));
+// } catch (ClassFormatException e) {
+// assertTrue(false);
+// } catch (IOException e) {
+// assertTrue(false);
+// }
+// }
+//
+// public void test007() {
+// final String[] testsSource = new String[] {
+// "X.java",
+// "public class X <T> {\n" +
+// " protected T t;\n" +
+// " X(T t) {\n" +
+// " this.t = t;\n" +
+// " }\n" +
+// " T foo(X<T> x1) {\n" +
+// " return x1.t;\n" +
+// " }\n" +
+// " X<T> field;\n" +
+// " public static void main(String[] args) {\n" +
+// " System.out.print(\"SUCCESS\");\n" +
+// " }\n" +
+// "}",
+// };
+// this.runConformTest(
+// testsSource,
+// "SUCCESS");
+//
+// try {
+// ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
+// assertEquals("Wrong signature", "<T:Ljava/lang/Object;>Ljava/lang/Object;", new String(classFileReader.getGenericSignature()));
+//
+// IBinaryField[] fields = classFileReader.getFields();
+// assertNotNull("No fields", fields);
+// assertEquals("Wrong size", 2, fields.length);
+// assertEquals("Wrong name", "field", new String(fields[1].getName()));
+// char[] signature = fields[1].getGenericSignature();
+// assertNotNull("No signature", signature);
+// assertEquals("Wrong signature", "LX<TT;>;", new String(signature));
+//
+// IBinaryMethod[] methods = classFileReader.getMethods();
+// assertNotNull("No methods", methods);
+// assertEquals("Wrong size", 3, methods.length);
+// assertEquals("Wrong name", "foo", new String(methods[1].getSelector()));
+// signature = methods[1].getGenericSignature();
+// assertNotNull("No signature", signature);
+// assertEquals("Wrong signature", "(LX<TT;>;)TT;", new String(signature));
+// } catch (ClassFormatException e) {
+// assertTrue(false);
+// } catch (IOException e) {
+// assertTrue(false);
+// }
+// }
+//
+// public void test008() {
+// final String[] testsSource = new String[] {
+// "X.java",
+// "public class X <T> {\n" +
+// " T newInstance() throws IllegalAccessException {\n" +
+// " return null;\n" +
+// " }\n" +
+// " public static void main(String[] args) {\n" +
+// " System.out.print(\"SUCCESS\");\n" +
+// " }\n" +
+// "}",
+// };
+// this.runConformTest(
+// testsSource,
+// "SUCCESS");
+//
+// try {
+// ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
+// IBinaryMethod[] methods = classFileReader.getMethods();
+// assertNotNull("No methods", methods);
+// assertEquals("Wrong size", 3, methods.length);
+// assertEquals("Wrong name", "newInstance", new String(methods[1].getSelector()));
+// char[] signature = methods[1].getGenericSignature();
+// assertNotNull("No signature", signature);
+// assertEquals("Wrong signature", "()TT;", new String(signature));
+// } catch (ClassFormatException e) {
+// assertTrue(false);
+// } catch (IOException e) {
+// assertTrue(false);
+// }
+// }
- public void test009() {
- final String[] testsSource = new String[] {
- "X.java",
- "public class X<T> {\n" +
- "class MX<U> {\n" +
- "}\n" +
- " \n" +
- "public static void main(String[] args) {\n" +
- " new X<Thread>().foo(new X<String>().new MX<Thread>());\n" +
- "}\n" +
- "void foo(X<String>.MX<Thread> mx) {\n" +
- " System.out.println(\"SUCCESS\");\n" +
- "}\n" +
- "}",
- };
- this.runConformTest(
- testsSource,
- "SUCCESS");
-
- try {
- ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
- IBinaryMethod[] methods = classFileReader.getMethods();
- assertNotNull("No methods", methods);
- assertEquals("Wrong size", 3, methods.length);
- assertEquals("Wrong name", "foo", new String(methods[2].getSelector()));
- char[] signature = methods[2].getGenericSignature();
- assertNotNull("No signature", signature);
- assertEquals("Wrong signature", "(LX<Ljava/lang/String;>.MX<Ljava/lang/Thread;>;)V", new String(signature));
- } catch (ClassFormatException e) {
- assertTrue(false);
- } catch (IOException e) {
- assertTrue(false);
- }
- }
+// public void test009() {
+// final String[] testsSource = new String[] {
+// "X.java",
+// "public class X<T> {\n" +
+// "class MX<U> {\n" +
+// "}\n" +
+// " \n" +
+// "public static void main(String[] args) {\n" +
+// " new X<Thread>().foo(new X<String>().new MX<Thread>());\n" +
+// "}\n" +
+// "void foo(X<String>.MX<Thread> mx) {\n" +
+// " System.out.println(\"SUCCESS\");\n" +
+// "}\n" +
+// "}",
+// };
+// this.runConformTest(
+// testsSource,
+// "SUCCESS");
+//
+// try {
+// ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
+// IBinaryMethod[] methods = classFileReader.getMethods();
+// assertNotNull("No methods", methods);
+// assertEquals("Wrong size", 3, methods.length);
+// assertEquals("Wrong name", "foo", new String(methods[2].getSelector()));
+// char[] signature = methods[2].getGenericSignature();
+// assertNotNull("No signature", signature);
+// assertEquals("Wrong signature", "(LX<Ljava/lang/String;>.MX<Ljava/lang/Thread;>;)V", new String(signature));
+// } catch (ClassFormatException e) {
+// assertTrue(false);
+// } catch (IOException e) {
+// assertTrue(false);
+// }
+// }
- public void test010() {
- final String[] testsSource = new String[] {
- "X.java",
- "public class X<T> {\n" +
- "class MX<U> {\n" +
- "}\n" +
- " \n" +
- "public static void main(String[] args) {\n" +
- " new X<Thread>().foo(new X<String>().new MX<Thread>());\n" +
- "}\n" +
- "void foo(X.MX mx) {\n" +
- " System.out.println(\"SUCCESS\");\n" +
- "}\n" +
- "}",
- };
- this.runConformTest(
- testsSource,
- "SUCCESS");
-
- try {
- ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
- IBinaryMethod[] methods = classFileReader.getMethods();
- assertNotNull("No methods", methods);
- assertEquals("Wrong size", 3, methods.length);
- assertEquals("Wrong name", "foo", new String(methods[2].getSelector()));
- char[] signature = methods[2].getGenericSignature();
- assertNull("Unexpected generic signature", signature);
- } catch (ClassFormatException e) {
- assertTrue(false);
- } catch (IOException e) {
- assertTrue(false);
- }
- }
+// public void test010() {
+// final String[] testsSource = new String[] {
+// "X.java",
+// "public class X<T> {\n" +
+// "class MX<U> {\n" +
+// "}\n" +
+// " \n" +
+// "public static void main(String[] args) {\n" +
+// " new X<Thread>().foo(new X<String>().new MX<Thread>());\n" +
+// "}\n" +
+// "void foo(X.MX mx) {\n" +
+// " System.out.println(\"SUCCESS\");\n" +
+// "}\n" +
+// "}",
+// };
+// this.runConformTest(
+// testsSource,
+// "SUCCESS");
+//
+// try {
+// ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
+// IBinaryMethod[] methods = classFileReader.getMethods();
+// assertNotNull("No methods", methods);
+// assertEquals("Wrong size", 3, methods.length);
+// assertEquals("Wrong name", "foo", new String(methods[2].getSelector()));
+// char[] signature = methods[2].getGenericSignature();
+// assertNull("Unexpected generic signature", signature);
+// } catch (ClassFormatException e) {
+// assertTrue(false);
+// } catch (IOException e) {
+// assertTrue(false);
+// }
+// }
- public void test011() {
- final String[] testsSource = new String[] {
- "X.java",
- "public class X<T> {\n" +
- " class MX<U> {\n" +
- " }\n" +
- "\n" +
- " public static void main(String[] args) {\n" +
- " new X<Thread>().foo(new X<String>().new MX<Thread>());\n" +
- " }\n" +
- " void foo(X<String>.MX<?> mx) {\n" +
- " System.out.println(\"SUCCESS\");\n" +
- " }\n" +
- "}",
- };
- this.runConformTest(
- testsSource,
- "SUCCESS");
-
- try {
- ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
- IBinaryMethod[] methods = classFileReader.getMethods();
- assertNotNull("No methods", methods);
- assertEquals("Wrong size", 3, methods.length);
- assertEquals("Wrong name", "foo", new String(methods[2].getSelector()));
- char[] signature = methods[2].getGenericSignature();
- assertNotNull("No signature", signature);
- assertEquals("Wrong signature", "(LX<Ljava/lang/String;>.MX<*>;)V", new String(signature));
- } catch (ClassFormatException e) {
- assertTrue(false);
- } catch (IOException e) {
- assertTrue(false);
- }
- }
+// public void test011() {
+// final String[] testsSource = new String[] {
+// "X.java",
+// "public class X<T> {\n" +
+// " class MX<U> {\n" +
+// " }\n" +
+// "\n" +
+// " public static void main(String[] args) {\n" +
+// " new X<Thread>().foo(new X<String>().new MX<Thread>());\n" +
+// " }\n" +
+// " void foo(X<String>.MX<?> mx) {\n" +
+// " System.out.println(\"SUCCESS\");\n" +
+// " }\n" +
+// "}",
+// };
+// this.runConformTest(
+// testsSource,
+// "SUCCESS");
+//
+// try {
+// ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
+// IBinaryMethod[] methods = classFileReader.getMethods();
+// assertNotNull("No methods", methods);
+// assertEquals("Wrong size", 3, methods.length);
+// assertEquals("Wrong name", "foo", new String(methods[2].getSelector()));
+// char[] signature = methods[2].getGenericSignature();
+// assertNotNull("No signature", signature);
+// assertEquals("Wrong signature", "(LX<Ljava/lang/String;>.MX<*>;)V", new String(signature));
+// } catch (ClassFormatException e) {
+// assertTrue(false);
+// } catch (IOException e) {
+// assertTrue(false);
+// }
+// }
// WORK check whether needed or not
/*
@@ -552,331 +548,331 @@
}
}
- public void test012() {
- final String[] testsSource = new String[] {
- "X.java",
- "public class X<T> {\n" +
- " class MX<U> {\n" +
- " }\n" +
- "\n" +
- " public static void main(String[] args) {\n" +
- " new X<Thread>().foo(new X<String>().new MX<Thread>());\n" +
- " }\n" +
- " void foo(X.MX mx) { // no signature\n" +
- " System.out.println(\"SUCCESS\");\n" +
- " }\n" +
- "}",
- };
- this.runConformTest(
- testsSource,
- "SUCCESS");
+// public void test012() {
+// final String[] testsSource = new String[] {
+// "X.java",
+// "public class X<T> {\n" +
+// " class MX<U> {\n" +
+// " }\n" +
+// "\n" +
+// " public static void main(String[] args) {\n" +
+// " new X<Thread>().foo(new X<String>().new MX<Thread>());\n" +
+// " }\n" +
+// " void foo(X.MX mx) { // no signature\n" +
+// " System.out.println(\"SUCCESS\");\n" +
+// " }\n" +
+// "}",
+// };
+// this.runConformTest(
+// testsSource,
+// "SUCCESS");
+//
+// try {
+// ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
+// IBinaryMethod[] methods = classFileReader.getMethods();
+// assertNotNull("No methods", methods);
+// assertEquals("Wrong size", 3, methods.length);
+// assertEquals("Wrong name", "foo", new String(methods[2].getSelector()));
+// assertNull("Wrong signature", methods[2].getGenericSignature());
+// } catch (ClassFormatException e) {
+// assertTrue(false);
+// } catch (IOException e) {
+// assertTrue(false);
+// }
+// }
- try {
- ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
- IBinaryMethod[] methods = classFileReader.getMethods();
- assertNotNull("No methods", methods);
- assertEquals("Wrong size", 3, methods.length);
- assertEquals("Wrong name", "foo", new String(methods[2].getSelector()));
- assertNull("Wrong signature", methods[2].getGenericSignature());
- } catch (ClassFormatException e) {
- assertTrue(false);
- } catch (IOException e) {
- assertTrue(false);
- }
- }
-
- public void test013() {
- final String[] testsSource = new String[] {
- "X.java",
- "import java.util.ArrayList;\n" +
- "\n" +
- "public class X<T> {\n" +
- " \n" +
- " public static void main(String[] args) {\n" +
- " System.out.println(\"SUCCESS\");\n" +
- " }\n" +
- " public <U> void foo(ArrayList<U> arr) {\n" +
- " for (U e : arr) {\n" +
- " System.out.println(e);\n" +
- " }\n" +
- " }\n" +
- "}",
- };
- this.runConformTest(
- testsSource,
- "SUCCESS");
-
- try {
- ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
- IBinaryMethod[] methods = classFileReader.getMethods();
- assertNotNull("No methods", methods);
- assertEquals("Wrong size", 3, methods.length);
- assertEquals("Wrong name", "foo", new String(methods[2].getSelector()));
- char[] signature = methods[2].getGenericSignature();
- assertNotNull("No signature", signature);
- assertEquals("Wrong signature", "<U:Ljava/lang/Object;>(Ljava/util/ArrayList<TU;>;)V", new String(signature));
- } catch (ClassFormatException e) {
- assertTrue(false);
- } catch (IOException e) {
- assertTrue(false);
- }
- }
+// public void test013() {
+// final String[] testsSource = new String[] {
+// "X.java",
+// "import java.util.ArrayList;\n" +
+// "\n" +
+// "public class X<T> {\n" +
+// " \n" +
+// " public static void main(String[] args) {\n" +
+// " System.out.println(\"SUCCESS\");\n" +
+// " }\n" +
+// " public <U> void foo(ArrayList<U> arr) {\n" +
+// " for (U e : arr) {\n" +
+// " System.out.println(e);\n" +
+// " }\n" +
+// " }\n" +
+// "}",
+// };
+// this.runConformTest(
+// testsSource,
+// "SUCCESS");
+//
+// try {
+// ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
+// IBinaryMethod[] methods = classFileReader.getMethods();
+// assertNotNull("No methods", methods);
+// assertEquals("Wrong size", 3, methods.length);
+// assertEquals("Wrong name", "foo", new String(methods[2].getSelector()));
+// char[] signature = methods[2].getGenericSignature();
+// assertNotNull("No signature", signature);
+// assertEquals("Wrong signature", "<U:Ljava/lang/Object;>(Ljava/util/ArrayList<TU;>;)V", new String(signature));
+// } catch (ClassFormatException e) {
+// assertTrue(false);
+// } catch (IOException e) {
+// assertTrue(false);
+// }
+// }
// 59983 - incorrect signature for List<X>
- public void test014() {
- final String[] testsSource = new String[] {
- "X.java",
- "import java.util.ArrayList;\n" +
- "import java.util.List;\n" +
- "public class X {\n" +
- " private List<X> games = new ArrayList<X>();\n" +
- " public static void main(String[] args) {\n" +
- " System.out.println(\"SUCCESS\");\n" +
- " }\n" +
- "}",
- };
- this.runConformTest(
- testsSource,
- "SUCCESS");
-
- try {
- ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
- IBinaryField[] fields = classFileReader.getFields();
- assertNotNull("No fields", fields);
- assertEquals("Wrong size", 1, fields.length);
- assertEquals("Wrong name", "games", new String(fields[0].getName()));
- char[] signature = fields[0].getGenericSignature();
- assertNotNull("No signature", signature);
- assertEquals("Wrong signature", "Ljava/util/List<LX;>;", new String(signature));
- } catch (ClassFormatException e) {
- assertTrue(false);
- } catch (IOException e) {
- assertTrue(false);
- }
- }
+// public void test014() {
+// final String[] testsSource = new String[] {
+// "X.java",
+// "import java.util.ArrayList;\n" +
+// "import java.util.List;\n" +
+// "public class X {\n" +
+// " private List<X> games = new ArrayList<X>();\n" +
+// " public static void main(String[] args) {\n" +
+// " System.out.println(\"SUCCESS\");\n" +
+// " }\n" +
+// "}",
+// };
+// this.runConformTest(
+// testsSource,
+// "SUCCESS");
+//
+// try {
+// ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
+// IBinaryField[] fields = classFileReader.getFields();
+// assertNotNull("No fields", fields);
+// assertEquals("Wrong size", 1, fields.length);
+// assertEquals("Wrong name", "games", new String(fields[0].getName()));
+// char[] signature = fields[0].getGenericSignature();
+// assertNotNull("No signature", signature);
+// assertEquals("Wrong signature", "Ljava/util/List<LX;>;", new String(signature));
+// } catch (ClassFormatException e) {
+// assertTrue(false);
+// } catch (IOException e) {
+// assertTrue(false);
+// }
+// }
// 65953 - incorrect signature for generic interface
- public void test015() {
- final String[] testsSource = new String[] {
- "X.java",
- "public interface X<T> {\n" +
- "}",
- };
- this.runConformTest(
- testsSource,
- "");
-
- try {
- ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
- char[] signature = classFileReader.getGenericSignature();
- assertNotNull("No signature", signature);
- assertEquals("Wrong signature", "<T:Ljava/lang/Object;>Ljava/lang/Object;", new String(signature));
- } catch (ClassFormatException e) {
- assertTrue(false);
- } catch (IOException e) {
- assertTrue(false);
- }
- }
+// public void test015() {
+// final String[] testsSource = new String[] {
+// "X.java",
+// "public interface X<T> {\n" +
+// "}",
+// };
+// this.runConformTest(
+// testsSource,
+// "");
+//
+// try {
+// ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
+// char[] signature = classFileReader.getGenericSignature();
+// assertNotNull("No signature", signature);
+// assertEquals("Wrong signature", "<T:Ljava/lang/Object;>Ljava/lang/Object;", new String(signature));
+// } catch (ClassFormatException e) {
+// assertTrue(false);
+// } catch (IOException e) {
+// assertTrue(false);
+// }
+// }
// 70975 - invalid signature for method with array of type variables
- public void test016() {
- final String[] testsSource = new String[] {
- "X.java",
- "import java.util.ArrayList;\n" +
- "\n" +
- "public class X<T> {\n" +
- " \n" +
- " public static void main(String[] args) {\n" +
- " System.out.println(\"SUCCESS\");\n" +
- " }\n" +
- " public <U> void foo(U[] arr) {\n" +
- " }\n" +
- "}",
- };
- this.runConformTest(
- testsSource,
- "SUCCESS");
-
- try {
- ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
- IBinaryMethod[] methods = classFileReader.getMethods();
- assertNotNull("No methods", methods);
- assertEquals("Wrong size", 3, methods.length);
- assertEquals("Wrong name", "foo", new String(methods[2].getSelector()));
- char[] signature = methods[2].getGenericSignature();
- assertNotNull("No signature", signature);
- assertEquals("Wrong signature", "<U:Ljava/lang/Object;>([TU;)V", new String(signature));
- } catch (ClassFormatException e) {
- assertTrue(false);
- } catch (IOException e) {
- assertTrue(false);
- }
- }
- public void test017() {
- final String[] testsSource = new String[] {
- "X.java",
- "public class X<T> {\n" +
- " static class MX<U> {\n" +
- " }\n" +
- "\n" +
- " public static void main(String[] args) {\n" +
- " new X<Thread>().foo(new MX<Thread>());\n" +
- " }\n" +
- " void foo(X.MX<?> mx) {\n" +
- " System.out.println(\"SUCCESS\");\n" +
- " }\n" +
- "}",
- };
- this.runConformTest(
- testsSource,
- "SUCCESS");
-
- try {
- ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
- IBinaryMethod[] methods = classFileReader.getMethods();
- assertNotNull("No methods", methods);
- assertEquals("Wrong size", 3, methods.length);
- assertEquals("Wrong name", "foo", new String(methods[2].getSelector()));
- char[] signature = methods[2].getGenericSignature();
- assertNotNull("No signature", signature);
- assertEquals("Wrong signature", "(LX$MX<*>;)V", new String(signature));
- } catch (ClassFormatException e) {
- assertTrue(false);
- } catch (IOException e) {
- assertTrue(false);
- }
- }
- //https://bugs.eclipse.org/bugs/show_bug.cgi?id=98322
- public void test018() {
- final String[] testsSource = new String[] {
- "X.java",
- "public class X<K extends X.Key> {\n" +
- " public abstract static class Key {\n" +
- " public abstract String getName();\n" +
- " }\n" +
- " public class Holder {}\n" +
- " \n" +
- " void baz(X<K>.Holder h) {} // (LX<TK;>.Holder;)V\n" +
- " void bar(X.Holder h) {} // n/a\n" +
- " void foo(X<Key>.Holder h) {} // (LX<LX$Key;>.Holder;)V\n" +
- "}\n",
- };
- this.runConformTest(
- testsSource,
- "");
-
- try {
- ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
- IBinaryMethod[] methods = classFileReader.getMethods();
- assertNotNull("No methods", methods);
- assertEquals("Wrong size", 4, methods.length);
-
- assertEquals("Wrong name", "baz", new String(methods[1].getSelector()));
- char[] signature = methods[1].getGenericSignature();
- assertNotNull("No signature", signature);
- assertEquals("Wrong signature", "(LX<TK;>.Holder;)V", new String(signature));
-
- assertEquals("Wrong name", "bar", new String(methods[2].getSelector()));
- signature = methods[2].getGenericSignature();
- assertNull("No signature", signature);
-
- assertEquals("Wrong name", "foo", new String(methods[3].getSelector()));
- signature = methods[3].getGenericSignature();
- assertNotNull("No signature", signature);
- assertEquals("Wrong signature", "(LX<LX$Key;>.Holder;)V", new String(signature));
- } catch (ClassFormatException e) {
- assertTrue(false);
- } catch (IOException e) {
- assertTrue(false);
- }
- }
- //https://bugs.eclipse.org/bugs/show_bug.cgi?id=100293
- public void test019() {
- final String[] testsSource = new String[] {
- "X.java",
- "public class X<K extends X.Key> {\n" +
- " public abstract static class Key {\n" +
- " public abstract String getName();\n" +
- " }\n" +
- " public class Holder {}\n" +
- " \n" +
- " X<K>.Holder foo() { return null; }\n" +
- " \n" +
- " static void bar() {\n" +
- " Object o = new X<Key>().foo();\n" +
- " class Local<U> {\n" +
- " X<Key>.Holder field;\n" +
- " Local<String> foo1() { return null; }\n" +
- " Local<U> foo2() { return null; }\n" +
- " Local foo3() { return null; }\n" +
- " }\n" +
- " }\n" +
- "}\n",
- };
- this.runConformTest(
- testsSource,
- "");
-
- try {
- ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X$1Local.class");
- IBinaryField[] fields = classFileReader.getFields();
- assertNotNull("No fields", fields);
- assertEquals("Wrong size", 1, fields.length);
-
- assertEquals("Wrong name", "field", new String(fields[0].getName()));
- char[] signature = fields[0].getGenericSignature();
- assertNotNull("No signature", signature);
- assertEquals("Wrong signature", "LX<LX$Key;>.Holder;", new String(signature));
-
- IBinaryMethod[] methods = classFileReader.getMethods();
- assertNotNull("No methods", methods);
- assertEquals("Wrong size", 4, methods.length);
-
- assertEquals("Wrong name", "foo1", new String(methods[1].getSelector()));
- signature = methods[1].getGenericSignature();
- assertNotNull("No signature", signature);
- assertEquals("Wrong signature", "()LX$1Local<Ljava/lang/String;>;", new String(signature));
-
- assertEquals("Wrong name", "foo2", new String(methods[2].getSelector()));
- signature = methods[2].getGenericSignature();
- assertNotNull("No signature", signature);
- assertEquals("Wrong signature", "()LX$1Local<TU;>;", new String(signature));
-
- assertEquals("Wrong name", "foo3", new String(methods[3].getSelector()));
- signature = methods[3].getGenericSignature();
- assertNull("No signature", signature);
- } catch (ClassFormatException e) {
- assertTrue(false);
- } catch (IOException e) {
- assertTrue(false);
- }
- }
- //https://bugs.eclipse.org/bugs/show_bug.cgi?id=160132 - variation
- public void test020() {
- final String[] testsSource = new String[] {
- "X.java",
- "public interface X<E extends Object & X.Entry> {\n" +
- " interface Entry {\n" +
- " interface Internal extends Entry {\n" +
- " Internal createEntry();\n" +
- " }\n" +
- " }\n" +
- "}\n",
- };
- this.runConformTest(
- testsSource,
- "");
-
- try {
- ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X$Entry$Internal.class");
- IBinaryMethod[] methods = classFileReader.getMethods();
- assertNotNull("No methods", methods);
- assertEquals("Wrong size", 1, methods.length);
- assertEquals("Wrong name", "createEntry", new String(methods[0].getSelector()));
- char[] signature = methods[0].getGenericSignature();
- assertNull("Unexpected signature", signature); // no generic signature should have been produced
- } catch (ClassFormatException e) {
- assertTrue(false);
- } catch (IOException e) {
- assertTrue(false);
- }
- }
+// public void test016() {
+// final String[] testsSource = new String[] {
+// "X.java",
+// "import java.util.ArrayList;\n" +
+// "\n" +
+// "public class X<T> {\n" +
+// " \n" +
+// " public static void main(String[] args) {\n" +
+// " System.out.println(\"SUCCESS\");\n" +
+// " }\n" +
+// " public <U> void foo(U[] arr) {\n" +
+// " }\n" +
+// "}",
+// };
+// this.runConformTest(
+// testsSource,
+// "SUCCESS");
+//
+// try {
+// ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
+// IBinaryMethod[] methods = classFileReader.getMethods();
+// assertNotNull("No methods", methods);
+// assertEquals("Wrong size", 3, methods.length);
+// assertEquals("Wrong name", "foo", new String(methods[2].getSelector()));
+// char[] signature = methods[2].getGenericSignature();
+// assertNotNull("No signature", signature);
+// assertEquals("Wrong signature", "<U:Ljava/lang/Object;>([TU;)V", new String(signature));
+// } catch (ClassFormatException e) {
+// assertTrue(false);
+// } catch (IOException e) {
+// assertTrue(false);
+// }
+// }
+// public void test017() {
+// final String[] testsSource = new String[] {
+// "X.java",
+// "public class X<T> {\n" +
+// " static class MX<U> {\n" +
+// " }\n" +
+// "\n" +
+// " public static void main(String[] args) {\n" +
+// " new X<Thread>().foo(new MX<Thread>());\n" +
+// " }\n" +
+// " void foo(X.MX<?> mx) {\n" +
+// " System.out.println(\"SUCCESS\");\n" +
+// " }\n" +
+// "}",
+// };
+// this.runConformTest(
+// testsSource,
+// "SUCCESS");
+//
+// try {
+// ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
+// IBinaryMethod[] methods = classFileReader.getMethods();
+// assertNotNull("No methods", methods);
+// assertEquals("Wrong size", 3, methods.length);
+// assertEquals("Wrong name", "foo", new String(methods[2].getSelector()));
+// char[] signature = methods[2].getGenericSignature();
+// assertNotNull("No signature", signature);
+// assertEquals("Wrong signature", "(LX$MX<*>;)V", new String(signature));
+// } catch (ClassFormatException e) {
+// assertTrue(false);
+// } catch (IOException e) {
+// assertTrue(false);
+// }
+// }
+// //https://bugs.eclipse.org/bugs/show_bug.cgi?id=98322
+// public void test018() {
+// final String[] testsSource = new String[] {
+// "X.java",
+// "public class X<K extends X.Key> {\n" +
+// " public abstract static class Key {\n" +
+// " public abstract String getName();\n" +
+// " }\n" +
+// " public class Holder {}\n" +
+// " \n" +
+// " void baz(X<K>.Holder h) {} // (LX<TK;>.Holder;)V\n" +
+// " void bar(X.Holder h) {} // n/a\n" +
+// " void foo(X<Key>.Holder h) {} // (LX<LX$Key;>.Holder;)V\n" +
+// "}\n",
+// };
+// this.runConformTest(
+// testsSource,
+// "");
+//
+// try {
+// ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class");
+// IBinaryMethod[] methods = classFileReader.getMethods();
+// assertNotNull("No methods", methods);
+// assertEquals("Wrong size", 4, methods.length);
+//
+// assertEquals("Wrong name", "baz", new String(methods[1].getSelector()));
+// char[] signature = methods[1].getGenericSignature();
+// assertNotNull("No signature", signature);
+// assertEquals("Wrong signature", "(LX<TK;>.Holder;)V", new String(signature));
+//
+// assertEquals("Wrong name", "bar", new String(methods[2].getSelector()));
+// signature = methods[2].getGenericSignature();
+// assertNull("No signature", signature);
+//
+// assertEquals("Wrong name", "foo", new String(methods[3].getSelector()));
+// signature = methods[3].getGenericSignature();
+// assertNotNull("No signature", signature);
+// assertEquals("Wrong signature", "(LX<LX$Key;>.Holder;)V", new String(signature));
+// } catch (ClassFormatException e) {
+// assertTrue(false);
+// } catch (IOException e) {
+// assertTrue(false);
+// }
+// }
+// //https://bugs.eclipse.org/bugs/show_bug.cgi?id=100293
+// public void test019() {
+// final String[] testsSource = new String[] {
+// "X.java",
+// "public class X<K extends X.Key> {\n" +
+// " public abstract static class Key {\n" +
+// " public abstract String getName();\n" +
+// " }\n" +
+// " public class Holder {}\n" +
+// " \n" +
+// " X<K>.Holder foo() { return null; }\n" +
+// " \n" +
+// " static void bar() {\n" +
+// " Object o = new X<Key>().foo();\n" +
+// " class Local<U> {\n" +
+// " X<Key>.Holder field;\n" +
+// " Local<String> foo1() { return null; }\n" +
+// " Local<U> foo2() { return null; }\n" +
+// " Local foo3() { return null; }\n" +
+// " }\n" +
+// " }\n" +
+// "}\n",
+// };
+// this.runConformTest(
+// testsSource,
+// "");
+//
+// try {
+// ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X$1Local.class");
+// IBinaryField[] fields = classFileReader.getFields();
+// assertNotNull("No fields", fields);
+// assertEquals("Wrong size", 1, fields.length);
+//
+// assertEquals("Wrong name", "field", new String(fields[0].getName()));
+// char[] signature = fields[0].getGenericSignature();
+// assertNotNull("No signature", signature);
+// assertEquals("Wrong signature", "LX<LX$Key;>.Holder;", new String(signature));
+//
+// IBinaryMethod[] methods = classFileReader.getMethods();
+// assertNotNull("No methods", methods);
+// assertEquals("Wrong size", 4, methods.length);
+//
+// assertEquals("Wrong name", "foo1", new String(methods[1].getSelector()));
+// signature = methods[1].getGenericSignature();
+// assertNotNull("No signature", signature);
+// assertEquals("Wrong signature", "()LX$1Local<Ljava/lang/String;>;", new String(signature));
+//
+// assertEquals("Wrong name", "foo2", new String(methods[2].getSelector()));
+// signature = methods[2].getGenericSignature();
+// assertNotNull("No signature", signature);
+// assertEquals("Wrong signature", "()LX$1Local<TU;>;", new String(signature));
+//
+// assertEquals("Wrong name", "foo3", new String(methods[3].getSelector()));
+// signature = methods[3].getGenericSignature();
+// assertNull("No signature", signature);
+// } catch (ClassFormatException e) {
+// assertTrue(false);
+// } catch (IOException e) {
+// assertTrue(false);
+// }
+// }
+// //https://bugs.eclipse.org/bugs/show_bug.cgi?id=160132 - variation
+// public void test020() {
+// final String[] testsSource = new String[] {
+// "X.java",
+// "public interface X<E extends Object & X.Entry> {\n" +
+// " interface Entry {\n" +
+// " interface Internal extends Entry {\n" +
+// " Internal createEntry();\n" +
+// " }\n" +
+// " }\n" +
+// "}\n",
+// };
+// this.runConformTest(
+// testsSource,
+// "");
+//
+// try {
+// ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X$Entry$Internal.class");
+// IBinaryMethod[] methods = classFileReader.getMethods();
+// assertNotNull("No methods", methods);
+// assertEquals("Wrong size", 1, methods.length);
+// assertEquals("Wrong name", "createEntry", new String(methods[0].getSelector()));
+// char[] signature = methods[0].getGenericSignature();
+// assertNull("Unexpected signature", signature); // no generic signature should have been produced
+// } catch (ClassFormatException e) {
+// assertTrue(false);
+// } catch (IOException e) {
+// assertTrue(false);
+// }
+// }
}
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java
index 5b20b2a..febe824 100644
--- a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java
+++ b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java
@@ -10,11 +10,6 @@
*******************************************************************************/
package org.eclipse.wst.jsdt.core.tests.compiler.regression;
-import java.io.File;
-
-import org.eclipse.wst.jsdt.internal.compiler.classfmt.ClassFileReader;
-import org.eclipse.wst.jsdt.internal.compiler.env.IBinaryMethod;
-
import junit.framework.Test;
public class ProblemTypeAndMethodTest extends AbstractRegressionTest {
@@ -78,40 +73,40 @@
false /* do not show warning token */,
false /* do not skip javac for this peculiar test */,
false /* do not perform statements recovery */);
- ClassFileReader reader = this.getClassFileReader(OUTPUT_DIR + File.separator +"X$W.class", "X$W");
- IBinaryMethod[] methods = reader.getMethods();
- assertEquals("Wrong size", 2, methods.length);
- int counter = 0;
- for (int i = 0; i < 2; i++) {
- IBinaryMethod method = methods[i];
- if (new String(method.getSelector()).equals("foo")) {
- counter++;
- }
- }
- assertEquals("Wrong number of foo method", 1, counter);
-
- reader = this.getClassFileReader(OUTPUT_DIR + File.separator +"X$Y.class", "X$Y");
- methods = reader.getMethods();
- assertEquals("Wrong size", 2, methods.length);
- counter = 0;
- for (int i = 0; i < 2; i++) {
- IBinaryMethod method = methods[i];
- if (new String(method.getSelector()).equals("foo")) {
- counter++;
- }
- }
- assertEquals("Wrong number of foo method", 1, counter);
-
- reader = this.getClassFileReader(OUTPUT_DIR + File.separator +"X$Z.class", "X$Z");
- methods = reader.getMethods();
- assertEquals("Wrong size", 2, methods.length);
- counter = 0;
- for (int i = 0; i < 2; i++) {
- IBinaryMethod method = methods[i];
- if (new String(method.getSelector()).equals("foo")) {
- counter++;
- }
- }
- assertEquals("Wrong number of foo method", 1, counter);
+// ClassFileReader reader = this.getClassFileReader(OUTPUT_DIR + File.separator +"X$W.class", "X$W");
+// IBinaryMethod[] methods = reader.getMethods();
+// assertEquals("Wrong size", 2, methods.length);
+// int counter = 0;
+// for (int i = 0; i < 2; i++) {
+// IBinaryMethod method = methods[i];
+// if (new String(method.getSelector()).equals("foo")) {
+// counter++;
+// }
+// }
+// assertEquals("Wrong number of foo method", 1, counter);
+//
+// reader = this.getClassFileReader(OUTPUT_DIR + File.separator +"X$Y.class", "X$Y");
+// methods = reader.getMethods();
+// assertEquals("Wrong size", 2, methods.length);
+// counter = 0;
+// for (int i = 0; i < 2; i++) {
+// IBinaryMethod method = methods[i];
+// if (new String(method.getSelector()).equals("foo")) {
+// counter++;
+// }
+// }
+// assertEquals("Wrong number of foo method", 1, counter);
+//
+// reader = this.getClassFileReader(OUTPUT_DIR + File.separator +"X$Z.class", "X$Z");
+// methods = reader.getMethods();
+// assertEquals("Wrong size", 2, methods.length);
+// counter = 0;
+// for (int i = 0; i < 2; i++) {
+// IBinaryMethod method = methods[i];
+// if (new String(method.getSelector()).equals("foo")) {
+// counter++;
+// }
+// }
+// assertEquals("Wrong number of foo method", 1, counter);
}
}
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/Requestor.java b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/Requestor.java
index 47563c3..647b6d3 100644
--- a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/Requestor.java
+++ b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/compiler/regression/Requestor.java
@@ -10,14 +10,11 @@
*******************************************************************************/
package org.eclipse.wst.jsdt.core.tests.compiler.regression;
-import java.io.File;
-import java.io.IOException;
import java.util.Hashtable;
import junit.framework.Assert;
import org.eclipse.wst.jsdt.core.compiler.CategorizedProblem;
-import org.eclipse.wst.jsdt.internal.compiler.ClassFile;
import org.eclipse.wst.jsdt.internal.compiler.CompilationResult;
import org.eclipse.wst.jsdt.internal.compiler.ICompilerRequestor;
import org.eclipse.wst.jsdt.internal.compiler.IProblemFactory;
@@ -87,27 +84,9 @@
}
problemLog += buffer.toString();
}
- outputClassFiles(compilationResult);
if (this.clientRequestor != null) {
this.clientRequestor.acceptResult(compilationResult);
}
}
-protected void outputClassFiles(CompilationResult unitResult) {
- if ((unitResult != null) && (!unitResult.hasErrors() || generateOutput)) {
- ClassFile[]classFiles = unitResult.getClassFiles();
- if (outputPath != null) {
- for (int i = 0, fileCount = classFiles.length; i < fileCount; i++) {
- // retrieve the key and the corresponding classfile
- ClassFile classFile = classFiles[i];
- String relativeName =
- new String(classFile.fileName()).replace('/', File.separatorChar) + ".class";
- try {
- ClassFile.writeToDisk(true, outputPath, relativeName, classFile);
- } catch(IOException e) {
- }
- }
- }
- }
-}
}
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/CodeSnippetTest.java b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/CodeSnippetTest.java
deleted file mode 100644
index fe64514..0000000
--- a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/CodeSnippetTest.java
+++ /dev/null
@@ -1,702 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.jsdt.core.tests.eval;
-
-import junit.framework.Test;
-
-import org.eclipse.wst.jsdt.core.compiler.CategorizedProblem;
-import org.eclipse.wst.jsdt.core.compiler.IProblem;
-import org.eclipse.wst.jsdt.internal.compiler.problem.ProblemSeverities;
-import org.eclipse.wst.jsdt.internal.eval.EvaluationResult;
-import org.eclipse.wst.jsdt.internal.eval.IRequestor;
-/**
- * Test the code snippet evaluation.
- * This assumes that the EvaluationContext class and that the EvaluationResult class
- * are working correctly.
- */
-public class CodeSnippetTest extends EvaluationTest {
-/**
- * Creates a new CodeSnippetTest.
- */
-public CodeSnippetTest(String name) {
- super(name);
-}
-/**
- * Returns a requestor that expects no result.
- */
-private IRequestor getNoResultRequestor() {
- return new Requestor() {
- public void acceptResult(EvaluationResult result) {
- assertTrue("No result", false);
- }
- };
-}
-public static Test suite() {
- return setupSuite(testClass());
-}
-/**
- * Tests code snippet that throws a checked exception.
- * (Regression test for 1G0T5XK)
- */
-public void testCheckedException() {
- evaluateWithExpectedDisplayString(buildCharArray(new String[] {
- "try {",
- " throw new java.io.IOException();",
- "} finally {",
- " System.err.println(\"This is an expected exception printed by the target VM:\");",
- "}"}),
- null);
-}
-public static Class testClass() {
- return CodeSnippetTest.class;
-}
-/**
- * Tests that no errors are reported for an empty statement followed by an expression.
- * (Regression test for PR #1G1HGHE)
- */
-public void testEmptyStatement() {
- evaluateWithExpectedDisplayString(buildCharArray(new String[] {
- "class X {",
- " public int fact(int n){",
- " return fact0(n, 1);",
- " }",
- " public int fact0(int n, int acc){",
- " if (n <= 1) return acc;",
- " return fact0(n - 1, acc * n);",
- " }",
- "};",
- "new X().fact(10)"}),
- "3628800".toCharArray());
-}
-/**
- * Tests that an error is reported for an empty import.
- */
-public void testEvaluateEmptyImport() {
- try {
- char[] importName = new char[0];
- context.setImports(new char[][] {importName});
- Requestor requestor = new Requestor();
- context.evaluateImports(getEnv(), requestor, getProblemFactory());
- assertTrue("Got one result", requestor.resultIndex == 0);
- EvaluationResult result = requestor.results[0];
- assertTrue("Problems", result.hasProblems());
- assertEquals("Evaluation type", EvaluationResult.T_IMPORT, result.getEvaluationType());
- assertEquals("Evaluation ID", importName, result.getEvaluationID());
- } finally {
- // clean up
- context.setImports(new char[0][]);
- }
-}
-/**
- * Tests that an error is reported for an existing package and a non existing type imports.
- */
-public void testEvaluateExistingPackageAndNonExistingTypeImports() {
- try {
- char[] importName = "non.existing.Type".toCharArray();
- context.setImports(new char[][] {"java.lang.reflect.*".toCharArray(), importName});
- Requestor requestor = new Requestor();
- context.evaluateImports(getEnv(), requestor, getProblemFactory());
- assertTrue("Got one result", requestor.resultIndex == 0);
- EvaluationResult result = requestor.results[0];
- assertTrue("Problems", result.hasProblems());
- assertEquals("Evaluation type", EvaluationResult.T_IMPORT, result.getEvaluationType());
- assertEquals("Evaluation ID", importName, result.getEvaluationID());
- } finally {
- // clean up
- context.setImports(new char[0][]);
- }
-}
-/**
- * Tests that an error is reported for a non existing package and an existing type imports.
- */
-public void testEvaluateNonExistingPackageAndExistingTypeImports() {
- try {
- char[] importName = "non.existing.*".toCharArray();
- context.setImports(new char[][] {importName, "java.math.BigInteger".toCharArray()});
- Requestor requestor = new Requestor();
- context.evaluateImports(getEnv(), requestor, getProblemFactory());
- assertTrue("Got one result", requestor.resultIndex == 0);
- EvaluationResult result = requestor.results[0];
- assertTrue("Problems", result.hasProblems());
- assertEquals("Evaluation type", EvaluationResult.T_IMPORT, result.getEvaluationType());
- assertEquals("Evaluation ID", importName, result.getEvaluationID());
- } finally {
- // clean up
- context.setImports(new char[0][]);
- }
-}
-/**
- * Tests that an error is reported for a non existing package import.
- */
-public void testEvaluateNonExistingPackageImport() {
- try {
- char[] importName = "non.existing.*".toCharArray();
- context.setImports(new char[][] {importName});
- Requestor requestor = new Requestor();
- context.evaluateImports(getEnv(), requestor, getProblemFactory());
- assertTrue("Got one result", requestor.resultIndex == 0);
- EvaluationResult result = requestor.results[0];
- assertTrue("Problems", result.hasProblems());
- assertEquals("Evaluation type", EvaluationResult.T_IMPORT, result.getEvaluationType());
- assertEquals("Evaluation ID", importName, result.getEvaluationID());
- } finally {
- // clean up
- context.setImports(new char[0][]);
- }
-}
-/**
- * Tests that an error is reported for a non existing type import.
- */
-public void testEvaluateNonExistingTypeImport() {
- try {
- char[] importName = "non.existing.Type".toCharArray();
- context.setImports(new char[][] {importName});
- Requestor requestor = new Requestor();
- context.evaluateImports(getEnv(), requestor, getProblemFactory());
- assertTrue("Got one result", requestor.resultIndex == 0);
- EvaluationResult result = requestor.results[0];
- assertTrue("Problems", result.hasProblems());
- assertEquals("Evaluation type", EvaluationResult.T_IMPORT, result.getEvaluationType());
- assertEquals("Evaluation ID", importName, result.getEvaluationID());
- } finally {
- // clean up
- context.setImports(new char[0][]);
- }
-}
-/**
- * Tests that no errors are reported for valid package and type imports.
- */
-public void testEvaluateValidPackageAndTypeImports() {
- try {
- context.setImports(new char[][] {"java.util.Enumeration".toCharArray(), "java.lang.reflect.*".toCharArray()});
- context.evaluateImports(getEnv(), getNoResultRequestor(), getProblemFactory());
- } finally {
- // clean up
- context.setImports(new char[0][]);
- }
-}
-/**
- * Tests that no errors are reported for a valid package import.
- */
-public void testEvaluateValidPackageImport() {
- try {
- context.setImports(new char[][] {"java.io.*".toCharArray()});
- context.evaluateImports(getEnv(), getNoResultRequestor(), getProblemFactory());
- } finally {
- // clean up
- context.setImports(new char[0][]);
- }
-}
-/**
- * Tests that no errors are reported for a valid type import.
- */
-public void testEvaluateValidTypeImport() {
- try {
- context.setImports(new char[][] {"java.math.BigInteger".toCharArray()});
- context.evaluateImports(getEnv(), getNoResultRequestor(), getProblemFactory());
- } finally {
- // clean up
- context.setImports(new char[0][]);
- }
-}
-/**
- * Tests code snippet that include a finally block triggered by an error.
- */
-public void testFinallyError() {
- evaluateWithExpectedDisplayString(buildCharArray(new String[] {
- "try {",
- " throw new Error();",
- "} finally {",
- " System.err.println(\"This is an expected error printed by the target VM:\");",
- "}"}),
- null);
-}
-/**
- * Tests code snippet that include one finally block.
- */
-public void testFinallyOneBlock() {
- evaluateWithExpectedWarningAndDisplayString(buildCharArray(new String[] {
- "try {",
- " return 1;",
- "} finally {",
- " return 2;",
- "}"}),
- new CategorizedProblem[] {
- newProblem(IProblem.FinallyMustCompleteNormally, ProblemSeverities.Warning, 30, 40, 4),
- },
- "2".toCharArray());
-}
-/**
- * Tests code snippet that include 2 finally blocks.
- */
-public void testFinallyTwoBlock() {
- evaluateWithExpectedWarningAndDisplayString(buildCharArray(new String[] {
- "try {",
- " try {",
- " return 1;",
- " } finally {",
- " return 2;",
- " }",
- "} finally {",
- " return 3;",
- "}"}),
- new CategorizedProblem[] {
- newProblem(IProblem.FinallyMustCompleteNormally, ProblemSeverities.Warning, 40, 51, 5),
- newProblem(IProblem.FinallyMustCompleteNormally, ProblemSeverities.Warning, 66, 76, 8),
- },
- "3".toCharArray());
-}
-/**
- * Tests the free return addition at the end of the code snippet
- * for an anonymous inner class.
- */
-public void testFreeReturnAnonymous() {
- evaluateWithExpectedDisplayString(buildCharArray(new String[] {
- "new Object() {",
- " public String toString() {",
- " return \"an object\";",
- " }",
- "}"}),
- "an object".toCharArray());
-}
-/**
- * Tests the free return addition at the end of the code snippet
- * for a class declaration followed by an expression.
- */
-public void testFreeReturnClassDeclaration() {
- evaluateWithExpectedDisplayString(buildCharArray(new String[] {
- "class Point {",
- " int x;",
- " int y;",
- " Point(int x, int y) {",
- " this.x = x;",
- " this.y = y;",
- " }",
- "}",
- "new Point(56, 99).x"}),
- "56".toCharArray());
-}
-/**
- * Tests the free return addition at the end of the code snippet
- * for an expression.
- */
-public void testFreeReturnExpression() {
- evaluateWithExpectedDisplayString("(1 + 2) * 3.0 / 4".toCharArray(), "2.25".toCharArray());
-}
-/**
- * Tests the free return addition at the end of the code snippet
- * for an integer.
- */
-public void testFreeReturnInteger() {
- evaluateWithExpectedDisplayString("1".toCharArray(), "1".toCharArray());
-}
-/**
- * Tests the free return addition at the end of the code snippet
- * for a local variable declaration followed by an expression.
- */
-public void testFreeReturnLocalVar() {
- evaluateWithExpectedDisplayString(buildCharArray(new String[] {
- "int i = 99;",
- "i + 4"}),
- "103".toCharArray());
-}
-/**
- * Tests the free return addition at the end of the code snippet
- * for a statement followed by an expression.
- */
-public void testFreeReturnStatement() {
- evaluateWithExpectedDisplayString(buildCharArray(new String[] {
- "int i = 2;",
- "for (int j=0;j<10;j++) {",
- " i++;",
- "}",
- "i"}),
- "12".toCharArray());
-}
-/**
- * Tests code snippet that include a package import.
- */
-public void testImportPackage() {
- try {
- context.setImports(new char[][] {"java.io.*".toCharArray()});
- evaluateWithExpectedDisplayString("return new File(\"!@#%\").exists();".toCharArray(), "false".toCharArray());
- } finally {
- // clean up
- context.setImports(new char[0][]);
- }
-}
-/**
- * Tests code snippet that include a type import.
- */
-public void testImportType() {
- try {
- context.setImports(new char[][] {"java.math.BigInteger".toCharArray()});
- evaluateWithExpectedDisplayString("return new BigInteger(\"123456789012345678901234567890\");".toCharArray(), "123456789012345678901234567890".toCharArray());
- } finally {
- // clean up
- context.setImports(new char[0][]);
- }
-}
-/**
- * Tests code snippet that include a type import and a package import.
- */
-public void testImportTypeAndPackage() {
- try {
- context.setImports(new char[][] {"java.util.Enumeration".toCharArray(), "java.lang.reflect.*".toCharArray()});
- evaluateWithExpectedDisplayString("Field[] fields = Enumeration.class.getDeclaredFields(); return fields.length;".toCharArray(), "0".toCharArray());
- } finally {
- // clean up
- context.setImports(new char[0][]);
- }
-}
-/**
- * Tests code snippet that include an anonymous inner class.
- */
-public void testInnerClassAnonymous() {
- evaluateWithExpectedDisplayString(buildCharArray(new String[] {
- "return new Object() {",
- " public String toString() {",
- " return \"an inner class\";",
- " }",
- "};"}),
- "an inner class".toCharArray());
-}
-/**
- * Tests code snippet that include a named inner class.
- */
-public void testInnerClassNamed() {
- evaluateWithExpectedDisplayString(buildCharArray(new String[] {
- "class X {",
- " int foo = 1;",
- "}",
- "return new X().foo;"}),
- "1".toCharArray());
-}
-/**
- * Tests code snippet that include a package declaration.
- */
-public void testPackage() {
- if (isJRockitVM()) return;
- // TBD: Test access to package private member
- // TBD: Test access to package class and members in another package than a java.* package
- try {
- // declare that the code snippet is run in java.util.zip and access a package private class
- context.setPackageName("java.util.zip".toCharArray());
- evaluateWithExpectedDisplayString("return ZipConstants.LOCSIG;".toCharArray(), "67324752".toCharArray());
- } finally {
- // clean up
- context.setPackageName(new char[0]);
- }
-}
-/**
- * Tests the return value display strings for a boolean.
- */
-public void testReturnDisplayStringBoolean() {
- evaluateWithExpectedDisplayString("return true;".toCharArray(), "true".toCharArray());
-}
-/**
- * Tests the return value display strings for a character.
- */
-public void testReturnDisplayStringCharacter() {
- evaluateWithExpectedDisplayString("return 'c';".toCharArray(), "c".toCharArray());
-}
-/**
- * Tests the return value display strings for a double.
- */
-public void testReturnDisplayStringDouble() {
- evaluateWithExpectedDisplayString("return 1.0;".toCharArray(), "1.0".toCharArray());
-}
-/**
- * Tests the return value display strings for no explicit returned value
- * because of an empty code snippet.
- */
-public void testReturnDisplayStringEmptyCodeSnippet() {
- evaluateWithExpectedDisplayString(new char[0], null);
-}
-/**
- * Tests the return value display strings for a float.
- */
-public void testReturnDisplayStringFloat() {
- evaluateWithExpectedDisplayString("return (float)1.0;".toCharArray(), "1.0".toCharArray());
-}
-/**
- * Tests the return value display strings for an integer.
- */
-public void testReturnDisplayStringInteger() {
- evaluateWithExpectedDisplayString("return 1;".toCharArray(), "1".toCharArray());
-}
-/**
- * Tests the return value display strings for a long.
- */
-public void testReturnDisplayStringLong() {
- evaluateWithExpectedDisplayString("return (long)1;".toCharArray(), "1".toCharArray());
-}
-/**
- * Tests the return value display strings for a code snippet
- * with no explicit returned value (implicitly the last expression is
- * wrapped inside a return statement).
- */
-public void testReturnDisplayStringNoExplicitReturnedValue() {
- evaluateWithExpectedDisplayString("new String(\"hello\".toCharArray());".toCharArray(), "hello".toCharArray());
-}
-/**
- * Tests the return value display strings for an object.
- */
-public void testReturnDisplayStringObject() {
- evaluateWithExpectedDisplayString(buildCharArray(new String[] {
- "return new Object() {",
- " public String toString() {",
- " return \"an object\";",
- " }",
- "};"}),
- "an object".toCharArray());
-}
-/**
- * Tests the return value display strings for a short.
- */
-public void testReturnDisplayStringShort() {
- evaluateWithExpectedDisplayString("return (short)1;".toCharArray(), "1".toCharArray());
-}
-/**
- * Tests the return value display strings for a String.
- */
-public void testReturnDisplayStringString() {
- evaluateWithExpectedDisplayString("return \"hello\";".toCharArray(), "hello".toCharArray());
-}
-/**
- * Tests the return value display strings for a code snippet
- * with a void returned value.
- */
-public void testReturnDisplayStringVoid() {
- evaluateWithExpectedDisplayString("new Thread().start()".toCharArray(), null);
-}
-/**
- * Tests the return type for a boolean.
- */
-public void testReturnTypeBoolean() {
- evaluateWithExpectedType("return true;".toCharArray(), "boolean".toCharArray());
-}
-/**
- * Tests the return type for a boolean array.
- */
-public void testReturnTypeBooleanArray() {
- evaluateWithExpectedType("return new boolean[] {true};".toCharArray(), "[Z".toCharArray());
-}
-/**
- * Tests the return type for a Boolean object.
- */
-public void testReturnTypeBooleanObject() {
- evaluateWithExpectedType("return new Boolean(true);".toCharArray(), "java.lang.Boolean".toCharArray());
-}
-/**
- * Tests the return type for a char.
- */
-public void testReturnTypeChar() {
- evaluateWithExpectedType("return 'c';".toCharArray(), "char".toCharArray());
-}
-/**
- * Tests the return type for a Character object.
- */
-public void testReturnTypeCharacterObject() {
- evaluateWithExpectedType("return new Character('c');".toCharArray(), "java.lang.Character".toCharArray());
-}
-/**
- * Tests the return type for a char array.
- */
-public void testReturnTypeCharArray() {
- evaluateWithExpectedType("return new char[] {'c'};".toCharArray(), "[C".toCharArray());
-}
-/**
- * Tests the return type for a double.
- */
-public void testReturnTypeDouble() {
- evaluateWithExpectedType("return 1.0;".toCharArray(), "double".toCharArray());
-}
-/**
- * Tests the return type for a double array.
- */
-public void testReturnTypeDoubleArray() {
- evaluateWithExpectedType("return new double[] {1.0};".toCharArray(), "[D".toCharArray());
-}
-/**
- * Tests the return type for a Double object.
- */
-public void testReturnTypeDoubleObject() {
- evaluateWithExpectedType("return new Double(1.0);".toCharArray(), "java.lang.Double".toCharArray());
-}
-/**
- * Tests the return type for an empty code snippet.
- */
-public void testReturnTypeEmptyCodeSnippet() {
- evaluateWithExpectedType(new char[0], null);
-}
-/**
- * Tests the return type for a float.
- */
-public void testReturnTypeFloat() {
- evaluateWithExpectedType("return (float)1.0;".toCharArray(), "float".toCharArray());
-}
-/**
- * Tests the return type for a float array.
- */
-public void testReturnTypeFloatArray() {
- evaluateWithExpectedType("return new float[] {(float)1.0};".toCharArray(), "[F".toCharArray());
-}
-/**
- * Tests the return type for a Float object.
- */
-public void testReturnTypeFloatObject() {
- evaluateWithExpectedType("return new Float(1.0);".toCharArray(), "java.lang.Float".toCharArray());
-}
-/**
- * Tests the return type for an int.
- */
-public void testReturnTypeInt() {
- evaluateWithExpectedType("return 1;".toCharArray(), "int".toCharArray());
-}
-/**
- * Tests the return type for an Integer object.
- */
-public void testReturnTypeIntegerObject() {
- evaluateWithExpectedType("return new Integer(1);".toCharArray(), "java.lang.Integer".toCharArray());
-}
-/**
- * Tests the return type for a long.
- */
-public void testReturnTypeLong() {
- evaluateWithExpectedType("return (long)1;".toCharArray(), "long".toCharArray());
-}
-/**
- * Tests the return type for a long array.
- */
-public void testReturnTypeLongArray() {
- evaluateWithExpectedType("return new long[] {(long)1};".toCharArray(), "[J".toCharArray());
-}
-/**
- * Tests the return type for a Long object.
- */
-public void testReturnTypeLongObject() {
- evaluateWithExpectedType("return new Long(1);".toCharArray(), "java.lang.Long".toCharArray());
-}
-/**
- * Tests the return type for no explicit returned value.
- */
-public void testReturnTypeNoExplicitReturnedValue() {
- evaluateWithExpectedType("new Object();".toCharArray(), "java.lang.Object".toCharArray());
-}
-/**
- * Tests the return type for an Object.
- */
-public void testReturnTypeObject() {
- evaluateWithExpectedType("return new Object();".toCharArray(), "java.lang.Object".toCharArray());
-}
-/**
- * Tests the return type for an Object array.
- */
-public void testReturnTypeObjectArray() {
- evaluateWithExpectedType("return new Object[] {new Object()};".toCharArray(), "[Ljava.lang.Object;".toCharArray());
-}
-/**
- * Tests the return type for a short.
- */
-public void testReturnTypeShort() {
- evaluateWithExpectedType("return (short)1;".toCharArray(), "short".toCharArray());
-}
-/**
- * Tests the return type for a short array.
- */
-public void testReturnTypeShortArray() {
- evaluateWithExpectedType("return new short[] {(short)1};".toCharArray(), "[S".toCharArray());
-}
-/**
- * Tests the return type for a Short object.
- */
-public void testReturnTypeShortObject() {
- evaluateWithExpectedType("return new Short((short)1);".toCharArray(), "java.lang.Short".toCharArray());
-}
-/**
- * Tests the return type for an int array.
- */
-public void testReturnTypesIntArray() {
- evaluateWithExpectedType("return new int[] {1};".toCharArray(), "[I".toCharArray());
-}
-/**
- * Tests the return type for a String.
- */
-public void testReturnTypeString() {
- evaluateWithExpectedType("return \"hello\";".toCharArray(), "java.lang.String".toCharArray());
-}
-/**
- * Tests the return type for a String array.
- */
-public void testReturnTypeStringArray() {
- evaluateWithExpectedType("return new String[] {\"hello\"};".toCharArray(), "[Ljava.lang.String;".toCharArray());
-}
-/**
- * Tests the return type for a void value.
- */
-public void testReturnTypeVoid() {
- evaluateWithExpectedType("new Thread().start()".toCharArray(), null);
-}
-/**
- * Tests that the run() method defined in an anonymous class doesn't interfer with the
- * code snippet support (see PR #1G1C0HR).
- */
-public void testRunMethodInAnonymous() {
- evaluateWithExpectedDisplayString(buildCharArray(new String[] {
- "class X {",
- " public int i = 0;",
- " public boolean finished = false;",
- "}",
- "final X x = new X();",
- "(new Thread() {",
- " public void run() {",
- " for (int i=0;i<10;i++) {",
- " try {",
- " Thread.currentThread().sleep(10);",
- " } catch (InterruptedException e) {",
- " }",
- " x.i++;",
- " }",
- " x.finished = true;",
- " }",
- "}).start();",
- "while (!x.finished) Thread.currentThread().sleep(100);",
- "x.i"}),
- "10".toCharArray());
-}
-/**
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=89632
- */
-public void testFor89632() {
- if (this.complianceLevel.compareTo(COMPLIANCE_1_5) < 0) return;
- try {
- context.setImports(new char[][] {"java.util.*".toCharArray()});
- evaluateWithExpectedDisplayString(
- buildCharArray(new String[] {
- "Collection<String> c = new ArrayList<String>();\n" +
- "c.add(\"a\");\n" +
- "c.add(\"b\");\n" +
- "c.add(\"c\"); \n" +
- "Iterator<String> i = c.iterator();\n" +
- "StringBuffer buffer = new StringBuffer();\n" +
- "while (i.hasNext()) {\n" +
- " buffer.append(i.next());\n" +
- "}" +
- "return String.valueOf(buffer);"
- }),
- "abc".toCharArray());
- } finally {
- // clean up
- context.setImports(new char[0][]);
- }
-}
-}
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/EvaluationSetup.java b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/EvaluationSetup.java
deleted file mode 100644
index 65bda62..0000000
--- a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/EvaluationSetup.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.jsdt.core.tests.eval;
-
-import java.io.File;
-import java.io.InputStream;
-import java.io.PrintStream;
-
-import junit.framework.Test;
-
-import org.eclipse.wst.jsdt.core.tests.runtime.LocalVirtualMachine;
-
-import org.eclipse.wst.jsdt.core.tests.runtime.LocalVMLauncher;
-import org.eclipse.wst.jsdt.core.tests.runtime.TargetException;
-import org.eclipse.wst.jsdt.core.tests.runtime.TargetInterface;
-import org.eclipse.wst.jsdt.core.tests.util.CompilerTestSetup;
-import org.eclipse.wst.jsdt.core.tests.util.Util;
-import org.eclipse.wst.jsdt.internal.compiler.batch.FileSystem;
-import org.eclipse.wst.jsdt.internal.compiler.env.INameEnvironment;
-import org.eclipse.wst.jsdt.internal.eval.EvaluationContext;
-
-public class EvaluationSetup extends CompilerTestSetup {
-
- public static final String EVAL_DIRECTORY = Util.getOutputDirectory() + File.separator + "evaluation";
- public static final String JRE_PATH = Util.getJREDirectory();
-
- EvaluationContext context;
- TargetInterface target;
- LocalVirtualMachine launchedVM;
- INameEnvironment env;
-
- public EvaluationSetup(Test test, String complianceLevel) {
- super(test, complianceLevel);
- }
-
-
- protected void setUp() {
- if (this.context == null) { // non null if called from subclass
-
- // Launch VM in evaluation mode
- int evalPort;
- if (EvaluationTest.JSDT_ENABLE) {
- evalPort = Util.getFreePort();
- try {
- LocalVMLauncher launcher = LocalVMLauncher.getLauncher();
- launcher.setVMPath(JRE_PATH);
- launcher.setEvalPort(evalPort);
- launcher.setEvalTargetPath(EVAL_DIRECTORY);
- this.launchedVM = launcher.launch();
- } catch (TargetException e) {
- throw new Error(e.getMessage());
- }
- // Thread that read the stout of the VM so that the VM doesn't block
- try {
- startReader("VM's stdout reader", this.launchedVM
- .getInputStream(), System.out);
- } catch (TargetException e) {
- }
- // Thread that read the sterr of the VM so that the VM doesn't block
- try {
- startReader("VM's sterr reader", this.launchedVM
- .getErrorStream(), System.err);
- } catch (TargetException e) {
- }
- }
- // Create context
- this.context = new EvaluationContext();
-
- if (EvaluationTest.JSDT_ENABLE) {
- // Create target
- this.target = new TargetInterface();
- this.target.connect("localhost", evalPort, 10000);
- }
-
- // Create name environment
- this.env = new FileSystem(Util.getJavaClassLibs(), new String[0], null);
- }
- super.setUp();
- }
-
- protected void startReader(String name, final InputStream in, final PrintStream out) {
- (new Thread(name) {
- public void run() {
- int read = 0;
- while (read != -1) {
- try {
- read = in.read();
- } catch (java.io.IOException e) {
- read = -1;
- }
- if (read != -1) {
- out.print((char)read);
- }
- }
- }
- }).start();
- }
-
- protected void tearDown() {
- if (this.context != null) {
- LocalVirtualMachine vm = this.launchedVM;
- if (vm != null) {
- try {
- if (this.target != null) {
- this.target.disconnect(); // Close the socket first so that the OS resource has a chance to be freed.
- }
- int retry = 0;
- while (vm.isRunning() && (++retry < 20)) {
- try {
- Thread.sleep(retry * 100);
- } catch (InterruptedException e) {
- }
- }
- if (vm.isRunning()) {
- vm.shutDown();
- }
- this.context = null;
- } catch (TargetException e) {
- throw new Error(e.getMessage());
- }
- }
- }
- }
-}
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/EvaluationTest.java b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/EvaluationTest.java
deleted file mode 100644
index 6ddffb4..0000000
--- a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/EvaluationTest.java
+++ /dev/null
@@ -1,566 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.jsdt.core.tests.eval;
-
-import java.io.File;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Map;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.eclipse.wst.jsdt.core.compiler.CategorizedProblem;
-import org.eclipse.wst.jsdt.core.tests.junit.extension.StopableTestCase;
-import org.eclipse.wst.jsdt.core.tests.runtime.LocalVMLauncher;
-import org.eclipse.wst.jsdt.core.tests.runtime.LocalVirtualMachine;
-import org.eclipse.wst.jsdt.core.tests.runtime.TargetException;
-import org.eclipse.wst.jsdt.core.tests.runtime.TargetInterface;
-import org.eclipse.wst.jsdt.core.tests.util.*;
-import org.eclipse.wst.jsdt.internal.compiler.ClassFile;
-import org.eclipse.wst.jsdt.internal.compiler.IProblemFactory;
-import org.eclipse.wst.jsdt.internal.compiler.batch.FileSystem;
-import org.eclipse.wst.jsdt.internal.compiler.classfmt.ClassFileReader;
-import org.eclipse.wst.jsdt.internal.compiler.classfmt.ClassFormatException;
-import org.eclipse.wst.jsdt.internal.compiler.env.IBinaryField;
-import org.eclipse.wst.jsdt.internal.compiler.env.INameEnvironment;
-import org.eclipse.wst.jsdt.internal.compiler.impl.CompilerOptions;
-import org.eclipse.wst.jsdt.internal.compiler.problem.DefaultProblem;
-import org.eclipse.wst.jsdt.internal.compiler.problem.DefaultProblemFactory;
-import org.eclipse.wst.jsdt.core.compiler.CharOperation;
-import org.eclipse.wst.jsdt.internal.eval.EvaluationContext;
-import org.eclipse.wst.jsdt.internal.eval.EvaluationResult;
-import org.eclipse.wst.jsdt.internal.eval.GlobalVariable;
-import org.eclipse.wst.jsdt.internal.eval.IRequestor;
-import org.eclipse.wst.jsdt.internal.eval.InstallException;
-
-
-public class EvaluationTest extends AbstractCompilerTest implements StopableTestCase {
- public static final boolean JSDT_ENABLE=false;
-
- public class Requestor implements IRequestor {
- public int resultIndex = -1;
- public EvaluationResult[] results = new EvaluationResult[5];
- public boolean acceptClassFiles(ClassFile[] classFiles, char[] codeSnippetClassName) {
- try {
- target.sendClasses(codeSnippetClassName != null, classFiles);
- } catch (TargetException e) {
- return false;
- }
- if (codeSnippetClassName != null) {
- TargetInterface.Result result = target.getResult();
- if (result.displayString == null) {
- this.acceptResult(new EvaluationResult(null, EvaluationResult.T_CODE_SNIPPET, null, null));
- } else {
- this.acceptResult(new EvaluationResult(null, EvaluationResult.T_CODE_SNIPPET, result.displayString, result.typeName));
- }
- } else {
- for (int i = 0, length = classFiles.length; i < length; i++) {
- char[][] compoundName = classFiles[i].getCompoundName();
- if (new String(compoundName[compoundName.length - 1]).startsWith("GlobalVariable")) {
- try {
- IBinaryField[] fields = new ClassFileReader(classFiles[i].getBytes(), null).getFields();
- if (fields != null) {
- for (int j = 0; j < fields.length; j++) {
- IBinaryField field = fields[j];
- if (Modifier.isPublic(field.getModifiers())) {
- TargetInterface.Result result = target.getResult();
- if (result.displayString == null) {
- this.acceptResult(new EvaluationResult(field.getName(), EvaluationResult.T_VARIABLE, null, null));
- } else {
- this.acceptResult(new EvaluationResult(field.getName(), EvaluationResult.T_VARIABLE, result.displayString, result.typeName));
- }
- }
- }
- }
- } catch (ClassFormatException e) {
- }
- }
- }
- }
- return true;
- }
- public void acceptProblem(CategorizedProblem problem, char[] fragmentSource, int fragmentKind) {
- this.acceptResult(new EvaluationResult(fragmentSource, fragmentKind, new CategorizedProblem[]{problem}));
- }
- public void acceptResult(EvaluationResult result) {
- try {
- this.results[++this.resultIndex] = result;
- } catch (ArrayIndexOutOfBoundsException e) {
- int oldResultLength = this.results.length;
- System.arraycopy(this.results, 0, (this.results = new EvaluationResult[oldResultLength * 2]), 0, oldResultLength);
- this.results[this.resultIndex] = result;
- }
- }
- }
-
- String[] classPath;
- public EvaluationContext context;
- INameEnvironment env;
- LocalVirtualMachine launchedVM;
- TargetInterface target;
-
- /**
- * Creates a new EvaluationTest.
- */
- public EvaluationTest(String name) {
- super(name);
- }
-
- public static Test setupSuite(Class clazz) {
- ArrayList testClasses = new ArrayList();
- testClasses.add(clazz);
- return buildAllCompliancesTestSuite(clazz, EvaluationSetup.class, testClasses);
- }
-
- public static Test suite(Class evaluationTestClass) {
- TestSuite suite = new TestSuite(evaluationTestClass);
- return suite;
- }
-
- /**
- * Asserts that two char arrays are equal. If they are not an AssertionFailedError is thrown.
- *
- * @param message
- * the detail message for this assertion
- * @param expected
- * the expected value of a char array
- * @param actual
- * the actual value of a char array
- */
- public void assertEquals(String message, char[] expected, char[] actual) {
- if (expected == null && actual == null)
- return;
- if (expected != null) {
- if (actual == null) {
- failNotEquals(message, expected, actual);
- return;
- }
- if (expected.length == actual.length) {
- for (int i = 0; i < expected.length; i++) {
- if (expected[i] != actual[i]) {
- failNotEquals(message, expected, actual);
- return;
- }
- }
- return;
- }
- }
- failNotEquals(message, expected, actual);
- }
-
- /**
- * Build a char array from the given lines
- */
- protected char[] buildCharArray(String[] lines) {
- StringBuffer buffer = new StringBuffer();
- for (int i = 0; i < lines.length; i++) {
- buffer.append(lines[i]);
- if (i < lines.length - 1) {
- buffer.append("\n");
- }
- }
- int length = buffer.length();
- char[] result = new char[length];
- buffer.getChars(0, length, result, 0);
- return result;
- }
-
- /**
- * Returns whether the 2 given problems are equals.
- */
- public boolean equals(CategorizedProblem pb1, CategorizedProblem pb2) {
- if ((pb1 == null) && (pb2 == null)) {
- return true;
- }
- if ((pb1 == null) || (pb2 == null)) {
- return false;
- }
- return (pb1.getID() == pb2.getID()) && (pb1.isError() == pb2.isError()) && (pb1.getSourceStart() == pb2.getSourceStart()) && (pb1.getSourceEnd() == pb2.getSourceEnd()) && (pb1.getSourceLineNumber() == pb2.getSourceLineNumber());
- }
-
- /**
- * Evaluates the given code snippet and makes sure it returns a result with the given display string.
- */
- public void evaluateWithExpectedDisplayString(Map compilerOptions, char[] codeSnippet, char[] displayString) {
- Requestor requestor = new Requestor();
- try {
- context.evaluate(codeSnippet, getEnv(), compilerOptions, requestor, getProblemFactory());
- } catch (InstallException e) {
- assertTrue("Target exception " + e.getMessage(), false);
- }
- if (requestor.resultIndex != 0) {
- for (int i = 0; i < requestor.resultIndex; i++) {
- System.out.println("unexpected result[" + i + "]: " + requestor.results[i]);
- }
- }
- assertTrue("Unexpected result", requestor.resultIndex == 0);
- EvaluationResult result = requestor.results[0];
- assertTrue("Has problem", !result.hasProblems());
- assertTrue("Empty problem list", result.getProblems().length == 0);
- if (displayString == null) {
- assertTrue("Has value", !result.hasValue());
- } else {
- assertTrue("Has value", result.hasValue());
- assertEquals("Evaluation type", EvaluationResult.T_CODE_SNIPPET, result.getEvaluationType());
- //assertEquals("Evaluation id", codeSnippet, result.getEvaluationID());
- assertEquals("Value display string", displayString, result.getValueDisplayString());
- }
- }
-
- /**
- * Evaluates the given code snippet and makes sure it returns a result with the given display string.
- */
- public void evaluateWithExpectedDisplayString(char[] codeSnippet, char[] displayString) {
- Requestor requestor = new Requestor();
- try {
- context.evaluate(codeSnippet, getEnv(), getCompilerOptions(), requestor, getProblemFactory());
- } catch (InstallException e) {
- assertTrue("Target exception " + e.getMessage(), false);
- }
- if (requestor.resultIndex != 0) {
- for (int i = 0; i < requestor.resultIndex; i++) {
- System.out.println("unexpected result[" + i + "]: " + requestor.results[i]);
- }
- }
- assertTrue("Unexpected result", requestor.resultIndex == 0);
- EvaluationResult result = requestor.results[0];
- assertTrue("Has problem", !result.hasProblems());
- assertTrue("Empty problem list", result.getProblems().length == 0);
- if (displayString == null) {
- assertTrue("Has value", !result.hasValue());
- } else {
- assertTrue("Has value", result.hasValue());
- assertEquals("Evaluation type", EvaluationResult.T_CODE_SNIPPET, result.getEvaluationType());
- //assertEquals("Evaluation id", codeSnippet, result.getEvaluationID());
- assertEquals("Value display string", displayString, result.getValueDisplayString());
- }
- }
-
- /**
- * Evaluates the given code snippet and makes sure the evaluation result has at least the given problem on the given import.
- */
- protected void evaluateWithExpectedImportProblem(char[] codeSnippet, char[] importDeclaration, CategorizedProblem expected) {
- evaluateWithExpectedImportProblem(codeSnippet, importDeclaration, getCompilerOptions(), expected);
- }
-
- /**
- * Evaluates the given code snippet and makes sure the evaluation result has at least the given problem on the given import.
- */
- protected void evaluateWithExpectedImportProblem(char[] codeSnippet, char[] importDeclaration, Map options, CategorizedProblem expected) {
- Requestor requestor = new Requestor();
- try {
- context.evaluate(codeSnippet, getEnv(), options, requestor, getProblemFactory());
- } catch (InstallException e) {
- assertTrue("Target exception " + e.getMessage(), false);
- }
- for (int i = 0; i <= requestor.resultIndex; i++) {
- EvaluationResult result = requestor.results[i];
- assertTrue("Has value", !result.hasValue());
- assertTrue("Has problem", result.hasProblems());
- assertEquals("Evaluation type", EvaluationResult.T_IMPORT, result.getEvaluationType());
- assertEquals("Evaluation id", importDeclaration, result.getEvaluationID());
- CategorizedProblem[] problems = result.getProblems();
- if (equals(expected, problems[0])) {
- return;
- }
- }
- assertTrue("Expected problem not found", false);
- }
-
- /**
- * Evaluates the given code snippet and makes sure the evaluation result has at least the given problem.
- */
- protected void evaluateWithExpectedProblem(char[] codeSnippet, CategorizedProblem expected) {
- Requestor requestor = new Requestor();
- try {
- context.evaluate(codeSnippet, getEnv(), getCompilerOptions(), requestor, getProblemFactory());
- } catch (InstallException e) {
- assertTrue("Target exception " + e.getMessage(), false);
- }
- for (int i = 0; i <= requestor.resultIndex; i++) {
- EvaluationResult result = requestor.results[i];
- assertTrue("Has value", !result.hasValue());
- assertTrue("Has problem", result.hasProblems());
- assertEquals("Evaluation type", EvaluationResult.T_CODE_SNIPPET, result.getEvaluationType());
- assertEquals("Evaluation id", codeSnippet, result.getEvaluationID());
- CategorizedProblem[] problems = result.getProblems();
- if (equals(expected, problems[0])) {
- return;
- }
- }
- assertTrue("Expected problem not found", false);
- }
-
- /**
- * Evaluates the given code snippet and makes sure the evaluation result has at least the given problem.
- */
- protected void evaluateWithExpectedProblem(char[] codeSnippet, String problemsString) {
- Requestor requestor = new Requestor();
- try {
- context.evaluate(codeSnippet, getEnv(), getCompilerOptions(), requestor, getProblemFactory());
- } catch (InstallException e) {
- assertTrue("Target exception " + e.getMessage(), false);
- }
- assertTrue("Got one result", requestor.resultIndex == 0);
- EvaluationResult result = requestor.results[0];
- assertTrue("Has value", !result.hasValue());
- assertTrue("Has problem", result.hasProblems());
- assertEquals("Evaluation type", EvaluationResult.T_CODE_SNIPPET, result.getEvaluationType());
- assertEquals("Evaluation id", codeSnippet, result.getEvaluationID());
- StringBuffer problemBuffer = new StringBuffer(20);
- CategorizedProblem[] problems = result.getProblems();
- for (int i = 0; i < problems.length; i++) {
- problemBuffer.append(problems[i].getMessage()).append('\n');
- }
- assertEquals("Unexpected problems", problemsString, problemBuffer.toString());
- }
-
- /**
- * Evaluates the given variable and makes sure the evaluation result has at least the given problem.
- */
- protected void evaluateWithExpectedProblem(GlobalVariable var, CategorizedProblem expected) {
- Requestor requestor = new Requestor();
- try {
- context.evaluateVariables(getEnv(), getCompilerOptions(), requestor, getProblemFactory());
- } catch (InstallException e) {
- assertTrue("Target exception " + e.getMessage(), false);
- }
- for (int i = 0; i <= requestor.resultIndex; i++) {
- EvaluationResult result = requestor.results[i];
- assertTrue("Has value", !result.hasValue());
- assertTrue("Has problem", result.hasProblems());
- assertEquals("Evaluation type", EvaluationResult.T_VARIABLE, result.getEvaluationType());
- assertEquals("Evaluation id", var.getName(), result.getEvaluationID());
- CategorizedProblem[] problems = result.getProblems();
- if (equals(expected, problems[0])) {
- return;
- }
- }
- assertTrue("Expected problem not found", false);
- }
-
- /**
- * Evaluates the given code snippet and makes sure it returns a result with the given type name.
- */
- protected void evaluateWithExpectedType(char[] codeSnippet, char[] expectedTypeName) {
- Requestor requestor = new Requestor();
- try {
- context.evaluate(codeSnippet, getEnv(), getCompilerOptions(), requestor, getProblemFactory());
- } catch (InstallException e) {
- assertTrue("Target exception " + e.getMessage(), false);
- }
- if (requestor.resultIndex != 0) {
- for (int i = 0; i < requestor.resultIndex; i++) {
- System.out.println("unexpected result[" + i + "]: " + requestor.results[i]);
- }
- }
- assertTrue("Got one result", requestor.resultIndex == 0);
- EvaluationResult result = requestor.results[0];
- if (expectedTypeName == null) {
- assertTrue("Has value", !result.hasValue());
- } else {
- assertTrue("Has value", result.hasValue());
- assertEquals("Evaluation type", EvaluationResult.T_CODE_SNIPPET, result.getEvaluationType());
- //assertEquals("Evaluation id", codeSnippet, result.getEvaluationID());
- assertEquals("Value type name", expectedTypeName, result.getValueTypeName());
- }
- }
-
- /**
- * Evaluates the given code snippet and makes sure it returns a result with the given display string and type name.
- */
- protected void evaluateWithExpectedValue(char[] codeSnippet, char[] displayString, char[] typeName) {
- Requestor requestor = new Requestor();
- try {
- context.evaluate(codeSnippet, getEnv(), getCompilerOptions(), requestor, getProblemFactory());
- } catch (InstallException e) {
- assertTrue("Target exception " + e.getMessage(), false);
- }
- assertTrue("Got one result", requestor.resultIndex == 0);
- EvaluationResult result = requestor.results[0];
- if (displayString == null) {
- assertTrue("Missing value", !result.hasValue());
- } else {
- assertTrue("Has value", result.hasValue());
- assertEquals("Evaluation type", EvaluationResult.T_CODE_SNIPPET, result.getEvaluationType());
- //assertEquals("Evaluation id", codeSnippet, result.getEvaluationID());
- assertEquals("Value display string", displayString, result.getValueDisplayString());
- assertEquals("Value type name", typeName, result.getValueTypeName());
- }
- }
-
- /**
- * Evaluates the given variable and makes sure it returns a result with the given display string and type name.
- */
- protected void evaluateWithExpectedValue(GlobalVariable var, char[] displayString, char[] typeName) {
- Requestor requestor = new Requestor();
- try {
- context.evaluateVariable(var, getEnv(), getCompilerOptions(), requestor, getProblemFactory());
- } catch (InstallException e) {
- assertTrue("Target exception " + e.getMessage(), false);
- }
- if (requestor.resultIndex != 0) {
- for (int i = 0; i < requestor.resultIndex; i++) {
- System.out.println("unexpected result[" + i + "]: " + requestor.results[i]);
- }
- }
- assertTrue("Unexpected result", requestor.resultIndex == 0);
- EvaluationResult result = requestor.results[0];
- if (displayString == null) {
- assertTrue("Has value", !result.hasValue());
- } else {
- assertTrue("Has value", result.hasValue());
- assertEquals("Value display string", displayString, result.getValueDisplayString());
- assertEquals("Value type name", typeName, result.getValueTypeName());
- }
- }
-
- /**
- * Evaluates the given code snippet and makes sure an evaluation result has at least the given warning, and that another evaluation result has the given display string.
- */
- protected void evaluateWithExpectedWarningAndDisplayString(final char[] codeSnippet, final CategorizedProblem[] expected, final char[] displayString) {
- class ResultRequestor extends Requestor {
- ArrayList collectedProblems = new ArrayList();
- boolean gotDisplayString = false;
- public void acceptResult(EvaluationResult result) {
- assertEquals("Evaluation type", EvaluationResult.T_CODE_SNIPPET, result.getEvaluationType());
- //assertEquals("Evaluation id", codeSnippet, result.getEvaluationID());
- if (result.hasValue()) {
- if (CharOperation.equals(result.getValueDisplayString(), displayString)) {
- gotDisplayString = true;
- }
- } else {
- assertTrue("Has problem", result.hasProblems());
- CategorizedProblem[] problems = result.getProblems();
- for (int i = 0; i < problems.length; i++) {
- collectedProblems.add(problems[i]);
- }
- }
- }
- }
- ResultRequestor requestor = new ResultRequestor();
- try {
- context.evaluate(codeSnippet, getEnv(), getCompilerOptions(), requestor, getProblemFactory());
- } catch (InstallException e) {
- assertTrue("Target exception " + e.getMessage(), false);
- }
- if (expected.length == requestor.collectedProblems.size()) {
- for (int i = 0; i < expected.length; i++) {
- assertTrue("Problem mismatch" + requestor.collectedProblems.get(i), this.equals(expected[i], (CategorizedProblem)requestor.collectedProblems.get(i)));
- }
- } else {
- assertTrue("Wrong problem count", false);
- }
- assertTrue("Expected display string", requestor.gotDisplayString);
- }
-
- private void failNotEquals(String message, char[] expected, char[] actual) {
- String formatted = "";
- if (message != null)
- formatted = message + " ";
- String expectedString = expected == null ? "null" : new String(expected);
- String actualString = actual == null ? "null" : new String(actual);
- fail(formatted + "expected:<" + expectedString + "> but was:<" + actualString + ">");
- }
-
- public Map getCompilerOptions() {
- Map defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.DO_NOT_GENERATE);
- defaultOptions.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.DO_NOT_GENERATE);
- defaultOptions.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.DO_NOT_GENERATE);
- defaultOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING);
- defaultOptions.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.IGNORE);
- defaultOptions.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.WARNING);
- defaultOptions.put(CompilerOptions.OPTION_ReportLocalVariableHiding, CompilerOptions.WARNING);
- defaultOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE);
- defaultOptions.put(CompilerOptions.OPTION_ReportPossibleAccidentalBooleanAssignment, CompilerOptions.WARNING);
- return defaultOptions;
- }
-
- public INameEnvironment getEnv() {
- return env;
- }
-
- public IProblemFactory getProblemFactory() {
- return new DefaultProblemFactory(java.util.Locale.getDefault());
- }
-
- public void initialize(CompilerTestSetup setUp) {
- super.initialize(setUp);
- EvaluationSetup evalSetUp = (EvaluationSetup)setUp;
- this.context = evalSetUp.context;
- this.target = evalSetUp.target;
- this.launchedVM = evalSetUp.launchedVM;
- this.env = evalSetUp.env;
- }
-
- /**
- * Installs all the variables and check that the number of installed variables is the given number.
- */
- protected void installVariables(final int expectedNumber) {
- class InstallRequestor extends Requestor {
- int count = 0;
- public void acceptResult(EvaluationResult result) {
- assertTrue("Has problems", !result.hasProblems());
- assertTrue("Has value", result.hasValue());
- this.count++;
- }
- }
-
- InstallRequestor installRequestor = new InstallRequestor();
- try {
- context.evaluateVariables(getEnv(), getCompilerOptions(), installRequestor, getProblemFactory());
- } catch (InstallException e) {
- assertTrue("Target exception: " + e.getMessage(), false);
- }
- assertEquals("Number of installed variables", expectedNumber, installRequestor.count);
- }
-
- public boolean isJRockitVM() {
- final String vmName = System.getProperty("java.vm.name");
- return vmName != null && vmName.indexOf("JRockit") != -1;
- }
- /**
- * Returns a new problem with the given id, severity, source positions and line number.
- */
- protected DefaultProblem newProblem(int id, int severity, int startPos, int endPos, int line) {
- return new DefaultProblem(null, null, id, null, severity, startPos, endPos, line, 0);
- }
-
- public void resetEnv() {
- String encoding = (String)getCompilerOptions().get(CompilerOptions.OPTION_Encoding);
- if ("".equals(encoding))
- encoding = null;
- env = new FileSystem(Util.concatWithClassLibs(EvaluationSetup.EVAL_DIRECTORY + File.separator + LocalVMLauncher.REGULAR_CLASSPATH_DIRECTORY, false), new String[0], encoding);
- }
-
- public void stop() {
- if (this.target != null) {
- this.target.disconnect(); // Close the socket first so that the OS resource has a chance to be freed.
- }
- if (this.launchedVM != null) {
- try {
- int retry = 0;
- while (this.launchedVM.isRunning() && (++retry < 20)) {
- try {
- Thread.sleep(retry * 100);
- } catch (InterruptedException e) {
- }
- }
- if (this.launchedVM.isRunning()) {
- this.launchedVM.shutDown();
- }
- } catch (TargetException e) {
- }
- }
- }
-}
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/NegativeCodeSnippetTest.java b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/NegativeCodeSnippetTest.java
deleted file mode 100644
index 6af3642..0000000
--- a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/NegativeCodeSnippetTest.java
+++ /dev/null
@@ -1,366 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.jsdt.core.tests.eval;
-
-import java.util.Map;
-
-import junit.framework.Test;
-
-import org.eclipse.wst.jsdt.core.compiler.CategorizedProblem;
-import org.eclipse.wst.jsdt.core.compiler.IProblem;
-import org.eclipse.wst.jsdt.internal.compiler.impl.CompilerOptions;
-import org.eclipse.wst.jsdt.internal.compiler.lookup.ProblemReasons;
-import org.eclipse.wst.jsdt.internal.compiler.problem.ProblemSeverities;
-import org.eclipse.wst.jsdt.internal.eval.GlobalVariable;
-/**
- * Negative tests for code snippet. Only compilation problems should be reported in
- * these tests.
- */
-public class NegativeCodeSnippetTest extends EvaluationTest implements ProblemSeverities, ProblemReasons {
-/**
- * Creates a new NegativeCodeSnippetTest.
- */
-public NegativeCodeSnippetTest(String name) {
- super(name);
-}
-public static Test suite() {
- return setupSuite(testClass());
-}
-/**
- * Test a scenario where the change of the package declaration causes a problem in a code snippet.
- */
-public void testChangePackage() {
- if (isJRockitVM()) return;
- try {
- // define the package
- context.setPackageName("java.util.zip".toCharArray());
-
- // evaluate a code snippet that uses this variable
- char[] codeSnippet = "new InflaterInputStream(new java.io.ByteArrayInputStream(new byte[0])).len".toCharArray();
- evaluateWithExpectedDisplayString(
- codeSnippet,
- "0".toCharArray());
-
- // back to the default package but with correct import
- this.context.setPackageName(new char[0]);
- this.context.setImports(new char[][] {"java.util.zip.*".toCharArray()});
-
- // evaluate same code snippet
- evaluateWithExpectedProblem(
- codeSnippet,
- newProblem(IProblem.NotVisibleField, Error, 71, 73, 1)); // The field len is not visible
-
- // back to the default package and with no imports
- this.context.setImports(new char[0][]);
-
- // evaluate same code snippet
- evaluateWithExpectedProblem(
- codeSnippet,
- newProblem(IProblem.UndefinedType, Error, 4, 22, 1)); // The type InflaterInputStream is undefined
- } finally {
- // Clean up
- this.context.setPackageName(new char[0]);
- this.context.setImports(new char[0][]);
- }
-}
-public static Class testClass() {
- return NegativeCodeSnippetTest.class;
-}
-/**
- * Test a code snippet which declares a class that uses an expression as a returned statement
- * in one of its methods.
- */
-public void testExpressionInInnerClass() {
- //TODO (david) Syntax error diagnose should be improved in this case.
- evaluateWithExpectedProblem(buildCharArray(new String[] {
- "class X {",
- " int foo() {",
- " 1 + 1",
- " }",
- "}",
- "return new X().foo();"}),
- newProblem(IProblem.ParsingError, Error, 21, 21, 2)); // Syntax error on token "+"
-}
-/**
- * Test extra closing curly bracket.
- */
-public void testExtraClosingCurlyBracket() {
- //TODO (david) Syntax error diagnose should be improved in this case.
- // just an expression with an extra curly bracket
- evaluateWithExpectedProblem(
- "1 + 2}".toCharArray(),
- newProblem(IProblem.ParsingError, Error, 0, 0, 1)); // Unmatched bracket
-
- // a statement followed by an unreachable expression with an extra curly bracket
- evaluateWithExpectedProblem(buildCharArray(new String[] {
- "return 1 + 1;",
- " 2 + 2}"}),
- newProblem(IProblem.ParsingError, Error, 15, 15, 2)); // Unmatched bracket
-}
-/**
- * Test extra open round bracket.
- */
-public void testExtraOpenRoundBracket() {
- evaluateWithExpectedProblem(
- "foo((a);".toCharArray(),
- newProblem(IProblem.ParsingErrorInsertToComplete, Error, 6, 6, 1)); // Unmatched bracket
-}
-/**
- * Test a code snippet that contains an expression followed by a semi-colon.
- */
-public void testExtraSemiColonInExpression() {
- evaluateWithExpectedProblem(
- "1;".toCharArray(),
- newProblem(IProblem.ParsingErrorInsertToComplete, Error, 0, 0, 1)); // Syntax error on token EOF
-}
-/**
- * Test access to a non existing field.
- * (regression test for bug 25250 Scrapbook shows wrong error message)
- */
-public void testInvalidField() {
- evaluateWithExpectedProblem(
- ("String s = \"\";\n" +
- "s.length").toCharArray(),
- "s.length cannot be resolved or is not a field\n");
-}
-/**
- * Test a code snippet which is valid but the evaluation context imports have problems.
- */
-public void testInvalidImport() {
- try {
- // problem on the first import
- context.setImports(new char[][] {"bar.Y".toCharArray()});
- evaluateWithExpectedImportProblem(buildCharArray(new String[] {
- "class X {",
- " Y foo = new Y();",
- "}",
- "return new X().foo;"}),
- "bar.Y".toCharArray(),
- newProblem(IProblem.ImportNotFound, Error, 0, 4, 1)); // The import bar.Y could not be resolved
-
- // problem on the second import
- context.setImports(new char[][] {"java.io.*".toCharArray(), "{".toCharArray()});
- evaluateWithExpectedImportProblem(buildCharArray(new String[] {
- "new File(\"c:\\temp\")"}),
- "{".toCharArray(),
- newProblem(IProblem.ParsingError, Error, 0, 0, 1)); // Syntax error on token "{", "Identifier" expected
- } finally {
- // Clean up
- context.setImports(new char[0][]);
- }
-}
-/**
- * Test use of this.
- */
-public void testInvalidUseOfThisInSnippet() {
- evaluateWithExpectedProblem(
- "this".toCharArray(),
- "Cannot use this in a static context \n");
-}
-/**
- * Test use of this.
- */
-public void testInvalidUseOfThisInSnippet2() {
- // just an expression with an extra curly bracket
- evaluateWithExpectedProblem(
- "return this;".toCharArray(),
- "Cannot use this in a static context \n");
-}
-/**
- * Test a code snippet that misses a closing round bracket.
- */
-public void testMissingClosingRoundBracket() {
- evaluateWithExpectedProblem(buildCharArray(new String[] {
- "System.out.println(\"3 + 3\";"}),
- newProblem(IProblem.ParsingErrorInsertToComplete, Error, 19, 25, 1)); // Unmatched bracket
-}
-/**
- * Test a code snippet that contains a string that misses the closing double quote .
- */
-public void testMissingDoubleQuote() {
- evaluateWithExpectedProblem(buildCharArray(new String[] {
- "System.out.println(\"3 + 3 = );",
- "3 + 3"}),
- newProblem(IProblem.UnterminatedString , Error, 19, 29, 1)); // String literal is not properly closed by a double-quote
-}
-/**
- * Test an expression which is not the last statement.
- */
-public void testNonLastExpressionStatement() {
- evaluateWithExpectedProblem(buildCharArray(new String[] {
- "1 == '1';",
- "true"}),
- newProblem(IProblem.ParsingErrorInvalidToken, Error, 2, 3, 1)); // Syntax error on token "=="
-}
-/**
- * Test a problem in the returned expression.
- */
-public void testProblemInExpression() {
- evaluateWithExpectedProblem(
- "new Object(); 3 + ".toCharArray(),
- newProblem(IProblem.ParsingErrorDeleteToken, Error, 16, 16, 1)); // Syntax error on token '+'
-}
-/**
- * Test a problem in the returned expression.
- */
-public void testProblemInExpression2() {
- evaluateWithExpectedProblem(
- "new UnknownClass()".toCharArray(),
- newProblem(IProblem.UndefinedType, Error, 4, 15, 1)); // UnknownClass cannot be resolved to a type
-}
-/**
- * Test a code snippet which declares a class that has a problem.
- */
-public void testProblemInInnerClass() {
- // class declared before the last expression
- evaluateWithExpectedProblem(buildCharArray(new String[] {
- "class X {",
- " Y foo = new Y();",
- "}",
- "return new X().foo;"}),
- newProblem(IProblem.UndefinedType, Error, 11, 11, 2)); // The type Y is undefined
-
- // class declared as part of the last expression
- evaluateWithExpectedWarningAndDisplayString(buildCharArray(new String[] {
- "return new Object() {",
- " public String toString() {",
- " int i = 0;",
- " return \"an inner class\";",
- " }",
- "};"}),
- new CategorizedProblem[] {
- newProblem(IProblem.LocalVariableIsNeverUsed, Warning, 56, 56, 3), // The local variable i is never used
- },
- "an inner class".toCharArray());
-}
-/**
- * Test a problem in the statement before the returned expression.
- */
-public void testProblemInPreviousStatement() {
- //TODO (david) Syntax error diagnose should be improved in this case.
- evaluateWithExpectedProblem(buildCharArray(new String[] {
- "return foo(a a);",
- "1 + 3"}),
- newProblem(IProblem.ParsingErrorDeleteToken, Error, 13, 13, 1)); // Syntax error on token "a"
-}
-/**
- * Test a code snippet that has a problem in a return statement.
- */
-public void testProblemInReturnStatement() {
- evaluateWithExpectedProblem(
- "return 1 ++ 1;".toCharArray(),
- newProblem(IProblem.InvalidUnaryExpression, Error, 7, 7, 1)); // Invalid argument to operation ++/--
-}
-/**
- * Test a scenario where the removal of an import causes a problem in a code snippet.
- */
-public void testRemoveImport() {
- try {
- // define the import
- this.context.setImports(new char[][] {"java.io.*".toCharArray()});
-
- // evaluate a code snippet that uses this variable
- char[] codeSnippet = "new File(\"c:\\\\temp\")".toCharArray();
- evaluateWithExpectedDisplayString(
- codeSnippet,
- "c:\\temp".toCharArray());
-
- // remove the import
- this.context.setImports(new char[0][]);
-
- // evaluate same code snippet
- evaluateWithExpectedProblem(
- codeSnippet,
- newProblem(IProblem.UndefinedType, Error, 4, 7, 1)); // The type File is undefined
- } finally {
- // Clean up
- this.context.setImports(new char[0][]);
- }
-}
-/**
- * Test a scenario where the removal of a variable causes a problem in a code snippet.
- */
-public void testRemoveVariable() {
- GlobalVariable var = null;
- try {
- // define the variable
- var = this.context.newVariable("int".toCharArray(), "i".toCharArray(), "1".toCharArray());
- installVariables(1);
-
- // evaluate a code snippet that uses this variable
- char[] codeSnippet = "i".toCharArray();
- evaluateWithExpectedDisplayString(
- codeSnippet,
- "1".toCharArray());
-
- // remove the variable
- this.context.deleteVariable(var);
- installVariables(0);
-
- // evaluate same code snippet
- evaluateWithExpectedProblem(
- codeSnippet,
- newProblem(IProblem.UndefinedName, Error, 0, 0, 1)); // i cannot be resolved
- } finally {
- // Clean up
- if (var != null) {
- this.context.deleteVariable(var);
- }
- }
-}
-/**
- * Test a code snippet that contains an expression which is not reachable.
- */
-public void testUnreachableExpression() {
- evaluateWithExpectedProblem(buildCharArray(new String[] {
- "return 1 + 1;",
- "2 + 2"}),
- newProblem(IProblem.CodeCannotBeReached, Error, 14, 18, 2)); // Unreachable code
-}
-/**
- * Test a code snippet which is valid but never uses the evaluation context imports.
- * (regression test for bug 18922 Scrapbook does not come back when errors in snippet)
- */
-public void testUnusedImport() {
- try {
- context.setImports(new char[][] {"java.util.*".toCharArray()});
-
- // evaluate with import as error
- Map options = this.getCompilerOptions();
- options.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.ERROR);
-
- // force evaluation so that the following evaluation will use a CodeSnippetEvaluator instead
- // of a VariableEvualator
- evaluateWithExpectedValue("1".toCharArray(), "1".toCharArray(), "int".toCharArray());
-
- evaluateWithExpectedImportProblem(
- "new String(\"NOPE\")".toCharArray(),
- "java.util.*".toCharArray(),
- options,
- newProblem(IProblem.UnusedImport, Error, 0, 10, 1)); // The import java.util.* is unused
- } finally {
- // Clean up
- context.setImports(new char[0][]);
- }
-}
-/**
- * Test a code snippet that has warnings but no errors.
- */
-public void testWarning() {
- evaluateWithExpectedWarningAndDisplayString(buildCharArray(new String[] {
- "int i;",
- "1 + 1"}),
- new CategorizedProblem[] {
- newProblem(IProblem.LocalVariableIsNeverUsed, Warning, 4, 4, 1), // The local variable i is never used
- },
- "2".toCharArray());
-}
-}
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/NegativeVariableTest.java b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/NegativeVariableTest.java
deleted file mode 100644
index b57e336..0000000
--- a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/NegativeVariableTest.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.jsdt.core.tests.eval;
-
-import junit.framework.Test;
-
-import org.eclipse.wst.jsdt.core.compiler.IProblem;
-import org.eclipse.wst.jsdt.internal.compiler.lookup.ProblemReasons;
-import org.eclipse.wst.jsdt.internal.compiler.problem.ProblemSeverities;
-import org.eclipse.wst.jsdt.internal.eval.GlobalVariable;
-/**
- * Negative tests for variables. Only compilation problems should be reported in
- * these tests.
- */
-public class NegativeVariableTest extends EvaluationTest implements ProblemSeverities, ProblemReasons {
-/**
- * Creates a new NegativeVariableTest.
- */
-public NegativeVariableTest(String name) {
- super(name);
-}
-public static Test suite() {
- return setupSuite(testClass());
-}
-public static Class testClass() {
- return NegativeVariableTest.class;
-}
-/**
- * Test a variable that has a problem in its initializer.
- */
-public void testInitializerProblem() {
- // Problem in first variable
- GlobalVariable var = null;
- try {
- var = context.newVariable("int".toCharArray(), "i".toCharArray(), buildCharArray(new String[] {
- "(1 + 1) *",
- "(j + 2)"}));
- evaluateWithExpectedProblem(
- var,
- newProblem(IProblem.UndefinedName, Error, 11, 11, 2)); // j cannot be resolved
- } finally {
- if (var != null) {
- context.deleteVariable(var);
- }
- }
-
- // Problem in second variable
- GlobalVariable var1 = null;
- GlobalVariable var2 = null;
- try {
- var1 = context.newVariable("Object".toCharArray(), "o".toCharArray(), "new Object()".toCharArray());
- var2 = context.newVariable("int".toCharArray(), "i".toCharArray(), buildCharArray(new String[] {
- "(1 + 1) *",
- "(1 ++ 2)"}));
- evaluateWithExpectedProblem(
- var2,
- newProblem(IProblem.InvalidUnaryExpression, Error, 11, 11, 2)); // Invalid argument to operation ++/--
- } finally {
- if (var1 != null) {
- context.deleteVariable(var1);
- }
- if (var2 != null) {
- context.deleteVariable(var2);
- }
- }
-
-}
-/**
- * Test a variable that has a problem in its name.
- * TODO (david) investigate why changes in enum recovery caused this test to fail
- */
-public void _testInvalidName() {
- // Problem in first variable
- GlobalVariable var = null;
- try {
- var = context.newVariable("int".toCharArray(), "!@#$%^&*()_".toCharArray(), "1".toCharArray());
- evaluateWithExpectedProblem(
- var,
- newProblem(IProblem.ParsingErrorDeleteTokens, Error, 0, 9, 0)); // Syntax error, delete these tokens
- } finally {
- if (var != null) {
- context.deleteVariable(var);
- }
- }
-
- // Problem in second variable
- GlobalVariable var1 = null;
- GlobalVariable var2 = null;
- try {
- var1 = context.newVariable("String".toCharArray(), "foo".toCharArray(), "\"bar\"".toCharArray());
- var2 = context.newVariable("int".toCharArray(), "!@#$%^&*()_".toCharArray(), "1".toCharArray());
- evaluateWithExpectedProblem(
- var2,
- newProblem(IProblem.ParsingErrorDeleteTokens, Error, 0, 9, 0)); // Syntax error, delete these tokens
- } finally {
- if (var1 != null) {
- context.deleteVariable(var1);
- }
- if (var2 != null) {
- context.deleteVariable(var2);
- }
- }
-}
-/**
- * Test a variable that has a problem in its type declaration.
- */
-public void testUnknownType() {
- // Problem in first variable
- GlobalVariable var = null;
- try {
- var = context.newVariable("foo.Bar".toCharArray(), "var".toCharArray(), null);
- evaluateWithExpectedProblem(
- var,
- newProblem(IProblem.UndefinedType, Error, 0, 2, -1)); // The type foo is undefined
- } finally {
- if (var != null) {
- context.deleteVariable(var);
- }
- }
-
- // Problem in second variable
- GlobalVariable var1 = null;
- GlobalVariable var2 = null;
- try {
- var1 = context.newVariable("int".toCharArray(), "x".toCharArray(), null);
- var2 = context.newVariable("foo.Bar".toCharArray(), "var".toCharArray(), null);
- evaluateWithExpectedProblem(
- var2,
- newProblem(IProblem.UndefinedType, Error, 0, 2, -1)); // The type foo is undefined
- } finally {
- if (var1 != null) {
- context.deleteVariable(var1);
- }
- if (var2 != null) {
- context.deleteVariable(var2);
- }
- }
-}
-}
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/SanityTestEvaluationContext.java b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/SanityTestEvaluationContext.java
deleted file mode 100644
index df700c4..0000000
--- a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/SanityTestEvaluationContext.java
+++ /dev/null
@@ -1,233 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.jsdt.core.tests.eval;
-
-import junit.framework.Test;
-
-import org.eclipse.wst.jsdt.internal.eval.EvaluationResult;
-import org.eclipse.wst.jsdt.internal.eval.GlobalVariable;
-import org.eclipse.wst.jsdt.internal.eval.IRequestor;
-import org.eclipse.wst.jsdt.internal.eval.InstallException;
-/**
- * Sanity test the IEvaluationContext interface.
- * For in depth tests, see VariableTest or CodeSnippetTest.
- */
-public class SanityTestEvaluationContext extends EvaluationTest {
-/**
- * Creates a new SanityEvaluationContextTest.
- */
-public SanityTestEvaluationContext(String name) {
- super(name);
-}
-public static Test suite() {
- return setupSuite(testClass());
-}
-/**
- * Sanity test of IEvaluationContext.allVariables()
- */
-public void testAllVariables() {
- // No variables defined yet
- GlobalVariable[] vars = context.allVariables();
- assertEquals("No variables should be defined", 0, vars.length);
-
- // Define 3 variables
- context.newVariable("int".toCharArray(), "foo".toCharArray(), "1".toCharArray());
- context.newVariable("Object".toCharArray(), "bar".toCharArray(), null);
- context.newVariable("String".toCharArray(), "zip".toCharArray(), "\"abcdefg\"".toCharArray());
- vars = context.allVariables();
- assertEquals("3 variables should be defined", 3, vars.length);
- assertEquals("1st variable", "foo".toCharArray(), vars[0].getName());
- assertEquals("2nd variable", "bar".toCharArray(), vars[1].getName());
- assertEquals("3rd variable", "zip".toCharArray(), vars[2].getName());
-
- // Remove 2nd variable
- context.deleteVariable(vars[1]);
- vars = context.allVariables();
- assertEquals("2 variables should be defined", 2, vars.length);
- assertEquals("1st variable", "foo".toCharArray(), vars[0].getName());
- assertEquals("2nd variable", "zip".toCharArray(), vars[1].getName());
-
- // Remove last variable
- context.deleteVariable(vars[1]);
- vars = context.allVariables();
- assertEquals("1 variable should be defined", 1, vars.length);
- assertEquals("1st variable", "foo".toCharArray(), vars[0].getName());
-
- // Remove 1st variable
- context.deleteVariable(vars[0]);
- vars = context.allVariables();
- assertEquals("No variables should be defined", 0, vars.length);
-}
-public static Class testClass() {
- return SanityTestEvaluationContext.class;
-}
-/**
- * Sanity test of IEvaluationContext.evaluate(char[], INameEnvironment, ConfigurableOption[], IRequestor , IProblemFactory)
- */
-public void testEvaluate() {
- Requestor requestor = new Requestor();
- char[] snippet = "return 1;".toCharArray();
- try {
- context.evaluate(snippet, getEnv(), getCompilerOptions(), requestor, getProblemFactory());
- } catch (InstallException e) {
- assertTrue("No targetException " + e.getMessage(), false);
- }
- assertTrue("Got one result", requestor.resultIndex == 0);
- EvaluationResult result = requestor.results[0];
- assertTrue("No problems with the code snippet", !result.hasProblems());
- assertTrue("Result has a value", result.hasValue());
- assertEquals("Value", "1".toCharArray(), result.getValueDisplayString());
- assertEquals("Type", "int".toCharArray(), result.getValueTypeName());
-}
-/**
- * Sanity test of IEvaluationContext.evaluateImports(INameEnvironment, IRequestor , IProblemFactory)
- */
-public void testEvaluateImports() {
- try {
- // Define imports
- context.setImports(new char[][] {"java.util.*".toCharArray(), "java.lang.reflect.Method".toCharArray()});
-
- // Evaluate them
- IRequestor requestor = new Requestor() {
- public void acceptResult(EvaluationResult result) {
- assertTrue("No problems with the imports", !result.hasProblems());
- }
- };
- context.evaluateImports(getEnv(), requestor, getProblemFactory());
- } finally {
- // Clean up
- context.setImports(new char[0][]);
- }
-}
-/**
- * Sanity test of IEvaluationContext.evaluateVariable(IGlobalVariable, IRequestor)
- */
-public void testEvaluateVariable() {
- GlobalVariable var = null;
- try {
- // Create the variable
- var = context.newVariable("int".toCharArray(), "foo".toCharArray(), "1".toCharArray());
-
- // Install it
- class NoPbRequestor extends Requestor {
- public void acceptResult(EvaluationResult result) {
- assertTrue("No problems with the variable", !result.hasProblems());
- }
- }
- try {
- context.evaluateVariables(getEnv(), getCompilerOptions(), new NoPbRequestor(), getProblemFactory());
- } catch (InstallException e) {
- assertTrue("No targetException " + e.getMessage(), false);
- }
-
- // Get its value
- Requestor requestor = new Requestor();
- try {
- context.evaluateVariable(var, getEnv(), getCompilerOptions(), requestor, getProblemFactory());
- } catch (InstallException e) {
- assertTrue("No targetException " + e.getMessage(), false);
- }
- assertTrue("Got one result", requestor.resultIndex == 0);
- EvaluationResult result = requestor.results[0];
- assertTrue("Result has value", result.hasValue());
- assertEquals("Value", "1".toCharArray(), result.getValueDisplayString());
- assertEquals("Type", "int".toCharArray(), result.getValueTypeName());
- } finally {
- // Clean up
- if (var != null) {
- context.deleteVariable(var);
- }
- }
-}
-/**
- * Sanity test of IEvaluationContext.evaluateVariables(INameEnvironment, ConfigurableOption[], IRequestor, IProblemFactory)
- */
-public void testEvaluateVariables() {
- GlobalVariable var = null;
- try {
- // Create 1 variable
- var = context.newVariable("int".toCharArray(), "foo".toCharArray(), "1".toCharArray());
-
- // Install it and get its value
- Requestor requestor = new Requestor();
- try {
- context.evaluateVariables(getEnv(), getCompilerOptions(), requestor, getProblemFactory());
- } catch (InstallException e) {
- assertTrue("No targetException " + e.getMessage(), false);
- }
- assertTrue("Got one result", requestor.resultIndex == 0);
- EvaluationResult result = requestor.results[0];
- assertTrue("No problems with the variable", !result.hasProblems());
- assertTrue("Result has value", result.hasValue());
- assertEquals("Value", "1".toCharArray(), result.getValueDisplayString());
- assertEquals("Type", "int".toCharArray(), result.getValueTypeName());
- } finally {
- // Clean up
- if (var != null) {
- context.deleteVariable(var);
- }
- }
-}
-/**
- * Sanity test of IEvaluationContext.getImports() and IEvaluationContext.setImports(char[][])
- */
-public void testGetSetImports() {
- try {
- // No imports
- assertTrue("No imports defined", context.getImports().length == 0);
-
- // Define some imports
- char[][] imports = new char[][] {"java.util".toCharArray(), "java.lang.reflect.Method".toCharArray()};
- context.setImports(imports);
- char[][] storedImports = context.getImports();
- assertEquals("Same length", imports.length, storedImports.length);
- for (int i = 0; i < imports.length; i++){
- assertEquals("Import #" + i, imports[i], storedImports[i]);
- }
- } finally {
- // Clean up
- context.setImports(new char[0][]);
- }
-}
-/**
- * Sanity test of IEvaluationContext.getPackageName() and IEvaluationContext.setPackageName(char[])
- */
-public void testGetSetPackageName() {
- try {
- // Default package
- assertTrue("Default package", context.getPackageName().length == 0);
-
- // Define a package
- char[] packageName = "x.y.z".toCharArray();
- context.setPackageName(packageName);
- char[] storedPackageName = context.getPackageName();
- assertEquals("Same package name", packageName, storedPackageName);
- } finally {
- // Clean up
- context.setPackageName(new char[0]);
- }
-}
-/**
- * Sanity test of IEvaluationContext.newVariable(char[], char[], char[]) and
- * IEvaluationContext.deleteVariable(IGlobalVariable)
- */
-public void testNewDeleteVariable() {
- // Define 1 variable
- GlobalVariable var = context.newVariable("int".toCharArray(), "deleted".toCharArray(), null);
-
- // Delete it
- context.deleteVariable(var);
- GlobalVariable[] vars = context.allVariables();
- for (int i = 0; i < vars.length; i++) {
- assertTrue("Variable should not exist", !var.getName().equals(vars[i].getName()));
- }
-}
-}
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/SanityTestEvaluationResult.java b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/SanityTestEvaluationResult.java
deleted file mode 100644
index 82be84e..0000000
--- a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/SanityTestEvaluationResult.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.jsdt.core.tests.eval;
-
-import junit.framework.Test;
-
-import org.eclipse.wst.jsdt.core.compiler.CategorizedProblem;
-import org.eclipse.wst.jsdt.internal.eval.EvaluationResult;
-import org.eclipse.wst.jsdt.internal.eval.IRequestor;
-import org.eclipse.wst.jsdt.internal.eval.InstallException;
-/**
- * Sanity test the IEvaluationResult interface.
- * For in depth tests, see VariableTest or CodeSnippetTest.
- */
-public class SanityTestEvaluationResult extends EvaluationTest {
- EvaluationResult result;
-/**
- * Creates a new SanityEvaluationResultTest.
- */
-public SanityTestEvaluationResult(String name) {
- super(name);
-}
-/**
- * Initializes this test with an evaluation result coming from the
- * evaluation of the following code snippet: "return 1;".
- */
-protected void setUp() throws Exception {
- super.setUp();
- IRequestor requestor = new Requestor() {
- public void acceptResult(EvaluationResult evalResult) {
- SanityTestEvaluationResult.this.result = evalResult;
- }
- };
- try {
- this.context.evaluate("return 1;".toCharArray(), getEnv(), getCompilerOptions(), requestor, getProblemFactory());
- } catch (InstallException e) {
- throw new Error(e.getMessage());
- }
-}
-public static Test suite() {
- return setupSuite(testClass());
-}
-public static Class testClass() {
- return SanityTestEvaluationResult.class;
-}
-/**
- * Sanity test of IEvaluationResult.getEvaluationType()
- */
-public void testGetEvaluationType() {
- int evaluationType = result.getEvaluationType();
- assertEquals("Evaluation type", EvaluationResult.T_CODE_SNIPPET, evaluationType);
-}
-/**
- * Sanity test of IEvaluationResult.getProblems()
- */
-public void testGetProblems() {
- CategorizedProblem[] problems = result.getProblems();
- assertTrue("Problems", problems == null || problems.length == 0);
-}
-/**
- * Sanity test of IEvaluationResult.getValue()
- */
-public void testGetValue() {
- // TBD: Not implemented yet
-}
-/**
- * Sanity test of IEvaluationResult.getValueDisplayString()
- */
-public void testGetValueDisplayString() {
- char[] displayString = this.result.getValueDisplayString();
- assertEquals("Value display string", "1".toCharArray(), displayString);
-}
-/**
- * Sanity test of IEvaluationResult.getValueTypeName()
- */
-public void testGetValueTypeName() {
- char[] typeName = this.result.getValueTypeName();
- assertEquals("Value type name", "int".toCharArray(), typeName);
-}
-/**
- * Sanity test of IEvaluationResult.hasErrors()
- */
-public void testHasErrors() {
- assertTrue("Result has no errors", !result.hasErrors());
-}
-/**
- * Sanity test of IEvaluationResult.hasProblems()
- */
-public void testHasProblems() {
- assertTrue("Result has no problems", !result.hasProblems());
-}
-/**
- * Sanity test of IEvaluationResult.hasValue()
- */
-public void testHasValue() {
- assertTrue("Result has a value", result.hasValue());
-}
-/**
- * Sanity test of IEvaluationResult.hasWarnings()
- */
-public void testHasWarnings() {
- assertTrue("Result has no warnings", !result.hasWarnings());
-}
-}
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/SimpleCodeSnippetTest.java b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/SimpleCodeSnippetTest.java
deleted file mode 100644
index 02a068a..0000000
--- a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/SimpleCodeSnippetTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.jsdt.core.tests.eval;
-
-import org.eclipse.wst.jsdt.core.tests.runtime.TargetException;
-import org.eclipse.wst.jsdt.internal.compiler.env.INameEnvironment;
-import org.eclipse.wst.jsdt.internal.eval.InstallException;
-
-
-public class SimpleCodeSnippetTest
- extends SimpleTest {
- public char[] getCodeSnippetSource() {
-
- return buildCharArray(new String[] { "1 + 1" });
- }
-
- public static void main(String[] args)
- throws TargetException, InstallException {
-
- SimpleCodeSnippetTest test = new SimpleCodeSnippetTest();
- test.runCodeSnippet();
- }
-
- void runCodeSnippet()
- throws TargetException, InstallException {
- this.startEvaluationContext();
-
- char[] snippet = getCodeSnippetSource();
- INameEnvironment env = getEnv();
- this.context.evaluate(snippet, env, null, this.requestor,
- getProblemFactory());
- this.stopEvaluationContext();
- }
-}
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/SimpleTest.java b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/SimpleTest.java
deleted file mode 100644
index d55c7b9..0000000
--- a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/SimpleTest.java
+++ /dev/null
@@ -1,313 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.jsdt.core.tests.eval;
-
-import java.io.File;
-
-import org.eclipse.wst.jsdt.core.compiler.CategorizedProblem;
-import org.eclipse.wst.jsdt.core.tests.runtime.LocalVMLauncher;
-import org.eclipse.wst.jsdt.core.tests.runtime.LocalVirtualMachine;
-
-import org.eclipse.wst.jsdt.core.tests.runtime.TargetException;
-import org.eclipse.wst.jsdt.core.tests.runtime.TargetInterface;
-import org.eclipse.wst.jsdt.core.tests.util.Util;
-import org.eclipse.wst.jsdt.internal.compiler.ClassFile;
-import org.eclipse.wst.jsdt.internal.compiler.IProblemFactory;
-import org.eclipse.wst.jsdt.internal.compiler.batch.FileSystem;
-import org.eclipse.wst.jsdt.internal.compiler.classfmt.ClassFileReader;
-import org.eclipse.wst.jsdt.internal.compiler.classfmt.ClassFormatException;
-import org.eclipse.wst.jsdt.internal.compiler.env.IBinaryField;
-import org.eclipse.wst.jsdt.internal.compiler.env.INameEnvironment;
-import org.eclipse.wst.jsdt.internal.compiler.problem.DefaultProblem;
-import org.eclipse.wst.jsdt.internal.compiler.problem.DefaultProblemFactory;
-import org.eclipse.wst.jsdt.core.compiler.CharOperation;
-import org.eclipse.wst.jsdt.internal.eval.EvaluationContext;
-import org.eclipse.wst.jsdt.internal.eval.EvaluationResult;
-import org.eclipse.wst.jsdt.internal.eval.GlobalVariable;
-import org.eclipse.wst.jsdt.internal.eval.IRequestor;
-
-public class SimpleTest {
- static final String JRE_PATH = Util.getJREDirectory();
- static final String[] COMPILATION_CLASSPATH = Util.concatWithClassLibs(Util.getOutputDirectory(), false);
- static final String[] RUNTIME_CLASSPATH = new String[] {Util.getOutputDirectory()};
- static final String TARGET_PATH = Util.getOutputDirectory() + File.separator + "evaluation";
- protected EvaluationContext context;
- protected LocalVirtualMachine launchedVM;
- protected TargetInterface target;
- protected Requestor requestor;
-
- class Requestor implements IRequestor {
- int globalProblemCount = 0;
- public boolean acceptClassFiles(ClassFile[] classFiles, char[] codeSnippetClassName) {
- try {
- target.sendClasses(codeSnippetClassName != null, classFiles);
- } catch (TargetException e) {
- return false;
- }
- if (codeSnippetClassName != null) {
- TargetInterface.Result result = target.getResult();
- if (result.displayString == null) {
- System.out.println("(No explicit return value)");
- } else {
- System.out.print("(");
- System.out.print(result.typeName);
- System.out.print(") ");
- System.out.println(result.displayString);
- }
- } else {
- for (int i = 0, length = classFiles.length; i < length; i++) {
- char[][] compoundName = classFiles[i].getCompoundName();
- if (new String(compoundName[compoundName.length-1]).startsWith("GlobalVariable")) {
- try {
- IBinaryField[] fields = new ClassFileReader(classFiles[i].getBytes(), null).getFields();
- if (fields != null) {
- for (int j = 0; j < fields.length; j++) {
- TargetInterface.Result result = target.getResult();
- if (result.displayString == null) {
- System.out.println("(No explicit return value)");
- } else {
- System.out.print("(");
- System.out.print(result.typeName);
- System.out.print(") ");
- System.out.println(result.displayString);
- }
- }
- }
- } catch (ClassFormatException e) {
- }
- }
- }
- }
- return true;
- }
- public void acceptProblem(CategorizedProblem problem, char[] fragmentSource, int fragmentKind) {
- int localErrorCount = 0;
- globalProblemCount++;
- char[] source = fragmentSource;
- if (localErrorCount == 0)
- System.out.println("----------");
- if (fragmentKind == EvaluationResult.T_INTERNAL) {
- System.out.print(globalProblemCount + (problem.isError() ? ". INTERNAL ERROR" : ". INTERNAL WARNING"));
- System.out.print(" in generated compilation unit");
- } else {
- System.out.print(globalProblemCount + (problem.isError() ? ". ERROR" : ". WARNING"));
- System.out.print(" in ");
- switch (fragmentKind) {
- case EvaluationResult.T_PACKAGE:
- System.out.print("package");
- break;
- case EvaluationResult.T_IMPORT:
- System.out.print("import");
- break;
- case EvaluationResult.T_CODE_SNIPPET:
- System.out.print("code snippet");
- break;
- case EvaluationResult.T_VARIABLE:
- int line = problem.getSourceLineNumber();
- if (line == -1) {
- System.out.print("variable type");
- source = findVar(fragmentSource).getTypeName();
- } else if (line == 0) {
- System.out.print("variable name");
- source = findVar(fragmentSource).getName();
- } else {
- System.out.print("variable initializer");
- source = findVar(fragmentSource).getInitializer();
- }
- break;
- }
- }
- System.out.println(errorReportSource((DefaultProblem)problem, source));
- System.out.println(problem.getMessage());
- System.out.println("----------");
- if (problem.isError())
- localErrorCount++;
- }
- }
-/**
- * Build a char array from the given lines
- */
-protected char[] buildCharArray(String[] lines) {
- StringBuffer buffer = new StringBuffer();
- for (int i = 0; i < lines.length; i++) {
- buffer.append(lines[i]);
- if (i < lines.length -1) {
- buffer.append("\n");
- }
- }
- int length = buffer.length();
- char[] result = new char[length];
- buffer.getChars(0, length, result, 0);
- return result;
-}
-protected String errorReportSource(DefaultProblem problem, char[] source) {
- //extra from the source the innacurate token
- //and "highlight" it using some underneath ^^^^^
- //put some context around too.
-
- //this code assumes that the font used in the console is fixed size
-
- //sanity .....
- if ((problem.getSourceStart() > problem.getSourceEnd()) || ((problem.getSourceStart() < 0) && (problem.getSourceEnd() < 0)))
- return "\n!! no source information available !!";
-
- //regular behavior....(slow code)
-
- final char SPACE = '\u0020';
- final char MARK = '^';
- final char TAB = '\t';
- //the next code tries to underline the token.....
- //it assumes (for a good display) that token source does not
- //contain any \r \n. This is false on statements !
- //(the code still works but the display is not optimal !)
-
- //compute the how-much-char we are displaying around the inaccurate token
- int begin = problem.getSourceStart() >= source.length ? source.length - 1 : problem.getSourceStart();
- int relativeStart = 0;
- int end = problem.getSourceEnd() >= source.length ? source.length - 1 : problem.getSourceEnd();
- int relativeEnd = 0;
- label : for (relativeStart = 0;; relativeStart++) {
- if (begin == 0)
- break label;
- if ((source[begin - 1] == '\n') || (source[begin - 1] == '\r'))
- break label;
- begin--;
- }
- label : for (relativeEnd = 0;; relativeEnd++) {
- if ((end + 1) >= source.length)
- break label;
- if ((source[end + 1] == '\r') || (source[end + 1] == '\n')) {
- break label;
- }
- end++;
- }
- //extract the message form the source
- char[] extract = new char[end - begin + 1];
- System.arraycopy(source, begin, extract, 0, extract.length);
- char c;
- //remove all SPACE and TAB that begin the error message...
- int trimLeftIndex = 0;
- while (((c = extract[trimLeftIndex++]) == TAB) || (c == SPACE)) {
- }
- System.arraycopy(extract, trimLeftIndex - 1, extract = new char[extract.length - trimLeftIndex + 1], 0, extract.length);
- relativeStart -= trimLeftIndex;
- //buffer spaces and tabs in order to reach the error position
- int pos = 0;
- char[] underneath = new char[extract.length]; // can't be bigger
- for (int i = 0; i <= relativeStart; i++) {
- if (extract[i] == TAB) {
- underneath[pos++] = TAB;
- } else {
- underneath[pos++] = SPACE;
- }
- }
- //mark the error position
- for (int i = problem.getSourceStart(); i <= (problem.getSourceEnd() >= source.length ? source.length - 1 : problem.getSourceEnd()); i++)
- underneath[pos++] = MARK;
- //resize underneathto remove 'null' chars
- System.arraycopy(underneath, 0, underneath = new char[pos], 0, pos);
- return
- ((problem.getSourceLineNumber() > 0) ?
- (" (at line " + String.valueOf(problem.getSourceLineNumber()) + ")") :
- ""
- ) +
- "\n\t" + new String(extract) + "\n\t" + new String(underneath);
-}
-protected GlobalVariable findVar(char[] varName) {
- GlobalVariable[] vars = this.context.allVariables();
- for (int i = 0; i < vars.length; i++) {
- GlobalVariable var = vars[i];
- if (CharOperation.equals(var.getName(), varName)) {
- return var;
- }
- }
- return null;
-}
-protected INameEnvironment getEnv() {
-
- return new FileSystem(COMPILATION_CLASSPATH, new String[0], null);
-}
-protected IProblemFactory getProblemFactory() {
- return new DefaultProblemFactory(java.util.Locale.getDefault());
-}
-protected void startEvaluationContext() throws TargetException {
- LocalVMLauncher launcher = LocalVMLauncher.getLauncher();
- launcher.setVMPath(JRE_PATH);
- launcher.setClassPath(RUNTIME_CLASSPATH);
- int evalPort = Util.getFreePort();
- launcher.setEvalPort(evalPort);
- launcher.setEvalTargetPath(TARGET_PATH);
- this.launchedVM = launcher.launch();
-
- (new Thread() {
- public void run() {
- try {
- java.io.InputStream in = SimpleTest.this.launchedVM.getInputStream();
- int read = 0;
- while (read != -1) {
- try {
- read = in.read();
- } catch (java.io.IOException e) {
- read = -1;
- }
- if (read != -1) {
- System.out.print((char)read);
- }
- }
- } catch (TargetException e) {
- }
- }
- }).start();
-
- (new Thread() {
- public void run() {
- try {
- java.io.InputStream in = SimpleTest.this.launchedVM.getErrorStream();
- int read = 0;
- while (read != -1) {
- try {
- read = in.read();
- } catch (java.io.IOException e) {
- read = -1;
- }
- if (read != -1) {
- System.out.print((char)read);
- }
- }
- } catch (TargetException e) {
- }
- }
- }).start();
-
- this.requestor = new Requestor();
- this.target = new TargetInterface();
- this.target.connect("localhost", evalPort, 10000);
- this.context = new EvaluationContext();
-}
-protected void stopEvaluationContext() {
- try {
- this.target.disconnect(); // Close the socket first so that the OS resource has a chance to be freed.
- int retry = 0;
- while (this.launchedVM.isRunning() && (++retry < 20)) {
- try {
- Thread.sleep(retry * 100);
- } catch (InterruptedException e) {
- }
- }
- if (this.launchedVM.isRunning()) {
- this.launchedVM.shutDown();
- }
- this.context = null;
- } catch (TargetException e) {
- throw new Error(e.getMessage());
- }
-}
-}
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/SimpleVariableTest.java b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/SimpleVariableTest.java
deleted file mode 100644
index 8dbed11..0000000
--- a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/SimpleVariableTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.jsdt.core.tests.eval;
-
-import org.eclipse.wst.jsdt.core.tests.runtime.TargetException;
-import org.eclipse.wst.jsdt.internal.compiler.env.INameEnvironment;
-import org.eclipse.wst.jsdt.internal.eval.GlobalVariable;
-import org.eclipse.wst.jsdt.internal.eval.InstallException;
-
-public class SimpleVariableTest extends SimpleTest {
-void evaluateVariable() throws TargetException, InstallException {
- startEvaluationContext();
- GlobalVariable var = getVariable();
- INameEnvironment env = getEnv();
- this.context.evaluateVariables(env, null, this.requestor, getProblemFactory());
- this.context.deleteVariable(var);
- stopEvaluationContext();
-}
-public GlobalVariable getVariable() {
- return this.context.newVariable(
- "int".toCharArray(),
- "var".toCharArray(),
- "1".toCharArray());
-}
-public static void main(String[] args) throws TargetException, InstallException {
- SimpleVariableTest test = new SimpleVariableTest();
- test.evaluateVariable();
-}
-}
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/TestAll.java b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/TestAll.java
deleted file mode 100644
index b05428c..0000000
--- a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/TestAll.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.jsdt.core.tests.eval;
-
-import java.util.ArrayList;
-
-import org.eclipse.wst.jsdt.core.tests.util.AbstractCompilerTest;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-/**
- * Run all tests defined in this package.
- */
-public class TestAll extends EvaluationTest {
-public TestAll(String name) {
- super(name);
-}
-public static Test suite() {
- if (System.getProperty("os.name").indexOf("Linux") == -1) {//$NON-NLS-1$//$NON-NLS-2$
- ArrayList testClasses = new ArrayList();
- testClasses.add(SanityTestEvaluationContext.class);
- testClasses.add(SanityTestEvaluationResult.class);
- testClasses.add(VariableTest.class);
- testClasses.add(CodeSnippetTest.class);
- testClasses.add(NegativeCodeSnippetTest.class);
- testClasses.add(NegativeVariableTest.class);
-// testClasses.add(DebugEvaluationTest.class);
-
- return AbstractCompilerTest.buildAllCompliancesTestSuite(TestAll.class, EvaluationSetup.class, testClasses);
- }
- // Disable evaluation tests on Linux
- return new TestSuite(TestAll.class.getName());
-}
-}
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/VariableTest.java b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/VariableTest.java
deleted file mode 100644
index 15dcf5b..0000000
--- a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/eval/VariableTest.java
+++ /dev/null
@@ -1,295 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.jsdt.core.tests.eval;
-
-import junit.framework.Test;
-
-import org.eclipse.wst.jsdt.internal.eval.GlobalVariable;
-/**
- * Test the global variable evaluation.
- * This assumes that the EvaluationContext class and that the GlobalVariable class
- * are working correctly.
- */
-public class VariableTest extends EvaluationTest {
-/**
- * Creates a new EvaluationContextTest.
- */
-public VariableTest(String name) {
- super(name);
-}
-public static Test suite() {
- return setupSuite(testClass());
-}
-/**
- * Tests the individual evaluation of variables with expected values of all kind of types.
- */
-public void testAllKindOfValues() {
- try {
- // Creates the variables
- GlobalVariable var1 = context.newVariable("int".toCharArray(), "var1".toCharArray(), "1".toCharArray());
- GlobalVariable var2 = context.newVariable("boolean".toCharArray(), "var2".toCharArray(), "true".toCharArray());
- GlobalVariable var3 = context.newVariable("char".toCharArray(), "var3".toCharArray(), "'c'".toCharArray());
- GlobalVariable var4 = context.newVariable("float".toCharArray(), "var4".toCharArray(), "(float)1.0".toCharArray());
- GlobalVariable var5 = context.newVariable("double".toCharArray(), "var5".toCharArray(), "1.0".toCharArray());
- GlobalVariable var6 = context.newVariable("short".toCharArray(), "var6".toCharArray(), "(short)1".toCharArray());
- GlobalVariable var7 = context.newVariable("long".toCharArray(), "var7".toCharArray(), "(long)1".toCharArray());
- GlobalVariable var8 = context.newVariable("String".toCharArray(), "var8".toCharArray(), "\"hello\"".toCharArray());
- GlobalVariable var9 = context.newVariable("Object".toCharArray(), "var9".toCharArray(), buildCharArray(new String[] {
- "new Object() {",
- " public String toString() {",
- " return \"an object\";",
- " }",
- "}"}));
- GlobalVariable var10 = context.newVariable("Object".toCharArray(), "var10".toCharArray(), null);
-
- // Install them
- installVariables(10);
-
- // Get values one by one
- evaluateWithExpectedValue(var1, "1".toCharArray(), "int".toCharArray());
- evaluateWithExpectedValue(var2, "true".toCharArray(), "boolean".toCharArray());
- evaluateWithExpectedValue(var3, "c".toCharArray(), "char".toCharArray());
- evaluateWithExpectedValue(var4, "1.0".toCharArray(), "float".toCharArray());
- evaluateWithExpectedValue(var5, "1.0".toCharArray(), "double".toCharArray());
- evaluateWithExpectedValue(var6, "1".toCharArray(), "short".toCharArray());
- evaluateWithExpectedValue(var7, "1".toCharArray(), "long".toCharArray());
- evaluateWithExpectedValue(var8, "hello".toCharArray(), "java.lang.String".toCharArray());
- evaluateWithExpectedValue(var9, "an object".toCharArray(), "java.lang.Object".toCharArray());
- evaluateWithExpectedValue(var10, "null".toCharArray(), "java.lang.Object".toCharArray());
- } finally {
- // Clean up
- GlobalVariable[] vars = context.allVariables();
- for (int i = 0; i < vars.length; i++) {
- context.deleteVariable(vars[i]);
- }
- }
-}
-public static Class testClass() {
- return VariableTest.class;
-}
-/**
- * Tests the assignment of a global variable in a code snippet.
- */
-public void testCodeSnippetVarAssign() {
- try {
- // Creates the variables
- GlobalVariable var1 = context.newVariable("int".toCharArray(), "var1".toCharArray(), null);
- GlobalVariable var2 = context.newVariable("boolean".toCharArray(), "var2".toCharArray(), null);
- GlobalVariable var3 = context.newVariable("char".toCharArray(), "var3".toCharArray(), null);
- GlobalVariable var4 = context.newVariable("float".toCharArray(), "var4".toCharArray(), null);
- GlobalVariable var5 = context.newVariable("double".toCharArray(), "var5".toCharArray(), null);
- GlobalVariable var6 = context.newVariable("short".toCharArray(), "var6".toCharArray(), null);
- GlobalVariable var7 = context.newVariable("long".toCharArray(), "var7".toCharArray(), null);
- GlobalVariable var8 = context.newVariable("String".toCharArray(), "var8".toCharArray(), null);
- GlobalVariable var9 = context.newVariable("Object".toCharArray(), "var9".toCharArray(), null);
- GlobalVariable var10 = context.newVariable("Object".toCharArray(), "var10".toCharArray(), null);
-
- // Install them
- installVariables(10);
-
- // Assign each of the variable and get its value
- evaluateWithExpectedDisplayString("var1 = 1;".toCharArray(), "1".toCharArray());
- evaluateWithExpectedValue(var1, "1".toCharArray(), "int".toCharArray());
-
- evaluateWithExpectedDisplayString("var2 = true;".toCharArray(), "true".toCharArray());
- evaluateWithExpectedValue(var2, "true".toCharArray(), "boolean".toCharArray());
-
- evaluateWithExpectedDisplayString("var3 = 'c';".toCharArray(), "c".toCharArray());
- evaluateWithExpectedValue(var3, "c".toCharArray(), "char".toCharArray());
-
- evaluateWithExpectedDisplayString("var4 = (float)1.0;".toCharArray(), "1.0".toCharArray());
- evaluateWithExpectedValue(var4, "1.0".toCharArray(), "float".toCharArray());
-
- evaluateWithExpectedDisplayString("var5 = 1.0;".toCharArray(), "1.0".toCharArray());
- evaluateWithExpectedValue(var5, "1.0".toCharArray(), "double".toCharArray());
-
- evaluateWithExpectedDisplayString("var6 = (short)1;".toCharArray(), "1".toCharArray());
- evaluateWithExpectedValue(var6, "1".toCharArray(), "short".toCharArray());
-
- evaluateWithExpectedDisplayString("var7 = (long)1;".toCharArray(), "1".toCharArray());
- evaluateWithExpectedValue(var7, "1".toCharArray(), "long".toCharArray());
-
- evaluateWithExpectedDisplayString("var8 = \"hello\";".toCharArray(), "hello".toCharArray());
- evaluateWithExpectedValue(var8, "hello".toCharArray(), "java.lang.String".toCharArray());
-
- evaluateWithExpectedDisplayString(buildCharArray(new String[] {
- "var9 = new Object() {",
- " public String toString() {",
- " return \"an object\";",
- " }",
- "};"}), "an object".toCharArray());
- evaluateWithExpectedValue(var9, "an object".toCharArray(), "java.lang.Object".toCharArray());
-
- evaluateWithExpectedDisplayString("var10 = null;".toCharArray(), "null".toCharArray());
- evaluateWithExpectedValue(var10, "null".toCharArray(), "java.lang.Object".toCharArray());
- } finally {
- // Clean up
- GlobalVariable[] vars = context.allVariables();
- for (int i = 0; i < vars.length; i++) {
- context.deleteVariable(vars[i]);
- }
- }
-}
-/**
- * Tests the retrieval of a global variable from a code snippet.
- */
-public void testCodeSnippetVarRetrieval() {
- try {
- // Creates the variables
- GlobalVariable var1 = context.newVariable("int".toCharArray(), "var1".toCharArray(), "1".toCharArray());
- GlobalVariable var2 = context.newVariable("boolean".toCharArray(), "var2".toCharArray(), "true".toCharArray());
- GlobalVariable var3 = context.newVariable("char".toCharArray(), "var3".toCharArray(), "'c'".toCharArray());
- GlobalVariable var4 = context.newVariable("float".toCharArray(), "var4".toCharArray(), "(float)1.0".toCharArray());
- GlobalVariable var5 = context.newVariable("double".toCharArray(), "var5".toCharArray(), "1.0".toCharArray());
- GlobalVariable var6 = context.newVariable("short".toCharArray(), "var6".toCharArray(), "(short)1".toCharArray());
- GlobalVariable var7 = context.newVariable("long".toCharArray(), "var7".toCharArray(), "(long)1".toCharArray());
- GlobalVariable var8 = context.newVariable("String".toCharArray(), "var8".toCharArray(), "\"hello\"".toCharArray());
- GlobalVariable var9 = context.newVariable("Object".toCharArray(), "var9".toCharArray(), buildCharArray(new String[] {
- "new Object() {",
- " public String toString() {",
- " return \"an object\";",
- " }",
- "}"}));
- GlobalVariable var10 = context.newVariable("Object".toCharArray(), "var10".toCharArray(), null);
-
- // Install them
- installVariables(10);
-
- // Get values one by one
- evaluateWithExpectedValue(var1, "1".toCharArray(), "int".toCharArray());
- evaluateWithExpectedValue(var2, "true".toCharArray(), "boolean".toCharArray());
- evaluateWithExpectedValue(var3, "c".toCharArray(), "char".toCharArray());
- evaluateWithExpectedValue(var4, "1.0".toCharArray(), "float".toCharArray());
- evaluateWithExpectedValue(var5, "1.0".toCharArray(), "double".toCharArray());
- evaluateWithExpectedValue(var6, "1".toCharArray(), "short".toCharArray());
- evaluateWithExpectedValue(var7, "1".toCharArray(), "long".toCharArray());
- evaluateWithExpectedValue(var8, "hello".toCharArray(), "java.lang.String".toCharArray());
- evaluateWithExpectedValue(var9, "an object".toCharArray(), "java.lang.Object".toCharArray());
- evaluateWithExpectedValue(var10, "null".toCharArray(), "java.lang.Object".toCharArray());
- } finally {
- // Clean up
- GlobalVariable[] vars = context.allVariables();
- for (int i = 0; i < vars.length; i++) {
- context.deleteVariable(vars[i]);
- }
- }
-}
-/**
- * Tests variables that include one or more imports.
- */
-public void testImports() {
- try {
- // import a package
- context.setImports(new char[][] {"java.io.*".toCharArray()});
- GlobalVariable file = context.newVariable("boolean".toCharArray(), "file".toCharArray(), "new File(\"!@#%\").exists()".toCharArray());
- installVariables(1);
- evaluateWithExpectedValue(file, "false".toCharArray(), "boolean".toCharArray());
- context.deleteVariable(file);
-
- // import a type
- context.setImports(new char[][] {"java.math.BigInteger".toCharArray()});
- GlobalVariable big = context.newVariable("BigInteger".toCharArray(), "big".toCharArray(), "new BigInteger(\"123456789012345678901234567890\")".toCharArray());
- installVariables(1);
- evaluateWithExpectedValue(big, "123456789012345678901234567890".toCharArray(), "java.math.BigInteger".toCharArray());
- context.deleteVariable(big);
-
- // import a type and a package
- context.setImports(new char[][] {"java.util.Enumeration".toCharArray(), "java.lang.reflect.*".toCharArray()});
- GlobalVariable fields = context.newVariable("Field[]".toCharArray(), "fields".toCharArray(), "Enumeration.class.getDeclaredFields()".toCharArray());
- installVariables(1);
- evaluateWithExpectedType("return fields;".toCharArray(), "[Ljava.lang.reflect.Field;".toCharArray());
- context.deleteVariable(fields);
- } finally {
- // clean up
- context.setImports(new char[0][]);
- }
-}
-/**
- * Tests the additions and deletion of variables, installing them each time.
- */
-public void testSeveralVariableInstallations() {
- try {
- // Creates 6 variables
- GlobalVariable var1 = context.newVariable("int".toCharArray(), "var1".toCharArray(), "1".toCharArray());
- GlobalVariable var2 = context.newVariable("boolean".toCharArray(), "var2".toCharArray(), "true".toCharArray());
- GlobalVariable var3 = context.newVariable("char".toCharArray(), "var3".toCharArray(), "'c'".toCharArray());
- GlobalVariable var4 = context.newVariable("float".toCharArray(), "var4".toCharArray(), "(float)1.0".toCharArray());
- GlobalVariable var5 = context.newVariable("double".toCharArray(), "var5".toCharArray(), "1.0".toCharArray());
- GlobalVariable var6 = context.newVariable("short".toCharArray(), "var6".toCharArray(), "(short)1".toCharArray());
-
- // Install the variables
- installVariables(6);
-
- // Get their values
- evaluateWithExpectedValue(var1, "1".toCharArray(), "int".toCharArray());
- evaluateWithExpectedValue(var2, "true".toCharArray(), "boolean".toCharArray());
- evaluateWithExpectedValue(var3, "c".toCharArray(), "char".toCharArray());
- evaluateWithExpectedValue(var4, "1.0".toCharArray(), "float".toCharArray());
- evaluateWithExpectedValue(var5, "1.0".toCharArray(), "double".toCharArray());
- evaluateWithExpectedValue(var6, "1".toCharArray(), "short".toCharArray());
-
- // Delete 3 variables
- context.deleteVariable(var2);
- context.deleteVariable(var5);
- context.deleteVariable(var6);
-
- // Install the variables
- installVariables(3);
-
- // Get their values
- evaluateWithExpectedValue(var1, "1".toCharArray(), "int".toCharArray());
- evaluateWithExpectedValue(var3, "c".toCharArray(), "char".toCharArray());
- evaluateWithExpectedValue(var4, "1.0".toCharArray(), "float".toCharArray());
-
- // Add 4 more variables
- GlobalVariable var7 = context.newVariable("long".toCharArray(), "var7".toCharArray(), "(long)1".toCharArray());
- GlobalVariable var8 = context.newVariable("String".toCharArray(), "var8".toCharArray(), "\"hello\"".toCharArray());
- GlobalVariable var9 = context.newVariable("Object".toCharArray(), "var9".toCharArray(), buildCharArray(new String[] {
- "new Object() {",
- " public String toString() {",
- " return \"an object\";",
- " }",
- "}"}));
- GlobalVariable var10 = context.newVariable("Object".toCharArray(), "var10".toCharArray(), null);
-
- // Install the variables
- installVariables(7);
-
- // Change value of a variable using a code snippet and move it
- evaluateWithExpectedValue("var3 = 'z'; return var3;".toCharArray(), "z".toCharArray(), "char".toCharArray());
- context.deleteVariable(var3);
-
- // Change the type of another variable to an incompatible type
- context.deleteVariable(var4);
- installVariables(5);
-
- // Recreate the variables
- var3 = context.newVariable(var3.getTypeName(), var3.getName(), var3.getInitializer());
- var4 = context.newVariable("java.net.URL".toCharArray(), "var4".toCharArray(), "new java.net.URL(\"http://www.ibm.com/index.html\")".toCharArray());
- installVariables(7);
-
- // Get their values
- evaluateWithExpectedValue(var1, "1".toCharArray(), "int".toCharArray());
- evaluateWithExpectedValue(var3, "c".toCharArray(), "char".toCharArray());
- evaluateWithExpectedValue(var4, "http://www.ibm.com/index.html".toCharArray(), "java.net.URL".toCharArray());
- evaluateWithExpectedValue(var7, "1".toCharArray(), "long".toCharArray());
- evaluateWithExpectedValue(var8, "hello".toCharArray(), "java.lang.String".toCharArray());
- evaluateWithExpectedValue(var9, "an object".toCharArray(), "java.lang.Object".toCharArray());
- evaluateWithExpectedValue(var10, "null".toCharArray(), "java.lang.Object".toCharArray());
- } finally {
- // Clean up
- GlobalVariable[] vars = context.allVariables();
- for (int i = 0; i < vars.length; i++) {
- context.deleteVariable(vars[i]);
- }
- }
-}
-}
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/runtime/TargetInterface.java b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/runtime/TargetInterface.java
index e441613..24cfba3 100644
--- a/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/runtime/TargetInterface.java
+++ b/tests/org.eclipse.wst.jsdt.core.tests.compiler/src/org/eclipse/wst/jsdt/core/tests/runtime/TargetInterface.java
@@ -10,9 +10,10 @@
*******************************************************************************/
package org.eclipse.wst.jsdt.core.tests.runtime;
-import org.eclipse.wst.jsdt.internal.compiler.ClassFile;
-import java.io.*;
-import java.net.*;
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.net.Socket;
+import java.net.UnknownHostException;
/**
* This is the interface to the target VM. It connects to an IDEInterface on the target side
* using TCP/IO to send request for code snippet evaluation and to get the result back.
@@ -143,49 +144,5 @@
/**
* Sends the given class definitions to the target for loading and (if specified) for running.
*/
-public void sendClasses(boolean mustRun, ClassFile[] classes) throws TargetException {
- if (DEBUG) {
- for (int i = 0; i < classes.length; i++) {
- String className = new String(classes[i].fileName()).replace('/', '\\') + ".class";
- if ((i == 0) && (className.indexOf("CodeSnippet") != -1)) {
- codeSnippetClassName = className;
- try {
- ClassFile.writeToDisk(true, "d:\\eval\\snippets", className, classes[0]);
- } catch(IOException e) {
- }
- } else {
- String dirName;
- if (className.startsWith("java")) {
- dirName = "d:\\eval\\" + LocalVMLauncher.BOOT_CLASSPATH_DIRECTORY;
- } else {
- dirName = "d:\\eval\\" + LocalVMLauncher.REGULAR_CLASSPATH_DIRECTORY;
- }
- try {
- ClassFile.writeToDisk(true, dirName, className, classes[i]);
- } catch(IOException e) {
- }
- }
- }
- } else {
- if (TIMING) {
- this.sentTime = System.currentTimeMillis();
- }
- if (!isConnected()) {
- throw new TargetException("Connection to the target VM has been lost");
- }
- try {
- DataOutputStream out = new DataOutputStream(this.socket.getOutputStream());
- out.writeBoolean(mustRun);
- out.writeInt(classes.length);
- for (int i = 0; i < classes.length; i++) {
- byte[] classDefinition = classes[i].getBytes();
- out.writeInt(classDefinition.length);
- out.write(classDefinition);
- }
- } catch (IOException e) {
- // The socket has likely been closed on the other end. So the code snippet runner has stopped.
- this.disconnect();
- }
- }
-}
+
}
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.model/src/org/eclipse/wst/jsdt/core/tests/RunCompilerTests.java b/tests/org.eclipse.wst.jsdt.core.tests.model/src/org/eclipse/wst/jsdt/core/tests/RunCompilerTests.java
index e3e63d8..57434c9 100644
--- a/tests/org.eclipse.wst.jsdt.core.tests.model/src/org/eclipse/wst/jsdt/core/tests/RunCompilerTests.java
+++ b/tests/org.eclipse.wst.jsdt.core.tests.model/src/org/eclipse/wst/jsdt/core/tests/RunCompilerTests.java
@@ -31,7 +31,7 @@
return new Class[] {
org.eclipse.wst.jsdt.core.tests.compiler.regression.TestAll.class,
org.eclipse.wst.jsdt.core.tests.compiler.parser.TestAll.class,
- org.eclipse.wst.jsdt.core.tests.eval.TestAll.class,
+// org.eclipse.wst.jsdt.core.tests.eval.TestAll.class,
};
}
public static Test suite() {
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.model/src/org/eclipse/wst/jsdt/core/tests/model/AttachSourceTests.java b/tests/org.eclipse.wst.jsdt.core.tests.model/src/org/eclipse/wst/jsdt/core/tests/model/AttachSourceTests.java
index 79d192c..481e8f8 100644
--- a/tests/org.eclipse.wst.jsdt.core.tests.model/src/org/eclipse/wst/jsdt/core/tests/model/AttachSourceTests.java
+++ b/tests/org.eclipse.wst.jsdt.core.tests.model/src/org/eclipse/wst/jsdt/core/tests/model/AttachSourceTests.java
@@ -13,17 +13,28 @@
import java.io.IOException;
import junit.framework.Test;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
-import org.eclipse.wst.jsdt.core.*;
-import org.eclipse.wst.jsdt.core.dom.*;
-import org.eclipse.wst.jsdt.internal.compiler.classfmt.ClassFileConstants;
+import org.eclipse.wst.jsdt.core.IClassFile;
+import org.eclipse.wst.jsdt.core.IJavaElement;
+import org.eclipse.wst.jsdt.core.IJavaProject;
+import org.eclipse.wst.jsdt.core.IMember;
+import org.eclipse.wst.jsdt.core.IMethod;
+import org.eclipse.wst.jsdt.core.IPackageFragment;
+import org.eclipse.wst.jsdt.core.IPackageFragmentRoot;
+import org.eclipse.wst.jsdt.core.ISourceRange;
+import org.eclipse.wst.jsdt.core.IType;
+import org.eclipse.wst.jsdt.core.JavaCore;
+import org.eclipse.wst.jsdt.core.JavaModelException;
+import org.eclipse.wst.jsdt.core.dom.AST;
+import org.eclipse.wst.jsdt.core.dom.ASTNode;
+import org.eclipse.wst.jsdt.core.dom.ASTParser;
import org.eclipse.wst.jsdt.internal.core.JarPackageFragmentRoot;
-import org.eclipse.wst.jsdt.internal.core.util.Util;
/**
* TO DO:
@@ -956,35 +967,35 @@
this.attachSource(root, null, null); // detach source
root.close();
}
-/**
- * http://bugs.eclipse.org/bugs/show_bug.cgi?id=35965
- */
-public void testRootPath11() throws JavaModelException {
- IJavaProject project = this.getJavaProject("/AttachSourceTests");
- IPackageFragmentRoot root = project.getPackageFragmentRoot(this.getFile("/AttachSourceTests/test4.jar"));
- this.attachSource(root, "/AttachSourceTests/test4_src.zip", null);
-
- IClassFile cf = root.getPackageFragment("P1").getClassFile("D.class");
- assertSourceEquals(
- "Unexpected source for class file P1.D",
- "package P1;\n" +
- "\n" +
- "public class D {}",
- cf.getSource());
-
- cf = root.getPackageFragment("P1.p2").getClassFile("A.class");
- assertSourceEquals(
- "Unexpected source for class file P1.p2.A",
- "package P1.p2;\n" +
- "\n" +
- "public class A {}",
- cf.getSource());
-
- assertTrue("Not a binary root", root.getKind() == IPackageFragmentRoot.K_BINARY);
- assertEquals("wrong jdk level", ClassFileConstants.JDK1_2, Util.getJdkLevel(root.getResource()));
- this.attachSource(root, null, null); // detach source
- root.close();
-}
+///**
+// * http://bugs.eclipse.org/bugs/show_bug.cgi?id=35965
+// */
+//public void testRootPath11() throws JavaModelException {
+// IJavaProject project = this.getJavaProject("/AttachSourceTests");
+// IPackageFragmentRoot root = project.getPackageFragmentRoot(this.getFile("/AttachSourceTests/test4.jar"));
+// this.attachSource(root, "/AttachSourceTests/test4_src.zip", null);
+//
+// IClassFile cf = root.getPackageFragment("P1").getClassFile("D.class");
+// assertSourceEquals(
+// "Unexpected source for class file P1.D",
+// "package P1;\n" +
+// "\n" +
+// "public class D {}",
+// cf.getSource());
+//
+// cf = root.getPackageFragment("P1.p2").getClassFile("A.class");
+// assertSourceEquals(
+// "Unexpected source for class file P1.p2.A",
+// "package P1.p2;\n" +
+// "\n" +
+// "public class A {}",
+// cf.getSource());
+//
+// assertTrue("Not a binary root", root.getKind() == IPackageFragmentRoot.K_BINARY);
+// assertEquals("wrong jdk level", ClassFileConstants.JDK1_2, Util.getJdkLevel(root.getResource()));
+// this.attachSource(root, null, null); // detach source
+// root.close();
+//}
/**
* Attach a jar with a source attachement that is itself. The jar contains 2 root paths for the same class file.
* (regression test for bug 74014 prefix path for source attachements - automatic detection does not seem to work)
diff --git a/tests/org.eclipse.wst.jsdt.core.tests.model/src/org/eclipse/wst/jsdt/core/tests/model/JavaProjectTests.java b/tests/org.eclipse.wst.jsdt.core.tests.model/src/org/eclipse/wst/jsdt/core/tests/model/JavaProjectTests.java
index 478bbe9..fdd6b3a 100644
--- a/tests/org.eclipse.wst.jsdt.core.tests.model/src/org/eclipse/wst/jsdt/core/tests/model/JavaProjectTests.java
+++ b/tests/org.eclipse.wst.jsdt.core.tests.model/src/org/eclipse/wst/jsdt/core/tests/model/JavaProjectTests.java
@@ -16,18 +16,38 @@
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceDescription;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
-import org.eclipse.wst.jsdt.core.*;
-import org.eclipse.wst.jsdt.internal.compiler.classfmt.ClassFileConstants;
+import org.eclipse.wst.jsdt.core.IAccessRule;
+import org.eclipse.wst.jsdt.core.IClassFile;
+import org.eclipse.wst.jsdt.core.IClasspathAttribute;
+import org.eclipse.wst.jsdt.core.IClasspathEntry;
+import org.eclipse.wst.jsdt.core.ICompilationUnit;
+import org.eclipse.wst.jsdt.core.IJavaElement;
+import org.eclipse.wst.jsdt.core.IJavaModelStatusConstants;
+import org.eclipse.wst.jsdt.core.IJavaProject;
+import org.eclipse.wst.jsdt.core.IMethod;
+import org.eclipse.wst.jsdt.core.IPackageFragment;
+import org.eclipse.wst.jsdt.core.IPackageFragmentRoot;
+import org.eclipse.wst.jsdt.core.IType;
+import org.eclipse.wst.jsdt.core.JavaCore;
+import org.eclipse.wst.jsdt.core.JavaModelException;
import org.eclipse.wst.jsdt.internal.core.JavaModelManager;
import org.eclipse.wst.jsdt.internal.core.UserLibrary;
import org.eclipse.wst.jsdt.internal.core.UserLibraryManager;
-import org.eclipse.wst.jsdt.internal.core.util.Util;
public class JavaProjectTests extends ModifyingResourceTests {
public JavaProjectTests(String name) {
@@ -1180,14 +1200,14 @@
IResource corr= methods[0].getCorrespondingResource();
assertTrue("incorrect corresponding resource", corr == null);
}
-/**
- * Test the jdklevel of the package fragment root
- */
-public void testJdkLevelRoot() throws JavaModelException {
- IPackageFragmentRoot root= getPackageFragmentRoot("JavaProjectLibTests", "lib/");
- assertEquals("wrong type", IPackageFragmentRoot.K_BINARY, root.getKind());
- assertEquals("wrong jdk level", ClassFileConstants.JDK1_1, Util.getJdkLevel(root.getResource()));
-}
+///**
+// * Test the jdklevel of the package fragment root
+// */
+//public void testJdkLevelRoot() throws JavaModelException {
+// IPackageFragmentRoot root= getPackageFragmentRoot("JavaProjectLibTests", "lib/");
+// assertEquals("wrong type", IPackageFragmentRoot.K_BINARY, root.getKind());
+// assertEquals("wrong jdk level", ClassFileConstants.JDK1_1, Util.getJdkLevel(root.getResource()));
+//}
/**
* Test User Library preference. External jar file referenced in library entry does not exist.
* It does not need to as we only test the preference value...