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
.daemon
.impl
.HighlightInfo
;
20 import com
.intellij
.codeInsight
.intention
.IntentionAction
;
21 import com
.intellij
.openapi
.util
.Comparing
;
22 import com
.intellij
.openapi
.diagnostic
.Logger
;
25 import java
.util
.List
;
26 import java
.util
.ArrayList
;
31 class IntentionActionWithTextCaching
implements Comparable
<IntentionActionWithTextCaching
> {
32 private static final Logger LOG
= Logger
.getInstance("#com.intellij.codeInsight.intention.impl.IntentionActionWithTextCaching");
33 private final List
<IntentionAction
> myOptionIntentions
;
34 private final List
<IntentionAction
> myOptionErrorFixes
;
35 private final String myText
;
36 private final IntentionAction myAction
;
37 private final String myDisplayName
;
38 private final List
<IntentionAction
> myOptionInspectionFixes
;
39 private final Icon myIcon
;
41 IntentionActionWithTextCaching(IntentionAction action
){
42 this(action
, action
.getText(), null);
45 IntentionActionWithTextCaching(HighlightInfo
.IntentionActionDescriptor action
){
46 this(action
.getAction(), action
.getDisplayName(), action
.getIcon());
49 private IntentionActionWithTextCaching(IntentionAction action
, String displayName
, Icon icon
) {
51 myOptionIntentions
= new ArrayList
<IntentionAction
>();
52 myOptionErrorFixes
= new ArrayList
<IntentionAction
>();
53 myOptionInspectionFixes
= new ArrayList
<IntentionAction
>();
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() {
100 public int compareTo(final IntentionActionWithTextCaching other
) {
101 if (myAction
instanceof Comparable
) {
102 return ((Comparable
)myAction
).compareTo(other
.getAction());
104 else if (other
.getAction() instanceof Comparable
) {
105 return ((Comparable
)other
.getAction()).compareTo(myAction
);
107 return Comparing
.compare(getText(), other
.getText());
110 public Icon
getIcon() {