示例#1
0
        private void DrawOutputndicator(Cairo.Context context)
        {
            context.Save();
            RelativeLocator locator = new RelativeLocator(-0.04, 1.2);
            PointD          point   = locator.Locate(this);

            context.MoveTo(point);
            context.LineCap = LineCap.Round;
            context.Color   = s_ioIndicatorColor;

            double l = 4;   //arm lenght of indicator icon
            double s = 0.4; //spacing between arms in the indicator icon

            //draw <<
            //up
            context.RelLineTo(new Distance(-s, -l));
            context.RelMoveTo(new Distance(s, l));   //back

            //right
            context.RelLineTo(new Distance(l, s));
            context.RelMoveTo(new Distance(-l, -s));   //back

            context.RelMoveTo(new Distance(3, -3));

            //repeat above for second arrow
            context.RelLineTo(new Distance(-s, -l));
            context.RelMoveTo(new Distance(s, l));   //back
            context.RelLineTo(new Distance(l, s));
            context.RelMoveTo(new Distance(-l, -s)); //back

            context.Stroke();

            context.Restore();
        }
        private void GenerateAndAssertSnapshot(
            Type patternType,
            string patternInterfaceFile,
            string patternImplementationFile,
            string declarationInterfaceFile,
            string targetNameSpace,
            string snapshotName)
        {
            var resolver = this.LoadWorkSpace(
                patternInterfaceFile,
                patternImplementationFile,
                declarationInterfaceFile,
                out var itfDeclaration,
                out var itfPatternDeclaration,
                out var implPatternDeclaration,
                out var files);

            var locator = new RelativeLocator(string.Empty, targetNameSpace);

            var snapshotGenerator = new SnapshotGenerator();

            var implGenerator = new AutomatedGenerator(
                snapshotGenerator, locator, resolver, patternType);

            implGenerator.Generate(files);

            string location = SnapshotHelper.GetLocationFromCallingProjectRoot("Generator");

            SnapshotHelper.AssertSnapshot(snapshotGenerator.GetAllGenerated(), snapshotName, location);
        }
        private void GenerateSnapshot(string snapshotName, params string[] files)
        {
            var sc = new ServiceCollection();

            sc.AddTestLogging(this.testOutputHelper);
            sc.AddCSharpToolsGenerator();

            using (var sp = sc.BuildServiceProvider())
            {
                var workspace = sp.GetService <ICSharpWorkspace>();

                foreach (var file in files)
                {
                    workspace.RegisterFile(file);
                }

                var generator = new ToolsGenerator(
                    sp.GetService <ILogger <ToolsGenerator> >(),
                    workspace);

                var inputs  = new HashSet <string>();
                var locator = new RelativeLocator(string.Empty, "target.name.space");

                var snapshotGenerator = new SnapshotGenerator();

                generator.Generate(locator, snapshotGenerator, workspace.Files);

                var location = SnapshotHelper.GetLocationFromCallingProjectRoot(null);
                SnapshotHelper.AssertSnapshot(snapshotGenerator.GetAllGenerated(), snapshotName, location);
            }
        }
示例#4
0
        internal void Generate(RelativeLocator locator, IGenerator fileGenerator, IEnumerable <ICSharpFile> files)
        {
            this.workspace.RegisterFile(GetContentFile("./Patterns/Itf/IObjectPattern.cs"));
            this.workspace.RegisterFile(GetContentFile("./Patterns/Itf/IFactoryPattern.cs"));
            this.workspace.RegisterFile(GetContentFile("./Patterns/Impl/FactoryPattern.cs"));
            this.workspace.RegisterFile(GetContentFile("./Patterns/Impl/ObjectPattern.cs"));

            var resolver = this.workspace.DeepLoad();

            var generator1 = new AutomatedGenerator(
                fileGenerator,
                locator,
                resolver,
                typeof(IFactoryPattern));

            var generatedItems1 = generator1.Generate(files);

            var generator2 = new AutomatedGenerator(
                fileGenerator,
                locator,
                resolver,
                typeof(FactoryPattern));

            var generatedItems2 = generator2.Generate(files);

            var generator3 = new AutomatedGenerator(
                fileGenerator,
                locator,
                resolver,
                typeof(ObjectPattern));

            var generatedItems3 = generator3.Generate(files);
        }
        private void GenerateAndAssertSnapshot(
            string patternInterfaceFile,
            string patternImplementationFile,
            string declarationInterfaceFile,
            string targetNameSpace,
            string implName,
            string snapshotName)
        {
            this.LoadWorkSpace(
                patternInterfaceFile,
                patternImplementationFile,
                declarationInterfaceFile,
                out var itfDeclaration,
                out var itfPatternDeclaration,
                out var implPatternDeclaration);

            var locator = new RelativeLocator(string.Empty, targetNameSpace);

            var snapshotGenerator = new SnapshotGenerator();

            var implGenerator = new ImplementationGenerator(
                snapshotGenerator, locator, itfPatternDeclaration, implPatternDeclaration);

            var writerSelector = SetupWriterSelector(itfPatternDeclaration, implPatternDeclaration, itfDeclaration, implName);

            implGenerator.Generate(writerSelector, itfDeclaration, implName);

            string location = SnapshotHelper.GetLocationFromCallingProjectRoot("Generator");

            SnapshotHelper.AssertSnapshot(snapshotGenerator.GetAllGenerated(), snapshotName, location);
        }
        /// <summary>
        /// Process the generator.
        /// </summary>
        /// <param name="projectFile">The project file to work from.</param>
        public void Generate(string projectFile)
        {
            this.logger.LogInformation($"Loading {Path.GetFileName(projectFile)}...");

            var projectFolder = Path.GetDirectoryName(projectFile);

            // First we need to register the project.
            var project = this.workspace.RegisterProject(projectFile);

            // Register the pattern interface.
            var patternInterfaceDeclaration = this.workspace.RegisterFile("./Patterns/Itf/IModelPattern.cs")
                                              .Declarations.Single() as IInterfaceDeclaration;

            // Register the pattern implementation.
            var patternImplementationDeclaration = this.workspace.RegisterFile("./Patterns/Impl/ModelPattern.cs")
                                                   .Declarations.Single() as IGenericDeclaration <SyntaxNode>;

            // Load the project and its project dependencies. (Note that for now we only load the sources.
            // The binary assembly dependencies are not taken into account)
            var resolver = this.workspace.DeepLoad();

            // Get the base interface in order to find all extended interfaces that need to be implemented.
            var modelBaseInterface = resolver.Find("SoloX.GeneratorTools.Core.CSharp.Examples.Core.IModelBase").Single() as IGenericDeclaration <SyntaxNode>;

            // Setup a locator that will tell the location where the generated classes must be written.
            var locator = new RelativeLocator(projectFolder, project.RootNameSpace, suffix: "Impl");

            // Create the Implementation Generator with a file generator, the locator and the pattern interface/class.
            var generator = new ImplementationGenerator(
                new FileGenerator(".generated.cs"),
                locator,
                patternInterfaceDeclaration,
                patternImplementationDeclaration);

            // Loop on all interface extending the base interface.
            foreach (var modelInterface in modelBaseInterface.ExtendedBy.Where(d => d != patternInterfaceDeclaration))
            {
                this.logger.LogInformation(modelInterface.FullName);

                var implName = GeneratorHelper.ComputeClassName(modelInterface.Name);

                // Create the property writer what will use all properties from the model interface to generate
                // and write the corresponding code depending on the given patterns.
                var propertyWriter = new PropertyWriter(
                    patternInterfaceDeclaration.Properties.Single(),
                    modelInterface.Properties);

                // Setup some basic text replacement writer.
                var itfNameWriter  = new StringReplaceWriter(patternInterfaceDeclaration.Name, modelInterface.Name);
                var implNameWriter = new StringReplaceWriter(patternImplementationDeclaration.Name, implName);

                // Create the writer selector.
                var writerSelector = new WriterSelector(propertyWriter, itfNameWriter, implNameWriter);

                // And generate the class implementation.
                generator.Generate(writerSelector, (IInterfaceDeclaration)modelInterface, implName);
            }
        }
示例#7
0
        public void BaicTargetLocationTest(
            string baseFolder,
            string baseNameSpace,
            string inputNameSpace,
            string expectedLocation,
            string expectedNameSpace)
        {
            var locator = new RelativeLocator(baseFolder, baseNameSpace);

            var(targetLocation, targetNameSpace) = locator.ComputeTargetLocation(inputNameSpace);
            Assert.Equal(Normalize(targetLocation), Normalize(expectedLocation));
            Assert.Equal(targetNameSpace, expectedNameSpace);
        }
示例#8
0
        /// <inheritdoc/>
        public void Generate(string projectFile)
        {
            var projectFolder = Path.GetDirectoryName(projectFile);

            this.logger.LogInformation($"Loading {Path.GetFileName(projectFile)}...");

            var project = this.workspace.RegisterProject(projectFile);

            var locator       = new RelativeLocator(projectFolder, project.RootNameSpace, suffix: "Impl");
            var fileGenerator = new FileGenerator(".generated.cs");

            // Generate with a filter on current project interface declarations.
            this.Generate(
                locator,
                fileGenerator,
                project.Files);
        }