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
.usageView
;
19 import com
.intellij
.lang
.findUsages
.FindUsagesProvider
;
20 import com
.intellij
.lang
.findUsages
.LanguageFindUsages
;
21 import com
.intellij
.psi
.ElementDescriptionLocation
;
22 import com
.intellij
.psi
.ElementDescriptionProvider
;
23 import com
.intellij
.psi
.PsiElement
;
24 import com
.intellij
.psi
.PsiFile
;
25 import com
.intellij
.psi
.meta
.PsiMetaData
;
26 import com
.intellij
.psi
.meta
.PsiMetaOwner
;
27 import com
.intellij
.psi
.meta
.PsiPresentableMetaData
;
28 import org
.jetbrains
.annotations
.NotNull
;
33 public class UsageViewNodeTextLocation
extends ElementDescriptionLocation
{
34 private UsageViewNodeTextLocation() {
37 public static final UsageViewNodeTextLocation INSTANCE
= new UsageViewNodeTextLocation();
39 public ElementDescriptionProvider
getDefaultProvider() {
40 return DEFAULT_PROVIDER
;
43 private static final ElementDescriptionProvider DEFAULT_PROVIDER
= new ElementDescriptionProvider() {
44 public String
getElementDescription(@NotNull final PsiElement element
, @NotNull final ElementDescriptionLocation location
) {
45 if (!(location
instanceof UsageViewNodeTextLocation
)) return null;
47 if (element
instanceof PsiMetaOwner
) {
48 final PsiMetaData metaData
= ((PsiMetaOwner
)element
).getMetaData();
49 if (metaData
instanceof PsiPresentableMetaData
) {
50 return ((PsiPresentableMetaData
)metaData
).getTypeName() + " " + UsageViewUtil
.getMetaDataName(metaData
);
54 if (element
instanceof PsiFile
) {
55 return ((PsiFile
) element
).getName();
57 FindUsagesProvider provider
= LanguageFindUsages
.INSTANCE
.forLanguage(element
.getLanguage());
58 return provider
.getNodeText(element
, true);