Browse Source

Class base types now converted to python.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@5340 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Matt Ward 16 years ago
parent
commit
341be44215
  1. 21
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/NRefactoryToPythonConverter.cs
  2. 36
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/BaseClassConversionTestFixture.cs
  3. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

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

@ -1129,7 +1129,9 @@ namespace ICSharpCode.PythonBinding @@ -1129,7 +1129,9 @@ namespace ICSharpCode.PythonBinding
public override object TrackedVisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
{
codeBuilder.AppendLineIfPreviousLineIsCode();
AppendIndentedLine("class " + typeDeclaration.Name + "(object):");
AppendIndented("class " + typeDeclaration.Name);
AppendBaseTypes(typeDeclaration.BaseTypes);
AppendLine();
IncreaseIndent();
AppendDocstring(xmlDocComments);
if (typeDeclaration.Children.Count > 0) {
@ -1985,5 +1987,22 @@ namespace ICSharpCode.PythonBinding @@ -1985,5 +1987,22 @@ namespace ICSharpCode.PythonBinding
Append(")");
AppendLine();
}
void AppendBaseTypes(List<TypeReference> baseTypes)
{
Append("(");
if (baseTypes.Count == 0) {
Append("object");
} else {
for (int i = 0; i < baseTypes.Count; ++i) {
TypeReference typeRef = baseTypes[i];
if (i > 0) {
Append(", ");
}
Append(GetTypeName(typeRef));
}
}
Append("):");
}
}
}

36
src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/BaseClassConversionTestFixture.cs

@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
// <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 BaseClassConversionTestFixture
{
string csharp =
"class Foo : Bar, IMyInterface\r\n" +
"{\r\n" +
"}";
[Test]
public void ConvertedPythonCode()
{
string expectedCode =
"class Foo(Bar, IMyInterface):\r\n" +
" pass";
NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp);
converter.IndentString = " ";
string code = converter.Convert(csharp);
Assert.AreEqual(expectedCode, code);
}
}
}

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

@ -100,6 +100,7 @@ @@ -100,6 +100,7 @@
<Compile Include="Converter\ArrayCastConversionTestFixture.cs" />
<Compile Include="Converter\ArrayConversionTestFixture.cs" />
<Compile Include="Converter\AssignmentOperatorConversionTestFixture.cs" />
<Compile Include="Converter\BaseClassConversionTestFixture.cs" />
<Compile Include="Converter\BitShiftConversionTestFixture.cs" />
<Compile Include="Converter\BooleanConversionTestFixture.cs" />
<Compile Include="Converter\BreakAndContinueConversionTestFixture.cs" />

Loading…
Cancel
Save