public void finished()

in javac-ast-extension/src/org/jetbrains/jps/javac/ast/JavacReferenceCollectorListener.java [89:141]


  public void finished(TaskEvent e) {
    // Should be initialized only when JavaCompiler was created (jdk 6-7).
    // Otherwise JavacReferenceCollectorListener will not be loaded to javac Context.
    initializeUtilitiesIfNeeded();
    if (e.getKind() == TaskEvent.Kind.ANALYZE) {
      // javac creates an event on each processed top level declared class not file
      final CompilationUnitTree unit = e.getCompilationUnit();
      final String fileName = new File(e.getSourceFile().toUri().getPath()).getPath();

      Tree declarationToProcess = myTreeUtility.getTree(e.getTypeElement());

      boolean collectImportsData;
      boolean addedToCache = true;
      ReferenceCollector incompletelyProcessedFile = myIncompletelyProcessedFiles.get(fileName);
      if (incompletelyProcessedFile == null) {
        final int declarationCount = unit.getTypeDecls().size();
        incompletelyProcessedFile = new ReferenceCollector(declarationCount, fileName, unit);
        if (declarationCount == 1 && declarationToProcess != null) {
          addedToCache = false;
        } else {
          myIncompletelyProcessedFiles.put(fileName, incompletelyProcessedFile);
        }
        collectImportsData = true;
      }
      else {
        collectImportsData = false;
      }

      final boolean isFileDataComplete;
      if (incompletelyProcessedFile.decrementRemainDeclarationsAndGet(declarationToProcess) == 0) {
        if (addedToCache) {
          myIncompletelyProcessedFiles.remove(fileName);
        }
        isFileDataComplete = true;
      }
      else {
        isFileDataComplete = false;
      }

      if (collectImportsData) {
        scanImports(unit, incompletelyProcessedFile.myFileData.getRefs(), incompletelyProcessedFile);
      }
      myAstScanner.scan(declarationToProcess, incompletelyProcessedFile);

      if (isFileDataComplete) {
        for (AnnotationTree annotation : unit.getPackageAnnotations()) {
          myAstScanner.scan(annotation, incompletelyProcessedFile);
        }

        myDataConsumer.consume(incompletelyProcessedFile.myFileData);
      }
    }
  }