@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; }
@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); } } }
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); } }
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; }
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; }
private GlobErrorAnnotator createAnnotator(PsiFile file) { annotationHolder = new AnnotationHolderImpl(new AnnotationSession(file)); return new GlobErrorAnnotator() { @Override protected AnnotationHolder getHolder() { return annotationHolder; } }; }
private LoadStatementAnnotator createAnnotator(PsiFile file) { annotationHolder = new AnnotationHolderImpl(new AnnotationSession(file)); return new LoadStatementAnnotator() { @Override protected AnnotationHolder getHolder() { return annotationHolder; } }; }
private BuiltInRuleAnnotator createAnnotator(PsiFile file) { annotationHolder = new AnnotationHolderImpl(new AnnotationSession(file)); return new BuiltInRuleAnnotator() { @Override protected AnnotationHolder getHolder() { return annotationHolder; } }; }
@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; }
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; }
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; }
/** * @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")) ); }
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; }
public AnnotationHolderImpl(@NotNull AnnotationSession session) { this(session, false); }
public AnnotationHolderImpl(@NotNull AnnotationSession session, boolean batchMode) { myAnnotationSession = session; myBatchMode = batchMode; }
@NotNull @Override public AnnotationSession getCurrentAnnotationSession() { return myAnnotationSession; }
@NotNull @Override public AnnotationSession getAnnotationSession() { return myHolder.getAnnotationSession(); }
public HighlightInfoHolder(@NotNull final PsiFile contextFile, @NotNull final HighlightInfoFilter... filters) { myContextFile = contextFile; myAnnotationSession = new AnnotationSession(contextFile); myFilters = filters; }
@NotNull public AnnotationSession getAnnotationSession() { return myAnnotationSession; }
@NotNull @Override public AnnotationSession getCurrentAnnotationSession() { return myHolder.getCurrentAnnotationSession(); }
@NotNull public AnnotationSession getCurrentAnnotationSession() {return holder.getCurrentAnnotationSession();}
/** * @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")) ); }
public AnnotationHolderImpl(@Nonnull AnnotationSession session) { this(session, false); }
public AnnotationHolderImpl(@Nonnull AnnotationSession session, boolean batchMode) { myAnnotationSession = session; myBatchMode = batchMode; }
@Nonnull @Override public AnnotationSession getCurrentAnnotationSession() { return myAnnotationSession; }
@Nonnull @Override public AnnotationSession getAnnotationSession() { return myHolder.getAnnotationSession(); }
public HighlightInfoHolder(@Nonnull final PsiFile contextFile, @Nonnull final HighlightInfoFilter... filters) { myContextFile = contextFile; myAnnotationSession = new AnnotationSession(contextFile); myFilters = filters; }
@Nonnull public AnnotationSession getAnnotationSession() { return myAnnotationSession; }