@Override public boolean visit(CopySourceEdit edit) { manageCopy(new RangeMarker(edit.getOffset(), edit.getLength())); return true; } @Override
@Override public boolean visit(CopySourceEdit edit) { manageCopy(new RangeMarker(edit.getOffset(), edit.getLength())); return true; } @Override
@Override public boolean visit(CopySourceEdit edit) { try { if (edit.getTargetEdit() != null) { org.eclipse.lsp4j.TextEdit te = new org.eclipse.lsp4j.TextEdit(); te.setRange(JDTUtils.toRange(compilationUnit, edit.getOffset(), edit.getLength())); Document doc = new Document(compilationUnit.getSource()); edit.apply(doc, TextEdit.UPDATE_REGIONS); String content = doc.get(edit.getOffset(), edit.getLength()); if (edit.getSourceModifier() != null) { content = applySourceModifier(content, edit.getSourceModifier()); } te.setNewText(content); converted.add(te); } return false; } catch (JavaModelException | MalformedTreeException | BadLocationException e) { JavaLanguageServerPlugin.logException("Error converting TextEdits", e); } return super.visit(edit); }
@Override void performSourceComputation(TextEditProcessor processor, IDocument document) { try { MultiTextEdit root= new MultiTextEdit(getOffset(), getLength()); root.internalSetChildren(internalGetChildren()); fSourceContent= document.get(getOffset(), getLength()); fSourceRoot= PartialCopier.perform(root); fSourceRoot.internalMoveTree(-getOffset()); if (fSourceRoot.hasChildren()) { EditDocument subDocument= new EditDocument(fSourceContent); TextEditProcessor subProcessor= TextEditProcessor.createSourceComputationProcessor(subDocument, fSourceRoot, TextEdit.NONE); subProcessor.performEdits(); if (needsTransformation()) applyTransformation(subDocument); fSourceContent= subDocument.get(); fSourceRoot= null; } else { if (needsTransformation()) { EditDocument subDocument= new EditDocument(fSourceContent); applyTransformation(subDocument); fSourceContent= subDocument.get(); } } } catch (BadLocationException cannotHappen) { Assert.isTrue(false); } }
@Override void performSourceComputation(TextEditProcessor processor, IDocument document) { try { MultiTextEdit root= new MultiTextEdit(getOffset(), getLength()); root.internalSetChildren(internalGetChildren()); fSourceContent= document.get(getOffset(), getLength()); fSourceRoot= PartialCopier.perform(root); fSourceRoot.internalMoveTree(-getOffset()); if (fSourceRoot.hasChildren()) { EditDocument subDocument= new EditDocument(fSourceContent); TextEditProcessor subProcessor= TextEditProcessor.createSourceComputationProcessor(subDocument, fSourceRoot, TextEdit.NONE); subProcessor.performEdits(); if (needsTransformation()) applyTransformation(subDocument); fSourceContent= subDocument.get(); fSourceRoot= null; } else { if (needsTransformation()) { EditDocument subDocument= new EditDocument(fSourceContent); applyTransformation(subDocument); fSourceContent= subDocument.get(); } } } catch (BadLocationException cannotHappen) { Assert.isTrue(false); } }
@Override public boolean visit(CopyTargetEdit edit) { try { if (edit.getSourceEdit() != null) { org.eclipse.lsp4j.TextEdit te = new org.eclipse.lsp4j.TextEdit(); te.setRange(JDTUtils.toRange(compilationUnit, edit.getOffset(), edit.getLength())); Document doc = new Document(compilationUnit.getSource()); edit.apply(doc, TextEdit.UPDATE_REGIONS); String content = doc.get(edit.getSourceEdit().getOffset(), edit.getSourceEdit().getLength()); if (edit.getSourceEdit().getSourceModifier() != null) { content = applySourceModifier(content, edit.getSourceEdit().getSourceModifier()); } te.setNewText(content); converted.add(te); } return false; // do not visit children } catch (MalformedTreeException | BadLocationException | CoreException e) { JavaLanguageServerPlugin.logException("Error converting TextEdits", e); } return super.visit(edit); }