public override void Analyze()
        {
            var variables = _tree
                            .GetRoot()
                            .DescendantNodes()
                            .OfType <VariableDeclaratorSyntax>()
                            .Select(p => new { SyntaxNode = p, Symbol = _model.GetDeclaredSymbol(p) })
                            .Where(p => p.Symbol != null);

            foreach (var variable in variables)
            {
                ILocalSymbol ils = variable.Symbol as ILocalSymbol;
                IFieldSymbol ifs = variable.Symbol as IFieldSymbol;

                if (ils != null || ifs != null)
                {
                    ITypeSymbol its = ils != null ? ils.Type : ifs.Type;

                    if (its.IsSubclassOf(NsObject))
                    {
                        var availability = its.GetAttribute(Availability);

                        if (availability != null)
                        {
                            ulong version = GetDeprecatedVersion(availability);
                            if (version != 0 && version <= SdkVersion)
                            {
                                DeprecatedElements.Add(new Tuple <CSharpSyntaxNode, ISymbol, ulong>(variable.SyntaxNode, its, version));
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public override void Analyze()
        {
            var mas = _tree
                      .GetRoot()
                      .DescendantNodes()
                      .OfType <MemberAccessExpressionSyntax>()
                      .Select(p => new { SyntaxNode = p, Symbol = _model.GetSymbolInfo(p) })
                      .Where(p => p.Symbol.Symbol != null);

            foreach (var ma in mas)
            {
                if (ma.Symbol.Symbol.ContainingType.IsSubclassOf(NsObject))
                {
                    object availability = null;
                    if (ma.Symbol.Symbol.Kind == SymbolKind.Property)
                    {
                        availability = ma.Symbol.Symbol.GetAttribute(Availability, MemberTypes.Property);
                    }
                    else
                    {
                        availability = ma.Symbol.Symbol.GetAttribute(Availability, MemberTypes.Method);
                    }

                    if (availability != null)
                    {
                        ulong version = GetDeprecatedVersion(availability);
                        if (version != 0 && version <= SdkVersion)
                        {
                            DeprecatedElements.Add(new Tuple <CSharpSyntaxNode, ISymbol, ulong>(ma.SyntaxNode, ma.Symbol.Symbol, version));
                        }
                    }
                }
            }
        }
        public override void Analyze()
        {
            var identifiers = _tree
                              .GetRoot()
                              .DescendantNodes()
                              .OfType <IdentifierNameSyntax>()
                              .Select(p => new { SyntaxNode = p, Symbol = _model.GetSymbolInfo(p) })
                              .Select(p => new { p.SyntaxNode, Symbol = p.Symbol.Symbol != null ? p.Symbol.Symbol : p.Symbol.CandidateSymbols.FirstOrDefault() })
                              .Where(p => p.Symbol != null)
                              .Where(p => p.Symbol.Kind == SymbolKind.Property || p.Symbol.Kind == SymbolKind.Method);

            foreach (var identifier in identifiers)
            {
                if (identifier.Symbol.ContainingType.IsSubclassOf(NsObject))
                {
                    object availability = null;
                    if (identifier.Symbol.Kind == SymbolKind.Property)
                    {
                        availability = identifier.Symbol.GetAttribute(Availability, MemberTypes.Property);
                    }
                    else
                    {
                        availability = identifier.Symbol.GetAttribute(Availability, MemberTypes.Method);
                    }

                    if (availability != null)
                    {
                        ulong version = GetDeprecatedVersion(availability);
                        if (version != 0 && version <= SdkVersion)
                        {
                            DeprecatedElements.Add(new Tuple <CSharpSyntaxNode, ISymbol, ulong>(identifier.SyntaxNode, identifier.Symbol, version));
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public override void Analyze()
        {
            //get all overriden properties/methods
            var properties = _tree
                             .GetRoot()
                             .DescendantNodes()
                             .OfType <PropertyDeclarationSyntax>()
                             .Select(p => new { SyntaxNode = p, Symbol = _model.GetDeclaredSymbol(p) as IPropertySymbol })
                             .Where(p => p.Symbol.IsOverride && p.Symbol.ContainingType.IsSubclassOf(NsObject))
                             .GroupBy(p => p.Symbol.ContainingType, p => p, (key, g) => new { Key = key, Symbols = g });
            var methods = _tree
                          .GetRoot()
                          .DescendantNodes()
                          .OfType <MethodDeclarationSyntax>()
                          .Select(p => new { SyntaxNode = p, Symbol = _model.GetDeclaredSymbol(p) as IMethodSymbol })
                          .Where(p => p.Symbol.IsOverride && p.Symbol.ContainingType.IsSubclassOf(NsObject))
                          .GroupBy(p => p.Symbol.ContainingType, p => p, (key, g) => new { Key = key, Symbols = g });

            //group by types
            var types = properties.Select(p => p.Key)
                        .Concat(methods.Select(p => p.Key))
                        .Distinct()
                        .OrderBy(p => p.Name);

            foreach (var type in types)
            {
                string name = type.Name;

                var prop = properties.Where(p => p.Key == type).SingleOrDefault();
                if (prop != null)
                {
                    foreach (var propSymbol in prop.Symbols)
                    {
                        var availability = propSymbol.Symbol.GetAttribute(Availability);
                        if (availability != null)
                        {
                            ulong version = GetDeprecatedVersion(availability);
                            if (version != 0 && version <= SdkVersion)
                            {
                                DeprecatedElements.Add(new Tuple <CSharpSyntaxNode, ISymbol, ulong>(propSymbol.SyntaxNode, propSymbol.Symbol, version));
                            }
                        }
                    }
                }

                var meth = methods.Where(p => p.Key == type).SingleOrDefault();
                if (meth != null)
                {
                    foreach (var methSymbol in meth.Symbols)
                    {
                        var availability = methSymbol.Symbol.GetAttribute(Availability);
                        if (availability != null)
                        {
                            ulong version = GetDeprecatedVersion(availability);
                            if (version != 0 && version <= SdkVersion)
                            {
                                DeprecatedElements.Add(new Tuple <CSharpSyntaxNode, ISymbol, ulong>(methSymbol.SyntaxNode, methSymbol.Symbol, version));
                            }
                        }
                    }
                }
            }
        }