@Override protected TextEdit doCopy() { return new CopyTargetEdit(this); }
@Override public boolean visit(CopyTargetEdit edit) { manageCopy(new InsertEdit(edit.getOffset(), edit.getSourceEdit().getContent())); return true; } @Override
@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); }
translatedTextEdit = new CopyTargetEdit(jspOffset); ((CopyTargetEdit) textEdit).getSourceEdit().setTargetEdit((CopyTargetEdit) translatedTextEdit);
@Override void performConsistencyCheck(TextEditProcessor processor, IDocument document) throws MalformedTreeException { if (fTarget == null) throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("CopySourceEdit.no_target")); //$NON-NLS-1$ if (fTarget.getSourceEdit() != this) throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("CopySourceEdit.different_source")); //$NON-NLS-1$ /* causes ASTRewrite to fail if (getRoot() != fTarget.getRoot()) throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("CopySourceEdit.different_tree")); //$NON-NLS-1$ */ }
/** * Constructs an new copy target edit * * @param offset the edit's offset * @param source the corresponding source edit */ public CopyTargetEdit(int offset, CopySourceEdit source) { this(offset); setSourceEdit(source); }
@Override public boolean visit(CopyTargetEdit edit) { fSize += edit.getLength(); return super.visit(edit); }
@Override void performConsistencyCheck(TextEditProcessor processor, IDocument document) throws MalformedTreeException { if (fSource == null) throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("CopyTargetEdit.no_source")); //$NON-NLS-1$ if (fSource.getTargetEdit() != this) throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("CopyTargetEdit.different_target")); //$NON-NLS-1$ }
@Override protected void accept0(TextEditVisitor visitor) { boolean visitChildren= visitor.visit(this); if (visitChildren) { acceptChildren(visitor); } }
@Override void performConsistencyCheck(TextEditProcessor processor, IDocument document) throws MalformedTreeException { if (fTarget == null) throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("CopySourceEdit.no_target")); //$NON-NLS-1$ if (fTarget.getSourceEdit() != this) throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("CopySourceEdit.different_source")); //$NON-NLS-1$ /* causes ASTRewrite to fail if (getRoot() != fTarget.getRoot()) throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("CopySourceEdit.different_tree")); //$NON-NLS-1$ */ }
/** * Constructs an new copy target edit * * @param offset the edit's offset * @param source the corresponding source edit */ public CopyTargetEdit(int offset, CopySourceEdit source) { this(offset); setSourceEdit(source); }
@Override public boolean visit(CopyTargetEdit edit) { fSize += edit.getLength(); return super.visit(edit); }
@Override void performConsistencyCheck(TextEditProcessor processor, IDocument document) throws MalformedTreeException { if (fSource == null) throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("CopyTargetEdit.no_source")); //$NON-NLS-1$ if (fSource.getTargetEdit() != this) throw new MalformedTreeException(getParent(), this, TextEditMessages.getString("CopyTargetEdit.different_target")); //$NON-NLS-1$ }
@Override protected void accept0(TextEditVisitor visitor) { boolean visitChildren= visitor.visit(this); if (visitChildren) { acceptChildren(visitor); } }
@Override protected TextEdit doCopy() { return new CopyTargetEdit(this); }
@Override public boolean visit(CopyTargetEdit edit) { manageCopy(new InsertEdit(edit.getOffset(), edit.getSourceEdit().getContent())); return true; } @Override
/** * Sets the target edit. * * @param edit the new target edit. * * @exception MalformedTreeException is thrown if the target edit * is a direct or indirect child of the source edit */ public void setTargetEdit(CopyTargetEdit edit) throws MalformedTreeException { Assert.isNotNull(edit); if (fTarget != edit) { fTarget= edit; fTarget.setSourceEdit(this); } }
/** * Sets the source edit. * * @param edit the source edit * * @exception MalformedTreeException is thrown if the target edit * is a direct or indirect child of the source edit */ public void setSourceEdit(CopySourceEdit edit) throws MalformedTreeException { Assert.isNotNull(edit); if (fSource != edit) { fSource= edit; fSource.setTargetEdit(this); TextEdit parent= getParent(); while (parent != null) { if (parent == fSource) throw new MalformedTreeException(parent, this, TextEditMessages.getString("CopyTargetEdit.wrong_parent")); //$NON-NLS-1$ parent= parent.getParent(); } } }