public static void ParseEvent(string member, ref ExtClass ec) { /** * @event arrowclick * Fires when this button's arrow is clicked * @param {SplitButton} this * @param {EventObject} e The click event */ ExtEvent ev = new ExtEvent(); ev.Description = new ExtDescription(); ev.Parameters = new ExtParameterCollection(); string[] data = member.Split(SourceConverter.CRLFA, StringSplitOptions.RemoveEmptyEntries); foreach (string line in data) { if (line.StartsWith("*/")) break; if (line.StartsWith("/**")) continue; if (line.StartsWith("@event")) { ev.Name = line.Substring("@event ".Length).Trim(); } else if (line.StartsWith("@param")) { ev.Parameters.Add(ExtParameter.ParseParameter(line)); } else if (line.StartsWith("@hide")) { return; } else { ev.Description.Value += line + SourceConverter.CRLF; } } ev.Description.Value = ev.Description.Value.Trim(SourceConverter.CRLFA); ec.Events.Add(ev); }
public ExtConstructor Dupe(ExtClass ec) { ExtConstructor ctor = new ExtConstructor(); ctor.Name = ec.Name; ctor.Class = ec; ctor.Description = Description; ctor.Parameters = new ExtParameterCollection(); for (int j = 0; j < Parameters.Count; j++) { ctor.Parameters.Add(Parameters[j].Dupe()); } return ctor; }
/// <summary> /// Creates an empty class. This is needed for compilation /// </summary> /// <param name="types">An array of strings specifying the classes to create. Each string should bee the fully qulified class name (incl. Namespace)</param> public ExtClassCollection CreateCustomClasses(params string[] types) { ExtClassCollection classes = new ExtClassCollection(); foreach (string t in types) { if (String.IsNullOrEmpty(t)) continue; ExtClass ec = new ExtClass(); ec.Description = new ExtDescription(); ec.Constructors = new ExtConstructorCollection(); ec.Properties = new ExtPropertyCollection(); ec.Methods = new ExtMethodCollection(); ec.Events = new ExtEventCollection(); ec.Configs = new ExtConfigCollection(); ec.Name = t; if (ec.Name.Contains(".")) { int p = ec.Name.LastIndexOf('.'); ec.Namespace = ec.Name.Substring(0, p); ec.Name = ec.Name.Substring(p + 1); } ec.Constructors.AddDefault(ec); ec.SourceFile = "custom"; classes.Add(ec); } return classes; }
public static void ParseConstructor(string member, ref ExtClass ec) { /** * @constructor * Blah Blah Blah * @param {String/HTMLElement/Ext.Element} el The id of or container element * @param {Object} config configuration options */ ExtConstructor ctor = new ExtConstructor(); ctor.Name = ec.Name; ctor.Class = ec; ctor.Description = new ExtDescription(); ctor.Parameters = new ExtParameterCollection(); string[] data = member.Split(SourceConverter.CRLFA, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < data.Length; i++) { if (data[i].StartsWith("*/")) break; if (data[i].StartsWith("@param")) { ctor.Parameters.Add(ExtParameter.ParseParameter(data[i])); } else { ctor.Description.Value += data[i] + SourceConverter.CRLF; } } ctor.Description.Value = ctor.Description.Value.Trim(SourceConverter.CRLFA); if (ctor.Parameters.HasParamWithManyTypes) { ec.Constructors.AddRange(ctor.SplitByParams()); } else { ec.Constructors.Add(ctor); } }
public static void ParseClass(string member, ref ExtClass ec) { /** * @class Ext.SplitButton * @extends Ext.Button * A split button that provides a built-in dropdown arrow that can fire an event separately from the default * click event of the button. Typically this would be used to display a dropdown menu that provides additional * options to the primary button action, but any custom handler can provide the arrowclick implementation. * @cfg {Function} arrowHandler A function called when the arrow button is clicked (can be used instead of click event) * @cfg {String} arrowTooltip The title attribute of the arrow * @constructor * Create a new menu button * @param {String/HTMLElement/Element} renderTo The element to append the button to * @param {Object} config The config object */ string[] data = member.Split(SourceConverter.CRLFA, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < data.Length; i++) { string line = data[i].Trim(); if (line.StartsWith("@class")) { ec.Name = line.Substring("@class".Length).Trim(); if (ec.Name.Contains(".")) { int p = ec.Name.LastIndexOf('.'); ec.Namespace = ec.Name.Substring(0, p); ec.Name = ec.Name.Substring(p + 1); } } else if (line.StartsWith("@extends")) { ec.SuperClass = line.Substring("@extends".Length).Trim(); } else if (line.StartsWith("@singleton")) { ec.Singleton = true; } else if (line.StartsWith("@constructor")) { string ctor = String.Empty; while (++i < data.Length - 1) { ctor += data[i] + SourceConverter.CRLF; } ExtConstructor.ParseConstructor(ctor, ref ec); } else { ec.Description.Value += line + SourceConverter.CRLF; } } ec.Description.Value.Trim(SourceConverter.CRLFA); // undocumented superclass if (ec.Name == "XTemplate") ec.SuperClass = "Ext.Template"; // Missing config options that need to be added before writing to file so that superclasses can copy this option to their configs if (ec.FullyQualifiedName == "Ext.Component") ec.Configs.Add(ExtConfig.Create("xtype", "string", "The registered xtype to create. This config option is not used when passing a config object into a constructor. This config option is used only when lazy instantiation is being used, and a child item of a Container is being specified not as a fully instantiated Component, but as a Component config object. The xtype will be looked up at render time up to determine what type of child Component to create.\r\nThe predefined xtypes are listed at the top of this document.\r\nIf you subclass Components to create your own Components, you may register them using Ext.ComponentMgr.registerType in order to be able to take advantage of lazy instantiation and rendering.")); if (ec.FullyQualifiedName == "Ext.Container") ec.Configs.Add(ExtConfig.Create("defaultType", "string", "The default type of container represented by this object as registered in Ext.ComponentMgr (defaults to 'panel').")); }
/// <summary> /// Checks the last line of a member to see if it is a fuction declaration /// </summary> /// <param name="member">The member to check</param> /// <param name="ec">The class the member belongs to</param> /// <returns>True is this member is a function</returns> public static bool IsFunction(string member, ExtClass ec) { string[] lines = member.Split(CRLFA, StringSplitOptions.RemoveEmptyEntries); string line = lines[lines.Length - 1]; if (line.Contains("function")) return true; if (line.Contains(" = ")) { // check if a variable if being set that points to another function in the class string[] d = line.Split(" = ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (d.Length > 1) { string method = d[1].Trim(); if (method.Contains(".")) method = method.Substring(method.LastIndexOf(".") + 1); if (method.Contains(";")) method = method.Replace(";", ""); foreach (ExtMethod m in ec.Methods) { if (m.Name == method) return true; } } } return false; }
/// <summary> /// Parses a list of members which contain all of the members for a single class /// </summary> /// <param name="members">The members of a single class</param> /// <returns>The object representation of the members in the file</returns> public static ExtClass Parse(List<string> members) { ExtClass ec = new ExtClass(); ec.Description = new ExtDescription(); ec.Constructors = new ExtConstructorCollection(); ec.Properties = new ExtPropertyCollection(); ec.Methods = new ExtMethodCollection(); ec.Events = new ExtEventCollection(); ec.Configs = new ExtConfigCollection(); foreach (string member in members) { if (member.Contains("@class")) { ExtClass.ParseClass(member, ref ec); } else if (member.Contains("@event")) { ExtEvent.ParseEvent(member, ref ec); } else if (member.Contains("@method")) { ExtMethod.ParseMethod(member, ref ec); } else if (member.Contains("@extproperty")) { ExtProperty.ParseProperty(member, ref ec); } else { if (IsFunction(member, ec)) { ExtMethod.ParseMethod(member, ref ec); } else { ExtProperty.ParseProperty(member, ref ec); } } if (member.Contains("@cfg") && !member.Contains("@hide")) { // since some definitions for config options and properties will be // in the same comment, parse this outside of the if stmt ExtConfig.ParseConfig(member, ref ec); } } ec.Constructors = ec.Constructors.CreateOverloads(); if (!ec.Constructors.HasDefaultConstructor) ec.Constructors.AddDefault(ec); ec.Methods = ec.Methods.CreateOverloads(); return ec; }
public static void ParseProperty(string member, ref ExtClass ec) { /** * true if this component has been rendered. Read-only. */ // rendered : false, string[] data = member.Split(SourceConverter.CRLFA, StringSplitOptions.RemoveEmptyEntries); ExtProperty ep = new ExtProperty(); ep.Description = new ExtDescription(); for (int i = 0; i < data.Length; i++) { string line = data[i]; if (line.StartsWith("/**") && line.EndsWith("*/")) { if (line.Contains("@type")) { // /** blah blah @type Boolean */ // isOpera : isOpera, line = line.Replace("/**", "").Replace("*/", "").Trim(); if (line.StartsWith("@type")) { ep.Type = line.Replace("@type", "").Trim(); } else { int index = line.IndexOf("@type"); ep.Description.Value += line.Substring(0, index).Trim(); ep.Type = line.Substring(index + "@type".Length).Trim(); } } else { // /** The normal browser event */ // browserEvent : null, line = line.Replace("/**", "").Replace("*/", "").Trim(); ep.Type = "object"; ep.Description.Value = line; } break; } if (line.StartsWith("*/")) break; if (line.StartsWith("/**")) continue; if (line.StartsWith("@type")) { ep.Type = line.Substring("@type".Length).Trim(); if (ep.Type.IndexOf(" ") > 0) ep.Type = ep.Type.Substring(0, ep.Type.IndexOf(" ")).Trim(); } else if (line.StartsWith("@cfg") && !line.Contains("@hide")) { // @cfg {String} emptyText The default text to display in an empty field (defaults to null). string[] text = line.Split(" ".ToCharArray()); if (text.Length > 1) ep.Type = text[1]; // capture {String} if (text.Length > 2) ep.Name = text[2]; // capture emptyText if (text.Length > 3) { // capture "The default text to display in an empty field (defaults to null)." for (int j = 3; j < text.Length; j++) { ep.Description.Value += text[j] + " "; } ep.Description.Value = ep.Description.Value.Trim(); } } else if (line.StartsWith("@static")) { ep.Scope = "static"; } else if (line.StartsWith("@property")) { ep.Name = line.Substring("@property".Length).Trim(); if (ep.Name.Contains(".")) ep.Name = ep.Name.Substring(0, ep.Name.IndexOf(".")).Trim(); // hack for ColumnModel config property // @property {Array} config if (ec.Name == "ColumnModel" && line.EndsWith("config")) { ep.Name = "config"; ep.Type = "Array"; } } else if (line.StartsWith("@private") || line.StartsWith("@hide")) { return; // ignore private & hidden members } else if (!line.Contains("@extproperty")) { ep.Description.Value += line.Trim() + SourceConverter.CRLF; } } ep.Description.Value = ep.Description.Value.Trim(SourceConverter.CRLFA); if (String.IsNullOrEmpty(ep.Name)) { string[] lastLine = SourceConverter.ParseLastLine(member); if (lastLine.Length > 0) { ep.Name = lastLine[0].Replace("this.", "").Replace("var", "").Trim(); ep.Name = ep.Name.Replace("'", "").Replace("\"", ""); // remove quotes if (ep.Name.Contains(".")) { string[] split = ep.Name.Split(".".ToCharArray()); ep.Name = split[split.Length - 1]; } } else { return; // dont add if we cant parse the name } } ep.Name = ep.Name.Replace("<p>", ""); if (String.IsNullOrEmpty(ep.Type)) { // try to guess the type based on the value on the last line string[] lastLine = SourceConverter.ParseLastLine(member); if (lastLine.Length > 1) { string value = lastLine[1].Trim(); value.TrimEnd(','); ep.Type = "Object"; if (value == "true" || value == "false") ep.Type = "boolean"; if (value.IndexOf("\"") >= 0) ep.Type = "String"; int d; if (Int32.TryParse(value, out d)) ep.Type = "int"; } } if (ExtType.IsStatic(ec, ep.Name)) ep.Scope = "static"; if (ExtType.IsKeyword(ep.Name)) { string fqn = String.Format("{0}.{1}", ec.FullyQualifiedName, ep.Name); SourceConverter.PropertyAliases.Add(fqn, fqn + "_"); ep.Name += "_"; } // Ext.BasicForm bug if (ep.Name == "fileUpload.") ep.Name = "fileUpload"; ec.Properties.AddProperty(ep); }