You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StructureViewNodeFactory.java 3.6KB

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