@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; }
protected boolean showInfoBalloon(@NotNull AnnotationSession annotationSession) { Boolean showInfoBalloon = annotationSession.getUserData(SHOW_INFO_BALLOON_KEY); if (showInfoBalloon == null) { showInfoBalloon = CsvEditorSettingsExternalizable.getInstance().isShowInfoBalloon(); annotationSession.putUserData(SHOW_INFO_BALLOON_KEY, showInfoBalloon); } return showInfoBalloon; }
protected boolean handleSeparatorElement(@NotNull PsiElement element, @NotNull AnnotationHolder holder, IElementType elementType, CsvFile csvFile) { if (elementType == CsvTypes.COMMA) { TextAttributes textAttributes = holder.getCurrentAnnotationSession().getUserData(TAB_SEPARATOR_HIGHLIGHT_COLOR_KEY); if (!Boolean.TRUE.equals(holder.getCurrentAnnotationSession().getUserData(TAB_SEPARATOR_HIGHLIGHT_COLOR_DETERMINED_KEY))) { String separator = CsvCodeStyleSettings.getCurrentSeparator(csvFile.getProject(), csvFile.getLanguage()); if (CsvEditorSettingsExternalizable.getInstance().isHighlightTabSeparator() && separator.equals(CsvCodeStyleSettings.TAB_SEPARATOR)) { textAttributes = new TextAttributes(null, CsvEditorSettingsExternalizable.getInstance().getTabHighlightColor(), null, null, 0); holder.getCurrentAnnotationSession().putUserData(TAB_SEPARATOR_HIGHLIGHT_COLOR_KEY, textAttributes); holder.getCurrentAnnotationSession().putUserData(TAB_SEPARATOR_HIGHLIGHT_COLOR_DETERMINED_KEY, Boolean.TRUE); } } if (textAttributes != null) { Annotation annotation = holder.createAnnotation( CSV_COLUMN_INFO_SEVERITY, element.getTextRange(), showInfoBalloon(holder.getCurrentAnnotationSession()) ? "↹" : null ); annotation.setEnforcedTextAttributes(textAttributes); annotation.setNeedsUpdateOnTyping(false); } return true; } return false; }
/** * @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")) ); }
PsiElement phpDocTag = psiElement.getParent(); AnnotationHolderImpl annotations = new AnnotationHolderImpl(new AnnotationSession(psiFile));