summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRohit Agrawal2012-08-15 14:25:06 (EDT)
committerRohit Agrawal2012-08-15 14:25:06 (EDT)
commitccec3ae50f026dc23d755e340305361c918b114b (patch)
tree0b146015dd06c0c91b541bd9e778a5c813ca045f
parent1f7198e462bb7bff7a1221ce4d6deab7288a0e93 (diff)
downloadorg.eclipse.etrice-ccec3ae50f026dc23d755e340305361c918b114b.zip
org.eclipse.etrice-ccec3ae50f026dc23d755e340305361c918b114b.tar.gz
org.eclipse.etrice-ccec3ae50f026dc23d755e340305361c918b114b.tar.bz2
[CQ6589] : More changes using HandledMessage class , slight issues withrefs/changes/40/7240/1
warning markers 1. I authored 100% of the content I contributed 2. I have the rights to donate the content to Eclipse 3. I contribute the content under the EPL Change-Id: Ib305250b7aa0db8fd3f81e971912a7a11300fc10
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/AbstractExecutionValidator.java124
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ActiveRules.java60
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ProposalGenerator.java72
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/SemanticsCheck.java37
4 files changed, 198 insertions, 95 deletions
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/AbstractExecutionValidator.java b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/AbstractExecutionValidator.java
index d9bfaa3..b35551a 100644
--- a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/AbstractExecutionValidator.java
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/AbstractExecutionValidator.java
@@ -20,19 +20,22 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.genmodel.base.NullDiagnostician;
import org.eclipse.etrice.core.genmodel.base.NullLogger;
import org.eclipse.etrice.core.genmodel.builder.GeneratorModelBuilder;
+import org.eclipse.etrice.core.genmodel.etricegen.ActiveTrigger;
import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass;
import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.DetailCode;
import org.eclipse.etrice.core.room.GeneralProtocolClass;
import org.eclipse.etrice.core.room.InterfaceItem;
import org.eclipse.etrice.core.room.ProtocolClass;
import org.eclipse.etrice.core.room.State;
+import org.eclipse.etrice.core.room.StateGraphItem;
import org.eclipse.etrice.core.room.util.RoomHelpers;
import org.eclipse.etrice.core.validation.IRoomValidator;
import org.eclipse.xtext.validation.ValidationMessageAcceptor;
/**
* @author rentzhnr
- *
+ *
*/
public class AbstractExecutionValidator implements IRoomValidator {
@@ -40,31 +43,40 @@ public class AbstractExecutionValidator implements IRoomValidator {
private static String traceName = "";
static {
if (Activator.getDefault().isDebugging()) {
- String value = Platform.getDebugOption("org.eclipse.etrice.abstractexec.behavior/trace/abstractexec");
+ String value = Platform
+ .getDebugOption("org.eclipse.etrice.abstractexec.behavior/trace/abstractexec");
if (value != null && value.equalsIgnoreCase(Boolean.toString(true))) {
traceExec = true;
}
- traceName = Platform.getDebugOption("org.eclipse.etrice.abstractexec.behavior/trace/abstractexec/name");
+ traceName = Platform
+ .getDebugOption("org.eclipse.etrice.abstractexec.behavior/trace/abstractexec/name");
}
}
- /* (non-Javadoc)
- * @see org.eclipse.etrice.core.validation.IRoomValidator#validate(org.eclipse.emf.ecore.EObject, org.eclipse.xtext.validation.ValidationMessageAcceptor)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.etrice.core.validation.IRoomValidator#validate(org.eclipse
+ * .emf.ecore.EObject,
+ * org.eclipse.xtext.validation.ValidationMessageAcceptor)
*/
@Override
- public void validate(EObject object, ValidationMessageAcceptor messageAcceptor) {
+ public void validate(EObject object,
+ ValidationMessageAcceptor messageAcceptor) {
if (!(object instanceof ActorClass))
return;
ActorClass ac = (ActorClass) object;
-
+
if (traceExec && !ac.getName().equals(traceName))
return;
-
+
if (traceExec)
- System.out.println("AbstractExecutionValidator checking class " + ac.getName());
-
+ System.out.println("AbstractExecutionValidator checking class "
+ + ac.getName());
+
boolean oneProtocolsWithSemantics = false;
List<InterfaceItem> ifItems = RoomHelpers.getAllInterfaceItems(ac);
for (InterfaceItem item : ifItems) {
@@ -73,44 +85,96 @@ public class AbstractExecutionValidator implements IRoomValidator {
continue;
if (traceExec)
- System.out.println(" Checking protocolClass " + pc.getName() + " for semantics");
-
+ System.out.println(" Checking protocolClass " + pc.getName()
+ + " for semantics");
+
if (((ProtocolClass) pc).getSemantics() != null) {
oneProtocolsWithSemantics = true;
if (traceExec)
- System.out.println(" Will execute because semantics defined for "+ pc.getName());
+ System.out
+ .println(" Will execute because semantics defined for "
+ + pc.getName());
break;
}
}
if (oneProtocolsWithSemantics) {
// begin abstract execution on state machine of expanded actor class
- System.out.println(" Reached where at least one interface items has semantics");
+ System.out
+ .println(" Reached where at least one interface items has semantics");
NullDiagnostician diagnostician = new NullDiagnostician();
- GeneratorModelBuilder builder = new GeneratorModelBuilder(new NullLogger(), diagnostician);
+ GeneratorModelBuilder builder = new GeneratorModelBuilder(
+ new NullLogger(), diagnostician);
ExpandedActorClass xpac = builder.createExpandedActorClass(ac);
-
- if (xpac != null && !diagnostician.isFailed() ) {
- SemanticsCheck checker = new SemanticsCheck(xpac);
+
+ if (xpac != null && !diagnostician.isFailed()) {
+ SemanticsCheck checker = new SemanticsCheck(xpac);
checker.checkSemantics();
-// System.out.println("Final printing of rules : ");
-// checker.printRules();
+ // System.out.println("Final printing of rules : ");
+ // checker.printRules();
if (traceExec)
- System.out.println(" Rule checking for " + xpac.getActorClass().getName() + " is over");
-
- TreeIterator<EObject> it = xpac.getStateMachine().eAllContents();
- while(it.hasNext())
- {
+ System.out.println(" Rule checking for "
+ + xpac.getActorClass().getName() + " is over");
+
+ TreeIterator<EObject> it = xpac.getStateMachine()
+ .eAllContents();
+ while (it.hasNext()) {
EObject obj = it.next();
- if(obj instanceof State)
- {
- ProposalGenerator propGen = new ProposalGenerator(xpac,checker);
+ if (obj instanceof State) {
+ ProposalGenerator propGen = new ProposalGenerator(xpac,
+ checker);
State st = (State) obj;
- propGen.createProposals(st, messageAcceptor);
+ propGen.createProposals(st);
+ // TODO : create markers for the proposals
+ }
+ // the following part takes care of all the warnings
+ if (obj instanceof StateGraphItem) {
+ StateGraphItem item = (StateGraphItem) obj;
+ List<HandledMessage> warningList = checker
+ .getWarningMsg(item);
+ if (traceExec) {
+ System.out
+ .println("Messages in the warning list for item "
+ + item.getName() );
+ if(warningList != null)
+ for (HandledMessage msg : warningList) {
+ System.out.println(msg.getMsg().getName());
+ }
+ }
+ /*
+ * for(HandledMessage msg : warningList) { EObject
+ * origin = msg.getOrigin(); if(origin instanceof
+ * ActiveTrigger) { ActiveTrigger trigger =
+ * (ActiveTrigger) origin; //TODO : issue a warning
+ * marker EObject orig = xpac.getOrig(trigger); EObject
+ * container = orig.eContainer();
+ *
+ * @SuppressWarnings("unchecked") int idx = ((List<?
+ * extends
+ * EObject>)container.eGet(orig.eContainingFeature
+ * ())).indexOf(orig); messageAcceptor.acceptWarning(
+ * "The message violates the semantic rule", container,
+ * orig.eContainingFeature(), idx, "VIOLATION",
+ * trigger.getMsg().getName()); } else if (origin
+ * instanceof DetailCode) { DetailCode dc = (DetailCode)
+ * origin; EObject orig = xpac.getOrig(dc); EObject
+ * container = orig.eContainer();
+ *
+ * @SuppressWarnings("unchecked") int idx = ((List<?
+ * extends
+ * EObject>)container.eGet(orig.eContainingFeature
+ * ())).indexOf(orig); messageAcceptor.acceptWarning(
+ * "The message violates the semantic rule", container,
+ * orig.eContainingFeature(), idx, "VIOLATION" );
+ *
+ * } }
+ */
}
}
if (traceExec)
- System.out.println("AbstractExecutionValidator done checking class " + ac.getName());
+ System.out
+ .println("AbstractExecutionValidator done checking class "
+ + ac.getName());
}
}
}
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ActiveRules.java b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ActiveRules.java
index f9f0af0..726fb61 100644
--- a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ActiveRules.java
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ActiveRules.java
@@ -32,18 +32,20 @@ public class ActiveRules {
private static int traceLevel = 0;
static {
if (Activator.getDefault().isDebugging()) {
- String value = Platform.getDebugOption("org.eclipse.etrice.abstractexec.behavior/trace/rules");
+ String value = Platform
+ .getDebugOption("org.eclipse.etrice.abstractexec.behavior/trace/rules");
if (value != null && value.equalsIgnoreCase(Boolean.toString(true))) {
traceRules = true;
}
- value = Platform.getDebugOption("org.eclipse.etrice.abstractexec.behavior/trace/rules/level");
+ value = Platform
+ .getDebugOption("org.eclipse.etrice.abstractexec.behavior/trace/rules/level");
if (value != null) {
traceLevel = Integer.parseInt(value);
}
}
}
- //private static final int TRACE_RESULT = 1;
+ // private static final int TRACE_RESULT = 1;
private static final int TRACE_DETAILS = 2;
public ActiveRules() {
@@ -64,10 +66,11 @@ public class ActiveRules {
// checks for currently active rules against a message list and modifies the
// rules which can be merged with the destination node
- public void consumeMessages(List<HandledMessage> msgList) {
+ public List<HandledMessage> consumeMessages(List<HandledMessage> msgList) {
+ List<HandledMessage> wrongMsgList = new ArrayList<HandledMessage>();
for (HandledMessage msg : msgList) {
List<SemanticsRule> localRules = rules.get(msg.getIfitem());
- if (localRules!=null) {
+ if (localRules != null) {
SemanticsRule match = null;
for (SemanticsRule rule : localRules) {
if (rule.getMsg() == msg.getMsg()) {
@@ -75,28 +78,31 @@ public class ActiveRules {
break;
}
}
-
- if (match!=null) {
- if (traceRules && traceLevel>=TRACE_DETAILS)
- System.out.println(" found match for "+msg.getMsg().getName());
+
+ if (match != null) {
+ if (traceRules && traceLevel >= TRACE_DETAILS)
+ System.out.println(" found match for "
+ + msg.getMsg().getName());
// discard all alternatives
localRules.clear();
-
+
// and add all follow ups
localRules.addAll(match.getFollowUps());
- }
- else {
+ } else {
// TODO: issue a warning?
+ wrongMsgList.add(msg);
}
}
}
+ return wrongMsgList;
}
// merges the rules with the destination active rules
public boolean merge(ActiveRules ar) {
boolean added_at_least_one = false;
- for (Entry<InterfaceItem, List<SemanticsRule>> entry : ar.rules.entrySet()) {
+ for (Entry<InterfaceItem, List<SemanticsRule>> entry : ar.rules
+ .entrySet()) {
for (SemanticsRule rule : entry.getValue()) {
InterfaceItem ifitem = entry.getKey();
if (rules.containsKey(ifitem)) {
@@ -104,8 +110,7 @@ public class ActiveRules {
rules.get(ifitem).add(rule);
added_at_least_one = true;
}
- }
- else {
+ } else {
List<SemanticsRule> tempList = new ArrayList<SemanticsRule>();
tempList.add(rule);
rules.put(ifitem, tempList);
@@ -113,8 +118,8 @@ public class ActiveRules {
}
}
}
-
- if (traceRules && traceLevel>=TRACE_DETAILS)
+
+ if (traceRules && traceLevel >= TRACE_DETAILS)
System.out.println(" merge changed rules");
return added_at_least_one;
@@ -123,7 +128,8 @@ public class ActiveRules {
public ActiveRules createCopy() {
HashMap<InterfaceItem, List<SemanticsRule>> newRules = new HashMap<InterfaceItem, List<SemanticsRule>>();
for (InterfaceItem ifitem : rules.keySet()) {
- newRules.put(ifitem, new ArrayList<SemanticsRule>(rules.get(ifitem)));
+ newRules.put(ifitem,
+ new ArrayList<SemanticsRule>(rules.get(ifitem)));
}
return new ActiveRules(newRules);
}
@@ -131,11 +137,14 @@ public class ActiveRules {
public void buildInitLocalRules(ExpandedActorClass xpAct) {
// HashMap<InterfaceItem, EList<SemanticsRule>> locals = new
// HashMap<InterfaceItem, EList<SemanticsRule>>();
- List<InterfaceItem> portList = RoomHelpers.getAllInterfaceItems(xpAct.getActorClass());
+ List<InterfaceItem> portList = RoomHelpers.getAllInterfaceItems(xpAct
+ .getActorClass());
for (InterfaceItem ifitem : portList) {
GeneralProtocolClass gpc = ifitem.getGeneralProtocol();
- if (gpc instanceof ProtocolClass && ((ProtocolClass) gpc).getSemantics()!=null)
- rules.put(ifitem, ((ProtocolClass) gpc).getSemantics().getRules());
+ if (gpc instanceof ProtocolClass
+ && ((ProtocolClass) gpc).getSemantics() != null)
+ rules.put(ifitem, ((ProtocolClass) gpc).getSemantics()
+ .getRules());
}
}
@@ -148,16 +157,15 @@ public class ActiveRules {
}
}
}
-
+
public void printRule(SemanticsRule rule, String indent) {
if (rule instanceof InSemanticsRule)
- System.out.println(indent+"in: "+rule.getMsg().getName());
+ System.out.println(indent + "in: " + rule.getMsg().getName());
else
- System.out.println(indent+"out: "+rule.getMsg().getName());
-
+ System.out.println(indent + "out: " + rule.getMsg().getName());
// recursion
for (SemanticsRule sr : rule.getFollowUps()) {
- printRule(sr, indent+" ");
+ printRule(sr, indent + " ");
}
}
}
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ProposalGenerator.java b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ProposalGenerator.java
index ba51819..1d577be 100644
--- a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ProposalGenerator.java
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ProposalGenerator.java
@@ -25,7 +25,6 @@ import org.eclipse.etrice.core.room.RoomFactory;
import org.eclipse.etrice.core.room.SemanticsRule;
import org.eclipse.etrice.core.room.State;
import org.eclipse.etrice.core.room.util.RoomHelpers;
-import org.eclipse.xtext.validation.ValidationMessageAcceptor;
public class ProposalGenerator {
private ExpandedActorClass xpac;
@@ -36,7 +35,8 @@ public class ProposalGenerator {
private static boolean traceProposals = false;
static {
if (Activator.getDefault().isDebugging()) {
- String value = Platform.getDebugOption("org.eclipse.etrice.abstractexec.behavior/trace/proposals");
+ String value = Platform
+ .getDebugOption("org.eclipse.etrice.abstractexec.behavior/trace/proposals");
if (value != null && value.equalsIgnoreCase(Boolean.toString(true))) {
traceProposals = true;
}
@@ -60,70 +60,74 @@ public class ProposalGenerator {
return warningTrigger;
}
- public void createProposals(State st, ValidationMessageAcceptor messageAcceptor) {
+ public void createProposals(State st) {
ActiveRules rules = checker.getActiveRules(st);
-
+
// in case the state is disconnected component of the graph
if (rules == null)
return;
-
+
outgoingProposal.clear();
incomingProposal.clear();
-
- xpac.getActiveTriggers(st);
+
Set<SemanticsRule> rulesToIgnore = new HashSet<SemanticsRule>();
- for (ActiveTrigger trigger : xpac.getActiveTriggers(st)) {
- SemanticsRule match = null;
- Port port = (Port) trigger.getIfitem();
- if (rules.getPortList().contains(port)) {
- List<SemanticsRule> ruleList = rules.getRulesForPort(port);
- for (SemanticsRule curRule : ruleList) {
- if (curRule.getMsg() == trigger.getMsg()) {
- match = curRule;
- break;
+ if (xpac.getActiveTriggers(st) != null)
+ for (ActiveTrigger trigger : xpac.getActiveTriggers(st)) {
+ SemanticsRule match = null;
+ Port port = (Port) trigger.getIfitem();
+ if (rules.getPortList().contains(port)) {
+ List<SemanticsRule> ruleList = rules.getRulesForPort(port);
+ for (SemanticsRule curRule : ruleList) {
+ if (curRule.getMsg() == trigger.getMsg()) {
+ match = curRule;
+ break;
+ }
}
}
+ if (match != null) {
+ // mark this rule for ignoring while generating proposals
+ // as they have already been taken care of
+ rulesToIgnore.add(match);
+ } else {
+ // according to the rules this trigger isn't necessary
+ warningTrigger.add(trigger);
+ }
}
- if (match!=null) {
- // mark this rule for ignoring while generating proposals
- // as they have already been taken care of
- rulesToIgnore.add(match);
- }
- else {
- // according to the rules this trigger isn't necessary
- warningTrigger.add(trigger);
- }
- }
-
+
// now start generating proposals by listing all the rules and ignoring
// the ones
// marked above
for (InterfaceItem item : rules.getPortList()) {
for (SemanticsRule ruleToCheck : rules.getRulesForPort(item)) {
if (!rulesToIgnore.contains(ruleToCheck)) {
- MessageFromIf mif = RoomFactory.eINSTANCE.createMessageFromIf();
+ MessageFromIf mif = RoomFactory.eINSTANCE
+ .createMessageFromIf();
mif.setFrom(item);
mif.setMessage(ruleToCheck.getMsg());
- boolean isOutgoing = RoomHelpers.getMessageList(item, true).contains(ruleToCheck.getMsg());
+ boolean isOutgoing = RoomHelpers.getMessageList(item, true)
+ .contains(ruleToCheck.getMsg());
if (isOutgoing) {
outgoingProposal.add(mif);
- }
- else {
+ } else {
incomingProposal.add(mif);
}
}
}
}
-
+
if (traceProposals) {
System.out.println(" Proposals for : " + st.getName());
for (MessageFromIf msg : outgoingProposal) {
- System.out.println(" Outgoing msg proposal : " + msg.getFrom().getName()+"."+msg.getMessage().getName()+"()");
+ System.out.println(" Outgoing msg proposal : "
+ + msg.getFrom().getName() + "."
+ + msg.getMessage().getName() + "()");
}
for (MessageFromIf msg : incomingProposal) {
- System.out.println(" Incoming msg proposal : " + msg.getMessage().getName() + " from " + msg.getFrom().getName());
+ System.out.println(" Incoming msg proposal : "
+ + msg.getMessage().getName() + " from "
+ + msg.getFrom().getName());
}
}
}
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/SemanticsCheck.java b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/SemanticsCheck.java
index b57d32c..efa6d40 100644
--- a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/SemanticsCheck.java
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/SemanticsCheck.java
@@ -36,7 +36,7 @@ public class SemanticsCheck {
private ExpandedActorClass xpAct;
private HashMap<StateGraphItem, ActiveRules> mapToRules = new HashMap<StateGraphItem, ActiveRules>();
private ActionCodeAnalyzer codeAnalyzer;
-
+ private HashMap<StateGraphItem, List<HandledMessage>> mapToWarnings = new HashMap<StateGraphItem, List<HandledMessage>>();
private static boolean traceChecks = false;
private static int traceLevel = 0;
static {
@@ -89,7 +89,15 @@ public class SemanticsCheck {
if (cur instanceof State) {
msgList.addAll(codeAnalyzer.analyze(((State) cur).getEntryCode()));
}
- localRules.consumeMessages(msgList);
+ List<HandledMessage> wrongMsgList = localRules.consumeMessages(msgList);
+ if(mapToWarnings.containsKey(trans))
+ {
+ mapToWarnings.get(trans).addAll(wrongMsgList);
+ }
+ else
+ {
+ mapToWarnings.put(trans, wrongMsgList);
+ }
boolean rulesChanged = false;
if (mapToRules.containsKey(cur)) {
rulesChanged = mapToRules.get(cur).merge(localRules);
@@ -155,7 +163,15 @@ public class SemanticsCheck {
System.out.println(" rules before consuming message list : ");
printRules();
}
- tempRule.consumeMessages(msgList);
+ List<HandledMessage> wrongMsgList = tempRule.consumeMessages(msgList);
+ if(mapToWarnings.containsKey(node))
+ {
+ mapToWarnings.get(node).addAll(wrongMsgList);
+ }
+ else
+ {
+ mapToWarnings.put(node, wrongMsgList);
+ }
if (traceChecks && traceLevel>=TRACE_DETAILS)
System.out.println(" Messages consumed");
@@ -188,7 +204,15 @@ public class SemanticsCheck {
if (target instanceof State) {
msgList.addAll(codeAnalyzer.analyze(((State) target).getEntryCode()));
}
- tempRule.consumeMessages(msgList);
+ List<HandledMessage> wrongMsgList = tempRule.consumeMessages(msgList);
+ if(mapToWarnings.containsKey(node))
+ {
+ mapToWarnings.get(node).addAll(wrongMsgList);
+ }
+ else
+ {
+ mapToWarnings.put(node, wrongMsgList);
+ }
addAndMergeRules(target, tempRule);
}
}
@@ -220,5 +244,8 @@ public class SemanticsCheck {
public ActiveRules getActiveRules(StateGraphItem item) {
return mapToRules.get(item);
}
-
+ public List<HandledMessage> getWarningMsg (StateGraphItem item)
+ {
+ return mapToWarnings.get(item);
+ }
}