/// <summary> /// Visits a class. /// </summary> public override object TrackedVisitTypeDeclaration(TypeDeclaration typeDeclaration, object data) { currentTypeDeclaration = typeDeclaration; if (currentNamespaceDeclaration == null) { 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 = RubyConstructorInfo.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); } DecreaseIndent(); codeBuilder.TrimEnd(); AppendLine(); AppendIndentedLine("end"); return null; }
void CreateConstructor(RubyConstructorInfo constructorInfo) { if (constructorInfo.Constructor != null) { AppendIndented("def initialize"); AddParameters(constructorInfo.Constructor); methodParameters = constructorInfo.Constructor.Parameters; } else { AppendIndented("def initialize()"); } AppendLine(); // Add fields at start of constructor. IncreaseIndent(); // AppendDocstring(xmlDocComments); if (constructorInfo.Fields.Count > 0) { foreach (FieldDeclaration field in constructorInfo.Fields) { // Ignore field if it has no initializer. if (FieldHasInitialValue(field)) { CreateFieldInitialization(field); } } } if (!IsEmptyConstructor(constructorInfo.Constructor)) { constructorInfo.Constructor.Body.AcceptVisitor(this, null); } DecreaseIndent(); AppendIndentedLine("end"); AppendLine(); }