public List <SyntaxNode> GetSyntaxNodesFromClass(ClassDeclarationSyntax node, TaggedSyntaxLibrary lib)
        {
            List <SyntaxNode> nodes       = new List <SyntaxNode>();
            INamedTypeSymbol  classSymbol = this.symbolHelper.GetSymbol(node) as INamedTypeSymbol;

            if (classSymbol != null)
            {
                List <ISymbol>   symbols  = new List <ISymbol>();
                INamedTypeSymbol baseType = classSymbol.BaseType;
                if (baseType != null)
                {
                    symbols.Add(baseType);
                }

                ImmutableArray <INamedTypeSymbol> interfaces = classSymbol.Interfaces;
                if (interfaces != null && interfaces.Count() > 0)
                {
                    foreach (INamedTypeSymbol inter in interfaces)
                    {
                        if (inter != null)
                        {
                            symbols.Add(inter);
                        }
                    }
                }

                // check for override methods
                List <IMethodSymbol> oMethods = this.getOverrideMethodSymbolsFromClass(node);
                if (oMethods != null && oMethods.Count() > 0)
                {
                    foreach (IMethodSymbol oMethod in oMethods)
                    {
                        IMethodSymbol overridden = oMethod.OverriddenMethod;
                        if (overridden != null)
                        {
                            List <SyntaxNode> oNodes = ScriptAnalyzerResourceHelper.GetSyntaxNodesFromSymbol(overridden);
                            if (oNodes != null && oNodes.Count() > 0)
                            {
                                MethodDeclarationSyntax oNode = oNodes.First() as MethodDeclarationSyntax;
                                if (oNode != null)
                                {
                                    TaggedSyntaxTree tTree = lib.GetTreeFromNode(oNode);
                                    if (tTree != null && tTree.IsTagged(oNode))
                                    {
                                        symbols.Add(oMethod);
                                    }
                                }
                            }
                        }
                    }
                }

                nodes = ScriptAnalyzerResourceHelper.GetSyntaxNodesFromSymbols(symbols);
            }

            return(nodes);
        }
        public List <SyntaxNode> GetSyntaxNodesFromIdentifier(IdentifierNameSyntax node)
        {
            List <SyntaxNode> nodes  = new List <SyntaxNode>();
            ISymbol           symbol = this.SymbolHelper.GetSymbolInfo(node).Symbol;

            if (symbol != null)
            {
                nodes = ScriptAnalyzerResourceHelper.GetSyntaxNodesFromSymbol(symbol);
            }
            return(nodes);
        }
        public List <SyntaxNode> GetSyntaxNodesFromObjectCreation(ObjectCreationExpressionSyntax node)
        {
            List <SyntaxNode> nodes  = new List <SyntaxNode>();
            ISymbol           symbol = this.SymbolHelper.GetSymbolInfo(node).Symbol;

            if (symbol != null)
            {
                nodes = ScriptAnalyzerResourceHelper.GetSyntaxNodesFromSymbol(symbol);
            }
            return(nodes);
        }
        public List <SyntaxNode> GetSyntaxNodesFromConstructorInitializer(ConstructorInitializerSyntax node)
        {
            List <SyntaxNode> nodes  = new List <SyntaxNode>();
            ISymbol           symbol = this.symbolHelper.GetSymbolInfo(node).Symbol;

            if (symbol != null)
            {
                nodes = ScriptAnalyzerResourceHelper.GetSyntaxNodesFromSymbol(symbol);
            }
            return(nodes);
        }
Пример #5
0
        private ScriptAnalyzer createScriptAnalyzer(Project project)
        {
            ScriptAnalyzer     result = null;
            List <Compilation> comps  = this.getCompilations(project);

            if (comps != null && comps.Count() > 0)
            {
                ScriptAnalyzerSymbolHelper   sHelper = new ScriptAnalyzerSymbolHelper(comps.ToArray());
                ScriptAnalyzerResourceHelper rHelper = new ScriptAnalyzerResourceHelper(sHelper);
                result = new ScriptAnalyzer(rHelper);
            }

            return(result);
        }
        public List <SyntaxNode> GetSyntaxNodesFromInvocation(InvocationExpressionSyntax node)
        {
            List <SyntaxNode> nodes   = new List <SyntaxNode>();
            List <ISymbol>    symbols = new List <ISymbol>();

            // function
            if (node.Expression != null)
            {
                ISymbol symbol = this.symbolHelper.GetSymbolInfo(node.Expression).Symbol;
                if (symbol != null)
                {
                    symbols.Add(symbol);
                }
            }

            nodes = ScriptAnalyzerResourceHelper.GetSyntaxNodesFromSymbols(symbols);
            return(nodes);
        }
        public static List <SyntaxNode> GetSyntaxNodesFromSymbols(List <ISymbol> symbols)
        {
            List <SyntaxNode> nodes = new List <SyntaxNode>();

            if (symbols != null && symbols.Count() > 0)
            {
                // filter duplicate symbols
                symbols = ScriptAnalyzerResourceHelper.filterSymbols(symbols);
                foreach (ISymbol symbol in symbols)
                {
                    List <SyntaxNode> newNodes = ScriptAnalyzerResourceHelper.GetSyntaxNodesFromSymbol(symbol);
                    if (newNodes.Count() > 0)
                    {
                        nodes.AddRange(newNodes);
                    }
                }
            }
            return(nodes);
        }
        public List <SyntaxNode> GetSyntaxNodesFromMethod(MethodDeclarationSyntax node, TaggedSyntaxLibrary lib)
        {
            List <SyntaxNode> nodes  = new List <SyntaxNode>();
            IMethodSymbol     symbol = this.symbolHelper.GetSymbol(node) as IMethodSymbol;

            if (symbol != null)
            {
                List <ISymbol> symbols = new List <ISymbol>();
                if (symbol.IsOverride)
                {
                    symbols.Add(symbol.OverriddenMethod);
                }
                if (symbol.IsVirtual)
                {
                    List <ISymbol> mSymbols = this.GetSymbolsFromVirtualFunction(symbol, lib).Select(s => s as ISymbol).ToList();
                    symbols.AddRange(mSymbols);
                }
                // return type
                ITypeSymbol returnType = symbol.ReturnType;
                if (returnType != null)
                {
                    symbols.Add(returnType);
                }

                // parameters
                ImmutableArray <IParameterSymbol> parameterList = symbol.Parameters;
                if (parameterList != null && parameterList.Count() > 0)
                {
                    foreach (IParameterSymbol param in parameterList)
                    {
                        if (param != null && param.Type != null)
                        {
                            symbols.Add(param.Type);
                        }
                    }
                }
                nodes = ScriptAnalyzerResourceHelper.GetSyntaxNodesFromSymbols(symbols);
            }

            return(nodes);
        }
Пример #9
0
 public ScriptAnalyzer(ScriptAnalyzerResourceHelper rHelper)
 {
     this.resourceHelper = rHelper;
 }