update sources to v_C18, build config to v_C17 (no build containing C18 is available at this point)
diff --git a/org.eclipse.jdt.core.tests.model/.cvsignore b/org.eclipse.jdt.core.tests.model/.cvsignore
deleted file mode 100644
index c5e82d7..0000000
--- a/org.eclipse.jdt.core.tests.model/.cvsignore
+++ /dev/null
@@ -1 +0,0 @@
-bin
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/.settings/org.eclipse.core.runtime.prefs b/org.eclipse.jdt.core.tests.model/.settings/org.eclipse.core.runtime.prefs
new file mode 100644
index 0000000..5a0ad22
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/.settings/org.eclipse.core.runtime.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+line.separator=\n
diff --git a/org.eclipse.jdt.core.tests.model/plugin.xml b/org.eclipse.jdt.core.tests.model/plugin.xml
index 6cda687..5d8226c 100644
--- a/org.eclipse.jdt.core.tests.model/plugin.xml
+++ b/org.eclipse.jdt.core.tests.model/plugin.xml
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java
index c6f70e8..2af2c81 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java
@@ -7,7 +7,9 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
- * Stephan Herrmann - Contribution for Bug 342671 - ClassCastException: org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding cannot be cast to org.eclipse.jdt.internal.compiler.lookup.ArrayBinding
+ * Stephan Herrmann - Contributions for
+ * Bug 342671 - ClassCastException: org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding cannot be cast to org.eclipse.jdt.internal.compiler.lookup.ArrayBinding
+ * Bug 353474 - type converters should include more annotations
*******************************************************************************/
package org.eclipse.jdt.core.tests.dom;
@@ -50,7 +52,7 @@
static {
// TESTS_NUMBERS = new int[] { 353 };
// TESTS_RANGE = new int[] { 325, -1 };
-// TESTS_NAMES = new String[] {"test0204"};
+// TESTS_NAMES = new String[] {"testBug353474"};
}
public static Test suite() {
return buildModelTestSuite(ASTConverter15Test.class);
@@ -11348,5 +11350,100 @@
rhsType = ((Assignment)((ExpressionStatement)((Statement) statements.get(1))).getExpression()).getRightHandSide().resolveTypeBinding();
assertFalse("Assignement compatible", rhsType.isAssignmentCompatible(assignmentType));
}
+ // Bug 353474 - type converters should include more annotations
+ public void testBug353474() throws CoreException {
+
+ this.createFolder("/Converter15/src/testBug353474/annot");
+ String contents =
+ "package testBug353474.annot;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.*;\n" +
+ "@Retention(RetentionPolicy.CLASS)\n" +
+ "@Target({METHOD,PARAMETER,LOCAL_VARIABLE})\n" +
+ "public @interface Nullable {\n" +
+ "}\n";
+ getWorkingCopy("/Converter15/src/testBug353474/annot/Nullable.java", contents, true/*resolve*/);
+
+ this.createFolder("/Converter15/src/testBug353474/p1");
+ contents =
+ "package testBug353474.p1;\n" +
+ "import testBug353474.annot.*;\n" +
+ "public class C1 {\n" +
+ " public @Nullable String foo(@Nullable Object arg) {\n" +
+ " return \"\";\n" +
+ " }\n" +
+ "}\n";
+ getWorkingCopy("/Converter15/src/testBug353474/p1/C1.java", contents, true/*resolve*/);
+
+ this.workingCopy = getWorkingCopy("/Converter15/src/testBug353474/p1/C2.java", true/*resolve*/);
+ contents =
+ "package testBug353474.p1;\n" +
+ "public class C2 {\n" +
+ " public String bar(C1 c1) {\n" +
+ " return c1.foo(null);\n" +
+ " }\n" +
+ "}\n";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ true);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ TypeDeclaration c2 = (TypeDeclaration) compilationUnit.types().get(0);
+ MethodDeclaration bar = (MethodDeclaration) c2.bodyDeclarations().get(0);
+ ReturnStatement returnStat = (ReturnStatement) bar.getBody().statements().get(0);
+ MethodInvocation fooCall = (MethodInvocation) returnStat.getExpression();
+ IMethodBinding resolvedFoo = fooCall.resolveMethodBinding();
+ IAnnotationBinding[] parameterAnnotations0 = resolvedFoo.getParameterAnnotations(0);
+ assertNotNull("Parameter annotation should not be null", parameterAnnotations0);
+ assertEquals("Should have exactly one annotation", 1, parameterAnnotations0.length);
+ assertEquals("Unexpected annotation name", "Nullable", parameterAnnotations0[0].getName());
+
+ IAnnotationBinding[] returnAnnotations = resolvedFoo.getAnnotations();
+ assertNotNull("Return annotation should not be null", returnAnnotations);
+ assertEquals("Should have exactly one return annotation", 1, returnAnnotations.length);
+ assertEquals("Unexpected annotation name", "Nullable", returnAnnotations[0].getName());
+ deleteFolder("/Converter15/src/testBug353474");
+ }
+ // Bug 353474 - type converters should include more annotations
+ // secondary type comes from binary
+ public void testBug353474a() throws CoreException {
+ String jarLocation = getWorkspacePath()+"Converter15/bins/bug353474.jar";
+ IJavaProject jp = createJavaProject("Bug353464a", new String[]{"src"}, new String[]{"CONVERTER_JCL15_LIB", jarLocation}, "bin", "1.5");
+ try {
+ this.workingCopy = getWorkingCopy("/Bug353464a/src/testBug353474/p1/C2.java", true/*resolve*/);
+ String contents =
+ "package testBug353474.p1;\n" +
+ "public class C2 {\n" +
+ " public String bar(C1a c1) {\n" +
+ " return c1.foo(null);\n" +
+ " }\n" +
+ "}\n";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ true);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ TypeDeclaration c2 = (TypeDeclaration) compilationUnit.types().get(0);
+ MethodDeclaration bar = (MethodDeclaration) c2.bodyDeclarations().get(0);
+ ReturnStatement returnStat = (ReturnStatement) bar.getBody().statements().get(0);
+ MethodInvocation fooCall = (MethodInvocation) returnStat.getExpression();
+ IMethodBinding resolvedFoo = fooCall.resolveMethodBinding();
+ IAnnotationBinding[] parameterAnnotations0 = resolvedFoo.getParameterAnnotations(0);
+ assertNotNull("Parameter annotation should not be null", parameterAnnotations0);
+ assertEquals("Should have exactly one annotation", 1, parameterAnnotations0.length);
+ assertEquals("Unexpected annotation name", "Nullable", parameterAnnotations0[0].getName());
+
+ IAnnotationBinding[] returnAnnotations = resolvedFoo.getAnnotations();
+ assertNotNull("Return annotation should not be null", returnAnnotations);
+ assertEquals("Should have exactly one return annotation", 1, returnAnnotations.length);
+ assertEquals("Unexpected annotation name", "Nullable", returnAnnotations[0].getName());
+ } finally {
+ deleteProject(jp);
+ }
+ }
}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST4_2.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST4_2.java
index e3f0158..3e8435b 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST4_2.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST4_2.java
@@ -122,7 +122,7 @@
static {
// TESTS_NAMES = new String[] {"test0602"};
// TESTS_RANGE = new int[] { 721, -1 };
-// TESTS_NUMBERS = new int[] { 723, 724 };
+// TESTS_NUMBERS = new int[] { 725 };
}
public static Test suite() {
return buildModelTestSuite(ASTConverterTestAST4_2.class);
@@ -10684,4 +10684,47 @@
assertFalse(isRecovered((ASTNode) statements.get(1)));
assertFalse(isRecovered((ASTNode) statements.get(2)));
}
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=357471
+ */
+ public void test0725() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "package one.two;\n" +
+ "public class one {}";
+ workingCopy = getWorkingCopy("/Converter/src/one/two/one.java", true/*resolve*/);
+ CompilationUnit unit = (CompilationUnit) buildAST(
+ AST.JLS3,
+ contents,
+ workingCopy,
+ true,
+ true,
+ true);
+ PackageDeclaration packageDeclaration = unit.getPackage();
+ IPackageBinding packageBinding = packageDeclaration.resolveBinding();
+ assertNotNull("No binding", packageBinding);
+ assertEquals("Wrong name", "one.two", packageBinding.getName());
+ Name packageName = packageDeclaration.getName();
+ IBinding binding = packageName.resolveBinding();
+ assertEquals("Wrong type", IBinding.PACKAGE, binding.getKind());
+ packageBinding = (IPackageBinding) binding;
+ assertEquals("Wrong name", "one.two", packageBinding.getName());
+ packageName = ((QualifiedName) packageName).getQualifier();
+ binding = packageName.resolveBinding();
+ assertEquals("Wrong type", IBinding.PACKAGE, binding.getKind());
+ packageBinding = (IPackageBinding) binding;
+ assertEquals("Wrong name", "one", packageBinding.getName());
+ packageName = packageDeclaration.getName();
+ packageName = ((QualifiedName) packageName).getName();
+ binding = packageName.resolveBinding();
+ assertEquals("Wrong type", IBinding.PACKAGE, binding.getKind());
+ packageBinding = (IPackageBinding) binding;
+ assertEquals("Wrong name", "one.two", packageBinding.getName());
+ } finally {
+ if (workingCopy != null) {
+ workingCopy.discardWorkingCopy();
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java
index feb73b5..80b5445 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java
@@ -62,7 +62,7 @@
Map formatterOptions;
static {
-// TESTS_NUMBERS = new int[] { 776, 777, 778, 779,780,781 };
+// TESTS_NUMBERS = new int[] { 783 };
// TESTS_RANGE = new int[] { 734, -1 };
}
public static Test suite() {
@@ -12861,4 +12861,22 @@
"}"
);
}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=359646
+public void test783() throws Exception {
+ this.formatterPrefs = null;
+ String source =
+ "public class X {public static void main(String[] args) {\n" +
+ " long x = 0x8000000000000000L;\n" +
+ " System.out.println(x);\n" +
+ " }\n" +
+ "}";
+ formatSource(source,
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " long x = 0x8000000000000000L;\n" +
+ " System.out.println(x);\n" +
+ " }\n" +
+ "}"
+ );
+}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java
index 4166cb2..5f0c5bf 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java
@@ -249,6 +249,7 @@
suite.addTest(new ClasspathTests("testInvalidClasspath2"));
suite.addTest(new ClasspathTests("testInvalidExternalClassFolder"));
suite.addTest(new ClasspathTests("testInvalidExternalJar"));
+ suite.addTest(new ClasspathTests("testTransitionFromInvalidToValidJar"));
suite.addTest(new ClasspathTests("testInvalidInternalJar1"));
suite.addTest(new ClasspathTests("testInvalidInternalJar2"));
suite.addTest(new ClasspathTests("testInvalidSourceFolder"));
@@ -334,6 +335,8 @@
suite.addTest(new ClasspathTests("testBug321170"));
suite.addTest(new ClasspathTests("testBug229042"));
suite.addTest(new ClasspathTests("testBug274737"));
+ suite.addTest(new ClasspathTests("testBug357425"));
+ suite.addTest(new ClasspathTests("testBug287164"));
return suite;
}
public void setUpSuite() throws Exception {
@@ -2020,6 +2023,7 @@
public void testClasspathValidation22() throws CoreException {
try {
IJavaProject proj = this.createJavaProject("P", new String[] {}, "");
+ proj.setOption(JavaCore.CORE_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE, JavaCore.ERROR);
IClasspathEntry[] originalCP = proj.getRawClasspath();
IClasspathEntry[] newCP = new IClasspathEntry[originalCP.length+2];
@@ -2045,6 +2049,7 @@
public void testClasspathValidation23() throws CoreException {
try {
IJavaProject proj = this.createJavaProject("P", new String[] {}, "");
+ proj.setOption(JavaCore.CORE_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE, JavaCore.IGNORE);
IClasspathEntry[] originalCP = proj.getRawClasspath();
IClasspathEntry[] newCP = new IClasspathEntry[originalCP.length+2];
@@ -4201,6 +4206,41 @@
}
}
/*
+ * Ensures that validateClasspathEntry() sees a transition from an invalid/missing jar to a valid jar.
+ */
+public void testTransitionFromInvalidToValidJar() throws CoreException, IOException {
+ String transitioningJarName = "transitioningJar.jar";
+ String transitioningJar = getExternalPath() + transitioningJarName;
+ String nonExistingJar = getExternalPath() + "nonExisting.jar";
+ IClasspathEntry transitioningEntry = JavaCore.newLibraryEntry(new Path(transitioningJar), null, null);
+ IClasspathEntry nonExistingEntry = JavaCore.newLibraryEntry(new Path(nonExistingJar), null, null);
+
+ try {
+ IJavaProject proj = createJavaProject("P", new String[] {}, new String[] {transitioningJar, nonExistingJar}, "bin");
+
+ IJavaModelStatus status1 = ClasspathEntry.validateClasspathEntry(proj, transitioningEntry, false, false);
+ IJavaModelStatus status2 = ClasspathEntry.validateClasspathEntry(proj, nonExistingEntry, false, false);
+ assertFalse("Non-existing jar should be invalid", status1.isOK());
+ assertFalse("Non-existing jar should be invalid", status2.isOK());
+
+ Util.createJar(
+ new String[0],
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "Manifest-Version: 1.0\n"
+ },
+ transitioningJar,
+ JavaCore.VERSION_1_4);
+ status1 = ClasspathEntry.validateClasspathEntry(proj, transitioningEntry, false, false);
+ status2 = ClasspathEntry.validateClasspathEntry(proj, nonExistingEntry, false, false);
+ assertTrue("Existing jar should be valid", status1.isOK());
+ assertFalse("Non-existing jar should be invalid", status2.isOK());
+ } finally {
+ deleteExternalResource(transitioningJarName);
+ deleteProject("P");
+ }
+}
+/*
* Ensures that a non existing internal jar cannot be put on the classpath.
*/
public void testInvalidInternalJar1() throws CoreException {
@@ -7190,4 +7230,112 @@
}
}
+/*
+ * Ensures that the correct delta is reported when changing the Class-Path: clause
+ * of an external jar from not containing a chained jar to containing a chained jar.
+ * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=357425)
+ */
+public void testBug357425() throws Exception {
+ try {
+ IJavaProject p = createJavaProject("P");
+ addExternalLibrary(p, getExternalResourcePath("lib357425_a.jar"), new String[0],
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "Manifest-Version: 1.0\n"
+ },
+ JavaCore.VERSION_1_4);
+ refreshExternalArchives(p);
+
+ startDeltas();
+ org.eclipse.jdt.core.tests.util.Util.createJar(new String[0],
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "Manifest-Version: 1.0\n" +
+ "Class-Path: lib357425_b.jar\n",
+ },
+ getExternalResourcePath("lib357425_a.jar"),
+ JavaCore.VERSION_1_4);
+ createExternalFile("lib357425_b.jar", "");
+
+ refreshExternalArchives(p);
+ assertDeltas(
+ "Unexpected delta",
+ "P[*]: {CHILDREN | RESOLVED CLASSPATH CHANGED}\n" +
+ " "+ getExternalPath() + "lib357425_a.jar[*]: {CONTENT | REORDERED | ARCHIVE CONTENT CHANGED}\n" +
+ " "+ getExternalPath() + "lib357425_b.jar[+]: {}"
+ );
+ } finally {
+ stopDeltas();
+ deleteProject("P");
+ deleteExternalResource("lib357425_a.jar");
+ deleteExternalResource("lib357425_b.jar");
+ }
+}
+/**
+ * @bug287164: Report build path error if source folder has other source folder as output folder
+ *
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=287164"
+ */
+public void testBug287164() throws CoreException {
+ try {
+ IJavaProject proj = this.createJavaProject("P", new String[] {}, "");
+
+ // Test that with the option set to IGNORE, the Java model status returns OK
+ proj.setOption(JavaCore.CORE_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE, JavaCore.IGNORE);
+ IClasspathEntry[] originalCP = proj.getRawClasspath();
+
+ IClasspathEntry[] newCP = new IClasspathEntry[originalCP.length+2];
+ System.arraycopy(originalCP, 0, newCP, 0, originalCP.length);
+ newCP[originalCP.length] = JavaCore.newSourceEntry(new Path("/P/src"), new IPath[0], new Path("/P/src2"));
+ newCP[originalCP.length+1] = JavaCore.newSourceEntry(new Path("/P/src2"), new IPath[0], new Path("/P/src"));
+
+ createFolder("/P/src");
+ createFolder("/P/src2");
+
+ IJavaModelStatus status = JavaConventions.validateClasspath(proj, newCP, proj.getOutputLocation());
+ assertTrue(status.isOK());
+ assertStatus(
+ "OK",
+ status);
+
+ proj.setRawClasspath(newCP, null);
+ assertMarkers("Unexpected markers", "", proj);
+
+ // Test that with the option set to WARNING, status.isOK() returns true
+ proj.setOption(JavaCore.CORE_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE, JavaCore.WARNING);
+
+ status = JavaConventions.validateClasspath(proj, newCP, proj.getOutputLocation());
+ assertTrue(status.isOK());
+ assertStatus(
+ "Source folder \'src\' in project \'P\' cannot output to distinct source folder \'src2\'",
+ status);
+
+ assertMarkers("Unexpected markers",
+ "Source folder \'src\' in project \'P\' cannot output to distinct source folder \'src2\'", proj);
+
+ // Test that with the option set to WARNING and the presence of a more severe error scenario, the error status
+ // is returned
+ IClasspathEntry[] newCP2 = new IClasspathEntry[newCP.length+1];
+ System.arraycopy(newCP, 0, newCP2, 0, newCP.length-1);
+ newCP2[newCP.length] = JavaCore.newLibraryEntry(new Path("/P/lib2"), null, null);
+ newCP2[newCP.length-1] = JavaCore.newSourceEntry(new Path("/P/src2"), new IPath[0], new Path("/P/lib2"));
+
+ status = JavaConventions.validateClasspath(proj, newCP2, proj.getOutputLocation());
+ assertFalse(status.isOK());
+ assertStatus(
+ "Source folder \'src2\' in project 'P' cannot output to library \'lib2\'",
+ status);
+
+ proj.setOption(JavaCore.CORE_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE, JavaCore.ERROR);
+
+ status = JavaConventions.validateClasspath(proj, newCP, proj.getOutputLocation());
+ assertStatus(
+ "Source folder \'src\' in project \'P\' cannot output to distinct source folder \'src2\'",
+ status);
+
+ } finally {
+ this.deleteProject("P");
+ }
+}
+
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java
index 6357803..a7388ab 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java
@@ -37,7 +37,7 @@
super(name);
}
static {
-// TESTS_NAMES = new String[] { "testAddExternalLibFolder6" };
+// TESTS_NAMES = new String[] { "testBug360164" };
}
public static Test suite() {
TestSuite suite = (TestSuite) buildModelTestSuite(JavaProjectTests.class);
@@ -2389,4 +2389,102 @@
deleteProject("JavaProjectTestsInvalidProject");
}
}
+// Bug 360164 - Compile error in XSDImpl
+// test that we can tolerate if a 1.4 project refers to an enum inside a library.
+public void testBug360164() throws IOException, CoreException {
+ String libPath = getWorkspacePath()+"JavaProjectTests/bin/bug360164.jar";
+ try {
+ this.createJavaProject("P", new String[] {"src"}, new String[] {"JCL_LIB", libPath}, "bin", JavaCore.VERSION_1_4);
+ IFile file = createFile("/P/src/X.java",
+ "import p360164.Provider;\n" +
+ "import p360164.MyEnum;\n" +
+ "public class X {\n" +
+ " int foo(Provider p) {\n" +
+ " MyEnum e = p.getE();\n" +
+ " switch (e.getValue()) {\n" +
+ " case MyEnum.ONE_COMPAT: return 1;\n" +
+ " case MyEnum.TWO_COMPAT: return 2;\n" +
+ " }\n" +
+ " return 0;\n" +
+ " }\n" +
+ "}"
+ );
+ ICompilationUnit unit = (ICompilationUnit)JavaCore.create(file);
+ ProblemRequestor problemRequestor = new ProblemRequestor();
+ WorkingCopyOwner owner = newWorkingCopyOwner(problemRequestor);
+ unit.getWorkingCopy(owner, null);
+ assertProblems("Unexpected problems",
+ "----------\n" +
+ "----------\n",
+ problemRequestor);
+ } finally {
+ this.deleteProject("P");
+ }
+}
+// Bug 360164 - Compile error in XSDImpl
+// test that we still report the missing superclass when resolving non-local methods
+public void testBug360164a() throws IOException, CoreException {
+ String libPath = getWorkspacePath()+"JavaProjectTests/bin/bug360164.jar";
+ try {
+ this.createJavaProject("P", new String[] {"src"}, new String[] {"JCL_LIB", libPath}, "bin", JavaCore.VERSION_1_4);
+ IFile file = createFile("/P/src/X.java",
+ "import p360164.Provider;\n" +
+ "import p360164.MyEnum;\n" +
+ "public class X {\n" +
+ " String foo(Provider p) {\n" +
+ " MyEnum e = p.getE();\n" +
+ " return e.toString();\n" +
+ " }\n" +
+ "}"
+ );
+ ICompilationUnit unit = (ICompilationUnit)JavaCore.create(file);
+ ProblemRequestor problemRequestor = new ProblemRequestor();
+ WorkingCopyOwner owner = newWorkingCopyOwner(problemRequestor);
+ unit.getWorkingCopy(owner, null);
+ assertProblems("Unexpected problems",
+ "----------\n" +
+ "1. ERROR in /P/src/X.java\n" +
+ "The type java.lang.Enum cannot be resolved. It is indirectly referenced from required .class files\n" +
+ "----------\n",
+ problemRequestor);
+ } finally {
+ this.deleteProject("P");
+ }
+}
+// Bug 360317 - [compiler] report switch over enum in 1.4- mode
+public void testBug360317() throws IOException, CoreException {
+ // use the setup from testBug360164():
+ String libPath = getWorkspacePath()+"JavaProjectTests/bin/bug360164.jar";
+ try {
+ this.createJavaProject("P", new String[] {"src"}, new String[] {"JCL_LIB", libPath}, "bin", JavaCore.VERSION_1_4);
+ String sourceX = "import p360164.Provider;\n" +
+ "import p360164.MyEnum;\n" +
+ "public class X {\n" +
+ " int foo(Provider p) {\n" +
+ " MyEnum e = p.getE();\n" +
+ " switch (e) {\n" +
+ " case ONE: return 1;\n" +
+ " case TWO: return 2;\n" +
+ " }\n" +
+ " return 0;\n" +
+ " }\n" +
+ "}";
+ IFile file = createFile("/P/src/X.java", sourceX);
+ ICompilationUnit unit = (ICompilationUnit)JavaCore.create(file);
+ ProblemRequestor problemRequestor = new ProblemRequestor();
+ problemRequestor.initialize(sourceX.toCharArray());
+ WorkingCopyOwner owner = newWorkingCopyOwner(problemRequestor);
+ unit.getWorkingCopy(owner, null);
+ assertProblems("Unexpected problems",
+ "----------\n" +
+ "1. ERROR in /P/src/X.java (at line 6)\n" +
+ " switch (e) {\n" +
+ " ^\n" +
+ "Cannot switch on an enum value for source level below 1.5. Only convertible int values are permitted\n" +
+ "----------\n",
+ problemRequestor);
+ } finally {
+ this.deleteProject("P");
+ }
+}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java
index 6f41895..2b21dc7 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java
@@ -712,6 +712,7 @@
suite.addTest(new JavaSearchBugsTests("testBug349683"));
suite.addTest(new JavaSearchBugsTests("testBug345807"));
suite.addTest(new JavaSearchBugsTests("testBug355605"));
+ suite.addTest(new JavaSearchBugsTests("testBug241834"));
return suite;
}
class TestCollector extends JavaSearchResultCollector {
@@ -13760,4 +13761,30 @@
deleteProject("P");
}
}
+/**
+ * @bug 241834: [search] ClassCastException during move class refactoring
+ * @test that search for declarations of referenced types doesn't cause CCE
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=241834"
+ */
+public void testBug241834() throws CoreException {
+ try {
+ IJavaProject project = createJavaProject("P");
+ project.setOption(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED);
+ createFolder("/P/pkg");
+ createFile("/P/pkg/Foo.java",
+ "package pkg;\n"+
+ "/**\n" +
+ " * {@link missing.Foo}\n" +
+ " */\n" +
+ "public class Foo {\n" +
+ "}\n");
+ waitUntilIndexesReady();
+ IType type = getCompilationUnit("/P/pkg/Foo.java").getType("Foo");
+ searchDeclarationsOfReferencedTypes(type, this.resultCollector);
+ assertSearchResults("");
+ } finally {
+ deleteProject("P");
+
+ }
+}
}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java
index 5ea8bc1..429dce8 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java
@@ -15,6 +15,7 @@
import junit.framework.TestSuite;
import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaCore;
@@ -5694,7 +5695,157 @@
assertEqualString(preview, buf.toString());
}
+
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=350285
+ // Test that converting a multi catch into a normal catch using complete block copy doesn't change indentation
+ public void testTryStatementWithMultiCatch1() throws Exception {
+ createProject("P_17", JavaCore.VERSION_1_7);
+ IPackageFragmentRoot currentSourceFolder = getPackageFragmentRoot("P_17", "src");
+ try {
+ IPackageFragment pack1= currentSourceFolder.createPackageFragment("test1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public class E {\n");
+ buf.append(" public void foo(int i) {\n");
+ buf.append(" try {\n");
+ buf.append(" System.out.println(\"foo\");\n");
+ buf.append(" } catch (IllegalArgumentException | NullPointerException exe) {\n");
+ buf.append(" System.out.println(exe);\n");
+ buf.append(" }\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null);
+ CompilationUnit astRoot= createAST(AST.JLS4, cu, false);
+ AST ast= astRoot.getAST();
+ ASTRewrite rewrite= ASTRewrite.create(ast);
+
+ assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0);
+ TypeDeclaration type= findTypeDeclaration(astRoot, "E");
+ MethodDeclaration methodDecl= findMethodDeclaration(type, "foo");
+ Block block= methodDecl.getBody();
+ List blockStatements= block.statements();
+ assertTrue("Number of statements not 1", blockStatements.size() == 1);
+ { // convert multicatch to normal catch blocks
+ TryStatement tryStatement= (TryStatement) blockStatements.get(0);
+ List catchClauses= tryStatement.catchClauses();
+ assertTrue("Number of catch clauses not 1", catchClauses.size() == 1);
+ CatchClause catchClause = (CatchClause) catchClauses.get(0);
+
+ SingleVariableDeclaration singleVariableDeclaration= catchClause.getException();
+ UnionType unionType = (UnionType) singleVariableDeclaration.getType();
+ List types = unionType.types();
+ assertTrue("Number of union types", types.size() == 2);
+ for (int i= types.size() - 1; i >= 0; i--) {
+ Type type2= (Type)types.get(i);
+ CatchClause newCatchClause= ast.newCatchClause();
+ SingleVariableDeclaration newSingleVariableDeclaration= ast.newSingleVariableDeclaration();
+ newSingleVariableDeclaration.setType((Type) rewrite.createCopyTarget(type2));
+ newSingleVariableDeclaration.setName((SimpleName) rewrite.createCopyTarget(singleVariableDeclaration.getName()));
+ newCatchClause.setException(newSingleVariableDeclaration);
+ newCatchClause.setBody((Block) rewrite.createCopyTarget(catchClause.getBody()));
+ rewrite.getListRewrite(tryStatement, TryStatement.CATCH_CLAUSES_PROPERTY).insertAfter(newCatchClause, catchClause, null);
+ }
+ rewrite.remove(catchClause, null);
+ }
+ String preview= evaluateRewrite(cu, rewrite);
+
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public class E {\n");
+ buf.append(" public void foo(int i) {\n");
+ buf.append(" try {\n");
+ buf.append(" System.out.println(\"foo\");\n");
+ buf.append(" } catch (IllegalArgumentException exe) {\n");
+ buf.append(" System.out.println(exe);\n");
+ buf.append(" } catch (NullPointerException exe) {\n");
+ buf.append(" System.out.println(exe);\n");
+ buf.append(" }\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ assertEqualString(preview, buf.toString());
+ } finally {
+ deleteProject("P_17");
+ }
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=350285
+ // similar to testTryStatementWithMultiCatch1() but has a different brace position
+ public void testTryStatementWithMultiCatch2() throws Exception {
+ IJavaProject project = createProject("P_17", JavaCore.VERSION_1_7);
+ project.setOption(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_BLOCK, DefaultCodeFormatterConstants.NEXT_LINE);
+ IPackageFragmentRoot currentSourceFolder = getPackageFragmentRoot("P_17", "src");
+ try {
+ IPackageFragment pack1= currentSourceFolder.createPackageFragment("test1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public class E {\n");
+ buf.append(" public void foo(int i) {\n");
+ buf.append(" try {\n");
+ buf.append(" System.out.println(\"foo\");\n");
+ buf.append(" } catch (IllegalArgumentException | NullPointerException exe)\n");
+ buf.append(" {\n");
+ buf.append(" System.out.println(exe);\n");
+ buf.append(" }\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(AST.JLS4, cu, false);
+ AST ast= astRoot.getAST();
+ ASTRewrite rewrite= ASTRewrite.create(ast);
+
+ assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0);
+ TypeDeclaration type= findTypeDeclaration(astRoot, "E");
+ MethodDeclaration methodDecl= findMethodDeclaration(type, "foo");
+ Block block= methodDecl.getBody();
+ List blockStatements= block.statements();
+ assertTrue("Number of statements not 1", blockStatements.size() == 1);
+ { // convert multicatch to normal catch blocks
+ TryStatement tryStatement= (TryStatement) blockStatements.get(0);
+ List catchClauses= tryStatement.catchClauses();
+ assertTrue("Number of catch clauses not 1", catchClauses.size() == 1);
+ CatchClause catchClause = (CatchClause) catchClauses.get(0);
+
+ SingleVariableDeclaration singleVariableDeclaration= catchClause.getException();
+ UnionType unionType = (UnionType) singleVariableDeclaration.getType();
+ List types = unionType.types();
+ assertTrue("Number of union types", types.size() == 2);
+ for (int i= types.size() - 1; i >= 0; i--) {
+ Type type2= (Type)types.get(i);
+ CatchClause newCatchClause= ast.newCatchClause();
+ SingleVariableDeclaration newSingleVariableDeclaration= ast.newSingleVariableDeclaration();
+ newSingleVariableDeclaration.setType((Type) rewrite.createCopyTarget(type2));
+ newSingleVariableDeclaration.setName((SimpleName) rewrite.createCopyTarget(singleVariableDeclaration.getName()));
+ newCatchClause.setException(newSingleVariableDeclaration);
+ newCatchClause.setBody((Block) rewrite.createCopyTarget(catchClause.getBody()));
+ rewrite.getListRewrite(tryStatement, TryStatement.CATCH_CLAUSES_PROPERTY).insertAfter(newCatchClause, catchClause, null);
+ }
+ rewrite.remove(catchClause, null);
+ }
+ String preview= evaluateRewrite(cu, rewrite);
+
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public class E {\n");
+ buf.append(" public void foo(int i) {\n");
+ buf.append(" try {\n");
+ buf.append(" System.out.println(\"foo\");\n");
+ buf.append(" } catch (IllegalArgumentException exe)\n");
+ buf.append(" {\n");
+ buf.append(" System.out.println(exe);\n");
+ buf.append(" } catch (NullPointerException exe)\n");
+ buf.append(" {\n");
+ buf.append(" System.out.println(exe);\n");
+ buf.append(" }\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ assertEqualString(preview, buf.toString());
+ } finally {
+ deleteProject("P_17");
+ }
+ }
}
diff --git a/org.eclipse.jdt.core.tests.model/test.xml b/org.eclipse.jdt.core.tests.model/test.xml
index 07b24f9..0d7d4e2 100644
--- a/org.eclipse.jdt.core.tests.model/test.xml
+++ b/org.eclipse.jdt.core.tests.model/test.xml
Binary files differ