public static PythonConstructorInfo GetConstructorInfo(TypeDeclaration type)
 {
     PythonConstructorInfo pythonConstructorInfo;
     List<FieldDeclaration> fieldDeclarations = new List<FieldDeclaration>();
     ConstructorDeclaration constructorDeclaration = null;
     foreach (INode child in type.Children)
     {
         ConstructorDeclaration constructorDeclaration1 = child as ConstructorDeclaration;
         FieldDeclaration fieldDeclaration = child as FieldDeclaration;
         if (constructorDeclaration1 != null)
         {
             constructorDeclaration = constructorDeclaration1;
         }
         else if (fieldDeclaration != null)
         {
             fieldDeclarations.Add(fieldDeclaration);
         }
     }
     if ((fieldDeclarations.Count > 0 ? false : constructorDeclaration == null))
     {
         pythonConstructorInfo = null;
     }
     else
     {
         pythonConstructorInfo = new PythonConstructorInfo(constructorDeclaration, fieldDeclarations);
     }
     return pythonConstructorInfo;
 }
Example #2
0
        public static PythonConstructorInfo GetConstructorInfo(TypeDeclaration type)
        {
            PythonConstructorInfo   pythonConstructorInfo;
            List <FieldDeclaration> fieldDeclarations      = new List <FieldDeclaration>();
            ConstructorDeclaration  constructorDeclaration = null;

            foreach (INode child in type.Children)
            {
                ConstructorDeclaration constructorDeclaration1 = child as ConstructorDeclaration;
                FieldDeclaration       fieldDeclaration        = child as FieldDeclaration;
                if (constructorDeclaration1 != null)
                {
                    constructorDeclaration = constructorDeclaration1;
                }
                else if (fieldDeclaration != null)
                {
                    fieldDeclarations.Add(fieldDeclaration);
                }
            }
            if ((fieldDeclarations.Count > 0 ? false : constructorDeclaration == null))
            {
                pythonConstructorInfo = null;
            }
            else
            {
                pythonConstructorInfo = new PythonConstructorInfo(constructorDeclaration, fieldDeclarations);
            }
            return(pythonConstructorInfo);
        }
 private void CreateConstructor(PythonConstructorInfo constructorInfo)
 {
     if (constructorInfo.Constructor == null)
     {
         this.AppendIndented("def __init__(self):");
     }
     else
     {
         this.AppendIndented("def __init__");
         this.AddParameters(constructorInfo.Constructor);
         this.methodParameters = constructorInfo.Constructor.Parameters;
     }
     this.AppendLine();
     this.IncreaseIndent();
     this.AppendDocstring(this.xmlDocComments);
     if (constructorInfo.Fields.Count > 0)
     {
         foreach (FieldDeclaration field in constructorInfo.Fields)
         {
             if (NRefactoryToPythonConverter.FieldHasInitialValue(field))
             {
                 this.CreateFieldInitialization(field);
             }
         }
     }
     if (!NRefactoryToPythonConverter.IsEmptyConstructor(constructorInfo.Constructor))
     {
         constructorInfo.Constructor.Body.AcceptVisitor(this, null);
         this.AppendLine();
     }
     else if (constructorInfo.Fields.Count != 0)
     {
         this.AppendLine();
     }
     else
     {
         this.AppendIndentedPassStatement();
     }
     this.DecreaseIndent();
 }
 public override object TrackedVisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
 {
     this.codeBuilder.AppendLineIfPreviousLineIsCode();
     this.AppendIndented(string.Concat("class ", typeDeclaration.Name));
     this.AppendBaseTypes(typeDeclaration.BaseTypes);
     this.AppendLine();
     this.IncreaseIndent();
     this.AppendDocstring(this.xmlDocComments);
     if (typeDeclaration.Children.Count <= 0)
     {
         this.AppendIndentedPassStatement();
     }
     else
     {
         this.constructorInfo = PythonConstructorInfo.GetConstructorInfo(typeDeclaration);
         if (this.constructorInfo != null)
         {
             if (this.constructorInfo.Constructor == null)
             {
                 this.CreateConstructor(this.constructorInfo);
             }
         }
         typeDeclaration.AcceptChildren(this, data);
     }
     this.DecreaseIndent();
     return null;
 }