private string AllInstancesHandler(OperationCallExp operationExpression, OperationInfo operationInfo, OclExpression[] arguments) { var type = arguments[0] is TypeExp ? ((TypeExp)arguments[0]).ReferredType : arguments[0].Type; PSMBridgeClass psmBridgeClass = (PSMBridgeClass)type; PSMClass psmClass = (PSMClass)psmBridgeClass.PSMSource; Path allInstancesXPath = psmClass.GetXPathFull(); return(allInstancesXPath.ToString()); }
private void TranslateScript(XElement schSchema, OCLScript oclScript, TranslationSettings translationSettings, ref Dictionary <PSMClass, List <PatternInfo> > patterns) { OclCompilerResult compilerResult = oclScript.CompileToAst(); compilerResult.CompileExpressionsInMessages(); if (!compilerResult.Errors.HasError) { XComment comment = new XComment(string.Format("Below follow constraints from OCL script '{0}'. ", oclScript.Name)); schSchema.Add(comment); foreach (ClassifierConstraintBlock classifierConstraintBlock in compilerResult.Constraints.ClassifierConstraintBlocks) { PSMClass contextClass = (PSMClass)classifierConstraintBlock.Context.Tag; patterns.CreateSubCollectionIfNeeded(contextClass); string patternName = NameSuggestor <PatternInfo> .SuggestUniqueName(patterns[contextClass], contextClass.Name, p => p.PatternName, true, false); PatternInfo patternInfo = new PatternInfo { PatternName = patternName }; XElement patternElement = schSchema.SchematronPattern(patternInfo.PatternName); patterns[contextClass].Add(patternInfo); bool abstractPattern = !contextClass.GeneralizationsAsGeneral.IsEmpty(); if (abstractPattern) { patternElement.AddAttributeWithValue("abstract", "true"); } string context = !abstractPattern?contextClass.GetXPathFull(true).ToString() : "$" + classifierConstraintBlock.Self.Name; XElement ruleElement = patternElement.SchematronRule(context); patternInfo.ContextVariableName = classifierConstraintBlock.Self.Name; if (!abstractPattern) { ruleElement.SchematronLet(patternInfo.ContextVariableName, @"."); } TranslateInvariantsToXPath(classifierConstraintBlock, ruleElement, (PSMBridge)compilerResult.Bridge, translationSettings); } } else { XComment comment = new XComment(string.Format("OCL script '{0}' contains errors and thus can not be translated. ", oclScript.Name)); schSchema.Add(comment); } }