Search in sources :

Example 21 with ASTFormalParameter

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

the class UnusedFormalParameterRule method isSerializationMethod.

private boolean isSerializationMethod(ASTMethodDeclaration node) {
    ASTMethodDeclarator declarator = node.getFirstDescendantOfType(ASTMethodDeclarator.class);
    List<ASTFormalParameter> parameters = declarator.findDescendantsOfType(ASTFormalParameter.class);
    if (node.isPrivate() && "readObject".equals(node.getMethodName()) && parameters.size() == 1 && throwsOneException(node, InvalidObjectException.class)) {
        ASTType type = parameters.get(0).getTypeNode();
        if (type.getType() == ObjectInputStream.class || ObjectInputStream.class.getSimpleName().equals(type.getTypeImage()) || ObjectInputStream.class.getName().equals(type.getTypeImage())) {
            return true;
        }
    }
    return false;
}
Also used : ASTMethodDeclarator(net.sourceforge.pmd.lang.java.ast.ASTMethodDeclarator) ASTType(net.sourceforge.pmd.lang.java.ast.ASTType) InvalidObjectException(java.io.InvalidObjectException) ASTFormalParameter(net.sourceforge.pmd.lang.java.ast.ASTFormalParameter) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

ASTFormalParameter (net.sourceforge.pmd.lang.java.ast.ASTFormalParameter)21 ASTFormalParameters (net.sourceforge.pmd.lang.java.ast.ASTFormalParameters)8 Node (net.sourceforge.pmd.lang.ast.Node)7 ASTPrimitiveType (net.sourceforge.pmd.lang.java.ast.ASTPrimitiveType)5 ASTMethodDeclarator (net.sourceforge.pmd.lang.java.ast.ASTMethodDeclarator)4 ASTType (net.sourceforge.pmd.lang.java.ast.ASTType)4 ASTVariableDeclaratorId (net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId)4 ArrayList (java.util.ArrayList)3 ASTClassOrInterfaceType (net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType)3 Test (org.junit.Test)3 List (java.util.List)2 Map (java.util.Map)2 ASTCompilationUnit (net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit)2 ASTReferenceType (net.sourceforge.pmd.lang.java.ast.ASTReferenceType)2 ASTTryStatement (net.sourceforge.pmd.lang.java.ast.ASTTryStatement)2 VariableNameDeclaration (net.sourceforge.pmd.lang.java.symboltable.VariableNameDeclaration)2 InvalidObjectException (java.io.InvalidObjectException)1 ObjectInputStream (java.io.ObjectInputStream)1 RuleContext (net.sourceforge.pmd.RuleContext)1 AbstractNode (net.sourceforge.pmd.lang.ast.AbstractNode)1