Search in sources :

Example 1 with ASTNameList

use of net.sourceforge.pmd.lang.java.ast.ASTNameList in project pmd by pmd.

the class SignatureDeclareThrowsExceptionRule method checkExceptions.

/**
 * Search the list of thrown exceptions for Exception
 */
private void checkExceptions(Node method, Object o) {
    List<ASTName> exceptionList = Collections.emptyList();
    ASTNameList nameList = method.getFirstChildOfType(ASTNameList.class);
    if (nameList != null) {
        exceptionList = nameList.findDescendantsOfType(ASTName.class);
    }
    if (!exceptionList.isEmpty()) {
        evaluateExceptions(exceptionList, o);
    }
}
Also used : ASTName(net.sourceforge.pmd.lang.java.ast.ASTName) ASTNameList(net.sourceforge.pmd.lang.java.ast.ASTNameList)

Example 2 with ASTNameList

use of net.sourceforge.pmd.lang.java.ast.ASTNameList in project pmd by pmd.

the class UselessOverridingMethodRule method isMethodThrowingType.

// TODO: this method should be externalize into an utility class, shouldn't it ?
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;
}
Also used : ASTName(net.sourceforge.pmd.lang.java.ast.ASTName) ASTNameList(net.sourceforge.pmd.lang.java.ast.ASTNameList)

Aggregations

ASTName (net.sourceforge.pmd.lang.java.ast.ASTName)2 ASTNameList (net.sourceforge.pmd.lang.java.ast.ASTNameList)2