Search in sources :

Example 1 with ApexParserVisitorAdapter

use of net.sourceforge.pmd.lang.apex.ast.ApexParserVisitorAdapter in project pmd by pmd.

the class ApexProjectMirrorTest method visitWith.

private List<Integer> visitWith(ApexNode<Compilation> acu, final boolean force) {
    final ApexProjectMemoizer toplevel = ApexMetrics.getFacade().getLanguageSpecificProjectMemoizer();
    final List<Integer> result = new ArrayList<>();
    acu.jjtAccept(new ApexParserVisitorAdapter() {

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

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

Example 2 with ApexParserVisitorAdapter

use of net.sourceforge.pmd.lang.apex.ast.ApexParserVisitorAdapter in project pmd by pmd.

the class ApexMultifileVisitorTest method testOperationsAreThere.

@Test
public void testOperationsAreThere() throws IOException {
    ApexNode<Compilation> acu = parseAndVisitForString(IOUtils.toString(ApexMultifileVisitorTest.class.getResourceAsStream("MetadataDeployController.cls")));
    final ApexSignatureMatcher toplevel = ApexProjectMirror.INSTANCE;
    final ApexOperationSigMask opMask = new ApexOperationSigMask();
    // We could parse qnames from string but probably simpler to do that
    acu.jjtAccept(new ApexParserVisitorAdapter() {

        @Override
        public Object visit(ASTMethod node, Object data) {
            if (!node.getImage().matches("(<clinit>|<init>|clone)")) {
                assertTrue(toplevel.hasMatchingSig(node.getQualifiedName(), opMask));
            }
            return data;
        }
    }, null);
}
Also used : Compilation(apex.jorje.semantic.ast.compilation.Compilation) ApexOperationSigMask(net.sourceforge.pmd.lang.apex.metrics.signature.ApexOperationSigMask) ASTMethod(net.sourceforge.pmd.lang.apex.ast.ASTMethod) ApexSignatureMatcher(net.sourceforge.pmd.lang.apex.metrics.ApexSignatureMatcher) ApexParserVisitorAdapter(net.sourceforge.pmd.lang.apex.ast.ApexParserVisitorAdapter) Test(org.junit.Test) ApexParserTest(net.sourceforge.pmd.lang.apex.ast.ApexParserTest)

Aggregations

ASTMethod (net.sourceforge.pmd.lang.apex.ast.ASTMethod)2 ApexParserVisitorAdapter (net.sourceforge.pmd.lang.apex.ast.ApexParserVisitorAdapter)2 Compilation (apex.jorje.semantic.ast.compilation.Compilation)1 ArrayList (java.util.ArrayList)1 ASTUserClass (net.sourceforge.pmd.lang.apex.ast.ASTUserClass)1 ApexParserTest (net.sourceforge.pmd.lang.apex.ast.ApexParserTest)1 ApexSignatureMatcher (net.sourceforge.pmd.lang.apex.metrics.ApexSignatureMatcher)1 ApexOperationSigMask (net.sourceforge.pmd.lang.apex.metrics.signature.ApexOperationSigMask)1 MetricMemoizer (net.sourceforge.pmd.lang.metrics.MetricMemoizer)1 Test (org.junit.Test)1