@Override public void visitNode(Tree tree) { List<? extends Tree> trees = Collections.emptyList(); switch (tree.kind()) { case INITIALIZER: case STATIC_INITIALIZER: trees = ((BlockTree) tree).body(); break; case VARIABLE: trees = visitVariable((VariableTree) tree); break; case LAMBDA_EXPRESSION: trees = visitLambda((LambdaExpressionTree) tree); break; case METHOD: case CONSTRUCTOR: trees = visitMethod((MethodTree) tree); break; case FOR_STATEMENT: case FOR_EACH_STATEMENT: case WHILE_STATEMENT: case DO_STATEMENT: executableLines.add(tree.lastToken().line()); break; default: // Do nothing particular } computeExecutableLines(trees); }
@Override public void leaveFile(AstNode astNode) { FileLinesContext fileLinesContext = sonarComponents.fileLinesContextFor(getContext().getFile()); // TODO minimize access to files, another one in LinesVisitor int fileLength; try { fileLength = Files.readLines(getContext().getFile(), charset).size(); } catch (IOException e) { throw Throwables.propagate(e); } for (int line = 1; line <= fileLength; line++) { fileLinesContext.setIntValue(CoreMetrics.NCLOC_DATA_KEY, line, linesOfCode.contains(line) ? 1 : 0); fileLinesContext.setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, line, linesOfComments.contains(line) ? 1 : 0); } fileLinesContext.save(); linesOfCode.clear(); linesOfComments.clear(); }
private List<? extends Tree> visitVariable(VariableTree variableTree) { ExpressionTree initializer = variableTree.initializer(); if(initializer != null && !isConstant(variableTree)) { return Lists.newArrayList(initializer); } if(variableTree.parent().is(CATCH)) { // catch variable are counted as executable lines new ExecutableLinesTokenVisitor().scanTree(variableTree); } return Collections.emptyList(); }
if (sonarComponents != null) { if(!sonarComponents.isSonarLintContext()) { codeVisitors = Iterables.concat(codeVisitors, Arrays.asList(new FileLinesVisitor(sonarComponents), new SyntaxHighlighterVisitor(sonarComponents))); testCodeVisitors.add(new SyntaxHighlighterVisitor(sonarComponents));
if (sonarComponents != null) { if(!sonarComponents.isSonarLintContext()) { codeVisitors = Iterables.concat(codeVisitors, Arrays.asList(new FileLinesVisitor(sonarComponents), new SyntaxHighlighterVisitor(sonarComponents))); testCodeVisitors.add(new SyntaxHighlighterVisitor(sonarComponents));
codeVisitors, Arrays.asList( new FileLinesVisitor(sonarComponents, conf.getCharset()), new SyntaxHighlighterVisitor(sonarComponents, conf.getCharset())
@Override public void visitNode(Tree tree) { List<? extends Tree> trees = Collections.emptyList(); switch (tree.kind()) { case INITIALIZER: case STATIC_INITIALIZER: trees = ((BlockTree) tree).body(); break; case VARIABLE: trees = visitVariable((VariableTree) tree); break; case LAMBDA_EXPRESSION: trees = visitLambda((LambdaExpressionTree) tree); break; case METHOD: case CONSTRUCTOR: trees = visitMethod((MethodTree) tree); break; case FOR_STATEMENT: case FOR_EACH_STATEMENT: case WHILE_STATEMENT: case DO_STATEMENT: executableLines.add(tree.lastToken().line()); break; default: // Do nothing particular } computeExecutableLines(trees); }
private List<? extends Tree> visitVariable(VariableTree variableTree) { ExpressionTree initializer = variableTree.initializer(); if(initializer != null && !isConstant(variableTree)) { return Lists.newArrayList(initializer); } if(variableTree.parent().is(CATCH)) { // catch variable are counted as executable lines new ExecutableLinesTokenVisitor().scanTree(variableTree); } return Collections.emptyList(); }
private void setupAstScanner(AstScanner astScanner, Iterable<CodeVisitor> visitorsToBridge, List<File> classpath, JavaConfiguration conf, @Nullable SonarComponents sonarComponents) { if(sonarComponents != null) { astScanner.accept(new FileLinesVisitor(sonarComponents, conf.getCharset())); astScanner.accept(new SyntaxHighlighterVisitor(sonarComponents, conf.getCharset())); } VisitorsBridge visitorsBridgeTest = new VisitorsBridge(visitorsToBridge, classpath, sonarComponents); visitorsBridgeTest.setCharset(conf.getCharset()); visitorsBridgeTest.setAnalyseAccessors(conf.separatesAccessorsFromMethods()); astScanner.accept(visitorsBridgeTest); }