Пример #1
0
        /// <summary>
        /// Generate method header from a selector.
        /// </summary>
        /// <param name="selector">Selector of the method.</param>
        /// <param name="message">Optional message description that describes the method.</param>
        /// <returns></returns>
        public static string BuildMethodHeader(string selector, Definitions.Description.Message message)
        {
            List <string> parts = MethodHelper.SplitSelectorParts(selector);

            StringBuilder str  = new StringBuilder();
            int           args = parts.Count;

            if ((args == 1) && !selector.Contains(':') && (selector.IndexOfAny("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_".ToCharArray()) != -1))
            {
                args = 0;
            }
            for (int i = 0; i < parts.Count; i++)
            {
                if (i != 0)
                {
                    str.Append(" ");
                }
                str.Append(parts[i]);
                if (i < args)
                {
                    str.Append(" ");
                    if ((message != null) && (i < message.Parameters.Count))
                    {
                        str.Append(message.Parameters[i].Name);
                    }
                    else
                    {
                        str.AppendFormat("arg{0}", i);
                    }
                }
            }
            return(str.ToString());
        }
Пример #2
0
            public Parameter ToParameter(Definitions.Description.Message message)
            {
                Parameter p = new Parameter(message);

                p.Aliasing = this.Aliasing;
                p.Name     = this.Name;
                foreach (string prot in this.Protocols)
                {
                    p.Protocols.Add(prot);
                }
                return(p);
            }
Пример #3
0
 private void CreateNewMessagelMenuItem_Click(object sender, EventArgs e)
 {
     if (this.Protocol == null)
     {
         return;
     }
     Definitions.Description.Message m = new Definitions.Description.Message(this.Protocol);
     if (!this.MessageHolder.SetValue(m))
     {
         return;
     }
 }
Пример #4
0
 private void listMessages_ItemChanging(object sender, ListItemChangingEventArgs e)
 {
     if (this.Updating)
     {
         return;
     }
     if (e.Item == null)
     {
         return;
     }
     Definitions.Description.Message m = e.Item.Tag as Definitions.Description.Message;
     this.MessageHolder.Value = m;
     e.Item = this.listMessages.Items.Cast <ListViewItem>()
              .FirstOrDefault(i => i.Tag == this.Message);
 }
Пример #5
0
        public static string BuildDocumentation(Definitions.Description.Message message, int indent)
        {
            if (message == null)
            {
                return(null);
            }

            StringBuilder str = new StringBuilder();

            if (!String.IsNullOrWhiteSpace(message.DocumentationId))
            {
                str.AppendHeading(String.Format("{0} {1}{2}:",
                                                message.DocumentationId,
                                                message.Protocol.Name,
                                                (message.IsRefined) ? " (refined)" : ""));
                str.AppendParagraph(String.Format("<strong>{0}</strong>",
                                                  MethodHelper.BuildMethodHeader(message.Selector, message)));
            }
            string tmp = message.Synopsis.Text;

            if (!String.IsNullOrWhiteSpace(tmp))
            {
                str.AppendHeading("Synopsys:");
                str.AppendParagraph(tmp);
            }

            tmp = message.DefinitionDescription.Text;
            if (!String.IsNullOrWhiteSpace(tmp) || !String.IsNullOrWhiteSpace(message.DefinitionProtocol))
            {
                str.AppendHeading(String.Format("Definition: {0}", message.DefinitionProtocol));
                if (!String.IsNullOrWhiteSpace(tmp))
                {
                    str.AppendParagraph(tmp);
                }
            }

            foreach (var pair in message.Refinement)
            {
                str.AppendHeading(String.Format("Refinement: {0}", pair.Key));
                str.AppendParagraph(pair.Value.Text);
            }

            foreach (var param in message.Parameters)
            {
                str.AppendHeading("Parameter:");
                str.AppendParagraph(String.Format("<strong>{0}</strong>: {1} - {2}",
                                                  param.Name, String.Join(", ", param.Protocols), param.Aliasing));
            }

            if (message.ReturnValue != null)
            {
                str.AppendHeading("Return Value:");
                str.AppendParagraph(String.Format("{0} - {1}{2} {2}",
                                                  String.Join(", ", message.ReturnValue.Protocols),
                                                  message.ReturnValue.Aliasing,
                                                  (String.IsNullOrWhiteSpace(message.ReturnValue.Description.Text) ? "" : ":"),
                                                  message.ReturnValue.Description.Text));
            }

            tmp = message.Errors.Text;
            if (!String.IsNullOrWhiteSpace(tmp))
            {
                str.AppendHeading("Errors:");
                str.AppendParagraph(tmp);
            }


            //StringBuilder str = new StringBuilder();
            //if (!String.IsNullOrWhiteSpace(message.DocumentationId))
            //{
            //    str.Indent(indent);
            //    str.AppendFormat("<p><strong>{0} {1}{2}:</strong></p>",
            //        message.DocumentationId,
            //        message.Protocol.Name,
            //        (message.IsRefined) ? " (refined)" : "");
            //    str.AppendMultiline(MethodHelper.BuildMethodHeader(message.Selector, message), indent+1);
            //    str.AppendSectionSeparator();
            //}
            //string tmp = message.Synopsis.Text;
            //if (!String.IsNullOrWhiteSpace(tmp))
            //{
            //    str.Indent(indent);
            //    str.Append("<p><strong>Synopsys:</strong></p>");
            //    str.AppendMultiline(tmp, indent+1);
            //    str.AppendSectionSeparator();
            //}

            //tmp = message.DefinitionDescription.Text;
            //if (!String.IsNullOrWhiteSpace(tmp) || !String.IsNullOrWhiteSpace(message.DefinitionProtocol))
            //{
            //    str.Indent(indent);
            //    str.AppendFormat("<p><strong>Definition: {0}</strong></p>", message.DefinitionProtocol);
            //    if (!String.IsNullOrWhiteSpace(tmp))
            //        str.AppendMultiline(tmp, indent+1);
            //    str.AppendSectionSeparator();
            //}

            //foreach (var pair in message.Refinement)
            //{
            //    str.Indent(indent);
            //    str.AppendFormat("<p><strong>Refinement: {0}</strong></p>", pair.Key);
            //    str.AppendMultiline(pair.Value.Text, indent + 1);
            //    str.AppendSectionSeparator();
            //}

            //foreach (var param in message.Parameters)
            //{
            //    str.Indent(indent);
            //    str.Append("<p><strong>Parameter:</strong></p>");
            //    str.AppendMultiline(String.Format("<strong>{0}</strong>: {1} - {2}",
            //        param.Name, String.Join(", ", param.Protocols), param.Aliasing), indent+1);
            //    str.AppendSectionSeparator();
            //}

            //if (message.ReturnValue != null)
            //{
            //    str.Indent(indent);
            //    str.Append("<p><strong>Return Value:</strong>");
            //    str.AppendMultiline(String.Format("{0} - {1}{2} {2}",
            //        String.Join(", ", message.ReturnValue.Protocols),
            //        message.ReturnValue.Aliasing,
            //        (String.IsNullOrWhiteSpace(message.ReturnValue.Description.Text) ? "" : ":"),
            //        message.ReturnValue.Description.Text), indent + 1);
            //    str.AppendSectionSeparator();
            //}

            //tmp = message.Errors.Text;
            //if (!String.IsNullOrWhiteSpace(tmp))
            //{
            //    str.Indent(indent);
            //    str.Append("<p><strong>Errors:</strong></p>");
            //    str.AppendMultiline(tmp, indent + 1);
            //    str.AppendSectionSeparator();
            //}

            return(str.ToString());
        }
Пример #6
0
        /// <summary>
        /// Get (or try to get) the first and the best protocol that implements the given message.
        /// </summary>
        /// <param name="methodName">Selector of the message to look for.</param>
        /// <param name="methodType">Type of the method (instance / class) to look for.</param>
        /// <param name="cls">Class where to start looking for the method.</param>
        /// <param name="protocolName">Optional protocol that may contain the message.</param>
        /// <returns>Message definition for the given selector or null if one was not found.</returns>
        public static Definitions.Description.Message GetMessageForMethod(string methodName, MethodType methodType, Class cls, string protocolName)
        {
            if (String.IsNullOrWhiteSpace(methodName))
            {
                throw new ArgumentNullException("methodName");
            }
            if (methodType == null)
            {
                throw new ArgumentNullException("methodType");
            }
            if (cls == null)
            {
                throw new ArgumentNullException("cls");
            }

            while (cls != null)
            {
                Definitions.Description.Message msg = null;
                var prot = cls.Parent.SmalltalkSystem.SystemDescription.Protocols.FirstOrDefault(p => p.Name == protocolName);
                if (prot != null)
                {
                    msg = prot.Messages.FirstOrDefault(m => m.Selector == methodName);
                }
                if (msg != null)
                {
                    return(msg);
                }

                List <Class> classesList;
                List <Class> superclassesList;
                Dictionary <string, Class>          classesMap;
                Dictionary <string, List <Class> >  protocolNameClassesMap;
                Dictionary <string, List <Class> >  protocolNameSuperslassesMap;
                Dictionary <string, List <Class> >  methodNameClassesMap;
                Dictionary <string, List <Class> >  methodNameSuperclassesMap;
                Dictionary <string, List <string> > methodNameProtocolNamesMap;
                Dictionary <string, List <string> > allMethodNameProtocolNamesMap;
                Dictionary <string, Definitions.Description.Protocol> protocolMap;
                HashSet <string> subclassResponsibilityMethods;
                Dictionary <string, List <Class> > methodNameLocalImplementorsMap;
                Dictionary <string, List <Class> > methodNameSuperImplementorsMap;
                MethodHelper.BuildLists(cls, cls, methodType, out classesList, out superclassesList, out classesMap,
                                        out protocolNameClassesMap, out protocolNameSuperslassesMap, out methodNameClassesMap,
                                        out methodNameSuperclassesMap, out methodNameProtocolNamesMap, out allMethodNameProtocolNamesMap,
                                        out protocolMap, out subclassResponsibilityMethods, out methodNameLocalImplementorsMap,
                                        out methodNameSuperImplementorsMap);
                List <string> pns;
                methodNameProtocolNamesMap.TryGetValue(methodName, out pns);
                if ((pns != null) && (pns.Count > 0))
                {
                    protocolMap.TryGetValue(pns[0], out prot);
                    if (prot != null)
                    {
                        msg = prot.Messages.FirstOrDefault(m => m.Selector == methodName);
                    }
                }
                if (msg != null)
                {
                    return(msg);
                }

                if (String.IsNullOrWhiteSpace(cls.SuperclassName))
                {
                    cls = null;
                }
                else
                {
                    cls = cls.Parent.Classes.FirstOrDefault(c => c.Name == cls.SuperclassName);
                }
            }

            return(null);
        }
 private void CreateNewMessagelMenuItem_Click(object sender, EventArgs e)
 {
     if (this.Protocol == null)
         return;
     Definitions.Description.Message m = new Definitions.Description.Message(this.Protocol);
     if (!this.MessageHolder.SetValue(m))
         return;
 }