use of org.eclipse.xtext.example.domainmodel.domainmodel.Feature in project xtext-eclipse by eclipse.
the class DomainmodelParsingTest method testReturnTypeInference.
@Test
public void testReturnTypeInference() {
try {
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());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.example.domainmodel.domainmodel.Feature in project xtext-eclipse by eclipse.
the class DomainmodelParsingTest method testParsing.
@Test
public void testParsing() {
try {
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 _get = model.getElements().get(0);
final PackageDeclaration pack = ((PackageDeclaration) _get);
Assert.assertEquals("example", pack.getName());
AbstractElement _get_1 = pack.getElements().get(0);
final Entity entity = ((Entity) _get_1);
Assert.assertEquals("MyEntity", entity.getName());
Feature _get_2 = entity.getFeatures().get(0);
final Property property = ((Property) _get_2);
Assert.assertEquals("property", property.getName());
Assert.assertEquals("java.lang.String", property.getType().getIdentifier());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.example.domainmodel.domainmodel.Feature in project xtext-eclipse by eclipse.
the class DomainmodelJvmModelInferrer method _infer.
protected void _infer(final Entity entity, @Extension final IJvmDeclaredTypeAcceptor acceptor, final boolean prelinkingPhase) {
final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> {
this._jvmTypesBuilder.setDocumentation(it, this._jvmTypesBuilder.getDocumentation(entity));
JvmParameterizedTypeReference _superType = entity.getSuperType();
boolean _tripleNotEquals = (_superType != null);
if (_tripleNotEquals) {
EList<JvmTypeReference> _superTypes = it.getSuperTypes();
JvmTypeReference _cloneWithProxies = this._jvmTypesBuilder.cloneWithProxies(entity.getSuperType());
this._jvmTypesBuilder.<JvmTypeReference>operator_add(_superTypes, _cloneWithProxies);
}
EList<JvmMember> _members = it.getMembers();
final Procedure1<JvmConstructor> _function_1 = (JvmConstructor it_1) -> {
};
JvmConstructor _constructor = this._jvmTypesBuilder.toConstructor(entity, _function_1);
this._jvmTypesBuilder.<JvmConstructor>operator_add(_members, _constructor);
final JvmTypeReference procedureType = this._typeReferenceBuilder.typeRef(Procedure1.class, this._typeReferenceBuilder.typeRef(it));
EList<JvmMember> _members_1 = it.getMembers();
final Procedure1<JvmConstructor> _function_2 = (JvmConstructor it_1) -> {
EList<JvmFormalParameter> _parameters = it_1.getParameters();
JvmFormalParameter _parameter = this._jvmTypesBuilder.toParameter(entity, "initializer", procedureType);
this._jvmTypesBuilder.<JvmFormalParameter>operator_add(_parameters, _parameter);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("initializer.apply(this);");
_builder.newLine();
}
};
this._jvmTypesBuilder.setBody(it_1, _client);
};
JvmConstructor _constructor_1 = this._jvmTypesBuilder.toConstructor(entity, _function_2);
this._jvmTypesBuilder.<JvmConstructor>operator_add(_members_1, _constructor_1);
EList<Feature> _features = entity.getFeatures();
for (final Feature f : _features) {
boolean _matched = false;
if (f instanceof Property) {
_matched = true;
final JvmField field = this._jvmTypesBuilder.toField(f, ((Property) f).getName(), ((Property) f).getType());
EList<JvmMember> _members_2 = it.getMembers();
this._jvmTypesBuilder.<JvmField>operator_add(_members_2, field);
EList<JvmMember> _members_3 = it.getMembers();
JvmOperation _getter = this._jvmTypesBuilder.toGetter(f, ((Property) f).getName(), ((Property) f).getType());
this._jvmTypesBuilder.<JvmOperation>operator_add(_members_3, _getter);
EList<JvmMember> _members_4 = it.getMembers();
JvmOperation _setter = this._jvmTypesBuilder.toSetter(f, ((Property) f).getName(), ((Property) f).getType());
this._jvmTypesBuilder.<JvmOperation>operator_add(_members_4, _setter);
}
if (!_matched) {
if (f instanceof Operation) {
_matched = true;
EList<JvmMember> _members_2 = it.getMembers();
String _name = ((Operation) f).getName();
JvmTypeReference _elvis = null;
JvmTypeReference _type = ((Operation) f).getType();
if (_type != null) {
_elvis = _type;
} else {
JvmTypeReference _inferredType = this._jvmTypesBuilder.inferredType();
_elvis = _inferredType;
}
final Procedure1<JvmOperation> _function_3 = (JvmOperation it_1) -> {
this._jvmTypesBuilder.setDocumentation(it_1, this._jvmTypesBuilder.getDocumentation(f));
EList<JvmFormalParameter> _params = ((Operation) f).getParams();
for (final JvmFormalParameter p : _params) {
EList<JvmFormalParameter> _parameters = it_1.getParameters();
JvmFormalParameter _parameter = this._jvmTypesBuilder.toParameter(p, p.getName(), p.getParameterType());
this._jvmTypesBuilder.<JvmFormalParameter>operator_add(_parameters, _parameter);
}
this._jvmTypesBuilder.setBody(it_1, ((Operation) f).getBody());
};
JvmOperation _method = this._jvmTypesBuilder.toMethod(f, _name, _elvis, _function_3);
this._jvmTypesBuilder.<JvmOperation>operator_add(_members_2, _method);
}
}
}
EList<JvmMember> _members_2 = it.getMembers();
JvmOperation _toStringMethod = this._jvmTypesBuilder.toToStringMethod(entity, it);
this._jvmTypesBuilder.<JvmOperation>operator_add(_members_2, _toStringMethod);
};
acceptor.<JvmGenericType>accept(this._jvmTypesBuilder.toClass(entity, this._iQualifiedNameProvider.getFullyQualifiedName(entity)), _function);
}
use of org.eclipse.xtext.example.domainmodel.domainmodel.Feature in project xtext-eclipse by eclipse.
the class DomainmodelFormatter method _format.
protected void _format(final Entity entity, @Extension final IFormattableDocument document) {
final ISemanticRegion open = this.textRegionExtensions.regionFor(entity).keyword("{");
final ISemanticRegion close = this.textRegionExtensions.regionFor(entity).keyword("}");
final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
it.oneSpace();
};
document.surround(this.textRegionExtensions.regionFor(entity).feature(DomainmodelPackage.Literals.ABSTRACT_ELEMENT__NAME), _function);
final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
it.oneSpace();
};
document.<JvmParameterizedTypeReference>surround(entity.getSuperType(), _function_1);
final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
it.newLine();
};
document.append(open, _function_2);
final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
it.indent();
};
document.<ISemanticRegion, ISemanticRegion>interior(open, close, _function_3);
this.format(entity.getSuperType(), document);
EList<Feature> _features = entity.getFeatures();
for (final Feature feature : _features) {
{
document.<Feature>format(feature);
final Procedure1<IHiddenRegionFormatter> _function_4 = (IHiddenRegionFormatter it) -> {
it.setNewLines(1, 1, 2);
};
document.<Feature>append(feature, _function_4);
}
}
}
Aggregations