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