io.joynr.generator.provider.InterfaceAbstractProviderTemplate Maven / Gradle / Ivy
package io.joynr.generator.provider;
import com.google.inject.Inject;
import io.joynr.generator.util.JoynrJavaGeneratorExtensions;
import io.joynr.generator.util.TemplateBase;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.franca.core.franca.FAttribute;
import org.franca.core.franca.FInterface;
@SuppressWarnings("all")
public class InterfaceAbstractProviderTemplate {
@Inject
@Extension
private JoynrJavaGeneratorExtensions _joynrJavaGeneratorExtensions;
@Inject
@Extension
private TemplateBase _templateBase;
public CharSequence generate(final FInterface serviceInterface) {
CharSequence _xblockexpression = null;
{
final String interfaceName = this._joynrJavaGeneratorExtensions.joynrName(serviceInterface);
final String className = (interfaceName + "AbstractProvider");
final String providerInterfaceName = (interfaceName + "Provider");
final String packagePath = this._joynrJavaGeneratorExtensions.getPackagePathWithJoynrPrefix(serviceInterface, ".");
StringConcatenation _builder = new StringConcatenation();
CharSequence _warning = this._templateBase.warning();
_builder.append(_warning, "");
_builder.newLineIfNotEmpty();
_builder.append("package ");
_builder.append(packagePath, "");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("import java.util.List;");
_builder.newLine();
_builder.append("import java.util.ArrayList;");
_builder.newLine();
_builder.append("import java.util.Map;");
_builder.newLine();
_builder.newLine();
_builder.append("import io.joynr.provider.AbstractJoynrProvider;");
_builder.newLine();
_builder.append("import ");
String _joynTypePackagePrefix = this._joynrJavaGeneratorExtensions.getJoynTypePackagePrefix();
_builder.append(_joynTypePackagePrefix, "");
_builder.append(".types.ProviderQos;");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.newLine();
{
Iterable _requiredIncludesFor = this._joynrJavaGeneratorExtensions.getRequiredIncludesFor(serviceInterface);
for(final String datatype : _requiredIncludesFor) {
_builder.append("import ");
_builder.append(datatype, "");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("//TODO: Only include the necessary imports in the xtend template. This needs to be checked depending on the fibex. ");
_builder.newLine();
_builder.append("@SuppressWarnings(\"unused\")");
_builder.newLine();
_builder.newLine();
_builder.append("public abstract class ");
_builder.append(className, "");
_builder.append(" extends AbstractJoynrProvider implements ");
_builder.append(providerInterfaceName, "");
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t ");
_builder.append("protected ProviderQos providerQos = new ProviderQos();");
_builder.newLine();
_builder.append("\t ");
_builder.newLine();
_builder.newLine();
{
EList _attributes = this._joynrJavaGeneratorExtensions.getAttributes(serviceInterface);
int _size = _attributes.size();
boolean _greaterThan = (_size > 0);
if (_greaterThan) {
_builder.append("//attributes");
_builder.newLine();
}
}
{
EList _attributes_1 = this._joynrJavaGeneratorExtensions.getAttributes(serviceInterface);
for(final FAttribute attribute : _attributes_1) {
final String attributeName = this._joynrJavaGeneratorExtensions.joynrName(attribute);
_builder.newLineIfNotEmpty();
final String attributeType = this._joynrJavaGeneratorExtensions.getMappedDatatypeOrList(attribute);
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("protected ");
_builder.append(attributeType, " ");
_builder.append(" ");
_builder.append(attributeName, " ");
_builder.append(";\t");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
{
EList _attributes_2 = this._joynrJavaGeneratorExtensions.getAttributes(serviceInterface);
int _size_1 = _attributes_2.size();
boolean _greaterThan_1 = (_size_1 > 0);
if (_greaterThan_1) {
_builder.append("//setter & abstract getter");
_builder.newLine();
}
}
{
EList _attributes_3 = this._joynrJavaGeneratorExtensions.getAttributes(serviceInterface);
for(final FAttribute attribute_1 : _attributes_3) {
_builder.append("\t\t");
final String attributeName_1 = this._joynrJavaGeneratorExtensions.joynrName(attribute_1);
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
final String attributeType_1 = this._joynrJavaGeneratorExtensions.getMappedDatatypeOrList(attribute_1);
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.newLine();
{
boolean _isReadable = this._joynrJavaGeneratorExtensions.isReadable(attribute_1);
if (_isReadable) {
_builder.append("\t\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t\t");
_builder.append("public abstract ");
_builder.append(attributeType_1, " ");
_builder.append(" get");
String _firstUpper = StringExtensions.toFirstUpper(attributeName_1);
_builder.append(_firstUpper, " ");
_builder.append("();");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.newLine();
{
boolean _isNotifiable = this._joynrJavaGeneratorExtensions.isNotifiable(attribute_1);
if (_isNotifiable) {
_builder.append("\t\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t\t");
_builder.append("public final void ");
String _firstLower = StringExtensions.toFirstLower(attributeName_1);
_builder.append(_firstLower, " ");
_builder.append("Changed(");
_builder.append(attributeType_1, " ");
_builder.append(" ");
_builder.append(attributeName_1, " ");
_builder.append(") {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("\t");
_builder.append("this.");
_builder.append(attributeName_1, " ");
_builder.append(" = ");
_builder.append(attributeName_1, " ");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("\t");
_builder.append("onAttributeValueChanged(\"");
_builder.append(attributeName_1, " ");
_builder.append("\", this.");
_builder.append(attributeName_1, " ");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
}
}
_builder.newLine();
{
boolean _isWritable = this._joynrJavaGeneratorExtensions.isWritable(attribute_1);
if (_isWritable) {
_builder.append("\t\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t\t");
_builder.append("public abstract void set");
String _firstUpper_1 = StringExtensions.toFirstUpper(attributeName_1);
_builder.append(_firstUpper_1, " ");
_builder.append("(");
_builder.append(attributeType_1, " ");
_builder.append(" ");
_builder.append(attributeName_1, " ");
_builder.append(");");
_builder.newLineIfNotEmpty();
}
}
}
}
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public ProviderQos getProviderQos() {");
_builder.newLine();
_builder.append("\t");
_builder.append("return providerQos;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_xblockexpression = (_builder);
}
return _xblockexpression;
}
}