use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.
the class AssistQuickFixTest method testInvertEquals22.
@Test
public void testInvertEquals22() 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(" \"a\".equals(true ? \"a\" : \"b\");\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
String str = "equals";
AssistContext context = getCorrectionContext(cu, buf.toString().indexOf(str), 0);
List proposals = collectAssists(context, FILTER_EQ);
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(" (true ? \"a\" : \"b\").equals(\"a\");\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
cu = pack1.createCompilationUnit("E.java", buf.toString(), true, null);
context = getCorrectionContext(cu, buf.toString().indexOf(str), 0);
proposals = collectAssists(context, FILTER_EQ);
assertNumberOfProposals(proposals, 1);
assertCorrectLabels(proposals);
proposal = (CUCorrectionProposal) proposals.get(0);
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(" \"a\".equals(true ? \"a\" : \"b\");\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.
the class AssistQuickFixTest method testAssignToLocal.
@Test
public void testAssignToLocal() 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(" getClass();\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
int offset = buf.toString().indexOf("getClass()");
AssistContext context = getCorrectionContext(cu, offset, 0);
List proposals = collectAssists(context, false);
assertNumberOfProposals(proposals, 2);
assertCorrectLabels(proposals);
CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0);
String preview1 = getPreviewContent(proposal);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" private Class<? extends E> class1;\n");
buf.append("\n");
buf.append(" public void foo() {\n");
buf.append(" class1 = getClass();\n");
buf.append(" }\n");
buf.append("}\n");
String expected1 = buf.toString();
proposal = (CUCorrectionProposal) proposals.get(1);
String preview2 = getPreviewContent(proposal);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append(" public void foo() {\n");
buf.append(" Class<? extends E> class1 = getClass();\n");
buf.append(" }\n");
buf.append("}\n");
String expected2 = buf.toString();
assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 });
}
use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.
the class AssistQuickFixTest method testAssignToLocal4.
@Test
public void testAssignToLocal4() throws Exception {
// test name conflict
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append("\n");
buf.append(" private int f;\n");
buf.append("\n");
buf.append(" public void foo() {\n");
buf.append(" Math.min(1.0f, 2.0f);\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
int offset = buf.toString().indexOf("Math");
AssistContext context = getCorrectionContext(cu, offset, 0);
List proposals = collectAssists(context, false);
assertNumberOfProposals(proposals, 2);
assertCorrectLabels(proposals);
CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0);
String preview1 = getPreviewContent(proposal);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append("\n");
buf.append(" private int f;\n");
buf.append(" private float min;\n");
buf.append("\n");
buf.append(" public void foo() {\n");
buf.append(" min = Math.min(1.0f, 2.0f);\n");
buf.append(" }\n");
buf.append("}\n");
String expected1 = buf.toString();
proposal = (CUCorrectionProposal) proposals.get(1);
String preview2 = getPreviewContent(proposal);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E {\n");
buf.append("\n");
buf.append(" private int f;\n");
buf.append("\n");
buf.append(" public void foo() {\n");
buf.append(" float min = Math.min(1.0f, 2.0f);\n");
buf.append(" }\n");
buf.append("}\n");
String expected2 = buf.toString();
assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 });
}
use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.
the class AssistQuickFixTest method testInvertEquals9.
@Test
public void testInvertEquals9() 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(" equals(new E());\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
String str = "equals";
AssistContext context = getCorrectionContext(cu, buf.toString().indexOf(str), 0);
List proposals = collectAssists(context, FILTER_EQ);
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(" new E().equals(this);\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
cu = pack1.createCompilationUnit("E.java", buf.toString(), true, null);
context = getCorrectionContext(cu, buf.toString().indexOf(str), 0);
proposals = collectAssists(context, FILTER_EQ);
assertNumberOfProposals(proposals, 1);
assertCorrectLabels(proposals);
proposal = (CUCorrectionProposal) proposals.get(0);
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(" equals(new E());\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.
the class AssistQuickFixTest method testSplitDeclaration5.
@Test
public void testSplitDeclaration5() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package e;\n");
buf.append("public class Test {\n");
buf.append(" public void test() {\n");
buf.append(" String[] test = { null };\n");
buf.append(" }\n");
buf.append("}");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
String str = "=";
AssistContext context = getCorrectionContext(cu, buf.toString().indexOf(str), 0);
List proposals = collectAssists(context, false);
assertNumberOfProposals(proposals, 1);
assertCorrectLabels(proposals);
CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0);
String preview = getPreviewContent(proposal);
buf = new StringBuffer();
buf.append("package e;\n");
buf.append("public class Test {\n");
buf.append(" public void test() {\n");
buf.append(" String[] test;\n");
buf.append(" test = new String[]{ null };\n");
buf.append(" }\n");
buf.append("}");
assertEqualString(preview, buf.toString());
}
Aggregations