org.openprovenance.prov.template.compiler.CompilerTemplateBuilders Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of prov-template-compiler Show documentation
Show all versions of prov-template-compiler Show documentation
A template system for PROV bundles.
The newest version!
package org.openprovenance.prov.template.compiler;
import com.squareup.javapoet.*;
import org.openprovenance.prov.model.ProvFactory;
import org.openprovenance.prov.template.compiler.common.BeanDirection;
import org.openprovenance.prov.template.compiler.common.Constants;
import org.openprovenance.prov.template.compiler.configuration.*;
import javax.lang.model.element.Modifier;
import static org.openprovenance.prov.template.compiler.common.Constants.DOT_JAVA_EXTENSION;
import static org.openprovenance.prov.template.compiler.common.Constants.LOGGER;
public class CompilerTemplateBuilders {
private final CompilerUtil compilerUtil;
public CompilerTemplateBuilders(ProvFactory pFactory) {
this.compilerUtil=new CompilerUtil(pFactory);
}
SpecificationFile generateTemplateBuilders(TemplatesProjectConfiguration configs, Locations locations, String fileName) {
StackTraceElement stackTraceElement=compilerUtil.thisMethodAndLine();
TypeSpec.Builder builder = compilerUtil.generateClassInit(Constants.TEMPLATE_BUILDERS);
for (TemplateCompilerConfig config : configs.templates) {
if (!(config instanceof SimpleTemplateCompilerConfig)) continue;
final String templateNameClass = compilerUtil.templateNameClass(config.name);
locations.updateWithConfig(config);
final ClassName className = ClassName.get(locations.getFilePackage(BeanDirection.COMMON), templateNameClass);
FieldSpec fspec = FieldSpec.builder(className, config.name + "Builder")
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
.initializer(LOGGER + "." + Constants.GENERATED_VAR_PREFIX + config.name)
.build();
builder.addField(fspec);
}
TypeSpec theLogger = builder.build();
String myPackage=locations.getFilePackage(fileName);
JavaFile myfile = compilerUtil.specWithComment(theLogger, configs, myPackage, stackTraceElement);
return new SpecificationFile(myfile, locations.convertToDirectory(myPackage), fileName+DOT_JAVA_EXTENSION, myPackage);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy