Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.ExtLibs/HeuristicLab.NRefactory/5.5.0/NRefactory.CSharp-5.5.0/Formatter/FormattingVisitor_Query.cs @ 13400

Last change on this file since 13400 was 11700, checked in by jkarder, 9 years ago

#2077: created branch and added first version

File size: 4.0 KB
Line 
1//
2// AstFormattingVisitor_Query.cs
3//
4// Author:
5//       Luís Reis <luiscubal@gmail.com>
6//
7// Copyright (c) 2013 Luís Reis
8//
9// Permission is hereby granted, free of charge, to any person obtaining a copy
10// of this software and associated documentation files (the "Software"), to deal
11// in the Software without restriction, including without limitation the rights
12// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13// copies of the Software, and to permit persons to whom the Software is
14// furnished to do so, subject to the following conditions:
15//
16// The above copyright notice and this permission notice shall be included in
17// all copies or substantial portions of the Software.
18//
19// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25// THE SOFTWARE.
26using System;
27using System.Linq;
28
29namespace ICSharpCode.NRefactory.CSharp
30{
31  partial class FormattingVisitor
32  {
33    int GetUpdatedStartLocation(QueryExpression queryExpression)
34    {
35      //TODO
36      return queryExpression.StartLocation.Column;
37    }
38
39    public override void VisitQueryExpression(QueryExpression queryExpression)
40    {
41      var oldIndent = curIndent.Clone();
42
43      var column = GetUpdatedStartLocation(queryExpression);
44
45      int extraSpaces = column - 1 - (curIndent.CurIndent / options.TabSize);
46      if (extraSpaces < 0) {
47        //This check should probably be removed in the future, when GetUpdatedStartLocation is implemented
48        extraSpaces = 0;
49      }
50
51      curIndent.ExtraSpaces = extraSpaces;
52      VisitChildren(queryExpression);
53
54      curIndent = oldIndent;
55    }
56
57    public override void VisitQueryFromClause(QueryFromClause queryFromClause)
58    {
59      FixClauseIndentation(queryFromClause, queryFromClause.FromKeyword);
60    }
61
62    public override void VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause)
63    {
64      VisitChildren(queryContinuationClause);
65    }
66
67    public override void VisitQueryGroupClause(QueryGroupClause queryGroupClause)
68    {
69      FixClauseIndentation(queryGroupClause, queryGroupClause.GroupKeyword);
70    }
71
72    public override void VisitQueryJoinClause(QueryJoinClause queryJoinClause)
73    {
74      FixClauseIndentation(queryJoinClause, queryJoinClause.JoinKeyword);
75    }
76
77    public override void VisitQueryLetClause(QueryLetClause queryLetClause)
78    {
79      FixClauseIndentation(queryLetClause, queryLetClause.LetKeyword);
80    }
81
82    public override void VisitQuerySelectClause(QuerySelectClause querySelectClause)
83    {
84      FixClauseIndentation(querySelectClause, querySelectClause.SelectKeyword);
85    }
86
87    public override void VisitQueryOrderClause(QueryOrderClause queryOrderClause)
88    {
89      FixClauseIndentation(queryOrderClause, queryOrderClause.OrderbyToken);
90    }
91
92    public override void VisitQueryWhereClause(QueryWhereClause queryWhereClause)
93    {
94      FixClauseIndentation(queryWhereClause, queryWhereClause.WhereKeyword);
95    }
96
97    void FixClauseIndentation(QueryClause clause, AstNode keyword) {
98      var parentExpression = clause.GetParent<QueryExpression>();
99      bool isFirstClause = parentExpression.Clauses.First() == clause;
100      if (!isFirstClause) {
101        PlaceOnNewLine(policy.NewLineBeforeNewQueryClause, keyword);
102      }
103
104      int extraSpaces = options.IndentSize;
105      curIndent.ExtraSpaces += extraSpaces;
106      foreach (var child in clause.Children) {
107        var expression = child as Expression;
108        if (expression != null) {
109          FixIndentation(child);
110          child.AcceptVisitor(this);
111        }
112
113        var tokenNode = child as CSharpTokenNode;
114        if (tokenNode != null) {
115          if (tokenNode.GetNextSibling(NoWhitespacePredicate).StartLocation.Line != tokenNode.EndLocation.Line) {
116            ForceSpacesAfter(tokenNode, false);
117          }
118        }
119      }
120      curIndent.ExtraSpaces -= extraSpaces;
121    }
122  }
123}
124
Note: See TracBrowser for help on using the repository browser.