diff options
author | 2021-08-03 18:42:39 +0900 | |
---|---|---|
committer | 2021-08-06 19:32:38 +0900 | |
commit | be4f78978faba3d3ceb88df02a7f93a2e09ff1e0 (patch) | |
tree | 1f3f1a96251ac4f655c8a96fc33d5d4ee779cd06 /rba.tool.editor/src/rba/tool/editor/generator/RBAModelGeneratorDelegate.xtend | |
parent | 71ca7c6cab863767ef30c8bd05b2bbfda8731cb5 (diff) |
Initial commit
Bug-AGL: SPEC-4033
Signed-off-by: Kenji Hosokawa <khosokawa@jp.adit-jv.com>
Diffstat (limited to 'rba.tool.editor/src/rba/tool/editor/generator/RBAModelGeneratorDelegate.xtend')
-rw-r--r-- | rba.tool.editor/src/rba/tool/editor/generator/RBAModelGeneratorDelegate.xtend | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/rba.tool.editor/src/rba/tool/editor/generator/RBAModelGeneratorDelegate.xtend b/rba.tool.editor/src/rba/tool/editor/generator/RBAModelGeneratorDelegate.xtend new file mode 100644 index 0000000..5d0b582 --- /dev/null +++ b/rba.tool.editor/src/rba/tool/editor/generator/RBAModelGeneratorDelegate.xtend @@ -0,0 +1,184 @@ +package rba.tool.editor.generator + +import com.google.inject.Inject +import java.util.Set +import org.eclipse.emf.ecore.resource.Resource +import org.eclipse.emf.ecore.resource.ResourceSet +import org.eclipse.xtext.generator.GeneratorContext +import org.eclipse.xtext.generator.IFileSystemAccess +import org.eclipse.xtext.generator.IFileSystemAccess2 +import org.eclipse.xtext.generator.IGenerator +import org.eclipse.xtext.generator.IGenerator2 +import org.eclipse.xtext.generator.IGeneratorContext +import org.eclipse.xtext.generator.OutputConfiguration +import org.eclipse.xtext.util.CancelIndicator +import rba.tool.editor.generator.json.IJSONGenerator +import rba.tool.editor.generator.rtmodel.IRTModelUpdater +import rba.tool.editor.generator.z3.IConstraintGenerator +import rba.tool.editor.generator.z3.ISortValueGenerator + +class RBAModelGeneratorDelegate implements IGenerator, IGenerator2 { + + @Inject(optional=true) + private ISortValueGenerator sortValueGenerator; + + private ThreadLocal<Boolean> sortValueGeneratorInBuilding = new ThreadLocal<Boolean>() { + override protected initialValue() { + return false; + } + }; + + @Inject(optional=true) + private IRTModelUpdater rtModelUpdater; + + private ThreadLocal<Boolean> rtModelUpdaterInBuilding = new ThreadLocal<Boolean>() { + override protected initialValue() { + return false; + } + }; + + @Inject(optional=true) + private IConstraintGenerator constraintGenerator; + + private ThreadLocal<Boolean> constraintGeneratorInBuilding = new ThreadLocal<Boolean>() { + override protected initialValue() { + return false; + } + }; + + @Inject(optional=true) + private IJSONGenerator jsonGenerator; + + private ThreadLocal<Boolean> jsonGeneratorInBuilding = new ThreadLocal<Boolean>() { + override protected initialValue() { + return false; + } + }; + + def public void generate(Resource input, IFileSystemAccess2 fsa, IGeneratorContext context) { + generate(input.resourceSet, fsa, context); + } + + def public void generate(ResourceSet input, IFileSystemAccess2 fsa, IGeneratorContext context) { + if (sortValueGenerator !== null && !sortValueGeneratorInBuilding.get.booleanValue) { + sortValueGeneratorInBuilding.set(true); + } + if (rtModelUpdater !== null && !rtModelUpdaterInBuilding.get.booleanValue) { + rtModelUpdaterInBuilding.set(true); + } + if (constraintGenerator !== null && !constraintGeneratorInBuilding.get.booleanValue) { + constraintGeneratorInBuilding.set(true); + } + if (jsonGenerator !== null && !jsonGeneratorInBuilding.get.booleanValue) { + jsonGeneratorInBuilding.set(true); + } + + try { + beforeGenerate(input, fsa, context); + doGenerate(input, fsa, context); + } finally { + afterGenerate(input, fsa, context); + } + } + + override doGenerate(Resource input, IFileSystemAccess2 fsa, IGeneratorContext context) { + doGenerate(input.resourceSet, fsa, context); + } + + def void doGenerate(ResourceSet input, IFileSystemAccess2 fsa, IGeneratorContext context) { + if (sortValueGenerator !== null && sortValueGeneratorInBuilding.get.booleanValue) { + sortValueGenerator.doGenerate(input, fsa, context); + } + if (rtModelUpdater !== null && rtModelUpdaterInBuilding.get.booleanValue) { + rtModelUpdater.doGenerate(input, fsa, context); + } + if (constraintGenerator !== null && constraintGeneratorInBuilding.get.booleanValue) { + constraintGenerator.doGenerate(input, fsa, context); + } + if (jsonGenerator !== null && jsonGeneratorInBuilding.get.booleanValue) { + jsonGenerator.doGenerate(input, fsa, context); + } + } + + override beforeGenerate(Resource input, IFileSystemAccess2 fsa, IGeneratorContext context) { + beforeGenerate(input.resourceSet, fsa, context); + } + + def void beforeGenerate(ResourceSet input, IFileSystemAccess2 fsa, IGeneratorContext context) { + if (sortValueGenerator !== null && sortValueGeneratorInBuilding.get.booleanValue) { + sortValueGenerator.beforeGenerate(input, fsa, context); + } + if (rtModelUpdater !== null && rtModelUpdaterInBuilding.get.booleanValue) { + rtModelUpdater.beforeGenerate(input, fsa, context); + } + if (constraintGenerator !== null && constraintGeneratorInBuilding.get.booleanValue) { + constraintGenerator.beforeGenerate(input, fsa, context); + } + if (jsonGenerator !== null && jsonGeneratorInBuilding.get.booleanValue) { + jsonGenerator.beforeGenerate(input, fsa, context); + } + } + + override afterGenerate(Resource input, IFileSystemAccess2 fsa, IGeneratorContext context) { + afterGenerate(input.resourceSet, fsa, context); + } + + def void afterGenerate(ResourceSet input, IFileSystemAccess2 fsa, IGeneratorContext context) { + if (sortValueGenerator !== null && sortValueGeneratorInBuilding.get.booleanValue) { + sortValueGenerator.afterGenerate(input, fsa, context); + } + if (rtModelUpdater !== null && rtModelUpdaterInBuilding.get.booleanValue) { + rtModelUpdater.afterGenerate(input, fsa, context); + } + if (constraintGenerator !== null && constraintGeneratorInBuilding.get.booleanValue) { + constraintGenerator.afterGenerate(input, fsa, context); + } + if (jsonGenerator !== null && jsonGeneratorInBuilding.get.booleanValue) { + jsonGenerator.afterGenerate(input, fsa, context); + } + } + + override doGenerate(Resource input, IFileSystemAccess fsa) { + doGenerate(input.resourceSet, fsa); + } + + def void doGenerate(ResourceSet input, IFileSystemAccess fsa) { + val casted = fsa as IFileSystemAccess2; + val context = new GeneratorContext(); + context.setCancelIndicator(CancelIndicator.NullImpl); + try { + beforeGenerate(input, casted, context); + doGenerate(input, casted, context); + } finally { + afterGenerate(input, casted, context); + } + } + + def public void setRBAModelInBuilding(boolean value) { + sortValueGeneratorInBuilding.set(value); + rtModelUpdaterInBuilding.set(value); + constraintGeneratorInBuilding.set(value); + jsonGeneratorInBuilding.set(value); + } + + def public boolean isRBAModelInBuilding() { + if (sortValueGeneratorInBuilding.get().booleanValue) { + return true; + } + if (rtModelUpdaterInBuilding.get().booleanValue) { + return true; + } + if (constraintGeneratorInBuilding.get().booleanValue) { + return true; + } + if (jsonGeneratorInBuilding.get().booleanValue) { + return true; + } + return false; + } + + def public Set<OutputConfiguration> getRBAModelGeneratorOutputConfigurations() { + return newHashSet(IJSONGenerator.OUTPUT_CONFIGURATION); + } + +} |