1 /*******************************************************************************
2  * Copyright (c) 2004, 2013 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.ant.internal.ui.model;
15 
16 import java.io.File;
17 import java.net.URLClassLoader;
18 import java.util.Map;
19 
20 import org.apache.tools.ant.BuildException;
21 import org.apache.tools.ant.Project;
22 import org.apache.tools.ant.Target;
23 import org.apache.tools.ant.Task;
24 import org.eclipse.core.resources.IFile;
25 import org.eclipse.jface.text.BadLocationException;
26 import org.xml.sax.Attributes;
27 
28 public interface IAntModel {
29 
30 	/**
31 	 * Returns the project node for this Ant model
32 	 *
33 	 * @return the project node for this Ant model
34 	 */
getProjectNode()35 	AntProjectNode getProjectNode();
36 
37 	/**
38 	 * Returns the name of the external entity defined by the specified path
39 	 *
40 	 * @param path
41 	 *            the path to the entity
42 	 * @return the name or the entity or <code>null</code> if no entity could be resolved
43 	 */
getEntityName(String path)44 	String getEntityName(String path);
45 
46 	/**
47 	 * Returns the location provider for this Ant model
48 	 *
49 	 * @return the location provider for this Ant model
50 	 */
getLocationProvider()51 	LocationProvider getLocationProvider();
52 
53 	/**
54 	 * Disposes this Ant model
55 	 */
dispose()56 	void dispose();
57 
58 	/**
59 	 * Reconciles this Ant model with the buildfile it represents
60 	 */
reconcile()61 	void reconcile();
62 
63 	/**
64 	 * Sets the classloader for this Ant model
65 	 *
66 	 * @param newClassLoader
67 	 *            the classloader to use when resolving this Ant model
68 	 */
setClassLoader(URLClassLoader newClassLoader)69 	void setClassLoader(URLClassLoader newClassLoader);
70 
71 	/**
72 	 * Sets the extra properties to be used for parsing If global settings as defined in the Ant UI preferences are to be used this method does not
73 	 * need to be called.
74 	 *
75 	 * @param properties
76 	 *            the properties to ensure are set for parsing.
77 	 */
setProperties(Map<String, String> properties)78 	void setProperties(Map<String, String> properties);
79 
80 	/**
81 	 * Sets the property files to be used for parsing If global settings as defined in the Ant UI preferences are to be used this method does not need
82 	 * to be called.
83 	 *
84 	 * @param propertyFiles
85 	 *            the file names of the property files to use for parsing
86 	 */
setPropertyFiles(String[] propertyFiles)87 	void setPropertyFiles(String[] propertyFiles);
88 
89 	/**
90 	 * Returns the Eclipse resource for the buildfile this Ant model represents
91 	 *
92 	 * @return the Eclipse resource or <code>null</code> if the buildfile is not in the workspace
93 	 */
getFile()94 	IFile getFile();
95 
96 	/**
97 	 * Returns the encoding from the backing {@link IAntModel}. If the model is <code>null</code> or the encoding cannot be computed from the location
98 	 * backing the model, <code>UTF-8</code> is returned
99 	 *
100 	 * @return the encoding
101 	 * @since 3.7
102 	 */
getEncoding()103 	String getEncoding();
104 
105 	/**
106 	 * Handles a <code>BuildException</code> that occurred during parsing.
107 	 *
108 	 * @param be
109 	 *            the build exception that occurred
110 	 * @param node
111 	 *            the node associated with the problem
112 	 * @param severity
113 	 *            the severity of the problem
114 	 */
handleBuildException(BuildException be, AntElementNode node, int severity)115 	void handleBuildException(BuildException be, AntElementNode node, int severity);
116 
117 	/**
118 	 * Returns the project node for this Ant model
119 	 *
120 	 * @param reconcile
121 	 *            whether or not to ensure the Ant model is reconciled before retrieving the project node
122 	 * @return the project node for this Ant model
123 	 */
getProjectNode(boolean reconcile)124 	AntProjectNode getProjectNode(boolean reconcile);
125 
126 	/**
127 	 * Adds the new target to this Ant model
128 	 *
129 	 * @param newTarget
130 	 *            the new Apache Ant target
131 	 * @param lineNumber
132 	 *            the line number of the new target
133 	 * @param columnNumber
134 	 *            the column number of the new target
135 	 */
addTarget(Target newTarget, int lineNumber, int columnNumber)136 	void addTarget(Target newTarget, int lineNumber, int columnNumber);
137 
138 	/**
139 	 * Adds the new project to this Ant model
140 	 *
141 	 * @param project
142 	 *            the new Apache Ant project
143 	 * @param lineNumber
144 	 *            the line number of the new target
145 	 * @param columnNumber
146 	 *            the column number of the new target
147 	 */
addProject(Project project, int lineNumber, int columnNumber)148 	void addProject(Project project, int lineNumber, int columnNumber);
149 
150 	/**
151 	 * Return the <code>java.io.File</code> that is the buildfile that this Ant model represents
152 	 *
153 	 * @return the <code>java.io.File</code> that is the buildfile
154 	 */
155 	// TODO Could this just be getPath().toLocation();
getEditedFile()156 	File getEditedFile();
157 
158 	/**
159 	 * Returns whether this model contains task information
160 	 *
161 	 * @return whether task information is included in this model
162 	 */
canGetTaskInfo()163 	boolean canGetTaskInfo();
164 
165 	/**
166 	 * Returns whether this model contains lexical information
167 	 *
168 	 * @return whether lexical information is included in this model
169 	 */
canGetLexicalInfo()170 	boolean canGetLexicalInfo();
171 
172 	/**
173 	 * Returns whether this model contains position information for the elements
174 	 *
175 	 * @return whether position information is included in this model
176 	 */
canGetPositionInfo()177 	boolean canGetPositionInfo();
178 
179 	/**
180 	 * Adds a comment to the Ant model Only called if <code>canGetLexicalInfo()</code> is <code>true</code>
181 	 *
182 	 * @param lineNumber
183 	 *            the line number of the comment
184 	 * @param columnNumber
185 	 *            the column number of the comment
186 	 * @param length
187 	 *            the length of the comment
188 	 */
addComment(int lineNumber, int columnNumber, int length)189 	void addComment(int lineNumber, int columnNumber, int length);
190 
191 	/**
192 	 * Adds a DTD element to the Ant model Only called if <code>canGetLexicalInfo()</code> is <code>true</code>
193 	 *
194 	 * @param name
195 	 *            the name of the DTD element
196 	 * @param lineNumber
197 	 *            the line number of the comment
198 	 * @param columnNumber
199 	 *            the column number of the comment
200 	 */
addDTD(String name, int lineNumber, int columnNumber)201 	void addDTD(String name, int lineNumber, int columnNumber);
202 
203 	/**
204 	 * Adds the external entity to the Ant model
205 	 *
206 	 * @param name
207 	 *            the name of the external entity
208 	 * @param currentEntityPath
209 	 *            the path of the entity
210 	 */
addEntity(String name, String currentEntityPath)211 	void addEntity(String name, String currentEntityPath);
212 
213 	/**
214 	 * Adds a task element to the Ant model Only called if <code>canGetTaskInfo()</code>() is <code>true</code>
215 	 *
216 	 * @param newTask
217 	 *            the new Apache Ant task
218 	 * @param parentTask
219 	 *            the parent Apache Ant task or <code>null</code>
220 	 * @param attributes
221 	 *            the attributes of the new task
222 	 * @param lineNumber
223 	 *            the line number of the task
224 	 * @param columnNumber
225 	 *            the column number of the task
226 	 */
addTask(Task newTask, Task parentTask, Attributes attributes, int lineNumber, int columnNumber)227 	void addTask(Task newTask, Task parentTask, Attributes attributes, int lineNumber, int columnNumber);
228 
229 	/**
230 	 * Sets the length of the current element that was just finished being parsed
231 	 *
232 	 * @param lineNumber
233 	 *            the current line number of parsing
234 	 * @param columnNumber
235 	 *            the current column number of parsing
236 	 */
setCurrentElementLength(int lineNumber, int columnNumber)237 	void setCurrentElementLength(int lineNumber, int columnNumber);
238 
239 	/**
240 	 * Returns the offset in the document associated with this Ant model for the given line number and position in the line
241 	 *
242 	 * @param lineNumber
243 	 *            the line number in the doc
244 	 * @param column
245 	 *            the column number in that line
246 	 * @return the offset in the document
247 	 * @throws BadLocationException
248 	 */
getOffset(int lineNumber, int column)249 	int getOffset(int lineNumber, int column) throws BadLocationException;
250 
251 	/**
252 	 * Handles a fatal error from an exception during parsing.
253 	 *
254 	 * @param e
255 	 *            the exception that occurred
256 	 */
error(Exception e)257 	void error(Exception e);
258 
259 	/**
260 	 * Handles a fatal error from an exception during parsing.
261 	 *
262 	 * @param e
263 	 *            the exception that occurred
264 	 */
fatalError(Exception e)265 	void fatalError(Exception e);
266 
267 	/**
268 	 * Handles a warning from an exception during parsing.
269 	 *
270 	 * @param e
271 	 *            the exception that occurred
272 	 */
warning(Exception e)273 	void warning(Exception e);
274 
errorFromElement(Exception e, AntElementNode element, int lineNumber, int columnNumber)275 	void errorFromElement(Exception e, AntElementNode element, int lineNumber, int columnNumber);
276 
errorFromElementText(Exception e, int offset, int columnNumber)277 	void errorFromElementText(Exception e, int offset, int columnNumber);
278 
279 	/**
280 	 * Returns the text in the document of this Ant model for the given offset and length
281 	 *
282 	 * @param offset
283 	 *            the offset within the document
284 	 * @param length
285 	 *            the length of text to retrieve
286 	 * @return the text at the given offset of <code>null</code> if not contained within the document range
287 	 */
getText(int offset, int length)288 	String getText(int offset, int length);
289 
290 	/**
291 	 * Caches the text from the provided defining node so that the node definitions are only updated if the text changes on reconciliation
292 	 *
293 	 * @param node
294 	 *            the defining task node to cache the associated text
295 	 */
setDefiningTaskNodeText(AntDefiningTaskNode node)296 	void setDefiningTaskNodeText(AntDefiningTaskNode node);
297 
298 	/**
299 	 * Record the prefix-URI Namespace mapping.
300 	 *
301 	 * @param prefix
302 	 *            The Namespace prefix being declared.
303 	 * @param uri
304 	 *            The Namespace URI the prefix is mapped to.
305 	 */
addPrefixMapping(String prefix, String uri)306 	void addPrefixMapping(String prefix, String uri);
307 }
308