Search in sources :

Example 1 with DefaultRenameStrategy

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

the class DefaultRenameElementStrategyTest method testValueConversion.

@Test
public void testValueConversion() throws Exception {
    DefaultRenameStrategy strategy = new DefaultRenameStrategy() {

        @Override
        protected String getNameRuleName(EObject targetElement, EAttribute nameAttribute) {
            return "STRING";
        }
    };
    getInjector().injectMembers(strategy);
    final XtextResource resource = getResourceFromString("foo { }");
    Element targetElement = (Element) resource.getContents().get(0).eContents().get(0);
    assertEquals("foo", targetElement.getName());
    strategy.initialize(targetElement, null);
    assertEquals("\"foo\"", strategy.getOriginalName());
    strategy.createDeclarationUpdates("\"bar\"", resource.getResourceSet(), this);
    assertEquals(1, textEdits.size());
    assertEquals(0, textEdits.get(0).getOffset());
    assertEquals(3, textEdits.get(0).getLength());
    assertEquals("\"bar\"", ((ReplaceEdit) textEdits.get(0)).getText());
    strategy.applyDeclarationChange("\"bar\"", resource.getResourceSet());
    assertEquals("bar", targetElement.getName());
    strategy.revertDeclarationChange(resource.getResourceSet());
    assertEquals("foo", targetElement.getName());
}
Also used : EAttribute(org.eclipse.emf.ecore.EAttribute) DefaultRenameStrategy(org.eclipse.xtext.ui.refactoring.impl.DefaultRenameStrategy) EObject(org.eclipse.emf.ecore.EObject) Element(org.eclipse.xtext.ui.tests.refactoring.refactoring.Element) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Aggregations

EAttribute (org.eclipse.emf.ecore.EAttribute)1 EObject (org.eclipse.emf.ecore.EObject)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 DefaultRenameStrategy (org.eclipse.xtext.ui.refactoring.impl.DefaultRenameStrategy)1 Element (org.eclipse.xtext.ui.tests.refactoring.refactoring.Element)1 Test (org.junit.Test)1