public DefaultJavaFileScannerContext(CompilationUnitTree tree, SourceFile sourceFile, File file, SemanticModel semanticModel, boolean analyseAccessors) { this.tree = tree; this.sourceFile = sourceFile; this.file = file; this.semanticModel = semanticModel; this.complexityVisitor = new ComplexityVisitor(analyseAccessors); }
@Override public int getComplexity(Tree tree) { return complexityVisitor.scan(tree); }
@Override public List<Tree> getComplexityNodes(Tree tree) { return complexityVisitor.getNodes(tree); }
@Override public void visitNode(Tree tree) { if (isClass(tree)) { classTrees.push((ClassTree) tree); } else if (isMethod(tree)) { computeMethodComplexity((MethodTree) tree); } else if (tree.is(Tree.Kind.CASE_LABEL)) { CaseLabelTree caseLabelTree = (CaseLabelTree) tree; if (!"default".equals(caseLabelTree.caseOrDefaultKeyword().text())) { complexity++; } } else { complexity++; } }
private void computeMethodComplexity(MethodTree methodTree) { BlockTree block = methodTree.block(); if (block != null && (classTrees.isEmpty() || !isAccessor(methodTree))) { blame.add(methodTree.simpleName().identifierToken()); } }
case METHOD: case CONSTRUCTOR: computeMethodComplexity((MethodTree) tree); break; case CASE_LABEL:
@Override public void leaveNode(Tree tree) { if (isClass(tree)) { classTrees.pop(); } } }
@Override public void leaveNode(Tree tree) { switch (tree.kind()) { case CLASS: case ENUM: case ANNOTATION_TYPE: classTrees.pop(); break; case METHOD: case CONSTRUCTOR: leaveMethod((MethodTree) tree); break; default: // nothing to do } }
private void computeMethodComplexity(MethodTree methodTree) { BlockTree block = methodTree.block(); if (block != null) { if (classTrees.isEmpty() || !isAccessor(methodTree)) { complexity++; } if (!block.body().isEmpty() && Iterables.getLast(block.body()).is(Tree.Kind.RETURN_STATEMENT)) { //minus one because we are going to count the return with +1 complexity--; } } }
@Override public int getMethodComplexity(ClassTree enclosingClass, MethodTree methodTree) { return complexityVisitor.scan(enclosingClass, methodTree); }
public DefaultJavaFileScannerContext(CompilationUnitTree tree, File file, SemanticModel semanticModel, @Nullable SonarComponents sonarComponents, JavaVersion javaVersion, boolean fileParsed) { this.tree = tree; this.file = file; this.semanticModel = semanticModel; this.sonarComponents = sonarComponents; this.complexityVisitor = new ComplexityVisitor(); this.javaVersion = javaVersion; this.fileParsed = fileParsed; }
@Override public List<Tree> getComplexityNodes(Tree tree) { return complexityVisitor.getNodes(tree); }
@Override public List<Tree> getComplexityNodes(Tree tree) { return complexityVisitor.scan(tree); }
public DefaultJavaFileScannerContext(CompilationUnitTree tree, File file, SemanticModel semanticModel, @Nullable SonarComponents sonarComponents, JavaVersion javaVersion, boolean fileParsed) { this.tree = tree; this.file = file; this.semanticModel = semanticModel; this.sonarComponents = sonarComponents; this.complexityVisitor = new ComplexityVisitor(); this.javaVersion = javaVersion; this.fileParsed = fileParsed; }
@Override public List<Tree> getMethodComplexityNodes(ClassTree enclosingClass, MethodTree methodTree) { return complexityVisitor.scan(enclosingClass, methodTree); }
public DefaultJavaFileScannerContext(CompilationUnitTree tree, File file, SemanticModel semanticModel, boolean analyseAccessors, @Nullable SonarComponents sonarComponents, JavaVersion javaVersion, boolean fileParsed) { this.tree = tree; this.file = file; this.semanticModel = semanticModel; this.sonarComponents = sonarComponents; this.complexityVisitor = new ComplexityVisitor(analyseAccessors); this.javaVersion = javaVersion; this.fileParsed = fileParsed; }
public List<Tree> getNodes(Tree tree) { blame.clear(); root = tree; scan(tree); root = null; return blame; }
public List<Tree> getNodes(Tree tree) { blame.clear(); root = tree; scan(tree); root = null; return blame; }