Browse Source

Fixed SD2-1298: Converting single assignment and comparison statement from C# to VB.NET

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2642 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 18 years ago
parent
commit
50015a2b7b
  1. 6
      src/Libraries/NRefactory/NRefactory.sln
  2. 3
      src/Libraries/NRefactory/Project/NRefactory.csproj
  3. 39
      src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetConvertVisitor.cs
  4. 19
      src/Libraries/NRefactory/Test/Output/VBNet/CSharpToVBConverterTest.cs

6
src/Libraries/NRefactory/NRefactory.sln

@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 9.00 Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2005 # Visual Studio 2008
# SharpDevelop 2.1.0.2168 # SharpDevelop 3.0.0.2632
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactory", "Project\NRefactory.csproj", "{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactory", "Project\NRefactory.csproj", "{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactoryTests", "Test\NRefactoryTests.csproj", "{870115DD-960A-4406-A6B9-600BCDC36A03}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactoryTests", "Test\NRefactoryTests.csproj", "{870115DD-960A-4406-A6B9-600BCDC36A03}"

3
src/Libraries/NRefactory/Project/NRefactory.csproj

@ -1,4 +1,4 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -23,6 +23,7 @@
<FileAlignment>4096</FileAlignment> <FileAlignment>4096</FileAlignment>
<RunCodeAnalysis>False</RunCodeAnalysis> <RunCodeAnalysis>False</RunCodeAnalysis>
<CodeAnalysisRules>-Microsoft.Design#CA1002;-Microsoft.Design#CA1020;-Microsoft.Design#CA1051;-Microsoft.Design#CA1062;-Microsoft.Globalization#CA1303;-Microsoft.Globalization#CA1305;-Microsoft.Naming#CA1704;-Microsoft.Performance#CA1800;-Microsoft.Performance#CA1805;-Microsoft.Usage#CA2211;-Microsoft.Usage#CA2227</CodeAnalysisRules> <CodeAnalysisRules>-Microsoft.Design#CA1002;-Microsoft.Design#CA1020;-Microsoft.Design#CA1051;-Microsoft.Design#CA1062;-Microsoft.Globalization#CA1303;-Microsoft.Globalization#CA1305;-Microsoft.Naming#CA1704;-Microsoft.Performance#CA1800;-Microsoft.Performance#CA1805;-Microsoft.Usage#CA2211;-Microsoft.Usage#CA2227</CodeAnalysisRules>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<Optimize>False</Optimize> <Optimize>False</Optimize>

39
src/Libraries/NRefactory/Project/Src/Visitors/ToVBNetConvertVisitor.cs

@ -189,7 +189,44 @@ namespace ICSharpCode.NRefactory.Visitors
} }
} }
} }
return base.VisitAssignmentExpression(assignmentExpression, data); base.VisitAssignmentExpression(assignmentExpression, data);
if (assignmentExpression.Op == AssignmentOperatorType.Assign && !(assignmentExpression.Parent is ExpressionStatement)) {
AddInlineAssignHelper();
ReplaceCurrentNode(
new InvocationExpression(
new IdentifierExpression("InlineAssignHelper"),
new List<Expression> { assignmentExpression.Left, assignmentExpression.Right }
));
}
return null;
}
void AddInlineAssignHelper()
{
MethodDeclaration method;
foreach (INode node in currentType.Children) {
method = node as MethodDeclaration;
if (method != null && method.Name == "InlineAssignHelper") {
// inline assign helper already exists
return;
}
}
method = new MethodDeclaration(
"InlineAssignHelper", Modifiers.Private | Modifiers.Static,
new TypeReference("T"),
new List<ParameterDeclarationExpression> {
new ParameterDeclarationExpression(new TypeReference("T"), "target", ParameterModifiers.Ref),
new ParameterDeclarationExpression(new TypeReference("T"), "value")
}, null);
method.Templates.Add(new TemplateDefinition("T", null));
method.Body = new BlockStatement();
method.Body.AddChild(new ExpressionStatement(new AssignmentExpression(
new IdentifierExpression("target"),
AssignmentOperatorType.Assign,
new IdentifierExpression("value"))));
method.Body.AddChild(new ReturnStatement(new IdentifierExpression("value")));
currentType.AddChild(method);
} }
bool IsClassType(ClassType c) bool IsClassType(ClassType c)

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

@ -479,5 +479,24 @@ End Class
TestStatement("string[,] i = new string[6, 6];", TestStatement("string[,] i = new string[6, 6];",
"Dim i As String(,) = New String(5, 5) {}"); "Dim i As String(,) = New String(5, 5) {}");
} }
[Test]
public void InlineAssignment()
{
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
End Class
");
}
} }
} }

Loading…
Cancel
Save