@@ -1397,9 +1397,10 @@ public void acceptType(
1397
1397
if (this.options.checkVisibility) {
1398
1398
if((modifiers & ClassFileConstants.AccPublic) == 0) {
1399
1399
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
+ }
1403
1404
}
1404
1405
}
1405
1406
@@ -2079,56 +2080,65 @@ public void complete(ICompilationUnit sourceUnit, int completionPosition, int po
2079
2080
}
2080
2081
}
2081
2082
}
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);
2094
2093
return;
2095
2094
}
2096
2095
}
2097
2096
}
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);
2111
2105
return;
2112
2106
}
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);
2126
2113
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);
2127
2130
}
2128
- } else if (implementation instanceof CompletionOnKeyword) {
2129
- contextAccepted = true;
2130
- processModuleKeywordCompletion(parsedUnit, implementation, (CompletionOnKeyword) implementation);
2131
2131
}
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);
2132
2142
}
2133
2143
}
2134
2144
}
@@ -2308,6 +2318,26 @@ public void complete(ICompilationUnit sourceUnit, int completionPosition, int po
2308
2318
}
2309
2319
}
2310
2320
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
+
2311
2341
private boolean completeOnPackageVisibilityStatements(boolean contextAccepted,
2312
2342
CompilationUnitDeclaration parsedUnit, PackageVisibilityStatement[] pvsStmts) {
2313
2343
for (int i = 0, l = pvsStmts.length; i < l; ++i) {
@@ -3622,8 +3652,7 @@ private void completionOnProvidesInterfacesQualifiedTypeReference(ASTNode astNod
3622
3652
}
3623
3653
3624
3654
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);
3627
3656
}
3628
3657
3629
3658
private void completionOnSingleNameReference(ASTNode astNode, ASTNode astNodeParent, Scope scope,
@@ -3760,12 +3789,11 @@ private void completionOnSingleTypeReference(ASTNode astNode, ASTNode astNodePar
3760
3789
}
3761
3790
3762
3791
private void completionOnProvidesInterfacesSingleTypeReference(ASTNode astNode, ASTNode astNodeParent, Binding qualifiedBinding, Scope scope) {
3763
- // TODO : filter the results.
3764
3792
completionOnSingleTypeReference(astNode, astNodeParent, qualifiedBinding, scope);
3765
3793
}
3766
3794
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.
3769
3797
}
3770
3798
3771
3799
private char[][] computeAlreadyDefinedName(
@@ -11855,30 +11883,7 @@ public void acceptName(char[] name) {
11855
11883
return null;
11856
11884
}
11857
11885
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 ) {
11882
11887
char[][] tokens = reference.getTypeName();
11883
11888
char[] typeName = CharOperation.concatWithAll(tokens, '.');
11884
11889
@@ -11895,15 +11900,19 @@ private void findImplementations(ProvidesStatement providesStmt, int stmtIndex,
11895
11900
CharOperation.concat(typeName, new char[]{'.'}) :lastToken;
11896
11901
}
11897
11902
setSourceRange(reference.sourceStart, reference.sourceEnd);
11898
- findImplementations(this.completionToken, this.unitScope, providesStmt, stmtIndex );
11903
+ findImplementations(this.completionToken, this.unitScope, providesStmt, -1 );
11899
11904
}
11900
11905
11901
11906
private void findImplementations(char[] token, Scope scope, ProvidesStatement providesStmt, int stmtIndex) {
11902
-
11903
11907
TypeReference theInterface = providesStmt.serviceInterface;
11904
-
11905
11908
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;
11907
11916
if (theInterfaceType == null) return;
11908
11917
SearchPattern pattern = null;
11909
11918
NameEnvironmentAnswer answer = this.nameEnvironment.findTypeInModules(theInterfaceType, scope.module());
@@ -11930,7 +11939,7 @@ public ImplSearchRequestor(char[] prefixToken, List<String> filter) {
11930
11939
}
11931
11940
@Override
11932
11941
public void acceptSearchMatch(SearchMatch match) throws CoreException {
11933
- checkCancel();
11942
+ // checkCancel();
11934
11943
IJavaElement element = ((IJavaElement) match.getElement());
11935
11944
if (element.getElementType() == IJavaElement.TYPE) {
11936
11945
IType type = (IType) element;
@@ -11941,7 +11950,9 @@ public void acceptSearchMatch(SearchMatch match) throws CoreException {
11941
11950
} else {
11942
11951
fullTypeName = type.getElementName();
11943
11952
}
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;
11945
11956
}
11946
11957
this.types.add(type);
11947
11958
}
0 commit comments