public override SyntaxNode VisitTypeArgumentList(TypeArgumentListSyntax node) { node = (TypeArgumentListSyntax)base.VisitTypeArgumentList(node); TypeArgumentListSyntax original = node; bool didSomething = false; SeparatedSyntaxList <TypeSyntax> arguments = node.Arguments; for (int j = 0, i = 0; j < arguments.Count; j++) { SyntaxTriviaList leading = arguments[j].GetLeadingTrivia(); IdentifierNameSyntax typeName = arguments[j] as IdentifierNameSyntax; if (RemoveTestTriviaAnnotation(leading) || ((typeName != null) && suppressedTypeParameters.Contains(typeName.Identifier.Text))) { node = node.Update( node.LessThanToken, node.Arguments.RemoveAt(i), node.GreaterThanToken); didSomething = true; continue; } i++; } if (node.Arguments.Count == 0) { didSomething = true; node = null; } return(didSomething ? node : original); }
public static IEnumerable <SyntaxNode> BuildFunctionCall(this RoslynEcsTranslator translator, FunctionCallNodeModel call, IPortModel portModel) { if (call.MethodInfo == null) { yield break; } var instance = translator.BuildArgumentList(call, out var argumentList); var typeArgumentList = new List <TypeSyntax>(); if (call.MethodInfo.IsGenericMethod) { typeArgumentList.AddRange(call.TypeArguments.Select(t => IdentifierName(t.GetMetadata(translator.Stencil).Name))); } TypeArgumentListSyntax typeArgList = null; if (typeArgumentList.Any()) { typeArgList = TypeArgumentList(SingletonSeparatedList(typeArgumentList.First())); } var method = RoslynBuilder.MethodInvocation(call.MethodInfo.Name, call.MethodInfo, instance, argumentList, typeArgList); if (method is ExpressionSyntax exp && call.MethodInfo is MethodInfo mi && mi.ReturnType != typeof(void) && call.MethodInfo.DeclaringType.Namespace.StartsWith("UnityEngine")) { var key = call.DeclaringType.Name(translator.Stencil).ToPascalCase() + call.Title.ToPascalCase(); yield return(translator.context.GetCachedValue(key, exp, mi.ReturnType.GenerateTypeHandle(translator.Stencil))); }
/// <summary> /// If the member is generic, construct it with the CrefTypeParameterSymbols that should be in scope. /// </summary> private Symbol ConstructWithCrefTypeParameters(int arity, TypeArgumentListSyntax typeArgumentListSyntax, Symbol symbol) { if (arity > 0) { SeparatedSyntaxList <TypeSyntax> typeArgumentSyntaxes = typeArgumentListSyntax.Arguments; TypeSymbol[] typeArgumentSymbols = new TypeSymbol[arity]; DiagnosticBag unusedDiagnostics = DiagnosticBag.GetInstance(); for (int i = 0; i < arity; i++) { TypeSyntax typeArgumentSyntax = typeArgumentSyntaxes[i]; typeArgumentSymbols[i] = BindType(typeArgumentSyntax, unusedDiagnostics); // Should be in a WithCrefTypeParametersBinder. Debug.Assert(typeArgumentSyntax.ContainsDiagnostics || !typeArgumentSyntax.SyntaxTree.ReportDocumentationCommentDiagnostics() || (!unusedDiagnostics.HasAnyErrors() && typeArgumentSymbols[i] is CrefTypeParameterSymbol)); unusedDiagnostics.Clear(); } unusedDiagnostics.Free(); if (symbol.Kind == SymbolKind.Method) { symbol = ((MethodSymbol)symbol).Construct(typeArgumentSymbols); } else { Debug.Assert(symbol is NamedTypeSymbol); symbol = ((NamedTypeSymbol)symbol).Construct(typeArgumentSymbols); } } return(symbol); }
private static bool TryMatchGenericSyntaxNodeWithGivenSymbol(GenericNameSyntax genericName, ISymbol previewReturnTypeSymbol, [NotNullWhen(true)] out SyntaxNode?syntaxNode) { if (IsSyntaxToken(genericName.Identifier, previewReturnTypeSymbol)) { syntaxNode = genericName; return(true); } TypeArgumentListSyntax typeArgumentList = genericName.TypeArgumentList; foreach (TypeSyntax typeArgument in typeArgumentList.Arguments) { TypeSyntax typeArgumentElementType = GetElementTypeForNullableAndArrayTypeNodes(typeArgument); if (typeArgumentElementType is GenericNameSyntax innerGenericName) { if (TryMatchGenericSyntaxNodeWithGivenSymbol(innerGenericName, previewReturnTypeSymbol, out syntaxNode)) { return(true); } } if (IsIdentifierNameSyntax(typeArgumentElementType, previewReturnTypeSymbol)) { syntaxNode = typeArgumentElementType; return(true); } } syntaxNode = null; return(false); }
public static void AnalyzeGenericName(SyntaxNodeAnalysisContext context) { var genericName = (GenericNameSyntax)context.Node; if (!genericName.IsParentKind( SyntaxKind.QualifiedName, SyntaxKind.UsingDirective, SyntaxKind.NameMemberCref) && !IsWithinNameOfExpression(genericName, context.SemanticModel, context.CancellationToken)) { TypeArgumentListSyntax typeArgumentList = genericName.TypeArgumentList; if (typeArgumentList != null) { SeparatedSyntaxList <TypeSyntax> arguments = typeArgumentList.Arguments; if (arguments.Count == 1 && !arguments[0].IsKind(SyntaxKind.OmittedTypeArgument)) { var namedTypeSymbol = context.SemanticModel.GetSymbol(genericName, context.CancellationToken) as INamedTypeSymbol; if (namedTypeSymbol?.IsConstructedFrom(SpecialType.System_Nullable_T) == true) { context.ReportDiagnostic( DiagnosticDescriptors.SimplifyNullableOfT, genericName); } } } } }
public override void VisitTypeArgumentList(TypeArgumentListSyntax node) { foreach (var argument in node.Arguments) { var name = GetTypeName(argument); var argVisitor = new TypeArgumentListWalker(Cache, Reference); argVisitor.Visit(argument); var classDefinition = new ClassDefinition { TypeName = name, TypeParameters = argVisitor.Collection }; var className = classDefinition.Name; if (!Cache.ContainsKey(className)) { Cache.Add(className, classDefinition); } else { classDefinition = Cache[className]; } Reference.Add(className); this.Collection.Add(classDefinition); } }
public override SyntaxNode VisitTypeArgumentList(TypeArgumentListSyntax node) { var first = node.Arguments.First(); node = node.ReplaceNode(first, SyntaxFactory.ParseTypeName($"List<{InputType}>")); return(base.VisitTypeArgumentList(node)); }
public static IEnumerable <SyntaxNode> BuildFunctionCall(this RoslynTranslator translator, FunctionCallNodeModel call, IPortModel portModel) { if (call.MethodInfo == null) { yield break; } var instance = BuildArgumentList(translator, call, out var argumentList); var typeArgumentList = new List <TypeSyntax>(); if (call.MethodInfo.IsGenericMethod) { foreach (var typeArgument in call.TypeArguments) { typeArgumentList.Add(TypeSystem.BuildTypeSyntax(typeArgument.Resolve(translator.Stencil))); } } TypeArgumentListSyntax typeArgList = null; if (typeArgumentList.Any()) { typeArgList = SyntaxFactory.TypeArgumentList(SyntaxFactory.SingletonSeparatedList(typeArgumentList.First())); } SyntaxNode method = RoslynBuilder.MethodInvocation(call.Title, call.MethodInfo, instance, argumentList, typeArgList); yield return(method); }
private static TypeDeclaration BuildPropertyTypeFromGenericNameSyntax(GenericNameSyntax genericNameSyntax) { TypeArgumentListSyntax agrumentListSyntax = genericNameSyntax.TypeArgumentList; TypeDeclaration type = BuildPropertyTypeFromStandardSyntax(agrumentListSyntax.Arguments.First()); type.IsArray = true; return(type); }
public static Doc Print(TypeArgumentListSyntax node) { return(Doc.Concat( Token.Print(node.LessThanToken), Doc.Indent(SeparatedSyntaxList.Print(node.Arguments, Node.Print, Doc.Line)), Token.Print(node.GreaterThanToken) )); }
public new void AddChildren() { base.AddChildren(); Kind = Node.Kind(); _isUnboundGenericName = ((GenericNameSyntax)Node).IsUnboundGenericName; _isUnboundGenericNameIsChanged = false; _typeArgumentList = ((GenericNameSyntax)Node).TypeArgumentList; _typeArgumentListIsChanged = false; }
internal GenericNameSyntax(SyntaxToken identifer, TypeArgumentListSyntax argumentList) : base(SyntaxKind.GenericName) { Add (identifer); Add (argumentList); Identifier = identifer; TypeArgumentList = argumentList; }
internal static SignatureHelpState GetSignatureHelpState(TypeArgumentListSyntax argumentList, int position) { return CommonSignatureHelpUtilities.GetSignatureHelpState( argumentList, position, s_getTypeArgumentListOpenToken, s_getTypeArgumentListCloseToken, s_getTypeArgumentListArgumentsWithSeparators, s_getTypeArgumentListNames); }
internal static SignatureHelpState GetSignatureHelpState(TypeArgumentListSyntax argumentList, int position) { return(CommonSignatureHelpUtilities.GetSignatureHelpState( argumentList, position, s_getTypeArgumentListOpenToken, s_getTypeArgumentListCloseToken, s_getTypeArgumentListArgumentsWithSeparators, s_getTypeArgumentListNames)); }
public override void VisitTypeArgumentList(TypeArgumentListSyntax node) { foreach (TypeSyntax argument in node.Arguments) { argument.Accept(this); } base.VisitTypeArgumentList(node); }
public MethodDeclarationSyntax AsyncMethod(TypeArgumentListSyntax list, string name, BlockSyntax body) { var amethod = ParenthesizedLambdaExpression(body) .WithAsyncKeyword(Token(SyntaxKind.AsyncKeyword)); return MethodDeclaration( GenericName(Identifier("Task")) .WithTypeArgumentList(list), Identifier(name) ).WithBody(body).AddModifiers(Token(SyntaxKind.AsyncKeyword)); }
public override Evaluation VisitTypeArgumentList(TypeArgumentListSyntax node) { EvaluationList list = new EvaluationList(); foreach (TypeSyntax argument in node.Arguments) { list.Add(argument.Accept <Evaluation>(this)); } return(list); }
public static void Write(this TypeArgumentListSyntax syntax, IIndentedTextWriterWrapper textWriter, IContext context) { textWriter.Write("{"); syntax.Arguments.Write((argSyntax, argTextWriter, argContext) => { argSyntax.Write(argTextWriter, argContext); textWriter.Write(".__typeof"); }, textWriter, context); textWriter.Write("}"); }
/// <summary> /// Rewrites the type(s) to qualified names inside a list of generic type arguments. /// Primarily intended for the generic method Goto<StateType>(). /// </summary> private SyntaxNode RewriteStatement(TypeArgumentListSyntax node) { this.typeNameQualifier.InitializeForNode(node); var qualifiedNames = node.Arguments.Select(argType => this.typeNameQualifier.GetQualifiedName(argType, out _)); var qualifiedNamesCsv = string.Join(", ", qualifiedNames); var fakeGenericExpression = SyntaxFactory.ParseExpression($"X<{qualifiedNamesCsv}>") as GenericNameSyntax; var rewritten = node.WithArguments(fakeGenericExpression.TypeArgumentList.Arguments); return(rewritten); }
public override void VisitTypeArgumentList(TypeArgumentListSyntax node) { foreach (TypeSyntax type in node.Arguments) { if (!ShouldVisit) { return; } VisitType(type); } }
public static TypeSyntax ToTypeSyntax(this Type typeToConvert) { TypeSyntax ts; if (typeToConvert.IsArray) { var elementTypeSyntax = typeToConvert.GetElementType().ToTypeSyntax(); ts = SyntaxFactory.ArrayType(elementTypeSyntax) .WithRankSpecifiers( SyntaxFactory.SingletonList( SyntaxFactory.ArrayRankSpecifier( SyntaxFactory.SingletonSeparatedList <ExpressionSyntax>( SyntaxFactory.OmittedArraySizeExpression())))); } else if (typeToConvert.IsGenericType) { TypeArgumentListSyntax typeArgumentListSyntax = GenerateGenericTypeArgumentList(typeToConvert); string genericTypeName; if (!typeToConvert.IsVsArrayType()) { genericTypeName = GetFriendlyTypeName(typeToConvert); } else { genericTypeName = k_VSArrayReplacingTypeFriendlyName; } ts = SyntaxFactory.GenericName(SyntaxFactory.Identifier(genericTypeName)) .WithTypeArgumentList(typeArgumentListSyntax); } else { var roslynPredefKind = KindFromType(typeToConvert); if (roslynPredefKind != SyntaxKind.None) { ts = SyntaxFactory.PredefinedType(SyntaxFactory.Token(roslynPredefKind)); } else { if (typeToConvert.IsNested) { ts = SyntaxFactory.QualifiedName(SyntaxFactory.ParseName(typeToConvert.DeclaringType.FullName), SyntaxFactory.IdentifierName(typeToConvert.Name)); } else { ts = SyntaxFactory.ParseTypeName(typeToConvert.FullName); } } } return(ts); }
public static Task <Document> FixListAsync( Document document, TypeArgumentListSyntax typeArgumentList, ListFixMode fixMode = ListFixMode.Fix, CancellationToken cancellationToken = default) { return(FixListAsync( document, typeArgumentList, typeArgumentList.LessThanToken, typeArgumentList.Arguments, fixMode, cancellationToken)); }
public override SyntaxNode VisitTypeArgumentList(TypeArgumentListSyntax node) { var result = (base.VisitTypeArgumentList(node) as TypeArgumentListSyntax) !; // VisitQualifiedName doesn’t hit these var children = node.ChildNodes().OfType <NameSyntax>(); if (children.Count() > 0) { result = result.ReplaceNodes(children, (child, rewritten) => Reduce(child)); } return(result); }
private Doc PrintTypeArgumentListSyntax(TypeArgumentListSyntax node) { return(Concat( this.PrintSyntaxToken(node.LessThanToken), Indent( this.PrintSeparatedSyntaxList( node.Arguments, this.Print, Line ) ), this.PrintSyntaxToken(node.GreaterThanToken) )); }
private static NameSyntax GetReplacementGenericName(TypeSyntax symbolNameSyntax, GenericNameSyntax genericNameSyntax) { var symbolQualifiedNameSyntax = symbolNameSyntax as QualifiedNameSyntax; var symbolGenericNameSyntax = (GenericNameSyntax)(symbolQualifiedNameSyntax?.Right ?? symbolNameSyntax); TypeArgumentListSyntax newTypeArgumentList = GetReplacementTypeArgumentList(symbolGenericNameSyntax, genericNameSyntax); if (symbolQualifiedNameSyntax != null) { var newRightPart = ((GenericNameSyntax)symbolQualifiedNameSyntax.Right).WithTypeArgumentList(newTypeArgumentList); return(symbolQualifiedNameSyntax.WithRight(newRightPart)); } return(genericNameSyntax.WithTypeArgumentList(newTypeArgumentList)); }
public override void VisitTypeArgumentList(TypeArgumentListSyntax node) { if (!PreVisit(node)) { return; } foreach (TypeSyntax argument in node.Arguments) { argument.Accept(this); } base.VisitTypeArgumentList(node); PostVisit(node); }
public override void VisitTypeArgumentList(TypeArgumentListSyntax node) { if (debug) { Console.WriteLine(node.ToFullString()); } var nl = OurLine.NewLine(LineKind.Decl, "TypeArgumentList"); nl.Source = node.ToFullString(); OurLine.AddEssentialInfo(ref nl, "arguments:" + node.Arguments.ToString()); nl.ParentKind = node.Parent.RawKind; nl.RawKind = node.RawKind; LogCommand(nl); base.VisitTypeArgumentList(node); }
private static void AnalyzeNode( SyntaxNodeAnalysisContext context ) { var syntaxNode = context.Node as GenericNameSyntax; // Attributes are not allowed on local function parameters so we // have to ignore this node, otherwise we'll tell people to // annotate a declaration that is forbidden. if (syntaxNode.Ancestors().Any(a => a is LocalFunctionStatementSyntax)) { return; } SymbolInfo hostTypeSymbolInfo = context.SemanticModel.GetSymbolInfo(syntaxNode); var hostTypeSymbol = hostTypeSymbolInfo.Symbol as INamedTypeSymbol; if (hostTypeSymbol == default) { return; } TypeArgumentListSyntax typeArgumentNode = syntaxNode.TypeArgumentList; for (int index = 0; index < typeArgumentNode.Arguments.Count; index++) { ITypeParameterSymbol hostParameterSymbol = hostTypeSymbol.TypeParameters[index]; ImmutabilityScope declarationScope = hostParameterSymbol.GetImmutabilityScope(); if (declarationScope != ImmutabilityScope.SelfAndChildren) { continue; } SymbolInfo argumentSymbolInfo = context.SemanticModel.GetSymbolInfo(typeArgumentNode.Arguments[index]); var typeSymbol = argumentSymbolInfo.Symbol as ITypeSymbol; if (typeSymbol == default) { continue; } ValidateImmutability( context, typeSymbol ); } }
public static bool CanRefactor(RefactoringContext context, GenericNameSyntax genericName) { TypeArgumentListSyntax typeArgumentList = genericName.TypeArgumentList; if (typeArgumentList != null) { SeparatedSyntaxList <TypeSyntax> arguments = typeArgumentList.Arguments; if (arguments.Count == 1 && context.Span.IsBetweenSpans(arguments[0])) { return(true); } } return(false); }
/// <summary> /// Moves node to a new line, indents it and visit it using provided rewriter. /// </summary> protected SyntaxNode RewriteGenericNode(GenericNameSyntax node, BqlRewriterBase rewriter) { GenericNameSyntax newNode = OnNewLineAndIndented(node); if (newNode?.TypeArgumentList == null) { return(node); } TypeArgumentListSyntax newTypeArgsListNode = rewriter.Visit(newNode.TypeArgumentList) as TypeArgumentListSyntax; if (newTypeArgsListNode == null) { return(newNode); } return(newNode.WithTypeArgumentList(newTypeArgsListNode)); }
public static string GetFirstGenericArgument(this TypeArgumentListSyntax typeArgumentListSyntaxExtensions) { var childNodes = typeArgumentListSyntaxExtensions.ChildNodes(); foreach (var syntaxNode in childNodes) { if (syntaxNode is QualifiedNameSyntax) { return(string.Join(".", syntaxNode.ChildNodes().OfType <IdentifierNameSyntax>().Select(x => x.Identifier.ToString()))); } else if (syntaxNode is IdentifierNameSyntax) { return((syntaxNode as IdentifierNameSyntax).Identifier.ToString()); } } return(null); }
// indent is set by the containing VisitBlock public override SyntaxNode VisitTypeArgumentList(TypeArgumentListSyntax node) { var separatedSyntaxList = node.Arguments; if (!LineSpanNeedsWrapping(node, separatedSyntaxList)) { return(base.VisitTypeArgumentList(node)); } m_CurrentIndent += k_IndentSize; node = node .WithLessThanToken(SyntaxFactory.Token(SyntaxKind.LessThanToken).WithTrailingTrivia(SyntaxFactory.TriviaList(SyntaxFactory.LineFeed))) .WithArguments(FormatList(separatedSyntaxList)); var visited = base.VisitTypeArgumentList(node); m_CurrentIndent -= k_IndentSize; return(visited); }
public override void VisitTypeArgumentList(TypeArgumentListSyntax node) { if (_cancellationToken.IsCancellationRequested) { return; } if (_bqlDeepnessLevel == 0) { if (!_cancellationToken.IsCancellationRequested) { base.VisitTypeArgumentList(node); } return; } IClassificationType braceClassificationType = _tagger.Provider[_braceLevel]; try { _braceLevel = (_braceLevel + 1) % ColoringConstants.MaxBraceLevel; if (braceClassificationType != null && !_cancellationToken.IsCancellationRequested) { AddClassificationTag(node.LessThanToken.Span, braceClassificationType); AddClassificationTag(node.GreaterThanToken.Span, braceClassificationType); } if (!_cancellationToken.IsCancellationRequested) { base.VisitTypeArgumentList(node); } } finally { _braceLevel = _braceLevel == 0 ? ColoringConstants.MaxBraceLevel - 1 : _braceLevel - 1; } UpdateCodeEditorIfNecessary(); }
public MethodDeclarationSyntax AsyncMethod(TypeArgumentListSyntax list, string name, BlockSyntax body) { var amethod = SF.ParenthesizedLambdaExpression(body) .WithAsyncKeyword(Token(SyntaxKind.AsyncKeyword)); return MethodDeclaration( GenericName(Identifier("IAsyncOperation")) .WithTypeArgumentList(list), Identifier(name) ).AddBodyStatements( ReturnStatement().WithExpression( InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, InvocationExpression(MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName("Task"), IdentifierName("Run") )).WithArgumentList( ArgumentList().AddArguments(Argument(amethod)) ), IdentifierName("AsAsyncOperation") ) ))); }
/// <summary> /// /// </summary> /// <param name="node"></param> public override sealed void VisitTypeArgumentList(TypeArgumentListSyntax node) { this.OnNodeVisited(node); if (!this.traverseRootOnly) base.VisitTypeArgumentList(node); }
/// <summary> /// If the member is generic, construct it with the CrefTypeParameterSymbols that should be in scope. /// </summary> private Symbol ConstructWithCrefTypeParameters(int arity, TypeArgumentListSyntax typeArgumentListSyntax, Symbol symbol) { if (arity > 0) { SeparatedSyntaxList<TypeSyntax> typeArgumentSyntaxes = typeArgumentListSyntax.Arguments; TypeSymbol[] typeArgumentSymbols = new TypeSymbol[arity]; DiagnosticBag unusedDiagnostics = DiagnosticBag.GetInstance(); for (int i = 0; i < arity; i++) { TypeSyntax typeArgumentSyntax = typeArgumentSyntaxes[i]; typeArgumentSymbols[i] = BindType(typeArgumentSyntax, unusedDiagnostics); // Should be in a WithCrefTypeParametersBinder. Debug.Assert(typeArgumentSyntax.ContainsDiagnostics || !typeArgumentSyntax.SyntaxTree.ReportDocumentationCommentDiagnostics() || (!unusedDiagnostics.HasAnyErrors() && typeArgumentSymbols[i] is CrefTypeParameterSymbol)); unusedDiagnostics.Clear(); } unusedDiagnostics.Free(); if (symbol.Kind == SymbolKind.Method) { symbol = ((MethodSymbol)symbol).Construct(typeArgumentSymbols); } else { Debug.Assert(symbol is NamedTypeSymbol); symbol = ((NamedTypeSymbol)symbol).Construct(typeArgumentSymbols); } } return symbol; }
/// <summary> /// Replace any named type in the symbol list with its instance constructors. /// Construct all candidates with the implicitly-declared CrefTypeParameterSymbols. /// </summary> private void GetCrefOverloadResolutionCandidates(ImmutableArray<Symbol> symbols, int arity, TypeArgumentListSyntax typeArgumentListSyntax, ArrayBuilder<Symbol> candidates) { foreach (Symbol candidate in symbols) { Symbol constructedCandidate = ConstructWithCrefTypeParameters(arity, typeArgumentListSyntax, candidate); NamedTypeSymbol constructedCandidateType = constructedCandidate as NamedTypeSymbol; if ((object)constructedCandidateType == null) { // Construct before overload resolution so the signatures will match. candidates.Add(constructedCandidate); } else { candidates.AddRange(constructedCandidateType.InstanceConstructors); } } }
/// <summary> /// At this point, we have a list of viable symbols and no parameter list with which to perform /// overload resolution. We'll just return the first symbol, giving a diagnostic if there are /// others. /// Caveat: If there are multiple candidates and only one is from source, then the source symbol /// wins and no diagnostic is reported. /// </summary> private ImmutableArray<Symbol> ProcessParameterlessCrefMemberLookupResults( ImmutableArray<Symbol> symbols, int arity, MemberCrefSyntax memberSyntax, TypeArgumentListSyntax typeArgumentListSyntax, out Symbol ambiguityWinner, DiagnosticBag diagnostics) { // If the syntax indicates arity zero, then we match methods of any arity. // However, if there are both generic and non-generic methods, then the // generic methods should be ignored. if (symbols.Length > 1 && arity == 0) { bool hasNonGenericMethod = false; bool hasGenericMethod = false; foreach (Symbol s in symbols) { if (s.Kind != SymbolKind.Method) { continue; } if (((MethodSymbol)s).Arity == 0) { hasNonGenericMethod = true; } else { hasGenericMethod = true; } if (hasGenericMethod && hasNonGenericMethod) { break; //Nothing else to be learned. } } if (hasNonGenericMethod && hasGenericMethod) { symbols = symbols.WhereAsArray(s => s.Kind != SymbolKind.Method || ((MethodSymbol)s).Arity == 0); } } Debug.Assert(!symbols.IsEmpty); Symbol symbol = symbols[0]; // If there's ambiguity, prefer source symbols. // Logic is similar to ResultSymbol, but separate because the error handling is totally different. if (symbols.Length > 1) { // Size is known, but IndexOfSymbolFromCurrentCompilation expects a builder. ArrayBuilder<Symbol> unwrappedSymbols = ArrayBuilder<Symbol>.GetInstance(symbols.Length); foreach (Symbol wrapped in symbols) { unwrappedSymbols.Add(UnwrapAliasNoDiagnostics(wrapped)); } BestSymbolInfo secondBest; BestSymbolInfo best = GetBestSymbolInfo(unwrappedSymbols, out secondBest); Debug.Assert(!best.IsNone); Debug.Assert(!secondBest.IsNone); unwrappedSymbols.Free(); int symbolIndex = 0; if (best.IsFromCompilation) { symbolIndex = best.Index; symbol = symbols[symbolIndex]; // NOTE: symbols, not unwrappedSymbols. } if (symbol.Kind == SymbolKind.TypeParameter) { CrefSyntax crefSyntax = GetRootCrefSyntax(memberSyntax); diagnostics.Add(ErrorCode.WRN_BadXMLRefTypeVar, crefSyntax.Location, crefSyntax.ToString()); } else if (secondBest.IsFromCompilation == best.IsFromCompilation) { CrefSyntax crefSyntax = GetRootCrefSyntax(memberSyntax); int otherIndex = symbolIndex == 0 ? 1 : 0; diagnostics.Add(ErrorCode.WRN_AmbiguousXMLReference, crefSyntax.Location, crefSyntax.ToString(), symbol, symbols[otherIndex]); ambiguityWinner = ConstructWithCrefTypeParameters(arity, typeArgumentListSyntax, symbol); return symbols.SelectAsArray(sym => ConstructWithCrefTypeParameters(arity, typeArgumentListSyntax, sym)); } } else if (symbol.Kind == SymbolKind.TypeParameter) { CrefSyntax crefSyntax = GetRootCrefSyntax(memberSyntax); diagnostics.Add(ErrorCode.WRN_BadXMLRefTypeVar, crefSyntax.Location, crefSyntax.ToString()); } ambiguityWinner = null; return ImmutableArray.Create<Symbol>(ConstructWithCrefTypeParameters(arity, typeArgumentListSyntax, symbol)); }
/// <summary> /// Given a list of viable lookup results (based on the name, arity, and containing symbol), /// attempt to select one. /// </summary> private ImmutableArray<Symbol> ProcessCrefMemberLookupResults( ImmutableArray<Symbol> symbols, int arity, MemberCrefSyntax memberSyntax, TypeArgumentListSyntax typeArgumentListSyntax, BaseCrefParameterListSyntax parameterListSyntax, out Symbol ambiguityWinner, DiagnosticBag diagnostics) { Debug.Assert(!symbols.IsEmpty); if (parameterListSyntax == null) { return ProcessParameterlessCrefMemberLookupResults(symbols, arity, memberSyntax, typeArgumentListSyntax, out ambiguityWinner, diagnostics); } ArrayBuilder<Symbol> candidates = ArrayBuilder<Symbol>.GetInstance(); GetCrefOverloadResolutionCandidates(symbols, arity, typeArgumentListSyntax, candidates); ImmutableArray<ParameterSymbol> parameterSymbols = BindCrefParameters(parameterListSyntax, diagnostics); ImmutableArray<Symbol> results = PerformCrefOverloadResolution(candidates, parameterSymbols, arity, memberSyntax, out ambiguityWinner, diagnostics); candidates.Free(); // NOTE: This diagnostic is just a hint that might help fix a broken cref, so don't do // any work unless there are no viable candidates. if (results.Length == 0) { for (int i = 0; i < parameterSymbols.Length; i++) { if (ContainsNestedTypeOfUnconstructedGenericType(parameterSymbols[i].Type)) { // This warning is new in Roslyn, because our better-defined semantics for // cref lookup disallow some things that were possible in dev12. // // Consider the following code: // // public class C<T> // { // public class Inner { } // // public void M(Inner i) { } // // /// <see cref="M"/> // /// <see cref="C{T}.M"/> // /// <see cref="C{Q}.M"/> // /// <see cref="C{Q}.M(C{Q}.Inner)"/> // /// <see cref="C{Q}.M(Inner)"/> // WRN_UnqualifiedNestedTypeInCref // public void N() { } // } // // Dev12 binds all of the crefs as "M:C`1.M(C{`0}.Inner)". // Roslyn accepts all but the last. The issue is that the context for performing // the lookup is not C<Q>, but C<T>. Consequently, Inner binds to C<T>.Inner and // then overload resolution fails because C<T>.Inner does not match C<Q>.Inner, // the parameter type of C<Q>.M. Since we could not agree that the old behavior // was desirable (other than for backwards compatibility) and since mimicking it // would have been expensive, we settled on introducing a new warning that at // least hints to the user how then can work around the issue (i.e. by qualifying // Inner as C{Q}.Inner). Additional details are available in DevDiv #743425. // // CONSIDER: We could actually put the qualified form in the warning message, // but that would probably just make it more frustrating (i.e. if the compiler // knows exactly what I mean, why do I have to type it). // // NOTE: This is not a great location (whole parameter instead of problematic type), // but it's better than nothing. diagnostics.Add(ErrorCode.WRN_UnqualifiedNestedTypeInCref, parameterListSyntax.Parameters[i].Location); break; } } } return results; }
public void VisitTypeArgumentList(TypeArgumentListSyntax node) { if (node == null) throw new ArgumentNullException("node"); node.Validate(); if (_writer.Configuration.Spaces.BeforeParentheses.BeforeTypeArgumentListAngle) _writer.WriteSpace(); _writer.WriteSyntax(Syntax.LessThan); if (_writer.Configuration.Spaces.WithinParentheses.TypeArgumentAngles) _writer.WriteSpace(); bool hadOne = false; foreach (var argument in node.Arguments) { if (hadOne) _writer.WriteListSeparator(); else hadOne = true; argument.Accept(this); } if (_writer.Configuration.Spaces.WithinParentheses.TypeArgumentAngles) _writer.WriteSpace(); _writer.WriteSyntax(Syntax.GreaterThan); }
public TypeArgumentListTranslation(TypeArgumentListSyntax syntax, SyntaxTranslation parent) : base(syntax, parent) { Arguments = syntax.Arguments.Get<TypeSyntax, TypeTranslation>(this); }
public static GenericNameSyntax GenericName(SyntaxToken identifier, TypeArgumentListSyntax typeArgumentList) { return new GenericNameSyntax (identifier, typeArgumentList); }
public static string TypeArgumentList(TypeArgumentListSyntax list) { return "<" + string.Join(", ", list.Arguments.Select(SyntaxNode)) + ">"; }
/// <summary> /// /// </summary> /// <param name="node"></param> public override sealed void VisitTypeArgumentList(TypeArgumentListSyntax node) { this.OnNodeVisited(node, this.type.IsInstanceOfType(node)); base.VisitTypeArgumentList(node); }
internal static TextSpan GetSignatureHelpSpan(TypeArgumentListSyntax argumentList) { return CommonSignatureHelpUtilities.GetSignatureHelpSpan(argumentList, s_getTypeArgumentListCloseToken); }