use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.
the class AssistQuickFixTest17 method testConvertToMultiCatch4.
@Test
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);
}
use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.
the class AssistQuickFixTest17 method testUnrollMultiCatch4.
@Test
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 });
}
use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.
the class AssistQuickFixTest17 method testReplaceMultiCatchClauseWithThrows4.
@Test
public void testReplaceMultiCatchClauseWithThrows4() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("import java.lang.reflect.InvocationTargetException;\n");
buf.append("public class E {\n");
buf.append(" public void foo() {\n");
buf.append(" try {\n");
buf.append(" String.class.getConstructor().newInstance();\n");
buf.append(" } catch (InstantiationException | IllegalAccessException\n");
buf.append(" | IllegalArgumentException | InvocationTargetException\n");
buf.append(" | NoSuchMethodException | SecurityException 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("IllegalArgumentException");
AssistContext context = getCorrectionContext(cu, offset, 0);
List proposals = collectAssists(context, false);
assertNumberOfProposals(proposals, 4);
assertCorrectLabels(proposals);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("import java.lang.reflect.InvocationTargetException;\n");
buf.append("public class E {\n");
buf.append(" public void foo() {\n");
buf.append(" try {\n");
buf.append(" String.class.getConstructor().newInstance();\n");
buf.append(" } catch (InstantiationException | IllegalAccessException\n");
buf.append(" | InvocationTargetException\n");
buf.append(" | NoSuchMethodException | SecurityException e) {\n");
buf.append(" e.printStackTrace();\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
String expected1 = buf.toString();
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("import java.lang.reflect.InvocationTargetException;\n");
buf.append("public class E {\n");
buf.append(" public void foo() throws IllegalArgumentException {\n");
buf.append(" try {\n");
buf.append(" String.class.getConstructor().newInstance();\n");
buf.append(" } catch (InstantiationException | IllegalAccessException\n");
buf.append(" | InvocationTargetException\n");
buf.append(" | NoSuchMethodException | SecurityException e) {\n");
buf.append(" e.printStackTrace();\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
String expected2 = buf.toString();
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("import java.lang.reflect.InvocationTargetException;\n");
buf.append("public class E {\n");
buf.append(" public void foo() {\n");
buf.append(" try {\n");
buf.append(" String.class.getConstructor().newInstance();\n");
buf.append(" } catch (InstantiationException | IllegalAccessException\n");
buf.append(" | InvocationTargetException\n");
buf.append(" | NoSuchMethodException | SecurityException e) {\n");
buf.append(" e.printStackTrace();\n");
buf.append(" } catch (IllegalArgumentException e) {\n");
buf.append(" e.printStackTrace();\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
String expected3 = buf.toString();
assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3 });
}
use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.
the class QuickFixTest method collectCorrections.
protected static final ArrayList collectCorrections(ICompilationUnit cu, IProblem curr, IInvocationContext context) throws CoreException {
int offset = curr.getSourceStart();
int length = curr.getSourceEnd() + 1 - offset;
if (context == null) {
context = new AssistContext(cu, offset, length);
}
ProblemLocation problem = new ProblemLocation(curr);
ArrayList proposals = collectCorrections(context, problem);
if (!proposals.isEmpty()) {
assertCorrectContext(context, problem);
}
return proposals;
}
use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.
the class ReorgQuickFixTest method testTodoTasks5.
@Test
public void testTodoTasks5() 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(" public void foo() {\n");
buf.append(" /**\n");
buf.append(" Some other text: TODO: XXX\n");
buf.append(" */\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
String str = "TODO: XXX";
AssistContext context = getCorrectionContext(cu, buf.toString().indexOf(str), 0);
ProblemLocation problem = new ProblemLocation(buf.toString().indexOf(str), str.length(), IProblem.Task, new String[0], true, IJavaModelMarker.TASK_MARKER);
ArrayList proposals = collectCorrections(context, problem);
assertNumberOfProposals(proposals, 1);
assertCorrectLabels(proposals);
CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0);
String preview = getPreviewContent(proposal);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" public void foo() {\n");
buf.append(" /**\n");
buf.append(" Some other text: \n");
buf.append(" */\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
Aggregations