From 7e57bcc1818a402ad6ec32416af2b4522671f9ab Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Tue, 29 Mar 2016 11:02:34 +1000 Subject: Java types and type parameters can be annotated since JSR 308 --- src/compiler/scala/tools/nsc/javac/JavaParsers.scala | 5 ++++- test/files/pos/java-type-annotations/NotNull.java | 6 ++++++ test/files/pos/java-type-annotations/Test.java | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test/files/pos/java-type-annotations/NotNull.java create mode 100644 test/files/pos/java-type-annotations/Test.java diff --git a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala index 8cdc5944e8..cc851b6330 100644 --- a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala +++ b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala @@ -264,7 +264,8 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { } } - def typ(): Tree = + def typ(): Tree = { + annotations() optArrayBrackets { if (in.token == FINAL) in.nextToken() if (in.token == IDENTIFIER) { @@ -287,6 +288,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { basicType() } } + } def typeArgs(t: Tree): Tree = { val wildcards = new ListBuffer[TypeDef] @@ -404,6 +406,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { def typeParam(): TypeDef = atPos(in.currentPos) { + annotations() val name = identForType() val hi = if (in.token == EXTENDS) { in.nextToken() ; bound() } else EmptyTree TypeDef(Modifiers(Flags.JAVA | Flags.DEFERRED | Flags.PARAM), name, Nil, TypeBoundsTree(EmptyTree, hi)) diff --git a/test/files/pos/java-type-annotations/NotNull.java b/test/files/pos/java-type-annotations/NotNull.java new file mode 100644 index 0000000000..2716fe1a99 --- /dev/null +++ b/test/files/pos/java-type-annotations/NotNull.java @@ -0,0 +1,6 @@ +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +public @interface NotNull { +} diff --git a/test/files/pos/java-type-annotations/Test.java b/test/files/pos/java-type-annotations/Test.java new file mode 100644 index 0000000000..d6bda1dedb --- /dev/null +++ b/test/files/pos/java-type-annotations/Test.java @@ -0,0 +1,4 @@ +public class Test { + static class C<@NotNull T> {}; + @NotNull String foo() { return ""; } +} -- cgit v1.2.3