Browse Source

Fix missing array type when converting VB.NET multiple fields on a single line to Ruby.

4.0
Matt Ward 14 years ago
parent
commit
30d6618f14
  1. 20
      src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/NRefactoryToRubyConverter.cs
  2. 22
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Converter/MultipleFieldsOnSameLineTests.cs

20
src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/NRefactoryToRubyConverter.cs

@ -646,7 +646,6 @@ namespace ICSharpCode.RubyBinding @@ -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 @@ -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 @@ -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 @@ -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;
}
/// <summary>
/// Converts a post or pre increment expression to an assign statement.
/// This converts "i++" and "++i" to "i = i + 1" since python

22
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Converter/MultipleFieldsOnSameLineTests.cs

@ -89,5 +89,27 @@ namespace RubyBinding.Tests.Converter @@ -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);
}
}
}

Loading…
Cancel
Save