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

com.reprezen.genflow.common.xtend.ZenModelHelper Maven / Gradle / Ivy

/**
 * Copyright © 2013, 2016 Modelsolv, Inc.
 * All Rights Reserved.
 * 
 * NOTICE: All information contained herein is, and remains the property
 * of ModelSolv, Inc. See the file license.html in the root directory of
 * this project for further information.
 */
package com.reprezen.genflow.common.xtend;

import com.google.common.collect.Iterables;
import com.reprezen.rapidml.Documentable;
import com.reprezen.rapidml.Documentation;
import com.reprezen.rapidml.Enumeration;
import com.reprezen.rapidml.Feature;
import com.reprezen.rapidml.ObjectRealization;
import com.reprezen.rapidml.PrimitiveProperty;
import com.reprezen.rapidml.PropertyRealization;
import com.reprezen.rapidml.RealizationContainer;
import com.reprezen.rapidml.ReferenceElement;
import com.reprezen.rapidml.ReferenceEmbed;
import com.reprezen.rapidml.ReferenceLink;
import com.reprezen.rapidml.ReferenceProperty;
import com.reprezen.rapidml.ReferenceTreatment;
import com.reprezen.rapidml.ResourceAPI;
import com.reprezen.rapidml.ServiceDataResource;
import com.reprezen.rapidml.SimpleType;
import com.reprezen.rapidml.SingleValueType;
import com.reprezen.rapidml.TypedMessage;
import com.reprezen.rapidml.UserDefinedType;
import com.reprezen.rapidml.ZenModel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ListExtensions;

@SuppressWarnings("all")
public class ZenModelHelper {
  protected List _getReferenceTreatmentIncludedProperties(final ReferenceEmbed refEmbed) {
    final ArrayList includedProps = new ArrayList();
    includedProps.addAll(this.getIncludedPrimitiveProperties(refEmbed));
    includedProps.addAll(refEmbed.getNestedReferenceTreatments());
    return includedProps;
  }
  
  protected List _getReferenceTreatmentIncludedProperties(final ReferenceLink refEmbed) {
    return this.getIncludedPrimitiveProperties(refEmbed);
  }
  
  public List getIncludedPrimitiveProperties(final ReferenceTreatment refTreatment) {
    final Function1 _function = (Feature e) -> {
      return Boolean.valueOf((e instanceof PrimitiveProperty));
    };
    return IterableExtensions.toList(IterableExtensions.filter(this.getIncludedProperties(refTreatment), _function));
  }
  
  public List getIncludedProperties(final ReferenceTreatment refLink) {
    List _elvis = null;
    ObjectRealization _linkDescriptor = refLink.getLinkDescriptor();
    EList _allIncludedProperties = null;
    if (_linkDescriptor!=null) {
      _allIncludedProperties=_linkDescriptor.getAllIncludedProperties();
    }
    List _map = null;
    if (_allIncludedProperties!=null) {
      final Function1 _function = (PropertyRealization it) -> {
        return it.getBaseProperty();
      };
      _map=ListExtensions.map(_allIncludedProperties, _function);
    }
    if (_map != null) {
      _elvis = _map;
    } else {
      List _emptyList = Collections.emptyList();
      _elvis = _emptyList;
    }
    return _elvis;
  }
  
  public boolean hasReferenceTreatment(final RealizationContainer resource, final Feature feature) {
    final Function1 _function = (ReferenceTreatment it) -> {
      return it.getReferenceElement();
    };
    final Function1 _function_1 = (ReferenceElement f) -> {
      return Boolean.valueOf((f == feature));
    };
    return IterableExtensions.exists(ListExtensions.map(resource.getReferenceTreatments(), _function), _function_1);
  }
  
  public boolean hasReferenceTreatment(final TypedMessage resource, final Feature feature) {
    final Function1 _function = (ReferenceTreatment it) -> {
      return it.getReferenceElement();
    };
    final Function1 _function_1 = (ReferenceElement f) -> {
      return Boolean.valueOf((f == feature));
    };
    return IterableExtensions.exists(ListExtensions.map(resource.getReferenceTreatments(), _function), _function_1);
  }
  
  protected Collection _getUsedEnums(final Object o) {
    String _string = Arrays.asList(o).toString();
    String _plus = ("Unhandled parameter types: " + _string);
    throw new IllegalArgumentException(_plus);
  }
  
  protected Collection _getUsedEnums(final ZenModel model) {
    final Function1> _function = (ResourceAPI it) -> {
      return this.getUsedEnums(it);
    };
    return IterableExtensions.toSet(Iterables.concat(ListExtensions.>map(model.getResourceAPIs(), _function)));
  }
  
  protected Collection _getUsedEnums(final ResourceAPI resourceAPI) {
    final Function1> _function = (ServiceDataResource dataInterface) -> {
      return this.getUsedEnums(dataInterface);
    };
    return IterableExtensions.toSet(Iterables.concat(IterableExtensions.>map(Iterables.filter(resourceAPI.getOwnedResourceDefinitions(), ServiceDataResource.class), _function)));
  }
  
  protected Collection _getUsedEnums(final ServiceDataResource resource) {
    final Function1 _function = (PropertyRealization e) -> {
      boolean _hasReferenceTreatment = this.hasReferenceTreatment(resource, e.getBaseProperty());
      return Boolean.valueOf((!_hasReferenceTreatment));
    };
    final Function1> _function_1 = (PropertyRealization it) -> {
      return this.getUsedEnums(it.getBaseProperty());
    };
    Iterable _flatten = Iterables.concat(IterableExtensions.>map(IterableExtensions.filter(resource.getIncludedProperties(), _function), _function_1));
    final Function1> _function_2 = (ReferenceEmbed it) -> {
      return this.getUsedEnums(it);
    };
    Iterable _flatten_1 = Iterables.concat(IterableExtensions.>map(Iterables.filter(resource.getReferenceTreatments(), ReferenceEmbed.class), _function_2));
    return IterableExtensions.toSet(Iterables.concat(_flatten, _flatten_1));
  }
  
  protected Collection _getUsedEnums(final ReferenceTreatment ref) {
    final Function1> _function = (Object it) -> {
      return this.getUsedEnums(it);
    };
    return IterableExtensions.toSet(Iterables.concat(ListExtensions.map(this.getReferenceTreatmentIncludedProperties(ref), _function)));
  }
  
  protected Collection _getUsedEnums(final PrimitiveProperty pp) {
    List _xifexpression = null;
    SingleValueType _type = pp.getType();
    if ((_type instanceof Enumeration)) {
      SingleValueType _type_1 = pp.getType();
      _xifexpression = Collections.singletonList(((Enumeration) _type_1));
    } else {
      _xifexpression = Collections.emptyList();
    }
    return _xifexpression;
  }
  
  protected Collection _getUsedEnums(final ReferenceProperty ref) {
    return Collections.emptyList();
  }
  
  protected Collection _getUsedUserDefinedTypes(final Object o) {
    String _string = Arrays.asList(o).toString();
    String _plus = ("Unhandled parameter types: " + _string);
    throw new IllegalArgumentException(_plus);
  }
  
  protected Collection _getUsedUserDefinedTypes(final ZenModel model) {
    final Function1> _function = (ResourceAPI it) -> {
      return this.getUsedUserDefinedTypes(it);
    };
    return IterableExtensions.toSet(Iterables.concat(ListExtensions.>map(model.getResourceAPIs(), _function)));
  }
  
  protected Collection _getUsedUserDefinedTypes(final ResourceAPI resourceAPI) {
    final Function1> _function = (ServiceDataResource dataInterface) -> {
      return this.getUsedUserDefinedTypes(dataInterface);
    };
    return IterableExtensions.toSet(Iterables.concat(IterableExtensions.>map(Iterables.filter(resourceAPI.getOwnedResourceDefinitions(), ServiceDataResource.class), _function)));
  }
  
  protected Collection _getUsedUserDefinedTypes(final ServiceDataResource resource) {
    final Function1 _function = (PropertyRealization e) -> {
      boolean _hasReferenceTreatment = this.hasReferenceTreatment(resource, e.getBaseProperty());
      return Boolean.valueOf((!_hasReferenceTreatment));
    };
    final Function1> _function_1 = (PropertyRealization it) -> {
      return this.getUsedUserDefinedTypes(it.getBaseProperty());
    };
    Iterable _flatten = Iterables.concat(IterableExtensions.>map(IterableExtensions.filter(resource.getIncludedProperties(), _function), _function_1));
    final Function1> _function_2 = (ReferenceEmbed it) -> {
      return this.getUsedUserDefinedTypes(it);
    };
    Iterable _flatten_1 = Iterables.concat(IterableExtensions.>map(Iterables.filter(resource.getReferenceTreatments(), ReferenceEmbed.class), _function_2));
    return IterableExtensions.toSet(Iterables.concat(_flatten, _flatten_1));
  }
  
  protected Collection _getUsedUserDefinedTypes(final ReferenceTreatment ref) {
    final Function1> _function = (Object it) -> {
      return this.getUsedUserDefinedTypes(it);
    };
    return IterableExtensions.toSet(Iterables.concat(ListExtensions.map(this.getReferenceTreatmentIncludedProperties(ref), _function)));
  }
  
  protected Collection _getUsedUserDefinedTypes(final PrimitiveProperty pp) {
    List _xifexpression = null;
    SingleValueType _type = pp.getType();
    if ((_type instanceof UserDefinedType)) {
      List _xblockexpression = null;
      {
        List list = new ArrayList();
        SingleValueType _type_1 = pp.getType();
        list.add(((UserDefinedType) _type_1));
        SingleValueType _type_2 = pp.getType();
        SimpleType parent = ((UserDefinedType) _type_2).getBaseType();
        while ((parent instanceof UserDefinedType)) {
          {
            list.add(((UserDefinedType) parent));
            parent = ((UserDefinedType) parent).getBaseType();
          }
        }
        _xblockexpression = list;
      }
      _xifexpression = _xblockexpression;
    } else {
      _xifexpression = Collections.emptyList();
    }
    return _xifexpression;
  }
  
  protected Collection _getUsedUserDefinedTypes(final ReferenceProperty ref) {
    return Collections.emptyList();
  }
  
  public String getDocumentation(final EObject obj) {
    String _xifexpression = null;
    if ((obj instanceof Documentable)) {
      String _xblockexpression = null;
      {
        String _elvis = null;
        Documentation _documentation = ((Documentable) obj).getDocumentation();
        String _text = null;
        if (_documentation!=null) {
          _text=_documentation.getText();
        }
        if (_text != null) {
          _elvis = _text;
        } else {
          _elvis = "";
        }
        final String doc = _elvis;
        _xblockexpression = doc.trim();
      }
      _xifexpression = _xblockexpression;
    } else {
      _xifexpression = "";
    }
    return _xifexpression;
  }
  
  protected List getReferenceTreatmentIncludedProperties(final ReferenceTreatment refEmbed) {
    if (refEmbed instanceof ReferenceEmbed) {
      return _getReferenceTreatmentIncludedProperties((ReferenceEmbed)refEmbed);
    } else if (refEmbed instanceof ReferenceLink) {
      return _getReferenceTreatmentIncludedProperties((ReferenceLink)refEmbed);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.asList(refEmbed).toString());
    }
  }
  
  public Collection getUsedEnums(final Object resource) {
    if (resource instanceof ServiceDataResource) {
      return _getUsedEnums((ServiceDataResource)resource);
    } else if (resource instanceof PrimitiveProperty) {
      return _getUsedEnums((PrimitiveProperty)resource);
    } else if (resource instanceof ReferenceProperty) {
      return _getUsedEnums((ReferenceProperty)resource);
    } else if (resource instanceof ResourceAPI) {
      return _getUsedEnums((ResourceAPI)resource);
    } else if (resource instanceof ReferenceTreatment) {
      return _getUsedEnums((ReferenceTreatment)resource);
    } else if (resource instanceof ZenModel) {
      return _getUsedEnums((ZenModel)resource);
    } else if (resource != null) {
      return _getUsedEnums(resource);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.asList(resource).toString());
    }
  }
  
  public Collection getUsedUserDefinedTypes(final Object resource) {
    if (resource instanceof ServiceDataResource) {
      return _getUsedUserDefinedTypes((ServiceDataResource)resource);
    } else if (resource instanceof PrimitiveProperty) {
      return _getUsedUserDefinedTypes((PrimitiveProperty)resource);
    } else if (resource instanceof ReferenceProperty) {
      return _getUsedUserDefinedTypes((ReferenceProperty)resource);
    } else if (resource instanceof ResourceAPI) {
      return _getUsedUserDefinedTypes((ResourceAPI)resource);
    } else if (resource instanceof ReferenceTreatment) {
      return _getUsedUserDefinedTypes((ReferenceTreatment)resource);
    } else if (resource instanceof ZenModel) {
      return _getUsedUserDefinedTypes((ZenModel)resource);
    } else if (resource != null) {
      return _getUsedUserDefinedTypes(resource);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.asList(resource).toString());
    }
  }
}