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
.structureView
.StructureViewTreeElement
;
19 import com
.intellij
.ide
.structureView
.impl
.AddAllMembersProcessor
;
20 import com
.intellij
.psi
.*;
21 import gnu
.trove
.THashSet
;
22 import org
.jetbrains
.annotations
.NotNull
;
26 public class JavaClassTreeElement
extends JavaClassTreeElementBase
<PsiClass
> {
27 public JavaClassTreeElement(PsiClass aClass
, boolean inherited
) {
28 super(inherited
,aClass
);
32 public Collection
<StructureViewTreeElement
> getChildrenBase() {
33 return getClassChildren();
36 private Collection
<StructureViewTreeElement
> getClassChildren() {
37 ArrayList
<StructureViewTreeElement
> array
= new ArrayList
<StructureViewTreeElement
>();
39 final PsiClass aClass
= getElement();
40 if (aClass
== null) return array
;
42 List
<PsiElement
> children
= Arrays
.asList(aClass
.getChildren());
43 Collection
<PsiElement
> ownChildren
= new THashSet
<PsiElement
>();
44 ownChildren
.addAll(Arrays
.asList(aClass
.getFields()));
45 ownChildren
.addAll(Arrays
.asList(aClass
.getMethods()));
46 ownChildren
.addAll(Arrays
.asList(aClass
.getInnerClasses()));
47 ownChildren
.addAll(Arrays
.asList(aClass
.getInitializers()));
48 Collection
<PsiElement
> inherited
= new LinkedHashSet
<PsiElement
>(children
);
50 aClass
.processDeclarations(new AddAllMembersProcessor(inherited
, aClass
), ResolveState
.initial(), null, aClass
);
52 for (PsiElement child
: inherited
) {
53 if (!child
.isValid()) continue;
54 boolean isInherited
= !ownChildren
.contains(child
);
55 if (child
instanceof PsiClass
) {
56 array
.add(new JavaClassTreeElement((PsiClass
)child
, isInherited
));
58 else if (child
instanceof PsiField
) {
59 array
.add(new PsiFieldTreeElement((PsiField
)child
, isInherited
));
61 else if (child
instanceof PsiMethod
) {
62 array
.add(new PsiMethodTreeElement((PsiMethod
)child
, isInherited
));
64 else if (child
instanceof PsiClassInitializer
) {
65 array
.add(new ClassInitializerTreeElement((PsiClassInitializer
)child
));
71 public String
getPresentableText() {
72 return getElement().getName();
75 public boolean isPublic() {
76 return getElement().getParent() instanceof PsiFile
|| super.isPublic();