GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — [java] Move annotations inside the node they apply to by oowekyala · Pull Request #1875 · pmd/pmd Conversation
|
| Code | Old AST | Current 7.0 AST | New AST after this PR |
|---|---|---|---|
|
Top-level type declaration @A class C {} |
+TypeDeclaration +MarkerAnnotation "A" +ClassOrInterfaceDeclaration +ClassOrInterfaceBody |
Same |
+TypeDeclaration - +MarkerAnnotation "A" +ClassOrInterfaceDeclaration + +MarkerAnnotation "A" +ClassOrInterfaceBody |
|
Cast expression (@A T.@B S) expr |
N/A (Parse error) |
+CastExpression +MarkerAnnotation "A" +ClassOrInterfaceType "S" +MarkerAnnotation "B" +AmbiguousName "T" +(Expression `expr`) |
+CastExpression - +MarkerAnnotation "A" +ClassOrInterfaceType "S" +MarkerAnnotation "B" - +AmbiguousName "T" + +ClassOrInterfaceType "T" + +MarkerAnnotation "A" +(Expression `expr`) Notice how |
|
Cast expression with intersection (@A T & S) expr |
+CastExpression +MarkerAnnotation "A" +ClassOrInterfaceType "T" +ClassOrInterfaceType "S" +(Expression `expr`) |
+CastExpression
+MarkerAnnotation "A"
+ +IntersectionType
+ClassOrInterfaceType "T"
+ClassOrInterfaceType "S"
+(Expression `expr`) |
+CastExpression - +MarkerAnnotation "A" +IntersectionType +ClassOrInterfaceType "T" + +MarkerAnnotation "A" +ClassOrInterfaceType "S" +(Expression `expr`) Notice |
|
Constructor call new @A T() |
+AllocationExpression +MarkerAnnotation "A" +Type +ReferenceType +ClassOrInterfaceType "T" +Arguments |
+ConstructorCall +MarkerAnnotation "A" +ClassOrInterfaceType "T" +ArgumentsList |
+ConstructorCall +ClassOrInterfaceType "T" +MarkerAnnotation "A" +ArgumentsList |
|
Array allocation new @A int[0] |
+AllocationExpression +MarkerAnnotation "A" +Type +PrimitiveType "int" +ArrayDimsAndInits +Expression +PrimaryExpression +Literal "0" |
+ArrayAllocation +MarkerAnnotation "A" +PrimitiveType "int" +ArrayAllocationDims +ArrayDimExpr +NumericLiteral "0" |
+ArrayAllocation - +MarkerAnnotation "A" +PrimitiveType "int" + +MarkerAnnotation "A" +ArrayAllocationDims +ArrayDimExpr +NumericLiteral "0" |
|
Array type @A int @B[] |
N/A (parse error) |
+MarkerAnnotation "A" +ArrayType +PrimitiveType "int" +ArrayTypeDims +ArrayTypeDim +MarkerAnnotation "B" |
-+MarkerAnnotation "A" +ArrayType +PrimitiveType "int" + +MarkerAnnotation "A" +ArrayTypeDims +ArrayTypeDim +MarkerAnnotation "B" Notice |
|
Type parameters <@A T, @B S extends @C Object> |
+TypeParameters +MarkerAnnotation "A" +TypeParameter "T" +MarkerAnnotation "B" +TypeParameter "S" +MarkerAnnotation "C" +TypeBound +ReferenceType +ClassOrInterfaceType "Object" |
+TypeParameters
+MarkerAnnotation "A"
+TypeParameter "T"
+MarkerAnnotation "B"
+TypeParameter "S"
+MarkerAnnotation "C"
+TypeBound
- +ReferenceType
+ClassOrInterfaceType "Object" |
+TypeParameters - +MarkerAnnotation "A" +TypeParameter "T" + +MarkerAnnotation "A" - +MarkerAnnotation "B" +TypeParameter "S" + +MarkerAnnotation "B" - +MarkerAnnotation "C" - +TypeBound +ClassOrInterfaceType "Object" + +MarkerAnnotation "C"
|
|
Enum constants enum { @A E1, @B E2 } |
+EnumBody +MarkerAnnotation "A" +EnumConstant "E1" +MarkerAnnotation "B" +EnumConstant "E2" |
+EnumBody +MarkerAnnotation "A" +EnumConstant "E1" + +VariableDeclaratorId "E1" +MarkerAnnotation "B" +EnumConstant "E2" + +VariableDeclaratorId "E1" |
+EnumBody - +MarkerAnnotation "A" +EnumConstant "E1" + +MarkerAnnotation "A" +VariableDeclaratorId "E1" - +MarkerAnnotation "B" +EnumConstant "E2" + +MarkerAnnotation "B" +VariableDeclaratorId "E1"
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I added a lengthy test case for type annotations that includes all contexts where type annotations may appear for exhaustiveness. It's based off the spec of type annotations. There are a few cases where type annotations are legal that this PR fixes
There are two cases which we currently don't handle:
Note that this representation is both more economic in number of nodes (especially in the most common case where there are no annotations on the array dimensions), and also preserves every intermediary array type, which is nice. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Fixes some failing tests
| * | ||
| * @author Clément Fournier | ||
| */ | ||
| interface JSingleChildNode<T extends JavaNode> extends JavaNode { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Is it important, that the interface starts with the prefix "J"? We don't usually do this...
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I only did this, because this interface is equivalent to one that is introduced in #1622, and I want to avoid the name clash. When that PR is merged we can remove this one.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| * https://checkerframework.org/jsr308/java-annotation-design.html#type-names | ||
| * is particularly interesting | ||
| */ | ||
| public class ParserCornerCases18 { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We should probably rename this class to avoid confusion 😄
Do we have annotated method declarations covered? Like
@Override public void run() { }
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@oowekyala |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.