Search in sources :

Example 1 with ImportRewrite

use of org.springframework.ide.vscode.boot.java.jdt.imports.ImportRewrite in project sts4 by spring-projects.

the class JavaSnippetCompletion method getAdditionalEdit.

@Override
public Optional<DocumentEdits> getAdditionalEdit() {
    ImportRewrite rewrite = ImportRewrite.create(cu, true);
    javaSnippet.getImports().ifPresent((imprts -> {
        for (String imprt : imprts) {
            rewrite.addImport(imprt);
        }
    }));
    DocumentEdits edit = rewrite.createEdit(query.getDocument());
    return edit != null ? Optional.of(edit) : Optional.empty();
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) CompletionItemKind(org.eclipse.lsp4j.CompletionItemKind) ImportRewrite(org.springframework.ide.vscode.boot.java.jdt.imports.ImportRewrite) DocumentEdits(org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits) ICompletionProposal(org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion) Renderables(org.springframework.ide.vscode.commons.util.Renderables) Supplier(com.google.common.base.Supplier) Optional(java.util.Optional) Renderable(org.springframework.ide.vscode.commons.util.Renderable) SnippetBuilder(org.springframework.ide.vscode.commons.languageserver.util.SnippetBuilder) ImportRewrite(org.springframework.ide.vscode.boot.java.jdt.imports.ImportRewrite) DocumentEdits(org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits)

Aggregations

Supplier (com.google.common.base.Supplier)1 Optional (java.util.Optional)1 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)1 CompletionItemKind (org.eclipse.lsp4j.CompletionItemKind)1 ImportRewrite (org.springframework.ide.vscode.boot.java.jdt.imports.ImportRewrite)1 DocumentEdits (org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits)1 ICompletionProposal (org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal)1 SnippetBuilder (org.springframework.ide.vscode.commons.languageserver.util.SnippetBuilder)1 Renderable (org.springframework.ide.vscode.commons.util.Renderable)1 Renderables (org.springframework.ide.vscode.commons.util.Renderables)1 DocumentRegion (org.springframework.ide.vscode.commons.util.text.DocumentRegion)1