From a60d313f9818a11b65d78b48a2b010f92f4fb25d Mon Sep 17 00:00:00 2001 From: Jonathon Marolf Date: Mon, 24 May 2021 19:19:21 -0700 Subject: [PATCH] remove vb mustache generator --- .../GeneratedDemo/UseMustacheGenerator.vb | 94 ------------------- .../MustacheGenerator.vb | 92 ------------------ .../VisualBasicSourceGeneratorSamples.vbproj | 4 - 3 files changed, 190 deletions(-) delete mode 100644 samples/VisualBasic/SourceGenerators/GeneratedDemo/UseMustacheGenerator.vb delete mode 100644 samples/VisualBasic/SourceGenerators/SourceGeneratorSamples/MustacheGenerator.vb diff --git a/samples/VisualBasic/SourceGenerators/GeneratedDemo/UseMustacheGenerator.vb b/samples/VisualBasic/SourceGenerators/GeneratedDemo/UseMustacheGenerator.vb deleted file mode 100644 index 2717aab0e..000000000 --- a/samples/VisualBasic/SourceGenerators/GeneratedDemo/UseMustacheGenerator.vb +++ /dev/null @@ -1,94 +0,0 @@ -Option Explicit On -Option Strict On -Option Infer On - -Imports GeneratedDemo.UseMustacheGenerator - - - - - - - -Friend Class UseMustacheGenerator - - Public Shared Sub Run() - Console.WriteLine(Mustache.Constants.Lottery) - Console.WriteLine(Mustache.Constants.HR) - Console.WriteLine(Mustache.Constants.HTML) - Console.WriteLine(Mustache.Constants.Section) - Console.WriteLine(Mustache.Constants.NestedSection) - End Sub - - ' Mustache templates and hashes from the manual at https://mustache.github.io/mustache.1.html... - Public Const t1 As String = " -Hello {{name}} -You have just won {{value}} dollars! -{{#in_ca}} -Well, {{taxed_value}} dollars, after taxes. -{{/in_ca}} -" - Public Const h1 As String = " -{ - ""name"": ""Chris"", - ""value"": 10000, - ""taxed_value"": 5000, - ""in_ca"": true -} -" - Public Const t2 As String = " -* {{name}} -* {{age}} -* {{company}} -* {{{company}}} -" - Public Const h2 As String = " -{ - ""name"": ""Chris"", - ""company"": ""GitHub"" -} -" - Public Const t3 As String = " - Shown - {{#person}} - Never shown! - {{/person}} - " - Public Const h3 As String = " -{ - ""person"": false -} -" - Public Const t4 As String = " -{{#repo}} - {{name}} -{{/repo}} -" - Public Const h4 As String = " -{ - ""repo"": [ - { ""name"": ""resque"" }, - { ""name"": ""hub"" }, - { ""name"": ""rip"" } - ] -} -" - Public Const t5 As String = " -{{#repo}} - {{name}} - {{#nested}} - NestedName: {{name}} - {{/nested}} -{{/repo}} -" - Public Const h5 As String = " -{ - ""repo"": [ - { ""name"": ""resque"", ""nested"":[{""name"":""nestedResque""}] }, - { ""name"": ""hub"" }, - { ""name"": ""rip"" } - ] -} -" - -End Class diff --git a/samples/VisualBasic/SourceGenerators/SourceGeneratorSamples/MustacheGenerator.vb b/samples/VisualBasic/SourceGenerators/SourceGeneratorSamples/MustacheGenerator.vb deleted file mode 100644 index 532c91bad..000000000 --- a/samples/VisualBasic/SourceGenerators/SourceGeneratorSamples/MustacheGenerator.vb +++ /dev/null @@ -1,92 +0,0 @@ -Option Explicit On -Option Infer On -Option Strict On - -Imports Microsoft.CodeAnalysis - -Imports Microsoft.CodeAnalysis.VisualBasic -Imports Microsoft.CodeAnalysis.VisualBasic.Syntax - -Namespace SourceGeneratorSamples - - - Public Class MustacheGenerator - Implements ISourceGenerator - - Const attributeSource = "Option Explicit On -Option Strict On -Option Infer On - -Namespace Global - - - Friend NotInheritable Class MustacheAttribute - Inherits System.Attribute - - Public ReadOnly Property Name As String - Public ReadOnly Property Template As String - Public ReadOnly Property Hash As String - - Public Sub New(name As String, template As String, hash As String) - Me.Name = name - Me.Template = template - Me.Hash = hash - End Sub - - End Class - -End Namespace -" - - Public Sub Execute(context As GeneratorExecutionContext) Implements ISourceGenerator.Execute - Dim rx = CType(context.SyntaxContextReceiver, SyntaxReceiver) - For Each element In rx.TemplateInfo - Dim source = SourceFileFromMustachePath(element.name, element.template, element.hash) - context.AddSource($"Mustache{element.name}", source) - Next - End Sub - - Private Shared Function SourceFileFromMustachePath(name As String, template As String, hash As String) As String - Dim tree = HandlebarsDotNet.Handlebars.Compile(template) - Dim [object] = Newtonsoft.Json.JsonConvert.DeserializeObject(hash) - Dim mustacheText = tree([object]) - - Return $" -Namespace Global.Mustache - - Partial Public Module Constants - - Public Const {name} As String = ""{mustacheText.Replace("""", """""")}"" - - End Module - -End Namespace" - End Function - - Public Sub Initialize(context As GeneratorInitializationContext) Implements ISourceGenerator.Initialize - context.RegisterForPostInitialization(Sub(pi) pi.AddSource("Mustache_MainAttributes__", attributeSource)) - context.RegisterForSyntaxNotifications(Function() New SyntaxReceiver()) - End Sub - - Private Class SyntaxReceiver - Implements ISyntaxContextReceiver - - Public TemplateInfo As New List(Of (name As String, template As String, hash As String)) - - Public Sub OnVisitSyntaxNode(context As GeneratorSyntaxContext) Implements ISyntaxContextReceiver.OnVisitSyntaxNode - If context.Node.Kind() = SyntaxKind.Attribute Then - Dim attrib = CType(context.Node, AttributeSyntax) - If attrib.ArgumentList?.Arguments.Count = 3 AndAlso - context.SemanticModel.GetTypeInfo(attrib).Type?.ToDisplayString() = "MustacheAttribute" Then - Dim name = context.SemanticModel.GetConstantValue(attrib.ArgumentList.Arguments(0).GetExpression).ToString() - Dim template = context.SemanticModel.GetConstantValue(attrib.ArgumentList.Arguments(1).GetExpression).ToString() - Dim hash = context.SemanticModel.GetConstantValue(attrib.ArgumentList.Arguments(2).GetExpression).ToString() - TemplateInfo.Add((name, template, hash)) - End If - End If - End Sub - End Class - - End Class - -End Namespace diff --git a/samples/VisualBasic/SourceGenerators/SourceGeneratorSamples/VisualBasicSourceGeneratorSamples.vbproj b/samples/VisualBasic/SourceGenerators/SourceGeneratorSamples/VisualBasicSourceGeneratorSamples.vbproj index 845eb4fd1..9e9f12565 100644 --- a/samples/VisualBasic/SourceGenerators/SourceGeneratorSamples/VisualBasicSourceGeneratorSamples.vbproj +++ b/samples/VisualBasic/SourceGenerators/SourceGeneratorSamples/VisualBasicSourceGeneratorSamples.vbproj @@ -12,8 +12,6 @@ - - @@ -23,8 +21,6 @@ - -