Author: maurelio1234
Date: 2008-07-16 23:25:43-0700
New Revision: 15296
Added:
branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateExpression.java
branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/InvalidOclException.java
branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/OclAPIModelInterpreter.java
- copied, changed from r15250, /branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/OCLAPIModelInterpreter.java
branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/OclType.java
branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/ui/explorer/rules/GoProfileToCritics.java
- copied, changed from r15250, /branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/ui/explorer/GoProfileToCritics.java
Removed:
branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/OCLAPIModelInterpreter.java
branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/ui/explorer/GoProfileToCritics.java
Modified:
branches/gsoc2008/work_midterm_maurelio1234/ext/jbeans.jar
branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/application/Main.java
branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/cognitive/ui/PriorityNode.java
branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/CompositeModelInterpreter.java
branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/CrOCL.java
branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java
branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/ModelInterpreter.java
branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java
branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/CollectionsModelInterpreter.java
branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/ModelAccessModelInterpreter.java
branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/Uml14ModelInterpreter.java
branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/profiles/uml14/metaprofile.xmi
branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/ui/explorer/PerspectiveManager.java
branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/uml/diagram/static_structure/ui/FigEnumeration.java
branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/uml/ui/ActionClassDiagram.java
branches/gsoc2008/work_midterm_maurelio1234/tests/org/argouml/profile/internal/ocl/TestCrOCL.java
branches/gsoc2008/work_midterm_maurelio1234/tests/org/argouml/profile/internal/ocl/TestCrOCL2.java
branches/gsoc2008/work_midterm_maurelio1234/tests/org/argouml/profile/internal/ocl/TestOclInterpreter.java
Log:
new features
Modified: branches/gsoc2008/work_midterm_maurelio1234/ext/jbeans.jar
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_midterm_maurelio1234/ext/jbeans.jar?view=diff&rev=15296&p1=branches/gsoc2008/work_midterm_maurelio1234/ext/jbeans.jar&p2=branches/gsoc2008/work_midterm_maurelio1234/ext/jbeans.jar&r1=15295&r2=15296
==============================================================================
Binary files. No diff available.
Modified: branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/application/Main.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/application/Main.java?view=diff&rev=15296&p1=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/application/Main.java&p2=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/application/Main.java&r1=15295&r2=15296
==============================================================================
--- branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/application/Main.java (original)
+++ branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/application/Main.java 2008-07-16 23:25:43-0700
@@ -160,9 +160,9 @@
if (theTheme != null) {
LookAndFeelMgr.getInstance().setCurrentTheme(theTheme);
}
- if (doSplash) {
+/* if (doSplash) {
splash = initializeSplash();
- }
+ }*/
}
// main initialization happens here
Modified: branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/cognitive/ui/PriorityNode.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/cognitive/ui/PriorityNode.java?view=diff&rev=15296&p1=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/cognitive/ui/PriorityNode.java&p2=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/cognitive/ui/PriorityNode.java&r1=15295&r2=15296
==============================================================================
--- branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/cognitive/ui/PriorityNode.java (original)
+++ branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/cognitive/ui/PriorityNode.java 2008-07-16 23:25:43-0700
@@ -27,6 +27,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
+
import org.argouml.cognitive.ToDoItem;
import org.argouml.cognitive.Translator;
Modified: branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/CompositeModelInterpreter.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/CompositeModelInterpreter.java?view=diff&rev=15296&p1=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/CompositeModelInterpreter.java&p2=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/CompositeModelInterpreter.java&r1=15295&r2=15296
==============================================================================
--- branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/CompositeModelInterpreter.java (original)
+++ branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/CompositeModelInterpreter.java 2008-07-16 23:25:43-0700
@@ -63,4 +63,17 @@
return null;
}
+ /**
+ * @see org.argouml.profile.internal.ocl.ModelInterpreter#getBuiltInSymbol(java.lang.Object)
+ */
+ public Object getBuiltInSymbol(String sym) {
+ for (ModelInterpreter mi : set) {
+ Object ret = mi.getBuiltInSymbol(sym);
+ if (ret != null) {
+ return ret;
+ }
+ }
+ return null;
+ }
+
}
Modified: branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/CrOCL.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/CrOCL.java?view=diff&rev=15296&p1=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/CrOCL.java&p2=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/CrOCL.java&r1=15295&r2=15296
==============================================================================
--- branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/CrOCL.java (original)
+++ branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/CrOCL.java 2008-07-16 23:25:43-0700
@@ -26,6 +26,7 @@
import java.util.Vector;
+import org.argouml.cognitive.Decision;
import org.argouml.cognitive.Designer;
import org.argouml.cognitive.ToDoItem;
import org.argouml.profile.internal.ocl.uml14.Uml14ModelInterpreter;
@@ -49,13 +50,23 @@
* the OCL Interpreter
*/
private OclInterpreter interpreter = null;
-
+
/**
* Creates a new OCL critic
*
* @param ocl ocl expression
+ * @param headline headline
+ * @param description description
+ * @param moreInfoURL
+ * @param knowledgeTypes
+ * @param supportedDecisions
+ * @param priority
+ * @throws InvalidOclException if the ocl is not valid
*/
- public CrOCL(String ocl) {
+ public CrOCL(String ocl, String headline, String description,
+ Integer priority, Vector<Decision> supportedDecisions,
+ Vector<String> knowledgeTypes, String moreInfoURL)
+ throws InvalidOclException {
interpreter = new OclInterpreter(ocl, new Uml14ModelInterpreter());
addSupportedDecision(UMLDecision.PLANNED_EXTENSIONS);
@@ -67,20 +78,40 @@
addTrigger(string);
}
- super.setHeadline("OCL Expression");
- super.setDescription(ocl);
- }
+ if (headline == null) {
+ super.setHeadline("OCL Expression");
+ } else {
+ super.setHeadline(headline);
+ }
- /**
- * Creates a new OCL critic
- *
- * @param ocl ocl expression
- * @param headline headline
- */
- public CrOCL(String ocl, String headline) {
- this(ocl);
- super.setHeadline(headline);
- }
+ if (description == null) {
+ super.setDescription(ocl);
+ } else {
+ super.setDescription(description);
+ }
+
+ if (priority == null) {
+ setPriority(ToDoItem.HIGH_PRIORITY);
+ } else {
+ setPriority(priority);
+ }
+
+ if (supportedDecisions != null) {
+ for (Decision d : supportedDecisions) {
+ addSupportedDecision(d);
+ }
+ }
+
+ if (knowledgeTypes != null) {
+ for (String k : knowledgeTypes) {
+ addKnowledgeType(k);
+ }
+ }
+
+ if (moreInfoURL != null) {
+ setMoreInfoURL(moreInfoURL);
+ }
+ }
/**
* @see org.argouml.uml.cognitive.critics.CrUML#predicate2(java.lang.Object,
Added: branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateExpression.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateExpression.java?view=auto&rev=15296
==============================================================================
--- (empty file)
+++ branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateExpression.java 2008-07-16 23:25:43-0700
@@ -0,0 +1,776 @@
+// $Id: eclipse-argo-codetemplates.xml 11347 2006-10-26 22:37:44Z linus $
+// Copyright (c) 2008 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.profile.internal.ocl;
+
+import java.util.HashMap;
+import java.util.Vector;
+
+import org.apache.log4j.Logger;
+
+import tudresden.ocl.parser.analysis.DepthFirstAdapter;
+import tudresden.ocl.parser.node.AActualParameterList;
+import tudresden.ocl.parser.node.AAdditiveExpressionTail;
+import tudresden.ocl.parser.node.AAndLogicalOperator;
+import tudresden.ocl.parser.node.ABooleanLiteral;
+import tudresden.ocl.parser.node.ADeclaratorTail;
+import tudresden.ocl.parser.node.ADivMultiplyOperator;
+import tudresden.ocl.parser.node.AEmptyFeatureCallParameters;
+import tudresden.ocl.parser.node.AEnumLiteral;
+import tudresden.ocl.parser.node.AEqualRelationalOperator;
+import tudresden.ocl.parser.node.AFeatureCall;
+import tudresden.ocl.parser.node.AFeatureCallParameters;
+import tudresden.ocl.parser.node.AFeaturePrimaryExpression;
+import tudresden.ocl.parser.node.AGtRelationalOperator;
+import tudresden.ocl.parser.node.AGteqRelationalOperator;
+import tudresden.ocl.parser.node.AIfExpression;
+import tudresden.ocl.parser.node.AImpliesLogicalOperator;
+import tudresden.ocl.parser.node.AIntegerLiteral;
+import tudresden.ocl.parser.node.AIterateDeclarator;
+import tudresden.ocl.parser.node.ALetExpression;
+import tudresden.ocl.parser.node.ALiteralCollection;
+import tudresden.ocl.parser.node.ALogicalExpressionTail;
+import tudresden.ocl.parser.node.ALtRelationalOperator;
+import tudresden.ocl.parser.node.ALteqRelationalOperator;
+import tudresden.ocl.parser.node.AMinusAddOperator;
+import tudresden.ocl.parser.node.AMinusUnaryOperator;
+import tudresden.ocl.parser.node.AMultMultiplyOperator;
+import tudresden.ocl.parser.node.AMultiplicativeExpressionTail;
+import tudresden.ocl.parser.node.ANEqualRelationalOperator;
+import tudresden.ocl.parser.node.ANotUnaryOperator;
+import tudresden.ocl.parser.node.AOrLogicalOperator;
+import tudresden.ocl.parser.node.APlusAddOperator;
+import tudresden.ocl.parser.node.APostfixExpressionTail;
+import tudresden.ocl.parser.node.ARealLiteral;
+import tudresden.ocl.parser.node.ARelationalExpressionTail;
+import tudresden.ocl.parser.node.AStandardDeclarator;
+import tudresden.ocl.parser.node.AStringLiteral;
+import tudresden.ocl.parser.node.AUnaryUnaryExpression;
+import tudresden.ocl.parser.node.AXorLogicalOperator;
+import tudresden.ocl.parser.node.PActualParameterListTail;
+import tudresden.ocl.parser.node.PDeclaratorTail;
+import tudresden.ocl.parser.node.PExpression;
+
+/**
+ * Evaluates OCL expressions, this class should not depend on the model
+ * subsystem. This adapter assumes the ocl expression is syntacally and
+ * semantically correct.
+ *
+ * @author maurelio1234
+ */
+public class EvaluateExpression extends DepthFirstAdapter {
+
+ /**
+ * Logger.
+ */
+ private static final Logger LOG = Logger.getLogger(EvaluateExpression.class);
+
+ /**
+ * The Variable Table
+ */
+ private HashMap<String, Object> vt = null;
+
+ /**
+ * Keeps the return value of the visitor
+ */
+ private Object val = null;
+
+ /**
+ * Keeps a forward propagated value
+ */
+ private Object fwd = null;
+
+ /**
+ * The model interpreter
+ */
+ private ModelInterpreter interp = null;
+
+ /**
+ * Constructor
+ *
+ * @param modelElement self
+ * @param mi model interpreter
+ */
+ public EvaluateExpression(Object modelElement, ModelInterpreter mi) {
+ reset(modelElement, mi);
+ }
+
+ /**
+ * Resets the internal state of this adapter
+ *
+ * @param mi
+ * @param modelElement
+ */
+ public void reset(Object modelElement, ModelInterpreter mi) {
+ this.interp = mi;
+
+ val = null;
+ fwd = null;
+ vt = new HashMap<String, Object>();
+ vt.put("self", modelElement);
+ }
+
+ /**
+ * @return is the invariant ok?
+ */
+ public Object getValue() {
+ return val;
+ }
+
+ /** Interpreter Code **/
+
+ /**
+ * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAIfExpression(tudresden.ocl.parser.node.AIfExpression)
+ */
+ public void caseAIfExpression(AIfExpression node)
+ {
+ boolean test = false;
+ boolean ret = false;
+
+ inAIfExpression(node);
+ if(node.getTIf() != null)
+ {
+ node.getTIf().apply(this);
+ }
+ if(node.getIfBranch() != null)
+ {
+ node.getIfBranch().apply(this);
+ test = asBoolean(val, node.getIfBranch());
+ val = null;
+ }
+ if(node.getTThen() != null)
+ {
+ node.getTThen().apply(this);
+ }
+ if(node.getThenBranch() != null)
+ {
+ node.getThenBranch().apply(this);
+ if (test) {
+ ret = asBoolean(val, node.getThenBranch());
+ val = null;
+ }
+ }
+ if(node.getTElse() != null)
+ {
+ node.getTElse().apply(this);
+ }
+ if(node.getElseBranch() != null)
+ {
+ node.getElseBranch().apply(this);
+ if (!test) {
+ ret = asBoolean(val, node.getThenBranch());
+ val = null;
+ }
+ }
+ if(node.getEndif() != null)
+ {
+ node.getEndif().apply(this);
+ }
+
+ val = ret;
+ outAIfExpression(node);
+ }
+
+ /**
+ * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseALogicalExpressionTail(tudresden.ocl.parser.node.ALogicalExpressionTail)
+ */
+ public void caseALogicalExpressionTail(ALogicalExpressionTail node)
+ {
+ Object left = val;
+ val = null;
+
+ inALogicalExpressionTail(node);
+ if(node.getLogicalOperator() != null)
+ {
+ node.getLogicalOperator().apply(this);
+ }
+ if(node.getRelationalExpression() != null)
+ {
+ node.getRelationalExpression().apply(this);
+ }
+
+ Object op = node.getLogicalOperator();
+ Object right = val;
+ val = null;
+
+ if (left != null && op!= null && right != null) {
+ if (op instanceof AAndLogicalOperator) {
+ val = asBoolean(left, node) && asBoolean(right, node);
+ } else if (op instanceof AImpliesLogicalOperator) {
+ val = !asBoolean(left, node) || asBoolean(right, node);
+ } else if (op instanceof AOrLogicalOperator) {
+ val = asBoolean(left, node) || asBoolean(right, node);
+ } else if (op instanceof AXorLogicalOperator) {
+ val = !asBoolean(left, node) ^ asBoolean(right, node);
+ } else {
+ error(node);
+ }
+ } else {
+ error(node);
+ }
+ outALogicalExpressionTail(node);
+ }
+
+ /**
+ * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseARelationalExpressionTail(tudresden.ocl.parser.node.ARelationalExpressionTail)
+ */
+ public void caseARelationalExpressionTail(ARelationalExpressionTail node)
+ {
+ Object left = val;
+ val = null;
+
+ inARelationalExpressionTail(node);
+ if(node.getRelationalOperator() != null)
+ {
+ node.getRelationalOperator().apply(this);
+ }
+ if(node.getAdditiveExpression() != null)
+ {
+ node.getAdditiveExpression().apply(this);
+ }
+
+ Object op = node.getRelationalOperator();
+ Object right = val;
+ val = null;
+
+ if (left != null && op!= null && right != null) {
+ if (op instanceof AEqualRelationalOperator) {
+ val = left.equals(right);
+ } else if (op instanceof AGteqRelationalOperator) {
+ val = asInteger(left, node) >= asInteger(right, node);
+ } else if (op instanceof AGtRelationalOperator) {
+ val = asInteger(left, node) > asInteger(right, node);
+ } else if (op instanceof ALteqRelationalOperator) {
+ val = asInteger(left, node) <= asInteger(right, node);
+ } else if (op instanceof ALtRelationalOperator) {
+ val = asInteger(left, node) < asInteger(right, node);
+ } else if (op instanceof ANEqualRelationalOperator) {
+ val = !left.equals(right);
+ } else {
+ error(node);
+ }
+ } else {
+ error(node);
+ }
+ outARelationalExpressionTail(node);
+ }
+
+ /**
+ * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAAdditiveExpressionTail(tudresden.ocl.parser.node.AAdditiveExpressionTail)
+ */
+ public void caseAAdditiveExpressionTail(AAdditiveExpressionTail node)
+ {
+ Object left = val;
+ val = null;
+
+ inAAdditiveExpressionTail(node);
+ if(node.getAddOperator() != null)
+ {
+ node.getAddOperator().apply(this);
+ }
+ if(node.getMultiplicativeExpression() != null)
+ {
+ node.getMultiplicativeExpression().apply(this);
+ }
+
+ Object op = node.getAddOperator();
+ Object right = val;
+ val = null;
+
+ if (left != null && op!= null && right != null) {
+ if (op instanceof AMinusAddOperator) {
+ val = asInteger(left, node) - asInteger(right, node);
+ } else if (op instanceof APlusAddOperator) {
+ val = asInteger(left, node) + asInteger(right, node);
+ } else {
+ error(node);
+ }
+ } else {
+ error(node);
+ }
+
+ outAAdditiveExpressionTail(node);
+ }
+
+ /**
+ * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAMultiplicativeExpressionTail(tudresden.ocl.parser.node.AMultiplicativeExpressionTail)
+ */
+ public void caseAMultiplicativeExpressionTail(AMultiplicativeExpressionTail node)
+ {
+ Object left = val;
+ val = null;
+
+ inAMultiplicativeExpressionTail(node);
+ if(node.getMultiplyOperator() != null)
+ {
+ node.getMultiplyOperator().apply(this);
+ }
+ if(node.getUnaryExpression() != null)
+ {
+ node.getUnaryExpression().apply(this);
+ }
+
+ Object op = node.getMultiplyOperator();
+ Object right = val;
+ val = null;
+
+ if (left != null && op!= null && right != null) {
+ if (op instanceof ADivMultiplyOperator) {
+ val = asInteger(left, node) / asInteger(right, node);
+ } else if (op instanceof AMultMultiplyOperator) {
+ val = asInteger(left, node) * asInteger(right, node);
+ } else {
+ error(node);
+ }
+ } else {
+ error(node);
+ }
+
+ outAMultiplicativeExpressionTail(node);
+ }
+
+ /**
+ * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAUnaryUnaryExpression(tudresden.ocl.parser.node.AUnaryUnaryExpression)
+ */
+ public void caseAUnaryUnaryExpression(AUnaryUnaryExpression node)
+ {
+ inAUnaryUnaryExpression(node);
+ if(node.getUnaryOperator() != null)
+ {
+ node.getUnaryOperator().apply(this);
+ }
+ if(node.getPostfixExpression() != null)
+ {
+ val = null;
+ node.getPostfixExpression().apply(this);
+ }
+
+ Object op = node.getUnaryOperator();
+ if (op instanceof AMinusUnaryOperator) {
+ val = -asInteger(val, node);
+ } else if (op instanceof ANotUnaryOperator) {
+ val = !asBoolean(val, node);
+ }
+
+ outAUnaryUnaryExpression(node);
+ }
+
+ /**
+ * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAPostfixExpressionTail(tudresden.ocl.parser.node.APostfixExpressionTail)
+ */
+ public void caseAPostfixExpressionTail(APostfixExpressionTail node)
+ {
+ inAPostfixExpressionTail(node);
+ if(node.getPostfixExpressionTailBegin() != null)
+ {
+ node.getPostfixExpressionTailBegin().apply(this);
+ }
+ if(node.getFeatureCall() != null)
+ {
+ fwd = node.getPostfixExpressionTailBegin();
+ node.getFeatureCall().apply(this);
+
+ // XXX: hypotheses for AFeatureCall: fwd = op, val = head
+ }
+ outAPostfixExpressionTail(node);
+ }
+
+ /**
+ * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAFeaturePrimaryExpression(tudresden.ocl.parser.node.AFeaturePrimaryExpression)
+ */
+ @SuppressWarnings("unchecked")
+ public void caseAFeaturePrimaryExpression(AFeaturePrimaryExpression node)
+ {
+ Object subject = val;
+ Object feature = null;
+ Vector<Object> parameters = null;
+
+ inAFeaturePrimaryExpression(node);
+ if(node.getPathName() != null)
+ {
+ // TODO support other name kinds
+ node.getPathName().apply(this);
+ feature = node.getPathName().toString().trim();
+ }
+ if(node.getTimeExpression() != null)
+ {
+ // hypotheses no time expression (only invariants)
+ node.getTimeExpression().apply(this);
+ }
+ if(node.getQualifiers() != null)
+ {
+ // XXX: hypotheses no qualifiers (I don't know)
+ node.getQualifiers().apply(this);
+ }
+ if(node.getFeatureCallParameters() != null)
+ {
+ val = null;
+ node.getFeatureCallParameters().apply(this);
+ parameters = (Vector<Object>) val;
+ }
+
+ if (subject == null) {
+ val = vt.get(feature);
+ if (val == null) {
+ val = this.interp.getBuiltInSymbol(feature.toString().trim());
+ }
+ } else {
+ val = runFeatureCall(subject, feature,fwd,parameters);
+ }
+ outAFeaturePrimaryExpression(node);
+ }
+
+ /**
+ * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outAEmptyFeatureCallParameters(tudresden.ocl.parser.node.AEmptyFeatureCallParameters)
+ */
+ 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")
+ public void caseAFeatureCallParameters(AFeatureCallParameters node)
+ {
+ inAFeatureCallParameters(node);
+ if(node.getLPar() != null)
+ {
+ node.getLPar().apply(this);
+ }
+
+ boolean hasDeclarator = false;
+ if(node.getDeclarator() != null)
+ {
+ node.getDeclarator().apply(this);
+ hasDeclarator = true;
+ }
+ if (node.getActualParameterList() != null) {
+ Vector<String> vars = null;
+ if (hasDeclarator) {
+ Vector<Object> ret = new Vector<Object>();
+ vars = (Vector<String>) val;
+ final PExpression exp = ((AActualParameterList) node
+ .getActualParameterList()).getExpression();
+
+ /*
+ * For a iterator call we should provide:
+ * (a) the variables
+ * (b) the expression to be evaluated on each step
+ * (c) the lambda-evaluator to evaluate it
+ */
+
+ ret.add(vars);
+ ret.add(exp);
+ ret.add(new LambdaEvaluator() {
+
+ /**
+ * @see org.argouml.profile.internal.ocl.LambdaEvaluator#evaluate(java.util.HashMap, java.lang.Object)
+ */
+ public Object evaluate(HashMap<String, Object> vti, Object expi) {
+ Object old_val = EvaluateExpression.this.val;
+ EvaluateExpression.this.val = null;
+ ((PExpression)expi).apply(EvaluateExpression.this);
+
+ Object reti = EvaluateExpression.this.val;
+ EvaluateExpression.this.val = old_val;
+
+ return reti;
+ }
+
+ });
+
+ val = ret;
+ } else {
+ node.getActualParameterList().apply(this);
+ }
+
+ }
+ if (node.getRPar() != null) {
+ node.getRPar().apply(this);
+ }
+ outAFeatureCallParameters(node);
+ }
+
+ /**
+ * @param node
+ * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAStandardDeclarator(tudresden.ocl.parser.node.AStandardDeclarator)
+ */
+ public void caseAStandardDeclarator(AStandardDeclarator node)
+ {
+ inAStandardDeclarator(node);
+
+ Vector<String> vars = new Vector<String>();
+
+ if(node.getName() != null)
+ {
+ node.getName().apply(this);
+
+ vars.add(node.getName().toString().trim());
+ }
+ {
+ Object temp[] = node.getDeclaratorTail().toArray();
+ for (int i = 0; i < temp.length; i++) {
+ ((PDeclaratorTail) temp[i]).apply(this);
+
+ vars.add(((ADeclaratorTail) temp[i]).getName()
+
+ .toString().trim());
+ }
+
+ val = vars;
+ }
+ if(node.getDeclaratorTypeDeclaration() != null)
+ {
+ // TODO check types!
+ node.getDeclaratorTypeDeclaration().apply(this);
+ }
+ if(node.getBar() != null)
+ {
+ node.getBar().apply(this);
+ }
+ outAStandardDeclarator(node);
+ }
+
+ public void outAIterateDeclarator(AIterateDeclarator node)
+ {
+ //TODO support iterate declarator
+ val = new Vector<String>();
+ defaultOut(node);
+ }
+
+ /**
+ * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseALetExpression(tudresden.ocl.parser.node.ALetExpression)
+ */
+ public void caseALetExpression(ALetExpression node)
+ {
+ // TODO support nested let expressions !
+
+ Object name = null;
+ Object value = null;
+
+ inALetExpression(node);
+ if(node.getTLet() != null)
+ {
+ node.getTLet().apply(this);
+ }
+ if(node.getName() != null)
+ {
+ node.getName().apply(this);
+ name = node.getName().toString().trim();
+ }
+ if(node.getLetExpressionTypeDeclaration() != null)
+ {
+ // TODO: check type!
+ node.getLetExpressionTypeDeclaration().apply(this);
+ }
+ if(node.getEqual() != null)
+ {
+ node.getEqual().apply(this);
+ }
+ if(node.getExpression() != null)
+ {
+ node.getExpression().apply(this);
+ }
+ if(node.getTIn() != null)
+ {
+ node.getTIn().apply(this);
+ }
+
+ vt.put((""+name).trim(), value);
+ val = value;
+ outALetExpression(node);
+ }
+
+ /**
+ * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outAStringLiteral(tudresden.ocl.parser.node.AStringLiteral)
+ */
+ public void outAStringLiteral(AStringLiteral node)
+ {
+ val = node.getStringLit().getText();
+ defaultOut(node);
+ }
+
+ /**
+ * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outARealLiteral(tudresden.ocl.parser.node.ARealLiteral)
+ */
+ public void outARealLiteral(ARealLiteral node)
+ {
+ // TODO support real types
+ val = (int)Double.parseDouble(node.getReal().getText());
+ defaultOut(node);
+ }
+
+ /**
+ * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outAIntegerLiteral(tudresden.ocl.parser.node.AIntegerLiteral)
+ */
+ public void outAIntegerLiteral(AIntegerLiteral node)
+ {
+ val = Integer.parseInt(node.getInt().getText());
+ defaultOut(node);
+ }
+
+ /**
+ * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outABooleanLiteral(tudresden.ocl.parser.node.ABooleanLiteral)
+ */
+ public void outABooleanLiteral(ABooleanLiteral node)
+ {
+ val = Boolean.parseBoolean(node.getBool().getText());
+ defaultOut(node);
+ }
+
+ /**
+ * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outAEnumLiteral(tudresden.ocl.parser.node.AEnumLiteral)
+ */
+ public void outAEnumLiteral(AEnumLiteral node)
+ {
+ // TODO support enums!
+ val = null;
+ defaultOut(node);
+ }
+
+ /**
+ * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outALiteralCollection(tudresden.ocl.parser.node.ALiteralCollection)
+ */
+ public void outALiteralCollection(ALiteralCollection node)
+ {
+ // TODO support collections
+ val = new Vector<Object>();
+ defaultOut(node);
+ }
+
+ /**
+ * @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;
+ Vector<Object> parameters = null;
+
+ inAFeatureCall(node);
+ if(node.getPathName() != null)
+ {
+ // TODO support other name kinds
+ node.getPathName().apply(this);
+
+ feature = node.getPathName().toString().trim();
+ }
+ if(node.getTimeExpression() != null)
+ {
+ // XXX hypothesis: no time expression (inv)
+ node.getTimeExpression().apply(this);
+ }
+ if(node.getQualifiers() != null)
+ {
+ // TODO understand qualifiers
+ node.getQualifiers().apply(this);
+ }
+ if(node.getFeatureCallParameters() != null)
+ {
+ val = null;
+ node.getFeatureCallParameters().apply(this);
+
+ parameters = (Vector<Object>) val;
+ } else {
+ parameters = new Vector<Object>();
+ }
+
+ val = runFeatureCall(subject, feature, fwd, parameters);
+ outAFeatureCall(node);
+ }
+
+ public void caseAActualParameterList(AActualParameterList node)
+ {
+ Vector<Object> list = new Vector<Object>();
+ inAActualParameterList(node);
+ if(node.getExpression() != null)
+ {
+ val = null;
+ node.getExpression().apply(this);
+ list.add(val);
+ }
+ {
+
+ Object temp[] = node.getActualParameterListTail().toArray();
+ for(int i = 0; i < temp.length; i++)
+ {
+ val = null;
+ ((PActualParameterListTail) temp[i]).apply(this);
+ list.add(val);
+ }
+ }
+
+ val = list;
+ outAActualParameterList(node);
+ }
+
+ /** HELPER METHODS **/
+ private boolean asBoolean(Object value, Object node) {
+ if (value instanceof Boolean) {
+ return (Boolean) value;
+ } else {
+ errorNotType(node, "Boolean", false);
+ return false;
+ }
+ }
+
+ private int asInteger(Object value, Object node) {
+ if (value instanceof Integer) {
+ return (Integer) value;
+ } else {
+ errorNotType(node, "integer", 0);
+ return 0;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private Object runFeatureCall(Object subject, Object feature, Object type, Vector<Object> parameters) {
+ //LOG.debug("OCL FEATURE CALL: " + subject + ""+ type +""+ feature + "" + parameters);
+
+ if (parameters == null) {
+ parameters = new Vector<Object>();
+ }
+
+ return interp.invokeFeature(vt, subject, feature.toString().trim(),
+ type.toString().trim(), parameters.toArray());
+ }
+
+ /** Error Handling **/
+ private void errorNotType(Object node, String type, Object dft) {
+ LOG.error("OCL does not evaluate to a "+type+ " expression!! Exp: "
+ + node + " Val: " + val);
+ val = dft;
+ }
+
+ private void error(Object node) {
+ LOG.error("Unknown error processing OCL exp!! Exp: "
+ + node + " Val: " + val);
+ val = null;
+ }
+
+}
Modified: branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java?view=diff&rev=15296&p1=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java&p2=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java&r1=15295&r2=15296
==============================================================================
--- branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java (original)
+++ branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java 2008-07-16 23:25:43-0700
@@ -24,57 +24,9 @@
package org.argouml.profile.internal.ocl;
-import java.util.HashMap;
-import java.util.Vector;
-
-import org.apache.log4j.Logger;
-
import tudresden.ocl.parser.analysis.DepthFirstAdapter;
-import tudresden.ocl.parser.node.AActualParameterList;
-import tudresden.ocl.parser.node.AAdditiveExpressionTail;
-import tudresden.ocl.parser.node.AAndLogicalOperator;
-import tudresden.ocl.parser.node.ABooleanLiteral;
import tudresden.ocl.parser.node.AConstraint;
-import tudresden.ocl.parser.node.ADeclaratorTail;
-import tudresden.ocl.parser.node.ADivMultiplyOperator;
-import tudresden.ocl.parser.node.AEmptyFeatureCallParameters;
-import tudresden.ocl.parser.node.AEnumLiteral;
-import tudresden.ocl.parser.node.AEqualRelationalOperator;
-import tudresden.ocl.parser.node.AFeatureCall;
-import tudresden.ocl.parser.node.AFeatureCallParameters;
-import tudresden.ocl.parser.node.AFeaturePrimaryExpression;
-import tudresden.ocl.parser.node.AGtRelationalOperator;
-import tudresden.ocl.parser.node.AGteqRelationalOperator;
-import tudresden.ocl.parser.node.AIfExpression;
-import tudresden.ocl.parser.node.AImpliesLogicalOperator;
-import tudresden.ocl.parser.node.AIntegerLiteral;
-import tudresden.ocl.parser.node.AIterateDeclarator;
-import tudresden.ocl.parser.node.ALetExpression;
-import tudresden.ocl.parser.node.ALiteralCollection;
-import tudresden.ocl.parser.node.ALogicalExpressionTail;
-import tudresden.ocl.parser.node.ALtRelationalOperator;
-import tudresden.ocl.parser.node.ALteqRelationalOperator;
-import tudresden.ocl.parser.node.AMinusAddOperator;
-import tudresden.ocl.parser.node.AMinusUnaryOperator;
-import tudresden.ocl.parser.node.AMultMultiplyOperator;
-import tudresden.ocl.parser.node.AMultiplicativeExpressionTail;
-import tudresden.ocl.parser.node.ANEqualRelationalOperator;
-import tudresden.ocl.parser.node.ANotUnaryOperator;
-import tudresden.ocl.parser.node.AOrLogicalOperator;
-import tudresden.ocl.parser.node.APlusAddOperator;
-import tudresden.ocl.parser.node.APostfixExpressionTail;
-import tudresden.ocl.parser.node.ARealLiteral;
-import tudresden.ocl.parser.node.ARelationalExpressionTail;
-import tudresden.ocl.parser.node.AStandardDeclarator;
-import tudresden.ocl.parser.node.AStringLiteral;
-import tudresden.ocl.parser.node.AUnaryUnaryExpression;
-import tudresden.ocl.parser.node.AXorLogicalOperator;
-import tudresden.ocl.parser.node.Node;
-import tudresden.ocl.parser.node.PActualParameterListTail;
import tudresden.ocl.parser.node.PConstraintBody;
-import tudresden.ocl.parser.node.PDeclaratorTail;
-import tudresden.ocl.parser.node.PExpression;
-import tudresden.ocl.parser.node.Start;
/**
* Evaluates OCL invariants, this class should not depend on the model
@@ -87,33 +39,22 @@
/**
* Logger.
*/
- private static final Logger LOG = Logger.getLogger(EvaluateInvariant.class);
-
- /**
- * The Variable Table
- */
- private HashMap<String, Object> vt = new HashMap<String, Object>();
-
+ //private static final Logger LOG = Logger.getLogger(EvaluateInvariant.class);
+
/**
* Is this invariant satified?
*/
private boolean ok = true;
-
- /**
- * Keeps the return value of the visitor
- */
- private Object val = null;
-
- /**
- * Keeps a forward propagated value
- */
- private Object fwd = null;
-
+
/**
- * The model interpreter
+ * The Expression Evaluator
*/
- private ModelInterpreter interp = null;
-
+ private EvaluateExpression expEvaluator = null;
+
+ private Object modelElement;
+
+ private ModelInterpreter mi;
+
/**
* Constructor
*
@@ -121,8 +62,9 @@
* @param mi model interpreter
*/
public EvaluateInvariant(Object modelElement, ModelInterpreter mi) {
- this.interp = mi;
- vt.put("self", modelElement);
+ this.modelElement = modelElement;
+ this.mi = mi;
+ this.expEvaluator = new EvaluateExpression(modelElement, mi);
}
/**
@@ -131,675 +73,33 @@
public boolean isOK() {
return ok;
}
-
- /** Interpreter Code **/
- public void outStart(Start node)
- {
- ok = asBoolean(val, node);
- }
-
- /**
- * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#defaultIn(tudresden.ocl.parser.node.Node)
- */
- public void defaultIn(Node node)
- {
- //LOG.debug("\nEntering: " + node.getClass() + "\n NODE: " + node + "\n VAL: " + val + " fwd: "+ fwd);
- }
+
+ /** Interpreter Code **/
/**
* @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAConstraint(tudresden.ocl.parser.node.AConstraint)
*/
- public void caseAConstraint(AConstraint node)
- {
+ public void caseAConstraint(AConstraint node) {
inAConstraint(node);
- if(node.getContextDeclaration() != null)
- {
+ if (node.getContextDeclaration() != null) {
node.getContextDeclaration().apply(this);
}
{
boolean localOk = true;
-
- Object temp[] = node.getConstraintBody().toArray();
- for(int i = 0; i < temp.length; i++)
- {
- ((PConstraintBody) temp[i]).apply(this);
- localOk &= asBoolean(val, temp[i]);
- }
-
- val = localOk;
- }
- outAConstraint(node);
- }
-
- /**
- * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAIfExpression(tudresden.ocl.parser.node.AIfExpression)
- */
- public void caseAIfExpression(AIfExpression node)
- {
- boolean test = false;
- boolean ret = false;
-
- inAIfExpression(node);
- if(node.getTIf() != null)
- {
- node.getTIf().apply(this);
- }
- if(node.getIfBranch() != null)
- {
- node.getIfBranch().apply(this);
- test = asBoolean(val, node.getIfBranch());
- val = null;
- }
- if(node.getTThen() != null)
- {
- node.getTThen().apply(this);
- }
- if(node.getThenBranch() != null)
- {
- node.getThenBranch().apply(this);
- if (test) {
- ret = asBoolean(val, node.getThenBranch());
- val = null;
- }
- }
- if(node.getTElse() != null)
- {
- node.getTElse().apply(this);
- }
- if(node.getElseBranch() != null)
- {
- node.getElseBranch().apply(this);
- if (!test) {
- ret = asBoolean(val, node.getThenBranch());
- val = null;
- }
- }
- if(node.getEndif() != null)
- {
- node.getEndif().apply(this);
- }
-
- val = ret;
- outAIfExpression(node);
- }
-
- /**
- * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseALogicalExpressionTail(tudresden.ocl.parser.node.ALogicalExpressionTail)
- */
- public void caseALogicalExpressionTail(ALogicalExpressionTail node)
- {
- Object left = val;
- val = null;
-
- inALogicalExpressionTail(node);
- if(node.getLogicalOperator() != null)
- {
- node.getLogicalOperator().apply(this);
- }
- if(node.getRelationalExpression() != null)
- {
- node.getRelationalExpression().apply(this);
- }
-
- Object op = node.getLogicalOperator();
- Object right = val;
- val = null;
-
- if (left != null && op!= null && right != null) {
- if (op instanceof AAndLogicalOperator) {
- val = asBoolean(left, node) && asBoolean(right, node);
- } else if (op instanceof AImpliesLogicalOperator) {
- val = !asBoolean(left, node) || asBoolean(right, node);
- } else if (op instanceof AOrLogicalOperator) {
- val = asBoolean(left, node) || asBoolean(right, node);
- } else if (op instanceof AXorLogicalOperator) {
- val = !asBoolean(left, node) ^ asBoolean(right, node);
- } else {
- error(node);
- }
- } else {
- error(node);
- }
- outALogicalExpressionTail(node);
- }
-
- /**
- * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseARelationalExpressionTail(tudresden.ocl.parser.node.ARelationalExpressionTail)
- */
- public void caseARelationalExpressionTail(ARelationalExpressionTail node)
- {
- Object left = val;
- val = null;
-
- inARelationalExpressionTail(node);
- if(node.getRelationalOperator() != null)
- {
- node.getRelationalOperator().apply(this);
- }
- if(node.getAdditiveExpression() != null)
- {
- node.getAdditiveExpression().apply(this);
- }
-
- Object op = node.getRelationalOperator();
- Object right = val;
- val = null;
-
- if (left != null && op!= null && right != null) {
- if (op instanceof AEqualRelationalOperator) {
- val = left.equals(right);
- } else if (op instanceof AGteqRelationalOperator) {
- val = asInteger(left, node) >= asInteger(right, node);
- } else if (op instanceof AGtRelationalOperator) {
- val = asInteger(left, node) > asInteger(right, node);
- } else if (op instanceof ALteqRelationalOperator) {
- val = asInteger(left, node) <= asInteger(right, node);
- } else if (op instanceof ALtRelationalOperator) {
- val = asInteger(left, node) < asInteger(right, node);
- } else if (op instanceof ANEqualRelationalOperator) {
- val = !left.equals(right);
- } else {
- error(node);
- }
- } else {
- error(node);
- }
- outARelationalExpressionTail(node);
- }
-
- /**
- * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAAdditiveExpressionTail(tudresden.ocl.parser.node.AAdditiveExpressionTail)
- */
- public void caseAAdditiveExpressionTail(AAdditiveExpressionTail node)
- {
- Object left = val;
- val = null;
-
- inAAdditiveExpressionTail(node);
- if(node.getAddOperator() != null)
- {
- node.getAddOperator().apply(this);
- }
- if(node.getMultiplicativeExpression() != null)
- {
- node.getMultiplicativeExpression().apply(this);
- }
-
- Object op = node.getAddOperator();
- Object right = val;
- val = null;
-
- if (left != null && op!= null && right != null) {
- if (op instanceof AMinusAddOperator) {
- val = asInteger(left, node) - asInteger(right, node);
- } else if (op instanceof APlusAddOperator) {
- val = asInteger(left, node) + asInteger(right, node);
- } else {
- error(node);
- }
- } else {
- error(node);
- }
-
- outAAdditiveExpressionTail(node);
- }
-
- /**
- * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAMultiplicativeExpressionTail(tudresden.ocl.parser.node.AMultiplicativeExpressionTail)
- */
- public void caseAMultiplicativeExpressionTail(AMultiplicativeExpressionTail node)
- {
- Object left = val;
- val = null;
-
- inAMultiplicativeExpressionTail(node);
- if(node.getMultiplyOperator() != null)
- {
- node.getMultiplyOperator().apply(this);
- }
- if(node.getUnaryExpression() != null)
- {
- node.getUnaryExpression().apply(this);
- }
-
- Object op = node.getMultiplyOperator();
- Object right = val;
- val = null;
-
- if (left != null && op!= null && right != null) {
- if (op instanceof ADivMultiplyOperator) {
- val = asInteger(left, node) / asInteger(right, node);
- } else if (op instanceof AMultMultiplyOperator) {
- val = asInteger(left, node) * asInteger(right, node);
- } else {
- error(node);
- }
- } else {
- error(node);
- }
-
- outAMultiplicativeExpressionTail(node);
- }
-
- /**
- * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAUnaryUnaryExpression(tudresden.ocl.parser.node.AUnaryUnaryExpression)
- */
- public void caseAUnaryUnaryExpression(AUnaryUnaryExpression node)
- {
- inAUnaryUnaryExpression(node);
- if(node.getUnaryOperator() != null)
- {
- node.getUnaryOperator().apply(this);
- }
- if(node.getPostfixExpression() != null)
- {
- val = null;
- node.getPostfixExpression().apply(this);
- }
-
- Object op = node.getUnaryOperator();
- if (op instanceof AMinusUnaryOperator) {
- val = -asInteger(val, node);
- } else if (op instanceof ANotUnaryOperator) {
- val = !asBoolean(val, node);
- }
-
- outAUnaryUnaryExpression(node);
- }
-
- /**
- * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAPostfixExpressionTail(tudresden.ocl.parser.node.APostfixExpressionTail)
- */
- public void caseAPostfixExpressionTail(APostfixExpressionTail node)
- {
- inAPostfixExpressionTail(node);
- if(node.getPostfixExpressionTailBegin() != null)
- {
- node.getPostfixExpressionTailBegin().apply(this);
- }
- if(node.getFeatureCall() != null)
- {
- fwd = node.getPostfixExpressionTailBegin();
- node.getFeatureCall().apply(this);
-
- // XXX: hypotheses for AFeatureCall: fwd = op, val = head
- }
- outAPostfixExpressionTail(node);
- }
-
- /**
- * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAFeaturePrimaryExpression(tudresden.ocl.parser.node.AFeaturePrimaryExpression)
- */
- @SuppressWarnings("unchecked")
- public void caseAFeaturePrimaryExpression(AFeaturePrimaryExpression node)
- {
- Object subject = val;
- Object feature = null;
- Vector<Object> parameters = null;
-
- inAFeaturePrimaryExpression(node);
- if(node.getPathName() != null)
- {
- // TODO support other name kinds
- node.getPathName().apply(this);
- feature = node.getPathName().toString().trim();
- }
- if(node.getTimeExpression() != null)
- {
- // hypotheses no time expression (only invariants)
- node.getTimeExpression().apply(this);
- }
- if(node.getQualifiers() != null)
- {
- // XXX: hypotheses no qualifiers (I don't know)
- node.getQualifiers().apply(this);
- }
- if(node.getFeatureCallParameters() != null)
- {
- val = null;
- node.getFeatureCallParameters().apply(this);
- parameters = (Vector<Object>) val;
- }
-
- if (subject == null) {
- val = vt.get(feature);
- } else {
- val = runFeatureCall(subject, feature,fwd,parameters);
- }
- outAFeaturePrimaryExpression(node);
- }
-
- /**
- * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outAEmptyFeatureCallParameters(tudresden.ocl.parser.node.AEmptyFeatureCallParameters)
- */
- 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")
- public void caseAFeatureCallParameters(AFeatureCallParameters node)
- {
- inAFeatureCallParameters(node);
- if(node.getLPar() != null)
- {
- node.getLPar().apply(this);
- }
-
- boolean hasDeclarator = false;
- if(node.getDeclarator() != null)
- {
- node.getDeclarator().apply(this);
- hasDeclarator = true;
- }
- if (node.getActualParameterList() != null) {
- Vector<String> vars = null;
- if (hasDeclarator) {
- Vector<Object> ret = new Vector<Object>();
- vars = (Vector<String>) val;
- final PExpression exp = ((AActualParameterList) node
- .getActualParameterList()).getExpression();
-
- /*
- * For a iterator call we should provide:
- * (a) the variables
- * (b) the expression to be evaluated on each step
- * (c) the lambda-evaluator to evaluate it
- */
-
- ret.add(vars);
- ret.add(exp);
- ret.add(new LambdaEvaluator() {
-
- /**
- * @see org.argouml.profile.internal.ocl.LambdaEvaluator#evaluate(java.util.HashMap, java.lang.Object)
- */
- public Object evaluate(HashMap<String, Object> vti, Object expi) {
- Object old_val = EvaluateInvariant.this.val;
- EvaluateInvariant.this.val = null;
- ((PExpression)expi).apply(EvaluateInvariant.this);
-
- Object reti = EvaluateInvariant.this.val;
- EvaluateInvariant.this.val = old_val;
-
- return reti;
- }
-
- });
-
- val = ret;
- } else {
- node.getActualParameterList().apply(this);
- }
-
- }
- if (node.getRPar() != null) {
- node.getRPar().apply(this);
- }
- outAFeatureCallParameters(node);
- }
-
- /**
- * @param node
- * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseAStandardDeclarator(tudresden.ocl.parser.node.AStandardDeclarator)
- */
- public void caseAStandardDeclarator(AStandardDeclarator node)
- {
- inAStandardDeclarator(node);
-
- Vector<String> vars = new Vector<String>();
-
- if(node.getName() != null)
- {
- node.getName().apply(this);
-
- vars.add(node.getName().toString().trim());
- }
- {
- Object temp[] = node.getDeclaratorTail().toArray();
+ Object temp[] = node.getConstraintBody().toArray();
for (int i = 0; i < temp.length; i++) {
- ((PDeclaratorTail) temp[i]).apply(this);
-
- vars.add(((ADeclaratorTail) temp[i]).getName()
-
- .toString().trim());
- }
-
- val = vars;
- }
- if(node.getDeclaratorTypeDeclaration() != null)
- {
- // TODO check types!
- node.getDeclaratorTypeDeclaration().apply(this);
- }
- if(node.getBar() != null)
- {
- node.getBar().apply(this);
- }
- outAStandardDeclarator(node);
- }
-
- public void outAIterateDeclarator(AIterateDeclarator node)
- {
- //TODO support iterate declarator
- val = new Vector<String>();
- defaultOut(node);
- }
-
- /**
- * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#caseALetExpression(tudresden.ocl.parser.node.ALetExpression)
- */
- public void caseALetExpression(ALetExpression node)
- {
- // TODO support nested let expressions !
-
- Object name = null;
- Object value = null;
-
- inALetExpression(node);
- if(node.getTLet() != null)
- {
- node.getTLet().apply(this);
- }
- if(node.getName() != null)
- {
- node.getName().apply(this);
- name = node.getName().toString().trim();
- }
- if(node.getLetExpressionTypeDeclaration() != null)
- {
- // TODO: check type!
- node.getLetExpressionTypeDeclaration().apply(this);
- }
- if(node.getEqual() != null)
- {
- node.getEqual().apply(this);
- }
- if(node.getExpression() != null)
- {
- node.getExpression().apply(this);
- }
- if(node.getTIn() != null)
- {
- node.getTIn().apply(this);
- }
-
- vt.put((""+name).trim(), value);
- val = value;
- outALetExpression(node);
- }
-
- /**
- * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outAStringLiteral(tudresden.ocl.parser.node.AStringLiteral)
- */
- public void outAStringLiteral(AStringLiteral node)
- {
- val = node.getStringLit().getText();
- defaultOut(node);
- }
-
- /**
- * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outARealLiteral(tudresden.ocl.parser.node.ARealLiteral)
- */
- public void outARealLiteral(ARealLiteral node)
- {
- // TODO support real types
- val = (int)Double.parseDouble(node.getReal().getText());
- defaultOut(node);
- }
-
- /**
- * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outAIntegerLiteral(tudresden.ocl.parser.node.AIntegerLiteral)
- */
- public void outAIntegerLiteral(AIntegerLiteral node)
- {
- val = Integer.parseInt(node.getInt().getText());
- defaultOut(node);
- }
-
- /**
- * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outABooleanLiteral(tudresden.ocl.parser.node.ABooleanLiteral)
- */
- public void outABooleanLiteral(ABooleanLiteral node)
- {
- val = Boolean.parseBoolean(node.getBool().getText());
- defaultOut(node);
- }
-
- /**
- * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outAEnumLiteral(tudresden.ocl.parser.node.AEnumLiteral)
- */
- public void outAEnumLiteral(AEnumLiteral node)
- {
- // TODO support enums!
- val = null;
- defaultOut(node);
- }
-
- /**
- * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outALiteralCollection(tudresden.ocl.parser.node.ALiteralCollection)
- */
- public void outALiteralCollection(ALiteralCollection node)
- {
- // support collections
- val = new Vector<Object>();
- defaultOut(node);
- }
+ expEvaluator.reset(modelElement, mi);
+ ((PConstraintBody) temp[i]).apply(expEvaluator);
- /**
- * @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;
- Vector<Object> parameters = null;
-
- inAFeatureCall(node);
- if(node.getPathName() != null)
- {
- // TODO support other name kinds
- node.getPathName().apply(this);
-
- feature = node.getPathName().toString().trim();
- }
- if(node.getTimeExpression() != null)
- {
- // XXX hypothesis: no time expression (inv)
- node.getTimeExpression().apply(this);
- }
- if(node.getQualifiers() != null)
- {
- // TODO understand qualifiers
- node.getQualifiers().apply(this);
- }
- if(node.getFeatureCallParameters() != null)
- {
- val = null;
- node.getFeatureCallParameters().apply(this);
-
- parameters = (Vector<Object>) val;
- } else {
- parameters = new Vector<Object>();
- }
-
- val = runFeatureCall(subject, feature, fwd, parameters);
- outAFeatureCall(node);
- }
-
- public void caseAActualParameterList(AActualParameterList node)
- {
- Vector<Object> list = new Vector<Object>();
- inAActualParameterList(node);
- if(node.getExpression() != null)
- {
- val = null;
- node.getExpression().apply(this);
- list.add(val);
- }
- {
-
- Object temp[] = node.getActualParameterListTail().toArray();
- for(int i = 0; i < temp.length; i++)
- {
- val = null;
- ((PActualParameterListTail) temp[i]).apply(this);
- list.add(val);
+ Object val = expEvaluator.getValue();
+ localOk &= val != null && (val instanceof Boolean)
+ && (Boolean) val;
}
- }
-
- val = list;
- outAActualParameterList(node);
- }
-
- /** HELPER METHODS **/
- private boolean asBoolean(Object value, Object node) {
- if (value instanceof Boolean) {
- return (Boolean) value;
- } else {
- errorNotType(node, "Boolean", false);
- return false;
- }
- }
-
- private int asInteger(Object value, Object node) {
- if (value instanceof Integer) {
- return (Integer) value;
- } else {
- errorNotType(node, "integer", 0);
- return 0;
- }
- }
- @SuppressWarnings("unchecked")
- private Object runFeatureCall(Object subject, Object feature, Object type, Vector<Object> parameters) {
- //LOG.debug("OCL FEATURE CALL: " + subject + ""+ type +""+ feature + "" + parameters);
-
- if (parameters == null) {
- parameters = new Vector<Object>();
+ ok = localOk;
}
-
- return interp.invokeFeature(vt, subject, feature.toString().trim(),
- type.toString().trim(), parameters.toArray());
- }
-
- /** Error Handling **/
- private void errorNotType(Object node, String type, Object dft) {
- LOG.error("OCL does not evaluate to a "+type+ " expression!! Exp: "
- + node + " Val: " + val);
- val = dft;
+ outAConstraint(node);
}
- private void error(Object node) {
- LOG.error("Unknown error processing OCL exp!! Exp: "
- + node + " Val: " + val);
- val = null;
- }
-
}
Added: branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/InvalidOclException.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/InvalidOclException.java?view=auto&rev=15296
==============================================================================
--- (empty file)
+++ branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/InvalidOclException.java 2008-07-16 23:25:43-0700
@@ -0,0 +1,42 @@
+// $Id: eclipse-argo-codetemplates.xml 11347 2006-10-26 22:37:44Z linus $
+// Copyright (c) 2008 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.profile.internal.ocl;
+
+/**
+ * Exception thrown when an invalid ocl is set
+ *
+ * @author maurelio1234
+ */
+public class InvalidOclException extends Exception {
+
+ /**
+ * Default Constructor
+ *
+ * @param ocl
+ */
+ public InvalidOclException(String ocl) {
+ super(ocl);
+ }
+}
Modified: branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/ModelInterpreter.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/ModelInterpreter.java?view=diff&rev=15296&p1=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/ModelInterpreter.java&p2=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/ModelInterpreter.java&r1=15295&r2=15296
==============================================================================
--- branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/ModelInterpreter.java (original)
+++ branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/ModelInterpreter.java 2008-07-16 23:25:43-0700
@@ -50,5 +50,16 @@
*/
Object invokeFeature(HashMap<String, Object> vt, Object subject,
String feature, String type, Object[] parameters);
+
+ /**
+ * Looks for a built-in symbol. In the case that not all possible built-in
+ * symbols are not in the variable table, the remaining ones should be
+ * resolved using this method. This should be the case, e.g., for the names
+ * of the UML metaclasses.
+ *
+ * @param sym the symbol name
+ * @return the symbol value, or null if the passed symbol is not built-in
+ */
+ Object getBuiltInSymbol(String sym);
}
Modified: branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java?view=diff&rev=15296&p1=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java&p2=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java&r1=15295&r2=15296
==============================================================================
--- branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java (original)
+++ branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/OclInterpreter.java 2008-07-16 23:25:43-0700
@@ -46,7 +46,7 @@
/**
* Logger.
*/
- private static final Logger LOG = Logger.getLogger(OclInterpreter.class);
+ //private static final Logger LOG = Logger.getLogger(OclInterpreter.class);
/**
* Parser OCL tree
@@ -63,8 +63,10 @@
*
* @param ocl expression
* @param interpreter
+ * @throws InvalidOclException
*/
- public OclInterpreter(String ocl, ModelInterpreter interpreter) {
+ public OclInterpreter(String ocl, ModelInterpreter interpreter)
+ throws InvalidOclException {
this.modelInterpreter = interpreter;
Lexer lexer = new Lexer(new PushbackReader(new StringReader(ocl), 2));
@@ -74,7 +76,7 @@
try {
tree = parser.parse();
} catch (Exception e) {
- LOG.error("Exception", e);
+ throw new InvalidOclException("Invalid OCL!");
}
}
Modified: branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/CollectionsModelInterpreter.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/CollectionsModelInterpreter.java?view=diff&rev=15296&p1=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/CollectionsModelInterpreter.java&p2=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/CollectionsModelInterpreter.java&r1=15295&r2=15296
==============================================================================
--- branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/CollectionsModelInterpreter.java (original)
+++ branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/CollectionsModelInterpreter.java 2008-07-16 23:25:43-0700
@@ -137,5 +137,12 @@
}
}
+ /**
+ * @see org.argouml.profile.internal.ocl.ModelInterpreter#getBuiltInSymbol(java.lang.String)
+ */
+ public Object getBuiltInSymbol(String sym) {
+ return null;
+ }
+
}
Modified: branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/ModelAccessModelInterpreter.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/ModelAccessModelInterpreter.java?view=diff&rev=15296&p1=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/ModelAccessModelInterpreter.java&p2=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/ModelAccessModelInterpreter.java&r1=15295&r2=15296
==============================================================================
--- branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/ModelAccessModelInterpreter.java (original)
+++ branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/ModelAccessModelInterpreter.java 2008-07-16 23:25:43-0700
@@ -24,10 +24,13 @@
package org.argouml.profile.internal.ocl.uml14;
+import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
+import org.apache.log4j.Logger;
+import org.argouml.model.Facade;
import org.argouml.model.Model;
import org.argouml.profile.internal.ocl.ModelInterpreter;
@@ -39,6 +42,12 @@
public class ModelAccessModelInterpreter implements ModelInterpreter {
/**
+ * Logger.
+ */
+ private static final Logger LOG = Logger
+ .getLogger(ModelAccessModelInterpreter.class);
+
+ /**
* @see org.argouml.profile.internal.ocl.ModelInterpreter#invokeFeature(java.util.HashMap, java.lang.Object, java.lang.String, java.lang.String, java.lang.Object[])
*/
@SuppressWarnings("unchecked")
@@ -71,4 +80,23 @@
return null;
}
+ /**
+ * Add the metamodel-metaclasses as built-in symbols
+ *
+ * @see org.argouml.profile.internal.ocl.ModelInterpreter#getBuiltInSymbol(java.lang.String)
+ */
+ public Object getBuiltInSymbol(String sym) {
+ Method m;
+ try {
+ m = Facade.class.getDeclaredMethod("isA" + sym,
+ new Class[] { Object.class });
+ if (m != null) {
+ return new OclType(sym.toString());
+ }
+ } catch (Exception e) {
+ LOG.error("Exception", e);
+ }
+ return null;
+ }
+
}
Removed: branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/OCLAPIModelInterpreter.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/OCLAPIModelInterpreter.java?view=auto&rev=15295
Copied: branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/OclAPIModelInterpreter.java (from r15250, /branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/OCLAPIModelInterpreter.java)
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/OclAPIModelInterpreter.java?view=diff&rev=15296&p1=/branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/OCLAPIModelInterpreter.java&p2=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/OclAPIModelInterpreter.java&r1=15250&r2=15296
==============================================================================
--- /branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/OCLAPIModelInterpreter.java (original)
+++ branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/OclAPIModelInterpreter.java 2008-07-16 23:25:43-0700
@@ -24,8 +24,12 @@
package org.argouml.profile.internal.ocl.uml14;
+import java.lang.reflect.Method;
import java.util.HashMap;
+import org.apache.log4j.Logger;
+import org.argouml.model.Facade;
+import org.argouml.model.Model;
import org.argouml.profile.internal.ocl.ModelInterpreter;
/**
@@ -33,8 +37,14 @@
*
* @author maurelio1234
*/
-public class OCLAPIModelInterpreter implements ModelInterpreter {
+public class OclAPIModelInterpreter implements ModelInterpreter {
+
+ /**
+ * Logger.
+ */
+ private static final Logger LOG = Logger.getLogger(OclAPIModelInterpreter.class);
+
/**
* @see org.argouml.profile.internal.ocl.ModelInterpreter#invokeFeature(java.util.HashMap,
* java.lang.Object, java.lang.String, java.lang.String,
@@ -43,11 +53,54 @@
public Object invokeFeature(HashMap<String, Object> vt, Object subject,
String feature, String type, Object[] parameters) {
if (type.equals(".")) {
- if (feature.toString().trim().equals("oclIsKindOf")) {
- return true;
+ // TODO implement the difference between oclIsKindOf and oclIsTypeOf
+ if (feature.toString().trim().equals("oclIsKindOf") ||
+ feature.toString().trim().equals("oclIsTypeOf")) {
+
+ String typeName = ((OclType)parameters[0]).getName();
+
+ if (typeName.equals("OclAny")) {
+ return true;
+ } else {
+ boolean applicable = false;
+ try {
+ Method m = Facade.class.getDeclaredMethod("isA" + typeName,
+ new Class[] { Object.class });
+ if (m != null) {
+ applicable = (Boolean) m.invoke(Model.getFacade(),
+ new Object[] { subject });
+ }
+ } catch (Exception e) {
+ LOG.error("Exception", e);
+ }
+ return applicable;
+ }
+ }
+
+ if (subject instanceof OclType) {
+ if (feature.toString().trim().equals("name")) {
+ return ((OclType)subject).getName();
+ }
}
+
}
return null;
}
+ /**
+ * @see org.argouml.profile.internal.ocl.ModelInterpreter#getBuiltInSymbol(java.lang.String)
+ */
+ public Object getBuiltInSymbol(String sym) {
+ if (sym.equals("OclType")) {
+ return new OclType("OclType");
+ } else if (sym.equals("OclExpression")) {
+ return new OclType("OclExpression");
+ }
+ if (sym.equals("OclAny")) {
+ return new OclType("OclAny");
+ }
+ return null;
+ }
+
+
}
Added: branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/OclType.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/OclType.java?view=auto&rev=15296
==============================================================================
--- (empty file)
+++ branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/OclType.java 2008-07-16 23:25:43-0700
@@ -0,0 +1,55 @@
+// $Id: eclipse-argo-codetemplates.xml 11347 2006-10-26 22:37:44Z linus $
+// Copyright (c) 2008 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.profile.internal.ocl.uml14;
+
+/**
+ * Represents the OCL "OclType" class
+ *
+ * @author maurelio1234
+ */
+public class OclType {
+
+ /**
+ * The name of the type
+ */
+ private String name;
+
+ /**
+ * Default Constructor
+ *
+ * @param type
+ */
+ public OclType(String type) {
+ this.name = type;
+ }
+
+ /**
+ * @return Returns the name.
+ */
+ public String getName() {
+ return name;
+ }
+
+}
Modified: branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/Uml14ModelInterpreter.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/Uml14ModelInterpreter.java?view=diff&rev=15296&p1=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/Uml14ModelInterpreter.java&p2=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/Uml14ModelInterpreter.java&r1=15295&r2=15296
==============================================================================
--- branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/Uml14ModelInterpreter.java (original)
+++ branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/internal/ocl/uml14/Uml14ModelInterpreter.java 2008-07-16 23:25:43-0700
@@ -38,7 +38,7 @@
*/
public Uml14ModelInterpreter() {
addModelInterpreter(new ModelAccessModelInterpreter());
- addModelInterpreter(new OCLAPIModelInterpreter());
+ addModelInterpreter(new OclAPIModelInterpreter());
addModelInterpreter(new CollectionsModelInterpreter());
}
Modified: branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/profiles/uml14/metaprofile.xmi
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/profiles/uml14/metaprofile.xmi?view=diff&rev=15296&p1=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/profiles/uml14/metaprofile.xmi&p2=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/profiles/uml14/metaprofile.xmi&r1=15295&r2=15296
==============================================================================
--- branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/profiles/uml14/metaprofile.xmi (original)
+++ branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/profile/profiles/uml14/metaprofile.xmi 2008-07-16 23:25:43-0700
@@ -1,8 +1,8 @@
<?xml version = '1.0' encoding = 'UTF-8' ?>
-<XMI xmi.version = '1.2' xmlns:UML = 'org.omg.xmi.namespace.UML' timestamp = 'Thu Jun 19 21:01:27 CEST 2008'>
+<XMI xmi.version = '1.2' xmlns:UML = 'org.omg.xmi.namespace.UML' timestamp = 'Thu Jul 17 07:16:58 CEST 2008'>
<XMI.header> <XMI.documentation>
<XMI.exporter>ArgoUML (using Netbeans XMI Writer version 1.0)</XMI.exporter>
- <XMI.exporterVersion>PRE-0.25.6(6) revised on $Date: 2007-05-12 08:08:08 +0200 (sam., 12 mai 2007) $ </XMI.exporterVersion>
+ <XMI.exporterVersion>PRE-0.26.beta1(6) revised on $Date: 2007-05-12 08:08:08 +0200 (sam., 12 mai 2007) $ </XMI.exporterVersion>
</XMI.documentation>
<XMI.metamodel xmi.name="UML" xmi.version="1.4"/></XMI.header>
<XMI.content>
@@ -66,6 +66,50 @@
</UML:Multiplicity>
</UML:TagDefinition.multiplicity>
</UML:TagDefinition>
+ <UML:TagDefinition xmi.id = '127-0-1-1--690faa61:11b2f4ae818:-8000:00000000000008AC'
+ name = 'Priority' isSpecification = 'false'>
+ <UML:TagDefinition.multiplicity>
+ <UML:Multiplicity xmi.id = '127-0-1-1--690faa61:11b2f4ae818:-8000:00000000000008B0'>
+ <UML:Multiplicity.range>
+ <UML:MultiplicityRange xmi.id = '127-0-1-1--690faa61:11b2f4ae818:-8000:00000000000008AF'
+ lower = '0' upper = '1'/>
+ </UML:Multiplicity.range>
+ </UML:Multiplicity>
+ </UML:TagDefinition.multiplicity>
+ </UML:TagDefinition>
+ <UML:TagDefinition xmi.id = '127-0-1-1--690faa61:11b2f4ae818:-8000:00000000000008B1'
+ name = 'SupportedDecision' isSpecification = 'false'>
+ <UML:TagDefinition.multiplicity>
+ <UML:Multiplicity xmi.id = '127-0-1-1--690faa61:11b2f4ae818:-8000:00000000000008B2'>
+ <UML:Multiplicity.range>
+ <UML:MultiplicityRange xmi.id = '127-0-1-1--690faa61:11b2f4ae818:-8000:00000000000008B3'
+ lower = '0' upper = '1'/>
+ </UML:Multiplicity.range>
+ </UML:Multiplicity>
+ </UML:TagDefinition.multiplicity>
+ </UML:TagDefinition>
+ <UML:TagDefinition xmi.id = '127-0-1-1--690faa61:11b2f4ae818:-8000:00000000000008B4'
+ name = 'KnowldgeType' isSpecification = 'false'>
+ <UML:TagDefinition.multiplicity>
+ <UML:Multiplicity xmi.id = '127-0-1-1--690faa61:11b2f4ae818:-8000:00000000000008B5'>
+ <UML:Multiplicity.range>
+ <UML:MultiplicityRange xmi.id = '127-0-1-1--690faa61:11b2f4ae818:-8000:00000000000008B6'
+ lower = '0' upper = '1'/>
+ </UML:Multiplicity.range>
+ </UML:Multiplicity>
+ </UML:TagDefinition.multiplicity>
+ </UML:TagDefinition>
+ <UML:TagDefinition xmi.id = '127-0-1-1--690faa61:11b2f4ae818:-8000:00000000000008B7'
+ name = 'MoreInfoURL' isSpecification = 'false'>
+ <UML:TagDefinition.multiplicity>
+ <UML:Multiplicity xmi.id = '127-0-1-1--690faa61:11b2f4ae818:-8000:00000000000008B8'>
+ <UML:Multiplicity.range>
+ <UML:MultiplicityRange xmi.id = '127-0-1-1--690faa61:11b2f4ae818:-8000:00000000000008B9'
+ lower = '0' upper = '1'/>
+ </UML:Multiplicity.range>
+ </UML:Multiplicity>
+ </UML:TagDefinition.multiplicity>
+ </UML:TagDefinition>
</UML:Namespace.ownedElement>
</UML:Model>
</XMI.content>
Removed: branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/ui/explorer/GoProfileToCritics.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/ui/explorer/GoProfileToCritics.java?view=auto&rev=15295
Modified: branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/ui/explorer/PerspectiveManager.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/ui/explorer/PerspectiveManager.java?view=diff&rev=15296&p1=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/ui/explorer/PerspectiveManager.java&p2=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/ui/explorer/PerspectiveManager.java&r1=15295&r2=15296
==============================================================================
--- branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/ui/explorer/PerspectiveManager.java (original)
+++ branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/ui/explorer/PerspectiveManager.java 2008-07-16 23:25:43-0700
@@ -77,6 +77,7 @@
import org.argouml.ui.explorer.rules.GoPackageToClass;
import org.argouml.ui.explorer.rules.GoPackageToElementImport;
import org.argouml.ui.explorer.rules.GoProfileConfigurationToProfile;
+import org.argouml.ui.explorer.rules.GoProfileToCritics;
import org.argouml.ui.explorer.rules.GoProfileToModel;
import org.argouml.ui.explorer.rules.GoProjectToCollaboration;
import org.argouml.ui.explorer.rules.GoProjectToDiagram;
Copied: branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/ui/explorer/rules/GoProfileToCritics.java (from r15250, /branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/ui/explorer/GoProfileToCritics.java)
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/ui/explorer/rules/GoProfileToCritics.java?view=diff&rev=15296&p1=/branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/ui/explorer/GoProfileToCritics.java&p2=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/ui/explorer/rules/GoProfileToCritics.java&r1=15250&r2=15296
==============================================================================
--- /branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/ui/explorer/GoProfileToCritics.java (original)
+++ branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/ui/explorer/rules/GoProfileToCritics.java 2008-07-16 23:25:43-0700
@@ -22,7 +22,7 @@
// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
-package org.argouml.ui.explorer;
+package org.argouml.ui.explorer.rules;
import java.util.Collection;
import java.util.Collections;
@@ -30,7 +30,6 @@
import org.argouml.i18n.Translator;
import org.argouml.profile.Profile;
-import org.argouml.ui.explorer.rules.PerspectiveRule;
/**
* Show the critics exported by a Profile
Modified: branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/uml/diagram/static_structure/ui/FigEnumeration.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/uml/diagram/static_structure/ui/FigEnumeration.java?view=diff&rev=15296&p1=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/uml/diagram/static_structure/ui/FigEnumeration.java&p2=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/uml/diagram/static_structure/ui/FigEnumeration.java&r1=15295&r2=15296
==============================================================================
--- branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/uml/diagram/static_structure/ui/FigEnumeration.java (original)
+++ branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/uml/diagram/static_structure/ui/FigEnumeration.java 2008-07-16 23:25:43-0700
@@ -27,7 +27,6 @@
import java.awt.Dimension;
import java.awt.Rectangle;
import java.beans.PropertyChangeEvent;
-import java.beans.PropertyVetoException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@@ -38,7 +37,6 @@
import org.argouml.model.AttributeChangeEvent;
import org.argouml.model.Model;
import org.argouml.ui.ArgoJMenu;
-import org.argouml.uml.diagram.ui.CompartmentFigText;
import org.argouml.uml.diagram.ui.EnumLiteralsCompartmentContainer;
import org.argouml.uml.diagram.ui.FigEnumLiteralsCompartment;
import org.argouml.uml.diagram.ui.FigStereotypesCompartment;
@@ -46,7 +44,6 @@
import org.tigris.gef.base.Selection;
import org.tigris.gef.graph.GraphModel;
import org.tigris.gef.presentation.Fig;
-import org.tigris.gef.presentation.FigText;
/**
* Class to display graphics for a UML Enumeration in a diagram.
Modified: branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/uml/ui/ActionClassDiagram.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/uml/ui/ActionClassDiagram.java?view=diff&rev=15296&p1=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/uml/ui/ActionClassDiagram.java&p2=branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/uml/ui/ActionClassDiagram.java&r1=15295&r2=15296
==============================================================================
--- branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/uml/ui/ActionClassDiagram.java (original)
+++ branches/gsoc2008/work_midterm_maurelio1234/src/org/argouml/uml/ui/ActionClassDiagram.java 2008-07-16 23:25:43-0700
@@ -26,8 +26,8 @@
import org.apache.log4j.Logger;
import org.argouml.model.Model;
-import org.argouml.uml.diagram.DiagramFactory;
import org.argouml.uml.diagram.ArgoDiagram;
+import org.argouml.uml.diagram.DiagramFactory;
/**
* Action to trigger creation of new class diagram.
Modified: branches/gsoc2008/work_midterm_maurelio1234/tests/org/argouml/profile/internal/ocl/TestCrOCL.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_midterm_maurelio1234/tests/org/argouml/profile/internal/ocl/TestCrOCL.java?view=diff&rev=15296&p1=branches/gsoc2008/work_midterm_maurelio1234/tests/org/argouml/profile/internal/ocl/TestCrOCL.java&p2=branches/gsoc2008/work_midterm_maurelio1234/tests/org/argouml/profile/internal/ocl/TestCrOCL.java&r1=15295&r2=15296
==============================================================================
--- branches/gsoc2008/work_midterm_maurelio1234/tests/org/argouml/profile/internal/ocl/TestCrOCL.java (original)
+++ branches/gsoc2008/work_midterm_maurelio1234/tests/org/argouml/profile/internal/ocl/TestCrOCL.java 2008-07-16 23:25:43-0700
@@ -55,7 +55,8 @@
String ocl = "context Actor inv: 0 > 2";
- CrOCL cr = new CrOCL(ocl);
+ CrOCL cr = new CrOCL(ocl, null, null, null,
+ null, null, null);
assertEquals(cr.predicate2(obj1, Designer.theDesigner()),
Critic.PROBLEM_FOUND);
Modified: branches/gsoc2008/work_midterm_maurelio1234/tests/org/argouml/profile/internal/ocl/TestCrOCL2.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_midterm_maurelio1234/tests/org/argouml/profile/internal/ocl/TestCrOCL2.java?view=diff&rev=15296&p1=branches/gsoc2008/work_midterm_maurelio1234/tests/org/argouml/profile/internal/ocl/TestCrOCL2.java&p2=branches/gsoc2008/work_midterm_maurelio1234/tests/org/argouml/profile/internal/ocl/TestCrOCL2.java&r1=15295&r2=15296
==============================================================================
--- branches/gsoc2008/work_midterm_maurelio1234/tests/org/argouml/profile/internal/ocl/TestCrOCL2.java (original)
+++ branches/gsoc2008/work_midterm_maurelio1234/tests/org/argouml/profile/internal/ocl/TestCrOCL2.java 2008-07-16 23:25:43-0700
@@ -52,7 +52,8 @@
public void test6_5_4_2() throws Exception {
Object obj = Model.getUseCasesFactory().createActor();
- CrOCL ocl = new CrOCL("context Actor inv: 2->size() = 1");
+ CrOCL ocl = new CrOCL("context Actor inv: 2->size() = 1", null, null,
+ null, null, null, null);
assertEquals(ocl.predicate2(obj, Designer.theDesigner()),
Critic.NO_PROBLEM);
Modified: branches/gsoc2008/work_midterm_maurelio1234/tests/org/argouml/profile/internal/ocl/TestOclInterpreter.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_midterm_maurelio1234/tests/org/argouml/profile/internal/ocl/TestOclInterpreter.java?view=diff&rev=15296&p1=branches/gsoc2008/work_midterm_maurelio1234/tests/org/argouml/profile/internal/ocl/TestOclInterpreter.java&p2=branches/gsoc2008/work_midterm_maurelio1234/tests/org/argouml/profile/internal/ocl/TestOclInterpreter.java&r1=15295&r2=15296
==============================================================================
--- branches/gsoc2008/work_midterm_maurelio1234/tests/org/argouml/profile/internal/ocl/TestOclInterpreter.java (original)
+++ branches/gsoc2008/work_midterm_maurelio1234/tests/org/argouml/profile/internal/ocl/TestOclInterpreter.java 2008-07-16 23:25:43-0700
@@ -43,6 +43,10 @@
String feature, String type, Object[] parameters) {
return null;
}
+
+ public Object getBuiltInSymbol(String sym) {
+ return null;
+ }
}
@Override
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.