diff options
author | Kristóf Marussy <kris7topher@gmail.com> | 2019-02-05 23:54:03 +0100 |
---|---|---|
committer | Kristóf Marussy <kris7topher@gmail.com> | 2019-02-19 19:18:25 +0100 |
commit | 7f7f934fe6ad11df96906d009eec68583fd46660 (patch) | |
tree | 17828b0e833bc89b2b796fcc7da6cb74d6ec3e9c /Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit | |
parent | Generated files change (diff) | |
download | VIATRA-Generator-7f7f934fe6ad11df96906d009eec68583fd46660.tar.gz VIATRA-Generator-7f7f934fe6ad11df96906d009eec68583fd46660.tar.zst VIATRA-Generator-7f7f934fe6ad11df96906d009eec68583fd46660.zip |
[Stochastic] Fault tree transformation langauge
Diffstat (limited to 'Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit')
10 files changed, 466 insertions, 0 deletions
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/CftLanguage.xtext b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/CftLanguage.xtext new file mode 100644 index 00000000..3d82413f --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/CftLanguage.xtext | |||
@@ -0,0 +1,82 @@ | |||
1 | grammar hu.bme.mit.inf.dslreasoner.faulttree.components.CftLanguage with org.eclipse.xtext.common.Terminals | ||
2 | |||
3 | import "http://www.eclipse.org/emf/2002/Ecore" as ecore | ||
4 | import "http://www.eclipse.org/viatra/query/patternlanguage/emf/PatternLanguage" as vql | ||
5 | |||
6 | generate cftLanguage "http://www.bme.hu/mit/inf/dslreasoner/faulttree/components/CftLanguage" | ||
7 | |||
8 | CftModel: | ||
9 | "package" packageName=QualifiedName ";"? | ||
10 | imports+=ImportDeclaration* | ||
11 | (componentDefinitions+=ComponentDefinition | transformationDefinitions+=TransformationDefinition)*; | ||
12 | |||
13 | ImportDeclaration: | ||
14 | "import" importedNamespace=QualifiedNameWithWildcard ";"?; | ||
15 | |||
16 | ComponentDefinition: | ||
17 | "cft" name=ID "{" | ||
18 | (("in" inputEvents+=InputEvent* ";")? & ("out" outputEvents+=[EventDeclaration]* ";")?) | ||
19 | (eventDefinitions+=EventDefinition ";")* | ||
20 | "}"; | ||
21 | |||
22 | EventDeclaration: | ||
23 | InputEvent | EventDefinition; | ||
24 | |||
25 | InputEvent: | ||
26 | name=ID multiple?="[]"?; | ||
27 | |||
28 | EventDefinition: | ||
29 | BasicEventDefinition | GateDefinition; | ||
30 | |||
31 | BasicEventDefinition: | ||
32 | name=ID "lambda" "=" rate=DOULBE; | ||
33 | |||
34 | GateDefinition: | ||
35 | AndGate | OrGate; | ||
36 | |||
37 | AndGate: | ||
38 | name=ID "and" inputEvents+=[EventDeclaration]*; | ||
39 | |||
40 | OrGate: | ||
41 | name=ID "or" inputEvents+=[EventDeclaration]*; | ||
42 | |||
43 | TransformationDefinition: | ||
44 | "transformation" name=ID "{" | ||
45 | mappingDefinitions+=MappingDefinition* | ||
46 | "}"; | ||
47 | |||
48 | MappingDefinition: | ||
49 | topLevel?="toplevel"? "mapping" pattern=[vql::Pattern|QualifiedName] | ||
50 | "(" parameters+=MappingParameter ("," parameters+=MappingParameter)* ")" | ||
51 | (componentInstance=ComponentInstance)? ("{" | ||
52 | ((lookupDefinitions+=LookupDefinition | assignments+=Assignment) ";")* | ||
53 | "}")?; | ||
54 | |||
55 | MappingParameter: | ||
56 | name=ID; | ||
57 | |||
58 | LookupDefinition: | ||
59 | "lookup" mapping=[MappingDefinition] | ||
60 | "(" arguments+=[MappingParameter] ("," arguments+=[MappingParameter])* ")" | ||
61 | "as" name=ID; | ||
62 | |||
63 | Variable: | ||
64 | ComponentInstance | LookupDefinition; | ||
65 | |||
66 | Assignment: | ||
67 | input=EventReference (multiple?="+=" | ":=") output=EventReference; | ||
68 | |||
69 | EventReference: | ||
70 | component=[Variable] "." event=[EventDeclaration]; | ||
71 | |||
72 | ComponentInstance: | ||
73 | "=>" componentType=[ComponentDefinition|QualifiedName] name=ID?; | ||
74 | |||
75 | QualifiedName returns ecore::EString: | ||
76 | ID ("." ID)*; | ||
77 | |||
78 | QualifiedNameWithWildcard returns ecore::EString: | ||
79 | QualifiedName ("." "*")?; | ||
80 | |||
81 | terminal DOULBE returns ecore::EDouble: | ||
82 | ('0'..'9')+ ("." ('0'..'9')+ | ("." ('0'..'9')+)? ("e" | "E") ("+" | "-")? ('0'..'9')+); | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/CftLanguageRuntimeModule.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/CftLanguageRuntimeModule.xtend new file mode 100644 index 00000000..f780591d --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/CftLanguageRuntimeModule.xtend | |||
@@ -0,0 +1,33 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.16.0 | ||
3 | */ | ||
4 | package hu.bme.mit.inf.dslreasoner.faulttree.components | ||
5 | |||
6 | import com.google.inject.Binder | ||
7 | import com.google.inject.name.Names | ||
8 | import hu.bme.mit.inf.dslreasoner.faulttree.components.naming.CftLanguageQualifiedNameProvider | ||
9 | import hu.bme.mit.inf.dslreasoner.faulttree.components.scoping.CftLanguageImportedNamespaceAwareLocalScopeProvider | ||
10 | import org.eclipse.xtext.scoping.IScopeProvider | ||
11 | import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider | ||
12 | import org.eclipse.xtext.scoping.impl.DefaultGlobalScopeProvider | ||
13 | |||
14 | /** | ||
15 | * Use this class to register components to be used at runtime / without the Equinox extension registry. | ||
16 | */ | ||
17 | class CftLanguageRuntimeModule extends AbstractCftLanguageRuntimeModule { | ||
18 | |||
19 | override bindIGlobalScopeProvider() { | ||
20 | DefaultGlobalScopeProvider | ||
21 | } | ||
22 | |||
23 | override configureIScopeProviderDelegate(Binder binder) { | ||
24 | binder.bind(IScopeProvider).annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE)).to( | ||
25 | CftLanguageImportedNamespaceAwareLocalScopeProvider) | ||
26 | } | ||
27 | |||
28 | |||
29 | override bindIQualifiedNameProvider() { | ||
30 | CftLanguageQualifiedNameProvider | ||
31 | } | ||
32 | |||
33 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/CftLanguageStandaloneSetup.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/CftLanguageStandaloneSetup.xtend new file mode 100644 index 00000000..7ec57980 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/CftLanguageStandaloneSetup.xtend | |||
@@ -0,0 +1,15 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.16.0 | ||
3 | */ | ||
4 | package hu.bme.mit.inf.dslreasoner.faulttree.components | ||
5 | |||
6 | |||
7 | /** | ||
8 | * Initialization support for running Xtext languages without Equinox extension registry. | ||
9 | */ | ||
10 | class CftLanguageStandaloneSetup extends CftLanguageStandaloneSetupGenerated { | ||
11 | |||
12 | def static void doSetup() { | ||
13 | new CftLanguageStandaloneSetup().createInjectorAndDoEMFRegistration() | ||
14 | } | ||
15 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/GenerateCftLanguage.mwe2 b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/GenerateCftLanguage.mwe2 new file mode 100644 index 00000000..fa383404 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/GenerateCftLanguage.mwe2 | |||
@@ -0,0 +1,46 @@ | |||
1 | module hu.bme.mit.inf.dslreasoner.faulttree.components.GenerateCftLanguage | ||
2 | |||
3 | import org.eclipse.xtext.xtext.generator.* | ||
4 | import org.eclipse.xtext.xtext.generator.model.project.* | ||
5 | |||
6 | var rootPath = ".." | ||
7 | |||
8 | Workflow { | ||
9 | |||
10 | component = XtextGenerator { | ||
11 | configuration = { | ||
12 | project = StandardProjectConfig { | ||
13 | baseName = "hu.bme.mit.inf.dslreasoner.faulttree.components" | ||
14 | rootPath = rootPath | ||
15 | eclipsePlugin = { | ||
16 | enabled = true | ||
17 | } | ||
18 | createEclipseMetaData = true | ||
19 | } | ||
20 | code = { | ||
21 | encoding = "UTF-8" | ||
22 | lineDelimiter = "\n" | ||
23 | fileHeader = "/*\n * generated by Xtext \${version}\n */" | ||
24 | } | ||
25 | } | ||
26 | language = StandardLanguage { | ||
27 | name = "hu.bme.mit.inf.dslreasoner.faulttree.components.CftLanguage" | ||
28 | fileExtensions = "cft" | ||
29 | |||
30 | referencedResource = "platform:/resource/org.eclipse.emf.ecore/model/Ecore.genmodel" | ||
31 | referencedResource = "platform:/resource/org.eclipse.viatra.query.patternlanguage.emf/model/PatternLanguage.genmodel" | ||
32 | |||
33 | serializer = { | ||
34 | generateStub = false | ||
35 | } | ||
36 | validator = { | ||
37 | // composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator" | ||
38 | // Generates checks for @Deprecated grammar annotations, an IssueProvider and a corresponding PropertyPage | ||
39 | generateDeprecationValidation = true | ||
40 | } | ||
41 | junitSupport = { | ||
42 | junitVersion = "5" | ||
43 | } | ||
44 | } | ||
45 | } | ||
46 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/generator/CftLanguageGenerator.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/generator/CftLanguageGenerator.xtend new file mode 100644 index 00000000..d7ebace4 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/generator/CftLanguageGenerator.xtend | |||
@@ -0,0 +1,25 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.16.0 | ||
3 | */ | ||
4 | package hu.bme.mit.inf.dslreasoner.faulttree.components.generator | ||
5 | |||
6 | import org.eclipse.emf.ecore.resource.Resource | ||
7 | import org.eclipse.xtext.generator.AbstractGenerator | ||
8 | import org.eclipse.xtext.generator.IFileSystemAccess2 | ||
9 | import org.eclipse.xtext.generator.IGeneratorContext | ||
10 | |||
11 | /** | ||
12 | * Generates code from your model files on save. | ||
13 | * | ||
14 | * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation | ||
15 | */ | ||
16 | class CftLanguageGenerator extends AbstractGenerator { | ||
17 | |||
18 | override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) { | ||
19 | // fsa.generateFile('greetings.txt', 'People to greet: ' + | ||
20 | // resource.allContents | ||
21 | // .filter(Greeting) | ||
22 | // .map[name] | ||
23 | // .join(', ')) | ||
24 | } | ||
25 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/naming/CftLanguageQualifiedNameProvider.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/naming/CftLanguageQualifiedNameProvider.xtend new file mode 100644 index 00000000..eb96901c --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/naming/CftLanguageQualifiedNameProvider.xtend | |||
@@ -0,0 +1,27 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.components.naming | ||
2 | |||
3 | import com.google.inject.Inject | ||
4 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.ComponentDefinition | ||
5 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.TransformationDefinition | ||
6 | import org.eclipse.emf.ecore.EObject | ||
7 | import org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider | ||
8 | |||
9 | class CftLanguageQualifiedNameProvider extends DefaultDeclarativeQualifiedNameProvider { | ||
10 | @Inject PackageNameProvider packageNameProvider | ||
11 | |||
12 | def qualifiedName(ComponentDefinition componentDefinition) { | ||
13 | computePackageQualifiedName(componentDefinition, componentDefinition.name) | ||
14 | } | ||
15 | |||
16 | def qualifiedName(TransformationDefinition transformationDefinition) { | ||
17 | computePackageQualifiedName(transformationDefinition, transformationDefinition.name) | ||
18 | } | ||
19 | |||
20 | private def computePackageQualifiedName(EObject eObj, String name) { | ||
21 | if (name === null) { | ||
22 | return null | ||
23 | } | ||
24 | val packageQualifier = packageNameProvider.getPackageName(eObj) | ||
25 | packageQualifier.append(name) | ||
26 | } | ||
27 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/naming/PackageNameProvider.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/naming/PackageNameProvider.xtend new file mode 100644 index 00000000..a05c8138 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/naming/PackageNameProvider.xtend | |||
@@ -0,0 +1,30 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.components.naming | ||
2 | |||
3 | import com.google.inject.Inject | ||
4 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.CftModel | ||
5 | import org.eclipse.emf.ecore.EObject | ||
6 | import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor | ||
7 | import org.eclipse.xtext.EcoreUtil2 | ||
8 | import org.eclipse.xtext.naming.IQualifiedNameConverter | ||
9 | import org.eclipse.xtext.naming.QualifiedName | ||
10 | |||
11 | class PackageNameProvider { | ||
12 | val IQualifiedNameConverter qualifiedNameConverter | ||
13 | |||
14 | @FinalFieldsConstructor | ||
15 | @Inject | ||
16 | new() { | ||
17 | } | ||
18 | |||
19 | def getPackageName(EObject eObj) { | ||
20 | if (eObj === null) { | ||
21 | return QualifiedName.EMPTY | ||
22 | } | ||
23 | val pacakgeName = EcoreUtil2.getContainerOfType(eObj, CftModel)?.packageName | ||
24 | if (pacakgeName.isNullOrEmpty) { | ||
25 | QualifiedName.EMPTY | ||
26 | } else { | ||
27 | qualifiedNameConverter.toQualifiedName(pacakgeName) | ||
28 | } | ||
29 | } | ||
30 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/scoping/CftLanguageImportedNamespaceAwareLocalScopeProvider.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/scoping/CftLanguageImportedNamespaceAwareLocalScopeProvider.xtend new file mode 100644 index 00000000..39a6e5a5 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/scoping/CftLanguageImportedNamespaceAwareLocalScopeProvider.xtend | |||
@@ -0,0 +1,45 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.components.scoping | ||
2 | |||
3 | import com.google.inject.Inject | ||
4 | import com.google.inject.Singleton | ||
5 | import hu.bme.mit.inf.dslreasoner.faulttree.components.naming.PackageNameProvider | ||
6 | import org.eclipse.emf.ecore.EObject | ||
7 | import org.eclipse.emf.ecore.EReference | ||
8 | import org.eclipse.xtext.naming.IQualifiedNameConverter | ||
9 | import org.eclipse.xtext.naming.IQualifiedNameProvider | ||
10 | import org.eclipse.xtext.scoping.ICaseInsensitivityHelper | ||
11 | import org.eclipse.xtext.scoping.IGlobalScopeProvider | ||
12 | import org.eclipse.xtext.scoping.IScope | ||
13 | import org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider | ||
14 | |||
15 | @Singleton | ||
16 | class CftLanguageImportedNamespaceAwareLocalScopeProvider extends ImportedNamespaceAwareLocalScopeProvider { | ||
17 | @Inject PackageNameProvider packageNameProvider | ||
18 | |||
19 | @Inject | ||
20 | new() { | ||
21 | } | ||
22 | |||
23 | new(IGlobalScopeProvider globalScopeProvider, IQualifiedNameProvider qualifiedNameProvider, | ||
24 | IQualifiedNameConverter qualifiedNameConverter, ICaseInsensitivityHelper caseInsensitivityHelper) { | ||
25 | super(globalScopeProvider, qualifiedNameProvider, qualifiedNameConverter, caseInsensitivityHelper) | ||
26 | packageNameProvider = new PackageNameProvider(qualifiedNameConverter) | ||
27 | } | ||
28 | |||
29 | override protected internalGetImportedNamespaceResolvers(EObject context, boolean ignoreCase) { | ||
30 | val resolvers = super.internalGetImportedNamespaceResolvers(context, ignoreCase) | ||
31 | val packageName = packageNameProvider.getPackageName(context) | ||
32 | if (!packageName.empty) { | ||
33 | val packageNormalizer = doCreateImportNormalizer(packageName, true, ignoreCase) | ||
34 | resolvers.add(0, packageNormalizer) | ||
35 | } | ||
36 | resolvers | ||
37 | } | ||
38 | |||
39 | def createImportNormalizedScope(IScope elements, EObject context, EReference reference) { | ||
40 | val ignoreCase = isIgnoreCase(reference) | ||
41 | val type = reference.EReferenceType | ||
42 | val namespaceResolvers = getImportedNamespaceResolvers(context, ignoreCase) | ||
43 | createImportScope(elements, namespaceResolvers, null, type, ignoreCase) | ||
44 | } | ||
45 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/scoping/CftLanguageScopeProvider.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/scoping/CftLanguageScopeProvider.xtend new file mode 100644 index 00000000..ab708087 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/scoping/CftLanguageScopeProvider.xtend | |||
@@ -0,0 +1,138 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.16.0 | ||
3 | */ | ||
4 | package hu.bme.mit.inf.dslreasoner.faulttree.components.scoping | ||
5 | |||
6 | import com.google.common.collect.Lists | ||
7 | import com.google.inject.Inject | ||
8 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.ComponentDefinition | ||
9 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.ComponentInstance | ||
10 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.EventReference | ||
11 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.LookupDefinition | ||
12 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.MappingDefinition | ||
13 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.TransformationDefinition | ||
14 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.Variable | ||
15 | import org.eclipse.emf.common.notify.Notifier | ||
16 | import org.eclipse.emf.ecore.EObject | ||
17 | import org.eclipse.emf.ecore.EReference | ||
18 | import org.eclipse.xtext.EcoreUtil2 | ||
19 | import org.eclipse.xtext.resource.EObjectDescription | ||
20 | import org.eclipse.xtext.resource.IResourceDescriptions | ||
21 | import org.eclipse.xtext.resource.IResourceDescriptionsProvider | ||
22 | import org.eclipse.xtext.scoping.IScope | ||
23 | import org.eclipse.xtext.scoping.Scopes | ||
24 | import org.eclipse.xtext.scoping.impl.SimpleScope | ||
25 | |||
26 | import static hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.CftLanguagePackage.Literals.* | ||
27 | |||
28 | /** | ||
29 | * This class contains custom scoping description. | ||
30 | * | ||
31 | * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#scoping | ||
32 | * on how and when to use it. | ||
33 | */ | ||
34 | class CftLanguageScopeProvider extends AbstractCftLanguageScopeProvider { | ||
35 | public static val SINGLETON_VARIABLE_PREFIX = "_" | ||
36 | |||
37 | @Inject IResourceDescriptionsProvider resourceDescriptionsProvider | ||
38 | @Inject CftLanguageImportedNamespaceAwareLocalScopeProvider importedNamespaceProvider | ||
39 | |||
40 | override getScope(EObject context, EReference reference) { | ||
41 | switch (reference) { | ||
42 | case LOOKUP_DEFINITION__MAPPING: | ||
43 | getRuleDefinitionsScope(context, reference) | ||
44 | case LOOKUP_DEFINITION__ARGUMENTS: | ||
45 | getMappingParametersScope(context) | ||
46 | case EVENT_REFERENCE__COMPONENT: | ||
47 | getComponentInstancesScope(context) | ||
48 | case EVENT_REFERENCE__EVENT: | ||
49 | getEventDeclarationsScope(context) | ||
50 | default: | ||
51 | super.getScope(context, reference) | ||
52 | } | ||
53 | } | ||
54 | |||
55 | protected def getRuleDefinitionsScope(EObject context, EReference referece) { | ||
56 | val transformationDefinition = EcoreUtil2.getContainerOfType(context, TransformationDefinition) | ||
57 | if (transformationDefinition === null) { | ||
58 | return IScope.NULLSCOPE | ||
59 | } | ||
60 | val resourceDescriptions = getResourceDescriptions(transformationDefinition) | ||
61 | val mappingDefinitionDescriptions = toMappingDefinitionDescriptions(resourceDescriptions, | ||
62 | transformationDefinition.mappingDefinitions) | ||
63 | val ruleDefinitionsScope = new SimpleScope(IScope.NULLSCOPE, mappingDefinitionDescriptions) | ||
64 | importedNamespaceProvider.createImportNormalizedScope(ruleDefinitionsScope, context, referece) | ||
65 | } | ||
66 | |||
67 | protected def toMappingDefinitionDescriptions(IResourceDescriptions resourceDescriptions, | ||
68 | Iterable<? extends MappingDefinition> ruleDefinitions) { | ||
69 | val mappingDefinitionDescriptions = Lists.newArrayListWithExpectedSize(ruleDefinitions.size) | ||
70 | for (ruleDefinition : ruleDefinitions) { | ||
71 | val pattern = ruleDefinition?.pattern | ||
72 | if (pattern !== null) { | ||
73 | val patternName = resourceDescriptions.getExportedObjectsByObject(pattern).head?.qualifiedName | ||
74 | if (patternName !== null) { | ||
75 | mappingDefinitionDescriptions += EObjectDescription.create(patternName, ruleDefinition) | ||
76 | } | ||
77 | } | ||
78 | |||
79 | } | ||
80 | mappingDefinitionDescriptions | ||
81 | } | ||
82 | |||
83 | private def getResourceDescriptions(Notifier notifier) { | ||
84 | val resourceSet = EcoreUtil2.getResourceSet(notifier) | ||
85 | if (resourceSet === null) { | ||
86 | new IResourceDescriptions.NullImpl | ||
87 | } else { | ||
88 | resourceDescriptionsProvider.getResourceDescriptions(resourceSet) | ||
89 | } | ||
90 | } | ||
91 | |||
92 | protected def getMappingParametersScope(EObject context) { | ||
93 | val mappingDefinition = EcoreUtil2.getContainerOfType(context, MappingDefinition) | ||
94 | if (mappingDefinition === null) { | ||
95 | return IScope.NULLSCOPE | ||
96 | } | ||
97 | val variables = mappingDefinition.parameters.filter [ | ||
98 | !name.startsWith(SINGLETON_VARIABLE_PREFIX) | ||
99 | ] | ||
100 | Scopes.scopeFor(variables) | ||
101 | } | ||
102 | |||
103 | protected def getComponentInstancesScope(EObject context) { | ||
104 | val mappingDefinition = EcoreUtil2.getContainerOfType(context, MappingDefinition) | ||
105 | if (mappingDefinition === null) { | ||
106 | return IScope.NULLSCOPE | ||
107 | } | ||
108 | val componentInstances = <Variable>newArrayList | ||
109 | componentInstances.addAll(mappingDefinition.lookupDefinitions) | ||
110 | if (mappingDefinition.componentInstance !== null) { | ||
111 | componentInstances += mappingDefinition.componentInstance | ||
112 | } | ||
113 | Scopes.scopeFor(componentInstances) | ||
114 | } | ||
115 | |||
116 | protected def getEventDeclarationsScope(EObject context) { | ||
117 | val variable = EcoreUtil2.getContainerOfType(context, EventReference)?.component | ||
118 | val events = switch (variable) { | ||
119 | ComponentInstance: | ||
120 | variable.componentType?.allEventDeclarations | ||
121 | LookupDefinition: | ||
122 | variable.mapping?.componentInstance?.componentType?.allEventDeclarations | ||
123 | default: | ||
124 | null | ||
125 | } | ||
126 | if (events === null) { | ||
127 | return IScope.NULLSCOPE | ||
128 | } | ||
129 | Scopes.scopeFor(events) | ||
130 | } | ||
131 | |||
132 | private def getAllEventDeclarations(ComponentDefinition componentDefinition) { | ||
133 | val eventDeclarations = newArrayList | ||
134 | eventDeclarations.addAll(componentDefinition.inputEvents) | ||
135 | eventDeclarations.addAll(componentDefinition.eventDefinitions) | ||
136 | eventDeclarations | ||
137 | } | ||
138 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/validation/CftLanguageValidator.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/validation/CftLanguageValidator.xtend new file mode 100644 index 00000000..f1da10bb --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/validation/CftLanguageValidator.xtend | |||
@@ -0,0 +1,25 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.16.0 | ||
3 | */ | ||
4 | package hu.bme.mit.inf.dslreasoner.faulttree.components.validation | ||
5 | |||
6 | |||
7 | /** | ||
8 | * This class contains custom validation rules. | ||
9 | * | ||
10 | * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation | ||
11 | */ | ||
12 | class CftLanguageValidator extends AbstractCftLanguageValidator { | ||
13 | |||
14 | // public static val INVALID_NAME = 'invalidName' | ||
15 | // | ||
16 | // @Check | ||
17 | // def checkGreetingStartsWithCapital(Greeting greeting) { | ||
18 | // if (!Character.isUpperCase(greeting.name.charAt(0))) { | ||
19 | // warning('Name should start with a capital', | ||
20 | // CftLanguagePackage.Literals.GREETING__NAME, | ||
21 | // INVALID_NAME) | ||
22 | // } | ||
23 | // } | ||
24 | |||
25 | } | ||