本文整理汇总了Java中org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation类的典型用法代码示例。如果您正苦于以下问题:Java OrganizeImportsOperation类的具体用法?Java OrganizeImportsOperation怎么用?Java OrganizeImportsOperation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OrganizeImportsOperation类属于org.eclipse.jdt.internal.corext.codemanipulation包,在下文中一共展示了OrganizeImportsOperation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testClearImports
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入依赖的package包/类
@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());
}
示例2: testNewImports
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入依赖的package包/类
@Test
public void testNewImports() 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("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("package test1;\n");
buf.append("\n");
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());
}
示例3: testClearImportsNoPackage
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入依赖的package包/类
@Test
public void testClearImportsNoPackage() throws Exception {
IPackageFragmentRoot sourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
IPackageFragment pack1 = sourceFolder.getPackageFragment("");
StringBuffer buf = new StringBuffer();
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("public class C {\n");
buf.append("}\n");
assertEqualString(cu.getSource(), buf.toString());
}
示例4: 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());
}
示例5: testReplaceImportsNoPackage
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入依赖的package包/类
@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());
}
示例6: getOrganizeInfo
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入依赖的package包/类
private String getOrganizeInfo(OrganizeImportsOperation op) {
int nImportsAdded= op.getNumberOfImportsAdded();
if (nImportsAdded >= 0) {
if (nImportsAdded == 1) {
return ActionMessages.OrganizeImportsAction_summary_added_singular;
} else {
return Messages.format(ActionMessages.OrganizeImportsAction_summary_added_plural, String.valueOf(nImportsAdded));
}
} else {
if (nImportsAdded == -1) {
return ActionMessages.OrganizeImportsAction_summary_removed_singular;
} else {
return Messages.format(ActionMessages.OrganizeImportsAction_summary_removed_plural, String.valueOf(-nImportsAdded));
}
}
}
示例7: createOrganizeImportOperation
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入依赖的package包/类
private OrganizeImportResult createOrganizeImportOperation(
ICompilationUnit compilationUnit, List<String> chosen) throws CoreException {
CodeGenerationSettings settings =
JavaPreferencesSettings.getCodeGenerationSettings(compilationUnit.getJavaProject());
OrganizeImportsOperation operation =
new OrganizeImportsOperation(
compilationUnit,
null,
settings.importIgnoreLowercase,
!compilationUnit.isWorkingCopy(),
true,
chosen,
null);
NullProgressMonitor monitor = new NullProgressMonitor();
TextEdit edit = operation.createTextEdit(monitor);
OrganizeImportResult result = DtoFactory.newDto(OrganizeImportResult.class);
TypeNameMatch[][] choices = operation.getChoices();
// Apply organize import declarations if operation doesn't have conflicts (choices.length == 0)
// or all conflicts were resolved (!chosen.isEmpty())
if ((chosen != null && !chosen.isEmpty()) || choices == null || choices.length == 0) {
IBuffer buffer = compilationUnit.getBuffer();
IDocument document = new Document(buffer.getContents());
DocumentChangeListener documentChangeListener = new DocumentChangeListener(document);
try {
edit.apply(document);
} catch (BadLocationException e) {
LOG.debug("Applying Organize import text edits goes wrong:", e);
}
result.setChanges(documentChangeListener.getChanges());
return result;
}
result.setConflicts(createListOfDTOMatches(choices));
return result;
}
示例8: 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",
});
}
示例9: 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",
});
}
示例10: test4
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入依赖的package包/类
@Test
public void test4() 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/textui/TestRunner.java"));
assertNotNull("TestRunner.java", cu);
String[] order = new String[0];
IChooseImportQuery query = createQuery("TestRunner", new String[] {}, new int[] {});
OrganizeImportsOperation op = createOperation(cu, order, 99, false, true, true, query);
op.run(null);
assertImports(
cu,
new String[] {
"java.io.PrintStream",
"junit.framework.Test",
"junit.framework.TestResult",
"junit.framework.TestSuite",
"junit.runner.BaseTestRunner",
"junit.runner.StandardTestSuiteLoader",
"junit.runner.TestSuiteLoader",
"junit.runner.Version"
});
}
示例11: testReplaceImports
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入依赖的package包/类
@Test
public void testReplaceImports() 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("\n");
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("package test1;\n");
buf.append("\n");
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());
}
示例12: 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());
}
示例13: testVisibility_bug26746
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入依赖的package包/类
@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());
}
示例14: testVisibility_bug56704
import org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation; //导入依赖的package包/类
@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());
}
示例15: 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());
}