コード例 #1
0
        public static HashSet <AssignedInfo> GetAssignedAndRelease(MakeMemberReadOnlyWalker walker)
        {
            HashSet <AssignedInfo> assigned = walker.Assigned;

            Release(walker);

            return(assigned);
        }
コード例 #2
0
        public virtual HashSet <ISymbol> GetFixableSymbols(
            SymbolAnalysisContext context,
            INamedTypeSymbol containingType,
            HashSet <ISymbol> symbols)
        {
            CancellationToken cancellationToken = context.CancellationToken;
            ImmutableArray <SyntaxReference> syntaxReferences = containingType.DeclaringSyntaxReferences;

            for (int i = 0; i < syntaxReferences.Length; i++)
            {
                var typeDeclaration = (TypeDeclarationSyntax)syntaxReferences[i].GetSyntax(cancellationToken);

                SemanticModel semanticModel = context.Compilation.GetSemanticModel(typeDeclaration.SyntaxTree);

                foreach (MemberDeclarationSyntax memberDeclaration in typeDeclaration.Members)
                {
                    MakeMemberReadOnlyWalker walker = MakeMemberReadOnlyWalkerCache.Acquire();

                    walker.Visit(memberDeclaration);

                    HashSet <AssignedInfo> assigned = MakeMemberReadOnlyWalkerCache.GetAssignedAndRelease(walker);

                    if (assigned != null)
                    {
                        foreach (AssignedInfo info in assigned)
                        {
                            foreach (ISymbol symbol in symbols)
                            {
                                if (symbol.Name == info.NameText &&
                                    ((symbol.IsStatic) ? !info.IsInStaticConstructor : !info.IsInInstanceConstructor))
                                {
                                    ISymbol nameSymbol = semanticModel.GetSymbol(info.Name, cancellationToken);

                                    if (ValidateSymbol(nameSymbol) &&
                                        symbols.Remove(nameSymbol.OriginalDefinition))
                                    {
                                        if (symbols.Count == 0)
                                        {
                                            return(symbols);
                                        }

                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(symbols);
        }
コード例 #3
0
        public static MakeMemberReadOnlyWalker Acquire()
        {
            MakeMemberReadOnlyWalker walker = _cachedInstance;

            if (walker != null)
            {
                _cachedInstance = null;
                walker.Clear();
                return(walker);
            }

            return(new MakeMemberReadOnlyWalker());
        }
コード例 #4
0
 public static void Release(MakeMemberReadOnlyWalker walker)
 {
     _cachedInstance = walker;
 }