public static void CreateItems(APropertyDecl decl, List <MethodDescription> methods, out VariableDescription variable)
        {
            if (decl.GetName().Text == "")
            {
                variable = null;
            }
            else
            {
                variable = new VariableDescription(decl);
            }

            TextPoint getterStart, setterStart;

            getterStart = setterStart = TextPoint.FromCompilerCoords(decl.GetName());
            if (decl.GetSetter() != null && decl.GetGetter() != null)
            {
                if (Util.TokenLessThan(((AABlock)decl.GetSetter()).GetToken(), ((AABlock)decl.GetGetter()).GetToken()))
                {
                    getterStart = TextPoint.FromCompilerCoords(((AABlock)decl.GetSetter()).GetToken());
                }
                else
                {
                    setterStart = TextPoint.FromCompilerCoords(((AABlock)decl.GetGetter()).GetToken());
                }
            }
            if (decl.GetGetter() != null)
            {
                methods.Add(new MethodDescription(getterStart, decl.GetType(), (AABlock)decl.GetGetter(), decl.GetType()));
            }
            if (decl.GetSetter() != null)
            {
                methods.Add(new MethodDescription(setterStart, new AVoidType(new TVoid("void")), (AABlock)decl.GetSetter(), decl.GetType()));
            }
        }
Beispiel #2
0
            public override void CaseAALocalDecl(AALocalDecl node)
            {
                //If parent is a methoddecl, we are a parameter
                if (node.Parent() is AMethodDecl)
                {
                    VariableDescription variable = new VariableDescription(node, VariableDescription.VariableTypes.Parameter);
                    Formals.Add(variable);
                }
                else
                {
                    VariableDescription variable = new VariableDescription(node, VariableDescription.VariableTypes.LocalVariable);
                    Locals.Add(variable);
                }

                base.CaseAALocalDecl(node);
            }
Beispiel #3
0
        public override bool Equals(object obj)
        {
            if (!(obj is VariableDescription))
            {
                return(false);
            }
            VariableDescription other = (VariableDescription)obj;

            if (Name != other.Name ||
                Type != other.Type ||
                Line != other.Line ||
                PlacementPrefix != other.PlacementPrefix ||
                Visibility.GetType() != other.Visibility.GetType())
            {
                return(false);
            }
            return(true);
        }
        public static void CreateItems(APropertyDecl decl, List<MethodDescription> methods, out VariableDescription variable)
        {
            if (decl.GetName().Text == "")
                variable = null;
            else
                variable = new VariableDescription(decl);

            TextPoint getterStart, setterStart;
            getterStart = setterStart = TextPoint.FromCompilerCoords(decl.GetName());
            if (decl.GetSetter() != null && decl.GetGetter() != null)
            {
                if (Util.TokenLessThan(((AABlock)decl.GetSetter()).GetToken(), ((AABlock)decl.GetGetter()).GetToken()))
                    getterStart = TextPoint.FromCompilerCoords(((AABlock)decl.GetSetter()).GetToken());
                else
                    setterStart = TextPoint.FromCompilerCoords(((AABlock)decl.GetGetter()).GetToken());
            }
            if (decl.GetGetter() != null)
                methods.Add(new MethodDescription(getterStart, decl.GetType(), (AABlock)decl.GetGetter(), decl.GetType()));
            if (decl.GetSetter() != null)
                methods.Add(new MethodDescription(setterStart, new AVoidType(new TVoid("void")), (AABlock)decl.GetSetter(), decl.GetType()));
        }
            public override void CaseAALocalDecl(AALocalDecl node)
            {
                //If parent is a methoddecl, we are a parameter
                if (node.Parent() is AMethodDecl)
                {
                    VariableDescription variable = new VariableDescription(node, VariableDescription.VariableTypes.Parameter);
                    Formals.Add(variable);
                }
                else
                {
                    VariableDescription variable = new VariableDescription(node, VariableDescription.VariableTypes.LocalVariable);
                    Locals.Add(variable);
                }

                base.CaseAALocalDecl(node);
            }
            public override void OutAFieldDecl(AFieldDecl node)
            {
                VariableDescription field = new VariableDescription(node);

                Fields.Add(field);
            }
        private void RebuildVisibleListInternal()
        {
            rebuildingData.suggestTypes &= !rebuildingData.onlySuggestMethods;
            rebuildingData.suggestKeywords &= !rebuildingData.onlySuggestMethods;
            List<string> addedNamespaces = new List<string>();

            //Get the sourcefile for the current editor
            object openFileData = currentEditor.Tag is Form1.OpenFileData ? ((Form1.OpenFileData)currentEditor.Tag).File : (object)((DialogData)currentEditor.Tag).DialogItem;
            SourceFileContents sourceFile = null;
            foreach (SourceFileContents sourceFileContents in Compiler.ParsedSourceFiles)
            {
                if (openFileData == sourceFileContents.Item && !sourceFileContents.IsDialogDesigner)
                {
                    sourceFile = sourceFileContents;
                    break;
                }
            }
            if (sourceFile == null)
                return;
            IDeclContainer currentContext = sourceFile.GetDeclContainerAt(currentEditor.caret.Position.Line);

            //Remove everything in the displayed list, and rebuild it.
            //Remember to join overloaded methods
            string selectedSignature = null;
            if (SelectedIndex >= 0 && SelectedIndex < rebuildingData.displayedItems.Count)
                selectedSignature = rebuildingData.displayedItems[SelectedIndex].Signature;

            IEnumerator<SuggestionBoxItem> enumerator;
            if (oldMatchText != "" && rebuildingData.matchText.StartsWith(oldMatchText))
            {//Remove all those that does not match the new text
                enumerator = rebuildingData.displayedItems.GetEnumerator();
                RedBlackTree<SuggestionBoxItem> newDispalyedItems = new RedBlackTree<SuggestionBoxItem>(RelevanceSorter);
                while (enumerator.MoveNext())
                {
                    if (enumerator.Current.DisplayText.ToLower().Contains(rebuildingData.matchText))
                        newDispalyedItems.Add(enumerator.Current);
                }
                rebuildingData.displayedItems = newDispalyedItems;
            }
            else
            {

                rebuildingData.displayedItems.Clear();

                if (rebuildingData.targetEnrichments.Count == 0 && rebuildingData.isDynamicArray)
                {
                    if ("resize".Contains(rebuildingData.matchText))
                        rebuildingData.displayedItems.Add(
                            new MethodDescription(new AMethodDecl(new APublicVisibilityModifier(), null, null, null,
                                                                    null, null, new AVoidType(new TVoid("void")),
                                                                    new TIdentifier("Resize"),
                                                                    new ArrayList()
                                                                        {
                                                                            new AALocalDecl(
                                                                                new APublicVisibilityModifier(), null,
                                                                                null, null, null,
                                                                                new ANamedType(
                                                                                    new TIdentifier("int"), null),
                                                                                new TIdentifier("size"), null)
                                                                        },
                                                                    new AABlock(new ArrayList(), new TRBrace("}")))));
                    if ("length".Contains(rebuildingData.matchText))
                        rebuildingData.displayedItems.Add(new CustomSuggestionBoxItem("length", "length", "int length", null));

                }
                else if (rebuildingData.onlySuggestInitKeywords)
                {
                    foreach (GalaxyKeywords.GalaxyKeyword keyword in GalaxyKeywords.InitializerKeywords.keywords)
                    {
                        if (keyword.DisplayText != "" && keyword.DisplayText.ToLower().Contains(rebuildingData.matchText))
                            rebuildingData.displayedItems.Add(keyword);
                    }
                }
                else if (rebuildingData.onlySuggestDelegates)
                {
                    foreach (SourceFileContents file in Compiler.ParsedSourceFiles)
                    {
                        foreach (MethodDescription method in file.Methods)
                        {
                            if (method.IsDelegate && method.DisplayText != "" && method.DisplayText.ToLower().Contains(rebuildingData.matchText))
                            {
                                rebuildingData.displayedItems.Add(method);
                            }
                        }
                    }
                }
                else if (rebuildingData.isDelegateInvoke)
                {
                    if ("invoke".Contains(rebuildingData.matchText))
                        rebuildingData.displayedItems.Add(new CustomSuggestionBoxItem("Invoke", "Invoke(", null, null));
                }
                else if (rebuildingData.isGlobal)
                {
                    //Suggest everything in visible source files
                    List<IDeclContainer> visibleDecls = sourceFile.GetVisibleDecls(currentContext.NamespaceList, true);
                    foreach (IDeclContainer file in visibleDecls)
                    {
                        //if (sourceFile.CanSeeOther(file))
                        {
                            foreach (VariableDescription field in file.Fields)
                            {
                                if (field.Visibility is APrivateVisibilityModifier &&
                                    currentContext.FullName != file.FullName)
                                    continue;

                                //Dont add static fields if we are in another file
                                if (field.IsStatic && field.ParentFile != sourceFile)
                                    continue;
                                if (field.DisplayText != "" && field.DisplayText.ToLower().Contains(rebuildingData.matchText))
                                    rebuildingData.displayedItems.Add(field);
                            }
                            foreach (MethodDescription method in file.Methods)
                            {
                                if (method.Visibility is APrivateVisibilityModifier &&
                                    currentContext.FullName != file.FullName)
                                    continue;

                                //Dont add static methods if we are in another file
                                if (method.IsStatic && method.ParentFile != sourceFile)
                                    continue;
                                if (method.DisplayText != "" && method.DisplayText.ToLower().Contains(rebuildingData.matchText))
                                    rebuildingData.displayedItems.Add(method);
                            }

                            foreach (StructDescription structDescription in file.Structs)
                            {
                                if (structDescription.Visibility is APrivateVisibilityModifier &&
                                    currentContext.FullName != file.FullName)
                                    continue;

                                if (structDescription.DisplayText != "" && structDescription.DisplayText.ToLower().Contains(rebuildingData.matchText))
                                    rebuildingData.displayedItems.Add(structDescription);
                            }
                            foreach (TypedefDescription typedef in file.Typedefs)
                            {
                                if (typedef.DisplayText != "" && typedef.DisplayText.ToLower().Contains(rebuildingData.matchText))
                                    rebuildingData.displayedItems.Add(typedef);
                            }
                        }
                    }
                    foreach (AFieldDecl field in Compiler.libraryData.Fields)
                    {
                        if (field.GetName().Text != "" && field.GetName().Text.ToLower().Contains(rebuildingData.matchText))
                        {
                            VariableDescription desc = new VariableDescription(field);
                            if (desc.Const && desc.init != null)
                            {
                                ConstantFolder folder = new ConstantFolder();
                                desc.init.Apply(folder);
                                desc.initStr = folder.Value;
                            }
                            rebuildingData.displayedItems.Add(desc);
                        }
                    }
                    foreach (AMethodDecl method in Compiler.libraryData.Methods)
                    {
                        if (method.GetName().Text != "" && method.GetName().Text.ToLower().Contains(rebuildingData.matchText))
                            rebuildingData.displayedItems.Add(new MethodDescription(method));
                    }
                }
                else
                {
                    if (rebuildingData.isDynamicArray)
                    {
                        if ("resize".Contains(rebuildingData.matchText))
                            rebuildingData.displayedItems.Add(
                                new MethodDescription(new AMethodDecl(new APublicVisibilityModifier(), null, null, null,
                                                                      null, null, new AVoidType(new TVoid("void")),
                                                                      new TIdentifier("Resize"),
                                                                      new ArrayList()
                                                                          {
                                                                              new AALocalDecl(
                                                                                  new APublicVisibilityModifier(), null,
                                                                                  null, null, null,
                                                                                  new ANamedType(
                                                                                      new TIdentifier("int"), null),
                                                                                  new TIdentifier("size"), null)
                                                                          },
                                                                      new AABlock(new ArrayList(), new TRBrace("}")))));
                    }
                    if (rebuildingData.suggestArrayLength)
                    {
                        if ("length".Contains(rebuildingData.matchText))
                            rebuildingData.displayedItems.Add(new CustomSuggestionBoxItem("length", "length", "int length", null));
                    }
                    if (rebuildingData.suggestVariables && rebuildingData.targetStructs.Count == 0 && rebuildingData.targetEnrichments.Count == 0 && rebuildingData.namespacePrefixes.Count == 0)
                    {
                        foreach (GalaxyKeywords.GalaxyKeyword keyword in GalaxyKeywords.SystemExpressions.keywords)
                        {
                            if (keyword.DisplayText != "" && keyword.DisplayText.ToLower().Contains(rebuildingData.matchText))
                                rebuildingData.displayedItems.Add(keyword);
                        }
                    }

                    StructDescription currentStruct = null;
                    foreach (StructDescription @struct in sourceFile.Structs)
                    {
                        if (@struct.LineFrom <= currentEditor.caret.Position.Line &&
                            @struct.LineTo >= currentEditor.caret.Position.Line)
                        {
                            currentStruct = @struct;
                            break;
                        }
                    }

                    EnrichmentDescription currentEnrichment = null;
                    foreach (EnrichmentDescription enrichment in sourceFile.Enrichments)
                    {
                        if (enrichment.LineFrom <= currentEditor.caret.Position.Line &&
                           enrichment.LineTo >= currentEditor.caret.Position.Line)
                        {
                            currentEnrichment = enrichment;
                            break;
                        }
                    }

                    //if (rebuildingData.targetStruct != null)
                    foreach (StructDescription feStr in rebuildingData.targetStructs)
                    {
                        StructDescription str = feStr;
                        StructDescription initStr = str;
                        while (str != null)
                        {
                            foreach (MethodDescription method in str.Methods)
                            {
                                //Dont add static methods if we are in another file
                                if (method.IsStatic)// != currentRebuildData.staticStruct)
                                    continue;
                                //Visibility
                                if (method.Visibility is APrivateVisibilityModifier &&
                                    str != currentStruct)
                                    continue;
                                if (method.Visibility is AProtectedVisibilityModifier)
                                {
                                    bool extends = false;
                                    StructDescription cStr = currentStruct;
                                    while (cStr != null)
                                    {
                                        if (cStr == str)
                                        {
                                            extends = true;
                                            break;
                                        }
                                        cStr = cStr.Base;
                                    }
                                    if (!extends)
                                        continue;
                                }

                                if (method.DisplayText != "" && method.DisplayText.ToLower().Contains(rebuildingData.matchText))
                                    rebuildingData.displayedItems.Add(method);
                            }

                            if (!rebuildingData.onlySuggestMethods)
                                foreach (VariableDescription field in str.Fields)
                                {
                                    if (field.IsStatic)
                                        continue;

                                    //Visibility
                                    if (field.Visibility is APrivateVisibilityModifier &&
                                        str != currentStruct)
                                        continue;
                                    if (field.Visibility is AProtectedVisibilityModifier)
                                    {
                                        bool extends = false;
                                        StructDescription cStr = currentStruct;
                                        while (cStr != null)
                                        {
                                            if (cStr == str)
                                            {
                                                extends = true;
                                                break;
                                            }
                                            cStr = cStr.Base;
                                        }
                                        if (!extends)
                                            continue;
                                    }

                                    //Dont add static fields if we are in another file
                                    //if (field.IsStatic && field.ParentFile != sourceFile)
                                    //    continue;
                                    if (field.DisplayText != "" && field.DisplayText.ToLower().Contains(rebuildingData.matchText))
                                        rebuildingData.displayedItems.Add(field);
                                }
                            str = str.Base;
                            if (str == initStr)
                                break;
                        }
                    }
                    foreach (StructDescription feStr in rebuildingData.staticStructs)
                    {
                        StructDescription str = feStr;
                        StructDescription initStr = str;
                        while (str != null)
                        {
                            foreach (MethodDescription method in str.Methods)
                            {
                                //Dont add static methods if we are in another file
                                if (!method.IsStatic)// != currentRebuildData.staticStruct)
                                    continue;
                                //Visibility
                                if (method.Visibility is APrivateVisibilityModifier &&
                                    str != currentStruct)
                                    continue;
                                if (method.Visibility is AProtectedVisibilityModifier)
                                {
                                    bool extends = false;
                                    StructDescription cStr = currentStruct;
                                    while (cStr != null)
                                    {
                                        if (cStr == str)
                                        {
                                            extends = true;
                                            break;
                                        }
                                        cStr = cStr.Base;
                                    }
                                    if (!extends)
                                        continue;
                                }

                                if (method.DisplayText != "" && method.DisplayText.ToLower().Contains(rebuildingData.matchText))
                                    rebuildingData.displayedItems.Add(method);
                            }

                            if (!rebuildingData.onlySuggestMethods)
                                foreach (VariableDescription field in str.Fields)
                                {
                                    if (!field.IsStatic)
                                        continue;

                                    //Visibility
                                    if (field.Visibility is APrivateVisibilityModifier &&
                                        str != currentStruct)
                                        continue;
                                    if (field.Visibility is AProtectedVisibilityModifier)
                                    {
                                        bool extends = false;
                                        StructDescription cStr = currentStruct;
                                        while (cStr != null)
                                        {
                                            if (cStr == str)
                                            {
                                                extends = true;
                                                break;
                                            }
                                            cStr = cStr.Base;
                                        }
                                        if (!extends)
                                            continue;
                                    }

                                    //Dont add static fields if we are in another file
                                    //if (field.IsStatic && field.ParentFile != sourceFile)
                                    //    continue;
                                    if (field.DisplayText != "" && field.DisplayText.ToLower().Contains(rebuildingData.matchText))
                                        rebuildingData.displayedItems.Add(field);
                                }
                            str = str.Base;
                            if (str == initStr)
                                break;
                        }
                    }
                    //if (rebuildingData.targetEnrichments.Count > 0)
                    {
                        foreach (EnrichmentDescription enrichment in rebuildingData.targetEnrichments)
                        {
                            foreach (VariableDescription field in enrichment.Fields)
                            {
                                if (field.IsStatic)
                                    continue;

                                //Visibility
                                /* !FIX! if ((field.Visibility is APrivateVisibilityModifier ||
                                       field.Visibility is AProtectedVisibilityModifier) &&
                                       (currentEnrichment == null || !ExtractDotType.TypesEqual(enrichment.type, currentEnrichment.type,
                                          enrichment.ParentFile, currentEnrichment.ParentFile)))
                                      continue;*/

                                //Dont add static fields if we are in another file
                                //if (field.IsStatic && field.ParentFile != sourceFile)
                                //    continue;
                                if (field.DisplayText != "" &&
                                    field.DisplayText.ToLower().Contains(rebuildingData.matchText))
                                    rebuildingData.displayedItems.Add(field);
                            }
                            foreach (MethodDescription method in enrichment.Methods)
                            {
                                //Dont add static methods if we are in another file
                                if (method.IsStatic)
                                    continue;
                                //Visibility
                                /*!FIX!if ((method.Visibility is APrivateVisibilityModifier ||
                                     method.Visibility is AProtectedVisibilityModifier) &&
                                    (currentEnrichment == null || !ExtractDotType.TypesEqual(enrichment.type, currentEnrichment.type,
                                        enrichment.ParentFile, currentEnrichment.ParentFile)))
                                    continue;*/

                                if (method.DisplayText != "" &&
                                    method.DisplayText.ToLower().Contains(rebuildingData.matchText))
                                    rebuildingData.displayedItems.Add(method);
                            }
                        }
                    }
                    //else if (rebuildingData.namespacePrefix != null)
                    foreach (NamespaceDescription ns in rebuildingData.namespacePrefixes)
                    {
                        if (!rebuildingData.onlySuggestMethods)
                            foreach (VariableDescription field in ns.Fields)
                            {
                                //Visibility
                                if (field.Visibility is APrivateVisibilityModifier &&
                                    ns.FullName != currentContext.FullName)
                                    continue;

                                //Dont add static fields if we are in another file
                                if (field.IsStatic && field.ParentFile != sourceFile)
                                    continue;
                                if (field.DisplayText != "" && field.DisplayText.ToLower().Contains(rebuildingData.matchText))
                                    rebuildingData.displayedItems.Add(field);
                            }
                        foreach (MethodDescription method in ns.Methods)
                        {
                            //Visibility
                            if (method.Visibility is APrivateVisibilityModifier &&
                                ns.FullName != currentContext.FullName)
                                continue;
                            //Dont add static methods if we are in another file
                            if (method.IsStatic && method.ParentFile != sourceFile)
                                continue;
                            if (method.DisplayText != "" && method.DisplayText.ToLower().Contains(rebuildingData.matchText))
                                rebuildingData.displayedItems.Add(method);
                        }
                        if (!rebuildingData.onlySuggestMethods)
                            foreach (StructDescription structDescription in ns.Structs)
                            {
                                if (structDescription.Visibility is APrivateVisibilityModifier &&
                                    ns.FullName != currentContext.FullName)
                                    continue;
                                if (structDescription.DisplayText != "" && structDescription.DisplayText.ToLower().Contains(rebuildingData.matchText))
                                    rebuildingData.displayedItems.Add(structDescription);
                            }
                        foreach (NamespaceDescription ns2 in ns.Namespaces)
                        {
                            if (ns2.Name.ToLower().Contains(rebuildingData.matchText) && !addedNamespaces.Contains(ns2.Name))
                            {
                                addedNamespaces.Add(ns2.Name);
                                rebuildingData.displayedItems.Add(ns2);
                            }
                        }
                        if (rebuildingData.suggestTypes)
                            foreach (TypedefDescription typedef in ns.Typedefs)
                            {
                                if (typedef.Name.ToLower().Contains(rebuildingData.matchText))
                                    rebuildingData.displayedItems.Add(typedef);
                            }
                    }
                    if (rebuildingData.targetStructs.Count == 0 && rebuildingData.staticStructs.Count == 0 && rebuildingData.targetEnrichments.Count == 0 && rebuildingData.namespacePrefixes.Count == 0)
                    {
                        //Check if we are inside a method
                        MethodDescription inMethod = null;
                        foreach (MethodDescription method in currentContext.Methods)
                        {
                            if (method.Start < currentEditor.caret.Position &&
                                method.End > currentEditor.caret.Position)
                            {
                                inMethod = method;
                                break;
                            }
                        }
                        //Check struct methods
                        //StructDescription inStruct = null;
                        if (inMethod == null)
                        {
                            foreach (StructDescription @struct in currentContext.Structs)
                            {
                                if (@struct.LineFrom <= currentEditor.caret.Position.Line &&
                                    @struct.LineTo >= currentEditor.caret.Position.Line)
                                {

                                    if (rebuildingData.suggestTypes)
                                        foreach (string generic in @struct.GenericVars)
                                        {
                                            if (generic != "" && generic.ToLower().Contains(rebuildingData.matchText))
                                                rebuildingData.displayedItems.Add(
                                                    new CustomSuggestionBoxItem(generic, generic,
                                                                                "Generic " + generic,
                                                                                typeof (string)));
                                        }

                                    List<MethodDescription> list = new List<MethodDescription>();
                                    list.AddRange(@struct.Methods);
                                    list.AddRange(@struct.Constructors);
                                    list.AddRange(@struct.Deconstructors);
                                    foreach (MethodDescription method in list)
                                    {
                                        if (method.Start < currentEditor.caret.Position &&
                                            method.End > currentEditor.caret.Position)
                                        {
                                            inMethod = method;

                                            StructDescription str = @struct;
                                            StructDescription initStr = str;
                                            while (str != null)
                                            {

                                                //Add variables from this struct
                                                if (rebuildingData.suggestVariables)
                                                {
                                                    if (!rebuildingData.onlySuggestMethods)
                                                        foreach (VariableDescription field in str.Fields)
                                                        {
                                                            //Visibility
                                                            if (field.Visibility is APrivateVisibilityModifier &&
                                                                str != currentStruct)
                                                                continue;
                                                            if (field.Visibility is AProtectedVisibilityModifier)
                                                            {
                                                                bool extends = false;
                                                                StructDescription cStr = currentStruct;
                                                                while (cStr != null)
                                                                {
                                                                    if (cStr == str)
                                                                    {
                                                                        extends = true;
                                                                        break;
                                                                    }
                                                                    cStr = cStr.Base;
                                                                }
                                                                if (!extends)
                                                                    continue;
                                                            }

                                                            if (!field.IsStatic && method.IsStatic)
                                                                continue;//Cant refference nonstatic fields from static

                                                            if (field.DisplayText != "" && field.DisplayText.ToLower().Contains(
                                                                    rebuildingData.matchText))
                                                                rebuildingData.displayedItems.Add(field);
                                                        }

                                                    foreach (MethodDescription m in str.Methods)
                                                    {
                                                        //Visibility
                                                        if (m.Visibility is APrivateVisibilityModifier &&
                                                            str != currentStruct)
                                                            continue;
                                                        if (m.Visibility is AProtectedVisibilityModifier)
                                                        {
                                                            bool extends = false;
                                                            StructDescription cStr = currentStruct;
                                                            while (cStr != null)
                                                            {
                                                                if (cStr == str)
                                                                {
                                                                    extends = true;
                                                                    break;
                                                                }
                                                                cStr = cStr.Base;
                                                            }
                                                            if (!extends)
                                                                continue;
                                                        }

                                                        if (!m.IsStatic && method.IsStatic)
                                                            continue;//Cant refference nonstatic methods from static

                                                        if (m.DisplayText != "" && m.DisplayText.ToLower().Contains(rebuildingData.matchText))
                                                            rebuildingData.displayedItems.Add(m);
                                                    }
                                                }

                                                str = str.Base;
                                                if (str == initStr)
                                                    break;
                                            }
                                            break;
                                        }
                                    }
                                    if (inMethod != null)
                                        break;
                                }
                            }
                        }

                        if (inMethod == null)
                        {//Look for enrichment
                            foreach (EnrichmentDescription enrichment in currentContext.Enrichments)
                            {
                                if (enrichment.LineFrom <= currentEditor.caret.Position.Line &&
                                    enrichment.LineTo >= currentEditor.caret.Position.Line)
                                {
                                    List<MethodDescription> list = new List<MethodDescription>();
                                    list.AddRange(enrichment.Methods);
                                    list.AddRange(enrichment.Constructors);
                                    list.AddRange(enrichment.Deconstructors);
                                    foreach (MethodDescription method in list)
                                    {
                                        if (method.Start < currentEditor.caret.Position &&
                                            method.End > currentEditor.caret.Position)
                                        {
                                            inMethod = method;
                                            //Add all fields/methods from the current enrichment
                                            if (rebuildingData.suggestVariables)
                                            {
                                                if (!rebuildingData.onlySuggestMethods)
                                                    foreach (VariableDescription field in enrichment.Fields)
                                                    {
                                                        //Visibility
                                                        if ((field.Visibility is APrivateVisibilityModifier ||
                                                             field.Visibility is AProtectedVisibilityModifier) &&
                                                            enrichment != currentEnrichment)
                                                            continue;

                                                        if (!field.IsStatic && method.IsStatic)
                                                            continue; //Cant refference nonstatic fields from static

                                                        if (field.DisplayText != "" &&
                                                            field.DisplayText.ToLower().Contains(
                                                                rebuildingData.matchText))
                                                            rebuildingData.displayedItems.Add(field);
                                                    }

                                                foreach (MethodDescription m in enrichment.Methods)
                                                {
                                                    //Visibility
                                                    if ((m.Visibility is APrivateVisibilityModifier ||
                                                            m.Visibility is AProtectedVisibilityModifier) &&
                                                        enrichment != currentEnrichment)
                                                        continue;

                                                    if (!m.IsStatic && method.IsStatic)
                                                        continue;//Cant refference nonstatic methods from static

                                                    if (m.DisplayText != "" && m.DisplayText.ToLower().Contains(rebuildingData.matchText))
                                                        rebuildingData.displayedItems.Add(m);
                                                }
                                            }
                                        }
                                    }
                                    if (inMethod != null)
                                        break;
                                }
                            }

                        }

                        //Add keywords depending on if we're in a method or not

                        rebuildingData.suggestVariables = rebuildingData.onlySuggestVariablesInsideMethods ? inMethod != null : rebuildingData.suggestVariables;
                        if (inMethod == null)
                        {
                            if (rebuildingData.suggestKeywords)
                                foreach (
                                    GalaxyKeywords.GalaxyKeyword keyword in GalaxyKeywords.OutMethodKeywords.keywords)
                                {
                                    if (keyword.DisplayText != "" && keyword.DisplayText.ToLower().Contains(rebuildingData.matchText))
                                        rebuildingData.displayedItems.Add(keyword);
                                }
                            if ("preloadbank".Contains(rebuildingData.matchText))
                            {
                                rebuildingData.displayedItems.Add(
                                    new MethodDescription(new AMethodDecl(new APublicVisibilityModifier(), null, null, null, null, null,
                                                                          new ANamedType(new TIdentifier("void"), null),
                                                                          new TIdentifier("PreloadBank"),
                                                                          new ArrayList
                                                                              {
                                                                                  new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null,
                                                                                                  new ANamedType(
                                                                                                      new TIdentifier(
                                                                                                          "string"),
                                                                                                      null),
                                                                                                  new TIdentifier(
                                                                                                      "bankName"), null),
                                                                                  new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null,
                                                                                                  new ANamedType(
                                                                                                      new TIdentifier(
                                                                                                          "int"), null),
                                                                                                  new TIdentifier(
                                                                                                      "player"), null)
                                                                              },
                                                                          null)));
                            }
                        }
                        else
                        {
                            if (rebuildingData.suggestKeywords)
                                foreach (
                                    GalaxyKeywords.GalaxyKeyword keyword in GalaxyKeywords.InMethodKeywords.keywords)
                                {
                                    if (keyword.DisplayText != "" && keyword.DisplayText.ToLower().Contains(rebuildingData.matchText))
                                        rebuildingData.displayedItems.Add(keyword);
                                }

                        }

                        //Add globals
                        List<IDeclContainer> visibleDecls = sourceFile.GetVisibleDecls(currentContext.NamespaceList, true);
                        foreach (IDeclContainer file in visibleDecls)
                        {
                            //!FIX! if (sourceFile.CanSeeOther(file))
                            {
                                if (rebuildingData.suggestVariables)
                                {
                                    if (!rebuildingData.onlySuggestMethods)
                                        foreach (VariableDescription field in file.Fields)
                                        {
                                            if (field.Visibility is APrivateVisibilityModifier &&
                                                currentContext.FullName != file.FullName)
                                                continue;

                                            //Dont add static fields if we are in another file
                                            if (field.IsStatic && field.ParentFile != sourceFile)
                                                continue;
                                            if (field.DisplayText != "" && field.DisplayText.ToLower().Contains(rebuildingData.matchText))
                                                rebuildingData.displayedItems.Add(field);
                                        }
                                    foreach (MethodDescription method in file.Methods)
                                    {
                                        if (method.Visibility is APrivateVisibilityModifier &&
                                            currentContext.FullName != file.FullName)
                                            continue;

                                        //Dont add static methods if we are in another file
                                        if (method.IsStatic && method.ParentFile != sourceFile)
                                            continue;
                                        if (method.DisplayText != "" && method.DisplayText.ToLower().Contains(rebuildingData.matchText))
                                            rebuildingData.displayedItems.Add(method);
                                    }

                                }
                                if (rebuildingData.suggestTypes)
                                {
                                    foreach (StructDescription structDescription in file.Structs)
                                    {
                                        if (structDescription.Visibility is APrivateVisibilityModifier &&
                                            currentContext.FullName != file.FullName)
                                            continue;
                                        if (structDescription.DisplayText != "" && structDescription.DisplayText.ToLower().Contains(rebuildingData.matchText))
                                            rebuildingData.displayedItems.Add(structDescription);
                                    }
                                    foreach (TypedefDescription typedef in file.Typedefs)
                                    {
                                        if (typedef.DisplayText != "" && typedef.DisplayText.ToLower().Contains(rebuildingData.matchText))
                                            rebuildingData.displayedItems.Add(typedef);
                                    }
                                }
                            }
                        }
                        if (rebuildingData.suggestTypes)
                            foreach (var primitive in GalaxyKeywords.Primitives.keywords)
                            {
                                if (primitive.DisplayText != "" && primitive.DisplayText.ToLower().Contains(rebuildingData.matchText))
                                    rebuildingData.displayedItems.Add(primitive);
                            }
                        //Add namespaces
                        if (rebuildingData.suggestVariables || rebuildingData.suggestTypes)
                        {
                            List<IDeclContainer> visibleDecls2 =
                                currentContext.File.GetVisibleDecls(currentContext.NamespaceList, false);
                            foreach (IDeclContainer visibleDecl in visibleDecls2)
                            {
                                foreach (NamespaceDescription ns in visibleDecl.Namespaces)
                                {
                                    if (ns.Name.ToLower().Contains(rebuildingData.matchText) && !addedNamespaces.Contains(ns.Name))
                                    {
                                        addedNamespaces.Add(ns.Name);
                                        rebuildingData.displayedItems.Add(ns);
                                    }
                                }
                            }
                        }
                        /*foreach (SuggestionBoxItem item in globalItems)
                        {
                            if ((item is MethodDescription && suggestVariables) ||
                                (item is StructDescription && suggestTypes) ||
                                (item is VariableDescription && suggestVariables) ||
                                (item is GalaxyKeywords.GalaxyKeyword && suggestKeywords))
                                if (item.DisplayText.ToLower().Contains(matchText))
                                    displayedItems.Add(item);
                        }*/

                        //If we are in a method, add all variables from that
                        if (inMethod != null && rebuildingData.suggestVariables && !rebuildingData.onlySuggestMethods)
                        {
                            foreach (VariableDescription formal in inMethod.Formals)
                            {
                                if (formal.DisplayText != "" && formal.DisplayText.ToLower().Contains(rebuildingData.matchText))
                                    rebuildingData.displayedItems.Add(formal);
                            }
                            foreach (VariableDescription formal in inMethod.Locals)
                            {
                                if (formal.DisplayText != "" && formal.DisplayText.ToLower().Contains(rebuildingData.matchText))
                                    rebuildingData.displayedItems.Add(formal);
                            }
                        }

                        //Add library data
                        if (rebuildingData.suggestVariables)
                        {
                            if (!rebuildingData.onlySuggestMethods)
                                foreach (AFieldDecl field in Compiler.libraryData.Fields)
                                {
                                    if (field.GetName().Text != "" && field.GetName().Text.ToLower().Contains(rebuildingData.matchText))
                                    {
                                        VariableDescription desc = new VariableDescription(field);
                                        if (desc.Const && desc.init != null)
                                        {
                                            ConstantFolder folder = new ConstantFolder();
                                            desc.init.Apply(folder);
                                            desc.initStr = folder.Value;
                                        }
                                        rebuildingData.displayedItems.Add(desc);
                                    }
                                }
                            foreach (AMethodDecl method in Compiler.libraryData.Methods)
                            {
                                if (method.GetName().Text != "" && method.GetName().Text.ToLower().Contains(rebuildingData.matchText))
                                    rebuildingData.displayedItems.Add(new MethodDescription(method));
                            }
                        }
                    }
                }
            }
            //Look through displayedItems, and join overloaded methods
            int firstMethodIndex = -1;
            int i = 0;
            List<MethodDescription> lastMethods = new List<MethodDescription>();
            enumerator = rebuildingData.displayedItems.GetEnumerator();
            while (enumerator.MoveNext())
            {
                if (!(enumerator.Current is MethodDescription))
                    continue;
                MethodDescription method = (MethodDescription) enumerator.Current;
                if (lastMethods.Count > 0 && lastMethods[0].Name != method.Name)
                {
                    if (lastMethods.Count > 1)
                    {
                        //Join methods
                        CustomSuggestionBoxItem overloadItem =
                            new CustomSuggestionBoxItem(lastMethods[0].DisplayText,
                                                        lastMethods[0].InsertText,
                                                        lastMethods.Aggregate("",
                                                                              (
                                                                                  current,
                                                                                  methodDescription)
                                                                              =>
                                                                              current +
                                                                              (methodDescription
                                                                                   .
                                                                                   TooltipText +
                                                                               "\n")),
                                                        typeof (MethodDescription));
                        //Remove last \n
                        overloadItem.TooltipText =
                            overloadItem.TooltipText.Remove(overloadItem.TooltipText.Length - 1);
                        foreach (MethodDescription methodDescription in lastMethods)
                        {
                            rebuildingData.displayedItems.Remove(methodDescription);
                        }
                        rebuildingData.displayedItems.Add(overloadItem);
                    }
                    lastMethods.Clear();
                }
                if (lastMethods.Count == 0) firstMethodIndex = i;
                lastMethods.Add(method);
                i++;
            }
            if (lastMethods.Count > 1)
            {

                //Join methods
                CustomSuggestionBoxItem overloadItem = new CustomSuggestionBoxItem(lastMethods[0].DisplayText,
                                                                                   lastMethods[0].InsertText,
                                                                                   lastMethods.Aggregate("",
                                                                                                         (
                                                                                                             current,
                                                                                                             methodDescription)
                                                                                                         =>
                                                                                                         current +
                                                                                                         (methodDescription
                                                                                                              .
                                                                                                              TooltipText +
                                                                                                          "\n")),
                                                                                   typeof (MethodDescription));
                //Remove last \n
                overloadItem.TooltipText = overloadItem.TooltipText.Remove(overloadItem.TooltipText.Length - 1);
                foreach (MethodDescription methodDescription in lastMethods)
                {
                    rebuildingData.displayedItems.Remove(methodDescription);
                }
                rebuildingData.displayedItems.Add(overloadItem);
            }

            //Check if the old selected is still there
            enumerator = rebuildingData.displayedItems.GetEnumerator();
            int selectedIndex = 0;
            while (enumerator.MoveNext())
            {
                if (enumerator.Current.Signature == selectedSignature)
                {
                    break;
                }
                selectedIndex++;
            }
            if (rebuildingData.displayedItems.Count > 0)
                SetSelectedIndex(selectedIndex % rebuildingData.displayedItems.Count);
            else
                SetSelectedIndex(-1);
            oldMatchText = rebuildingData.matchText;
            //Invalidate();
        }
Beispiel #8
0
            public override void CaseAALocalDecl(AALocalDecl node)
            {
                VariableDescription field = new VariableDescription(node, VariableDescription.VariableTypes.StructVariable);

                Fields.Add(field);
            }
 public override void CaseAALocalDecl(AALocalDecl node)
 {
     VariableDescription field = new VariableDescription(node, VariableDescription.VariableTypes.StructVariable);
     Fields.Add(field);
 }
 public override void OutAFieldDecl(AFieldDecl node)
 {
     VariableDescription field = new VariableDescription(node);
     Fields.Add(field);
 }