Search in sources :

Example 6 with Comment

use of net.sourceforge.pmd.lang.java.ast.Comment in project pmd-eclipse-plugin by pmd.

the class ASTContentProvider method withoutHiddenOnes.

private List<Node> withoutHiddenOnes(Object parent) {
    List<Node> kids = new ArrayList<Node>();
    if (includeComments && parent instanceof ASTCompilationUnit) {
        // if (!hiddenNodeTypes.contains(Comment.class)) {
        List<Comment> comments = ((ASTCompilationUnit) parent).getComments();
        kids.addAll(comments);
    // }
    }
    AbstractNode node = (AbstractNode) parent;
    int kidCount = node.jjtGetNumChildren();
    for (int i = 0; i < kidCount; i++) {
        Node kid = node.jjtGetChild(i);
        // if (hiddenNodeTypes.contains(kid.getClass())) continue;
        if (!includeImports && kid instanceof ASTImportDeclaration) {
            continue;
        }
        if (!includeComments && kid instanceof Comment) {
            continue;
        }
        kids.add(kid);
    }
    Collections.sort(kids, BY_LINE_NUMBER);
    return kids;
}
Also used : Comment(net.sourceforge.pmd.lang.java.ast.Comment) ASTImportDeclaration(net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration) ASTCompilationUnit(net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit) AbstractNode(net.sourceforge.pmd.lang.ast.AbstractNode) AbstractNode(net.sourceforge.pmd.lang.ast.AbstractNode) Node(net.sourceforge.pmd.lang.ast.Node) ArrayList(java.util.ArrayList)

Example 7 with Comment

use of net.sourceforge.pmd.lang.java.ast.Comment in project pmd-eclipse-plugin by pmd.

the class ASTPainterHelper method layoutFor.

public TextLayout layoutFor(TreeItem item) {
    Object data = item.getData();
    if (data instanceof Comment) {
        return layoutFor((Comment) data);
    }
    if (data instanceof JavadocElement) {
        return layoutFor((JavadocElement) data);
    }
    AbstractNode node = (AbstractNode) data;
    String label = node.toString();
    TextStyle extraStyle = imageStyle;
    String extra = NodeImageDeriver.derivedTextFor(node);
    if (extra != null) {
        extraStyle = derivedStyle;
    } else {
        extra = textFor(node);
    }
    textLayout.setText(label + (extra == null ? "" : " " + extra));
    int labelLength = label.length();
    textLayout.setStyle(labelStyle, 0, labelLength);
    if (extra != null) {
        textLayout.setStyle(extraStyle, labelLength, labelLength + extra.length() + 1);
    }
    return textLayout;
}
Also used : Comment(net.sourceforge.pmd.lang.java.ast.Comment) AbstractNode(net.sourceforge.pmd.lang.ast.AbstractNode) TextStyle(org.eclipse.swt.graphics.TextStyle) JavadocElement(net.sourceforge.pmd.lang.java.ast.JavadocElement)

Aggregations

Comment (net.sourceforge.pmd.lang.java.ast.Comment)7 AbstractNode (net.sourceforge.pmd.lang.ast.AbstractNode)3 Node (net.sourceforge.pmd.lang.ast.Node)2 ASTCompilationUnit (net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit)2 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 ASTImportDeclaration (net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration)1 DummyJavaNode (net.sourceforge.pmd.lang.java.ast.DummyJavaNode)1 FormalComment (net.sourceforge.pmd.lang.java.ast.FormalComment)1 JavadocElement (net.sourceforge.pmd.lang.java.ast.JavadocElement)1 ImportWrapper (net.sourceforge.pmd.lang.rule.ImportWrapper)1 TextStyle (org.eclipse.swt.graphics.TextStyle)1