Author: maurelio1234
Date: 2008-08-05 02:08:46-0700
New Revision: 15508
Modified:
branches/gsoc2008/work_issue5042_maurelio1234/src/org/argouml/profile/internal/ocl/CrOCL.java
branches/gsoc2008/work_issue5042_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateExpression.java
branches/gsoc2008/work_issue5042_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java
Log:
implementing the rest of the WFRs and improving code
Modified: branches/gsoc2008/work_issue5042_maurelio1234/src/org/argouml/profile/internal/ocl/CrOCL.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_issue5042_maurelio1234/src/org/argouml/profile/internal/ocl/CrOCL.java?view=diff&rev=15508&p1=branches/gsoc2008/work_issue5042_maurelio1234/src/org/argouml/profile/internal/ocl/CrOCL.java&p2=branches/gsoc2008/work_issue5042_maurelio1234/src/org/argouml/profile/internal/ocl/CrOCL.java&r1=15507&r2=15508
==============================================================================
--- branches/gsoc2008/work_issue5042_maurelio1234/src/org/argouml/profile/internal/ocl/CrOCL.java (original)
+++ branches/gsoc2008/work_issue5042_maurelio1234/src/org/argouml/profile/internal/ocl/CrOCL.java 2008-08-05 02:08:46-0700
@@ -24,6 +24,7 @@
package org.argouml.profile.internal.ocl;
+import java.util.Set;
import java.util.Vector;
import org.argouml.cognitive.Decision;
@@ -53,6 +54,11 @@
* the OCL string
*/
private String ocl = null;
+
+ /**
+ * the design materials to be criticized
+ */
+ private Set<Object> designMaterials;
/**
* Creates a new OCL critic
@@ -78,7 +84,8 @@
setPriority(ToDoItem.HIGH_PRIORITY);
Vector<String> triggers = interpreter.getTriggers();
-
+ designMaterials = interpreter.getCriticizedDesignMaterials();
+
for (String string : triggers) {
addTrigger(string);
}
@@ -118,7 +125,14 @@
}
}
- /**
+ /*
+ * @see org.argouml.cognitive.Critic#getCriticizedDesignMaterials()
+ */
+ public Set<Object> getCriticizedDesignMaterials() {
+ return designMaterials;
+ }
+
+ /*
* @see org.argouml.uml.cognitive.critics.CrUML#predicate2(java.lang.Object,
* org.argouml.cognitive.Designer)
*/
Modified: branches/gsoc2008/work_issue5042_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateExpression.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_issue5042_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateExpression.java?view=diff&rev=15508&p1=branches/gsoc2008/work_issue5042_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateExpression.java&p2=branches/gsoc2008/work_issue5042_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateExpression.java&r1=15507&r2=15508
==============================================================================
--- branches/gsoc2008/work_issue5042_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateExpression.java (original)
+++ branches/gsoc2008/work_issue5042_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateExpression.java 2008-08-05 02:08:46-0700
@@ -31,7 +31,6 @@
import java.util.Vector;
import org.apache.log4j.Logger;
-import org.argouml.model.Model;
import org.argouml.profile.internal.ocl.uml14.HashBag;
import org.argouml.profile.internal.ocl.uml14.OclEnumLiteral;
@@ -129,11 +128,12 @@
/**
* Constructor
*
- * @param vt the variable table
- * @param mi model interpreter
+ * @param variableTable the variable table
+ * @param modelInterpreter model interpreter
*/
- public EvaluateExpression(HashMap<String, Object> vt, ModelInterpreter mi) {
- reset(vt, mi);
+ public EvaluateExpression(HashMap<String, Object> variableTable,
+ ModelInterpreter modelInterpreter) {
+ reset(variableTable, modelInterpreter);
}
/**
@@ -169,7 +169,7 @@
/** Interpreter Code * */
- /**
+ /*
* @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAIfExpression(tudresden.ocl.parser.node.AIfExpression)
*/
public void caseAIfExpression(AIfExpression node) {
@@ -213,7 +213,7 @@
outAIfExpression(node);
}
- /**
+ /*
* @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseALogicalExpressionTail(tudresden.ocl.parser.node.ALogicalExpressionTail)
*/
public void caseALogicalExpressionTail(ALogicalExpressionTail node) {
@@ -250,7 +250,7 @@
outALogicalExpressionTail(node);
}
- /**
+ /*
* @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseARelationalExpressionTail(tudresden.ocl.parser.node.ARelationalExpressionTail)
*/
public void caseARelationalExpressionTail(ARelationalExpressionTail node) {
@@ -286,12 +286,20 @@
error(node);
}
} else {
- error(node);
+ // if one side is null we can only compare with the equality operator
+ if (op instanceof AEqualRelationalOperator) {
+ val = (left == right);
+ } else if (op instanceof ANEqualRelationalOperator) {
+ val = (left != right);
+ } else {
+ error(node);
+ val = null;
+ }
}
outARelationalExpressionTail(node);
}
- /**
+ /*
* @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAAdditiveExpressionTail(tudresden.ocl.parser.node.AAdditiveExpressionTail)
*/
public void caseAAdditiveExpressionTail(AAdditiveExpressionTail node) {
@@ -325,7 +333,7 @@
outAAdditiveExpressionTail(node);
}
- /**
+ /*
* @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAMultiplicativeExpressionTail(tudresden.ocl.parser.node.AMultiplicativeExpressionTail)
*/
public void caseAMultiplicativeExpressionTail(
@@ -360,7 +368,7 @@
outAMultiplicativeExpressionTail(node);
}
- /**
+ /*
* @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAUnaryUnaryExpression(tudresden.ocl.parser.node.AUnaryUnaryExpression)
*/
public void caseAUnaryUnaryExpression(AUnaryUnaryExpression node) {
@@ -383,7 +391,7 @@
outAUnaryUnaryExpression(node);
}
- /**
+ /*
* @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAPostfixExpressionTail(tudresden.ocl.parser.node.APostfixExpressionTail)
*/
public void caseAPostfixExpressionTail(APostfixExpressionTail node) {
@@ -400,7 +408,7 @@
outAPostfixExpressionTail(node);
}
- /**
+ /*
* @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAFeaturePrimaryExpression(tudresden.ocl.parser.node.AFeaturePrimaryExpression)
*/
@SuppressWarnings("unchecked")
@@ -440,15 +448,16 @@
outAFeaturePrimaryExpression(node);
}
- /**
+ /*
* @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outAEmptyFeatureCallParameters(tudresden.ocl.parser.node.AEmptyFeatureCallParameters)
*/
- public void outAEmptyFeatureCallParameters(AEmptyFeatureCallParameters node) {
+ public void outAEmptyFeatureCallParameters(AEmptyFeatureCallParameters node)
+ {
val = new Vector<Object>();
defaultOut(node);
}
- /**
+ /*
* @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAFeatureCallParameters(tudresden.ocl.parser.node.AFeatureCallParameters)
*/
@SuppressWarnings("unchecked")
@@ -487,13 +496,17 @@
*/
public Object evaluate(HashMap<String, Object> vti,
Object expi) {
- Object old_val = EvaluateExpression.this.val;
+
+ Object state = EvaluateExpression.this.saveState();
+
+ EvaluateExpression.this.vt = vti;
EvaluateExpression.this.val = null;
+ EvaluateExpression.this.fwd = null;
+
((PExpression) expi).apply(EvaluateExpression.this);
Object reti = EvaluateExpression.this.val;
- EvaluateExpression.this.val = old_val;
-
+ EvaluateExpression.this.loadState(state);
return reti;
}
@@ -510,8 +523,20 @@
}
outAFeatureCallParameters(node);
}
+
+ @SuppressWarnings("unchecked")
+ private void loadState(Object state) {
+ Object[] stateArr = (Object[]) state;
+ this.vt = (HashMap<String, Object>) stateArr[0];
+ this.val = stateArr[1];
+ this.fwd = stateArr[2];
+ }
- /**
+ private Object saveState() {
+ return new Object[] {vt, val, fwd};
+ }
+
+ /*
* @param node
* @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAStandardDeclarator(tudresden.ocl.parser.node.AStandardDeclarator)
*/
@@ -531,8 +556,7 @@
((PDeclaratorTail) temp[i]).apply(this);
vars.add(((ADeclaratorTail) temp[i]).getName()
-
- .toString().trim());
+ .toString().trim());
}
val = vars;
@@ -553,7 +577,7 @@
defaultOut(node);
}
- /**
+ /*
* @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseALetExpression(tudresden.ocl.parser.node.ALetExpression)
*/
public void caseALetExpression(ALetExpression node) {
@@ -590,16 +614,16 @@
outALetExpression(node);
}
- /**
+ /*
* @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outAStringLiteral(tudresden.ocl.parser.node.AStringLiteral)
*/
public void outAStringLiteral(AStringLiteral node) {
String text = node.getStringLit().getText();
- val = text.substring(1,text.length()-1);
+ val = text.substring(1, text.length() - 1);
defaultOut(node);
}
- /**
+ /*
* @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outARealLiteral(tudresden.ocl.parser.node.ARealLiteral)
*/
public void outARealLiteral(ARealLiteral node) {
@@ -608,7 +632,7 @@
defaultOut(node);
}
- /**
+ /*
* @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outAIntegerLiteral(tudresden.ocl.parser.node.AIntegerLiteral)
*/
public void outAIntegerLiteral(AIntegerLiteral node) {
@@ -616,7 +640,7 @@
defaultOut(node);
}
- /**
+ /*
* @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outABooleanLiteral(tudresden.ocl.parser.node.ABooleanLiteral)
*/
public void outABooleanLiteral(ABooleanLiteral node) {
@@ -624,7 +648,7 @@
defaultOut(node);
}
- /**
+ /*
* @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outAEnumLiteral(tudresden.ocl.parser.node.AEnumLiteral)
*/
public void outAEnumLiteral(AEnumLiteral node) {
@@ -632,15 +656,16 @@
defaultOut(node);
}
- /**
+ /*
* @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseALiteralCollection(tudresden.ocl.parser.node.ALiteralCollection)
*/
+ @SuppressWarnings("unchecked")
public void caseALiteralCollection(ALiteralCollection node)
{
Collection<Object> col = null;
inALiteralCollection(node);
- if(node.getCollectionKind() != null)
+ if (node.getCollectionKind() != null)
{
node.getCollectionKind().apply(this);
@@ -653,39 +678,34 @@
col = new HashBag<Object>();
}
}
- if(node.getLBrace() != null)
- {
+ if (node.getLBrace() != null) {
node.getLBrace().apply(this);
}
- if(node.getExpressionListOrRange() != null)
- {
+ if (node.getExpressionListOrRange() != null) {
val = null;
node.getExpressionListOrRange().apply(this);
col.addAll((Collection<Object>) val);
}
- if(node.getRBrace() != null)
- {
+ if (node.getRBrace() != null) {
node.getRBrace().apply(this);
}
val = col;
outALiteralCollection(node);
}
- /**
+ /*
* @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAExpressionListOrRange(tudresden.ocl.parser.node.AExpressionListOrRange)
*/
public void caseAExpressionListOrRange(AExpressionListOrRange node)
{
Vector<Object> ret = new Vector<Object>();
inAExpressionListOrRange(node);
- if(node.getExpression() != null)
- {
+ if (node.getExpression() != null) {
val = null;
- node.getExpression().apply(this);
+ node.getExpression().apply(this);
ret.add(val);
}
- if(node.getExpressionListOrRangeTail() != null)
- {
+ if (node.getExpressionListOrRangeTail() != null) {
val = null;
node.getExpressionListOrRangeTail().apply(this);
ret.addAll((Collection<? extends Object>) val);
@@ -694,10 +714,11 @@
outAExpressionListOrRange(node);
}
- /**
+ /*
* @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAListExpressionListOrRangeTail(tudresden.ocl.parser.node.AListExpressionListOrRangeTail)
*/
- public void caseAListExpressionListOrRangeTail(AListExpressionListOrRangeTail node)
+ public void caseAListExpressionListOrRangeTail(
+ AListExpressionListOrRangeTail node)
{
// TODO support other kinds of tail
@@ -705,8 +726,7 @@
{
Vector<Object> ret = new Vector<Object>();
Object temp[] = node.getExpressionListTail().toArray();
- for(int i = 0; i < temp.length; i++)
- {
+ for (int i = 0; i < temp.length; i++) {
val = null;
((PExpressionListTail) temp[i]).apply(this);
ret.add(val);
@@ -717,13 +737,14 @@
}
- /**
+ /*
* @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAFeatureCall(tudresden.ocl.parser.node.AFeatureCall)
*/
@SuppressWarnings("unchecked")
public void caseAFeatureCall(AFeatureCall node) {
Object subject = val;
Object feature = null;
+ Object type = fwd;
Vector<Object> parameters = null;
inAFeatureCall(node);
@@ -750,7 +771,7 @@
parameters = new Vector<Object>();
}
- val = runFeatureCall(subject, feature, fwd, parameters);
+ val = runFeatureCall(subject, feature, type, parameters);
outAFeatureCall(node);
}
Modified: branches/gsoc2008/work_issue5042_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_issue5042_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java?view=diff&rev=15508&p1=branches/gsoc2008/work_issue5042_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java&p2=branches/gsoc2008/work_issue5042_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java&r1=15507&r2=15508
==============================================================================
--- branches/gsoc2008/work_issue5042_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java (original)
+++ branches/gsoc2008/work_issue5042_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java 2008-08-05 02:08:46-0700
@@ -26,6 +26,7 @@
import java.io.PushbackReader;
import java.io.StringReader;
+import java.util.Set;
import java.util.Vector;
import tudresden.ocl.parser.OclParser;
@@ -43,7 +44,8 @@
/**
* Logger.
*/
- // private static final Logger LOG = Logger.getLogger(OclInterpreter.class);
+ //private static final Logger LOG = Logger.getLogger(OclInterpreter.class);
+
/**
* Parser OCL tree
*/
@@ -72,7 +74,8 @@
try {
tree = parser.parse();
} catch (Exception e) {
- throw new InvalidOclException("Invalid OCL!");
+ e.printStackTrace();
+ throw new InvalidOclException(ocl);
}
}
@@ -105,7 +108,7 @@
/**
* Computes and returns the set of triggers for this constraint.
*
- * @see Critic#addTrigger(String)
+ * @see org.argouml.cognitive.Critic#addTrigger(String)
* @return the set of triggers
*/
public Vector<String> getTriggers() {
@@ -114,4 +117,14 @@
return ct.getTriggers();
}
+ /**
+ * @return the design materials to be criticized by this ocl, no metatype
+ * is assumed by default.
+ */
+ public Set<Object> getCriticizedDesignMaterials() {
+ ComputeDesignMaterials cdm = new ComputeDesignMaterials();
+ tree.apply(cdm);
+ return cdm.getCriticizedDesignMaterials();
+ }
+
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.