Browse Source

Fixed forum-18391 and forum-18392 (pretty printer bugs).

VBNetOutputVisitor: Don't output "ByVal" by default.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2660 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
b78656bd6f
  1. 23
      src/Libraries/NRefactory/Project/Src/OperatorPrecedence.cs
  2. 3
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs
  3. 13
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs
  4. 7
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetPrettyPrintOptions.cs
  5. 4
      src/Libraries/NRefactory/Test/NRefactoryTests.csproj
  6. 152
      src/Libraries/NRefactory/Test/Output/CSharp/VBNetToCSharpConverterTest.cs
  7. 5
      src/Libraries/NRefactory/Test/Output/SpecialOutputVisitorTest.cs
  8. 141
      src/Libraries/NRefactory/Test/Output/VBNet/CSharpToVBNetConverterTest.cs
  9. 1
      src/Libraries/NRefactory/Test/Output/VBNet/VBNetOutputTest.cs
  10. 2
      src/Main/Base/Project/Src/Project/AbstractProject.cs
  11. 7
      src/Main/Base/Project/Src/Project/MSBuildEngine.cs
  12. 20
      src/Main/Base/Test/CodeConverterTests.cs

23
src/Libraries/NRefactory/Project/Src/OperatorPrecedence.cs

@ -36,6 +36,22 @@ namespace ICSharpCode.NRefactory @@ -36,6 +36,22 @@ namespace ICSharpCode.NRefactory
new BinaryOperatorType[] { BinaryOperatorType.ExclusiveOr }
);
static readonly Dictionary<BinaryOperatorType, int> csharpDict = MakePrecedenceTable(
new BinaryOperatorType[] { BinaryOperatorType.Multiply, BinaryOperatorType.Divide, BinaryOperatorType.Modulus },
new BinaryOperatorType[] { BinaryOperatorType.Add, BinaryOperatorType.Subtract },
new BinaryOperatorType[] { BinaryOperatorType.ShiftLeft, BinaryOperatorType.ShiftRight },
new BinaryOperatorType[] {
BinaryOperatorType.LessThan, BinaryOperatorType.LessThanOrEqual,
BinaryOperatorType.GreaterThan, BinaryOperatorType.GreaterThanOrEqual,
},
new BinaryOperatorType[] { BinaryOperatorType.Equality, BinaryOperatorType.InEquality },
new BinaryOperatorType[] { BinaryOperatorType.BitwiseAnd },
new BinaryOperatorType[] { BinaryOperatorType.ExclusiveOr },
new BinaryOperatorType[] { BinaryOperatorType.BitwiseOr },
new BinaryOperatorType[] { BinaryOperatorType.LogicalAnd, BinaryOperatorType.LogicalOr },
new BinaryOperatorType[] { BinaryOperatorType.NullCoalescing }
);
// create a dictionary operator->precedence (higher value = higher precedence)
static Dictionary<BinaryOperatorType, int> MakePrecedenceTable(params BinaryOperatorType[][] input)
{
@ -55,6 +71,13 @@ namespace ICSharpCode.NRefactory @@ -55,6 +71,13 @@ namespace ICSharpCode.NRefactory
return p1.CompareTo(p2);
}
public static int ComparePrecedenceCSharp(BinaryOperatorType op1, BinaryOperatorType op2)
{
int p1 = GetOperatorPrecedence(vbDict, op1);
int p2 = GetOperatorPrecedence(vbDict, op2);
return p1.CompareTo(p2);
}
static int GetOperatorPrecedence(Dictionary<BinaryOperatorType, int> dict, BinaryOperatorType op)
{
int p;

3
src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs

@ -1159,7 +1159,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1159,7 +1159,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
}
foreach (Statement stmt in statements) {
TrackVisit(stmt, null);
TrackVisit(stmt, prettyPrintOptions.StatementBraceStyle);
}
if (statements.Count != 1) {
outputFormatter.PrintToken(Tokens.CloseCurlyBrace);
@ -1171,6 +1171,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1171,6 +1171,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public override object TrackedVisitElseIfSection(ElseIfSection elseIfSection, object data)
{
outputFormatter.Indent();
outputFormatter.PrintToken(Tokens.Else);
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.If);

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

@ -1441,6 +1441,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -1441,6 +1441,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public override object TrackedVisitElseIfSection(ElseIfSection elseIfSection, object data)
{
outputFormatter.Indent();
outputFormatter.PrintToken(Tokens.ElseIf);
outputFormatter.Space();
TrackedVisit(elseIfSection.Condition, data);
@ -2585,26 +2586,32 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -2585,26 +2586,32 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
switch (modifier) {
case ParameterModifiers.None:
case ParameterModifiers.In:
outputFormatter.PrintToken(Tokens.ByVal);
if (prettyPrintOptions.OutputByValModifier) {
outputFormatter.PrintToken(Tokens.ByVal);
outputFormatter.Space();
}
break;
case ParameterModifiers.Out:
Error("Out parameter converted to ByRef", position);
//Error("Out parameter converted to ByRef", position);
outputFormatter.PrintToken(Tokens.ByRef);
outputFormatter.Space();
break;
case ParameterModifiers.Params:
outputFormatter.PrintToken(Tokens.ParamArray);
outputFormatter.Space();
break;
case ParameterModifiers.Ref:
outputFormatter.PrintToken(Tokens.ByRef);
outputFormatter.Space();
break;
case ParameterModifiers.Optional:
outputFormatter.PrintToken(Tokens.Optional);
outputFormatter.Space();
break;
default:
Error(String.Format("Unsupported modifier : {0}", modifier), position);
break;
}
outputFormatter.Space();
}
void OutputModifier(Modifiers modifier)

7
src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetPrettyPrintOptions.cs

@ -14,8 +14,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -14,8 +14,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
/// </summary>
public class VBNetPrettyPrintOptions : AbstractPrettyPrintOptions
{
public VBNetPrettyPrintOptions()
{
}
/// <summary>
/// Gets/Sets if the optional "ByVal" modifier should be written.
/// </summary>
public bool OutputByValModifier { get; set; }
}
}

4
src/Libraries/NRefactory/Test/NRefactoryTests.csproj

@ -143,8 +143,8 @@ @@ -143,8 +143,8 @@
<Compile Include="Lexer\CSharp\CustomLexerTests.cs" />
<Compile Include="Parser\Expressions\DefaultValueExpressionTests.cs" />
<Compile Include="Output\VBNet\VBNetOutputTest.cs" />
<Compile Include="Output\VBNet\CSharpToVBConverterTest.cs" />
<Compile Include="Output\CSharp\VBToCSharpConverterTest.cs" />
<Compile Include="Output\VBNet\CSharpToVBNetConverterTest.cs" />
<Compile Include="Output\CSharp\VBNetToCSharpConverterTest.cs" />
<Compile Include="Output\SpecialOutputVisitorTest.cs" />
</ItemGroup>
<ItemGroup>

152
src/Libraries/NRefactory/Test/Output/CSharp/VBToCSharpConverterTest.cs → src/Libraries/NRefactory/Test/Output/CSharp/VBNetToCSharpConverterTest.cs

@ -17,7 +17,7 @@ using ICSharpCode.NRefactory.Visitors; @@ -17,7 +17,7 @@ using ICSharpCode.NRefactory.Visitors;
namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
[TestFixture]
public class VBToCSharpConverterTest
public class VBNetToCSharpConverterTest
{
public void TestProgram(string input, string expectedOutput)
{
@ -27,6 +27,8 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -27,6 +27,8 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
parser.CompilationUnit.AcceptVisitor(new VBNetConstructsConvertVisitor(), null);
parser.CompilationUnit.AcceptVisitor(new ToCSharpConvertVisitor(), null);
CSharpOutputVisitor outputVisitor = new CSharpOutputVisitor();
outputVisitor.Options.IndentationChar = ' ';
outputVisitor.Options.IndentSize = 2;
outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
Assert.AreEqual(expectedOutput, outputVisitor.Text);
@ -50,7 +52,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -50,7 +52,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
using (StringReader r = new StringReader(expectedOutput)) {
string line;
while ((line = r.ReadLine()) != null) {
b.Append("\t");
b.Append(" ");
b.AppendLine(line);
}
}
@ -63,16 +65,16 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -63,16 +65,16 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
StringBuilder b = new StringBuilder();
b.AppendLine("class tmp1");
b.AppendLine("{");
b.AppendLine("\tpublic void tmp2()");
b.AppendLine("\t{");
b.AppendLine(" public void tmp2()");
b.AppendLine(" {");
using (StringReader r = new StringReader(expectedOutput)) {
string line;
while ((line = r.ReadLine()) != null) {
b.Append("\t\t");
b.Append(" ");
b.AppendLine(line);
}
}
b.AppendLine("\t}");
b.AppendLine(" }");
b.AppendLine("}");
TestProgram("Class tmp1 \n Sub tmp2() \n" + input + "\n End Sub \n End Class", b.ToString());
}
@ -116,7 +118,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -116,7 +118,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
public void RaiseEvent()
{
TestStatement("RaiseEvent someEvent(Me, EventArgs.Empty)",
"if (someEvent != null) {\n\tsomeEvent(this, EventArgs.Empty);\n}");
"if (someEvent != null) {\n someEvent(this, EventArgs.Empty);\n}");
}
[Test]
@ -145,42 +147,42 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -145,42 +147,42 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
public void Property()
{
TestMember("ReadOnly Property A()\nGet\nReturn Nothing\nEnd Get\nEnd Property",
"public object A {\n\tget { return null; }\n}");
"public object A {\n get { return null; }\n}");
}
[Test]
public void ValueInPropertySetter()
{
TestMember("WriteOnly Property A()\nSet\nDim x As Object = Value\nEnd Set\nEnd Property",
"public object A {\n\tset {\n\t\tobject x = value;\n\t}\n}");
"public object A {\n set {\n object x = value;\n }\n}");
}
[Test]
public void ValueInPropertySetter2()
{
TestMember("WriteOnly Property A()\nSet(ByVal otherName)\nDim x As Object = otherName\nEnd Set\nEnd Property",
"public object A {\n\tset {\n\t\tobject x = value;\n\t}\n}");
"public object A {\n set {\n object x = value;\n }\n}");
}
[Test]
public void AbstractProperty1()
{
TestMember("Public MustOverride Property Salary() As Decimal",
"public abstract decimal Salary {\n\tget;\n\tset;\n}");
"public abstract decimal Salary {\n get;\n set;\n}");
}
[Test]
public void AbstractProperty2()
{
TestMember("Public ReadOnly MustOverride Property Salary() As Decimal",
"public abstract decimal Salary {\n\tget;\n}");
"public abstract decimal Salary {\n get;\n}");
}
[Test]
public void AbstractProperty3()
{
TestMember("Public WriteOnly MustOverride Property Salary() As Decimal",
"public abstract decimal Salary {\n\tset;\n}");
"public abstract decimal Salary {\n set;\n}");
}
[Test]
@ -243,9 +245,9 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -243,9 +245,9 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
[Test]
public void Constructor()
{
TestMember("Sub New()\n\tMyBase.New(1)\nEnd Sub",
TestMember("Sub New()\n MyBase.New(1)\nEnd Sub",
"public tmp1() : base(1)\n{\n}");
TestMember("Public Sub New()\n\tMe.New(1)\nEnd Sub",
TestMember("Public Sub New()\n Me.New(1)\nEnd Sub",
"public tmp1() : this(1)\n{\n}");
}
@ -260,16 +262,16 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -260,16 +262,16 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
public void Destructor()
{
TestMember("Protected Overrides Sub Finalize()\n" +
"\tTry\n" +
"\t\tDead()\n" +
"\tFinally\n" +
"\t\tMyBase.Finalize()\n" +
"\tEnd Try\n" +
" Try\n" +
" Dead()\n" +
" Finally\n" +
" MyBase.Finalize()\n" +
" End Try\n" +
"End Sub",
"~tmp1()\n" +
"{\n" +
"\tDead();\n" +
" Dead();\n" +
"}");
}
@ -370,8 +372,8 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -370,8 +372,8 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
TestStatement("Using r1 As New StreamReader(file1), r2 As New StreamReader(file2)\n" +
"End Using",
"using (StreamReader r1 = new StreamReader(file1)) {\n" +
"\tusing (StreamReader r2 = new StreamReader(file2)) {\n" +
"\t}\n" +
" using (StreamReader r2 = new StreamReader(file2)) {\n" +
" }\n" +
"}");
}
@ -387,20 +389,20 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -387,20 +389,20 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
i = 9
End Select",
"switch (i) {\n" +
"\tcase 0:\n" +
"\tcase 1:\n" +
"\tcase 2:\n" +
"\tcase 3:\n" +
"\tcase 4:\n" +
"\tcase 5:\n" +
"\t\ti = 10;\n" +
"\t\tbreak;\n" +
"\tcase 11:\n" +
"\t\ti = 0;\n" +
"\t\tbreak;\n" +
"\tdefault:\n" +
"\t\ti = 9;\n" +
"\t\tbreak;\n" +
" case 0:\n" +
" case 1:\n" +
" case 2:\n" +
" case 3:\n" +
" case 4:\n" +
" case 5:\n" +
" i = 10;\n" +
" break;\n" +
" case 11:\n" +
" i = 0;\n" +
" break;\n" +
" default:\n" +
" i = 9;\n" +
" break;\n" +
"}");
}
@ -412,7 +414,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -412,7 +414,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
"End Function",
"public int run(int i)\n" +
"{\n" +
"\treturn 0;\n" +
" return 0;\n" +
"}");
}
@ -424,7 +426,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -424,7 +426,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
"End Function",
"public int run(int i)\n" +
"{\n" +
"\treturn 0;\n" +
" return 0;\n" +
"}");
}
@ -438,11 +440,11 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -438,11 +440,11 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
"End Function",
"public int run(int i)\n" +
"{\n" +
"\tint " + VBNetConstructsConvertVisitor.FunctionReturnValueName + " = 0;\n" +
"\twhile (something) {\n" +
"\t\t" + VBNetConstructsConvertVisitor.FunctionReturnValueName + " += i;\n" +
"\t}\n" +
"\treturn " + VBNetConstructsConvertVisitor.FunctionReturnValueName + ";\n" +
" int " + VBNetConstructsConvertVisitor.FunctionReturnValueName + " = 0;\n" +
" while (something) {\n" +
" " + VBNetConstructsConvertVisitor.FunctionReturnValueName + " += i;\n" +
" }\n" +
" return " + VBNetConstructsConvertVisitor.FunctionReturnValueName + ";\n" +
"}");
}
@ -457,11 +459,11 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -457,11 +459,11 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
"End Function",
"public int run(int i)\n" +
"{\n" +
"\tint " + ReturnValueName + " = 0;\n" +
"\twhile (something) {\n" +
"\t\t" + ReturnValueName + " = " + ReturnValueName + " + run(i - 1);\n" +
"\t}\n" +
"\treturn " + ReturnValueName + ";\n" +
" int " + ReturnValueName + " = 0;\n" +
" while (something) {\n" +
" " + ReturnValueName + " = " + ReturnValueName + " + run(i - 1);\n" +
" }\n" +
" return " + ReturnValueName + ";\n" +
"}");
}
@ -475,11 +477,11 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -475,11 +477,11 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
"End Function",
"public CustomType run(int i)\n" +
"{\n" +
"\tCustomType " + VBNetConstructsConvertVisitor.FunctionReturnValueName + " = default(CustomType);\n" +
"\twhile (something) {\n" +
"\t\t" + VBNetConstructsConvertVisitor.FunctionReturnValueName + " = new CustomType();\n" +
"\t}\n" +
"\treturn " + VBNetConstructsConvertVisitor.FunctionReturnValueName + ";\n" +
" CustomType " + VBNetConstructsConvertVisitor.FunctionReturnValueName + " = default(CustomType);\n" +
" while (something) {\n" +
" " + VBNetConstructsConvertVisitor.FunctionReturnValueName + " = new CustomType();\n" +
" }\n" +
" return " + VBNetConstructsConvertVisitor.FunctionReturnValueName + ";\n" +
"}");
}
@ -512,7 +514,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -512,7 +514,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
End Sub",
@"private void Test()
{
static_Test_j += 1;
static_Test_j += 1;
}
static int static_Test_j = 0;");
}
@ -530,12 +532,12 @@ Private Sub Test2 @@ -530,12 +532,12 @@ Private Sub Test2
End Sub",
@"private void Test()
{
static_Test_j += 1;
static_Test_j += 1;
}
static int static_Test_j = 0;
private void Test2()
{
static_Test2_j += 2;
static_Test2_j += 2;
}
static int static_Test2_j = 0;");
}
@ -551,9 +553,9 @@ static int static_Test2_j = 0;"); @@ -551,9 +553,9 @@ static int static_Test2_j = 0;");
public void WithStatementTest()
{
TestStatement("With Ejes\n" +
"\t.AddLine(p1, p2)\n" +
" .AddLine(p1, p2)\n" +
"End With",
"{\n\tEjes.AddLine(p1, p2);\n}");
"{\n Ejes.AddLine(p1, p2);\n}");
}
[Test]
@ -566,7 +568,7 @@ static int static_Test2_j = 0;"); @@ -566,7 +568,7 @@ static int static_Test2_j = 0;");
" End With\n" +
"End With",
"{\n\t{\n\t\ttb1.Font.Italic = true;\n\t}\n}");
"{\n {\n tb1.Font.Italic = true;\n }\n}");
}
[Test]
@ -579,14 +581,14 @@ static int static_Test2_j = 0;"); @@ -579,14 +581,14 @@ static int static_Test2_j = 0;");
" End With\n" +
"End With",
"{\n\t{\n\t\ttb1.Something.Font.Italic = true;\n\t}\n}");
"{\n {\n tb1.Something.Font.Italic = true;\n }\n}");
}
[Test]
public void StructureWithImplicitPublicField()
{
TestMember("Public Structure Example \n Dim x As Object \n End Structure",
"public struct Example\n{\n\tpublic object x;\n}");
"public struct Example\n{\n public object x;\n}");
}
[Test]
@ -607,16 +609,16 @@ static int static_Test2_j = 0;"); @@ -607,16 +609,16 @@ static int static_Test2_j = 0;");
public void InterfaceVisibility()
{
TestMember("Public Interface ITest\n" +
"\tSub Test()\n" +
"\tProperty Name As String\n" +
" Sub Test()\n" +
" Property Name As String\n" +
"End Interface",
"public interface ITest\n" +
"{\n" +
"\tvoid Test();\n" +
"\tstring Name {\n" +
"\t\tget;\n" +
"\t\tset;\n" +
"\t}\n" +
" void Test();\n" +
" string Name {\n" +
" get;\n" +
" set;\n" +
" }\n" +
"}");
}
@ -648,6 +650,18 @@ static int static_Test2_j = 0;"); @@ -648,6 +650,18 @@ static int static_Test2_j = 0;");
TestStatement("If \"\" <> a Then Return", "if (!string.IsNullOrEmpty(a)) return; ");
}
[Test]
public void ElseIfConversion()
{
TestStatement("If a Then\nElse If b Then\nElse\nEnd If",
"if (a) {\n" +
"}\n" +
"else if (b) {\n" +
"}\n" +
"else {\n" +
"}");
}
[Test]
public void ArrayCreationUpperBound()
{

5
src/Libraries/NRefactory/Test/Output/SpecialOutputVisitorTest.cs

@ -63,7 +63,6 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -63,7 +63,6 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
List<ISpecial> specials = parser.Lexer.SpecialTracker.RetrieveSpecials();
PreprocessingDirective.CSharpToVB(specials);
outputVisitor.Options.IndentationChar = ' ';
outputVisitor.Options.TabSize = 2;
outputVisitor.Options.IndentSize = 2;
using (SpecialNodesInserter.Install(specials, outputVisitor)) {
outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
@ -180,7 +179,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -180,7 +179,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
public void CommentsInsideMethodVB()
{
TestProgramVB(@"Public Class Class1
Private Function test(ByVal l As Integer, ByVal lvw As Integer) As Boolean
Private Function test(l As Integer, lvw As Integer) As Boolean
' Begin
Dim i As Integer = 1
Return False
@ -212,7 +211,7 @@ End Class"); @@ -212,7 +211,7 @@ End Class");
"Class A\n" +
" ' comment\n" +
" <PreserveSig()> _\n" +
" Public Sub B(ByVal c As Integer)\n" +
" Public Sub B(c As Integer)\n" +
" End Sub\n" +
"End Class");
}

141
src/Libraries/NRefactory/Test/Output/VBNet/CSharpToVBConverterTest.cs → src/Libraries/NRefactory/Test/Output/VBNet/CSharpToVBNetConverterTest.cs

@ -17,7 +17,7 @@ using ICSharpCode.NRefactory.Visitors; @@ -17,7 +17,7 @@ using ICSharpCode.NRefactory.Visitors;
namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
[TestFixture]
public class CSharpToVBConverterTest
public class CSharpToVBNetConverterTest
{
public void TestProgram(string input, string expectedOutput)
{
@ -27,6 +27,9 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -27,6 +27,9 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
parser.CompilationUnit.AcceptVisitor(new CSharpConstructsConvertVisitor(), null);
parser.CompilationUnit.AcceptVisitor(new ToVBNetConvertVisitor(), null);
VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor();
outputVisitor.Options.IndentationChar = ' ';
outputVisitor.Options.IndentSize = 2;
outputVisitor.Options.OutputByValModifier = true;
outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
Assert.AreEqual(expectedOutput, outputVisitor.Text);
@ -39,7 +42,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -39,7 +42,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
using (StringReader r = new StringReader(expectedOutput)) {
string line;
while ((line = r.ReadLine()) != null) {
b.Append("\t");
b.Append(" ");
b.AppendLine(line);
}
}
@ -51,15 +54,15 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -51,15 +54,15 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
StringBuilder b = new StringBuilder();
b.AppendLine("Class tmp1");
b.AppendLine("\tPrivate Sub tmp2()");
b.AppendLine(" Private Sub tmp2()");
using (StringReader r = new StringReader(expectedOutput)) {
string line;
while ((line = r.ReadLine()) != null) {
b.Append("\t\t");
b.Append(" ");
b.AppendLine(line);
}
}
b.AppendLine("\tEnd Sub");
b.AppendLine(" End Sub");
b.AppendLine("End Class");
TestProgram("class tmp1 { void tmp2() {\n" + input + "\n}}", b.ToString());
}
@ -78,7 +81,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -78,7 +81,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
TestProgram("class test : IComparable { }",
"Class test\r\n" +
"\tImplements IComparable\r\n" +
" Implements IComparable\r\n" +
"End Class\r\n");
}
@ -87,7 +90,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -87,7 +90,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
TestProgram("class test : System.IComparable { }",
"Class test\r\n" +
"\tImplements System.IComparable\r\n" +
" Implements System.IComparable\r\n" +
"End Class\r\n");
}
@ -96,7 +99,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -96,7 +99,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
TestProgram("class test : InvalidDataException { }",
"Class test\r\n" +
"\tInherits InvalidDataException\r\n" +
" Inherits InvalidDataException\r\n" +
"End Class\r\n");
}
@ -105,7 +108,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -105,7 +108,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
TestProgram("class test : System.IO.InvalidDataException { }",
"Class test\r\n" +
"\tInherits System.IO.InvalidDataException\r\n" +
" Inherits System.IO.InvalidDataException\r\n" +
"End Class\r\n");
}
@ -115,8 +118,8 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -115,8 +118,8 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
TestStatement("for (i = 0; unknownCondition; i++) b[i] = s[i];",
"i = 0\n" +
"While unknownCondition\n" +
"\tb(i) = s(i)\n" +
"\ti += 1\n" +
" b(i) = s(i)\n" +
" i += 1\n" +
"End While");
}
@ -126,8 +129,8 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -126,8 +129,8 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
TestStatement("for (i = 0; unknownCondition; i++) { b[i] = s[i]; }",
"i = 0\n" +
"While unknownCondition\n" +
"\tb(i) = s(i)\n" +
"\ti += 1\n" +
" b(i) = s(i)\n" +
" i += 1\n" +
"End While");
}
@ -136,7 +139,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -136,7 +139,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
TestStatement("for (i = 0; i < end; i++) b[i] = s[i];",
"For i = 0 To [end] - 1\n" +
"\tb(i) = s(i)\n" +
" b(i) = s(i)\n" +
"Next");
}
[Test]
@ -144,7 +147,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -144,7 +147,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
TestStatement("for (i = 0; i < end; i++) { b[i] = s[i]; }",
"For i = 0 To [end] - 1\n" +
"\tb(i) = s(i)\n" +
" b(i) = s(i)\n" +
"Next");
}
@ -170,28 +173,38 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -170,28 +173,38 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
TestStatement("if (FullImage != null) DrawImage();",
"If FullImage IsNot Nothing Then\n" +
"\tDrawImage()\n" +
" DrawImage()\n" +
"End If");
// regression test:
TestStatement("if (FullImage != null) e.DrawImage();",
"If FullImage IsNot Nothing Then\n" +
"\te.DrawImage()\n" +
" e.DrawImage()\n" +
"End If");
// with braces:
TestStatement("if (FullImage != null) { DrawImage(); }",
"If FullImage IsNot Nothing Then\n" +
"\tDrawImage()\n" +
" DrawImage()\n" +
"End If");
TestStatement("if (FullImage != null) { e.DrawImage(); }",
"If FullImage IsNot Nothing Then\n" +
"\te.DrawImage()\n" +
" e.DrawImage()\n" +
"End If");
// another bug related to the IfStatement code:
TestStatement("if (Tiles != null) foreach (Tile t in Tiles) this.TileTray.Controls.Remove(t);",
"If Tiles IsNot Nothing Then\n" +
"\tFor Each t As Tile In Tiles\n" +
"\t\tMe.TileTray.Controls.Remove(t)\n" +
"\tNext\n" +
" For Each t As Tile In Tiles\n" +
" Me.TileTray.Controls.Remove(t)\n" +
" Next\n" +
"End If");
}
[Test]
public void ElseIfStatement()
{
TestStatement("if (a) {} else if (b) {} else {}",
"If a Then\n" +
"ElseIf b Then\n" +
"Else\n" +
"End If");
}
@ -200,7 +213,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -200,7 +213,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
TestMember("void A() { Converter<int, int> i = delegate(int argument) { return argument * 2; }; }",
"Private Sub A()\n" +
"\tDim i As Converter(Of Integer, Integer) = Function(ByVal argument As Integer) argument * 2\n" +
" Dim i As Converter(Of Integer, Integer) = Function(ByVal argument As Integer) argument * 2\n" +
"End Sub");
}
@ -241,9 +254,9 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -241,9 +254,9 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
public void Constructor()
{
TestMember("public tmp1() : base(1) { }",
"Public Sub New()\n\tMyBase.New(1)\nEnd Sub");
"Public Sub New()\n MyBase.New(1)\nEnd Sub");
TestMember("public tmp1() : this(1) { }",
"Public Sub New()\n\tMe.New(1)\nEnd Sub");
"Public Sub New()\n Me.New(1)\nEnd Sub");
}
[Test]
@ -258,11 +271,11 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -258,11 +271,11 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
TestMember("~tmp1() { Dead(); }",
"Protected Overrides Sub Finalize()\n" +
"\tTry\n" +
"\t\tDead()\n" +
"\tFinally\n" +
"\t\tMyBase.Finalize()\n" +
"\tEnd Try\n" +
" Try\n" +
" Dead()\n" +
" Finally\n" +
" MyBase.Finalize()\n" +
" End Try\n" +
"End Sub");
}
@ -271,9 +284,9 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -271,9 +284,9 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
TestMember("public CategoryInfo this[int index] { get { return List[index] as CategoryInfo; } }",
"Public Default ReadOnly Property Item(ByVal index As Integer) As CategoryInfo\n" +
"\tGet\n" +
"\t\tReturn TryCast(List(index), CategoryInfo)\n" +
"\tEnd Get\n" +
" Get\n" +
" Return TryCast(List(index), CategoryInfo)\n" +
" End Get\n" +
"End Property");
}
@ -288,21 +301,21 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -288,21 +301,21 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
"Private m_count As Integer\n" +
"Public ReadOnly Property Count() As Integer\n" +
"\tGet\n" +
"\t\tReturn m_count\n" +
"\tEnd Get\n" +
" Get\n" +
" Return m_count\n" +
" End Get\n" +
"End Property\n" +
"Private Sub Test1(ByVal count As Integer)\n" +
"\tcount = 3\n" +
" count = 3\n" +
"End Sub\n" +
"Private Sub Test2()\n" +
"\tDim count As Integer\n" +
"\tcount = 3\n" +
" Dim count As Integer\n" +
" count = 3\n" +
"End Sub\n" +
"Private Sub Test3()\n" +
"\tFor Each count As Integer In someList\n" +
"\t\tcount = 3\n" +
"\tNext\n" +
" For Each count As Integer In someList\n" +
" count = 3\n" +
" Next\n" +
"End Sub");
}
@ -325,7 +338,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -325,7 +338,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
TestStatement("while (cond) example();",
"While cond\n" +
"\texample()\n" +
" example()\n" +
"End While");
}
@ -340,7 +353,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -340,7 +353,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
TestStatement("while (test != null) { break; }",
"While test IsNot Nothing\n" +
"\tExit While\n" +
" Exit While\n" +
"End While");
}
@ -349,7 +362,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -349,7 +362,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
TestStatement("do { break; } while (test != null);",
"Do\n" +
"\tExit Do\n" +
" Exit Do\n" +
"Loop While test IsNot Nothing");
}
@ -358,7 +371,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -358,7 +371,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
{
TestMember("public struct A { int field; }",
"Public Structure A\n" +
"\tPrivate field As Integer\n" +
" Private field As Integer\n" +
"End Structure");
}
@ -385,8 +398,8 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -385,8 +398,8 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
" string Name { get; set; }\n" +
"}",
"Public Interface ITest\n" +
"\tSub Test()\n" +
"\tProperty Name() As String\n" +
" Sub Test()\n" +
" Property Name() As String\n" +
"End Interface");
}
@ -406,8 +419,8 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -406,8 +419,8 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
public void StaticClass()
{
TestProgram("public static class Test {}", @"Public NotInheritable Class Test
Private Sub New()
End Sub
Private Sub New()
End Sub
End Class
");
}
@ -429,8 +442,8 @@ End Class @@ -429,8 +442,8 @@ End Class
{
TestMember("void T(int v) { int V = v; M(V, v); }",
"Private Sub T(ByVal v__1 As Integer)\n" +
"\tDim V__2 As Integer = v__1\n" +
"\tM(V__2, v__1)\n" +
" Dim V__2 As Integer = v__1\n" +
" M(V__2, v__1)\n" +
"End Sub");
}
@ -488,16 +501,16 @@ End Class @@ -488,16 +501,16 @@ End Class
{
TestProgram(@"public class Convert { void Run(string s) { char c; if ((c = s[0]) == '\n') { c = ' '; } } }",
@"Public Class Convert
Private Sub Run(ByVal s As String)
Dim c As Char
If (InlineAssignHelper(c, s(0))) = Chr(10) Then
c = "" ""C
End If
End Sub
Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
target = value
Return value
End Function
Private Sub Run(ByVal s As String)
Dim c As Char
If (InlineAssignHelper(c, s(0))) = Chr(10) Then
c = "" ""C
End If
End Sub
Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
target = value
Return value
End Function
End Class
");
}
@ -507,10 +520,10 @@ End Class @@ -507,10 +520,10 @@ End Class
{
TestStatement("{ int a; } { string a; }",
"If True Then\n" +
"\tDim a As Integer\n" +
" Dim a As Integer\n" +
"End If\n" +
"If True Then\n" +
"\tDim a As String\n" +
" Dim a As String\n" +
"End If");
}
}

1
src/Libraries/NRefactory/Test/Output/VBNet/VBNetOutputTest.cs

@ -23,6 +23,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter @@ -23,6 +23,7 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
parser.Parse();
Assert.AreEqual("", parser.Errors.ErrorOutput);
VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor();
outputVisitor.Options.OutputByValModifier = true;
outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null);
Assert.AreEqual("", outputVisitor.Errors.ErrorOutput);
Assert.AreEqual(StripWhitespace(program), StripWhitespace(outputVisitor.Text));

2
src/Main/Base/Project/Src/Project/AbstractProject.cs

@ -114,7 +114,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -114,7 +114,7 @@ namespace ICSharpCode.SharpDevelop.Project
}
set {
WorkbenchSingleton.AssertMainThread();
Debug.Assert(Path.IsPathRooted(value));
Debug.Assert(FileUtility.IsUrl(value) || Path.IsPathRooted(value));
lock (SyncRoot) { // locking still required for Directory
fileName = value;

7
src/Main/Base/Project/Src/Project/MSBuildEngine.cs

@ -162,12 +162,13 @@ namespace ICSharpCode.SharpDevelop.Project @@ -162,12 +162,13 @@ namespace ICSharpCode.SharpDevelop.Project
{
try {
PrepareBuild();
if (MSBuildEngine.isRunning) {
StartWorkerBuild();
}
} catch (Exception ex) {
MessageService.ShowError(ex);
}
if (MSBuildEngine.isRunning) {
StartWorkerBuild();
}
}
void Finish()

20
src/Main/Base/Test/CodeConverterTests.cs

@ -216,7 +216,7 @@ namespace ICSharpCode.SharpDevelop.Tests @@ -216,7 +216,7 @@ namespace ICSharpCode.SharpDevelop.Tests
" Private Function M() As Object\n" +
" Return New MatchEvaluator(AddressOf X)\n" +
" End Function\n" +
" Private Function X(ByVal match As Match) As String\n" +
" Private Function X(match As Match) As String\n" +
" End Function\n" +
"End Class");
}
@ -234,10 +234,10 @@ namespace ICSharpCode.SharpDevelop.Tests @@ -234,10 +234,10 @@ namespace ICSharpCode.SharpDevelop.Tests
"Imports System\n" +
"Imports System.Text.RegularExpressions\n" +
"Class Test\n" +
" Private Sub M(ByVal regex As Regex, ByVal text As String)\n" +
" Private Sub M(regex As Regex, text As String)\n" +
" regex.Replace(text, AddressOf X)\n" +
" End Sub\n" +
" Private Function X(ByVal match As Match) As String\n" +
" Private Function X(match As Match) As String\n" +
" End Function\n" +
"End Class");
}
@ -600,9 +600,9 @@ namespace ICSharpCode.SharpDevelop.Tests @@ -600,9 +600,9 @@ namespace ICSharpCode.SharpDevelop.Tests
"Imports System\n" +
"Class Test\n" +
" Implements IServiceProvider\n" +
" Public Function GetService(ByVal a As IntPtr) As Object\n" +
" Public Function GetService(a As IntPtr) As Object\n" +
" End Function\n" +
" Public Function GetService(ByVal a As Type) As Object Implements IServiceProvider.GetService\n" +
" Public Function GetService(a As Type) As Object Implements IServiceProvider.GetService\n" +
" End Function\n" +
"End Class");
}
@ -683,19 +683,19 @@ namespace ICSharpCode.SharpDevelop.Tests @@ -683,19 +683,19 @@ namespace ICSharpCode.SharpDevelop.Tests
"}",
"Imports System\n" +
"Interface IObj\n" +
" Sub T(ByVal a As Object)\n" +
" Sub T(a As Object)\n" +
"End Interface\n" +
"Interface IStr\n" +
" Sub T(ByVal a As String)\n" +
" Sub T(a As String)\n" +
"End Interface\n" +
"Class Test\n" +
" Implements IObj\n" +
" Implements IStr\n" +
" Public Sub T(ByVal a As String) Implements IStr.T\n" +
" Public Sub T(a As String) Implements IStr.T\n" +
" End Sub\n" +
" Public Sub T(ByVal a As Integer)\n" +
" Public Sub T(a As Integer)\n" +
" End Sub\n" +
" Public Sub T(ByVal a As Object) Implements IObj.T\n" +
" Public Sub T(a As Object) Implements IObj.T\n" +
" End Sub\n" +
"End Class");
}

Loading…
Cancel
Save