NPE (18686)
[fedora-idea.git] / platform / lang-impl / src / com / intellij / usageView / UsageViewTypeLocation.java
blob0a3bf4e046850cf0e4ebc6f162e5fb29c77053d5
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.
17 package com.intellij.usageView;
19 import com.intellij.psi.*;
20 import com.intellij.psi.meta.PsiMetaData;
21 import com.intellij.psi.meta.PsiMetaOwner;
22 import com.intellij.psi.meta.PsiPresentableMetaData;
23 import com.intellij.lang.LangBundle;
24 import com.intellij.lang.Language;
25 import com.intellij.lang.findUsages.FindUsagesProvider;
26 import com.intellij.lang.findUsages.LanguageFindUsages;
27 import com.intellij.openapi.util.text.StringUtil;
28 import com.intellij.util.xml.TypeNameManager;
29 import org.jetbrains.annotations.NotNull;
31 /**
32 * @author peter
34 public class UsageViewTypeLocation extends ElementDescriptionLocation {
35 private UsageViewTypeLocation() {
38 public static final UsageViewTypeLocation INSTANCE = new UsageViewTypeLocation();
40 public ElementDescriptionProvider getDefaultProvider() {
41 return DEFAULT_PROVIDER;
44 private static final ElementDescriptionProvider DEFAULT_PROVIDER = new ElementDescriptionProvider() {
45 public String getElementDescription(@NotNull final PsiElement psiElement, @NotNull final ElementDescriptionLocation location) {
46 if (!(location instanceof UsageViewTypeLocation)) return null;
48 if (psiElement instanceof PsiMetaOwner) {
49 final PsiMetaData metaData = ((PsiMetaOwner)psiElement).getMetaData();
50 if (metaData instanceof PsiPresentableMetaData) {
51 return ((PsiPresentableMetaData)metaData).getTypeName();
55 if (psiElement instanceof PsiFile) {
56 return LangBundle.message("terms.file");
58 if (psiElement instanceof PsiDirectory) {
59 return LangBundle.message("terms.directory");
62 final Language lang = psiElement.getLanguage();
63 FindUsagesProvider provider = LanguageFindUsages.INSTANCE.forLanguage(lang);
64 final String type = provider.getType(psiElement);
65 if (StringUtil.isNotEmpty(type)) {
66 return type;
69 return TypeNameManager.getTypeName(psiElement.getClass());