Search in sources :

Example 1 with TextEditConverter

use of org.eclipse.jdt.ls.core.internal.TextEditConverter in project eclipse.jdt.ls by eclipse.

the class CodeActionHandler method textEditToCommand.

private static Command textEditToCommand(ICompilationUnit unit, String label, TextEdit textEdit) {
    TextEditConverter converter = new TextEditConverter(unit, textEdit);
    String uri = JDTUtils.toURI(unit);
    WorkspaceEdit $ = new WorkspaceEdit();
    $.getChanges().put(uri, converter.convert());
    return new Command(label, COMMAND_ID_APPLY_EDIT, Arrays.asList($));
}
Also used : Command(org.eclipse.lsp4j.Command) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) TextEditConverter(org.eclipse.jdt.ls.core.internal.TextEditConverter)

Example 2 with TextEditConverter

use of org.eclipse.jdt.ls.core.internal.TextEditConverter in project eclipse.jdt.ls by eclipse.

the class CompletionProposalReplacementProvider method addImports.

/**
 * Adds imports collected by importRewrite to item
 * @param item
 */
private void addImports(List<org.eclipse.lsp4j.TextEdit> additionalEdits) {
    if (this.importRewrite != null) {
        try {
            TextEdit edit = this.importRewrite.rewriteImports(new NullProgressMonitor());
            TextEditConverter converter = new TextEditConverter(this.compilationUnit, edit);
            List<org.eclipse.lsp4j.TextEdit> edits = converter.convert();
            if (ChangeUtil.hasChanges(edits)) {
                additionalEdits.addAll(edits);
            }
        } catch (CoreException e) {
            JavaLanguageServerPlugin.logException("Error adding imports", e);
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) TextEdit(org.eclipse.text.edits.TextEdit) TextEditConverter(org.eclipse.jdt.ls.core.internal.TextEditConverter)

Example 3 with TextEditConverter

use of org.eclipse.jdt.ls.core.internal.TextEditConverter in project eclipse.jdt.ls by eclipse.

the class RenameProcessor method convert.

protected void convert(WorkspaceEdit root, ICompilationUnit unit, TextEdit edits) {
    TextEditConverter converter = new TextEditConverter(unit, edits);
    String uri = JDTUtils.toURI(unit);
    Map<String, List<org.eclipse.lsp4j.TextEdit>> changes = root.getChanges();
    if (changes.containsKey(uri)) {
        changes.get(uri).addAll(converter.convert());
    } else {
        changes.put(uri, converter.convert());
    }
}
Also used : List(java.util.List) TextEditConverter(org.eclipse.jdt.ls.core.internal.TextEditConverter)

Example 4 with TextEditConverter

use of org.eclipse.jdt.ls.core.internal.TextEditConverter in project eclipse.jdt.ls by eclipse.

the class OrganizeImportsCommand method addWorkspaceEdit.

private void addWorkspaceEdit(ICompilationUnit cu, CUCorrectionProposal proposal, WorkspaceEdit rootEdit) throws CoreException {
    TextChange textChange = proposal.getTextChange();
    TextEdit edit = textChange.getEdit();
    TextEditConverter converter = new TextEditConverter(cu, edit);
    List<org.eclipse.lsp4j.TextEdit> edits = converter.convert();
    if (ChangeUtil.hasChanges(edits)) {
        rootEdit.getChanges().put(JDTUtils.toURI(cu), edits);
    }
}
Also used : TextEdit(org.eclipse.text.edits.TextEdit) TextChange(org.eclipse.ltk.core.refactoring.TextChange) TextEditConverter(org.eclipse.jdt.ls.core.internal.TextEditConverter)

Example 5 with TextEditConverter

use of org.eclipse.jdt.ls.core.internal.TextEditConverter in project eclipse.jdt.ls by eclipse.

the class SourceAssistProcessor method convertToWorkspaceEdit.

public static WorkspaceEdit convertToWorkspaceEdit(ICompilationUnit cu, TextEdit edit) {
    if (cu == null || edit == null) {
        return null;
    }
    WorkspaceEdit workspaceEdit = new WorkspaceEdit();
    TextEditConverter converter = new TextEditConverter(cu, edit);
    String uri = JDTUtils.toURI(cu);
    workspaceEdit.getChanges().put(uri, converter.convert());
    return workspaceEdit;
}
Also used : WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) TextEditConverter(org.eclipse.jdt.ls.core.internal.TextEditConverter)

Aggregations

TextEditConverter (org.eclipse.jdt.ls.core.internal.TextEditConverter)5 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)2 TextEdit (org.eclipse.text.edits.TextEdit)2 List (java.util.List)1 CoreException (org.eclipse.core.runtime.CoreException)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Command (org.eclipse.lsp4j.Command)1 TextChange (org.eclipse.ltk.core.refactoring.TextChange)1