本文整理汇总了Java中org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.run方法的典型用法代码示例。如果您正苦于以下问题:Java OrganizeImportsOperation.run方法的具体用法?Java OrganizeImportsOperation.run怎么用?Java OrganizeImportsOperation.run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation
的用法示例。
在下文中一共展示了OrganizeImportsOperation.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNewImportsNoPackage
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入方法依赖的package包/类
@Test
public void testNewImportsNoPackage() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack1 = sourceFolder.getPackageFragment("");
StringBuffer buf = new StringBuffer();
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());
}
示例2: test2
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入方法依赖的package包/类
@Test
public void test2() throws Exception {
File junitSrcArchive =
new File(
JUnitSourceSetup.class
.getClassLoader()
.getResource(JavaProjectHelper.JUNIT_SRC_381.toOSString())
.getFile());
assertTrue("junit src not found", junitSrcArchive != null && junitSrcArchive.exists());
JavaProjectHelper.addSourceContainerWithImport(
fJProject1, "src", junitSrcArchive, JavaProjectHelper.JUNIT_SRC_ENCODING);
ICompilationUnit cu =
(ICompilationUnit)
fJProject1.findElement(new Path("junit/runner/LoadingTestCollector.java"));
assertNotNull("LoadingTestCollector.java", cu);
String[] order = new String[0];
IChooseImportQuery query = createQuery("LoadingTestCollector", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
op.run(null);
assertImports(
cu,
new String[] {
"java.lang.reflect.Modifier", "junit.framework.Test", "junit.framework.TestSuite",
});
}
示例3: test3
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入方法依赖的package包/类
@Test
public void test3() throws Exception {
File junitSrcArchive =
new File(
JUnitSourceSetup.class
.getClassLoader()
.getResource(JavaProjectHelper.JUNIT_SRC_381.toOSString())
.getFile());
assertTrue("junit src not found", junitSrcArchive != null && junitSrcArchive.exists());
JavaProjectHelper.addSourceContainerWithImport(
fJProject1, "src", junitSrcArchive, JavaProjectHelper.JUNIT_SRC_ENCODING);
ICompilationUnit cu =
(ICompilationUnit)
fJProject1.findElement(new Path("junit/runner/TestCaseClassLoader.java"));
assertNotNull("TestCaseClassLoader.java", cu);
String[] order = new String[0];
IChooseImportQuery query = createQuery("TestCaseClassLoader", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, 3, false, true, true, query);
op.run(null);
assertImports(
cu,
new String[] {
"java.io.*",
"java.net.URL",
"java.util.*",
"java.util.zip.ZipEntry",
"java.util.zip.ZipFile",
});
}
示例4: test_bug78533
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入方法依赖的package包/类
@Test
public void test_bug78533() 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("public class A {\n");
buf.append(" public <T extends Collection> void method1() { }\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("\n");
buf.append("import java.util.Collection;\n");
buf.append("\n");
buf.append("public class A {\n");
buf.append(" public <T extends Collection> void method1() { }\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
示例5: testVisibility_bug85831
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入方法依赖的package包/类
@Test
public void testVisibility_bug85831() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack2 = sourceFolder.createPackageFragment("pack2", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package pack2;\n");
buf.append("\n");
buf.append("class A {\n");
buf.append(" public class AX {\n");
buf.append(" }\n");
buf.append("}\n");
buf.append("public class B {\n");
buf.append(" Object x= new A().new AX();\n");
buf.append("}\n");
ICompilationUnit cu = pack2.createCompilationUnit("B.java", buf.toString(), false, null);
String[] order = new String[] {};
IChooseImportQuery query =
createQuery("testVisibility_bug85831", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
op.run(null);
buf = new StringBuffer();
buf.append("package pack2;\n");
buf.append("\n");
buf.append("class A {\n");
buf.append(" public class AX {\n");
buf.append(" }\n");
buf.append("}\n");
buf.append("public class B {\n");
buf.append(" Object x= new A().new AX();\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
示例6: testStaticImports_bug230067
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入方法依赖的package包/类
@Test
public void testStaticImports_bug230067() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack1 = sourceFolder.createPackageFragment("a", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package a;\n");
buf.append("\n");
buf.append("class Test<T> {\n");
buf.append(" private static String TEST = \"constant\";\n");
buf.append("\n");
buf.append(" static class Inner extends Test<String> {\n");
buf.append(" public void test() {\n");
buf.append(" TEST.concat(\"access\");\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.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 a;\n");
buf.append("\n"); // no static import for 'TEST'
buf.append("class Test<T> {\n");
buf.append(" private static String TEST = \"constant\";\n");
buf.append("\n");
buf.append(" static class Inner extends Test<String> {\n");
buf.append(" public void test() {\n");
buf.append(" TEST.concat(\"access\");\n");
buf.append(" }\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
示例7: testImportCountAddNew
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入方法依赖的package包/类
@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());
}
示例8: testCommentAfterImport
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入方法依赖的package包/类
@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());
}
示例9: testStaticImports1
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入方法依赖的package包/类
@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());
}
示例10: test1
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入方法依赖的package包/类
@Test
public void test1() throws Exception {
File junitSrcArchive =
new File(
JUnitSourceSetup.class
.getClassLoader()
.getResource(JavaProjectHelper.JUNIT_SRC_381.toOSString())
.getFile());
assertTrue("junit src not found", junitSrcArchive != null && junitSrcArchive.exists());
JavaProjectHelper.addSourceContainerWithImport(
fJProject1, "src", junitSrcArchive, JavaProjectHelper.JUNIT_SRC_ENCODING);
ICompilationUnit cu =
(ICompilationUnit) fJProject1.findElement(new Path("junit/runner/BaseTestRunner.java"));
assertNotNull("BaseTestRunner.java", cu);
IPackageFragmentRoot root = (IPackageFragmentRoot) cu.getParent().getParent();
IPackageFragment pack = root.createPackageFragment("mytest", true, null);
ICompilationUnit colidingCU = pack.getCompilationUnit("TestListener.java");
colidingCU.createType("public abstract class TestListener {\n}\n", null, true, null);
String[] order = new String[0];
IChooseImportQuery query =
createQuery("BaseTestRunner", new String[] {"junit.framework.TestListener"}, new int[] {2});
OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
op.run(null);
assertImports(
cu,
new String[] {
"java.io.BufferedReader",
"java.io.File",
"java.io.FileInputStream",
"java.io.FileOutputStream",
"java.io.IOException",
"java.io.InputStream",
"java.io.PrintWriter",
"java.io.StringReader",
"java.io.StringWriter",
"java.lang.reflect.InvocationTargetException",
"java.lang.reflect.Method",
"java.lang.reflect.Modifier",
"java.text.NumberFormat",
"java.util.Properties",
"junit.framework.AssertionFailedError",
"junit.framework.Test",
"junit.framework.TestListener",
"junit.framework.TestSuite"
});
}
示例11: test_bug78716
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入方法依赖的package包/类
@Test
public void test_bug78716() 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 enum MyEnum {\n");
buf.append(" A, B, C\n");
buf.append("}\n");
pack0.createCompilationUnit("MyEnum.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.MyEnum;\n");
buf.append("import static pack0.MyEnum.*;\n");
buf.append("\n");
buf.append("public class Test2 {\n");
buf.append(" MyEnum e= A;\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");
buf.append("import pack0.MyEnum;\n");
buf.append("\n");
buf.append("import static pack0.MyEnum.A;\n");
buf.append("\n");
buf.append("public class Test2 {\n");
buf.append(" MyEnum e= A;\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
示例12: testImportCountAddandRemoveWithComments
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入方法依赖的package包/类
@Test
public void testImportCountAddandRemoveWithComments() 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("/**comment1*/\n");
buf.append("/*lead1*/import java.util.*;// trail 1\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("/**comment1*/\n");
buf.append("/*lead1*/");
buf.append("import java.util.ArrayList;\n");
buf.append("import java.util.HashMap;// trail 1\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(1, op.getNumberOfImportsRemoved());
}
示例13: testStaticImports_bug187004a
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入方法依赖的package包/类
@Test
public void testStaticImports_bug187004a() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack0 = sourceFolder.createPackageFragment("b", false, null);
StringBuffer buf = new StringBuffer();
buf.append("package b;\n");
buf.append("\n");
buf.append("abstract public class Parent<T> {\n");
buf.append(" protected static final int CONSTANT = 42;\n");
buf.append("}\n");
pack0.createCompilationUnit("Parent.java", buf.toString(), false, null);
IPackageFragment pack1 = sourceFolder.createPackageFragment("a", false, null);
buf = new StringBuffer();
buf.append("package a;\n");
buf.append("\n");
buf.append("import b.Parent;\n");
buf.append("\n");
buf.append("public class Child extends Parent<String> {\n");
buf.append(" public Child() {\n");
buf.append(" System.out.println(CONSTANT);\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("Child.java", buf.toString(), false, null);
String[] order = new String[] {};
IChooseImportQuery query = createQuery("Child", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
op.run(null);
buf = new StringBuffer();
buf.append("package a;\n");
buf.append("\n");
buf.append("import b.Parent;\n"); // no static import for CONSTANT
buf.append("\n");
buf.append("public class Child extends Parent<String> {\n");
buf.append(" public Child() {\n");
buf.append(" System.out.println(CONSTANT);\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
示例14: testStaticImports_bug78585
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入方法依赖的package包/类
@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");
buf.append("import pack0.Test1;\n"); // no static import for 'assertNotEquals'
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());
}
示例15: testImportToStar
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入方法依赖的package包/类
@Test
public void testImportToStar() 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("import java.util.Set;\n");
buf.append("import java.util.Vector;\n");
buf.append("import java.util.Map;\n");
buf.append("\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("import java.util.*;\n");
buf.append("\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());
}