Lines 10-15
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.jdt.core.tests.dom; |
11 |
package org.eclipse.jdt.core.tests.dom; |
12 |
|
12 |
|
|
|
13 |
import java.util.ArrayList; |
13 |
import java.util.HashMap; |
14 |
import java.util.HashMap; |
14 |
import java.util.Iterator; |
15 |
import java.util.Iterator; |
15 |
import java.util.List; |
16 |
import java.util.List; |
Lines 51-63
Link Here
|
51 |
int astStart, astEnd; |
52 |
int astStart, astEnd; |
52 |
|
53 |
|
53 |
public MarkerInfo(String source) { |
54 |
public MarkerInfo(String source) { |
54 |
this(null, source); |
55 |
this(null, source, -1); |
|
|
56 |
} |
57 |
public MarkerInfo(String source, int markerIndex) { |
58 |
this(null, source, markerIndex); |
55 |
} |
59 |
} |
56 |
public MarkerInfo(String path, String source) { |
60 |
public MarkerInfo(String path, String source) { |
|
|
61 |
this(path, source, -1); |
62 |
} |
63 |
public MarkerInfo(String path, String source, int markerIndex) { |
57 |
this.path = path; |
64 |
this.path = path; |
58 |
this.source = source; |
65 |
this.source = source; |
59 |
String markerStart = "/*start*/"; |
66 |
String markerNumber = markerIndex == -1 ? "" : Integer.toString(markerIndex); |
60 |
String markerEnd = "/*end*/"; |
67 |
String markerStart = "/*start" + markerNumber + "*/"; |
|
|
68 |
String markerEnd = "/*end" + markerNumber + "*/"; |
61 |
this.astStart = source.indexOf(markerStart); // start of AST inclusive |
69 |
this.astStart = source.indexOf(markerStart); // start of AST inclusive |
62 |
this.source = new String(CharOperation.replace(this.source.toCharArray(), markerStart.toCharArray(), CharOperation.NO_CHAR)); |
70 |
this.source = new String(CharOperation.replace(this.source.toCharArray(), markerStart.toCharArray(), CharOperation.NO_CHAR)); |
63 |
this.astEnd = this.source.indexOf(markerEnd); // end of AST exclusive |
71 |
this.astEnd = this.source.indexOf(markerEnd); // end of AST exclusive |
Lines 180-185
Link Here
|
180 |
return findNode(unit, markerInfo); |
188 |
return findNode(unit, markerInfo); |
181 |
} |
189 |
} |
182 |
|
190 |
|
|
|
191 |
protected ASTNode buildAST(String contents, ICompilationUnit cu) throws JavaModelException { |
192 |
return buildAST(contents, cu, true); |
193 |
} |
194 |
|
183 |
protected ASTNode buildAST(MarkerInfo markerInfo, IClassFile classFile) throws JavaModelException { |
195 |
protected ASTNode buildAST(MarkerInfo markerInfo, IClassFile classFile) throws JavaModelException { |
184 |
return buildAST(markerInfo, classFile, true); |
196 |
return buildAST(markerInfo, classFile, true); |
185 |
} |
197 |
} |
Lines 190-197
Link Here
|
190 |
* by "*start*" and "*end*". |
202 |
* by "*start*" and "*end*". |
191 |
*/ |
203 |
*/ |
192 |
protected ASTNode buildAST(String contents, ICompilationUnit cu, boolean reportErrors) throws JavaModelException { |
204 |
protected ASTNode buildAST(String contents, ICompilationUnit cu, boolean reportErrors) throws JavaModelException { |
193 |
MarkerInfo markerInfo = new MarkerInfo(contents); |
205 |
ASTNode[] nodes = buildASTs(contents, cu, reportErrors); |
194 |
contents = markerInfo.source; |
206 |
if (nodes.length == 0) return null; |
|
|
207 |
return nodes[0]; |
208 |
} |
209 |
|
210 |
protected ASTNode[] buildASTs(String contents, ICompilationUnit cu) throws JavaModelException { |
211 |
return buildASTs(contents, cu, true); |
212 |
} |
213 |
|
214 |
/* |
215 |
* Removes the marker comments "*start?*" and "*end?*" from the given contents |
216 |
* (where ? is either empty or a number). |
217 |
* Builds an AST from the resulting source. |
218 |
* For each of the pairs, returns the AST node that was delimited by "*start?*" and "*end?*". |
219 |
*/ |
220 |
protected ASTNode[] buildASTs(String contents, ICompilationUnit cu, boolean reportErrors) throws JavaModelException { |
221 |
ArrayList infos = new ArrayList(); |
222 |
MarkerInfo markerInfo; |
223 |
int markerIndex = 0; |
224 |
while (contents.indexOf("/*start" + ++markerIndex + "*/") != -1) { |
225 |
markerInfo = new MarkerInfo(contents, markerIndex); |
226 |
infos.add(markerInfo); |
227 |
contents = markerInfo.source; |
228 |
} |
229 |
if (contents.indexOf("/*start*/") != -1 || infos.size() == 0) { |
230 |
markerInfo = new MarkerInfo(contents); |
231 |
infos.add(markerInfo); |
232 |
contents = markerInfo.source; |
233 |
} |
195 |
|
234 |
|
196 |
cu.getBuffer().setContents(contents); |
235 |
cu.getBuffer().setContents(contents); |
197 |
CompilationUnit unit = cu.reconcile(AST.JLS3, false, null, null); |
236 |
CompilationUnit unit = cu.reconcile(AST.JLS3, false, null, null); |
Lines 205-215
Link Here
|
205 |
System.err.println(buffer.toString()); |
244 |
System.err.println(buffer.toString()); |
206 |
} |
245 |
} |
207 |
|
246 |
|
208 |
return findNode(unit, markerInfo); |
247 |
int length = infos.size(); |
209 |
} |
248 |
ASTNode[] nodes = new ASTNode[length]; |
210 |
|
249 |
for (int i = 0; i < length; i++) { |
211 |
protected ASTNode buildAST(String contents, ICompilationUnit cu) throws JavaModelException { |
250 |
MarkerInfo info = (MarkerInfo) infos.get(i); |
212 |
return buildAST(contents, cu, true); |
251 |
nodes[i] = findNode(unit, info); |
|
|
252 |
} |
253 |
|
254 |
return nodes; |
213 |
} |
255 |
} |
214 |
|
256 |
|
215 |
protected MarkerInfo[] createMarkerInfos(String[] pathAndSources) { |
257 |
protected MarkerInfo[] createMarkerInfos(String[] pathAndSources) { |