use of net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType in project pmd by pmd.
the class CouplingBetweenObjectsRule method visit.
@Override
public Object visit(ASTResultType node, Object data) {
for (int x = 0; x < node.jjtGetNumChildren(); x++) {
Node tNode = node.jjtGetChild(x);
if (tNode instanceof ASTType) {
Node reftypeNode = tNode.jjtGetChild(0);
if (reftypeNode instanceof ASTReferenceType) {
Node classOrIntType = reftypeNode.jjtGetChild(0);
if (classOrIntType instanceof ASTClassOrInterfaceType) {
Node nameNode = classOrIntType;
this.checkVariableType(nameNode, nameNode.getImage());
}
}
}
}
return super.visit(node, data);
}
use of net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType in project pmd by pmd.
the class CheckResultSetRule method visit.
@Override
public Object visit(ASTLocalVariableDeclaration node, Object data) {
ASTClassOrInterfaceType type = node.getFirstChildOfType(ASTType.class).getFirstDescendantOfType(ASTClassOrInterfaceType.class);
if (type != null && (type.getType() != null && "java.sql.ResultSet".equals(type.getType().getName()) || "ResultSet".equals(type.getImage()))) {
ASTVariableDeclarator declarator = node.getFirstChildOfType(ASTVariableDeclarator.class);
if (declarator != null) {
ASTName name = declarator.getFirstDescendantOfType(ASTName.class);
if (type.getType() != null || name != null && name.getImage().endsWith("executeQuery")) {
ASTVariableDeclaratorId id = declarator.getFirstChildOfType(ASTVariableDeclaratorId.class);
resultSetVariables.put(id.getImage(), node);
}
}
}
return super.visit(node, data);
}
use of net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType in project pmd by pmd.
the class AccessorClassGenerationRule method visit.
@Override
public Object visit(final ASTAllocationExpression node, final Object data) {
if (node.jjtGetChild(0) instanceof ASTClassOrInterfaceType) {
// Ignore primitives
final ASTClassOrInterfaceType type = (ASTClassOrInterfaceType) node.jjtGetChild(0);
final List<ASTConstructorDeclaration> constructors = privateConstructors.get(type.getImage());
if (constructors != null) {
final ASTArguments callArguments = node.getFirstChildOfType(ASTArguments.class);
// Is this really a constructor call and not an array?
if (callArguments != null) {
final ClassScope enclosingScope = node.getScope().getEnclosingScope(ClassScope.class);
for (final ASTConstructorDeclaration cd : constructors) {
// Are we within the same class scope?
if (cd.getScope().getEnclosingScope(ClassScope.class) == enclosingScope) {
break;
}
if (cd.getParameterCount() == callArguments.getArgumentCount()) {
// TODO : Check types
addViolation(data, node);
break;
}
}
}
}
}
return data;
}
use of net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType in project pmd by pmd.
the class ClassScope method determineSuper.
private SimpleTypedNameDeclaration determineSuper(Node declaringNode) {
SimpleTypedNameDeclaration result = null;
if (declaringNode instanceof ASTClassOrInterfaceDeclaration) {
ASTClassOrInterfaceDeclaration classDeclaration = (ASTClassOrInterfaceDeclaration) declaringNode;
ASTImplementsList implementsList = classDeclaration.getFirstChildOfType(ASTImplementsList.class);
if (implementsList != null) {
List<ASTClassOrInterfaceType> types = implementsList.findChildrenOfType(ASTClassOrInterfaceType.class);
SimpleTypedNameDeclaration type = convertToSimpleType(types);
result = type;
}
ASTExtendsList extendsList = classDeclaration.getFirstChildOfType(ASTExtendsList.class);
if (extendsList != null) {
List<ASTClassOrInterfaceType> types = extendsList.findChildrenOfType(ASTClassOrInterfaceType.class);
SimpleTypedNameDeclaration type = convertToSimpleType(types);
if (result == null) {
result = type;
} else {
result.addNext(type);
}
}
}
return result;
}
use of net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType in project pmd by pmd.
the class InefficientStringBufferingRule method isAllocatedStringBuffer.
private boolean isAllocatedStringBuffer(ASTAdditiveExpression node) {
ASTAllocationExpression ao = node.getFirstParentOfType(ASTAllocationExpression.class);
if (ao == null) {
return false;
}
// note that the child can be an ArrayDimsAndInits, for example, from
// java.lang.FloatingDecimal: t = new int[ nWords+wordcount+1 ];
ASTClassOrInterfaceType an = ao.getFirstChildOfType(ASTClassOrInterfaceType.class);
return an != null && TypeHelper.isEither(an, StringBuffer.class, StringBuilder.class);
}
Aggregations