summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODOS.md1
-rw-r--r--src/main/java/org/javacs/JavaCompilerService.java32
-rw-r--r--src/test/java/org/javacs/CompletionsTest.java8
-rw-r--r--src/test/test-project/workspace/src/org/javacs/example/AutocompleteImplements.java3
4 files changed, 27 insertions, 17 deletions
diff --git a/TODOS.md b/TODOS.md
index 00378e0..dcf7c76 100644
--- a/TODOS.md
+++ b/TODOS.md
@@ -6,7 +6,6 @@
## Autocomplete
- NameOfClass... default constructor initializing final fields
-- im[plements]
- Annotation fields
- cc should match CamelCase
diff --git a/src/main/java/org/javacs/JavaCompilerService.java b/src/main/java/org/javacs/JavaCompilerService.java
index 5e2b721..743628b 100644
--- a/src/main/java/org/javacs/JavaCompilerService.java
+++ b/src/main/java/org/javacs/JavaCompilerService.java
@@ -619,6 +619,7 @@ public class JavaCompilerService {
"abstract",
"class",
"interface",
+ "implements",
};
private static String[] CLASS_BODY_KEYWORDS = {
@@ -824,30 +825,26 @@ public class JavaCompilerService {
completeScopeIdentifiers(partialName);
// Add keywords
if (insideClass == 0) {
- for (var k : TOP_LEVEL_KEYWORDS) {
- if (k.startsWith(partialName)) {
- result.add(Completion.ofKeyword(k));
- }
- }
+ addKeywords(TOP_LEVEL_KEYWORDS, partialName);
}
else if (insideMethod == 0) {
- for (var k : CLASS_BODY_KEYWORDS) {
- if (k.startsWith(partialName)) {
- result.add(Completion.ofKeyword(k));
- }
- }
+ addKeywords(CLASS_BODY_KEYWORDS, partialName);
}
else {
- for (var k : METHOD_BODY_KEYWORDS) {
- if (k.startsWith(partialName)) {
- result.add(Completion.ofKeyword(k));
- }
- }
+ addKeywords(METHOD_BODY_KEYWORDS, partialName);
}
}
return null;
}
+ private void addKeywords(String[] keywords, String partialName) {
+ for (var k : keywords) {
+ if (k.startsWith(partialName)) {
+ result.add(Completion.ofKeyword(k));
+ }
+ }
+ }
+
private void completeScopeIdentifiers(String partialName) {
var startsWithUpperCase = partialName.length() > 0 && Character.isUpperCase(partialName.charAt(0));
var alreadyImported = new HashSet<String>();
@@ -941,7 +938,10 @@ public class JavaCompilerService {
CompletionResult run() {
scan(parse, null);
- if (result == null) result = Collections.emptyList();
+ if (result == null) {
+ result = new ArrayList<>();
+ addKeywords(TOP_LEVEL_KEYWORDS, "");
+ }
if (isIncomplete) LOG.info(String.format("Found %d items (incomplete)", result.size()));
return new CompletionResult(result, isIncomplete);
}
diff --git a/src/test/java/org/javacs/CompletionsTest.java b/src/test/java/org/javacs/CompletionsTest.java
index c8f01ca..12e7010 100644
--- a/src/test/java/org/javacs/CompletionsTest.java
+++ b/src/test/java/org/javacs/CompletionsTest.java
@@ -784,4 +784,12 @@ public class CompletionsTest extends CompletionsBase {
assertThat(suggestions, hasItem(containsString("void superMethod() {")));
}
+
+ @Test
+ public void implementsKeyword() {
+ var file = "/org/javacs/example/AutocompleteImplements.java";
+ var suggestions = insertText(file, 3, 34);
+
+ assertThat(suggestions, hasItem(containsString("implements")));
+ }
}
diff --git a/src/test/test-project/workspace/src/org/javacs/example/AutocompleteImplements.java b/src/test/test-project/workspace/src/org/javacs/example/AutocompleteImplements.java
new file mode 100644
index 0000000..9c8b2c0
--- /dev/null
+++ b/src/test/test-project/workspace/src/org/javacs/example/AutocompleteImplements.java
@@ -0,0 +1,3 @@
+package org.javacs.example;
+
+class AutocompleteImplements impl \ No newline at end of file