use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.
the class AdvancedQuickAssistTest method testInnerAndOuterIfConditions3.
@Test
public void testInnerAndOuterIfConditions3() 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 int foo(int a, Object b) {\n");
buf.append(" if (a == 8) {\n");
buf.append(" if (b instanceof String) {\n");
buf.append(" return 0;\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append(" return 1;\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
int offset = buf.toString().indexOf("if (b");
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(" public int foo(int a, Object b) {\n");
buf.append(" if (b instanceof String) {\n");
buf.append(" if (a == 8) {\n");
buf.append(" return 0;\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append(" return 1;\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 AdvancedQuickAssistTest method testAssignAndCastBug331195_8.
@Test
public void testAssignAndCastBug331195_8() 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(int a, Object b) {\n");
buf.append(" while (b instanceof String) \n");
buf.append(" System.out.println(b);\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
int offset = buf.toString().indexOf("System") - 1;
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(" public void foo(int a, Object b) {\n");
buf.append(" while (b instanceof String) {\n");
buf.append(" String string = (String) b;\n");
buf.append(" System.out.println(b);\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 AdvancedQuickAssistTest method testConvertSwitchToIfBug352422.
@Test
public void testConvertSwitchToIfBug352422() 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(int a) {\n");
buf.append(" switch (a) {\n");
buf.append(" case 1:\n");
buf.append(" System.out.println(1);\n");
buf.append(" break;\n");
buf.append(" case 2:\n");
buf.append(" case 3:\n");
buf.append(" System.out.println(2);\n");
buf.append(" break;\n");
buf.append(" case 4:\n");
buf.append(" case 5:\n");
buf.append(" default:\n");
buf.append(" System.out.println(-1);\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("switch");
AssistContext context = getCorrectionContext(cu, offset, 0);
assertNoErrors(context);
List proposals = collectAssists(context, false);
assertNumberOfProposals(proposals, 1);
assertCorrectLabels(proposals);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" public void foo(int a) {\n");
buf.append(" if (a == 1) {\n");
buf.append(" System.out.println(1);\n");
buf.append(" } else if (a == 2 || a == 3) {\n");
buf.append(" System.out.println(2);\n");
buf.append(" } else if (a == 4 || a == 5 || true) {\n");
buf.append(" System.out.println(-1);\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 AdvancedQuickAssistTest method testPickOutStringProposals1.
// public void testSurroundWithTemplate01() throws Exception {
// IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
// StringBuffer buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" System.out.println(1);\n");
// buf.append(" }\n");
// buf.append("}\n");
// ICompilationUnit cu= pack1.createCompilationUnit("E1.java", buf.toString(), false, null);
//
// String selection= "System.out.println(1);";
// int offset= buf.toString().indexOf(selection);
//
// AssistContext context= getCorrectionContext(cu, offset, selection.length());
// assertNoErrors(context);
// List proposals= Arrays.asList(new QuickTemplateProcessor().getAssists(context, null));
//
// assertCorrectLabels(proposals);
// assertNumberOfProposals(proposals, 7);
//
// String[] expected= new String[7];
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" do {\n");
// buf.append(" System.out.println(1);\n");
// buf.append(" } while (condition);\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[0]= buf.toString();
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" for (int i = 0; i < array.length; i++) {\n");
// buf.append(" System.out.println(1);\n");
// buf.append(" }\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[1]= buf.toString();
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" if (condition) {\n");
// buf.append(" System.out.println(1);\n");
// buf.append(" }\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[2]= buf.toString();
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" new Runnable() {\n");
// buf.append(" public void run() {\n");
// buf.append(" System.out.println(1);\n");
// buf.append(" }\n");
// buf.append(" }\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[3]= buf.toString();
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" synchronized (mutex) {\n");
// buf.append(" System.out.println(1);\n");
// buf.append(" }\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[4]= buf.toString();
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" try {\n");
// buf.append(" System.out.println(1);\n");
// buf.append(" } catch (Exception e) {\n");
// buf.append(" // TODO: handle exception\n");
// buf.append(" }\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[5]= buf.toString();
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" while (condition) {\n");
// buf.append(" System.out.println(1);\n");
// buf.append(" }\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[6]= buf.toString();
//
// assertExpectedExistInProposals(proposals, expected);
// }
//
// public void testSurroundWithTemplate02() throws Exception {
// IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
// StringBuffer buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" int i= 10;\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append("}\n");
// ICompilationUnit cu= pack1.createCompilationUnit("E1.java", buf.toString(), false, null);
//
// String selection= "System.out.println(i);";
// int offset= buf.toString().indexOf(selection);
//
// AssistContext context= getCorrectionContext(cu, offset, selection.length());
// assertNoErrors(context);
// List proposals= Arrays.asList(new QuickTemplateProcessor().getAssists(context, null));
//
// assertCorrectLabels(proposals);
// assertNumberOfProposals(proposals, 7);
//
// String[] expected= new String[7];
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" int i= 10;\n");
// buf.append(" do {\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" } while (condition);\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[0]= buf.toString();
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" int i= 10;\n");
// buf.append(" for (int j = 0; j < array.length; j++) {\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[1]= buf.toString();
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" int i= 10;\n");
// buf.append(" if (condition) {\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[2]= buf.toString();
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" final int i= 10;\n");
// buf.append(" new Runnable() {\n");
// buf.append(" public void run() {\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append(" }\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[3]= buf.toString();
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" int i= 10;\n");
// buf.append(" synchronized (mutex) {\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[4]= buf.toString();
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" int i= 10;\n");
// buf.append(" try {\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" } catch (Exception e) {\n");
// buf.append(" // TODO: handle exception\n");
// buf.append(" }\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[5]= buf.toString();
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" int i= 10;\n");
// buf.append(" while (condition) {\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[6]= buf.toString();
//
// assertExpectedExistInProposals(proposals, expected);
// }
//
// public void testSurroundWithTemplate03() throws Exception {
// IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
// StringBuffer buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" int i= 10;\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append("}\n");
// ICompilationUnit cu= pack1.createCompilationUnit("E1.java", buf.toString(), false, null);
//
// String selection= "int i= 10;\n System.out.println(i);";
// int offset= buf.toString().indexOf(selection);
//
// AssistContext context= getCorrectionContext(cu, offset, selection.length());
// assertNoErrors(context);
// List proposals= Arrays.asList(new QuickTemplateProcessor().getAssists(context, null));
//
// assertCorrectLabels(proposals);
// assertNumberOfProposals(proposals, 7);
//
// String[] expected= new String[7];
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" int i;\n");
// buf.append(" do {\n");
// buf.append(" i = 10;\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" } while (condition);\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[0]= buf.toString();
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" int i;\n");
// buf.append(" for (int j = 0; j < array.length; j++) {\n");
// buf.append(" i = 10;\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[1]= buf.toString();
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" int i;\n");
// buf.append(" if (condition) {\n");
// buf.append(" i = 10;\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[2]= buf.toString();
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" int i;\n");
// buf.append(" new Runnable() {\n");
// buf.append(" public void run() {\n");
// buf.append(" i = 10;\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append(" }\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[3]= buf.toString();
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" int i;\n");
// buf.append(" synchronized (mutex) {\n");
// buf.append(" i = 10;\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[4]= buf.toString();
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" int i;\n");
// buf.append(" try {\n");
// buf.append(" i = 10;\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" } catch (Exception e) {\n");
// buf.append(" // TODO: handle exception\n");
// buf.append(" }\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[5]= buf.toString();
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" int i;\n");
// buf.append(" while (condition) {\n");
// buf.append(" i = 10;\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[6]= buf.toString();
//
// assertExpectedExistInProposals(proposals, expected);
// }
//
// public void testSurroundWithTemplate04() throws Exception {
// IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
// StringBuffer buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" int i= 10;\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append("}\n");
// ICompilationUnit cu= pack1.createCompilationUnit("E1.java", buf.toString(), false, null);
//
// String selection= "System.out.println(i);";
// int offset= buf.toString().indexOf(selection);
//
// AssistContext context= getCorrectionContext(cu, offset, selection.length());
// assertNoErrors(context);
// List proposals= Arrays.asList(new QuickTemplateProcessor().getAssists(context, null));
//
// assertCorrectLabels(proposals);
// assertNumberOfProposals(proposals, 7);
//
// String[] expected= new String[7];
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" int i= 10;\n");
// buf.append(" do {\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" } while (condition);\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[0]= buf.toString();
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" int i= 10;\n");
// buf.append(" for (int j = 0; j < array.length; j++) {\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[1]= buf.toString();
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" int i= 10;\n");
// buf.append(" if (condition) {\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[2]= buf.toString();
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" final int i= 10;\n");
// buf.append(" new Runnable() {\n");
// buf.append(" public void run() {\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append(" }\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[3]= buf.toString();
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" int i= 10;\n");
// buf.append(" synchronized (mutex) {\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[4]= buf.toString();
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" int i= 10;\n");
// buf.append(" try {\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" } catch (Exception e) {\n");
// buf.append(" // TODO: handle exception\n");
// buf.append(" }\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[5]= buf.toString();
//
// buf= new StringBuffer();
// buf.append("package test1;\n");
// buf.append("public class E1 {\n");
// buf.append(" public void foo() {\n");
// buf.append(" int i= 10;\n");
// buf.append(" while (condition) {\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append(" System.out.println(i);\n");
// buf.append(" }\n");
// buf.append("}\n");
// expected[6]= buf.toString();
//
// assertExpectedExistInProposals(proposals, expected);
// }
@Test
public void testPickOutStringProposals1() 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(" String string = \"Hello World\";\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
int offset = buf.toString().indexOf("llo");
int length = "llo".length();
AssistContext context = getCorrectionContext(cu, offset, length);
List proposals = collectAssists(context, false);
assertCorrectLabels(proposals);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" public void foo() {\n");
buf.append(" String string = \"He\" + \"llo\" + \" World\";\n");
buf.append(" }\n");
buf.append("}\n");
String expected = buf.toString();
assertExpectedExistInProposals(proposals, new String[] { expected });
}
use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.
the class AdvancedQuickAssistTest method testCombineStringsProposals4.
@Test
public void testCombineStringsProposals4() 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(" System.out.println(\"Hello\" + \" \" + \"World\");\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
int offset = buf.toString().indexOf("\"Hello\"");
int length = "\"Hello\" + \" \" + \"World\"".length();
AssistContext context = getCorrectionContext(cu, offset, length);
List proposals = collectAssists(context, false);
assertCorrectLabels(proposals);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" public void foo() {\n");
buf.append(" System.out.println(\"Hello World\");\n");
buf.append(" }\n");
buf.append("}\n");
String expected = buf.toString();
assertExpectedExistInProposals(proposals, new String[] { expected });
}
Aggregations