private boolean hasImports(ASTCompilationUnit cu, String className) { List<ASTImportDeclaration> imports = cu.findDescendantsOfType(ASTImportDeclaration.class); for (ASTImportDeclaration importDeclaration : imports) { ASTName name = importDeclaration.getFirstChildOfType(ASTName.class); if (name != null && name.hasImageEqualTo(className)) { return true; } } return false; } }
@Override public Object visit(ASTImportDeclaration node, Object data) { ASTName name = node.getFirstChildOfType(ASTName.class); if (!lombokImported && name != null && name.getImage() != null & name.getImage().startsWith(LOMBOK_PACKAGE)) { lombokImported = true; } return super.visit(node, data); }
/** * if there is no introduction of related packages, skip the inspection * The import statement is generally at the start of the class, do some cleaning */ private boolean hasSqlMapClientImport(List<ASTImportDeclaration> importDeclarations) { if (importDeclarations == null || importDeclarations.isEmpty()) { return false; } for (ASTImportDeclaration importDeclaration : importDeclarations) { ASTName astName = importDeclaration.getFirstChildOfType(ASTName.class); boolean hasImport = astName != null && (SQL_MAP_CLIENT_IMPORT_FULL_NAME.equals(astName.getImage()) || SQL_MAP_CLIENT_IMPORT_SIMPLE_NAME.equals(astName.getImage())); if (hasImport) { return true; } } return false; }
private boolean hasImports(ASTCompilationUnit cu, String className) { List<ASTImportDeclaration> imports = cu.findDescendantsOfType(ASTImportDeclaration.class); for (ASTImportDeclaration importDeclaration : imports) { ASTName name = importDeclaration.getFirstChildOfType(ASTName.class); if (name != null && name.hasImageEqualTo(className)) { return true; } } return false; } }
@Override public Object visit(ASTImportDeclaration node, Object data) { ASTName name = node.getFirstChildOfType(ASTName.class); if (!lombokImported && name != null && name.getImage() != null & name.getImage().startsWith(LOMBOK_PACKAGE)) { lombokImported = true; } return super.visit(node, data); }
@Override public Object visit(ASTCompilationUnit node, Object data) { Object superResult = super.visit(node, data); Info info = new Info(); List<ASTImportDeclaration> importDeclarations = node.findChildrenOfType(ASTImportDeclaration.class); for (ASTImportDeclaration importDeclaration : importDeclarations) { ASTName name = importDeclaration.getFirstChildOfType(ASTName.class); info.executorsUsed = info.executorsUsed || (name.getType() == Executors.class || Executors.class.getName().equals(name.getImage())); if (name.getImage().startsWith(Executors.class.getName() + DOT)) { info.importedExecutorsMethods.add(name.getImage()); } } List<ASTPrimaryExpression> primaryExpressions = node.findDescendantsOfType(ASTPrimaryExpression.class); for(ASTPrimaryExpression primaryExpression : primaryExpressions){ if (!info.executorsUsed && info.importedExecutorsMethods.isEmpty()) { continue; } Token initToken = (Token)primaryExpression.jjtGetFirstToken(); if (!checkInitStatement(initToken, info)) { addViolationWithMessage(data, primaryExpression,"java.concurrent.ThreadPoolCreationRule.violation.msg"); } } return superResult; }