use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.
the class AdvancedQuickAssistTest method testSplitIfElseCondition.
@Test
public void testSplitIfElseCondition() 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) {\n");
buf.append(" if (a && (b == 0)) {\n");
buf.append(" b= 9;\n");
buf.append(" } else {\n");
buf.append(" b= 2;\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("&&");
AssistContext context = getCorrectionContext(cu, offset, 0);
List proposals = collectAssists(context, false);
assertNumberOfProposals(proposals, 5);
assertCorrectLabels(proposals);
ArrayList previews = new ArrayList();
ArrayList expecteds = new ArrayList();
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" public void foo(boolean a, int b) {\n");
buf.append(" if (a) {\n");
buf.append(" if (b == 0) {\n");
buf.append(" b= 9;\n");
buf.append(" } else {\n");
buf.append(" b= 2;\n");
buf.append(" }\n");
buf.append(" } else {\n");
buf.append(" b= 2;\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
addPreviewAndExpected(proposals, buf, expecteds, previews);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" public void foo(boolean a, int b) {\n");
buf.append(" if ((b == 0) && a) {\n");
buf.append(" b= 9;\n");
buf.append(" } else {\n");
buf.append(" b= 2;\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
addPreviewAndExpected(proposals, buf, expecteds, previews);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" public void foo(boolean a, int b) {\n");
buf.append(" boolean c = a && (b == 0);\n");
buf.append(" if (c) {\n");
buf.append(" b= 9;\n");
buf.append(" } else {\n");
buf.append(" b= 2;\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
addPreviewAndExpected(proposals, buf, expecteds, previews);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" public void foo(boolean a, int b) {\n");
buf.append(" boolean c = a && (b == 0);\n");
buf.append(" if (c) {\n");
buf.append(" b= 9;\n");
buf.append(" } else {\n");
buf.append(" b= 2;\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
addPreviewAndExpected(proposals, buf, expecteds, previews);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" public void foo(boolean a, int b) {\n");
buf.append(" if ((a && (b == 0))) {\n");
buf.append(" b= 9;\n");
buf.append(" } else {\n");
buf.append(" b= 2;\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
addPreviewAndExpected(proposals, buf, expecteds, previews);
assertEqualStringsIgnoreOrder(previews, expecteds);
}
use of org.eclipse.jdt.internal.ui.text.correction.AssistContext in project che by eclipse.
the class AdvancedQuickAssistTest method testPushNegationDownBug117960.
@Test
public void testPushNegationDownBug117960() 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, boolean b) {\n");
buf.append(" if (!(a || b ? !a : !b)) {\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("!(");
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(boolean a, boolean b) {\n");
buf.append(" if (a || b ? a : 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 testInverseVariable2.
@Test
public void testInverseVariable2() 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 b) {\n");
buf.append(" boolean var= b && !b;\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
int offset = buf.toString().indexOf("var");
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(boolean b) {\n");
buf.append(" boolean notVar= !b || b;\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 testAddParenthesesForExpression1.
@Test
public void testAddParenthesesForExpression1() 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(Object obj) {\n");
buf.append(" if (obj instanceof String) {\n");
buf.append(" String string = (String) obj;\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("(String) obj"), 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(Object obj) {\n");
buf.append(" if (obj instanceof String) {\n");
buf.append(" String string = ((String) obj);\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 testAssignAndCastBug331195_6.
@Test
public void testAssignAndCastBug331195_6() 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(" if (b instanceof String) {\n");
buf.append(" int x=10;\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("int x") - 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(" if (b instanceof String) {\n");
buf.append(" String string = (String) b;\n");
buf.append(" int x=10;\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
String expected1 = buf.toString();
assertExpectedExistInProposals(proposals, new String[] { expected1 });
}
Aggregations