From 30d6618f14efb1d8f466162d0b765c6501feedeb Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Sat, 4 Jun 2011 10:30:04 +0100 Subject: [PATCH] Fix missing array type when converting VB.NET multiple fields on a single line to Ruby. --- .../Project/Src/NRefactoryToRubyConverter.cs | 20 +++++++++++++++-- .../MultipleFieldsOnSameLineTests.cs | 22 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/NRefactoryToRubyConverter.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/NRefactoryToRubyConverter.cs index d65cbcfa18..e06ee1b01a 100644 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/NRefactoryToRubyConverter.cs +++ b/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/NRefactoryToRubyConverter.cs @@ -646,7 +646,6 @@ namespace ICSharpCode.RubyBinding AppendLine(); IncreaseIndent(); -// AppendDocstring(xmlDocComments); if (methodDeclaration.Body.Children.Count > 0) { methodDeclaration.Body.AcceptVisitor(this, data); } @@ -871,7 +870,6 @@ namespace ICSharpCode.RubyBinding AppendBaseTypes(typeDeclaration.BaseTypes); AppendLine(); IncreaseIndent(); -// AppendDocstring(xmlDocComments); if (typeDeclaration.Children.Count > 0) { // Look for fields or a constructor for the type. constructorInfo = RubyConstructorInfo.GetConstructorInfo(typeDeclaration); @@ -1269,6 +1267,8 @@ namespace ICSharpCode.RubyBinding foreach (VariableDeclaration variable in field.Fields) { // Ignore field if it has no initializer. if (FieldHasInitialValue(variable)) { + AddTypeToArrayInitializerIfMissing(variable); + string oldVariableName = variable.Name; variable.Name = "@" + variable.Name; VisitVariableDeclaration(variable, null); @@ -1277,6 +1277,22 @@ namespace ICSharpCode.RubyBinding } } + void AddTypeToArrayInitializerIfMissing(VariableDeclaration variable) + { + ArrayCreateExpression arrayCreate = variable.Initializer as ArrayCreateExpression; + if (IsArrayMissingTypeToCreate(arrayCreate)) { + arrayCreate.CreateType = variable.TypeReference; + } + } + + bool IsArrayMissingTypeToCreate(ArrayCreateExpression arrayCreate) + { + if (arrayCreate != null) { + return String.IsNullOrEmpty(arrayCreate.CreateType.Type); + } + return false; + } + /// /// Converts a post or pre increment expression to an assign statement. /// This converts "i++" and "++i" to "i = i + 1" since python diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Converter/MultipleFieldsOnSameLineTests.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Converter/MultipleFieldsOnSameLineTests.cs index 8e652905bb..7709ba19c0 100644 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Converter/MultipleFieldsOnSameLineTests.cs +++ b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Converter/MultipleFieldsOnSameLineTests.cs @@ -89,5 +89,27 @@ namespace RubyBinding.Tests.Converter Assert.AreEqual(expectedRuby, ruby); } + + string vnetClassWithTwoArrayFieldsOnSameLine = + "class Foo\r\n" + + " Private i(10), j(20) as integer\r\n" + + "end class"; + + [Test] + public void ConvertVBNetClassWithTwoArrayFieldsOnSameLine() + { + NRefactoryToRubyConverter converter = new NRefactoryToRubyConverter(SupportedLanguage.VBNet); + converter.IndentString = " "; + string python = converter.Convert(vnetClassWithTwoArrayFieldsOnSameLine); + string expectedPython = + "class Foo\r\n" + + " def initialize()\r\n" + + " @i = Array.CreateInstance(System::Int32, 10)\r\n" + + " @j = Array.CreateInstance(System::Int32, 20)\r\n" + + " end\r\n" + + "end"; + + Assert.AreEqual(expectedPython, python); + } } }