private static int CompareParameter(IParameterSymbol x, IParameterSymbol y)
        {
            if (object.ReferenceEquals(x, y))
            {
                return(0);
            }

            if (x == null)
            {
                return(-1);
            }

            if (y == null)
            {
                return(1);
            }

            int diff = ((int)x.RefKind).CompareTo((int)y.RefKind);

            if (diff != 0)
            {
                return(diff);
            }

            return(SymbolDefinitionComparer.CompareName(x, y));
        }
示例#2
0
        private int CompareMethods(IMethodSymbol methodSymbol1, IMethodSymbol methodSymbol2)
        {
            int diff = SymbolDefinitionComparer.CompareName(methodSymbol1, methodSymbol2);

            if (diff != 0)
            {
                return(diff);
            }

            diff = methodSymbol1.TypeParameters.Length.CompareTo(methodSymbol2.TypeParameters.Length);

            if (diff != 0)
            {
                return(diff);
            }

            diff = CompareParameters(methodSymbol1.Parameters, methodSymbol2.Parameters);

            if (diff != 0)
            {
                return(diff);
            }

            return(CompareContainingNamespace(methodSymbol1, methodSymbol2));
        }
        private static int CompareProperties(IPropertySymbol propertySymbol1, IPropertySymbol propertySymbol2)
        {
            int diff = SymbolDefinitionComparer.CompareName(propertySymbol1, propertySymbol2);

            if (diff != 0)
            {
                return(diff);
            }

            return(CompareParameters(propertySymbol1.Parameters, propertySymbol2.Parameters));
        }
示例#4
0
        private int CompareProperties(IPropertySymbol propertySymbol1, IPropertySymbol propertySymbol2)
        {
            int diff = SymbolDefinitionComparer.CompareName(propertySymbol1, propertySymbol2);

            if (diff != 0)
            {
                return(diff);
            }

            diff = CompareParameters(propertySymbol1.Parameters, propertySymbol2.Parameters);

            if (diff != 0)
            {
                return(diff);
            }

            return(CompareContainingNamespace(propertySymbol1, propertySymbol2));
        }
示例#5
0
        public int Compare(INamedTypeSymbol x, INamedTypeSymbol y)
        {
            if (object.ReferenceEquals(x, y))
            {
                return(0);
            }

            if (x == null)
            {
                return(-1);
            }

            if (y == null)
            {
                return(1);
            }

            int diff = 0;

            if ((SymbolComparer.Options & SymbolDefinitionSortOptions.OmitContainingNamespace) == 0)
            {
                diff = SymbolComparer.NamespaceComparer.Compare(x.ContainingNamespace, y.ContainingNamespace);

                if (diff != 0)
                {
                    return(diff);
                }
            }

            diff = GetRank(x).CompareTo(GetRank(y));

            if (diff != 0)
            {
                return(diff);
            }

            int count1 = CountContainingTypes(x);
            int count2 = CountContainingTypes(y);

            while (true)
            {
                INamedTypeSymbol containingType1 = GetContainingType(x, count1);
                INamedTypeSymbol containingType2 = GetContainingType(y, count2);

                diff = SymbolDefinitionComparer.CompareName(containingType1, containingType2);

                if (diff != 0)
                {
                    return(diff);
                }

                diff = containingType1.TypeParameters.Length.CompareTo(containingType2.TypeParameters.Length);

                if (diff != 0)
                {
                    return(diff);
                }

                if (count1 == 0)
                {
                    return((count2 == 0) ? 0 : -1);
                }

                if (count2 == 0)
                {
                    return(1);
                }

                count1--;
                count2--;
            }

            int CountContainingTypes(INamedTypeSymbol namedType)
            {
                int count = 0;

                while (true)
                {
                    namedType = namedType.ContainingType;

                    if (namedType == null)
                    {
                        break;
                    }

                    count++;
                }

                return(count);
            }

            INamedTypeSymbol GetContainingType(INamedTypeSymbol namedType, int count)
            {
                while (count > 0)
                {
                    namedType = namedType.ContainingType;
                    count--;
                }

                return(namedType);
            }

            int GetRank(INamedTypeSymbol symbol)
            {
                switch (symbol.TypeKind)
                {
                case TypeKind.Class:
                    return(1);

                case TypeKind.Struct:
                    return(2);

                case TypeKind.Interface:
                    return(3);

                case TypeKind.Enum:
                    return(4);

                case TypeKind.Delegate:
                    return(5);
                }

                Debug.Fail(symbol.ToDisplayString(SymbolDisplayFormats.Test));

                return(0);
            }
        }
示例#6
0
 internal NamedTypeSymbolDefinitionComparer(SymbolDefinitionComparer symbolComparer)
 {
     SymbolComparer = symbolComparer;
 }
示例#7
0
        public int Compare(INamespaceSymbol x, INamespaceSymbol y)
        {
            if (object.ReferenceEquals(x, y))
            {
                return(0);
            }

            if (x == null)
            {
                return(-1);
            }

            if (y == null)
            {
                return(1);
            }

            if (x.IsGlobalNamespace)
            {
                return((y.IsGlobalNamespace) ? 0 : -1);
            }
            else if (y.IsGlobalNamespace)
            {
                return(1);
            }

            int count1 = CountContainingNamespaces(x);
            int count2 = CountContainingNamespaces(y);

            if ((SymbolComparer.Options & SymbolDefinitionSortOptions.SystemFirst) != 0)
            {
                INamespaceSymbol namespaceSymbol1 = GetNamespaceSymbol(x, count1);
                INamespaceSymbol namespaceSymbol2 = GetNamespaceSymbol(y, count2);

                if (namespaceSymbol1.Name == "System")
                {
                    if (namespaceSymbol2.Name != "System")
                    {
                        return(-1);
                    }
                }
                else if (namespaceSymbol2.Name == "System")
                {
                    return(1);
                }
            }

            while (true)
            {
                INamespaceSymbol namespaceSymbol1 = GetNamespaceSymbol(x, count1);
                INamespaceSymbol namespaceSymbol2 = GetNamespaceSymbol(y, count2);

                int diff = SymbolDefinitionComparer.CompareName(namespaceSymbol1, namespaceSymbol2);

                if (diff != 0)
                {
                    return(diff);
                }

                if (count1 == 0)
                {
                    return((count2 == 0) ? 0 : -1);
                }

                if (count2 == 0)
                {
                    return(1);
                }

                count1--;
                count2--;
            }

            int CountContainingNamespaces(INamespaceSymbol namespaceSymbol)
            {
                int count = 0;

                while (true)
                {
                    namespaceSymbol = namespaceSymbol.ContainingNamespace;

                    if (namespaceSymbol.IsGlobalNamespace)
                    {
                        break;
                    }

                    count++;
                }

                return(count);
            }

            INamespaceSymbol GetNamespaceSymbol(INamespaceSymbol namespaceSymbol, int count)
            {
                while (count > 0)
                {
                    namespaceSymbol = namespaceSymbol.ContainingNamespace;
                    count--;
                }

                return(namespaceSymbol);
            }
        }
        public int Compare(ISymbol x, ISymbol y)
        {
            Debug.Assert(x.IsKind(SymbolKind.Event, SymbolKind.Field, SymbolKind.Method, SymbolKind.Property), x.Kind.ToString());
            Debug.Assert(y.IsKind(SymbolKind.Event, SymbolKind.Field, SymbolKind.Method, SymbolKind.Property), y.Kind.ToString());

            if (object.ReferenceEquals(x, y))
            {
                return(0);
            }

            if (x == null)
            {
                return(-1);
            }

            if (y == null)
            {
                return(1);
            }

            int diff = 0;

            if ((SymbolComparer.Options & SymbolDefinitionSortOptions.OmitContainingNamespace) == 0)
            {
                diff = SymbolComparer.NamespaceComparer.Compare(x.ContainingNamespace, y.ContainingNamespace);

                if (diff != 0)
                {
                    return(diff);
                }
            }

            if ((SymbolComparer.Options & SymbolDefinitionSortOptions.OmitContainingType) == 0)
            {
                diff = SymbolComparer.TypeComparer.Compare(x.ContainingType, y.ContainingType);

                if (diff != 0)
                {
                    return(diff);
                }
            }

            MemberDeclarationKind kind1 = x.GetMemberDeclarationKind();
            MemberDeclarationKind kind2 = y.GetMemberDeclarationKind();

            diff = ((int)kind1).CompareTo((int)kind2);

            if (diff != 0)
            {
                return(diff);
            }

            switch (kind1)
            {
            case MemberDeclarationKind.Constructor:
            case MemberDeclarationKind.Method:
            {
                return(CompareMethods((IMethodSymbol)x, (IMethodSymbol)y));
            }

            case MemberDeclarationKind.Indexer:
            case MemberDeclarationKind.Property:
            {
                return(CompareProperties((IPropertySymbol)x, (IPropertySymbol)y));
            }

            case MemberDeclarationKind.ExplicitlyImplementedEvent:
            {
                var e1 = (IEventSymbol)x;
                var e2 = (IEventSymbol)y;

                diff = CompareExplicitImplementations(e1.ExplicitInterfaceImplementations, e2.ExplicitInterfaceImplementations);

                if (diff != 0)
                {
                    return(diff);
                }

                break;
            }

            case MemberDeclarationKind.ExplicitlyImplementedMethod:
            {
                var m1 = (IMethodSymbol)x;
                var m2 = (IMethodSymbol)y;

                diff = CompareExplicitImplementations(m1.ExplicitInterfaceImplementations, m2.ExplicitInterfaceImplementations);

                if (diff != 0)
                {
                    return(diff);
                }

                return(CompareMethods(m1, m2));
            }

            case MemberDeclarationKind.ExplicitlyImplementedProperty:
            {
                var p1 = (IPropertySymbol)x;
                var p2 = (IPropertySymbol)y;

                diff = CompareExplicitImplementations(p1.ExplicitInterfaceImplementations, p2.ExplicitInterfaceImplementations);

                if (diff != 0)
                {
                    return(diff);
                }

                return(CompareProperties(p1, p2));
            }
            }

            return(SymbolDefinitionComparer.CompareName(x, y));
        }
 internal MemberSymbolDefinitionComparer(SymbolDefinitionComparer symbolComparer)
 {
     SymbolComparer = symbolComparer;
 }
        public int Compare(INamedTypeSymbol x, INamedTypeSymbol y)
        {
            if (object.ReferenceEquals(x, y))
            {
                return(0);
            }

            if (x == null)
            {
                return(-1);
            }

            if (y == null)
            {
                return(1);
            }

            int diff;

            if ((SymbolComparer.Options & SymbolDefinitionSortOptions.OmitContainingNamespace) == 0)
            {
                diff = SymbolComparer.CompareContainingNamespace(x, y);

                if (diff != 0)
                {
                    return(diff);
                }
            }

            diff = GetRank(x).CompareTo(GetRank(y));

            if (diff != 0)
            {
                return(diff);
            }

            int count1 = CountContainingTypes(x);
            int count2 = CountContainingTypes(y);

            while (true)
            {
                INamedTypeSymbol containingType1 = GetContainingType(x, count1);
                INamedTypeSymbol containingType2 = GetContainingType(y, count2);

                diff = SymbolDefinitionComparer.CompareName(containingType1, containingType2);

                if (diff != 0)
                {
                    return(diff);
                }

                diff = containingType1.TypeParameters.Length.CompareTo(containingType2.TypeParameters.Length);

                if (diff != 0)
                {
                    return(diff);
                }

                if (count1 == 0)
                {
                    if (count2 == 0)
                    {
                        return(SymbolComparer.CompareContainingNamespace(x, y));
                    }
                    else
                    {
                        return(-1);
                    }
                }

                if (count2 == 0)
                {
                    return(1);
                }

                count1--;
                count2--;
            }