Search in sources :

Example 1 with AbstractNode

use of net.sourceforge.pmd.lang.ast.AbstractNode in project pmd by pmd.

the class StatementAndBraceFinderTest method testOnlyWorksForMethodsAndConstructors.

@Test
public void testOnlyWorksForMethodsAndConstructors() {
    StatementAndBraceFinder sbf = new StatementAndBraceFinder(LanguageRegistry.getLanguage(PLSQLLanguageModule.NAME).getDefaultVersion().getLanguageVersionHandler().getDataFlowHandler());
    PLSQLNode node = new ASTMethodDeclaration(1);
    ((AbstractNode) node).testingOnlySetBeginColumn(1);
    sbf.buildDataFlowFor(node);
    // sbf.buildDataFlowFor(new ASTConstructorDeclaration(1));
    node = new ASTProgramUnit(1);
    ((AbstractNode) node).testingOnlySetBeginColumn(1);
    sbf.buildDataFlowFor(node);
}
Also used : ASTMethodDeclaration(net.sourceforge.pmd.lang.plsql.ast.ASTMethodDeclaration) AbstractNode(net.sourceforge.pmd.lang.ast.AbstractNode) PLSQLNode(net.sourceforge.pmd.lang.plsql.ast.PLSQLNode) ASTProgramUnit(net.sourceforge.pmd.lang.plsql.ast.ASTProgramUnit) Test(org.junit.Test)

Example 2 with AbstractNode

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

the class ASTUtil method parameterTypes.

public static String parameterTypes(ASTMethodDeclaration node) {
    StringBuilder sb = new StringBuilder();
    for (int ix = 0; ix < node.jjtGetNumChildren(); ix++) {
        Node sn = node.jjtGetChild(ix);
        if (sn instanceof ASTMethodDeclarator) {
            List<ASTFormalParameter> allParams = ((ASTMethodDeclarator) sn).findDescendantsOfType(ASTFormalParameter.class);
            for (ASTFormalParameter formalParam : allParams) {
                AbstractNode param = formalParam.getFirstDescendantOfType(ASTClassOrInterfaceType.class);
                if (param == null) {
                    param = formalParam.getFirstDescendantOfType(ASTPrimitiveType.class);
                }
                if (param == null) {
                    continue;
                }
                sb.append(param.getImage()).append(", ");
            }
        }
    }
    int length = sb.length();
    return length == 0 ? "" : sb.toString().substring(0, length - 2);
}
Also used : ASTMethodDeclarator(net.sourceforge.pmd.lang.java.ast.ASTMethodDeclarator) ASTPrimitiveType(net.sourceforge.pmd.lang.java.ast.ASTPrimitiveType) AbstractNode(net.sourceforge.pmd.lang.ast.AbstractNode) AbstractNode(net.sourceforge.pmd.lang.ast.AbstractNode) Node(net.sourceforge.pmd.lang.ast.Node) AbstractJavaAccessNode(net.sourceforge.pmd.lang.java.ast.AbstractJavaAccessNode) ASTFormalParameter(net.sourceforge.pmd.lang.java.ast.ASTFormalParameter)

Example 3 with AbstractNode

use of net.sourceforge.pmd.lang.ast.AbstractNode in project pmd by pmd.

the class GetCommentOnFunction method call.

public Object call(Context context, List args) throws FunctionCallException {
    if (!args.isEmpty()) {
        return Boolean.FALSE;
    }
    Node n = (Node) context.getNodeSet().get(0);
    if (n instanceof AbstractNode) {
        int codeBeginLine = ((AbstractNode) n).getBeginLine();
        int codeEndLine = ((AbstractNode) n).getEndLine();
        List<Comment> commentList = ((AbstractNode) n).getFirstParentOfType(ASTCompilationUnit.class).getComments();
        for (Comment comment : commentList) {
            if (comment.getBeginLine() == codeBeginLine || comment.getEndLine() == codeEndLine) {
                return comment.getImage();
            }
        }
    }
    return Boolean.FALSE;
}
Also used : Comment(net.sourceforge.pmd.lang.java.ast.Comment) 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)

Example 4 with AbstractNode

use of net.sourceforge.pmd.lang.ast.AbstractNode 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 5 with AbstractNode

use of net.sourceforge.pmd.lang.ast.AbstractNode 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

AbstractNode (net.sourceforge.pmd.lang.ast.AbstractNode)7 Node (net.sourceforge.pmd.lang.ast.Node)4 Comment (net.sourceforge.pmd.lang.java.ast.Comment)3 ASTCompilationUnit (net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit)2 ASTPrimitiveType (net.sourceforge.pmd.lang.java.ast.ASTPrimitiveType)2 AbstractJavaAccessNode (net.sourceforge.pmd.lang.java.ast.AbstractJavaAccessNode)2 ArrayList (java.util.ArrayList)1 ASTFormalParameter (net.sourceforge.pmd.lang.java.ast.ASTFormalParameter)1 ASTImportDeclaration (net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration)1 ASTMethodDeclarator (net.sourceforge.pmd.lang.java.ast.ASTMethodDeclarator)1 ASTResultType (net.sourceforge.pmd.lang.java.ast.ASTResultType)1 JavadocElement (net.sourceforge.pmd.lang.java.ast.JavadocElement)1 ASTMethodDeclaration (net.sourceforge.pmd.lang.plsql.ast.ASTMethodDeclaration)1 ASTProgramUnit (net.sourceforge.pmd.lang.plsql.ast.ASTProgramUnit)1 PLSQLNode (net.sourceforge.pmd.lang.plsql.ast.PLSQLNode)1 TextStyle (org.eclipse.swt.graphics.TextStyle)1 Test (org.junit.Test)1