private boolean isInStaticInitializer(ASTAllocationExpression node) { ASTInitializer initializer = node.getFirstParentOfType(ASTInitializer.class); return initializer != null && initializer.isStatic(); }
private boolean isAddShutdownHook(ASTAllocationExpression node) { ASTBlockStatement blockStatement = node.getFirstParentOfType(ASTBlockStatement.class); if (blockStatement == null) { return false; } Token token = (Token)blockStatement.jjtGetFirstToken(); return Runtime.class.getSimpleName().equals(token.image); }
private boolean threadFactoryVariable(ASTAllocationExpression node) { ASTMethodDeclaration methodDeclaration = node.getFirstParentOfType(ASTMethodDeclaration.class); if (methodDeclaration == null) { return false; } ASTVariableDeclarator variableDeclarator = methodDeclaration.getFirstParentOfType(ASTVariableDeclarator.class); return variableDeclarator != null && variableDeclarator.getType() == ThreadFactory.class; }
private boolean isInPrimaryOrProtectedMethod(ASTAllocationExpression node) { ASTMethodDeclaration methodDeclaration = node.getFirstParentOfType(ASTMethodDeclaration.class); return methodDeclaration != null && returnThread(methodDeclaration) && (methodDeclaration.isPrivate() || methodDeclaration.isProtected()); }
private boolean isInNewThreadMethod(ASTAllocationExpression node) { ASTMethodDeclaration methodDeclaration = node.getFirstParentOfType(ASTMethodDeclaration.class); if (methodDeclaration == null) { return false; } if (!returnThread(methodDeclaration)) { return false; } if (!METHOD_NEW_THREAD.equals(methodDeclaration.getMethodName())) { return false; } List<ASTFormalParameter> parameters = methodDeclaration.getFirstDescendantOfType(ASTFormalParameters.class) .findChildrenOfType(ASTFormalParameter.class); return parameters.size() == 1 && parameters.get(0).getFirstChildOfType(ASTType.class).getType() == Runnable.class; }
private boolean checkForNamingClass(ASTAllocationExpression node) { ASTClassOrInterfaceDeclaration classOrInterfaceDeclaration = node.getFirstParentOfType(ASTClassOrInterfaceDeclaration.class); if (classOrInterfaceDeclaration == null) { return false; } ASTImplementsList implementsList = classOrInterfaceDeclaration.getFirstChildOfType(ASTImplementsList.class); if (implementsList == null) { return false; } List<ASTClassOrInterfaceType> interfaceTypes = implementsList.findChildrenOfType(ASTClassOrInterfaceType.class); for (ASTClassOrInterfaceType type : interfaceTypes) { if (type.getType() == ThreadFactory.class) { return true; } } return false; } }
if (node.getFirstParentOfType(ASTLambdaExpression.class) != null) { return super.visit(node, data); ASTFieldDeclaration fieldDeclaration = node.getFirstParentOfType(ASTFieldDeclaration.class); if (node.getDataFlowNode() == null && node.getFirstParentOfType(ASTLambdaExpression.class) != null) { if (fieldDeclaration == null || fieldDeclaration.getType() != ThreadFactory.class) { return addViolationAndReturn(node, data);