aboutsummaryrefslogtreecommitdiffstats
path: root/rba.tool.editor/src/rba/tool/editor/validation/validators/SoundContentSetValidator.xtend
diff options
context:
space:
mode:
authorKenji Hosokawa <khosokawa@jp.adit-jv.com>2021-08-03 18:42:39 +0900
committerKenji Hosokawa <khosokawa@jp.adit-jv.com>2021-08-06 19:32:38 +0900
commitbe4f78978faba3d3ceb88df02a7f93a2e09ff1e0 (patch)
tree1f3f1a96251ac4f655c8a96fc33d5d4ee779cd06 /rba.tool.editor/src/rba/tool/editor/validation/validators/SoundContentSetValidator.xtend
parent71ca7c6cab863767ef30c8bd05b2bbfda8731cb5 (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/validation/validators/SoundContentSetValidator.xtend')
-rw-r--r--rba.tool.editor/src/rba/tool/editor/validation/validators/SoundContentSetValidator.xtend70
1 files changed, 70 insertions, 0 deletions
diff --git a/rba.tool.editor/src/rba/tool/editor/validation/validators/SoundContentSetValidator.xtend b/rba.tool.editor/src/rba/tool/editor/validation/validators/SoundContentSetValidator.xtend
new file mode 100644
index 0000000..b12cd3c
--- /dev/null
+++ b/rba.tool.editor/src/rba/tool/editor/validation/validators/SoundContentSetValidator.xtend
@@ -0,0 +1,70 @@
+package rba.tool.editor.validation.validators
+
+import java.util.HashSet
+import org.eclipse.xtext.validation.Check
+import rba.core.AbstractAllocatable
+import rba.core.AbstractContent
+import rba.core.RBACorePackage
+import rba.sound.SoundContent
+import rba.sound.SoundContentSet
+import rba.sound.Zone
+import rba.sound.ZoneSet
+import rba.tool.editor.messages.Messages
+
+class SoundContentSetValidator extends ContentSetValidator {
+
+ private String SOUNDCONTENTSET_TARGET_SIZE = Messages.SOUNDCONTENTSET_TARGET_SIZE;
+
+ private String SOUNDCONTENTSET_TARGET_INVALID_TYPE = Messages.SOUNDCONTENTSET_TARGET_INVALID_TYPE;
+
+ private String SOUNDCONTENTSET_TARGET_INCLUDE_SELF = Messages.SOUNDCONTENTSET_TARGET_INCLUDE_SELF;
+
+ private String SOUNDCONTENTSET_TARGET_DUPLICATE = Messages.SOUNDCONTENTSET_TARGET_DUPLICATE;
+
+ private String SOUNDCONTENTSET_ALLOCATABLE_INVALID_TYPE = Messages.SOUNDCONTENTSET_ALLOCATABLE_INVALID_TYPE;
+
+ private String SOUNDCONTENTSET_ALLOCATABLE_DUPLICATE = Messages.SOUNDCONTENTSET_ALLOCATABLE_DUPLICATE;
+
+ @Check(NORMAL)
+ def checkContent(SoundContentSet soundContentSet) {
+ if (soundContentSet.target.size === 0) {
+ warning(String.format(SOUNDCONTENTSET_TARGET_SIZE, soundContentSet.name), RBACorePackage.Literals.CONTENT_SET__TARGET);
+ }
+
+ if (soundContentSet.target.contains(soundContentSet)) {
+ error(String.format(SOUNDCONTENTSET_TARGET_INCLUDE_SELF, soundContentSet.name), RBACorePackage.Literals.CONTENT_SET__TARGET,
+ soundContentSet.target.indexOf(soundContentSet));
+ return;
+ }
+
+ var hash = new HashSet<AbstractContent>
+ for (var index = 0; index < soundContentSet.target.size; index.operator_plusPlus()) {
+ val AbstractContent abstractContent = soundContentSet.target.get(index);
+ if (!(abstractContent instanceof SoundContent || abstractContent instanceof SoundContentSet)) {
+ error(String.format(SOUNDCONTENTSET_TARGET_INVALID_TYPE, soundContentSet.name), RBACorePackage.Literals.CONTENT_SET__TARGET, index);
+ return;
+ }
+ if (hash.contains(abstractContent)) {
+ error(String.format(SOUNDCONTENTSET_TARGET_DUPLICATE, soundContentSet.name), RBACorePackage.Literals.CONTENT_SET__TARGET, index);
+ return;
+ } else {
+ hash.add(abstractContent)
+ }
+ }
+
+ var allocatableSet = new HashSet<AbstractAllocatable>
+ for (var index = 0; index < soundContentSet.allocatable.size; index.operator_plusPlus()) {
+ val AbstractAllocatable abstractAllocatable = soundContentSet.allocatable.get(index);
+ if (!(abstractAllocatable instanceof Zone || abstractAllocatable instanceof ZoneSet)) {
+ error(String.format(SOUNDCONTENTSET_ALLOCATABLE_INVALID_TYPE, soundContentSet.name), RBACorePackage.Literals.ABSTRACT_CONTENT__ALLOCATABLE, index);
+ return;
+ }
+ if (allocatableSet.contains(abstractAllocatable)) {
+ error(String.format(SOUNDCONTENTSET_ALLOCATABLE_DUPLICATE, soundContentSet.name), RBACorePackage.Literals.ABSTRACT_CONTENT__ALLOCATABLE, index);
+ return;
+ } else {
+ allocatableSet.add(abstractAllocatable)
+ }
+ }
+ }
+}