|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2011 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* This is an implementation of an early-draft specification developed under the Java |
| 9 |
* Community Process (JCP) and is made available for testing and evaluation purposes |
| 10 |
* only. The code is not compatible with any specification of the JCP. |
| 11 |
* |
| 12 |
* Contributors: |
| 13 |
* IBM Corporation - initial API and implementation |
| 14 |
*******************************************************************************/ |
| 15 |
package org.eclipse.jdt.ui.tests.quickfix; |
| 16 |
|
| 17 |
import java.util.Hashtable; |
| 18 |
import java.util.List; |
| 19 |
|
| 20 |
import junit.framework.Test; |
| 21 |
import junit.framework.TestSuite; |
| 22 |
|
| 23 |
import org.eclipse.jdt.testplugin.JavaProjectHelper; |
| 24 |
import org.eclipse.jdt.testplugin.TestOptions; |
| 25 |
|
| 26 |
import org.eclipse.core.runtime.Preferences; |
| 27 |
|
| 28 |
import org.eclipse.jface.preference.IPreferenceStore; |
| 29 |
|
| 30 |
import org.eclipse.jdt.core.ICompilationUnit; |
| 31 |
import org.eclipse.jdt.core.IJavaProject; |
| 32 |
import org.eclipse.jdt.core.IPackageFragment; |
| 33 |
import org.eclipse.jdt.core.IPackageFragmentRoot; |
| 34 |
import org.eclipse.jdt.core.JavaCore; |
| 35 |
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; |
| 36 |
|
| 37 |
import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility; |
| 38 |
import org.eclipse.jdt.internal.corext.template.java.CodeTemplateContextType; |
| 39 |
|
| 40 |
import org.eclipse.jdt.ui.PreferenceConstants; |
| 41 |
import org.eclipse.jdt.ui.tests.core.Java17ProjectTestSetup; |
| 42 |
import org.eclipse.jdt.ui.tests.core.ProjectTestSetup; |
| 43 |
|
| 44 |
import org.eclipse.jdt.internal.ui.JavaPlugin; |
| 45 |
import org.eclipse.jdt.internal.ui.text.correction.AssistContext; |
| 46 |
|
| 47 |
public class AssistQuickFixTest17 extends QuickFixTest { |
| 48 |
|
| 49 |
private static final String CONVERT_TO_A_SINGLE_MULTI_CATCH_BLOCK= "Convert to a single multi-catch block"; |
| 50 |
private static final String CONVERT_TO_MULTIPLE_CATCH_BLOCKS= "Convert to multiple catch blocks"; |
| 51 |
|
| 52 |
private static final Class THIS= AssistQuickFixTest17.class; |
| 53 |
|
| 54 |
private IJavaProject fJProject1; |
| 55 |
|
| 56 |
private IPackageFragmentRoot fSourceFolder; |
| 57 |
|
| 58 |
public AssistQuickFixTest17(String name) { |
| 59 |
super(name); |
| 60 |
} |
| 61 |
|
| 62 |
public static Test suite() { |
| 63 |
return setUpTest(new TestSuite(THIS)); |
| 64 |
} |
| 65 |
|
| 66 |
public static Test setUpTest(Test test) { |
| 67 |
return new Java17ProjectTestSetup(test); |
| 68 |
} |
| 69 |
|
| 70 |
protected void setUp() throws Exception { |
| 71 |
Hashtable options= TestOptions.getDefaultOptions(); |
| 72 |
options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE); |
| 73 |
options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4"); |
| 74 |
|
| 75 |
JavaCore.setOptions(options); |
| 76 |
|
| 77 |
IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore(); |
| 78 |
store.setValue(PreferenceConstants.CODEGEN_ADD_COMMENTS, false); |
| 79 |
store.setValue(PreferenceConstants.CODEGEN_KEYWORD_THIS, false); |
| 80 |
|
| 81 |
StubUtility.setCodeTemplate(CodeTemplateContextType.METHODSTUB_ID, "//TODO\n${body_statement}", null); |
| 82 |
|
| 83 |
Preferences corePrefs= JavaPlugin.getJavaCorePluginPreferences(); |
| 84 |
corePrefs.setValue(JavaCore.CODEASSIST_FIELD_PREFIXES, ""); |
| 85 |
corePrefs.setValue(JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES, ""); |
| 86 |
corePrefs.setValue(JavaCore.CODEASSIST_FIELD_SUFFIXES, ""); |
| 87 |
corePrefs.setValue(JavaCore.CODEASSIST_STATIC_FIELD_SUFFIXES, ""); |
| 88 |
|
| 89 |
fJProject1= ProjectTestSetup.getProject(); |
| 90 |
|
| 91 |
fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); |
| 92 |
} |
| 93 |
|
| 94 |
protected void tearDown() throws Exception { |
| 95 |
JavaProjectHelper.clear(fJProject1, Java17ProjectTestSetup.getDefaultClasspath()); |
| 96 |
} |
| 97 |
|
| 98 |
public void testConvertToMultiCatch1() throws Exception { |
| 99 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 100 |
StringBuffer buf= new StringBuffer(); |
| 101 |
buf.append("package test1;\n"); |
| 102 |
buf.append("public class E {\n"); |
| 103 |
buf.append(" void foo() {\n"); |
| 104 |
buf.append(" try {\n"); |
| 105 |
buf.append(" System.out.println(\"foo\");\n"); |
| 106 |
buf.append(" } catch (IllegalArgumentException ex) {\n"); |
| 107 |
buf.append(" ex.printStackTrace();\n"); |
| 108 |
buf.append(" } catch (NullPointerException ex) {\n"); |
| 109 |
buf.append(" ex.printStackTrace();\n"); |
| 110 |
buf.append(" }\n"); |
| 111 |
buf.append(" }\n"); |
| 112 |
buf.append("}\n"); |
| 113 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 114 |
|
| 115 |
int offset= buf.toString().indexOf("catch"); |
| 116 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
| 117 |
assertNoErrors(context); |
| 118 |
List proposals= collectAssists(context, false); |
| 119 |
|
| 120 |
assertCorrectLabels(proposals); |
| 121 |
|
| 122 |
buf= new StringBuffer(); |
| 123 |
buf.append("package test1;\n"); |
| 124 |
buf.append("public class E {\n"); |
| 125 |
buf.append(" void foo() {\n"); |
| 126 |
buf.append(" try {\n"); |
| 127 |
buf.append(" System.out.println(\"foo\");\n"); |
| 128 |
buf.append(" } catch (IllegalArgumentException | NullPointerException ex) {\n"); |
| 129 |
buf.append(" ex.printStackTrace();\n"); |
| 130 |
buf.append(" }\n"); |
| 131 |
buf.append(" }\n"); |
| 132 |
buf.append("}\n"); |
| 133 |
String expected1= buf.toString(); |
| 134 |
|
| 135 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
| 136 |
} |
| 137 |
|
| 138 |
public void testConvertToMultiCatch2() throws Exception { |
| 139 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 140 |
StringBuffer buf= new StringBuffer(); |
| 141 |
buf.append("package test1;\n"); |
| 142 |
buf.append("public class E {\n"); |
| 143 |
buf.append(" void foo() {\n"); |
| 144 |
buf.append(" try {\n"); |
| 145 |
buf.append(" System.out.println(\"foo\");\n"); |
| 146 |
buf.append(" } catch (IllegalArgumentException e) {\n"); |
| 147 |
buf.append(" e.printStackTrace();\n"); |
| 148 |
buf.append(" } catch (NullPointerException e) {\n"); |
| 149 |
buf.append(" e.printStackTrace();\n"); |
| 150 |
buf.append(" }\n"); |
| 151 |
buf.append(" }\n"); |
| 152 |
buf.append("}\n"); |
| 153 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 154 |
|
| 155 |
int offset= buf.toString().indexOf("catch"); |
| 156 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
| 157 |
assertNoErrors(context); |
| 158 |
List proposals= collectAssists(context, false); |
| 159 |
|
| 160 |
assertCorrectLabels(proposals); |
| 161 |
|
| 162 |
buf= new StringBuffer(); |
| 163 |
buf.append("package test1;\n"); |
| 164 |
buf.append("public class E {\n"); |
| 165 |
buf.append(" void foo() {\n"); |
| 166 |
buf.append(" try {\n"); |
| 167 |
buf.append(" System.out.println(\"foo\");\n"); |
| 168 |
buf.append(" } catch (IllegalArgumentException | NullPointerException e) {\n"); |
| 169 |
buf.append(" e.printStackTrace();\n"); |
| 170 |
buf.append(" }\n"); |
| 171 |
buf.append(" }\n"); |
| 172 |
buf.append("}\n"); |
| 173 |
String expected1= buf.toString(); |
| 174 |
|
| 175 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
| 176 |
|
| 177 |
} |
| 178 |
|
| 179 |
public void testConvertToMultiCatch3() throws Exception { |
| 180 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 181 |
StringBuffer buf= new StringBuffer(); |
| 182 |
buf.append("package test1;\n"); |
| 183 |
buf.append("public class E {\n"); |
| 184 |
buf.append(" void foo() {\n"); |
| 185 |
buf.append(" try {\n"); |
| 186 |
buf.append(" System.out.println(\"foo\");\n"); |
| 187 |
buf.append(" } catch (IllegalArgumentException | NullPointerException e) {\n"); |
| 188 |
buf.append(" e.printStackTrace();\n"); |
| 189 |
buf.append(" } catch (RuntimeException e) {\n"); |
| 190 |
buf.append(" e.printStackTrace();\n"); |
| 191 |
buf.append(" }\n"); |
| 192 |
buf.append(" }\n"); |
| 193 |
buf.append("}\n"); |
| 194 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 195 |
|
| 196 |
int offset= buf.toString().indexOf("catch"); |
| 197 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
| 198 |
assertNoErrors(context); |
| 199 |
List proposals= collectAssists(context, false); |
| 200 |
|
| 201 |
assertCorrectLabels(proposals); |
| 202 |
|
| 203 |
buf= new StringBuffer(); |
| 204 |
buf.append("package test1;\n"); |
| 205 |
buf.append("public class E {\n"); |
| 206 |
buf.append(" void foo() {\n"); |
| 207 |
buf.append(" try {\n"); |
| 208 |
buf.append(" System.out.println(\"foo\");\n"); |
| 209 |
buf.append(" } catch (IllegalArgumentException | NullPointerException | RuntimeException e) {\n"); |
| 210 |
buf.append(" e.printStackTrace();\n"); |
| 211 |
buf.append(" }\n"); |
| 212 |
buf.append(" }\n"); |
| 213 |
buf.append("}\n"); |
| 214 |
String expected1= buf.toString(); |
| 215 |
|
| 216 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
| 217 |
} |
| 218 |
|
| 219 |
public void testConvertToMultiCatch4() throws Exception { |
| 220 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 221 |
StringBuffer buf= new StringBuffer(); |
| 222 |
buf.append("package test1;\n"); |
| 223 |
buf.append("public class E {\n"); |
| 224 |
buf.append(" void foo() {\n"); |
| 225 |
buf.append(" try {\n"); |
| 226 |
buf.append(" System.out.println(\"foo\");\n"); |
| 227 |
buf.append(" } catch (IllegalArgumentException e) {\n"); |
| 228 |
buf.append(" e.printStackTrace();\n"); |
| 229 |
buf.append(" } catch (NullPointerException e) {\n"); |
| 230 |
buf.append(" \n"); |
| 231 |
buf.append(" }\n"); |
| 232 |
buf.append(" }\n"); |
| 233 |
buf.append("}\n"); |
| 234 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 235 |
|
| 236 |
int offset= buf.toString().indexOf("catch"); |
| 237 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
| 238 |
assertNoErrors(context); |
| 239 |
List proposals= collectAssists(context, false); |
| 240 |
|
| 241 |
assertProposalDoesNotExist(proposals, CONVERT_TO_A_SINGLE_MULTI_CATCH_BLOCK); |
| 242 |
} |
| 243 |
|
| 244 |
public void testConvertToMultiCatch5() throws Exception { |
| 245 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 246 |
StringBuffer buf= new StringBuffer(); |
| 247 |
buf.append("package test1;\n"); |
| 248 |
buf.append("public class E {\n"); |
| 249 |
buf.append(" void foo() {\n"); |
| 250 |
buf.append(" try {\n"); |
| 251 |
buf.append(" System.out.println(\"foo\");\n"); |
| 252 |
buf.append(" } catch (IllegalArgumentException e) {\n"); |
| 253 |
buf.append(" e.printStackTrace();\n"); |
| 254 |
buf.append(" }\n"); |
| 255 |
buf.append(" }\n"); |
| 256 |
buf.append("}\n"); |
| 257 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 258 |
|
| 259 |
int offset= buf.toString().indexOf("catch"); |
| 260 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
| 261 |
assertNoErrors(context); |
| 262 |
List proposals= collectAssists(context, false); |
| 263 |
|
| 264 |
assertProposalDoesNotExist(proposals, CONVERT_TO_A_SINGLE_MULTI_CATCH_BLOCK); |
| 265 |
} |
| 266 |
|
| 267 |
public void testConvertToMultiCatch6() throws Exception { |
| 268 |
//Quick assist should not be offered in 1.5 mode |
| 269 |
JavaProjectHelper.set15CompilerOptions(fJProject1); |
| 270 |
try { |
| 271 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 272 |
StringBuffer buf= new StringBuffer(); |
| 273 |
buf.append("package test1;\n"); |
| 274 |
buf.append("public class E {\n"); |
| 275 |
buf.append(" void foo() {\n"); |
| 276 |
buf.append(" try {\n"); |
| 277 |
buf.append(" System.out.println(\"foo\");\n"); |
| 278 |
buf.append(" } catch (IllegalArgumentException e) {\n"); |
| 279 |
buf.append(" e.printStackTrace();\n"); |
| 280 |
buf.append(" } catch (NullPointerException e) {\n"); |
| 281 |
buf.append(" e.printStackTrace();\n"); |
| 282 |
buf.append(" }\n"); |
| 283 |
buf.append(" }\n"); |
| 284 |
buf.append("}\n"); |
| 285 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 286 |
|
| 287 |
int offset= buf.toString().indexOf("catch"); |
| 288 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
| 289 |
assertNoErrors(context); |
| 290 |
List proposals= collectAssists(context, false); |
| 291 |
|
| 292 |
assertProposalDoesNotExist(proposals, CONVERT_TO_A_SINGLE_MULTI_CATCH_BLOCK); |
| 293 |
} finally { |
| 294 |
JavaProjectHelper.set17CompilerOptions(fJProject1); |
| 295 |
} |
| 296 |
} |
| 297 |
|
| 298 |
public void testUnrollMultiCatch1() throws Exception { |
| 299 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 300 |
StringBuffer buf= new StringBuffer(); |
| 301 |
buf.append("package test1;\n"); |
| 302 |
buf.append("public class E {\n"); |
| 303 |
buf.append(" void foo() {\n"); |
| 304 |
buf.append(" try {\n"); |
| 305 |
buf.append(" System.out.println(\"foo\");\n"); |
| 306 |
buf.append(" } catch (IllegalArgumentException | NullPointerException ex) {\n"); |
| 307 |
buf.append(" ex.printStackTrace();\n"); |
| 308 |
buf.append(" }\n"); |
| 309 |
buf.append(" }\n"); |
| 310 |
buf.append("}\n"); |
| 311 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 312 |
|
| 313 |
int offset= buf.toString().indexOf("catch"); |
| 314 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
| 315 |
assertNoErrors(context); |
| 316 |
List proposals= collectAssists(context, false); |
| 317 |
|
| 318 |
assertCorrectLabels(proposals); |
| 319 |
|
| 320 |
buf= new StringBuffer(); |
| 321 |
buf.append("package test1;\n"); |
| 322 |
buf.append("public class E {\n"); |
| 323 |
buf.append(" void foo() {\n"); |
| 324 |
buf.append(" try {\n"); |
| 325 |
buf.append(" System.out.println(\"foo\");\n"); |
| 326 |
buf.append(" } catch (IllegalArgumentException ex) {\n"); |
| 327 |
buf.append(" ex.printStackTrace();\n"); |
| 328 |
buf.append(" } catch (NullPointerException ex) {\n"); |
| 329 |
buf.append(" ex.printStackTrace();\n"); |
| 330 |
buf.append(" }\n"); |
| 331 |
buf.append(" }\n"); |
| 332 |
buf.append("}\n"); |
| 333 |
String expected1= buf.toString(); |
| 334 |
|
| 335 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
| 336 |
} |
| 337 |
|
| 338 |
public void testUnrollMultiCatch2() throws Exception { |
| 339 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 340 |
StringBuffer buf= new StringBuffer(); |
| 341 |
buf.append("package test1;\n"); |
| 342 |
buf.append("public class E {\n"); |
| 343 |
buf.append(" void foo() {\n"); |
| 344 |
buf.append(" try {\n"); |
| 345 |
buf.append(" System.out.println(\"foo\");\n"); |
| 346 |
buf.append(" } catch (IllegalArgumentException | NullPointerException e) {\n"); |
| 347 |
buf.append(" e.printStackTrace();\n"); |
| 348 |
buf.append(" } catch (RuntimeException e) {\n"); |
| 349 |
buf.append(" e.printStackTrace();\n"); |
| 350 |
buf.append(" }\n"); |
| 351 |
buf.append(" }\n"); |
| 352 |
buf.append("}\n"); |
| 353 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 354 |
|
| 355 |
int offset= buf.toString().indexOf("catch"); |
| 356 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
| 357 |
assertNoErrors(context); |
| 358 |
List proposals= collectAssists(context, false); |
| 359 |
|
| 360 |
assertCorrectLabels(proposals); |
| 361 |
|
| 362 |
buf= new StringBuffer(); |
| 363 |
buf.append("package test1;\n"); |
| 364 |
buf.append("public class E {\n"); |
| 365 |
buf.append(" void foo() {\n"); |
| 366 |
buf.append(" try {\n"); |
| 367 |
buf.append(" System.out.println(\"foo\");\n"); |
| 368 |
buf.append(" } catch (IllegalArgumentException e) {\n"); |
| 369 |
buf.append(" e.printStackTrace();\n"); |
| 370 |
buf.append(" } catch (NullPointerException e) {\n"); |
| 371 |
buf.append(" e.printStackTrace();\n"); |
| 372 |
buf.append(" } catch (RuntimeException e) {\n"); |
| 373 |
buf.append(" e.printStackTrace();\n"); |
| 374 |
buf.append(" }\n"); |
| 375 |
buf.append(" }\n"); |
| 376 |
buf.append("}\n"); |
| 377 |
String expected1= buf.toString(); |
| 378 |
|
| 379 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
| 380 |
} |
| 381 |
|
| 382 |
public void testUnrollMultiCatch3() throws Exception { |
| 383 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 384 |
StringBuffer buf= new StringBuffer(); |
| 385 |
buf.append("package test1;\n"); |
| 386 |
buf.append("public class E {\n"); |
| 387 |
buf.append(" void foo() {\n"); |
| 388 |
buf.append(" try {\n"); |
| 389 |
buf.append(" System.out.println(\"foo\");\n"); |
| 390 |
buf.append(" } catch (IllegalArgumentException e) {\n"); |
| 391 |
buf.append(" e.printStackTrace();\n"); |
| 392 |
buf.append(" } catch (NullPointerException | ClassCastException e) {\n"); |
| 393 |
buf.append(" e.printStackTrace();\n"); |
| 394 |
buf.append(" }\n"); |
| 395 |
buf.append(" }\n"); |
| 396 |
buf.append("}\n"); |
| 397 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 398 |
|
| 399 |
int offset= buf.toString().indexOf("catch (NullPointerException"); |
| 400 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
| 401 |
assertNoErrors(context); |
| 402 |
List proposals= collectAssists(context, false); |
| 403 |
|
| 404 |
assertCorrectLabels(proposals); |
| 405 |
|
| 406 |
buf= new StringBuffer(); |
| 407 |
buf.append("package test1;\n"); |
| 408 |
buf.append("public class E {\n"); |
| 409 |
buf.append(" void foo() {\n"); |
| 410 |
buf.append(" try {\n"); |
| 411 |
buf.append(" System.out.println(\"foo\");\n"); |
| 412 |
buf.append(" } catch (IllegalArgumentException e) {\n"); |
| 413 |
buf.append(" e.printStackTrace();\n"); |
| 414 |
buf.append(" } catch (NullPointerException e) {\n"); |
| 415 |
buf.append(" e.printStackTrace();\n"); |
| 416 |
buf.append(" } catch (ClassCastException e) {\n"); |
| 417 |
buf.append(" e.printStackTrace();\n"); |
| 418 |
buf.append(" }\n"); |
| 419 |
buf.append(" }\n"); |
| 420 |
buf.append("}\n"); |
| 421 |
String expected1= buf.toString(); |
| 422 |
|
| 423 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
| 424 |
} |
| 425 |
|
| 426 |
public void testUnrollMultiCatch4() throws Exception { |
| 427 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 428 |
StringBuffer buf= new StringBuffer(); |
| 429 |
buf.append("package test1;\n"); |
| 430 |
buf.append("public class E {\n"); |
| 431 |
buf.append(" void foo() {\n"); |
| 432 |
buf.append(" try {\n"); |
| 433 |
buf.append(" System.out.println(\"foo\");\n"); |
| 434 |
buf.append(" } catch (IllegalArgumentException e) {\n"); |
| 435 |
buf.append(" e.printStackTrace();\n"); |
| 436 |
buf.append(" } catch (NullPointerException | ClassCastException e) {\n"); |
| 437 |
buf.append(" e.printStackTrace();\n"); |
| 438 |
buf.append(" } catch (ArrayIndexOutOfBoundsException e) {\n"); |
| 439 |
buf.append(" e.printStackTrace();\n"); |
| 440 |
buf.append(" }\n"); |
| 441 |
buf.append(" }\n"); |
| 442 |
buf.append("}\n"); |
| 443 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 444 |
|
| 445 |
int offset= buf.toString().indexOf("catch (NullPointerException"); |
| 446 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
| 447 |
assertNoErrors(context); |
| 448 |
List proposals= collectAssists(context, false); |
| 449 |
|
| 450 |
assertCorrectLabels(proposals); |
| 451 |
|
| 452 |
buf= new StringBuffer(); |
| 453 |
buf.append("package test1;\n"); |
| 454 |
buf.append("public class E {\n"); |
| 455 |
buf.append(" void foo() {\n"); |
| 456 |
buf.append(" try {\n"); |
| 457 |
buf.append(" System.out.println(\"foo\");\n"); |
| 458 |
buf.append(" } catch (IllegalArgumentException e) {\n"); |
| 459 |
buf.append(" e.printStackTrace();\n"); |
| 460 |
buf.append(" } catch (NullPointerException e) {\n"); |
| 461 |
buf.append(" e.printStackTrace();\n"); |
| 462 |
buf.append(" } catch (ClassCastException e) {\n"); |
| 463 |
buf.append(" e.printStackTrace();\n"); |
| 464 |
buf.append(" } catch (ArrayIndexOutOfBoundsException e) {\n"); |
| 465 |
buf.append(" e.printStackTrace();\n"); |
| 466 |
buf.append(" }\n"); |
| 467 |
buf.append(" }\n"); |
| 468 |
buf.append("}\n"); |
| 469 |
String expected1= buf.toString(); |
| 470 |
|
| 471 |
assertExpectedExistInProposals(proposals, new String[] { expected1 }); |
| 472 |
} |
| 473 |
|
| 474 |
public void testUnrollMultiCatch5() throws Exception { |
| 475 |
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); |
| 476 |
StringBuffer buf= new StringBuffer(); |
| 477 |
buf.append("package test1;\n"); |
| 478 |
buf.append("public class E {\n"); |
| 479 |
buf.append(" void foo() {\n"); |
| 480 |
buf.append(" try {\n"); |
| 481 |
buf.append(" System.out.println(\"foo\");\n"); |
| 482 |
buf.append(" } catch (NullPointerException ex) {\n"); |
| 483 |
buf.append(" ex.printStackTrace();\n"); |
| 484 |
buf.append(" }\n"); |
| 485 |
buf.append(" }\n"); |
| 486 |
buf.append("}\n"); |
| 487 |
ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); |
| 488 |
|
| 489 |
int offset= buf.toString().indexOf("catch"); |
| 490 |
AssistContext context= getCorrectionContext(cu, offset, 0); |
| 491 |
assertNoErrors(context); |
| 492 |
List proposals= collectAssists(context, false); |
| 493 |
|
| 494 |
assertProposalDoesNotExist(proposals, CONVERT_TO_MULTIPLE_CATCH_BLOCKS); |
| 495 |
} |
| 496 |
|
| 497 |
} |