Skip to content

Commit

Permalink
Eclipse 4.21 (M3) JDT Patch for Groovy-Eclipse
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Aug 20, 2021
1 parent 5a0f8f7 commit f3e2092
Show file tree
Hide file tree
Showing 26 changed files with 1,296 additions and 210 deletions.
2 changes: 1 addition & 1 deletion groovy-eclipse.setup
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@
<repository
url="https://download.eclipse.org/eclipse/updates/4.21"/>
<repository
url="https://download.eclipse.org/eclipse/updates/4.21-I-builds/I20210729-1800"/>
url="https://download.eclipse.org/eclipse/updates/4.21-I-builds/I20210818-1800"/>
</repositoryList>
<repositoryList
name="2021-06">
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.900.v20210729-1800" patch="true"/>
<import feature="org.eclipse.jdt" version="3.18.900.v20210818-1800" patch="true"/>
</requires>

<plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7346,7 +7346,7 @@ public void test0112_Method(){
String expectedCompletionNodeToString = "<CompleteOnName:zzz>";
String expectedParentNodeToString = "(1 == <CompleteOnName:zzz>)";
String completionIdentifier = "zzz";
String expectedReplacedSource = "(zzz)";
String expectedReplacedSource = "zzz";
String expectedUnitDisplayString =
"package p;\n" +
"public class X {\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ public void test18() {
" int hello() {\n" +
" }\n" +
" }\n" +
" <CompleteOnName:>;\n" +
" }\n" +
"}\n",
// expectedCompletionIdentifier:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;

import java.io.IOException;
import java.util.Map;

import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
import org.eclipse.jdt.core.util.ClassFormatException;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;

import junit.framework.Test;
Expand Down Expand Up @@ -3876,4 +3879,89 @@ public void testBug574906() {
"true",
options);
}
public void testBug575035() throws ClassFormatException, IOException {
Map<String, String> options = getCompilerOptions(false);
String source =
"import java.lang.annotation.ElementType;\n" +
"import java.lang.annotation.Retention;\n" +
"import java.lang.annotation.RetentionPolicy;\n" +
"import java.lang.annotation.Target;\n" +
" \n" +
"public class Test {\n" +
" @Target({ ElementType.LOCAL_VARIABLE})\n" +
" @Retention(RetentionPolicy.RUNTIME)\n" +
" @interface Var {}\n" +
" @Target({ ElementType.TYPE_USE})\n" +
" @Retention(RetentionPolicy.RUNTIME)\n" +
" @interface Type {}\n" +
" public static void main(String[] args) {" +
" @Var @Type String y = \"OK: \";\n" +
" if (((Object)\"local\") instanceof @Var @Type String x) {\n" +
" System.out.println(y + x);\n" +
" }\n" +
" }\n" +
"}";
String expectedOutput = ""
+ " // Method descriptor #15 ([Ljava/lang/String;)V\n"
+ " // Stack: 4, Locals: 4\n"
+ " public static void main(String[] args);\n"
+ " 0 ldc <String \"OK: \"> [16]\n"
+ " 2 astore_1 [y]\n"
+ " 3 ldc <String \"local\"> [18]\n"
+ " 5 astore_3 [ instanceOfPatternExpressionValue]\n"
+ " 6 aload_3 [ instanceOfPatternExpressionValue]\n"
+ " 7 instanceof String [20]\n"
+ " 10 ifeq 50\n"
+ " 13 aload_3 [ instanceOfPatternExpressionValue]\n"
+ " 14 checkcast String [20]\n"
+ " 17 dup\n"
+ " 18 astore_2\n"
+ " 19 aload_3\n"
+ " 20 checkcast String [20]\n"
+ " 23 if_acmpne 50\n"
+ " 26 getstatic System.out : PrintStream [22]\n"
+ " 29 new StringBuilder [28]\n"
+ " 32 dup\n"
+ " 33 aload_1 [y]\n"
+ " 34 invokestatic String.valueOf(Object) : String [30]\n"
+ " 37 invokespecial StringBuilder(String) [34]\n"
+ " 40 aload_2 [x]\n"
+ " 41 invokevirtual StringBuilder.append(String) : StringBuilder [37]\n"
+ " 44 invokevirtual StringBuilder.toString() : String [41]\n"
+ " 47 invokevirtual PrintStream.println(String) : void [45]\n"
+ " 50 return\n"
+ " Line numbers:\n"
+ " [pc: 0, line: 13]\n"
+ " [pc: 3, line: 14]\n"
+ " [pc: 26, line: 15]\n"
+ " [pc: 50, line: 17]\n"
+ " Local variable table:\n"
+ " [pc: 0, pc: 51] local: args index: 0 type: String[]\n"
+ " [pc: 3, pc: 51] local: y index: 1 type: String\n"
+ " [pc: 26, pc: 50] local: x index: 2 type: String\n"
+ " [pc: 6, pc: 20] local: instanceOfPatternExpressionValue index: 3 type: Object\n"
+ " Stack map table: number of frames 1\n"
+ " [pc: 50, append: {String}]\n"
+ " RuntimeVisibleTypeAnnotations: \n"
+ " #59 @Type(\n"
+ " target type = 0x40 LOCAL_VARIABLE\n"
+ " local variable entries:\n"
+ " [pc: 3, pc: 51] index: 1\n"
+ " )\n"
+ " #59 @Type(\n"
+ " target type = 0x40 LOCAL_VARIABLE\n"
+ " local variable entries:\n"
+ " [pc: 26, pc: 50] index: 2\n"
+ " )\n"
+ "\n";
checkClassFile("Test", source, expectedOutput, ClassFileBytesDisassembler.DETAILED | ClassFileBytesDisassembler.COMPACT);
runConformTest(
new String[] {
"Test.java",
source,
},
"OK: local",
options);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,11 @@ public static int getPossibleComplianceLevels() {
isJRE10Plus = isJRE11Plus || CompilerOptions.VERSION_10.equals(specVersion);
isJRE9Plus = isJRE10Plus || CompilerOptions.VERSION_9.equals(specVersion);
initReflectionVersion();
String compliances = System.getProperty("compliance");
String key = "compliance.jre." + specVersion;
String compliances = System.getProperty(key);
if (compliances == null) {
compliances = System.getProperty("compliance");
}
if (compliances != null) {
possibleComplianceLevels = 0;
for (String compliance : compliances.split(",")) {
Expand Down
5 changes: 4 additions & 1 deletion jdt-patch/e421/org.eclipse.jdt.core.tests.compiler/test.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Copyright (c) 2002, 2014 IBM Corporation and others.
Copyright (c) 2002, 2021 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 @@ -56,6 +56,9 @@
<property name="plugin-name" value="${plugin-name}"/>
<property name="classname"
value="org.eclipse.jdt.core.tests.compiler.regression.TestAll"/>
<property name="vmargs"
value="-Dcompliance.jre.11=1.8,9,10,11 -Dcompliance.jre.16=1.8,11,15,16 -Dcompliance.jre.17=1.8,11,16,17"
/>
</ant>

<antcall target="evaluation_tests"/>
Expand Down
9 changes: 9 additions & 0 deletions jdt-patch/e421/org.eclipse.jdt.core/.settings/.api_filters
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
</message_arguments>
</filter>
</resource>
<resource path="dom/org/eclipse/jdt/core/dom/ASTNode.java" type="org.eclipse.jdt.core.dom.ASTNode">
<filter comment="To fix the mistake and considering nodes added till 107 in BETA Branch" id="388194388">
<message_arguments>
<message_argument value="org.eclipse.jdt.core.dom.ASTNode"/>
<message_argument value="MODULE_QUALIFIED_NAME"/>
<message_argument value="103"/>
</message_arguments>
</filter>
</resource>
<resource path="dom/org/eclipse/jdt/core/dom/Annotation.java" type="org.eclipse.jdt.core.dom.Annotation">
<filter id="576725006">
<message_arguments>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@
import org.eclipse.jdt.internal.codeassist.complete.CompletionNodeFound;
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnAnnotationOfType;
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnArgumentName;
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnBranchStatementLabel;
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnBreakStatement;
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnClassLiteralAccess;
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnContinueStatement;
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnExplicitConstructorCall;
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnFieldName;
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnFieldType;
Expand Down Expand Up @@ -2020,8 +2021,10 @@ private boolean complete(
completionOnMarkerAnnotationName(astNode, qualifiedBinding, scope);
} else if (astNode instanceof CompletionOnMemberValueName) {
completionOnMemberValueName(astNode, astNodeParent, scope, insideTypeAnnotation);
} else if(astNode instanceof CompletionOnBranchStatementLabel) {
completionOnBranchStatementLabel(astNode);
} else if(astNode instanceof CompletionOnBreakStatement) {
completionOnBreakStatement((CompletionOnBreakStatement) astNode);
} else if(astNode instanceof CompletionOnContinueStatement) {
completionOnContinueStatement((CompletionOnContinueStatement) astNode);
} else if(astNode instanceof CompletionOnMessageSendName) {
completionOnMessageSendName(astNode, qualifiedBinding, scope);
} else if (astNode instanceof CompletionOnReferenceExpressionName) {
Expand Down Expand Up @@ -2608,11 +2611,17 @@ public void complete(IType type, char[] snippet, int position, char[][] localVar
}
}

private void completionOnBranchStatementLabel(ASTNode astNode) {
private void completionOnBreakStatement(CompletionOnBreakStatement astNode) {
if (!this.requestor.isIgnored(CompletionProposal.LABEL_REF)) {
CompletionOnBranchStatementLabel label = (CompletionOnBranchStatementLabel) astNode;
this.completionToken = label.label;
findLabels(this.completionToken, label.possibleLabels);
this.completionToken = astNode.label;
findLabels(this.completionToken, astNode.possibleLabels);
}
}

private void completionOnContinueStatement(CompletionOnContinueStatement astNode) {
if (!this.requestor.isIgnored(CompletionProposal.LABEL_REF)) {
this.completionToken = astNode.label;
findLabels(this.completionToken, astNode.possibleLabels);
}
}

Expand Down Expand Up @@ -3240,6 +3249,7 @@ private void completionOnMessageSendName(ASTNode astNode, Binding qualifiedBindi
if (messageSend.nextIsCast) {
// optionalPrefix|((String) s) was mistaken as a messageSend(?). Treat like beginning of statement.
findVariablesAndMethods(this.completionToken, scope, messageSend, scope, false, false);
findTypesAndPackages(this.completionToken, scope, true, false, new ObjectVector());
return;
}

Expand Down Expand Up @@ -3694,6 +3704,17 @@ private void completionOnQualifiedTypeReference(ASTNode astNode, ASTNode astNode
}
}
} else if (qualifiedBinding instanceof ReferenceBinding && !(qualifiedBinding instanceof TypeVariableBinding)) {
ReferenceBinding receiverType = (ReferenceBinding) qualifiedBinding;
if (astNodeParent instanceof LocalDeclaration && ref.nextToken == TerminalTokens.TokenNameLPAREN && !this.assistNodeIsConstructor) {
// the subsequent '(' makes the interpretation as LocalDeclaration illegal (unless it's "new prefix.token()").
// therefore we assume that "name(" (where name is LocalDeclaration.name) is the start of a new statement,
// and propose *everything* that can be referenced via the receiverType:
findMethods(this.completionToken, null, null, receiverType, scope, new ObjectVector(), true/*onlyStatic*/, false,
FakeInvocationSite, scope, false, false, false, null, null, null, false, null, -1, -1);
findFields(this.completionToken, receiverType, scope, new ObjectVector(), new ObjectVector(), true/*onlyStatic*/,
FakeInvocationSite, scope, false, false, null, null, null, false, null, -1, -1);
// fall through to propose member types
}
if (!this.requestor.isIgnored(CompletionProposal.TYPE_REF)) {
setSourceAndTokenRange((int) (completionPosition >>> 32), (int) completionPosition);

Expand All @@ -3702,7 +3723,7 @@ private void completionOnQualifiedTypeReference(ASTNode astNode, ASTNode astNode
if (this.assistNodeIsException && astNodeParent instanceof TryStatement) {
findExceptionFromTryStatement(
this.completionToken,
(ReferenceBinding)qualifiedBinding,
receiverType,
scope.enclosingSourceType(),
(BlockScope)scope,
typesFound);
Expand All @@ -3712,7 +3733,7 @@ private void completionOnQualifiedTypeReference(ASTNode astNode, ASTNode astNode

findMemberTypes(
this.completionToken,
(ReferenceBinding) qualifiedBinding,
receiverType,
scope,
scope.enclosingSourceType(),
false,
Expand All @@ -3731,12 +3752,22 @@ private void completionOnQualifiedTypeReference(ASTNode astNode, ASTNode astNode
findTypesAndSubpackages(this.completionToken, (PackageBinding) qualifiedBinding, scope);
}
ASTNode parentNode = this.parser.assistNodeParent;
if (ref.tokens.length == 1 && parentNode instanceof LocalDeclaration && ((LocalDeclaration) parentNode).type == ref) {
if (ref.tokens.length > 0 && parentNode instanceof LocalDeclaration && ((LocalDeclaration) parentNode).type == ref) {
// additionally check if 'prefix.' should be interpreted as a variable receiver rather then part of a type reference:
Binding variable = scope.getBinding(ref.tokens[0], Binding.VARIABLE, FakeInvocationSite, true);
if (variable instanceof VariableBinding) {
lookupViaVariable: if (variable instanceof VariableBinding) {
TypeBinding receiverType = ((VariableBinding) variable).type;
if (receiverType != null && receiverType.isValidBinding()) {
int len = ref.tokens.length;
for (int i=1; i<len; i++) {
// lookup subsequent fields in 'prefix.q.r.'
if (!(receiverType instanceof ReferenceBinding && receiverType.isValidBinding()))
break lookupViaVariable;
FieldBinding field = scope.getField(receiverType, ref.tokens[i], FakeInvocationSite);
if (!field.isValidBinding())
break lookupViaVariable;
receiverType = field.type;
}
if (receiverType instanceof ReferenceBinding && receiverType.isValidBinding()) {
findFieldsAndMethods(this.completionToken, receiverType, scope, new ObjectVector(), new ObjectVector(), FakeInvocationSite, scope, false, false, null, null, null, false, null, ref.sourceStart, (int)ref.sourcePositions[0]);
}
}
Expand Down Expand Up @@ -3897,8 +3928,15 @@ else if ( astNodeParent instanceof InstanceOfExpression) {
if (receiverType != null && receiverType.isValidBinding()) {
findVariablesAndMethods(this.completionToken, scope, FakeInvocationSite, scope, false, false);
}
// ... or a keyword (possibly starting a new statement):
if (!this.requestor.isIgnored(CompletionProposal.KEYWORD)) {
if (this.completionToken != null && this.completionToken.length != 0) {
findKeywords(this.completionToken, singleRef.possibleKeywords, false, false);
} else {
findTrueOrFalseKeywords(singleRef.possibleKeywords);
}
}
}

}

private void completionOnProvidesInterfacesSingleTypeReference(ASTNode astNode, ASTNode astNodeParent, Binding qualifiedBinding, Scope scope) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.eclipse.jdt.internal.codeassist.select.SelectionOnPackageVisibilityReference;
import org.eclipse.jdt.internal.codeassist.select.SelectionOnImportReference;
import org.eclipse.jdt.internal.codeassist.select.SelectionOnLocalName;
import org.eclipse.jdt.internal.codeassist.select.SelectionOnMessageSend;
import org.eclipse.jdt.internal.codeassist.select.SelectionOnPackageReference;
import org.eclipse.jdt.internal.codeassist.select.SelectionOnQualifiedTypeReference;
import org.eclipse.jdt.internal.codeassist.select.SelectionOnSingleTypeReference;
Expand All @@ -64,6 +65,7 @@
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
import org.eclipse.jdt.internal.compiler.ast.ImportReference;
import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
import org.eclipse.jdt.internal.compiler.ast.MessageSend;
import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.ModuleDeclaration;
import org.eclipse.jdt.internal.compiler.ast.PackageVisibilityStatement;
Expand Down Expand Up @@ -1425,6 +1427,12 @@ private void selectLocalDeclaration(ASTNode node) {
// for traversing the parse tree, the parser assist identifier is necessary for identitiy checks
final char[] assistIdentifier = getParser().assistIdentifier();
if (assistIdentifier == null) return;
final BlockScope nodeScope;
if (node instanceof AbstractMethodDeclaration) {
nodeScope = ((AbstractMethodDeclaration)node).scope;
} else {
nodeScope = null;
}

class Visitor extends ASTVisitor {
@Override
Expand Down Expand Up @@ -1490,6 +1498,19 @@ public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) {
return true;
}
@Override
public boolean visit(MessageSend messageSend, BlockScope scope) {
if (messageSend.selector == assistIdentifier && messageSend instanceof SelectionOnMessageSend) {
if (scope == null) {
scope = nodeScope;
}
if (scope != null) {
messageSend.resolve(scope);
throw new SelectionNodeFound(messageSend.binding);
}
}
return true;
}
@Override
public boolean visit(
Argument argument, BlockScope scope) {
if (argument.type instanceof SingleTypeReference && ((SingleTypeReference)argument.type).token == assistIdentifier)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@
*/
public class CompletionNodeDetector extends ASTVisitor {

static class FindAny extends GenericAstVisitor {
private ASTNode searchFor;
boolean found;

public FindAny(ASTNode searchFor) {
this.searchFor = searchFor;
}

@Override
protected boolean visitNode(ASTNode node) {
if (node == this.searchFor) {
this.found = true;
}
return !this.found;
}
}
public static boolean findAny(CompilationUnitDeclaration unit, ASTNode searchFor) {
FindAny visitor = new FindAny(searchFor);
unit.traverse(visitor, (CompilationUnitScope)null, false);
return visitor.found;
}

@SuppressWarnings("serial")
static class StopTraversal extends RuntimeException { /* no details */}

Expand Down
Loading

0 comments on commit f3e2092

Please sign in to comment.