io.joynr.generator.provider.InterfaceProviderTemplate 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 InterfaceProviderTemplate {
@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 + "Provider");
final String syncClassName = (interfaceName + "Sync");
final String packagePath = this._joynrJavaGeneratorExtensions.getPackagePathWithJoynrPrefix(serviceInterface, ".");
StringConcatenation _builder = new StringConcatenation();
_builder.newLine();
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.JoynrProvider;");
_builder.newLine();
_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("//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.append("\t");
_builder.newLine();
_builder.append("public interface ");
_builder.append(className, "");
_builder.append(" extends ");
_builder.append(syncClassName, "");
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
{
EList _attributes = this._joynrJavaGeneratorExtensions.getAttributes(serviceInterface);
for(final FAttribute attribute : _attributes) {
_builder.append("\t");
final String attributeName = this._joynrJavaGeneratorExtensions.joynrName(attribute);
_builder.newLineIfNotEmpty();
_builder.append("\t");
final String attributeType = this._joynrJavaGeneratorExtensions.getMappedDatatypeOrList(attribute);
_builder.newLineIfNotEmpty();
{
boolean _isReadable = this._joynrJavaGeneratorExtensions.isReadable(attribute);
if (_isReadable) {
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public ");
_builder.append(attributeType, " ");
_builder.append(" get");
String _firstUpper = StringExtensions.toFirstUpper(attributeName);
_builder.append(_firstUpper, " ");
_builder.append("();");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
{
boolean _isNotifiable = this._joynrJavaGeneratorExtensions.isNotifiable(attribute);
if (_isNotifiable) {
_builder.append("\t");
_builder.append("public void ");
_builder.append(attributeName, " ");
_builder.append("Changed(");
_builder.append(attributeType, " ");
_builder.append(" ");
_builder.append(attributeName, " ");
_builder.append(");");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
{
boolean _isWritable = this._joynrJavaGeneratorExtensions.isWritable(attribute);
if (_isWritable) {
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public void set");
String _firstUpper_1 = StringExtensions.toFirstUpper(attributeName);
_builder.append(_firstUpper_1, " ");
_builder.append("(");
_builder.append(attributeType, " ");
_builder.append(" ");
_builder.append(attributeName, " ");
_builder.append(");");
_builder.newLineIfNotEmpty();
}
}
}
}
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_xblockexpression = (_builder);
}
return _xblockexpression;
}
}