示例#1
0
 public void test_toUI_LinkedCorrectionProposal() throws Exception {
   Source source = createTestFileSource();
   // fill SourceChange
   SourceChange sourceChange = new SourceChange("My linked change", source);
   sourceChange.addEdit(new Edit(10, 1, "a"));
   sourceChange.addEdit(new Edit(20, 1, "a"));
   sourceChange.addEdit(new Edit(30, 3, "b"));
   // create SourceCorrectionProposal
   SourceCorrectionProposal proposal =
       new SourceCorrectionProposal(sourceChange, CorrectionKind.QA_ADD_TYPE_ANNOTATION);
   {
     List<SourceRange> ranges = ImmutableList.of(new SourceRange(10, 1), new SourceRange(20, 1));
     Map<String, List<SourceRange>> linkedPositons = ImmutableMap.of("a", ranges);
     proposal.setLinkedPositions(linkedPositons);
   }
   {
     List<LinkedPositionProposal> proposals =
         ImmutableList.of(
             new LinkedPositionProposal(CorrectionImage.IMG_CORRECTION_CHANGE, "proposalA"));
     Map<String, List<LinkedPositionProposal>> linkedProposals = ImmutableMap.of("a", proposals);
     proposal.setLinkedPositionProposals(linkedProposals);
   }
   //
   LinkedCorrectionProposal uiProposal = ServiceUtils.toUI(proposal);
   CompilationUnitChange ltkChange = (CompilationUnitChange) uiProposal.getChange();
   assertEquals("My linked change", ltkChange.getName());
 }
示例#2
0
 public void test_toUI_LinkedCorrectionProposal_noFile() throws Exception {
   Source source = new FileBasedSource(new File("no-such-file.dart"));
   SourceChange sourceChange = new SourceChange("My change", source);
   SourceCorrectionProposal proposal =
       new SourceCorrectionProposal(sourceChange, CorrectionKind.QA_ADD_TYPE_ANNOTATION);
   LinkedCorrectionProposal uiProposal = ServiceUtils.toUI(proposal);
   assertNull(uiProposal);
 }
示例#3
0
 public void test_createCoreException() throws Exception {
   Throwable e = new Throwable("msg");
   CoreException coreException = ServiceUtils.createCoreException(e);
   assertSame(e, coreException.getCause());
   // status
   IStatus status = coreException.getStatus();
   assertSame(e, status.getException());
   assertSame(IStatus.ERROR, status.getSeverity());
 }
示例#4
0
 public void test_toLTK_Throwable() throws Exception {
   Throwable e = new Throwable("msg");
   org.eclipse.ltk.core.refactoring.RefactoringStatus ltkStatus = ServiceUtils.toLTK(e);
   org.eclipse.ltk.core.refactoring.RefactoringStatusEntry[] ltkEntries = ltkStatus.getEntries();
   assertThat(ltkEntries).hasSize(1);
   // entry[0]
   assertEquals("msg", ltkEntries[0].getMessage());
   assertEquals(
       org.eclipse.ltk.core.refactoring.RefactoringStatus.FATAL, ltkEntries[0].getSeverity());
 }
示例#5
0
 public void test_toLTK_Change_SourceChange() throws Exception {
   Source source = createTestFileSource();
   // fill SourceChange
   SourceChange sourceChange = new SourceChange("My change", source);
   sourceChange.addEdit(new Edit(10, 1, "a"));
   sourceChange.addEdit(new Edit(20, 2, "b"));
   // toLTK
   TextFileChange ltkChange = (TextFileChange) ServiceUtils.toLTK((Change) sourceChange);
   assertEquals("My change", ltkChange.getName());
 }
示例#6
0
 public void test_toLTK_RefactoringStatus() throws Exception {
   RefactoringStatus serviceStatus = RefactoringStatus.createErrorStatus("msg");
   org.eclipse.ltk.core.refactoring.RefactoringStatus ltkStatus =
       ServiceUtils.toLTK(serviceStatus);
   org.eclipse.ltk.core.refactoring.RefactoringStatusEntry[] ltkEntries = ltkStatus.getEntries();
   assertThat(ltkEntries).hasSize(1);
   // entry[0]
   assertEquals("msg", ltkEntries[0].getMessage());
   assertEquals(
       org.eclipse.ltk.core.refactoring.RefactoringStatus.ERROR, ltkEntries[0].getSeverity());
 }
示例#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_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();
 }
示例#9
0
 /**
  * It is OK to apply more than one insert {@link Edit} with the same offset.
  *
  * <p>For example Quick Fix "Implement Missing Overrides" inserts several method declarations.
  */
 public void test_toLTK_SourceChange_twoInserts() throws Exception {
   Source source = createTestFileSource();
   // fill SourceChange
   SourceChange sourceChange = new SourceChange("My change", source);
   sourceChange.addEdit(new Edit(2, 0, "a"));
   sourceChange.addEdit(new Edit(2, 0, "b"));
   // toLTK
   TextFileChange ltkChange = ServiceUtils.toLTK(sourceChange);
   TextEdit textEdit = ltkChange.getEdit();
   // apply
   Document document = new Document("01234");
   textEdit.apply(document);
   assertEquals("01ab234", document.get());
 }
示例#10
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);
 }
示例#11
0
 public void test_toUI_ChangeCorrectionProposal() throws Exception {
   Source source = createTestFileSource();
   // fill SourceChange
   SourceChange sourceChange = new SourceChange("My change", source);
   sourceChange.addEdit(new Edit(10, 1, "a"));
   sourceChange.addEdit(new Edit(20, 1, "a"));
   sourceChange.addEdit(new Edit(30, 3, "b"));
   // create ChangeCorrectionProposal
   CorrectionProposal proposal =
       new ChangeCorrectionProposal(sourceChange, CorrectionKind.QA_ADD_TYPE_ANNOTATION);
   //
   com.google.dart.tools.ui.internal.text.correction.proposals.ChangeCorrectionProposal
       uiProposal =
           (com.google.dart.tools.ui.internal.text.correction.proposals.ChangeCorrectionProposal)
               ServiceUtils.toUI(proposal);
   ReflectionUtils.invokeMethod(uiProposal, "getChange()");
   CompilationUnitChange ltkChange = (CompilationUnitChange) uiProposal.getChange();
   assertEquals("My change", ltkChange.getName());
 }
示例#12
0
 public void test_toLTK_SourceChange_noGroups() throws Exception {
   Source source = createTestFileSource();
   // fill SourceChange
   SourceChange sourceChange = new SourceChange("My change", source);
   sourceChange.addEdit(new Edit(10, 1, "a"));
   sourceChange.addEdit(new Edit(20, 2, "b"));
   // toLTK
   TextFileChange ltkChange = ServiceUtils.toLTK(sourceChange);
   assertEquals("My change", ltkChange.getName());
   // no groups
   TextEditBasedChangeGroup[] changeGroups = ltkChange.getChangeGroups();
   assertThat(changeGroups).isEmpty();
   // check edits
   MultiTextEdit multiTextEdit = (MultiTextEdit) ltkChange.getEdit();
   TextEdit[] textEdits = multiTextEdit.getChildren();
   assertThat(textEdits).hasSize(2);
   assertEquals("a", ((ReplaceEdit) textEdits[0]).getText());
   assertEquals("b", ((ReplaceEdit) textEdits[1]).getText());
 }
示例#13
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);
 }
示例#14
0
 public void test_toLTK_SourceChange_withGroups() throws Exception {
   Source source = createTestFileSource();
   // fill SourceChange
   SourceChange sourceChange = new SourceChange("My change", source);
   sourceChange.addEdit(new Edit(10, 1, "a1"), "groupA");
   sourceChange.addEdit(new Edit(20, 2, "a2"), "groupA");
   sourceChange.addEdit(new Edit(30, 3, "b"), "groupB");
   // toLTK
   TextFileChange ltkChange = ServiceUtils.toLTK(sourceChange);
   assertEquals("My change", ltkChange.getName());
   TextEditBasedChangeGroup[] changeGroups = ltkChange.getChangeGroups();
   assertThat(changeGroups).hasSize(2);
   {
     TextEditBasedChangeGroup group = changeGroups[0];
     assertEquals("groupA", group.getName());
     TextEdit[] textEdits = group.getTextEdits();
     assertThat(textEdits).hasSize(2);
     assertEquals("a1", ((ReplaceEdit) textEdits[0]).getText());
     assertEquals("a2", ((ReplaceEdit) textEdits[1]).getText());
   }
 }
示例#15
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);
 }
示例#16
0
 public void test_toLTK_CorrectionImage() throws Exception {
   assertNotNull(ServiceUtils.toLTK(CorrectionImage.IMG_CORRECTION_CHANGE));
   assertNotNull(ServiceUtils.toLTK(CorrectionImage.IMG_CORRECTION_CLASS));
 }