Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests9.java118
-rw-r--r--org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java41
2 files changed, 156 insertions, 3 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests9.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests9.java
index 62b87f8a2e..b9fc44645b 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests9.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests9.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2016, 2018 IBM Corporation and others.
+ * Copyright (c) 2016, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -830,6 +830,122 @@ public void test522613_001() throws Exception {
deleteProject(project1);
}
}
+public void test540591() throws Exception {
+ IJavaProject project1 = createJavaProject("Completion9_1", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "9");
+ try {
+ project1.open(null);
+ createTypePlus("/Completion9_1/src/", "pack11", "IService", "", false /* isClass */, true /* createFolder */);
+ createTypePlus("/Completion9_1/src/", "pack11", "CCC", "implements pack11.IService", true /* isClass */, false /* createFolder */);
+ createTypePlus("/Completion9_1/src/", "pack11", "AbstractService", "implements pack11.IService", true /* isClass */, false /* createFolder */);
+ createTypePlus("/Completion9_1/src/", "pack11", "CCC2", "extends pack11.AbstractService", true /* isClass */, false /* createFolder */);
+ createTypePlus("/Completion9_1/src/", "pack11", "CCC3", "extends pack11.AbstractService", true /* isClass */, false /* createFolder */);
+
+ String filePath1 = "/Completion9_1/src/module-info.java";
+ String completeBehind = "CC";
+ String fileContent1 = "module first {\n"
+ + "provides pack11.IService with " + completeBehind
+ + "}\n";
+ createFile(filePath1, fileContent1);
+ addClasspathEntry(project1, JavaCore.newContainerEntry(new Path("org.eclipse.jdt.MODULE_PATH")));
+
+ project1.close(); // sync
+ project1.open(null);
+
+ int cursorLocation = fileContent1.lastIndexOf(completeBehind) + completeBehind.length();
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2();
+
+ ICompilationUnit unit = getCompilationUnit(filePath1);
+ unit.codeComplete(cursorLocation, requestor);
+
+ String expected = "CCC[TYPE_REF]{pack11.CCC, pack11, Lpack11.CCC;, null, 49}\n" +
+ "CCC2[TYPE_REF]{pack11.CCC2, pack11, Lpack11.CCC2;, null, 49}\n" +
+ "CCC3[TYPE_REF]{pack11.CCC3, pack11, Lpack11.CCC3;, null, 49}"
+ ;
+ assertResults(expected, requestor.getResults());
+ } finally {
+ deleteProject(project1);
+ }
+}
+
+
+public void test540591_mismatchedCase() throws Exception {
+ IJavaProject project1 = createJavaProject("Completion9_1", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "9");
+ try {
+ project1.open(null);
+ createTypePlus("/Completion9_1/src/", "pack11", "IService", "", false /* isClass */, true /* createFolder */);
+ createTypePlus("/Completion9_1/src/", "pack11", "CCC", "implements pack11.IService", true /* isClass */, false /* createFolder */);
+ createTypePlus("/Completion9_1/src/", "pack11", "AbstractService", "implements pack11.IService", true /* isClass */, false /* createFolder */);
+ createTypePlus("/Completion9_1/src/", "pack11", "CCC2", "extends pack11.AbstractService", true /* isClass */, false /* createFolder */);
+ createTypePlus("/Completion9_1/src/", "pack11", "CCC3", "extends pack11.AbstractService", true /* isClass */, false /* createFolder */);
+
+ String filePath1 = "/Completion9_1/src/module-info.java";
+ String completeBehind = "cc";
+ String fileContent1 = "module first {\n"
+ + "provides pack11.IService with " + completeBehind
+ + "}\n";
+ createFile(filePath1, fileContent1);
+ addClasspathEntry(project1, JavaCore.newContainerEntry(new Path("org.eclipse.jdt.MODULE_PATH")));
+
+ project1.close(); // sync
+ project1.open(null);
+
+ int cursorLocation = fileContent1.lastIndexOf(completeBehind) + completeBehind.length();
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2();
+
+ ICompilationUnit unit = getCompilationUnit(filePath1);
+ unit.codeComplete(cursorLocation, requestor);
+
+ String expected = "CCC[TYPE_REF]{pack11.CCC, pack11, Lpack11.CCC;, null, 39}\n" +
+ "CCC2[TYPE_REF]{pack11.CCC2, pack11, Lpack11.CCC2;, null, 39}\n" +
+ "CCC3[TYPE_REF]{pack11.CCC3, pack11, Lpack11.CCC3;, null, 39}"
+ ;
+ assertResults(expected, requestor.getResults());
+ } finally {
+ deleteProject(project1);
+ }
+}
+
+public void test540591_withoutPrefix() throws Exception {
+ IJavaProject project1 = createJavaProject("Completion9_1", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "9");
+ try {
+ project1.open(null);
+ createTypePlus("/Completion9_1/src/", "pack11", "IService", "", false /* isClass */, true /* createFolder */);
+ createTypePlus("/Completion9_1/src/", "pack11", "CCC", "implements pack11.IService", true /* isClass */, false /* createFolder */);
+ createTypePlus("/Completion9_1/src/", "pack11", "AbstractService", "implements pack11.IService", true /* isClass */, false /* createFolder */);
+ createTypePlus("/Completion9_1/src/", "pack11", "CCC2", "extends pack11.AbstractService", true /* isClass */, false /* createFolder */);
+ createTypePlus("/Completion9_1/src/", "pack11", "CCC3", "extends pack11.AbstractService", true /* isClass */, false /* createFolder */);
+
+ String filePath1 = "/Completion9_1/src/module-info.java";
+ String completeBehind = "with ";
+ String fileContent1 = "module first {\n"
+ + "provides pack11.IService " + completeBehind
+ + "}\n";
+ createFile(filePath1, fileContent1);
+ addClasspathEntry(project1, JavaCore.newContainerEntry(new Path("org.eclipse.jdt.MODULE_PATH")));
+
+ project1.close(); // sync
+ project1.open(null);
+
+ int cursorLocation = fileContent1.lastIndexOf(completeBehind) + completeBehind.length();
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2();
+
+ ICompilationUnit unit = getCompilationUnit(filePath1);
+ unit.codeComplete(cursorLocation, requestor);
+
+ String expected = "AbstractService[TYPE_REF]{pack11.AbstractService, pack11, Lpack11.AbstractService;, null, 39}\n" +
+ "CCC[TYPE_REF]{pack11.CCC, pack11, Lpack11.CCC;, null, 39}\n" +
+ "CCC2[TYPE_REF]{pack11.CCC2, pack11, Lpack11.CCC2;, null, 39}\n" +
+ "CCC3[TYPE_REF]{pack11.CCC3, pack11, Lpack11.CCC3;, null, 39}\n"+
+ "pack11[PACKAGE_REF]{pack11, pack11, null, null, 39}"
+ ;
+
+
+ assertResults(expected, requestor.getResults());
+ } finally {
+ deleteProject(project1);
+ }
+}
+
public void test527099_001() throws Exception {
IJavaProject project1 = createJavaProject("Completion9_1", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "9");
IJavaProject project2 = createJavaProject("Completion9_2", new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "9");
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
index f2b428d9b6..099d883256 100644
--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -41,6 +41,7 @@ import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IModuleDescription;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.ITypeHierarchy;
import org.eclipse.jdt.core.ITypeRoot;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
@@ -12018,7 +12019,33 @@ public final class CompletionEngine
if (answer != null ) {
if (answer.isSourceType()) {
IType typeHandle = ((SourceTypeElementInfo) answer.getSourceTypes()[0]).getHandle();
- pattern = SearchPattern.createPattern(typeHandle, IJavaSearchConstants.IMPLEMENTORS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);
+ try {
+ ArrayList<IType> allTypes = new ArrayList<IType>();
+ ITypeHierarchy newTypeHierarchy = typeHandle.newTypeHierarchy(this.javaProject, null);
+ IType[] implementingClasses = newTypeHierarchy.getImplementingClasses(typeHandle);
+ for (IType iClass : implementingClasses) {
+ getAllTypesInHierarchy(newTypeHierarchy,iClass,allTypes);
+ }
+ for (IType iType : allTypes) {
+ String pkg = iType.getPackageFragment().getElementName();
+ String name = iType.getElementName();
+ if ( CharOperation.ALL_PREFIX != this.completionToken) {
+ if(!CharOperation.prefixEquals(this.completionToken, name.toCharArray(), false))
+ if(!CharOperation.prefixEquals(this.completionToken, pkg.toCharArray(), false))
+ continue;
+ }
+ this.acceptType(pkg.toCharArray(), name.toCharArray(), CharOperation.NO_CHAR_CHAR, iType.getFlags(), null);
+ acceptTypes(scope);
+ }
+ if(!this.requestor.isIgnored(CompletionProposal.PACKAGE_REF)) {
+ checkCancel();
+ findPackagesInCurrentModule();
+ }
+ return;
+
+ } catch (JavaModelException e) {
+ //
+ }
} else if (answer.isBinaryType()) {
String typeName = new String(CharOperation.replaceOnCopy(answer.getBinaryType().getName(), '/', '.'));
pattern = SearchPattern.createPattern(typeName,
@@ -12097,6 +12124,16 @@ public final class CompletionEngine
}
}
+ private void getAllTypesInHierarchy(ITypeHierarchy newTypeHierarchy, IType iClass, ArrayList<IType> allTypes) {
+ allTypes.add(iClass);
+ IType[] subclasses = newTypeHierarchy.getSubclasses(iClass);
+ for (IType iType2 : subclasses) {
+ getAllTypesInHierarchy(newTypeHierarchy,iType2,allTypes);
+
+ }
+
+ }
+
private char[][] findVariableFromUnresolvedReference(LocalDeclaration variable, BlockScope scope, final char[][] discouragedNames) {
final TypeReference type = variable.type;
if(type != null &&

Back to the top