record ( @NotNull @IntentionName String name, @NotNull PriorityAction.Priority priority, @NotNull List<HighlightRange> rangesToHighlight, @Nullable Icon icon, @Nullable Presentation.FixAllOption fixAllOption ) { /** * @param priority wanted priority of the action * @return new presentation with updated priority */ public @NotNull Presentation withPriority(@NotNull PriorityAction.Priority priority) { return new Presentation(name, priority, rangesToHighlight, icon, fixAllOption); } /** * @param icon wanted icon of the action (null for default or absent icon) * @return new presentation with updated icon */ public @NotNull Presentation withIcon(@Nullable Icon icon) { return new Presentation(name, priority, rangesToHighlight, icon, fixAllOption); } /** * @param thisAction the action the presentation is created for * @return a presentation for an action that has a standard "Fix all" option * to fix all the issues like this in the file. Inapplicable to intention quick-fixes. */ public @NotNull Presentation withFixAllOption(@NotNull ModCommandAction thisAction) { FixAllOption fixAllOption = new FixAllOption( AnalysisBundle.message("intention.name.apply.all.fixes.in.file", thisAction.getFamilyName()), action -> action.getClass().equals(thisAction.getClass())); return new Presentation(name, priority, rangesToHighlight, icon, fixAllOption); } /** * @param thisAction the action the presentation is created for * @param belongsToMyFamily a predicate that checks if another action belongs to this action family, * and should be applied together with this action * @return a presentation for an action that has a standard "Fix all" option * to fix all the issues like this in the file. Inapplicable to intention quick-fixes. */ public @NotNull Presentation withFixAllOption(@NotNull ModCommandAction thisAction, @NotNull Predicate<@NotNull ModCommandAction> belongsToMyFamily) { FixAllOption fixAllOption = new FixAllOption( AnalysisBundle.message("intention.name.apply.all.fixes.in.file", thisAction.getFamilyName()), belongsToMyFamily); return new Presentation(name, priority, rangesToHighlight, icon, fixAllOption); } /** * @param ranges the ranges to highlight in the current file * @return a presentation that highlights the specified ranges */ public @NotNull Presentation withHighlighting(@NotNull HighlightRange @NotNull ... ranges) { return new Presentation(name, priority, List.of(ranges), icon, fixAllOption); } public @NotNull Presentation withHighlighting(@NotNull TextRange @NotNull ... ranges) { List<HighlightRange> highlightRanges = ContainerUtil.map(ranges, r -> new HighlightRange(r, EditorColors.SEARCH_RESULT_ATTRIBUTES)); return new Presentation(name, priority, highlightRanges, icon, fixAllOption); } /** * @param name localized name of the action * @return simple presentation with NORMAL priority and no icon */ public static @NotNull Presentation of(@NotNull @IntentionName String name) { return new Presentation(name, PriorityAction.Priority.NORMAL, List.of(), null, null); } public record FixAllOption( @NotNull @IntentionName String name, @NotNull Predicate<@NotNull ModCommandAction> belongsToMyFamily ) {} /** * Represents a tuple of a TextRange and TextAttributesKey used for highlighting a specific range of text. * * @param range The TextRange to be highlighted. * @param highlightKey The TextAttributesKey to be used for highlighting the range. */ public record HighlightRange( @NotNull TextRange range, @NotNull TextAttributesKey highlightKey ) {} }