@Override
  public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
    if (pm.isCanceled()) {
      return null;
    }
    if (!getArguments().getUpdateReferences()) {
      return null;
    }
    CompositeChange result = new CompositeChange(getName());
    result.markAsSynthetic();

    addManifestFileChanges(result);

    // Update layout files; we don't just need to react to custom view
    // changes, we need to update fragment references and even tool:context activity
    // references
    addLayoutFileChanges(mProject, result);

    // Also update in dependent projects
    ProjectState projectState = Sdk.getProjectState(mProject);
    if (projectState != null) {
      Collection<ProjectState> parentProjects = projectState.getFullParentProjects();
      for (ProjectState parentProject : parentProjects) {
        IProject project = parentProject.getProject();
        addLayoutFileChanges(project, result);
      }
    }

    return (result.getChildren().length == 0) ? null : result;
  }
 /**
  * Merges the children of the given composite change into this change. This means the changes are
  * removed from the given composite change and added to this change.
  *
  * @param change the change to merge
  */
 public void merge(CompositeChange change) {
   Change[] others = change.getChildren();
   for (int i = 0; i < others.length; i++) {
     Change other = others[i];
     change.remove(other);
     add(other);
   }
 }
示例#3
0
 public void test_toLTK_Change_CompositeChange_noFile() throws Exception {
   Source source = new FileBasedSource(new File("no-such-file.dart"));
   SourceChange sourceChangeA = new SourceChange("My change A", source);
   SourceChange sourceChangeB = new SourceChange("My change B", source);
   CompositeChange compositeChange =
       new CompositeChange("My composite change", sourceChangeA, sourceChangeB);
   // toLTK
   org.eclipse.ltk.core.refactoring.Change ltkChange_ = ServiceUtils.toLTK(compositeChange);
   org.eclipse.ltk.core.refactoring.CompositeChange ltkChange =
       (org.eclipse.ltk.core.refactoring.CompositeChange) ltkChange_;
   assertEquals("My composite change", ltkChange.getName());
   org.eclipse.ltk.core.refactoring.Change[] ltkChanges = ltkChange.getChildren();
   assertThat(ltkChanges).isEmpty();
 }
示例#4
0
 public void test_toLTK_Change_CompositeChange() throws Exception {
   Source source = createTestFileSource();
   // fill SourceChange
   SourceChange sourceChangeA = new SourceChange("My change A", source);
   SourceChange sourceChangeB = new SourceChange("My change B", source);
   CompositeChange compositeChange =
       new CompositeChange("My composite change", sourceChangeA, sourceChangeB);
   // toLTK
   org.eclipse.ltk.core.refactoring.Change ltkChange_ = ServiceUtils.toLTK(compositeChange);
   org.eclipse.ltk.core.refactoring.CompositeChange ltkChange =
       (org.eclipse.ltk.core.refactoring.CompositeChange) ltkChange_;
   assertEquals("My composite change", ltkChange.getName());
   org.eclipse.ltk.core.refactoring.Change[] ltkChanges = ltkChange.getChildren();
   assertThat(ltkChanges).hasSize(2);
 }
示例#5
0
 @Override
 void createChange(final IProgressMonitor pm, final CompositeChange rootChange) {
   try {
     pm.beginTask(UITexts.mkPointFreeDelegate_collectingChanges, 100);
     if (change == null) {
       throw new IllegalStateException();
     }
     // do not have the intermediate step
     for (Change c : change.getChildren()) {
       change.remove(c);
       rootChange.add(c);
     }
     // rootChange.add( change );
   } finally {
     pm.done();
   }
 }
示例#6
0
 public void test_toLTK_Change_MergeCompositeChange_emptyPreview() throws Exception {
   IFile testFile = testProject.setFileContent("test.dart", "012345");
   Source source = createFileSource(testFile);
   // fill SourceChange
   SourceChange sourceChangeB = new SourceChange("My change B", source);
   sourceChangeB.addEdit(new Edit(2, 0, "b"));
   CompositeChange compositeChangeA = new CompositeChange("A");
   CompositeChange compositeChangeB = new CompositeChange("B", sourceChangeB);
   MergeCompositeChange mergeChange =
       new MergeCompositeChange("My composite change", compositeChangeA, compositeChangeB);
   // toLTK
   org.eclipse.ltk.core.refactoring.Change ltkChange_ = ServiceUtils.toLTK(mergeChange);
   org.eclipse.ltk.core.refactoring.CompositeChange ltkChange =
       (org.eclipse.ltk.core.refactoring.CompositeChange) ltkChange_;
   assertEquals("My composite change", ltkChange.getName());
   org.eclipse.ltk.core.refactoring.Change[] ltkChanges = ltkChange.getChildren();
   assertThat(ltkChanges).hasSize(1);
   assertThat(ltkChanges[0]).isInstanceOf(CompilationUnitChange.class);
 }
示例#7
0
 public void test_toLTK_Change_SourceChange_externalFile() throws Exception {
   FileBasedSource source = new FileBasedSource(FileUtilities2.createFile("/some/path"));
   // fill SourceChange
   SourceChange sourceChange = new SourceChange("My change", source);
   sourceChange.addEdit(new Edit(10, 1, "a"));
   sourceChange.addEdit(new Edit(20, 2, "b"));
   // no IFile for this Source, so no LTK change
   {
     org.eclipse.ltk.core.refactoring.Change ltkChange = ServiceUtils.toLTK(sourceChange);
     assertNull(ltkChange);
   }
   // try as part of CompositeChange
   {
     CompositeChange compositeChange = new CompositeChange("My composite change", sourceChange);
     org.eclipse.ltk.core.refactoring.CompositeChange ltkChange =
         ServiceUtils.toLTK(compositeChange);
     assertNotNull(ltkChange);
     // wrong SourceChange was ignored
     assertThat(ltkChange.getChildren()).isEmpty();
   }
 }
示例#8
0
 public void test_toLTK_Change_MergeCompositeChange() throws Exception {
   IFile testFile = testProject.setFileContent("test.dart", "012345");
   Source source = createFileSource(testFile);
   // fill SourceChange
   SourceChange sourceChangeA = new SourceChange("My change A", source);
   SourceChange sourceChangeB = new SourceChange("My change B", source);
   sourceChangeA.addEdit(new Edit(0, 0, "a"));
   sourceChangeB.addEdit(new Edit(2, 0, "b"));
   CompositeChange compositeChangeA = new CompositeChange("A", sourceChangeA);
   CompositeChange compositeChangeB = new CompositeChange("B", sourceChangeB);
   MergeCompositeChange mergeChange =
       new MergeCompositeChange("My composite change", compositeChangeA, compositeChangeB);
   // toLTK
   org.eclipse.ltk.core.refactoring.Change ltkChange_ = ServiceUtils.toLTK(mergeChange);
   org.eclipse.ltk.core.refactoring.CompositeChange ltkChange =
       (org.eclipse.ltk.core.refactoring.CompositeChange) ltkChange_;
   assertEquals("My composite change", ltkChange.getName());
   org.eclipse.ltk.core.refactoring.Change[] ltkChanges = ltkChange.getChildren();
   assertThat(ltkChanges).hasSize(2);
   //
   ltkChange.perform(NULL_PM);
   String newContent = testProject.getFileString(testFile);
   assertEquals("a01b2345", newContent);
 }