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

Collapse All | Expand All

(-)a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest.java (-1 / +63 lines)
Lines 10-15 Link Here
10
 *     Sebastian Davids <sdavids@gmx.de> - testInvertEquals1-23
10
 *     Sebastian Davids <sdavids@gmx.de> - testInvertEquals1-23
11
 *     Lukas Hanke <hanke@yatta.de> - Bug 241696 [quick fix] quickfix to iterate over a collection - https://bugs.eclipse.org/bugs/show_bug.cgi?id=241696
11
 *     Lukas Hanke <hanke@yatta.de> - Bug 241696 [quick fix] quickfix to iterate over a collection - https://bugs.eclipse.org/bugs/show_bug.cgi?id=241696
12
 *     Lukas Hanke <hanke@yatta.de> - Bug 430818 [1.8][quick fix] Quick fix for "for loop" is not shown for bare local variable/argument/field - https://bugs.eclipse.org/bugs/show_bug.cgi?id=430818
12
 *     Lukas Hanke <hanke@yatta.de> - Bug 430818 [1.8][quick fix] Quick fix for "for loop" is not shown for bare local variable/argument/field - https://bugs.eclipse.org/bugs/show_bug.cgi?id=430818
13
 *     Sandra Lions <sandra.lions-piron@oracle.com> - [quick fix] Provide a quickfix to add 'finally' block - https://bugs.eclipse.org/bugs/show_bug.cgi?id=338785
13
 *******************************************************************************/
14
 *******************************************************************************/
14
package org.eclipse.jdt.ui.tests.quickfix;
15
package org.eclipse.jdt.ui.tests.quickfix;
15
16
Lines 2322-2328 public class AssistQuickFixTest extends QuickFixTest { Link Here
2322
		assertEqualStringsIgnoreOrder(new String[] { preview1, preview2, preview3, preview4 }, new String[] { expected1, expected2, expected3, expected4 });
2323
		assertEqualStringsIgnoreOrder(new String[] { preview1, preview2, preview3, preview4 }, new String[] { expected1, expected2, expected3, expected4 });
2323
	}
2324
	}
2324
2325
2325
	public void testUnwrapTryStatement() throws Exception {
2326
	public void testUnwrapTryStatement1() throws Exception {
2326
2327
2327
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
2328
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
2328
		StringBuffer buf= new StringBuffer();
2329
		StringBuffer buf= new StringBuffer();
Lines 2364-2369 public class AssistQuickFixTest extends QuickFixTest { Link Here
2364
		assertEqualString(preview, buf.toString());
2365
		assertEqualString(preview, buf.toString());
2365
	}
2366
	}
2366
2367
2368
	public void testUnwrapTryStatement2() throws Exception {
2369
2370
		final IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
2371
		StringBuffer buf= new StringBuffer();
2372
		buf.append("package test1;\n");
2373
		buf.append("public class E {\n");
2374
		buf.append("    public void foo() {\n");
2375
		buf.append("        try {\n");
2376
		buf.append("            StringBuffer buf= new StringBuffer();\n");
2377
		buf.append("            buf.append(1);\n");
2378
		buf.append("            buf.append(2);\n");
2379
		buf.append("            buf.append(3);\n");
2380
		buf.append("        }\n");
2381
		buf.append("    }\n");
2382
		buf.append("}\n");
2383
		ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null);
2384
2385
		final String str= "try";
2386
		final AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0);
2387
		final List proposals= collectAssists(context, false);
2388
2389
		assertNumberOfProposals(proposals, 2);
2390
		assertCorrectLabels(proposals);
2391
2392
		CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0);
2393
		final String preview1= getPreviewContent(proposal);
2394
2395
		buf= new StringBuffer();
2396
		buf.append("package test1;\n");
2397
		buf.append("public class E {\n");
2398
		buf.append("    public void foo() {\n");
2399
		buf.append("        try {\n");
2400
		buf.append("            StringBuffer buf= new StringBuffer();\n");
2401
		buf.append("            buf.append(1);\n");
2402
		buf.append("            buf.append(2);\n");
2403
		buf.append("            buf.append(3);\n");
2404
		buf.append("        } finally {\n");
2405
		buf.append("        }\n");
2406
		buf.append("    }\n");
2407
		buf.append("}\n");
2408
		final String expected1= buf.toString();
2409
2410
		proposal= (CUCorrectionProposal)proposals.get(1);
2411
		final String preview2= getPreviewContent(proposal);
2412
2413
		buf= new StringBuffer();
2414
		buf.append("package test1;\n");
2415
		buf.append("public class E {\n");
2416
		buf.append("    public void foo() {\n");
2417
		buf.append("        StringBuffer buf= new StringBuffer();\n");
2418
		buf.append("        buf.append(1);\n");
2419
		buf.append("        buf.append(2);\n");
2420
		buf.append("        buf.append(3);\n");
2421
		buf.append("    }\n");
2422
		buf.append("}\n");
2423
2424
		final String expected2= buf.toString();
2425
		
2426
		assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 });
2427
	}
2428
2367
	public void testUnwrapAnonymous() throws Exception {
2429
	public void testUnwrapAnonymous() throws Exception {
2368
2430
2369
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
2431
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java (+7 lines)
Lines 10-15 Link Here
10
 *     Renaud Waldura &lt;renaud+eclipse@waldura.com&gt; - Access to static proposal
10
 *     Renaud Waldura &lt;renaud+eclipse@waldura.com&gt; - Access to static proposal
11
 *     Benjamin Muskalla <bmuskalla@innoopract.com> - [quick fix] Shouldn't offer "Add throws declaration" quickfix for overriding signature if result would conflict with overridden signature
11
 *     Benjamin Muskalla <bmuskalla@innoopract.com> - [quick fix] Shouldn't offer "Add throws declaration" quickfix for overriding signature if result would conflict with overridden signature
12
 *     Lukas Hanke <hanke@yatta.de> - Bug 241696 [quick fix] quickfix to iterate over a collection - https://bugs.eclipse.org/bugs/show_bug.cgi?id=241696
12
 *     Lukas Hanke <hanke@yatta.de> - Bug 241696 [quick fix] quickfix to iterate over a collection - https://bugs.eclipse.org/bugs/show_bug.cgi?id=241696
13
 *     Sandra Lions <sandra.lions-piron@oracle.com> - [quick fix] Provide a quickfix to add 'finally' block - https://bugs.eclipse.org/bugs/show_bug.cgi?id=338785
13
 *******************************************************************************/
14
 *******************************************************************************/
14
package org.eclipse.jdt.internal.ui.text.correction;
15
package org.eclipse.jdt.internal.ui.text.correction;
15
16
Lines 1861-1864 public class LocalCorrectionsSubProcessor { Link Here
1861
		}
1862
		}
1862
	}
1863
	}
1863
1864
1865
	public static void getAddFinallyProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
1866
		ASTNode coveringNode= problem.getCoveringNode(context.getASTRoot());
1867
		if (coveringNode != null) {
1868
			QuickAssistProcessor.getAddFinallyProposals(context, coveringNode, proposals);
1869
		}
1870
	}
1864
}
1871
}
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickAssistProcessor.java (-2 / +3 lines)
Lines 13-18 Link Here
13
 *     Lukas Hanke <hanke@yatta.de> - Bug 241696 [quick fix] quickfix to iterate over a collection - https://bugs.eclipse.org/bugs/show_bug.cgi?id=241696
13
 *     Lukas Hanke <hanke@yatta.de> - Bug 241696 [quick fix] quickfix to iterate over a collection - https://bugs.eclipse.org/bugs/show_bug.cgi?id=241696
14
 *     Eugene Lucash <e.lucash@gmail.com> - [quick assist] Add key binding for Extract method Quick Assist - https://bugs.eclipse.org/424166
14
 *     Eugene Lucash <e.lucash@gmail.com> - [quick assist] Add key binding for Extract method Quick Assist - https://bugs.eclipse.org/424166
15
 *     Lukas Hanke <hanke@yatta.de> - Bug 430818 [1.8][quick fix] Quick fix for "for loop" is not shown for bare local variable/argument/field - https://bugs.eclipse.org/bugs/show_bug.cgi?id=430818
15
 *     Lukas Hanke <hanke@yatta.de> - Bug 430818 [1.8][quick fix] Quick fix for "for loop" is not shown for bare local variable/argument/field - https://bugs.eclipse.org/bugs/show_bug.cgi?id=430818
16
 *     Sandra Lions <sandra.lions-piron@oracle.com> - [quick fix] Provide a quickfix to add 'finally' block - https://bugs.eclipse.org/bugs/show_bug.cgi?id=338785
16
 *******************************************************************************/
17
 *******************************************************************************/
17
package org.eclipse.jdt.internal.ui.text.correction;
18
package org.eclipse.jdt.internal.ui.text.correction;
18
19
Lines 1388-1396 public class QuickAssistProcessor implements IQuickAssistProcessor { Link Here
1388
		return true;
1389
		return true;
1389
	}
1390
	}
1390
1391
1391
	private static boolean getAddFinallyProposals(IInvocationContext context, ASTNode node, Collection<ICommandAccess> resultingCollections) {
1392
	public static boolean getAddFinallyProposals(IInvocationContext context, ASTNode node, Collection<ICommandAccess> resultingCollections) {
1392
		TryStatement tryStatement= ASTResolving.findParentTryStatement(node);
1393
		TryStatement tryStatement= ASTResolving.findParentTryStatement(node);
1393
		if (tryStatement == null || tryStatement.getFinally() != null) {
1394
		if (tryStatement == null || (tryStatement.getFinally() != null && tryStatement.getFinally().getLength() != 0)) {
1394
			return false;
1395
			return false;
1395
		}
1396
		}
1396
		Statement statement= ASTResolving.findParentStatement(node);
1397
		Statement statement= ASTResolving.findParentStatement(node);
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java (+5 lines)
Lines 14-19 Link Here
14
 *								[quick fix] don't propose null annotations when those are disabled - https://bugs.eclipse.org/405086
14
 *								[quick fix] don't propose null annotations when those are disabled - https://bugs.eclipse.org/405086
15
 *								[quickfix] Update null annotation quick fixes for bug 388281 - https://bugs.eclipse.org/395555
15
 *								[quickfix] Update null annotation quick fixes for bug 388281 - https://bugs.eclipse.org/395555
16
 *     Lukas Hanke <hanke@yatta.de> - Bug 241696 [quick fix] quickfix to iterate over a collection - https://bugs.eclipse.org/bugs/show_bug.cgi?id=241696
16
 *     Lukas Hanke <hanke@yatta.de> - Bug 241696 [quick fix] quickfix to iterate over a collection - https://bugs.eclipse.org/bugs/show_bug.cgi?id=241696
17
 *     Sandra Lions <sandra.lions-piron@oracle.com> - [quick fix] Provide a quickfix to add 'finally' block - https://bugs.eclipse.org/bugs/show_bug.cgi?id=338785
17
 *******************************************************************************/
18
 *******************************************************************************/
18
package org.eclipse.jdt.internal.ui.text.correction;
19
package org.eclipse.jdt.internal.ui.text.correction;
19
20
Lines 273-278 public class QuickFixProcessor implements IQuickFixProcessor { Link Here
273
			case IProblem.ConstructorReferenceNotBelow18:
274
			case IProblem.ConstructorReferenceNotBelow18:
274
			case IProblem.IntersectionCastNotBelow18:
275
			case IProblem.IntersectionCastNotBelow18:
275
			case IProblem.InvalidUsageOfTypeAnnotations:
276
			case IProblem.InvalidUsageOfTypeAnnotations:
277
			case IProblem.ParsingErrorInsertToComplete:
276
				return true;
278
				return true;
277
			default:
279
			default:
278
				return SuppressWarningsSubProcessor.hasSuppressWarningsProposal(cu.getJavaProject(), problemId);
280
				return SuppressWarningsSubProcessor.hasSuppressWarningsProposal(cu.getJavaProject(), problemId);
Lines 760-765 public class QuickFixProcessor implements IQuickFixProcessor { Link Here
760
				NullAnnotationsCorrectionProcessor.addReturnAndArgumentTypeProposal(context, problem, ChangeKind.LOCAL, proposals);
762
				NullAnnotationsCorrectionProcessor.addReturnAndArgumentTypeProposal(context, problem, ChangeKind.LOCAL, proposals);
761
				NullAnnotationsCorrectionProcessor.addReturnAndArgumentTypeProposal(context, problem, ChangeKind.INVERSE, proposals);
763
				NullAnnotationsCorrectionProcessor.addReturnAndArgumentTypeProposal(context, problem, ChangeKind.INVERSE, proposals);
762
				break;
764
				break;
765
			case IProblem.ParsingErrorInsertToComplete:
766
				LocalCorrectionsSubProcessor.getAddFinallyProposals(context, problem, proposals);
767
				break;
763
			default:
768
			default:
764
		}
769
		}
765
		if (JavaModelUtil.is50OrHigher(context.getCompilationUnit().getJavaProject())) {
770
		if (JavaModelUtil.is50OrHigher(context.getCompilationUnit().getJavaProject())) {

Return to bug 338785