/platform/lang-impl/src/com/intellij/psi/impl/DefaultPomTargetDescriptionProvider.java

https://bitbucket.org/nbargnesi/idea · Java · 55 lines · 32 code · 5 blank · 18 comment · 7 complexity · 4f023b50d210983bafc41ab49fbcb188 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.psi.impl;
  17. import com.intellij.ide.TypePresentationService;
  18. import com.intellij.openapi.util.text.StringUtil;
  19. import com.intellij.pom.PomDescriptionProvider;
  20. import com.intellij.pom.PomNamedTarget;
  21. import com.intellij.pom.PomTarget;
  22. import com.intellij.psi.ElementDescriptionLocation;
  23. import com.intellij.psi.PsiElement;
  24. import com.intellij.usageView.UsageViewNodeTextLocation;
  25. import com.intellij.usageView.UsageViewTypeLocation;
  26. import com.intellij.codeInsight.highlighting.HighlightUsagesDescriptionLocation;
  27. import org.jetbrains.annotations.NotNull;
  28. /**
  29. * @author peter
  30. */
  31. public class DefaultPomTargetDescriptionProvider extends PomDescriptionProvider {
  32. @Override
  33. public String getElementDescription(@NotNull PomTarget element, @NotNull ElementDescriptionLocation location) {
  34. if (element instanceof PsiElement) return null;
  35. if (location == UsageViewTypeLocation.INSTANCE) {
  36. return getTypeName(element);
  37. }
  38. if (location == UsageViewNodeTextLocation.INSTANCE) {
  39. return getTypeName(element) + " " + StringUtil.notNullize(element instanceof PomNamedTarget ? ((PomNamedTarget)element).getName() : null, "''");
  40. }
  41. if (location instanceof HighlightUsagesDescriptionLocation) {
  42. return getTypeName(element);
  43. }
  44. return null;
  45. }
  46. private static String getTypeName(PomTarget element) {
  47. final String s = TypePresentationService.getService().getTypePresentableName(element.getClass());
  48. return s == null ? "Element" : s;
  49. }
  50. }