Browse Source

Fixed SD2-997: C# comments re-ubication may result in a code error when converting code from C# to VB.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1739 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
e4ede6d7b4
  1. 8
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/AbstractOutputFormatter.cs
  2. 11
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputFormatter.cs
  3. 11
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs
  4. 27
      src/Libraries/NRefactory/Test/Output/SpecialOutputVisitor.cs
  5. 10
      src/Libraries/NRefactory/Test/Output/VBNet/CSharpToVBConverterTest.cs

8
src/Libraries/NRefactory/Project/Src/PrettyPrinter/AbstractOutputFormatter.cs

@ -21,9 +21,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -21,9 +21,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
/// </summary>
public abstract class AbstractOutputFormatter : IOutputFormatter
{
int indentationLevel = 0;
StringBuilder text = new StringBuilder();
internal StringBuilder text = new StringBuilder();
int indentationLevel = 0;
bool indent = true;
bool doNewLine = true;
AbstractPrettyPrintOptions prettyPrintOptions;
@ -91,8 +91,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -91,8 +91,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
text.Append(' ');
}
int lastLineStart = 0;
int lineBeforeLastStart = 0;
internal int lastLineStart = 0;
internal int lineBeforeLastStart = 0;
public bool LastCharacterIsNewLine {
get {

11
src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputFormatter.cs

@ -1,13 +1,13 @@ @@ -1,13 +1,13 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using ICSharpCode.NRefactory.Parser;
@ -56,5 +56,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -56,5 +56,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
break;
}
}
public void PrintLineContinuation()
{
if (!LastCharacterIsWhiteSpace)
Space();
PrintText("_\r\n");
}
}
}

11
src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs

@ -206,13 +206,15 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -206,13 +206,15 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
Debug.Assert(attributeSection.Attributes != null);
AppendCommaSeparatedList(attributeSection.Attributes);
outputFormatter.PrintText(">");
if ("assembly".Equals(attributeSection.AttributeTarget, StringComparison.InvariantCultureIgnoreCase)
|| "module".Equals(attributeSection.AttributeTarget, StringComparison.InvariantCultureIgnoreCase)) {
outputFormatter.PrintText(">");
outputFormatter.NewLine();
} else {
outputFormatter.PrintText("> _");
outputFormatter.PrintLineContinuation();
}
outputFormatter.NewLine();
return null;
}
@ -2676,8 +2678,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2676,8 +2678,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.Comma);
outputFormatter.Space();
if ((i + 1) % 6 == 0) {
outputFormatter.PrintText("_ ");
outputFormatter.NewLine();
outputFormatter.PrintLineContinuation();
outputFormatter.Indent();
outputFormatter.PrintText("\t");
}

27
src/Libraries/NRefactory/Test/Output/SpecialOutputVisitor.cs

@ -47,6 +47,21 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -47,6 +47,21 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
parser.Dispose();
}
void TestProgramCS2VB(string programCS, string programVB)
{
IParser parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(programCS));
parser.Parse();
Assert.AreEqual("", parser.Errors.ErrorOutput);
VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor();
using (SpecialNodesInserter.Install(parser.Lexer.SpecialTracker.RetrieveSpecials(),
outputVisitor)) {
outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
}
Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
Assert.AreEqual(programVB.Replace("\r", ""), outputVisitor.Text.TrimEnd().Replace("\r", ""));
parser.Dispose();
}
[Test]
public void BlankLine()
{
@ -178,5 +193,17 @@ End Class"); @@ -178,5 +193,17 @@ End Class");
"\n" +
"Imports System.IO");
}
[Test]
public void CommentAfterAttribute()
{
TestProgramCS2VB("class A { [PreserveSig] public void B(// comment\nint c) {} }",
"Class A\n" +
"\t\t' comment\n" +
"\t<PreserveSig()> _\n" +
"\tPublic Sub B(ByVal c As Integer)\n" +
"\tEnd Sub\n" +
"End Class");
}
}
}

10
src/Libraries/NRefactory/Test/Output/VBNet/CSharpToVBConverterTest.cs

@ -212,16 +212,16 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -212,16 +212,16 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
"End Sub");
}
[Test]
[Test, Ignore]
public void AnonymousMethodInVarDeclaration()
{
TestMember("void A() { SomeDelegate i = delegate(int argument) { return argument * 2; }; }",
TestMember("void A() { Converter<int, int> i = delegate(int argument) { return argument * 2; }; }",
"Private Sub A()\n" +
"\tDim i As SomeDelegate = AddressOf ConvertedAnonymousMethod1\n" +
"\tDim i As Converter(Of Integer, Integer) = AddressOf ConvertedAnonymousMethod1\n" +
"End Sub\n" +
"Private Sub ConvertedAnonymousMethod1(ByVal argument As Integer)\n" +
"Private Function ConvertedAnonymousMethod1(ByVal argument As Integer) As Integer\n" +
"\tReturn argument * 2\n" +
"End Sub");
"End Function");
}
[Test]

Loading…
Cancel
Save