/platform/lang-impl/src/com/intellij/usageView/UsageViewTypeLocation.java

https://bitbucket.org/nbargnesi/idea · Java · 74 lines · 46 code · 10 blank · 18 comment · 6 complexity · 91421c9eee5f474e7ff1655a4f7a64f4 MD5 · raw file

  1. /*
  2. * Copyright 2000-2009 JetBrains s.r.o.
  3. *
  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
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  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.
  15. */
  16. package com.intellij.usageView;
  17. import com.intellij.ide.TypePresentationService;
  18. import com.intellij.psi.*;
  19. import com.intellij.psi.meta.PsiMetaData;
  20. import com.intellij.psi.meta.PsiMetaOwner;
  21. import com.intellij.psi.meta.PsiPresentableMetaData;
  22. import com.intellij.lang.LangBundle;
  23. import com.intellij.lang.Language;
  24. import com.intellij.lang.findUsages.FindUsagesProvider;
  25. import com.intellij.lang.findUsages.LanguageFindUsages;
  26. import com.intellij.openapi.util.text.StringUtil;
  27. import org.jetbrains.annotations.NotNull;
  28. /**
  29. * @author peter
  30. */
  31. public class UsageViewTypeLocation extends ElementDescriptionLocation {
  32. private UsageViewTypeLocation() {
  33. }
  34. public static final UsageViewTypeLocation INSTANCE = new UsageViewTypeLocation();
  35. @Override
  36. public ElementDescriptionProvider getDefaultProvider() {
  37. return DEFAULT_PROVIDER;
  38. }
  39. private static final ElementDescriptionProvider DEFAULT_PROVIDER = new ElementDescriptionProvider() {
  40. @Override
  41. public String getElementDescription(@NotNull final PsiElement psiElement, @NotNull final ElementDescriptionLocation location) {
  42. if (!(location instanceof UsageViewTypeLocation)) return null;
  43. if (psiElement instanceof PsiMetaOwner) {
  44. final PsiMetaData metaData = ((PsiMetaOwner)psiElement).getMetaData();
  45. if (metaData instanceof PsiPresentableMetaData) {
  46. return ((PsiPresentableMetaData)metaData).getTypeName();
  47. }
  48. }
  49. if (psiElement instanceof PsiFile) {
  50. return LangBundle.message("terms.file");
  51. }
  52. if (psiElement instanceof PsiDirectory) {
  53. return LangBundle.message("terms.directory");
  54. }
  55. final Language lang = psiElement.getLanguage();
  56. FindUsagesProvider provider = LanguageFindUsages.INSTANCE.forLanguage(lang);
  57. final String type = provider.getType(psiElement);
  58. if (StringUtil.isNotEmpty(type)) {
  59. return type;
  60. }
  61. return TypePresentationService.getService().getTypePresentableName(psiElement.getClass());
  62. }
  63. };
  64. }