2 * Copyright 2000-2013 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.intellij.codeInsight.intention.impl;
19 import com.intellij.codeInsight.daemon.impl.HighlightInfo;
20 import com.intellij.codeInsight.intention.IntentionAction;
21 import com.intellij.openapi.project.DumbService;
22 import com.intellij.openapi.project.PossiblyDumbAware;
23 import com.intellij.openapi.util.Comparing;
24 import com.intellij.openapi.diagnostic.Logger;
25 import org.jetbrains.annotations.NotNull;
28 import java.util.List;
29 import java.util.ArrayList;
34 class IntentionActionWithTextCaching implements Comparable<IntentionActionWithTextCaching>, PossiblyDumbAware {
35 private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.intention.impl.IntentionActionWithTextCaching");
36 private final List<IntentionAction> myOptionIntentions = new ArrayList<IntentionAction>();
37 private final List<IntentionAction> myOptionErrorFixes = new ArrayList<IntentionAction>();
38 private final List<IntentionAction> myOptionInspectionFixes = new ArrayList<IntentionAction>();
39 private final String myText;
40 private final IntentionAction myAction;
41 private final String myDisplayName;
42 private final Icon myIcon;
44 IntentionActionWithTextCaching(IntentionAction action){
45 this(action, action.getText(), null);
48 IntentionActionWithTextCaching(HighlightInfo.IntentionActionDescriptor action){
49 this(action.getAction(), action.getDisplayName(), action.getIcon());
52 private IntentionActionWithTextCaching(IntentionAction action, String displayName, Icon icon) {
54 myText = action.getText();
55 // needed for checking errors in user written actions
56 //noinspection ConstantConditions
57 LOG.assertTrue(myText != null, "action "+action.getClass()+" text returned null");
59 myDisplayName = displayName;
66 public void addIntention(final IntentionAction action) {
67 myOptionIntentions.add(action);
69 public void addErrorFix(final IntentionAction action) {
70 myOptionErrorFixes.add(action);
72 public void addInspectionFix(final IntentionAction action) {
73 myOptionInspectionFixes.add(action);
76 public IntentionAction getAction() {
80 public List<IntentionAction> getOptionIntentions() {
81 return myOptionIntentions;
84 public List<IntentionAction> getOptionErrorFixes() {
85 return myOptionErrorFixes;
88 public List<IntentionAction> getOptionInspectionFixes() {
89 return myOptionInspectionFixes;
92 public String getToolName() {
96 public String toString() {
101 public int compareTo(@NotNull final IntentionActionWithTextCaching other) {
102 if (myAction instanceof Comparable) {
103 return ((Comparable)myAction).compareTo(other.getAction());
105 else if (other.getAction() instanceof Comparable) {
106 return ((Comparable)other.getAction()).compareTo(myAction);
108 return Comparing.compare(getText(), other.getText());
111 public Icon getIcon() {
116 public boolean isDumbAware() {
117 return DumbService.isDumbAware(myAction);