View | Details | Raw Unified | Return to bug 192233
Collapse All | Expand All

(-)dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java (+5 lines)
Lines 1588-1593 Link Here
1588
		boolean returnTypeExists=  originalReturnType != null && originalReturnType.getStartPosition() != -1;
1588
		boolean returnTypeExists=  originalReturnType != null && originalReturnType.getStartPosition() != -1;
1589
		if (!isConstructorChange && returnTypeExists) {
1589
		if (!isConstructorChange && returnTypeExists) {
1590
			rewriteRequiredNode(node, property);
1590
			rewriteRequiredNode(node, property);
1591
			ensureSpaceAfterReplace(node, property);
1591
			return;
1592
			return;
1592
		}
1593
		}
1593
		// difficult cases: return type insert or remove
1594
		// difficult cases: return type insert or remove
Lines 2158-2163 Link Here
2158
		}
2159
		}
2159
2160
2160
		pos= rewriteRequiredNode(node, FieldDeclaration.TYPE_PROPERTY);
2161
		pos= rewriteRequiredNode(node, FieldDeclaration.TYPE_PROPERTY);
2162
		ensureSpaceAfterReplace(node, FieldDeclaration.TYPE_PROPERTY);
2161
		rewriteNodeList(node, FieldDeclaration.FRAGMENTS_PROPERTY, pos, "", ", "); //$NON-NLS-1$ //$NON-NLS-2$
2163
		rewriteNodeList(node, FieldDeclaration.FRAGMENTS_PROPERTY, pos, "", ", "); //$NON-NLS-1$ //$NON-NLS-2$
2162
		return false;
2164
		return false;
2163
	}
2165
	}
Lines 2639-2644 Link Here
2639
				}
2641
				}
2640
			}
2642
			}
2641
		}
2643
		}
2644
		if (!node.isVarargs()) {
2645
			ensureSpaceAfterReplace(node, SingleVariableDeclaration.TYPE_PROPERTY);
2646
		}
2642
2647
2643
		pos= rewriteRequiredNode(node, SingleVariableDeclaration.NAME_PROPERTY);
2648
		pos= rewriteRequiredNode(node, SingleVariableDeclaration.NAME_PROPERTY);
2644
		int extraDims= rewriteExtraDimensions(node, SingleVariableDeclaration.EXTRA_DIMENSIONS_PROPERTY, pos);
2649
		int extraDims= rewriteExtraDimensions(node, SingleVariableDeclaration.EXTRA_DIMENSIONS_PROPERTY, pos);
(-)dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFormatter.java (-3 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 546-553 Link Here
546
546
547
	public final BlockContext IF_BLOCK_WITH_ELSE= new BlockFormattingPrefixSuffix("if (true)", "else{}", 8); //$NON-NLS-1$ //$NON-NLS-2$
547
	public final BlockContext IF_BLOCK_WITH_ELSE= new BlockFormattingPrefixSuffix("if (true)", "else{}", 8); //$NON-NLS-1$ //$NON-NLS-2$
548
	public final BlockContext IF_BLOCK_NO_ELSE= new BlockFormattingPrefix("if (true)", 8); //$NON-NLS-1$
548
	public final BlockContext IF_BLOCK_NO_ELSE= new BlockFormattingPrefix("if (true)", 8); //$NON-NLS-1$
549
	public final BlockContext ELSE_AFTER_STATEMENT= new BlockFormattingPrefix("if (true) foo(); else ", 15); //$NON-NLS-1$
549
	public final BlockContext ELSE_AFTER_STATEMENT= new BlockFormattingPrefix("if (true) foo();else ", 15); //$NON-NLS-1$
550
	public final BlockContext ELSE_AFTER_BLOCK= new BlockFormattingPrefix("if (true) {} else ", 11); //$NON-NLS-1$
550
	public final BlockContext ELSE_AFTER_BLOCK= new BlockFormattingPrefix("if (true) {}else ", 11); //$NON-NLS-1$
551
551
552
	public final BlockContext FOR_BLOCK= new BlockFormattingPrefix("for (;;) ", 7); //$NON-NLS-1$
552
	public final BlockContext FOR_BLOCK= new BlockFormattingPrefix("for (;;) ", 7); //$NON-NLS-1$
553
	public final BlockContext WHILE_BLOCK= new BlockFormattingPrefix("while (true)", 11); //$NON-NLS-1$
553
	public final BlockContext WHILE_BLOCK= new BlockFormattingPrefix("while (true)", 11); //$NON-NLS-1$
(-)src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingReplaceTest.java (-1 / +227 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 236-239 Link Here
236
		buf.append("}\n");
236
		buf.append("}\n");
237
		assertEqualString(preview, buf.toString());
237
		assertEqualString(preview, buf.toString());
238
	}
238
	}
239
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=192233
240
	public void test0007() throws Exception {
241
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0007", false, null);
242
		StringBuffer buf= new StringBuffer();
243
		buf.append("package test0007;\n");
244
		buf.append("public class X {\n");
245
		buf.append("    List/**/getUsers() {}\n");
246
		buf.append("}\n");
247
248
		ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
249
250
		CompilationUnit astRoot= createCU(cu, false, AST.JLS3);
251
252
		astRoot.recordModifications();
253
254
		AST ast = astRoot.getAST();
255
256
		List types = astRoot.types();
257
		List list= ((TypeDeclaration) types.get(0)).bodyDeclarations();
258
		MethodDeclaration methodDecl= (MethodDeclaration) list.get(0);
259
260
		methodDecl.setReturnType2(ast.newPrimitiveType(PrimitiveType.VOID));
261
262
		String preview = evaluateRewrite(cu, astRoot);
263
264
		buf= new StringBuffer();
265
		buf.append("package test0007;\n");
266
		buf.append("public class X {\n");
267
		buf.append("    void getUsers() {}\n");
268
		buf.append("}\n");
269
		assertEqualString(preview, buf.toString());
270
	}
271
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=192233
272
	public void test0008() throws Exception {
273
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0008", false, null);
274
		StringBuffer buf= new StringBuffer();
275
		buf.append("package test0008;\n");
276
		buf.append("public class X {\n");
277
		buf.append("    List /**/getUsers() {}\n");
278
		buf.append("}\n");
279
280
		ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
281
282
		CompilationUnit astRoot= createCU(cu, false, AST.JLS3);
283
284
		astRoot.recordModifications();
285
286
		AST ast = astRoot.getAST();
287
288
		List types = astRoot.types();
289
		List list= ((TypeDeclaration) types.get(0)).bodyDeclarations();
290
		MethodDeclaration methodDecl= (MethodDeclaration) list.get(0);
291
292
		methodDecl.setReturnType2(ast.newPrimitiveType(PrimitiveType.VOID));
293
294
		String preview = evaluateRewrite(cu, astRoot);
295
296
		buf= new StringBuffer();
297
		buf.append("package test0008;\n");
298
		buf.append("public class X {\n");
299
		buf.append("    void getUsers() {}\n");
300
		buf.append("}\n");
301
		assertEqualString(preview, buf.toString());
302
	}
303
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=192233
304
	public void test0009() throws Exception {
305
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0009", false, null);
306
		StringBuffer buf= new StringBuffer();
307
		buf.append("package test0009;\n");
308
		buf.append("public class X {\n");
309
		buf.append("    List/**/ getUsers() {}\n");
310
		buf.append("}\n");
311
312
		ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
313
314
		CompilationUnit astRoot= createCU(cu, false, AST.JLS3);
315
316
		astRoot.recordModifications();
317
318
		AST ast = astRoot.getAST();
319
320
		List types = astRoot.types();
321
		List list= ((TypeDeclaration) types.get(0)).bodyDeclarations();
322
		MethodDeclaration methodDecl= (MethodDeclaration) list.get(0);
323
324
		methodDecl.setReturnType2(ast.newPrimitiveType(PrimitiveType.VOID));
325
326
		String preview = evaluateRewrite(cu, astRoot);
327
328
		buf= new StringBuffer();
329
		buf.append("package test0009;\n");
330
		buf.append("public class X {\n");
331
		buf.append("    void getUsers() {}\n");
332
		buf.append("}\n");
333
		assertEqualString(preview, buf.toString());
334
	}
335
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=192233
336
	public void test0010() throws Exception {
337
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0010", false, null);
338
		StringBuffer buf= new StringBuffer();
339
		buf.append("package test0010;\n");
340
		buf.append("public class X {\n");
341
		buf.append("    void getUsers(List/**/list) {}\n");
342
		buf.append("}\n");
343
344
		ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
345
346
		CompilationUnit astRoot= createCU(cu, false, AST.JLS3);
347
348
		astRoot.recordModifications();
349
350
		AST ast = astRoot.getAST();
351
352
		List types = astRoot.types();
353
		List list= ((TypeDeclaration) types.get(0)).bodyDeclarations();
354
		MethodDeclaration methodDecl= (MethodDeclaration) list.get(0);
355
		List parameters = methodDecl.parameters();
356
		SingleVariableDeclaration variableDeclaration = (SingleVariableDeclaration) parameters.get(0);
357
		variableDeclaration.setType(ast.newPrimitiveType(PrimitiveType.INT));
358
359
		String preview = evaluateRewrite(cu, astRoot);
360
361
		buf= new StringBuffer();
362
		buf.append("package test0010;\n");
363
		buf.append("public class X {\n");
364
		buf.append("    void getUsers(int list) {}\n");
365
		buf.append("}\n");
366
		assertEqualString(preview, buf.toString());
367
	}
368
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=192233
369
	public void test0011() throws Exception {
370
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0011", false, null);
371
		StringBuffer buf= new StringBuffer();
372
		buf.append("package test0011;\n");
373
		buf.append("public class X {\n");
374
		buf.append("    void getUsers(int i, List/**/list) {}\n");
375
		buf.append("}\n");
376
377
		ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
378
379
		CompilationUnit astRoot= createCU(cu, false, AST.JLS3);
380
381
		astRoot.recordModifications();
382
383
		AST ast = astRoot.getAST();
384
385
		List types = astRoot.types();
386
		List list= ((TypeDeclaration) types.get(0)).bodyDeclarations();
387
		MethodDeclaration methodDecl= (MethodDeclaration) list.get(0);
388
		List parameters = methodDecl.parameters();
389
		SingleVariableDeclaration variableDeclaration = (SingleVariableDeclaration) parameters.get(1);
390
		variableDeclaration.setType(ast.newPrimitiveType(PrimitiveType.INT));
391
392
		String preview = evaluateRewrite(cu, astRoot);
393
394
		buf= new StringBuffer();
395
		buf.append("package test0011;\n");
396
		buf.append("public class X {\n");
397
		buf.append("    void getUsers(int i, int list) {}\n");
398
		buf.append("}\n");
399
		assertEqualString(preview, buf.toString());
400
	}
401
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=192233
402
	public void test0012() throws Exception {
403
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0012", false, null);
404
		StringBuffer buf= new StringBuffer();
405
		buf.append("package test0012;\n");
406
		buf.append("public class X {\n");
407
		buf.append("    void getUsers(int i, List.../**/list) {}\n");
408
		buf.append("}\n");
409
410
		ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
411
412
		CompilationUnit astRoot= createCU(cu, false, AST.JLS3);
413
414
		astRoot.recordModifications();
415
416
		AST ast = astRoot.getAST();
417
418
		List types = astRoot.types();
419
		List list= ((TypeDeclaration) types.get(0)).bodyDeclarations();
420
		MethodDeclaration methodDecl= (MethodDeclaration) list.get(0);
421
		List parameters = methodDecl.parameters();
422
		SingleVariableDeclaration variableDeclaration = (SingleVariableDeclaration) parameters.get(1);
423
		variableDeclaration.setType(ast.newPrimitiveType(PrimitiveType.INT));
424
425
		String preview = evaluateRewrite(cu, astRoot);
426
427
		buf= new StringBuffer();
428
		buf.append("package test0012;\n");
429
		buf.append("public class X {\n");
430
		buf.append("    void getUsers(int i, int.../**/list) {}\n");
431
		buf.append("}\n");
432
		assertEqualString(preview, buf.toString());
433
	}
434
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=192233
435
	public void test0013() throws Exception {
436
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0013", false, null);
437
		StringBuffer buf= new StringBuffer();
438
		buf.append("package test0013;\n");
439
		buf.append("public class X {\n");
440
		buf.append("    List/**/list;\n");
441
		buf.append("}\n");
442
443
		ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
444
445
		CompilationUnit astRoot= createCU(cu, false, AST.JLS3);
446
447
		astRoot.recordModifications();
448
449
		AST ast = astRoot.getAST();
450
451
		List types = astRoot.types();
452
		List list= ((TypeDeclaration) types.get(0)).bodyDeclarations();
453
		FieldDeclaration fieldDeclaration= (FieldDeclaration) list.get(0);
454
		fieldDeclaration.setType(ast.newPrimitiveType(PrimitiveType.INT));
455
456
		String preview = evaluateRewrite(cu, astRoot);
457
458
		buf= new StringBuffer();
459
		buf.append("package test0013;\n");
460
		buf.append("public class X {\n");
461
		buf.append("    int list;\n");
462
		buf.append("}\n");
463
		assertEqualString(preview, buf.toString());
464
	}
239
}
465
}
(-)src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingTest.java (-2 / +9 lines)
Lines 82-91 Link Here
82
	}
82
	}
83
	public CompilationUnit createCU(
83
	public CompilationUnit createCU(
84
		ICompilationUnit unit,
84
		ICompilationUnit unit,
85
		boolean resolveBindings) {
85
		boolean resolveBindings,
86
		int astLevel) {
86
87
87
		try {
88
		try {
88
			ASTParser c = ASTParser.newParser(AST_INTERNAL_JLS2);
89
			ASTParser c = ASTParser.newParser(astLevel);
89
			c.setSource(unit);
90
			c.setSource(unit);
90
			c.setResolveBindings(resolveBindings);
91
			c.setResolveBindings(resolveBindings);
91
			ASTNode result = c.createAST(null);
92
			ASTNode result = c.createAST(null);
Lines 96-101 Link Here
96
		}
97
		}
97
	}
98
	}
98
99
100
	public CompilationUnit createCU(
101
			ICompilationUnit unit,
102
			boolean resolveBindings) {
103
		return createCU(unit, resolveBindings, AST_INTERNAL_JLS2);
104
	}
105
99
	public CompilationUnit createCU(char[] source) {
106
	public CompilationUnit createCU(char[] source) {
100
		if (source == null) {
107
		if (source == null) {
101
			throw new IllegalArgumentException();
108
			throw new IllegalArgumentException();

Return to bug 192233