Search in sources :

Example 1 with RenamedElementTracker

use of org.eclipse.xtext.ui.refactoring.impl.RenamedElementTracker in project xtext-eclipse by eclipse.

the class RenamedElementTrackerTest method testResolveElements.

@Test
public void testResolveElements() throws Exception {
    URI resourceURI = URI.createFileURI("testresource.refactoringtestlanguage");
    String textualModel = "A { B { C { ref A.B } } ref B }";
    XtextResource resource = getResource(textualModel, resourceURI.toString());
    Element elementA = (Element) resource.getContents().get(0).eContents().get(0);
    Element elementB = elementA.getContained().get(0);
    Element elementC = elementB.getContained().get(0);
    URI uriB = EcoreUtil.getURI(elementB);
    URI uriC = EcoreUtil.getURI(elementC);
    String newName = "newB";
    List<URI> renamedElementURIs = newArrayList(uriB, uriC);
    IRenameStrategy renameStrategy = getInjector().getInstance(IRenameStrategy.Provider.class).get(elementB, null);
    IRenamedElementTracker renamedElementTracker = new RenamedElementTracker();
    Map<URI, URI> original2newElementURIs = renamedElementTracker.renameAndTrack(renamedElementURIs, newName, resource.getResourceSet(), renameStrategy, new NullProgressMonitor());
    assertEquals("B", elementB.getName());
    assertEquals(2, original2newElementURIs.size());
    assertEquals(resourceURI.appendFragment(newName), original2newElementURIs.get(uriB));
    assertEquals(uriC, original2newElementURIs.get(uriC));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IRenameStrategy(org.eclipse.xtext.ui.refactoring.IRenameStrategy) RenamedElementTracker(org.eclipse.xtext.ui.refactoring.impl.RenamedElementTracker) IRenamedElementTracker(org.eclipse.xtext.ui.refactoring.IRenamedElementTracker) Element(org.eclipse.xtext.ui.tests.refactoring.refactoring.Element) XtextResource(org.eclipse.xtext.resource.XtextResource) URI(org.eclipse.emf.common.util.URI) IRenamedElementTracker(org.eclipse.xtext.ui.refactoring.IRenamedElementTracker) RefactoringTestLanguageFragmentProvider(org.eclipse.xtext.ui.tests.refactoring.resource.RefactoringTestLanguageFragmentProvider) Test(org.junit.Test)

Aggregations

NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 URI (org.eclipse.emf.common.util.URI)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 IRenameStrategy (org.eclipse.xtext.ui.refactoring.IRenameStrategy)1 IRenamedElementTracker (org.eclipse.xtext.ui.refactoring.IRenamedElementTracker)1 RenamedElementTracker (org.eclipse.xtext.ui.refactoring.impl.RenamedElementTracker)1 Element (org.eclipse.xtext.ui.tests.refactoring.refactoring.Element)1 RefactoringTestLanguageFragmentProvider (org.eclipse.xtext.ui.tests.refactoring.resource.RefactoringTestLanguageFragmentProvider)1 Test (org.junit.Test)1