use of net.sourceforge.pmd.lang.java.ast.ASTName in project pmd by pmd.
the class MethodNamingConventionsRule method isOverriddenMethod.
private boolean isOverriddenMethod(ASTMethodDeclarator node) {
ASTClassOrInterfaceBodyDeclaration declaration = node.getFirstParentOfType(ASTClassOrInterfaceBodyDeclaration.class);
List<ASTMarkerAnnotation> annotations = declaration.findDescendantsOfType(ASTMarkerAnnotation.class);
for (ASTMarkerAnnotation ann : annotations) {
ASTName name = ann.getFirstChildOfType(ASTName.class);
if (name != null && name.hasImageEqualTo("Override")) {
return true;
}
}
return false;
}
use of net.sourceforge.pmd.lang.java.ast.ASTName in project pmd by pmd.
the class ClassTypeResolverTest method testFullyQualifiedType.
/**
* The type should be filled also on the ASTVariableDeclaratorId node, not
* only on the variable name declaration.
*/
@Test
public void testFullyQualifiedType() {
String source = "public class Foo {\n" + " public void bar() {\n" + " java.util.StringTokenizer st = new StringTokenizer(\"a.b.c.d\", \".\");\n" + " while (st.hasMoreTokens()) {\n" + " System.out.println(st.nextToken());\n" + " }\n" + " }\n" + "}";
ASTCompilationUnit acu = parseAndTypeResolveForString(source, "1.5");
List<ASTName> names = acu.findDescendantsOfType(ASTName.class);
ASTName theStringTokenizer = null;
for (ASTName name : names) {
if (name.hasImageEqualTo("st.hasMoreTokens")) {
theStringTokenizer = name;
break;
}
}
Assert.assertNotNull(theStringTokenizer);
VariableNameDeclaration declaration = (VariableNameDeclaration) theStringTokenizer.getNameDeclaration();
Assert.assertNotNull(declaration);
Assert.assertEquals("java.util.StringTokenizer", declaration.getTypeImage());
Assert.assertNotNull(declaration.getType());
Assert.assertSame(StringTokenizer.class, declaration.getType());
ASTVariableDeclaratorId id = (ASTVariableDeclaratorId) declaration.getNode();
Assert.assertNotNull(id.getType());
Assert.assertSame(StringTokenizer.class, id.getType());
}
use of net.sourceforge.pmd.lang.java.ast.ASTName in project pmd by pmd.
the class LocalScopeTest method testNameWithSuperIsNotFlaggedAsUnused.
@Test
public void testNameWithSuperIsNotFlaggedAsUnused() {
LocalScope scope = new LocalScope();
ASTName name = new ASTName(1);
name.setImage("foo");
ASTPrimaryPrefix prefix = new ASTPrimaryPrefix(2);
prefix.setUsesSuperModifier();
name.jjtAddChild(prefix, 1);
JavaNameOccurrence occ = new JavaNameOccurrence(name, "foo");
scope.addNameOccurrence(occ);
assertFalse(scope.getDeclarations().keySet().iterator().hasNext());
}
Aggregations