Java Code Examples for org.eclipse.ltk.core.refactoring.TextChange#addEdit()

The following examples show how to use org.eclipse.ltk.core.refactoring.TextChange#addEdit() . 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: TextEditUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Moves the given text edit groups (and its text edits) into the given
 * change.
 */
public static void moveTextEditGroupsIntoChange(
    TextEditBasedChangeGroup[] groups, TextChange textChange) {
  for (TextEditBasedChangeGroup changeGroup : groups) {
    TextEditGroup group = changeGroup.getTextEditGroup();
    for (TextEdit edit : group.getTextEdits()) {
      if (edit.getParent() != null) {
        edit.getParent().removeChild(edit);
      }

      textChange.addEdit(edit);
    }

    // We must create a new change group since it doesn't have API to change
    // the parent change
    TextEditBasedChangeGroup newChangeGroup = new TextEditBasedChangeGroup(
        textChange, group);
    newChangeGroup.setEnabled(changeGroup.isEnabled());
    textChange.addChangeGroup(newChangeGroup);
  }
}
 
Example 2
Source File: AccessorClassModifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static Change addFields(ICompilationUnit cu, List<String> fields) throws CoreException {
	AccessorClassModifier sourceModification= new AccessorClassModifier(cu);
	String message= Messages.format(NLSMessages.AccessorClassModifier_add_fields_to_accessor, BasicElementLabels.getFileName(cu));

	TextChange change= new CompilationUnitChange(message, cu);
	MultiTextEdit multiTextEdit= new MultiTextEdit();
	change.setEdit(multiTextEdit);

	for (int i= 0; i < fields.size(); i++) {
		String field= fields.get(i);
		NLSSubstitution substitution= new NLSSubstitution(NLSSubstitution.EXTERNALIZED, field, null, null, null);
		sourceModification.addKey(substitution, change);
	}

	if (change.getChangeGroups().length == 0)
		return null;

	change.addEdit(sourceModification.getTextEdit());

	return change;
}
 
Example 3
Source File: AccessorClassModifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static Change removeFields(ICompilationUnit cu, List<String> fields) throws CoreException {
	AccessorClassModifier sourceModification= new AccessorClassModifier(cu);
	String message= Messages.format(NLSMessages.AccessorClassModifier_remove_fields_from_accessor, BasicElementLabels.getFileName(cu));

	TextChange change= new CompilationUnitChange(message, cu);
	MultiTextEdit multiTextEdit= new MultiTextEdit();
	change.setEdit(multiTextEdit);

	for (int i= 0; i < fields.size(); i++) {
		String field= fields.get(i);
		NLSSubstitution substitution= new NLSSubstitution(NLSSubstitution.EXTERNALIZED, field, null, null, null);
		sourceModification.removeKey(substitution, change);
	}

	if (change.getChangeGroups().length == 0)
		return null;

	change.addEdit(sourceModification.getTextEdit());

	return change;
}