public void emitTyped()

in src/main/java/com/uber/scip/aggregator/scip/UberScipWriter.java [76:156]


  public void emitTyped(Scip.Index index) {
    // We need stable output, documents should be sorted by their relative path.
    // In java proto list is unmodifiable, so we need to create a new list.
    List<Scip.Document> processedDocuments = new ArrayList<>();
    for (Scip.Document document : index.getDocumentsList()) {
      if (isGeneratedDocument(document)) {
        if (is3rdPartyDocument(document) && !this.buildOptions.shouldShade3rdPartySymbols()) {
          processedDocuments.add(document);
          continue;
        }
        if (isIdlDocument(document) && !this.buildOptions.shouldShadeIdlSymbols()) {
          processedDocuments.add(document);
          continue;
        }
        // We need to set the relative path for each document to be consistent with the project
        // root.
        List<Scip.Occurrence> occurrences = document.getOccurrencesList();
        occurrences =
            occurrences.stream()
                .filter(
                    occurrence ->
                        isDefinition(occurrence) && !isLocalSymbol(occurrence.getSymbol()))
                .collect(Collectors.toList());

        List<Scip.SymbolInformation> symbolInformation = document.getSymbolsList();
        symbolInformation =
            symbolInformation.stream()
                .filter(symbolInfo -> !isLocalSymbol(symbolInfo.getSymbol()))
                .collect(Collectors.toList());

        processedDocuments.add(
            document.toBuilder()
                .clearOccurrences()
                .clearSymbols()
                .addAllOccurrences(occurrences)
                .addAllSymbols(symbolInformation)
                .build());
      } else {
        String path = document.getRelativePath();
        List<CompilationIssue> fileIssues = analysisIssues.get(path);
        if (this.analysisIssues.containsKey(path) && fileIssues != null) {
          Scip.Document.Builder documentBuilder = document.toBuilder();
          // No parallel execution to maintain order
          IntStream.range(0, fileIssues.size())
              .forEach(
                  i -> {
                    CompilationIssue issue = fileIssues.get(i);
                    Scip.Occurrence.Builder newOccurrence =
                        Scip.Occurrence.newBuilder()
                            .setSymbol(SCIP_LOCAL_DIAGNOSTIC_PREFIX + i)
                            .addRange((int) issue.getLineNumber()) // startLine
                            .addRange((int) issue.getColumnNumberStart()) // startCharacter
                            .addRange((int) issue.getColumnNumberEnd()) // endCharacter (estimate)
                            .addDiagnostics(
                                Scip.Diagnostic.newBuilder()
                                    .setSeverity(mapCompilationKindToScipSeverity(issue.getKind()))
                                    .setMessage(issue.getMessage())
                                    .build());

                    documentBuilder.addOccurrences(newOccurrence);
                  });
          document = documentBuilder.build();
        }
        processedDocuments.add(document);
      }
    }

    processedDocuments =
        processedDocuments.stream()
            .sorted(Comparator.comparing(Scip.Document::getRelativePath))
            .collect(Collectors.toList());
    // We are not using the default metadata builder because we want to set the project root.
    Scip.Metadata metadata = index.getMetadata();
    index =
        index.toBuilder()
            .setMetadata(metadata.toBuilder().setProjectRoot("java-code").build())
            .clearDocuments()
            .addAllDocuments(processedDocuments)
            .build();
    this.originalEmitTyped(index);
  }