Browse Source

Improved binary operator line break handling.

newNRvisualizers
mike 14 years ago
parent
commit
47c5b9fae1
  1. 30
      ICSharpCode.NRefactory.CSharp/Formatter/AstFormattingVisitor.cs

30
ICSharpCode.NRefactory.CSharp/Formatter/AstFormattingVisitor.cs

@ -222,7 +222,7 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
int endOffset = segment.EndOffset; int endOffset = segment.EndOffset;
for (int i = segment.Offset; i < endOffset; i++) { for (int i = segment.Offset; i < endOffset; i++) {
if (!IsSpacing(document.GetCharAt(i))) if (!IsSpacing (document.GetCharAt (i)))
return false; return false;
} }
return true; return true;
@ -1348,8 +1348,18 @@ namespace ICSharpCode.NRefactory.CSharp
break; break;
} }
ForceSpacesAround (binaryOperatorExpression.OperatorToken, forceSpaces); ForceSpacesAround (binaryOperatorExpression.OperatorToken, forceSpaces);
base.VisitBinaryOperatorExpression (binaryOperatorExpression); base.VisitBinaryOperatorExpression (binaryOperatorExpression);
// Handle line breaks in binary opeartor expression.
if (binaryOperatorExpression.Left.StartLocation.Line != binaryOperatorExpression.Right.StartLocation.Line) {
IndentLevel++;
if (binaryOperatorExpression.OperatorToken.StartLocation.Line == binaryOperatorExpression.Right.StartLocation.Line) {
FixStatementIndentation (binaryOperatorExpression.OperatorToken.StartLocation);
} else {
FixStatementIndentation (binaryOperatorExpression.Right.StartLocation);
}
IndentLevel--;
}
} }
public override void VisitConditionalExpression (ConditionalExpression conditionalExpression) public override void VisitConditionalExpression (ConditionalExpression conditionalExpression)
@ -1558,7 +1568,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (offset < endOffset) { if (offset < endOffset) {
AddChange (offset, endOffset - offset, null); AddChange (offset, endOffset - offset, null);
} }
} }
void PlaceOnNewLine (bool newLine, AstNode keywordNode) void PlaceOnNewLine (bool newLine, AstNode keywordNode)
{ {
@ -1631,18 +1641,18 @@ namespace ICSharpCode.NRefactory.CSharp
} }
} }
string GetIndentation(int lineNumber) string GetIndentation (int lineNumber)
{ {
IDocumentLine line = document.GetLineByNumber(lineNumber); IDocumentLine line = document.GetLineByNumber (lineNumber);
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder ();
int endOffset = line.EndOffset; int endOffset = line.EndOffset;
for (int i = line.Offset; i < endOffset; i++) { for (int i = line.Offset; i < endOffset; i++) {
char c = document.GetCharAt(i); char c = document.GetCharAt (i);
if (!IsSpacing(c)) if (!IsSpacing (c))
break; break;
b.Append(c); b.Append (c);
} }
return b.ToString(); return b.ToString ();
} }
} }
} }

Loading…
Cancel
Save