Exemplo n.º 1
0
        public static string GetContainingMethodBlock(VisualBasicSyntaxNode node)
        {
            string methodBlock = "<METHODBLOCK>";

            var a5 = node.Ancestors()
                     .Where(x => x.IsKind(SyntaxKind.FunctionBlock) || x.IsKind(SyntaxKind.SubBlock))
                     .Cast <MethodBlockSyntax>().ToList();

            if (a5.Count > 0)
            {
                methodBlock = node.Ancestors()
                              .Where(x => x.IsKind(SyntaxKind.FunctionBlock) || x.IsKind(SyntaxKind.SubBlock))
                              .Cast <MethodBlockSyntax>().FirstOrDefault().ToString();
            }

            return(methodBlock);
        }
Exemplo n.º 2
0
        public static string GetContainingMethodName(VisualBasicSyntaxNode node)
        {
            string methodName = "none";

            var a5 = node.Ancestors()
                     .Where(x => x.IsKind(SyntaxKind.FunctionBlock) || x.IsKind(SyntaxKind.SubBlock))
                     .Cast <MethodBlockSyntax>().ToList();

            if (a5.Count > 0)
            {
                methodName = node.Ancestors()
                             .Where(x => x.IsKind(SyntaxKind.FunctionBlock) || x.IsKind(SyntaxKind.SubBlock))
                             .Cast <MethodBlockSyntax>().First().SubOrFunctionStatement.Identifier.ToString();
            }

            return(methodName);
        }
Exemplo n.º 3
0
        private static string GetClassModuleContext(VisualBasicSyntaxNode node, CodeAnalysisOptions displayInfo)
        {
            string classModuleContext = "";

            if (displayInfo.DisplayClassOrModuleName)
            {
                var inClassBlock = node.Ancestors()
                                   .Where(x => x.IsKind(SyntaxKind.ClassBlock))
                                   .Cast <ClassBlockSyntax>().ToList();

                var inModuleBlock = node.Ancestors()
                                    .Where(x => x.IsKind(SyntaxKind.ModuleBlock))
                                    .Cast <ModuleBlockSyntax>().ToList();

                string typeName   = "unknown";
                string className  = "unknown";
                string moduleName = "unknown";

                if (inClassBlock.Count > 0)
                {
                    typeName = "Class";

                    className = node.Ancestors()
                                .Where(x => x.IsKind(SyntaxKind.ClassBlock))
                                .Cast <ClassBlockSyntax>().First().ClassStatement.Identifier.ToString();
                }

                if (inModuleBlock.Count > 0)
                {
                    typeName = "Module";

                    moduleName = node.Ancestors()
                                 .Where(x => x.IsKind(SyntaxKind.ModuleBlock))
                                 .Cast <ModuleBlockSyntax>().First().ModuleStatement.Identifier.ToString();
                }

                classModuleContext = String.Format("{0, 8}{1,6}:({2,-25})",
                                                   classModuleContext,
                                                   typeName,
                                                   typeName == "Class" ? className : moduleName);
            }

            return(classModuleContext);
        }
Exemplo n.º 4
0
        private static string GetAncestorContext(VisualBasicSyntaxNode node, CodeAnalysisOptions displayInfo)
        {
            string ancestorContext = "";

            if (displayInfo.DisplayContainingBlock)
            {
                ancestorContext += GetContainingBlock(node).Kind().ToString();
            }

            if (displayInfo.InTryBlock)
            {
                var inTryBlock = node.Ancestors()
                                 .Where(x => x.IsKind(SyntaxKind.TryBlock))
                                 .Cast <TryBlockSyntax>().ToList();

                if (inTryBlock.Count > 0)
                {
                    ancestorContext += "T ";
                }
            }

            if (displayInfo.InWhileBlock)
            {
                var inDoWhileBlock = node.Ancestors()
                                     .Where(x => x.IsKind(SyntaxKind.DoWhileLoopBlock))
                                     .Cast <DoLoopBlockSyntax>().ToList();

                if (inDoWhileBlock.Count > 0)
                {
                    ancestorContext += "W ";
                }
            }

            if (displayInfo.InForBlock)
            {
                var inForBlock = node.Ancestors()
                                 .Where(x => x.IsKind(SyntaxKind.ForBlock))
                                 .Cast <ForBlockSyntax>().ToList();

                if (inForBlock.Count > 0)
                {
                    ancestorContext += "F ";
                }
            }

            if (displayInfo.InIfBlock)
            {
                var inMultiLineIfBlock = node.Ancestors()
                                         .Where(x => x.IsKind(SyntaxKind.MultiLineIfBlock))
                                         .Cast <MultiLineIfBlockSyntax>().ToList();

                if (inMultiLineIfBlock.Count > 0)
                {
                    ancestorContext += "I ";
                }
            }

            if (ancestorContext.Length > 0)
            {
                ancestorContext = string.Format("{0,8}", ancestorContext);
            }

            return(ancestorContext);
        }