Java Code Examples for org.eclipse.ltk.core.refactoring.CompositeChange#getChildren()
The following examples show how to use
org.eclipse.ltk.core.refactoring.CompositeChange#getChildren() .
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: TextChangeCombiner.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
public Change combineChanges(Change masterChange) { if (!(masterChange instanceof CompositeChange)) return masterChange; Map<Object, TextChange> resource2textChange = newLinkedHashMap(); List<Change> otherChanges = newArrayList(); Set<IEditorPart> editorsToSave = newHashSet(); visitCompositeChange((CompositeChange) masterChange, resource2textChange, otherChanges, editorsToSave); CompositeChange compositeChange = new FilteringCompositeChange(masterChange.getName()); for (TextChange combinedTextChange : resource2textChange.values()) { if(((MultiTextEdit) combinedTextChange.getEdit()).getChildrenSize() >0) { if(combinedTextChange instanceof EditorDocumentChange) { ((EditorDocumentChange) combinedTextChange).setDoSave(editorsToSave.contains(((EditorDocumentChange) combinedTextChange).getEditor())); compositeChange.add(combinedTextChange); } else compositeChange.add(DisplayChangeWrapper.wrap(combinedTextChange)); } } for(Change otherChange: otherChanges) compositeChange.add(DisplayChangeWrapper.wrap(otherChange)); if(compositeChange.getChildren().length == 0) return null; return compositeChange; }
Example 2
Source File: GWTRefactoringSupportTest.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
public void testCreateChange() { GWTRefactoringSupport support = new DummyGWTRefactoringSupport(); support.setUpdateReferences(true); IType refactorTestType = refactorTestClass.getCompilationUnit().findPrimaryType(); support.setOldElement(refactorTestType); RefactoringParticipant participant = new DummyRefactoringParticipant(); IRefactoringChangeFactory changeFactory = new DefaultChangeFactory(); CompositeChange change = support.createChange(participant, changeFactory); // Return value should contain one child change Change[] changeChildren = change.getChildren(); assertEquals(1, changeChildren.length); // Root edit should contain two child edits, one for each JSNI ref TextChange childChange = (TextChange) changeChildren[0]; TextEdit changeEdit = childChange.getEdit(); assertEquals(2, changeEdit.getChildrenSize()); }
Example 3
Source File: ChangeUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * 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 4
Source File: ChangeUtil.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private static void convertCompositeChange(CompositeChange change, WorkspaceEdit edit) throws CoreException { Change[] changes = change.getChildren(); for (Change ch : changes) { if (ch instanceof CompositeChange) { convertCompositeChange((CompositeChange) ch, edit); } else { convertSingleChange(ch, edit); } } }
Example 5
Source File: ChangeUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * Visits the given change and all its descendents. */ public static void acceptOnChange(Change change, ChangeVisitor visitor) { if (change instanceof CompositeChange) { CompositeChange compositeChange = (CompositeChange) change; for (Change curChange : compositeChange.getChildren()) { acceptOnChange(curChange, visitor); } } visitor.visit(change); }
Example 6
Source File: ChangeUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * 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 7
Source File: PairedMethodRenameParticipant.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
private Change createChangeFromMethodsToRefactor() { CompositeChange changes = new CompositeChange( "GWT RPC paired method renames"); changes.markAsSynthetic(); // Traverse the methods to refactor and create a rename change for each // Note: due to the recursive nature, this List could grow through each // iteration while (refactoringContext.toRefactorMethods.size() > 0) { IMethod method = refactoringContext.toRefactorMethods.remove(0); try { // Call to JDT to get a change that renames this method Change change = createChangeForMethodRename(method); if (change != null) { if (ChangeUtilities.mergeParticipantTextChanges(this, change)) { // This change was completely merged into existing changes continue; } // Walk through the created change tree and weave a change that, at // perform-time, will update the text regions ChangeUtilities.acceptOnChange(change, new RegionUpdaterChangeWeavingVisitor( new RenamedElementAstMatcher(pairedMethod.getElementName(), newMethodName), new ReferenceUpdater())); changes.add(change); } } catch (RefactoringException e) { GWTPluginLog.logError("Could not rename method " + method); // TODO: warn } } return (changes.getChildren().length > 0) ? changes : null; }
Example 8
Source File: CleanUpRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void findFilesToBeModified(CompositeChange change, List<IResource> result) throws JavaModelException { Change[] children= change.getChildren(); for (int i= 0; i < children.length; i++) { Change child= children[i]; if (child instanceof CompositeChange) { findFilesToBeModified((CompositeChange)child, result); } else if (child instanceof MultiStateCompilationUnitChange) { result.add(((MultiStateCompilationUnitChange)child).getCompilationUnit().getCorrespondingResource()); } else if (child instanceof CompilationUnitChange) { result.add(((CompilationUnitChange)child).getCompilationUnit().getCorrespondingResource()); } } }
Example 9
Source File: TextChangeCombiner.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
protected void visitCompositeChange(CompositeChange sourceChange, Map<Object, TextChange> resource2textChange, List<Change> otherChanges, Set<IEditorPart> editorsToSave) { for (Change sourceSubChange : sourceChange.getChildren()) { visitChange(sourceSubChange, resource2textChange, otherChanges, editorsToSave); } }