Fixed cyclomatic complexity rule
This commit is contained in:
@ -43,6 +43,10 @@ public interface ApexParserVisitor {
|
||||
Object visit(ASTIfBlockStatement node, Object data);
|
||||
|
||||
Object visit(ASTForEachStatement node, Object data);
|
||||
|
||||
Object visit(ASTDoLoopStatement node, Object data);
|
||||
|
||||
Object visit(ASTTernaryExpression node, Object data);
|
||||
|
||||
Object visit(ASTCompilation node, Object data);
|
||||
|
||||
|
@ -125,4 +125,14 @@ public class ApexParserVisitorAdapter implements ApexParserVisitor {
|
||||
public Object visit(ASTThrowStatement node, Object data) {
|
||||
return visit((ApexNode<?>) node, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(ASTDoLoopStatement node, Object data) {
|
||||
return visit((ApexNode<?>) node, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(ASTTernaryExpression node, Object data) {
|
||||
return visit((ApexNode<?>) node, data);
|
||||
}
|
||||
}
|
||||
|
@ -80,16 +80,13 @@ public class CompilerService {
|
||||
return visitAstsFromStrings(sources, visitor, CompilerStage.POST_TYPE_RESOLVE);
|
||||
}
|
||||
|
||||
public ApexCompiler visitAstsFromStrings(List<String> sources, AstVisitor<AdditionalPassScope> visitor,
|
||||
CompilerStage compilerStage) {
|
||||
List<SourceFile> sourceFiles = sources.stream()
|
||||
.map(s -> SourceFile.builder().setBody(canonicalizeString(s)).build()).collect(Collectors.toList());
|
||||
public ApexCompiler visitAstsFromStrings(List<String> sources, AstVisitor<AdditionalPassScope> visitor, CompilerStage compilerStage) {
|
||||
List<SourceFile> sourceFiles = sources.stream().map(s -> SourceFile.builder().setBody(canonicalizeString(s)).build()).collect(Collectors.toList());
|
||||
CompilationInput compilationUnit = createCompilationInput(sourceFiles, visitor);
|
||||
return compile(compilationUnit, visitor, compilerStage);
|
||||
}
|
||||
|
||||
private ApexCompiler compile(CompilationInput compilationInput, AstVisitor<AdditionalPassScope> visitor,
|
||||
CompilerStage compilerStage) {
|
||||
private ApexCompiler compile(CompilationInput compilationInput, AstVisitor<AdditionalPassScope> visitor, CompilerStage compilerStage) {
|
||||
ApexCompiler compiler = ApexCompiler.builder().setInput(compilationInput).build();
|
||||
compiler.compile(compilerStage);
|
||||
callAdditionalPassVisitor(compiler);
|
||||
|
@ -33,6 +33,8 @@ import net.sourceforge.pmd.lang.apex.ast.ASTUserClassMethods;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTUserEnum;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTUserInterface;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTWhileLoopStatement;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTDoLoopStatement;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTTernaryExpression;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ApexNode;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ApexParserVisitor;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
@ -166,6 +168,16 @@ public abstract class AbstractApexRule extends AbstractRule implements ApexParse
|
||||
public Object visit(ASTForEachStatement node, Object data) {
|
||||
return visit((ApexNode<?>) node, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(ASTDoLoopStatement node, Object data) {
|
||||
return visit((ApexNode<?>) node, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(ASTTernaryExpression node, Object data) {
|
||||
return visit((ApexNode<?>) node, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(ASTCompilation node, Object data) {
|
||||
|
@ -8,6 +8,9 @@ import net.sourceforge.pmd.lang.apex.ast.ASTForEachStatement;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTForLoopStatement;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTIfBlockStatement;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTWhileLoopStatement;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTDoLoopStatement;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTTernaryExpression;
|
||||
import net.sourceforge.pmd.lang.apex.rule.codesize.NPathComplexityRule;
|
||||
|
||||
/**
|
||||
* @author ported from Java version of Donald A. Leckie,
|
||||
@ -31,8 +34,7 @@ public class CyclomaticComplexityRule extends StdCyclomaticComplexityRule {
|
||||
public Object visit(ASTForEachStatement node, Object data) {
|
||||
super.visit(node, data);
|
||||
|
||||
int boolCompFor = NPathComplexityRule
|
||||
.sumExpressionComplexity(node.getFirstDescendantOfType(ASTExpression.class));
|
||||
int boolCompFor = NPathComplexityRule.sumExpressionComplexity(node.getFirstDescendantOfType(ASTExpression.class));
|
||||
entryStack.peek().bumpDecisionPoints(boolCompFor);
|
||||
return data;
|
||||
}
|
||||
@ -41,8 +43,7 @@ public class CyclomaticComplexityRule extends StdCyclomaticComplexityRule {
|
||||
public Object visit(ASTForLoopStatement node, Object data) {
|
||||
super.visit(node, data);
|
||||
|
||||
int boolCompFor = NPathComplexityRule
|
||||
.sumExpressionComplexity(node.getFirstDescendantOfType(ASTExpression.class));
|
||||
int boolCompFor = NPathComplexityRule.sumExpressionComplexity(node.getFirstDescendantOfType(ASTExpression.class));
|
||||
entryStack.peek().bumpDecisionPoints(boolCompFor);
|
||||
return data;
|
||||
}
|
||||
@ -55,4 +56,22 @@ public class CyclomaticComplexityRule extends StdCyclomaticComplexityRule {
|
||||
entryStack.peek().bumpDecisionPoints(boolCompWhile);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(ASTDoLoopStatement node, Object data) {
|
||||
super.visit( node, data );
|
||||
|
||||
int boolCompDo = NPathComplexityRule.sumExpressionComplexity( node.getFirstChildOfType( ASTExpression.class ) );
|
||||
entryStack.peek().bumpDecisionPoints( boolCompDo );
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(ASTTernaryExpression node, Object data) {
|
||||
super.visit(node, data);
|
||||
|
||||
int boolCompWhile = NPathComplexityRule.sumExpressionComplexity(node.getFirstChildOfType(ASTExpression.class));
|
||||
entryStack.peek().bumpDecisionPoints(boolCompWhile);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ import net.sourceforge.pmd.lang.apex.ast.ASTForEachStatement;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTIfBlockStatement;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTMethod;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTWhileLoopStatement;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTDoLoopStatement;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTTernaryExpression;
|
||||
import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
|
||||
import net.sourceforge.pmd.lang.rule.properties.BooleanProperty;
|
||||
import net.sourceforge.pmd.lang.rule.properties.IntegerProperty;
|
||||
@ -123,6 +125,20 @@ public class StdCyclomaticComplexityRule extends AbstractApexRule {
|
||||
super.visit(node, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(ASTDoLoopStatement node, Object data) {
|
||||
entryStack.peek().bumpDecisionPoints();
|
||||
super.visit(node, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(ASTTernaryExpression node, Object data) {
|
||||
entryStack.peek().bumpDecisionPoints();
|
||||
super.visit(node, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(ASTUserInterface node, Object data) {
|
||||
|
Reference in New Issue
Block a user