private static boolean isEmptyEdit(TextEdit edit) { return edit.getClass() == MultiTextEdit.class && ! edit.hasChildren(); }
private static boolean isEmptyEdit(TextEdit edit) { return edit.getClass() == MultiTextEdit.class && ! edit.hasChildren(); }
private static boolean isEmptyEdit(TextEdit edit) { return edit.getClass() == MultiTextEdit.class && ! edit.hasChildren(); }
/** * Create an edit which contains <code>edit1</code> and <code>edit2</code> * <p>If <code>edit1</code> overlaps <code>edit2</code> this method fails with a {@link MalformedTreeException}</p> * <p><strong>The given edits are modified and they can no longer be used.</strong></p> * * @param edit1 the edit to merge with edit2 * @param edit2 the edit to merge with edit1 * @return the merged tree * @throws MalformedTreeException if {@link #overlaps(TextEdit, TextEdit)} returns <b>true</b> * @see #overlaps(TextEdit, TextEdit) * @since 3.4 */ public static TextEdit merge(TextEdit edit1, TextEdit edit2) { if (edit1 instanceof MultiTextEdit && !edit1.hasChildren()) { return edit2; } if (edit2 instanceof MultiTextEdit && !edit2.hasChildren()) { return edit1; } MultiTextEdit result= new MultiTextEdit(); merge(edit1, edit2, result); return result; }
/** * Create an edit which contains <code>edit1</code> and <code>edit2</code> * <p>If <code>edit1</code> overlaps <code>edit2</code> this method fails with a {@link MalformedTreeException}</p> * <p><strong>The given edits are modified and they can no longer be used.</strong></p> * * @param edit1 the edit to merge with edit2 * @param edit2 the edit to merge with edit1 * @return the merged tree * @throws MalformedTreeException if {@link #overlaps(TextEdit, TextEdit)} returns <b>true</b> * @see #overlaps(TextEdit, TextEdit) * @since 3.4 */ public static TextEdit merge(TextEdit edit1, TextEdit edit2) { if (edit1 instanceof MultiTextEdit && !edit1.hasChildren()) { return edit2; } if (edit2 instanceof MultiTextEdit && !edit2.hasChildren()) { return edit1; } MultiTextEdit result= new MultiTextEdit(); merge(edit1, edit2, result); return result; }
public static void formatUnitSourceCode(ICompilationUnit unit, IProgressMonitor monitor) throws JavaModelException { CodeFormatter formatter = ToolFactory.createCodeFormatter(null); ISourceRange range = unit.getSourceRange(); TextEdit formatEdit = formatter.format(CodeFormatter.K_COMPILATION_UNIT, unit.getSource(), range.getOffset(), range.getLength(), 0, null); if (formatEdit != null && formatEdit.hasChildren()) { unit.applyTextEdit(formatEdit, monitor); } else { monitor.done(); } }
private static void flatten(TextEdit edit, MultiTextEdit result) { if (!edit.hasChildren()) { result.addChild(edit); } else { TextEdit[] children= edit.getChildren(); for (int i= 0; i < children.length; i++) { TextEdit child= children[i]; child.getParent().removeChild(0); flatten(child, result); } } }
private static void flatten(TextEdit edit, MultiTextEdit result) { if (!edit.hasChildren()) { result.addChild(edit); } else { TextEdit[] children= edit.getChildren(); for (int i= 0; i < children.length; i++) { TextEdit child= children[i]; child.getParent().removeChild(0); flatten(child, result); } } }
/** * Convenience method that applies the edit returned from {@link #replace(ISelection, String)} * to the underlying document and adapts the selection accordingly. * * @param selection the selection to replace * @param replacement the replacement text * @throws BadLocationException if accessing the document failed */ public void doReplace(ISelection selection, String replacement) throws BadLocationException { TextEdit edit= replace(selection, replacement); boolean complex= edit.hasChildren(); if (complex && fRewriteTarget != null) fRewriteTarget.beginCompoundChange(); try { edit.apply(fDocument, TextEdit.UPDATE_REGIONS); if (fSelectionProvider != null) { ISelection empty= makeReplaceSelection(selection, replacement); fSelectionProvider.setSelection(empty); } } finally { if (complex && fRewriteTarget != null) fRewriteTarget.endCompoundChange(); } }
/** * Convenience method that applies the edit returned from {@link #replace(ISelection, String)} * to the underlying document and adapts the selection accordingly. * * @param selection the selection to replace * @param replacement the replacement text * @throws BadLocationException if accessing the document failed */ public void doReplace(ISelection selection, String replacement) throws BadLocationException { TextEdit edit= replace(selection, replacement); boolean complex= edit.hasChildren(); if (complex && fRewriteTarget != null) fRewriteTarget.beginCompoundChange(); try { edit.apply(fDocument, TextEdit.UPDATE_REGIONS); if (fSelectionProvider != null) { ISelection empty= makeReplaceSelection(selection, replacement); fSelectionProvider.setSelection(empty); } } finally { if (complex && fRewriteTarget != null) fRewriteTarget.endCompoundChange(); } }
/** * Convenience method that applies the edit returned from {@link #delete(ISelection)} to the * underlying document. * * @param selection the selection to delete * @throws BadLocationException if accessing the document failed */ public void doDelete(ISelection selection) throws BadLocationException { TextEdit edit= delete(selection); boolean complex= edit.hasChildren(); if (complex && fRewriteTarget != null) fRewriteTarget.beginCompoundChange(); try { edit.apply(fDocument, TextEdit.UPDATE_REGIONS); if (fSelectionProvider != null) { ISelection empty= makeEmpty(selection, true); fSelectionProvider.setSelection(empty); } } finally { if (complex && fRewriteTarget != null) fRewriteTarget.endCompoundChange(); } }
/** * Convenience method that applies the edit returned from {@link #delete(ISelection)} to the * underlying document. * * @param selection the selection to delete * @throws BadLocationException if accessing the document failed */ public void doDelete(ISelection selection) throws BadLocationException { TextEdit edit= delete(selection); boolean complex= edit.hasChildren(); if (complex && fRewriteTarget != null) fRewriteTarget.beginCompoundChange(); try { edit.apply(fDocument, TextEdit.UPDATE_REGIONS); if (fSelectionProvider != null) { ISelection empty= makeEmpty(selection, true); fSelectionProvider.setSelection(empty); } } finally { if (complex && fRewriteTarget != null) fRewriteTarget.endCompoundChange(); } }
public static void insert(TextEdit parent, TextEdit edit) { if (!parent.hasChildren()) { parent.addChild(edit); return; } TextEdit[] children= parent.getChildren(); // First dive down to find the right parent. for (int i= 0; i < children.length; i++) { TextEdit child= children[i]; if (covers(child, edit)) { insert(child, edit); return; } } // We have the right parent. Now check if some of the children have to // be moved under the new edit since it is covering it. for (int i= children.length - 1; i >= 0; i--) { TextEdit child= children[i]; if (covers(edit, child)) { parent.removeChild(i); edit.addChild(child); } } parent.addChild(edit); }
private static void insert(TextEdit parent, ReplaceEdit edit, List<ReplaceEdit> edits) { if (!parent.hasChildren()) { parent.addChild(edit); return; } TextEdit[] children= parent.getChildren(); // First dive down to find the right parent. int removed= 0; for (int i= 0; i < children.length; i++) { TextEdit child= children[i]; if (child.covers(edit)) { insert(child, edit, edits); return; } else if (edit.covers(child)) { parent.removeChild(i - removed++); edit.addChild(child); } else { IRegion intersect= intersect(edit, child); if (intersect != null) { ReplaceEdit[] splits= splitEdit(edit, intersect); insert(child, splits[0], edits); edits.add(splits[1]); return; } } } parent.addChild(edit); }
public static void insert(TextEdit parent, TextEdit edit) { if (!parent.hasChildren()) { parent.addChild(edit); return; } TextEdit[] children= parent.getChildren(); // First dive down to find the right parent. for (int i= 0; i < children.length; i++) { TextEdit child= children[i]; if (covers(child, edit)) { insert(child, edit); return; } } // We have the right parent. Now check if some of the children have to // be moved under the new edit since it is covering it. for (int i= children.length - 1; i >= 0; i--) { TextEdit child= children[i]; if (covers(edit, child)) { parent.removeChild(i); edit.addChild(child); } } parent.addChild(edit); }
public static void insert(TextEdit parent, TextEdit edit) throws MalformedTreeException { if (!parent.hasChildren()) { parent.addChild(edit); return; } TextEdit[] children= parent.getChildren(); // First dive down to find the right parent. for (int i= 0; i < children.length; i++) { TextEdit child= children[i]; if (covers(child, edit)) { insert(child, edit); return; } } // We have the right parent. Now check if some of the children have to // be moved under the new edit since it is covering it. int removed= 0; for (int i= 0; i < children.length; i++) { TextEdit child= children[i]; if (covers(edit, child)) { parent.removeChild(i - removed++); edit.addChild(child); } } parent.addChild(edit); }
public static void insert(TextEdit parent, TextEdit edit) { if (!parent.hasChildren()) { parent.addChild(edit); return; } TextEdit[] children= parent.getChildren(); // First dive down to find the right parent. for (int i= 0; i < children.length; i++) { TextEdit child= children[i]; if (covers(child, edit)) { insert(child, edit); return; } } // We have the right parent. Now check if some of the children have to // be moved under the new edit since it is covering it. for (int i= children.length - 1; i >= 0; i--) { TextEdit child= children[i]; if (covers(edit, child)) { parent.removeChild(i); edit.addChild(child); } } parent.addChild(edit); }
return null; if (!edit.hasChildren()) return null;
protected static void insert(TextEdit parent, TextEdit edit) { if (!parent.hasChildren()) { parent.addChild(edit); if (edit instanceof MoveSourceEdit) {
@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); } }