Ejemplo n.º 1
0
 private void AddLastRewritings(OperationCallExp operationCallExp, OperationInfo operationInfo)
 {
     AddCollectionAccessRewritings(operationCallExp, "{{last()}}", operationInfo);
 }
Ejemplo n.º 2
0
        private void AddCollectionAccessRewritings(OperationCallExp operationCallExp, string accesExpr, OperationInfo operationInfo)
        {
            TranslationOption optionIndex = new TranslationOption();

            SubexpressionTranslations.AddTranslationOption(operationCallExp, optionIndex);
            // XPath filter changes context - no variable corresponds to the context in this case
            optionIndex.ContextVariableForSubExpressions = null;
            optionIndex.ContextVariableChangeOnlyIn      = 1;
            // in some special cases, parentheses can be omitted
            bool omitParentheses = false;

            if (operationCallExp.Source is LiteralExp)
            {
                omitParentheses = true;
            }
            if (operationCallExp.Source is VariableExp)
            {
                omitParentheses = true;
            }
            if (!operationInfo.IsXPathInfix && !operationInfo.IsXPathPrefix &&
                !operationInfo.IsAmong(OperationHelper.firstOperationInfo, OperationHelper.lastOperationInfo, OperationHelper.atOperationInfo))
            {
                omitParentheses = true;
            }

            if (omitParentheses)
            {
                optionIndex.FormatString = string.Format("({{0}})[{0}]", accesExpr);
            }
            else
            {
                optionIndex.FormatString = string.Format("({{0}})[{0}]", accesExpr);
            }

            optionIndex.LogMessagesWhenSelected = new List <LogMessage <OclExpression> >();
            optionIndex.LogMessagesWhenSelected.Add(new LogMessage <OclExpression>()
            {
                Tag = operationCallExp, MessageText =
                    "Using indexing returns empty sequence when indexes are out of bounds (no error reported, unlike in OCL). "
            });
        }
Ejemplo n.º 3
0
 public void AddFirstRewritings(OperationCallExp operationCallExp, OperationInfo operationInfo)
 {
     AddCollectionAccessRewritings(operationCallExp, "1", operationInfo);
 }