Java Code Examples for org.eclipse.text.edits.TextEdit#hasChildren()
The following examples show how to use
org.eclipse.text.edits.TextEdit#hasChildren() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextEditUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Returns true if the given <code>edit</code> is minimal. * <p> * That is if: * <ul> * <li><b>true</b> if <code>edit</code> is a leaf</li> * <li>if <code>edit</code> is a inner node then <b>true</b> if * <ul> * <li><code>edit</code> has same size as all its children</li> * <li><code>isPacked</code> is <b>true</b> for all children</li> * </ul> * </li> * </ul> * </p> * * @param edit the edit to verify * @return true if edit is minimal * @since 3.4 */ public static boolean isPacked(TextEdit edit) { if (!(edit instanceof MultiTextEdit)) return true; if (!edit.hasChildren()) return true; TextEdit[] children= edit.getChildren(); if (edit.getOffset() != children[0].getOffset()) return false; if (edit.getExclusiveEnd() != children[children.length - 1].getExclusiveEnd()) return false; for (int i= 0; i < children.length; i++) { if (!isPacked(children[i])) return false; } return true; }
Example 2
Source File: TextEditUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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); } } }
Example 3
Source File: TextEditUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * 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; }
Example 4
Source File: TextEditUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 4 votes |
/** * Removes a text edit from a group, optionally updating its owner change. If * the edit is the root edit of the owner change, the change will be removed * from its parent. * * @param edit the text edit * @param group the text edit group to update, optional * @param change the change to update, optional * @return true if the text edit was removed */ public static boolean removeTextEdit(TextEdit edit, TextEditGroup group, TextEditBasedChange change) { boolean removed = false; boolean removeChange = false; // First remove this edit from its parent, if it has one TextEdit parentEdit = edit.getParent(); if (parentEdit != null) { removed |= parentEdit.removeChild(edit); if (!parentEdit.hasChildren()) { // This parent edit is now empty, so remove it from the change and group edit = parentEdit; } } // Remove the edit from the group if (group != null) { removed |= group.removeTextEdit(edit); if (group.getTextEdits().length == 0) { // The group has no more edits. We'd like to remove it from the change, // but there is no API. Instead, see if this group is the only group in // the change and trigger removing the change altogether. if (change != null) { TextEditBasedChangeGroup[] changeGroups = change.getChangeGroups(); if (changeGroups.length == 1 && changeGroups[0].getTextEditGroup().equals(group)) { // This is the only group in the change, remove the change removeChange = true; } } } } // Remove the change if this was its root edit if (!removeChange && change != null && change instanceof TextFileChange) { TextFileChange textFileChange = (TextFileChange) change; if (edit.equals(textFileChange.getEdit())) { removeChange = true; } } // Execute change removal if (removeChange && change != null) { Change parentChange = change.getParent(); if (parentChange instanceof CompositeChange) { removed |= ((CompositeChange) parentChange).remove(change); } } return removed; }
Example 5
Source File: CompilationUnitRewrite.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private static boolean isEmptyEdit(TextEdit edit) { return edit.getClass() == MultiTextEdit.class && ! edit.hasChildren(); }