use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation in project che by eclipse.
the class ImportOrganizeTest method testCommentAfterImport.
@Test
public void testCommentAfterImport() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack1 = sourceFolder.createPackageFragment("pack1", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack1;\r\n");
buf.append("\r\n");
buf.append("import x;\r\n");
buf.append("import java.util.Vector; //comment\n");
buf.append("\r\n");
buf.append("public class C {\r\n");
buf.append(" Vector v;\r\n");
buf.append("}\r\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 pack1;\r\n");
buf.append("\r\n");
buf.append("import java.util.Vector; //comment\n");
buf.append("\r\n");
buf.append("public class C {\r\n");
buf.append(" Vector v;\r\n");
buf.append("}\r\n");
assertEqualString(cu.getSource(), buf.toString());
}
use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation in project che by eclipse.
the class ImportOrganizeTest method testVisibility_bug26746.
@Test
public void testVisibility_bug26746() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack2 = sourceFolder.createPackageFragment("pack0", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack0;\n");
buf.append("public interface MyInterface {\n");
buf.append(" public interface MyInnerInterface {\n");
buf.append(" }\n");
buf.append("}\n");
pack2.createCompilationUnit("MyInterface.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package pack0;\n");
buf.append("\n");
buf.append("import pack0.MyInterface.MyInnerInterface;\n");
buf.append("public class MyClass implements MyInterface {\n");
buf.append(" public MyInnerInterface myMethod() {\n");
buf.append(" return null;\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack2.createCompilationUnit("MyClass.java", buf.toString(), false, null);
String[] order = new String[] {};
IChooseImportQuery query = createQuery("MyClass", 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("public class MyClass implements MyInterface {\n");
buf.append(" public MyInnerInterface myMethod() {\n");
buf.append(" return null;\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation in project che by eclipse.
the class ImportOrganizeTest method test_bug25773.
@Test
public void test_bug25773() throws Exception {
String[] types = new String[] { "java.util.Vector", "java.util.Map", "java.util.Set", "org.eclipse.gef.X1", "org.eclipse.gef.X2", "org.eclipse.gef.X3", "org.eclipse.core.runtime.IAdaptable", "org.eclipse.draw2d.IFigure", "org.eclipse.draw2d.LayoutManager", "org.eclipse.draw2d.geometry.Point", "org.eclipse.draw2d.geometry.Rectangle", "org.eclipse.swt.accessibility.ACC", "org.eclipse.swt.accessibility.AccessibleControlEvent" };
String[] order = new String[] { "java", "org.eclipse", "org.eclipse.gef", "org.eclipse.draw2d", "org.eclipse.gef.examples" };
int threshold = 3;
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 java.util.*;\n");
buf.append("\n");
buf.append("import org.eclipse.core.runtime.IAdaptable;\n");
buf.append("import org.eclipse.swt.accessibility.ACC;\n");
buf.append("import org.eclipse.swt.accessibility.AccessibleControlEvent;\n");
buf.append("\n");
buf.append("import org.eclipse.gef.*;\n");
buf.append("\n");
buf.append("import org.eclipse.draw2d.IFigure;\n");
buf.append("import org.eclipse.draw2d.LayoutManager;\n");
buf.append("import org.eclipse.draw2d.geometry.Point;\n");
buf.append("import org.eclipse.draw2d.geometry.Rectangle;\n");
buf.append("\n");
buf.append(body.toString());
assertEqualString(cu.getSource(), buf.toString());
}
use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation in project che by eclipse.
the class ImportOrganizeTest method testStaticImports_bug78585.
@Test
public void testStaticImports_bug78585() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack0 = sourceFolder.createPackageFragment("pack0", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack0;\n");
buf.append("public class Test1 {\n");
buf.append(" public static final <T> void assertNotEquals(final String msg, final T expected, final T toCheck) {\n");
buf.append(" }\n");
buf.append("}\n");
pack0.createCompilationUnit("Test1.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("import pack0.Test1;\n");
buf.append("import java.util.List;\n");
buf.append("\n");
buf.append("public class Test2 extends Test1 {\n");
buf.append(" public void testMe() {\n");
buf.append(" assertNotEquals(\"A\", \"B\", \"C\");\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("Test2.java", buf.toString(), false, null);
String[] order = new String[] {};
IChooseImportQuery query = createQuery("MyClass", 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");
// no static import for 'assertNotEquals'
buf.append("import pack0.Test1;\n");
buf.append("\n");
buf.append("public class Test2 extends Test1 {\n");
buf.append(" public void testMe() {\n");
buf.append(" assertNotEquals(\"A\", \"B\", \"C\");\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation in project che by eclipse.
the class ImportOrganizeTest method testReplaceImportsNoPackage.
@Test
public void testReplaceImportsNoPackage() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack1 = sourceFolder.getPackageFragment("");
StringBuffer buf = new StringBuffer();
buf.append("import java.util.Set;\n");
buf.append("\n");
buf.append("public class C extends Vector {\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("import java.util.Vector;\n");
buf.append("\n");
buf.append("public class C extends Vector {\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
Aggregations