New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #3238: Java 8 Grammar: annotations on arrays and varargs #7407
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -257,6 +257,14 @@ typeSpec[boolean addImagNode] | |
| builtInTypeSpec[addImagNode] | ||
; | ||
|
||
// A type specification for a variable length parameter is a type name with | ||
// possible brackets afterwards that can end with annotations. | ||
variableLengthParameterTypeSpec | ||
: (classOrInterfaceType[false] | builtInType) | ||
rnveach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
({LA(1) == AT}? annotations | ) | ||
(lb:LBRACK^ {#lb.setType(ARRAY_DECLARATOR);} RBRACK ({LA(1) == AT}? annotations | ))* | ||
; | ||
|
||
// A class type specification is a class type with either: | ||
// - possible brackets afterwards | ||
// (which would make it an array type). | ||
|
@@ -387,8 +395,8 @@ builtInTypeSpec[boolean addImagNode] | |
// A type name. which is either a (possibly qualified and parameterized) | ||
// class name or a primitive (builtin) type | ||
type | ||
: classOrInterfaceType[false] | ||
| builtInType | ||
: ({LA(1) == AT}? annotations | ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: reference: in the spec,
but while checkstyle's My thinking was to allow the annotation here in |
||
(classOrInterfaceType[false] | builtInType) | ||
; | ||
|
||
/** A declaration is the creation of a reference or primitive-type variable | ||
|
@@ -893,9 +901,11 @@ variableDeclarator![AST mods, AST t] | |
{#variableDeclarator = #(#[VARIABLE_DEF,"VARIABLE_DEF"], mods, #(#[TYPE,"TYPE"],d), id, v);} | ||
; | ||
|
||
declaratorBrackets[AST typ] | ||
: {#declaratorBrackets=typ;} | ||
(lb:LBRACK^ {#lb.setType(ARRAY_DECLARATOR);} RBRACK)* | ||
declaratorBrackets![AST typ] | ||
: ({LA(1) == AT}? an:annotations | ) lb:LBRACK {#lb.setType(ARRAY_DECLARATOR);} rb:RBRACK | ||
db:declaratorBrackets[#(lb, typ, an, rb)] | ||
{#declaratorBrackets = #db;} | ||
| {#declaratorBrackets = typ;} | ||
esilkensen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
; | ||
|
||
varInitializer | ||
|
@@ -969,7 +979,7 @@ parameterDeclarationList | |
; | ||
|
||
variableLengthParameterDeclaration! | ||
: pm:parameterModifier t:typeSpec[false] td:ELLIPSIS IDENT | ||
: pm:parameterModifier t:variableLengthParameterTypeSpec td:ELLIPSIS IDENT | ||
pd:declaratorBrackets[#t] | ||
{#variableLengthParameterDeclaration = #(#[PARAMETER_DEF,"PARAMETER_DEF"], | ||
pm, #([TYPE,"TYPE"],pd), td, IDENT);} | ||
|
@@ -1592,6 +1602,7 @@ newArrayDeclarator | |
warnWhenFollowAmbig = false; | ||
} | ||
: | ||
({LA(1) == AT}? annotations | ) | ||
lb:LBRACK^ {#lb.setType(ARRAY_DECLARATOR);} | ||
(expression)? | ||
RBRACK | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//start line index in expected file is 2 | ||
package com.puppycrawl.tools.checkstyle.grammar; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.Map; | ||
import java.util.List; | ||
import java.util.function.IntBinaryOperator; | ||
import java.util.function.Predicate; | ||
import java.util.function.Supplier; | ||
|
||
public class InputRegressionJava8Class2 { | ||
static class Inner1 { static class Inner2<V> { public void m() {} } } | ||
static class Inner3<T> { public void m() {} } | ||
|
||
public void m1(@MyAnnotation String @MyAnnotation ... vararg) {} | ||
public String m2() @MyAnnotation [] @MyAnnotation [] { return null; } | ||
|
||
public void instructions() { | ||
// annotations | ||
Map.@MyAnnotation Entry e; | ||
String str = (@MyAnnotation String) ""; | ||
(new Inner3()).<@MyAnnotation String>m(); | ||
Object arr = new @MyAnnotation String @MyAnnotation [3]; | ||
for (String a @MyAnnotation [] : m2()) {} | ||
Object arr2 = new @MyAnnotation int[3]; | ||
} | ||
} | ||
|
||
@Retention(RetentionPolicy.CLASS) | ||
@Target({ ElementType.TYPE_USE }) | ||
@interface MyAnnotation { | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reference:
LastFormalParameter
which allows zero or moreAnnotation
just before the...