Merge branch 'grammar-flatten-body-declarations' into java-grammar

This commit is contained in:
Clément Fournier
2020-03-17 15:22:02 +01:00
41 changed files with 147 additions and 300 deletions

View File

@ -838,7 +838,7 @@ void ModifierList():
/*
* Declaration syntax follows.
*/
void TypeDeclaration():
void TypeDeclaration() #void:
{}
{
ModifierList()
@ -987,7 +987,7 @@ void ClassOrInterfaceBody():
"{" ( ClassOrInterfaceBodyDeclaration() )* "}"
}
void ClassOrInterfaceBodyDeclaration():
void ClassOrInterfaceBodyDeclaration() #void:
{}
{ LOOKAHEAD(["static"] "{" ) Initializer()
| ModifierList()
@ -2411,7 +2411,7 @@ void AnnotationTypeBody():
"{" ( AnnotationTypeMemberDeclaration() )* "}"
}
void AnnotationTypeMemberDeclaration():
void AnnotationTypeMemberDeclaration() #void:
{}
{
ModifierList()

View File

@ -15,7 +15,6 @@ public final class ASTAnnotationTypeBody extends AbstractJavaNode implements AST
return visitor.visit(this, data);
}
@Override
public <T> void jjtAccept(SideEffectingVisitor<T> visitor, T data) {
visitor.visit(this, data);

View File

@ -1,23 +0,0 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java.ast;
public final class ASTAnnotationTypeMemberDeclaration extends AbstractTypeBodyDeclaration {
ASTAnnotationTypeMemberDeclaration(int id) {
super(id);
}
@Override
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
@Override
public <T> void jjtAccept(SideEffectingVisitor<T> visitor, T data) {
visitor.visit(this, data);
}
}

View File

@ -8,19 +8,11 @@ package net.sourceforge.pmd.lang.java.ast;
* Marker interface for type body declarations, such as annotation members, field or method declarations.
*
* @author Clément Fournier
*
* @deprecated This type and subtypes are removed from the tree
*/
@Deprecated
public interface ASTAnyTypeBodyDeclaration extends JavaNode {
/**
* Returns the child of this declaration,
* which can be cast to a more specific node
* type using #getKind() as a cue.
*
* <p>Returns null if this is an empty declaration,
* that is, a single semicolon.
*/
JavaNode getDeclarationNode();
}

View File

@ -27,6 +27,8 @@ public interface ASTAnyTypeDeclaration
JavaQualifiableNode,
AccessNode,
TypeParamOwnerNode,
ASTBodyDeclaration,
ASTTopLevelDeclaration,
FinalizableNode {
@Override
@ -130,8 +132,8 @@ public interface ASTAnyTypeDeclaration
*
* @return The member declarations declared in this type declaration
*/
default NodeStream<ASTAnyTypeBodyDeclaration> getDeclarations() {
return getBody().children(ASTAnyTypeBodyDeclaration.class);
default NodeStream<ASTBodyDeclaration> getDeclarations() {
return getBody().getDeclarations();
}
@ -154,7 +156,7 @@ public interface ASTAnyTypeDeclaration
* class or annotation.
*/
default boolean isNested() {
return getParent() instanceof ASTAnyTypeBodyDeclaration;
return getParent() instanceof ASTTypeBody;
}
@ -174,7 +176,7 @@ public interface ASTAnyTypeDeclaration
* Returns true if this type is declared at the top-level of a file.
*/
default boolean isTopLevel() {
return getParent() instanceof ASTTypeDeclaration;
return getParent() instanceof ASTCompilationUnit;
}

View File

@ -0,0 +1,28 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java.ast;
/**
* Marker interface for declarations that can occur in a {@linkplain ASTTypeBody type body},
* such as field or method declarations. Some of those can also appear on the
* {@linkplain ASTTopLevelDeclaration top-level} of a file.
*
* <pre class="grammar">
*
* BodyDeclaration ::= {@link ASTAnyTypeDeclaration AnyTypeDeclaration}
* | {@link ASTMethodDeclaration MethodDeclaration}
* | {@link ASTConstructorDeclaration ConstructorDeclaration}
* | {@link ASTInitializer Initializer}
* | {@link ASTFieldDeclaration FieldDeclaration}
* | {@link ASTEnumConstant EnumConstant}
* | {@link ASTEmptyDeclaration EmptyDeclaration}
*
* </pre>
*
*/
public interface ASTBodyDeclaration extends JavaNode {
}

View File

@ -10,7 +10,7 @@ package net.sourceforge.pmd.lang.java.ast;
*
* <pre class="grammar">
*
* ClassOrInterfaceBody ::= "{" {@linkplain ASTClassOrInterfaceBodyDeclaration ClassOrInterfaceBodyDeclaration}* "}"
* ClassOrInterfaceBody ::= "{" {@linkplain ASTBodyDeclaration ClassOrInterfaceBodyDeclaration}* "}"
*
* </pre>
*/
@ -31,12 +31,4 @@ public final class ASTClassOrInterfaceBody extends AbstractJavaNode implements A
visitor.visit(this, data);
}
public boolean isAnonymousInnerClass() {
return getParent() instanceof ASTAllocationExpression;
}
public boolean isEnumChild() {
return getParent() instanceof ASTEnumConstant;
}
}

View File

@ -7,12 +7,12 @@ package net.sourceforge.pmd.lang.java.ast;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import net.sourceforge.pmd.annotation.InternalApi;
import net.sourceforge.pmd.lang.ast.NodeStream;
import net.sourceforge.pmd.lang.ast.RootNode;
import net.sourceforge.pmd.lang.java.typeresolution.ClassTypeResolver;
@ -68,9 +68,8 @@ public final class ASTCompilationUnit extends AbstractJavaTypeNode implements Ro
* This may be empty if this a package-info.java, or a modular
* compilation unit.
*/
public List<ASTAnyTypeDeclaration> getTypeDeclarations() {
List<ASTTypeDeclaration> tds = findChildrenOfType(ASTTypeDeclaration.class);
return tds.stream().map(it -> (ASTAnyTypeDeclaration) it.getFirstChild()).collect(Collectors.toList());
public NodeStream<ASTAnyTypeDeclaration> getTypeDeclarations() {
return children(ASTAnyTypeDeclaration.class);
}

View File

@ -14,7 +14,8 @@ package net.sourceforge.pmd.lang.java.ast;
*
* </pre>
*/
public final class ASTEmptyDeclaration extends AbstractJavaNode {
public final class ASTEmptyDeclaration extends AbstractJavaNode
implements ASTBodyDeclaration, ASTTopLevelDeclaration {
ASTEmptyDeclaration(int id) {
super(id);

View File

@ -12,7 +12,7 @@ package net.sourceforge.pmd.lang.java.ast;
* EnumBody ::= "{"
* [ {@link ASTEnumConstant EnumConstant} ( "," ( {@link ASTEnumConstant EnumConstant} )* ]
* [ "," ]
* [ ";" ( {@link ASTClassOrInterfaceBodyDeclaration ClassOrInterfaceBodyDeclaration} )* ]
* [ ";" ( {@link ASTBodyDeclaration ClassOrInterfaceBodyDeclaration} )* ]
* "}"
*
* </pre>

View File

@ -18,6 +18,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public final class ASTEnumConstant extends AbstractJavaNode
implements Annotatable,
AccessNode,
ASTBodyDeclaration,
InternalInterfaces.VariableIdOwner {
ASTEnumConstant(int id) {

View File

@ -26,6 +26,7 @@ public final class ASTFieldDeclaration extends AbstractJavaNode
Iterable<ASTVariableDeclaratorId>,
LeftRecursiveNode,
AccessNode,
ASTBodyDeclaration,
InternalInterfaces.MultiVariableIdOwner {
private JavaFieldSignature signature;

View File

@ -15,7 +15,7 @@ package net.sourceforge.pmd.lang.java.ast;
*
* @see <a href="https://docs.oracle.com/javase/specs/jls/se9/html/jls-7.html#jls-7.5">JLS 7.5</a>
*/
public final class ASTImportDeclaration extends AbstractJavaNode {
public final class ASTImportDeclaration extends AbstractJavaNode implements ASTTopLevelDeclaration {
private boolean isImportOnDemand;
private boolean isStatic;

View File

@ -14,7 +14,7 @@ package net.sourceforge.pmd.lang.java.ast;
* </pre>
*
*/
public final class ASTInitializer extends AbstractJavaNode {
public final class ASTInitializer extends AbstractJavaNode implements ASTBodyDeclaration {
private boolean isStatic;

View File

@ -31,6 +31,7 @@ public interface ASTMethodOrConstructorDeclaration
extends MethodLikeNode,
AccessNode,
SignedNode<ASTMethodOrConstructorDeclaration>,
ASTBodyDeclaration,
TypeParamOwnerNode {

View File

@ -16,8 +16,6 @@ import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
import net.sourceforge.pmd.lang.ast.NodeStream;
/**
* List of modifiers of a declaration.
*
@ -241,11 +239,7 @@ public final class ASTModifierList extends AbstractJavaNode {
@Override
public void visit(ASTAnonymousClassDeclaration node, Set<JModifier> effective) {
JavaNode enclosing = NodeStream.filterIsAny(node.ancestors(),
ASTAnyTypeDeclaration.class,
ASTEnumConstant.class,
ASTAnyTypeBodyDeclaration.class)
.first();
ASTBodyDeclaration enclosing = node.ancestors(ASTBodyDeclaration.class).first();
assert enclosing != null && !(enclosing instanceof ASTAnyTypeDeclaration)
: "Weird position for an anonymous class " + enclosing;
@ -253,9 +247,8 @@ public final class ASTModifierList extends AbstractJavaNode {
if (enclosing instanceof ASTEnumConstant) {
effective.add(STATIC);
} else {
JavaNode decl = ((ASTAnyTypeBodyDeclaration) enclosing).getDeclarationNode();
if (decl instanceof AccessNode && ((AccessNode) decl).hasModifiers(STATIC)
|| decl instanceof ASTInitializer && ((ASTInitializer) decl).isStatic()) {
if (enclosing instanceof AccessNode && ((AccessNode) enclosing).hasModifiers(STATIC)
|| enclosing instanceof ASTInitializer && ((ASTInitializer) enclosing).isStatic()) {
effective.add(STATIC);
}
}

View File

@ -17,7 +17,7 @@ package net.sourceforge.pmd.lang.java.ast;
* </pre>
*
*/
public final class ASTPackageDeclaration extends AbstractJavaNode implements Annotatable {
public final class ASTPackageDeclaration extends AbstractJavaNode implements Annotatable, ASTTopLevelDeclaration {
ASTPackageDeclaration(int id) {
super(id);

View File

@ -0,0 +1,25 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java.ast;
/**
* Marker interface for nodes that can appear on the top-level of a file.
* In these contexts, they are children of the {@link ASTCompilationUnit CompilationUnit}
* node. Note that both {@link ASTAnyTypeDeclaration AnyTypeDeclaration}
* and {@link ASTEmptyDeclaration EmptyDeclaration} can appear also in
* a {@linkplain ASTTypeBody type body}.
*
* <pre class="grammar">
*
* BodyDeclaration ::= {@link ASTAnyTypeDeclaration AnyTypeDeclaration}
* | {@link ASTImportDeclaration ImportDeclaration}
* | {@link ASTPackageDeclaration PackageDeclaration}
* | {@link ASTEmptyDeclaration EmptyDeclaration}
*
* </pre>
*/
public interface ASTTopLevelDeclaration extends JavaNode {
}

View File

@ -4,6 +4,8 @@
package net.sourceforge.pmd.lang.java.ast;
import net.sourceforge.pmd.lang.ast.NodeStream;
/**
* Body of a type declaration.
*
@ -17,4 +19,11 @@ package net.sourceforge.pmd.lang.java.ast;
* </pre>
*/
public interface ASTTypeBody extends JavaNode {
default NodeStream<ASTBodyDeclaration> getDeclarations() {
return children(ASTBodyDeclaration.class);
}
}

View File

@ -1,23 +0,0 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java.ast;
public final class ASTTypeDeclaration extends AbstractJavaTypeNode {
ASTTypeDeclaration(int id) {
super(id);
}
@Override
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
@Override
public <T> void jjtAccept(SideEffectingVisitor<T> visitor, T data) {
visitor.visit(this, data);
}
}

View File

@ -182,41 +182,6 @@ public final class ASTVariableDeclaratorId extends AbstractTypedSymbolDeclarator
return getImage();
}
/**
* Returns true if the variable declared by this node is declared final.
* Doesn't account for the "effectively-final" nuance. Resource
* declarations are implicitly final.
*/
@Override
public boolean isFinal() {
if (isResourceDeclaration()) {
// this is implicit even if "final" is not explicitly declared.
return true;
} else if (getParent() instanceof ASTLambdaParameter) {
return ((ASTLambdaParameter) getParent()).isFinal();
} else if (isPatternBinding()) {
// implicitly like final, assignment of a pattern binding is not allowed
return true;
}
if (getParent() instanceof ASTFormalParameter) {
// This accounts for exception parameters too for now
return ((ASTFormalParameter) getParent()).isFinal();
}
Node grandpa = getNthParent(2);
if (grandpa instanceof ASTLocalVariableDeclaration) {
return ((ASTLocalVariableDeclaration) grandpa).isFinal();
} else if (grandpa instanceof ASTFieldDeclaration) {
return ((ASTFieldDeclaration) grandpa).isFinal();
}
throw new IllegalStateException("All cases should be handled");
}
/**
* Returns true if this declarator id declares a resource in a try-with-resources statement.
*/
@ -237,7 +202,7 @@ public final class ASTVariableDeclaratorId extends AbstractTypedSymbolDeclarator
* since the type node is absent.
*/
public boolean isTypeInferred() {
return isLocalVariableTypeInferred() || isLambdaTypeInferred();
return getTypeNode() == null;
}
/**
@ -250,23 +215,6 @@ public final class ASTVariableDeclaratorId extends AbstractTypedSymbolDeclarator
}
private boolean isLocalVariableTypeInferred() {
if (isResourceDeclaration()) {
// covers "var" in try-with-resources
return getParent().getFirstChildOfType(ASTType.class) == null;
} else if (getNthParent(2) instanceof ASTLocalVariableDeclaration) {
// covers "var" as local variables and in for statements
return getNthParent(2).getFirstChildOfType(ASTType.class) == null;
}
return false;
}
private boolean isLambdaTypeInferred() {
return getParent() instanceof ASTLambdaParameter && ((ASTLambdaParameter) getParent()).isTypeInferred();
}
/**
* Returns the initializer of the variable, or null if it doesn't exist.
*/
@ -303,29 +251,8 @@ public final class ASTVariableDeclaratorId extends AbstractTypedSymbolDeclarator
*/
@Nullable
public ASTType getTypeNode() {
Node parent = getParent();
if (parent instanceof ASTFormalParameter) {
// ASTResource is a subclass of ASTFormal parameter for now but this will change
// and this will need to be corrected here, see #998
return ((ASTFormalParameter) parent).getTypeNode();
} else if (parent instanceof ASTCatchParameter) {
return ((ASTCatchParameter) parent).getTypeNode();
} else if (parent instanceof ASTLambdaParameter) {
return ((ASTLambdaParameter) parent).getTypeNode();
} else if (isTypeInferred()) {
// lambda expression with lax types. The type is inferred...
return null;
} else if (getParent() instanceof ASTTypeTestPattern) {
return ((ASTTypeTestPattern) getParent()).getTypeNode();
} else if (getParent() instanceof ASTRecordComponent) {
return ((ASTRecordComponent) getParent()).getTypeNode();
} else {
Node n = parent.getParent();
if (n instanceof ASTLocalVariableDeclaration || n instanceof ASTFieldDeclaration) {
return n.getFirstChildOfType(ASTType.class);
}
}
return null;
AccessNode parent = getModifierOwnerParent();
return parent.children(ASTType.class).first();
}
// @formatter:off

View File

@ -14,21 +14,4 @@ abstract class AbstractTypeBodyDeclaration extends AbstractJavaNode implements A
super(id);
}
@Override
public JavaNode getDeclarationNode() {
if (getNumChildren() == 0) {
return null;
}
// skips the annotations
AccessNode node = getFirstChildOfType(AccessNode.class);
if (node == null) {
return getFirstChildOfType(ASTInitializer.class);
}
return node;
}
}

View File

@ -444,6 +444,12 @@ public class JavaParserVisitorAdapter implements JavaParserVisitor {
return null;
}
@Deprecated
public Object visit(ASTClassOrInterfaceBodyDeclaration node, Object data) {
return null;
}
@Deprecated
public Object visit(ASTStatementExpression node, Object data) {
return null;

View File

@ -17,7 +17,6 @@ import net.sourceforge.pmd.lang.dfa.DataFlowNode;
import net.sourceforge.pmd.lang.dfa.StartOrEndDataFlowNode;
import net.sourceforge.pmd.lang.dfa.VariableAccess;
import net.sourceforge.pmd.lang.java.ast.ASTAssignmentOperator;
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBodyDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTExpression;
import net.sourceforge.pmd.lang.java.ast.ASTFormalParameter;
@ -40,9 +39,7 @@ import net.sourceforge.pmd.lang.symboltable.NameOccurrence;
public class VariableAccessVisitor extends JavaParserVisitorAdapter {
public void compute(ASTMethodDeclaration node) {
if (node.getParent() instanceof ASTClassOrInterfaceBodyDeclaration) {
this.computeNow(node);
}
this.computeNow(node);
}
public void compute(ASTConstructorDeclaration node) {

View File

@ -7,7 +7,6 @@ package net.sourceforge.pmd.lang.java.metrics;
import java.util.List;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeBodyDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration;
@ -107,10 +106,7 @@ public abstract class AbstractJavaClassMetric extends AbstractJavaMetric<ASTAnyT
private <T extends Node> List<T> getDeclarationsOfType(ASTAnyTypeDeclaration node, Class<T> tClass) {
return node.getDeclarations()
.map(ASTAnyTypeBodyDeclaration::getDeclarationNode)
.filterIs(tClass)
.toList();
return node.getDeclarations().filterIs(tClass).toList();
}

View File

@ -5,10 +5,8 @@
package net.sourceforge.pmd.lang.java.metrics;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeBodyDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration;
import net.sourceforge.pmd.lang.java.ast.MethodLikeNode;
@ -140,13 +138,6 @@ public final class JavaMetrics {
}
public static List<MethodLikeNode> findOps(ASTAnyTypeDeclaration node) {
List<MethodLikeNode> operations = new ArrayList<>();
for (ASTAnyTypeBodyDeclaration decl : node.getDeclarations()) {
if (decl.getDeclarationNode() instanceof ASTMethodOrConstructorDeclaration) {
operations.add((MethodLikeNode) decl.getDeclarationNode());
}
}
return operations;
return node.getDeclarations().filterIs(MethodLikeNode.class).toList();
}
}

View File

@ -7,7 +7,6 @@ package net.sourceforge.pmd.lang.java.metrics.internal;
import org.apache.commons.lang3.mutable.MutableInt;
import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBodyDeclaration;
import net.sourceforge.pmd.lang.java.ast.MethodLikeNode;
import net.sourceforge.pmd.lang.java.metrics.AbstractJavaClassMetric;
import net.sourceforge.pmd.lang.java.metrics.AbstractJavaOperationMetric;
@ -58,14 +57,7 @@ public final class ClassFanOutMetric {
@Override
public double computeFor(MethodLikeNode node, MetricOptions options) {
MutableInt cfo;
// look at the parent to catch annotations
if (node.getParent() instanceof ASTClassOrInterfaceBodyDeclaration) {
ASTClassOrInterfaceBodyDeclaration parent = (ASTClassOrInterfaceBodyDeclaration) node.getParent();
cfo = (MutableInt) parent.jjtAccept(new ClassFanOutVisitor(options, node), new MutableInt(0));
} else {
cfo = (MutableInt) node.jjtAccept(new ClassFanOutVisitor(options, node), new MutableInt(0));
}
MutableInt cfo = (MutableInt) node.jjtAccept(new ClassFanOutVisitor(options, node), new MutableInt(0));
return (double) cfo.getValue();
}

View File

@ -18,6 +18,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTAllocationExpression;
import net.sourceforge.pmd.lang.java.ast.ASTAndExpression;
import net.sourceforge.pmd.lang.java.ast.ASTArguments;
import net.sourceforge.pmd.lang.java.ast.ASTBlockStatement;
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBodyDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
import net.sourceforge.pmd.lang.java.ast.ASTConditionalAndExpression;
import net.sourceforge.pmd.lang.java.ast.ASTConditionalOrExpression;
@ -230,4 +231,8 @@ public abstract class AbstractJavaRule extends AbstractRule implements JavaParse
return null;
}
@Deprecated
public Object visit(ASTClassOrInterfaceBodyDeclaration node, Object data) {
return null;
}
}

View File

@ -5,7 +5,6 @@
package net.sourceforge.pmd.lang.java.rule;
import java.util.Iterator;
import java.util.List;
import org.checkerframework.checker.nullness.qual.Nullable;
@ -13,6 +12,7 @@ import net.sourceforge.pmd.Rule;
import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.NodeStream;
import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
import net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration;
@ -67,14 +67,12 @@ public class JavaRuleViolation extends ParametricRuleViolation<JavaNode> {
: node.getEnclosingType();
if (enclosing == null) {
List<ASTAnyTypeDeclaration> tds = node.getRoot().getTypeDeclarations();
enclosing = tds.stream()
.filter(AccessNode::isPublic)
.findFirst()
.orElseGet(
() -> tds.isEmpty() ? null : tds.get(0)
);
NodeStream<ASTAnyTypeDeclaration> tds = node.getRoot().getTypeDeclarations();
enclosing = tds.first(AccessNode::isPublic);
if (enclosing == null) {
enclosing = tds.first();
}
}
if (enclosing == null) {

View File

@ -10,14 +10,13 @@ import java.util.List;
import java.util.Map;
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBody;
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBodyDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTEnumBody;
import net.sourceforge.pmd.lang.java.ast.ASTEnumConstant;
import net.sourceforge.pmd.lang.java.ast.ASTEnumDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTName;
import net.sourceforge.pmd.lang.java.ast.ASTPrimaryPrefix;
import net.sourceforge.pmd.lang.java.ast.ASTPrimarySuffix;
import net.sourceforge.pmd.lang.java.ast.ASTTypeBody;
import net.sourceforge.pmd.lang.java.ast.AccessNode;
import net.sourceforge.pmd.lang.java.ast.Annotatable;
import net.sourceforge.pmd.lang.java.ast.JavaNode;
@ -87,15 +86,8 @@ public class UnusedPrivateFieldRule extends AbstractLombokAwareRule {
return false;
}
private boolean usedInOuter(NameDeclaration decl, JavaNode body) {
List<ASTClassOrInterfaceBodyDeclaration> classOrInterfaceBodyDeclarations = body
.findChildrenOfType(ASTClassOrInterfaceBodyDeclaration.class);
List<ASTEnumConstant> enumConstants = body.findChildrenOfType(ASTEnumConstant.class);
List<JavaNode> nodes = new ArrayList<>();
nodes.addAll(classOrInterfaceBodyDeclarations);
nodes.addAll(enumConstants);
for (JavaNode node : nodes) {
private boolean usedInOuter(NameDeclaration decl, ASTTypeBody body) {
for (JavaNode node : body.getDeclarations()) {
for (ASTPrimarySuffix primarySuffix : node.findDescendantsOfType(ASTPrimarySuffix.class, true)) {
if (decl.getImage().equals(primarySuffix.getImage())) {
return true; // No violation

Some files were not shown because too many files have changed in this diff Show More