use of com.robotoworks.mechanoid.ops.opServiceModel.ServiceBlock in project mechanoid by robotoworks.
the class OperationRegistryGenerator method generateStub.
public CharSequence generateStub(final Model model) {
StringConcatenation _builder = new StringConcatenation();
ServiceBlock svc = model.getService();
_builder.newLineIfNotEmpty();
_builder.append("/*");
_builder.newLine();
_builder.append(" ");
_builder.append("* Generated by Robotoworks Mechanoid");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("package ");
String _packageName = model.getPackageName();
_builder.append(_packageName, "");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("public class ");
String _name = svc.getName();
String _formatServiceName = Extensions.formatServiceName(_name);
_builder.append(_formatServiceName, "");
_builder.append("OperationConfigurationRegistry extends Abstract");
String _name_1 = svc.getName();
String _formatServiceName_1 = Extensions.formatServiceName(_name_1);
_builder.append(_formatServiceName_1, "");
_builder.append("OperationConfigurationRegistry {");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.newLine();
_builder.append("} ");
_builder.newLine();
return _builder;
}
use of com.robotoworks.mechanoid.ops.opServiceModel.ServiceBlock in project mechanoid by robotoworks.
the class ServiceConfigurationGenerator method generate.
public CharSequence generate(final Model model) {
StringConcatenation _builder = new StringConcatenation();
ServiceBlock svc = model.getService();
_builder.newLineIfNotEmpty();
_builder.append("/*");
_builder.newLine();
_builder.append(" ");
_builder.append("* Generated by Robotoworks Mechanoid");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("package ");
String _packageName = model.getPackageName();
_builder.append(_packageName, "");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("import com.robotoworks.mechanoid.ops.OperationServiceConfiguration;");
_builder.newLine();
_builder.append("import com.robotoworks.mechanoid.ops.OperationConfigurationRegistry;");
_builder.newLine();
_builder.newLine();
_builder.append("public abstract class Abstract");
String _name = svc.getName();
String _formatServiceName = Extensions.formatServiceName(_name);
_builder.append(_formatServiceName, "");
_builder.append("Configuration extends OperationServiceConfiguration {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("private OperationConfigurationRegistry mOperationConfigurationRegistry = new ");
String _name_1 = svc.getName();
String _formatServiceName_1 = Extensions.formatServiceName(_name_1);
_builder.append(_formatServiceName_1, "\t");
_builder.append("OperationConfigurationRegistry();");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public OperationConfigurationRegistry getOperationConfigurationRegistry() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return mOperationConfigurationRegistry;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
return _builder;
}
use of com.robotoworks.mechanoid.ops.opServiceModel.ServiceBlock in project mechanoid by robotoworks.
the class ServiceGenerator method generate.
public CharSequence generate(final Model model) {
StringConcatenation _builder = new StringConcatenation();
ServiceBlock svc = model.getService();
_builder.newLineIfNotEmpty();
_builder.append("/*");
_builder.newLine();
_builder.append(" ");
_builder.append("* Generated by Robotoworks Mechanoid");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("package ");
String _packageName = model.getPackageName();
_builder.append(_packageName, "");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("import com.robotoworks.mechanoid.ops.OperationProcessor;");
_builder.newLine();
_builder.append("import com.robotoworks.mechanoid.ops.OperationService;");
_builder.newLine();
_builder.append("import com.robotoworks.mechanoid.ops.OperationServiceConfiguration;");
_builder.newLine();
_builder.newLine();
_builder.append("import ");
String _packageName_1 = model.getPackageName();
_builder.append(_packageName_1, "");
_builder.append(".");
String _name = svc.getName();
String _pascalize = Strings.pascalize(_name);
_builder.append(_pascalize, "");
_builder.append("Processor;");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("public abstract class Abstract");
String _name_1 = svc.getName();
String _formatServiceName = Extensions.formatServiceName(_name_1);
_builder.append(_formatServiceName, "");
_builder.append(" extends OperationService {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("public static final OperationServiceConfiguration CONFIG = new ");
String _name_2 = svc.getName();
String _formatServiceName_1 = Extensions.formatServiceName(_name_2);
_builder.append(_formatServiceName_1, "\t");
_builder.append("Configuration();");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected OperationProcessor createProcessor() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return new ");
String _name_3 = svc.getName();
String _pascalize_1 = Strings.pascalize(_name_3);
_builder.append(_pascalize_1, "\t\t");
_builder.append("Processor(this);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("public Abstract");
String _name_4 = svc.getName();
String _formatServiceName_2 = Extensions.formatServiceName(_name_4);
_builder.append(_formatServiceName_2, "\t");
_builder.append("(boolean enableLogging) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("super(enableLogging);");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
return _builder;
}
use of com.robotoworks.mechanoid.ops.opServiceModel.ServiceBlock in project mechanoid by robotoworks.
the class OpServiceModelGenerator method generateServiceConfiguration.
public void generateServiceConfiguration(final Resource resource, final IFileSystemAccess fsa) {
EList<EObject> _contents = resource.getContents();
EObject _head = IterableExtensions.<EObject>head(_contents);
Model model = ((Model) _head);
String _packageName = model.getPackageName();
ServiceBlock _service = model.getService();
String _name = _service.getName();
String _pascalize = Strings.pascalize(_name);
String _concat = "Abstract".concat(_pascalize);
String _concatOnce = Strings.concatOnce(_concat, "Service");
String _concat_1 = _concatOnce.concat("Configuration");
String _resolveFileName = Strings.resolveFileName(_packageName, _concat_1);
CharSequence _generate = this.mServiceConfigGenerator.generate(model);
fsa.generateFile(_resolveFileName, _generate);
String _packageName_1 = model.getPackageName();
ServiceBlock _service_1 = model.getService();
String _name_1 = _service_1.getName();
String _pascalize_1 = Strings.pascalize(_name_1);
String _concatOnce_1 = Strings.concatOnce(_pascalize_1, "Service");
String _concat_2 = _concatOnce_1.concat("Configuration");
String _resolveFileName_1 = Strings.resolveFileName(_packageName_1, _concat_2);
CharSequence _generateStub = this.mServiceConfigGenerator.generateStub(model);
fsa.generateFile(_resolveFileName_1, MechanoidOutputConfigurationProvider.DEFAULT_STUB_OUTPUT, _generateStub);
}
use of com.robotoworks.mechanoid.ops.opServiceModel.ServiceBlock in project mechanoid by robotoworks.
the class OperationGenerator method generate.
public CharSequence generate(final Model model, final Operation op) {
StringConcatenation _builder = new StringConcatenation();
ServiceBlock svc = model.getService();
_builder.newLineIfNotEmpty();
_builder.append("/*");
_builder.newLine();
_builder.append(" ");
_builder.append("* Generated by Robotoworks Mechanoid");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("package ");
String _packageName = model.getPackageName();
_builder.append(_packageName, "");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("import com.robotoworks.mechanoid.Mechanoid;");
_builder.newLine();
_builder.append("import com.robotoworks.mechanoid.ops.Operation;");
_builder.newLine();
_builder.append("import com.robotoworks.mechanoid.ops.OperationContext;");
_builder.newLine();
_builder.append("import com.robotoworks.mechanoid.ops.OperationResult;");
_builder.newLine();
_builder.append("import com.robotoworks.mechanoid.ops.OperationServiceBridge;");
_builder.newLine();
_builder.append("import com.robotoworks.mechanoid.ops.OperationConfiguration;");
_builder.newLine();
_builder.append("import android.content.Intent;");
_builder.newLine();
_builder.append("import android.os.Bundle;");
_builder.newLine();
_builder.newLine();
_builder.append("public abstract class Abstract");
String _name = op.getName();
String _pascalize = Strings.pascalize(_name);
_builder.append(_pascalize, "");
_builder.append("Operation extends Operation {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("public static final String ACTION_");
String _name_1 = op.getName();
String _underscore = Strings.underscore(_name_1);
String _upperCase = _underscore.toUpperCase();
_builder.append(_upperCase, "\t");
_builder.append(" = \"");
String _packageName_1 = model.getPackageName();
_builder.append(_packageName_1, "\t");
_builder.append(".");
String _name_2 = svc.getName();
String _formatServiceName = Extensions.formatServiceName(_name_2);
_builder.append(_formatServiceName, "\t");
_builder.append(".actions.");
String _name_3 = op.getName();
String _underscore_1 = Strings.underscore(_name_3);
String _upperCase_1 = _underscore_1.toUpperCase();
_builder.append(_upperCase_1, "\t");
_builder.append("\";");
_builder.newLineIfNotEmpty();
_builder.newLine();
{
EList<OperationArg> _args = op.getArgs();
for (final OperationArg arg : _args) {
_builder.append("\t");
_builder.append("public static final String EXTRA_");
String _name_4 = arg.getName();
String _underscore_2 = Strings.underscore(_name_4);
String _upperCase_2 = _underscore_2.toUpperCase();
_builder.append(_upperCase_2, "\t");
_builder.append(" = \"");
String _packageName_2 = model.getPackageName();
_builder.append(_packageName_2, "\t");
_builder.append(".");
String _name_5 = svc.getName();
String _formatServiceName_1 = Extensions.formatServiceName(_name_5);
_builder.append(_formatServiceName_1, "\t");
_builder.append(".extras.");
String _name_6 = arg.getName();
String _underscore_3 = Strings.underscore(_name_6);
String _upperCase_3 = _underscore_3.toUpperCase();
_builder.append(_upperCase_3, "\t");
_builder.append("\";");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
_builder.append("\t");
_builder.append("static class Args {");
_builder.newLine();
{
EList<OperationArg> _args_1 = op.getArgs();
for (final OperationArg arg_1 : _args_1) {
_builder.append("\t\t");
_builder.append("public ");
OpArgType _type = arg_1.getType();
String _typeLiteral = Extensions.toTypeLiteral(_type);
_builder.append(_typeLiteral, "\t\t");
_builder.append(" ");
String _name_7 = arg_1.getName();
String _camelize = Strings.camelize(_name_7);
_builder.append(_camelize, "\t\t");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("static class Configuration extends OperationConfiguration {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("@Override ");
_builder.newLine();
_builder.append("\t\t");
_builder.append("public Operation createOperation() {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("return new ");
String _name_8 = op.getName();
String _pascalize_1 = Strings.pascalize(_name_8);
_builder.append(_pascalize_1, "\t\t\t");
_builder.append("Operation();");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t\t");
_builder.append("public Intent findMatchOnConstraint(OperationServiceBridge bridge, Intent intent) {");
_builder.newLine();
{
UniqueClause _uniqueClause = op.getUniqueClause();
boolean _equals = Objects.equal(_uniqueClause, null);
if (_equals) {
_builder.append("\t\t\t");
_builder.append("Intent existingRequest = bridge.findPendingRequestByActionWithExtras(Abstract");
String _name_9 = op.getName();
String _pascalize_2 = Strings.pascalize(_name_9);
_builder.append(_pascalize_2, "\t\t\t");
_builder.append("Operation.ACTION_");
String _name_10 = op.getName();
String _underscore_4 = Strings.underscore(_name_10);
String _upperCase_4 = _underscore_4.toUpperCase();
_builder.append(_upperCase_4, "\t\t\t");
_builder.append(", intent.getExtras());");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("return existingRequest;");
_builder.newLine();
_builder.append("\t\t\t");
_builder.newLine();
} else {
UniqueClause _uniqueClause_1 = op.getUniqueClause();
if ((_uniqueClause_1 instanceof UniqueDeclaration)) {
_builder.append("\t\t\t");
UniqueClause _uniqueClause_2 = op.getUniqueClause();
UniqueDeclaration uniqueDecl = ((UniqueDeclaration) _uniqueClause_2);
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("android.os.Bundle matcher = new android.os.Bundle();");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("android.os.Bundle intentExtras = intent.getExtras();");
_builder.newLine();
{
EList<OperationArg> _args_2 = uniqueDecl.getArgs();
for (final OperationArg uarg : _args_2) {
_builder.append("\t\t\t");
_builder.append("matcher.");
OpArgType _type_1 = uarg.getType();
String _bundlePutMethodName = Extensions.toBundlePutMethodName(_type_1);
_builder.append(_bundlePutMethodName, "\t\t\t");
_builder.append("(");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("\t");
String _name_11 = op.getName();
String _pascalize_3 = Strings.pascalize(_name_11);
_builder.append(_pascalize_3, "\t\t\t\t");
_builder.append("Operation.EXTRA_");
String _name_12 = uarg.getName();
String _underscore_5 = Strings.underscore(_name_12);
String _upperCase_5 = _underscore_5.toUpperCase();
_builder.append(_upperCase_5, "\t\t\t\t");
_builder.append(", ");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("\t");
_builder.append("intentExtras.");
OpArgType _type_2 = uarg.getType();
String _bundleGetMethodName = Extensions.toBundleGetMethodName(_type_2);
_builder.append(_bundleGetMethodName, "\t\t\t\t");
_builder.append("(");
String _name_13 = op.getName();
String _pascalize_4 = Strings.pascalize(_name_13);
_builder.append(_pascalize_4, "\t\t\t\t");
_builder.append("Operation.EXTRA_");
String _name_14 = uarg.getName();
String _underscore_6 = Strings.underscore(_name_14);
String _upperCase_6 = _underscore_6.toUpperCase();
_builder.append(_upperCase_6, "\t\t\t\t");
_builder.append("));");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t\t\t");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("Intent existingRequest = bridge.findPendingRequestByActionWithExtras(Abstract");
String _name_15 = op.getName();
String _pascalize_5 = Strings.pascalize(_name_15);
_builder.append(_pascalize_5, "\t\t\t");
_builder.append("Operation.ACTION_");
String _name_16 = op.getName();
String _underscore_7 = Strings.underscore(_name_16);
String _upperCase_7 = _underscore_7.toUpperCase();
_builder.append(_upperCase_7, "\t\t\t");
_builder.append(", matcher);");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("return existingRequest;");
_builder.newLine();
} else {
_builder.append("\t\t\t");
_builder.append("return null;");
_builder.newLine();
}
}
}
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("public static final Intent newIntent(");
{
EList<OperationArg> _args_3 = op.getArgs();
boolean _hasElements = false;
for (final OperationArg arg_2 : _args_3) {
if (!_hasElements) {
_hasElements = true;
} else {
_builder.appendImmediate(", ", "\t");
}
OpArgType _type_3 = arg_2.getType();
String _typeLiteral_1 = Extensions.toTypeLiteral(_type_3);
_builder.append(_typeLiteral_1, "\t");
_builder.append(" ");
String _name_17 = arg_2.getName();
String _camelize_1 = Strings.camelize(_name_17);
_builder.append(_camelize_1, "\t");
}
}
_builder.append(") {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("Intent intent = new Intent(ACTION_");
String _name_18 = op.getName();
String _underscore_8 = Strings.underscore(_name_18);
String _upperCase_8 = _underscore_8.toUpperCase();
_builder.append(_upperCase_8, "\t\t");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("intent.setClass(Mechanoid.getApplicationContext(), ");
String _name_19 = svc.getName();
String _formatServiceName_2 = Extensions.formatServiceName(_name_19);
_builder.append(_formatServiceName_2, "\t\t");
_builder.append(".class);");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("Bundle extras = new Bundle();");
_builder.newLine();
{
EList<OperationArg> _args_4 = op.getArgs();
for (final OperationArg arg_3 : _args_4) {
_builder.append("\t\t");
_builder.append("extras.");
OpArgType _type_4 = arg_3.getType();
String _bundlePutMethodName_1 = Extensions.toBundlePutMethodName(_type_4);
_builder.append(_bundlePutMethodName_1, "\t\t");
_builder.append("(EXTRA_");
String _name_20 = arg_3.getName();
String _underscore_9 = Strings.underscore(_name_20);
String _upperCase_9 = _underscore_9.toUpperCase();
_builder.append(_upperCase_9, "\t\t");
_builder.append(", ");
String _name_21 = arg_3.getName();
String _camelize_2 = Strings.camelize(_name_21);
_builder.append(_camelize_2, "\t\t");
_builder.append(");");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("intent.putExtras(extras);");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return intent;");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public OperationResult execute(OperationContext context) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("Args args = new Args();");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
{
EList<OperationArg> _args_5 = op.getArgs();
int _size = _args_5.size();
boolean _greaterThan = (_size > 0);
if (_greaterThan) {
_builder.append("\t\t");
_builder.append("Bundle extras = context.getIntent().getExtras();");
_builder.newLine();
{
EList<OperationArg> _args_6 = op.getArgs();
for (final OperationArg arg_4 : _args_6) {
_builder.append("\t\t");
_builder.append("args.");
String _name_22 = arg_4.getName();
String _camelize_3 = Strings.camelize(_name_22);
_builder.append(_camelize_3, "\t\t");
_builder.append(" = extras.");
OpArgType _type_5 = arg_4.getType();
String _bundleGetMethodName_1 = Extensions.toBundleGetMethodName(_type_5);
_builder.append(_bundleGetMethodName_1, "\t\t");
_builder.append("(EXTRA_");
String _name_23 = arg_4.getName();
String _underscore_10 = Strings.underscore(_name_23);
String _upperCase_10 = _underscore_10.toUpperCase();
_builder.append(_upperCase_10, "\t\t");
_builder.append(");");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t\t");
_builder.newLine();
}
}
_builder.append("\t\t");
_builder.append("return onExecute(context, args);");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t\t");
_builder.newLine();
_builder.append("\t");
_builder.append("protected abstract OperationResult onExecute(OperationContext context, Args args);");
_builder.newLine();
_builder.append("}");
_builder.newLine();
return _builder;
}
Aggregations