use of net.sourceforge.pmd.lang.java.metrics.impl.visitors.CycloAssertAwareDecorator in project pmd by pmd.
the class CycloMetric method computeFor.
// TODO:cf Cyclo should develop factorized boolean operators to count them
@Override
public double computeFor(final MethodLikeNode node, MetricOptions options) {
Set<MetricOption> opts = options.getOptions();
JavaParserDecoratedVisitor visitor = new // TODO decorators are unmaintainable, change that someday
JavaParserDecoratedVisitor(// TODO decorators are unmaintainable, change that someday
CycloBaseVisitor.INSTANCE) {
// stops the visit when stumbling on a lambda or class decl
@Override
public Object visit(JavaNode localNode, Object data) {
// TODO generalize that to other metrics
return localNode.isFindBoundary() && !localNode.equals(node) ? data : super.visit(localNode, data);
}
};
if (opts.contains(CycloOption.CONSIDER_ASSERT)) {
visitor.decorateWith(new CycloAssertAwareDecorator());
}
if (!opts.contains(CycloOption.IGNORE_BOOLEAN_PATHS)) {
visitor.decorateWith(new CycloPathAwareDecorator());
}
MutableInt cyclo = (MutableInt) node.jjtAccept(visitor, new MutableInt(1));
return (double) cyclo.getValue();
}
Aggregations