use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.
the class AssistQuickFixTest method testSplitDeclaration7.
@Test
public void testSplitDeclaration7() 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 = x;\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 = x;\n");
buf.append(" }\n");
buf.append("}");
assertEqualString(preview, buf.toString());
}
use of org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal in project che by eclipse.
the class AssistQuickFixTest method testAssignToLocal12.
@Test
public void testAssignToLocal12() throws Exception {
// assign to recovered statement in if body with no brackets
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 i) {\n");
buf.append(" if (i == 0)\n");
buf.append(" i++\n");
buf.append(" else\n");
buf.append(" System.getProperties()\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
int offset = buf.toString().indexOf("System.getProperties()");
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("\n");
buf.append("import java.util.Properties;\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append(" public void foo(int i) {\n");
buf.append(" if (i == 0)\n");
buf.append(" i++\n");
buf.append(" else {\n");
buf.append(" Properties properties = System.getProperties();\n");
buf.append(" }\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("\n");
buf.append("import java.util.Properties;\n");
buf.append("\n");
buf.append("public class E {\n");
buf.append(" private Properties properties;\n");
buf.append("\n");
buf.append(" public void foo(int i) {\n");
buf.append(" if (i == 0)\n");
buf.append(" i++\n");
buf.append(" else\n");
buf.append(" properties = System.getProperties();\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 testInvertEquals3.
@Test
public void testInvertEquals3() 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(" private String a= \"a\";\n");
buf.append(" private String b= \"b\";\n");
buf.append(" public void foo() {\n");
buf.append(" a.equals(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), str.length());
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(" private String a= \"a\";\n");
buf.append(" private String b= \"b\";\n");
buf.append(" public void foo() {\n");
buf.append(" 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), str.length());
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(" private String a= \"a\";\n");
buf.append(" private String b= \"b\";\n");
buf.append(" public void foo() {\n");
buf.append(" a.equals(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 testCreateInSuper.
@Test
public void testCreateInSuper() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class A {\n");
buf.append("}\n");
pack1.createCompilationUnit("A.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public interface IB {\n");
buf.append("}\n");
pack1.createCompilationUnit("IB.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("import java.io.IOException;\n");
buf.append("import java.util.Vector;\n");
buf.append("public class E extends A implements IB {\n");
buf.append(" public Vector foo(int count) throws IOException {\n");
buf.append(" return null;\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
String str = "foo";
AssistContext context = getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 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("\n");
buf.append("import java.io.IOException;\n");
buf.append("import java.util.Vector;\n");
buf.append("\n");
buf.append("public interface IB {\n");
buf.append("\n");
buf.append(" Vector foo(int count) throws IOException;\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("\n");
buf.append("import java.io.IOException;\n");
buf.append("import java.util.Vector;\n");
buf.append("\n");
buf.append("public class A {\n");
buf.append("\n");
buf.append(" public Vector foo(int count) throws IOException {\n");
buf.append(" //TODO\n");
buf.append(" return null;\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 testUnwrapTryStatement.
@Test
public void testUnwrapTryStatement() 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(" try {\n");
buf.append(" StringBuffer buf= new StringBuffer();\n");
buf.append(" buf.append(1);\n");
buf.append(" buf.append(2);\n");
buf.append(" buf.append(3);\n");
buf.append(" } finally {\n");
buf.append(" return;\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
String str = "try";
AssistContext context = getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 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 test1;\n");
buf.append("public class E {\n");
buf.append(" public void foo() {\n");
buf.append(" StringBuffer buf= new StringBuffer();\n");
buf.append(" buf.append(1);\n");
buf.append(" buf.append(2);\n");
buf.append(" buf.append(3);\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
Aggregations