Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.reprezen.genflow.rapidml.csharp.generators.ResourceAPIGenerator Maven / Gradle / Ivy
package com.reprezen.genflow.rapidml.csharp.generators;
import com.google.common.base.Objects;
import com.reprezen.genflow.api.template.IGenTemplateContext;
import com.reprezen.genflow.rapidml.csharp.Config;
import com.reprezen.genflow.rapidml.csharp.helpers.DocHelper;
import com.reprezen.genflow.rapidml.csharp.helpers.FileHelper;
import com.reprezen.genflow.rapidml.csharp.helpers.FileRole;
import com.reprezen.genflow.rapidml.csharp.helpers.NameHelper;
import com.reprezen.genflow.rapidml.csharp.helpers.SnippetHelper;
import com.reprezen.genflow.rapidml.csharp.helpers.TypeHelper;
import com.reprezen.genflow.rapidml.csharp.helpers.UtilsHelper;
import com.reprezen.rapidml.CollectionResource;
import com.reprezen.rapidml.DataModel;
import com.reprezen.rapidml.HTTPMethods;
import com.reprezen.rapidml.MessageParameter;
import com.reprezen.rapidml.Method;
import com.reprezen.rapidml.ObjectResource;
import com.reprezen.rapidml.ResourceAPI;
import com.reprezen.rapidml.ResourceDefinition;
import com.reprezen.rapidml.ServiceDataResource;
import com.reprezen.rapidml.SingleValueType;
import com.reprezen.rapidml.Structure;
import com.reprezen.rapidml.TypedMessage;
import com.reprezen.rapidml.TypedRequest;
import com.reprezen.rapidml.TypedResponse;
import com.reprezen.rapidml.URI;
import com.reprezen.rapidml.URIParameter;
import com.reprezen.rapidml.URISegment;
import com.reprezen.rapidml.ZenModel;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
@SuppressWarnings("all")
public class ResourceAPIGenerator {
private final ZenModel model;
private final IGenTemplateContext context;
private final Config config;
@Extension
private NameHelper nameHelper;
@Extension
private TypeHelper typeHelper;
@Extension
private SnippetHelper snippetHelper;
public ResourceAPIGenerator(final ZenModel model, final IGenTemplateContext context, final Config config) {
this.model = model;
this.context = context;
this.config = config;
NameHelper _forModel = NameHelper.forModel(model);
this.nameHelper = _forModel;
TypeHelper _forModel_1 = TypeHelper.forModel(model);
this.typeHelper = _forModel_1;
SnippetHelper _snippetHelper = new SnippetHelper(config);
this.snippetHelper = _snippetHelper;
}
public void generate() {
EList _resourceAPIs = this.model.getResourceAPIs();
for (final ResourceAPI api : _resourceAPIs) {
EList _ownedResourceDefinitions = api.getOwnedResourceDefinitions();
for (final ResourceDefinition resource : _ownedResourceDefinitions) {
{
this.generateInterface(resource);
boolean _isGenerateDelegateController = this.config.isGenerateDelegateController();
if (_isGenerateDelegateController) {
this.generateDelegateController(resource);
this.generateAbstractDelegateHandler(resource);
}
}
}
}
}
private Path generateInterface(final ResourceDefinition resource) {
Path _xblockexpression = null;
{
final String name = this.nameHelper.getResourceName(resource);
@Extension
final FileHelper fileHelper = FileHelper.of(resource, FileRole.INTERFACE, this.context, this.config);
this.useDataModels(fileHelper, resource);
StringConcatenation _builder = new StringConcatenation();
CharSequence _simpleDoc = DocHelper.simpleDoc(resource);
_builder.append(_simpleDoc, "");
CharSequence _generatedAttr = UtilsHelper.generatedAttr();
_builder.append(_generatedAttr, "");
_builder.newLineIfNotEmpty();
_builder.append("public interface I");
_builder.append(name, "");
_builder.append("Controller {");
_builder.newLineIfNotEmpty();
{
EList _methods = resource.getMethods();
for(final Method method : _methods) {
_builder.append(" ");
CharSequence _returnType = this.getReturnType(method);
_builder.append(_returnType, " ");
_builder.append(" ");
String _name = method.getName();
String _initialUpper = this.nameHelper.initialUpper(_name);
_builder.append(_initialUpper, " ");
_builder.append("(");
String _signature = this.getSignature(method);
_builder.append(_signature, " ");
_builder.append(");");
_builder.newLineIfNotEmpty();
}
}
_builder.append("}");
_builder.newLine();
final String content = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("I");
_builder_1.append(name, "");
_builder_1.append("Controller");
String _csharpFileName = fileHelper.getCsharpFileName(_builder_1);
_xblockexpression = fileHelper.writeFile(content, _csharpFileName);
}
return _xblockexpression;
}
private Path generateDelegateController(final ResourceDefinition resource) {
Path _xblockexpression = null;
{
final String name = this.nameHelper.getResourceName(resource);
EObject _eContainer = resource.eContainer();
final ResourceAPI api = ((ResourceAPI) _eContainer);
@Extension
final FileHelper fileHelper = FileHelper.of(resource, FileRole.DELEGATE_CONTROLLER, this.context, this.config);
this.useDataModels(fileHelper, resource);
StringConcatenation _builder = new StringConcatenation();
CharSequence _simpleDoc = DocHelper.simpleDoc(resource);
_builder.append(_simpleDoc, "");
CharSequence _routingAttrs = this.getRoutingAttrs(api);
_builder.append(_routingAttrs, "");
CharSequence _generatedAttr = UtilsHelper.generatedAttr();
_builder.append(_generatedAttr, "");
_builder.newLineIfNotEmpty();
_builder.append("public partial class ");
_builder.append(name, "");
_builder.append("DelegateController : ");
String _apiController = this.snippetHelper.apiController();
_builder.append(_apiController, "");
_builder.append(", I");
_builder.append(name, "");
_builder.append("Controller {");
_builder.newLineIfNotEmpty();
{
EList _methods = resource.getMethods();
for(final Method method : _methods) {
_builder.append(" ");
String _name = method.getName();
final String methName = this.nameHelper.initialUpper(_name);
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.newLine();
_builder.append(" ");
_builder.append("public delegate void ");
_builder.append(methName, " ");
_builder.append("_PreProcessDelegate(");
String _signature = this.getSignature(method);
_builder.append(_signature, " ");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("public static ");
_builder.append(methName, " ");
_builder.append("_PreProcessDelegate ");
_builder.append(methName, " ");
_builder.append("_PreProcess;");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("public delegate ");
CharSequence _delegateReturnType = this.getDelegateReturnType(method);
_builder.append(_delegateReturnType, " ");
_builder.append(" ");
_builder.append(methName, " ");
_builder.append("_ProcessDelegate(");
String _signature_1 = this.getSignature(method);
_builder.append(_signature_1, " ");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("public static ");
_builder.append(methName, " ");
_builder.append("_ProcessDelegate ");
_builder.append(methName, " ");
_builder.append("_Process;");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("public delegate void ");
_builder.append(methName, " ");
_builder.append("_PostProcessDelegate(");
String _signature_2 = this.getSignature(method, true);
_builder.append(_signature_2, " ");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("public static ");
_builder.append(methName, " ");
_builder.append("_PostProcessDelegate ");
_builder.append(methName, " ");
_builder.append("_PostProcess;");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
{
EList _methods_1 = resource.getMethods();
for(final Method method_1 : _methods_1) {
_builder.append(" ");
String _name_1 = method_1.getName();
final String methName_1 = this.nameHelper.initialUpper(_name_1);
_builder.newLineIfNotEmpty();
_builder.append(" ");
CharSequence _returnType = this.getReturnType(method_1);
final boolean notVoid = (!Objects.equal(_returnType, "void"));
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.newLine();
_builder.append(" ");
List _routingAttrs_1 = this.getRoutingAttrs(method_1);
_builder.append(_routingAttrs_1, " ");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("public ");
CharSequence _returnType_1 = this.getReturnType(method_1);
_builder.append(_returnType_1, " ");
_builder.append(" ");
_builder.append(methName_1, " ");
_builder.append("(");
String _signature_3 = this.getSignature(method_1, false, true);
_builder.append(_signature_3, " ");
_builder.append(") {");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append(" ");
EList _responses = method_1.getResponses();
TypedResponse _head = IterableExtensions.head(_responses);
String _valueType = this.getValueType(_head);
CharSequence _delegateVarDecl = this.snippetHelper.delegateVarDecl(_valueType);
_builder.append(_delegateVarDecl, " ");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append(" ");
_builder.append("if (");
_builder.append(methName_1, " ");
_builder.append("_PreProcess != null) {");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append(" ");
_builder.append(methName_1, " ");
_builder.append("_PreProcess(");
String _args = this.getArgs(method_1);
_builder.append(_args, " ");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append(" ");
_builder.append("if (");
_builder.append(methName_1, " ");
_builder.append("_Process != null) {");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append(" ");
{
if (notVoid) {
String _delegateVar = this.snippetHelper.delegateVar();
_builder.append(_delegateVar, " ");
_builder.append(" = ");
}
}
_builder.append(methName_1, " ");
_builder.append("_Process(");
String _args_1 = this.getArgs(method_1);
_builder.append(_args_1, " ");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append(" ");
_builder.append("} else {");
_builder.newLine();
_builder.append(" ");
_builder.append(" ");
_builder.append("throw new NotImplementedException();");
_builder.newLine();
_builder.append(" ");
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append(" ");
_builder.append("if (");
_builder.append(methName_1, " ");
_builder.append("_PostProcess != null");
String _postProcessExtraCond = this.snippetHelper.postProcessExtraCond();
_builder.append(_postProcessExtraCond, " ");
_builder.append(") {");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append(" ");
_builder.append(methName_1, " ");
_builder.append("_PostProcess(");
String _args_2 = this.getArgs(method_1, true);
_builder.append(_args_2, " ");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append(" ");
String _delegateReturn = this.snippetHelper.delegateReturn(notVoid);
_builder.append(_delegateReturn, " ");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
}
}
_builder.append("}");
_builder.newLine();
final String content = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append(name, "");
_builder_1.append("DelegateController");
String _csharpFileName = fileHelper.getCsharpFileName(_builder_1);
_xblockexpression = fileHelper.writeFile(content, _csharpFileName);
}
return _xblockexpression;
}
private Path generateAbstractDelegateHandler(final ResourceDefinition resource) {
Path _xblockexpression = null;
{
final String name = this.nameHelper.getResourceName(resource);
@Extension
final FileHelper fileHelper = FileHelper.of(resource, FileRole.ABSTRACT_DELEGATE_HANDLER, this.context, this.config);
EObject _eContainer = resource.eContainer();
fileHelper.using(((ResourceAPI) _eContainer));
this.useDataModels(fileHelper, resource);
StringConcatenation _builder = new StringConcatenation();
_builder.append("public abstract class Abstract");
_builder.append(name, "");
_builder.append("Handlers {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append(" ");
_builder.append("/// ");
_builder.newLine();
_builder.append(" ");
_builder.append("/// Bind handlers to delegates here. For example:");
_builder.newLine();
_builder.append(" ");
_builder.append("/// ");
_builder.append(name, " ");
_builder.append("DelegateController.MethodName_Process += MethodName;");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("/// Unbound handlers will not be used. Handlers that are not overridden act as follows:");
_builder.newLine();
_builder.append(" ");
_builder.append("/// * PreProcess handlers do nothing");
_builder.newLine();
_builder.append(" ");
_builder.append("/// * Process handlers throw NotImplementedException");
_builder.newLine();
_builder.append(" ");
_builder.append("/// * PostProcess handlers do nothing");
_builder.newLine();
_builder.append(" ");
_builder.append("/// ");
_builder.newLine();
_builder.append(" ");
_builder.append("public Abstract");
_builder.append(name, " ");
_builder.append("Handlers() {}");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.newLine();
{
EList _methods = resource.getMethods();
for(final Method method : _methods) {
_builder.append(" ");
String _name = method.getName();
final String methName = this.nameHelper.initialUpper(_name);
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.newLine();
_builder.append(" ");
_builder.append("protected virtual void ");
_builder.append(methName, " ");
_builder.append("_PreProcess(");
String _signature = this.getSignature(method);
_builder.append(_signature, " ");
_builder.append(") { }");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("protected virtual ");
CharSequence _delegateReturnType = this.getDelegateReturnType(method);
_builder.append(_delegateReturnType, " ");
_builder.append(" ");
_builder.append(methName, " ");
_builder.append("(");
String _signature_1 = this.getSignature(method);
_builder.append(_signature_1, " ");
_builder.append(") {");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append(" ");
_builder.append("throw new NotImplementedException();");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append("protected virtual void ");
_builder.append(methName, " ");
_builder.append("_PostProcess(");
String _signature_2 = this.getSignature(method, true);
_builder.append(_signature_2, " ");
_builder.append(") { }");
_builder.newLineIfNotEmpty();
}
}
_builder.append("}");
_builder.newLine();
final String content = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("Abstract");
_builder_1.append(name, "");
_builder_1.append("DelegateHandler");
String _csharpFileName = fileHelper.getCsharpFileName(_builder_1);
_xblockexpression = fileHelper.writeFile(content, _csharpFileName);
}
return _xblockexpression;
}
private FileHelper useDataModels(final FileHelper helper, final ResourceDefinition resource) {
FileHelper _xblockexpression = null;
{
final Set usedDataModels = CollectionLiterals.newHashSet();
EList _methods = resource.getMethods();
for (final Method method : _methods) {
{
TypedRequest _request = method.getRequest();
ResourceDefinition _resourceType = null;
if (_request!=null) {
_resourceType=_request.getResourceType();
}
Structure _structure = null;
if (_resourceType!=null) {
_structure=this.getStructure(_resourceType);
}
EObject _eContainer = null;
if (_structure!=null) {
_eContainer=_structure.eContainer();
}
usedDataModels.add(((DataModel) _eContainer));
EList _responses = method.getResponses();
for (final TypedResponse response : _responses) {
ResourceDefinition _resourceType_1 = response.getResourceType();
Structure _structure_1 = null;
if (_resourceType_1!=null) {
_structure_1=this.getStructure(_resourceType_1);
}
EObject _eContainer_1 = null;
if (_structure_1!=null) {
_eContainer_1=_structure_1.eContainer();
}
usedDataModels.add(((DataModel) _eContainer_1));
}
}
}
final Function1 _function = (DataModel it) -> {
return Boolean.valueOf((it != null));
};
Iterable _filter = IterableExtensions.filter(usedDataModels, _function);
List _list = IterableExtensions.toList(_filter);
Object[] _array = _list.toArray();
_xblockexpression = helper.using(_array);
}
return _xblockexpression;
}
private boolean isVoidReturn(final Method method) {
EList _responses = method.getResponses();
TypedResponse _head = IterableExtensions.head(_responses);
Structure _underlyingStructure = this.getUnderlyingStructure(_head);
return (_underlyingStructure == null);
}
private CharSequence getReturnType(final Method method) {
CharSequence _elvis = null;
EList _responses = method.getResponses();
TypedResponse _head = IterableExtensions.head(_responses);
CharSequence _messageType = this.getMessageType(_head);
if (_messageType != null) {
_elvis = _messageType;
} else {
String _voidMethodResponseType = this.snippetHelper.voidMethodResponseType();
_elvis = _voidMethodResponseType;
}
return _elvis;
}
private CharSequence getDelegateReturnType(final Method method) {
CharSequence _elvis = null;
EList _responses = method.getResponses();
TypedResponse _head = IterableExtensions.head(_responses);
CharSequence _delegateType = this.getDelegateType(_head);
if (_delegateType != null) {
_elvis = _delegateType;
} else {
String _voidDelegateType = this.snippetHelper.voidDelegateType();
_elvis = _voidDelegateType;
}
return _elvis;
}
private String getRequestType(final Method method) {
TypedRequest _request = method.getRequest();
String _valueType = null;
if (_request!=null) {
_valueType=this.getValueType(_request);
}
return _valueType;
}
private CharSequence getMessageType(final TypedMessage msg) {
String _valueType = this.getValueType(msg);
CharSequence _methodResponseType = null;
if (_valueType!=null) {
_methodResponseType=this.snippetHelper.methodResponseType(_valueType);
}
return _methodResponseType;
}
private CharSequence getDelegateType(final TypedMessage msg) {
String _valueType = this.getValueType(msg);
CharSequence _delegateType = null;
if (_valueType!=null) {
_delegateType=this.snippetHelper.delegateType(_valueType);
}
return _delegateType;
}
private String getValueType(final TypedMessage msg) {
String _xblockexpression = null;
{
Structure _underlyingStructure = this.getUnderlyingStructure(msg);
String _name = null;
if (_underlyingStructure!=null) {
_name=_underlyingStructure.getName();
}
String _initialUpper = null;
if (_name!=null) {
_initialUpper=this.nameHelper.initialUpper(_name);
}
final String typeName = _initialUpper;
String _xifexpression = null;
if ((typeName != null)) {
String _xifexpression_1 = null;
ResourceDefinition _resourceType = msg.getResourceType();
if ((_resourceType instanceof CollectionResource)) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("IEnumerable");
_xifexpression_1 = _builder.toString();
} else {
_xifexpression_1 = ("I" + typeName);
}
_xifexpression = _xifexpression_1;
}
_xblockexpression = _xifexpression;
}
return _xblockexpression;
}
private Structure getUnderlyingStructure(final TypedMessage msg) {
Structure _elvis = null;
Structure _elvis_1 = null;
Structure _dataType = msg.getDataType();
if (_dataType != null) {
_elvis_1 = _dataType;
} else {
Structure _msgResourceDataType = this.getMsgResourceDataType(msg);
_elvis_1 = _msgResourceDataType;
}
if (_elvis_1 != null) {
_elvis = _elvis_1;
} else {
Structure _containingResourceDataType = this.getContainingResourceDataType(msg);
_elvis = _containingResourceDataType;
}
return _elvis;
}
private Structure getMsgResourceDataType(final TypedMessage msg) {
ResourceDefinition _resourceType = msg.getResourceType();
Structure _resourceDataType = null;
if (_resourceType!=null) {
_resourceDataType=this.getResourceDataType(_resourceType);
}
return _resourceDataType;
}
private Structure getContainingResourceDataType(final TypedMessage msg) {
Structure _xifexpression = null;
boolean _isUseParentTypeReference = msg.isUseParentTypeReference();
if (_isUseParentTypeReference) {
EObject _eContainer = msg.eContainer();
ResourceDefinition _containingResourceDefinition = ((Method) _eContainer).getContainingResourceDefinition();
_xifexpression = this.getResourceDataType(_containingResourceDefinition);
}
return _xifexpression;
}
private Structure getResourceDataType(final ResourceDefinition resource) {
Structure _switchResult = null;
boolean _matched = false;
if (!_matched) {
if (resource instanceof ServiceDataResource) {
_matched=true;
_switchResult = ((ServiceDataResource)resource).getDataType();
}
}
return _switchResult;
}
private Structure getStructure(final ResourceDefinition resource) {
Structure _switchResult = null;
boolean _matched = false;
if (!_matched) {
if (resource instanceof ObjectResource) {
_matched=true;
_switchResult = ((ObjectResource)resource).getDataType();
}
}
if (!_matched) {
if (resource instanceof CollectionResource) {
_matched=true;
_switchResult = ((CollectionResource)resource).getDataType();
}
}
return _switchResult;
}
private String getSignature(final Method method) {
return this.getSignature(method, false);
}
private String getSignature(final Method method, final boolean includeResponse) {
return this.getSignature(method, includeResponse, false);
}
private String getSignature(final Method method, final boolean includeResponse, final boolean includeBodyAttr) {
String _xblockexpression = null;
{
final List params = CollectionLiterals.newArrayList();
List _elvis = null;
ResourceDefinition _containingResourceDefinition = method.getContainingResourceDefinition();
URI _uRI = _containingResourceDefinition.getURI();
EList _uriParameters = _uRI.getUriParameters();
if (_uriParameters != null) {
_elvis = _uriParameters;
} else {
_elvis = Collections.unmodifiableList(CollectionLiterals.newArrayList());
}
for (final URIParameter param : _elvis) {
StringConcatenation _builder = new StringConcatenation();
SingleValueType _type = param.getType();
String _name = _type.getName();
String _csharpType = this.typeHelper.getCsharpType(_name);
_builder.append(_csharpType, "");
_builder.append(" ");
String _name_1 = param.getName();
_builder.append(_name_1, "");
params.add(_builder.toString());
}
TypedRequest _request = method.getRequest();
EList _parameters = _request.getParameters();
for (final MessageParameter param_1 : _parameters) {
StringConcatenation _builder_1 = new StringConcatenation();
SingleValueType _type_1 = param_1.getType();
String _name_2 = _type_1.getName();
String _csharpType_1 = this.typeHelper.getCsharpType(_name_2);
_builder_1.append(_csharpType_1, "");
_builder_1.append(" ");
String _name_3 = param_1.getName();
_builder_1.append(_name_3, "");
params.add(_builder_1.toString());
}
String _requestType = this.getRequestType(method);
boolean _tripleNotEquals = (_requestType != null);
if (_tripleNotEquals) {
StringConcatenation _builder_2 = new StringConcatenation();
{
if (includeBodyAttr) {
_builder_2.append("[FromBody] ");
}
}
String _requestType_1 = this.getRequestType(method);
_builder_2.append(_requestType_1, "");
_builder_2.append(" requestPayload");
params.add(_builder_2.toString());
}
boolean _and = false;
if (!includeResponse) {
_and = false;
} else {
boolean _isVoidReturn = this.isVoidReturn(method);
boolean _not = (!_isVoidReturn);
_and = _not;
}
if (_and) {
StringConcatenation _builder_3 = new StringConcatenation();
EList _responses = method.getResponses();
TypedResponse _head = IterableExtensions.head(_responses);
String _valueType = this.getValueType(_head);
_builder_3.append(_valueType, "");
_builder_3.append(" responsePayload");
params.add(_builder_3.toString());
}
_xblockexpression = IterableExtensions.join(params, ", ");
}
return _xblockexpression;
}
private String getArgs(final Method method) {
return this.getArgs(method, false);
}
private String getArgs(final Method method, final boolean includeResponse) {
String _xblockexpression = null;
{
final List args = CollectionLiterals.newArrayList();
List _elvis = null;
ResourceDefinition _containingResourceDefinition = method.getContainingResourceDefinition();
URI _uRI = _containingResourceDefinition.getURI();
EList _uriParameters = _uRI.getUriParameters();
if (_uriParameters != null) {
_elvis = _uriParameters;
} else {
_elvis = Collections.unmodifiableList(CollectionLiterals.newArrayList());
}
for (final URIParameter param : _elvis) {
String _name = param.getName();
args.add(_name);
}
TypedRequest _request = method.getRequest();
EList _parameters = _request.getParameters();
for (final MessageParameter param_1 : _parameters) {
String _name_1 = param_1.getName();
args.add(_name_1);
}
String _requestType = this.getRequestType(method);
boolean _tripleNotEquals = (_requestType != null);
if (_tripleNotEquals) {
args.add("requestPayload");
}
boolean _and = false;
if (!includeResponse) {
_and = false;
} else {
boolean _isVoidReturn = this.isVoidReturn(method);
boolean _not = (!_isVoidReturn);
_and = _not;
}
if (_and) {
String _responseValue = this.snippetHelper.responseValue();
args.add(_responseValue);
}
_xblockexpression = IterableExtensions.join(args, ", ");
}
return _xblockexpression;
}
private CharSequence getRoutingAttrs(final ResourceAPI api) {
try {
CharSequence _xblockexpression = null;
{
String _baseURI = api.getBaseURI();
java.net.URI _uRI = new java.net.URI(_baseURI);
String prefix = _uRI.getPath();
boolean _startsWith = prefix.startsWith("/");
if (_startsWith) {
String _substring = prefix.substring(1);
prefix = _substring;
}
CharSequence _xifexpression = null;
boolean _isEmpty = prefix.isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("[");
String _routePrefix = this.snippetHelper.routePrefix();
_builder.append(_routePrefix, "");
_builder.append("(\"");
_builder.append(prefix, "");
_builder.append("\")]");
_builder.newLineIfNotEmpty();
_xifexpression = _builder;
}
_xblockexpression = _xifexpression;
}
return _xblockexpression;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
private List getRoutingAttrs(final Method method) {
List _xblockexpression = null;
{
final List attrs = CollectionLiterals.newArrayList();
String _switchResult = null;
HTTPMethods _httpMethod = method.getHttpMethod();
if (_httpMethod != null) {
switch (_httpMethod) {
case GET:
_switchResult = "HttpGet";
break;
case HEAD:
_switchResult = "HttpHead";
break;
case POST:
_switchResult = "HttpPost";
break;
case PUT:
_switchResult = "HttpPut";
break;
case OPTIONS:
_switchResult = "HttpOptions";
break;
case DELETE:
_switchResult = "HttpDelete";
break;
case CONNECT:
_switchResult = "HttpConnect";
break;
case PATCH:
_switchResult = "HttpPatch";
break;
case TRACE:
_switchResult = "HttpTrace";
break;
default:
break;
}
}
final String methodAttr = _switchResult;
if ((methodAttr != null)) {
attrs.add(methodAttr);
}
ResourceDefinition _containingResourceDefinition = method.getContainingResourceDefinition();
URI _uRI = _containingResourceDefinition.getURI();
EList _segments = _uRI.getSegments();
final String uri = IterableExtensions.join(_segments, "/");
StringConcatenation _builder = new StringConcatenation();
_builder.append("Route(\"");
_builder.append(uri, "");
_builder.append("\")");
attrs.add(_builder.toString());
IterableExtensions.join(attrs, ", ");
_xblockexpression = attrs;
}
return _xblockexpression;
}
}