io.joynr.generator.interfaces.InterfacesTemplate Maven / Gradle / Ivy
package io.joynr.generator.interfaces;
import com.google.common.base.Objects;
import com.google.inject.Inject;
import io.joynr.generator.util.JoynrJavaGeneratorExtensions;
import io.joynr.generator.util.TemplateBase;
import java.util.ArrayList;
import java.util.Collection;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.Extension;
import org.franca.core.franca.FInterface;
@SuppressWarnings("all")
public class InterfacesTemplate {
@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;
final String packagePath = this._joynrJavaGeneratorExtensions.getPackagePathWithJoynrPrefix(serviceInterface, ".");
StringConcatenation _builder = new StringConcatenation();
_builder.newLine();
_builder.append("\t\t");
CharSequence _warning = this._templateBase.warning();
_builder.append(_warning, " ");
_builder.append(" ");
_builder.newLineIfNotEmpty();
_builder.append("package ");
_builder.append(packagePath, "");
_builder.append("; \t");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("import java.util.List;");
_builder.newLine();
_builder.newLine();
_builder.append("import com.fasterxml.jackson.core.type.TypeReference;");
_builder.newLine();
{
Iterable _requiredIncludesFor = this._joynrJavaGeneratorExtensions.getRequiredIncludesFor(serviceInterface);
for(final String datatype : _requiredIncludesFor) {
_builder.append("import ");
_builder.append(datatype, "");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
_builder.append("//The current generator is not able to check wether some of the imports are acutally necessary for this specific interface.");
_builder.newLine();
_builder.append("//Therefore some imports migth be unused in this version of the interface.");
_builder.newLine();
_builder.append("//To prevent warnings @SuppressWarnings(\"unused\") is being used. ");
_builder.newLine();
_builder.append("//To prevent warnings about an unnecessary SuppressWarnings we have to import something that is not used. (e.g. TreeSet)");
_builder.newLine();
_builder.append("import java.util.TreeSet;");
_builder.newLine();
_builder.append("@SuppressWarnings(\"unused\")");
_builder.newLine();
_builder.append("public interface ");
_builder.append(className, "");
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("public static String INTERFACE_NAME = \"");
String _packagePathWithoutJoynrPrefix = this._joynrJavaGeneratorExtensions.getPackagePathWithoutJoynrPrefix(serviceInterface, "/");
_builder.append(_packagePathWithoutJoynrPrefix, " ");
_builder.append("/");
String _lowerCase = interfaceName.toLowerCase();
_builder.append(_lowerCase, " ");
_builder.append("\";");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.newLine();
{
Collection