summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Haug2013-11-05 10:50:44 (EST)
committerJuergen Haug2013-11-06 03:45:27 (EST)
commit2b85f2979e30fe259fa83dc98447203fed01763b (patch)
tree75b8569449761a1c64010c6beb832ba603dd322f
parente6aac5d7d801c2a19e707845cc125d2ee5e003d0 (diff)
downloadorg.eclipse.etrice-2b85f2979e30fe259fa83dc98447203fed01763b.zip
org.eclipse.etrice-2b85f2979e30fe259fa83dc98447203fed01763b.tar.gz
org.eclipse.etrice-2b85f2979e30fe259fa83dc98447203fed01763b.tar.bz2
[core] validation: compound protocol circular + fix stackoverflow refs/changes/89/18089/2
-rw-r--r--plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidationUtil.java53
1 files changed, 49 insertions, 4 deletions
diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidationUtil.java b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidationUtil.java
index c2b54f6..0c6918b 100644
--- a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidationUtil.java
+++ b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidationUtil.java
@@ -15,6 +15,7 @@ package org.eclipse.etrice.core.validation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -205,12 +206,56 @@ public class ValidationUtil {
if (isKindOf(ref,ac))
return true;
- for (ActorRef ar : ref.getActorRefs()) {
- if (isKindOf(ar.getType(), ac) || isKindOf(ref, ar.getType()))
- return true;
- else if (isReferencing(ar.getType(), ac))
+ Set<ActorClass> visited = new HashSet<ActorClass>();
+ LinkedList<ActorClass> stack = new LinkedList<ActorClass>();
+ visited.add(ac);
+ stack.push(ref);
+
+ ActorClass next;
+ while(!stack.isEmpty()){
+ next = stack.pop();
+ if(visited.contains(next))
+ continue;
+
+ for (ActorRef ar : next.getActorRefs()) {
+ if (isKindOf(ar.getType(), ac) || isKindOf(next, ar.getType()))
+ return true;
+ stack.push(ar.getType());
+ }
+ visited.add(next);
+ }
+
+ return false;
+ }
+
+ /**
+ * check if compound protocol is circular
+ * @param ref
+ * @param ac
+ * @return <code>true</code> if cpc contains a cycle
+ */
+ public static boolean isCircular(CompoundProtocolClass ref, CompoundProtocolClass cpc) {
+ Set<CompoundProtocolClass> visited = new HashSet<CompoundProtocolClass>();
+ LinkedList<CompoundProtocolClass> stack = new LinkedList<CompoundProtocolClass>();
+ visited.add(cpc);
+ stack.push(ref);
+
+ CompoundProtocolClass next;
+ while(!stack.isEmpty()){
+ next = stack.pop();
+ if(next == cpc)
return true;
+ if(visited.contains(next))
+ continue;
+ for(SubProtocol subProtocol : next.getSubProtocols()){
+ if(subProtocol.getProtocol() instanceof CompoundProtocolClass){
+ CompoundProtocolClass c = (CompoundProtocolClass)subProtocol.getProtocol();
+ stack.push(c);
+ }
+ }
+ visited.add(next);
}
+
return false;
}