Skip to content

Commit

Permalink
Eclipse 4.26 (M3) JDT Patch for Groovy-Eclipse
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Nov 12, 2022
1 parent 393f33c commit 42f36d4
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 71 deletions.
2 changes: 1 addition & 1 deletion groovy-eclipse.setup
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@
<repository
url="https://download.eclipse.org/technology/m2e/releases/1.20.1"/>
<repository
url="https://download.eclipse.org/eclipse/updates/4.26-I-builds/I20221020-1800"/>
url="https://download.eclipse.org/eclipse/updates/4.26-I-builds/I20221109-1850"/>
</repositoryList>
<repositoryList
name="2022-09">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</license>

<requires>
<import feature="org.eclipse.jdt" version="3.18.1400.v20221020-1800" patch="true"/>
<import feature="org.eclipse.jdt" version="3.18.1400.v20220928-1800" patch="true"/>
</requires>

<plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50642,23 +50642,10 @@ public void test1436() {
" ^^^^^^^^^^^\n" +
"Type safety: Unchecked invocation foo(List, IllegalArgumentException) of the generic method foo(List<U>, T) of type X\n" +
"----------\n" +
(this.complianceLevel < ClassFileConstants.JDK1_8
?
"3. WARNING in X.java (at line 8)\n" +
" foo(l, iae);\n" +
" ^\n" +
"Type safety: The expression of type List needs unchecked conversion to conform to List<List<?>>\n"
:
"3. ERROR in X.java (at line 8)\n" +
" foo(l, iae);\n" +
" ^^^^^^^^^^^\n" +
"Unhandled exception type Throwable\n" + // new error since 1.8 (bug 473657)
"----------\n" +
"4. WARNING in X.java (at line 8)\n" +
" foo(l, iae);\n" +
" ^\n" +
"Type safety: The expression of type List needs unchecked conversion to conform to List<List<?>>\n"
) +
"3. WARNING in X.java (at line 8)\n" +
" foo(l, iae);\n" +
" ^\n" +
"Type safety: The expression of type List needs unchecked conversion to conform to List<List<?>>\n" +
"----------\n");
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=258798 - variation
Expand Down Expand Up @@ -50690,23 +50677,10 @@ public void test1437() {
" ^^^^^^^^^^^^^\n" +
"Type safety: Unchecked invocation X(List, IllegalArgumentException) of the generic constructor X(List<U>, T) of type X\n" +
"----------\n" +
(this.complianceLevel < ClassFileConstants.JDK1_8
?
"3. WARNING in X.java (at line 8)\n" +
" new X(l, iae);\n" +
" ^\n" +
"Type safety: The expression of type List needs unchecked conversion to conform to List<List<?>>\n"
:
"3. ERROR in X.java (at line 8)\n" +
" new X(l, iae);\n" +
" ^^^^^^^^^^^^^\n" +
"Unhandled exception type Throwable\n" + // new error since 1.8 (bug 473657)
"----------\n" +
"4. WARNING in X.java (at line 8)\n" +
" new X(l, iae);\n" +
" ^\n" +
"Type safety: The expression of type List needs unchecked conversion to conform to List<List<?>>\n"
) +
"3. WARNING in X.java (at line 8)\n" +
" new X(l, iae);\n" +
" ^\n" +
"Type safety: The expression of type List needs unchecked conversion to conform to List<List<?>>\n" +
"----------\n");
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=258798 - variation
Expand Down Expand Up @@ -50738,23 +50712,10 @@ public void test1438() {
" ^^^^^^^^^^^^^^^\n" +
"Type safety: Unchecked invocation X(List, IllegalArgumentException) of the generic constructor X(List<U>, T) of type X\n" +
"----------\n" +
(this.complianceLevel < ClassFileConstants.JDK1_8
?
"3. WARNING in X.java (at line 8)\n" +
" new X(l, iae){};\n" +
" ^\n" +
"Type safety: The expression of type List needs unchecked conversion to conform to List<List<?>>\n"
:
"3. ERROR in X.java (at line 8)\n" +
" new X(l, iae){};\n" +
" ^^^^^^^^^^^^^^^\n" +
"Unhandled exception type Throwable\n" + // new error since 1.8 (bug 473657)
"----------\n" +
"4. WARNING in X.java (at line 8)\n" +
" new X(l, iae){};\n" +
" ^\n" +
"Type safety: The expression of type List needs unchecked conversion to conform to List<List<?>>\n"
) +
"3. WARNING in X.java (at line 8)\n" +
" new X(l, iae){};\n" +
" ^\n" +
"Type safety: The expression of type List needs unchecked conversion to conform to List<List<?>>\n" +
"----------\n");
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=258798 - variation
Expand Down Expand Up @@ -50783,11 +50744,14 @@ public void test1439() {
" ^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"Type safety: Unchecked invocation X(List, null) of the generic constructor X(List<U>, T) of type X\n" +
"----------\n" +
(this.complianceLevel < ClassFileConstants.JDK1_8 ?
"2. ERROR in X.java (at line 7)\n" +
" this((List) null, null);\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"Unhandled exception type Throwable\n" +
"----------\n" +
"----------\n"
: "" // no error in 1.8 (bug GH472)
) +
"3. WARNING in X.java (at line 7)\n" +
" this((List) null, null);\n" +
" ^^^^^^^^^^^\n" +
Expand Down Expand Up @@ -51071,16 +51035,22 @@ public void test1445() {
" ^^^^^^^^^^^^^^^\n" +
"Type safety: Unchecked invocation foo(List) of the generic method foo(List<T>) of type X\n" +
"----------\n" +
(this.complianceLevel < ClassFileConstants.JDK1_8 ?
"4. ERROR in X.java (at line 9)\n" +
" new X(l).foo(l);\n" +
" ^^^^^^^^\n" +
"Unhandled exception type Throwable\n" +
"----------\n" +
"----------\n"
: "" // no error in 1.8 (bug GH472)
) +
(this.complianceLevel < ClassFileConstants.JDK1_8 ?
"5. ERROR in X.java (at line 9)\n" +
" new X(l).foo(l);\n" +
" ^^^^^^^^^^^^^^^\n" +
"Unhandled exception type Throwable\n" +
"----------\n" +
"----------\n"
: "" // no error in 1.8 (bug GH472)
) +
"6. WARNING in X.java (at line 9)\n" +
" new X(l).foo(l);\n" +
" ^\n" +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2020 IBM Corporation and others.
* Copyright (c) 2000, 2022 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -6681,5 +6681,94 @@ public void testBug576524() {
);
}
}

// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/472
// If unchecked conversion was necessary for the arguments,
// substitute and erase the return type.
public void testBugGH472_a() {
if (this.complianceLevel >= ClassFileConstants.JDK1_8) {
this.runConformTest(
new String[] {
"ReturnTypeTest.java",
"public class ReturnTypeTest {\n"
+ " <T> T m(Class<T> arg1, Class<T> arg2) { return null; }\n"
+ "\n"
+ " void test(Class c1, Class<Class<String>> c2) throws Exception {\n"
+ " m(c1, c2).newInstance();\n"
+ " }\n"
+ "}"
}
);
}
}

// A variation for the unchecked conversion test case.
// the type arguments contain wildcards like <? extends T>.
public void testBugGH472_b() {
if (this.complianceLevel >= ClassFileConstants.JDK1_8) {
this.runConformTest(
new String[] {
"ReturnTypeTest.java",
"public class ReturnTypeTest {\n"
+ " <T> T m(Class<T> arg1, Class<? extends T> arg2) { return null; }\n"
+ "\n"
+ " void test(Class c1, Class<Class<String>> c2) throws Exception {\n"
+ " m(c1, c2).newInstance();\n"
+ " }\n"
+ "}"
}
);
}
}

// A variation for the unchecked conversion test case.
// the type arguments contain wildcards like <? super T>.
public void testBugGH472_c() {
if (this.complianceLevel >= ClassFileConstants.JDK1_8) {
this.runConformTest(
new String[] {
"ReturnTypeTest.java",
"public class ReturnTypeTest {\n"
+ " <T> T m(Class<T> arg1, Class<? super T> arg2) { return null; }\n"
+ "\n"
+ " void test(Class c1, Class<Class<String>> c2) throws Exception {\n"
+ " m(c1, c2).newInstance();\n"
+ " }\n"
+ "}"
}
);
}
}

// If unchecked conversion was necessary for the arguments,
// substitute and erase the thrown type.
public void testBugGH472_d() {
if (this.complianceLevel >= ClassFileConstants.JDK1_8) {
this.runConformTest(
new String[] {
"ThrowTest.java",
"public class ThrowTest {\n"
+ "\n"
+ " public static void test(MyDerivedException e, MyType t) {\n"
+ " try {\n"
+ " new Foo(e, t);\n"
+ " } catch (MyDerivedException e2) {}\n"
+ " }\n"
+ "}\n"
+ "\n"
+ "class MyException extends Exception {}\n"
+ "class MyDerivedException extends MyException {}\n"
+ "\n"
+ "class MyType<T> {}\n"
+ "\n"
+ "class Foo {\n"
+ " public <E1 extends MyException> Foo(E1 e, MyType<String> a) throws E1 {\n"
+ " throw e;\n"
+ " }\n"
+ "}"
}
);
}
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corporation and others.
* Copyright (c) 2000, 2022 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -560,10 +560,10 @@ public ParameterizedGenericMethodBinding(MethodBinding originalMethod, TypeBindi
this.parameters = Scope.substitute(this, originalMethod.parameters);
// error case where exception type variable would have been substituted by a non-reference type (207573)
if (inferredWithUncheckConversion) { // JSL 18.5.2: "If unchecked conversion was necessary..."
this.returnType = getErasure18_5_2(originalMethod.returnType, environment, hasReturnProblem); // propagate simulation of Bug JDK_8026527
this.returnType = getErasure18_5_2(originalMethod.returnType, environment);
this.thrownExceptions = new ReferenceBinding[originalMethod.thrownExceptions.length];
for (int i = 0; i < originalMethod.thrownExceptions.length; i++) {
this.thrownExceptions[i] = (ReferenceBinding) getErasure18_5_2(originalMethod.thrownExceptions[i], environment, false); // no excuse for exceptions
this.thrownExceptions[i] = (ReferenceBinding) getErasure18_5_2(originalMethod.thrownExceptions[i], environment);
}
} else {
this.returnType = Scope.substitute(this, originalMethod.returnType);
Expand Down Expand Up @@ -608,13 +608,12 @@ public ParameterizedGenericMethodBinding(MethodBinding originalMethod, TypeBindi
}
}

TypeBinding getErasure18_5_2(TypeBinding type, LookupEnvironment env, boolean substitute) {
TypeBinding getErasure18_5_2(TypeBinding type, LookupEnvironment env) {
// opportunistic interpretation of (JLS 18.5.2):
// "If unchecked conversion was necessary ..., then ...
// the return type and thrown types of the invocation type of m are given by
// the erasure of the return type and thrown types of m's type."
if (substitute)
type = Scope.substitute(this, type);
type = Scope.substitute(this, type); // compliant with Bug JDK-8135087: Erasure for unchecked invocation happens after inference
return env.convertToRawType(type.erasure(), true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.eclipse.jdt.core;

import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.internal.core.JavaModelManager;

/**
* Interface of a classpath container.
Expand Down Expand Up @@ -141,5 +142,16 @@ public interface IClasspathContainer {
* @return IPath - the container path that is associated with this container
*/
IPath getPath();

/**
* Answer the IDs of all registered classpath containers (extensions at extension point
* {@link JavaModelManager#CPCONTAINER_INITIALIZER_EXTPOINT_ID}).
* @return array of strings as extracted from the "id" attribute from all registered
* classpath containers.
* @since 3.32
*/
public static String[] getRegisteredContainerIds() {
return JavaModelManager.getRegisteredContainerIDs();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Bundle-ClassPath: .
Bundle-Vendor: Eclipse.org
Export-Package: org.eclipse.jdt.core,
org.eclipse.jdt.core.compiler,
org.eclipse.jdt.core.compiler.batch,
org.eclipse.jdt.internal.antadapter;x-internal:=true,
org.eclipse.jdt.internal.compiler;x-internal:=true,
org.eclipse.jdt.internal.compiler.apt.dispatch;x-internal:=true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class SourceIndexer extends AbstractIndexer implements ITypeRequestor, Su
private CompilationUnit compilationUnit;
private CompilationUnitDeclaration cud;
private static final boolean DEBUG = false;

public SourceIndexer(SearchDocument document) {
super(document);
this.requestor = new SourceIndexerRequestor(this);
Expand Down Expand Up @@ -120,7 +120,7 @@ public void indexDocument() {
}
}
}

@Override
public void accept(IBinaryType binaryType, PackageBinding packageBinding, AccessRestriction accessRestriction) {
this.lookupEnvironment.createBinaryTypeFrom(binaryType, packageBinding, accessRestriction);
Expand All @@ -142,9 +142,9 @@ public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, Acc
SourceTypeElementInfo elementInfo = (SourceTypeElementInfo) sourceType;
IType type = elementInfo.getHandle();
ICompilationUnit sourceUnit = (ICompilationUnit) type.getCompilationUnit();
accept(sourceUnit, accessRestriction);
accept(sourceUnit, accessRestriction);
}

public void resolveDocument() {
try {
IPath path = new Path(this.document.getPath());
Expand Down Expand Up @@ -196,7 +196,14 @@ private void purgeMethodStatements(TypeDeclaration type) {
AbstractMethodDeclaration[] methods = type.methods;
for (int j = 0, length = methods == null ? 0 : methods.length; j < length; j++) {
AbstractMethodDeclaration method = methods[j];
if (method != null && (method.bits & ASTNode.HasFunctionalInterfaceTypes) == 0) {
/*
* In case the method defines a local type, skip purging the method body.
* We don't know if the local type defines a method that uses a method reference or a lambda.
* See:
* https://github.com/eclipse-jdt/eclipse.jdt.core/issues/432
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=566435
*/
if (method != null && (method.bits & (ASTNode.HasFunctionalInterfaceTypes | ASTNode.HasLocalType)) == 0) {
method.statements = null;
method.javadoc = null;
}
Expand All @@ -219,11 +226,11 @@ public void indexResolvedDocument() {
if (lambdaExpression.binding != null && lambdaExpression.binding.isValidBinding()) {
final char[] superinterface = lambdaExpression.resolvedType.sourceName();
if (DEBUG) {
System.out.println('\t' + new String(superinterface) + '.' +
System.out.println('\t' + new String(superinterface) + '.' +
new String(lambdaExpression.descriptor.selector) + "-> {}"); //$NON-NLS-1$
}
SourceIndexer.this.addIndexEntry(IIndexConstants.METHOD_DECL, MethodPattern.createIndexKey(lambdaExpression.descriptor.selector, lambdaExpression.descriptor.parameters.length));

addClassDeclaration(0, // most entries are blank, that is fine, since lambda type/method cannot be searched.
CharOperation.NO_CHAR, // package name
ONE_ZERO,
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
<repository>
<id>milestone</id>
<layout>p2</layout>
<url>https://download.eclipse.org/eclipse/updates/4.26-I-builds/I20221020-1800</url>
<url>https://download.eclipse.org/eclipse/updates/4.26-I-builds/I20221109-1850</url>
</repository>
</repositories>
<modules>
Expand Down

0 comments on commit 42f36d4

Please sign in to comment.