Search in sources :

Example 6 with Type

use of org.eclipse.xtext.linking.langATestLanguage.Type in project xtext-core by eclipse.

the class Bug285381Test method _testSerializeReference_01.

public void _testSerializeReference_01() throws Exception {
    String modelAsString = "type A extends A";
    Main model = (Main) getModel(modelAsString);
    Type parsedType = model.getTypes().get(0);
    assertSame(parsedType, parsedType.getExtends());
    Type newType = LangATestLanguageFactory.eINSTANCE.createType();
    newType.setName("Foo");
    parsedType.setExtends(newType);
    String serialized = serialize(model);
    // we use the existing value from the node model
    // since there is not string representation of the newType
    assertEquals(modelAsString, serialized);
}
Also used : Type(org.eclipse.xtext.linking.langATestLanguage.Type) Main(org.eclipse.xtext.linking.langATestLanguage.Main)

Example 7 with Type

use of org.eclipse.xtext.linking.langATestLanguage.Type in project xtext-core by eclipse.

the class Bug285381Test method _testSerializeReference_02.

public void _testSerializeReference_02() throws Exception {
    String modelAsString = "type A";
    Main model = (Main) getModel(modelAsString);
    Type parsedType = model.getTypes().get(0);
    assertNull(parsedType.getExtends());
    Type newType = LangATestLanguageFactory.eINSTANCE.createType();
    newType.setName("Foo");
    parsedType.setExtends(newType);
    try {
        serialize(model);
        fail("expected XtextSerializationException");
    } catch (XtextSerializationException e) {
    // expected
    }
}
Also used : Type(org.eclipse.xtext.linking.langATestLanguage.Type) Main(org.eclipse.xtext.linking.langATestLanguage.Main)

Example 8 with Type

use of org.eclipse.xtext.linking.langATestLanguage.Type in project xtext-core by eclipse.

the class PortableURIsTest method testPortableUris.

@Test
public void testPortableUris() {
    try {
        final XtextResourceSet resourceSet = this.<XtextResourceSet>get(XtextResourceSet.class);
        Resource _createResource = resourceSet.createResource(URI.createURI("hubba:/bubba.langatestlanguage"));
        final StorageAwareResource resourceA = ((StorageAwareResource) _createResource);
        Resource _createResource_1 = resourceSet.createResource(URI.createURI("hubba:/bubba2.langatestlanguage"));
        final StorageAwareResource resourceB = ((StorageAwareResource) _createResource_1);
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("type B");
        _builder.newLine();
        resourceB.load(this.getAsStream(_builder.toString()), null);
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("import \'hubba:/bubba2.langatestlanguage\'");
        _builder_1.newLine();
        _builder_1.newLine();
        _builder_1.append("type A extends B");
        _builder_1.newLine();
        resourceA.load(this.getAsStream(_builder_1.toString()), null);
        final Type extended = IterableExtensions.<Type>head(IterableExtensions.<Main>head(Iterables.<Main>filter(resourceA.getContents(), Main.class)).getTypes()).getExtends();
        final URI uri = EcoreUtil.getURI(extended);
        final URI portableURI = resourceA.getPortableURIs().toPortableURI(resourceA, uri);
        Assert.assertEquals(resourceA.getURI(), portableURI.trimFragment());
        Assert.assertTrue(resourceA.getPortableURIs().isPortableURIFragment(portableURI.fragment()));
        Assert.assertSame(extended, resourceA.getEObject(portableURI.fragment()));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : Type(org.eclipse.xtext.linking.langATestLanguage.Type) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) Resource(org.eclipse.emf.ecore.resource.Resource) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) Main(org.eclipse.xtext.linking.langATestLanguage.Main) URI(org.eclipse.emf.common.util.URI) Test(org.junit.Test)

Example 9 with Type

use of org.eclipse.xtext.linking.langATestLanguage.Type 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 10 with Type

use of org.eclipse.xtext.linking.langATestLanguage.Type in project xtext-core by eclipse.

the class TypeImpl method setExtends.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setExtends(Type newExtends) {
    Type oldExtends = extends_;
    extends_ = newExtends;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, LangATestLanguagePackage.TYPE__EXTENDS, oldExtends, extends_));
}
Also used : Type(org.eclipse.xtext.linking.langATestLanguage.Type) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Aggregations

Type (org.eclipse.xtext.linking.langATestLanguage.Type)12 Main (org.eclipse.xtext.linking.langATestLanguage.Main)9 Test (org.junit.Test)7 XtextResource (org.eclipse.xtext.resource.XtextResource)6 INode (org.eclipse.xtext.nodemodel.INode)4 Adapter (org.eclipse.emf.common.notify.Adapter)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)2 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)1 DiagnosticChain (org.eclipse.emf.common.util.DiagnosticChain)1 URI (org.eclipse.emf.common.util.URI)1 EClass (org.eclipse.emf.ecore.EClass)1 EDataType (org.eclipse.emf.ecore.EDataType)1 EObject (org.eclipse.emf.ecore.EObject)1 EPackage (org.eclipse.emf.ecore.EPackage)1 EValidator (org.eclipse.emf.ecore.EValidator)1 InternalEObject (org.eclipse.emf.ecore.InternalEObject)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 Action (org.eclipse.xtext.Action)1