diff options
author | Stephan Herrmann | 2022-09-06 18:07:35 +0000 |
---|---|---|
committer | Stephan Herrmann | 2022-09-06 18:07:35 +0000 |
commit | ee6a6774aa707896c918383e95462ed098f85d02 (patch) | |
tree | 1cbe42c628610614d9bef87169b1ccc4bd7ddaa5 /org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt | |
parent | c5cd4952e8aa14027e66e7f2a912c1cd6c7fceca (diff) | |
download | org.eclipse.objectteams-ee6a6774aa707896c918383e95462ed098f85d02.tar.gz org.eclipse.objectteams-ee6a6774aa707896c918383e95462ed098f85d02.tar.xz org.eclipse.objectteams-ee6a6774aa707896c918383e95462ed098f85d02.zip |
update jdt.core to S4_25_0_RC2
Diffstat (limited to 'org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt')
6 files changed, 298 insertions, 3 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTStructuralPropertyTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTStructuralPropertyTest.java index 1274f910b..118decacf 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTStructuralPropertyTest.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTStructuralPropertyTest.java @@ -447,9 +447,9 @@ public class ASTStructuralPropertyTest extends org.eclipse.jdt.core.tests.junit. } // {ObjectTeams: adapted for OT specific ASTNodes /* orig: - assertEquals("Wrong last known type", 111, hi); // last known one + assertEquals("Wrong last known type", 112, hi); // last known one :giro */ - assertEquals("Wrong last known type", 127, hi); // last known one + assertEquals("Wrong last known type", 128, hi); // last known one // jwl} assertEquals("Wrong number of distinct types", hi, classes.size()); // all classes are distinct } diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java index 5c47af14a..20e7ec047 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java @@ -9510,6 +9510,7 @@ public class ASTTest extends org.eclipse.jdt.core.tests.junit.extension.TestCase ASTNode.CASE_DEFAULT_EXPRESSION, ASTNode.TAG_PROPERTY, ASTNode.JAVADOC_REGION, + ASTNode.JAVADOC_TEXT_ELEMENT, //{ObjectTeams: ASTNode.METHOD_SPEC, ASTNode.CALLIN_MAPPING_DECLARATION, diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations17Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations17Test.java index f5e77329b..7a346d39b 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations17Test.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations17Test.java @@ -710,6 +710,157 @@ public class ExternalAnnotations17Test extends ExternalAnnotations18Test { Platform.removeLogListener(listener); } } + // wrong selector + public void testBogusAnnotationFile3() throws Exception { + LogListener listener = new LogListener(); + try { + Platform.addLogListener(listener); + + myCreateJavaProject("TestLibs"); + String lib1Content = + "package libs;\n" + + "\n" + + "public interface Lib1<T> {\n" + + " public Lib1<T> getLib();\n" + + "}\n"; + addLibraryWithExternalAnnotations(this.project, "lib1.jar", "annots", new String[] { + "/UnannotatedLib/libs/Lib1.java", + lib1Content + }, null); + createFileInProject("annots/libs", "Lib1.eea", + "class libs/Lib1\n" + + "\n" + + "()V\n" + + "foo\n"); + + // type check sources: + IPackageFragment fragment = this.project.getPackageFragmentRoots()[0].createPackageFragment("tests", true, null); + ICompilationUnit cu = fragment.createCompilationUnit("Test1.java", + "package tests;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "import libs.Lib1;\n" + + "\n" + + "public class Test1 {\n" + + " @NonNull Lib1<String> test0(Lib1<String> stringLib) {\n" + + " return stringLib.getLib();\n" + + " }\n" + + "}\n", + true, new NullProgressMonitor()).getWorkingCopy(new NullProgressMonitor()); + CompilationUnit reconciled = cu.reconcile(getJLS8(), true, null, new NullProgressMonitor()); + IProblem[] problems = reconciled.getProblems(); + assertProblems(problems, new String[] { + "Pb(912) Null type safety: The expression of type 'Lib1<String>' needs unchecked conversion to conform to '@NonNull Lib1<String>'", + }, new int[] { 8 }); + + assertEquals("number of log entries", 1, listener.loggedStatus.size()); + final Throwable exception = listener.loggedStatus.get(0).getException(); + assertEquals("logged message", "Illegal selector in external annotation file for libs/Lib1 at line 3: \"()V\"", exception.getMessage()); + } finally { + Platform.removeLogListener(listener); + } + } + // invalid raw signature + public void testBogusAnnotationFile4() throws Exception { + LogListener listener = new LogListener(); + try { + Platform.addLogListener(listener); + + myCreateJavaProject("TestLibs"); + String lib1Content = + "package libs;\n" + + "\n" + + "public interface Lib1<T> {\n" + + " public Lib1<T> getLib();\n" + + "}\n"; + addLibraryWithExternalAnnotations(this.project, "lib1.jar", "annots", new String[] { + "/UnannotatedLib/libs/Lib1.java", + lib1Content + }, null); + createFileInProject("annots/libs", "Lib1.eea", + "class libs/Lib1\n" + + "\n" + + "foo\n" + + " wrong()\n"); + + // type check sources: + IPackageFragment fragment = this.project.getPackageFragmentRoots()[0].createPackageFragment("tests", true, null); + ICompilationUnit cu = fragment.createCompilationUnit("Test1.java", + "package tests;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "import libs.Lib1;\n" + + "\n" + + "public class Test1 {\n" + + " @NonNull Lib1<String> test0(Lib1<String> stringLib) {\n" + + " return stringLib.getLib();\n" + + " }\n" + + "}\n", + true, new NullProgressMonitor()).getWorkingCopy(new NullProgressMonitor()); + CompilationUnit reconciled = cu.reconcile(getJLS8(), true, null, new NullProgressMonitor()); + IProblem[] problems = reconciled.getProblems(); + assertProblems(problems, new String[] { + "Pb(912) Null type safety: The expression of type 'Lib1<String>' needs unchecked conversion to conform to '@NonNull Lib1<String>'", + }, new int[] { 8 }); + + assertEquals("number of log entries", 1, listener.loggedStatus.size()); + final Throwable exception = listener.loggedStatus.get(0).getException(); + assertEquals("logged message", "Illegal format in external annotation file for libs/Lib1 at line 4: invalid signature \"wrong()\"", exception.getMessage()); + } finally { + Platform.removeLogListener(listener); + } + } + // invalid annotated signature + public void testBogusAnnotationFile5() throws Exception { + LogListener listener = new LogListener(); + try { + Platform.addLogListener(listener); + + myCreateJavaProject("TestLibs"); + String lib1Content = + "package libs;\n" + + "\n" + + "public interface Lib1<T> {\n" + + " public Lib1<T> getLib();\n" + + "}\n"; + addLibraryWithExternalAnnotations(this.project, "lib1.jar", "annots", new String[] { + "/UnannotatedLib/libs/Lib1.java", + lib1Content + }, null); + createFileInProject("annots/libs", "Lib1.eea", + "class libs/Lib1\n" + + "\n" + + "foo\n" + + " ()V\n" + + " wrong()\n"); + + // type check sources: + IPackageFragment fragment = this.project.getPackageFragmentRoots()[0].createPackageFragment("tests", true, null); + ICompilationUnit cu = fragment.createCompilationUnit("Test1.java", + "package tests;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "import libs.Lib1;\n" + + "\n" + + "public class Test1 {\n" + + " @NonNull Lib1<String> test0(Lib1<String> stringLib) {\n" + + " return stringLib.getLib();\n" + + " }\n" + + "}\n", + true, new NullProgressMonitor()).getWorkingCopy(new NullProgressMonitor()); + CompilationUnit reconciled = cu.reconcile(getJLS8(), true, null, new NullProgressMonitor()); + IProblem[] problems = reconciled.getProblems(); + assertProblems(problems, new String[] { + "Pb(912) Null type safety: The expression of type 'Lib1<String>' needs unchecked conversion to conform to '@NonNull Lib1<String>'", + }, new int[] { 8 }); + + assertEquals("number of log entries", 1, listener.loggedStatus.size()); + final Throwable exception = listener.loggedStatus.get(0).getException(); + assertEquals("logged message", "Illegal format in external annotation file for libs/Lib1 at line 5: invalid signature \"wrong()\"", exception.getMessage()); + } finally { + Platform.removeLogListener(listener); + } + } public void testBug565246() throws Exception { myCreateJavaProject("TestForloop"); diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations18Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations18Test.java index 6b293f570..c43c1ff8b 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations18Test.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations18Test.java @@ -2625,6 +2625,55 @@ public class ExternalAnnotations18Test extends ModifyingResourceTests { CompilationUnit reconciled = cu.reconcile(getJSL9(), true, null, new NullProgressMonitor()); assertNoProblems(reconciled.getProblems()); } + public void testBug513880() throws Exception { + myCreateJavaProject("TestLibs"); + String lib1Content = + "package libs;\n" + + "import java.util.List;\n" + + "public abstract class Collections {\n" + + " public void foo() {}\n" + + " public static final <T> List<T> emptyList() {\n" + + " return null;\n" + + " }\n" + + "}\n"; + addLibraryWithExternalAnnotations(this.project, "lib1.jar", "annots", new String[] { + "/UnannotatedLib/libs/Collections.java", + lib1Content + }, null); + createFileInProject("annots/libs", "Collections.eea", + "class libs/Collections\n" + + "\n" + + "foo\n" + + " ()V\n" + // 2-line entry without separating empty line: ignore + "foo\n" + + "()V\n" + // 2-line entry without leading space on signature lines: ignore + "emptyList\n" + + " <T:Ljava/lang/Object;>()Ljava/util/List<TT;>;\n" + + " <T:Ljava/lang/Object;>()L1java/util/List<T1T;>;\n" + + "\n"); + + // type check sources: + IPackageFragment fragment = this.project.getPackageFragmentRoots()[0].createPackageFragment("tests", true, null); + ICompilationUnit cu = fragment.createCompilationUnit("Test1.java", + "package tests;\n" + + "import libs.Collections;\n" + + "import java.util.List;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Test1 {\n" + + " List<@NonNull String> strings;\n" + + "\n" + + " public Test1() {\n" + + " strings = Collections.emptyList(); // <<<<< WARNING\n" + + " }\n" + + "}\n", + true, new NullProgressMonitor()).getWorkingCopy(new NullProgressMonitor()); + CompilationUnit reconciled = cu.reconcile(getJSL9(), true, null, new NullProgressMonitor()); + assertNoProblems(reconciled.getProblems()); + } // Bug 522377 - [null] String.format(""...) shows warning public void testVargs() throws CoreException, IOException { diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java index a05dbd63f..9ee38b019 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016, 2020 IBM Corporation and others. + * Copyright (c) 2016, 2022 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -8988,6 +8988,34 @@ public class ModuleBuilderTests extends ModifyingResourceTests { deleteProject("ztest"); } } + public void testIssue23() throws CoreException { + IJavaProject p1 = createJava9Project("Issue23", "18"); + Map<String, String> options = new HashMap<>(); + // Make sure the new options map doesn't reset. + options.put(CompilerOptions.OPTION_Compliance, "16.8"); + options.put(CompilerOptions.OPTION_Source, "16.8"); + options.put(CompilerOptions.OPTION_TargetPlatform, "16.8"); + options.put(CompilerOptions.OPTION_Release, "enabled"); + p1.setOptions(options); + try { + createFolder("/Issue23/src/p1"); + createFile("/Issue23/src/p1/X.java", + "package p1;\n" + + "public class X {\n" + + " public java.util.stream.Stream<String> emptyStream() {\n" + + " return null;\n" + + " }\n" + + "}"); + + waitForManualRefresh(); + waitForAutoBuild(); + p1.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null); + IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE); + assertMarkers("Unexpected markers", "The project was not built due to \"Invalid value for --release argument:16.8\". Fix the problem, then try refreshing this project and building it since it may be inconsistent", markers); + } finally { + deleteProject(p1); + } + } protected void assertNoErrors() throws CoreException { for (IProject p : getWorkspace().getRoot().getProjects()) { int maxSeverity = p.findMaxProblemSeverity(null, true, IResource.DEPTH_INFINITE); diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java index 78349a71c..5268a775c 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java @@ -15,6 +15,8 @@ *******************************************************************************/ package org.eclipse.jdt.core.tests.model; +import static org.junit.Assert.assertNotEquals; + import java.io.File; import java.io.IOException; import java.util.Arrays; @@ -3679,4 +3681,68 @@ public void testIndexQualificationBinaryNestedSubTypes_SearchForNestedSuperType( } } +/** + * @bug GitHub 269: Wrong type hierarchy computed for types with cyclic static imports. + * @see "https://github.com/eclipse-jdt/eclipse.jdt.core/issues/269" + */ +public void testBugGh269() throws Exception { + String testProjectName = "TypeHierarchyBugGh269"; + IJavaProject projectQ = createJavaProject(testProjectName, new String[] {"src"}, new String[] {"JCL11_LIB"}, "bin", "11"); + try { + addClasspathEntry(projectQ, getJRTLibraryEntry()); + waitUntilIndexesReady(); + createFolder("/TypeHierarchyBugGh269/src/p269"); + createFolder("/TypeHierarchyBugGh269/src/p269/internal"); + createFile( + "/TypeHierarchyBugGh269/src/p269/Gh269TestInterface.java", + "package p269;\n" + + "public interface Gh269TestInterface {\n" + + " void foo();\n" + + "}" + ); + String subtypeContents = + "package p269.internal;\n" + + "import static p269.internal.Gh269SomeClass.*;\n" + + "import p269.Gh269TestInterface;\n" + + "public class Gh269TestImplementation implements Gh269TestInterface {\n" + + " @Override public void foo() { someStaticMethod(); }\n" + + " public static void someOtherStaticMethod() { System.out.println(\"hello world\"); }\n" + + "}"; + createFile( + "/TypeHierarchyBugGh269/src/p269/internal/Gh269TestImplementation.java", + subtypeContents + ); + createFile( + "/TypeHierarchyBugGh269/src/p269/internal/Gh269SomeClass.java", + "package p269.internal;\n" + + "import static p269.internal.Gh269TestImplementation.*;\n" + + "public class Gh269SomeClass implements Comparable<Gh269SomeClass> {\n" + + " public static void someStaticMethod() { someOtherStaticMethod(); }\n" + + " @Override public int compareTo(Gh269SomeClass o) { return 0; }\n" + + "}" + ); + waitUntilIndexesReady(); + + int indexStart = subtypeContents.indexOf("implements Gh269TestInterface"); + assertNotEquals("Failed to find implements statement", -1, indexStart); + indexStart += "implements ".length(); + int length = "Gh269TestInterface".length(); + + ICompilationUnit compilationUnit = getCompilationUnit("/TypeHierarchyBugGh269/src/p269/internal/Gh269TestImplementation.java"); + IJavaElement[] selectedTypes = compilationUnit.codeSelect(indexStart, length); + assertEquals("Expected only 1 type to be selected but got: " + Arrays.toString(selectedTypes), 1, selectedTypes.length); + IType type = (IType) selectedTypes[0]; + assertTrue("Type should exist!", type.exists()); + ITypeHierarchy hierarchy = type.newTypeHierarchy(new NullProgressMonitor()); + assertHierarchyEquals( + "Focus: Gh269TestInterface [in Gh269TestInterface.java [in p269 [in src [in TypeHierarchyBugGh269]]]]\n" + + "Super types:\n" + + "Sub types:\n" + + " Gh269TestImplementation [in Gh269TestImplementation.java [in p269.internal [in src [in TypeHierarchyBugGh269]]]]\n", + hierarchy); + } finally { + deleteProject(testProjectName); + } +} + } |