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.

BuildConfigNode.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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.io.ObjectStreamException;
  15. import java.io.Serializable;
  16. import java.util.ArrayList;
  17. import java.util.List;
  18. import org.aspectj.bridge.IMessage;
  19. import org.aspectj.bridge.ISourceLocation;
  20. import org.aspectj.util.FileUtil;
  21. /**
  22. * @author Mik Kersten
  23. *
  24. * TODO: clean-up after merging of org.aspectj.asm.StructureNode
  25. */
  26. public class BuildConfigNode {
  27. protected BuildConfigNode parent = null;
  28. protected String name = "";
  29. protected Kind kind;
  30. // children.listIterator() should support remove() operation
  31. protected List<BuildConfigNode> children = new ArrayList<BuildConfigNode>();
  32. protected IMessage message = null;
  33. protected ISourceLocation sourceLocation = null;
  34. /**
  35. * Used during serialization.
  36. */
  37. public BuildConfigNode() {
  38. }
  39. // public BuildConfigNode(String name, String kind, String resourcePath, List children) {
  40. // this(name, kind, children);
  41. // this.resourcePath = resourcePath;
  42. // }
  43. public BuildConfigNode(String name, Kind kind, String resourcePath) {
  44. this(name, kind);
  45. this.kind = kind;
  46. this.resourcePath = resourcePath;
  47. }
  48. // public BuildConfigNode(String name, Kind kind, List children) {
  49. // this.name = name;
  50. // this.kind = kind;
  51. // if (children != null) {
  52. // this.children = children;
  53. // }
  54. // setParents();
  55. // }
  56. public BuildConfigNode(String name, Kind kind) {
  57. this.name = name;
  58. this.kind = kind;
  59. }
  60. public String toString() {
  61. return name;
  62. }
  63. public List<BuildConfigNode> getChildren() {
  64. return children;
  65. }
  66. public void addChild(BuildConfigNode child) {
  67. if (children == null) {
  68. children = new ArrayList<BuildConfigNode>();
  69. }
  70. children.add(child);
  71. child.setParent(this);
  72. }
  73. public void addChild(int position, BuildConfigNode child) {
  74. if (children == null) {
  75. children = new ArrayList<BuildConfigNode>();
  76. }
  77. children.add(position, child);
  78. child.setParent(this);
  79. }
  80. public boolean removeChild(BuildConfigNode child) {
  81. child.setParent(null);
  82. return children.remove(child);
  83. }
  84. /**
  85. * Comparison is string-name based only.
  86. */
  87. public int compareTo(Object o) throws ClassCastException {
  88. if (o instanceof BuildConfigNode) {
  89. BuildConfigNode sn = (BuildConfigNode) o;
  90. return this.getName().compareTo(sn.getName());
  91. }
  92. return -1;
  93. }
  94. public String getName() {
  95. return name;
  96. }
  97. public ISourceLocation getSourceLocation() {
  98. return sourceLocation;
  99. }
  100. public void setSourceLocation(ISourceLocation sourceLocation) {
  101. this.sourceLocation = sourceLocation;
  102. }
  103. public IMessage getMessage() {
  104. return message;
  105. }
  106. public void setMessage(IMessage message) {
  107. this.message = message;
  108. }
  109. public BuildConfigNode getParent() {
  110. return parent;
  111. }
  112. public void setParent(BuildConfigNode parent) {
  113. this.parent = parent;
  114. }
  115. // private void setParents() {
  116. // if (children == null) return;
  117. // for (Iterator it = children.iterator(); it.hasNext(); ) {
  118. // ((BuildConfigNode)it.next()).setParent(this);
  119. // }
  120. // }
  121. public void setName(String string) {
  122. name = string;
  123. }
  124. private String resourcePath;
  125. private boolean isActive = true;
  126. public String getResourcePath() {
  127. return resourcePath;
  128. }
  129. public void setResourcePath(String resourcePath) {
  130. this.resourcePath = resourcePath;
  131. }
  132. public boolean isValidResource() {
  133. return FileUtil.hasSourceSuffix(name) || name.endsWith(".lst");
  134. }
  135. public boolean isActive() {
  136. return isActive;
  137. }
  138. public void setActive(boolean isActive) {
  139. this.isActive = isActive;
  140. }
  141. /**
  142. * Uses "typesafe enum" pattern.
  143. */
  144. public static class Kind implements Serializable {
  145. private static final long serialVersionUID = 3924996793884978885L;
  146. public static final Kind FILE_JAVA = new Kind("Java source file");
  147. public static final Kind FILE_ASPECTJ = new Kind("AspectJ source file");
  148. public static final Kind FILE_LST = new Kind("build configuration file");
  149. public static final Kind ERROR = new Kind("error");
  150. public static final Kind DIRECTORY = new Kind("directory");
  151. public static final Kind[] ALL = { FILE_JAVA, FILE_ASPECTJ, FILE_LST, DIRECTORY };
  152. private final String name;
  153. private Kind(String name) {
  154. this.name = name;
  155. }
  156. public String toString() {
  157. return name;
  158. }
  159. // public boolean equals(Object o) {
  160. // return (o instanceof Kind? this==o : false);
  161. // // return o.equals(name);
  162. // }
  163. //
  164. // public int hashCode() {
  165. // return ordinal;
  166. // // return name.hashCode();
  167. // }
  168. public boolean isDeclareKind() {
  169. return name.startsWith("declare");
  170. }
  171. // The 4 declarations below are necessary for serialization
  172. private static int nextOrdinal = 0;
  173. private final int ordinal = nextOrdinal++;
  174. private Object readResolve() throws ObjectStreamException {
  175. return ALL[ordinal];
  176. }
  177. }
  178. public Kind getBuildConfigNodeKind() {
  179. return kind;
  180. }
  181. }