/// <summary> /// Get a source type symbol of given name, arity and kind. If a tree and syntax are provided, restrict the results /// to those that are declared within the given syntax. /// </summary> /// <returns>Null if there is no matching declaration.</returns> internal SourceNamedTypeSymbol?GetSourceTypeMember( string name, int arity, SyntaxKind kind, CSharpSyntaxNode syntax) { TypeKind typeKind = kind.ToDeclarationKind().ToTypeKind(); foreach (var member in GetTypeMembers(name, arity)) { var memberT = member as SourceNamedTypeSymbol; if ((object?)memberT != null && memberT.TypeKind == typeKind) { if (syntax != null) { foreach (var loc in memberT.Locations) { if (loc.IsInSource && loc.SourceTree == syntax.SyntaxTree && syntax.Span.Contains(loc.SourceSpan)) { return(memberT); } } } else { return(memberT); } } } // None found. return(null); }
/// <summary> /// Get a source type symbol of given name, arity and kind. If a tree and syntax are provided, restrict the results /// to those that are declared within the given syntax. /// </summary> /// <returns>Null if there is no matching declaration.</returns> internal SourceNamedTypeSymbol GetSourceTypeMember( string name, int arity, SyntaxKind kind, CSharpSyntaxNode syntax) { Debug.Assert( kind == SyntaxKind.ClassDeclaration || kind == SyntaxKind.StructDeclaration || kind == SyntaxKind.InterfaceDeclaration || kind == SyntaxKind.EnumDeclaration || kind == SyntaxKind.DelegateDeclaration || kind == SyntaxKind.InstanceDeclaration /*@t-mawind*/ || kind == SyntaxKind.ConceptDeclaration /*@t-mawind*/); TypeKind typeKind = kind.ToDeclarationKind().ToTypeKind(); foreach (var member in GetTypeMembers(name, arity)) { var memberT = member as SourceNamedTypeSymbol; if ((object)memberT != null && memberT.TypeKind == typeKind) { if (syntax != null) { foreach (var loc in memberT.Locations) { if (loc.IsInSource && loc.SourceTree == syntax.SyntaxTree && syntax.Span.Contains(loc.SourceSpan)) { return(memberT); } } } else { return(memberT); } } } // None found. return(null); }
/// <summary> /// Get a source type symbol of given name, arity and kind. If a tree and syntax are provided, restrict the results /// to those that are declared within the given syntax. /// </summary> /// <returns>Null if there is no matching declaration.</returns> internal SourceNamedTypeSymbol?GetSourceTypeMember( string name, int arity, SyntaxKind kind, CSharpSyntaxNode syntax) { TypeKind typeKind = kind.ToDeclarationKind().ToTypeKind(); foreach (var member in GetTypeMembers(name, arity)) { var memberT = member as SourceNamedTypeSymbol; if ((object?)memberT != null && memberT.TypeKind == typeKind) { if (syntax != null) { // PERF: Avoid accessing Locations for performance, but assert that the alternative approach is // equivalent. Debug.Assert(memberT.MergedDeclaration.Declarations.SelectAsArray(decl => decl.NameLocation).SequenceEqual(memberT.Locations)); foreach (var declaration in memberT.MergedDeclaration.Declarations) { var loc = declaration.NameLocation; if (loc.IsInSource && loc.SourceTree == syntax.SyntaxTree && syntax.Span.Contains(loc.SourceSpan)) { return(memberT); } } } else { return(memberT); } } } // None found. return(null); }
/// <summary> /// Get a source type symbol of given name, arity and kind. If a tree and syntax are provided, restrict the results /// to those that are declared within the given syntax. /// </summary> /// <returns>Null if there is no matching declaration.</returns> internal SourceNamedTypeSymbol GetSourceTypeMember( string name, int arity, SyntaxKind kind, CSharpSyntaxNode syntax) { Debug.Assert( kind == SyntaxKind.ClassDeclaration || kind == SyntaxKind.StructDeclaration || kind == SyntaxKind.InterfaceDeclaration || kind == SyntaxKind.EnumDeclaration || kind == SyntaxKind.DelegateDeclaration); TypeKind typeKind = kind.ToDeclarationKind().ToTypeKind(); foreach (var member in GetTypeMembers(name, arity)) { var memberT = member as SourceNamedTypeSymbol; if ((object)memberT != null && memberT.TypeKind == typeKind) { if (syntax != null) { foreach (var loc in memberT.Locations) { if (loc.IsInSource && loc.SourceTree == syntax.SyntaxTree && syntax.Span.Contains(loc.SourceSpan)) { return memberT; } } } else { return memberT; } } } // None found. return null; }