Browse Source

Fixed null reference exception when converting a constructor to python.

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

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

@ -747,7 +747,7 @@ namespace ICSharpCode.PythonBinding @@ -747,7 +747,7 @@ namespace ICSharpCode.PythonBinding
memberRefExpression.TargetObject.AcceptVisitor(this, data);
Append("." + memberRefExpression.MemberName);
} else if (identifierExpression != null) {
if (IsStatic(currentMethod)) {
if ((currentMethod != null) && IsStatic(currentMethod)) {
Append(GetTypeName(currentMethod) + ".");
} else {
Append("self.");

42
src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/MethodCallInConstructorTestFixture.cs

@ -0,0 +1,42 @@ @@ -0,0 +1,42 @@
// <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
{
/// <summary>
/// Was causing a null reference exception in the convertor's IsStatic method since the method
/// being passed as a parameter is null.
/// </summary>
[TestFixture]
public class MethodCallInConstructorTestFixture
{
string csharp = "class Foo\r\n" +
"{\r\n" +
" public Foo()\r\n" +
" {\r\n" +
" Init();\r\n" +
" }\r\n" +
"}";
[Test]
public void GeneratedPythonSourceCode()
{
NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp);
string python = converter.Convert(csharp);
string expectedPython = "class Foo(object):\r\n" +
"\tdef __init__(self):\r\n" +
"\t\tself.Init()";
Assert.AreEqual(expectedPython, python);
}
}
}

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

@ -126,6 +126,7 @@ @@ -126,6 +126,7 @@
<Compile Include="Converter\LocalVariableAssignedInConstructorTestFixture.cs" />
<Compile Include="Converter\LocalVariableDeclarationInIfStatementTestFixture.cs" />
<Compile Include="Converter\LocalVariableNotInitializedTestFixture.cs" />
<Compile Include="Converter\MethodCallInConstructorTestFixture.cs" />
<Compile Include="Converter\MethodParameterConversionTestFixture.cs" />
<Compile Include="Converter\MethodReturnValueConversionTestFixture.cs" />
<Compile Include="Converter\MethodWithBodyConversionTestFixture.cs" />

Loading…
Cancel
Save