From 739068ba81b3c65de42eef24605fa9f4cbc85dfd Mon Sep 17 00:00:00 2001 From: eeichinger Date: Wed, 5 Nov 2008 21:34:30 +0000 Subject: [PATCH] resolved SPRNET-944 synced 2003, 2005 & 2008 solutions --- src/Spring/Spring.Aop/Spring.Aop.2003.csproj | 25 + src/Spring/Spring.Aop/Spring.Aop.2005.csproj | 5 + .../Spring.Core/Expressions/Expression.cs | 566 +++++++++--------- .../Spring.Core/Expressions/Expression.g | 3 +- .../Expressions/Parser/ExpressionLexer.cs | 1 - .../Expressions/Parser/ExpressionParser.cs | 2 +- .../Expressions/SyntaxErrorException.cs | 117 ++++ .../Spring.Core/Spring.Core.2003.csproj | 5 + .../Spring.Core/Spring.Core.2005.csproj | 7 +- .../Spring.Core/Spring.Core.2008.csproj | 3 +- .../Spring.Messaging.2005.csproj | 1 - src/Spring/Spring.Web/Spring.Web.2005.csproj | 7 +- .../Spring.Aop.Tests.2005.csproj | 3 + .../Spring.Core.Tests/ExceptionsTest.cs | 37 +- .../Expressions/ExpressionEvaluatorTests.cs | 29 +- .../Spring.Testing.NUnit.Tests.2005.csproj | 4 +- .../Spring.Web.Tests.2003.csproj | 2 +- .../Spring.Web.Tests.2005.csproj | 16 +- 18 files changed, 527 insertions(+), 306 deletions(-) create mode 100644 src/Spring/Spring.Core/Expressions/SyntaxErrorException.cs diff --git a/src/Spring/Spring.Aop/Spring.Aop.2003.csproj b/src/Spring/Spring.Aop/Spring.Aop.2003.csproj index a37238db..48e698ac 100644 --- a/src/Spring/Spring.Aop/Spring.Aop.2003.csproj +++ b/src/Spring/Spring.Aop/Spring.Aop.2003.csproj @@ -391,6 +391,16 @@ SubType = "Code" BuildAction = "Compile" /> + + + + + + + + + @@ -342,6 +346,7 @@ Code + Code diff --git a/src/Spring/Spring.Core/Expressions/Expression.cs b/src/Spring/Spring.Core/Expressions/Expression.cs index 3bd00647..3307a568 100644 --- a/src/Spring/Spring.Core/Expressions/Expression.cs +++ b/src/Spring/Spring.Core/Expressions/Expression.cs @@ -1,5 +1,5 @@ -#region License - +#region License + /* * Copyright © 2002-2005 the original author or authors. * @@ -14,271 +14,299 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#endregion - -using System; -using System.Collections; -using System.IO; -using System.Reflection; -using System.Runtime.Serialization; -using antlr; -using antlr.collections; -using Spring.Core; -using Spring.Util; -using StringUtils=Spring.Util.StringUtils; - -namespace Spring.Expressions -{ - /// - /// Container object for the parsed expression. - /// - /// - ///

- /// Preparing this object once and reusing it many times for expression - /// evaluation can result in significant performance improvements, as - /// expression parsing and reflection lookups are only performed once. - ///

- ///
- /// Aleksandar Seovic - [Serializable] - public class Expression : BaseNode - { - /// - /// Contains a list of reserved variable names. - /// You must not use any variable names with the reserved prefix! - /// - public class ReservedVariableNames - { - /// - /// Variable Names using this prefix are reserved for internal framework use - /// - public static readonly string RESERVEDPREFIX = "____spring_"; - - /// - /// variable name of the currently processed object factory, if any - /// - internal static readonly string CurrentObjectFactory = RESERVEDPREFIX + "CurrentObjectFactory"; - } - - private class SpringASTFactory : ASTFactory - { - public SpringASTFactory(Type t) : base(t.FullName) - { - base.defaultASTNodeTypeObject_ = t; - base.typename2creator_ = new Hashtable(32, 0.3f); - base.typename2creator_[t.FullName] = SpringAST.Creator; - } - } - - private class SpringExpressionParser : ExpressionParser - { - public SpringExpressionParser(TokenStream lexer) - : base(lexer) - { - base.astFactory = new SpringASTFactory(typeof(SpringAST)); - base.initialize(); - } - } - - static Expression() - { - // Ensure antlr is loaded (fixes GAC issues)! - Assembly antlrAss = typeof(antlr.LLkParser).Assembly; - } - - /// - /// Initializes a new instance of the class - /// by parsing specified expression string. - /// - /// Expression to parse. - public static IExpression Parse(string expression) - { - if (StringUtils.HasText(expression)) - { - ExpressionLexer lexer = new ExpressionLexer(new StringReader(expression)); - ExpressionParser parser = new SpringExpressionParser(lexer); - - parser.expr(); - - return (IExpression) parser.getAST(); - } - else - { - return new Expression(); - } - } - - /// - /// Registers lambda expression under the specified . - /// - /// Function name to register expression as. - /// Lambda expression to register. - /// Variables dictionary that the function will be registered in. - public static void RegisterFunction(string functionName, string lambdaExpression, IDictionary variables) - { - AssertUtils.ArgumentHasText(functionName, "functionName"); - AssertUtils.ArgumentHasText(lambdaExpression, "lambdaExpression"); - - ExpressionLexer lexer = new ExpressionLexer(new StringReader(lambdaExpression)); - ExpressionParser parser = new SpringExpressionParser(lexer); - - parser.lambda(); - variables[functionName] = parser.getAST(); - } - - /// - /// Initializes a new instance of the class - /// by parsing specified primary expression string. - /// - /// Primary expression to parse. - internal static IExpression ParsePrimary(string expression) - { - if (StringUtils.HasText(expression)) - { - ExpressionLexer lexer = new ExpressionLexer(new StringReader(expression)); - ExpressionParser parser = new SpringExpressionParser(lexer); - - parser.primaryExpression(); - return (IExpression) parser.getAST(); - } - else - { - return new Expression(); - } - } - - /// - /// Initializes a new instance of the class - /// by parsing specified property expression string. - /// - /// Property expression to parse. - internal static IExpression ParseProperty(string expression) - { - if (StringUtils.HasText(expression)) - { - ExpressionLexer lexer = new ExpressionLexer(new StringReader(expression)); - ExpressionParser parser = new SpringExpressionParser(lexer); - - parser.property(); - return (IExpression) parser.getAST(); - } - else - { - return new Expression(); - } - } - - /// - /// Initializes a new instance of the class. - /// - public Expression() - {} - - /// - /// Create a new instance from SerializationInfo - /// - protected Expression(SerializationInfo info, StreamingContext context) - : base(info, context) - {} - - /// - /// Evaluates this expression for the specified root object and returns - /// value of the last node. - /// - /// Context to evaluate expressions against. - /// Current expression evaluation context. - /// Value of the last node. - protected override object Get(object context, EvaluationContext evalContext) - { - object result = context; - - if (this.getNumberOfChildren() > 0) - { - AST node = this.getFirstChild(); - while (node != null) - { - result = ((BaseNode)node).GetValueInternal( result, evalContext ); - - node = node.getNextSibling(); - } - } - - return result; - } - - /// - /// Evaluates this expression for the specified root object and sets - /// value of the last node. - /// - /// Context to evaluate expressions against. - /// Current expression evaluation context. - /// Value to set last node to. - /// If navigation expression is empty. - protected override void Set(object context, EvaluationContext evalContext, object newValue) - { - object target = context; - - if (this.getNumberOfChildren() > 0) - { - AST node = this.getFirstChild(); - - for (int i = 0; i < this.getNumberOfChildren() - 1; i++) - { - try - { - target = ((BaseNode) node).GetValueInternal(target, evalContext); - node = node.getNextSibling(); - } - catch (NotReadablePropertyException e) - { - throw new NotWritablePropertyException("Cannot read the value of '" + node.getText() + "' property in the expression.", e); - } - } - ((BaseNode) node).SetValueInternal(target, evalContext, newValue); - } - else - { - throw new NotSupportedException("You cannot set the value for an empty expression."); - } - } - - /// - /// Evaluates this expression for the specified root object and returns - /// of the last node, if possible. - /// - /// Context to evaluate expression against. - /// Expression variables map. - /// Value of the last node. - internal PropertyInfo GetPropertyInfo(object context, IDictionary variables) - { - if (this.getNumberOfChildren() > 0) - { - object target = context; - AST node = this.getFirstChild(); - - for (int i = 0; i < this.getNumberOfChildren() - 1; i++) - { - target = ((IExpression) node).GetValue(target, variables); - node = node.getNextSibling(); - } - - if (node is PropertyOrFieldNode) - { - return (PropertyInfo) ((PropertyOrFieldNode) node).GetMemberInfo(target); - } - else if (node is IndexerNode) - { - return ((IndexerNode)node).GetPropertyInfo(target, variables); - } - else - { - throw new FatalReflectionException("Cannot obtain PropertyInfo from an expression that does not resolve to a property or an indexer."); - } - } - - throw new FatalReflectionException("Cannot obtain PropertyInfo for empty property name."); - } - } + */ + +#endregion + +using System; +using System.Collections; +using System.IO; +using System.Reflection; +using System.Runtime.Serialization; +using antlr; +using antlr.collections; +using Spring.Core; +using Spring.Util; +using StringUtils = Spring.Util.StringUtils; + +namespace Spring.Expressions +{ + /// + /// Container object for the parsed expression. + /// + /// + ///

+ /// Preparing this object once and reusing it many times for expression + /// evaluation can result in significant performance improvements, as + /// expression parsing and reflection lookups are only performed once. + ///

+ ///
+ /// Aleksandar Seovic + [Serializable] + public class Expression : BaseNode + { + /// + /// Contains a list of reserved variable names. + /// You must not use any variable names with the reserved prefix! + /// + public class ReservedVariableNames + { + /// + /// Variable Names using this prefix are reserved for internal framework use + /// + public static readonly string RESERVEDPREFIX = "____spring_"; + + /// + /// variable name of the currently processed object factory, if any + /// + internal static readonly string CurrentObjectFactory = RESERVEDPREFIX + "CurrentObjectFactory"; + } + + private class SpringASTFactory : ASTFactory + { + public SpringASTFactory( Type t ) + : base( t.FullName ) + { + base.defaultASTNodeTypeObject_ = t; + base.typename2creator_ = new Hashtable( 32, 0.3f ); + base.typename2creator_[t.FullName] = SpringAST.Creator; + } + } + + private class SpringExpressionParser : ExpressionParser + { + public SpringExpressionParser( TokenStream lexer ) + : base( lexer ) + { + base.astFactory = new SpringASTFactory( typeof( SpringAST ) ); + base.initialize(); + } + } + + static Expression() + { + // Ensure antlr is loaded (fixes GAC issues)! + Assembly antlrAss = typeof( antlr.LLkParser ).Assembly; + } + + /// + /// Initializes a new instance of the class + /// by parsing specified expression string. + /// + /// Expression to parse. + public static IExpression Parse( string expression ) + { + if (StringUtils.HasText( expression )) + { + ExpressionLexer lexer = new ExpressionLexer( new StringReader( expression ) ); + ExpressionParser parser = new SpringExpressionParser( lexer ); + + try + { + parser.expr(); + } + catch (TokenStreamRecognitionException ex) + { + throw new SyntaxErrorException( ex.recog.Message, ex.recog.getLine(), ex.recog.getColumn(), expression ); + } + return (IExpression)parser.getAST(); + } + else + { + return new Expression(); + } + } + + /// + /// Registers lambda expression under the specified . + /// + /// Function name to register expression as. + /// Lambda expression to register. + /// Variables dictionary that the function will be registered in. + public static void RegisterFunction( string functionName, string lambdaExpression, IDictionary variables ) + { + AssertUtils.ArgumentHasText( functionName, "functionName" ); + AssertUtils.ArgumentHasText( lambdaExpression, "lambdaExpression" ); + + ExpressionLexer lexer = new ExpressionLexer( new StringReader( lambdaExpression ) ); + ExpressionParser parser = new SpringExpressionParser( lexer ); + + try + { + parser.lambda(); + } + catch (TokenStreamRecognitionException ex) + { + throw new SyntaxErrorException( ex.recog.Message, ex.recog.getLine(), ex.recog.getColumn(), lambdaExpression ); + } + variables[functionName] = parser.getAST(); + } + + /// + /// Initializes a new instance of the class + /// by parsing specified primary expression string. + /// + /// Primary expression to parse. + internal static IExpression ParsePrimary( string expression ) + { + if (StringUtils.HasText( expression )) + { + ExpressionLexer lexer = new ExpressionLexer( new StringReader( expression ) ); + ExpressionParser parser = new SpringExpressionParser( lexer ); + + try + { + parser.primaryExpression(); + } + catch (TokenStreamRecognitionException ex) + { + throw new SyntaxErrorException( ex.recog.Message, ex.recog.getLine(), ex.recog.getColumn(), expression ); + } + return (IExpression)parser.getAST(); + } + else + { + return new Expression(); + } + } + + /// + /// Initializes a new instance of the class + /// by parsing specified property expression string. + /// + /// Property expression to parse. + 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(); + } + } + + /// + /// Initializes a new instance of the class. + /// + public Expression() + { } + + /// + /// Create a new instance from SerializationInfo + /// + protected Expression( SerializationInfo info, StreamingContext context ) + : base( info, context ) + { } + + /// + /// Evaluates this expression for the specified root object and returns + /// value of the last node. + /// + /// Context to evaluate expressions against. + /// Current expression evaluation context. + /// Value of the last node. + protected override object Get( object context, EvaluationContext evalContext ) + { + object result = context; + + if (this.getNumberOfChildren() > 0) + { + AST node = this.getFirstChild(); + while (node != null) + { + result = ((BaseNode)node).GetValueInternal( result, evalContext ); + + node = node.getNextSibling(); + } + } + + return result; + } + + /// + /// Evaluates this expression for the specified root object and sets + /// value of the last node. + /// + /// Context to evaluate expressions against. + /// Current expression evaluation context. + /// Value to set last node to. + /// If navigation expression is empty. + protected override void Set( object context, EvaluationContext evalContext, object newValue ) + { + object target = context; + + if (this.getNumberOfChildren() > 0) + { + AST node = this.getFirstChild(); + + for (int i = 0; i < this.getNumberOfChildren() - 1; i++) + { + try + { + target = ((BaseNode)node).GetValueInternal( target, evalContext ); + node = node.getNextSibling(); + } + catch (NotReadablePropertyException e) + { + throw new NotWritablePropertyException( "Cannot read the value of '" + node.getText() + "' property in the expression.", e ); + } + } + ((BaseNode)node).SetValueInternal( target, evalContext, newValue ); + } + else + { + throw new NotSupportedException( "You cannot set the value for an empty expression." ); + } + } + + /// + /// Evaluates this expression for the specified root object and returns + /// of the last node, if possible. + /// + /// Context to evaluate expression against. + /// Expression variables map. + /// Value of the last node. + internal PropertyInfo GetPropertyInfo( object context, IDictionary variables ) + { + if (this.getNumberOfChildren() > 0) + { + object target = context; + AST node = this.getFirstChild(); + + for (int i = 0; i < this.getNumberOfChildren() - 1; i++) + { + target = ((IExpression)node).GetValue( target, variables ); + node = node.getNextSibling(); + } + + if (node is PropertyOrFieldNode) + { + return (PropertyInfo)((PropertyOrFieldNode)node).GetMemberInfo( target ); + } + else if (node is IndexerNode) + { + return ((IndexerNode)node).GetPropertyInfo( target, variables ); + } + else + { + throw new FatalReflectionException( "Cannot obtain PropertyInfo from an expression that does not resolve to a property or an indexer." ); + } + } + + throw new FatalReflectionException( "Cannot obtain PropertyInfo for empty property name." ); + } + } } \ No newline at end of file diff --git a/src/Spring/Spring.Core/Expressions/Expression.g b/src/Spring/Spring.Core/Expressions/Expression.g index a549f6f8..fb58a31e 100644 --- a/src/Spring/Spring.Core/Expressions/Expression.g +++ b/src/Spring/Spring.Core/Expressions/Expression.g @@ -36,7 +36,7 @@ tokens { public override void reportError(RecognitionException ex) { //base.reportError(ex); - throw ex; + throw new antlr.TokenStreamRecognitionException(ex); } public override void reportError(string error) @@ -322,6 +322,7 @@ options { charVocabulary = '\u0000' .. '\uFFFE'; classHeaderPrefix = "internal"; k = 2; + testLiterals = false; } { diff --git a/src/Spring/Spring.Core/Expressions/Parser/ExpressionLexer.cs b/src/Spring/Spring.Core/Expressions/Parser/ExpressionLexer.cs index f80e88df..e6923693 100644 --- a/src/Spring/Spring.Core/Expressions/Parser/ExpressionLexer.cs +++ b/src/Spring/Spring.Core/Expressions/Parser/ExpressionLexer.cs @@ -364,7 +364,6 @@ tryAgain: break; } if ( null==returnToken_ ) goto tryAgain; // found SKIP token _ttype = returnToken_.Type; - _ttype = testLiteralsTable(_ttype); returnToken_.Type = _ttype; return returnToken_; } diff --git a/src/Spring/Spring.Core/Expressions/Parser/ExpressionParser.cs b/src/Spring/Spring.Core/Expressions/Parser/ExpressionParser.cs index d7779e60..ad96467e 100644 --- a/src/Spring/Spring.Core/Expressions/Parser/ExpressionParser.cs +++ b/src/Spring/Spring.Core/Expressions/Parser/ExpressionParser.cs @@ -100,7 +100,7 @@ namespace Spring.Expressions public override void reportError(RecognitionException ex) { //base.reportError(ex); - throw ex; + throw new antlr.TokenStreamRecognitionException(ex); } public override void reportError(string error) diff --git a/src/Spring/Spring.Core/Expressions/SyntaxErrorException.cs b/src/Spring/Spring.Core/Expressions/SyntaxErrorException.cs new file mode 100644 index 00000000..fc01ac42 --- /dev/null +++ b/src/Spring/Spring.Core/Expressions/SyntaxErrorException.cs @@ -0,0 +1,117 @@ +#region License + +/* + * Copyright © 2002-2008 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#endregion + +#region Imports + +using System; +using System.Globalization; +using System.Runtime.Serialization; +using antlr; + +#endregion + +namespace Spring.Expressions +{ + /// + /// Exception thrown when detecting invalid SpEL syntax + /// + /// Erich Eichinger + [Serializable] + internal class SyntaxErrorException : RecognitionException, ISerializable + { + private string _expression; + + /// + /// + public int Line + { + get { return line; } + } + + /// + /// + public int Column + { + get { return column; } + } + + /// + ///Gets a message that provides details on the syntax error. + /// + public override string Message + { + get + { + return string.Format("Syntax Error on line {0}, column {1}: {2} in expression{3}'{4}'", Line, Column, base.Message, Environment.NewLine, _expression ); + } + } + + /// + /// The expression that caused the error + /// + public string Expression + { + get { return _expression; } + } + + #region Public Instance Constructors + + /// + /// TODO + /// + public SyntaxErrorException(string message, int line, int column, string expression) + : base(message, null, line, column) + { + _expression = expression; + } + + #endregion Public Instance Constructors + + #region Protected Instance Constructors + + /// + /// TODO + /// + protected SyntaxErrorException(SerializationInfo info, StreamingContext context) : base(info.GetString("Message")) + { + base.line = info.GetInt32("Line"); + base.column = info.GetInt32("Column"); + this._expression = info.GetString("Expression"); + } + + /// + /// + /// + /// + /// + public override void GetObjectData( SerializationInfo info, StreamingContext context ) + { + // since RecognitionException does not implement .ctor(SerializationInfo info, StreamingContext context) + // we need to do the serialization on our own... #§$% + //base.GetObjectData( info, context ); + info.AddValue("Line", base.line); + info.AddValue("Column", base.column); + info.AddValue("Message", base.Message); + info.AddValue("Expression", this._expression); + } + + #endregion Protected Instance Constructors + } +} \ No newline at end of file diff --git a/src/Spring/Spring.Core/Spring.Core.2003.csproj b/src/Spring/Spring.Core/Spring.Core.2003.csproj index 26036771..9f584928 100644 --- a/src/Spring/Spring.Core/Spring.Core.2003.csproj +++ b/src/Spring/Spring.Core/Spring.Core.2003.csproj @@ -1121,6 +1121,11 @@ SubType = "Code" BuildAction = "Compile" /> + Code
+ Code @@ -585,7 +586,6 @@ - @@ -982,13 +982,18 @@ + + + + + diff --git a/src/Spring/Spring.Core/Spring.Core.2008.csproj b/src/Spring/Spring.Core/Spring.Core.2008.csproj index f83cc10a..45f9ee54 100644 --- a/src/Spring/Spring.Core/Spring.Core.2008.csproj +++ b/src/Spring/Spring.Core/Spring.Core.2008.csproj @@ -360,6 +360,7 @@ + @@ -1118,7 +1119,7 @@ - rem $(ProjectDir)\..\..\..\tools\antlr-2.7.6\antlr-2.7.6.exe -o $(ProjectDir)\Expressions\Parser $(ProjectDir)\Expressions\Expression.g + rem $(ProjectDir)..\..\..\build-support\tools\antlr-2.7.6\antlr-2.7.6.exe -o $(ProjectDir)Expressions\Parser $(ProjectDir)Expressions\Expression.g diff --git a/src/Spring/Spring.Messaging/Spring.Messaging.2005.csproj b/src/Spring/Spring.Messaging/Spring.Messaging.2005.csproj index 9ac20b22..8fc42205 100644 --- a/src/Spring/Spring.Messaging/Spring.Messaging.2005.csproj +++ b/src/Spring/Spring.Messaging/Spring.Messaging.2005.csproj @@ -52,7 +52,6 @@ - diff --git a/src/Spring/Spring.Web/Spring.Web.2005.csproj b/src/Spring/Spring.Web/Spring.Web.2005.csproj index f4994d15..53b766cd 100644 --- a/src/Spring/Spring.Web/Spring.Web.2005.csproj +++ b/src/Spring/Spring.Web/Spring.Web.2005.csproj @@ -123,8 +123,11 @@ Code + + + @@ -139,6 +142,7 @@ + @@ -167,8 +171,6 @@ - - @@ -275,6 +277,7 @@ ASPXCodeBehind + ASPXCodeBehind diff --git a/test/Spring/Spring.Aop.Tests/Spring.Aop.Tests.2005.csproj b/test/Spring/Spring.Aop.Tests/Spring.Aop.Tests.2005.csproj index 0c045b73..4224d062 100644 --- a/test/Spring/Spring.Aop.Tests/Spring.Aop.Tests.2005.csproj +++ b/test/Spring/Spring.Aop.Tests/Spring.Aop.Tests.2005.csproj @@ -124,12 +124,15 @@ + + + diff --git a/test/Spring/Spring.Core.Tests/ExceptionsTest.cs b/test/Spring/Spring.Core.Tests/ExceptionsTest.cs index 506f5f2a..7f346d46 100644 --- a/test/Spring/Spring.Core.Tests/ExceptionsTest.cs +++ b/test/Spring/Spring.Core.Tests/ExceptionsTest.cs @@ -42,6 +42,14 @@ namespace Spring /// public abstract class ExceptionsTest : StandardsComplianceTest { + // sorry folks, but this is really a special case - default ctor policy doesn't apply here + private bool ExcludeFromConstructorPolicyCheck(Type t) + { + //TODO: uncomment when making SyntaxErrorException public: + if (t.FullName == "Spring.Expressions.SyntaxErrorException") return true; + return false; + } + protected ExceptionsTest() { CheckedType = typeof (Exception); @@ -74,15 +82,21 @@ namespace Spring { return; } - // Does the exception have the 3 standard constructors? - // Default constructor - CheckPublicConstructor(t, "()"); - // Constructor with a single string parameter - CheckPublicConstructor(t, "(string message)", typeof (String)); - // Constructor with a string and an inner exception - CheckPublicConstructor(t, "(string message, Exception inner)", - typeof (String), typeof (Exception)); - // check to see if the serialization constructor is present + + if (!ExcludeFromConstructorPolicyCheck(t)) + { + // Does the exception have the 3 standard constructors? + // Default constructor + CheckPublicConstructor(t, "()"); + // Constructor with a single string parameter + CheckPublicConstructor(t, "(string message)", typeof (String)); + // Constructor with a string and an inner exception + CheckPublicConstructor(t, "(string message, Exception inner)", + typeof (String), typeof (Exception)); + } + + + // check to see if the serialization constructor is present // if exception is sealed, constructor should be private // if exception is not sealed, constructor should be protected if (t.IsSealed) @@ -121,9 +135,10 @@ namespace Spring Assert.Fail(t.Name + " does not implement GetObjectData but has private fields."); } } - if (!t.IsAbstract) + if (!t.IsAbstract + && !ExcludeFromConstructorPolicyCheck(t)) { - CheckInstantiation(t); + CheckInstantiation(t); } } diff --git a/test/Spring/Spring.Core.Tests/Expressions/ExpressionEvaluatorTests.cs b/test/Spring/Spring.Core.Tests/Expressions/ExpressionEvaluatorTests.cs index a0803ec1..4878e0f8 100644 --- a/test/Spring/Spring.Core.Tests/Expressions/ExpressionEvaluatorTests.cs +++ b/test/Spring/Spring.Core.Tests/Expressions/ExpressionEvaluatorTests.cs @@ -33,6 +33,7 @@ using System.Runtime.Serialization.Formatters.Soap; using System.Text; using System.Threading; using System.Web.Services; +using antlr; using antlr.collections; using NUnit.Framework; using Spring.Collections; @@ -134,14 +135,6 @@ namespace Spring.Expressions #endregion - [Test] - [Ignore("SPRNET-944")] - public void DateTests() - { - string dateLiteral = (string)ExpressionEvaluator.GetValue(null, "'date'"); - Assert.AreEqual("date", dateLiteral); - } - #region Serialization Tests /// @@ -279,6 +272,26 @@ namespace Spring.Expressions #endregion Serialization Tests + [Test(Description="SPRNET-944")] + public void DateTests() + { + string dateLiteral = (string)ExpressionEvaluator.GetValue(null, "'date'"); + Assert.AreEqual("date", dateLiteral); + } + + [Test] + public void ThrowsSyntaxErrorException() + { + try + { + ExpressionEvaluator.GetValue(null, "'date"); // unclose string literal + Assert.Fail(); + } + catch (RecognitionException ex) + { + Assert.AreEqual("Syntax Error on line 1, column 6: expecting ''', found '' in expression"+Environment.NewLine+"''date'", ex.Message); + } + } /// /// Should throw exception for null root object diff --git a/test/Spring/Spring.Testing.NUnit.Tests/Spring.Testing.NUnit.Tests.2005.csproj b/test/Spring/Spring.Testing.NUnit.Tests/Spring.Testing.NUnit.Tests.2005.csproj index 36d8f0cf..ae4af770 100644 --- a/test/Spring/Spring.Testing.NUnit.Tests/Spring.Testing.NUnit.Tests.2005.csproj +++ b/test/Spring/Spring.Testing.NUnit.Tests/Spring.Testing.NUnit.Tests.2005.csproj @@ -44,9 +44,7 @@ - - - + diff --git a/test/Spring/Spring.Web.Tests/Spring.Web.Tests.2003.csproj b/test/Spring/Spring.Web.Tests/Spring.Web.Tests.2003.csproj index 85f925e0..4abdc4fb 100644 --- a/test/Spring/Spring.Web.Tests/Spring.Web.Tests.2003.csproj +++ b/test/Spring/Spring.Web.Tests/Spring.Web.Tests.2003.csproj @@ -321,7 +321,7 @@ /> Code + ASPXCodeBehind + + ASPXCodeBehind + - - ASPXCodeBehind - Code + + ASPXCodeBehind + + @@ -119,15 +124,13 @@ + - - - @@ -138,6 +141,7 @@ +