Пример #1
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")));
        }
Пример #2
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)));
            }
        }
Пример #3
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);
        }