io.vrap.codegen.languages.javalang.client.builder.predicates.JavaExpansionProducer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-builder-client Show documentation
Show all versions of java-builder-client Show documentation
RAML API client code generators based on the REST Modeling Framework. https://github.com/vrapio/rest-modeling-framework
package io.vrap.codegen.languages.javalang.client.builder.predicates
import io.vrap.codegen.languages.java.base.JavaSubTemplates
import io.vrap.codegen.languages.java.base.extensions.toJavaPackage
import io.vrap.rmf.codegen.io.TemplateFile
import io.vrap.rmf.codegen.rendering.FileProducer
import io.vrap.rmf.codegen.rendering.utils.keepAngleIndent
class JavaExpansionProducer constructor(val basePackageName: String) : FileProducer {
override fun produceFiles(): List {
return listOf(
generateCollectionHelper(),
expansionDsl()
)
}
private fun expansionDsl() : TemplateFile {
val content = """
|package ${basePackageName.toJavaPackage()}.predicates.expansion;
|
|import io.vrap.rmf.base.client.Builder;
|import io.vrap.rmf.base.client.utils.Generated;
|import java.util.List;
|
|<<${JavaSubTemplates.generatedAnnotation}>>
|public interface ExpansionDsl extends Builder {
| public List getPath();
|
| @Override
| public default String build() {
| return String.join(".", getPath());
| }
|}
""".trimMargin().keepAngleIndent()
return TemplateFile(
relativePath = "$basePackageName.predicates.expansion.ExpansionDsl".replace(".", "/") + ".java",
content = content
)
}
private fun generateCollectionHelper() : TemplateFile {
val content = """
|package ${basePackageName.toJavaPackage()}.predicates.expansion;
|
|import io.vrap.rmf.base.client.utils.Generated;
|import java.util.ArrayList;
|import java.util.Collections;
|import java.util.List;
|
|<<${JavaSubTemplates.generatedAnnotation}>>
|public class ExpansionUtil {
|
| public static List appendOne(final List list, T element) {
| final List arr = new ArrayList(list);
| arr.add(element);
| return Collections.unmodifiableList(arr);
| }
|}
""".trimMargin().keepAngleIndent()
return TemplateFile(
relativePath = "$basePackageName.predicates.expansion.ExpansionUtil".replace(".", "/") + ".java",
content = content
)
}
}