public static Expression createExpression(String type, SQLRepository repository) { Expression newExpression = null; if (type.ToLower() == "attributevalueexpression") { newExpression = new AttributeValueExpression(repository); } else if (type.ToLower() == "objectvariableexpression") { newExpression = new ObjectVariableExpression(repository); } else if (type.ToLower() == "parameterexpression") { newExpression = new ParameterExpression(repository); } else if (type.ToLower() == "comparisonexpression") { newExpression = new ComparisonExpression(repository); } else if (type.ToLower() == "methodcallexpression") { newExpression = new MethodCallExpression(repository); } else if (type.ToLower() == "literalexpression") { newExpression = new LiteralExpression(); } else if (type.ToLower() == "textualexpression") { newExpression = new TextualExpression(); } return(newExpression); }
public void ObjectListElementExpression() { var variableObjectExpr = new ObjectVariableExpression("a", typeof(A)); var listExpr = new ObjectPropertyExpression(variableObjectExpr, typeof(A).GetProperty("Bs")); var indexExpr = new NumericLiteralExpression(1); var expr = new ObjectListElementExpression(listExpr, indexExpr); B b; A a = new A { Bs = new[] { new B { Id = 0 }, b = new B { Id = 1 }, } }; object instance = expr.GetInstance(new Dictionary <string, object> { { "a", a } }); Assert.Same(b, instance); }
public static MethodCallExpression generateMethodCallExpression(SQLRepository sqlRepository, Object target, SQLMethod method) { MethodCallExpression methodCallExpression = new MethodCallExpression(method, sqlRepository); Expression targetExpression = null; foreach (SQLParameter parameter in method.Parameters) { ParameterBinding parameterBinding = new ParameterBinding(sqlRepository, parameter); Expression expression = new LiteralExpression("null"); parameterBinding.ValueExpression = expression; methodCallExpression.OwnedParameterBinding.Add(parameterBinding); } //check if the target is an ObjectVariable or a Parameter if (target is SQLParameter) { SQLParameter parameter = target as SQLParameter; ParameterExpression parameterExpression = new ParameterExpression(sqlRepository, parameter); targetExpression = parameterExpression; } else if (target is SQLElement) { SQLElement element = target as SQLElement; ObjectVariableExpression ovExp = new ObjectVariableExpression(element, sqlRepository); targetExpression = ovExp; } methodCallExpression.Target = targetExpression; return(methodCallExpression); }
public static string setOvMethodCallExpressionGui(ObjectVariable ov) { SQLTaggedValue mceVisTag = EAUtil.findTaggedValue(ov.sqlElement, ObjectVariable.MceVisualizationTaggedValueName); Expression BindingExpression = ov.BindingExpression; if (BindingExpression != null) { deletePossibleBindingConnectors(ov.sqlElement.getRealElement()); if (BindingExpression is MethodCallExpression) { var mcE = BindingExpression as MethodCallExpression; ObjectVariableExpression firstOvExpression = null; if (mcE.OwnedParameterBinding.Count == 1 && (mceVisTag == null || mceVisTag.Value == "true")) { foreach (ParameterBinding paramBinding in mcE.OwnedParameterBinding) { if (paramBinding.ValueExpression is ObjectVariableExpression) { firstOvExpression = paramBinding.ValueExpression as ObjectVariableExpression; } } if (firstOvExpression != null) { EA.Element firstOvEaElement = ov.Repository.GetOriginalRepository().GetElementByGuid(firstOvExpression.ObjectVariableGUID); if (firstOvEaElement.ParentID == ov.sqlElement.ParentID) { EA.Connector bindingLink = firstOvEaElement.Connectors.AddNew("", Main.EADependencyType) as EA.Connector; bindingLink.Stereotype = SDMModelingMain.BindingExpressionLinkStereotype; bindingLink.Name = mcE.Target + "." + mcE.MethodName; bindingLink.SupplierID = ov.sqlElement.ElementID; bindingLink.Update(); EA.Element realElement = ov.sqlElement.getRealElement(); realElement.Connectors.Refresh(); realElement.Notes = ""; realElement.Update(); EAUtil.setTaggedValue(ov.Repository, realElement, ObjectVariable.BindingExpressionOutputTaggedValueName, ""); return(""); } } } } return(BindingExpression.ToString()); } return(""); }
private Expression computeExpression() { Expression expression = null; try { //output will be computed as the name of the stopNode //AttributeValueExpression with target(cmbTarget) and attribute(cmbSources) if (selectedExpressionString == "AttributeValueExpression" && secondObjects.Count > selectedSecondObjectIndex && firstObjects.Count > selectedFirstObjectIndex && selectedSecondObjectIndex != -1 && selectedFirstObjectIndex != -1) { //get OV and Attribute SQLAttribute attribute = this.secondObjects[selectedSecondObjectIndex].EaObject as SQLAttribute; SQLElement targetObjectVariable = this.firstObjects[selectedFirstObjectIndex].EaObject as SQLElement; AttributeValueExpression avExp = new AttributeValueExpression(repository, attribute, targetObjectVariable); expression = avExp; } //MethodCallExpression with target(cmbTarget) and Method(cmbSources) else if (selectedExpressionString == "MethodCallExpression" && secondObjects.Count > selectedSecondObjectIndex && firstObjects.Count > selectedFirstObjectIndex && selectedSecondObjectIndex != -1 && selectedFirstObjectIndex != -1) { SQLMethod method = this.secondObjects[selectedSecondObjectIndex].EaObject as SQLMethod; String name = method.Name; Object target = this.firstObjects[selectedFirstObjectIndex].EaObject; MethodCallExpression methodCallExpression = EditorMethodCallExpression.generateMethodCallExpression(repository, target, method); expression = methodCallExpression; } //parameterExpression else if (selectedExpressionString == "ParameterExpression" && firstObjects.Count > selectedFirstObjectIndex && selectedFirstObjectIndex != -1) { SQLParameter parameter = this.firstObjects[selectedFirstObjectIndex].EaObject as SQLParameter; ParameterExpression pExp = new ParameterExpression(repository, parameter); expression = pExp; } //literalExpression else if (selectedExpressionString == "LiteralExpression") { LiteralExpression literalExpression = new LiteralExpression("null"); expression = literalExpression; } //objectVariableExpression else if (selectedExpressionString == "ObjectVariableExpression" && firstObjects.Count > selectedFirstObjectIndex) { SQLElement sdmObject = this.firstObjects[selectedFirstObjectIndex].EaObject as SQLElement; ObjectVariableExpression ovExp = new ObjectVariableExpression(sdmObject, repository); expression = ovExp; } } catch (Exception) { } return(expression); }
public static String getTargetName(MethodCallExpression methodCallExpression) { string targetName = ""; if (methodCallExpression.Target is ObjectVariableExpression) { ObjectVariableExpression ovExp = methodCallExpression.Target as ObjectVariableExpression; targetName = ovExp.ObjectVariableName; } else if (methodCallExpression.Target is ParameterExpression) { ParameterExpression pExp = methodCallExpression.Target as ParameterExpression; targetName = pExp.ParameterName; } return(targetName); }
public void NumberListElementExpression() { var variableObjectExpr = new ObjectVariableExpression("a", typeof(A)); var listExpr = new ObjectPropertyExpression(variableObjectExpr, typeof(A).GetProperty("Ints")); var indexExpr = new NumericLiteralExpression(1); var expr = new NumericListElementExpression(listExpr, indexExpr); A a = new A { Ints = new List <int> { 1, 2 } }; double value = expr.Evaluate(new Dictionary <string, object> { { "a", a } }); Assert.Equal(2.0, value); }
public static String getExpressionOutput(Expression expression, SQLRepository repository) { String outputString = ""; if (expression is AttributeValueExpression) { AttributeValueExpression aVe = expression as AttributeValueExpression; outputString = "AttributeValueExpression: " + aVe.ObjectVariableName + "." + aVe.AttributeName + "is corrupted"; } else if (expression is ObjectVariableExpression) { ObjectVariableExpression oVe = expression as ObjectVariableExpression; outputString = "ObjectVariableExpression: " + oVe.ObjectVariableName + "is corrupted"; } else if (expression is ParameterExpression) { ParameterExpression pExp = expression as ParameterExpression; } return(outputString); }
public static Boolean checkExpression(SQLElement containingElement, Expression expression, SQLRepository sqlRepository) { if (expression is AttributeValueExpression) { AttributeValueExpression aVe = expression as AttributeValueExpression; return(checkAttributeValueExpression(containingElement, sqlRepository, aVe)); } else if (expression is MethodCallExpression) { MethodCallExpression mCe = expression as MethodCallExpression; return(checkMethodCallExpression(containingElement, sqlRepository, mCe)); } else if (expression is ObjectVariableExpression) { ObjectVariableExpression oVe = expression as ObjectVariableExpression; return(checkObjectVariableExpression(containingElement, sqlRepository, oVe)); } else if (expression is ParameterExpression) { return(checkParameterExpression(containingElement, expression as ParameterExpression, sqlRepository)); } else if (expression is ComparisonExpression) { ComparisonExpression compExp = expression as ComparisonExpression; return(checkComparisonExpression(containingElement, sqlRepository, compExp)); } else if (expression is LiteralExpression) { LiteralExpression litExpression = expression as LiteralExpression; return(null == checkLiteralExpression(containingElement, litExpression, sqlRepository)); } else if (expression is ComparisonExpression) { return(checkComparisonExpression(containingElement, expression as ComparisonExpression, sqlRepository)); } return(true); }
public static ExpressionControlData getExpressionStringRepresentation(IExpressionProvider provider, Expression expression, SQLRepository repository) { ExpressionControlData data = new ExpressionControlData(); Expression providerExpression = expression; if (providerExpression == null) { providerExpression = provider.getProviderExpression(); } if (providerExpression != null) { data.Expression = providerExpression.GetType().Name; if (data.Expression == "AttributeValueExpression") { AttributeValueExpression attributeValueExpression = providerExpression as AttributeValueExpression; data.First = attributeValueExpression.ObjectVariableName; data.Second = attributeValueExpression.AttributeName; } else if (data.Expression == "MethodCallExpression") { MethodCallExpression methodCallExpression = providerExpression as MethodCallExpression; if (methodCallExpression.Target is ObjectVariableExpression) { ObjectVariableExpression ovExp = methodCallExpression.Target as ObjectVariableExpression; data.First = ovExp.ObjectVariableName; } else if (methodCallExpression.Target is ParameterExpression) { ParameterExpression pExp = methodCallExpression.Target as ParameterExpression; data.First = pExp.ParameterName; } data.Second = EditorMethodCallExpression.getOperationName(repository, methodCallExpression); foreach (ParameterBinding parameterBinding in methodCallExpression.OwnedParameterBinding) { data.Parameters.Add((parameterBinding.ValueExpression.ToString())); } } else if (data.Expression == "ParameterExpression") { ParameterExpression parameterExpression = providerExpression as ParameterExpression; data.First = parameterExpression.ParameterName; } else if (data.Expression == "LiteralExpression") { LiteralExpression literalExpression = providerExpression as LiteralExpression; data.Parameters.Add(literalExpression.Value); } else if (data.Expression == "ObjectVariableExpression") { ObjectVariableExpression objectVariableExpression = providerExpression as ObjectVariableExpression; data.First = objectVariableExpression.ObjectVariableName; } else if (data.Expression == "TextualExpression") { TextualExpression textualExpression = providerExpression as TextualExpression; data.Expression = "LiteralExpression"; data.Parameters.Add(textualExpression.ExpressionText); } } return(data); }
private static bool checkObjectVariableExpression(SQLElement containingElement, SQLRepository sqlRepository, ObjectVariableExpression oVe) { SQLElement referencedObject = sqlRepository.GetElementByGuid(oVe.ObjectVariableGUID); if (referencedObject == null) { return(false); } if (oVe.ObjectVariableNameOld != oVe.ObjectVariableName) { return(false); } return(compareSDMContainerOfSDMElements(referencedObject, containingElement, sqlRepository)); }
private void createExtractedSDMStatementNode() { Boolean thisPatternCreated = false; int leftMax = 0; int topMax = -100000; computeLeftAndTopMax(ref leftMax, ref topMax); EA.Element thisObject = searchThisObject(); //only create a statementNode if there exists a this object on the sdm //otherwise create new story node with an this variable if (thisObject == null) { thisOvPattern = createStoryPattern("this Activity"); thisObject = createThisOv(thisOvPattern); createDiagramObject(leftMax + 50, topMax - 20, 50, 100, thisObject); createDiagramObject(leftMax, topMax, 100, 200, thisOvPattern); thisPatternCreated = true; leftMax += 300; } //create new story node with objectvariable bound to new sdm. if (checkBoxBoundOv.Checked) { EA.Element boundOvPattern = createStoryPattern("Bound new SDM"); EA.Element boundObject2 = createThisOv(boundOvPattern); SQLElement boundObject = sqlRepository.GetElementByID(boundObject2.ElementID); createDiagramObject(leftMax + 20, topMax - 20, 50, 100, boundObject2); createDiagramObject(leftMax, topMax, 100, 200, boundOvPattern); ObjectVariable ov = new ObjectVariable(boundObject, sqlRepository); ov.loadTreeFromTaggedValue(); ov.BindingState = BindingState.BOUND; MethodCallExpression mcExp = new MethodCallExpression(sqlRepository.GetMethodByID(newMethod.MethodID), sqlRepository); ObjectVariableExpression ovExp = new ObjectVariableExpression(sqlRepository.GetElementByID(thisObject.ElementID), sqlRepository); mcExp.Target = ovExp; ov.BindingExpression = mcExp; ov.Classifier = ovClassifiersComboBox1.Classifiers[ovClassifiersComboBox1.SelectedIndex]; ov.saveTreeToEATaggedValue(true); sdmCallPattern = boundOvPattern; EA.Method sdmMethod = repository.GetMethodByGuid(EAUtil.findTaggedValue(sqlRepository.GetElementByID(newSdmContainer.ElementID), SDMModelingMain.SDMContainerAssociatedMethodTaggedValueName).Value); sdmMethod.ClassifierID = "" + ov.Classifier.EaElement.ElementID; sdmMethod.ReturnType = ov.Classifier.EaElement.Name; sdmMethod.Update(); } //instead create statement node construct else { EA.Element statementActivity = createStoryPattern("Call extracted method"); StatementNode statementNode = new StatementNode(sqlRepository, sqlRepository.GetElementByID(statementActivity.ElementID)); MethodCallExpression mcExp = new MethodCallExpression(sqlRepository.GetMethodByID(newMethod.MethodID), sqlRepository); ObjectVariableExpression ovExp = new ObjectVariableExpression(sqlRepository.GetElementByID(thisObject.ElementID), sqlRepository); mcExp.Target = ovExp; statementNode.StatementExpression = mcExp; statementActivity.Notes = thisObject.Name + "." + newMethod.Name + "()"; EAEcoreAddin.Util.EAUtil.setTaggedValue(sqlRepository, statementActivity, "activityType", "call"); EAEcoreAddin.Util.EAUtil.setTaggedValue(sqlRepository, statementActivity, "evacuated", "false"); statementActivity.Update(); createDiagramObject(leftMax, topMax, 200, 200, statementActivity); statementNode.saveTreeToEATaggedValue(true); sdmCallPattern = statementActivity; } if (thisPatternCreated) { //create edge between this pattern and statement pattern EA.Connector acEdge = thisOvPattern.Connectors.AddNew("", Main.EAControlFlowType) as EA.Connector; acEdge.SupplierID = sdmCallPattern.ElementID; acEdge.Update(); ActivityEdge edge = new ActivityEdge(sqlRepository, sqlRepository.GetConnectorByID(acEdge.ConnectorID)); edge.saveTreeToEATaggedValue(true); } }