update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / ide / structureView / impl / java / PsiMethodTreeElement.java
bloba9586a55f4c17ff344e47095ffa1faba8d83a8b2
1 /*
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.util.treeView.smartTree.SortableTreeElement;
20 import com.intellij.openapi.editor.colors.CodeInsightColors;
21 import com.intellij.openapi.editor.colors.TextAttributesKey;
22 import com.intellij.openapi.util.TextRange;
23 import com.intellij.psi.*;
24 import com.intellij.psi.impl.source.jsp.jspJava.JspHolderMethod;
25 import com.intellij.psi.util.PsiFormatUtil;
26 import org.jetbrains.annotations.NotNull;
28 import java.util.ArrayList;
29 import java.util.Collection;
31 public class PsiMethodTreeElement extends JavaClassTreeElementBase<PsiMethod> implements SortableTreeElement {
32 public PsiMethodTreeElement(PsiMethod method, boolean isInherited) {
33 super(isInherited,method);
36 @NotNull
37 public Collection<StructureViewTreeElement> getChildrenBase() {
38 final ArrayList<StructureViewTreeElement> result = new ArrayList<StructureViewTreeElement>();
39 final PsiMethod element = getElement();
40 if (element == null || element instanceof JspHolderMethod) return result;
42 final TextRange range = element.getTextRange();
43 if (range == null) return result;
45 final PsiFile psiFile = element.getContainingFile();
46 if (psiFile == null || psiFile instanceof PsiCompiledElement) return result;
48 final String fileText = psiFile.getText();
49 if (fileText == null) return result;
51 if (!range.substring(fileText).contains(PsiKeyword.CLASS)) return result;
53 element.accept(new JavaRecursiveElementWalkingVisitor(){
54 @Override public void visitClass(PsiClass aClass) {
55 if (!(aClass instanceof PsiAnonymousClass) && !(aClass instanceof PsiTypeParameter)) {
56 result.add(new JavaClassTreeElement(aClass, isInherited()));
60 });
61 return result;
64 public String getPresentableText() {
65 return PsiFormatUtil.formatMethod(
66 getElement(),
67 PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_TYPE | PsiFormatUtil.TYPE_AFTER | PsiFormatUtil.SHOW_PARAMETERS,
68 PsiFormatUtil.SHOW_TYPE
73 public TextAttributesKey getTextAttributesKey() {
74 if (isInherited()) return CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES;
75 return super.getTextAttributesKey();
78 public PsiMethod getMethod() {
79 return getElement();
82 public String getAlphaSortKey() {
83 final PsiMethod method = getElement();
84 if (method != null) {
85 return method.getName();
87 return "";