From 0ecd1da200ae59c03048fe6e99c19fd598a0dbe3 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 28 Feb 2020 18:16:19 +0100 Subject: [PATCH] [java] Get rid of RecordBodyDeclaration node --- pmd-java/etc/grammar/Java.jjt | 2 +- .../pmd/lang/java/ast/ASTRecordBody.java | 3 +- .../java/ast/ASTRecordBodyDeclaration.java | 37 ------------------- .../lang/java/ast/ASTRecordDeclaration.java | 4 ++ .../java/ast/AbstractAnyTypeDeclaration.java | 2 +- .../java/ast/JavaParserDecoratedVisitor.java | 7 ---- .../java/ast/JavaParserVisitorAdapter.java | 6 --- .../java/ast/JavaParserVisitorDecorator.java | 6 --- .../pmd/lang/java/rule/AbstractJavaRule.java | 7 ---- .../pmd/lang/java/ast/Java14PreviewTest.java | 12 +++--- 10 files changed, 14 insertions(+), 72 deletions(-) delete mode 100644 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTRecordBodyDeclaration.java diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index 10e7f995bde..1e80bc67d70 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -1159,7 +1159,7 @@ void RecordBody(): "}" } -void RecordBodyDeclaration(): +void RecordBodyDeclaration() #void : {} { LOOKAHEAD(4) RecordConstructorDeclaration() diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTRecordBody.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTRecordBody.java index 7b8f19039cc..a066bfa2aaa 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTRecordBody.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTRecordBody.java @@ -13,7 +13,8 @@ * *
  *
- * RecordBody ::= "{" ({@linkplain ASTRecordBodyDeclaration RecordBodyDeclaration})* "}"
+ * RecordBody ::= "{" (   {@linkplain ASTRecordConstructorDeclaration RecordConstructorDeclaration}
+ *                      | {@linkplain ASTClassOrInterfaceBodyDeclaration ClassOrInterfaceBodyDeclaration} )* "}"
  *
  * 
* diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTRecordBodyDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTRecordBodyDeclaration.java deleted file mode 100644 index 20c5c99ef29..00000000000 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTRecordBodyDeclaration.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - - -package net.sourceforge.pmd.lang.java.ast; - -import net.sourceforge.pmd.annotation.Experimental; - -/** - * This is part of {@linkplain ASTRecordDeclaration RecordDeclaration} (JDK 14 preview feature). - * It is can contain either a normal method or constructor or a compact - * {@linkplain ASTRecordConstructorDeclaration RecordConstructorDeclaration}. - * - *
- *
- * RecordBodyDeclaration ::=   {@linkplain ASTRecordConstructorDeclaration RecordConstructorDeclaration}
- *                           | {@linkplain ASTClassOrInterfaceBodyDeclaration ClassOrInterfaceBodyDeclaration}
- *
- * 
- * - */ -@Experimental -public class ASTRecordBodyDeclaration extends AbstractJavaNode { - ASTRecordBodyDeclaration(int id) { - super(id); - } - - ASTRecordBodyDeclaration(JavaParser p, int id) { - super(p, id); - } - - @Override - public Object jjtAccept(JavaParserVisitor visitor, Object data) { - return visitor.visit(this, data); - } -} diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTRecordDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTRecordDeclaration.java index 8eebc3450b5..aeb882f8845 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTRecordDeclaration.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTRecordDeclaration.java @@ -61,4 +61,8 @@ public boolean isFindBoundary() { public List getRecordComponents() { return getFirstChildOfType(ASTRecordComponentList.class).findChildrenOfType(ASTRecordComponent.class); } + + public String getName() { + return getImage(); + } } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractAnyTypeDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractAnyTypeDeclaration.java index 52f8c63d0e3..fbdacd93bc7 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractAnyTypeDeclaration.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractAnyTypeDeclaration.java @@ -34,7 +34,7 @@ public abstract class AbstractAnyTypeDeclaration extends AbstractJavaAccessTypeN public final boolean isNested() { return getParent() instanceof ASTClassOrInterfaceBodyDeclaration || getParent() instanceof ASTAnnotationTypeMemberDeclaration - || getParent() instanceof ASTRecordBodyDeclaration; + || getParent() instanceof ASTRecordBody; } @Override diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaParserDecoratedVisitor.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaParserDecoratedVisitor.java index a7f99ff1a3a..ab614443bc6 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaParserDecoratedVisitor.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaParserDecoratedVisitor.java @@ -936,13 +936,6 @@ public Object visit(ASTRecordBody node, Object data) { return visit((JavaNode) node, data); } - @Override - @Experimental - public Object visit(ASTRecordBodyDeclaration node, Object data) { - visitor.visit(node, data); - return visit((JavaNode) node, data); - } - @Override @Experimental public Object visit(ASTRecordConstructorDeclaration node, Object data) { diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaParserVisitorAdapter.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaParserVisitorAdapter.java index dd25b22a72e..fc0cc8e59f8 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaParserVisitorAdapter.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaParserVisitorAdapter.java @@ -658,12 +658,6 @@ public Object visit(ASTRecordBody node, Object data) { return visit((JavaNode) node, data); } - @Override - @Experimental - public Object visit(ASTRecordBodyDeclaration node, Object data) { - return visit((JavaNode) node, data); - } - @Override @Experimental public Object visit(ASTRecordConstructorDeclaration node, Object data) { diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaParserVisitorDecorator.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaParserVisitorDecorator.java index 3aeb67f59a8..e56a5b09256 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaParserVisitorDecorator.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaParserVisitorDecorator.java @@ -790,12 +790,6 @@ public Object visit(ASTRecordBody node, Object data) { return visitor.visit(node, data); } - @Override - @Experimental - public Object visit(ASTRecordBodyDeclaration node, Object data) { - return visitor.visit(node, data); - } - @Override @Experimental public Object visit(ASTRecordConstructorDeclaration node, Object data) { diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/AbstractJavaRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/AbstractJavaRule.java index 37557fef305..2c243390d3c 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/AbstractJavaRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/AbstractJavaRule.java @@ -97,7 +97,6 @@ import net.sourceforge.pmd.lang.java.ast.ASTRSIGNEDSHIFT; import net.sourceforge.pmd.lang.java.ast.ASTRUNSIGNEDSHIFT; import net.sourceforge.pmd.lang.java.ast.ASTRecordBody; -import net.sourceforge.pmd.lang.java.ast.ASTRecordBodyDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTRecordComponent; import net.sourceforge.pmd.lang.java.ast.ASTRecordComponentList; import net.sourceforge.pmd.lang.java.ast.ASTRecordConstructorDeclaration; @@ -873,12 +872,6 @@ public Object visit(ASTRecordBody node, Object data) { return visit((JavaNode) node, data); } - @Override - @Experimental - public Object visit(ASTRecordBodyDeclaration node, Object data) { - return visit((JavaNode) node, data); - } - @Override @Experimental public Object visit(ASTRecordConstructorDeclaration node, Object data) { diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/Java14PreviewTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/Java14PreviewTest.java index 204dd419449..1b92c6b7dc9 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/Java14PreviewTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/Java14PreviewTest.java @@ -116,36 +116,36 @@ public void innerRecords() { Assert.assertEquals(6, recordDecls.size()); ASTRecordDeclaration complex = recordDecls.get(0); - Assert.assertEquals("MyComplex", complex.getImage()); + Assert.assertEquals("MyComplex", complex.getName()); Assert.assertTrue(complex.isNested()); Assert.assertEquals(0, complex.getRecordComponents().get(0).findChildrenOfType(ASTAnnotation.class).size()); Assert.assertEquals(1, complex.getRecordComponents().get(1).findChildrenOfType(ASTAnnotation.class).size()); ASTRecordDeclaration nested = recordDecls.get(1); - Assert.assertEquals("Nested", nested.getImage()); + Assert.assertEquals("Nested", nested.getName()); Assert.assertTrue(nested.isNested()); ASTRecordDeclaration range = recordDecls.get(2); - Assert.assertEquals("Range", range.getImage()); + Assert.assertEquals("Range", range.getName()); Assert.assertEquals(2, range.getRecordComponents().size()); List rangeConstructors = range.findDescendantsOfType(ASTRecordConstructorDeclaration.class); Assert.assertEquals(1, rangeConstructors.size()); Assert.assertEquals("Range", rangeConstructors.get(0).getImage()); ASTRecordDeclaration varRec = recordDecls.get(3); - Assert.assertEquals("VarRec", varRec.getImage()); + Assert.assertEquals("VarRec", varRec.getName()); Assert.assertEquals("x", varRec.getRecordComponents().get(0).getVariableDeclaratorId().getImage()); Assert.assertTrue(varRec.getRecordComponents().get(0).isVarargs()); Assert.assertEquals(2, varRec.getRecordComponents().get(0).findChildrenOfType(ASTAnnotation.class).size()); Assert.assertEquals(1, varRec.getRecordComponents().get(0).getTypeNode().findDescendantsOfType(ASTAnnotation.class).size()); ASTRecordDeclaration arrayRec = recordDecls.get(4); - Assert.assertEquals("ArrayRec", arrayRec.getImage()); + Assert.assertEquals("ArrayRec", arrayRec.getName()); Assert.assertEquals("x", arrayRec.getRecordComponents().get(0).getVariableDeclaratorId().getImage()); Assert.assertTrue(arrayRec.getRecordComponents().get(0).getVariableDeclaratorId().hasArrayType()); ASTRecordDeclaration emptyRec = recordDecls.get(5); - Assert.assertEquals("EmptyRec", emptyRec.getImage()); + Assert.assertEquals("EmptyRec", emptyRec.getName()); Assert.assertEquals(0, emptyRec.getRecordComponents().size()); }