Java Code Examples for org.eclipse.ltk.core.refactoring.CompositeChange#remove()

The following examples show how to use org.eclipse.ltk.core.refactoring.CompositeChange#remove() . 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: RenamePackageProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Change postCreateChange(Change[] participantChanges, IProgressMonitor pm) throws CoreException {
	if (fQualifiedNameSearchResult != null) {
		CompositeChange parent= (CompositeChange) fRenamePackageChange.getParent();
		try {
			/*
			 * Sneak text changes in before the package rename to ensure
			 * modified files are still at original location (see
			 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=154238)
			 */
			parent.remove(fRenamePackageChange);
			parent.add(fQualifiedNameSearchResult.getSingleChange(Changes.getModifiedFiles(participantChanges)));
		} finally {
			fQualifiedNameSearchResult= null;
			parent.add(fRenamePackageChange);
			fRenamePackageChange= null;
		}
	}
	return null;
}
 
Example 2
Source File: ChangeUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Inserts a change at the specified index.
 * 
 * @param change the change to insert
 * @param insertIndex the index to insert at (if >= the number of children, it
 *          will be added to the end)
 * @param parentChange the new parent of the change
 */
public static void insertChange(Change change, int insertIndex,
    CompositeChange parentChange) {
  Change[] changes = parentChange.getChildren();

  if (insertIndex >= changes.length) {
    parentChange.add(change);
  } else {
    // CompositeChange.clear does not clear the parent field on the removed
    // changes, but CompositeChange.remove does
    for (Change curChange : changes) {
      parentChange.remove(curChange);
    }

    for (int i = 0; i < changes.length; i++) {
      if (i == insertIndex) {
        parentChange.add(change);
      }
      parentChange.add(changes[i]);
    }
  }
}
 
Example 3
Source File: RenamePackageProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Change postCreateChange(Change[] participantChanges, IProgressMonitor pm) throws CoreException {
	if (fQualifiedNameSearchResult != null) {
		CompositeChange parent= (CompositeChange) fRenamePackageChange.getParent();
		try {
			/*
			 * Sneak text changes in before the package rename to ensure
			 * modified files are still at original location (see
			 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=154238)
			 */
			parent.remove(fRenamePackageChange);
			parent.add(fQualifiedNameSearchResult.getSingleChange(Changes.getModifiedFiles(participantChanges)));
		} finally {
			fQualifiedNameSearchResult= null;
			parent.add(fRenamePackageChange);
			fRenamePackageChange= null;
		}
	}
	return null;
}
 
Example 4
Source File: TextChangeCombiner.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void visitChange(Change sourceChange, Map<Object, TextChange> resource2textChange, List<Change> otherChanges, Set<IEditorPart> editorsToSave) {
	if (sourceChange instanceof DisplayChangeWrapper.Wrapper) 
		visitChange(((DisplayChangeWrapper.Wrapper) sourceChange).getDelegate(), resource2textChange, otherChanges, editorsToSave);
	else if (sourceChange instanceof CompositeChange) {
		visitCompositeChange((CompositeChange) sourceChange, resource2textChange, otherChanges, editorsToSave);
	} else if (sourceChange instanceof TextChange) {
		if (sourceChange instanceof EditorDocumentChange) 
			editorsToSave.add(((EditorDocumentChange) sourceChange).getEditor());
		Object key = getKey((TextChange) sourceChange);
		if (key != null) {
			TextChange textChange = resource2textChange.get(key);
			if (textChange == null) {
				textChange = createTextChange(key, ((TextChange) sourceChange).getTextType());
				resource2textChange.put(key, textChange);
			}
			MultiTextEdit combinedEdits = (MultiTextEdit) textChange.getEdit();
			TextEdit newEdit = ((TextChange) sourceChange).getEdit().copy();
			if (newEdit instanceof MultiTextEdit) {
				for (TextEdit newTextEdit : ((MultiTextEdit) newEdit).getChildren()) {
					addIfNotDuplicate(combinedEdits, newTextEdit);
				}
			} else {
				addIfNotDuplicate(combinedEdits, newEdit);
			}
		}
	} else {
		CompositeChange parent = (CompositeChange) sourceChange.getParent();
		if(parent != null)
			parent.remove(sourceChange);
		otherChanges.add(sourceChange);
	}
}
 
Example 5
Source File: ChangeUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Removes a change and returns its old index, or -1 if it was not found.
 */
public static int removeChange(Change change, CompositeChange parentChange) {
  Change[] changes = parentChange.getChildren();
  for (int index = 0; index < changes.length; index++) {
    if (changes[index] == change) {
      parentChange.remove(change);
      return index;
    }
  }

  return -1;
}
 
Example 6
Source File: RenameRefactoringProcessor.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
private void unregisterChangeAtParent(Change change) {
	if (change != null) {
		CompositeChange parent = change2Parent.remove(change);
		parent.remove(change);
	}
}