Lines 240-252
Link Here
|
240 |
|
240 |
|
241 |
return findNode(unit, markerInfo); |
241 |
return findNode(unit, markerInfo); |
242 |
} |
242 |
} |
|
|
243 |
|
244 |
protected ASTNode buildAST(ICompilationUnit cu) throws JavaModelException { |
245 |
return buildAST(null/*use existing contenst*/, cu, true/*report errors*/); |
246 |
} |
243 |
|
247 |
|
244 |
protected ASTNode buildAST(String contents, ICompilationUnit cu) throws JavaModelException { |
248 |
protected ASTNode buildAST(String newContents, ICompilationUnit cu) throws JavaModelException { |
245 |
return buildAST(contents, cu, true); |
249 |
return buildAST(newContents, cu, true/*report errors*/); |
246 |
} |
250 |
} |
247 |
|
251 |
|
248 |
protected ASTNode buildAST(MarkerInfo markerInfo, IClassFile classFile) throws JavaModelException { |
252 |
protected ASTNode buildAST(MarkerInfo markerInfo, IClassFile classFile) throws JavaModelException { |
249 |
return buildAST(markerInfo, classFile, true); |
253 |
return buildAST(markerInfo, classFile, true/*report errors*/); |
250 |
} |
254 |
} |
251 |
|
255 |
|
252 |
/* |
256 |
/* |
Lines 254-261
Link Here
|
254 |
* builds an AST from the resulting source, and returns the AST node that was delimited |
258 |
* builds an AST from the resulting source, and returns the AST node that was delimited |
255 |
* by "*start*" and "*end*". |
259 |
* by "*start*" and "*end*". |
256 |
*/ |
260 |
*/ |
257 |
protected ASTNode buildAST(String contents, ICompilationUnit cu, boolean reportErrors) throws JavaModelException { |
261 |
protected ASTNode buildAST(String newContents, ICompilationUnit cu, boolean reportErrors) throws JavaModelException { |
258 |
ASTNode[] nodes = buildASTs(contents, cu, reportErrors); |
262 |
ASTNode[] nodes = buildASTs(newContents, cu, reportErrors); |
259 |
if (nodes.length == 0) return null; |
263 |
if (nodes.length == 0) return null; |
260 |
return nodes[0]; |
264 |
return nodes[0]; |
261 |
} |
265 |
} |
Lines 265-283
Link Here
|
265 |
} |
269 |
} |
266 |
|
270 |
|
267 |
/* |
271 |
/* |
268 |
* Removes the marker comments "*start?*" and "*end?*" from the given contents |
272 |
* Removes the marker comments "*start?*" and "*end?*" from the given new contents |
269 |
* (where ? is either empty or a number). |
273 |
* (where ? is either empty or a number), or use the current contents if the given new contents is null. |
270 |
* Builds an AST from the resulting source. |
274 |
* Builds an AST from the resulting source. |
271 |
* For each of the pairs, returns the AST node that was delimited by "*start?*" and "*end?*". |
275 |
* For each of the pairs, returns the AST node that was delimited by "*start?*" and "*end?*". |
272 |
*/ |
276 |
*/ |
273 |
protected ASTNode[] buildASTs(String contents, ICompilationUnit cu, boolean reportErrors) throws JavaModelException { |
277 |
protected ASTNode[] buildASTs(String newContents, ICompilationUnit cu, boolean reportErrors) throws JavaModelException { |
274 |
MarkerInfo markerInfo = new MarkerInfo(contents); |
278 |
MarkerInfo markerInfo; |
275 |
contents = markerInfo.source; |
279 |
if (newContents == null) { |
276 |
|
280 |
markerInfo = new MarkerInfo(cu.getSource()); |
277 |
cu.getBuffer().setContents(contents); |
281 |
newContents = markerInfo.source; |
|
|
282 |
cu.getBuffer().setContents(newContents); |
283 |
cu.makeConsistent(null); |
284 |
} else { |
285 |
markerInfo = new MarkerInfo(newContents); |
286 |
newContents = markerInfo.source; |
287 |
cu.getBuffer().setContents(newContents); |
288 |
} |
278 |
CompilationUnit unit; |
289 |
CompilationUnit unit; |
279 |
if (cu.isWorkingCopy()) |
290 |
if (cu.isWorkingCopy()) |
280 |
unit = cu.reconcile(AST.JLS3, false, null, null); |
291 |
unit = cu.reconcile(AST.JLS3, reportErrors, null, null); |
281 |
else { |
292 |
else { |
282 |
ASTParser parser = ASTParser.newParser(AST.JLS3); |
293 |
ASTParser parser = ASTParser.newParser(AST.JLS3); |
283 |
parser.setSource(cu); |
294 |
parser.setSource(cu); |
Lines 289-295
Link Here
|
289 |
StringBuffer buffer = new StringBuffer(); |
300 |
StringBuffer buffer = new StringBuffer(); |
290 |
IProblem[] problems = unit.getProblems(); |
301 |
IProblem[] problems = unit.getProblems(); |
291 |
for (int i = 0, length = problems.length; i < length; i++) |
302 |
for (int i = 0, length = problems.length; i < length; i++) |
292 |
Util.appendProblem(buffer, problems[i], contents.toCharArray(), i+1); |
303 |
Util.appendProblem(buffer, problems[i], newContents.toCharArray(), i+1); |
293 |
if (buffer.length() > 0) |
304 |
if (buffer.length() > 0) |
294 |
System.err.println(buffer.toString()); |
305 |
System.err.println(buffer.toString()); |
295 |
} |
306 |
} |