Search in sources :

Example 1 with Attribute

use of org.applause.lang.applauseDsl.Attribute in project applause by applause.

the class EntitiesValidationTestHelper method isValidEntityWithAttributes.

public void isValidEntityWithAttributes(final CharSequence sequence) {
    try {
        final Model model = this._parseHelper.parse(sequence);
        EList<NamedElement> _elements = model.getElements();
        Iterable<Entity> _filter = Iterables.<Entity>filter(_elements, Entity.class);
        final Entity entity = IterableExtensions.<Entity>head(_filter);
        final EList<Attribute> attributes = entity.getAttributes();
        int _size = attributes.size();
        Matcher<Integer> _is = CoreMatchers.<Integer>is(Integer.valueOf(2));
        Assert.<Integer>assertThat(Integer.valueOf(_size), _is);
        EList<NamedElement> _elements_1 = model.getElements();
        final Function1<NamedElement, Boolean> _function = new Function1<NamedElement, Boolean>() {

            public Boolean apply(final NamedElement it) {
                String _name = it.getName();
                boolean _equals = Objects.equal(_name, "Date");
                return Boolean.valueOf(_equals);
            }
        };
        final NamedElement dateType = IterableExtensions.<NamedElement>findFirst(_elements_1, _function);
        EList<NamedElement> _elements_2 = model.getElements();
        final Function1<NamedElement, Boolean> _function_1 = new Function1<NamedElement, Boolean>() {

            public Boolean apply(final NamedElement it) {
                String _name = it.getName();
                boolean _equals = Objects.equal(_name, "String");
                return Boolean.valueOf(_equals);
            }
        };
        final NamedElement stringType = IterableExtensions.<NamedElement>findFirst(_elements_2, _function_1);
        final Attribute firstAttribute = IterableExtensions.<Attribute>head(attributes);
        String _name = firstAttribute.getName();
        Matcher<String> _is_1 = CoreMatchers.<String>is("name");
        Assert.<String>assertThat(_name, _is_1);
        Type _type = firstAttribute.getType();
        Matcher<NamedElement> _is_2 = CoreMatchers.<NamedElement>is(stringType);
        Assert.<Type>assertThat(_type, _is_2);
        final Attribute secondAttribute = IterableExtensions.<Attribute>last(attributes);
        String _name_1 = secondAttribute.getName();
        Matcher<String> _is_3 = CoreMatchers.<String>is("birthdate");
        Assert.<String>assertThat(_name_1, _is_3);
        Type _type_1 = secondAttribute.getType();
        Matcher<NamedElement> _is_4 = CoreMatchers.<NamedElement>is(dateType);
        Assert.<Type>assertThat(_type_1, _is_4);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : Entity(org.applause.lang.applauseDsl.Entity) Attribute(org.applause.lang.applauseDsl.Attribute) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) Type(org.applause.lang.applauseDsl.Type) Model(org.applause.lang.applauseDsl.Model) NamedElement(org.applause.lang.applauseDsl.NamedElement)

Example 2 with Attribute

use of org.applause.lang.applauseDsl.Attribute in project applause by applause.

the class EntitiesValidationTestHelper method isValidEntityWithOneToManyRelationship.

public void isValidEntityWithOneToManyRelationship(final CharSequence sequence) {
    try {
        final Model model = this._parseHelper.parse(sequence);
        EList<NamedElement> _elements = model.getElements();
        Iterable<Entity> _filter = Iterables.<Entity>filter(_elements, Entity.class);
        final Entity person = IterableExtensions.<Entity>head(_filter);
        EList<Attribute> _attributes = person.getAttributes();
        final Attribute friends = IterableExtensions.<Attribute>head(_attributes);
        boolean _isMany = friends.isMany();
        Matcher<Boolean> _is = CoreMatchers.<Boolean>is(Boolean.valueOf(true));
        Assert.<Boolean>assertThat(Boolean.valueOf(_isMany), _is);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : Entity(org.applause.lang.applauseDsl.Entity) Attribute(org.applause.lang.applauseDsl.Attribute) Model(org.applause.lang.applauseDsl.Model) NamedElement(org.applause.lang.applauseDsl.NamedElement)

Example 3 with Attribute

use of org.applause.lang.applauseDsl.Attribute in project applause by applause.

the class EntityDataMappingModuleFileCompiler method compileModuleFile.

public CharSequence compileModuleFile(final Entity it) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("#import \"");
    String _entityModelHeaderFileName = this._entityClassExtensions.entityModelHeaderFileName(it);
    _builder.append(_entityModelHeaderFileName, "");
    _builder.append("\"");
    _builder.newLineIfNotEmpty();
    _builder.append("#import \"");
    String _dataMappingHeaderFileName = this._dataMappingExtensions.dataMappingHeaderFileName(it);
    _builder.append(_dataMappingHeaderFileName, "");
    _builder.append("\"");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("@implementation ");
    String _typeName = this._typeExtensions.typeName(it);
    _builder.append(_typeName, "");
    _builder.append(" (DataMapping)");
    _builder.newLineIfNotEmpty();
    _builder.append("- (id)initWithAttributes:(NSDictionary *)attributes");
    _builder.newLine();
    _builder.append("{");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("self = [super init];");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("if (self) {");
    _builder.newLine();
    {
        EList<Attribute> _attributes = it.getAttributes();
        for (final Attribute attribute : _attributes) {
            _builder.append("\t\t");
            CharSequence _compileAttributeToPropertyMapping = this.compileAttributeToPropertyMapping(attribute);
            _builder.append(_compileAttributeToPropertyMapping, "		");
            _builder.newLineIfNotEmpty();
        }
    }
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("return self;");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("- (NSDictionary *)attributes");
    _builder.newLine();
    _builder.append("{");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];");
    _builder.newLine();
    {
        EList<Attribute> _attributes_1 = it.getAttributes();
        for (final Attribute attribute_1 : _attributes_1) {
            _builder.append("\t");
            CharSequence _compilePropertyToAttributeMapping = this.compilePropertyToAttributeMapping(attribute_1);
            _builder.append(_compilePropertyToAttributeMapping, "	");
            _builder.newLineIfNotEmpty();
        }
    }
    _builder.append("\t");
    _builder.append("return attributes;");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("@end");
    _builder.newLine();
    return _builder;
}
Also used : EList(org.eclipse.emf.common.util.EList) Attribute(org.applause.lang.applauseDsl.Attribute) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Example 4 with Attribute

use of org.applause.lang.applauseDsl.Attribute in project applause by applause.

the class ExpressionExtensions method _evaluateExpression.

protected String _evaluateExpression(final EntityMemberCallTail it) {
    Attribute _head = it.getHead();
    String _evaluateExpression = this.evaluateExpression(_head);
    String _plus = ("." + _evaluateExpression);
    String _xifexpression = null;
    EntityMemberCallTail _tail = it.getTail();
    boolean _notEquals = (!Objects.equal(_tail, null));
    if (_notEquals) {
        EntityMemberCallTail _tail_1 = it.getTail();
        String _evaluateExpression_1 = this.evaluateExpression(_tail_1);
        String _plus_1 = ("memberCallTail.tail:" + _evaluateExpression_1);
        _xifexpression = _plus_1;
    } else {
        _xifexpression = "";
    }
    String _plus_2 = (_plus + _xifexpression);
    return _plus_2;
}
Also used : Attribute(org.applause.lang.applauseDsl.Attribute) EntityMemberCallTail(org.applause.lang.applauseDsl.EntityMemberCallTail)

Example 5 with Attribute

use of org.applause.lang.applauseDsl.Attribute in project applause by applause.

the class ApplauseDslScopeProvider method _attributesScope.

private IScope _attributesScope(final Entity entity) {
    EList<Attribute> _attributes = entity.getAttributes();
    IScope _scopeFor = Scopes.scopeFor(_attributes);
    return _scopeFor;
}
Also used : Attribute(org.applause.lang.applauseDsl.Attribute) IScope(org.eclipse.xtext.scoping.IScope)

Aggregations

Attribute (org.applause.lang.applauseDsl.Attribute)11 Entity (org.applause.lang.applauseDsl.Entity)3 EList (org.eclipse.emf.common.util.EList)3 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)3 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)3 EntityMemberCallTail (org.applause.lang.applauseDsl.EntityMemberCallTail)2 Model (org.applause.lang.applauseDsl.Model)2 NamedElement (org.applause.lang.applauseDsl.NamedElement)2 Type (org.applause.lang.applauseDsl.Type)1 IScope (org.eclipse.xtext.scoping.IScope)1 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)1