public override ValueTask <TResult> Visit(ISymbol symbol) { #pragma warning disable CA2012 // Use ValueTasks correctly (https://github.com/dotnet/roslyn-analyzers/issues/3384) return(symbol?.Accept(this) ?? new ValueTask <TResult>(DefaultResult)); #pragma warning restore CA2012 // Use ValueTasks correctly }
public virtual void Visit(ISymbol symbol) { if (symbol != null) { symbol.Accept(this); } }
public static string GetSpecId( ISymbol symbol, IReadOnlyList<string> typeGenericParameters, IReadOnlyList<string> methodGenericParameters = null) { var id = symbol.Accept(SpecIdCoreVisitor.Instance); if (methodGenericParameters == null) { id = SpecMethodGenericParameter(symbol as IMethodSymbol ?? symbol.ContainingSymbol as IMethodSymbol, id); } else { id = SpecMethodGenericParameter(methodGenericParameters, id); } id = SpecTypeGenericParameter(typeGenericParameters, id); return id; }
protected override void GenerateReference(ISymbol symbol, ReferenceItem reference, SymbolVisitorAdapter adapter) { symbol.Accept(new VBReferenceItemVisitor(reference)); }
public override ValueTask <TResult> Visit(ISymbol?symbol) => symbol?.Accept(this) ?? ValueTaskFactory.FromResult(DefaultResult);
public virtual TResult Visit(ISymbol symbol) { return(symbol == null ? default(TResult) : symbol.Accept(this)); }
protected override void GenerateReference(ISymbol symbol, ReferenceItem reference, SymbolVisitorAdapter adapter, bool asOverload) { symbol.Accept(new CSReferenceItemVisitor(reference, asOverload)); }
public virtual void Visit(ISymbol?symbol) { symbol?.Accept(this); }
public Unit Visit(ISymbol symbol) { symbol.Accept(this); return(Unit.Value); }
public override ExpressionSyntax DefaultVisit(ISymbol symbol) => symbol.Accept(TypeSyntaxGeneratorVisitor.Create());
public void Accept(SymbolVisitor visitor) => _symbol.Accept(visitor);
public string GetName(ISymbol symbol) { var visitor = Create(); symbol.Accept(visitor); return visitor.GetTypeName(); }
protected override void GenerateReference(ISymbol symbol, ReferenceItem reference, SymbolVisitorAdapter adapter) { symbol.Accept(new CSReferenceItemVisitor(reference)); }
public IEnumerable <DocumentSymbol> Visit(ISymbol symbol) { _cancellationToken.ThrowIfCancellationRequested(); return(symbol.Accept(this)); }
private string GenerateGlyphs(IEnumerable <Classification.Range> ranges) { if (!SolutionGenerator.LoadPlugins) { return(""); } var lines = new Dictionary <int, HashSet <string> >(); int lineNumber = -1; ISymbol symbol = null; Dictionary <string, string> context = new Dictionary <string, string> { { MEF.ContextKeys.FilePath, Document.FilePath }, { MEF.ContextKeys.LineNumber, "-1" } }; Action <string> maybeLog = g => { if (!string.IsNullOrWhiteSpace(g)) { HashSet <string> lineGlyphs; if (!lines.TryGetValue(lineNumber, out lineGlyphs)) { lineGlyphs = new HashSet <string>(); lines.Add(lineNumber, lineGlyphs); } lineGlyphs.Add(g); } }; Func <MEF.ITextVisitor, string> VisitText = v => { try { return(v.Visit(Text.Lines[lineNumber - 1].ToString(), context)); } catch (Exception ex) { Log.Write("Exception in text visitor: " + ex.Message); return(null); } }; Func <MEF.ISymbolVisitor, string> VisitSymbol = v => { try { return(symbol.Accept(new MEF.SymbolVisitorWrapper(v, context))); } catch (Exception ex) { Log.Write("Exception in symbol visitor: " + ex.Message); return(null); } }; foreach (var r in ranges) { var pos = r.ClassifiedSpan.TextSpan.Start; var token = Root.FindToken(pos, true); var nextLineNumber = token.SyntaxTree.GetLineSpan(token.Span).StartLinePosition.Line + 1; if (nextLineNumber != lineNumber) { lineNumber = nextLineNumber; context[MEF.ContextKeys.LineNumber] = lineNumber.ToString(); maybeLog(string.Concat(projectGenerator.PluginTextVisitors.Select(VisitText))); } symbol = SemanticModel.GetDeclaredSymbol(token.Parent); if (symbol != null) { maybeLog(string.Concat(projectGenerator.PluginSymbolVisitors.Select(VisitSymbol))); } } if (lines.Any()) { var sb = new StringBuilder(); for (var i = 1; i <= lines.Keys.Max(); i++) { HashSet <string> glyphs; if (lines.TryGetValue(i, out glyphs)) { foreach (var g in glyphs) { sb.Append(g); } } sb.Append("<br/>"); } return(sb.ToString()); } else { return(string.Empty); } }
public override ValueTask <TResult> Visit(ISymbol symbol) { return(symbol?.Accept(this) ?? new ValueTask <TResult>(DefaultResult)); }
internal void WriteSymbolKey(ISymbol symbol) { WriteSpace(); if (symbol == null) { WriteType(SymbolKeyType.Null); return; } int id; var shouldWriteOrdinal = ShouldWriteTypeParameterOrdinal(symbol, out _); if (!shouldWriteOrdinal) { if (_symbolToId.TryGetValue(symbol, out id)) { StartKey(); WriteType(SymbolKeyType.Reference); WriteInteger(id); EndKey(); return; } } id = _nextId; _nextId++; StartKey(); if (BodyLevelSymbolKey.IsBodyLevelSymbol(symbol)) { WriteType(SymbolKeyType.BodyLevel); BodyLevelSymbolKey.Create(symbol, this); } else { symbol.Accept(this); } if (!shouldWriteOrdinal) { // Note: it is possible in some situations to hit the same symbol // multiple times. For example, if you have: // // Goo<Z>(List<Z> list) // // If we start with the symbol for "list" then we'll see the following // chain of symbols hit: // // List<Z> // Z // Goo<Z>(List<Z>) // List<Z> // // The recursion is prevented because when we hit 'Goo' we mark that // we're writing out a signature. And, in signature mode we only write // out the ordinal for 'Z' without recursing. However, even though // we prevent the recursion, we still hit List<Z> twice. After writing // the innermost one out, we'll give it a reference ID. When we // then hit the outermost one, we want to just reuse that one. if (_symbolToId.TryGetValue(symbol, out var existingId)) { // While we recursed, we already hit this symbol. Use its ID as our // ID. id = existingId; } else { // Haven't hit this symbol before, write out its fresh ID. _symbolToId.Add(symbol, id); } } // Now write out the ID for this symbol so that any future hits of it can // write out a reference to it instead. WriteInteger(id); EndKey(); }
private static ImmutableArray<SymbolDisplayPart> ToDisplayParts( ISymbol symbol, SemanticModel semanticModelOpt, int positionOpt, SymbolDisplayFormat format, bool minimal) { if (symbol == null) { throw new ArgumentNullException(nameof(symbol)); } if (minimal) { if (semanticModelOpt == null) { throw new ArgumentException(CSharpResources.SyntaxTreeSemanticModelMust); } else if (positionOpt < 0 || positionOpt > semanticModelOpt.SyntaxTree.Length) // Note: not >= since EOF is allowed. { throw new ArgumentOutOfRangeException(CSharpResources.PositionNotWithinTree); } } else { Debug.Assert(semanticModelOpt == null); Debug.Assert(positionOpt < 0); } var builder = ArrayBuilder<SymbolDisplayPart>.GetInstance(); var visitor = new SymbolDisplayVisitor(builder, format, semanticModelOpt, positionOpt); symbol.Accept(visitor); return builder.ToImmutableAndFree(); }
public override ExpressionSyntax DefaultVisit(ISymbol symbol) { return(symbol.Accept(TypeSyntaxGeneratorVisitor.Instance)); }
/// <summary> /// Returns true if this symbol contains anything unsafe within it. for example /// List<int*[]> is unsafe, as it "int* Foo { get; }" /// </summary> public static bool IsUnsafe(this ISymbol member) { // TODO(cyrusn): Defer to compiler code to handle this once it can. return(member?.Accept(new IsUnsafeVisitor()) == true); }
public override string DefaultVisit(ISymbol symbol) { var segments = symbol.Accept(new SymbolNameSegments()); return(string.Join(".", segments)); }