public override void Execute(object parameter = null) { if (Current.ActiveDiagram != null) { OCLScript script = Current.ActiveOCLScript; if (script != null) { var res = script.CompileToAst(); StringBuilder sb = new StringBuilder(); if (res.Errors.HasError) { sb.AppendLine("Errors:"); foreach (var er in res.Errors.Errors) { sb.AppendLine(er.ToString()); } } else { sb.AppendLine("Compilation OK."); foreach (var context in res.Constraints.ClassifierConstraintBlocks) { sb.AppendLine("context " + context.Context.ToString()); foreach (var constraint in context.Invariants) { sb.AppendLine("inv: " + constraint.ToString()); } } } Exolutio.Dialogs.ExolutioMessageBox.Show("OCL Compilation", "OCL compilation result", sb.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); } }