Search in sources :

Example 1 with IRenameStrategy

use of org.eclipse.xtext.ui.refactoring.IRenameStrategy in project xtext-xtend by eclipse.

the class RenameStrategyTest method testInferredClassRenamed.

@Test
public void testInferredClassRenamed() throws Exception {
    XtendClass fooClass = (XtendClass) testHelper.xtendFile("Foo", "class Foo { }").getXtendTypes().get(0);
    IRenameStrategy renameStrategy = createRenameStrategy(fooClass);
    renameStrategy.applyDeclarationChange("Bar", fooClass.eResource().getResourceSet());
    JvmGenericType inferredType = associations.getInferredType(fooClass);
    JvmConstructor inferredConstructor = associations.getInferredConstructor(fooClass);
    assertEquals("Bar", fooClass.getName());
    assertEquals("Bar", inferredType.getSimpleName());
    assertEquals("Bar", inferredConstructor.getSimpleName());
    renameStrategy.revertDeclarationChange(fooClass.eResource().getResourceSet());
    inferredType = associations.getInferredType(fooClass);
    inferredConstructor = associations.getInferredConstructor(fooClass);
    assertEquals("Foo", fooClass.getName());
    assertEquals("Foo", inferredType.getSimpleName());
    assertEquals("Foo", inferredConstructor.getSimpleName());
}
Also used : IRenameStrategy(org.eclipse.xtext.ui.refactoring.IRenameStrategy) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) Test(org.junit.Test)

Example 2 with IRenameStrategy

use of org.eclipse.xtext.ui.refactoring.IRenameStrategy in project xtext-xtend by eclipse.

the class RenameStrategyTest method testDispatchMethods.

@Test
public void testDispatchMethods() throws Exception {
    XtendClass fooClass = (XtendClass) testHelper.xtendFile("Foo", "class Foo { def dispatch foo(Number it) {} def dispatch foo(String it) {} }").getXtendTypes().get(0);
    IResourcesSetupUtil.waitForBuild();
    XtendFunction fooMethod0 = (XtendFunction) fooClass.getMembers().get(0);
    IRenameStrategy renameStrategy = createRenameStrategy(fooMethod0);
    assertNotNull(renameStrategy);
    renameStrategy.applyDeclarationChange("bar", fooMethod0.eResource().getResourceSet());
    for (XtendFunction f : filter(fooClass.getMembers(), XtendFunction.class)) {
        assertEquals("bar", f.getName());
        assertEquals("_bar", associations.getDirectlyInferredOperation(f).getSimpleName());
        assertEquals("bar", associations.getDispatchOperation(f).getSimpleName());
    }
    renameStrategy.revertDeclarationChange(fooMethod0.eResource().getResourceSet());
    for (XtendFunction f : filter(fooClass.getMembers(), XtendFunction.class)) {
        assertEquals("foo", f.getName());
        assertEquals("_foo", associations.getDirectlyInferredOperation(f).getSimpleName());
        assertEquals("foo", associations.getDispatchOperation(f).getSimpleName());
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) IRenameStrategy(org.eclipse.xtext.ui.refactoring.IRenameStrategy) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) Test(org.junit.Test)

Example 3 with IRenameStrategy

use of org.eclipse.xtext.ui.refactoring.IRenameStrategy in project xtext-xtend by eclipse.

the class RenameStrategyTest method testInferredMethodRenamed.

@Test
public void testInferredMethodRenamed() throws Exception {
    XtendFunction fooMethod = (XtendFunction) ((XtendClass) testHelper.xtendFile("Foo", "class Foo { def Foo foo() {this} }").getXtendTypes().get(0)).getMembers().get(0);
    IRenameStrategy renameStrategy = createRenameStrategy(fooMethod);
    renameStrategy.applyDeclarationChange("bar", fooMethod.eResource().getResourceSet());
    assertEquals("bar", fooMethod.getName());
    JvmOperation inferredOperation = associations.getDirectlyInferredOperation(fooMethod);
    assertEquals("bar", inferredOperation.getSimpleName());
    renameStrategy.revertDeclarationChange(fooMethod.eResource().getResourceSet());
    inferredOperation = associations.getDirectlyInferredOperation(fooMethod);
    assertEquals("foo", fooMethod.getName());
    assertEquals("foo", inferredOperation.getSimpleName());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) IRenameStrategy(org.eclipse.xtext.ui.refactoring.IRenameStrategy) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) Test(org.junit.Test)

Example 4 with IRenameStrategy

use of org.eclipse.xtext.ui.refactoring.IRenameStrategy in project xtext-xtend by eclipse.

the class RenameStrategyTest method testXtendConstructorIgnored.

@Test
public void testXtendConstructorIgnored() throws Exception {
    XtendConstructor constructor = (XtendConstructor) ((XtendClass) testHelper.xtendFile("Foo", "class Foo { new() {} }").getXtendTypes().get(0)).getMembers().get(0);
    IRenameStrategy renameStrategy = createRenameStrategy(constructor);
    assertNull(renameStrategy);
}
Also used : IRenameStrategy(org.eclipse.xtext.ui.refactoring.IRenameStrategy) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) Test(org.junit.Test)

Aggregations

XtendClass (org.eclipse.xtend.core.xtend.XtendClass)4 IRenameStrategy (org.eclipse.xtext.ui.refactoring.IRenameStrategy)4 Test (org.junit.Test)4 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)2 XtendConstructor (org.eclipse.xtend.core.xtend.XtendConstructor)1 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)1 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)1 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)1