Search in sources :

Example 1 with DummyJavaNode

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

the class ClassScopeTest method testCantContainsSuperToString.

@Test
public void testCantContainsSuperToString() {
    ClassNameDeclaration classDeclaration = new ClassNameDeclaration(null);
    ClassScope s = new ClassScope("Foo", classDeclaration);
    JavaNode node = new DummyJavaNode(1);
    node.setImage("super.toString");
    assertFalse(s.contains(new JavaNameOccurrence(node, node.getImage())));
}
Also used : DummyJavaNode(net.sourceforge.pmd.lang.java.ast.DummyJavaNode) DummyJavaNode(net.sourceforge.pmd.lang.java.ast.DummyJavaNode) JavaNode(net.sourceforge.pmd.lang.java.ast.JavaNode) Test(org.junit.Test) EnumTest(net.sourceforge.pmd.lang.java.symboltable.testdata.InnerClass.TheInnerClass.EnumTest)

Example 2 with DummyJavaNode

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

the class ClassScopeTest method testContainsStaticVariablePrefixedWithClassName.

@Test
public void testContainsStaticVariablePrefixedWithClassName() {
    ClassNameDeclaration classDeclaration = new ClassNameDeclaration(null);
    ClassScope s = new ClassScope("Foo", classDeclaration);
    ASTVariableDeclaratorId node = new ASTVariableDeclaratorId(1);
    node.setImage("X");
    s.addDeclaration(new VariableNameDeclaration(node));
    JavaNode node2 = new DummyJavaNode(2);
    node2.setImage("Foo.X");
    assertTrue(s.contains(new JavaNameOccurrence(node2, node2.getImage())));
}
Also used : ASTVariableDeclaratorId(net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId) DummyJavaNode(net.sourceforge.pmd.lang.java.ast.DummyJavaNode) DummyJavaNode(net.sourceforge.pmd.lang.java.ast.DummyJavaNode) JavaNode(net.sourceforge.pmd.lang.java.ast.JavaNode) Test(org.junit.Test) EnumTest(net.sourceforge.pmd.lang.java.symboltable.testdata.InnerClass.TheInnerClass.EnumTest)

Example 3 with DummyJavaNode

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

the class UnusedImportsRule method visitComments.

private void visitComments(ASTCompilationUnit node) {
    if (imports.isEmpty()) {
        return;
    }
    for (Comment comment : node.getComments()) {
        if (!(comment instanceof FormalComment)) {
            continue;
        }
        for (Pattern p : PATTERNS) {
            Matcher m = p.matcher(comment.getImage());
            while (m.find()) {
                String s = m.group(1);
                imports.remove(new ImportWrapper(s, s, new DummyJavaNode(-1)));
                if (m.groupCount() > 1) {
                    s = m.group(2);
                    if (s != null) {
                        String[] params = s.split("\\s*,\\s*");
                        for (String param : params) {
                            final int firstDot = param.indexOf('.');
                            final String expectedImportName;
                            if (firstDot == -1) {
                                expectedImportName = param;
                            } else {
                                expectedImportName = param.substring(0, firstDot);
                            }
                            imports.remove(new ImportWrapper(param, expectedImportName, new DummyJavaNode(-1)));
                        }
                    }
                }
                if (imports.isEmpty()) {
                    return;
                }
            }
        }
    }
}
Also used : FormalComment(net.sourceforge.pmd.lang.java.ast.FormalComment) Comment(net.sourceforge.pmd.lang.java.ast.Comment) Pattern(java.util.regex.Pattern) FormalComment(net.sourceforge.pmd.lang.java.ast.FormalComment) ImportWrapper(net.sourceforge.pmd.lang.rule.ImportWrapper) Matcher(java.util.regex.Matcher) DummyJavaNode(net.sourceforge.pmd.lang.java.ast.DummyJavaNode)

Aggregations

DummyJavaNode (net.sourceforge.pmd.lang.java.ast.DummyJavaNode)3 JavaNode (net.sourceforge.pmd.lang.java.ast.JavaNode)2 EnumTest (net.sourceforge.pmd.lang.java.symboltable.testdata.InnerClass.TheInnerClass.EnumTest)2 Test (org.junit.Test)2 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 ASTVariableDeclaratorId (net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId)1 Comment (net.sourceforge.pmd.lang.java.ast.Comment)1 FormalComment (net.sourceforge.pmd.lang.java.ast.FormalComment)1 ImportWrapper (net.sourceforge.pmd.lang.rule.ImportWrapper)1