update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / psi / presentation / java / JavaPresentationUtil.java
blob2466190c4c2e3341ff7fac2cd2384a2dc146b91c
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.psi.presentation.java;
18 import com.intellij.navigation.ItemPresentation;
19 import com.intellij.openapi.editor.colors.CodeInsightColors;
20 import com.intellij.openapi.editor.colors.TextAttributesKey;
21 import com.intellij.openapi.util.Iconable;
22 import com.intellij.psi.*;
23 import com.intellij.psi.util.PsiFormatUtil;
24 import com.intellij.psi.util.PsiTreeUtil;
25 import org.jetbrains.annotations.Nullable;
27 import javax.swing.*;
29 public class JavaPresentationUtil {
30 private JavaPresentationUtil() {
33 public static ItemPresentation getMethodPresentation(final PsiMethod psiMethod) {
34 return new ItemPresentation() {
35 public String getPresentableText() {
36 return PsiFormatUtil.formatMethod(
37 psiMethod,
38 PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS,
39 PsiFormatUtil.SHOW_TYPE
43 public TextAttributesKey getTextAttributesKey() {
44 if (psiMethod.isDeprecated()) {
45 return CodeInsightColors.DEPRECATED_ATTRIBUTES;
47 return null;
50 public String getLocationString() {
51 return getJavaSymbolContainerText(psiMethod);
54 public Icon getIcon(boolean open) {
55 return psiMethod.getIcon(Iconable.ICON_FLAG_VISIBILITY);
60 public static ItemPresentation getFieldPresentation(final PsiField psiField) {
61 return new ItemPresentation() {
62 public String getPresentableText() {
63 return psiField.getName();
66 public TextAttributesKey getTextAttributesKey() {
67 if (psiField.isDeprecated()) {
68 return CodeInsightColors.DEPRECATED_ATTRIBUTES;
70 return null;
73 public String getLocationString() {
74 return getJavaSymbolContainerText(psiField);
77 public Icon getIcon(boolean open) {
78 return psiField.getIcon(Iconable.ICON_FLAG_VISIBILITY);
83 public static ItemPresentation getVariablePresentation(final PsiVariable variable) {
84 return new ItemPresentation() {
85 public String getPresentableText() {
86 return PsiFormatUtil.formatVariable(variable, PsiFormatUtil.SHOW_TYPE, PsiSubstitutor.EMPTY);
89 public String getLocationString() {
90 return "";
93 public TextAttributesKey getTextAttributesKey() {
94 return null;
97 public Icon getIcon(boolean open) {
98 return variable.getIcon(Iconable.ICON_FLAG_OPEN);
103 @Nullable
104 private static String getJavaSymbolContainerText(final PsiElement element) {
105 final String result;
106 PsiElement container = PsiTreeUtil.getParentOfType(element, PsiMember.class, PsiFile.class);
108 if (container instanceof PsiClass) {
109 String qName = ((PsiClass)container).getQualifiedName();
110 if (qName != null) {
111 result = qName;
113 else {
114 result = ((PsiClass)container).getName();
117 else if (container instanceof PsiJavaFile) {
118 result = ((PsiJavaFile)container).getPackageName();
120 else {//TODO: local classes
121 result = null;
123 if (result != null) {
124 return PsiBundle.message("aux.context.display", result);
126 return null;