Browse Source

Typeof expressions and for each loops using a method call now converted to Python.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4067 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 16 years ago
parent
commit
1751aa4bdc
  1. 19
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/NRefactoryToPythonConverter.cs
  2. 44
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ForeachConversionWithMethodCallTestFixture.cs
  3. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

19
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/NRefactoryToPythonConverter.cs

@ -1086,6 +1086,9 @@ namespace ICSharpCode.PythonBinding @@ -1086,6 +1086,9 @@ namespace ICSharpCode.PythonBinding
public object VisitTypeOfExpression(TypeOfExpression typeOfExpression, object data)
{
Append("clr.GetClrType(");
Append(typeOfExpression.TypeReference.Type);
Append(")");
return null;
}
@ -1361,19 +1364,26 @@ namespace ICSharpCode.PythonBinding @@ -1361,19 +1364,26 @@ namespace ICSharpCode.PythonBinding
/// </summary>
object CreateInitStatement(ForeachStatement foreachStatement)
{
Append("enumerator = " + GetForeachVariableName(foreachStatement) + ".GetEnumerator()");
Append("enumerator = ");
AppendForeachVariableName(foreachStatement);
Append(".GetEnumerator()");
return null;
}
/// <summary>
/// Gets the name of the variable that is used in the
/// foreach loop as the item being iterated.
/// foreach loop as the item being iterated and appends the code.
/// </summary>
string GetForeachVariableName(ForeachStatement foreachStatement)
void AppendForeachVariableName(ForeachStatement foreachStatement)
{
IdentifierExpression identifierExpression = foreachStatement.Expression as IdentifierExpression;
return identifierExpression.Identifier;
InvocationExpression invocationExpression = foreachStatement.Expression as InvocationExpression;
if (identifierExpression != null) {
Append(identifierExpression.Identifier);
} else if (invocationExpression != null) {
invocationExpression.AcceptVisitor(this, null);
}
}
/// <summary>
@ -1436,7 +1446,6 @@ namespace ICSharpCode.PythonBinding @@ -1436,7 +1446,6 @@ namespace ICSharpCode.PythonBinding
if (identifierExpression != null) {
Append(identifierExpression.Identifier);
} else if (objectCreateExpression != null) {
//if (objectCreateExpression.Parameters.Count > 0) {
CreateDelegateCreateExpression(objectCreateExpression.Parameters[0]);
}
return null;

44
src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ForeachConversionWithMethodCallTestFixture.cs

@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.NRefactory;
using ICSharpCode.PythonBinding;
using NUnit.Framework;
namespace PythonBinding.Tests.Converter
{
[TestFixture]
public class ForeachConversionWithMethodCallTestFixture
{
string csharp = "class Foo\r\n" +
"{\r\n" +
" public void PrintEnvironmentVariables()\r\n" +
" {\r\n" +
" foreach (Environment.SpecialFolder folder in Environment.SpecialFolder.GetValues(typeof(Environment.SpecialFolder)))\r\n" +
" {\r\n" +
" Console.WriteLine(\"{0}={1}\\n\", folder, Environment.GetFolderPath(folder));\r\n" +
" }\r\n" +
" }\r\n" +
"}";
[Test]
public void ConvertedPythonCode()
{
NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp);
converter.IndentString = " ";
string code = converter.Convert(csharp);
string expectedCode = "class Foo(object):\r\n" +
" def PrintEnvironmentVariables(self):\r\n" +
" enumerator = Environment.SpecialFolder.GetValues(clr.GetClrType(Environment.SpecialFolder)).GetEnumerator()\r\n" +
" while enumerator.MoveNext():\r\n" +
" folder = enumerator.Current\r\n" +
" Console.WriteLine(\"{0}={1}\\n\", folder, Environment.GetFolderPath(folder))";
Assert.AreEqual(expectedCode, code);
}
}
}

1
src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

@ -104,6 +104,7 @@ @@ -104,6 +104,7 @@
<Compile Include="Converter\ConverterSupportedLanguageTests.cs" />
<Compile Include="Converter\ConvertToPythonProjectCommandTestFixture.cs" />
<Compile Include="Converter\EventHandlerWithObjectCreationTestFixture.cs" />
<Compile Include="Converter\ForeachConversionWithMethodCallTestFixture.cs" />
<Compile Include="Converter\IntegerMethodParameterTestFixture.cs" />
<Compile Include="Converter\BaseClassReferenceTestFixture.cs" />
<Compile Include="Converter\BinaryOperatorConversionTests.cs" />

Loading…
Cancel
Save