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.
17 package com
.intellij
.refactoring
.util
;
19 import com
.intellij
.psi
.*;
20 import com
.intellij
.psi
.impl
.file
.PsiDirectoryFactory
;
21 import com
.intellij
.psi
.meta
.PsiMetaOwner
;
22 import com
.intellij
.psi
.meta
.PsiMetaData
;
23 import com
.intellij
.openapi
.diagnostic
.Logger
;
24 import org
.jetbrains
.annotations
.Nullable
;
25 import org
.jetbrains
.annotations
.NotNull
;
30 public class DefaultNonCodeSearchElementDescriptionProvider
implements ElementDescriptionProvider
{
31 private static final Logger LOG
= Logger
.getInstance("#com.intellij.refactoring.util.DefaultNonCodeSearchElementDescriptionProvider");
33 public static final DefaultNonCodeSearchElementDescriptionProvider INSTANCE
= new DefaultNonCodeSearchElementDescriptionProvider();
35 public String
getElementDescription(@NotNull final PsiElement element
, @NotNull final ElementDescriptionLocation location
) {
36 if (!(location
instanceof NonCodeSearchDescriptionLocation
)) return null;
37 final NonCodeSearchDescriptionLocation ncdLocation
= (NonCodeSearchDescriptionLocation
)location
;
39 if (element
instanceof PsiDirectory
) {
40 if (ncdLocation
.isNonJava()) {
41 final String qName
= PsiDirectoryFactory
.getInstance(element
.getProject()).getQualifiedName((PsiDirectory
)element
, false);
42 if (qName
.length() > 0) return qName
;
45 return ((PsiDirectory
) element
).getName();
48 if (ncdLocation
.isNonJava()) return null;
49 if (element
instanceof PsiMetaOwner
) {
50 final PsiMetaOwner psiMetaOwner
= (PsiMetaOwner
)element
;
51 final PsiMetaData metaData
= psiMetaOwner
.getMetaData();
52 if (metaData
!= null) {
53 return metaData
.getName();
56 if (element
instanceof PsiNamedElement
) {
57 return ((PsiNamedElement
)element
).getName();
60 LOG
.error("Unknown element type: " + element
);