diff options
author | 2019-02-06 18:28:18 +0100 | |
---|---|---|
committer | 2019-02-19 19:18:25 +0100 | |
commit | 615b602f0a9b4ce9eca8c38b9aa780b81d03d8e7 (patch) | |
tree | 1c9fe0f4ae152d84152c8ff1cfb6366ec8b277e9 /Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/conversion | |
parent | [Stochastic] Fault tree transformation langauge (diff) | |
download | VIATRA-Generator-615b602f0a9b4ce9eca8c38b9aa780b81d03d8e7.tar.gz VIATRA-Generator-615b602f0a9b4ce9eca8c38b9aa780b81d03d8e7.tar.zst VIATRA-Generator-615b602f0a9b4ce9eca8c38b9aa780b81d03d8e7.zip |
Extract component fault tree model
Diffstat (limited to 'Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/conversion')
2 files changed, 50 insertions, 0 deletions
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/conversion/CftLanguageValueConverterService.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/conversion/CftLanguageValueConverterService.xtend new file mode 100644 index 00000000..974e0df4 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/conversion/CftLanguageValueConverterService.xtend | |||
@@ -0,0 +1,15 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.components.conversion | ||
2 | |||
3 | import com.google.inject.Inject | ||
4 | import org.eclipse.xtext.common.services.DefaultTerminalConverters | ||
5 | import org.eclipse.xtext.conversion.IValueConverter | ||
6 | import org.eclipse.xtext.conversion.ValueConverter | ||
7 | |||
8 | class CftLanguageValueConverterService extends DefaultTerminalConverters { | ||
9 | @Inject OF_INTValueConverter ofIntValueConverter | ||
10 | |||
11 | @ValueConverter(rule="OF_INT") | ||
12 | def IValueConverter<Integer> OF_INT() { | ||
13 | ofIntValueConverter | ||
14 | } | ||
15 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/conversion/OF_INTValueConverter.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/conversion/OF_INTValueConverter.xtend new file mode 100644 index 00000000..ba3d39e6 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.components/src/hu/bme/mit/inf/dslreasoner/faulttree/components/conversion/OF_INTValueConverter.xtend | |||
@@ -0,0 +1,35 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.components.conversion | ||
2 | |||
3 | import org.eclipse.xtext.conversion.ValueConverterException | ||
4 | import org.eclipse.xtext.conversion.impl.AbstractLexerBasedConverter | ||
5 | import org.eclipse.xtext.nodemodel.INode | ||
6 | |||
7 | class OF_INTValueConverter extends AbstractLexerBasedConverter<Integer> { | ||
8 | static val PREFIX = "of" | ||
9 | |||
10 | override toValue(String string, INode node) throws ValueConverterException { | ||
11 | if (string === null) { | ||
12 | return null | ||
13 | } | ||
14 | if (string.length < PREFIX.length || string.substring(0, PREFIX.length) != PREFIX) { | ||
15 | throw new ValueConverterException("'" + string + "' must start with the characters 'of'.", node, null); | ||
16 | } | ||
17 | try { | ||
18 | val intValue = Integer.parseInt(string.substring(PREFIX.length), 10) | ||
19 | Integer.valueOf(intValue) | ||
20 | } catch (NumberFormatException e) { | ||
21 | throw new ValueConverterException("Couldn't convert '" + string + "' to an int value.", node, e); | ||
22 | } | ||
23 | } | ||
24 | |||
25 | override protected toEscapedString(Integer value) { | ||
26 | PREFIX + value | ||
27 | } | ||
28 | |||
29 | override protected assertValidValue(Integer value) { | ||
30 | super.assertValidValue(value) | ||
31 | if (value < 0) { | ||
32 | throw new ValueConverterException(getRuleName() + " may not be negative.", null, null); | ||
33 | } | ||
34 | } | ||
35 | } | ||