use default lambda icon
[idea/community.git] / java / debugger / impl / src / com / intellij / debugger / actions / LambdaSmartStepTarget.java
1 /*
2  * Copyright 2000-2015 JetBrains s.r.o.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package com.intellij.debugger.actions;
17
18 import com.intellij.psi.PsiElement;
19 import com.intellij.psi.PsiLambdaExpression;
20 import com.intellij.psi.PsiSubstitutor;
21 import com.intellij.psi.util.PsiFormatUtil;
22 import com.intellij.util.Range;
23 import org.jetbrains.annotations.NotNull;
24 import org.jetbrains.annotations.Nullable;
25
26 import javax.swing.*;
27
28 /**
29  * @author Eugene Zhuravlev
30  *         Date: 10/25/13
31  */
32 public class LambdaSmartStepTarget extends SmartStepTarget{
33   private final PsiLambdaExpression myLambda;
34   private final int myOrdinal;
35
36   public LambdaSmartStepTarget(@NotNull PsiLambdaExpression lambda, @Nullable String label, @Nullable PsiElement highlightElement, int ordinal, Range<Integer> lines) {
37     super(label, highlightElement, true, lines);
38     myLambda = lambda;
39     myOrdinal = ordinal;
40   }
41
42   public PsiLambdaExpression getLambda() {
43     return myLambda;
44   }
45
46   public int getOrdinal() {
47     return myOrdinal;
48   }
49
50   @Nullable
51   @Override
52   public Icon getIcon() {
53     return myLambda.getIcon(0);
54   }
55
56   @NotNull
57   @Override
58   public String getPresentation() {
59     String typeText = PsiFormatUtil.formatType(myLambda.getType(), 0, PsiSubstitutor.EMPTY);
60     String label = getLabel();
61     return label != null ? label + typeText : typeText;
62   }
63
64   public boolean equals(Object o) {
65     if (this == o) {
66       return true;
67     }
68     if (o == null || getClass() != o.getClass()) {
69       return false;
70     }
71
72     final LambdaSmartStepTarget that = (LambdaSmartStepTarget)o;
73
74     if (myOrdinal != that.myOrdinal) {
75       return false;
76     }
77     if (!myLambda.equals(that.myLambda)) {
78       return false;
79     }
80
81     return true;
82   }
83
84   public int hashCode() {
85     int result = myLambda.hashCode();
86     result = 31 * result + myOrdinal;
87     return result;
88   }
89 }