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/scoping/internal/RBAModelMemberOperationRegistry.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/scoping/internal/RBAModelMemberOperationRegistry.xtend')
-rw-r--r-- | rba.tool.editor/src/rba/tool/editor/scoping/internal/RBAModelMemberOperationRegistry.xtend | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/rba.tool.editor/src/rba/tool/editor/scoping/internal/RBAModelMemberOperationRegistry.xtend b/rba.tool.editor/src/rba/tool/editor/scoping/internal/RBAModelMemberOperationRegistry.xtend new file mode 100644 index 0000000..b641362 --- /dev/null +++ b/rba.tool.editor/src/rba/tool/editor/scoping/internal/RBAModelMemberOperationRegistry.xtend @@ -0,0 +1,68 @@ +package rba.tool.editor.scoping.internal + +import com.google.inject.Inject +import com.google.inject.Singleton +import java.util.Collections +import java.util.Map +import java.util.Set +import java.util.regex.Matcher +import java.util.regex.Pattern +import org.eclipse.emf.ecore.EObject +import org.eclipse.xtext.GrammarUtil +import org.eclipse.xtext.IGrammarAccess +import org.eclipse.xtext.Keyword +import org.eclipse.xtext.generator.parser.antlr.FirstSetComputer +import org.eclipse.xtext.naming.QualifiedName +import org.eclipse.xtext.resource.IEObjectDescription +import rba.core.ExpressionType +import rba.core.Operator +import rba.core.RuleObject +import rba.tool.editor.resource.RBAModelEObjectDescription +import rba.tool.editor.scoping.IExpressionScope + +@Singleton +class RBAModelMemberOperationRegistry { + + private static Map<String, String> EMPTY_USERDATA = Collections.<String, String>emptyMap(); + private static Pattern pattern = Pattern.compile("^ConfigurationParserRule_([A-Za-z]+)OperatorFor([A-Za-z]+)$"); + private static String DESCRIPTION_KEY = "%s_%s"; + private static String QUALIFIED_NAME = "%s()"; + + private final Map<String, Set<IEObjectDescription>> operations = newLinkedHashMap(); + + @Inject + public new(IGrammarAccess grammarAccess) { + registerOperations(grammarAccess); + } + + def protected void registerOperations(IGrammarAccess grammarAccess) { + val multipleOperandParserRule = GrammarUtil.findRuleForName(grammarAccess.getGrammar(), "ConfigurationParserRule_OperatorWithMultipleOperand"); + val multipleOperandConfiguration = FirstSetComputer.getFirstSet(multipleOperandParserRule.alternatives).filter(Keyword).toList; + val allConfigurations = GrammarUtil.allRules(grammarAccess.getGrammar()).filter(r|pattern.matcher(r.name).find); + for (configuration : allConfigurations) { + val Matcher matcher = pattern.matcher(configuration.name); + if (matcher.find) { + val descriptionKey = String.format(DESCRIPTION_KEY, matcher.group(1), matcher.group(2)).toUpperCase; + val descriptionEntries = newHashSet(); + val keywords = FirstSetComputer.getFirstSet(configuration.alternatives).filter(Keyword); + for (keyword : keywords) { + descriptionEntries.add( + new RBAModelEObjectDescription(QualifiedName.create(String.format(QUALIFIED_NAME, keyword.value)), null, EMPTY_USERDATA, + #[if (multipleOperandConfiguration.contains(keyword)) -1 else 0, -50])); + } + operations.put(descriptionKey, descriptionEntries); + } + } + } + + def public Set<IEObjectDescription> getOperations(EObject model, IExpressionScope.Anchor anchor) { + var ExpressionType expressionType = ExpressionType.BOOLEAN; + if (model instanceof RuleObject) { + expressionType = (model as RuleObject).expressionType; + } else if (model instanceof Operator) { + expressionType = (model as Operator).underlyingType; + } + return operations.get(String.format(DESCRIPTION_KEY, expressionType.getName(), anchor.name)); + } + +} |