Author: maurelio1234
Date: 2008-07-04 07:22:15-0700
New Revision: 15159
Added:
branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/CompositeModelInterpreter.java
Modified:
branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java
Log:
working on ocl interpreter
Added: branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/CompositeModelInterpreter.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/CompositeModelInterpreter.java?view=auto&rev=15159
==============================================================================
--- (empty file)
+++ branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/CompositeModelInterpreter.java 2008-07-04 07:22:15-0700
@@ -0,0 +1,66 @@
+// $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.HashSet;
+import java.util.Set;
+
+/**
+ * Represents a composite ModelInterpreter
+ *
+ * @author maurelio1234
+ */
+public class CompositeModelInterpreter implements ModelInterpreter {
+
+ private Set<ModelInterpreter> set = new HashSet<ModelInterpreter>();
+
+ /**
+ * Adds a ModelInterpreter to this set
+ *
+ * @param mi
+ */
+ public void addModelInterpreter(ModelInterpreter mi) {
+ set.add(mi);
+ }
+
+ /**
+ * @see org.argouml.profile.internal.ocl.ModelInterpreter#invokeFeature(java.util.HashMap,
+ * java.lang.Object, java.lang.String, java.lang.String,
+ * java.lang.Object[])
+ */
+ public Object invokeFeature(HashMap<String, Object> vt, Object subject,
+ String feature, String type, Object[] parameters) {
+ for (ModelInterpreter mi : set) {
+ Object ret = mi.invokeFeature(vt, subject, feature, type,
+ parameters);
+ if (ret != null) {
+ return ret;
+ }
+ }
+ return null;
+ }
+
+}
Modified: branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java?view=diff&rev=15159&p1=branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java&p2=branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java&r1=15158&r2=15159
==============================================================================
--- branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java (original)
+++ branches/gsoc2008/work_criticsprofiles_maurelio1234/src/org/argouml/profile/internal/ocl/EvaluateInvariant.java 2008-07-04 07:22:15-0700
@@ -59,7 +59,6 @@
import tudresden.ocl.parser.node.AMultMultiplyOperator;
import tudresden.ocl.parser.node.AMultiplicativeExpressionTail;
import tudresden.ocl.parser.node.ANEqualRelationalOperator;
-import tudresden.ocl.parser.node.ANamePathNameBegin;
import tudresden.ocl.parser.node.ANotUnaryOperator;
import tudresden.ocl.parser.node.AOrLogicalOperator;
import tudresden.ocl.parser.node.APlusAddOperator;
@@ -144,7 +143,7 @@
*/
public void defaultIn(Node node)
{
- LOG.debug("\nEntering: " + node.getClass() + "\n NODE: " + node + "\n VAL: " + val + " fwd: "+ fwd);
+ //LOG.debug("\nEntering: " + node.getClass() + "\n NODE: " + node + "\n VAL: " + val + " fwd: "+ fwd);
}
/**
@@ -190,6 +189,7 @@
{
node.getIfBranch().apply(this);
test = asBoolean(val, node.getIfBranch());
+ val = null;
}
if(node.getTThen() != null)
{
@@ -200,6 +200,7 @@
node.getThenBranch().apply(this);
if (test) {
ret = asBoolean(val, node.getThenBranch());
+ val = null;
}
}
if(node.getTElse() != null)
@@ -211,6 +212,7 @@
node.getElseBranch().apply(this);
if (!test) {
ret = asBoolean(val, node.getThenBranch());
+ val = null;
}
}
if(node.getEndif() != null)
@@ -228,6 +230,7 @@
public void caseALogicalExpressionTail(ALogicalExpressionTail node)
{
Object left = val;
+ val = null;
inALogicalExpressionTail(node);
if(node.getLogicalOperator() != null)
@@ -241,6 +244,7 @@
Object op = node.getLogicalOperator();
Object right = val;
+ val = null;
if (left != null && op!= null && right != null) {
if (op instanceof AAndLogicalOperator) {
@@ -266,6 +270,7 @@
public void caseARelationalExpressionTail(ARelationalExpressionTail node)
{
Object left = val;
+ val = null;
inARelationalExpressionTail(node);
if(node.getRelationalOperator() != null)
@@ -279,6 +284,7 @@
Object op = node.getRelationalOperator();
Object right = val;
+ val = null;
if (left != null && op!= null && right != null) {
if (op instanceof AEqualRelationalOperator) {
@@ -308,6 +314,7 @@
public void caseAAdditiveExpressionTail(AAdditiveExpressionTail node)
{
Object left = val;
+ val = null;
inAAdditiveExpressionTail(node);
if(node.getAddOperator() != null)
@@ -321,6 +328,7 @@
Object op = node.getAddOperator();
Object right = val;
+ val = null;
if (left != null && op!= null && right != null) {
if (op instanceof AMinusAddOperator) {
@@ -343,6 +351,7 @@
public void caseAMultiplicativeExpressionTail(AMultiplicativeExpressionTail node)
{
Object left = val;
+ val = null;
inAMultiplicativeExpressionTail(node);
if(node.getMultiplyOperator() != null)
@@ -356,6 +365,7 @@
Object op = node.getMultiplyOperator();
Object right = val;
+ val = null;
if (left != null && op!= null && right != null) {
if (op instanceof ADivMultiplyOperator) {
@@ -384,6 +394,7 @@
}
if(node.getPostfixExpression() != null)
{
+ val = null;
node.getPostfixExpression().apply(this);
}
@@ -429,9 +440,10 @@
inAFeaturePrimaryExpression(node);
if(node.getPathName() != null)
- {
+ {
+ // TODO support other name kinds
node.getPathName().apply(this);
- feature = val;
+ feature = node.getPathName().toString().trim();
}
if(node.getTimeExpression() != null)
{
@@ -445,8 +457,8 @@
}
if(node.getFeatureCallParameters() != null)
{
- node.getFeatureCallParameters().apply(this);
-
+ val = null;
+ node.getFeatureCallParameters().apply(this);
parameters = (Vector<Object>) val;
}
@@ -508,7 +520,8 @@
* @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;
+ Object old_val = EvaluateInvariant.this.val;
+ EvaluateInvariant.this.val = null;
((PExpression)expi).apply(EvaluateInvariant.this);
Object reti = EvaluateInvariant.this.val;
@@ -547,7 +560,7 @@
vars.add(node.getName().toString().trim());
}
- {
+ {
Object temp[] = node.getDeclaratorTail().toArray();
for (int i = 0; i < temp.length; i++) {
((PDeclaratorTail) temp[i]).apply(this);
@@ -596,7 +609,7 @@
if(node.getName() != null)
{
node.getName().apply(this);
- name = val;
+ name = node.getName().toString().trim();
}
if(node.getLetExpressionTypeDeclaration() != null)
{
@@ -691,9 +704,10 @@
inAFeatureCall(node);
if(node.getPathName() != null)
{
+ // TODO support other name kinds
node.getPathName().apply(this);
- feature = val;
+ feature = node.getPathName().toString().trim();
}
if(node.getTimeExpression() != null)
{
@@ -706,7 +720,8 @@
node.getQualifiers().apply(this);
}
if(node.getFeatureCallParameters() != null)
- {
+ {
+ val = null;
node.getFeatureCallParameters().apply(this);
parameters = (Vector<Object>) val;
@@ -724,6 +739,7 @@
inAActualParameterList(node);
if(node.getExpression() != null)
{
+ val = null;
node.getExpression().apply(this);
list.add(val);
}
@@ -732,8 +748,8 @@
Object temp[] = node.getActualParameterListTail().toArray();
for(int i = 0; i < temp.length; i++)
{
- ((PActualParameterListTail) temp[i]).apply(this);
-
+ val = null;
+ ((PActualParameterListTail) temp[i]).apply(this);
list.add(val);
}
}
@@ -742,16 +758,6 @@
outAActualParameterList(node);
}
- /**
- * @see tudresden.ocl.parser.analysis.DepthFirstAdapter#outANamePathNameBegin(tudresden.ocl.parser.node.ANamePathNameBegin)
- */
- public void outANamePathNameBegin(ANamePathNameBegin node)
- {
- // TODO support other name kinds
- val = node.getName().getText();
- defaultOut(node);
- }
-
/** HELPER METHODS **/
private boolean asBoolean(Object value, Object node) {
if (value instanceof Boolean) {
@@ -773,7 +779,11 @@
@SuppressWarnings("unchecked")
private Object runFeatureCall(Object subject, Object feature, Object type, Vector<Object> parameters) {
- LOG.debug("OCL FEATURE CALL: " + subject + ""+ type +""+ feature + "" + 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());
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.