Exemplo n.º 1
0
  public void analyse(Project project, SensorContext context) {
    this.project = project;
    this.context = context;

    Collection<SquidAstVisitor<LexerlessGrammar>> squidChecks = annotationCheckFactory.getChecks();
    List<SquidAstVisitor<LexerlessGrammar>> visitors = Lists.newArrayList(squidChecks);
    visitors.add(new FileLinesVisitor(project, fileLinesContextFactory));
    this.scanner =
        FlexAstScanner.create(
            createConfiguration(project), visitors.toArray(new SquidAstVisitor[visitors.size()]));
    Collection<java.io.File> files =
        InputFileUtils.toFiles(project.getFileSystem().mainFiles(Flex.KEY));
    files = ImmutableList.copyOf(Collections2.filter(files, Predicates.not(MXML_FILTER)));
    scanner.scanFiles(files);

    Collection<SourceCode> squidSourceFiles =
        scanner.getIndex().search(new QueryByType(SourceFile.class));
    save(squidSourceFiles);

    Collection<SourceCode> squidPackages =
        scanner.getIndex().search(new QueryByType(FlexSquidPackage.class));
    for (SourceCode pkg : squidPackages) {
      String packageName = pkg.getKey();
      if (!"".equals(packageName)) {
        Directory directory = resourceBridge.findDirectory(packageName);
        context.saveMeasure(directory, CoreMetrics.PACKAGES, 1.0);
      }
    }
  }
Exemplo n.º 2
0
 private void saveFunctionsComplexityDistribution(File sonarFile, SourceFile squidFile) {
   Collection<SourceCode> squidFunctionsInFile =
       scanner
           .getIndex()
           .search(new QueryByParent(squidFile), new QueryByType(SourceFunction.class));
   RangeDistributionBuilder complexityDistribution =
       new RangeDistributionBuilder(
           CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION, FUNCTIONS_DISTRIB_BOTTOM_LIMITS);
   for (SourceCode squidFunction : squidFunctionsInFile) {
     complexityDistribution.add(squidFunction.getDouble(FlexMetric.COMPLEXITY));
   }
   context.saveMeasure(
       sonarFile, complexityDistribution.build().setPersistenceMode(PersistenceMode.MEMORY));
 }
Exemplo n.º 3
0
 public boolean match(SourceCode unit) {
   switch (operator) {
     case EQUALS:
       return NumberUtils.compare(unit.getDouble(metric), value) == 0;
     case GREATER_THAN:
       return unit.getDouble(metric) > value;
     case GREATER_THAN_EQUALS:
       return unit.getDouble(metric) >= value;
     case LESS_THAN_EQUALS:
       return unit.getDouble(metric) <= value;
     case LESS_THAN:
       return unit.getDouble(metric) < value;
     default:
       throw new IllegalStateException("The operator value '" + operator + "' is unknown.");
   }
 }
Exemplo n.º 4
0
 private SourceCodeEdge createEdgeBetweenParents(
     Class<? extends SourceCode> type, SourceClass from, SourceClass to, SourceCodeEdge rootEdge) {
   SourceCode fromParent = from.getParent(type);
   SourceCode toParent = to.getParent(type);
   SourceCodeEdge parentEdge = null;
   if (canWeLinkNodes(fromParent, toParent) && rootEdge != null) {
     if (graph.getEdge(fromParent, toParent) == null) {
       parentEdge = new SourceCodeEdge(fromParent, toParent, SourceCodeEdgeUsage.USES);
       parentEdge.addRootEdge(rootEdge);
       graph.addEdge(parentEdge);
       fromParent.add(Metric.CE, 1);
       toParent.add(Metric.CA, 1);
     } else {
       parentEdge = graph.getEdge(fromParent, toParent);
       if (!parentEdge.hasAnEdgeFromRootNode(rootEdge.getFrom())) {
         toParent.add(Metric.CA, 1);
       }
       if (!parentEdge.hasAnEdgeToRootNode(rootEdge.getTo())) {
         fromParent.add(Metric.CE, 1);
       }
       parentEdge.addRootEdge(rootEdge);
     }
   }
   return parentEdge;
 }
Exemplo n.º 5
0
 private boolean canWeLinkNodes(SourceCode from, SourceCode to) {
   return from != null && to != null && !from.equals(to);
 }