use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.
the class AdvancedQuickAssistTest method testInverseIfCondition3.
@Test
public void testInverseIfCondition3() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=75109
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, boolean b) {\n");
buf.append(" if (a)\n");
buf.append(" if (b) //inverse\n");
buf.append(" return 1;\n");
buf.append(" else\n");
buf.append(" return 2;\n");
buf.append(" return 17;\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);
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, boolean b) {\n");
buf.append(" if (a)\n");
buf.append(" if (!b)\n");
buf.append(" return 2;\n");
buf.append(" else\n");
buf.append(" return 1;\n");
buf.append(" return 17;\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 testJoinOrIfStatements1.
@Test
public void testJoinOrIfStatements1() 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)\n");
buf.append(" return;\n");
buf.append(" if (b == 5)\n");
buf.append(" return;\n");
buf.append(" b= 9;\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
int offset1 = buf.toString().indexOf("if (a");
int offset2 = buf.toString().lastIndexOf("b= 9;");
AssistContext context = getCorrectionContext(cu, offset1, offset2 - offset1);
List proposals = collectAssists(context, false);
for (Iterator I = proposals.iterator(); I.hasNext(); ) {
Object o = I.next();
if (!(o instanceof CUCorrectionProposal))
I.remove();
}
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 == 5)\n");
buf.append(" return;\n");
buf.append(" b= 9;\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 testJoinIfListInIfElseIf.
@Test
public void testJoinIfListInIfElseIf() 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) {\n");
buf.append(" if (a == 1)\n");
buf.append(" System.out.println(1);\n");
buf.append(" if (a == 2)\n");
buf.append(" if (b > 0)\n");
buf.append(" System.out.println(2);\n");
buf.append(" if (a == 3)\n");
buf.append(" if (b > 0)\n");
buf.append(" System.out.println(3);\n");
buf.append(" else\n");
buf.append(" System.out.println(-3);\n");
buf.append(" if (a == 4)\n");
buf.append(" System.out.println(4);\n");
buf.append(" int stop;\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
int offset1 = buf.toString().indexOf("if (a == 1)");
int offset2 = buf.toString().indexOf("int stop;");
AssistContext context = getCorrectionContext(cu, offset1, offset2 - offset1);
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, int b) {\n");
buf.append(" if (a == 1)\n");
buf.append(" System.out.println(1);\n");
buf.append(" else if (a == 2) {\n");
buf.append(" if (b > 0)\n");
buf.append(" System.out.println(2);\n");
buf.append(" } else if (a == 3)\n");
buf.append(" if (b > 0)\n");
buf.append(" System.out.println(3);\n");
buf.append(" else\n");
buf.append(" System.out.println(-3); else if (a == 4)\n");
buf.append(" System.out.println(4);\n");
buf.append(" int stop;\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 testInnerAndOuterIfConditions1.
@Test
public void testInnerAndOuterIfConditions1() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=74746
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 (a");
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 testConvertIfToSwitch5.
@Test
public void testConvertIfToSwitch5() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("pack", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack;\n");
buf.append("\n");
buf.append("public class A {\n");
buf.append(" final static int SECONDS=1, MILLISECONDS=2, MICROSECONDS=4,NANOSECONDS=8;\n");
buf.append(" public static int getPower(int unit) {\n");
buf.append(" if (unit == SECONDS) {\n");
buf.append(" return 0;\n");
buf.append(" } else if (unit == MILLISECONDS) {\n");
buf.append(" return -3;\n");
buf.append(" } else if (unit == MICROSECONDS) {\n");
buf.append(" return -6;\n");
buf.append(" } else if (unit == NANOSECONDS) {\n");
buf.append(" return -9;\n");
buf.append(" } else {\n");
buf.append(" throw new InternalError();\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("A.java", buf.toString(), false, null);
int offset = buf.toString().indexOf("if");
AssistContext context = getCorrectionContext(cu, offset, 0);
assertNoErrors(context);
List proposals = collectAssists(context, false);
assertNumberOfProposals(proposals, 4);
assertCorrectLabels(proposals);
buf = new StringBuffer();
buf.append("package pack;\n");
buf.append("\n");
buf.append("public class A {\n");
buf.append(" final static int SECONDS=1, MILLISECONDS=2, MICROSECONDS=4,NANOSECONDS=8;\n");
buf.append(" public static int getPower(int unit) {\n");
buf.append(" switch (unit) {\n");
buf.append(" case SECONDS :\n");
buf.append(" return 0;\n");
buf.append(" case MILLISECONDS :\n");
buf.append(" return -3;\n");
buf.append(" case MICROSECONDS :\n");
buf.append(" return -6;\n");
buf.append(" case NANOSECONDS :\n");
buf.append(" return -9;\n");
buf.append(" default :\n");
buf.append(" throw new InternalError();\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
String expected1 = buf.toString();
assertExpectedExistInProposals(proposals, new String[] { expected1 });
}
Aggregations