All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.pelle.mango.dsl.generator.BaseEntityGenerator Maven / Gradle / Ivy

package io.pelle.mango.dsl.generator;

import com.google.common.base.Objects;
import com.google.inject.Inject;
import io.pelle.mango.client.base.vo.IAttributeDescriptor;
import io.pelle.mango.client.base.vo.IVOEntity;
import io.pelle.mango.dsl.generator.util.AttributeGeneratorFactory;
import io.pelle.mango.dsl.generator.util.NameUtils;
import io.pelle.mango.dsl.generator.util.TypeUtils;
import io.pelle.mango.dsl.mango.Entity;
import io.pelle.mango.dsl.mango.EntityAttribute;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.Extension;

@SuppressWarnings("all")
public abstract class BaseEntityGenerator {
  @Inject
  @Extension
  private NameUtils _nameUtils;
  
  public abstract TypeUtils getTypeUtils();
  
  public CharSequence attributeDescriptorsFromExtends(final Entity entity) {
    StringConcatenation _builder = new StringConcatenation();
    {
      Entity _extends = entity.getExtends();
      boolean _notEquals = (!Objects.equal(_extends, null));
      if (_notEquals) {
        {
          Entity _extends_1 = entity.getExtends();
          EList _attributes = _extends_1.getAttributes();
          for(final EntityAttribute attribute : _attributes) {
            TypeUtils _typeUtils = this.getTypeUtils();
            CharSequence _compileEntityAttributeDescriptor = _typeUtils.compileEntityAttributeDescriptor(attribute, entity);
            _builder.append(_compileEntityAttributeDescriptor, "");
            _builder.newLineIfNotEmpty();
          }
        }
      }
    }
    return _builder;
  }
  
  public CharSequence compileGetAttributeDescriptors(final Entity entity, final List extraAttributes) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.newLine();
    _builder.append("public static ");
    String _name = IAttributeDescriptor.class.getName();
    _builder.append(_name, "");
    _builder.append("[] getAttributeDescriptors() {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("return new ");
    String _name_1 = IAttributeDescriptor.class.getName();
    _builder.append(_name_1, "\t");
    _builder.append("[]{");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("\t\t");
    String _attributeConstantName = this._nameUtils.attributeConstantName(IVOEntity.ID_FIELD_NAME);
    _builder.append(_attributeConstantName, "\t\t");
    _builder.append(",");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    {
      EList _attributes = entity.getAttributes();
      for(final EntityAttribute attribute : _attributes) {
        _builder.append("\t\t");
        String _name_2 = attribute.getName();
        String _attributeConstantName_1 = this._nameUtils.attributeConstantName(_name_2);
        _builder.append(_attributeConstantName_1, "\t\t");
        _builder.append(",");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.append("\t\t");
    _builder.newLine();
    {
      Entity _extends = entity.getExtends();
      boolean _notEquals = (!Objects.equal(_extends, null));
      if (_notEquals) {
        {
          Entity _extends_1 = entity.getExtends();
          EList _attributes_1 = _extends_1.getAttributes();
          for(final EntityAttribute attribute_1 : _attributes_1) {
            _builder.append("\t\t");
            String _name_3 = attribute_1.getName();
            String _attributeConstantName_2 = this._nameUtils.attributeConstantName(_name_3);
            _builder.append(_attributeConstantName_2, "\t\t");
            _builder.append(",");
            _builder.newLineIfNotEmpty();
          }
        }
      }
    }
    _builder.append("\t\t");
    _builder.newLine();
    {
      TypeUtils _typeUtils = this.getTypeUtils();
      List _infoVOEntityAttributes = _typeUtils.infoVOEntityAttributes();
      for(final AttributeGeneratorFactory.AttributeGenerator infoVOEntityAttribute : _infoVOEntityAttributes) {
        _builder.append("\t\t");
        String _attributeName = infoVOEntityAttribute.getAttributeName();
        String _attributeDescriptorConstantName = this._nameUtils.attributeDescriptorConstantName(_attributeName);
        _builder.append(_attributeDescriptorConstantName, "\t\t");
        _builder.append(",");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.append("\t\t");
    _builder.newLine();
    {
      for(final AttributeGeneratorFactory.AttributeGenerator extraAttribute : extraAttributes) {
        _builder.append("\t\t");
        String _attributeName_1 = extraAttribute.getAttributeName();
        String _attributeDescriptorConstantName_1 = this._nameUtils.attributeDescriptorConstantName(_attributeName_1);
        _builder.append(_attributeDescriptorConstantName_1, "\t\t");
        _builder.append(",");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.append("\t");
    _builder.append("};");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy