Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Expression"/> class
        /// by parsing specified property expression string.
        /// </summary>
        /// <param name="expression">Property expression to parse.</param>
        internal static IExpression ParseProperty(string expression)
        {
            if (StringUtils.HasText(expression))
            {
                ExpressionLexer  lexer  = new ExpressionLexer(new StringReader(expression));
                ExpressionParser parser = new SpringExpressionParser(lexer);

                try
                {
                    parser.property();
                }
                catch (TokenStreamRecognitionException ex)
                {
                    throw new SyntaxErrorException(ex.recog.Message, ex.recog.getLine(), ex.recog.getColumn(), expression);
                }
                return((IExpression)parser.getAST());
            }
            else
            {
                return(new Expression());
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Returns MemberInfo for the specified property or field
        /// </summary>
        /// <param name="propertyOrFieldName">The name of the property or field to search for.</param>
        /// <returns>The <see cref="PropertyInfo"/> or <see cref="FieldInfo"/> for the specified property or field.</returns>
        /// <exception cref="FatalObjectException">If <paramref name="propertyOrFieldName"/> does not resolve to a property or field.</exception>
        private MemberInfo GetPropertyOrFieldInfo(string propertyOrFieldName)
        {
            if (StringUtils.IsNullOrEmpty(propertyOrFieldName))
            {
                throw new FatalObjectException("Can't find property or field info for null or zero length property name.");
            }

            try
            {
                IExpression propertyExpression = GetPropertyExpression(propertyOrFieldName);
                if (propertyExpression is PropertyOrFieldNode)
                {
                    return(((PropertyOrFieldNode)propertyExpression).GetMemberInfo(this.wrappedObject));
                }
                else if (propertyExpression is IndexerNode)
                {
                    return(((IndexerNode)propertyExpression).GetPropertyInfo(this.wrappedObject, null));
                }
                else if (propertyExpression is Expression)
                {
                    return(((Expression)propertyExpression).GetPropertyInfo(this.wrappedObject, null));
                }
                else
                {
                    throw new FatalObjectException("'" + propertyOrFieldName + "' is not a valid property or field expression.");
                }
            }
            catch (RecognitionException e)
            {
                throw new FatalObjectException("Failed to parse property or field name '" + propertyOrFieldName + "'.", e);
            }
            catch (TokenStreamRecognitionException e)
            {
                throw new FatalObjectException("Failed to parse property or field name '" + propertyOrFieldName + "'.", e);
            }
        }
Esempio n. 3
0
 public void SurroundObjectWithEmptyStrings()
 {
     Assert.AreEqual(":Hi", StringUtils.Surround(string.Empty, new Foo("Hi"), string.Empty));
 }
Esempio n. 4
0
 public void SurroundObject()
 {
     Assert.AreEqual("[:Hi]", StringUtils.Surround("[", new Foo("Hi"), "]"));
 }
Esempio n. 5
0
 public void SurroundNullWithNulls()
 {
     Assert.AreEqual(string.Empty, StringUtils.Surround(null, null));
 }
Esempio n. 6
0
 public void FullSurroundObjectWithNulls()
 {
     Assert.AreEqual(":Hi", StringUtils.Surround(null, new Foo("Hi"), null));
 }
Esempio n. 7
0
        public void GetAntExpressionsWithACoupleOfDuplicatedValidExpressions()
        {
            IList <string> actual = StringUtils.GetAntExpressions("${sigh}. Laura Palmer though... man, that sure was a tragedy. ${sigh}");

            CheckGetAntExpressions(actual, "sigh");
        }
Esempio n. 8
0
 public void SurroundEmptyStringWithEmptyStrings()
 {
     Assert.AreEqual(string.Empty, StringUtils.Surround(string.Empty, string.Empty));
 }
Esempio n. 9
0
 public void FullSurroundNullWithEmptyStrings()
 {
     Assert.AreEqual(string.Empty, StringUtils.Surround(string.Empty, null, string.Empty));
 }
Esempio n. 10
0
        public void ConvertUnsupportedEscapedCharacters()
        {
            string inputString = "what is this\\g";

            Assert.AreEqual(inputString, StringUtils.ConvertEscapedCharacters(inputString));
        }
Esempio n. 11
0
 public void FullSurroundWithNulls()
 {
     Assert.AreEqual("Hi", StringUtils.Surround(null, "Hi", null));
 }
Esempio n. 12
0
 public void FullSurround()
 {
     Assert.AreEqual("[Hi]", StringUtils.Surround("[", "Hi", "]"));
 }
Esempio n. 13
0
 public void GetAntExpressionsIgnoresEmptyExpression()
 {
     Assert.Throws <FormatException>(() => StringUtils.GetAntExpressions("This is an empty expression ${}..."));
 }
Esempio n. 14
0
        public void GetAntExpressionsWithMalformedExpression()
        {
            IList <string> actual = StringUtils.GetAntExpressions("Mmm... just what counts as ${a malformed{ expression?");

            CheckGetAntExpressions(actual, new string[] {});
        }
Esempio n. 15
0
        public void GetAntExpressionsWithACoupleOfUniqueValidExpressions()
        {
            IList <string> actual = StringUtils.GetAntExpressions("${Mmm}. Has there been any good telly since then... ${thinks}");

            CheckGetAntExpressions(actual, "Mmm", "thinks");
        }
Esempio n. 16
0
        public void ConvertEscapedCharactersNoEscapedCharacters()
        {
            string inputString = "foo bar is a funny term";

            Assert.AreEqual(inputString, StringUtils.ConvertEscapedCharacters(inputString));
        }
Esempio n. 17
0
        public void GetAntExpressionsWithAValidExpression()
        {
            IList <string> actual = StringUtils.GetAntExpressions("${slurp}. Ah! That is one good cup of tea. That agent Cooper and his coffee... he sure was missing out on a good thing.");

            CheckGetAntExpressions(actual, "slurp");
        }
Esempio n. 18
0
        public void ConvertEscapedCharactersAll()
        {
            string inputString = "newline\\n tab\\t return\\r";

            Assert.AreEqual("newline\n tab\t return\r", StringUtils.ConvertEscapedCharacters(inputString));
        }
Esempio n. 19
0
 public void Surround()
 {
     Assert.AreEqual("-Hi-", StringUtils.Surround("-", "Hi"));
 }
Esempio n. 20
0
 public void SurroundWithEmptyStrings()
 {
     Assert.AreEqual("Hi", StringUtils.Surround(string.Empty, "Hi"));
 }
Esempio n. 21
0
        public void GetAntExpressionsWithANestedExpression()
        {
            IList <string> actual = StringUtils.GetAntExpressions("And yeah, I've never been a fan of the doughnut... ${blechh${shudder}}");

            CheckGetAntExpressions(actual, "blechh${shudder");
        }