Browse Source

fixed insertion of End-Statements in VBNetBinding

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3684 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 17 years ago
parent
commit
85a49fecab
  1. 27
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs
  2. 58
      src/AddIns/BackendBindings/VBNetBinding/Test/FormattingStrategy/InterfaceTests.cs
  3. 1
      src/AddIns/BackendBindings/VBNetBinding/Test/VBNetBinding.Tests.csproj

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

@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
@ -229,7 +230,7 @@ namespace VBNetBinding.FormattingStrategy @@ -229,7 +230,7 @@ namespace VBNetBinding.FormattingStrategy
for (int i = 0; i < statement.IndentPlus; i++) {
indentation += Tab.GetIndentationString(textArea.Document);
}
textArea.Document.Replace(curLine.Offset, curLine.Length, indentation + curLineText.Trim());
textArea.Caret.Column = indentation.Length;
return;
@ -347,6 +348,11 @@ namespace VBNetBinding.FormattingStrategy @@ -347,6 +348,11 @@ namespace VBNetBinding.FormattingStrategy
return !inString;
}
bool IsDeclaration(int type)
{
return (type == Tokens.Class) || (type == Tokens.Module);
}
bool IsEndStatementNeeded(TextArea textArea, ref VBStatement statement, int lineNr)
{
Stack<Token> tokens = new Stack<Token>();
@ -356,24 +362,24 @@ namespace VBNetBinding.FormattingStrategy @@ -356,24 +362,24 @@ namespace VBNetBinding.FormattingStrategy
Token currentToken = null;
Token prevToken = null;
while ((currentToken = lexer.NextToken()).kind != Tokens.EOF) {
if (prevToken == null)
prevToken = currentToken;
if (IsBlockStart(lexer, currentToken, prevToken)) {
tokens.Push(currentToken);
if ((tokens.Count > 0 && tokens.Peek().kind != Tokens.Interface) || IsDeclaration(currentToken.kind))
tokens.Push(currentToken);
}
if (IsBlockEnd(currentToken, prevToken)) {
while (tokens.Count > 0 && !IsMatchingEnd(tokens.Peek(), currentToken)) {
Token t = null;
missingEnds.Add(t = tokens.Pop());
missingEnds.Add(tokens.Pop());
}
if (tokens.Count != 0) {
if (IsMatchingEnd(tokens.Peek(), currentToken)) {
if (tokens.Count > 0) {
if (IsMatchingEnd(tokens.Peek(), currentToken))
tokens.Pop();
}
}
}
@ -394,15 +400,16 @@ namespace VBNetBinding.FormattingStrategy @@ -394,15 +400,16 @@ namespace VBNetBinding.FormattingStrategy
foreach (Token t in missingEnds) {
if (!IsSingleLine(t.line, textArea)) {
if (IsMatchingStatement(t, statement) && ((diff = lineNr - t.line + 1) > -1)) {
if (closest == null)
if (closest == null) {
closest = t;
else {
} else {
if (diff < lineNr - closest.line + 1)
closest = t;
}
}
}
}
return closest;
}

58
src/AddIns/BackendBindings/VBNetBinding/Test/FormattingStrategy/InterfaceTests.cs

@ -0,0 +1,58 @@ @@ -0,0 +1,58 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/>
// <version>$Revision: 3548 $</version>
// </file>
using System;
using NUnit.Framework;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.TextEditor;
using VBNetBinding;
using VBNetBinding.FormattingStrategy;
namespace VBNetBinding.Tests
{
/// <summary>
/// Tests the special case of an interface. for ex. no insertion of End-Tags etc.
/// </summary>
[TestFixture]
public class InterfaceTests
{
[TestFixtureSetUp]
public void SetUpFixture()
{
if (!PropertyService.Initialized) {
PropertyService.InitializeService(String.Empty, String.Empty, "VBNetBindingTests");
}
}
[Test]
public void InterfaceEndSub()
{
string code = "Public Interface Foo\r\n" +
"\tPublic Sub Bar\r\n" +
"\r\n" + // This extra new line is required. This is the new line just entered by the user.
"End Interface";
string bar = "Sub Bar";
int cursorOffset = code.IndexOf(bar) + bar.Length;
int line = 2;
string expectedCode = "Public Interface Foo\r\n" +
"\tPublic Sub Bar\r\n" +
"\t\t\r\n" +
"End Interface";
using (TextEditorControl editor = new TextEditorControl()) {
editor.Document.TextContent = code;
editor.ActiveTextAreaControl.Caret.Position = editor.Document.OffsetToPosition(cursorOffset);
VBFormattingStrategy formattingStrategy = new VBFormattingStrategy();
formattingStrategy.FormatLine(editor.ActiveTextAreaControl.TextArea, line, cursorOffset, '\n');
Assert.AreEqual(expectedCode, editor.Document.TextContent);
}
}
}
}

1
src/AddIns/BackendBindings/VBNetBinding/Test/VBNetBinding.Tests.csproj

@ -64,6 +64,7 @@ @@ -64,6 +64,7 @@
<Folder Include="FormattingStrategy" />
<Compile Include="FormattingStrategy\EndOperatorTests.cs" />
<Compile Include="FormattingStrategy\EndSubTests.cs" />
<Compile Include="FormattingStrategy\InterfaceTests.cs" />
<None Include="app.config" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />

Loading…
Cancel
Save