Search in sources :

Example 1 with ASTAnyTypeDeclaration

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

the class ProjectMemoizerTest method visitWith.

private List<Integer> visitWith(ASTCompilationUnit acu, final boolean force) {
    final JavaProjectMemoizer toplevel = JavaMetrics.getFacade().getLanguageSpecificProjectMemoizer();
    final List<Integer> result = new ArrayList<>();
    acu.jjtAccept(new JavaParserVisitorReducedAdapter() {

        @Override
        public Object visit(ASTMethodOrConstructorDeclaration node, Object data) {
            MetricMemoizer<MethodLikeNode> op = toplevel.getOperationMemoizer(node.getQualifiedName());
            result.add((int) JavaMetricsComputer.INSTANCE.computeForOperation(opMetricKey, node, force, MetricOptions.emptyOptions(), op));
            return super.visit(node, data);
        }

        @Override
        public Object visit(ASTAnyTypeDeclaration node, Object data) {
            MetricMemoizer<ASTAnyTypeDeclaration> clazz = toplevel.getClassMemoizer(node.getQualifiedName());
            result.add((int) JavaMetricsComputer.INSTANCE.computeForType(classMetricKey, node, force, MetricOptions.emptyOptions(), clazz));
            return super.visit(node, data);
        }
    }, null);
    return result;
}
Also used : ArrayList(java.util.ArrayList) JavaParserVisitorReducedAdapter(net.sourceforge.pmd.lang.java.ast.JavaParserVisitorReducedAdapter) MetricMemoizer(net.sourceforge.pmd.lang.metrics.MetricMemoizer) ASTAnyTypeDeclaration(net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration) ASTMethodOrConstructorDeclaration(net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration)

Example 2 with ASTAnyTypeDeclaration

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

the class ClassTypeResolver method getClassName.

private String getClassName(ASTCompilationUnit node) {
    ASTAnyTypeDeclaration classDecl = node.getFirstDescendantOfType(ASTAnyTypeDeclaration.class);
    if (classDecl == null) {
        // package-info.java?
        return null;
    }
    if (node.declarationsAreInDefaultPackage()) {
        return classDecl.getImage();
    }
    importedOnDemand.add(node.getPackageDeclaration().getPackageNameImage());
    return classDecl.getQualifiedName().toString();
}
Also used : ASTAnyTypeDeclaration(net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration)

Example 3 with ASTAnyTypeDeclaration

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

the class ParameterizedMetricKeyTest method testAdHocMetricKey.

@Test
public void testAdHocMetricKey() {
    MetricKey<ASTAnyTypeDeclaration> adHocKey = MetricKeyUtil.of("metric", null);
    ParameterizedMetricKey key1 = ParameterizedMetricKey.getInstance(adHocKey, DUMMY_VERSION_1);
    ParameterizedMetricKey key2 = ParameterizedMetricKey.getInstance(adHocKey, DUMMY_VERSION_1);
    assertNotNull(key1);
    assertNotNull(key2);
    assertTrue(key1 == key2);
    assertEquals(key1, key2);
    assertTrue(key1.toString().contains(key1.key.name()));
    assertTrue(key1.toString().contains(key1.options.toString()));
}
Also used : ASTAnyTypeDeclaration(net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration) ParameterizedMetricKey(net.sourceforge.pmd.lang.metrics.ParameterizedMetricKey) Test(org.junit.Test)

Aggregations

ASTAnyTypeDeclaration (net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration)3 ArrayList (java.util.ArrayList)1 ASTMethodOrConstructorDeclaration (net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration)1 JavaParserVisitorReducedAdapter (net.sourceforge.pmd.lang.java.ast.JavaParserVisitorReducedAdapter)1 MetricMemoizer (net.sourceforge.pmd.lang.metrics.MetricMemoizer)1 ParameterizedMetricKey (net.sourceforge.pmd.lang.metrics.ParameterizedMetricKey)1 Test (org.junit.Test)1