diff options
author | Patrick Sattler <sattler@itestra.de> | 2013-09-03 09:34:12 +0200 |
---|---|---|
committer | Patrick Sattler <sattler@itestra.de> | 2013-09-03 09:34:12 +0200 |
commit | 5766a7870807c369d5dbf866aafbd0399ab5e007 (patch) | |
tree | bedc774f609a60a64c1ae6c650f9eea2dcd65c2e | |
parent | a6ee5f8c504127e7740c5a31e845ba06a11e7167 (diff) | |
download | genivi-common-api-runtime-5766a7870807c369d5dbf866aafbd0399ab5e007.tar.gz |
Encoding
-rw-r--r-- | .gitattributes | 1 | ||||
-rw-r--r-- | org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeCycleDetector.xtend | 162 |
2 files changed, 82 insertions, 81 deletions
diff --git a/.gitattributes b/.gitattributes index 9c624e1..4204714 100644 --- a/.gitattributes +++ b/.gitattributes @@ -39,3 +39,4 @@ org.eclipse.core.resources.prefs text # Denote all files that are truly binary and should not be modified. *.png binary *.jpg binary +*.jar binary diff --git a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeCycleDetector.xtend b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeCycleDetector.xtend index c7b5d29..ec0bfcc 100644 --- a/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeCycleDetector.xtend +++ b/org.genivi.commonapi.core/src/org/genivi/commonapi/core/generator/FTypeCycleDetector.xtend @@ -1,48 +1,48 @@ -package org.genivi.commonapi.core.generator
-
-import java.util.HashMap
-import java.util.List
-import java.util.Stack
-import org.franca.core.franca.FType
-import javax.inject.Inject
-
-class FTypeCycleDetector {
- @Inject
- private extension FrancaGeneratorExtensions francaGeneratorExtensions
-
- private val indices = new HashMap<FType, Integer>
- private val lowlink = new HashMap<FType, Integer>
- private val stack = new Stack<FType>
- private var int index
- public var String outErrorString
-
- new(FrancaGeneratorExtensions francaGeneratorExtensions) {
- this.francaGeneratorExtensions = francaGeneratorExtensions
- }
-
- new() {
- }
-
- def dispatch hasCycle(FType type) {
- indices.clear()
- lowlink.clear()
- stack.clear()
- index = 0
- outErrorString = type.name + "->";
- return tarjan(type)
- }
-
- def dispatch hasCycle(List<FType> types) {
- indices.clear()
- lowlink.clear()
- stack.clear()
- index = 0
-
- val typeWithCycle = types.findFirst[type|!indices.containsKey(type) && tarjan(type)]
-
- return typeWithCycle != null
- }
-
+package org.genivi.commonapi.core.generator + +import java.util.HashMap +import java.util.List +import java.util.Stack +import org.franca.core.franca.FType +import javax.inject.Inject + +class FTypeCycleDetector { + @Inject + private extension FrancaGeneratorExtensions francaGeneratorExtensions + + private val indices = new HashMap<FType, Integer> + private val lowlink = new HashMap<FType, Integer> + private val stack = new Stack<FType> + private var int index + public var String outErrorString + + new(FrancaGeneratorExtensions francaGeneratorExtensions) { + this.francaGeneratorExtensions = francaGeneratorExtensions + } + + new() { + } + + def dispatch hasCycle(FType type) { + indices.clear() + lowlink.clear() + stack.clear() + index = 0 + outErrorString = type.name + "->"; + return tarjan(type) + } + + def dispatch hasCycle(List<FType> types) { + indices.clear() + lowlink.clear() + stack.clear() + index = 0 + + val typeWithCycle = types.findFirst[type|!indices.containsKey(type) && tarjan(type)] + + return typeWithCycle != null + } + // Tarjan's Strongly Connected Components Algorithm // returns true if a cycle was detected /** @@ -51,40 +51,40 @@ class FTypeCycleDetector { * @param type * start searching from type. * @return <code>true</code> if a dependency cycle was detected. - */
- def private boolean tarjan(FType type) {
- indices.put(type, index)
- lowlink.put(type, index)
- index = index + 1
-
- stack.push(type)
-
- val directlyReferencedTypes = type.directlyReferencedTypes
-
- for (referencedType : directlyReferencedTypes) {
- outErrorString = outErrorString + referencedType.name + "->"
- if (!indices.containsKey(referencedType)) {
- if (tarjan(referencedType))
- return true
-
- lowlink.put(
- type,
- Math::min(lowlink.get(type), lowlink.get(referencedType))
- );
- } else if (stack.contains(referencedType))
- lowlink.put(
- type,
- Math::min(lowlink.get(type), indices.get(referencedType))
- );
- }
-
+ */ + def private boolean tarjan(FType type) { + indices.put(type, index) + lowlink.put(type, index) + index = index + 1 + + stack.push(type) + + val directlyReferencedTypes = type.directlyReferencedTypes + + for (referencedType : directlyReferencedTypes) { + outErrorString = outErrorString + referencedType.name + "->" + if (!indices.containsKey(referencedType)) { + if (tarjan(referencedType)) + return true + + lowlink.put( + type, + Math::min(lowlink.get(type), lowlink.get(referencedType)) + ); + } else if (stack.contains(referencedType)) + lowlink.put( + type, + Math::min(lowlink.get(type), indices.get(referencedType)) + ); + } + // if scc root and not on top of stack, then we have a cycle (scc size > 1) - if (lowlink.get(type) == indices.get(type) && !stack.pop().equals(type)) {
- outErrorString = outErrorString.subSequence(0, outErrorString.length - 2) as String
- return true;
- }
-
- return false
- }
-
-}
+ if (lowlink.get(type) == indices.get(type) && !stack.pop().equals(type)) { + outErrorString = outErrorString.subSequence(0, outErrorString.length - 2) as String + return true; + } + + return false + } + +} |