コード例 #1
0
 internal ReferenceLocation(Document document, IAliasSymbol alias, Location location, bool isImplicit, ValueUsageInfo valueUsageInfo, CandidateReason candidateReason)
     : this()
 {
     this.Document        = document;
     this.Alias           = alias;
     this.Location        = location;
     this.IsImplicit      = isImplicit;
     this.ValueUsageInfo  = valueUsageInfo;
     this.CandidateReason = candidateReason;
 }
コード例 #2
0
 internal ReferenceLocation(Document document, IAliasSymbol alias, Location location, bool isImplicit, bool isWrittenTo, CandidateReason candidateReason)
     : this()
 {
     this.Document        = document;
     this.Alias           = alias;
     this.Location        = location;
     this.IsImplicit      = isImplicit;
     this.IsWrittenTo     = isWrittenTo;
     this.CandidateReason = candidateReason;
 }
コード例 #3
0
 public TokenSemanticInfo(
     ISymbol declaredSymbol,
     IAliasSymbol aliasSymbol,
     ImmutableArray <ISymbol> referencedSymbols,
     ITypeSymbol type)
 {
     DeclaredSymbol    = declaredSymbol;
     AliasSymbol       = aliasSymbol;
     ReferencedSymbols = referencedSymbols;
     Type = type;
 }
コード例 #4
0
        public override void VisitAlias(IAliasSymbol symbol)
        {
            builder.Add(CreatePart(SymbolDisplayPartKind.AliasName, symbol, symbol.Name));

            if (format.LocalOptions.IncludesOption(SymbolDisplayLocalOptions.IncludeType))
            {
                // ???
                AddPunctuation(SyntaxKind.EqualsToken);
                symbol.Target.Accept(this);
            }
        }
コード例 #5
0
 internal ReferenceLocation(Document document, IAliasSymbol alias, Location location, bool isImplicit, SymbolUsageInfo symbolUsageInfo, ImmutableArray <FindUsageProperty> additionalProperties, CandidateReason candidateReason)
     : this()
 {
     this.Document             = document;
     this.Alias                = alias;
     this.Location             = location;
     this.IsImplicit           = isImplicit;
     this.SymbolUsageInfo      = symbolUsageInfo;
     this.FindUsagesProperties = additionalProperties.NullToEmpty();
     this.CandidateReason      = candidateReason;
 }
コード例 #6
0
 internal ReferenceLocation(Document document, IAliasSymbol alias, Location location, bool isImplicit, SymbolUsageInfo symbolUsageInfo, ImmutableDictionary <string, string> additionalProperties, CandidateReason candidateReason)
     : this()
 {
     this.Document             = document;
     this.Alias                = alias;
     this.Location             = location;
     this.IsImplicit           = isImplicit;
     this.SymbolUsageInfo      = symbolUsageInfo;
     this.AdditionalProperties = additionalProperties ?? ImmutableDictionary <string, string> .Empty;
     this.CandidateReason      = candidateReason;
 }
コード例 #7
0
            public override SyntaxNode VisitIdentifierName(IdentifierNameSyntax node)
            {
                IAliasSymbol aliasSymbol = SemanticModel.GetAliasInfo(node, CancellationToken);

                if (SymbolEqualityComparer.Default.Equals(aliasSymbol, AliasSymbol))
                {
                    return(Replacement
                           .WithTriviaFrom(node)
                           .WithSimplifierAnnotation());
                }

                return(base.VisitIdentifierName(node));
            }
コード例 #8
0
        private static bool IsFixable(SyntaxNodeAnalysisContext context, TypeSyntax name)
        {
            var typeSymbol = context.SemanticModel.GetSymbol(name, context.CancellationToken) as ITypeSymbol;

            if (typeSymbol?.SupportsPredefinedType() == true)
            {
                IAliasSymbol aliasSymbol = context.SemanticModel.GetAliasInfo(name, context.CancellationToken);

                return(aliasSymbol == null);
            }

            return(false);
        }
 public NameDeclarationInfo(
     ImmutableArray <SymbolKind> possibleSymbolKinds,
     Accessibility accessibility,
     DeclarationModifiers declarationModifiers,
     ITypeSymbol type,
     IAliasSymbol alias)
 {
     PossibleSymbolKinds   = possibleSymbolKinds;
     DeclaredAccessibility = accessibility;
     Modifiers             = declarationModifiers;
     Type  = type;
     Alias = alias;
 }
コード例 #10
0
        private static void AnalyzeIdentifierName(SyntaxNodeAnalysisContext context)
        {
            var identifierName = (IdentifierNameSyntax)context.Node;

            if (identifierName.IsVar)
            {
                return;
            }

            if (identifierName.IsParentKind(
                    SyntaxKind.SimpleMemberAccessExpression,
                    SyntaxKind.QualifiedName,
                    SyntaxKind.UsingDirective))
            {
                return;
            }

            if (!SupportsPredefinedType(identifierName))
            {
                return;
            }

            if (identifierName.IsPartOfDocumentationComment())
            {
                return;
            }

            if (IsArgumentExpressionOfNameOfExpression(context, identifierName))
            {
                return;
            }

            if (!(context.SemanticModel.GetSymbol(identifierName, context.CancellationToken) is ITypeSymbol typeSymbol))
            {
                return;
            }

            if (!CSharpFacts.IsPredefinedType(typeSymbol.SpecialType))
            {
                return;
            }

            IAliasSymbol aliasSymbol = context.SemanticModel.GetAliasInfo(identifierName, context.CancellationToken);

            if (aliasSymbol != null)
            {
                return;
            }

            ReportDiagnostic(context, identifierName);
        }
        public static IEnumerable <ReferencedSymbol> FilterToAliasMatches(
            this IEnumerable <ReferencedSymbol> result,
            IAliasSymbol aliasSymbolOpt)
        {
            if (aliasSymbolOpt == null)
            {
                return(result);
            }

            return(from r in result
                   let aliasLocations = r.Locations.Where(loc => SymbolEquivalenceComparer.Instance.Equals(loc.Alias, aliasSymbolOpt))
                                        where aliasLocations.Any()
                                        select new ReferencedSymbol(r.DefinitionAndProjectId, aliasLocations));
        }
コード例 #12
0
        public static IEnumerable<ReferencedSymbol> FilterToAliasMatches(
            this IEnumerable<ReferencedSymbol> result,
            IAliasSymbol aliasSymbolOpt)
        {
            if (aliasSymbolOpt == null)
            {
                return result;
            }

            return from r in result
                   let aliasLocations = r.Locations.Where(loc => SymbolEquivalenceComparer.Instance.Equals(loc.Alias, aliasSymbolOpt))
                   where aliasLocations.Any()
                   select new ReferencedSymbol(r.Definition, aliasLocations);
        }
コード例 #13
0
 public TokenSemanticInfo(
     ISymbol declaredSymbol,
     IAliasSymbol aliasSymbol,
     ImmutableArray <ISymbol> referencedSymbols,
     ITypeSymbol type,
     ITypeSymbol convertedType,
     TextSpan span)
 {
     DeclaredSymbol    = declaredSymbol;
     AliasSymbol       = aliasSymbol;
     ReferencedSymbols = referencedSymbols;
     Type          = type;
     ConvertedType = convertedType;
     Span          = span;
 }
コード例 #14
0
        public static bool TryGetAliasSymbol(SemanticModel semanticModel, int namespaceId, INamespaceOrTypeSymbol targetSymbol, out IAliasSymbol aliasSymbol)
        {
            // TODO: given semantic model must be not speculative semantic model for now. 
            // currently it can't be checked since it is not exposed to common layer yet.
            // once exposed, this method itself will make sure it use original semantic model
            aliasSymbol = null;
            if (!s_treeAliasMap.TryGetValue(semanticModel.Compilation, out var treeMap) ||
                !treeMap.TryGetValue((semanticModel.SyntaxTree, namespaceId), out var symbolMap))
            {
                return false;
            }

            symbolMap.TryGetValue(targetSymbol, out aliasSymbol);
            return true;
        }
コード例 #15
0
            internal static ImmutableArray <Words> GetBaseNames(IAliasSymbol alias)
            {
                var name = alias.Name;

                if (alias.Target.IsType && (((INamedTypeSymbol)alias.Target).IsInterfaceType() &&
                                            CanRemoveInterfacePrefix(name)))
                {
                    name = name.Substring(1);
                }

                var breaks = StringBreaker.GetWordParts(name);
                var result = GetInterleavedPatterns(breaks, name, pluralize: false);

                breaks.Free();
                return(result);
            }
            internal static ImmutableArray <Words> GetBaseNames(IAliasSymbol alias)
            {
                var name = alias.Name;

                if (alias.Target.IsType &&
                    ((INamedTypeSymbol)alias.Target).IsInterfaceType() &&
                    CanRemoveInterfacePrefix(name))
                {
                    name = name.Substring(1);
                }

                using var breaks = TemporaryArray <TextSpan> .Empty;
                StringBreaker.AddWordParts(name, ref breaks.AsRef());
                var result = GetInterleavedPatterns(breaks, name, pluralize: false);

                return(result);
            }
コード例 #17
0
        public static async Task <Document> RefactorAsync(
            Document document,
            UsingDirectiveSyntax usingDirective,
            CancellationToken cancellationToken)
        {
            SemanticModel semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);

            IAliasSymbol aliasSymbol = semanticModel.GetDeclaredSymbol(usingDirective, cancellationToken);

            SyntaxNode parent = usingDirective.Parent;

            Debug.Assert(parent.IsKind(SyntaxKind.CompilationUnit, SyntaxKind.NamespaceDeclaration), "");

            SyntaxList <UsingDirectiveSyntax> usings = GetUsings(parent);

            int index = usings.IndexOf(usingDirective);

            List <IdentifierNameSyntax> names = CollectNames(parent, aliasSymbol, semanticModel, cancellationToken);

            NameSyntax name = usingDirective.Name;

            ISymbol symbol = semanticModel.GetSymbol(name, cancellationToken);

            SyntaxNode newNode = parent.ReplaceNodes(names, (f, _) =>
            {
                if (symbol != null &&
                    semanticModel
                    .GetSpeculativeSymbolInfo(f.SpanStart, name, SpeculativeBindingOption.BindAsTypeOrNamespace)
                    .Symbol?
                    .Equals(symbol) == true)
                {
                    return(name.WithTriviaFrom(f));
                }
                else
                {
                    return(aliasSymbol.Target.ToMinimalTypeSyntax(semanticModel, f.SpanStart).WithTriviaFrom(f));
                }
            });

            newNode = RemoveUsingDirective(newNode, index);

            return(await document.ReplaceNodeAsync(parent, newNode, cancellationToken).ConfigureAwait(false));
        }
コード例 #18
0
        private static TokenSemanticInfo GetSemanticInfo(
            SemanticModelBase semanticModel,
            ISemanticFactsService semanticFacts,
            ISyntaxFactsService syntaxFacts,
            ISyntaxToken token,
            CancellationToken cancellationToken)
        {
            //var aliasSymbol = semanticModel.GetAliasInfo(token.Parent, cancellationToken);
            IAliasSymbol aliasSymbol = null;

            var bindableParent = syntaxFacts.GetBindableParent(token);
            var type           = semanticModel.GetTypeInfo(bindableParent).Type;

            var declaredSymbol = semanticFacts.GetDeclaredSymbol(semanticModel, token, cancellationToken);
            var allSymbols     = semanticModel.GetSymbolInfo(bindableParent)
                                 .GetBestOrAllSymbols()
                                 .WhereAsArray(s => !s.Equals(declaredSymbol))
                                 .SelectAsArray(s => s);

            return(new TokenSemanticInfo(declaredSymbol, aliasSymbol, allSymbols, type));
        }
コード例 #19
0
        public static void Analyze(SyntaxNodeAnalysisContext context, IdentifierNameSyntax identifierName)
        {
            if (!identifierName.IsVar &&
                !identifierName.IsParentKind(
                    SyntaxKind.SimpleMemberAccessExpression,
                    SyntaxKind.QualifiedName,
                    SyntaxKind.UsingDirective))
            {
                var typeSymbol = context.SemanticModel.GetSymbol(identifierName, context.CancellationToken) as ITypeSymbol;

                if (typeSymbol?.SupportsPredefinedType() == true)
                {
                    IAliasSymbol aliasSymbol = context.SemanticModel.GetAliasInfo(identifierName, context.CancellationToken);

                    if (aliasSymbol == null)
                    {
                        ReportDiagnostic(context, identifierName);
                    }
                }
            }
        }
コード例 #20
0
ファイル: ReferenceLocation.cs プロジェクト: belav/roslyn
 internal ReferenceLocation(
     Document document,
     IAliasSymbol alias,
     Location location,
     bool isImplicit,
     SymbolUsageInfo symbolUsageInfo,
     ImmutableDictionary <string, string> additionalProperties,
     CandidateReason candidateReason
     )
     : this(
         document,
         alias,
         location,
         isImplicit,
         symbolUsageInfo,
         additionalProperties,
         candidateReason,
         containingStringLocation : Location.None
         )
 {
 }
        protected static ITypeSymbol GetSymbolType(ISymbol symbol)
        {
            ILocalSymbol localSymbol = symbol as ILocalSymbol;

            if (localSymbol != null)
            {
                return(localSymbol.Type);
            }

            IFieldSymbol fieldSymbol = symbol as IFieldSymbol;

            if (fieldSymbol != null)
            {
                return(fieldSymbol.Type);
            }

            IPropertySymbol propertySymbol = symbol as IPropertySymbol;

            if (propertySymbol != null)
            {
                return(propertySymbol.Type);
            }

            IParameterSymbol parameterSymbol = symbol as IParameterSymbol;

            if (parameterSymbol != null)
            {
                return(parameterSymbol.Type);
            }

            IAliasSymbol aliasSymbol = symbol as IAliasSymbol;

            if (aliasSymbol != null)
            {
                return(aliasSymbol.Target as ITypeSymbol);
            }

            return(symbol as ITypeSymbol);
        }
コード例 #22
0
        public static async Task <Document> RefactorAsync(
            Document document,
            UsingDirectiveSyntax usingDirective,
            CancellationToken cancellationToken)
        {
            SemanticModel semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);

            IAliasSymbol aliasSymbol = semanticModel.GetDeclaredSymbol(usingDirective, cancellationToken);

            SyntaxNode parent = usingDirective.Parent;

            Debug.Assert(parent.IsKind(SyntaxKind.CompilationUnit, SyntaxKind.NamespaceDeclaration), "");

            int index = SyntaxInfo.UsingDirectiveListInfo(parent).IndexOf(usingDirective);

            var rewriter = new Rewriter(aliasSymbol, aliasSymbol.Target.ToTypeSyntax(), semanticModel, cancellationToken);

            SyntaxNode newNode = rewriter.Visit(parent);

            newNode = RemoveUsingDirective(newNode, index);

            return(await document.ReplaceNodeAsync(parent, newNode, cancellationToken).ConfigureAwait(false));
        }
コード例 #23
0
        private static List <IdentifierNameSyntax> CollectNames(
            SyntaxNode node,
            IAliasSymbol aliasSymbol,
            SemanticModel semanticModel,
            CancellationToken cancellationToken)
        {
            var names = new List <IdentifierNameSyntax>();

            foreach (SyntaxNode descendant in node.DescendantNodes())
            {
                if (descendant.Kind() == SyntaxKind.IdentifierName)
                {
                    IAliasSymbol symbol = semanticModel.GetAliasInfo(descendant, cancellationToken);

                    if (symbol?.Equals(aliasSymbol) == true)
                    {
                        names.Add((IdentifierNameSyntax)descendant);
                    }
                }
            }

            return(names);
        }
コード例 #24
0
        public static void Analyze(SyntaxNodeAnalysisContext context, MemberAccessExpressionSyntax memberAccess)
        {
            if (!memberAccess.IsParentKind(SyntaxKind.SimpleMemberAccessExpression))
            {
                ExpressionSyntax expression = memberAccess.Expression;

                if (expression?.IsKind(
                        SyntaxKind.SimpleMemberAccessExpression,
                        SyntaxKind.IdentifierName) == true)
                {
                    var typeSymbol = context.SemanticModel.GetSymbol(expression, context.CancellationToken) as ITypeSymbol;

                    if (typeSymbol?.SupportsPredefinedType() == true)
                    {
                        IAliasSymbol aliasSymbol = context.SemanticModel.GetAliasInfo(expression, context.CancellationToken);

                        if (aliasSymbol == null)
                        {
                            ReportDiagnostic(context, expression);
                        }
                    }
                }
            }
        }
 public override void VisitAlias(IAliasSymbol symbol)
 {
     // TODO(cyrusn): I don't think we need to inspect the target of an alias.
 }
コード例 #26
0
 public virtual TResult?VisitAlias(IAliasSymbol symbol)
 {
     return(DefaultVisit(symbol));
 }
コード例 #27
0
            public RenameRewriter(RenameRewriterParameters parameters)
                : base(visitIntoStructuredTrivia: true)
            {
                _documentId = parameters.Document.Id;
                _renameRenamableSymbolDeclaration = parameters.RenamedSymbolDeclarationAnnotation;
                _solution = parameters.OriginalSolution;
                _replacementText = parameters.ReplacementText;
                _originalText = parameters.OriginalText;
                _possibleNameConflicts = parameters.PossibleNameConflicts;
                _renameLocations = parameters.RenameLocations;
                _conflictLocations = parameters.ConflictLocationSpans;
                _cancellationToken = parameters.CancellationToken;
                _semanticModel = parameters.SemanticModel;
                _renamedSymbol = parameters.RenameSymbol;
                _replacementTextValid = parameters.ReplacementTextValid;
                _renameSpansTracker = parameters.RenameSpansTracker;
                _isRenamingInStrings = parameters.OptionSet.GetOption(RenameOptions.RenameInStrings);
                _isRenamingInComments = parameters.OptionSet.GetOption(RenameOptions.RenameInComments);
                _stringAndCommentTextSpans = parameters.StringAndCommentTextSpans;
                _renameAnnotations = parameters.RenameAnnotations;

                _aliasSymbol = _renamedSymbol as IAliasSymbol;
                _renamableDeclarationLocation = _renamedSymbol.Locations.FirstOrDefault(loc => loc.IsInSource && loc.SourceTree == _semanticModel.SyntaxTree);
                _isVerbatim = _replacementText.StartsWith("@", StringComparison.Ordinal);

                _simplificationService = parameters.Document.Project.LanguageServices.GetService<ISimplificationService>();
                _semanticFactsService = parameters.Document.Project.LanguageServices.GetService<ISemanticFactsService>();
            }
コード例 #28
0
 public static void Create(IAliasSymbol symbol, SymbolKeyWriter visitor)
 {
     visitor.WriteString(symbol.Name);
     visitor.WriteSymbolKey(symbol.Target);
     visitor.WriteString(symbol.DeclaringSyntaxReferences.FirstOrDefault()?.SyntaxTree.FilePath ?? "");
 }
コード例 #29
0
 public static SerializableSymbolAndProjectId Dehydrate(
     IAliasSymbol alias, Document document)
 {
     return alias == null
         ? null
         : Dehydrate(new SymbolAndProjectId(alias, document.Project.Id));
 }
コード例 #30
0
        // We must verify that the alias actually binds back to the thing it's aliasing.
        // It's possible there's another symbol with the same name as the alias that binds
        // first
        private static bool ValidateAliasForTarget(IAliasSymbol aliasReplacement, SemanticModel semanticModel, ExpressionSyntax node, ISymbol symbol)
        {
            var aliasName = aliasReplacement.Name;

            var boundSymbols = semanticModel.LookupNamespacesAndTypes(node.SpanStart, name: aliasName);

            if (boundSymbols.Length == 1)
            {
                var boundAlias = boundSymbols[0] as IAliasSymbol;
                if (boundAlias != null && aliasReplacement.Target.Equals(symbol))
                {
                    return true;
                }
            }

            return false;
        }
コード例 #31
0
 public override Accessibility VisitAlias(IAliasSymbol symbol)
 {
     return(symbol.Target.Accept(this));
 }
コード例 #32
0
ファイル: SymbolDisplayVisitor.cs プロジェクト: jkotas/roslyn
        public override void VisitAlias(IAliasSymbol symbol)
        {
            builder.Add(CreatePart(SymbolDisplayPartKind.AliasName, symbol, symbol.Name));

            if (format.LocalOptions.IncludesOption(SymbolDisplayLocalOptions.IncludeType))
            {
                // ???
                AddPunctuation(SyntaxKind.EqualsToken);
                symbol.Target.Accept(this);
            }
        }
コード例 #33
0
 public sealed override void VisitAlias(IAliasSymbol symbol)
 {
     Visit(symbol.Target);
 }
コード例 #34
0
ファイル: SymbolWalker.cs プロジェクト: x335/WootzJs
 public override void VisitAlias(IAliasSymbol symbol)
 {
     base.VisitAlias(symbol);
 }
コード例 #35
0
 public override TypeSyntax VisitAlias(IAliasSymbol symbol)
 {
     return(AddInformationTo(symbol.Name.ToIdentifierName(), symbol));
 }
コード例 #36
0
 public sealed override void VisitAlias(IAliasSymbol symbol)
 {
     Visit(symbol.Target);
 }
コード例 #37
0
 public sealed override void Create(IAliasSymbol symbol, SymbolKeyWriter visitor)
 {
     visitor.WriteString(symbol.Name);
     visitor.WriteSymbolKey(symbol.Target);
     visitor.WriteString(symbol.DeclaringSyntaxReferences.FirstOrDefault()?.SyntaxTree.FilePath ?? "");
 }
コード例 #38
0
ファイル: SymbolVisitor.cs プロジェクト: XieShuquan/roslyn
 public virtual void VisitAlias(IAliasSymbol symbol)
 {
     DefaultVisit(symbol);
 }
コード例 #39
0
 public virtual void VisitAlias(IAliasSymbol symbol)
 {
     DefaultVisit(symbol);
 }
コード例 #40
0
        private static bool TryReplaceWithAlias(this ExpressionSyntax node, SemanticModel semanticModel, bool preferAliasToQualifiedName, CancellationToken cancellationToken, out IAliasSymbol aliasReplacement)
        {
            aliasReplacement = null;

            if (!node.IsAliasReplaceableExpression())
            {
                return false;
            }

            var symbol = semanticModel.GetSymbolInfo(node, cancellationToken).Symbol;

            // If the Symbol is a constructor get its containing type
            if (symbol.IsConstructor())
            {
                symbol = symbol.ContainingType;
            }

            if (node is QualifiedNameSyntax || node is AliasQualifiedNameSyntax)
            {
                SyntaxAnnotation aliasAnnotationInfo = null;

                // The following condition checks if the user has used alias in the original code and
                // if so the expression is replaced with the Alias
                if (node is QualifiedNameSyntax)
                {
                    var qualifiedNameNode = (QualifiedNameSyntax)node;
                    if (qualifiedNameNode.Right.Identifier.HasAnnotations(AliasAnnotation.Kind))
                    {
                        aliasAnnotationInfo = qualifiedNameNode.Right.Identifier.GetAnnotations(AliasAnnotation.Kind).Single();
                    }
                }

                if (node is AliasQualifiedNameSyntax)
                {
                    var aliasQualifiedNameNode = (AliasQualifiedNameSyntax)node;
                    if (aliasQualifiedNameNode.Name.Identifier.HasAnnotations(AliasAnnotation.Kind))
                    {
                        aliasAnnotationInfo = aliasQualifiedNameNode.Name.Identifier.GetAnnotations(AliasAnnotation.Kind).Single();
                    }
                }

                if (aliasAnnotationInfo != null)
                {
                    var aliasName = AliasAnnotation.GetAliasName(aliasAnnotationInfo);
                    var aliasIdentifier = SyntaxFactory.IdentifierName(aliasName);

                    var aliasTypeInfo = semanticModel.GetSpeculativeAliasInfo(node.SpanStart, aliasIdentifier, SpeculativeBindingOption.BindAsTypeOrNamespace);

                    if (aliasTypeInfo != null)
                    {
                        aliasReplacement = aliasTypeInfo;
                        return ValidateAliasForTarget(aliasReplacement, semanticModel, node, symbol);
                    }
                }
            }

            if (node.Kind() == SyntaxKind.IdentifierName &&
                semanticModel.GetAliasInfo((IdentifierNameSyntax)node, cancellationToken) != null)
            {
                return false;
            }

            // an alias can only replace a type or namespace
            if (symbol == null ||
                (symbol.Kind != SymbolKind.Namespace && symbol.Kind != SymbolKind.NamedType))
            {
                return false;
            }

            if (node is QualifiedNameSyntax)
            {
                var qualifiedName = (QualifiedNameSyntax)node;
                if (!qualifiedName.Right.HasAnnotation(Simplifier.SpecialTypeAnnotation))
                {
                    var type = semanticModel.GetTypeInfo(node, cancellationToken).Type;
                    if (type != null)
                    {
                        var keywordKind = GetPredefinedKeywordKind(type.SpecialType);
                        if (keywordKind != SyntaxKind.None)
                        {
                            preferAliasToQualifiedName = false;
                        }
                    }
                }
            }

            if (node is AliasQualifiedNameSyntax)
            {
                var aliasQualifiedNameSyntax = (AliasQualifiedNameSyntax)node;
                if (!aliasQualifiedNameSyntax.Name.HasAnnotation(Simplifier.SpecialTypeAnnotation))
                {
                    var type = semanticModel.GetTypeInfo(node, cancellationToken).Type;
                    if (type != null)
                    {
                        var keywordKind = GetPredefinedKeywordKind(type.SpecialType);
                        if (keywordKind != SyntaxKind.None)
                        {
                            preferAliasToQualifiedName = false;
                        }
                    }
                }
            }

            aliasReplacement = GetAliasForSymbol((INamespaceOrTypeSymbol)symbol, node.GetFirstToken(), semanticModel, cancellationToken);
            if (aliasReplacement != null && preferAliasToQualifiedName)
            {
                return ValidateAliasForTarget(aliasReplacement, semanticModel, node, symbol);
            }

            return false;
        }
コード例 #41
0
 public override object VisitAlias(IAliasSymbol aliasSymbol)
 {
     WriteType(SymbolKeyType.Alias);
     AliasSymbolKey.Create(aliasSymbol, this);
     return(null);
 }
コード例 #42
0
 public override Accessibility VisitAlias(IAliasSymbol symbol)
 => symbol.Target.Accept(this);
コード例 #43
0
            public RenameRewriter(RenameRewriterParameters parameters)
                : base(visitIntoStructuredTrivia: true)
            {
                this.documentId = parameters.Document.Id;
                this.renameRenamableSymbolDeclaration = parameters.RenamedSymbolDeclarationAnnotation;
                this.solution = parameters.OriginalSolution;
                this.replacementText = parameters.ReplacementText;
                this.originalText = parameters.OriginalText;
                this.possibleNameConflicts = parameters.PossibleNameConflicts;
                this.renameLocations = parameters.RenameLocations;
                this.conflictLocations = parameters.ConflictLocationSpans;
                this.cancellationToken = parameters.CancellationToken;
                this.semanticModel = (SemanticModel)parameters.SemanticModel;
                this.renamedSymbol = parameters.RenameSymbol;
                this.replacementTextValid = parameters.ReplacementTextValid;
                this.renameSpansTracker = parameters.RenameSpansTracker;
                this.isRenamingInStrings = parameters.OptionSet.GetOption(RenameOptions.RenameInStrings);
                this.isRenamingInComments = parameters.OptionSet.GetOption(RenameOptions.RenameInComments);
                this.stringAndCommentTextSpans = parameters.StringAndCommentTextSpans;
                this.renameAnnotations = parameters.RenameAnnotations;

                this.aliasSymbol = this.renamedSymbol as IAliasSymbol;
                this.renamableDeclarationLocation = this.renamedSymbol.Locations.Where(loc => loc.IsInSource && loc.SourceTree == semanticModel.SyntaxTree).FirstOrDefault();
                this.isVerbatim = this.replacementText.StartsWith("@");

                this.simplificationService = LanguageService.GetService<ISimplificationService>(parameters.Document);
            }