use of org.eclipse.xtext.linking.langATestLanguage.Main in project xtext-core by eclipse.
the class ResourceTests method testFragmentsWorkInBothDirections.
@Test
public void testFragmentsWorkInBothDirections() throws Exception {
Main model = (Main) getModel("type A extends B type B extends A");
EObject typeA1 = model.getTypes().get(0);
EObject typeA2 = model.eResource().getEObject(model.eResource().getURIFragment(typeA1));
assertEquals(typeA1, typeA2);
}
use of org.eclipse.xtext.linking.langATestLanguage.Main in project xtext-core by eclipse.
the class GrammarUtilTest method testGetReference.
@Test
public void testGetReference() throws Exception {
this.with(LangATestLanguageStandaloneSetup.class);
XtextResource resource = this.getResourceFromStringAndExpect("type A extends B", 1);
Assignment asExtends = this.<LangATestLanguageGrammarAccess>get(LangATestLanguageGrammarAccess.class).getTypeAccess().getExtendsAssignment_2_1();
AbstractElement _terminal = asExtends.getTerminal();
CrossReference xref = ((CrossReference) _terminal);
EObject _model = this.getModel(resource);
Main model = ((Main) _model);
EObject typeA = model.getTypes().get(0);
EReference ref = GrammarUtil.getReference(xref, typeA.eClass());
Assert.assertNotNull(ref);
Assert.assertEquals("extends", ref.getName());
Assert.assertFalse(ref.isMany());
Assert.assertEquals(typeA.eClass(), ref.getEReferenceType());
}
use of org.eclipse.xtext.linking.langATestLanguage.Main in project xtext-core by eclipse.
the class DefaultReferenceDescriptionTest method testgetReferenceDescriptions.
@Test
public void testgetReferenceDescriptions() throws Exception {
with(new LangATestLanguageStandaloneSetup());
XtextResource targetResource = getResource("type C", "bar.langatestlanguage");
EObject typeC = targetResource.getContents().get(0).eContents().get(0);
XtextResource resource = (XtextResource) targetResource.getResourceSet().createResource(URI.createURI("foo.langatestlanguage"));
resource.load(new StringInputStream("type A extends C type B extends A"), null);
EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
IResourceDescription resDesc = resource.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(resource);
Iterable<IReferenceDescription> descriptions = resDesc.getReferenceDescriptions();
Collection<IReferenceDescription> collection = Lists.newArrayList(descriptions);
assertEquals(1, collection.size());
IReferenceDescription refDesc = descriptions.iterator().next();
Main m = (Main) resource.getParseResult().getRootASTElement();
assertEquals(m.getTypes().get(0), resource.getResourceSet().getEObject(refDesc.getSourceEObjectUri(), false));
assertEquals(typeC, resource.getResourceSet().getEObject(refDesc.getTargetEObjectUri(), false));
assertEquals(-1, refDesc.getIndexInList());
assertEquals(LangATestLanguagePackage.Literals.TYPE__EXTENDS, refDesc.getEReference());
}
use of org.eclipse.xtext.linking.langATestLanguage.Main in project xtext-core by eclipse.
the class LangATestLanguageSemanticSequencer 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 == LangATestLanguagePackage.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case LangATestLanguagePackage.IMPORT:
sequence_Import(context, (Import) semanticObject);
return;
case LangATestLanguagePackage.MAIN:
sequence_Main(context, (Main) semanticObject);
return;
case LangATestLanguagePackage.TYPE:
sequence_Type(context, (Type) semanticObject);
return;
}
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
use of org.eclipse.xtext.linking.langATestLanguage.Main in project xtext-core by eclipse.
the class DefaultReferenceDescriptionTest method testgetReferenceDescriptionForMultiValue.
@Test
public void testgetReferenceDescriptionForMultiValue() throws Exception {
with(new LangATestLanguageStandaloneSetup());
XtextResource targetResource = getResource("type C type D", "bar.langatestlanguage");
EObject typeC = targetResource.getContents().get(0).eContents().get(0);
EObject typeD = targetResource.getContents().get(0).eContents().get(1);
XtextResource resource = (XtextResource) targetResource.getResourceSet().createResource(URI.createURI("foo.langatestlanguage"));
resource.load(new StringInputStream("type A implements B,C,D type B"), null);
EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
IResourceDescription resDesc = resource.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(resource);
Iterable<IReferenceDescription> descriptions = resDesc.getReferenceDescriptions();
Collection<IReferenceDescription> collection = Lists.newArrayList(descriptions);
assertEquals(2, collection.size());
Iterator<IReferenceDescription> iterator = descriptions.iterator();
IReferenceDescription refDesc1 = iterator.next();
IReferenceDescription refDesc2 = iterator.next();
Main m = (Main) resource.getParseResult().getRootASTElement();
assertEquals(m.getTypes().get(0), resource.getResourceSet().getEObject(refDesc1.getSourceEObjectUri(), false));
assertEquals(typeC, resource.getResourceSet().getEObject(refDesc1.getTargetEObjectUri(), false));
assertEquals(1, refDesc1.getIndexInList());
assertEquals(LangATestLanguagePackage.Literals.TYPE__IMPLEMENTS, refDesc1.getEReference());
assertEquals(m.getTypes().get(0), resource.getResourceSet().getEObject(refDesc2.getSourceEObjectUri(), false));
assertEquals(typeD, resource.getResourceSet().getEObject(refDesc2.getTargetEObjectUri(), false));
assertEquals(2, refDesc2.getIndexInList());
assertEquals(LangATestLanguagePackage.Literals.TYPE__IMPLEMENTS, refDesc2.getEReference());
}
Aggregations