Siegfried Pammer 14 years ago
parent
commit
740332021f
  1. 30
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs
  2. 47
      src/AddIns/BackendBindings/VBNetBinding/Test/FormattingStrategy/EndSubTests.cs

30
src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs

@ -143,7 +143,7 @@ namespace ICSharpCode.VBNetBinding @@ -143,7 +143,7 @@ namespace ICSharpCode.VBNetBinding
InsertDocumentationComments(editor, lineNr, cursorOffset);
}
if (ch == '\n' && lineAboveText != null) {
if (ch == '\n' && lineAbove != null) {
if (LanguageUtils.IsInsideDocumentationComment(editor, lineAbove, lineAbove.EndOffset)) {
editor.Document.Insert(cursorOffset, "''' ");
return;
@ -410,7 +410,7 @@ namespace ICSharpCode.VBNetBinding @@ -410,7 +410,7 @@ namespace ICSharpCode.VBNetBinding
while ((currentToken = lexer.NextToken()).Kind != Tokens.EOF) {
if (prevToken == null)
prevToken = currentToken;
if (IsBlockStart(lexer, currentToken, prevToken)) {
if (IsBlockStart(lexer, currentToken, prevToken) && !IsAutomaticPropertyWithDefaultValue(lexer, currentToken, prevToken)) {
if ((tokens.Count > 0 && tokens.Peek().Kind != Tokens.Interface) || IsDeclaration(currentToken.Kind))
tokens.Push(currentToken);
}
@ -438,6 +438,30 @@ namespace ICSharpCode.VBNetBinding @@ -438,6 +438,30 @@ namespace ICSharpCode.VBNetBinding
return false;
}
static bool IsAutomaticPropertyWithDefaultValue(ILexer lexer, Token currentToken, Token prevToken)
{
if (currentToken.Kind != Tokens.Property)
return false;
lexer.StartPeek();
int parenthesesNesting = 0;
// look for parameter list, = or EOL
Token t;
while ((t = lexer.Peek()).Kind != Tokens.EOF) {
if (t.Kind == Tokens.OpenParenthesis)
parenthesesNesting++;
if (t.Kind == Tokens.CloseParenthesis)
parenthesesNesting--;
if (parenthesesNesting == 0 && t.Kind == Tokens.Assign)
return true;
if (t.Kind == Tokens.EOL)
return false;
}
return false;
}
static Token GetClosestMissing(List<Token> missingEnds, VBStatement statement, ITextEditor editor, int lineNr)
{
Token closest = null;
@ -612,7 +636,7 @@ namespace ICSharpCode.VBNetBinding @@ -612,7 +636,7 @@ namespace ICSharpCode.VBNetBinding
Indent(editor, indentation, new string(' ', endColumn - startColumn - 1));
}
if (!inInterface && !isMustOverride && !isDeclare && !isDelegate) {
if (!inInterface && !isMustOverride && !isDeclare && !isDelegate && !IsAutomaticPropertyWithDefaultValue(lexer, currentToken, prevToken)) {
Indent(editor, indentation);
if (currentToken.Kind == Tokens.Select)

47
src/AddIns/BackendBindings/VBNetBinding/Test/FormattingStrategy/EndSubTests.cs

@ -173,5 +173,52 @@ namespace ICSharpCode.VBNetBinding.Tests @@ -173,5 +173,52 @@ namespace ICSharpCode.VBNetBinding.Tests
RunTest(code, cursorOffset, expectedCode, expectedOffset, '\n');
}
[Test]
public void AutomaticPropertyWithInitializer()
{
string code = "Public Class Foo\r\n" +
"\tPublic Property Bar As Boolean = True\r\n" +
"\r\n" + // This extra new line is required. This is the new line just entered by the user.
"End Class";
string bar = "= True\r\n";
int cursorOffset = code.IndexOf(bar) + bar.Length;
string expectedCode = "Public Class Foo\r\n" +
"\tPublic Property Bar As Boolean = True\r\n" +
"\t\r\n" +
"End Class";
int expectedOffset = ("Public Class Foo\r\n" +
"\tPublic Property Bar As Boolean = True\r\n" +
"\t").Length;
RunTest(code, cursorOffset, expectedCode, expectedOffset, '\n');
}
[Test]
public void StandardProperty()
{
string code = "Public Class Foo\r\n" +
"\tPublic Property Bar As Boolean\r\n" +
"\r\n" + // This extra new line is required. This is the new line just entered by the user.
"End Class";
string bar = "As Boolean\r\n";
int cursorOffset = code.IndexOf(bar) + bar.Length;
string expectedCode = "Public Class Foo\r\n" +
"\tPublic Property Bar As Boolean\r\n" +
"\t\t\r\n" +
"\tEnd Property\r\n" +
"End Class";
int expectedOffset = ("Public Class Foo\r\n" +
"\tPublic Property Bar As Boolean\r\n" +
"\t\t").Length;
RunTest(code, cursorOffset, expectedCode, expectedOffset, '\n');
}
}
}

Loading…
Cancel
Save