use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery in project che by eclipse.
the class ImportOrganizeTest method test_bug78397.
@Test
public void test_bug78397() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack1 = sourceFolder.createPackageFragment("pack0", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack0;\n");
buf.append("import java.util.Collection;\n");
buf.append("public class A {\n");
buf.append(" Collection<java.sql.Date> foo;\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("A.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("import java.util.Collection;\n");
buf.append("public class A {\n");
// no import for Date
buf.append(" Collection<java.sql.Date> foo;\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery in project che by eclipse.
the class ImportOrganizeTest method createQuery.
protected IChooseImportQuery createQuery(final String name, final String[] choices, final int[] nEntries) {
return new IChooseImportQuery() {
public TypeNameMatch[] chooseImports(TypeNameMatch[][] openChoices, ISourceRange[] ranges) {
assertTrue(name + "-query-nchoices1", choices.length == openChoices.length);
assertTrue(name + "-query-nchoices2", nEntries.length == openChoices.length);
for (int i = 0; i < nEntries.length; i++) {
assertTrue(name + "-query-cnt" + i, openChoices[i].length == nEntries[i]);
}
TypeNameMatch[] res = new TypeNameMatch[openChoices.length];
for (int i = 0; i < openChoices.length; i++) {
TypeNameMatch[] selection = openChoices[i];
assertNotNull(name + "-query-setset" + i, selection);
assertTrue(name + "-query-setlen" + i, selection.length > 0);
TypeNameMatch found = null;
for (int k = 0; k < selection.length; k++) {
if (selection[k].getFullyQualifiedName().equals(choices[i])) {
found = selection[k];
}
}
assertNotNull(name + "-query-notfound" + i, found);
res[i] = found;
}
return res;
}
};
}
use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery in project che by eclipse.
the class ImportOrganizeTest method testVisibility_bug56704.
@Test
public void testVisibility_bug56704() 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 class A {\n");
buf.append(" public class AX {\n");
buf.append(" }\n");
buf.append("}\n");
pack2.createCompilationUnit("A.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package pack0;\n");
buf.append("\n");
buf.append("import pack0.A.AX;\n");
buf.append("public class B extends A {\n");
buf.append(" public class BX extends AX {\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack2.createCompilationUnit("B.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 B extends A {\n");
buf.append(" public class BX extends AX {\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery in project che by eclipse.
the class ImportOrganizeTest method testVisibility_bug131305.
@Test
public void testVisibility_bug131305() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment packUtil = sourceFolder.createPackageFragment("util", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package util;\n");
buf.append("\n");
buf.append("public interface Map \n");
buf.append(" public static interface Entry {\n");
buf.append(" }\n");
buf.append("}\n");
packUtil.createCompilationUnit("Map.java", buf.toString(), false, null);
buf = new StringBuffer();
buf.append("package util;\n");
buf.append("\n");
buf.append("public interface HashMap implements Map {\n");
buf.append(" private static interface Entry {\n");
buf.append(" }\n");
buf.append("}\n");
packUtil.createCompilationUnit("HashMap.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 util.HashMap;\n");
buf.append("import util.Map;\n");
buf.append("import util.Map.Entry;\n");
buf.append("\n");
buf.append("public class A extends HashMap {\n");
buf.append(" public A(Map m, Entry e) {\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("A.java", buf.toString(), false, null);
String[] order = new String[] {};
IChooseImportQuery query = createQuery("testVisibility_bug131305", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
op.run(null);
// no changes, import for Entry is required
assertEqualString(cu.getSource(), buf.toString());
}
use of org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery in project che by eclipse.
the class ImportOrganizeTest method testStaticImports1.
@Test
public void testStaticImports1() 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.lang.System.out;\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" public int foo() {\n");
buf.append(" out.print(File.separator);\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("C.java", buf.toString(), false, null);
String[] order = new String[] { "java", "pack", "#java" };
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.io.File;\n");
buf.append("\n");
buf.append("import static java.lang.System.out;\n");
buf.append("\n");
buf.append("public class C {\n");
buf.append(" public int foo() {\n");
buf.append(" out.print(File.separator);\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
Aggregations