Ejemplo n.º 1
0
        public void AddTrivialTranslation(OclExpression expression, string translation)
        {
            TranslationOptions options = new TranslationOptions();

            options.Expression = expression;
            options.SubexpressionTranslations = this;
            options.TranslatedExpression      = expression;
            TranslationOption option = new TranslationOption();

            option.OptionsContainer = options;
            option.FormatString     = translation;
            if (this.Translations.ContainsKey(expression))
            {
                throw new InvalidOperationException(string.Format("Expression '{0}' translated reapeatedly. ", expression));
            }
            options.Options.Add(option);
            this.Translations[expression]         = options;
            this.SelectedTranslations[expression] = 0;
        }
Ejemplo n.º 2
0
        public void AddTranslationOption(OclExpression expression, TranslationOption option, params OclExpression[] subExpressions)
        {
            TranslationOptions options;

            if (!this.Translations.ContainsKey(expression))
            {
                options            = new TranslationOptions();
                options.Expression = expression;
                options.SubexpressionTranslations = this;
                options.TranslatedExpression      = expression;
                foreach (OclExpression subExpression in subExpressions)
                {
                    options.SubExpressions.Add(subExpression);
                }
                this.Translations[expression] = options;
            }
            else
            {
                options = this.Translations[expression];
                if (subExpressions != null && subExpressions.Length > 0)
                {
                    if (subExpressions.Length != options.SubExpressions.Count)
                    {
                        throw new InvalidOperationException(string.Format("Inconsistency of subexpressions when adding options for '{0}'", expression));
                    }

                    for (int index = 0; index < subExpressions.Length; index++)
                    {
                        OclExpression subExpression = subExpressions[index];
                        if (subExpression != options.SubExpressions[index])
                        {
                            throw new InvalidOperationException(string.Format("Inconsistency of subexpressions when adding options for '{0}'", expression));
                        }
                    }
                }
            }

            option.OptionsContainer = options;
            this.SelectedTranslations[expression] = 0;
            options.Options.Add(option);
        }