Search in sources :

Example 1 with AbstractElement

use of org.eclipse.xtext.example.domainmodel.domainmodel.AbstractElement in project xtext-eclipse by eclipse.

the class DomainmodelParsingTest method testParsing.

@Test
public void testParsing() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package example {");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("entity MyEntity {");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("property : String");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final DomainModel model = this._parseHelper.parse(_builder);
    AbstractElement _head = IterableExtensions.<AbstractElement>head(model.getElements());
    final PackageDeclaration pack = ((PackageDeclaration) _head);
    Assert.assertEquals("example", pack.getName());
    AbstractElement _head_1 = IterableExtensions.<AbstractElement>head(pack.getElements());
    final Entity entity = ((Entity) _head_1);
    Assert.assertEquals("MyEntity", entity.getName());
    Feature _head_2 = IterableExtensions.<Feature>head(entity.getFeatures());
    final Property property = ((Property) _head_2);
    Assert.assertEquals("property", property.getName());
    Assert.assertEquals("java.lang.String", property.getType().getIdentifier());
}
Also used : Entity(org.eclipse.xtext.example.domainmodel.domainmodel.Entity) DomainModel(org.eclipse.xtext.example.domainmodel.domainmodel.DomainModel) AbstractElement(org.eclipse.xtext.example.domainmodel.domainmodel.AbstractElement) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Feature(org.eclipse.xtext.example.domainmodel.domainmodel.Feature) Property(org.eclipse.xtext.example.domainmodel.domainmodel.Property) PackageDeclaration(org.eclipse.xtext.example.domainmodel.domainmodel.PackageDeclaration) Test(org.junit.Test)

Example 2 with AbstractElement

use of org.eclipse.xtext.example.domainmodel.domainmodel.AbstractElement in project xtext-eclipse by eclipse.

the class DomainmodelParsingTest method testReturnTypeInference.

@Test
public void testReturnTypeInference() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package example {");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("entity MyEntity {");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("property : String");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("op foo(String s) {");
    _builder.newLine();
    _builder.append("    \t");
    _builder.append("return property.toUpperCase + s");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final DomainModel model = this._parseHelper.parse(_builder);
    AbstractElement _head = IterableExtensions.<AbstractElement>head(model.getElements());
    final PackageDeclaration pack = ((PackageDeclaration) _head);
    AbstractElement _head_1 = IterableExtensions.<AbstractElement>head(pack.getElements());
    final Entity entity = ((Entity) _head_1);
    Feature _last = IterableExtensions.<Feature>last(entity.getFeatures());
    final Operation op = ((Operation) _last);
    EObject _head_2 = IterableExtensions.<EObject>head(this._iJvmModelAssociations.getJvmElements(op));
    final JvmOperation method = ((JvmOperation) _head_2);
    Assert.assertEquals("String", method.getReturnType().getSimpleName());
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) Entity(org.eclipse.xtext.example.domainmodel.domainmodel.Entity) DomainModel(org.eclipse.xtext.example.domainmodel.domainmodel.DomainModel) AbstractElement(org.eclipse.xtext.example.domainmodel.domainmodel.AbstractElement) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) Operation(org.eclipse.xtext.example.domainmodel.domainmodel.Operation) Feature(org.eclipse.xtext.example.domainmodel.domainmodel.Feature) PackageDeclaration(org.eclipse.xtext.example.domainmodel.domainmodel.PackageDeclaration) Test(org.junit.Test)

Example 3 with AbstractElement

use of org.eclipse.xtext.example.domainmodel.domainmodel.AbstractElement in project xtext-eclipse by eclipse.

the class DomainmodelFormatter method _format.

protected void _format(final DomainModel domainmodel, @Extension final IFormattableDocument document) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.setNewLines(0, 0, 1);
        it.noSpace();
    };
    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
        it.newLine();
    };
    document.<DomainModel>append(document.<DomainModel>prepend(domainmodel, _function), _function_1);
    this.format(domainmodel.getImportSection(), document);
    EList<AbstractElement> _elements = domainmodel.getElements();
    for (final AbstractElement element : _elements) {
        this.format(element, document);
    }
}
Also used : DomainModel(org.eclipse.xtext.example.domainmodel.domainmodel.DomainModel) AbstractElement(org.eclipse.xtext.example.domainmodel.domainmodel.AbstractElement) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter)

Example 4 with AbstractElement

use of org.eclipse.xtext.example.domainmodel.domainmodel.AbstractElement in project xtext-eclipse by eclipse.

the class DomainmodelFormatter method _format.

protected void _format(final PackageDeclaration pkg, @Extension final IFormattableDocument document) {
    final ISemanticRegion open = this.textRegionExtensions.regionFor(pkg).keyword("{");
    final ISemanticRegion close = this.textRegionExtensions.regionFor(pkg).keyword("}");
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.oneSpace();
    };
    document.surround(this.textRegionExtensions.regionFor(pkg).feature(DomainmodelPackage.Literals.ABSTRACT_ELEMENT__NAME), _function);
    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
        it.newLine();
    };
    document.append(open, _function_1);
    final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
        it.indent();
    };
    document.<ISemanticRegion, ISemanticRegion>interior(open, close, _function_2);
    EList<AbstractElement> _elements = pkg.getElements();
    for (final AbstractElement element : _elements) {
        {
            document.<AbstractElement>format(element);
            final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
                it.setNewLines(1, 1, 2);
            };
            document.<AbstractElement>append(element, _function_3);
        }
    }
}
Also used : AbstractElement(org.eclipse.xtext.example.domainmodel.domainmodel.AbstractElement) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

Aggregations

AbstractElement (org.eclipse.xtext.example.domainmodel.domainmodel.AbstractElement)4 DomainModel (org.eclipse.xtext.example.domainmodel.domainmodel.DomainModel)3 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)2 Entity (org.eclipse.xtext.example.domainmodel.domainmodel.Entity)2 Feature (org.eclipse.xtext.example.domainmodel.domainmodel.Feature)2 PackageDeclaration (org.eclipse.xtext.example.domainmodel.domainmodel.PackageDeclaration)2 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)2 Test (org.junit.Test)2 EObject (org.eclipse.emf.ecore.EObject)1 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)1 Operation (org.eclipse.xtext.example.domainmodel.domainmodel.Operation)1 Property (org.eclipse.xtext.example.domainmodel.domainmodel.Property)1 ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)1 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)1