Esempio n. 1
0
 public override int GetHashCode()
 {
     return(SymbolMarkManager.GetHashCode(this));
 }
Esempio n. 2
0
 public int GetHashCode(IBookmarkedSymbol obj)
 {
     return(SymbolMarkManager.GetHashCode(obj));
 }
Esempio n. 3
0
        static IEnumerable <ClassificationTag> GetClassificationType(SyntaxNode node, SemanticModel semanticModel)
        {
            node = node.Kind() == SyntaxKind.Argument ? ((ArgumentSyntax)node).Expression : node;
            //System.Diagnostics.Debug.WriteLine(node.GetType().Name + node.Span.ToString());
            var symbol = semanticModel.GetSymbolInfo(node).Symbol;

            if (symbol == null)
            {
                symbol = semanticModel.GetDeclaredSymbol(node);
                if (symbol != null)
                {
                    switch (symbol.Kind)
                    {
                    case SymbolKind.NamedType:
                        yield return(symbol.ContainingType != null ? _Classifications.NestedDeclaration : _Classifications.Declaration);

                        break;

                    case SymbolKind.Event:
                        yield return(_Classifications.NestedDeclaration);

                        break;

                    case SymbolKind.Method:
                        if (HighlightOptions.LocalFunctionDeclaration ||
                            ((IMethodSymbol)symbol).MethodKind != MethodKind.LocalFunction)
                        {
                            yield return(_Classifications.NestedDeclaration);
                        }
                        break;

                    case SymbolKind.Property:
                        if (symbol.ContainingType.IsAnonymousType == false)
                        {
                            yield return(_Classifications.NestedDeclaration);
                        }
                        break;

                    case SymbolKind.Field:
                        if (node.IsKind(SyntaxKind.TupleElement))
                        {
                            if (((TupleElementSyntax)node).Identifier.IsKind(SyntaxKind.None))
                            {
                                symbol = semanticModel.GetTypeInfo(((TupleElementSyntax)node).Type).Type;
                            }
                        }
                        else if (HighlightOptions.NonPrivateField &&
                                 symbol.DeclaredAccessibility >= Accessibility.ProtectedAndInternal &&
                                 symbol.ContainingType.TypeKind != TypeKind.Enum)
                        {
                            yield return(_Classifications.NestedDeclaration);
                        }
                        break;

                    case SymbolKind.Local:
                        yield return(_Classifications.LocalDeclaration);

                        break;
                    }
                }
                else
                {
                    // NOTE: handle alias in using directive
                    if ((node.Parent as NameEqualsSyntax)?.Parent is UsingDirectiveSyntax)
                    {
                        yield return(_Classifications.AliasNamespace);
                    }
                    else if (node is AttributeArgumentSyntax)
                    {
                        symbol = semanticModel.GetSymbolInfo(((AttributeArgumentSyntax)node).Expression).Symbol;
                        if (symbol != null && symbol.Kind == SymbolKind.Field && (symbol as IFieldSymbol)?.IsConst == true)
                        {
                            yield return(_Classifications.ConstField);

                            yield return(_Classifications.StaticMember);
                        }
                    }
                    symbol = node.Parent is MemberAccessExpressionSyntax?semanticModel.GetSymbolInfo(node.Parent).CandidateSymbols.FirstOrDefault()
                                 : node.Parent.IsKind(SyntaxKind.Argument) ? semanticModel.GetSymbolInfo(((ArgumentSyntax)node.Parent).Expression).CandidateSymbols.FirstOrDefault()
                                                : node.IsKind(SyntaxKind.SimpleBaseType) ? semanticModel.GetTypeInfo(((SimpleBaseTypeSyntax)node).Type).Type
                                                : node.IsKind(SyntaxKind.TypeConstraint) ? semanticModel.GetTypeInfo(((TypeConstraintSyntax)node).Type).Type
                                                : null;

                    if (symbol == null)
                    {
                        yield break;
                    }
                }
            }
            switch (symbol.Kind)
            {
            case SymbolKind.Alias:
            case SymbolKind.ArrayType:
            case SymbolKind.Assembly:
            case SymbolKind.DynamicType:
            case SymbolKind.ErrorType:
            case SymbolKind.NetModule:
            case SymbolKind.PointerType:
            case SymbolKind.RangeVariable:
            case SymbolKind.Preprocessing:
                //case SymbolKind.Discard:
                yield break;

            case SymbolKind.Label:
                yield return(_Classifications.Label);

                yield break;

            case SymbolKind.TypeParameter:
                yield return(_Classifications.TypeParameter);

                yield break;

            case SymbolKind.Field:
                var f = symbol as IFieldSymbol;
                yield return(f.IsConst ?
                             f.ContainingType.TypeKind == TypeKind.Enum ? _Classifications.EnumField
                                                        : _Classifications.ConstField
                                                : f.IsReadOnly ? _Classifications.ReadonlyField
                                                : f.IsVolatile ? _Classifications.VolatileField
                                                : _Classifications.Field);

                break;

            case SymbolKind.Property:
                yield return(_Classifications.Property);

                break;

            case SymbolKind.Event:
                yield return(_Classifications.Event);

                break;

            case SymbolKind.Local:
                var localSymbol = symbol as ILocalSymbol;
                yield return(localSymbol.IsConst ? _Classifications.ConstField : _Classifications.LocalVariable);

                break;

            case SymbolKind.Namespace:
                yield return(_Classifications.Namespace);

                yield break;

            case SymbolKind.Parameter:
                yield return(_Classifications.Parameter);

                break;

            case SymbolKind.Method:
                var methodSymbol = symbol as IMethodSymbol;
                switch (methodSymbol.MethodKind)
                {
                case MethodKind.Constructor:
                    yield return
                        (node is AttributeSyntax || node.Parent is AttributeSyntax || node.Parent?.Parent is AttributeSyntax
                                                                        ? _Classifications.AttributeName
                                                                        : _Classifications.ConstructorMethod);

                    break;

                case MethodKind.Destructor:
                case MethodKind.StaticConstructor:
                    yield return(_Classifications.ConstructorMethod);

                    break;

                default:
                    yield return(methodSymbol.IsExtensionMethod ? _Classifications.ExtensionMethod
                                                                : methodSymbol.IsExtern ? _Classifications.ExternMethod
                                                                : _Classifications.Method);

                    break;
                }
                break;

            case SymbolKind.NamedType:
                break;

            default:
                yield break;
            }

            if (SymbolMarkManager.HasBookmark)
            {
                var markerStyle = SymbolMarkManager.GetSymbolMarkerStyle(symbol);
                if (markerStyle != null)
                {
                    yield return(markerStyle);
                }
            }

            if (FormatStore.IdentifySymbolSource && symbol.IsMemberOrType() && symbol.ContainingAssembly != null)
            {
                yield return(symbol.ContainingAssembly.GetSourceType() == AssemblySource.Metadata
                                        ? _Classifications.MetadataSymbol
                                        : _Classifications.UserSymbol);
            }

            if (symbol.IsStatic)
            {
                if (symbol.Kind != SymbolKind.Namespace)
                {
                    yield return(_Classifications.StaticMember);
                }
            }
            else if (symbol.IsSealed)
            {
                if (symbol.Kind == SymbolKind.NamedType && ((ITypeSymbol)symbol).TypeKind != TypeKind.Class)
                {
                    yield break;
                }
                yield return(_Classifications.SealedMember);
            }
            else if (symbol.IsOverride)
            {
                yield return(_Classifications.OverrideMember);
            }
            else if (symbol.IsVirtual)
            {
                yield return(_Classifications.VirtualMember);
            }
            else if (symbol.IsAbstract)
            {
                yield return(_Classifications.AbstractMember);
            }
        }