io.joynr.generator.provider.InterfaceAbstractProviderTemplate Maven / Gradle / Ivy
The newest version!
package io.joynr.generator.provider;
import com.google.inject.Inject;
import io.joynr.generator.templates.InterfaceTemplate;
import io.joynr.generator.templates.util.AttributeUtil;
import io.joynr.generator.templates.util.InterfaceUtil;
import io.joynr.generator.templates.util.NamingUtil;
import io.joynr.generator.util.JavaTypeUtil;
import io.joynr.generator.util.JoynrJavaGeneratorExtensions;
import io.joynr.generator.util.TemplateBase;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.Conversions;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.franca.core.franca.FAttribute;
import org.franca.core.franca.FBroadcast;
@SuppressWarnings("all")
public class InterfaceAbstractProviderTemplate extends InterfaceTemplate {
@Inject
@Extension
private JoynrJavaGeneratorExtensions _joynrJavaGeneratorExtensions;
@Inject
@Extension
private JavaTypeUtil _javaTypeUtil;
@Inject
@Extension
private NamingUtil _namingUtil;
@Inject
@Extension
private InterfaceUtil _interfaceUtil;
@Inject
@Extension
private AttributeUtil _attributeUtil;
@Inject
@Extension
private TemplateBase _templateBase;
@Override
public CharSequence generate(final boolean generateVersion) {
CharSequence _xblockexpression = null;
{
final String interfaceName = this._namingUtil.joynrName(this.francaIntf);
final String className = (interfaceName + "AbstractProvider");
final String providerInterfaceName = (interfaceName + "Provider");
final String packagePath = this._joynrJavaGeneratorExtensions.getPackagePathWithJoynrPrefix(this.francaIntf, ".", generateVersion);
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 io.joynr.provider.AbstractJoynrProvider;");
_builder.newLine();
{
boolean _isEmpty = this.francaIntf.getBroadcasts().isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
_builder.append("import java.util.Set;");
_builder.newLine();
_builder.append("import java.util.HashSet;");
_builder.newLine();
_builder.append("import io.joynr.pubsub.publication.BroadcastFilterImpl;");
_builder.newLine();
}
}
_builder.newLine();
{
Iterable _requiredIncludesFor = this._joynrJavaGeneratorExtensions.getRequiredIncludesFor(this.francaIntf, false, false, false, true, true, false, generateVersion);
for(final String datatype : _requiredIncludesFor) {
_builder.append("import ");
_builder.append(datatype);
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
_builder.append("public abstract class ");
_builder.append(className);
_builder.append(" extends AbstractJoynrProvider implements ");
_builder.append(providerInterfaceName);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("public ");
_builder.append(className, "\t");
_builder.append("() {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("super();");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
{
if ((this._interfaceUtil.hasNotifiableAttribute(this.francaIntf) || (!this.francaIntf.getBroadcasts().isEmpty()))) {
{
boolean _isEmpty_1 = this.francaIntf.getBroadcasts().isEmpty();
boolean _not_1 = (!_isEmpty_1);
if (_not_1) {
_builder.append("\t");
_builder.append("private Set queuedBroadcastFilters = new HashSet<>();");
_builder.newLine();
}
}
_builder.newLine();
_builder.append("\t");
_builder.append("protected ");
_builder.append(interfaceName, "\t");
_builder.append("SubscriptionPublisher ");
String _firstLower = StringExtensions.toFirstLower(interfaceName);
_builder.append(_firstLower, "\t");
_builder.append("SubscriptionPublisher;");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public void setSubscriptionPublisher(");
_builder.append(interfaceName, "\t");
_builder.append("SubscriptionPublisher ");
String _firstLower_1 = StringExtensions.toFirstLower(interfaceName);
_builder.append(_firstLower_1, "\t");
_builder.append("SubscriptionPublisher) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("this.");
String _firstLower_2 = StringExtensions.toFirstLower(interfaceName);
_builder.append(_firstLower_2, "\t\t");
_builder.append("SubscriptionPublisher = ");
String _firstLower_3 = StringExtensions.toFirstLower(interfaceName);
_builder.append(_firstLower_3, "\t\t");
_builder.append("SubscriptionPublisher;");
_builder.newLineIfNotEmpty();
{
boolean _isEmpty_2 = this.francaIntf.getBroadcasts().isEmpty();
boolean _not_2 = (!_isEmpty_2);
if (_not_2) {
_builder.append("\t");
_builder.append("\t");
_builder.append("for (BroadcastFilterImpl filter: queuedBroadcastFilters) {");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("\t");
_builder.append("this.");
String _firstLower_4 = StringExtensions.toFirstLower(interfaceName);
_builder.append(_firstLower_4, "\t\t\t");
_builder.append("SubscriptionPublisher.addBroadcastFilter(filter);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("queuedBroadcastFilters.clear();");
_builder.newLine();
}
}
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
{
boolean _isEmpty_3 = this.francaIntf.getBroadcasts().isEmpty();
boolean _not_3 = (!_isEmpty_3);
if (_not_3) {
_builder.append("\t");
_builder.append("public void addBroadcastFilter(BroadcastFilterImpl filter) {");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("if (this.");
String _firstLower_5 = StringExtensions.toFirstLower(interfaceName);
_builder.append(_firstLower_5, "\t\t");
_builder.append("SubscriptionPublisher != null) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t\t");
_builder.append("this.");
String _firstLower_6 = StringExtensions.toFirstLower(interfaceName);
_builder.append(_firstLower_6, "\t\t\t");
_builder.append("SubscriptionPublisher.addBroadcastFilter(filter);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("} else {");
_builder.newLine();
_builder.append("\t");
_builder.append("\t\t");
_builder.append("queuedBroadcastFilters.add(filter);");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("public void addBroadcastFilter(BroadcastFilterImpl... filters) {");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("if (this.");
String _firstLower_7 = StringExtensions.toFirstLower(interfaceName);
_builder.append(_firstLower_7, "\t\t");
_builder.append("SubscriptionPublisher != null) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t\t");
_builder.append("this.");
String _firstLower_8 = StringExtensions.toFirstLower(interfaceName);
_builder.append(_firstLower_8, "\t\t\t");
_builder.append("SubscriptionPublisher.addBroadcastFilter(filters);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("} else {");
_builder.newLine();
_builder.append("\t");
_builder.append("\t\t");
_builder.append("for (BroadcastFilterImpl filter: filters) {");
_builder.newLine();
_builder.append("\t");
_builder.append("\t\t\t");
_builder.append("queuedBroadcastFilters.add(filter);");
_builder.newLine();
_builder.append("\t");
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
}
}
}
}
_builder.newLine();
{
final Function1 _function = new Function1() {
@Override
public Boolean apply(final FAttribute a) {
return Boolean.valueOf(InterfaceAbstractProviderTemplate.this._attributeUtil.isNotifiable(a));
}
};
Iterable _filter = IterableExtensions.filter(this._interfaceUtil.getAttributes(this.francaIntf), _function);
for(final FAttribute attribute : _filter) {
_builder.append("\t");
final String attributeName = this._namingUtil.joynrName(attribute);
_builder.newLineIfNotEmpty();
_builder.append("\t");
final String attributeType = this._javaTypeUtil.getTypeName(attribute);
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("public void ");
_builder.append(attributeName, "\t");
_builder.append("Changed(");
_builder.append(attributeType, "\t");
_builder.append(" ");
_builder.append(attributeName, "\t");
_builder.append(") {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("if (");
String _firstLower_9 = StringExtensions.toFirstLower(interfaceName);
_builder.append(_firstLower_9, "\t\t");
_builder.append("SubscriptionPublisher != null) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t\t");
String _firstLower_10 = StringExtensions.toFirstLower(interfaceName);
_builder.append(_firstLower_10, "\t\t\t");
_builder.append("SubscriptionPublisher.");
_builder.append(attributeName, "\t\t\t");
_builder.append("Changed(");
_builder.append(attributeName, "\t\t\t");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
}
}
_builder.newLine();
{
final Function1 _function_1 = new Function1() {
@Override
public Boolean apply(final FBroadcast it) {
return Boolean.valueOf(it.isSelective());
}
};
Iterable _filter_1 = IterableExtensions.filter(this.francaIntf.getBroadcasts(), _function_1);
for(final FBroadcast broadcast : _filter_1) {
_builder.append("\t");
String broadcastName = this._namingUtil.joynrName(broadcast);
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("public void fire");
String _firstUpper = StringExtensions.toFirstUpper(broadcastName);
_builder.append(_firstUpper, "\t");
_builder.append("(");
String _commaSeperatedTypedOutputParameterList = this._javaTypeUtil.getCommaSeperatedTypedOutputParameterList(broadcast);
_builder.append(_commaSeperatedTypedOutputParameterList, "\t");
_builder.append(") {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("if (");
String _firstLower_11 = StringExtensions.toFirstLower(interfaceName);
_builder.append(_firstLower_11, "\t\t");
_builder.append("SubscriptionPublisher != null) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t\t");
String _firstLower_12 = StringExtensions.toFirstLower(interfaceName);
_builder.append(_firstLower_12, "\t\t\t");
_builder.append("SubscriptionPublisher.fire");
String _firstUpper_1 = StringExtensions.toFirstUpper(broadcastName);
_builder.append(_firstUpper_1, "\t\t\t");
_builder.append("(");
String _commaSeperatedUntypedOutputParameterList = this._javaTypeUtil.getCommaSeperatedUntypedOutputParameterList(broadcast);
_builder.append(_commaSeperatedUntypedOutputParameterList, "\t\t\t");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
}
}
{
final Function1 _function_2 = new Function1() {
@Override
public Boolean apply(final FBroadcast it) {
boolean _isSelective = it.isSelective();
return Boolean.valueOf((!_isSelective));
}
};
Iterable _filter_2 = IterableExtensions.filter(this.francaIntf.getBroadcasts(), _function_2);
for(final FBroadcast broadcast_1 : _filter_2) {
_builder.append("\t");
String broadcastName_1 = this._namingUtil.joynrName(broadcast_1);
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("public void fire");
String _firstUpper_2 = StringExtensions.toFirstUpper(broadcastName_1);
_builder.append(_firstUpper_2, "\t");
_builder.append("(");
String _commaSeperatedTypedOutputParameterList_1 = this._javaTypeUtil.getCommaSeperatedTypedOutputParameterList(broadcast_1);
_builder.append(_commaSeperatedTypedOutputParameterList_1, "\t");
{
int _length = ((Object[])Conversions.unwrapArray(this._broadcastUtil.getOutputParameters(broadcast_1), Object.class)).length;
boolean _greaterThan = (_length > 0);
if (_greaterThan) {
_builder.append(", ");
}
}
_builder.append("String... partitions) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("if (");
String _firstLower_13 = StringExtensions.toFirstLower(interfaceName);
_builder.append(_firstLower_13, "\t\t");
_builder.append("SubscriptionPublisher != null) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t\t");
String _firstLower_14 = StringExtensions.toFirstLower(interfaceName);
_builder.append(_firstLower_14, "\t\t\t");
_builder.append("SubscriptionPublisher.fire");
String _firstUpper_3 = StringExtensions.toFirstUpper(broadcastName_1);
_builder.append(_firstUpper_3, "\t\t\t");
_builder.append("(");
String _commaSeperatedUntypedOutputParameterList_1 = this._javaTypeUtil.getCommaSeperatedUntypedOutputParameterList(broadcast_1);
_builder.append(_commaSeperatedUntypedOutputParameterList_1, "\t\t\t");
{
int _length_1 = ((Object[])Conversions.unwrapArray(this._broadcastUtil.getOutputParameters(broadcast_1), Object.class)).length;
boolean _greaterThan_1 = (_length_1 > 0);
if (_greaterThan_1) {
_builder.append(", ");
}
}
_builder.append("partitions);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
}
}
_builder.append("}");
_builder.newLine();
_xblockexpression = _builder;
}
return _xblockexpression;
}
}