31 * Base class for all Ant Meta objects. Each Ant object is represented by a meta |
31 * Base class for all Ant Meta objects. Each Ant object is represented by a meta |
32 * object that provides core and additional data about it. |
32 * object that provides core and additional data about it. |
33 */ |
33 */ |
34 public class AntObjectMeta { |
34 public class AntObjectMeta { |
35 |
35 |
36 public static final Map<String, Integer> SCOPES = new HashMap<String, Integer>() { |
36 public static final Map<String, Integer> SCOPES; |
37 { |
37 |
38 put("public", new Integer(1)); |
38 static { |
39 put("protected", new Integer(2)); |
39 Map<String, Integer> tempMap = new HashMap<String, Integer>(); |
40 put("private", new Integer(3)); |
40 tempMap.put("public", new Integer(1)); |
41 } |
41 tempMap.put("protected", new Integer(2)); |
42 }; |
42 tempMap.put("private", new Integer(3)); |
|
43 SCOPES = Collections.unmodifiableMap(tempMap); |
|
44 } |
|
45 |
43 /** The default scope if an element does not have a defined scope. */ |
46 /** The default scope if an element does not have a defined scope. */ |
44 public static final String DEFAULT_SCOPE = "public"; |
47 public static final String DEFAULT_SCOPE = "public"; |
45 |
48 |
46 private static AntComment emptyComment; |
49 private static AntComment emptyComment; |
47 |
50 |
48 private Project rootProject; |
51 private Project runtimeProject; |
49 |
52 |
50 /** The parent meta object. */ |
53 /** The parent meta object. */ |
51 private AntObjectMeta parent; |
54 private AntObjectMeta parent; |
52 /** The dom4j XML Element of the Ant object represented by this meta object. */ |
55 /** The dom4j XML Element of the Ant object represented by this meta object. */ |
53 private Node node; |
56 private Node node; |
54 /** The AntComment of any preceeding comment block. */ |
57 /** The AntComment of any preceeding comment block. */ |
55 private AntComment comment = emptyComment; |
58 private AntComment comment = emptyComment; |
56 |
59 |
57 static { |
60 static { |
58 try { |
61 emptyComment = new AntComment(); |
59 emptyComment = new AntComment(); |
|
60 } |
|
61 catch (IOException e) { |
|
62 e.printStackTrace(); |
|
63 } |
|
64 } |
62 } |
65 |
63 |
66 /** |
64 /** |
67 * Constructor. |
65 * Constructor. |
68 * |
66 * |
69 * @param parent The parent meta object. |
67 * @param parent The parent meta object. |
70 * @param node The XML node of the Ant object. |
68 * @param node The XML node of the Ant object. |
71 * @throws IOException |
69 */ |
72 */ |
70 public AntObjectMeta(AntObjectMeta parent, Node node) { |
73 public AntObjectMeta(AntObjectMeta parent, Node node) throws IOException { |
|
74 this.parent = parent; |
71 this.parent = parent; |
75 this.node = node; |
72 this.node = node; |
76 processComment(); |
73 processComment(); |
77 } |
74 } |
78 |
75 |
79 public Project getRuntimeProject() { |
76 public Project getRuntimeProject() { |
80 return rootProject; |
77 return runtimeProject; |
81 } |
78 } |
82 |
79 |
83 public void setRuntimeProject(Project project) { |
80 public void setRuntimeProject(Project project) { |
84 this.rootProject = project; |
81 this.runtimeProject = project; |
85 } |
82 } |
86 |
83 |
87 /** |
84 /** |
88 * Gets an attribute if a value is available, otherwise returns an emtpy |
85 * Gets an attribute if a value is available, otherwise returns an emtpy |
89 * string. |
86 * string. |
140 */ |
137 */ |
141 public String getName() { |
138 public String getName() { |
142 String name = getAttr("name"); |
139 String name = getAttr("name"); |
143 if (name.length() == 0) { |
140 if (name.length() == 0) { |
144 name = getComment().getObjectName(); |
141 name = getComment().getObjectName(); |
145 // if (name.length() == 0) { |
|
146 // try { |
|
147 // System.out.println("name is 0 length: " + getLocation()); |
|
148 // // System.out.println(node.toString()); |
|
149 // } |
|
150 // catch (IOException e) { |
|
151 // e.printStackTrace(); |
|
152 // } |
|
153 // } |
|
154 } |
142 } |
155 return name; |
143 return name; |
156 } |
144 } |
157 |
145 |
158 /** |
146 /** |
159 * Returns the location path of the object. |
147 * Returns the location path of the object. |
160 * |
148 * |
161 * @return Location path string. |
149 * @return Location path string. |
162 * @throws IOException |
150 */ |
163 */ |
151 public String getLocation() { |
164 public String getLocation() throws IOException { |
|
165 RootAntObjectMeta rootMeta = getRootMeta(); |
152 RootAntObjectMeta rootMeta = getRootMeta(); |
166 return rootMeta.getFile().getCanonicalPath(); |
153 String location = rootMeta.getFilePath(); |
|
154 if (node instanceof ElementWithLocation) { |
|
155 location += ":" + ((ElementWithLocation)node).getLineNumber(); |
|
156 } |
|
157 return location; |
167 } |
158 } |
168 |
159 |
169 /** |
160 /** |
170 * Returns the first line summary from a doc comment. |
161 * Returns the first line summary from a doc comment. |
171 * |
162 * |
201 public boolean matchesScope(String scopeFilter) { |
192 public boolean matchesScope(String scopeFilter) { |
202 if (!SCOPES.containsKey(scopeFilter)) { |
193 if (!SCOPES.containsKey(scopeFilter)) { |
203 throw new IllegalArgumentException("Invalid scope filter: " + scopeFilter); |
194 throw new IllegalArgumentException("Invalid scope filter: " + scopeFilter); |
204 } |
195 } |
205 String scope = getScope(); |
196 String scope = getScope(); |
206 if (!SCOPES.containsKey(scope)) { |
197 if (scope.length() > 0 && !SCOPES.containsKey(scope)) { |
207 log("Invalid scope: " + scope + ", " + toString(), Project.MSG_WARN); |
198 log("Invalid scope: " + scope + ", " + toString(), Project.MSG_WARN); |
208 return false; |
199 return false; |
209 } |
200 } |
210 return SCOPES.get(scope).compareTo(SCOPES.get(scopeFilter)) <= 0; |
201 return SCOPES.get(scope).compareTo(SCOPES.get(scopeFilter)) <= 0; |
211 } |
202 } |