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

项目: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;
}
项目:intellij-ce-playground    文件:GroovyPostHighlightingPass.java   
@Override
public void doApplyInformationToEditor() {
  if (myUnusedDeclarations == null || myUnusedImports == null) {
    return;
  }

  AnnotationHolder annotationHolder = new AnnotationHolderImpl(new AnnotationSession(myFile));
  List<HighlightInfo> infos = new ArrayList<HighlightInfo>(myUnusedDeclarations);
  for (GrImportStatement unusedImport : myUnusedImports) {
    Annotation annotation = annotationHolder.createWarningAnnotation(calculateRangeToUse(unusedImport), GroovyInspectionBundle.message("unused.import"));
    annotation.setHighlightType(ProblemHighlightType.LIKE_UNUSED_SYMBOL);
    annotation.registerFix(GroovyQuickFixFactory.getInstance().createOptimizeImportsFix(false));
    infos.add(HighlightInfo.fromAnnotation(annotation));
  }

  UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument, 0, myFile.getTextLength(), infos, getColorsScheme(), getId());

  if (myUnusedImports != null && !myUnusedImports.isEmpty()) {
    IntentionAction fix = GroovyQuickFixFactory.getInstance().createOptimizeImportsFix(true);
    if (fix.isAvailable(myProject, myEditor, myFile) && myFile.isWritable()) {
      fix.invoke(myProject, myEditor, myFile);
    }
  }
}
项目:tools-idea    文件:GroovyPostHighlightingPass.java   
public void doApplyInformationToEditor() {
  if (myUnusedDeclarations == null || myUnusedImports == null) {
    return;
  }

  AnnotationHolder annotationHolder = new AnnotationHolderImpl(new AnnotationSession(myFile));
  List<HighlightInfo> infos = new ArrayList<HighlightInfo>(myUnusedDeclarations);
  for (GrImportStatement unusedImport : myUnusedImports) {
    Annotation annotation = annotationHolder.createWarningAnnotation(calculateRangeToUse(unusedImport), GroovyInspectionBundle.message("unused.import"));
    annotation.setHighlightType(ProblemHighlightType.LIKE_UNUSED_SYMBOL);
    annotation.registerFix(createUnusedImportIntention());
    infos.add(HighlightInfo.fromAnnotation(annotation));
  }

  UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument, 0, myFile.getTextLength(), infos, getColorsScheme(), getId());

  final Runnable optimize = myOptimizeRunnable;
  if (optimize != null && timeToOptimizeImports()) {
    PostHighlightingPass.invokeOnTheFlyImportOptimizer(new Runnable() {
      @Override
      public void run() {
        optimize.run();
      }
    }, myFile, myEditor);
  }
}
项目: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    文件:ExternalToolPass.java   
public ExternalToolPass(@NotNull ExternalToolPassFactory externalToolPassFactory,
                        @NotNull PsiFile file,
                        @NotNull Editor editor,
                        int startOffset,
                        int endOffset) {
  super(file.getProject(), editor.getDocument(), "External annotators", file, editor, new TextRange(startOffset, endOffset), false, new DefaultHighlightInfoProcessor());
  myAnnotationHolder = new AnnotationHolderImpl(new AnnotationSession(file));

  myExternalToolPassFactory = externalToolPassFactory;
}
项目:intellij    文件:GlobValidationTest.java   
private GlobErrorAnnotator createAnnotator(PsiFile file) {
  annotationHolder = new AnnotationHolderImpl(new AnnotationSession(file));
  return new GlobErrorAnnotator() {
    @Override
    protected AnnotationHolder getHolder() {
      return annotationHolder;
    }
  };
}
项目:intellij    文件:LoadStatementAnnotatorTest.java   
private LoadStatementAnnotator createAnnotator(PsiFile file) {
  annotationHolder = new AnnotationHolderImpl(new AnnotationSession(file));
  return new LoadStatementAnnotator() {
    @Override
    protected AnnotationHolder getHolder() {
      return annotationHolder;
    }
  };
}
项目:intellij    文件:BuiltInRuleAnnotatorTest.java   
private BuiltInRuleAnnotator createAnnotator(PsiFile file) {
  annotationHolder = new AnnotationHolderImpl(new AnnotationSession(file));
  return new BuiltInRuleAnnotator() {
    @Override
    protected AnnotationHolder getHolder() {
      return annotationHolder;
    }
  };
}
项目:idea-php-shopware-plugin    文件:ShopwareLightCodeInsightFixtureTestCase.java   
@NotNull
private AnnotationHolderImpl getAnnotationsAtCaret(String filename, String content) {
    PsiFile psiFile = myFixture.configureByText(filename, content);
    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

    AnnotationHolderImpl annotations = new AnnotationHolderImpl(new AnnotationSession(psiFile));

    for (Annotator annotator : LanguageAnnotators.INSTANCE.allForLanguage(psiFile.getLanguage())) {
        annotator.annotate(psiElement, annotations);
    }

    return annotations;
}
项目:idea-php-drupal-symfony2-bridge    文件:DrupalLightCodeInsightFixtureTestCase.java   
@NotNull
private AnnotationHolderImpl getAnnotationsAtCaret(String filename, String content) {
    PsiFile psiFile = myFixture.configureByText(filename, content);
    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

    AnnotationHolderImpl annotations = new AnnotationHolderImpl(new AnnotationSession(psiFile));

    for (Annotator annotator : LanguageAnnotators.INSTANCE.allForLanguage(psiFile.getLanguage())) {
        annotator.annotate(psiElement, annotations);
    }

    return annotations;
}
项目: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    文件: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;
}
项目:idea-php-symfony2-plugin    文件:TemplateAnnotationAnnotatorTest.java   
/**
 * @see TemplateAnnotationAnnotator#annotate
 */
public void testThatTemplateCreationAnnotationProvidesQuickfix() {
    PsiFile psiFile = myFixture.configureByText("foobar.php", "<?php\n" +
        "use Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Template;\n" +
        "\n" +
        "class Foobar\n" +
        "{\n" +
        "   /**\n" +
        "   * @Temp<caret>late(\"foobar.html.twig\")\n" +
        "   */\n" +
        "   public function fooAction()\n" +
        "   {\n" +
        "   }\n" +
        "}\n" +
        ""
    );

    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
    PsiElement phpDocTag = psiElement.getParent();

    AnnotationHolderImpl annotations = new AnnotationHolderImpl(new AnnotationSession(psiFile));

    new TemplateAnnotationAnnotator().annotate(new PhpAnnotationDocTagAnnotatorParameter(
        PhpIndex.getInstance(getProject()).getAnyByFQN(TwigUtil.TEMPLATE_ANNOTATION_CLASS).iterator().next(),
        (PhpDocTag) phpDocTag,
        annotations
    ));

    assertNotNull(
        annotations.stream().findFirst().filter(annotation -> annotation.getMessage().contains("Create Template"))
    );
}
项目:idea-php-symfony2-plugin    文件:SymfonyLightCodeInsightFixtureTestCase.java   
@NotNull
private AnnotationHolderImpl getAnnotationsAtCaret(String filename, String content) {
    PsiFile psiFile = myFixture.configureByText(filename, content);
    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

    AnnotationHolderImpl annotations = new AnnotationHolderImpl(new AnnotationSession(psiFile));

    for (Annotator annotator : LanguageAnnotators.INSTANCE.allForLanguage(psiFile.getLanguage())) {
        annotator.annotate(psiElement, annotations);
    }

    return annotations;
}
项目: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;
}
项目:intellij-ce-playground    文件:AnnotationHolderImpl.java   
public AnnotationHolderImpl(@NotNull AnnotationSession session) {
  this(session, false);
}
项目:intellij-ce-playground    文件:AnnotationHolderImpl.java   
public AnnotationHolderImpl(@NotNull AnnotationSession session, boolean batchMode) {
  myAnnotationSession = session;
  myBatchMode = batchMode;
}
项目:intellij-ce-playground    文件:AnnotationHolderImpl.java   
@NotNull
@Override
public AnnotationSession getCurrentAnnotationSession() {
  return myAnnotationSession;
}
项目:intellij-ce-playground    文件:CheckLevelHighlightInfoHolder.java   
@NotNull
@Override
public AnnotationSession getAnnotationSession() {
  return myHolder.getAnnotationSession();
}
项目:intellij-ce-playground    文件:HighlightInfoHolder.java   
public HighlightInfoHolder(@NotNull final PsiFile contextFile, @NotNull final HighlightInfoFilter... filters) {
  myContextFile = contextFile;
  myAnnotationSession = new AnnotationSession(contextFile);
  myFilters = filters;
}
项目:intellij-ce-playground    文件:HighlightInfoHolder.java   
@NotNull
public AnnotationSession getAnnotationSession() {
  return myAnnotationSession;
}
项目:intellij-ce-playground    文件:AliasedAnnotationHolder.java   
@NotNull
@Override
public AnnotationSession getCurrentAnnotationSession() {
  return myHolder.getCurrentAnnotationSession();
}
项目:idea-multimarkdown    文件:AnnotationState.java   
@NotNull
public AnnotationSession getCurrentAnnotationSession() {return holder.getCurrentAnnotationSession();}
项目:tools-idea    文件:AnnotationHolderImpl.java   
public AnnotationHolderImpl(@NotNull AnnotationSession session) {
  this(session, false);
}
项目:tools-idea    文件:AnnotationHolderImpl.java   
public AnnotationHolderImpl(@NotNull AnnotationSession session, boolean batchMode) {
  myAnnotationSession = session;
  myBatchMode = batchMode;
}
项目:tools-idea    文件:AnnotationHolderImpl.java   
@NotNull
@Override
public AnnotationSession getCurrentAnnotationSession() {
  return myAnnotationSession;
}
项目:tools-idea    文件:HighlightInfoHolder.java   
public HighlightInfoHolder(@NotNull final PsiFile contextFile, @NotNull final HighlightInfoFilter... filters) {
  myContextFile = contextFile;
  myAnnotationSession = new AnnotationSession(contextFile);
  myFilters = filters;
}
项目:tools-idea    文件:HighlightInfoHolder.java   
@NotNull
public AnnotationSession getAnnotationSession() {
  return myAnnotationSession;
}
项目:idea-php-symfony2-plugin    文件:TemplateAnnotationAnnotatorTest.java   
/**
 * @see TemplateAnnotationAnnotator#annotate
 */
public void testThatTemplateCreationForInvokeMethodProvidesQuickfix() {
    myFixture.copyFileToProject("controller_method.php");

    myFixture.configureByText(PhpFileType.INSTANCE, "<?php\n" +
        "namespace FooBundle\\Controller;\n" +
        "class FoobarController\n" +
        "{\n" +
        "   public function __in<caret>voke() {}\n" +
        "" +
        "}\n"
    );

    PsiFile psiFile = myFixture.configureByText("foobar.php", "<?php\n" +
        "use Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Template;\n" +
        "\n" +
        "class Foobar\n" +
        "{\n" +
        "   /**\n" +
        "   * @Temp<caret>late()\n" +
        "   */\n" +
        "   public function __invoke()\n" +
        "   {\n" +
        "   }\n" +
        "}\n" +
        ""
    );

    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
    PsiElement phpDocTag = psiElement.getParent();

    AnnotationHolderImpl annotations = new AnnotationHolderImpl(new AnnotationSession(psiFile));

    new TemplateAnnotationAnnotator().annotate(new PhpAnnotationDocTagAnnotatorParameter(
        PhpIndex.getInstance(getProject()).getAnyByFQN(TwigUtil.TEMPLATE_ANNOTATION_CLASS).iterator().next(),
        (PhpDocTag) phpDocTag,
        annotations
    ));

    assertNotNull(
        annotations.stream().findFirst().filter(annotation -> annotation.getMessage().contains("Create Template"))
    );
}
项目:consulo    文件:AnnotationHolderImpl.java   
public AnnotationHolderImpl(@Nonnull AnnotationSession session) {
  this(session, false);
}
项目:consulo    文件:AnnotationHolderImpl.java   
public AnnotationHolderImpl(@Nonnull AnnotationSession session, boolean batchMode) {
  myAnnotationSession = session;
  myBatchMode = batchMode;
}
项目:consulo    文件:AnnotationHolderImpl.java   
@Nonnull
@Override
public AnnotationSession getCurrentAnnotationSession() {
  return myAnnotationSession;
}
项目:consulo    文件:CheckLevelHighlightInfoHolder.java   
@Nonnull
@Override
public AnnotationSession getAnnotationSession() {
  return myHolder.getAnnotationSession();
}
项目:consulo    文件:HighlightInfoHolder.java   
public HighlightInfoHolder(@Nonnull final PsiFile contextFile, @Nonnull final HighlightInfoFilter... filters) {
  myContextFile = contextFile;
  myAnnotationSession = new AnnotationSession(contextFile);
  myFilters = filters;
}
项目:consulo    文件:HighlightInfoHolder.java   
@Nonnull
public AnnotationSession getAnnotationSession() {
  return myAnnotationSession;
}