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