Search in sources :

Example 1 with ComplexTypeDeclaration

use of com.robotoworks.mechanoid.net.netModel.ComplexTypeDeclaration in project mechanoid by robotoworks.

the class ResultGenerator method generateResponseClass.

public CharSequence generateResponseClass(final HttpMethod method, final Model module, final Client client) {
    StringConcatenation _builder = new StringConcatenation();
    final ResponseBlock responseBlock = ModelExtensions.getResponseBlock(method);
    _builder.newLineIfNotEmpty();
    _builder.append("public class ");
    String _name = method.getName();
    String _pascalize = Strings.pascalize(_name);
    _builder.append(_pascalize, "");
    _builder.append("Result extends ServiceResult {");
    _builder.newLineIfNotEmpty();
    {
        BlockType _type = null;
        if (responseBlock != null) {
            _type = responseBlock.getType();
        }
        boolean _notEquals = (!Objects.equal(_type, null));
        if (_notEquals) {
            _builder.append("\t");
            BlockType _type_1 = responseBlock.getType();
            CharSequence _generateFieldForType = this.generateFieldForType(_type_1);
            _builder.append(_generateFieldForType, "\t");
            _builder.append("\t");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            BlockType _type_2 = responseBlock.getType();
            CharSequence _generateGetterForType = this.generateGetterForType(_type_2);
            _builder.append(_generateGetterForType, "\t");
            _builder.append("\t");
            _builder.newLineIfNotEmpty();
        }
    }
    {
        ComplexTypeDeclaration _superType = null;
        if (responseBlock != null) {
            _superType = responseBlock.getSuperType();
        }
        boolean _notEquals_1 = (!Objects.equal(_superType, null));
        if (_notEquals_1) {
            _builder.append("\t");
            _builder.append("private ");
            ComplexTypeDeclaration _superType_1 = responseBlock.getSuperType();
            String _name_1 = _superType_1.getName();
            String _pascalize_1 = Strings.pascalize(_name_1);
            _builder.append(_pascalize_1, "\t");
            _builder.append(" base;");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            ComplexTypeDeclaration _superType_2 = responseBlock.getSuperType();
            ComplexTypeLiteral _literal = _superType_2.getLiteral();
            EList<Member> _members = _literal.getMembers();
            final Function1<Member, Boolean> _function = new Function1<Member, Boolean>() {

                public Boolean apply(final Member superMember) {
                    BlockType _type = null;
                    if (responseBlock != null) {
                        _type = responseBlock.getType();
                    }
                    if ((_type instanceof ComplexTypeLiteral)) {
                        BlockType _type_1 = responseBlock.getType();
                        EList<Member> _members = ((ComplexTypeLiteral) _type_1).getMembers();
                        final Function1<Member, Boolean> _function = new Function1<Member, Boolean>() {

                            public Boolean apply(final Member member) {
                                String _name = superMember.getName();
                                String _name_1 = member.getName();
                                return Boolean.valueOf(_name.equals(_name_1));
                            }
                        };
                        Member _findFirst = IterableExtensions.<Member>findFirst(_members, _function);
                        return Boolean.valueOf(Objects.equal(_findFirst, null));
                    }
                    return Boolean.valueOf(true);
                }
            };
            Iterable<Member> _filter = IterableExtensions.<Member>filter(_members, _function);
            CharSequence _generateBaseAccessors = this.generateBaseAccessors(_filter);
            _builder.append(_generateBaseAccessors, "\t");
            _builder.newLineIfNotEmpty();
        }
    }
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public ");
    String _name_2 = method.getName();
    String _pascalize_2 = Strings.pascalize(_name_2);
    _builder.append(_pascalize_2, "\t");
    _builder.append("Result(JsonEntityReaderProvider provider, InputStream inStream) throws IOException {");
    _builder.newLineIfNotEmpty();
    {
        boolean _notEquals_2 = (!Objects.equal(responseBlock, null));
        if (_notEquals_2) {
            {
                boolean _or = false;
                BlockType _type_3 = responseBlock.getType();
                if ((_type_3 instanceof ComplexTypeLiteral)) {
                    _or = true;
                } else {
                    ComplexTypeDeclaration _superType_3 = responseBlock.getSuperType();
                    boolean _notEquals_3 = (!Objects.equal(_superType_3, null));
                    _or = _notEquals_3;
                }
                if (_or) {
                    _builder.append("\t");
                    CharSequence _generateDeserializationStatementHeader = this.generateDeserializationStatementHeader(true);
                    _builder.append(_generateDeserializationStatementHeader, "\t");
                    _builder.newLineIfNotEmpty();
                    {
                        ComplexTypeDeclaration _superType_4 = responseBlock.getSuperType();
                        boolean _notEquals_4 = (!Objects.equal(_superType_4, null));
                        if (_notEquals_4) {
                            _builder.append("\t");
                            _builder.append("\t");
                            _builder.append("this.base = new ");
                            ComplexTypeDeclaration _superType_5 = responseBlock.getSuperType();
                            String _name_3 = _superType_5.getName();
                            String _pascalize_3 = Strings.pascalize(_name_3);
                            _builder.append(_pascalize_3, "\t\t");
                            _builder.append("();");
                            _builder.newLineIfNotEmpty();
                        }
                    }
                    {
                        BlockType _type_4 = responseBlock.getType();
                        if ((_type_4 instanceof ComplexTypeLiteral)) {
                            _builder.append("\t");
                            _builder.append("\t");
                            String _name_4 = method.getName();
                            String _pascalize_4 = Strings.pascalize(_name_4);
                            _builder.append(_pascalize_4, "\t\t");
                            _builder.append("Result subject = this;");
                            _builder.newLineIfNotEmpty();
                            _builder.append("\t");
                            _builder.append("\t");
                            BlockType _type_5 = responseBlock.getType();
                            ComplexTypeDeclaration _superType_6 = null;
                            if (responseBlock != null) {
                                _superType_6 = responseBlock.getSuperType();
                            }
                            ComplexTypeLiteral _literal_1 = null;
                            if (_superType_6 != null) {
                                _literal_1 = _superType_6.getLiteral();
                            }
                            EList<Member> _mergeMembers = this.mergeMembers(((ComplexTypeLiteral) _type_5), _literal_1);
                            CharSequence _genReadComplexTypeLiteralForMembers = this.jsonReaderGenerator.genReadComplexTypeLiteralForMembers(_mergeMembers);
                            _builder.append(_genReadComplexTypeLiteralForMembers, "\t\t");
                            _builder.newLineIfNotEmpty();
                        }
                    }
                    _builder.append("\t");
                    CharSequence _generateDeserializationStatementFooter = this.generateDeserializationStatementFooter(true);
                    _builder.append(_generateDeserializationStatementFooter, "\t");
                    _builder.newLineIfNotEmpty();
                } else {
                    _builder.append("\t");
                    BlockType _type_6 = responseBlock.getType();
                    CharSequence _generateDeserializationStatementForType = this.generateDeserializationStatementForType(responseBlock, ((Type) _type_6));
                    _builder.append(_generateDeserializationStatementForType, "\t");
                    _builder.newLineIfNotEmpty();
                }
            }
        } else {
            _builder.append("\t");
            _builder.append("Closeables.closeSilently(inStream);");
            _builder.newLine();
        }
    }
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder;
}
Also used : ComplexTypeDeclaration(com.robotoworks.mechanoid.net.netModel.ComplexTypeDeclaration) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) Type(com.robotoworks.mechanoid.net.netModel.Type) BlockType(com.robotoworks.mechanoid.net.netModel.BlockType) IntrinsicType(com.robotoworks.mechanoid.net.netModel.IntrinsicType) UserType(com.robotoworks.mechanoid.net.netModel.UserType) GenericListType(com.robotoworks.mechanoid.net.netModel.GenericListType) BasicEList(org.eclipse.emf.common.util.BasicEList) EList(org.eclipse.emf.common.util.EList) BlockType(com.robotoworks.mechanoid.net.netModel.BlockType) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ResponseBlock(com.robotoworks.mechanoid.net.netModel.ResponseBlock) ComplexTypeLiteral(com.robotoworks.mechanoid.net.netModel.ComplexTypeLiteral) TypedMember(com.robotoworks.mechanoid.net.netModel.TypedMember) Member(com.robotoworks.mechanoid.net.netModel.Member) SkipMember(com.robotoworks.mechanoid.net.netModel.SkipMember)

Example 2 with ComplexTypeDeclaration

use of com.robotoworks.mechanoid.net.netModel.ComplexTypeDeclaration in project mechanoid by robotoworks.

the class EntityReaderProviderGenerator method generateType.

public CharSequence generateType(final Client client, final Model model) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("public class Default");
    String _name = client.getName();
    _builder.append(_name, "");
    _builder.append("ReaderProvider implements JsonEntityReaderProvider {");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private HashMap<Class<?>, JsonEntityReader<?>> mMap = new HashMap<Class<?>, JsonEntityReader<?>>();");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public Default");
    String _name_1 = client.getName();
    _builder.append(_name_1, "\t");
    _builder.append("ReaderProvider(){");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("registerReaders(mMap);");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@SuppressWarnings(\"unchecked\")");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public <T, R extends JsonEntityReader<T>> R get(Class<T> entityType) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return (R) mMap.get(entityType);");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("protected void registerReaders(HashMap<Class<?>, JsonEntityReader<?>> map) {");
    _builder.newLine();
    {
        EList<Declaration> _declarations = model.getDeclarations();
        Iterable<ComplexTypeDeclaration> _filter = Iterables.<ComplexTypeDeclaration>filter(_declarations, ComplexTypeDeclaration.class);
        for (final ComplexTypeDeclaration entity : _filter) {
            _builder.append("\t\t");
            _builder.append("map.put(");
            String _name_2 = entity.getName();
            _builder.append(_name_2, "\t\t");
            _builder.append(".class, new ");
            String _name_3 = entity.getName();
            _builder.append(_name_3, "\t\t");
            _builder.append("Reader(this));");
            _builder.newLineIfNotEmpty();
        }
    }
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder;
}
Also used : ComplexTypeDeclaration(com.robotoworks.mechanoid.net.netModel.ComplexTypeDeclaration) EList(org.eclipse.emf.common.util.EList) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Example 3 with ComplexTypeDeclaration

use of com.robotoworks.mechanoid.net.netModel.ComplexTypeDeclaration in project mechanoid by robotoworks.

the class EntityWriterProviderGenerator method generateType.

public CharSequence generateType(final Client client, final Model model) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("public class Default");
    String _name = client.getName();
    _builder.append(_name, "");
    _builder.append("WriterProvider implements JsonEntityWriterProvider {");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private HashMap<Class<?>, JsonEntityWriter<?>> mMap = new HashMap<Class<?>, JsonEntityWriter<?>>();");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public Default");
    String _name_1 = client.getName();
    _builder.append(_name_1, "\t");
    _builder.append("WriterProvider(){");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("registerWriters(mMap);");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@SuppressWarnings(\"unchecked\")");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public <T, R extends JsonEntityWriter<T>> R get(Class<T> entityType) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return (R) mMap.get(entityType);");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("protected void registerWriters(HashMap<Class<?>, JsonEntityWriter<?>> map) {");
    _builder.newLine();
    {
        EList<Declaration> _declarations = model.getDeclarations();
        Iterable<ComplexTypeDeclaration> _filter = Iterables.<ComplexTypeDeclaration>filter(_declarations, ComplexTypeDeclaration.class);
        for (final ComplexTypeDeclaration entity : _filter) {
            _builder.append("\t\t");
            _builder.append("map.put(");
            String _name_2 = entity.getName();
            _builder.append(_name_2, "\t\t");
            _builder.append(".class, new ");
            String _name_3 = entity.getName();
            _builder.append(_name_3, "\t\t");
            _builder.append("Writer(this));");
            _builder.newLineIfNotEmpty();
        }
    }
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder;
}
Also used : ComplexTypeDeclaration(com.robotoworks.mechanoid.net.netModel.ComplexTypeDeclaration) EList(org.eclipse.emf.common.util.EList) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Example 4 with ComplexTypeDeclaration

use of com.robotoworks.mechanoid.net.netModel.ComplexTypeDeclaration in project mechanoid by robotoworks.

the class ResponseBlockImpl method setSuperType.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setSuperType(ComplexTypeDeclaration newSuperType) {
    ComplexTypeDeclaration oldSuperType = superType;
    superType = newSuperType;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, NetModelPackage.RESPONSE_BLOCK__SUPER_TYPE, oldSuperType, superType));
}
Also used : ComplexTypeDeclaration(com.robotoworks.mechanoid.net.netModel.ComplexTypeDeclaration) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Aggregations

ComplexTypeDeclaration (com.robotoworks.mechanoid.net.netModel.ComplexTypeDeclaration)4 EList (org.eclipse.emf.common.util.EList)3 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)3 BlockType (com.robotoworks.mechanoid.net.netModel.BlockType)1 ComplexTypeLiteral (com.robotoworks.mechanoid.net.netModel.ComplexTypeLiteral)1 GenericListType (com.robotoworks.mechanoid.net.netModel.GenericListType)1 IntrinsicType (com.robotoworks.mechanoid.net.netModel.IntrinsicType)1 Member (com.robotoworks.mechanoid.net.netModel.Member)1 ResponseBlock (com.robotoworks.mechanoid.net.netModel.ResponseBlock)1 SkipMember (com.robotoworks.mechanoid.net.netModel.SkipMember)1 Type (com.robotoworks.mechanoid.net.netModel.Type)1 TypedMember (com.robotoworks.mechanoid.net.netModel.TypedMember)1 UserType (com.robotoworks.mechanoid.net.netModel.UserType)1 BasicEList (org.eclipse.emf.common.util.BasicEList)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)1