/xml/dom-impl/src/com/intellij/util/xml/impl/DefaultDomTargetDescriptionProvider.java

https://bitbucket.org/nbargnesi/idea · Java · 54 lines · 30 code · 6 blank · 18 comment · 9 complexity · 4da2813973d6b0528fecc473eda71afa 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.util.xml.impl;
  17. import com.intellij.openapi.util.text.StringUtil;
  18. import com.intellij.pom.PomDescriptionProvider;
  19. import com.intellij.pom.PomTarget;
  20. import com.intellij.psi.ElementDescriptionLocation;
  21. import com.intellij.usageView.UsageViewNodeTextLocation;
  22. import com.intellij.usageView.UsageViewTypeLocation;
  23. import com.intellij.usageView.UsageViewLongNameLocation;
  24. import com.intellij.util.xml.*;
  25. import com.intellij.codeInsight.highlighting.HighlightUsagesDescriptionLocation;
  26. import org.jetbrains.annotations.NotNull;
  27. /**
  28. * @author peter
  29. */
  30. public class DefaultDomTargetDescriptionProvider extends PomDescriptionProvider {
  31. public String getElementDescription(@NotNull PomTarget element, @NotNull ElementDescriptionLocation location) {
  32. if (!(element instanceof DomTarget)) return null;
  33. final DomTarget target = (DomTarget)element;
  34. DomElement domElement = target.getDomElement();
  35. final ElementPresentationTemplate template = domElement.getChildDescription().getPresentationTemplate();
  36. final ElementPresentation presentation = template != null ? template.createPresentation(domElement) : domElement.getPresentation();
  37. if (location == UsageViewTypeLocation.INSTANCE) {
  38. return presentation.getTypeName();
  39. }
  40. if (location == UsageViewNodeTextLocation.INSTANCE || location == UsageViewLongNameLocation.INSTANCE) {
  41. return presentation.getTypeName() + " " + StringUtil.notNullize(presentation.getElementName(), "''");
  42. }
  43. if (location instanceof HighlightUsagesDescriptionLocation) {
  44. return presentation.getTypeName();
  45. }
  46. return null;
  47. }
  48. }