use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.
the class ImportOrganizeTest method testImportToStarWithComments.
@Test
public void testImportToStarWithComments() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack2 = sourceFolder.createPackageFragment("pack", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack;\n");
buf.append("public class List {\n");
buf.append("}\n");
pack2.createCompilationUnit("List.java", buf.toString(), false, null);
IPackageFragment pack1 = sourceFolder.createPackageFragment("pack1", false, null);
buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
buf.append("// comment 1\n");
buf.append("/*lead 1*/import java.util.Set;//test1\n");
buf.append("/*lead 2*/ import java.util.Vector;/*test2*/\n");
buf.append("/**lead 3*/import java.util.Map; //test3\n");
buf.append("/**comment 2*/\n");
buf.append("import pack.List;\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" Vector v;\n");
buf.append(" Set v2;\n");
buf.append(" Map v3;\n");
buf.append(" List v4;\n");
buf.append(" String v5;\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, 2, false, true, true, query);
op.run(null);
buf = new StringBuffer();
buf.append("package pack1;\n");
buf.append("\n");
buf.append("// comment 1\n");
buf.append("/*lead 1*//*lead 2*/ /**lead 3*/import java.util.*; //test3\n");
buf.append("//test1/*test2*/\n");
buf.append("");
buf.append("\n");
buf.append("/**comment 2*/\n");
buf.append("import pack.List;\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" Vector v;\n");
buf.append(" Set v2;\n");
buf.append(" Map v3;\n");
buf.append(" List v4;\n");
buf.append(" String v5;\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_PackageInfoBug157541a.
@Test
public void test_PackageInfoBug157541a() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack1 = sourceFolder.createPackageFragment("pack1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("@Foo\n");
buf.append("package pack1;");
ICompilationUnit cu = pack1.createCompilationUnit("package-info.java", buf.toString(), false, null);
IPackageFragment pack2 = sourceFolder.createPackageFragment("pack2", false, null);
buf = new StringBuffer();
buf.append("package pack2;\n");
buf.append("public @interface Foo {\n");
buf.append("}\n");
pack2.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("@Foo\n");
buf.append("package pack1;\n");
buf.append("import pack2.Foo;\n");
assertEqualString(cu.getSource(), buf.toString());
}
use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.
the class ImportOrganizeTest method testVisibility_bug37299b.
@Test
public void testVisibility_bug37299b() 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("public class ClusterSingletonStepped {\n");
buf.append(" public interface SingletonStep {\n");
buf.append(" }\n");
buf.append("}\n");
pack1.createCompilationUnit("ClusterSingletonStepped.java", buf.toString(), false, null);
IPackageFragment pack2 = sourceFolder.createPackageFragment("pack0", false, null);
buf = new StringBuffer();
buf.append("package pack0;\n");
buf.append("\n");
buf.append("import pack1.ClusterSingletonStepped;\n");
buf.append("import pack1.ClusterSingletonStepped.SingletonStep;\n");
buf.append("\n");
buf.append("public class TestFile extends ClusterSingletonStepped {\n");
buf.append(" SingletonStep step;\n");
buf.append("}\n");
ICompilationUnit cu = pack2.createCompilationUnit("TestFile.java", buf.toString(), false, null);
String[] order = new String[] {};
IChooseImportQuery query = createQuery("TestFile", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
op.run(null);
buf = new StringBuffer();
buf.append("package pack0;\n");
buf.append("\n");
buf.append("import pack1.ClusterSingletonStepped;\n");
buf.append("\n");
buf.append("public class TestFile extends ClusterSingletonStepped {\n");
buf.append(" SingletonStep step;\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 testClearImports.
@Test
public void testClearImports() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package test1;\n");
buf.append("import java.util.Vector;\n");
buf.append("public class C {\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("C.java", buf.toString(), false, null);
String[] order = new String[0];
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 test1;\n");
buf.append("public class C {\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 testStaticImports2.
@Test
public void testStaticImports2() 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 static java.io.File.*;\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" public String foo() {\n");
buf.append(" return pathSeparator + separator + File.separator;\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("C.java", buf.toString(), false, null);
String[] order = new String[] { "#java.io.File", "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 static java.io.File.pathSeparator;\n");
buf.append("import static java.io.File.separator;\n");
buf.append("\n");
buf.append("import java.io.File;\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" public String foo() {\n");
buf.append(" return pathSeparator + separator + File.separator;\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
Aggregations