diff options
author | Stephan Herrmann | 2022-12-29 09:22:23 +0000 |
---|---|---|
committer | Stephan Herrmann | 2022-12-29 09:22:23 +0000 |
commit | e6f75b57b986d4a6349e78876a9aa7fa084b1103 (patch) | |
tree | c92a00969b99903b990d9f60f75994e020d173b6 | |
parent | 9e3ac7e3cbb978601579e4d5052d10968b1ec570 (diff) | |
download | org.eclipse.objectteams-e6f75b57b986d4a6349e78876a9aa7fa084b1103.tar.gz org.eclipse.objectteams-e6f75b57b986d4a6349e78876a9aa7fa084b1103.tar.xz org.eclipse.objectteams-e6f75b57b986d4a6349e78876a9aa7fa084b1103.zip |
update jdt.core to I20221206-1800 for #592
9 files changed, 136 insertions, 10 deletions
diff --git a/org.eclipse.jdt.core.compiler.batch/.settings/.api_filters b/org.eclipse.jdt.core.compiler.batch/.settings/.api_filters index a69e00e6a..4e4557119 100644 --- a/org.eclipse.jdt.core.compiler.batch/.settings/.api_filters +++ b/org.eclipse.jdt.core.compiler.batch/.settings/.api_filters @@ -16,6 +16,14 @@ </message_arguments> </filter> </resource> + <resource path="src/org/eclipse/jdt/core/JDTCompilerAdapter.java" type="org.eclipse.jdt.core.JDTCompilerAdapter"> + <filter comment="See eclipse-pde/eclipse.pde#419 issue" id="305365105"> + <message_arguments> + <message_argument value="org.eclipse.jdt.core.JDTCompilerAdapter"/> + <message_argument value="org.eclipse.jdt.core.compiler.batch_3.33.0"/> + </message_arguments> + </filter> + </resource> <resource path="src/org/eclipse/jdt/core/compiler/batch/BatchCompiler.java" type="org.eclipse.jdt.core.compiler.batch.BatchCompiler"> <filter id="1108344834"> <message_arguments> diff --git a/org.eclipse.jdt.core.compiler.batch/META-INF/MANIFEST.MF b/org.eclipse.jdt.core.compiler.batch/META-INF/MANIFEST.MF index efab1a206..39fb4d14e 100644 --- a/org.eclipse.jdt.core.compiler.batch/META-INF/MANIFEST.MF +++ b/org.eclipse.jdt.core.compiler.batch/META-INF/MANIFEST.MF @@ -10,7 +10,7 @@ Automatic-Module-Name: org.eclipse.jdt.core.compiler.batch Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-11 Require-Bundle: org.eclipse.jdt.annotation;bundle-version="[2.0.0,3.0.0)";resolution:=optional;visibility:=reexport -Export-Package: org.eclipse.jdt.core, +Export-Package: META-INF.services, org.eclipse.jdt.core.compiler, org.eclipse.jdt.core.compiler.batch, org.eclipse.jdt.internal.antadapter;x-friends:="org.eclipse.jdt.core", @@ -45,5 +45,4 @@ Export-Package: org.eclipse.jdt.core, org.eclipse.objectteams.otdt.internal.core.compiler.smap;x-friends:="org.eclipse.objectteams.otdt.tests", org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.copyinheritance;x-friends:="org.eclipse.objectteams.otdt.compiler.adaptor", org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer;x-internal:=true, - org.eclipse.objectteams.otdt.internal.core.compiler.util;x-internal:=true, - META-INF.services + org.eclipse.objectteams.otdt.internal.core.compiler.util;x-internal:=true diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/core/README.md b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/core/README.md new file mode 100644 index 000000000..c5399cf3b --- /dev/null +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/core/README.md @@ -0,0 +1,74 @@ +## Notes for maintainers of the JDTCompilerAdapter (ant support) in ECJ. + +The org.eclipse.jdt.core.JDTCompilerAdapter class can be used by PDE/ant +via jdtCompilerAdapter.jar if running ant tasks from inside Eclipse or by ant +directly (by adding org.eclipse.jdt.core.compiler.batch jar to ant classpath) +if running in a separated VM without OSGI. + +### Standalone ant use + +Using JDTCompilerAdapter class from standalone ant is straightforward - the +org.eclipse.jdt.core.compiler.batch jar should be added to the ant javac classpath +in some way, like for example here: + +``` +<javac destdir="${temp.folder}/@dot.bin" failonerror="${javacFailOnError}" verbose="${javacVerbose}" + debug="${javacDebugInfo}" includeAntRuntime="no" source="${javacSource}" target="${javacTarget}" encoding="UTF-8"> + <compilerarg line="${compilerArg}" compiler="${build.compiler}"/> + <classpath refid="@dot.classpath" /> + <src path="src/" /> + <compilerarg line="-properties '.settings/org.eclipse.jdt.core.prefs'" compiler="org.eclipse.jdt.core.JDTCompilerAdapter" /> + <compilerarg line="-log '${temp.folder}/@dot.binnull'" compiler="org.eclipse.jdt.core.JDTCompilerAdapter" /> + <compilerarg line="-g -showversion -encoding UTF-8 -preserveAllLocals + -enableJavadoc -nowarn:[src-gen] -nowarn:[.src-gen] -time" compiler="org.eclipse.jdt.core.JDTCompilerAdapter" /> + <compilerclasspath> + <pathelement path="${ecjBatchCompilerJarLocation}"/> + </compilerclasspath> +</javac> +``` + +### Eclipse (OSGI) embedded ant use + +Using JDTCompilerAdapter class from ant started from OSGI container (Eclipse) is +not trivial and has few pitfalls. + +First of all, org.eclipse.jdt.core.JDTCompilerAdapter class is packaged into a dedicated +jdtCompilerAdapter.jar that is **not** part of org.eclipse.jdt.core.compiler.batch bundle! + +This jdtCompilerAdapter.jar is packaged **inside** org.eclipse.jdt.core bundle for some obscure reasons +and is extracted at runtime in org.eclipse.ant.internal.ui.datatransfer.BuildFileCreator.addInitEclipseCompiler(). + +Second most surprising point is: if the JDTCompilerAdapter code runs in OSGI environment, in order +to be properly loaded by ant which is started by PDE/ant.core bundle via +org.eclipse.ant.core.AntRunner.run(Object), the org.eclipse.jdt.core.JDTCompilerAdapter class +should **NOT** be found by classloaders of org.eclipse.jdt.core or org.eclipse.jdt.core.compiler.batch bundles! + +The reason is, that the JDTCompilerAdapter class itself needs ant classes for class initialization, +but that must be **same** ant classes loaded by org.eclipse.ant.internal.core.AntClassLoader. +If the ant classes needed by JDTCompilerAdapter class are loaded by OSGI bundle loaders, +ant engine can't use them (even if they are coming from same jar)! From Java + runtime point of view they are different because loaded by a different classloader. + +Therefore the code in org.eclipse.ant.internal.core.AntClassLoader.loadClassPlugins(String) +that goes over possible **bundle** classloaders that contribute ant tasks for Eclipse, +**must** fail to load org.eclipse.jdt.core.JDTCompilerAdapter class and return *null*! + +This is surprising at least, and has some non trivial consequences. + +The main one is: org.eclipse.jdt.core.JDTCompilerAdapter should be "not visible" +for default OSGI class loading from org.eclipse.jdt.core bundle that contributes +extra ant classpath entry jdtCompilerAdapter.jar, +and therefore org.eclipse.jdt.core package should be **not exported** in MANIFEST.MF +by org.eclipse.jdt.core.compiler.batch! + +After failing to load JDTCompilerAdapter class in AntClassLoader.loadClassPlugins(String) +the AntClassLoader code goes to the parent classloader (which is URLClassLoader) +and the parent walks over **extra** ant classpath entries contributed by plugins +via "org.eclipse.ant.core.extraClasspathEntries" extension point (see +org.eclipse.ant.core.AntCorePreferences.computeDefaultExtraClasspathEntries(List)). + +The URLClassLoader finally finds and loads JDTCompilerAdapter in jdtCompilerAdapter.jar +contributed by org.eclipse.jdt.core as an extra ant classpath entry +(with all the required ant classes found by ant own classloader)! +The URLClassLoader (AntClassLoader) should be initialized with core ant libraries at the beginning, so +it has no issues to satisfy all JDTCompilerAdapter ant dependencies.
\ No newline at end of file diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java index 294ed2700..1cee8d4c8 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java @@ -867,7 +867,7 @@ public class SwitchStatement extends Expression { this.expression.computeConversion(upperScope, TypeBinding.INT, expressionType); break checkType; } else if (compilerOptions.complianceLevel >= ClassFileConstants.JDK1_7 && expressionType.id == TypeIds.T_JavaLangString) { - if (this.containsPatterns) { + if (this.containsPatterns || this.containsNull) { isStringSwitch = !JavaFeature.PATTERN_MATCHING_IN_SWITCH.isSupported(compilerOptions); this.isNonTraditional = true; break checkType; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeSystem.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeSystem.java index 3c7300110..16795f2a4 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeSystem.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeSystem.java @@ -113,6 +113,10 @@ public class TypeSystem { ReferenceBinding enclosing = resolvedType.enclosingType(); if (enclosing != null) { this.enclosingType = resolvedType.isStatic() ? enclosing : (ReferenceBinding) env.convertUnresolvedBinaryToRawType(enclosing); // needed when binding unresolved member type + if (this.enclosingType.getClass() == ParameterizedTypeBinding.class) { + throw new IllegalStateException("unexpected: resolved enclosing type of " //$NON-NLS-1$ + + new String(this.type.readableName(false)) + " is a ParameterizedTypeBinding"); //$NON-NLS-1$ + } } } if (this.arguments != null) { @@ -147,6 +151,11 @@ public class TypeSystem { public int hashCode() { final int prime=31; int hashCode = 1 + hash(this.type); + if (this.enclosingType != null && this.enclosingType.getClass() == ParameterizedTypeBinding.class) { + // Note: this works as in swapUnresolved, a null enclosingType is never replaced by a + // ParameterizedTypeBinding (just by a non-generic or RawTypeBinding) + hashCode = hashCode * prime + System.identityHashCode(this.enclosingType); + } for (int i = 0, length = this.arguments == null ? 0 : this.arguments.length; i < length; i++) { hashCode = hashCode * prime + hash(this.arguments[i]); } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java index 754fdf33c..777fe4b70 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java @@ -29,7 +29,7 @@ public class SwitchPatternTest extends AbstractRegressionTest9 { static { // TESTS_NUMBERS = new int [] { 40 }; // TESTS_RANGE = new int[] { 1, -1 }; -// TESTS_NAMES = new String[] { "testIssue449_001"}; +// TESTS_NAMES = new String[] { "testIssue554_001"}; } private static String previewLevel = "19"; @@ -5321,4 +5321,21 @@ public class SwitchPatternTest extends AbstractRegressionTest9 { }, "1"); } + public void testIssue554_001() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " String obj = null;\n"+ + " var a = switch (obj) {\n"+ + " case null -> 1;\n"+ + " default -> 2;\n"+ + " };\n"+ + " System.out.println(a);\n"+ + " }\n" + + "}" + }, + "1"); + } } diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/IndexManagerTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/IndexManagerTests.java index c798224ab..de6c23f13 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/IndexManagerTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/IndexManagerTests.java @@ -166,6 +166,18 @@ public class IndexManagerTests extends ModifyingResourceTests { assertEquals("Expected number of indexes are not found for binary.Deep", size - 1, indexNames.get().size()); } + public void testSearchMetaIndex_ForSourceTypeDeclarations() throws CoreException { + if (SKIP_TESTS) + return; + + createFolder("/IndexProject/src/app"); + createFile("/IndexProject/src/app/Q1.java", "package app;\n public class Q1 {\n" + "}"); + + Optional<Set<String>> indexNames = searchInMetaIndex("app.Q1"); + assertTrue("No meta index", indexNames.isPresent()); + assertEquals("No results found", 1, indexNames.get().size()); + } + private void changeFile(String path, String content) { IFile file = getFile(path); if (!file.exists()) { diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/index/DiskIndex.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/index/DiskIndex.java index f99d9a0a7..8311a2aa2 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/index/DiskIndex.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/index/DiskIndex.java @@ -56,9 +56,9 @@ char separator = Index.DEFAULT_SEPARATOR; //{ObjectTeams: add a suffix for distinction: /* orig: -public static final String SIGNATURE= "INDEX VERSION 1.131"; //$NON-NLS-1$ +public static final String SIGNATURE = "INDEX VERSION 1.132"; //$NON-NLS-1$ :giro */ -public static final String SIGNATURE= "INDEX VERSION 1.131 OT2"; //$NON-NLS-1$ +public static final String SIGNATURE= "INDEX VERSION 1.132 OT1"; //$NON-NLS-1$ // SH} private static final char[] SIGNATURE_CHARS = SIGNATURE.toCharArray(); public static boolean DEBUG = false; diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/AbstractIndexer.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/AbstractIndexer.java index 3786ce4d6..7ecfcdbb3 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/AbstractIndexer.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/AbstractIndexer.java @@ -292,9 +292,16 @@ public abstract class AbstractIndexer implements IIndexConstants { packageName == null ? CharOperation.NO_CHAR : packageName); addIndexEntry(TYPE_DECL, indexKey); - addIndexMetaQualification( - CharOperation.concat(packageName, '.', CharOperation.concatWith(enclosingTypeNames, '$'), '$', name), - false); + if (enclosingTypeNames != null && enclosingTypeNames.length > 0) { + addIndexMetaQualification( + CharOperation.concat(packageName, '.', CharOperation.concatWith(enclosingTypeNames, '$'), '$', + name), + false); + } else { + addIndexMetaQualification( + CharOperation.concat(packageName, name, '.'), + false); + } } public void addTypeReference(char[] typeName) { addTypeReference(typeName, false); |