use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.
the class AdvancedQuickAssistTest method testJoinAndIfStatements4.
@Test
public void testJoinAndIfStatements4() 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(boolean a, int b, boolean c) {\n");
buf.append(" if (a && (b == 0))\n");
buf.append(" if (c) {\n");
buf.append(" b= 9;\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("if (c");
AssistContext context = getCorrectionContext(cu, offset, 0);
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(boolean a, int b, boolean c) {\n");
buf.append(" if (a && (b == 0) && c) {\n");
buf.append(" b= 9;\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 testConvertToIfReturn1.
@Test
public void testConvertToIfReturn1() throws Exception {
// positive cases
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 foo1() {\n");
buf.append(" if (a) {\n");
buf.append(" System.out.println(\"1\");\n");
buf.append(" System.out.println(\"11\");\n");
buf.append(" }\n");
buf.append(" }\n\n");
buf.append(" public void foo2() {\n");
buf.append(" bar();\n");
buf.append(" if (b) {\n");
buf.append(" System.out.println(\"2\");\n");
buf.append(" System.out.println(\"22\");\n");
buf.append(" }\n");
buf.append(" }\n\n");
buf.append(" public void foo3() {\n");
buf.append(" if (c) {\n");
buf.append(" if (d) {\n");
buf.append(" System.out.println(\"3\");\n");
buf.append(" System.out.println(\"33\");\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
String str = "if (a)";
AssistContext context = getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0);
List proposals = collectAssists(context, false);
assertNumberOfProposals(proposals, 3);
assertCorrectLabels(proposals);
StringBuffer buf1 = new StringBuffer();
buf1.append("package test1;\n");
buf1.append("public class E {\n");
buf1.append(" public void foo1() {\n");
buf1.append(" if (!a)\n");
buf1.append(" return;\n");
buf1.append(" System.out.println(\"1\");\n");
buf1.append(" System.out.println(\"11\");\n");
buf1.append(" }\n\n");
buf1.append(" public void foo2() {\n");
buf1.append(" bar();\n");
buf1.append(" if (b) {\n");
buf1.append(" System.out.println(\"2\");\n");
buf1.append(" System.out.println(\"22\");\n");
buf1.append(" }\n");
buf1.append(" }\n\n");
buf1.append(" public void foo3() {\n");
buf1.append(" if (c) {\n");
buf1.append(" if (d) {\n");
buf1.append(" System.out.println(\"3\");\n");
buf1.append(" System.out.println(\"33\");\n");
buf1.append(" }\n");
buf1.append(" }\n");
buf1.append(" }\n");
buf1.append("}\n");
String expected1 = buf1.toString();
assertExpectedExistInProposals(proposals, new String[] { expected1 });
str = "if (b)";
context = getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0);
proposals = collectAssists(context, false);
assertNumberOfProposals(proposals, 3);
assertCorrectLabels(proposals);
buf1 = new StringBuffer();
buf1.append("package test1;\n");
buf1.append("public class E {\n");
buf1.append(" public void foo1() {\n");
buf1.append(" if (a) {\n");
buf1.append(" System.out.println(\"1\");\n");
buf1.append(" System.out.println(\"11\");\n");
buf1.append(" }\n");
buf1.append(" }\n\n");
buf1.append(" public void foo2() {\n");
buf1.append(" bar();\n");
buf1.append(" if (!b)\n");
buf1.append(" return;\n");
buf1.append(" System.out.println(\"2\");\n");
buf1.append(" System.out.println(\"22\");\n");
buf1.append(" }\n\n");
buf1.append(" public void foo3() {\n");
buf1.append(" if (c) {\n");
buf1.append(" if (d) {\n");
buf1.append(" System.out.println(\"3\");\n");
buf1.append(" System.out.println(\"33\");\n");
buf1.append(" }\n");
buf1.append(" }\n");
buf1.append(" }\n");
buf1.append("}\n");
String expected2 = buf1.toString();
assertExpectedExistInProposals(proposals, new String[] { expected2 });
str = "if (d)";
context = getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0);
proposals = collectAssists(context, false);
assertNumberOfProposals(proposals, 5);
assertCorrectLabels(proposals);
buf1 = new StringBuffer();
buf1.append("package test1;\n");
buf1.append("public class E {\n");
buf1.append(" public void foo1() {\n");
buf1.append(" if (a) {\n");
buf1.append(" System.out.println(\"1\");\n");
buf1.append(" System.out.println(\"11\");\n");
buf1.append(" }\n");
buf1.append(" }\n\n");
buf1.append(" public void foo2() {\n");
buf1.append(" bar();\n");
buf1.append(" if (b) {\n");
buf1.append(" System.out.println(\"2\");\n");
buf1.append(" System.out.println(\"22\");\n");
buf1.append(" }\n");
buf1.append(" }\n\n");
buf1.append(" public void foo3() {\n");
buf1.append(" if (c) {\n");
buf1.append(" if (!d)\n");
buf1.append(" return;\n");
buf1.append(" System.out.println(\"3\");\n");
buf1.append(" System.out.println(\"33\");\n");
buf1.append(" }\n");
buf1.append(" }\n");
buf1.append("}\n");
String expected3 = buf1.toString();
assertExpectedExistInProposals(proposals, new String[] { expected3 });
}
use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.
the class AdvancedQuickAssistTest method testExchangeOperands2.
@Test
public void testExchangeOperands2() 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 boolean foo(int a, int b) {\n");
buf.append(" return (0 == (a & b));\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
int offset = buf.toString().indexOf("==");
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 boolean foo(int a, int b) {\n");
buf.append(" return ((a & b) == 0);\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 testAddParenthesesForExpression3.
@Test
public void testAddParenthesesForExpression3() 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, int b, int c) {\n");
buf.append(" if (a + b == 0 && b + c > 3) {\n");
buf.append(" b= 9;\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
AssistContext context = getCorrectionContext(cu, buf.toString().indexOf("=="), 0);
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, int b, int c) {\n");
buf.append(" if ((a + b == 0) && b + c > 3) {\n");
buf.append(" b= 9;\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 testConvertSwitchToIfBug252040_1.
@Test
public void testConvertSwitchToIfBug252040_1() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=252040
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(" switch (getSomethingWithSideEffects()) {\n");
buf.append(" case 1:\n");
buf.append(" System.out.println();\n");
buf.append(" break;\n");
buf.append(" case 2:\n");
buf.append(" System.out.println();\n");
buf.append(" break;\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append(" private int getSomethingWithSideEffects() {\n");
buf.append(" System.out.println(\"side effect\");\n");
buf.append(" return 2;\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() {\n");
buf.append(" int somethingWithSideEffects = getSomethingWithSideEffects();\n");
buf.append(" if (somethingWithSideEffects == 1) {\n");
buf.append(" System.out.println();\n");
buf.append(" } else if (somethingWithSideEffects == 2) {\n");
buf.append(" System.out.println();\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append(" private int getSomethingWithSideEffects() {\n");
buf.append(" System.out.println(\"side effect\");\n");
buf.append(" return 2;\n");
buf.append(" }\n");
buf.append("}\n");
String expected1 = buf.toString();
assertExpectedExistInProposals(proposals, new String[] { expected1 });
}
Aggregations