ComponentWithBrowseButton - optional remove listener on hide
[fedora-idea.git] / java / java-impl / src / com / intellij / refactoring / util / JavaRefactoringElementDescriptionProvider.java
blobc1e37c756df6dfcdea650e3f5693e19eac4a2e8c
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.refactoring.util;
18 import com.intellij.psi.*;
19 import com.intellij.psi.util.PsiFormatUtil;
20 import com.intellij.refactoring.RefactoringBundle;
21 import com.intellij.usageView.UsageViewUtil;
22 import org.jetbrains.annotations.Nullable;
23 import org.jetbrains.annotations.NotNull;
25 public class JavaRefactoringElementDescriptionProvider implements ElementDescriptionProvider {
26 public String getElementDescription(@NotNull final PsiElement element, @NotNull final ElementDescriptionLocation location) {
27 if (!(location instanceof RefactoringDescriptionLocation)) return null;
28 RefactoringDescriptionLocation rdLocation = (RefactoringDescriptionLocation) location;
30 if (element instanceof PsiField) {
31 int options = PsiFormatUtil.SHOW_NAME;
32 if (rdLocation.includeParent()) {
33 options |= PsiFormatUtil.SHOW_CONTAINING_CLASS;
35 return RefactoringBundle.message("field.description", CommonRefactoringUtil.htmlEmphasize(PsiFormatUtil.formatVariable((PsiVariable)element, options, PsiSubstitutor.EMPTY)));
38 if (element instanceof PsiMethod) {
39 int options = PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_PARAMETERS;
40 if (rdLocation.includeParent()) {
41 options |= PsiFormatUtil.SHOW_CONTAINING_CLASS;
43 final PsiMethod method = (PsiMethod) element;
44 return method.isConstructor() ?
45 RefactoringBundle.message("constructor.description", CommonRefactoringUtil.htmlEmphasize(PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY, options, PsiFormatUtil.SHOW_TYPE))) :
46 RefactoringBundle.message("method.description", CommonRefactoringUtil.htmlEmphasize( PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY, options, PsiFormatUtil.SHOW_TYPE)));
49 if (element instanceof PsiClassInitializer) {
50 PsiClassInitializer initializer = (PsiClassInitializer) element;
51 boolean isStatic = initializer.hasModifierProperty(PsiModifier.STATIC);
52 return isStatic
53 ? RefactoringBundle.message("static.initializer.description", getElementDescription(initializer.getContainingClass(), RefactoringDescriptionLocation.WITHOUT_PARENT))
54 : RefactoringBundle.message("instance.initializer.description", getElementDescription(initializer.getContainingClass(), RefactoringDescriptionLocation.WITHOUT_PARENT));
57 if (element instanceof PsiParameter) {
58 return RefactoringBundle.message("parameter.description", CommonRefactoringUtil.htmlEmphasize(((PsiParameter)element).getName()));
61 if (element instanceof PsiLocalVariable) {
62 return RefactoringBundle.message("local.variable.description", CommonRefactoringUtil.htmlEmphasize(((PsiVariable)element).getName()));
65 if (element instanceof PsiPackage) {
66 return RefactoringBundle.message("package.description", CommonRefactoringUtil.htmlEmphasize(((PsiPackage)element).getName()));
69 if ((element instanceof PsiClass)) {
70 //TODO : local & anonymous
71 PsiClass psiClass = (PsiClass) element;
72 return RefactoringBundle.message("class.description", CommonRefactoringUtil.htmlEmphasize(UsageViewUtil.getDescriptiveName(psiClass)));
74 return null;