Search in sources :

Example 11 with Main

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);
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Main(org.eclipse.xtext.linking.langATestLanguage.Main) Test(org.junit.Test)

Example 12 with Main

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());
}
Also used : Assignment(org.eclipse.xtext.Assignment) AbstractElement(org.eclipse.xtext.AbstractElement) EObject(org.eclipse.emf.ecore.EObject) LangATestLanguageGrammarAccess(org.eclipse.xtext.linking.services.LangATestLanguageGrammarAccess) CrossReference(org.eclipse.xtext.CrossReference) XtextResource(org.eclipse.xtext.resource.XtextResource) Main(org.eclipse.xtext.linking.langATestLanguage.Main) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Example 13 with Main

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());
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) XtextResource(org.eclipse.xtext.resource.XtextResource) Main(org.eclipse.xtext.linking.langATestLanguage.Main) LangATestLanguageStandaloneSetup(org.eclipse.xtext.linking.LangATestLanguageStandaloneSetup) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) Test(org.junit.Test)

Example 14 with Main

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));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) Type(org.eclipse.xtext.linking.langATestLanguage.Type) Import(org.eclipse.xtext.linking.langATestLanguage.Import) Parameter(org.eclipse.xtext.Parameter) Main(org.eclipse.xtext.linking.langATestLanguage.Main) EPackage(org.eclipse.emf.ecore.EPackage)

Example 15 with Main

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());
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) XtextResource(org.eclipse.xtext.resource.XtextResource) Main(org.eclipse.xtext.linking.langATestLanguage.Main) LangATestLanguageStandaloneSetup(org.eclipse.xtext.linking.LangATestLanguageStandaloneSetup) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) Test(org.junit.Test)

Aggregations

Main (org.eclipse.xtext.linking.langATestLanguage.Main)21 Test (org.junit.Test)18 XtextResource (org.eclipse.xtext.resource.XtextResource)12 Type (org.eclipse.xtext.linking.langATestLanguage.Type)9 EObject (org.eclipse.emf.ecore.EObject)6 InternalEObject (org.eclipse.emf.ecore.InternalEObject)4 Resource (org.eclipse.emf.ecore.resource.Resource)3 INode (org.eclipse.xtext.nodemodel.INode)3 IReferenceDescription (org.eclipse.xtext.resource.IReferenceDescription)3 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)3 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)2 EReference (org.eclipse.emf.ecore.EReference)2 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)2 Assignment (org.eclipse.xtext.Assignment)2 CrossReference (org.eclipse.xtext.CrossReference)2 LangATestLanguageStandaloneSetup (org.eclipse.xtext.linking.LangATestLanguageStandaloneSetup)2 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)2 StorageAwareResource (org.eclipse.xtext.resource.persistence.StorageAwareResource)2 StringInputStream (org.eclipse.xtext.util.StringInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1