Skip to content

Commit 4b641c8

Browse files
committed
Photon (M20171101) JDT Patch for Groovy-Eclipse: JDT commit 254915c
1 parent b446dd4 commit 4b641c8

File tree

6 files changed

+98
-85
lines changed

6 files changed

+98
-85
lines changed

jdt-patch/e47/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java

+90-79
Original file line numberDiff line numberDiff line change
@@ -1397,9 +1397,10 @@ public void acceptType(
13971397
if (this.options.checkVisibility) {
13981398
if((modifiers & ClassFileConstants.AccPublic) == 0) {
13991399
if((modifiers & ClassFileConstants.AccPrivate) != 0) return;
1400-
1401-
char[] currentPackage = CharOperation.concatWith(this.unitScope.fPackage.compoundName, '.');
1402-
if(!CharOperation.equals(packageName, currentPackage)) return;
1400+
if (this.moduleDeclaration == null) {
1401+
char[] currentPackage = CharOperation.concatWith(this.unitScope.fPackage.compoundName, '.');
1402+
if(!CharOperation.equals(packageName, currentPackage)) return;
1403+
}
14031404
}
14041405
}
14051406

@@ -2079,56 +2080,65 @@ public void complete(ICompilationUnit sourceUnit, int completionPosition, int po
20792080
}
20802081
}
20812082
}
2082-
UsesStatement[] uses = this.moduleDeclaration.uses;
2083-
if (uses != null) {
2084-
for (int i = 0, l = uses.length; i < l; ++i) {
2085-
TypeReference usesReference = uses[i].serviceInterface;
2086-
if (usesReference instanceof CompletionOnUsesSingleTypeReference ||
2087-
usesReference instanceof CompletionOnUsesQualifiedTypeReference) {
2088-
this.lookupEnvironment.buildTypeBindings(parsedUnit, null);
2089-
if ((this.unitScope = parsedUnit.scope) != null) {
2090-
contextAccepted = true;
2091-
buildContext(usesReference, null, parsedUnit, null, null);
2092-
findTypeReferences(usesReference, true);
2093-
debugPrintf();
2083+
try {
2084+
UsesStatement[] uses = this.moduleDeclaration.uses;
2085+
if (uses != null) {
2086+
for (int i = 0, l = uses.length; i < l; ++i) {
2087+
UsesStatement usesStatement = uses[i];
2088+
this.parser.enclosingNode = usesStatement;
2089+
TypeReference usesReference = usesStatement.serviceInterface;
2090+
if (usesReference instanceof CompletionOnUsesSingleTypeReference ||
2091+
usesReference instanceof CompletionOnUsesQualifiedTypeReference) {
2092+
contextAccepted = checkForCNF(usesReference, parsedUnit, true);
20942093
return;
20952094
}
20962095
}
20972096
}
2098-
}
2099-
ProvidesStatement[] providesStmts = this.moduleDeclaration.services;
2100-
for (int i = 0, l = providesStmts != null ? providesStmts.length : 0; i < l; ++i) {
2101-
ProvidesStatement providesStmt = providesStmts[i];
2102-
TypeReference pInterface = providesStmt.serviceInterface;
2103-
if (pInterface instanceof CompletionOnProvidesInterfacesSingleTypeReference ||
2104-
pInterface instanceof CompletionOnProvidesInterfacesQualifiedTypeReference) {
2105-
this.lookupEnvironment.buildTypeBindings(parsedUnit, null);
2106-
if ((this.unitScope = parsedUnit.scope) != null) {
2107-
contextAccepted = true;
2108-
buildContext(pInterface, null, parsedUnit, null, null);
2109-
findTypeReferences(pInterface, true);
2110-
debugPrintf();
2097+
ProvidesStatement[] providesStmts = this.moduleDeclaration.services;
2098+
for (int i = 0, l = providesStmts != null ? providesStmts.length : 0; i < l; ++i) {
2099+
ProvidesStatement providesStmt = providesStmts[i];
2100+
this.parser.enclosingNode = providesStmt;
2101+
TypeReference pInterface = providesStmt.serviceInterface;
2102+
if (pInterface instanceof CompletionOnProvidesInterfacesSingleTypeReference ||
2103+
pInterface instanceof CompletionOnProvidesInterfacesQualifiedTypeReference) {
2104+
contextAccepted = checkForCNF(pInterface, parsedUnit, true);
21112105
return;
21122106
}
2113-
}
2114-
TypeReference[] implementations = providesStmt.implementations;
2115-
for (int j = 0, k = implementations.length; j < k; ++j) {
2116-
TypeReference implementation = implementations[i];
2117-
2118-
if (implementation instanceof CompletionOnProvidesImplementationsSingleTypeReference ||
2119-
implementation instanceof CompletionOnProvidesImplementationsQualifiedTypeReference) {
2120-
this.lookupEnvironment.buildTypeBindings(parsedUnit, null);
2121-
if ((this.unitScope = parsedUnit.scope) != null) {
2122-
contextAccepted = true;
2123-
buildContext(implementation, null, parsedUnit, null, null);
2124-
findImplementations(providesStmt, i/* stmtIndex */, j/* implIndex */);
2125-
debugPrintf();
2107+
TypeReference[] implementations = providesStmt.implementations;
2108+
for (int j = 0, k = implementations.length; j < k; ++j) {
2109+
TypeReference implementation = implementations[j];
2110+
if (implementation instanceof CompletionOnProvidesImplementationsSingleTypeReference ||
2111+
implementation instanceof CompletionOnProvidesImplementationsQualifiedTypeReference) {
2112+
contextAccepted = checkForCNF(implementation, parsedUnit, false);
21262113
return;
2114+
} else if (implementation instanceof CompletionOnKeyword) {
2115+
contextAccepted = true;
2116+
processModuleKeywordCompletion(parsedUnit, implementation, (CompletionOnKeyword) implementation);
2117+
}
2118+
}
2119+
}
2120+
} catch (CompletionNodeFound e) {
2121+
// completionNodeFound = true;
2122+
if (e.astNode != null) {
2123+
// if null then we found a problem in the completion node
2124+
if(DEBUG) {
2125+
System.out.print("COMPLETION - Completion node : "); //$NON-NLS-1$
2126+
System.out.println(e.astNode.toString());
2127+
if(this.parser.assistNodeParent != null) {
2128+
System.out.print("COMPLETION - Parent Node : "); //$NON-NLS-1$
2129+
System.out.println(this.parser.assistNodeParent);
21272130
}
2128-
} else if (implementation instanceof CompletionOnKeyword) {
2129-
contextAccepted = true;
2130-
processModuleKeywordCompletion(parsedUnit, implementation, (CompletionOnKeyword) implementation);
21312131
}
2132+
this.lookupEnvironment.unitBeingCompleted = parsedUnit; // better resilient to further error reporting
2133+
contextAccepted =
2134+
complete(
2135+
e.astNode,
2136+
this.parser.assistNodeParent,
2137+
this.parser.enclosingNode,
2138+
parsedUnit,
2139+
e.qualifiedBinding,
2140+
e.scope,
2141+
e.insideTypeAnnotation);
21322142
}
21332143
}
21342144
}
@@ -2308,6 +2318,26 @@ public void complete(ICompilationUnit sourceUnit, int completionPosition, int po
23082318
}
23092319
}
23102320

2321+
private boolean checkForCNF(TypeReference ref, CompilationUnitDeclaration parsedUnit, boolean showAll) {
2322+
this.lookupEnvironment.buildTypeBindings(parsedUnit, null);
2323+
this.lookupEnvironment.completeTypeBindings(parsedUnit, true);
2324+
parsedUnit.resolve();
2325+
if ((this.unitScope = parsedUnit.scope) != null) {
2326+
if (showAll) {
2327+
char[][] tokens = ref.getTypeName();
2328+
char[] typeName = CharOperation.concatWithAll(tokens, '.');
2329+
if (typeName.length == 0) {
2330+
buildContext(ref, null, parsedUnit, null, null);
2331+
this.completionToken = new char[] {'*'};
2332+
findTypesAndPackages(this.completionToken, this.unitScope, true, true, new ObjectVector());
2333+
return true;
2334+
}
2335+
}
2336+
parsedUnit.scope.faultInTypes();
2337+
}
2338+
return false; // should not come here - will throw exception
2339+
}
2340+
23112341
private boolean completeOnPackageVisibilityStatements(boolean contextAccepted,
23122342
CompilationUnitDeclaration parsedUnit, PackageVisibilityStatement[] pvsStmts) {
23132343
for (int i = 0, l = pvsStmts.length; i < l; ++i) {
@@ -3622,8 +3652,7 @@ private void completionOnProvidesInterfacesQualifiedTypeReference(ASTNode astNod
36223652
}
36233653

36243654
private void completionOnProvidesImplementationsQualifiedTypeReference(ASTNode astNode, ASTNode astNodeParent, Binding qualifiedBinding, Scope scope) {
3625-
// TODO: Filter the results wrt accessibility and add relevance to the results.
3626-
completionOnQualifiedTypeReference(astNode, astNodeParent, qualifiedBinding, scope);
3655+
findImplementations((ProvidesStatement) this.parser.enclosingNode, (TypeReference) astNode);
36273656
}
36283657

36293658
private void completionOnSingleNameReference(ASTNode astNode, ASTNode astNodeParent, Scope scope,
@@ -3760,12 +3789,11 @@ private void completionOnSingleTypeReference(ASTNode astNode, ASTNode astNodePar
37603789
}
37613790

37623791
private void completionOnProvidesInterfacesSingleTypeReference(ASTNode astNode, ASTNode astNodeParent, Binding qualifiedBinding, Scope scope) {
3763-
// TODO : filter the results.
37643792
completionOnSingleTypeReference(astNode, astNodeParent, qualifiedBinding, scope);
37653793
}
37663794
private void completionOnProvidesImplementationsSingleTypeReference(ASTNode astNode, ASTNode astNodeParent, Binding qualifiedBinding, Scope scope) {
3767-
// TODO : filter the results.
3768-
completionOnSingleTypeReference(astNode, astNodeParent, qualifiedBinding, scope);
3795+
findImplementations((ProvidesStatement) this.parser.enclosingNode, (TypeReference) astNode);
3796+
// TODO : filter the results - remove packs without a type in impl.
37693797
}
37703798

37713799
private char[][] computeAlreadyDefinedName(
@@ -11855,30 +11883,7 @@ public void acceptName(char[] name) {
1185511883
return null;
1185611884
}
1185711885

11858-
private void findTypeReferences(TypeReference reference, boolean findMembers) {
11859-
char[][] tokens = reference.getTypeName();
11860-
11861-
char[] typeName = CharOperation.concatWithAll(tokens, '.');
11862-
11863-
if (typeName.length == 0) {
11864-
this.completionToken = new char[] {'*'};
11865-
} else if (reference instanceof CompletionOnUsesQualifiedTypeReference ||
11866-
reference instanceof CompletionOnProvidesInterfacesQualifiedTypeReference) {
11867-
CompletionOnQualifiedTypeReference qReference = (CompletionOnQualifiedTypeReference) reference;
11868-
if (qReference.completionIdentifier != null) {
11869-
this.completionToken = CharOperation.concatAll(typeName, qReference.completionIdentifier, '.');
11870-
}
11871-
} else {
11872-
char[] lastToken = tokens[tokens.length - 1];
11873-
this.completionToken = lastToken != null && lastToken.length == 0 ?
11874-
CharOperation.concat(typeName, new char[]{'.'}) :lastToken;
11875-
}
11876-
setSourceRange(reference.sourceStart, reference.sourceEnd);
11877-
findTypesAndPackages(this.completionToken, this.unitScope, true, true, new ObjectVector());
11878-
}
11879-
11880-
private void findImplementations(ProvidesStatement providesStmt, int stmtIndex, int implIndex) {
11881-
TypeReference reference = providesStmt.implementations[implIndex];
11886+
private void findImplementations(ProvidesStatement providesStmt, TypeReference reference ) {
1188211887
char[][] tokens = reference.getTypeName();
1188311888
char[] typeName = CharOperation.concatWithAll(tokens, '.');
1188411889

@@ -11895,15 +11900,19 @@ private void findImplementations(ProvidesStatement providesStmt, int stmtIndex,
1189511900
CharOperation.concat(typeName, new char[]{'.'}) :lastToken;
1189611901
}
1189711902
setSourceRange(reference.sourceStart, reference.sourceEnd);
11898-
findImplementations(this.completionToken, this.unitScope, providesStmt, stmtIndex);
11903+
findImplementations(this.completionToken, this.unitScope, providesStmt, -1);
1189911904
}
1190011905

1190111906
private void findImplementations(char[] token, Scope scope, ProvidesStatement providesStmt, int stmtIndex) {
11902-
1190311907
TypeReference theInterface = providesStmt.serviceInterface;
11904-
1190511908
if (token == null) return;
11906-
char[][] theInterfaceType = theInterface.getTypeName();
11909+
char[][] theInterfaceType = null;
11910+
if (theInterface.resolvedType != null && theInterface.resolvedType.isValidBinding()) {
11911+
char[] readableName = theInterface.resolvedType.readableName();
11912+
if (readableName != null)
11913+
theInterfaceType = CharOperation.splitOn('.', readableName);
11914+
}
11915+
theInterfaceType = theInterfaceType == null ? theInterface.getTypeName() : theInterfaceType;
1190711916
if (theInterfaceType == null) return;
1190811917
SearchPattern pattern = null;
1190911918
NameEnvironmentAnswer answer = this.nameEnvironment.findTypeInModules(theInterfaceType, scope.module());
@@ -11930,7 +11939,7 @@ public ImplSearchRequestor(char[] prefixToken, List<String> filter) {
1193011939
}
1193111940
@Override
1193211941
public void acceptSearchMatch(SearchMatch match) throws CoreException {
11933-
checkCancel();
11942+
// checkCancel();
1193411943
IJavaElement element = ((IJavaElement) match.getElement());
1193511944
if (element.getElementType() == IJavaElement.TYPE) {
1193611945
IType type = (IType) element;
@@ -11941,7 +11950,9 @@ public void acceptSearchMatch(SearchMatch match) throws CoreException {
1194111950
} else {
1194211951
fullTypeName = type.getElementName();
1194311952
}
11944-
if (!fullTypeName.startsWith(this.prefix) || this.filter.contains(fullTypeName)) return;
11953+
if (this.filter.contains(fullTypeName)) return;
11954+
if (!(fullTypeName.startsWith(this.prefix) || type.getElementName().startsWith(this.prefix)))
11955+
return;
1194511956
}
1194611957
this.types.add(type);
1194711958
}

jdt-patch/e47/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Annotation.java

-1
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,6 @@ public TypeBinding resolveType(BlockScope scope) {
902902
pairs[i].resolveTypeExpecting(scope, null); // resilient
903903
}
904904
}
905-
// if (scope.compilerOptions().storeAnnotations)
906905
this.compilerAnnotation = scope.environment().createAnnotation((ReferenceBinding) this.resolvedType,
907906
// GROOVY add
908907
isGroovyAlias ? Binding.NO_ELEMENT_VALUE_PAIRS : computeElementValuePairs());

jdt-patch/e47/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ void buildFieldsAndMethods() {
9999
}
100100
// GROOVY add
101101
/**
102-
* @return {@code true} if error gets reported
103-
*/
102+
* @return {@code true} if error gets reported
103+
*/
104104
protected boolean reportPackageIsNotExpectedPackage(CompilationUnitDeclaration unitDecl) {
105105
problemReporter().packageIsNotExpectedPackage(unitDecl);
106106
return true;

jdt-patch/e47/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -506,13 +506,14 @@ public static CompilationUnitDeclaration parse(
506506
compilerOptions.performMethodsFullRecovery = statementsRecovery;
507507
compilerOptions.performStatementsRecovery = statementsRecovery;
508508
compilerOptions.ignoreMethodBodies = (flags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
509-
// GROOVY edit
510-
/*Parser parser = new CommentRecorderParser(
509+
/* GROOVY edit
510+
Parser parser = new CommentRecorderParser(
511511
new ProblemReporter(
512512
DefaultErrorHandlingPolicies.proceedWithAllProblems(),
513513
compilerOptions,
514514
new DefaultProblemFactory()),
515-
false);*/
515+
false);
516+
*/
516517
Parser parser = LanguageSupportFactory.getParser(
517518
null,
518519
compilerOptions,

jdt-patch/e47/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java

+1
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,7 @@ public IModuleDescription getModuleDescription() {
877877
}
878878
}
879879
} catch (JavaModelException e) {
880+
e.printStackTrace();
880881
}
881882
return null;
882883
}

jdt-patch/e47/org.eclipse.jdt.core/readme.txt

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
29-Sep-2017: 8f4f8ed (Oxygen.1a RC2)
88
09-Oct-2017: 4229c6b (Oxygen.1a)
99
25-Oct-2017: ff3f680 (M20171025-0400)
10+
01-Nov-2017: 254915c (M20171101-0400)

0 commit comments

Comments
 (0)