@Override protected TextEdit doCopy() { return new MoveSourceEdit(this); }
/** * Constructs a new copy source edit. * * @param offset the edit's offset * @param length the edit's length * @param target the edit's target */ public MoveSourceEdit(int offset, int length, MoveTargetEdit target) { this(offset, length); setTargetEdit(target); }
@Override public boolean visit(MoveSourceEdit edit) { try { // If MoveSourcedEdit & MoveTargetEdit are the same level, should delete the original contenxt. // See issue#https://github.com/redhat-developer/vscode-java/issues/253 if (edit.getParent() != null && edit.getTargetEdit() != null && edit.getParent().equals(edit.getTargetEdit().getParent())) { org.eclipse.lsp4j.TextEdit te = new org.eclipse.lsp4j.TextEdit(); te.setNewText(""); te.setRange(JDTUtils.toRange(compilationUnit, edit.getOffset(), edit.getLength())); converted.add(te); return false; } } catch (JavaModelException e) { JavaLanguageServerPlugin.logException("Error converting TextEdits", e); } return super.visit(edit); }
@Override void performSourceComputation(TextEditProcessor processor, IDocument document) { try { TextEdit[] children= removeChildren(); if (children.length > 0) { String content= document.get(getOffset(), getLength()); EditDocument subDocument= new EditDocument(content); fSourceRoot= new MultiTextEdit(getOffset(), getLength()); fSourceRoot.addChildren(children); fSourceRoot.internalMoveTree(-getOffset()); int processingStyle= getStyle(processor); TextEditProcessor subProcessor= TextEditProcessor.createSourceComputationProcessor(subDocument, fSourceRoot, processingStyle); subProcessor.performEdits(); if (needsTransformation()) applyTransformation(subDocument, processingStyle); fSourceContent= subDocument.get(); } else { fSourceContent= document.get(getOffset(), getLength()); if (needsTransformation()) { EditDocument subDocument= new EditDocument(fSourceContent); applyTransformation(subDocument, getStyle(processor)); fSourceContent= subDocument.get(); } } } catch (BadLocationException cannotHappen) { Assert.isTrue(false); } }
final TextEdit getCopySourceEdit(CopySourceInfo info) { TextEdit edit= (TextEdit) this.sourceCopyInfoToEdit.get(info); if (edit == null) { SourceRange range= getExtendedRange(info.getNode()); int start= range.getStartPosition(); int end= start + range.getLength(); if (info.isMove) { MoveSourceEdit moveSourceEdit= new MoveSourceEdit(start, end - start); moveSourceEdit.setTargetEdit(new MoveTargetEdit(0)); edit= moveSourceEdit; } else { CopySourceEdit copySourceEdit= new CopySourceEdit(start, end - start); copySourceEdit.setTargetEdit(new CopyTargetEdit(0)); edit= copySourceEdit; } this.sourceCopyInfoToEdit.put(info, edit); } return edit; }
MoveSourceEdit source = new MoveSourceEdit(region.getOffset(), region.getLength()); region = getMoveRegion(node2); source.setTargetEdit(new MoveTargetEdit(region.getOffset())); MoveSourceEdit op = fMoveOperations.get(node1); if (op != null) { } else { op = fMoveOperations.get(node2); if (op != null && op.getTargetEdit().getOffset() == source.getOffset()) { fMoveOperations.remove(node2); ops.remove(op);
translatedTextEdit = new MoveSourceEdit(jspOffset, length); ((MoveSourceEdit) translatedTextEdit).setTargetEdit(((MoveSourceEdit) textEdit).getTargetEdit()); ((MoveTargetEdit) textEdit).getSourceEdit().setTargetEdit((MoveTargetEdit) translatedTextEdit);
@Override void performConsistencyCheck(TextEditProcessor processor, IDocument document) throws MalformedTreeException { if (fSource == null) throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("MoveTargetEdit.no_source")); //$NON-NLS-1$ if (fSource.getTargetEdit() != this) throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("MoveTargetEdit.different_target")); //$NON-NLS-1$ }
private final TextEdit doTextCopy(TextEdit sourceEdit, int destOffset, int sourceIndentLevel, String destIndentString, TextEditGroup editGroup) { TextEdit targetEdit; SourceModifier modifier= new SourceModifier(sourceIndentLevel, destIndentString, this.formatter.getTabWidth(), this.formatter.getIndentWidth()); if (sourceEdit instanceof MoveSourceEdit) { MoveSourceEdit moveEdit= (MoveSourceEdit) sourceEdit; moveEdit.setSourceModifier(modifier); targetEdit= new MoveTargetEdit(destOffset, moveEdit); addEdit(targetEdit); } else { CopySourceEdit copyEdit= (CopySourceEdit) sourceEdit; copyEdit.setSourceModifier(modifier); targetEdit= new CopyTargetEdit(destOffset, copyEdit); addEdit(targetEdit); } if (editGroup != null) { addEditGroup(editGroup, sourceEdit); addEditGroup(editGroup, targetEdit); } return targetEdit; }
@Override public boolean visit(MoveTargetEdit 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); }
@Override void performConsistencyCheck(TextEditProcessor processor, IDocument document) throws MalformedTreeException { if (fTarget == null) throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("MoveSourceEdit.no_target")); //$NON-NLS-1$ if (fTarget.getSourceEdit() != this) throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("MoveSourceEdit.different_source")); //$NON-NLS-1$ /* Causes AST rewrite to fail if (getRoot() != fTarget.getRoot()) throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("MoveSourceEdit.different_tree")); //$NON-NLS-1$ */ }
final TextEdit getCopySourceEdit(CopySourceInfo info) { TextEdit edit= (TextEdit) this.sourceCopyInfoToEdit.get(info); if (edit == null) { SourceRange range= getExtendedRange(info.getNode()); int start= range.getStartPosition(); int end= start + range.getLength(); if (info.isMove) { MoveSourceEdit moveSourceEdit= new MoveSourceEdit(start, end - start); moveSourceEdit.setTargetEdit(new MoveTargetEdit(0)); edit= moveSourceEdit; } else { CopySourceEdit copySourceEdit= new CopySourceEdit(start, end - start); copySourceEdit.setTargetEdit(new CopyTargetEdit(0)); edit= copySourceEdit; } this.sourceCopyInfoToEdit.put(info, edit); } return edit; }
@Override void performSourceComputation(TextEditProcessor processor, IDocument document) { try { TextEdit[] children= removeChildren(); if (children.length > 0) { String content= document.get(getOffset(), getLength()); EditDocument subDocument= new EditDocument(content); fSourceRoot= new MultiTextEdit(getOffset(), getLength()); fSourceRoot.addChildren(children); fSourceRoot.internalMoveTree(-getOffset()); int processingStyle= getStyle(processor); TextEditProcessor subProcessor= TextEditProcessor.createSourceComputationProcessor(subDocument, fSourceRoot, processingStyle); subProcessor.performEdits(); if (needsTransformation()) applyTransformation(subDocument, processingStyle); fSourceContent= subDocument.get(); } else { fSourceContent= document.get(getOffset(), getLength()); if (needsTransformation()) { EditDocument subDocument= new EditDocument(fSourceContent); applyTransformation(subDocument, getStyle(processor)); fSourceContent= subDocument.get(); } } } catch (BadLocationException cannotHappen) { Assert.isTrue(false); } }
@Override void performConsistencyCheck(TextEditProcessor processor, IDocument document) throws MalformedTreeException { if (fSource == null) throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("MoveTargetEdit.no_source")); //$NON-NLS-1$ if (fSource.getTargetEdit() != this) throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("MoveTargetEdit.different_target")); //$NON-NLS-1$ }
private final TextEdit doTextCopy(TextEdit sourceEdit, int destOffset, int sourceIndentLevel, String destIndentString, TextEditGroup editGroup) { TextEdit targetEdit; SourceModifier modifier= new SourceModifier(sourceIndentLevel, destIndentString, this.formatter.getTabWidth(), this.formatter.getIndentWidth()); if (sourceEdit instanceof MoveSourceEdit) { MoveSourceEdit moveEdit= (MoveSourceEdit) sourceEdit; moveEdit.setSourceModifier(modifier); targetEdit= new MoveTargetEdit(destOffset, moveEdit); addEdit(targetEdit); } else { CopySourceEdit copyEdit= (CopySourceEdit) sourceEdit; copyEdit.setSourceModifier(modifier); targetEdit= new CopyTargetEdit(destOffset, copyEdit); addEdit(targetEdit); } if (editGroup != null) { addEditGroup(editGroup, sourceEdit); addEditGroup(editGroup, targetEdit); } return targetEdit; }
@Override void performConsistencyCheck(TextEditProcessor processor, IDocument document) throws MalformedTreeException { if (fTarget == null) throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("MoveSourceEdit.no_target")); //$NON-NLS-1$ if (fTarget.getSourceEdit() != this) throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("MoveSourceEdit.different_source")); //$NON-NLS-1$ /* Causes AST rewrite to fail if (getRoot() != fTarget.getRoot()) throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("MoveSourceEdit.different_tree")); //$NON-NLS-1$ */ }
final TextEdit getCopySourceEdit(CopySourceInfo info) { TextEdit edit= (TextEdit) this.sourceCopyInfoToEdit.get(info); if (edit == null) { SourceRange range= getExtendedRange(info.getNode()); int start= range.getStartPosition(); int end= start + range.getLength(); if (info.isMove) { MoveSourceEdit moveSourceEdit= new MoveSourceEdit(start, end - start); moveSourceEdit.setTargetEdit(new MoveTargetEdit(0)); edit= moveSourceEdit; } else { CopySourceEdit copySourceEdit= new CopySourceEdit(start, end - start); copySourceEdit.setTargetEdit(new CopyTargetEdit(0)); edit= copySourceEdit; } this.sourceCopyInfoToEdit.put(info, edit); } return edit; }
@Override protected TextEdit doCopy() { return new MoveSourceEdit(this); }