Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 244276 Details for
Bug 338785
[quick fix] Provide a quickfix to add 'finally' block
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Unit Test + Patch version 2
338785_v2.diff (text/plain), 9.71 KB, created by
sandra lions
on 2014-06-16 04:27:17 EDT
(
hide
)
Description:
Unit Test + Patch version 2
Filename:
MIME Type:
Creator:
sandra lions
Created:
2014-06-16 04:27:17 EDT
Size:
9.71 KB
patch
obsolete
>diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest.java >index 500f32c..84b7fa4 100644 >--- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest.java >+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest.java >@@ -10,6 +10,7 @@ > * Sebastian Davids <sdavids@gmx.de> - testInvertEquals1-23 > * 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 > * 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 >+ * 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 > *******************************************************************************/ > package org.eclipse.jdt.ui.tests.quickfix; > >@@ -2322,7 +2323,7 @@ public class AssistQuickFixTest extends QuickFixTest { > assertEqualStringsIgnoreOrder(new String[] { preview1, preview2, preview3, preview4 }, new String[] { expected1, expected2, expected3, expected4 }); > } > >- public void testUnwrapTryStatement() throws Exception { >+ public void testUnwrapTryStatement1() throws Exception { > > IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); > StringBuffer buf= new StringBuffer(); >@@ -2364,6 +2365,67 @@ public class AssistQuickFixTest extends QuickFixTest { > assertEqualString(preview, buf.toString()); > } > >+ public void testUnwrapTryStatement2() throws Exception { >+ >+ final IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo() {\n"); >+ buf.append(" try {\n"); >+ buf.append(" StringBuffer buf= new StringBuffer();\n"); >+ buf.append(" buf.append(1);\n"); >+ buf.append(" buf.append(2);\n"); >+ buf.append(" buf.append(3);\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ final String str= "try"; >+ final AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0); >+ final List proposals= collectAssists(context, false); >+ >+ assertNumberOfProposals(proposals, 2); >+ assertCorrectLabels(proposals); >+ >+ CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); >+ final String preview1= getPreviewContent(proposal); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo() {\n"); >+ buf.append(" try {\n"); >+ buf.append(" StringBuffer buf= new StringBuffer();\n"); >+ buf.append(" buf.append(1);\n"); >+ buf.append(" buf.append(2);\n"); >+ buf.append(" buf.append(3);\n"); >+ buf.append(" } finally {\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ final String expected1= buf.toString(); >+ >+ proposal= (CUCorrectionProposal)proposals.get(1); >+ final String preview2= getPreviewContent(proposal); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo() {\n"); >+ buf.append(" StringBuffer buf= new StringBuffer();\n"); >+ buf.append(" buf.append(1);\n"); >+ buf.append(" buf.append(2);\n"); >+ buf.append(" buf.append(3);\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ >+ final String expected2= buf.toString(); >+ >+ assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 }); >+ } >+ > public void testUnwrapAnonymous() throws Exception { > > IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java >index a91c77e..c195017 100644 >--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java >+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java >@@ -10,6 +10,7 @@ > * Renaud Waldura <renaud+eclipse@waldura.com> - Access to static proposal > * Benjamin Muskalla <bmuskalla@innoopract.com> - [quick fix] Shouldn't offer "Add throws declaration" quickfix for overriding signature if result would conflict with overridden signature > * 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 >+ * 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 > *******************************************************************************/ > package org.eclipse.jdt.internal.ui.text.correction; > >@@ -1861,4 +1862,10 @@ public class LocalCorrectionsSubProcessor { > } > } > >+ public static void getAddFinallyProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { >+ ASTNode coveringNode= problem.getCoveringNode(context.getASTRoot()); >+ if (coveringNode != null) { >+ QuickAssistProcessor.getAddFinallyProposals(context, coveringNode, proposals); >+ } >+ } > } >diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickAssistProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickAssistProcessor.java >index 83c64a7..0c557d7 100644 >--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickAssistProcessor.java >+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickAssistProcessor.java >@@ -13,6 +13,7 @@ > * 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 > * Eugene Lucash <e.lucash@gmail.com> - [quick assist] Add key binding for Extract method Quick Assist - https://bugs.eclipse.org/424166 > * 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 >+ * 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 > *******************************************************************************/ > package org.eclipse.jdt.internal.ui.text.correction; > >@@ -1388,9 +1389,9 @@ public class QuickAssistProcessor implements IQuickAssistProcessor { > return true; > } > >- private static boolean getAddFinallyProposals(IInvocationContext context, ASTNode node, Collection<ICommandAccess> resultingCollections) { >+ public static boolean getAddFinallyProposals(IInvocationContext context, ASTNode node, Collection<ICommandAccess> resultingCollections) { > TryStatement tryStatement= ASTResolving.findParentTryStatement(node); >- if (tryStatement == null || tryStatement.getFinally() != null) { >+ if (tryStatement == null || (tryStatement.getFinally() != null && tryStatement.getFinally().getLength() != 0)) { > return false; > } > Statement statement= ASTResolving.findParentStatement(node); >diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java >index 0ef12af..6e85be0 100644 >--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java >+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java >@@ -14,6 +14,7 @@ > * [quick fix] don't propose null annotations when those are disabled - https://bugs.eclipse.org/405086 > * [quickfix] Update null annotation quick fixes for bug 388281 - https://bugs.eclipse.org/395555 > * 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 >+ * 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 > *******************************************************************************/ > package org.eclipse.jdt.internal.ui.text.correction; > >@@ -273,6 +274,7 @@ public class QuickFixProcessor implements IQuickFixProcessor { > case IProblem.ConstructorReferenceNotBelow18: > case IProblem.IntersectionCastNotBelow18: > case IProblem.InvalidUsageOfTypeAnnotations: >+ case IProblem.ParsingErrorInsertToComplete: > return true; > default: > return SuppressWarningsSubProcessor.hasSuppressWarningsProposal(cu.getJavaProject(), problemId); >@@ -760,6 +762,9 @@ public class QuickFixProcessor implements IQuickFixProcessor { > NullAnnotationsCorrectionProcessor.addReturnAndArgumentTypeProposal(context, problem, ChangeKind.LOCAL, proposals); > NullAnnotationsCorrectionProcessor.addReturnAndArgumentTypeProposal(context, problem, ChangeKind.INVERSE, proposals); > break; >+ case IProblem.ParsingErrorInsertToComplete: >+ LocalCorrectionsSubProcessor.getAddFinallyProposals(context, problem, proposals); >+ break; > default: > } > if (JavaModelUtil.is50OrHigher(context.getCompilationUnit().getJavaProject())) {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 338785
:
243234
| 244276