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 197665 Details for
Bug 348061
[1.7] [quick assist] Quick assists to convert multiple catch blocks to a single multi-catch block and vice versa
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
fix + tests
multicatch3.txt (text/plain), 31.50 KB, created by
Deepak Azad
on 2011-06-09 02:02:27 EDT
(
hide
)
Description:
fix + tests
Filename:
MIME Type:
Creator:
Deepak Azad
Created:
2011-06-09 02:02:27 EDT
Size:
31.50 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.ui >Index: ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java,v >retrieving revision 1.92.2.4 >diff -u -r1.92.2.4 CorrectionMessages.java >--- ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java 9 Jun 2011 04:02:38 -0000 1.92.2.4 >+++ ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java 9 Jun 2011 06:01:20 -0000 >@@ -45,6 +45,8 @@ > public static String QuickAssistProcessor_convert_anonym_to_nested; > public static String QuickAssistProcessor_convert_local_to_field_description; > public static String QuickAssistProcessor_convert_to_message_format; >+ public static String QuickAssistProcessor_convert_to_multiple_singletype_catch_blocks; >+ public static String QuickAssistProcessor_convert_to_single_multicatch_block; > public static String QuickAssistProcessor_convert_to_string_buffer_description; > public static String QuickAssistProcessor_extract_to_constant_description; > public static String QuickAssistProcessor_inline_local_description; >Index: ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties,v >retrieving revision 1.268.2.5 >diff -u -r1.268.2.5 CorrectionMessages.properties >--- ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties 9 Jun 2011 04:02:38 -0000 1.268.2.5 >+++ ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties 9 Jun 2011 06:01:20 -0000 >@@ -327,6 +327,8 @@ > QuickAssistProcessor_typetoarrayInitializer_description=Add type to initializer > QuickAssistProcessor_convert_local_to_field_description=Convert local variable to field > QuickAssistProcessor_convert_to_message_format=Use 'MessageFormat' for string concatenation >+QuickAssistProcessor_convert_to_multiple_singletype_catch_blocks=Convert to multiple single-type catch blocks >+QuickAssistProcessor_convert_to_single_multicatch_block=Convert to a single multi-catch block > QuickAssistProcessor_convert_to_string_buffer_description=Use ''{0}'' for string concatenation > QuickAssistProcessor_createmethodinsuper_description=Create ''{1}()'' in super type ''{0}'' > >Index: ui/org/eclipse/jdt/internal/ui/text/correction/QuickAssistProcessor.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickAssistProcessor.java,v >retrieving revision 1.168.2.1 >diff -u -r1.168.2.1 QuickAssistProcessor.java >--- ui/org/eclipse/jdt/internal/ui/text/correction/QuickAssistProcessor.java 11 Mar 2011 13:03:51 -0000 1.168.2.1 >+++ ui/org/eclipse/jdt/internal/ui/text/correction/QuickAssistProcessor.java 9 Jun 2011 06:01:21 -0000 >@@ -5,6 +5,10 @@ > * which accompanies this distribution, and is available at > * http://www.eclipse.org/legal/epl-v10.html > * >+ * This is an implementation of an early-draft specification developed under the Java >+ * Community Process (JCP) and is made available for testing and evaluation purposes >+ * only. The code is not compatible with any specification of the JCP. >+ * > * Contributors: > * IBM Corporation - initial API and implementation > * Sebastian Davids <sdavids@gmx.de> - Bug 37432 getInvertEqualsProposal >@@ -40,11 +44,13 @@ > import org.eclipse.ltk.core.refactoring.TextFileChange; > > import org.eclipse.jdt.core.Flags; >+import org.eclipse.jdt.core.IBuffer; > import org.eclipse.jdt.core.ICompilationUnit; > import org.eclipse.jdt.core.IJavaElement; > import org.eclipse.jdt.core.IJavaModelMarker; > import org.eclipse.jdt.core.IType; > import org.eclipse.jdt.core.JavaCore; >+import org.eclipse.jdt.core.JavaModelException; > import org.eclipse.jdt.core.NamingConventions; > import org.eclipse.jdt.core.compiler.IProblem; > import org.eclipse.jdt.core.dom.AST; >@@ -94,6 +100,7 @@ > import org.eclipse.jdt.core.dom.TryStatement; > import org.eclipse.jdt.core.dom.Type; > import org.eclipse.jdt.core.dom.TypeDeclaration; >+import org.eclipse.jdt.core.dom.UnionType; > import org.eclipse.jdt.core.dom.VariableDeclaration; > import org.eclipse.jdt.core.dom.VariableDeclarationExpression; > import org.eclipse.jdt.core.dom.VariableDeclarationFragment; >@@ -182,6 +189,8 @@ > ASTNode coveringNode= context.getCoveringNode(); > if (coveringNode != null) { > return getCatchClauseToThrowsProposals(context, coveringNode, null) >+ || getConvertToMultiCatchProposals(context, coveringNode, null) >+ || getUnrollMultiCatchProposals(context, coveringNode, null) > || getRenameLocalProposals(context, coveringNode, null, null) > || getRenameRefactoringProposal(context, coveringNode, null, null) > || getAssignToVariableProposals(context, coveringNode, null, null) >@@ -225,6 +234,8 @@ > if (noErrorsAtLocation) { > boolean problemsAtLocation= locations.length != 0; > getCatchClauseToThrowsProposals(context, coveringNode, resultingCollections); >+ getConvertToMultiCatchProposals(context, coveringNode, resultingCollections); >+ getUnrollMultiCatchProposals(context, coveringNode, resultingCollections); > getUnWrapProposals(context, coveringNode, resultingCollections); > getJoinVariableProposals(context, coveringNode, resultingCollections); > getSplitVariableProposals(context, coveringNode, resultingCollections); >@@ -1253,6 +1264,121 @@ > return true; > } > >+ private static boolean getConvertToMultiCatchProposals(IInvocationContext context, ASTNode covering, Collection<ICommandAccess> resultingCollections) { >+ if (!JavaModelUtil.is70OrHigher(context.getCompilationUnit().getJavaProject())) >+ return false; >+ >+ if (!(covering instanceof CatchClause)) >+ return false; >+ TryStatement tryStatement= (TryStatement) covering.getParent(); >+ List<CatchClause> catchClauses= tryStatement.catchClauses(); >+ if (catchClauses.size() <= 1) >+ return false; >+ >+ String commonSource= null; >+ try { >+ IBuffer buffer= context.getCompilationUnit().getBuffer(); >+ for (Iterator<CatchClause> iterator= catchClauses.iterator(); iterator.hasNext();) { >+ CatchClause catchClause= iterator.next(); >+ Block body= catchClause.getBody(); >+ String source= buffer.getText(body.getStartPosition(), body.getLength()); >+ if (commonSource == null) { >+ commonSource= source; >+ } else { >+ if (!commonSource.equals(source)) >+ return false; >+ } >+ } >+ } catch (JavaModelException e) { >+ return false; >+ } >+ >+ if (resultingCollections == null) >+ return true; >+ >+ AST ast= covering.getAST(); >+ ASTRewrite rewrite= ASTRewrite.create(ast); >+ CatchClause firstCatchClause= catchClauses.get(0); >+ >+ UnionType newUnionType= ast.newUnionType(); >+ List<Type> types= newUnionType.types(); >+ for (Iterator<CatchClause> iterator= catchClauses.iterator(); iterator.hasNext();) { >+ CatchClause catchClause= iterator.next(); >+ Type type= catchClause.getException().getType(); >+ if (type instanceof UnionType) { >+ List<Type> types2= ((UnionType) type).types(); >+ for (Iterator<Type> iterator2= types2.iterator(); iterator2.hasNext();) { >+ types.add((Type) rewrite.createCopyTarget(iterator2.next())); >+ } >+ } else { >+ types.add((Type) rewrite.createCopyTarget(type)); >+ } >+ } >+ >+ SingleVariableDeclaration newExceptionDeclaration= ast.newSingleVariableDeclaration(); >+ newExceptionDeclaration.setType(newUnionType); >+ newExceptionDeclaration.setName((SimpleName) rewrite.createCopyTarget(firstCatchClause.getException().getName())); >+ rewrite.replace(firstCatchClause.getException(), newExceptionDeclaration, null); >+ >+ for (int i= 1; i < catchClauses.size(); i++) { >+ rewrite.remove(catchClauses.get(i), null); >+ } >+ >+ Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); >+ String label= CorrectionMessages.QuickAssistProcessor_convert_to_single_multicatch_block; >+ ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, 2, image); >+ resultingCollections.add(proposal); >+ return true; >+ } >+ >+ private static boolean getUnrollMultiCatchProposals(IInvocationContext context, ASTNode covering, Collection<ICommandAccess> resultingCollections) { >+ if (!JavaModelUtil.is70OrHigher(context.getCompilationUnit().getJavaProject())) >+ return false; >+ >+ if (!(covering instanceof CatchClause)) >+ return false; >+ >+ CatchClause catchClause= (CatchClause) covering; >+ SingleVariableDeclaration singleVariableDeclaration= catchClause.getException(); >+ Type type= singleVariableDeclaration.getType(); >+ if (!(type instanceof UnionType)) >+ return false; >+ >+ if (resultingCollections == null) >+ return true; >+ >+ AST ast= covering.getAST(); >+ ASTRewrite rewrite= ASTRewrite.create(ast); >+ >+ TryStatement tryStatement= (TryStatement) covering.getParent(); >+ ListRewrite listRewrite= rewrite.getListRewrite(tryStatement, TryStatement.CATCH_CLAUSES_PROPERTY); >+ >+ UnionType unionType= (UnionType) type; >+ List<Type> types= unionType.types(); >+ for (int i= types.size() - 1; i >= 0; i--) { >+ Type type2= types.get(i); >+ CatchClause newCatchClause= ast.newCatchClause(); >+ >+ SingleVariableDeclaration newSingleVariableDeclaration= ast.newSingleVariableDeclaration(); >+ newSingleVariableDeclaration.setType((Type) rewrite.createCopyTarget(type2)); >+ newSingleVariableDeclaration.setName((SimpleName) rewrite.createCopyTarget(singleVariableDeclaration.getName())); >+ newCatchClause.setException(newSingleVariableDeclaration); >+ >+ //newCatchClause#setBody() destroys the formatting, hence copy statement by statement >+ List<Statement> statements= catchClause.getBody().statements(); >+ for (Iterator<Statement> iterator2= statements.iterator(); iterator2.hasNext();) { >+ newCatchClause.getBody().statements().add(rewrite.createCopyTarget(iterator2.next())); >+ } >+ listRewrite.insertAfter(newCatchClause, catchClause, null); >+ } >+ rewrite.remove(catchClause, null); >+ >+ Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); >+ String label= CorrectionMessages.QuickAssistProcessor_convert_to_multiple_singletype_catch_blocks; >+ ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, 2, image); >+ resultingCollections.add(proposal); >+ return true; >+ } > > private static boolean getRenameLocalProposals(IInvocationContext context, ASTNode node, IProblemLocation[] locations, Collection<ICommandAccess> resultingCollections) { > if (!(node instanceof SimpleName)) { >#P org.eclipse.jdt.ui.tests >Index: ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest17.java >=================================================================== >RCS file: ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest17.java >diff -N ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest17.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest17.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,497 @@ >+/******************************************************************************* >+ * Copyright (c) 2011 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * This is an implementation of an early-draft specification developed under the Java >+ * Community Process (JCP) and is made available for testing and evaluation purposes >+ * only. The code is not compatible with any specification of the JCP. >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.ui.tests.quickfix; >+ >+import java.util.Hashtable; >+import java.util.List; >+ >+import junit.framework.Test; >+import junit.framework.TestSuite; >+ >+import org.eclipse.jdt.testplugin.JavaProjectHelper; >+import org.eclipse.jdt.testplugin.TestOptions; >+ >+import org.eclipse.core.runtime.Preferences; >+ >+import org.eclipse.jface.preference.IPreferenceStore; >+ >+import org.eclipse.jdt.core.ICompilationUnit; >+import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.IPackageFragment; >+import org.eclipse.jdt.core.IPackageFragmentRoot; >+import org.eclipse.jdt.core.JavaCore; >+import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; >+ >+import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility; >+import org.eclipse.jdt.internal.corext.template.java.CodeTemplateContextType; >+ >+import org.eclipse.jdt.ui.PreferenceConstants; >+import org.eclipse.jdt.ui.tests.core.Java17ProjectTestSetup; >+import org.eclipse.jdt.ui.tests.core.ProjectTestSetup; >+ >+import org.eclipse.jdt.internal.ui.JavaPlugin; >+import org.eclipse.jdt.internal.ui.text.correction.AssistContext; >+ >+public class AssistQuickFixTest17 extends QuickFixTest { >+ >+ private static final String CONVERT_TO_A_SINGLE_MULTI_CATCH_BLOCK= "Convert to a single multi-catch block"; >+ private static final String CONVERT_TO_MULTIPLE_CATCH_BLOCKS= "Convert to multiple catch blocks"; >+ >+ private static final Class THIS= AssistQuickFixTest17.class; >+ >+ private IJavaProject fJProject1; >+ >+ private IPackageFragmentRoot fSourceFolder; >+ >+ public AssistQuickFixTest17(String name) { >+ super(name); >+ } >+ >+ public static Test suite() { >+ return setUpTest(new TestSuite(THIS)); >+ } >+ >+ public static Test setUpTest(Test test) { >+ return new Java17ProjectTestSetup(test); >+ } >+ >+ protected void setUp() throws Exception { >+ Hashtable options= TestOptions.getDefaultOptions(); >+ options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE); >+ options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4"); >+ >+ JavaCore.setOptions(options); >+ >+ IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore(); >+ store.setValue(PreferenceConstants.CODEGEN_ADD_COMMENTS, false); >+ store.setValue(PreferenceConstants.CODEGEN_KEYWORD_THIS, false); >+ >+ StubUtility.setCodeTemplate(CodeTemplateContextType.METHODSTUB_ID, "//TODO\n${body_statement}", null); >+ >+ Preferences corePrefs= JavaPlugin.getJavaCorePluginPreferences(); >+ corePrefs.setValue(JavaCore.CODEASSIST_FIELD_PREFIXES, ""); >+ corePrefs.setValue(JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES, ""); >+ corePrefs.setValue(JavaCore.CODEASSIST_FIELD_SUFFIXES, ""); >+ corePrefs.setValue(JavaCore.CODEASSIST_STATIC_FIELD_SUFFIXES, ""); >+ >+ fJProject1= ProjectTestSetup.getProject(); >+ >+ fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); >+ } >+ >+ protected void tearDown() throws Exception { >+ JavaProjectHelper.clear(fJProject1, Java17ProjectTestSetup.getDefaultClasspath()); >+ } >+ >+ public void testConvertToMultiCatch1() throws Exception { >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" void foo() {\n"); >+ buf.append(" try {\n"); >+ buf.append(" System.out.println(\"foo\");\n"); >+ buf.append(" } catch (IllegalArgumentException ex) {\n"); >+ buf.append(" ex.printStackTrace();\n"); >+ buf.append(" } catch (NullPointerException ex) {\n"); >+ buf.append(" ex.printStackTrace();\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ int offset= buf.toString().indexOf("catch"); >+ AssistContext context= getCorrectionContext(cu, offset, 0); >+ assertNoErrors(context); >+ List proposals= collectAssists(context, false); >+ >+ assertCorrectLabels(proposals); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" void foo() {\n"); >+ buf.append(" try {\n"); >+ buf.append(" System.out.println(\"foo\");\n"); >+ buf.append(" } catch (IllegalArgumentException | NullPointerException ex) {\n"); >+ buf.append(" ex.printStackTrace();\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertExpectedExistInProposals(proposals, new String[] { expected1 }); >+ } >+ >+ public void testConvertToMultiCatch2() throws Exception { >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" void foo() {\n"); >+ buf.append(" try {\n"); >+ buf.append(" System.out.println(\"foo\");\n"); >+ buf.append(" } catch (IllegalArgumentException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" } catch (NullPointerException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ int offset= buf.toString().indexOf("catch"); >+ AssistContext context= getCorrectionContext(cu, offset, 0); >+ assertNoErrors(context); >+ List proposals= collectAssists(context, false); >+ >+ assertCorrectLabels(proposals); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" void foo() {\n"); >+ buf.append(" try {\n"); >+ buf.append(" System.out.println(\"foo\");\n"); >+ buf.append(" } catch (IllegalArgumentException | NullPointerException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertExpectedExistInProposals(proposals, new String[] { expected1 }); >+ >+ } >+ >+ public void testConvertToMultiCatch3() throws Exception { >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" void foo() {\n"); >+ buf.append(" try {\n"); >+ buf.append(" System.out.println(\"foo\");\n"); >+ buf.append(" } catch (IllegalArgumentException | NullPointerException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" } catch (RuntimeException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ int offset= buf.toString().indexOf("catch"); >+ AssistContext context= getCorrectionContext(cu, offset, 0); >+ assertNoErrors(context); >+ List proposals= collectAssists(context, false); >+ >+ assertCorrectLabels(proposals); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" void foo() {\n"); >+ buf.append(" try {\n"); >+ buf.append(" System.out.println(\"foo\");\n"); >+ buf.append(" } catch (IllegalArgumentException | NullPointerException | RuntimeException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertExpectedExistInProposals(proposals, new String[] { expected1 }); >+ } >+ >+ public void testConvertToMultiCatch4() throws Exception { >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" void foo() {\n"); >+ buf.append(" try {\n"); >+ buf.append(" System.out.println(\"foo\");\n"); >+ buf.append(" } catch (IllegalArgumentException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" } catch (NullPointerException e) {\n"); >+ buf.append(" \n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ int offset= buf.toString().indexOf("catch"); >+ AssistContext context= getCorrectionContext(cu, offset, 0); >+ assertNoErrors(context); >+ List proposals= collectAssists(context, false); >+ >+ assertProposalDoesNotExist(proposals, CONVERT_TO_A_SINGLE_MULTI_CATCH_BLOCK); >+ } >+ >+ public void testConvertToMultiCatch5() throws Exception { >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" void foo() {\n"); >+ buf.append(" try {\n"); >+ buf.append(" System.out.println(\"foo\");\n"); >+ buf.append(" } catch (IllegalArgumentException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ int offset= buf.toString().indexOf("catch"); >+ AssistContext context= getCorrectionContext(cu, offset, 0); >+ assertNoErrors(context); >+ List proposals= collectAssists(context, false); >+ >+ assertProposalDoesNotExist(proposals, CONVERT_TO_A_SINGLE_MULTI_CATCH_BLOCK); >+ } >+ >+ public void testConvertToMultiCatch6() throws Exception { >+ //Quick assist should not be offered in 1.5 mode >+ JavaProjectHelper.set15CompilerOptions(fJProject1); >+ try { >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" void foo() {\n"); >+ buf.append(" try {\n"); >+ buf.append(" System.out.println(\"foo\");\n"); >+ buf.append(" } catch (IllegalArgumentException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" } catch (NullPointerException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ int offset= buf.toString().indexOf("catch"); >+ AssistContext context= getCorrectionContext(cu, offset, 0); >+ assertNoErrors(context); >+ List proposals= collectAssists(context, false); >+ >+ assertProposalDoesNotExist(proposals, CONVERT_TO_A_SINGLE_MULTI_CATCH_BLOCK); >+ } finally { >+ JavaProjectHelper.set17CompilerOptions(fJProject1); >+ } >+ } >+ >+ public void testUnrollMultiCatch1() throws Exception { >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" void foo() {\n"); >+ buf.append(" try {\n"); >+ buf.append(" System.out.println(\"foo\");\n"); >+ buf.append(" } catch (IllegalArgumentException | NullPointerException ex) {\n"); >+ buf.append(" ex.printStackTrace();\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ int offset= buf.toString().indexOf("catch"); >+ AssistContext context= getCorrectionContext(cu, offset, 0); >+ assertNoErrors(context); >+ List proposals= collectAssists(context, false); >+ >+ assertCorrectLabels(proposals); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" void foo() {\n"); >+ buf.append(" try {\n"); >+ buf.append(" System.out.println(\"foo\");\n"); >+ buf.append(" } catch (IllegalArgumentException ex) {\n"); >+ buf.append(" ex.printStackTrace();\n"); >+ buf.append(" } catch (NullPointerException ex) {\n"); >+ buf.append(" ex.printStackTrace();\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertExpectedExistInProposals(proposals, new String[] { expected1 }); >+ } >+ >+ public void testUnrollMultiCatch2() throws Exception { >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" void foo() {\n"); >+ buf.append(" try {\n"); >+ buf.append(" System.out.println(\"foo\");\n"); >+ buf.append(" } catch (IllegalArgumentException | NullPointerException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" } catch (RuntimeException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ int offset= buf.toString().indexOf("catch"); >+ AssistContext context= getCorrectionContext(cu, offset, 0); >+ assertNoErrors(context); >+ List proposals= collectAssists(context, false); >+ >+ assertCorrectLabels(proposals); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" void foo() {\n"); >+ buf.append(" try {\n"); >+ buf.append(" System.out.println(\"foo\");\n"); >+ buf.append(" } catch (IllegalArgumentException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" } catch (NullPointerException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" } catch (RuntimeException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertExpectedExistInProposals(proposals, new String[] { expected1 }); >+ } >+ >+ public void testUnrollMultiCatch3() throws Exception { >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" void foo() {\n"); >+ buf.append(" try {\n"); >+ buf.append(" System.out.println(\"foo\");\n"); >+ buf.append(" } catch (IllegalArgumentException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" } catch (NullPointerException | ClassCastException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ int offset= buf.toString().indexOf("catch (NullPointerException"); >+ AssistContext context= getCorrectionContext(cu, offset, 0); >+ assertNoErrors(context); >+ List proposals= collectAssists(context, false); >+ >+ assertCorrectLabels(proposals); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" void foo() {\n"); >+ buf.append(" try {\n"); >+ buf.append(" System.out.println(\"foo\");\n"); >+ buf.append(" } catch (IllegalArgumentException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" } catch (NullPointerException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" } catch (ClassCastException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertExpectedExistInProposals(proposals, new String[] { expected1 }); >+ } >+ >+ public void testUnrollMultiCatch4() throws Exception { >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" void foo() {\n"); >+ buf.append(" try {\n"); >+ buf.append(" System.out.println(\"foo\");\n"); >+ buf.append(" } catch (IllegalArgumentException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" } catch (NullPointerException | ClassCastException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" } catch (ArrayIndexOutOfBoundsException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ int offset= buf.toString().indexOf("catch (NullPointerException"); >+ AssistContext context= getCorrectionContext(cu, offset, 0); >+ assertNoErrors(context); >+ List proposals= collectAssists(context, false); >+ >+ assertCorrectLabels(proposals); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" void foo() {\n"); >+ buf.append(" try {\n"); >+ buf.append(" System.out.println(\"foo\");\n"); >+ buf.append(" } catch (IllegalArgumentException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" } catch (NullPointerException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" } catch (ClassCastException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" } catch (ArrayIndexOutOfBoundsException e) {\n"); >+ buf.append(" e.printStackTrace();\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ String expected1= buf.toString(); >+ >+ assertExpectedExistInProposals(proposals, new String[] { expected1 }); >+ } >+ >+ public void testUnrollMultiCatch5() throws Exception { >+ IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" void foo() {\n"); >+ buf.append(" try {\n"); >+ buf.append(" System.out.println(\"foo\");\n"); >+ buf.append(" } catch (NullPointerException ex) {\n"); >+ buf.append(" ex.printStackTrace();\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ int offset= buf.toString().indexOf("catch"); >+ AssistContext context= getCorrectionContext(cu, offset, 0); >+ assertNoErrors(context); >+ List proposals= collectAssists(context, false); >+ >+ assertProposalDoesNotExist(proposals, CONVERT_TO_MULTIPLE_CATCH_BLOCKS); >+ } >+ >+}
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 348061
: 197665