@Override public void scanFile(JavaFileScannerContext context) { sonarFile = fs.inputFile(fs.predicates().is(context.getFile())); classTrees.clear(); methods = 0; complexityInMethods = 0; accessors = 0; classes = 0; PublicApiChecker publicApiChecker = PublicApiChecker.newInstanceWithAccessorsHandledAsMethods(); if (separateAccessorsFromMethods) { publicApiChecker = PublicApiChecker.newInstanceWithAccessorsSeparatedFromMethods(); } publicApiChecker.scan(context.getTree()); methodComplexityDistribution = new RangeDistributionBuilder( CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION, LIMITS_COMPLEXITY_METHODS); CommentLinesVisitor commentLinesVisitor = new CommentLinesVisitor(); commentLinesVisitor.analyzeCommentLines(context.getTree()); noSonarFilter.addComponent( sensorContext.getResource(sonarFile).getEffectiveKey(), commentLinesVisitor.noSonarLines()); super.scanFile(context); // leave file. int fileComplexity = context.getComplexityNodes(context.getTree()).size(); saveMetricOnFile(CoreMetrics.CLASSES, classes); saveMetricOnFile(CoreMetrics.FUNCTIONS, methods); saveMetricOnFile(CoreMetrics.ACCESSORS, accessors); saveMetricOnFile(CoreMetrics.COMPLEXITY_IN_FUNCTIONS, complexityInMethods); saveMetricOnFile(CoreMetrics.COMPLEXITY_IN_CLASSES, fileComplexity); saveMetricOnFile(CoreMetrics.COMPLEXITY, fileComplexity); saveMetricOnFile(CoreMetrics.PUBLIC_API, publicApiChecker.getPublicApi()); saveMetricOnFile( CoreMetrics.PUBLIC_DOCUMENTED_API_DENSITY, publicApiChecker.getDocumentedPublicApiDensity()); saveMetricOnFile( CoreMetrics.PUBLIC_UNDOCUMENTED_API, publicApiChecker.getUndocumentedPublicApi()); saveMetricOnFile(CoreMetrics.COMMENT_LINES, commentLinesVisitor.commentLinesMetric()); saveMetricOnFile( CoreMetrics.STATEMENTS, new StatementVisitor().numberOfStatements(context.getTree())); saveMetricOnFile(CoreMetrics.NCLOC, new LinesOfCodeVisitor().linesOfCode(context.getTree())); sensorContext.saveMeasure( sonarFile, methodComplexityDistribution.build(true).setPersistenceMode(PersistenceMode.MEMORY)); RangeDistributionBuilder fileComplexityDistribution = new RangeDistributionBuilder( CoreMetrics.FILE_COMPLEXITY_DISTRIBUTION, LIMITS_COMPLEXITY_FILES); sensorContext.saveMeasure( sonarFile, fileComplexityDistribution .add(fileComplexity) .build(true) .setPersistenceMode(PersistenceMode.MEMORY)); saveLinesMetric(); }
private long getDevelopmentCost(DecoratorContext context) { InputFile file = fs.inputFile(fs.predicates().hasRelativePath(context.getResource().getKey())); if (file != null) { String language = file.language(); return getMeasureValue(context, sqaleRatingSettings.getSizeMetric(language, metrics)) * sqaleRatingSettings.getDevCost(language); } else { Collection<Measure> childrenMeasures = context.getChildrenMeasures(CoreMetrics.DEVELOPMENT_COST); Double sum = sum(childrenMeasures); return sum.longValue(); } }
private InputFile inputFromIOFile(File file) { return fs.inputFile(fs.predicates().is(file)); }
@Override public void visitFile(Tree scriptTree) { FileSystem fs = sensorContext.fileSystem(); this.inputFile = fs.inputFile(fs.predicates().is(getContext().getFile())); init(); }
@CheckForNull private InputFile getInputFile(String filePath) { return fs.inputFile(fs.predicates().hasRelativePath(filePath)); }