void CreateConstructor(PythonConstructorInfo constructorInfo) { if (constructorInfo.Constructor != null) { AppendIndented("def __init__"); AddParameters(constructorInfo.Constructor); methodParameters = constructorInfo.Constructor.Parameters; } else { AppendIndented("def __init__(self):"); } AppendLine(); // Add fields at start of constructor. IncreaseIndent(); AppendDocstring(xmlDocComments); if (constructorInfo.Fields.Count > 0) { foreach (FieldDeclaration field in constructorInfo.Fields) { CreateFieldInitialization(field); } } if (!IsEmptyConstructor(constructorInfo.Constructor)) { constructorInfo.Constructor.Body.AcceptVisitor(this, null); AppendLine(); } else if (constructorInfo.Fields.Count == 0) { AppendIndentedPassStatement(); } else { AppendLine(); } DecreaseIndent(); }
/// <summary> /// Visits a class. /// </summary> public override object TrackedVisitTypeDeclaration(TypeDeclaration typeDeclaration, object data) { codeBuilder.AppendLineIfPreviousLineIsCode(); AppendIndented("class " + typeDeclaration.Name); AppendBaseTypes(typeDeclaration.BaseTypes); AppendLine(); IncreaseIndent(); AppendDocstring(xmlDocComments); if (typeDeclaration.Children.Count > 0) { // Look for fields or a constructor for the type. constructorInfo = PythonConstructorInfo.GetConstructorInfo(typeDeclaration); if (constructorInfo != null) { if (constructorInfo.Constructor != null) { // Generate constructor later when VisitConstructorDeclaration method is called. // This allows the constructor comments to be converted in the right place. } else { CreateConstructor(constructorInfo); } } // Visit the rest of the class. typeDeclaration.AcceptChildren(this, data); } else { AppendIndentedPassStatement(); } DecreaseIndent(); return null; }