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());
}
Aggregations