void (@NotNull PsiElement element, @NotNull AnnotationHolder holder) { if (element instanceof PsiComment && element.getText().equals("//XXX")) { checkThrowsWhenCalledTwice(holder, builder -> builder.range(element.getTextRange())); checkThrowsWhenCalledTwice(holder, builder -> builder.range(element)); checkThrowsWhenCalledTwice(holder, builder -> builder.range(element.getNode())); checkThrowsWhenCalledTwice(holder, builder -> builder.fileLevel()); checkThrowsWhenCalledTwice(holder, builder -> builder.afterEndOfLine()); checkThrowsWhenCalledTwice(holder, builder -> builder.enforcedTextAttributes(TextAttributes.ERASE_MARKER)); checkThrowsWhenCalledTwice(holder, builder -> builder.highlightType(ProblemHighlightType.ERROR)); checkThrowsWhenCalledTwice(holder, builder -> builder.gutterIconRenderer(new GutterIconRenderer() { @Override public boolean equals(Object obj) { return false; } @Override public int hashCode() { return 0; } @NotNull @Override public Icon getIcon() { return Messages.getQuestionIcon(); } })); checkThrowsWhenCalledTwice(holder, builder -> builder.needsUpdateOnTyping()); checkThrowsWhenCalledTwice(holder, builder -> builder.problemGroup(() -> "")); checkThrowsWhenCalledTwice(holder, builder -> builder.tooltip("")); checkThrowsWhenCalledTwice(holder, builder -> builder.textAttributes(CodeInsightColors.DEPRECATED_ATTRIBUTES)); IntentionAction stubIntention = new IntentionAction() { @NotNull @Override public String getText() { return "?"; } @NotNull @Override public String getFamilyName() { return ""; } @Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { return false; } @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { } @Override public boolean startInWriteAction() { return false; } }; checkThrowsWhenCalledOnFixBuilder(holder, stubIntention, Function.identity(), AnnotationBuilder.FixBuilder::batch); //must not allow for IntentionAction checkThrowsWhenCalledOnFixBuilder(holder, stubIntention, Function.identity(), AnnotationBuilder.FixBuilder::universal); //must not allow for IntentionAction LocalQuickFix stubFix = new LocalQuickFix(){ @Nls(capitalization = Nls.Capitalization.Sentence) @NotNull @Override public String getFamilyName() { return "stub"; } @Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { } }; checkThrowsWhenCalledTwiceOnFixBuilder(holder, stubFix, AnnotationBuilder.FixBuilder::batch); checkThrowsWhenCalledTwiceOnFixBuilder(holder, stubFix, AnnotationBuilder.FixBuilder::universal); checkThrowsWhenCalledOnFixBuilder(holder, stubFix, AnnotationBuilder.FixBuilder::universal, builder1 -> { builder1 = builder1.batch(); builder1 = builder1.universal(); return builder1; }); checkThrowsWhenCalledOnFixBuilder(holder, stubFix, AnnotationBuilder.FixBuilder::universal, builder1 -> { builder1 = builder1.universal(); builder1 = builder1.batch(); return builder1; }); class MyUniversal implements IntentionAction, LocalQuickFix { @Nls(capitalization = Nls.Capitalization.Sentence) @NotNull @Override public String getText() { return "?"; } @Nls(capitalization = Nls.Capitalization.Sentence) @NotNull @Override public String getFamilyName() { return getText(); } @Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { return false; } @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { } @Override public boolean startInWriteAction() { return false; } @Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { } } MyUniversal stubUniversal = new MyUniversal(); checkThrowsWhenCalledTwiceOnFixBuilder(holder, (IntentionAction)stubUniversal, AnnotationBuilder.FixBuilder::batch); checkThrowsWhenCalledTwiceOnFixBuilder(holder, (IntentionAction)stubUniversal, AnnotationBuilder.FixBuilder::universal); checkThrowsWhenCalledOnFixBuilder(holder, (IntentionAction)stubUniversal, AnnotationBuilder.FixBuilder::universal, builder1 -> { builder1 = builder1.batch(); builder1 = builder1.universal(); return builder1; }); checkThrowsWhenCalledOnFixBuilder(holder, (IntentionAction)stubUniversal, AnnotationBuilder.FixBuilder::universal, builder1 -> { builder1 = builder1.universal(); builder1 = builder1.batch(); return builder1; }); HighlightDisplayKey myDeadCodeKey = HighlightDisplayKey.findOrRegister(UnusedDeclarationInspectionBase.SHORT_NAME, UnusedDeclarationInspectionBase.getDisplayNameText(), UnusedDeclarationInspectionBase.SHORT_NAME); checkThrowsWhenCalledTwiceOnFixBuilder(holder, stubIntention, fixBuilder -> fixBuilder.key(myDeadCodeKey)); checkThrowsWhenCalledTwiceOnFixBuilder(holder, stubIntention, fixBuilder -> fixBuilder.range(new TextRange(0, 0))); try { AnnotationBuilder builder = holder.newAnnotation(HighlightSeverity.ERROR, "xxx"); builder.create(); builder.create(); fail("must not be able to call create() twice"); } catch (IllegalStateException ignored) { } iDidIt(); } }