use of net.sourceforge.pmd.lang.java.ast.ASTInitializer in project pmd by pmd.
the class UnusedPrivateMethodRule method calledFromOutsideItself.
private boolean calledFromOutsideItself(List<NameOccurrence> occs, NameDeclaration mnd) {
int callsFromOutsideMethod = 0;
for (NameOccurrence occ : occs) {
Node occNode = occ.getLocation();
ASTConstructorDeclaration enclosingConstructor = occNode.getFirstParentOfType(ASTConstructorDeclaration.class);
if (enclosingConstructor != null) {
callsFromOutsideMethod++;
// Do we miss unused private constructors here?
break;
}
ASTInitializer enclosingInitializer = occNode.getFirstParentOfType(ASTInitializer.class);
if (enclosingInitializer != null) {
callsFromOutsideMethod++;
break;
}
ASTMethodDeclaration enclosingMethod = occNode.getFirstParentOfType(ASTMethodDeclaration.class);
if (enclosingMethod == null || !mnd.getNode().jjtGetParent().equals(enclosingMethod)) {
callsFromOutsideMethod++;
}
}
return callsFromOutsideMethod == 0;
}
use of net.sourceforge.pmd.lang.java.ast.ASTInitializer in project pmd by pmd.
the class AcceptanceTest method testInitializer.
@Test
public void testInitializer() {
parseCode(TEST_INITIALIZERS);
ASTInitializer a = acu.findDescendantsOfType(ASTInitializer.class).get(0);
assertFalse(a.isStatic());
a = acu.findDescendantsOfType(ASTInitializer.class).get(1);
assertTrue(a.isStatic());
}
Aggregations