Search in sources :

Example 1 with Reference

use of org.eclipse.xtext.ui.tests.refactoring.referring.Reference in project xtext-eclipse by eclipse.

the class RenameRefactoringIntegrationTest method testRefFromOtherNonXtextLanguage.

@Test
public void testRefFromOtherNonXtextLanguage() throws Exception {
    ResourceSet resourceSet = new ResourceSetImpl();
    EObject elementB = resourceSet.getEObject(uriB, true);
    String xmiFileName = "otherLanguageFile.referring_xmi";
    Resource referringResource = resourceSet.createResource(URI.createPlatformResourceURI(TEST_PROJECT + "/" + xmiFileName, true));
    Reference ref = ReferringFactory.eINSTANCE.createReference();
    ref.setReferenced(elementB);
    referringResource.getContents().add(ref);
    referringResource.save(null);
    project.refreshLocal(IResource.DEPTH_INFINITE, null);
    IFile referringXmiFile = project.getFile(xmiFileName);
    String originalContent = readFile(referringXmiFile);
    doRename();
    assertEquals(originalContent.replaceAll("#B", "#C"), readFile(referringXmiFile));
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) IFile(org.eclipse.core.resources.IFile) Reference(org.eclipse.xtext.ui.tests.refactoring.referring.Reference) EObject(org.eclipse.emf.ecore.EObject) XtextResource(org.eclipse.xtext.resource.XtextResource) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest) Test(org.junit.Test)

Example 2 with Reference

use of org.eclipse.xtext.ui.tests.refactoring.referring.Reference in project xtext-eclipse by eclipse.

the class LinkedEditingRefactoringIntegrationTest method testRefactorEcoreCrossLanguage.

@Test
public void testRefactorEcoreCrossLanguage() throws Exception {
    EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
    ePackage.setName("test");
    ePackage.setNsPrefix("test");
    ePackage.setNsURI("http://test");
    EClass eClass = EcoreFactory.eINSTANCE.createEClass();
    eClass.setName(TEST_CLASS);
    ePackage.getEClassifiers().add(eClass);
    Resource ecoreResource = new ResourceSetImpl().createResource(URI.createPlatformResourceURI(TEST_PROJECT + "/Test.ecore", true));
    ecoreResource.getContents().add(ePackage);
    ecoreResource.save(null);
    ecoreResource.unload();
    project.refreshLocal(IResource.DEPTH_INFINITE, null);
    String model = "ref test." + TEST_CLASS;
    IFile file = createFile(TEST_PROJECT + "/ref.referringtestlanguage", model);
    waitForBuild();
    final XtextEditor editor = openEditor(file);
    final TextSelection selection = new TextSelection(model.indexOf(TEST_CLASS), TEST_CLASS.length());
    editor.getSelectionProvider().setSelection(selection);
    waitForDisplay();
    IRenameElementContext context = editor.getDocument().readOnly(new IUnitOfWork<IRenameElementContext, XtextResource>() {

        @Override
        public IRenameElementContext exec(XtextResource state) throws Exception {
            Reference ref = (Reference) state.getContents().get(0).eContents().get(0);
            EObject referenced = ref.getReferenced();
            assertNotNull(referenced);
            return new IRenameElementContext.Impl(EcoreUtil.getURI(referenced), referenced.eClass(), editor, selection, state.getURI());
        }
    });
    renameRefactoringController.startRefactoring(context);
    waitForDisplay();
    pressKeys(editor, "NewTestClass\n");
    waitForReconciler(editor);
    waitForDisplay();
    waitForBuild();
    ecoreResource.load(null);
    assertEquals("NewTestClass", ((EPackage) ecoreResource.getContents().get(0)).getEClassifiers().get(0).getName());
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) IFile(org.eclipse.core.resources.IFile) TextSelection(org.eclipse.jface.text.TextSelection) Reference(org.eclipse.xtext.ui.tests.refactoring.referring.Reference) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) XtextResource(org.eclipse.xtext.resource.XtextResource) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) EPackage(org.eclipse.emf.ecore.EPackage) EClass(org.eclipse.emf.ecore.EClass) EObject(org.eclipse.emf.ecore.EObject) IRenameElementContext(org.eclipse.xtext.ui.refactoring.ui.IRenameElementContext) AbstractLinkedEditingIntegrationTest(org.eclipse.xtext.ui.testing.AbstractLinkedEditingIntegrationTest) Test(org.junit.Test)

Example 3 with Reference

use of org.eclipse.xtext.ui.tests.refactoring.referring.Reference in project xtext-eclipse by eclipse.

the class ReferringTestLanguageSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == ReferringPackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case ReferringPackage.MAIN:
                sequence_Main(context, (Main) semanticObject);
                return;
            case ReferringPackage.NAMED:
                if (rule == grammarAccess.getNamedRule()) {
                    sequence_Named(context, (Named) semanticObject);
                    return;
                } else if (rule == grammarAccess.getAbstractReferenceRule() || rule == grammarAccess.getReference2Rule()) {
                    sequence_Named_Reference2(context, (Named) semanticObject);
                    return;
                } else
                    break;
            case ReferringPackage.REFERENCE:
                sequence_Reference(context, (Reference) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Named(org.eclipse.xtext.ui.tests.refactoring.referring.Named) Action(org.eclipse.xtext.Action) Reference(org.eclipse.xtext.ui.tests.refactoring.referring.Reference) Parameter(org.eclipse.xtext.Parameter) Main(org.eclipse.xtext.ui.tests.refactoring.referring.Main) EPackage(org.eclipse.emf.ecore.EPackage)

Aggregations

Reference (org.eclipse.xtext.ui.tests.refactoring.referring.Reference)3 IFile (org.eclipse.core.resources.IFile)2 IResource (org.eclipse.core.resources.IResource)2 EObject (org.eclipse.emf.ecore.EObject)2 EPackage (org.eclipse.emf.ecore.EPackage)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)2 XtextResource (org.eclipse.xtext.resource.XtextResource)2 Test (org.junit.Test)2 EClass (org.eclipse.emf.ecore.EClass)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 TextSelection (org.eclipse.jface.text.TextSelection)1 Action (org.eclipse.xtext.Action)1 Parameter (org.eclipse.xtext.Parameter)1 ParserRule (org.eclipse.xtext.ParserRule)1 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)1 IRenameElementContext (org.eclipse.xtext.ui.refactoring.ui.IRenameElementContext)1 AbstractEditorTest (org.eclipse.xtext.ui.testing.AbstractEditorTest)1 AbstractLinkedEditingIntegrationTest (org.eclipse.xtext.ui.testing.AbstractLinkedEditingIntegrationTest)1 Main (org.eclipse.xtext.ui.tests.refactoring.referring.Main)1