Esempio n. 1
0
 public virtual void VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause)
 {
     if (ThrowException)
     {
         throw (Exception)CreateException(queryContinuationClause);
     }
 }
Esempio n. 2
0
 public virtual void VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause)
 {
     if (this.ThrowException)
     {
         throw (System.Exception) this.CreateException(queryContinuationClause);
     }
 }
        protected override CodeAction GetAction(RefactoringContext context, QueryExpression node)
        {
            AstNode currentNode = node;

            for (;;)
            {
                QueryContinuationClause continuationParent = currentNode.Parent as QueryContinuationClause;
                if (continuationParent != null)
                {
                    currentNode = continuationParent;
                    continue;
                }
                QueryExpression exprParent = currentNode.Parent as QueryExpression;
                if (exprParent != null)
                {
                    currentNode = exprParent;
                    continue;
                }

                break;
            }

            node = (QueryExpression)currentNode;

            return(new CodeAction(context.TranslateString("Convert LINQ query to fluent syntax"),
                                  script => ConvertQueryToFluent(context, script, node),
                                  node));
        }
Esempio n. 4
0
            private bool UsedIndependently(QueryContinuationClause node)
            {
                foreach (var astNode in AllAfter(src, node))
                {
                    if (astNode is QueryContinuationClause)
                    {
                        break;
                    }

                    var identifierExpression = astNode as IdentifierExpression;
                    if (identifierExpression == null)
                    {
                        continue;
                    }
                    if (identifierExpression.Identifier != node.Identifier)
                    {
                        continue;
                    }

                    // ignore this0 = this0 references
                    var namedExpression = identifierExpression.Parent as NamedExpression;
                    if (namedExpression != null && namedExpression.Name == node.Identifier)
                    {
                        continue;
                    }
                    if (identifierExpression.Parent is MemberReferenceExpression == false)
                    {
                        return(true);
                    }
                }
                return(false);
            }
Esempio n. 5
0
        public UnifiedElement VisitQueryContinuationClause(
            QueryContinuationClause query, object data)
        {
            var expr = query.PrecedingQuery.AcceptVisitor(this, data);

            throw new NotImplementedException("QueryContinuationClause");
        }
		void CombineQueries(AstNode node)
		{
			for (AstNode child = node.FirstChild; child != null; child = child.NextSibling) {
				CombineQueries(child);
			}
			QueryExpression query = node as QueryExpression;
			if (query != null) {
				QueryFromClause fromClause = (QueryFromClause)query.Clauses.First();
				QueryExpression innerQuery = fromClause.Expression as QueryExpression;
				if (innerQuery != null) {
					if (TryRemoveTransparentIdentifier(query, fromClause, innerQuery)) {
						RemoveTransparentIdentifierReferences(query);
					} else {
						QueryContinuationClause continuation = new QueryContinuationClause();
						continuation.PrecedingQuery = innerQuery.Detach();
						continuation.Identifier = fromClause.Identifier;
						fromClause.ReplaceWith(continuation);
					}
				} else {
					Match m = castPattern.Match(fromClause.Expression);
					if (m.Success) {
						fromClause.Type = m.Get<AstType>("targetType").Single().Detach();
						fromClause.Expression = m.Get<Expression>("inExpr").Single().Detach();
					}
				}
			}
		}
		public string CombineQuery(AstNode node, AstNode rootQuery = null)
		{
			if (rootQuery == null) {
				rootQuery = node;
			}

			QueryExpression query = node as QueryExpression;
			if (query != null) {
				string continuationIdentifier = null;

				foreach (var clause in query.Clauses) {
					var continuation = clause as QueryContinuationClause;
					if (continuation != null) {
						CombineQuery(continuation.PrecedingQuery);
					}

					var from = clause as QueryFromClause;
					if (from != null) {
						continuationIdentifier = CombineQuery(from.Expression, rootQuery);
					}
				}

				QueryFromClause fromClause = (QueryFromClause)query.Clauses.First();
				QueryExpression innerQuery = fromClause.Expression as QueryExpression;
				if (innerQuery != null) {
					continuationIdentifier = continuationIdentifier ?? ((QueryFromClause)innerQuery.Clauses.First()).Identifier;

					string transparentIdentifier;
					if (TryRemoveTransparentIdentifier(query, fromClause, innerQuery, continuationIdentifier, out transparentIdentifier)) {
						RemoveTransparentIdentifierReferences(rootQuery, transparentIdentifier);
					} else if (fromClause.Type.IsNull) {
						QueryContinuationClause continuation = new QueryContinuationClause();
						continuation.PrecedingQuery = innerQuery.Detach();
						continuation.Identifier = fromClause.Identifier;
						fromClause.ReplaceWith(continuation);
					}

					return transparentIdentifier;
				} else {
					Match m = castPattern.Match(fromClause.Expression);
					if (m.Success) {
						fromClause.Type = m.Get<AstType>("targetType").Single().Detach();
						fromClause.Expression = m.Get<Expression>("inExpr").Single().Detach();
					}
				}
			}

			return null;
		}
Esempio n. 8
0
            void CombineQueries(AstNode node)
            {
                for (AstNode child = node.FirstChild; child != null; child = child.NextSibling)
                {
                    CombineQueries(child);
                }
                QueryExpression query = node as QueryExpression;

                if (query != null)
                {
                    if (query.Clauses.First().GetType() != typeof(QueryFromClause))
                    {
                        return;
                    }

                    QueryFromClause fromClause = (QueryFromClause)query.Clauses.First();
                    QueryExpression innerQuery = fromClause.Expression as QueryExpression;
                    if (innerQuery != null)
                    {
                        if (TryRemoveTransparentIdentifier(query, fromClause, innerQuery))
                        {
                            RemoveTransparentIdentifierReferences(query);
                        }
                        else
                        {
                            QueryContinuationClause continuation = new QueryContinuationClause();
                            continuation.PrecedingQuery = Detach(innerQuery);
                            continuation.Identifier     = fromClause.Identifier;
                            fromClause.ReplaceWith(continuation);
                        }
                    }
                    else
                    {
                        Match m = castPattern.Match(fromClause.Expression);
                        if (m.Success)
                        {
                            fromClause.Type       = Detach(m.Get <AstType>("targetType").Single());
                            fromClause.Expression = Detach(m.Get <Expression>("inExpr").Single());
                        }
                    }
                }
            }
Esempio n. 9
0
        void CombineQueries(AstNode node, Dictionary <string, object> fromOrLetIdentifiers)
        {
            AstNode next;

            for (AstNode child = node.FirstChild; child != null; child = next)
            {
                // store reference to next child before transformation
                next = child.NextSibling;
                CombineQueries(child, fromOrLetIdentifiers);
            }
            QueryExpression query = node as QueryExpression;

            if (query != null)
            {
                QueryFromClause fromClause = (QueryFromClause)query.Clauses.First();
                QueryExpression innerQuery = fromClause.Expression as QueryExpression;
                if (innerQuery != null)
                {
                    if (TryRemoveTransparentIdentifier(query, fromClause, innerQuery, fromOrLetIdentifiers))
                    {
                        RemoveTransparentIdentifierReferences(query, fromOrLetIdentifiers);
                    }
                    else
                    {
                        QueryContinuationClause continuation = new QueryContinuationClause();
                        continuation.PrecedingQuery = innerQuery.Detach();
                        continuation.Identifier     = fromClause.Identifier;
                        continuation.CopyAnnotationsFrom(fromClause);
                        fromClause.ReplaceWith(continuation);
                    }
                }
                else
                {
                    Match m = castPattern.Match(fromClause.Expression);
                    if (m.Success)
                    {
                        fromClause.Type       = m.Get <AstType>("targetType").Single().Detach();
                        fromClause.Expression = m.Get <Expression>("inExpr").Single().Detach();
                    }
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Walks the children of the given query clause.
        /// </summary>
        /// <param name="clause">The clause.</param>
        /// <param name="parentClause">The parent clause, if any.</param>
        /// <param name="parentExpression">The parent expression, if any.</param>
        /// <param name="parentStatement">The parent statement, if any.</param>
        /// <param name="parentElement">The parent element, if any.</param>
        /// <param name="context">The optional visitor context data.</param>
        /// <returns>Returns true to continue, or false to stop the walker.</returns>
        private bool WalkQueryClause(
            QueryClause clause,
            QueryClause parentClause,
            Expression parentExpression,
            Statement parentStatement,
            CsElement parentElement,
            T context)
        {
            Param.Ignore(clause, parentClause, parentExpression, parentStatement, parentElement, context);

            if (clause != null)
            {
                T childContext = context;
                if (!this.VisitQueryClause(clause, parentClause, parentExpression, parentStatement, parentElement, ref childContext))
                {
                    return(false);
                }

                foreach (Expression childExpression in clause.ChildExpressions)
                {
                    if (!this.WalkExpression(childExpression, parentExpression, parentStatement, parentElement, childContext))
                    {
                        return(false);
                    }
                }

                if (clause.QueryClauseType == QueryClauseType.Continuation)
                {
                    QueryContinuationClause continuationClause = (QueryContinuationClause)clause;
                    foreach (QueryClause childClause in continuationClause.ChildClauses)
                    {
                        if (!this.WalkQueryClause(childClause, clause, parentExpression, parentStatement, parentElement, childContext))
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Esempio n. 11
0
        public override object VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause, object data)
        {
            var result = base.VisitQueryContinuationClause(queryContinuationClause, data);

            if (groupByIdentifier == null)
            {
                return(result);
            }

            var queryGroupClause = queryContinuationClause.PrecedingQuery.Clauses.LastOrNullObject() as QueryGroupClause;

            if (queryGroupClause == null)
            {
                return(result);
            }

            var queryExpression = queryContinuationClause.Parent as QueryExpression;

            if (queryExpression == null)
            {
                return(result);
            }

            bool foundIt = false;

            foreach (var queryClause in queryExpression.Clauses)
            {
                if (foundIt == false)
                {
                    foundIt = queryClause == queryContinuationClause;
                    continue;
                }
                foreach (var invocationExpression in queryClause.Descendants.OfType <InvocationExpression>())
                {
                    AssertInvocationExpression(invocationExpression, queryContinuationClause.Identifier);
                }
            }

            return(result);
        }
Esempio n. 12
0
 public override void VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause)
 {
     ProcessName(queryContinuationClause.Identifier);
     base.VisitQueryContinuationClause(queryContinuationClause);
 }
        /// <summary>
        /// Gets a query continuation clause.
        /// </summary>
        /// <param name="unsafeCode">Indicates whether the code being parsed resides 
        /// in an unsafe code block.</param>
        /// <returns>Returns the query continuation clause.</returns>
        private QueryContinuationClause GetQueryContinuationClause(bool unsafeCode)
        {
            Param.Ignore(unsafeCode);

            // Get and add the 'into' symbol.
            Symbol symbol = this.GetNextSymbol(SymbolType.Other);
            Debug.Assert(symbol.Text == "into", "Expected an into keyword");

            Node<CsToken> firstTokenNode = this.tokens.InsertLast(this.GetToken(CsTokenType.Into, SymbolType.Other));

            // Get the identifier.
            Variable rangeVariable = this.GetVariable(unsafeCode, true, true);
            if (rangeVariable == null)
            {
                throw this.CreateSyntaxException();
            }

            // Get the continuation clauses.
            List<QueryClause> clauses = new List<QueryClause>();

            // The variables defined by the clauses under this continuation clause.
            List<Variable> variables = new List<Variable>();

            // Extract the clauses.
            CsTokenList continuationClauseTokens = this.GetQueryExpressionClauses(unsafeCode, clauses, variables);
            if (clauses.Count == 0 || continuationClauseTokens.First == null)
            {
                throw this.CreateSyntaxException();
            }

            // Create and return the clause.
            QueryContinuationClause continuationClause = new QueryContinuationClause(
                new CsTokenList(this.tokens, firstTokenNode, continuationClauseTokens.Last),
                rangeVariable,
                clauses.ToArray());

            continuationClause.Variables.AddRange(variables);

            return continuationClause;
        }
Esempio n. 14
0
 public StringBuilder VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause, int data)
 {
     throw new SLSharpException("SL# does not understand LINQ.");
 }
 /// <inheritdoc/>
 public virtual void VisitQueryContinuationClause(QueryContinuationClause syntax)
 {
     VisitNode(syntax);
 }
 public StringBuilder VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause)
 {
     return(InvalidNode(queryContinuationClause, "LINQ is not supported"));
 }
Esempio n. 17
0
 public StringBuilder VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause, int data)
 {
     throw new ASLException("ASL does not understand LINQ.");
 }
 public virtual S VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause, T data)
 {
     return(VisitChildren(queryContinuationClause, data));
 }
 public override void VisitQueryContinuationClause(QueryContinuationClause syntax)
 {
     _underlyingVisitor.VisitQueryContinuationClause(syntax);
 }
Esempio n. 20
0
			public override void VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause)
			{
				ProcessName(queryContinuationClause.Identifier);
				base.VisitQueryContinuationClause(queryContinuationClause);
			}
 public Node VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause)
 {
     return(CreateDummy(queryContinuationClause));
 }
Esempio n. 22
0
 public void VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause)
 {
     throw new NotImplementedException();
 }
Esempio n. 23
0
        /// <summary>
        /// Analyzes the given query clauses.
        /// </summary>
        /// <param name="element">The element containing the clauses.</param>
        /// <param name="expression">The expression containing the clauses.</param>
        /// <param name="clauseParent">The direct parent of the collection of clauses to analyze.</param>
        /// <param name="previousClause">The previous clause in the expression, if any.</param>
        /// <param name="clauseOnSameLine">Indicates whether any clause has been seen previously which
        /// starts on the same line as the clause before it.</param>
        /// <param name="clauseOnSeparateLine">Indicates whether any clause has been seen previously which
        /// starts on the line after the clause before it.</param>
        /// <returns>Returns true to continue checking the query clause, or false to quit.</returns>
        private bool ProcessQueryClauses(
            Element element,
            QueryExpression expression,
            CodeUnit clauseParent,
            ref QueryClause previousClause,
            ref bool clauseOnSameLine,
            ref bool clauseOnSeparateLine)
        {
            Param.AssertNotNull(element, "element");
            Param.AssertNotNull(expression, "expression");
            Param.AssertNotNull(clauseParent, "clauseParent");
            Param.Ignore(previousClause);
            Param.Ignore(clauseOnSameLine);
            Param.Ignore(clauseOnSeparateLine);

            for (QueryClause clause = clauseParent.FindFirstChildQueryClause(); clause != null; clause = clause.FindNextSiblingQueryClause())
            {
                if (previousClause != null)
                {
                    // Figure out the line number that the previous clause ends on. For most
                    // clauses, this is simply the end point of the clause location property,
                    // but for continuation clauses we want to use the location of the 'into' variable,
                    // which conceptually represents the end of the continuation line.
                    int previousClauseEndLineNumber = previousClause.Location.EndPoint.LineNumber;

                    if (previousClause.QueryClauseType == QueryClauseType.Continuation)
                    {
                        previousClauseEndLineNumber = ((QueryContinuationClause)previousClause).Variable.Location.LineNumber;
                    }

                    // Ensure that the clause either starts on the same line as the expression, or
                    // on the very next line.
                    if (clause.LineNumber == previousClauseEndLineNumber)
                    {
                        // This is only ok if the previous clause does not span multiple lines.
                        if (previousClause.Location.LineSpan > 1)
                        {
                            this.AddViolation(element, clause.LineNumber, Rules.QueryClauseMustBeginOnNewLineWhenPreviousClauseSpansMultipleLines);
                            return(false);
                        }

                        // The rest of the checks are only applied when the clause is not a query continuation clause. A continuation
                        // clause is allowed to begin at the end of the previous clause, on the same line.
                        if (clause.QueryClauseType != QueryClauseType.Continuation)
                        {
                            // The clause starts on the same line as the ending of the previous clause.
                            // This is ok as long as we have not previously seen a clause which starts
                            // on its own line. The one exception is that query continuation clauses
                            // are allowed to be inserted at the end of the previous claus.
                            if (clauseOnSeparateLine)
                            {
                                this.AddViolation(element, clause.LineNumber, Rules.QueryClausesMustBeOnSeparateLinesOrAllOnOneLine);
                                return(false);
                            }

                            // If the clause spans multiple lines, it must begin on its own line. The exception is query continuation
                            // clauses, which are allowed to begin at the end of the previous claus.
                            if (clause.Location.LineSpan > 1)
                            {
                                this.AddViolation(element, clause.LineNumber, Rules.QueryClausesSpanningMultipleLinesMustBeginOnOwnLine);
                                return(false);
                            }

                            // Indicate that we have seen a clause which starts on the same line as the
                            // previous clause.
                            clauseOnSameLine = true;
                        }
                    }
                    else if (clause.LineNumber == previousClauseEndLineNumber + 1)
                    {
                        // The clause starts on the line just after the previous clause.
                        // This is fine unless we have previously seen two clauses on the same line.
                        if (clauseOnSameLine)
                        {
                            this.AddViolation(element, clause.LineNumber, Rules.QueryClausesMustBeOnSeparateLinesOrAllOnOneLine);
                            return(false);
                        }

                        // Indicate that we have seen a clause which begins on the line after
                        // the previous clause.
                        clauseOnSeparateLine = true;
                    }
                    else if (clause.LineNumber > previousClauseEndLineNumber + 1)
                    {
                        // The clause does not start on the line after the previous clause.
                        this.AddViolation(element, clause.LineNumber, Rules.QueryClauseMustFollowPreviousClause);
                        return(false);
                    }
                }

                previousClause = clause;

                if (clause.QueryClauseType == QueryClauseType.Continuation)
                {
                    QueryContinuationClause continuationClause = (QueryContinuationClause)clause;
                    if (!this.ProcessQueryClauses(
                            element,
                            expression,
                            continuationClause,
                            ref previousClause,
                            ref clauseOnSameLine,
                            ref clauseOnSeparateLine))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
		public override void VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause)
		{
			VisitChildren(queryContinuationClause);
		}
Esempio n. 25
0
		public virtual void VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause)
		{
			DebugExpression(queryContinuationClause);
			StartNode(queryContinuationClause);
			queryContinuationClause.PrecedingQuery.AcceptVisitor(this);
			Space();
			WriteKeyword(QueryContinuationClause.IntoKeywordRole);
			Space();
			WriteIdentifier(queryContinuationClause.IdentifierToken);
			EndNode(queryContinuationClause);
		}
Esempio n. 26
0
 public override void VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause)
 {
     queryContinuationClause.PrecedingQuery.AcceptVisitor(this);
 }
		public virtual void VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause)
		{
			VisitChildren (queryContinuationClause);
		}
 public virtual void VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause)
 {
     if (this.ThrowException)
     {
         throw (Exception)this.CreateException(queryContinuationClause);
     }
 }
Esempio n. 29
0
 public RedILNode VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause, State data)
 {
     throw new System.NotImplementedException();
 }
Esempio n. 30
0
 public void VisitQueryContinuationClause(QueryContinuationClause node)
 {
     NotSupported(node);
 }
Esempio n. 31
0
 public void VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause)
 {
     throw new NotImplementedException();
 }
 public override void VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause)
 {
     throw NotSupportedToConsistency();
 }
Esempio n. 33
0
        protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
        {
            QueryContinuationClause o = other as QueryContinuationClause;

            return(o != null && MatchString(this.Identifier, o.Identifier) && this.PrecedingQuery.DoMatch(o.PrecedingQuery, match));
        }
Esempio n. 34
0
			public override object Visit(Mono.CSharp.Linq.QueryStartClause queryExpression)
			{
				if (queryExpression.Expr == null) {
					var intoClause = new QueryContinuationClause();
					intoClause.AddChild(new CSharpTokenNode(Convert(queryExpression.Location), QueryContinuationClause.IntoKeywordRole), QueryContinuationClause.IntoKeywordRole);
					intoClause.AddChild(Identifier.Create(queryExpression.IntoVariable.Name, Convert(queryExpression.IntoVariable.Location)), Roles.Identifier);
					return intoClause;
				}
				
				var fromClause = new QueryFromClause();

				fromClause.AddChild(new CSharpTokenNode(Convert(queryExpression.Location), QueryFromClause.FromKeywordRole), QueryFromClause.FromKeywordRole);
				
				if (queryExpression.IdentifierType != null)
					fromClause.AddChild(ConvertToType(queryExpression.IdentifierType), Roles.Type);
				
				fromClause.AddChild(Identifier.Create(queryExpression.IntoVariable.Name, Convert(queryExpression.IntoVariable.Location)), Roles.Identifier);
				
				var location = LocationsBag.GetLocations(queryExpression);
				if (location != null)
					fromClause.AddChild(new CSharpTokenNode(Convert(location [0]), QueryFromClause.InKeywordRole), QueryFromClause.InKeywordRole);

				if (queryExpression.Expr != null)
					fromClause.AddChild((Expression)queryExpression.Expr.Accept(this), Roles.Expression);
				return fromClause;
			}
Esempio n. 35
0
 public JNode VisitQueryContinuationClause(QueryContinuationClause node)
 {
     throw new NotImplementedException();
 }
Esempio n. 36
0
		public void VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause)
		{
			StartNode(queryContinuationClause);
			queryContinuationClause.PrecedingQuery.AcceptVisitor(this);
			Space();
			WriteKeyword(QueryContinuationClause.IntoKeywordRole);
			Space();
			queryContinuationClause.IdentifierToken.AcceptVisitor(this);
			EndNode(queryContinuationClause);
		}
Esempio n. 37
0
 public virtual Node VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause)
 {
     throw new System.NotImplementedException();
 }