Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

StructureViewNodeFactory.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* *******************************************************************
  2. * Copyright (c) 1999-2001 Xerox Corporation,
  3. * 2002 Palo Alto Research Center, Incorporated (PARC).
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Public License v 2.0
  7. * which accompanies this distribution and is available at
  8. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * ******************************************************************/
  13. package org.aspectj.ajde.ui;
  14. import java.util.List;
  15. import org.aspectj.ajde.Ajde;
  16. import org.aspectj.asm.AsmManager;
  17. import org.aspectj.asm.IProgramElement;
  18. import org.aspectj.asm.IRelationship;
  19. import org.aspectj.asm.IRelationshipMap;
  20. /**
  21. * @author Mik Kersten
  22. */
  23. public abstract class StructureViewNodeFactory {
  24. private final AbstractIconRegistry iconRegistry;
  25. public StructureViewNodeFactory(AbstractIconRegistry iconRegistry) {
  26. this.iconRegistry = iconRegistry;
  27. }
  28. public IStructureViewNode createNode(IProgramElement node) {
  29. return createNode(node, null);
  30. }
  31. public IStructureViewNode createNode(IProgramElement node, List children) {
  32. AbstractIcon icon = iconRegistry.getStructureIcon(node.getKind(), node.getAccessibility());
  33. IStructureViewNode svNode = createDeclaration(node, icon, children);
  34. String nodeHandle = node.getHandleIdentifier();
  35. // Don't put relationships on fields as they can then appear twice when building the outline -
  36. // once under clinit field-set nodes and once under the field declaration.
  37. if (nodeHandle != null && !node.getKind().equals(IProgramElement.Kind.FIELD)) {
  38. AsmManager manager = Ajde.getDefault().getModel();
  39. IRelationshipMap relMap = (manager == null ? null : manager.getRelationshipMap());
  40. List relationships = (relMap == null ? null : relMap.get(nodeHandle));
  41. if (relationships != null) {
  42. for (Object relationship : relationships) {
  43. IRelationship rel = (IRelationship) relationship;
  44. if (rel != null && rel.getTargets().size() > 0) {
  45. IStructureViewNode relNode = createRelationship(rel, iconRegistry.getIcon(rel.getKind()));
  46. if (relNode != null) {
  47. svNode.add(relNode, 0);
  48. for (String handle : rel.getTargets()) {
  49. IProgramElement link = Ajde.getDefault().getModel().getHierarchy().findElementForHandle(handle);
  50. if (link != null) {
  51. IStructureViewNode linkNode = createLink(link, iconRegistry.getStructureIcon(link.getKind(),
  52. link.getAccessibility()));
  53. relNode.add(linkNode);
  54. }
  55. }
  56. }
  57. }
  58. }
  59. }
  60. }
  61. return svNode;
  62. }
  63. /**
  64. * Implementors must override this method in order to create link new nodes.
  65. */
  66. protected abstract IStructureViewNode createLink(IProgramElement node, AbstractIcon icon);
  67. /**
  68. * Implementors must override this method in order to create new relationship nodes.
  69. *
  70. * If returned node is null it will not be added to the tree.
  71. */
  72. protected abstract IStructureViewNode createRelationship(IRelationship relationship, AbstractIcon icon);
  73. /**
  74. * Implementors must override this method in order to create new nodes.
  75. */
  76. protected abstract IStructureViewNode createDeclaration(IProgramElement node, AbstractIcon icon, List children);
  77. /**
  78. * Don't show code elements under types since they show under the corresponding initializers.
  79. */
  80. public static boolean acceptNode(IProgramElement parent, IProgramElement child) {
  81. if (parent.getKind() == IProgramElement.Kind.CLASS && child.getKind() == IProgramElement.Kind.CODE) {
  82. return false;
  83. } else {
  84. return true;
  85. }
  86. }
  87. }