use of org.eclipse.jdt.core.IPackageFragment in project che by eclipse.
the class ConvertForLoopQuickFixTest method testExpressionPrecondition07.
@Test
public void testExpressionPrecondition07() 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(" public void foo(Object[] x) {\n");
buf.append(" for (int i = 0, length= x.length; i < length; i++) {}\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.IPackageFragment in project che by eclipse.
the class ConvertForLoopQuickFixTest method testBug130139_2.
@Test
public void testBug130139_2() 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(" public void foo(String[] strings) {\n");
buf.append(" for (int i= x(); i < strings.length; i++) {\n");
buf.append(" System.out.println(strings[i]);\n");
buf.append(" } \n");
buf.append(" }\n");
buf.append(" private int x(){\n");
buf.append(" return 0;\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 testBodyPrecondition344674_3.
@Test
public void testBodyPrecondition344674_3() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=344674
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(Object obj) {\n");
buf.append(" for (int i = 0; i < ((E) obj).x.length; i++) {\n");
buf.append(" System.out.println(((E) obj).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.IPackageFragment in project che by eclipse.
the class ConvertForLoopQuickFixTest method testNiceReduction.
@Test
public void testNiceReduction() throws Exception {
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("class Weirdy{}\n");
buf.append("private Weirdy[] weirdies;\n");
buf.append("public class A {\n");
buf.append(" public void foo(){\n");
buf.append(" for (int i = 0, length = weirdies.length; i < length; i++){\n");
buf.append(" System.out.println();\n");
buf.append(" Weirdy p = weirdies[i];\n");
buf.append(" if (p != null){\n");
buf.append(" System.out.println(p);\n");
buf.append(" }\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("class Weirdy{}\n");
buf.append("private Weirdy[] weirdies;\n");
buf.append("public class A {\n");
buf.append(" public void foo(){\n");
buf.append(" for (Weirdy p : weirdies) {\n");
buf.append(" System.out.println();\n");
buf.append(" if (p != null){\n");
buf.append(" System.out.println(p);\n");
buf.append(" }\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 testBodyPrecondition09.
@Test
public void testBodyPrecondition09() 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(" public void foo(Object[] x) {\n");
buf.append(" for (int i = 0; i < x.length; i++) {\n");
buf.append(" x[i]= null;\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
assertFalse(satisfiesPrecondition(cu));
}
Aggregations