public bool Run(
            string projectAssembly,
            string sourceDirectory,
            IList <string> sourceFiles,
            IList <string> generationList,
            IWriter writer,
            TextFormatter textFormatter,
            IDictionary <string, string> typeOverrideMap,
            ASTParserType parserType = ASTParserType.Sdcb
            )
        {
            TypeStatementTemplates.TaskTemplate = "[[GENERIC_TYPES]]";
            ReadInteropTemplates.SetReadTemplates();

            return(new GenerateSource()
                   .Run(
                       projectAssembly,
                       sourceDirectory,
                       sourceFiles,
                       generationList,
                       writer,
                       textFormatter,
                       typeOverrideMap,
                       parserType
                       ));
        }
예제 #2
0
        public void ShouldGenerateTypeOverrideScenarioStringsUsingSdcb(
            string sourceFile,
            string path,
            string expectedFile,
            ASTParserType parserType
            ) => ValidateGenerateWithTypeOverrideStrings(
            path,
            sourceFile,
            new Dictionary <string, string>
        {
            { "Examples.ExampleClass | static | vectorStaticCheck", "OverrideVector4" },
            { "Examples.ExampleClass | static | primativeStaticCheck", "int" },
            { "Examples.ExampleClass | vectorCheck", "OverrideVector4" },
            { "Examples.ExampleClass | primativeCheck", "int" },

            { "Examples.ExampleClass | static | methodStaticCheck", "int" },
            { "Examples.ExampleClass | static | vectorStaticMethodCheck | arg1", "OverrideVector4" },
            { "Examples.ExampleClass | static | primativeStaticMethodCheck | arg2", "int" },
            { "Examples.ExampleClass | methodCheck", "OverrideVector4" },
            { "Examples.ExampleClass | vectorMethodCheck | arg1", "OverrideVector4" },
            { "Examples.ExampleClass | primativeMethodCheck | arg2", "int" },

            { "Examples.ExampleClass | constructor | arg1", "OverrideVector4" },
            { "Examples.ExampleClass | constructor | arg2", "int" },
        },
            expectedFile,
            parserType: parserType
            );
예제 #3
0
 public void ShouldGenerateMethodStringsUsingSdcb(
     string sourceFile,
     string path,
     string expectedFile,
     ASTParserType parserType
     ) => ValidateGenerateStrings(
     path,
     sourceFile,
     expectedFile,
     parserType: parserType
     );
 public void ShouldGenerateConstructorStringsUsingNodeJS(
     string sourceFile,
     string path,
     string expectedFile,
     ASTParserType parserType
     ) => ValidateGenerateStrings(
     path,
     sourceFile,
     expectedFile,
     parserType: parserType
     );
예제 #5
0
 public void ShouldGenerateAccessorStringsWithNodeJS(
     string sourceFile,
     string path,
     string expectedFile,
     ASTParserType parserType
     ) => ValidateGenerateStrings(
     path,
     sourceFile,
     expectedFile,
     parserType: parserType
     );
예제 #6
0
 public void ShouldGenerateEnumScenarioStringsUsingSdcb(
     string sourceFile,
     string rootPath,
     string expectedFile,
     ASTParserType parserType
     ) => ValidateGenerateStrings(
     rootPath,
     sourceFile,
     expectedFile,
     parserType: parserType
     );
예제 #7
0
 public void ShouldGenerateMethodScenarioStringsUsingSdcb(
     string sourceFile,
     string rootPath,
     string scenariosPath,
     string expectedFile,
     ASTParserType parserType
     ) => ValidateGenerateStrings(
     Path.Combine(rootPath, scenariosPath),
     sourceFile,
     expectedFile,
     parserType: parserType
     );
예제 #8
0
 public void ShouldGenerateAccessorScenarioStringsWithNodeJS(
     string sourceFile,
     string rootPath,
     string scenariosPath,
     string expectedFile,
     ASTParserType parserType
     ) => ValidateGenerateStrings(
     Path.Combine(rootPath, scenariosPath),
     sourceFile,
     expectedFile,
     parserType: parserType
     );
예제 #9
0
 public void ShouldGenerateConstructorStringsUsingSdcb(
     string sourceFile,
     string path,
     string expectedFile,
     string classIdentifier,
     ASTParserType parserType
     ) => ValidateGenerateStrings(
     path,
     sourceFile,
     expectedFile,
     classIdentifier,
     parserType: parserType
     );
예제 #10
0
 private static AbstractSyntaxTree CreateParser(
     ASTParserType parserType,
     string source
     )
 {
     return(parserType switch
     {
         ASTParserType.NodeJS => new NodeJS_ASTWrapper(
             source
             ),
         _ => new Sdcb_TypeScriptASTWrapper(
             source
             ),
     });
예제 #11
0
        public void ValidateGenerateStrings(
            string path,
            string sourceFile,
            string expectedFile,
            string classIdentifier   = "ExampleClass",
            ASTParserType parserType = ASTParserType.Sdcb
            )
        {
            // Given
            GenerateSource.DisableCache();
            var sourcePath = Path.Combine(
                ".",
                "GenerateClassStatementStringTests",
                path
                );
            string expected = File.ReadAllText(Path.Combine(
                                                   sourcePath,
                                                   expectedFile
                                                   ));
            var source = File.ReadAllText(Path.Combine(
                                              sourcePath,
                                              sourceFile
                                              ));
            var ast = CreateParser(
                parserType,
                source
                );
            var typeOverrideMap = new Dictionary <string, string>();

            // When
            var generated = GenerateInteropClassStatement.Generate(
                "ProjectAssembly",
                classIdentifier,
                ast,
                typeOverrideMap
                );
            var actual = GenerateClassStatementString.Generate(
                generated,
                new NoFormattingTextFormatter()
                );

            // Then
            actual.Should().Be(
                expected
                );
        }
        public bool Run(
            string projectAssembly,
            string sourceDirectory,
            IList <string> sourceFiles,
            IList <string> generationList,
            IWriter writer,
            TextFormatter textFormatter,
            IDictionary <string, string> typeOverrideMap,
            ASTParserType parserType = ASTParserType.Sdcb
            )
        {
            var overallStopwatch = Stopwatch.StartNew();
            var stopwatch        = Stopwatch.StartNew();

            GlobalLogger.Info($"=== Consolidate Source Files");
            var sourceFilesAsText = GetSourceFilesAsSingleTextString(
                sourceDirectory,
                sourceFiles
                );

            GlobalLogger.Info($"=== Consolidated Source Files | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");

            stopwatch.Restart();
            GlobalLogger.Info($"=== Generated AST - {parserType}");
            var ast = ASTParser.ParseText(
                sourceFilesAsText,
                new ASTParserOptions
            {
                ParserType = parserType,
            }
                );

            GlobalLogger.Info($"=== Generated AST | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");
            var notGeneratedClassNames = new List <string>();

            var generatedStatements = new List <GeneratedStatement>();

            stopwatch.Restart();
            GlobalLogger.Info($"=== Generate Cached Entity Object");
            var cachedEntityObject = GenerateCachedEntityObject.GenerateClassStatement();

            generatedStatements.Add(
                new GeneratedStatement(
                    cachedEntityObject,
                    GenerateCachedEntityObject.GenerateString()
                    )
                );
            GlobalLogger.Info($"=== Generated Cached Entity Object | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");

            stopwatch.Restart();
            GlobalLogger.Info($"=== Generate Class Statements");
            var generatedClassStatements = GenerateClassFromList(
                ast,
                projectAssembly,
                generationList,
                notGeneratedClassNames,
                typeOverrideMap,
                new List <ClassStatement> {
                cachedEntityObject
            }
                );

            generatedClassStatements.Remove(cachedEntityObject);
            GlobalLogger.Info($"=== Generated Class Statements | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");

            stopwatch.Restart();
            GlobalLogger.Info($"=== Generate Statements");
            foreach (var generatedStatement in generatedClassStatements)
            {
                generatedStatements.Add(
                    new GeneratedStatement(
                        generatedStatement,
                        GenerateClassStatementString.Generate(
                            generatedStatement,
                            textFormatter
                            )
                        )
                    );
            }
            GlobalLogger.Info($"=== Generated Statements | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");

            stopwatch.Restart();
            GlobalLogger.Info($"=== Generating Shimmed Classes");
            foreach (var notGeneratedInterfaceName in notGeneratedClassNames)
            {
                if (!JavaScriptProvidedApiIdentifier.Identify(notGeneratedInterfaceName, out _))
                {
                    var classShim = GenerateClassShim.GenerateClassStatement(
                        notGeneratedInterfaceName
                        );
                    generatedStatements.Add(
                        new GeneratedStatement(
                            classShim,
                            textFormatter.Format(
                                GenerateClassShim.GenerateString(
                                    classShim
                                    )
                                )
                            )
                        );
                    GlobalLogger.Info($"=== Generated Shimmed Class: {notGeneratedInterfaceName}");
                }
            }
            GlobalLogger.Info($"=== Generated Shimmed Classes | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");

            // Write Generated Statements to Passed in Writer
            stopwatch.Restart();
            GlobalLogger.Info($"=== Writing Generated Statements");
            writer.Write(
                generatedStatements
                );
            GlobalLogger.Info($"=== Finished Writing Generated Statements | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");

            GlobalLogger.Success($"=== Finished Run | ElapsedTime: {overallStopwatch.ElapsedMilliseconds}ms");

            return(true);
        }