/// <summary> /// Initializes the contents of the expression. /// </summary> private void Initialize() { OpenParenthesisToken openParen = this.FindFirstChild <OpenParenthesisToken>(); if (openParen == null) { throw new SyntaxException(this.Document, this.LineNumber); } LiteralExpression literal = openParen.FindNextSibling <LiteralExpression>(); if (literal == null) { throw new SyntaxException(this.Document, this.LineNumber); } this.type.Value = CodeParser.ExtractTypeTokenFromLiteralExpression(literal); CloseParenthesisToken closeParen = literal.FindNextSibling <CloseParenthesisToken>(); if (closeParen == null) { throw new SyntaxException(this.Document, this.LineNumber); } this.castedExpression.Value = closeParen.FindNextSibling <Expression>(); if (this.castedExpression.Value == null) { throw new SyntaxException(this.Document, this.LineNumber); } }
/// <summary> /// Initializes a new instance of the DefaultValueExpression class. /// </summary> /// <param name="proxy">Proxy object for the expression.</param> /// <param name="type">The type to obtain the default value of.</param> internal DefaultValueExpression(CodeUnitProxy proxy, LiteralExpression type) : base(proxy, ExpressionType.DefaultValue) { Param.AssertNotNull(proxy, "proxy"); Param.AssertNotNull(type, "type"); this.type.Value = CodeParser.ExtractTypeTokenFromLiteralExpression(type); }
/// <summary> /// Initializes a new instance of the CastExpression class. /// </summary> /// <param name="proxy">Proxy object for the expression.</param> /// <param name="type">The cast type.</param> /// <param name="castedExpression">The expression being casted.</param> internal CastExpression(CodeUnitProxy proxy, LiteralExpression type, Expression castedExpression) : base(proxy, ExpressionType.Cast) { Param.AssertNotNull(proxy, "proxy"); Param.AssertNotNull(type, "type"); Param.AssertNotNull(castedExpression, "castedExpression"); this.type.Value = CodeParser.ExtractTypeTokenFromLiteralExpression(type); this.castedExpression.Value = castedExpression; }
/// <summary> /// Initializes a new instance of the AsExpression class. /// </summary> /// <param name="proxy">Proxy object for the expression.</param> /// <param name="value">The value to convert.</param> /// <param name="type">The type of the conversion.</param> internal AsExpression(CodeUnitProxy proxy, Expression value, LiteralExpression type) : base(proxy, ExpressionType.As) { Param.AssertNotNull(proxy, "proxy"); Param.AssertNotNull(value, "value"); Param.AssertNotNull(type, "type"); this.value.Value = value; this.type.Value = CodeParser.ExtractTypeTokenFromLiteralExpression(type); }
/// <summary> /// Initializes a new instance of the VariableDeclarationExpression class. /// </summary> /// <param name="proxy">Proxy object for the expression.</param> /// <param name="type">The type of the variable or variables being declared.</param> /// <param name="declarators">The collection of declarators on the expression.</param> internal VariableDeclarationExpression(CodeUnitProxy proxy, LiteralExpression type, ICollection <VariableDeclaratorExpression> declarators = null) : base(proxy, ExpressionType.VariableDeclaration) { Param.AssertNotNull(proxy, "proxy"); Param.AssertNotNull(type, "type"); Param.Ignore(declarators); this.type.Value = CodeParser.ExtractTypeTokenFromLiteralExpression(type); if (declarators != null && declarators.Count > 0) { this.declarators.Value = new List <VariableDeclaratorExpression>(declarators); } }
/// <summary> /// Initializes the contents of the expression. /// </summary> private void Initialize() { this.value.Value = this.FindFirstChildExpression(); if (this.value.Value == null) { throw new SyntaxException(this.Document, this.LineNumber); } AsToken @as = this.value.Value.FindNextSibling <AsToken>(); if (@as == null) { throw new SyntaxException(this.Document, this.LineNumber); } LiteralExpression literal = @as.FindNextSibling <LiteralExpression>(); if (literal == null) { throw new SyntaxException(this.Document, this.LineNumber); } this.type.Value = CodeParser.ExtractTypeTokenFromLiteralExpression(literal); }
/// <summary> /// Initializes the contents of the statement. /// </summary> private void Initialize() { CodeUnit start = this.FindFirstChild <OpenParenthesisToken>(); if (start == null) { throw new SyntaxException(this.Document, this.LineNumber); } Expression expression = start.FindNextSiblingExpression(); if (expression != null) { this.catchExpression.Value = expression; if (expression.ExpressionType == ExpressionType.Literal) { this.exceptionType.Value = CodeParser.ExtractTypeTokenFromLiteralExpression((LiteralExpression)expression); } else if (expression.ExpressionType == ExpressionType.VariableDeclaration) { VariableDeclarationExpression variableDeclaration = (VariableDeclarationExpression)expression; this.exceptionType.Value = variableDeclaration.Type; foreach (VariableDeclaratorExpression declarator in variableDeclaration.Declarators) { this.identifier.Value = declarator.Identifier.Text; break; } } start = expression; } CloseParenthesisToken closeParen = start.FindNextSibling <CloseParenthesisToken>(); if (closeParen == null) { throw new SyntaxException(this.Document, this.LineNumber); } this.body.Value = closeParen.FindNextSibling <BlockStatement>(); if (this.body.Value == null) { throw new SyntaxException(this.Document, this.LineNumber); } // Look for the try-statement that this catch-statement is attached to. this.tryStatement.Value = null; for (CodeUnit c = this.FindPreviousSibling(); c != null; c = c.FindNext()) { if (c.Is(StatementType.Try)) { this.tryStatement.Value = (TryStatement)c; } else if (!c.Is(StatementType.Catch) && (!c.Is(CodeUnitType.LexicalElement) || c.Is(LexicalElementType.Token))) { break; } } if (this.tryStatement.Value == null) { throw new SyntaxException(this.Document, this.LineNumber); } }