use of org.eclipse.jdt.core.ICompilationUnit in project che by eclipse.
the class AssistQuickFixTest method testConvertToStringBufferNoFixWithoutString.
@Test
public void testConvertToStringBufferNoFixWithoutString() 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(" public void foo() {\n");
buf.append(" int strX = 5+1;\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("A.java", buf.toString(), false, null);
AssistContext context = getCorrectionContext(cu, buf.toString().indexOf("strX ="), 0);
List proposals = collectAssists(context, false);
assertNumberOfProposals(proposals, 3);
assertCommandIdDoesNotExist(proposals, QuickAssistProcessor.CONVERT_TO_STRING_BUFFER_ID);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class A {\n");
buf.append(" public void foo() {\n");
buf.append(" int strX;\n");
buf.append(" strX = 5+1;\n");
buf.append(" }\n");
buf.append("}\n");
String expected1 = buf.toString();
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class A {\n");
buf.append(" public void foo() {\n");
buf.append(" }\n");
buf.append("}\n");
String expected2 = buf.toString();
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class A {\n");
buf.append(" private int strX;\n");
buf.append("\n");
buf.append(" public void foo() {\n");
buf.append(" strX = 5+1;\n");
buf.append(" }\n");
buf.append("}\n");
String expected3 = buf.toString();
assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3 });
}
use of org.eclipse.jdt.core.ICompilationUnit in project che by eclipse.
the class AssistQuickFixTest method testInvertEquals13.
@Test
public void testInvertEquals13() 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(" boolean equals(boolean b) {\n");
buf.append(" return false;\n");
buf.append(" }\n");
buf.append(" public void foo() {\n");
buf.append(" new E().equals(true ? true : false);\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
String str = "E().equals";
AssistContext context = getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0);
List proposals = collectAssists(context, FILTER_EQ);
assertNumberOfProposals(proposals, 0);
assertCorrectLabels(proposals);
context = getCorrectionContext(cu, buf.toString().lastIndexOf(str), 0);
proposals = collectAssists(context, FILTER_EQ);
assertNumberOfProposals(proposals, 0);
assertCorrectLabels(proposals);
}
use of org.eclipse.jdt.core.ICompilationUnit in project che by eclipse.
the class ConvertForLoopQuickFixTest method testCollectionsNotAcceptedYet.
@Test
public void testCollectionsNotAcceptedYet() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("import java.util.List;\n");
buf.append("import java.util.ArrayList;\n");
buf.append("public class A {\n");
buf.append(" public void foo() {\n");
buf.append(" List strings= new ArrayList();\n");
buf.append(" for (int i= 0; i < strings.size(); i++);\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("A.java", buf.toString(), false, null);
List proposals = fetchConvertingProposal(buf, cu);
assertNull(fConvertLoopProposal);
assertCorrectLabels(proposals);
}
use of org.eclipse.jdt.core.ICompilationUnit in project che by eclipse.
the class ConvertForLoopQuickFixTest method testBodyPrecondition03.
@Test
public void testBodyPrecondition03() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test;\n");
buf.append("public class E {\n");
buf.append(" Object[] x;\n");
buf.append(" public void foo() {\n");
buf.append(" for (int i = 0; i < x.length; i++) {\n");
buf.append(" System.out.println(this.x[i]);\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
assertTrue(satisfiesPrecondition(cu));
}
use of org.eclipse.jdt.core.ICompilationUnit in project che by eclipse.
the class ConvertForLoopQuickFixTest method testTwoIndexesNotAllowed.
@Test
public void testTwoIndexesNotAllowed() 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(" public void foo() {\n");
buf.append(" int[] array = {1,2,3,4};\n");
buf.append(" for (int i = 0, j = 0; i < array.length; i++, j++){\n");
buf.append(" System.out.println(array[i] + j);\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("A.java", buf.toString(), false, null);
List proposals = fetchConvertingProposal(buf, cu);
assertNull(fConvertLoopProposal);
assertCorrectLabels(proposals);
}
Aggregations