use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.
the class ImportOrganizeTest method testImportCountAddNew.
@Test
public void testImportCountAddNew() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack1 = sourceFolder.createPackageFragment("pack1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" public void foo() {\n");
buf.append(" HashMap m;\n");
buf.append(" ArrayList l;\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("C.java", buf.toString(), false, null);
String[] order = new String[] { "java", "pack" };
IChooseImportQuery query = createQuery("C", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
op.run(null);
buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
buf.append("import java.util.ArrayList;\n");
buf.append("import java.util.HashMap;\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" public void foo() {\n");
buf.append(" HashMap m;\n");
buf.append(" ArrayList l;\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
assertEquals(2, op.getNumberOfImportsAdded());
assertEquals(0, op.getNumberOfImportsRemoved());
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.
the class ImportOrganizeTest method testImportCountKeepStatic.
@Test
public void testImportCountKeepStatic() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack1 = sourceFolder.createPackageFragment("pack1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
buf.append("import java.util.BitSet;\n");
buf.append("// some comment;\n");
buf.append("import java.util.Calendar; /*another comment*/\n");
buf.append("import static java.io.File.pathSeparator;\n");
buf.append("import java.util.*;\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" public void foo() {\n");
buf.append(" String s= pathSeparator;\n");
buf.append(" HashMap m;\n");
buf.append(" ArrayList l;\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("C.java", buf.toString(), false, null);
String[] order = new String[] { "java", "pack", "#" };
IChooseImportQuery query = createQuery("C", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
op.run(null);
buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
buf.append("import java.util.ArrayList;\n");
buf.append("import java.util.HashMap;\n");
buf.append("\n");
buf.append("import static java.io.File.pathSeparator;\n");
buf.append("// some comment;\n");
buf.append("/*another comment*/\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" public void foo() {\n");
buf.append(" String s= pathSeparator;\n");
buf.append(" HashMap m;\n");
buf.append(" ArrayList l;\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
assertEquals(2, op.getNumberOfImportsAdded());
assertEquals(3, op.getNumberOfImportsRemoved());
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.
the class ImportOrganizeTest method testStaticImports_bug113770.
@Test
public void testStaticImports_bug113770() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack0 = sourceFolder.createPackageFragment("pack0", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test;\n");
buf.append("\n");
buf.append("public abstract class Test<M>\n");
buf.append("{\n");
buf.append(" private static Map<Object, Object[]> facetMap;\n");
buf.append("\n");
buf.append(" public void getFacets() {\n");
buf.append(" facetMap.get(null);\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack0.createCompilationUnit("Test.java", buf.toString(), false, null);
String[] order = new String[] {};
IChooseImportQuery query = createQuery("Test", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
op.run(null);
buf = new StringBuffer();
buf.append("package test;\n");
buf.append("\n");
buf.append("import java.util.Map;\n");
buf.append("\n");
buf.append("public abstract class Test<M>\n");
buf.append("{\n");
buf.append(" private static Map<Object, Object[]> facetMap;\n");
buf.append("\n");
buf.append(" public void getFacets() {\n");
buf.append(" facetMap.get(null);\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.
the class ImportOrganizeTest method test_bug135122.
@Test
public void test_bug135122() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack1 = sourceFolder.createPackageFragment("pack1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
buf.append("public class Foo extends Bar {\n");
buf.append(" public static final int MYCONSTANT= 9;\n");
buf.append("\n");
buf.append(" public void anotherMethod() {\n");
buf.append(" super.testMethod(MYCONSTANT);\n");
buf.append(" }\n");
buf.append("}\n");
buf.append("\n");
buf.append("class Bar {\n");
buf.append(" public void testMethod(int something) {\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("Foo.java", buf.toString(), false, null);
String[] order = new String[] { "", "#" };
IChooseImportQuery query = createQuery("Foo", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
op.run(null);
buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
buf.append("public class Foo extends Bar {\n");
buf.append(" public static final int MYCONSTANT= 9;\n");
buf.append("\n");
buf.append(" public void anotherMethod() {\n");
buf.append(" super.testMethod(MYCONSTANT);\n");
buf.append(" }\n");
buf.append("}\n");
buf.append("\n");
buf.append("class Bar {\n");
buf.append(" public void testMethod(int something) {\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.
the class ImportOrganizeTest method test_bug25113.
@Test
public void test_bug25113() throws Exception {
String[] types = new String[] { "com.mycompany.Class1", "com.foreigncompany.Class2", "com.foreigncompany.Class3", "com.mycompany.Class4", "com.misc.Class5" };
String[] order = new String[] { "com", "com.foreigncompany", "com.mycompany" };
int threshold = 99;
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
for (int i = 0; i < types.length; i++) {
String pack = Signature.getQualifier(types[i]);
if (!pack.startsWith("java.")) {
String name = Signature.getSimpleName(types[i]);
IPackageFragment pack2 = sourceFolder.createPackageFragment(pack, false, null);
StringBuffer buf = new StringBuffer();
buf.append("package ");
buf.append(pack);
buf.append(";\n");
buf.append("public class ");
buf.append(name);
buf.append(" {\n");
buf.append("}\n");
pack2.createCompilationUnit(name + ".java", buf.toString(), false, null);
}
}
StringBuffer body = new StringBuffer();
body.append("public class C {\n");
for (int i = 0; i < types.length; i++) {
String name = Signature.getSimpleName(types[i]);
body.append(name);
body.append(" a");
body.append(i);
body.append(";\n");
}
body.append("}\n");
IPackageFragment pack1 = sourceFolder.createPackageFragment("pack1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
buf.append(body.toString());
ICompilationUnit cu = pack1.createCompilationUnit("C.java", buf.toString(), false, null);
IChooseImportQuery query = createQuery("C", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, threshold, false, true, true, query);
op.run(null);
buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
buf.append("import com.misc.Class5;\n");
buf.append("\n");
buf.append("import com.foreigncompany.Class2;\n");
buf.append("import com.foreigncompany.Class3;\n");
buf.append("\n");
buf.append("import com.mycompany.Class1;\n");
buf.append("import com.mycompany.Class4;\n");
buf.append("\n");
buf.append(body.toString());
assertEqualString(cu.getSource(), buf.toString());
}
Aggregations