View | Details | Raw Unified | Return to bug 114909 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/dom/ASTConverterTest2.java (-1 / +23 lines)
Lines 42-48 Link Here
42
	}
42
	}
43
43
44
	static {
44
	static {
45
//		TESTS_NAMES = new String[] {"test0576"};
45
//		TESTS_NAMES = new String[] {"test0577"};
46
//		TESTS_NUMBERS =  new int[] { 606 };
46
//		TESTS_NUMBERS =  new int[] { 606 };
47
	}
47
	}
48
	public static Test suite() {
48
	public static Test suite() {
Lines 5366-5371 Link Here
5366
		}
5366
		}
5367
	}
5367
	}
5368
	
5368
	
5369
	/*
5370
	 * Ensures that strings are not optimized when creating the AST through a reconcile
5371
	 * even if the working copy was consistent.
5372
	 * (regression test for bug 114909 AST: String concatenation represented as single node)
5373
	 */
5374
	public void test0577() throws CoreException {
5375
		ICompilationUnit workingCopy = null;
5376
		try {
5377
			workingCopy = getWorkingCopy(
5378
				"/Converter/src/X.java", 
5379
				"public class X {\n" +
5380
				"  String s = /*start*/\"a\" + \"b\"/*end*/;\n" +
5381
				"}",
5382
				true/*resolve*/);
5383
			ASTNode string = buildAST(workingCopy);
5384
			assertEquals("Unexpected node type", ASTNode.INFIX_EXPRESSION, string.getNodeType());
5385
		} finally {
5386
			if (workingCopy != null)
5387
				workingCopy.discardWorkingCopy();
5388
		}
5389
	}
5390
	
5369
	public void test0606() throws JavaModelException {
5391
	public void test0606() throws JavaModelException {
5370
		ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0606", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
5392
		ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0606", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
5371
		ASTNode result = runConversion(sourceUnit, true);
5393
		ASTNode result = runConversion(sourceUnit, true);
(-)src/org/eclipse/jdt/core/tests/dom/AbstractASTTests.java (-14 / +25 lines)
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
		}

Return to bug 114909