Exemple #1
0
 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());
         }
     }
 }
Exemple #2
0
        public OCLScript CreateTestEnv() {
            ProjectSerializationManager m = new ProjectSerializationManager();
            Project loadedProject = m.LoadProject(@"..\..\..\Projects\tournaments.eXo");
            ModelIntegrity.ModelConsistency.CheckProject(loadedProject);

            OCLScript script = new OCLScript(loadedProject.SingleVersion.PIMSchema);
            return script;
        }
Exemple #3
0
        internal override CommandBase.OperationResult UndoOperation()
        {
            OCLScript oclScript = Project.TranslateComponent <OCLScript>(OCLScriptGuid);

            Project.TranslateComponent <Schema>(schemaGuid).OCLScripts.Remove(oclScript);
            Project.mappingDictionary.Remove(OCLScriptGuid);
            return(OperationResult.OK);
        }
Exemple #4
0
        private void bCopyToScript_Click(object sender, RoutedEventArgs e)
        {
            OCLScript s = new OCLScript(PSMSchema);

            s.Type     = OCLScript.EOclScriptType.Validation;
            s.Contents = tbConstraints.avalonEdit.Text;
            Current.ActiveOCLScript = s;
            CloseWindow();
        }
Exemple #5
0
        internal override void CommandOperation()
        {
            if (OCLScriptGuid == Guid.Empty)
            {
                OCLScriptGuid = Guid.NewGuid();
            }
            Schema    schema    = Project.TranslateComponent <Schema>(schemaGuid);
            OCLScript oclScript = new OCLScript(Project, OCLScriptGuid, schema);

            Report = new CommandReport("New OCL script was added to '{0}'.", schema);
        }
Exemple #6
0
        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);
            }
        }
 public override void Execute(object parameter = null)
 {
     if (Current.ActiveDiagram != null)
     {
         if (Current.ActiveDiagram.Schema != null)
         {
             OCLScript oclScript = new OCLScript(Current.Project, Guid.NewGuid(), Current.ActiveDiagram.Schema);
             oclScript.Type = CreatedScriptType;
             if (CreatedScriptType == OCLScript.EOclScriptType.Validation)
             {
                 oclScript.Contents = string.Format("-- new empty validation script, created {0}. ", DateTime.Now);
             }
             else if (CreatedScriptType == OCLScript.EOclScriptType.Evolution)
             {
                 oclScript.Contents = string.Format("-- new empty evolution script, created {0}. ", DateTime.Now);
             }
             Current.ActiveOCLScript = oclScript;
         }
     }
 }