예제 #1
0
            public override void CaseANamedType(ANamedType node)
            {
                AAName name = (AAName)node.GetName();

                if (name.GetIdentifier().Count > 2)
                {
                    return;
                }
                if (name.GetIdentifier().Count == 2 && ((TIdentifier)name.GetIdentifier()[0]).Text != "Dialogs")
                {
                    return;
                }
                if (name.GetIdentifier().Count == 1)
                {
                    bool         foundDialogs = false;
                    AASourceFile file         = Util.GetAncestor <AASourceFile>(node);
                    foreach (AUsingDecl usingDecl in file.GetUsings())
                    {
                        if (usingDecl.GetNamespace().Count == 1)
                        {
                            TIdentifier identifer = (TIdentifier)usingDecl.GetNamespace()[0];
                            if (identifer.Text == "Dialogs")
                            {
                                foundDialogs = true;
                                break;
                            }
                        }
                    }
                    if (!foundDialogs)
                    {
                        ANamespaceDecl ns = Util.GetAncestor <ANamespaceDecl>(node);
                        if (!Util.HasAncestor <ANamespaceDecl>(ns.Parent()) && ns.GetName().Text == "Dialogs")
                        {
                            foundDialogs = true;
                        }
                    }
                    if (!foundDialogs)
                    {
                        return;
                    }
                }
                if (((TIdentifier)name.GetIdentifier()[name.GetIdentifier().Count - 1]).Text == oldName)
                {
                    types.Add((TIdentifier)name.GetIdentifier()[name.GetIdentifier().Count - 1]);
                }
            }
예제 #2
0
        public static List <IList> GetVisibleDecls(Node node, bool includeUsings)
        {
            List <IList>          returner          = new List <IList>();
            AASourceFile          currentSourceFile = GetAncestor <AASourceFile>(node);
            List <List <string> > usedNamespaces    = new List <List <string> >();

            if (includeUsings)
            {
                foreach (AUsingDecl usingDecl in currentSourceFile.GetUsings())
                {
                    List <string> ns = new List <string>();
                    foreach (TIdentifier identifier in usingDecl.GetNamespace())
                    {
                        ns.Add(identifier.Text);
                    }
                    // ns.Reverse();
                    usedNamespaces.Add(ns);
                }
            }
            {
                List <string> currentNS = GetFullNamespace(node);
                if (currentNS.Count > 0)
                {
                    usedNamespaces.Add(currentNS);
                }
            }
            List <IList> currentList = new List <IList>();
            List <IList> nextList    = new List <IList>();
            AAProgram    program     = GetAncestor <AAProgram>(currentSourceFile);

            foreach (AASourceFile sourceFile in program.GetSourceFiles())
            {
                currentList.Add(sourceFile.GetDecl());
                returner.Add(sourceFile.GetDecl());
            }
            while (currentList.Count > 0)
            {
                foreach (IList declList in currentList)
                {
                    foreach (PDecl decl in declList)
                    {
                        if (decl is ANamespaceDecl)
                        {
                            ANamespaceDecl aDecl  = (ANamespaceDecl)decl;
                            List <string>  ns     = GetFullNamespace(decl);
                            bool           prefix = false;
                            bool           match  = false;
                            foreach (List <string> usedNamespace in usedNamespaces)
                            {
                                if (NamespacePrefix(ns, usedNamespace))
                                {
                                    prefix = true;
                                    if (NamespacesEquals(ns, usedNamespace))
                                    {
                                        match = true;
                                        break;
                                    }
                                }
                            }
                            if (prefix)
                            {
                                nextList.Add(aDecl.GetDecl());
                            }
                            if (match)
                            {
                                returner.Add(aDecl.GetDecl());
                            }
                        }
                    }
                }
                currentList = nextList;
                nextList    = new List <IList>();
            }
            return(returner);
        }