2 * Copyright 2000-2009 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
.intention
.IntentionAction
;
20 import com
.intellij
.openapi
.util
.Comparing
;
21 import com
.intellij
.openapi
.diagnostic
.Logger
;
24 import java
.util
.List
;
25 import java
.util
.ArrayList
;
30 class IntentionActionWithTextCaching
implements Comparable
<IntentionActionWithTextCaching
> {
31 private static final Logger LOG
= Logger
.getInstance("#com.intellij.codeInsight.intention.impl.IntentionActionWithTextCaching");
32 private final List
<IntentionAction
> myOptionIntentions
;
33 private final List
<IntentionAction
> myOptionErrorFixes
;
34 private final String myText
;
35 private final IntentionAction myAction
;
36 private final String myDisplayName
;
37 private final List
<IntentionAction
> myOptionInspectionFixes
;
38 private final Icon myIcon
;
40 IntentionActionWithTextCaching(IntentionAction action
, String displayName
){
41 this(action
, displayName
, null);
44 IntentionActionWithTextCaching(IntentionAction action
, String displayName
, Icon icon
) {
46 myOptionIntentions
= new ArrayList
<IntentionAction
>();
47 myOptionErrorFixes
= new ArrayList
<IntentionAction
>();
48 myOptionInspectionFixes
= new ArrayList
<IntentionAction
>();
49 myText
= action
.getText();
50 // needed for checking errors in user written actions
51 //noinspection ConstantConditions
52 LOG
.assertTrue(myText
!= null, "action "+action
.getClass()+" text returned null");
54 myDisplayName
= displayName
;
61 public void addIntention(final IntentionAction action
) {
62 myOptionIntentions
.add(action
);
64 public void addErrorFix(final IntentionAction action
) {
65 myOptionErrorFixes
.add(action
);
67 public void addInspectionFix(final IntentionAction action
) {
68 myOptionInspectionFixes
.add(action
);
71 public IntentionAction
getAction() {
75 public List
<IntentionAction
> getOptionIntentions() {
76 return myOptionIntentions
;
79 public List
<IntentionAction
> getOptionErrorFixes() {
80 return myOptionErrorFixes
;
83 public List
<IntentionAction
> getOptionInspectionFixes() {
84 return myOptionInspectionFixes
;
87 public String
getToolName() {
91 public String
toString() {
95 public int compareTo(final IntentionActionWithTextCaching other
) {
96 if (myAction
instanceof Comparable
) {
97 return ((Comparable
)myAction
).compareTo(other
.getAction());
99 else if (other
.getAction() instanceof Comparable
) {
100 return ((Comparable
)other
.getAction()).compareTo(myAction
);
102 return Comparing
.compare(getText(), other
.getText());
105 public Icon
getIcon() {