init
This commit is contained in:
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
bin/
|
||||
obj/
|
||||
/packages/
|
||||
riderModule.iml
|
||||
/_ReSharper.Caches/
|
||||
13
.idea/.idea.Polonium.Tasks/.idea/.gitignore
generated
vendored
Normal file
13
.idea/.idea.Polonium.Tasks/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/.idea.Polonium.Tasks.iml
|
||||
/modules.xml
|
||||
/projectSettingsUpdater.xml
|
||||
/contentModel.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
42
Polonium.Tasks.csproj
Normal file
42
Polonium.Tasks.csproj
Normal file
@@ -0,0 +1,42 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<IsPackable>true</IsPackable>
|
||||
<Nullable>disable</Nullable>
|
||||
<LangVersion>latest</LangVersion>
|
||||
|
||||
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
|
||||
|
||||
<RootNamespace>Polonium.Tasks</RootNamespace>
|
||||
<AssemblyName>Polonium.Tasks</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Build" Version="17.12.6" />
|
||||
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="17.12.6" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.3.0"/>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.3.0"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AdditionalFiles Remove="AnalyzerReleases.Shipped.md" />
|
||||
<AdditionalFiles Remove="AnalyzerReleases.Unshipped.md" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
24
Polonium.Tasks.sln
Normal file
24
Polonium.Tasks.sln
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Polonium.Tasks", "Polonium.Tasks.csproj", "{49610BA8-35D1-4185-AF6D-3DB5A7131DF8}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{49610BA8-35D1-4185-AF6D-3DB5A7131DF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{49610BA8-35D1-4185-AF6D-3DB5A7131DF8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{49610BA8-35D1-4185-AF6D-3DB5A7131DF8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{49610BA8-35D1-4185-AF6D-3DB5A7131DF8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{856F2142-B22B-43A9-86DD-4FD799CCA66B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{856F2142-B22B-43A9-86DD-4FD799CCA66B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{856F2142-B22B-43A9-86DD-4FD799CCA66B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{856F2142-B22B-43A9-86DD-4FD799CCA66B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B2944CFE-84E9-4B8A-87E2-7113C5EA3A70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B2944CFE-84E9-4B8A-87E2-7113C5EA3A70}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B2944CFE-84E9-4B8A-87E2-7113C5EA3A70}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B2944CFE-84E9-4B8A-87E2-7113C5EA3A70}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
88
Resources.Designer.cs
generated
Normal file
88
Resources.Designer.cs
generated
Normal file
@@ -0,0 +1,88 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Polonium.Tasks
|
||||
{
|
||||
using System;
|
||||
|
||||
|
||||
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources
|
||||
{
|
||||
private static System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance",
|
||||
"CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources()
|
||||
{
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static System.Resources.ResourceManager ResourceManager
|
||||
{
|
||||
get
|
||||
{
|
||||
if (object.Equals(null, resourceMan))
|
||||
{
|
||||
System.Resources.ResourceManager temp =
|
||||
new System.Resources.ResourceManager("Polonium.Tasks.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static System.Globalization.CultureInfo Culture
|
||||
{
|
||||
get { return resourceCulture; }
|
||||
set { resourceCulture = value; }
|
||||
}
|
||||
|
||||
internal static string AB0001Description
|
||||
{
|
||||
get { return ResourceManager.GetString("AB0001Description", resourceCulture); }
|
||||
}
|
||||
|
||||
internal static string AB0001MessageFormat
|
||||
{
|
||||
get { return ResourceManager.GetString("AB0001MessageFormat", resourceCulture); }
|
||||
}
|
||||
|
||||
internal static string AB0001Title
|
||||
{
|
||||
get { return ResourceManager.GetString("AB0001Title", resourceCulture); }
|
||||
}
|
||||
|
||||
internal static string AB0001CodeFixTitle
|
||||
{
|
||||
get { return ResourceManager.GetString("AB0001CodeFixTitle", resourceCulture); }
|
||||
}
|
||||
|
||||
internal static string AB0002Description
|
||||
{
|
||||
get { return ResourceManager.GetString("AB0002Description", resourceCulture); }
|
||||
}
|
||||
|
||||
internal static string AB0002MessageFormat
|
||||
{
|
||||
get { return ResourceManager.GetString("AB0002MessageFormat", resourceCulture); }
|
||||
}
|
||||
|
||||
internal static string AB0002Title
|
||||
{
|
||||
get { return ResourceManager.GetString("AB0002Title", resourceCulture); }
|
||||
}
|
||||
}
|
||||
}
|
||||
85
src/GenerateProxyNodesTask.cs
Normal file
85
src/GenerateProxyNodesTask.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.Build.Framework;
|
||||
using Microsoft.Build.Utilities;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
namespace Polonium.Tasks;
|
||||
|
||||
public class GenerateProxyNodesTask : Task
|
||||
{
|
||||
[Required]
|
||||
public string SourceDirectory { get; set; }
|
||||
|
||||
[Required]
|
||||
public string OutputDirectory { get; set; }
|
||||
|
||||
[Required]
|
||||
public string AttributeName { get; set; }
|
||||
|
||||
public override bool Execute()
|
||||
{
|
||||
try
|
||||
{
|
||||
if(Directory.Exists(OutputDirectory))
|
||||
Directory.Delete(OutputDirectory, true);
|
||||
Directory.CreateDirectory(OutputDirectory);
|
||||
|
||||
string[] csFiles = Directory.GetFiles(SourceDirectory, "*.cs", SearchOption.AllDirectories);
|
||||
foreach (string csFile in csFiles)
|
||||
{
|
||||
string code = File.ReadAllText(csFile);
|
||||
SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(code);
|
||||
CompilationUnitSyntax root = syntaxTree.GetCompilationUnitRoot();
|
||||
IEnumerable<ClassDeclarationSyntax> classes = root.DescendantNodes().OfType<ClassDeclarationSyntax>()
|
||||
.Where(cls => cls.AttributeLists
|
||||
.SelectMany(attrList => attrList.Attributes)
|
||||
.Any(attr => attr.Name.ToString().Contains(AttributeName)));
|
||||
|
||||
foreach (ClassDeclarationSyntax cls in classes)
|
||||
{
|
||||
string className = cls.Identifier.Text;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine("using Godot;");
|
||||
sb.AppendLine($"namespace GlobalProxy {{");
|
||||
sb.AppendLine($" [GlobalClass]");
|
||||
sb.AppendLine($" [Tool]");
|
||||
sb.AppendLine($" public partial class {className} : {GetDisplayName(cls)} {{ }}");
|
||||
sb.AppendLine("}");
|
||||
|
||||
string outputFile = Path.Combine(OutputDirectory, $"{className}.cs");
|
||||
File.WriteAllText(outputFile, sb.ToString());
|
||||
Log.LogMessage(MessageImportance.High, $"Generated proxy file: {outputFile}");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.LogErrorFromException(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private string GetDisplayName(ClassDeclarationSyntax cls)
|
||||
{
|
||||
string name = cls.Identifier.Text;
|
||||
SyntaxNode node = cls.Parent;
|
||||
while (node is not null)
|
||||
{
|
||||
if(node is NamespaceDeclarationSyntax ns)
|
||||
name = ns.Name.ToString() + "." + name;
|
||||
else if (node is FileScopedNamespaceDeclarationSyntax fs)
|
||||
name = fs.Name.ToString() + "." + name;
|
||||
node = node.Parent;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user