diff options
3 files changed, 34 insertions, 12 deletions
diff --git a/src/main/java/org/javacs/JavaCompilerService.java b/src/main/java/org/javacs/JavaCompilerService.java index 3eb28c6..c1915fb 100644 --- a/src/main/java/org/javacs/JavaCompilerService.java +++ b/src/main/java/org/javacs/JavaCompilerService.java @@ -20,6 +20,7 @@ import java.util.*; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Predicate; +import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -338,21 +339,25 @@ public class JavaCompilerService { // Place each member of `s` into results, and unwrap `this` and `super` void walkLocals(Scope s) { - for (var e : s.getLocalElements()) { - if (e instanceof TypeElement) { - var te = (TypeElement) e; - if (trees.isAccessible(start, te)) result.add(te); - } else if (e instanceof VariableElement) { - var ve = (VariableElement) e; - if (isThisOrSuper(ve)) { - unwrapThisSuper(ve); - if (!isStatic(s)) result.add(ve); + try { + for (var e : s.getLocalElements()) { + if (e instanceof TypeElement) { + var te = (TypeElement) e; + if (trees.isAccessible(start, te)) result.add(te); + } else if (e instanceof VariableElement) { + var ve = (VariableElement) e; + if (isThisOrSuper(ve)) { + unwrapThisSuper(ve); + if (!isStatic(s)) result.add(ve); + } else { + result.add(ve); + } } else { - result.add(ve); + result.add(e); } - } else { - result.add(e); } + } catch (Exception e) { + LOG.log(Level.WARNING, "error walking locals in scope", e); } } diff --git a/src/test/java/org/javacs/CompletionsTest.java b/src/test/java/org/javacs/CompletionsTest.java index 4370c93..52b1921 100644 --- a/src/test/java/org/javacs/CompletionsTest.java +++ b/src/test/java/org/javacs/CompletionsTest.java @@ -768,4 +768,12 @@ public class CompletionsTest extends CompletionsBase { assertThat(suggestions, hasItem(startsWith("class AutocompleteClassName"))); } + + @Test + public void annotationInInnerClass() { + var file = "/org/javacs/example/AnnotationInInnerClass.java"; + var suggestions = insertText(file, 6, 17); + + assertThat(suggestions, hasItem(startsWith("Override"))); + } } diff --git a/src/test/test-project/workspace/src/org/javacs/example/AnnotationInInnerClass.java b/src/test/test-project/workspace/src/org/javacs/example/AnnotationInInnerClass.java new file mode 100644 index 0000000..bbf33c6 --- /dev/null +++ b/src/test/test-project/workspace/src/org/javacs/example/AnnotationInInnerClass.java @@ -0,0 +1,9 @@ +package org.javacs.example; + +class AnnotationInInnerClass { + void test() { + class Inner { + @Ove + } + } +}
\ No newline at end of file |