Skip to content

Commit

Permalink
Fix Java parsing of annotations on qualified types (#21867)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand authored Nov 1, 2024
2 parents 24038b8 + 09e96e2 commit d9d1047
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ object JavaParsers {
}
while (in.token == DOT) {
in.nextToken()
annotations()
t = typeArgs(atSpan(t.span.start, in.offset)(typeSelect(t, ident())))
}
convertToTypeId(t)
Expand Down
8 changes: 8 additions & 0 deletions tests/pos/i21319/Foo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package app;

import java.util.Optional;
import lib.*;

public class Foo {
private java.util.@lib.Valid Optional<String> userId;
}
3 changes: 3 additions & 0 deletions tests/pos/i21319/Test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package app

class Test
17 changes: 17 additions & 0 deletions tests/pos/i21319/Valid.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package lib;

import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE_USE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

@Target({ METHOD, FIELD, CONSTRUCTOR, PARAMETER, TYPE_USE })
@Retention(RUNTIME)
@Documented
public @interface Valid {}

0 comments on commit d9d1047

Please sign in to comment.