From fb299f80f3f85e935695d5b7cb7f2c712b150e3c Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Thu, 24 Sep 2015 14:27:58 +1000 Subject: Improve presentation compilation of annotations A trio of problems were hampering autocompletion of annotations. First, given that that annotation is written before the annotated member, it is very common to end parse incomplete code that has a floating annotation without an anotatee. The parser was discarding the annotations (ie, the modifiers) and emitting an `EmptyTree`. Second, the presetation compiler was only looking for annotations in the Modifiers of a member def, but after typechecking annotations are moved into the symbol. Third, if an annotation failed to typecheck, it was being discarded in place of `ErroneousAnnotation`. This commit: - modifies the parser to uses a dummy class- or type-def tree, instead of EmptyTree, which can carry the annotations. - updates the locator to look in the symbol annotations of the modifiers contains no annotations. - uses a separate instance of `ErroneousAnnotation` for each erroneous annotation, and stores the original tree in its `original` tree. --- test/junit/scala/tools/nsc/interpreter/CompletionTest.scala | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'test/junit') diff --git a/test/junit/scala/tools/nsc/interpreter/CompletionTest.scala b/test/junit/scala/tools/nsc/interpreter/CompletionTest.scala index d00a9bf69a..78ebb7cf9c 100644 --- a/test/junit/scala/tools/nsc/interpreter/CompletionTest.scala +++ b/test/junit/scala/tools/nsc/interpreter/CompletionTest.scala @@ -51,6 +51,17 @@ class CompletionTest { assertEquals(List("prefix_aaa", "prefix_nnn", "prefix_zzz"), completer.complete( """class C { def prefix_nnn = 0; def prefix_zzz = 0; def prefix_aaa = 0; prefix_""").candidates) } + @Test + def annotations(): Unit = { + val intp = newIMain() + val completer = new PresentationCompilerCompleter(intp) + checkExact(completer, "def foo[@specialize", " A]")("specialized") + checkExact(completer, "def foo[@specialize")("specialized") + checkExact(completer, """@deprecatedN""", """ class Foo""")("deprecatedName") + checkExact(completer, """@deprecateN""")("deprecatedName") + checkExact(completer, """{@deprecateN""")("deprecatedName") + } + @Test def incompleteStringInterpolation(): Unit = { val intp = newIMain() -- cgit v1.2.3