Exemplo n.º 1
0
        public static string ResolveType(MxmlFilterContext ctx, string ns, string name)
        {
            if (!ctx.namespaces.ContainsKey(ns))
            {
                return(name);
            }

            string uri = ctx.namespaces[ns];

            if (uri == "*")
            {
                return(name);
            }
            if (uri.EndsWith(".*"))
            {
                return(uri.Substring(0, uri.Length - 1) + name);
            }

            if (uri == MxmlFilter.BETA_MX || uri == MxmlFilter.OLD_MX)
            {
                uri = MxmlFilter.NEW_MX;
            }

            foreach (MxmlCatalog cat in ctx.catalogs)
            {
                if (cat.URI == uri && cat.ContainsKey(name))
                {
                    return(cat[name]);
                }
            }
            return(name);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Called if a FileModel needs filtering
        /// - modify parsed model
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        static public void FilterSource(FileModel model, MxmlFilterContext ctx)
        {
            ctx.model           = model;
            model.InlinedIn     = "xml";
            model.InlinedRanges = ctx.as3ranges;

            if (model.MetaDatas == null)
            {
                model.MetaDatas = new List <ASMetaData>();
            }
            foreach (string key in ctx.namespaces.Keys)
            {
                ASMetaData meta = new ASMetaData("Namespace");
                meta.Params = new Dictionary <string, string>();
                meta.Params.Add(key, ctx.namespaces[key]);
                model.MetaDatas.Add(meta);
            }

            ClassModel aClass = model.GetPublicClass();

            if (aClass == ClassModel.VoidClass)
            {
                return;
            }
            aClass.Comments = "<" + ctx.baseTag + "/>";

            Dictionary <string, string> resolved = new Dictionary <string, string>();

            foreach (MemberModel mxmember in ctx.mxmlMembers)
            {
                string tag  = mxmember.Type;
                string type = null;
                if (resolved.ContainsKey(tag))
                {
                    type = resolved[tag];
                }
                else
                {
                    type          = MxmlComplete.ResolveType(ctx, tag);
                    resolved[tag] = type;
                }
                MemberModel member = aClass.Members.Search(mxmember.Name, FlagType.Variable, Visibility.Public);
                if (member != null)
                {
                    member.Comments = "<" + tag + "/>";
                    member.Type     = type;
                }
            }
        }
Exemplo n.º 3
0
        private static void ReadNamespaces(MxmlFilterContext ctx, string src, int i)
        {
            // declared ns
            int len = src.Length;

            while (i < len)
            {
                string name = GetAttributeName(src, ref i);
                if (name == null)
                {
                    break;
                }
                string value = GetAttributeValue(src, ref i);
                if (value == null)
                {
                    break;
                }
                if (name.StartsWith("xmlns"))
                {
                    string[] qname = name.Split(':');
                    if (qname.Length == 1)
                    {
                        ctx.namespaces["*"] = value;
                    }
                    else
                    {
                        ctx.namespaces[qname[1]] = value;
                    }
                }
            }
            // find catalogs
            foreach (string ns in ctx.namespaces.Keys)
            {
                string uri = ctx.namespaces[ns];
                if (uri == OLD_MX || uri == BETA_MX)
                {
                    uri = NEW_MX;
                }
                foreach (MxmlCatalog cat in catalogs)
                {
                    if (cat.URI == uri)
                    {
                        cat.NS = ns;
                        ctx.catalogs.Add(cat);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static string ResolveType(MxmlFilterContext ctx, string tag)
        {
            if (tag == null || ctx == null)
            {
                return("void");
            }
            int p = tag.IndexOf(':');

            if (p < 0)
            {
                return(ResolveType(ctx, "*", tag));
            }
            else
            {
                return(ResolveType(ctx, tag.Substring(0, p), tag.Substring(p + 1)));
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Called if a FileModel needs filtering
 /// - define inline AS3 ranges
 /// </summary>
 /// <param name="src"></param>
 /// <returns></returns>
 public override string FilterSource(string fileName, string src)
 {
     mxmlFilterContext = new MxmlFilterContext();
     return(MxmlFilter.FilterSource(Path.GetFileNameWithoutExtension(fileName), src, mxmlFilterContext));
 }
Exemplo n.º 6
0
        /// <summary>
        /// Called if a FileModel needs filtering
        /// - define inline AS3 ranges
        /// </summary>
        /// <param name="src"></param>
        /// <returns></returns>
        static public string FilterSource(string name, string src, MxmlFilterContext ctx)
        {
            List <InlineRange> as3ranges   = ctx.as3ranges;
            MemberList         mxmlMembers = ctx.mxmlMembers;

            StringBuilder sb = new StringBuilder();

            sb.Append("package{");
            int  len        = src.Length - 8;
            int  rangeStart = -1;
            int  nodeStart  = -1;
            int  nodeEnd    = -1;
            int  line       = 0;
            bool firstNode  = true;
            bool skip       = true;
            bool hadNL      = false;
            bool inComment  = false;

            for (int i = 0; i < len; i++)
            {
                char c = src[i];
                // keep newlines
                if (c == 10 || c == 13)
                {
                    if (c == 13)
                    {
                        line++;
                    }
                    else if (i > 0 && src[i - 1] != 13)
                    {
                        line++;
                    }
                    sb.Append(c);
                    hadNL = true;
                }
                // XML comment
                else if (inComment)
                {
                    if (i < len - 3 && c == '-' && src[i + 1] == '-' && src[i + 2] == '>')
                    {
                        inComment = false;
                        i        += 3;
                    }
                    continue;
                }
                // in XML
                else if (skip)
                {
                    if (c == '<' && i < len - 3)
                    {
                        if (src[i + 1] == '!')
                        {
                            if (src[i + 2] == '-' && src[i + 3] == '-')
                            {
                                inComment = true;
                                i        += 3;
                                continue;
                            }
                            else if (src[i + 2] == '[' && src.Substring(i + 2, 7) == "[CDATA[")
                            {
                                i         += 8;
                                skip       = false;
                                hadNL      = false;
                                rangeStart = i;
                                continue;
                            }
                        }
                        else
                        {
                            nodeStart = i + 1;
                            nodeEnd   = -1;

                            if (firstNode && src[i + 1] != '?')
                            {
                                int    space = src.IndexOfAny(new char[] { ' ', '\n' }, i);
                                string tag   = GetXMLContextTag(src, space);
                                if (tag != null && space > 0)
                                {
                                    firstNode   = false;
                                    ctx.baseTag = tag;
                                    ReadNamespaces(ctx, src, space);
                                    string type = MxmlComplete.ResolveType(ctx, tag);
                                    sb.Append("public class ").Append(name)
                                    .Append(" extends ").Append(type).Append('{');
                                }
                            }
                        }
                    }
                    else if (c == '=' && i > 4) // <node id="..."
                    {
                        int off = i - 1;
                        while (src[off] == ' ' && off > 4)
                        {
                            off--;
                        }
                        if (src[off - 2] <= 32 && src[off - 1] == 'i' && src[off] == 'd')
                        {
                            string tag = GetXMLContextTag(src, i);
                            if (tag != null)
                            {
                                string id = GetAttributeValue(src, ref i);
                                if (id != null)
                                {
                                    MemberModel member = new MemberModel(id, tag, FlagType.Variable | FlagType.Dynamic, Visibility.Public);
                                    member.LineTo = member.LineFrom = line;
                                    string type = MxmlComplete.ResolveType(ctx, tag);
                                    mxmlMembers.Add(member);
                                    sb.Append("public var ").Append(id)
                                    .Append(':').Append(type).Append(';');
                                }
                            }
                        }
                    }
                    else if (nodeEnd < 0)
                    {
                        if (nodeStart >= 0 && (c == ' ' || c == '>'))
                        {
                            nodeEnd = i;
                        }
                    }
                }
                // in script
                else
                {
                    if (c == ']' && src[i] == ']' && src[i + 1] == '>')
                    {
                        skip = true;
                        if (hadNL)
                        {
                            as3ranges.Add(new InlineRange("as3", rangeStart, i));
                        }
                        rangeStart = -1;
                    }
                    else
                    {
                        sb.Append(c);
                    }
                }
            }
            if (rangeStart >= 0 && hadNL)
            {
                as3ranges.Add(new InlineRange("as3", rangeStart, src.Length));
            }
            sb.Append("}}");
            return(sb.ToString());
        }