/** * Returns the exception names listed in the {@code throws} clause * of this method declaration, or null if there are none. */ public ASTNameList getThrows() { return getFirstChildOfType(ASTNameList.class); }
/** * Returns the result type node of the method. */ public ASTResultType getResultType() { return getFirstChildOfType(ASTResultType.class); }
/** * Returns the method declarator. Never null. */ public ASTMethodDeclarator getMethodDeclarator() { return getFirstChildOfType(ASTMethodDeclarator.class); } }
/** * Returns the block defined by this method, or * null if the method is abstract. */ public ASTBlock getBlock() { return getFirstChildOfType(ASTBlock.class); }
/** * Returns the simple name of the method. */ public String getMethodName() { return getFirstChildOfType(ASTMethodDeclarator.class).getImage(); }
public ASTFormalParameters getFormalParameters() { return getFirstChildOfType(ASTMethodDeclarator.class).getFirstChildOfType(ASTFormalParameters.class); }
private boolean isMethodThrowingType(ASTMethodDeclaration node, List<String> exceptedExceptions) { boolean result = false; ASTNameList thrownsExceptions = node.getFirstChildOfType(ASTNameList.class); if (thrownsExceptions != null) { List<ASTName> names = thrownsExceptions.findChildrenOfType(ASTName.class); for (ASTName name : names) { for (String exceptedException : exceptedExceptions) { if (exceptedException.equals(name.getImage())) { result = true; } } } } return result; }
@Override public Object visit(final ASTMethodDeclaration decl, final Object data) { if (shouldReport(decl)) { addViolationWithMessage(data, decl, String.format(MESSAGE, decl.getFirstChildOfType(ASTMethodDeclarator.class).getImage(), "method")); } return super.visit(decl, data); }
private ASTClassOrInterfaceType getTypeOfMethodCall(ASTPrimarySuffix node) { ASTClassOrInterfaceType type = null; ASTName methodName = node.jjtGetParent().getFirstChildOfType(ASTPrimaryPrefix.class) .getFirstChildOfType(ASTName.class); if (methodName != null) { ClassScope classScope = node.getScope().getEnclosingScope(ClassScope.class); Map<MethodNameDeclaration, List<NameOccurrence>> methods = classScope.getMethodDeclarations(); for (Map.Entry<MethodNameDeclaration, List<NameOccurrence>> e : methods.entrySet()) { if (e.getKey().getName().equals(methodName.getImage())) { type = e.getKey().getNode().getFirstParentOfType(ASTMethodDeclaration.class) .getFirstChildOfType(ASTResultType.class) .getFirstDescendantOfType(ASTClassOrInterfaceType.class); break; } } } return type; }
@Override public Object visit(ASTMethodDeclaration node, Object data) { createMethodScope(node); ASTMethodDeclarator md = node.getFirstChildOfType(ASTMethodDeclarator.class); node.getScope().getEnclosingScope(ClassScope.class).addDeclaration(new MethodNameDeclaration(md)); cont(node); return data; }
@Override public Object visit(ASTMethodDeclaration node, Object data) { /* * original XPath rule was //MethodDeclaration [ResultType * //PrimitiveType [@Image='int'] [//MethodDeclarator [@Image='hashcode' * or @Image='HashCode' or @Image='Hashcode'] * [not(FormalParameters/*)]]] */ ASTResultType type = node.getResultType(); ASTMethodDeclarator decl = node.getFirstChildOfType(ASTMethodDeclarator.class); String name = decl.getImage(); if ("hashcode".equalsIgnoreCase(name) && !"hashCode".equals(name) && decl.jjtGetChild(0).jjtGetNumChildren() == 0 && type.jjtGetNumChildren() != 0) { Node t = type.jjtGetChild(0).jjtGetChild(0); if (t instanceof ASTPrimitiveType && "int".equals(t.getImage())) { addViolation(data, node); return data; } } return super.visit(node, data); }
@Override public Object visit(final ASTMethodDeclaration node, final Object data) { final ASTMethodDeclarator methodDeclarator = node.getFirstChildOfType(ASTMethodDeclarator.class); if (!isCloneMethod(methodDeclarator)) { return data;
.getFirstChildOfType(ASTBlock.class);
/** * Returns the result type node of the method. */ public ASTResultType getResultType() { return getFirstChildOfType(ASTResultType.class); }
/** * Returns the block defined by this method, or * null if the method is abstract. */ public ASTBlock getBlock() { return getFirstChildOfType(ASTBlock.class); }
/** * Returns the method declarator. Never null. */ public ASTMethodDeclarator getMethodDeclarator() { return getFirstChildOfType(ASTMethodDeclarator.class); } }
/** * Returns the simple name of the method. */ public String getMethodName() { return getFirstChildOfType(ASTMethodDeclarator.class).getImage(); }
private boolean returnThread(ASTMethodDeclaration methodDeclaration) { ASTResultType resultType = methodDeclaration.getFirstChildOfType(ASTResultType.class); ASTType type = resultType.getFirstChildOfType(ASTType.class); return type != null && type.getType() == Thread.class; }
@Override public Object visit(final ASTMethodDeclaration decl, final Object data) { if (shouldReport(decl)) { addViolationWithMessage(data, decl, String.format(MESSAGE, decl.getFirstChildOfType(ASTMethodDeclarator.class).getImage(), "method")); } return super.visit(decl, data); }
@Override public Object visit(ASTMethodDeclaration node, Object data) { createMethodScope(node); ASTMethodDeclarator md = node.getFirstChildOfType(ASTMethodDeclarator.class); node.getScope().getEnclosingScope(ClassScope.class).addDeclaration(new MethodNameDeclaration(md)); cont(node); return data; }