Ejemplo n.º 1
0
 void Suggest(IEnumerable <Namescope> e, string ignoredClassName = null, SuggestTypesMode mode = SuggestTypesMode.Everything)
 {
     foreach (var n in e)
     {
         Suggest(n, ignoredClassName, mode);
     }
 }
Ejemplo n.º 2
0
        void SuggestTypes(string memberExp, bool includeStaticMembers, bool metaContext, SuggestTypesMode mode = SuggestTypesMode.Everything, bool onlyClassTypes = false)
        {
            _exceptionTypesOnly = InCatchBlockHeader();

            SourceObject item = _context.TypeOrNamespace;

            // Suggest generic arguments
            if (mode == SuggestTypesMode.Everything)
            {
                var vdt = _context.TypeOrNamespace as DataType;
                while (vdt != null)
                {
                    if (vdt.GenericParameters != null)
                    {
                        foreach (var t in vdt.GenericParameters)
                        {
                            Suggest(t);
                        }
                    }
                    vdt = vdt.Parent as DataType;
                }
            }

            if (memberExp == "")
            {
                foreach (var u in _context.Usings)
                {
                    var ns = _context.Compiler.ILFactory.GetEntity(_context.Root.Source, u, _context.Root) as Namespace;
                    if (ns != null)
                    {
                        foreach (var i in ns.Types)
                        {
                            if (!onlyClassTypes || (i.TypeType == TypeType.Class || i.TypeType == TypeType.Interface))
                            {
                                Suggest(i, null, mode);
                            }
                        }
                        if (mode == SuggestTypesMode.Blocks)
                        {
                            Suggest(ns.Blocks);
                        }
                    }
                }

                if (mode == SuggestTypesMode.Everything)
                {
                    FunctionCompiler fc = null;
                    foreach (var us in _context.UsingStatics)
                    {
                        var dte = Parser.ParseExpression(_compiler.Log, _source, us, metaContext ? ParseContext.MetaProperty : ParseContext.Default);
                        if (!dte.IsInvalid)
                        {
                            if (fc == null)
                            {
                                fc = CreateFunctionCompiler(_methodNode);
                            }
                            TrySuggestMembers(fc, dte, true);
                        }
                    }

                    SuggestNodePathTypes();
                }
            }

            if (memberExp != "")
            {
                item = ResolveStringInFunctionContext(_methodNode, memberExp, _source, new FunctionCompiler(_context.Compiler, _context.TypeOrNamespace));
                if (mode == SuggestTypesMode.Everything && memberExp.EndsWith("<"))
                {
                    SuggestKeywords(TypeAliases.AllAliases.ToArray());
                }

                if (item is PartialNamespace)
                {
                    var ns = (item as PartialNamespace).Namespace;
                    Suggest(ns.Namespaces, null, mode);
                    Suggest(ns.Types, null, mode);

                    if (mode == SuggestTypesMode.Blocks)
                    {
                        Suggest(ns.Blocks);
                    }
                }

                if (includeStaticMembers && item is PartialType)
                {
                    var dt = (item as PartialType).Type;
                    SuggestTypeMembers(dt, AccessorLevel.Public, true, metaContext, false, null);
                }
            }
            else
            {
                if (mode == SuggestTypesMode.Everything && !_exceptionTypesOnly)
                {
                    SuggestKeywords(TypeAliases.AllAliases.ToArray());
                    SuggestKeywords("void");
                }

                while (item != null)
                {
                    if (item is Namespace)
                    {
                        var ns = item as Namespace;
                        Suggest(ns.Namespaces, null, mode);
                        Suggest(ns.Types, null, mode);

                        if (mode == SuggestTypesMode.Blocks)
                        {
                            Suggest(ns.Blocks);
                        }

                        item = ns.Parent;
                    }
                    else if (includeStaticMembers && item is DataType)
                    {
                        var dt = item as DataType;
                        SuggestTypeMembers(dt, AccessorLevel.Private, true, metaContext, false, null);

                        item        = dt.Parent;
                        metaContext = false;
                    }
                    else if (item is DataType)
                    {
                        var dt = item as DataType;
                        item = dt.Parent;
                        if (dt.Block != null && mode == SuggestTypesMode.Blocks)
                        {
                            Suggest(dt.Block.NestedBlocks);
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        void Suggest(Namescope ns, string ignoredClassName = null, SuggestTypesMode mode = SuggestTypesMode.Everything)
        {
            if (ns is Namespace)
            {
                Suggest(SuggestItemType.Namespace, ns, ns.Name);
            }
            if (ns is ClassType)
            {
                if (ignoredClassName == null || ignoredClassName != ns.Name)
                {
                    if (_exceptionTypesOnly)
                    {
                        var ct = ns as ClassType;
                        if (!ct.Equals(_context.Compiler.ILFactory.Essentials.Exception) && !ct.IsSubclassOf(_context.Compiler.ILFactory.Essentials.Exception))
                        {
                            return;
                        }
                    }

                    string n = ns.Name;

                    var sit = SuggestItemType.Class;

                    if (mode == SuggestTypesMode.Blocks)
                    {
                        if (n.EndsWith("BlockFactory"))
                        {
                            n   = n.Substring(0, n.Length - "BlockFactory".Length);
                            sit = SuggestItemType.BlockFactory;
                        }
                        else
                        {
                            return;
                        }
                    }
                    else if (mode == SuggestTypesMode.Importers)
                    {
                        if (n.EndsWith("Importer"))
                        {
                            n   = n.Substring(0, n.Length - "Importer".Length);
                            sit = SuggestItemType.Importer;
                        }
                        else
                        {
                            return;
                        }
                    }
                    else if (mode == SuggestTypesMode.Attributes)
                    {
                        if (n.EndsWith("Attribute"))
                        {
                            n   = n.Substring(0, n.Length - "Attribute".Length);
                            sit = SuggestItemType.Class;
                        }
                        else
                        {
                            return;
                        }
                    }

                    Suggest(sit, ns, n);
                }
            }


            if (mode == SuggestTypesMode.Everything)
            {
                if (!_exceptionTypesOnly && ns is InterfaceType)
                {
                    Suggest(SuggestItemType.Interface, ns, ns.Name);
                }

                if (!_exceptionTypesOnly && ns is StructType)
                {
                    Suggest(SuggestItemType.Struct, ns, ns.Name);
                }

                if (!_exceptionTypesOnly && ns is DelegateType)
                {
                    Suggest(SuggestItemType.Delegate, ns, ns.Name);
                }

                if (!_exceptionTypesOnly && ns is EnumType)
                {
                    Suggest(SuggestItemType.Enum, ns, ns.Name);
                }

                if (ns is GenericParameterType)
                {
                    Suggest(SuggestItemType.GenericParameterType, ns, ns.Name);
                }
            }
        }