@Override public Object visit(ASTName node, Object data) { if (!(node.jjtGetParent() instanceof ASTImportDeclaration) && !(node.jjtGetParent() instanceof ASTPackageDeclaration)) { // This name has no qualification, it can't be unnecessarily qualified if (node.getImage().indexOf('.') < 0) { return data; } checkImports(node, data); } return data; }
/** * Checks if the given exception is declared in the method or constructor * signature. * * @param exception * to evaluate * @return true if parent node is either a method or constructor declaration */ private boolean isParentSignatureDeclaration(ASTName exception) { Node parent = exception.jjtGetParent().jjtGetParent(); return parent instanceof ASTMethodDeclaration || parent instanceof ASTConstructorDeclaration; }
Node parent = decl.jjtGetParent().jjtGetParent(); if (parent.jjtGetNumChildren() == 4) {
private Object process(Node node, Object data) { ASTClassOrInterfaceType cit = node.getFirstDescendantOfType(ASTClassOrInterfaceType.class); if (cit == null || !implClassNames.contains(cit.getImage())) { return data; } cit = cit.getFirstDescendantOfType(ASTClassOrInterfaceType.class); if (cit == null) { return data; } ASTVariableDeclaratorId decl = node.getFirstDescendantOfType(ASTVariableDeclaratorId.class); List<NameOccurrence> usages = decl.getUsages(); for (NameOccurrence no : usages) { ASTName name = (ASTName) no.getLocation(); Node n = name.jjtGetParent().jjtGetParent().jjtGetParent(); if (n instanceof ASTCastExpression) { addViolation(data, n); } } return null; } }
@Override public Object visit(ASTName node, Object data) { if (!(node.jjtGetParent() instanceof ASTImportDeclaration) && !(node.jjtGetParent() instanceof ASTPackageDeclaration)) { // This name has no qualification, it can't be unnecessarily qualified if (node.getImage().indexOf('.') < 0) { return data; } checkImports(node, data); } return data; }
/** * Checks if the given exception is declared in the method or constructor * signature. * * @param exception * to evaluate * @return true if parent node is either a method or constructor declaration */ private boolean isParentSignatureDeclaration(ASTName exception) { Node parent = exception.jjtGetParent().jjtGetParent(); return parent instanceof ASTMethodDeclaration || parent instanceof ASTConstructorDeclaration; }
@Override public Object visit(ASTName node, Object data) { /* * Only doing this for nodes where getNameDeclaration is null this means * it's not a named node, i.e. Static reference or Annotation Doing this * for memory - TODO: Investigate if there is a valid memory concern or * not */ if (node.getNameDeclaration() == null) { // Skip these scenarios as there is no type to populate in these // cases: // 1) Parent is a PackageDeclaration, which is not a type // 2) Parent is a ImportDeclaration, this is handled elsewhere. if (!(node.jjtGetParent() instanceof ASTPackageDeclaration || node.jjtGetParent() instanceof ASTImportDeclaration)) { String name = node.getImage(); if (name.indexOf(StringAndCharConstants.DOT) != -1) { name = name.substring(0, name.indexOf(StringAndCharConstants.DOT)); } populateType(node, name); } } else { // Carry over the type from the declaration if (node.getNameDeclaration().getNode() instanceof TypeNode) { node.setType(((TypeNode)node.getNameDeclaration().getNode()).getType()); } } return super.visit(node, data); }
Node parent = decl.jjtGetParent().jjtGetParent(); if (parent.jjtGetNumChildren() == 4) {
private Object process(Node node, Object data) { ASTClassOrInterfaceType cit = node.getFirstDescendantOfType(ASTClassOrInterfaceType.class); if (cit == null || !implClassNames.contains(cit.getImage())) { return data; } cit = cit.getFirstDescendantOfType(ASTClassOrInterfaceType.class); if (cit == null) { return data; } ASTVariableDeclaratorId decl = node.getFirstDescendantOfType(ASTVariableDeclaratorId.class); List<NameOccurrence> usages = decl.getUsages(); for (NameOccurrence no : usages) { ASTName name = (ASTName) no.getLocation(); Node n = name.jjtGetParent().jjtGetParent().jjtGetParent(); if (n instanceof ASTCastExpression) { addViolation(data, n); } } return null; } }