use of net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration in project pmd by pmd.
the class StructureTest method testAddResultsinDFANodeContainingAddedNode.
@Test
public void testAddResultsinDFANodeContainingAddedNode() {
Structure s = new Structure(LanguageRegistry.getLanguage(JavaLanguageModule.NAME).getDefaultVersion().getLanguageVersionHandler().getDataFlowHandler());
Node n = new ASTMethodDeclaration(1);
assertEquals(n, s.createNewNode(n).getNode());
}
use of net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration in project pmd by pmd.
the class SignatureTest method testGetterDetection.
@Test
public void testGetterDetection() {
ASTCompilationUnit compilationUnit = parseJava17(GetterDetection.class);
compilationUnit.jjtAccept(new JavaParserVisitorAdapter() {
@Override
public Object visit(ASTMethodDeclaration node, Object data) {
assertEquals(Role.GETTER_OR_SETTER, Role.get(node));
return data;
}
}, null);
}
use of net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration in project pmd by pmd.
the class JavaMultifileVisitorTest method testOperationsAreThere.
@Test
public void testOperationsAreThere() {
ASTCompilationUnit acu = parseAndVisitForClass(MultifileVisitorTestData2.class);
final ProjectMirror toplevel = PackageStats.INSTANCE;
final JavaOperationSigMask opMask = new JavaOperationSigMask();
// We could parse qnames from string but probably simpler to do that
acu.jjtAccept(new JavaParserVisitorAdapter() {
@Override
public Object visit(ASTMethodDeclaration node, Object data) {
assertTrue(toplevel.hasMatchingSig(node.getQualifiedName(), opMask));
return data;
}
}, null);
}
use of net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration in project pmd by pmd.
the class JUnitUseExpectedRule method visit.
@Override
public Object visit(ASTClassOrInterfaceBodyDeclaration node, Object data) {
boolean inAnnotation = false;
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
Node child = node.jjtGetChild(i);
if (child instanceof ASTAnnotation) {
ASTName annotationName = child.getFirstDescendantOfType(ASTName.class);
if ("Test".equals(annotationName.getImage())) {
inAnnotation = true;
continue;
}
}
if (child instanceof ASTMethodDeclaration) {
boolean isJUnitMethod = isJUnitMethod((ASTMethodDeclaration) child, data);
if (inAnnotation || isJUnitMethod) {
List<Node> found = new ArrayList<>();
found.addAll((List<Node>) visit((ASTMethodDeclaration) child, data));
for (Node name : found) {
addViolation(data, name);
}
}
}
inAnnotation = false;
}
return super.visit(node, data);
}
use of net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration 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;
}
Aggregations