The result of a Project Analysis
Inheritance: IDisposable
Exemple #1
0
        ///<inheritdoc/>
        public override async Task <AnalyzerResult> AnalyzeProject(string projectPath)
        {
            AnalyzerResult analyzerResult = (await Analyze(projectPath)).First();

            return(analyzerResult);
        }
Exemple #2
0
        public static async Task Main(string[] args)
        {
            AnalyzerCLI cli = new AnalyzerCLI();

            cli.HandleCommand(args);
            Console.WriteLine(cli);

            /* 1. Logger object */
            var loggerFactory = LoggerFactory.Create(builder => builder.SetMinimumLevel(LogLevel.Trace).AddConsole());


            /* 2. Create Configuration settings */

            /*AnalyzerConfiguration configuration = new AnalyzerConfiguration(LanguageOptions.CSharp)
             * {
             *  ExportSettings =
             *  {
             *      GenerateJsonOutput = true,
             *      OutputPath = outputPath
             *  },
             *
             *  MetaDataSettings =
             *  {
             *      LiteralExpressions = true,
             *      MethodInvocations = true
             *  }
             * };*/
            cli.Configuration.MetaDataSettings.DeclarationNodes = true;
            cli.Configuration.MetaDataSettings.ReferenceData    = true;

            /* 3. Get Analyzer instance based on language */
            CodeAnalyzer analyzer = CodeAnalyzerFactory.GetAnalyzer(cli.Configuration,
                                                                    loggerFactory.CreateLogger("Analyzer"));


            /* 4. Analyze the project or solution */
            AnalyzerResult analyzerResult = null;

            if (cli.Project)
            {
                analyzerResult = await analyzer.AnalyzeProject(cli.FilePath);

                if (analyzerResult.OutputJsonFilePath != null)
                {
                    Console.WriteLine("Exported to : " + analyzerResult.OutputJsonFilePath);
                }
            }
            else
            {
                var analyzerResults = await analyzer.AnalyzeSolution(cli.FilePath);

                foreach (var aresult in analyzerResults)
                {
                    if (aresult.OutputJsonFilePath != null)
                    {
                        Console.WriteLine("Exported to : " + aresult.OutputJsonFilePath);
                    }
                }

                if (analyzerResults.Count > 0)
                {
                    analyzerResult = analyzerResults[0];
                }
            }

            /* Consume the results as model objects */
            var sourcefile = analyzerResult?.ProjectResult?.SourceFileResults?.First();

            if (sourcefile != null)
            {
                foreach (var invocation in sourcefile.AllInvocationExpressions())
                {
                    Console.WriteLine(invocation.MethodName + ":" + invocation.SemanticMethodSignature);
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// Analyzes a code file and adds it to an existing project analysis. If the file already exists, it replaces it in the result.
 /// </summary>
 /// <param name="filePath">The path to the code file</param>
 /// <param name="analyzerResult">The analyzer result to be modified</param>
 /// <returns></returns>
 public abstract Task <AnalyzerResult> AnalyzeFile(string filePath, AnalyzerResult analyzerResult);