Java 类com.intellij.lang.annotation.ExternalAnnotator 实例源码

项目:intellij-ce-playground    文件:ExternalLanguageAnnotators.java   
@NotNull
public static List<ExternalAnnotator> allForFile(@NotNull Language language, @NotNull final PsiFile file) {
  List<ExternalAnnotator> annotators = INSTANCE.allForLanguage(language);
  final ExternalAnnotatorsFilter[] filters = Extensions.getExtensions(ExternalAnnotatorsFilter.EXTENSION_POINT_NAME);
  return ContainerUtil.findAll(annotators, new Condition<ExternalAnnotator>() {
    @Override
    public boolean value(ExternalAnnotator annotator) {
      for (ExternalAnnotatorsFilter filter : filters) {
        if (filter.isProhibited(annotator, file)) {
          return false;
        }
      }
      return true;
    }
  });
}
项目:intellij-ce-playground    文件:ExternalAnnotatorInspectionVisitor.java   
@NotNull
public static <Init,Result> ProblemDescriptor[] checkFileWithExternalAnnotator(@NotNull PsiFile file,
                                                                               @NotNull InspectionManager manager,
                                                                               boolean isOnTheFly,
                                                                               @NotNull ExternalAnnotator<Init,Result> annotator) {
  if (isOnTheFly) {
    // ExternalAnnotator does this work
    return ProblemDescriptor.EMPTY_ARRAY;
  }

  Init info = annotator.collectInformation(file);
  if (info != null) {
    Result annotationResult = annotator.doAnnotate(info);
    if (annotationResult == null) {
      return ProblemDescriptor.EMPTY_ARRAY;
    }
    AnnotationHolderImpl annotationHolder = new AnnotationHolderImpl(new AnnotationSession(file));
    annotator.apply(file, annotationResult, annotationHolder);
    return convertToProblemDescriptors(annotationHolder, manager, file);
  }
  return ProblemDescriptor.EMPTY_ARRAY;
}
项目:tools-idea    文件:ExternalToolPass.java   
@Override
public void doCollectInformation(@NotNull ProgressIndicator progress) {
  myDocumentChanged = false;

  final FileViewProvider viewProvider = myFile.getViewProvider();
  final Set<Language> relevantLanguages = viewProvider.getLanguages();
  for (Language language : relevantLanguages) {
    PsiFile psiRoot = viewProvider.getPsi(language);
    if (!HighlightLevelUtil.shouldInspect(psiRoot)) continue;
    final List<ExternalAnnotator> externalAnnotators = ExternalLanguageAnnotators.allForFile(language, psiRoot);

    if (!externalAnnotators.isEmpty()) {
      boolean errorFound = ((DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(myProject)).getFileStatusMap().wasErrorFound(myDocument);
      if (errorFound) return;

      for(ExternalAnnotator externalAnnotator: externalAnnotators) {
        externalAnnotator.annotate(psiRoot, myAnnotationHolder);

        final Object collectedInfo = externalAnnotator.collectInformation(psiRoot, myEditor);
        if (collectedInfo != null) {
          myAnnotator2DataMap.put(externalAnnotator, new MyData(psiRoot, collectedInfo));
        }
      }
    }
  }
}
项目:consulo    文件:ExternalToolPass.java   
@RequiredReadAction
@Override
public void doCollectInformation(@Nonnull ProgressIndicator progress) {
  myDocumentChanged = false;

  final FileViewProvider viewProvider = myFile.getViewProvider();
  final Set<Language> relevantLanguages = viewProvider.getLanguages();
  for (Language language : relevantLanguages) {
    PsiFile psiRoot = viewProvider.getPsi(language);
    if (!HighlightingLevelManager.getInstance(myProject).shouldInspect(psiRoot)) continue;
    final List<ExternalAnnotator> externalAnnotators = ExternalLanguageAnnotators.allForFile(language, psiRoot);

    if (!externalAnnotators.isEmpty()) {
      DaemonCodeAnalyzerEx daemonCodeAnalyzer = DaemonCodeAnalyzerEx.getInstanceEx(myProject);
      boolean errorFound = daemonCodeAnalyzer.getFileStatusMap().wasErrorFound(myDocument);

      for(ExternalAnnotator externalAnnotator: externalAnnotators) {
        final Object collectedInfo = externalAnnotator.collectInformation(psiRoot, myEditor, errorFound);
        if (collectedInfo != null) {
          myAnnotator2DataMap.put(externalAnnotator, new MyData(psiRoot, collectedInfo));
        }
      }
    }
  }
}
项目:intellij-ce-playground    文件:InspectionValidatorWrapper.java   
private Map<ProblemDescriptor, HighlightDisplayLevel> runXmlFileSchemaValidation(@NotNull XmlFile xmlFile) {
  final AnnotationHolderImpl holder = new AnnotationHolderImpl(new AnnotationSession(xmlFile));

  final List<ExternalAnnotator> annotators = ExternalLanguageAnnotators.allForFile(StdLanguages.XML, xmlFile);
  for (ExternalAnnotator<?, ?> annotator : annotators) {
    processAnnotator(xmlFile, holder, annotator);
  }

  if (!holder.hasAnnotations()) return Collections.emptyMap();

  Map<ProblemDescriptor, HighlightDisplayLevel> problemsMap = new LinkedHashMap<ProblemDescriptor, HighlightDisplayLevel>();
  for (final Annotation annotation : holder) {
    final HighlightInfo info = HighlightInfo.fromAnnotation(annotation);
    if (info.getSeverity() == HighlightSeverity.INFORMATION) continue;

    final PsiElement startElement = xmlFile.findElementAt(info.startOffset);
    final PsiElement endElement = info.startOffset == info.endOffset ? startElement : xmlFile.findElementAt(info.endOffset - 1);
    if (startElement == null || endElement == null) continue;

    final ProblemDescriptor descriptor =
      myInspectionManager.createProblemDescriptor(startElement, endElement, info.getDescription(), ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
                                                  false);
    final HighlightDisplayLevel level = info.getSeverity() == HighlightSeverity.ERROR? HighlightDisplayLevel.ERROR: HighlightDisplayLevel.WARNING;
    problemsMap.put(descriptor, level);
  }
  return problemsMap;
}
项目:intellij-ce-playground    文件:InspectionValidatorWrapper.java   
private static <X, Y> void processAnnotator(@NotNull XmlFile xmlFile, AnnotationHolderImpl holder, ExternalAnnotator<X, Y> annotator) {
  X initial = annotator.collectInformation(xmlFile);
  if (initial != null) {
    Y result = annotator.doAnnotate(initial);
    if (result != null) {
      annotator.apply(xmlFile, result, holder);
    }
  }
}
项目:intellij-ce-playground    文件:ExternalToolPass.java   
private void applyRelevant() {
  for (ExternalAnnotator annotator : myAnnotator2DataMap.keySet()) {
    final MyData data = myAnnotator2DataMap.get(annotator);
    if (data != null && data.myAnnotationResult != null) {
      annotator.apply(data.myPsiRoot, data.myAnnotationResult, myAnnotationHolder);
    }
  }
}
项目:intellij-ce-playground    文件:ExternalToolPass.java   
private void doAnnotate() {
  for (ExternalAnnotator annotator : DumbService.getInstance(myProject).filterByDumbAwareness(myAnnotator2DataMap.keySet())) {
    final MyData data = myAnnotator2DataMap.get(annotator);
    if (data != null) {
      data.myAnnotationResult = annotator.doAnnotate(data.myCollectedInfo);
    }
  }
}
项目:intellij-ce-playground    文件:ExternalToolPassFactory.java   
private static boolean externalAnnotatorsDefined(@NotNull PsiFile file) {
  for (Language language : file.getViewProvider().getLanguages()) {
    final List<ExternalAnnotator> externalAnnotators = ExternalLanguageAnnotators.allForFile(language, file);
    if (!externalAnnotators.isEmpty()) {
      return true;
    }
  }
  return false;
}
项目:tools-idea    文件:InspectionValidatorWrapper.java   
private Map<ProblemDescriptor, HighlightDisplayLevel> runXmlFileSchemaValidation(@NotNull XmlFile xmlFile) {
  final AnnotationHolderImpl holder = new AnnotationHolderImpl(new AnnotationSession(xmlFile));

  final List<ExternalAnnotator> annotators = ExternalLanguageAnnotators.allForFile(StdLanguages.XML, xmlFile);
  for (ExternalAnnotator annotator : annotators) {
    annotator.annotate(xmlFile, holder);
  }

  if (!holder.hasAnnotations()) return Collections.emptyMap();

  Map<ProblemDescriptor, HighlightDisplayLevel> problemsMap = new LinkedHashMap<ProblemDescriptor, HighlightDisplayLevel>();
  for (final Annotation annotation : holder) {
    final HighlightInfo info = HighlightInfo.fromAnnotation(annotation);
    if (info.getSeverity() == HighlightSeverity.INFORMATION) continue;

    final PsiElement startElement = xmlFile.findElementAt(info.startOffset);
    final PsiElement endElement = info.startOffset == info.endOffset ? startElement : xmlFile.findElementAt(info.endOffset - 1);
    if (startElement == null || endElement == null) continue;

    final ProblemDescriptor descriptor =
      myInspectionManager.createProblemDescriptor(startElement, endElement, info.getDescription(), ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
                                                  false);
    final HighlightDisplayLevel level = info.getSeverity() == HighlightSeverity.ERROR? HighlightDisplayLevel.ERROR: HighlightDisplayLevel.WARNING;
    problemsMap.put(descriptor, level);
  }
  return problemsMap;
}
项目:tools-idea    文件:ExternalLanguageAnnotators.java   
public static List<ExternalAnnotator> allForFile(Language language, final PsiFile file) {
  List<ExternalAnnotator> annotators = INSTANCE.allForLanguage(language);
  final ExternalAnnotatorsFilter[] filters = Extensions.getExtensions(ExternalAnnotatorsFilter.EXTENSION_POINT_NAME);
  return ContainerUtil.findAll(annotators, new Condition<ExternalAnnotator>() {
    @Override
    public boolean value(ExternalAnnotator annotator) {
      for (ExternalAnnotatorsFilter filter : filters) {
        if (filter.isProhibited(annotator, file)) {
          return false;
        }
      }
      return true;
    }
  });
}
项目:tools-idea    文件:ExternalToolPass.java   
public ExternalToolPass(@NotNull ExternalToolPassFactory externalToolPassFactory,
                        @NotNull PsiFile file,
                        @NotNull Editor editor,
                        int startOffset,
                        int endOffset) {
  super(file.getProject(), editor.getDocument(), false);
  myEditor = editor;
  myFile = file;
  myStartOffset = startOffset;
  myEndOffset = endOffset;
  myAnnotationHolder = new AnnotationHolderImpl(new AnnotationSession(file));

  myAnnotator2DataMap = new HashMap<ExternalAnnotator, MyData>();
  myExternalToolPassFactory = externalToolPassFactory;
}
项目:tools-idea    文件:ExternalToolPass.java   
private void collectHighlighters() {
  for (ExternalAnnotator annotator : myAnnotator2DataMap.keySet()) {
    final MyData data = myAnnotator2DataMap.get(annotator);
    if (data != null) {
      annotator.apply(data.myPsiRoot, data.myAnnotationResult, myAnnotationHolder);
    }
  }
}
项目:tools-idea    文件:ExternalToolPass.java   
private void doAnnotate() {
  for (ExternalAnnotator annotator : myAnnotator2DataMap.keySet()) {
    final MyData data = myAnnotator2DataMap.get(annotator);
    if (data != null) {
      data.myAnnotationResult = annotator.doAnnotate(data.myCollectedInfo);
    }
  }
}
项目:tools-idea    文件:ExternalToolPassFactory.java   
private static boolean externalAnnotatorsDefined(PsiFile file) {
  for (Language language : file.getViewProvider().getLanguages()) {
    final List<ExternalAnnotator> externalAnnotators = ExternalLanguageAnnotators.allForFile(language, file);
    if (!externalAnnotators.isEmpty()) {
      return true;
    }
  }
  return false;
}
项目:consulo    文件:ExternalLanguageAnnotators.java   
public static List<ExternalAnnotator> allForFile(Language language, final PsiFile file) {
  List<ExternalAnnotator> annotators = INSTANCE.allForLanguage(language);
  final ExternalAnnotatorsFilter[] filters = Extensions.getExtensions(ExternalAnnotatorsFilter.EXTENSION_POINT_NAME);
  return ContainerUtil.findAll(annotators, new Condition<ExternalAnnotator>() {
    @Override
    public boolean value(ExternalAnnotator annotator) {
      for (ExternalAnnotatorsFilter filter : filters) {
        if (filter.isProhibited(annotator, file)) {
          return false;
        }
      }
      return true;
    }
  });
}
项目:consulo    文件:ExternalToolPass.java   
public ExternalToolPass(@Nonnull ExternalToolPassFactory externalToolPassFactory,
                        @Nonnull PsiFile file,
                        @Nonnull Editor editor,
                        int startOffset,
                        int endOffset) {
  super(file.getProject(), editor.getDocument(), false);
  myEditor = editor;
  myFile = file;
  myStartOffset = startOffset;
  myEndOffset = endOffset;
  myAnnotationHolder = new AnnotationHolderImpl(new AnnotationSession(file));

  myAnnotator2DataMap = new HashMap<ExternalAnnotator, MyData>();
  myExternalToolPassFactory = externalToolPassFactory;
}
项目:consulo    文件:ExternalToolPass.java   
private void collectHighlighters() {
  for (ExternalAnnotator annotator : myAnnotator2DataMap.keySet()) {
    final MyData data = myAnnotator2DataMap.get(annotator);
    if (data != null) {
      annotator.apply(data.myPsiRoot, data.myAnnotationResult, myAnnotationHolder);
    }
  }
}
项目:consulo    文件:ExternalToolPass.java   
private void doAnnotate() {
  for (ExternalAnnotator annotator : myAnnotator2DataMap.keySet()) {
    final MyData data = myAnnotator2DataMap.get(annotator);
    if (data != null) {
      data.myAnnotationResult = annotator.doAnnotate(data.myCollectedInfo);
    }
  }
}
项目:consulo    文件:ExternalToolPassFactory.java   
private static boolean externalAnnotatorsDefined(@Nonnull PsiFile file) {
  for (Language language : file.getViewProvider().getLanguages()) {
    final List<ExternalAnnotator> externalAnnotators = ExternalLanguageAnnotators.allForFile(language, file);
    if (!externalAnnotators.isEmpty()) {
      return true;
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:ExternalAnnotatorInspectionVisitor.java   
public ExternalAnnotatorInspectionVisitor(ProblemsHolder holder, ExternalAnnotator annotator, boolean isOnTheFly) {
  myHolder = holder;
  myAnnotator = annotator;
  myIsOnTheFly = isOnTheFly;
}
项目:intellij-ce-playground    文件:AntAnnotatorsFilter.java   
@Override
public boolean isProhibited(ExternalAnnotator annotator, PsiFile file) {
  return annotator instanceof XMLExternalAnnotator &&
         file instanceof XmlFile &&
         AntDomFileDescription.isAntFile((XmlFile)file);
}
项目:form-follows-function    文件:F3Language.java   
@Nullable
public ExternalAnnotator getExternalAnnotator () {
    return new F3Annotator ();
}
项目:tools-idea    文件:AntAnnotatorsFilter.java   
@Override
public boolean isProhibited(ExternalAnnotator annotator, PsiFile file) {
  return annotator instanceof XMLExternalAnnotator &&
         file instanceof XmlFile &&
         AntDomFileDescription.isAntFile((XmlFile)file);
}
项目:consulo-apache-ant    文件:AntAnnotatorsFilter.java   
@Override
public boolean isProhibited(ExternalAnnotator annotator, PsiFile file) {
  return annotator instanceof XMLExternalAnnotator &&
         file instanceof XmlFile &&
         AntDomFileDescription.isAntFile((XmlFile)file);
}
项目:intellij-ce-playground    文件:ExternalAnnotatorsFilter.java   
boolean isProhibited(ExternalAnnotator annotator, PsiFile file);
项目:tools-idea    文件:ExternalAnnotatorsFilter.java   
boolean isProhibited(ExternalAnnotator annotator, PsiFile file);
项目:consulo    文件:ExternalAnnotatorsFilter.java   
boolean isProhibited(ExternalAnnotator annotator, PsiFile file);