Search in sources :

Example 1 with AbstractJavaAccessTypeNode

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

the class AbstractCommentRule method assignCommentsToDeclarations.

protected void assignCommentsToDeclarations(ASTCompilationUnit cUnit) {
    SortedMap<Integer, Node> itemsByLineNumber = orderedCommentsAndDeclarations(cUnit);
    FormalComment lastComment = null;
    AbstractJavaAccessNode lastNode = null;
    for (Entry<Integer, Node> entry : itemsByLineNumber.entrySet()) {
        Node value = entry.getValue();
        if (value instanceof AbstractJavaAccessNode) {
            AbstractJavaAccessNode node = (AbstractJavaAccessNode) value;
            // maybe the last comment is within the last node
            if (lastComment != null && isCommentNotWithin(lastComment, lastNode, node) && isCommentBefore(lastComment, node)) {
                node.comment(lastComment);
                lastComment = null;
            }
            if (!(node instanceof AbstractJavaAccessTypeNode)) {
                lastNode = node;
            }
        } else if (value instanceof FormalComment) {
            lastComment = (FormalComment) value;
        }
    }
}
Also used : AbstractJavaAccessNode(net.sourceforge.pmd.lang.java.ast.AbstractJavaAccessNode) FormalComment(net.sourceforge.pmd.lang.java.ast.FormalComment) Node(net.sourceforge.pmd.lang.ast.Node) AbstractJavaAccessNode(net.sourceforge.pmd.lang.java.ast.AbstractJavaAccessNode) AbstractJavaAccessTypeNode(net.sourceforge.pmd.lang.java.ast.AbstractJavaAccessTypeNode) AbstractJavaAccessTypeNode(net.sourceforge.pmd.lang.java.ast.AbstractJavaAccessTypeNode)

Aggregations

Node (net.sourceforge.pmd.lang.ast.Node)1 AbstractJavaAccessNode (net.sourceforge.pmd.lang.java.ast.AbstractJavaAccessNode)1 AbstractJavaAccessTypeNode (net.sourceforge.pmd.lang.java.ast.AbstractJavaAccessTypeNode)1 FormalComment (net.sourceforge.pmd.lang.java.ast.FormalComment)1