use of org.eclipse.jdt.core.IPackageFragment in project che by eclipse.
the class ConvertForLoopQuickFixTest method testSimplestClean.
@Test
public void testSimplestClean() 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(" String[] array = {\"1\",\"2\"};\n");
buf.append(" for (int i = 0; i < array.length; i++){\n");
buf.append(" System.out.println(array[i]);\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);
assertNotNull(fConvertLoopProposal);
assertCorrectLabels(proposals);
String preview1 = getPreviewContent(fConvertLoopProposal);
buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class A {\n");
buf.append(" public void foo() {\n");
buf.append(" String[] array = {\"1\",\"2\"};\n");
buf.append(" for (String element : array) {\n");
buf.append(" System.out.println(element);\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
String expected = buf.toString();
assertEqualString(preview1, expected);
}
use of org.eclipse.jdt.core.IPackageFragment in project che by eclipse.
the class ConvertForLoopQuickFixTest method testBug148419.
@Test
public void testBug148419() 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(" private int[] ints;\n");
buf.append(" public void foo() {\n");
buf.append(" for (int i = 0; i < this.ints.length; i++) {\n");
buf.append(" this.ints[i]= 0;\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
List proposals = fetchConvertingProposal(buf, cu);
assertNull(fConvertLoopProposal);
assertCorrectLabels(proposals);
}
use of org.eclipse.jdt.core.IPackageFragment in project che by eclipse.
the class ConvertForLoopQuickFixTest method testBug214340_2.
@Test
public void testBug214340_2() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("public class E1 {\n");
buf.append(" int[] array = new int[3];\n");
buf.append(" static boolean same(E1 one, E1 two) {\n");
buf.append(" for (int i = 0; i < one.array.length; i++) {\n");
buf.append(" if (one.array[i] != two.array[i])\n");
buf.append(" return false;\n");
buf.append(" }\n");
buf.append(" return true;\n");
buf.append(" }\n");
buf.append("}\n");
buf.append("\n");
ICompilationUnit cu = pack1.createCompilationUnit("E1.java", buf.toString(), false, null);
assertFalse(satisfiesPrecondition(cu));
}
use of org.eclipse.jdt.core.IPackageFragment in project che by eclipse.
the class ConvertForLoopQuickFixTest method testIndexReadOutsideArrayAccess.
@Test
public void testIndexReadOutsideArrayAccess() 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; i < array.length; i++){\n");
buf.append(" if (i == 1){};\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);
}
use of org.eclipse.jdt.core.IPackageFragment in project che by eclipse.
the class ConvertForLoopQuickFixTest method testCollectionIsNotArray.
@Test
public void testCollectionIsNotArray() 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(" java.util.List list = new ArrayList();\n");
buf.append(" list.add(null);\n");
buf.append(" for (int i = 0; i < list.size(); i++){\n");
buf.append(" System.out.println(list.get(i);\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