Пример #1
0
        internal static CompletionData ConvertMirrorToCompletionData(StaticMirror mirror, bool useShorterName = false,
                                                                     ElementResolver resolver = null)
        {
            var method = mirror as MethodMirror;

            if (method != null)
            {
                string         methodName = method.MethodName;
                string         signature  = method.ToString();
                CompletionType type       = method.IsConstructor ? CompletionType.Constructor : CompletionType.Method;
                return(new CompletionData(methodName, type, signature));
            }
            var property = mirror as PropertyMirror;

            if (property != null)
            {
                string propertyName = property.PropertyName;
                return(new CompletionData(propertyName, CompletionType.Property, property.ToString()));
            }
            var classMirror = mirror as ClassMirror;

            if (classMirror != null)
            {
                string className = useShorterName ? GetShortClassName(classMirror, resolver) : classMirror.Alias;
                return(new CompletionData(className, CompletionType.Class));
            }

            throw new ArgumentException("Invalid argument");
        }
Пример #2
0
        internal static CompletionData ConvertMirrorToCompletionData(StaticMirror mirror, bool useFullyQualifiedName = false)
        {
            MethodMirror method = mirror as MethodMirror;

            if (method != null)
            {
                string         methodName = method.MethodName;
                string         signature  = method.ToString();
                CompletionType type       = method.IsConstructor ? CompletionType.Constructor : CompletionType.Method;
                return(new CompletionData(methodName, type)
                {
                    Stub = signature
                });
            }
            PropertyMirror property = mirror as PropertyMirror;

            if (property != null)
            {
                string propertyName = property.PropertyName;
                return(new CompletionData(propertyName, CompletionType.Property));
            }
            ClassMirror classMirror = mirror as ClassMirror;

            if (classMirror != null)
            {
                string className = useFullyQualifiedName ? classMirror.ClassName : classMirror.Alias;
                return(new CompletionData(className, CompletionType.Class));
            }
            else
            {
                throw new ArgumentException("Invalid argument");
            }
        }
Пример #3
0
        public void TestGetAllTypesContainPrimitiveType()
        {
            var types = StaticMirror.GetAllTypes(core);

            Assert.IsTrue(types.Any(cm => cm.ClassName.Equals("int")));
            Assert.IsTrue(types.Any(cm => cm.ClassName.Equals("double")));
        }
Пример #4
0
        /// <summary>
        ///  Matches the completion string with classes, including primitive types.
        /// </summary>
        /// <param name="stringToComplete"></param>
        /// <returns></returns>
        internal IEnumerable <CompletionData> SearchTypes(string stringToComplete)
        {
            var completions = new List <CompletionData>();
            var partialName = stringToComplete.ToLower();

            // Add matching Classes
            var classMirrorGroups =
                StaticMirror.GetAllTypes(core)
                .Where(x => !x.IsHiddenInLibrary && x.Alias.ToLower().StartsWith(partialName))
                .GroupBy(x => x.Alias);

            // For those class names that have collisions (same alias), list
            // their fully qualified names in completion window.
            foreach (var classMirrorGroup in classMirrorGroups)
            {
                bool useFullyQualifiedName = classMirrorGroup.Count() > 1;
                foreach (var classMirror in classMirrorGroup)
                {
                    var completionData = CompletionData.ConvertMirrorToCompletionData(classMirror, useFullyQualifiedName);
                    completions.Add(completionData);
                }
            }

            return(completions);
        }
Пример #5
0
        private void AddTypesToCompletionData(string stringToComplete, List <CompletionData> completions, ElementResolver resolver)
        {
            var partialName = stringToComplete.ToLower();
            // Add matching Classes
            var classMirrorGroups = StaticMirror.GetAllTypes(core).
                                    Where(x => !x.IsHiddenInLibrary && x.Alias.ToLower().Contains(partialName)).
                                    GroupBy(x => x.Alias);

            foreach (var classMirrorGroup in classMirrorGroups)
            {
                // For those class names that have collisions, use shorter names
                bool useShorterName = classMirrorGroup.Count() > 1;
                if (useShorterName)
                {
                    // For colliding namespaces, compute shortest unique names for each
                    var namespaces = classMirrorGroup.Select(x => new Symbol(x.ClassName)).ToList();
                    var shortNames = Symbol.GetShortestUniqueNames(namespaces);
                    Debug.Assert(shortNames.Count() == classMirrorGroup.Count());

                    // Update class mirror (group) Alias with short name computed above
                    for (int i = 0; i < classMirrorGroup.Count(); i++)
                    {
                        var cm = classMirrorGroup.ElementAt(i);
                        cm.Alias = shortNames.ElementAt(i).Value;
                    }
                }
                completions.AddRange(classMirrorGroup.
                                     Where(x => !x.IsEmpty).
                                     Select(x =>
                                            CompletionData.ConvertMirrorToCompletionData(x, useShorterName,
                                                                                         resolver: resolver)));
            }
        }
Пример #6
0
            public MethodMirror GetDeclaredMethod(string methodName, List <ProtoCore.Type> argumentTypes)
            {
                ProcedureTable       procedureTable = ClassNode.vtable;
                List <ProcedureNode> procList       = procedureTable.procList;

                return(StaticMirror.FindMethod(methodName, argumentTypes, procList));
            }
Пример #7
0
            public MethodMirror GetDeclaredMethod(string className, string methodName, List <ProtoCore.Type> argumentTypes)
            {
                // Check global methods if classname is empty or null
                if (string.IsNullOrEmpty(className))
                {
                    List <MethodMirror> methods = null;
                    methods = GetGlobalMethods();
                    foreach (var method in methods)
                    {
                        if (method.MethodName == methodName)
                        {
                            List <ProtoCore.Type> argTypes = method.GetArgumentTypes();
                            if (argTypes.Count == argumentTypes.Count)
                            {
                                bool isEqual = true;
                                for (int i = 0; i < argumentTypes.Count; ++i)
                                {
                                    if (!argumentTypes[i].Equals(argTypes[i]))
                                    {
                                        isEqual = false;
                                        break;
                                    }
                                }
                                if (isEqual)
                                {
                                    return(method);
                                }
                            }
                        }
                    }
                }
                else // find method in Class
                {
                    Validity.Assert(staticCore != null);

                    ClassNode classNode = null;
                    ProtoCore.DSASM.ClassTable classTable = staticCore.ClassTable;
                    int ci = classTable.IndexOf(className);

                    if (ci != ProtoCore.DSASM.Constants.kInvalidIndex)
                    {
                        classNode = classTable.ClassNodes[ci];
                    }


                    ProcedureTable       procedureTable = classNode.vtable;
                    List <ProcedureNode> procList       = procedureTable.procList;

                    return(StaticMirror.FindMethod(methodName, argumentTypes, procList));
                }

                return(null);
            }
Пример #8
0
        public LibraryItem(NodeType type, string qualifiedName)
        {
            this.qualifiedName = qualifiedName;
            UpdateDisplayText();

            this.dataMirror = null;
            Level = -1;
            Type = MemberType.None;
            ItemType = type;
            Assembly = String.Empty;
            ArgumentTypes = String.Empty;
            ArgumentNames = String.Empty;
            IsOverloaded = false;
            IsExternal = false;
        }
Пример #9
0
        public LibraryItem(NodeType type, string qualifiedName)
        {
            this.qualifiedName = qualifiedName;
            UpdateDisplayText();

            this.dataMirror = null;
            Level           = -1;
            Type            = MemberType.None;
            ItemType        = type;
            Assembly        = String.Empty;
            ArgumentTypes   = String.Empty;
            ArgumentNames   = String.Empty;
            IsOverloaded    = false;
            IsExternal      = false;
        }
Пример #10
0
        public LibraryItem()
        {
            this.qualifiedName = String.Empty;

            this.dataMirror = null;
            Level           = -1;
            Type            = MemberType.None;
            ItemType        = NodeType.None;
            DisplayText     = String.Empty;
            Assembly        = String.Empty;
            ArgumentTypes   = String.Empty;
            ArgumentNames   = String.Empty;
            IsOverloaded    = false;
            IsExternal      = false;
        }
Пример #11
0
        public LibraryItem()
        {
            this.qualifiedName = String.Empty;

            this.dataMirror = null;
            Level = -1;
            Type = MemberType.None;
            ItemType = NodeType.None;
            DisplayText = String.Empty;
            Assembly = String.Empty;
            ArgumentTypes = String.Empty;
            ArgumentNames = String.Empty;
            IsOverloaded = false;
            IsExternal = false;
        }
Пример #12
0
        /// <summary>
        /// Returns the list of function signatures of all overloads of a given method
        /// </summary>
        /// <param name="code"> code being typed in code block </param>
        /// <param name="functionName"> given method name for which signature is queried </param>
        /// <param name="functionPrefix"> class name in case of constructor or static method, OR
        /// declared instance variable on which method is invoked </param>
        /// <param name="resolver"></param>
        /// <returns> list of method overload signatures </returns>
        internal IEnumerable <CompletionData> GetFunctionSignatures(string code, string functionName, string functionPrefix,
                                                                    ElementResolver resolver = null)
        {
            IEnumerable <MethodMirror> candidates = null;

            // if function is global, search for function in Built-ins
            if (string.IsNullOrEmpty(functionPrefix))
            {
                return(StaticMirror.GetOverloadsOnBuiltIns(core, functionName).
                       Select(x =>
                {
                    return new CompletionData(x.MethodName, CompletionData.CompletionType.Method)
                    {
                        Stub = x.ToString()
                    };
                }));
            }

            // Determine if the function prefix is a class name
            if (resolver != null)
            {
                functionPrefix = resolver.LookupResolvedName(functionPrefix) ?? functionPrefix;
            }

            var type = GetClassType(functionPrefix);

            if (type != null)
            {
                candidates = type.GetOverloadsOnType(functionName);
            }
            // If not of class type
            else
            {
                // Check if the function prefix is a typed identifier
                string typeName = CodeCompletionParser.GetVariableType(code, functionPrefix);
                if (typeName != null)
                {
                    type = GetClassType(typeName);
                }

                if (type != null)
                {
                    candidates = type.GetOverloadsOnInstance(functionName);
                }
            }
            return(candidates.Select(x => CompletionData.ConvertMirrorToCompletionData(x)));
        }
Пример #13
0
        /// <summary>
        /// Matches the completion string with classes and
        /// global methods and properties loaded in the session
        /// </summary>
        /// <param name="stringToComplete"> current string being typed which is to be completed </param>
        /// <param name="guid"> code block node guid to identify current node being typed </param>
        /// <param name="resolver"></param>
        /// <returns> list of classes, global methods and properties that match with string being completed </returns>
        internal IEnumerable <CompletionData> SearchCompletions(string stringToComplete, Guid guid, ElementResolver resolver = null)
        {
            var completions = new List <CompletionData>();

            // Add matching DS keywords
            completions.AddRange(KeywordList.Where(x => x.ToLower().Contains(stringToComplete.ToLower())).
                                 Select(x => new CompletionData(x, CompletionData.CompletionType.Keyword)));

            AddTypesToCompletionData(stringToComplete, completions, resolver);

            // Add matching builtin methods
            completions.AddRange(StaticMirror.GetBuiltInMethods(core).
                                 GroupBy(x => x.Name).Select(y => y.First()).
                                 Where(x => x.MethodName.ToLower().Contains(stringToComplete.ToLower())).
                                 Select(x => CompletionData.ConvertMirrorToCompletionData(x)));

            return(completions);
        }
Пример #14
0
            public MethodMirror GetDeclaredMethod(string methodName, List <ProtoCore.Type> argumentTypes)
            {
                if (classNode == null)
                {
                    Validity.Assert(staticCore != null);

                    ProtoCore.DSASM.ClassTable classTable = staticCore.ClassTable;
                    int ci = classTable.IndexOf(ClassName);

                    if (ci != ProtoCore.DSASM.Constants.kInvalidIndex)
                    {
                        classNode = classTable.ClassNodes[ci];
                    }
                }

                ProcedureTable       procedureTable = classNode.vtable;
                List <ProcedureNode> procList       = procedureTable.procList;

                return(StaticMirror.FindMethod(methodName, argumentTypes, procList));
            }
Пример #15
0
        /// <summary>
        /// Matches the completion string with classes and
        /// global methods and properties loaded in the session
        /// </summary>
        /// <param name="stringToComplete"> current string being typed which is to be completed </param>
        /// <param name="guid"> code block node guid to identify current node being typed </param>
        /// <returns> list of classes, global methods and properties that match with string being completed </returns>
        internal IEnumerable <CompletionData> SearchCompletions(string stringToComplete, Guid guid)
        {
            List <CompletionData> completions = new List <CompletionData>();

            // Add matching DS keywords
            completions.AddRange(KeywordList.Where(x => x.ToLower().Contains(stringToComplete.ToLower())).
                                 Select(x => new CompletionData(x, CompletionData.CompletionType.Keyword)));

            // Add matching Classes
            var groups = StaticMirror.GetClasses(core).
                         Where(x => x.Alias.ToLower().Contains(stringToComplete.ToLower())).
                         GroupBy(x => x.Alias);

            // For those class names that have collisions, list their fully qualified names in completion window
            foreach (var group in groups)
            {
                if (group.Count() > 1)
                {
                    completions.AddRange(group.
                                         Where(x => !x.IsHiddenInLibrary).
                                         Select(x => CompletionData.ConvertMirrorToCompletionData(x, useFullyQualifiedName: true)));
                }
                else
                {
                    completions.AddRange(group.
                                         Where(x => !x.IsHiddenInLibrary).
                                         Select(x => CompletionData.ConvertMirrorToCompletionData(x)));
                }
            }

            // Add matching builtin methods
            completions.AddRange(StaticMirror.GetBuiltInMethods(core).
                                 GroupBy(x => x.Name).Select(y => y.First()).
                                 Where(x => x.MethodName.ToLower().Contains(stringToComplete.ToLower())).
                                 Select(x => CompletionData.ConvertMirrorToCompletionData(x)));

            return(completions);
        }
Пример #16
0
 /// <summary>
 /// Returns the list of names of global methods and properties in Core
 /// </summary>
 /// <returns> list of names of global methods and properties </returns>
 internal IEnumerable <string> GetGlobals()
 {
     return(StaticMirror.GetGlobals(core).Select(x => x.Name));
 }
Пример #17
0
 /// <summary>
 /// Returns the list of names of classes loaded in the Core
 /// </summary>
 /// <returns> list of class names </returns>
 internal IEnumerable <string> GetClasses()
 {
     return(StaticMirror.GetClasses(core).Select(x => x.Alias));
 }
Пример #18
0
 internal static CompletionData ConvertMirrorToCompletionData(StaticMirror mirror, bool useShorterName = false, 
     ElementResolver resolver = null)
 {
     var method = mirror as MethodMirror;
     if (method != null)
     {
         string methodName = method.MethodName;
         string signature = method.ToString();
         CompletionType type = method.IsConstructor ? CompletionType.Constructor : CompletionType.Method;
         return new CompletionData(methodName, type)
         {
             Stub = signature
         };
     }
     var property = mirror as PropertyMirror;
     if (property != null)
     {
         string propertyName = property.PropertyName;
         return new CompletionData(propertyName, CompletionType.Property);
     }
     var classMirror = mirror as ClassMirror;
     if (classMirror != null)
     {
         string className = useShorterName ? GetShortClassName(classMirror, resolver) : classMirror.Alias;
         return new CompletionData(className, CompletionType.Class);
     }
     else
         throw new ArgumentException("Invalid argument");
 }
Пример #19
0
 internal static CompletionData ConvertMirrorToCompletionData(StaticMirror mirror, bool useFullyQualifiedName = false)
 {
     MethodMirror method = mirror as MethodMirror;
     if (method != null)
     {
         string methodName = method.MethodName;
         string signature = method.ToString();
         CompletionType type = method.IsConstructor ? CompletionType.Constructor : CompletionType.Method;
         return new CompletionData(methodName, type)
         {
             Stub = signature
         };
     }
     PropertyMirror property = mirror as PropertyMirror;
     if (property != null)
     {
         string propertyName = property.PropertyName;
         return new CompletionData(propertyName, CompletionType.Property);
     }
     ClassMirror classMirror = mirror as ClassMirror;
     if (classMirror != null)
     {
         string className = useFullyQualifiedName ? classMirror.ClassName : classMirror.Alias;
         return new CompletionData(className, CompletionType.Class);
     }
     else
         throw new ArgumentException("Invalid argument");
 }