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.
16 package com
.intellij
.ide
.structureView
.impl
.java
;
18 import com
.intellij
.ide
.IdeBundle
;
19 import com
.intellij
.ide
.util
.treeView
.smartTree
.Group
;
20 import com
.intellij
.ide
.util
.treeView
.smartTree
.TreeElement
;
21 import com
.intellij
.navigation
.ItemPresentation
;
22 import com
.intellij
.openapi
.editor
.colors
.TextAttributesKey
;
23 import com
.intellij
.openapi
.util
.IconLoader
;
24 import com
.intellij
.psi
.PsiClass
;
25 import com
.intellij
.psi
.SmartPointerManager
;
26 import com
.intellij
.psi
.SmartPsiElementPointer
;
27 import com
.intellij
.psi
.PsiModifierList
;
28 import com
.intellij
.psi
.util
.PsiUtil
;
29 import org
.jetbrains
.annotations
.Nullable
;
32 import java
.util
.ArrayList
;
33 import java
.util
.Collection
;
35 public class SuperTypeGroup
implements Group
, ItemPresentation
, AccessLevelProvider
{
36 private final SmartPsiElementPointer mySuperClassPointer
;
37 private final OwnershipType myOverrides
;
38 private final Collection
<TreeElement
> myChildren
= new ArrayList
<TreeElement
>();
39 private static final Icon OVERRIDING_ICON
= IconLoader
.getIcon("/general/overridingMethod.png");
40 private static final Icon IMPLEMENTING_ICON
= IconLoader
.getIcon("/general/implementingMethod.png");
41 private static final Icon INHERITED_ICON
= IconLoader
.getIcon("/general/inheritedMethod.png");
43 public static enum OwnershipType
{
49 public SuperTypeGroup(PsiClass superClass
, OwnershipType type
) {
51 mySuperClassPointer
= SmartPointerManager
.getInstance(superClass
.getProject()).createSmartPsiElementPointer(superClass
);
54 public Collection
<TreeElement
> getChildren() {
59 private PsiClass
getSuperClass() {
60 return (PsiClass
)mySuperClassPointer
.getElement();
63 public ItemPresentation
getPresentation() {
67 public Icon
getIcon(boolean open
) {
68 switch (myOverrides
) {
70 return IMPLEMENTING_ICON
;
72 return INHERITED_ICON
;
74 return OVERRIDING_ICON
;
77 return null; // Can't be
80 public String
getLocationString() {
84 public String
getPresentableText() {
88 public String
toString() {
89 final PsiClass superClass
= getSuperClass();
90 return superClass
!= null ? superClass
.getName() : IdeBundle
.message("node.structureview.invalid");
93 public boolean equals(Object o
) {
94 if (this == o
) return true;
95 if (!(o
instanceof SuperTypeGroup
)) return false;
97 final SuperTypeGroup superTypeGroup
= (SuperTypeGroup
)o
;
99 if (myOverrides
!= superTypeGroup
.myOverrides
) return false;
100 final PsiClass superClass
= getSuperClass();
101 if (superClass
!= null ?
!superClass
.equals(superTypeGroup
.getSuperClass() ) : superTypeGroup
.getSuperClass() != null) return false;
106 public int hashCode() {
107 final PsiClass superClass
= getSuperClass();
108 return superClass
!= null ? superClass
.hashCode() : 0;
111 public Object
getValue() {
115 public int getAccessLevel() {
116 final PsiClass superClass
= getSuperClass();
117 PsiModifierList modifierList
= superClass
== null ?
null : superClass
.getModifierList();
118 return modifierList
== null ? PsiUtil
.ACCESS_LEVEL_PUBLIC
: PsiUtil
.getAccessLevel(modifierList
);
121 public int getSubLevel() {
125 public TextAttributesKey
getTextAttributesKey() {
129 public void addMethod(final TreeElement superMethod
) {
130 myChildren
.add(superMethod
);