diff options
| author | Manoj Palat | 2017-12-20 03:43:12 +0000 |
|---|---|---|
| committer | Manoj Palat | 2017-12-20 03:43:12 +0000 |
| commit | 124c6007c2e3c0b7813d2d7198a1af4300e07d61 (patch) | |
| tree | 8a52b1c5bcec6632c7191766bc365a884bf6a868 | |
| parent | 56af3b2a1b351a279cc7c85e2b3ee05ecac26df5 (diff) | |
| download | eclipse.jdt.core-124c6007c2e3c0b7813d2d7198a1af4300e07d61.tar.gz eclipse.jdt.core-124c6007c2e3c0b7813d2d7198a1af4300e07d61.tar.xz eclipse.jdt.core-124c6007c2e3c0b7813d2d7198a1af4300e07d61.zip | |
available on the classpath
Change-Id: I1b8dceb99b0729f0a67e976c37f4dc6a768a65ab
| -rw-r--r-- | org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests9.java | 36 | ||||
| -rw-r--r-- | org.eclipse.jdt.core.tests.model/workspace/Completion/test.second.jar | bin | 0 -> 1359 bytes | |||
| -rw-r--r-- | org.eclipse.jdt.core.tests.model/workspace/Completion/test.some.api.jar | bin | 0 -> 1836 bytes | |||
| -rw-r--r-- | org.eclipse.jdt.core.tests.model/workspace/Completion/test.third.jar | bin | 0 -> 1390 bytes | |||
| -rw-r--r-- | org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java | 32 |
5 files changed, 64 insertions, 4 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 33d5140a34..fb1c08fbeb 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 @@ -28,7 +28,7 @@ public class CompletionTests9 extends AbstractJavaModelCompletionTests { static { // TESTS_NUMBERS = new int[] { 19 }; -// TESTS_NAMES = new String[] {"test486988_001"}; +// TESTS_NAMES = new String[] {"testBug525203_001"}; // TESTS_NAMES = new String[] {"test0001"}; } @@ -992,4 +992,38 @@ public void test527873_002() throws Exception { deleteProject(project2); } } +public void testBug525203_001() throws Exception { + IJavaProject project1 = createJavaProject("Completion9_1", new String[] {"src"}, new String[] {"JCL19_LIB"}, "bin", "9"); + try { + project1.open(null); + IClasspathAttribute[] attributes = {}; + addClasspathEntry(project1, JavaCore.newLibraryEntry(new Path("/Completion/test.second.jar"), null, null, null, attributes, false)); + addClasspathEntry(project1, JavaCore.newLibraryEntry(new Path("/Completion/test.third.jar"), null, null, null, attributes, false)); + addClasspathEntry(project1, JavaCore.newLibraryEntry(new Path("/Completion/test.some.api.jar"), null, null, null, attributes, false)); + + createFolder("/Completion9_1/src/x"); + String content = "module my.mod { \n" + + "requires test.\n" + + "}\n"; + String filePath = "/Completion9_1/src/module-info.java"; + String completeBehind = "requires test."; + createFile(filePath, content); + int cursorLocation = content.lastIndexOf(completeBehind) + completeBehind.length(); + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(); + + waitUntilIndexesReady(); + + ICompilationUnit unit = getCompilationUnit("/Completion9_1/src/module-info.java"); + unit.codeComplete(cursorLocation, requestor); + + String expected = "[PROPOSAL]{test.second, test.second, null, null, 49}\n" + + "[PROPOSAL]{test.some.core.api, test.some.core.api, null, null, 49}\n" + + "[PROPOSAL]{test.third.from.manifest, test.third.from.manifest, null, null, 49}"; + assertResults(expected, requestor.getResults()); + + } finally { + deleteProject(project1); + } +} + }
\ No newline at end of file diff --git a/org.eclipse.jdt.core.tests.model/workspace/Completion/test.second.jar b/org.eclipse.jdt.core.tests.model/workspace/Completion/test.second.jar Binary files differnew file mode 100644 index 0000000000..9a53d14cb7 --- /dev/null +++ b/org.eclipse.jdt.core.tests.model/workspace/Completion/test.second.jar diff --git a/org.eclipse.jdt.core.tests.model/workspace/Completion/test.some.api.jar b/org.eclipse.jdt.core.tests.model/workspace/Completion/test.some.api.jar Binary files differnew file mode 100644 index 0000000000..435a4d5abe --- /dev/null +++ b/org.eclipse.jdt.core.tests.model/workspace/Completion/test.some.api.jar diff --git a/org.eclipse.jdt.core.tests.model/workspace/Completion/test.third.jar b/org.eclipse.jdt.core.tests.model/workspace/Completion/test.third.jar Binary files differnew file mode 100644 index 0000000000..72d6763c52 --- /dev/null +++ b/org.eclipse.jdt.core.tests.model/workspace/Completion/test.third.jar 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 4687e800a5..36975802f4 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 @@ -22,7 +22,6 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; import java.util.Map; - import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; @@ -229,6 +228,7 @@ import org.eclipse.jdt.internal.core.BasicCompilationUnit; import org.eclipse.jdt.internal.core.BinaryTypeConverter; import org.eclipse.jdt.internal.core.INamingRequestor; import org.eclipse.jdt.internal.core.InternalNamingConventions; +import org.eclipse.jdt.internal.core.JarPackageFragmentRoot; import org.eclipse.jdt.internal.core.JavaElementRequestor; import org.eclipse.jdt.internal.core.JavaModelManager; import org.eclipse.jdt.internal.core.ModuleSourcePathManager; @@ -10713,7 +10713,25 @@ public final class CompletionEngine } } + private HashSet<String> getAllJarModuleNames(IJavaProject javaProject2) { + HashSet<String> modules = new HashSet<>(); + try { + for (IPackageFragmentRoot root : javaProject2.getAllPackageFragmentRoots()) { + if (root instanceof JarPackageFragmentRoot) { + IModuleDescription desc = root.getModuleDescription(); + desc = desc == null ? ((JarPackageFragmentRoot) root).getAutomaticModuleDescription() : desc; + String name = desc != null ? desc.getElementName() : null; + if (name != null && name.length() > 0) + modules.add(name); + } + } + } catch (JavaModelException e) { + // do nothing + } + return modules; + } private void findTargettedModules(char[] prefix, HashSet<String> skipSet) { + HashSet<String> probableModules = new HashSet<>(); ModuleSourcePathManager mManager = JavaModelManager.getModulePathManager(); JavaElementRequestor javaElementRequestor = new JavaElementRequestor(); try { @@ -10721,13 +10739,21 @@ public final class CompletionEngine IModuleDescription[] modules = javaElementRequestor.getModules(); for (IModuleDescription module : modules) { String name = module.getElementName(); - if (name == null || name.equals("") || skipSet.contains(name)) //$NON-NLS-1$ + if (name == null || name.equals("")) //$NON-NLS-1$ continue; - this.acceptModule(name.toCharArray()); + probableModules.add(name); } } catch (JavaModelException e) { // TODO ignore for now } + probableModules.addAll(getAllJarModuleNames(this.javaProject)); + if (prefix != CharOperation.ALL_PREFIX && prefix != null && prefix.length > 0) { + probableModules.removeIf(e -> isFailedMatch(prefix, e.toCharArray())); + } + for (String s : probableModules) { + if (!skipSet.contains(s)) + this.acceptModule(s.toCharArray()); + } } private void findTargettedModules(CompletionOnModuleReference moduleReference, HashSet<String> skipSet) { setCompletionToken(moduleReference.tokens, moduleReference.sourceStart, moduleReference.sourceEnd, moduleReference.sourcePositions); |
