Beispiel #1
0
 public void Transform(IProjectAnalyzationResult analyzationResult)
 {
     foreach (var document in analyzationResult.Documents)
     {
         TransformDocument(document);
     }
 }
        private static IProjectTransformationResult TransformProject(IProjectAnalyzationResult analyzationResult, ProjectTransformConfiguration configuration,
                                                                     ILoggerFactory loggerFactory)
        {
            var transformer = new ProjectTransformer(configuration, loggerFactory);

            return(transformer.Transform(analyzationResult));
        }
Beispiel #3
0
        private void IgnoreTest2(IProjectAnalyzationResult result)
        {
            bool val;
            var  test2 = GetMethodName <TestCase>(o => o.Test2(out val));

            var methods     = result.Documents.First().AllTypes.First().Methods.ToDictionary(o => o.Symbol.Name);
            var test2Method = (MethodData)methods[test2];

            Assert.AreEqual(DiagnosticSeverity.Hidden, test2Method.IgnoredReason.DiagnosticSeverity);
            Assert.AreEqual(0, test2Method.GetDiagnostics().Count());
            var bodyReference = test2Method.BodyFunctionReferences.First();

            Assert.AreEqual(0, bodyReference.GetDiagnostics().Count());
        }
        public IProjectTransformationResult Transform(IProjectAnalyzationResult analyzationResult)
        {
            var result = new ProjectTransformationResult(analyzationResult.Project);

            void TransfromDocument(IDocumentAnalyzationResult document)
            {
                // Skip empty documents
                if (document.GlobalNamespace.Types.Count == 0 && document.GlobalNamespace.NestedNamespaces.Count == 0)
                {
                    return;
                }
                var docResult = TransformDocument(document);

                result.Documents.Add(docResult);
                if (docResult.Transformed == null)
                {
                    return;
                }
                foreach (var transformer in _configuration.DocumentTransformers)
                {
                    docResult.Transformed = transformer.Transform(docResult) ?? docResult.Transformed;
                }
            }

            // Step 1: Transform all documents
            _logger.Info("Generating documents started");
            if (_configuration.ConcurrentRun)
            {
                Parallel.ForEach(analyzationResult.Documents, TransfromDocument);
            }
            else
            {
                foreach (var document in analyzationResult.Documents)
                {
                    TransfromDocument(document);
                }
            }
            _logger.Info("Generating documents completed");

            // Step 2: Modify the project by adding newly generated documents and optionally update the existing ones
            _logger.Info("Adding generated documents to the project started");
            var project = analyzationResult.Project;

            foreach (var docResult in result.Documents)
            {
                if (docResult.Transformed == null)
                {
                    continue;
                }
                var document = docResult.AnalyzationResult;
                if (docResult.OriginalModified != null)
                {
                    project = project.GetDocument(document.Document.Id).WithSyntaxRoot(docResult.OriginalModified).Project;
                }
                var folders = new List <string> {
                    _configuration.AsyncFolder
                }.Concat(document.Document.Folders);
                project = project.AddDocument(document.Document.Name, docResult.Transformed.GetText(Encoding.UTF8), folders, GetDocumentAsyncPath(document.Document)).Project;
            }
            result.Project = project;
            _logger.Info("Adding generated documents to the project completed");

            return(result);
        }
        private void TransformProject(IProjectAnalyzationResult analyzationResult, ProjectTransformConfiguration configuration)
        {
            var transformer = new ProjectTransformer(configuration);

            transformer.Transform(analyzationResult);
        }