コード例 #1
0
        public void ThrowsArgumentNullException_When_SemanticModelIsNull()
        {
            TypeParameterSyntax parameter     = GetNode <TypeParameterSyntax>("class Test<[Test]T> { }");
            SemanticModel?      semanticModel = null;

            Assert.Throws <ArgumentNullException>(() => semanticModel !.GetAllAttributesOfType(parameter, AttributeSymbol));
        }
コード例 #2
0
ファイル: WriteMethod.cs プロジェクト: FrankLIKE/SharpNative
        public static string TypeParameter(TypeParameterSyntax prm, IMethodSymbol methodSymbol,
                                           MethodDeclarationSyntax methodSyntax)
        {
            var identifier = Utility.TypeConstraints(prm, methodSyntax.ConstraintClauses);

            return(identifier);
        }
コード例 #3
0
        private static string TypeParameter(TypeParameterSyntax type)
        {
            var ret = Utility.TypeConstraints(type,
                                              Context.Instance.Partials.SelectMany(z => z.Syntax.As <TypeDeclarationSyntax>().ConstraintClauses));

            return(ret);
        }
コード例 #4
0
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            if (!Settings.IsCodeFixEnabled(CodeFixIdentifiers.RemoveTypeParameter))
            {
                return;
            }

            SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false);

            TypeParameterSyntax typeParameter = root
                                                .FindNode(context.Span, getInnermostNodeForTie: true)?
                                                .FirstAncestorOrSelf <TypeParameterSyntax>();

            Debug.Assert(typeParameter != null, $"{nameof(typeParameter)} is null");

            if (typeParameter == null)
            {
                return;
            }

            foreach (Diagnostic diagnostic in context.Diagnostics)
            {
                switch (diagnostic.Id)
                {
                case CompilerDiagnosticIdentifiers.TypeParameterHasSameNameAsTypeParameterFromOuterType:
                {
                    TypeParameterInfo info;
                    if (TypeParameterInfo.TryCreate(typeParameter, out info))
                    {
                        CodeAction codeAction = CodeAction.Create(
                            $"Remove type parameter '{info.Name}'",
                            cancellationToken =>
                            {
                                SeparatedSyntaxList <TypeParameterSyntax> parameters = info.TypeParameterList.Parameters;

                                TypeParameterListSyntax newTypeParameterList = (parameters.Count == 1)
                                            ? default(TypeParameterListSyntax)
                                            : info.TypeParameterList.WithParameters(parameters.Remove(typeParameter));

                                SyntaxNode newNode = GenericDeclarationHelper.WithTypeParameterList(info.Declaration, newTypeParameterList);

                                TypeParameterConstraintClauseSyntax constraintClause = info.ConstraintClause;

                                if (constraintClause != null)
                                {
                                    newNode = GenericDeclarationHelper.WithConstraintClauses(newNode, info.ConstraintClauses.Remove(constraintClause));
                                }

                                return(context.Document.ReplaceNodeAsync(info.Declaration, newNode, cancellationToken));
                            },
                            GetEquivalenceKey(diagnostic));

                        context.RegisterCodeFix(codeAction, diagnostic);
                    }

                    break;
                }
                }
            }
        }
コード例 #5
0
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);

            TypeParameterSyntax typeParameter = root
                                                .FindNode(context.Span, getInnermostNodeForTie: true)?
                                                .FirstAncestorOrSelf <TypeParameterSyntax>();

            Debug.Assert(typeParameter != null, $"{nameof(typeParameter)} is null");

            if (typeParameter == null)
            {
                return;
            }

            foreach (Diagnostic diagnostic in context.Diagnostics)
            {
                switch (diagnostic.Id)
                {
                case DiagnosticIdentifiers.AddTypeParameterToDocumentationComment:
                {
                    var refactoring = new AddTypeParameterToDocumentationCommentRefactoring();

                    CodeAction codeAction = CodeAction.Create(
                        "Add type parameter to documentation comment",
                        cancellationToken => refactoring.RefactorAsync(context.Document, typeParameter, cancellationToken),
                        diagnostic.Id + EquivalenceKeySuffix);

                    context.RegisterCodeFix(codeAction, diagnostic);
                    break;
                }
                }
            }
        }
コード例 #6
0
 internal GenericParameterDeclarationSyntax(
     TypeParameterSyntax typeParameter,
     TypeParameterConstraintClauseSyntax constraintClause)
 {
     this.typeParameter    = typeParameter;
     this.constraintClause = constraintClause;
 }
コード例 #7
0
ファイル: GenericInfo.cs プロジェクト: vitsatishjs/Roslynator
        public GenericInfo RemoveTypeParameter(TypeParameterSyntax typeParameter)
        {
            switch (Kind)
            {
            case SyntaxKind.ClassDeclaration:
                return(new GenericInfo(((ClassDeclarationSyntax)Declaration).WithTypeParameterList(RemoveTypeParameterHelper(typeParameter))));

            case SyntaxKind.DelegateDeclaration:
                return(new GenericInfo(((DelegateDeclarationSyntax)Declaration).WithTypeParameterList(RemoveTypeParameterHelper(typeParameter))));

            case SyntaxKind.InterfaceDeclaration:
                return(new GenericInfo(((InterfaceDeclarationSyntax)Declaration).WithTypeParameterList(RemoveTypeParameterHelper(typeParameter))));

            case SyntaxKind.LocalFunctionStatement:
                return(new GenericInfo(((LocalFunctionStatementSyntax)Declaration).WithTypeParameterList(RemoveTypeParameterHelper(typeParameter))));

            case SyntaxKind.MethodDeclaration:
                return(new GenericInfo(((MethodDeclarationSyntax)Declaration).WithTypeParameterList(RemoveTypeParameterHelper(typeParameter))));

            case SyntaxKind.StructDeclaration:
                return(new GenericInfo(((StructDeclarationSyntax)Declaration).WithTypeParameterList(RemoveTypeParameterHelper(typeParameter))));

            case SyntaxKind.None:
                return(this);
            }

            Debug.Fail(Kind.ToString());
            return(this);
        }
コード例 #8
0
        public static Task <Document> RefactorAsync(
            Document document,
            TypeParameterSyntax typeParameter,
            CancellationToken cancellationToken)
        {
            SyntaxNode node = typeParameter;

            var typeParameterList = (TypeParameterListSyntax)typeParameter.Parent;

            if (typeParameterList.Parameters.Count == 1)
            {
                node = typeParameterList;
            }

            SyntaxRemoveOptions options = SyntaxRemover.DefaultRemoveOptions;

            if (node.GetLeadingTrivia().All(f => f.IsWhitespaceTrivia()))
            {
                options &= ~SyntaxRemoveOptions.KeepLeadingTrivia;
            }

            if (node.GetTrailingTrivia().All(f => f.IsWhitespaceTrivia()))
            {
                options &= ~SyntaxRemoveOptions.KeepTrailingTrivia;
            }

            return(document.RemoveNodeAsync(node, options, cancellationToken));
        }
コード例 #9
0
 private TypeParameterInfo(
     TypeParameterSyntax typeParameter,
     TypeParameterListSyntax typeParameterList)
 {
     TypeParameter     = typeParameter;
     TypeParameterList = typeParameterList;
 }
コード例 #10
0
        private (TypeParameterSyntax syntax, SemanticModel semanticModel) GetTypeParameter(string src)
        {
            TypeParameterSyntax parameter     = GetNode <TypeParameterSyntax>(src);
            SemanticModel       semanticModel = Compilation.CurrentCompilation.GetSemanticModel(parameter.SyntaxTree, true);

            return(parameter, semanticModel);
        }
コード例 #11
0
 private Doc PrintTypeParameterSyntax(TypeParameterSyntax node)
 {
     return(Concat(
                this.PrintAttributeLists(node, node.AttributeLists),
                this.PrintSyntaxToken(node.VarianceKeyword, " "),
                this.PrintSyntaxToken(node.Identifier)
                ));
 }
コード例 #12
0
 public static Doc Print(TypeParameterSyntax node)
 {
     return(Doc.Concat(
                AttributeLists.Print(node, node.AttributeLists),
                Token.Print(node.VarianceKeyword, " "),
                Token.Print(node.Identifier)
                ));
 }
コード例 #13
0
ファイル: GenericInfo.cs プロジェクト: vitsatishjs/Roslynator
        private TypeParameterListSyntax RemoveTypeParameterHelper(TypeParameterSyntax typeParameter)
        {
            SeparatedSyntaxList <TypeParameterSyntax> parameters = TypeParameters;

            return((parameters.Count == 1)
                ? default(TypeParameterListSyntax)
                : TypeParameterList.WithParameters(parameters.Remove(typeParameter)));
        }
コード例 #14
0
 private TypeParameterInfo(TypeParameterSyntax typeParameter, SyntaxNode declaration, TypeParameterListSyntax typeParameterList, SyntaxList <TypeParameterConstraintClauseSyntax> constraintClauses) : this()
 {
     TypeParameter     = typeParameter;
     Name              = typeParameter.Identifier.ValueText;
     Declaration       = declaration;
     TypeParameterList = typeParameterList;
     ConstraintClauses = constraintClauses;
 }
コード例 #15
0
 public override void VisitTypeParameter(TypeParameterSyntax node)
 {
     if (node == null)
     {
         throw new InvalidOperationException("Type Parameter node is null!");
     }
     ((m_currentParent as AbstractAddressableEntity)).AddTypeParameter(node.Identifier.Text);
     base.VisitTypeParameter(node);
 }
コード例 #16
0
ファイル: Node.cs プロジェクト: binarybird/Cascade
        public override void VisitTypeParameter(TypeParameterSyntax node)
        {
            foreach (AttributeListSyntax listSyntax in node.AttributeLists)
            {
                listSyntax.Accept(this);
            }

            base.VisitTypeParameter(node);
        }
コード例 #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TypeParameterData"/> struct.
 /// </summary>
 /// <param name="syntax">Target <see cref="TypeParameterSyntax"/>.</param>
 /// <param name="symbol"><see cref="ITypeParameterSymbol"/> represented by the target <paramref name="syntax"/>.</param>
 /// <param name="semanticModel"><see cref="Microsoft.CodeAnalysis.SemanticModel"/> of the target <paramref name="syntax"/>.</param>
 /// <param name="attribute">Valid <c>Durian.DefaultParamAttribute</c> defined on the target <paramref name="symbol"/>.</param>
 /// <param name="targetType">The <see cref="ITypeSymbol"/> that was specified using the <paramref name="attribute"/>. -or- <see langword="null"/> if <paramref name="attribute"/> is <see langword="null"/> or the type cannot be resolved because of error.</param>
 public TypeParameterData(TypeParameterSyntax syntax, ITypeParameterSymbol symbol, SemanticModel semanticModel, AttributeSyntax?attribute, ITypeSymbol?targetType)
 {
     Syntax        = syntax;
     Symbol        = symbol;
     Attribute     = attribute;
     TargetType    = targetType;
     Parent        = (MemberDeclarationSyntax)syntax.Parent !.Parent !;
     SemanticModel = semanticModel;
 }
コード例 #18
0
        public static bool TryCreate(TypeParameterSyntax typeParameter, out TypeParameterInfo info)
        {
            if (typeParameter.IsParentKind(SyntaxKind.TypeParameterList))
            {
                var typeParameterList = (TypeParameterListSyntax)typeParameter.Parent;

                SyntaxNode parent = typeParameterList.Parent;

                switch (parent?.Kind())
                {
                case SyntaxKind.ClassDeclaration:
                {
                    var classDeclaration = (ClassDeclarationSyntax)parent;
                    info = new TypeParameterInfo(typeParameter, classDeclaration, typeParameterList, classDeclaration.ConstraintClauses);
                    return(true);
                }

                case SyntaxKind.DelegateDeclaration:
                {
                    var delegateDeclaration = (DelegateDeclarationSyntax)parent;
                    info = new TypeParameterInfo(typeParameter, delegateDeclaration, typeParameterList, delegateDeclaration.ConstraintClauses);
                    return(true);
                }

                case SyntaxKind.InterfaceDeclaration:
                {
                    var interfaceDeclaration = (InterfaceDeclarationSyntax)parent;
                    info = new TypeParameterInfo(typeParameter, interfaceDeclaration, typeParameterList, interfaceDeclaration.ConstraintClauses);
                    return(true);
                }

                case SyntaxKind.LocalFunctionStatement:
                {
                    var localFunctionStatement = (LocalFunctionStatementSyntax)parent;
                    info = new TypeParameterInfo(typeParameter, localFunctionStatement, typeParameterList, localFunctionStatement.ConstraintClauses);
                    return(true);
                }

                case SyntaxKind.MethodDeclaration:
                {
                    var methodDeclaration = (MethodDeclarationSyntax)parent;
                    info = new TypeParameterInfo(typeParameter, methodDeclaration, typeParameterList, methodDeclaration.ConstraintClauses);
                    return(true);
                }

                case SyntaxKind.StructDeclaration:
                {
                    var structDeclaration = (StructDeclarationSyntax)parent;
                    info = new TypeParameterInfo(typeParameter, structDeclaration, typeParameterList, structDeclaration.ConstraintClauses);
                    return(true);
                }
                }
            }

            info = default(TypeParameterInfo);
            return(false);
        }
コード例 #19
0
        public override Evaluation VisitTypeParameter(TypeParameterSyntax node)
        {
            foreach (AttributeListSyntax listSyntax in node.AttributeLists)
            {
                listSyntax.Accept <Evaluation>(this);
            }

            return(base.VisitTypeParameter(node));
        }
コード例 #20
0
ファイル: LocalUsageGatherer.cs プロジェクト: zwmyint/Bridge
            public override void VisitTypeParameter(TypeParameterSyntax node)
            {
                var name = node.Identifier.Value.ToString();

                if (!this.UsedVariablesNames.Contains(name))
                {
                    this.UsedVariablesNames.Add(name);
                }
                base.VisitTypeParameter(node);
            }
コード例 #21
0
        /// <summary>
        /// build up a string of summary text for a generic type parameter.
        /// </summary>
        /// <param name="typeParameter">the type parameter.</param>
        /// <returns>the text describing it.</returns>
        public string BuildSummaryTextForTypeParameter(TypeParameterSyntax typeParameter)
        {
            var name = typeParameter.Identifier.Text;
            var sentence = this.SplitCamelCaseWords(name);
            var articleFree = this.RemoveArticles(sentence);
            if (string.IsNullOrEmpty(articleFree))
                articleFree = $"{{{typeParameter.Identifier.Text}}}";

            return $"a type of {string.Join(" ", articleFree)}.";
        }
コード例 #22
0
        public static string TypeParameter(TypeParameterSyntax param)
        {
            if (!(param.Parent.Parent is MethodDeclarationSyntax)) return param.Identifier.Text;

            var typeConstraints = ((MethodDeclarationSyntax)param.Parent.Parent).ConstraintClauses;
            var constraints = typeConstraints
                .FirstOrDefault(constr => constr.Name.Identifier.Text == param.Identifier.Text).Constraints;

            return "<" + param.Identifier.Text + ": " + string.Join(", ", constraints) + ">"; //TODO: check if this is the right syntax for multiple constraints
        }
コード例 #23
0
ファイル: WriteMethod.cs プロジェクト: WarrenFerrell/CsScala
        public static string TypeParameter(TypeParameterSyntax prm, IMethodSymbol methodSymbol, MethodDeclarationSyntax methodSyntax)
        {
            var identifier = Utility.TypeConstraints(prm, methodSyntax.ConstraintClauses);

            if (ClassTags.NeedsClassTag(methodSymbol, methodSyntax, prm.Identifier.ValueText))
            {
                identifier += ":ClassTag";
            }

            return(identifier);
        }
コード例 #24
0
 private TypeParameterInfo(
     TypeParameterSyntax typeParameter,
     SyntaxNode declaration,
     TypeParameterListSyntax typeParameterList,
     SyntaxList <TypeParameterConstraintClauseSyntax> constraintClauses)
 {
     TypeParameter     = typeParameter;
     Declaration       = declaration;
     TypeParameterList = typeParameterList;
     ConstraintClauses = constraintClauses;
 }
コード例 #25
0
        public static TypeParameterInfo Create(TypeParameterSyntax typeParameter)
        {
            TypeParameterInfo info;

            if (TryCreate(typeParameter, out info))
            {
                return(info);
            }

            throw new ArgumentException("", nameof(typeParameter));
        }
コード例 #26
0
ファイル: WriteType.cs プロジェクト: WarrenFerrell/CsScala
        private static string TypeParameter(TypeParameterSyntax type)
        {
            var ret = Utility.TypeConstraints(type, TypeState.Instance.Partials.SelectMany(z => z.Syntax.As <TypeDeclarationSyntax>().ConstraintClauses));

            if (ClassTags.NeedsClassTag(TypeState.Instance.Partials.First().Symbol, type.Identifier.ValueText))
            {
                ret += " :ClassTag";
            }

            return(ret);
        }
コード例 #27
0
        public static string TypeParameter(TypeParameterSyntax node)
        {
            var constraint = "";

            if (node.Parent.Parent is MethodDeclarationSyntax)
            {
                var typeConstraints = ((MethodDeclarationSyntax)node.Parent.Parent).ConstraintClauses;
                var constraints     = typeConstraints.FirstOrDefault(constr => SyntaxNode(constr.Name) == node.Identifier.Text).Constraints;
                constraint = ": " + string.Join(", ", constraints); //TODO: check if this is the right syntax for multiple constraints
            }
            return(node.Identifier.Text + constraint);
        }
コード例 #28
0
        public override SyntaxNode VisitTypeParameter(TypeParameterSyntax node)
        {
            var newNode = (TypeParameterSyntax)base.VisitTypeParameter(node);

            if (_replacementMap.TryGetValue(node, out object newValue))
            {
                return(newNode.WithIdentifier(SyntaxFactory.Identifier(newValue.ToString())));
            }
            else
            {
                return(newNode);
            }
        }
コード例 #29
0
        public static string TypeParameter(TypeParameterSyntax param)
        {
            if (!(param.Parent.Parent is MethodDeclarationSyntax))
            {
                return(param.Identifier.Text);
            }

            var typeConstraints = ((MethodDeclarationSyntax)param.Parent.Parent).ConstraintClauses;
            var constraints     = typeConstraints
                                  .FirstOrDefault(constr => constr.Name.Identifier.Text == param.Identifier.Text).Constraints;

            return("<" + param.Identifier.Text + ": " + string.Join(", ", constraints) + ">"); //TODO: check if this is the right syntax for multiple constraints
        }
コード例 #30
0
ファイル: WriteMethod.cs プロジェクト: NNNIC/haxe-test
        public static string TypeParameter(TypeParameterSyntax prm, IEnumerable <TypeParameterConstraintClauseSyntax> constraints)
        {
            var identifier = prm.Identifier.ValueText;

            var constraint = constraints.SingleOrDefault(o => o.Name.Identifier.ValueText == identifier);

            if (constraint == null)
            {
                return(identifier);
            }

            return(identifier + ": (" + string.Join(", ", constraint.Constraints.OfType <TypeConstraintSyntax>().ToList().Select(o => TypeProcessor.ConvertType(o.Type))) + ")");
        }
コード例 #31
0
ファイル: Utility.cs プロジェクト: FizzerWL/CsScala
        internal static string TypeConstraints(TypeParameterSyntax prm, IEnumerable <TypeParameterConstraintClauseSyntax> constraints)
        {
            var identifier = prm.Identifier.ValueText;

            var constraint = constraints.SingleOrDefault(o => o.Name.Identifier.ValueText == identifier);

            if (constraint != null)
            {
                return(identifier + string.Join("", constraint.Constraints.Select(TransformTypeConstraint)));
            }

            return(identifier);
        }
コード例 #32
0
        internal static TypeParameterInfo Create(TypeParameterSyntax typeParameter)
        {
            if (!(typeParameter.Parent is TypeParameterListSyntax typeParameterList))
            {
                return(Default);
            }

            SyntaxNode parent = typeParameterList.Parent;

            switch (parent?.Kind())
            {
            case SyntaxKind.ClassDeclaration:
            {
                var classDeclaration = (ClassDeclarationSyntax)parent;
                return(new TypeParameterInfo(typeParameter, classDeclaration, typeParameterList, classDeclaration.ConstraintClauses));
            }

            case SyntaxKind.DelegateDeclaration:
            {
                var delegateDeclaration = (DelegateDeclarationSyntax)parent;
                return(new TypeParameterInfo(typeParameter, delegateDeclaration, typeParameterList, delegateDeclaration.ConstraintClauses));
            }

            case SyntaxKind.InterfaceDeclaration:
            {
                var interfaceDeclaration = (InterfaceDeclarationSyntax)parent;
                return(new TypeParameterInfo(typeParameter, interfaceDeclaration, typeParameterList, interfaceDeclaration.ConstraintClauses));
            }

            case SyntaxKind.LocalFunctionStatement:
            {
                var localFunctionStatement = (LocalFunctionStatementSyntax)parent;
                return(new TypeParameterInfo(typeParameter, localFunctionStatement, typeParameterList, localFunctionStatement.ConstraintClauses));
            }

            case SyntaxKind.MethodDeclaration:
            {
                var methodDeclaration = (MethodDeclarationSyntax)parent;
                return(new TypeParameterInfo(typeParameter, methodDeclaration, typeParameterList, methodDeclaration.ConstraintClauses));
            }

            case SyntaxKind.StructDeclaration:
            {
                var structDeclaration = (StructDeclarationSyntax)parent;
                return(new TypeParameterInfo(typeParameter, structDeclaration, typeParameterList, structDeclaration.ConstraintClauses));
            }
            }

            return(Default);
        }
コード例 #33
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="node"></param>
 public override sealed void VisitTypeParameter(TypeParameterSyntax node)
 {
     this.OnNodeVisited(node, this.type.IsInstanceOfType(node));
     base.VisitTypeParameter(node);
 }
コード例 #34
0
 public TypeParameterTranslation(TypeParameterSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
 {
 }
コード例 #35
0
        /// <summary>
        /// Given a type parameter declaration (field or method), get the corresponding symbol
        /// </summary>
        /// <param name="typeParameter"></param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public override ITypeParameterSymbol GetDeclaredSymbol(TypeParameterSyntax typeParameter, CancellationToken cancellationToken = default(CancellationToken))
        {
            using (Logger.LogBlock(FunctionId.CSharp_SemanticModel_GetDeclaredSymbol, message: this.SyntaxTree.FilePath, cancellationToken: cancellationToken))
            {
                if (typeParameter == null)
                {
                    throw new ArgumentNullException("typeParameter");
                }

                if (!IsInTree(typeParameter))
                {
                    throw new ArgumentException("typeParameter not within tree");
                }

                var typeParamList = typeParameter.Parent as TypeParameterListSyntax;
                if (typeParamList != null)
                {
                    var memberDecl = typeParamList.Parent as MemberDeclarationSyntax;
                    if (memberDecl != null)
                    {
                        var symbol = GetDeclaredSymbol(memberDecl, cancellationToken);
                        if ((object)symbol != null)
                        {
                            var typeSymbol = symbol as NamedTypeSymbol;
                            if ((object)typeSymbol != null)
                            {
                                return this.GetTypeParameterSymbol(typeSymbol.TypeParameters, typeParameter);
                            }

                            var methodSymbol = symbol as MethodSymbol;
                            if ((object)methodSymbol != null)
                            {
                                return
                                    this.GetTypeParameterSymbol(methodSymbol.TypeParameters, typeParameter) ??
                                    ((object)methodSymbol.PartialDefinitionPart == null ? null : this.GetTypeParameterSymbol(methodSymbol.PartialDefinitionPart.TypeParameters, typeParameter));
                            }
                        }
                    }
                }

                return null;
            }
        }
コード例 #36
0
        /// <summary>
        /// Given a type parameter declaration (field or method), get the corresponding symbol
        /// </summary>
        /// <param name="typeParameter"></param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public override ITypeParameterSymbol GetDeclaredSymbol(TypeParameterSyntax typeParameter, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (typeParameter == null)
            {
                throw new ArgumentNullException(nameof(typeParameter));
            }

            if (!IsInTree(typeParameter))
            {
                throw new ArgumentException("typeParameter not within tree");
            }

            var typeParamList = typeParameter.Parent as TypeParameterListSyntax;
            if (typeParamList != null)
            {
                var memberDecl = typeParamList.Parent as MemberDeclarationSyntax;
                if (memberDecl != null)
                {
                    var symbol = GetDeclaredSymbol(memberDecl, cancellationToken);
                    if ((object)symbol != null)
                    {
                        var typeSymbol = symbol as NamedTypeSymbol;
                        if ((object)typeSymbol != null)
                        {
                            return this.GetTypeParameterSymbol(typeSymbol.TypeParameters, typeParameter);
                        }

                        var methodSymbol = symbol as MethodSymbol;
                        if ((object)methodSymbol != null)
                        {
                            return
                                this.GetTypeParameterSymbol(methodSymbol.TypeParameters, typeParameter) ??
                                ((object)methodSymbol.PartialDefinitionPart == null ? null : this.GetTypeParameterSymbol(methodSymbol.PartialDefinitionPart.TypeParameters, typeParameter));
                        }
                    }
                }
            }

            return null;
        }
コード例 #37
0
 public override void VisitTypeParameter(TypeParameterSyntax node)
 {
     this.Found |= node.Identifier.ValueText == this.name;
     base.VisitTypeParameter(node);
 }
コード例 #38
0
 public override ITypeParameterSymbol GetDeclaredSymbol(TypeParameterSyntax typeParameter, CancellationToken cancellationToken = default(CancellationToken))
 {
     // Can't define alias inside member.
     return null;
 }
コード例 #39
0
        public void VisitTypeParameter(TypeParameterSyntax node)
        {
            if (node == null)
                throw new ArgumentNullException("node");

            node.Validate();

            WriteAttributes(node, true);

            switch (node.Variance)
            {
                case Variance.In:
                    _writer.WriteKeyword(PrinterKeyword.In);
                    _writer.WriteSpace();
                    break;

                case Variance.Out:
                    _writer.WriteKeyword(PrinterKeyword.Out);
                    _writer.WriteSpace();
                    break;
            }

            _writer.WriteIdentifier(node.Identifier);
        }
コード例 #40
0
 /// <summary>
 /// Given a type parameter declaration (field or method), get the corresponding symbol
 /// </summary>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <param name="typeParameter"></param>
 public abstract ITypeParameterSymbol GetDeclaredSymbol(TypeParameterSyntax typeParameter, CancellationToken cancellationToken = default(CancellationToken));
コード例 #41
0
        private TypeParameterSymbol GetTypeParameterSymbol(ImmutableArray<TypeParameterSymbol> parameters, TypeParameterSyntax parameter)
        {
            foreach (var symbol in parameters)
            {
                foreach (var location in symbol.Locations)
                {
                    if (location.SourceTree == this.SyntaxTree && parameter.Span.Contains(location.SourceSpan))
                    {
                        return symbol;
                    }
                }
            }

            return null;
        }
コード例 #42
0
ファイル: GraphRunner.cs プロジェクト: YoloDev/srclib-csharp
    public override void VisitTypeParameter(TypeParameterSyntax node)
    {
      if (!node.Identifier.Span.IsEmpty)
      {
        var symbol = _sm.GetDeclaredSymbol(node);

        _defined.Add(symbol);

        var def = Def.For(symbol: symbol, type: "typeparam", name: symbol.Name)
          .At(_path, node.Identifier.Span);

        def.Local = true;

        AddDef(def);
      }

      base.VisitTypeParameter(node);
    }
コード例 #43
0
            private void ClassifyUpdate(TypeParameterSyntax oldNode, TypeParameterSyntax newNode)
            {
                if (!SyntaxFactory.AreEquivalent(oldNode.Identifier, newNode.Identifier))
                {
                    ReportError(RudeEditKind.Renamed);
                    return;
                }

                Debug.Assert(!SyntaxFactory.AreEquivalent(oldNode.VarianceKeyword, newNode.VarianceKeyword));
                ReportError(RudeEditKind.VarianceUpdate);
            }
コード例 #44
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="node"></param>
 public override sealed void VisitTypeParameter(TypeParameterSyntax node)
 {
     this.OnNodeVisited(node);
     if (!this.traverseRootOnly) base.VisitTypeParameter(node);
 }