Java Code Examples for org.eclipse.jdt.core.dom.AST#newImportDeclaration()

The following examples show how to use org.eclipse.jdt.core.dom.AST#newImportDeclaration() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ASTUtil.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void addImports(ASTRewrite rewrite, CompilationUnit compilationUnit,
        Comparator<? super ImportDeclaration> comparator, boolean staticImports, String... imports) {
    requireNonNull(comparator, "import comparator");
    requireNonNull(imports, "imports");

    final AST ast = rewrite.getAST();
    SortedSet<ImportDeclaration> importDeclarations = new TreeSet<>(comparator);
    for (String importName : imports) {
        ImportDeclaration importDeclaration = ast.newImportDeclaration();
        importDeclaration.setName(ast.newName(importName));
        importDeclaration.setStatic(staticImports);
        importDeclarations.add(importDeclaration);
    }
    addImports(rewrite, compilationUnit, importDeclarations);
}
 
Example 2
Source File: ImportPopulator.java    From SparkBuilderGenerator with MIT License 4 votes vote down vote up
private void addImport(AST ast, ListRewrite importRewrite, String fullyQualifierImport) {
    ImportDeclaration importDeclaration = ast.newImportDeclaration();
    importDeclaration.setName(ast.newName(fullyQualifierImport));
    importRewrite.insertLast(importDeclaration, null);
}
 
Example 3
Source File: CreateDoPrivilegedBlockResolution.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
private ImportDeclaration createImportDeclaration(AST ast, String name, boolean isStatic) {
    ImportDeclaration importDeclaration = ast.newImportDeclaration();
    importDeclaration.setName(ast.newName(name));
    importDeclaration.setStatic(isStatic);
    return importDeclaration;
}