Skip to content

Commit

Permalink
[java] Get rid of RecordBodyDeclaration node
Browse files Browse the repository at this point in the history
  • Loading branch information
adangel committed Feb 28, 2020
1 parent fa28aa7 commit 0ecd1da
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 72 deletions.
2 changes: 1 addition & 1 deletion pmd-java/etc/grammar/Java.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ void RecordBody():
"}"
}

void RecordBodyDeclaration():
void RecordBodyDeclaration() #void :
{}
{
LOOKAHEAD(4) RecordConstructorDeclaration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
*
* <pre class="grammar">
*
* RecordBody ::= "{" ({@linkplain ASTRecordBodyDeclaration RecordBodyDeclaration})* "}"
* RecordBody ::= "{" ( {@linkplain ASTRecordConstructorDeclaration RecordConstructorDeclaration}
* | {@linkplain ASTClassOrInterfaceBodyDeclaration ClassOrInterfaceBodyDeclaration} )* "}"
*
* </pre>
*
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,8 @@ public boolean isFindBoundary() {
public List<ASTRecordComponent> getRecordComponents() {
return getFirstChildOfType(ASTRecordComponentList.class).findChildrenOfType(ASTRecordComponent.class);
}

public String getName() {
return getImage();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ASTRecordConstructorDeclaration> 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());
}

Expand Down

0 comments on commit 0ecd1da

Please sign in to comment.