Skip to content

Commit

Permalink
Remove unneeded stuff
Browse files Browse the repository at this point in the history
Remove abillitly to log. Not really used anywhere
  • Loading branch information
ChristianSauer committed Jan 30, 2024
1 parent 31cc071 commit dbf4004
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 333 deletions.
57 changes: 3 additions & 54 deletions AutomaticInterface/AutomaticInterface/AutomaticInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ namespace AutomaticInterface;
[Generator]
public class AutomaticInterfaceGenerator : IIncrementalGenerator
{
private GeneratorOptions options = new();
public const string DefaultAttributeName = "GenerateAutomaticInterface";
private const string DefaultAttributeName = "GenerateAutomaticInterface";

public void Initialize(IncrementalGeneratorInitializationContext context)
{
Expand All @@ -20,8 +19,6 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
.Collect();

context.RegisterSourceOutput(classes, GenerateCode);

options = GetGeneratorOptions(context);
}

private void GenerateCode(
Expand All @@ -45,7 +42,7 @@ private void GenerateCode(
? $"${Guid.NewGuid().ToString()}"
: $"{type.ContainingNamespace}";

var code = Builder.BuildInterfaceFor(options, type);
var code = Builder.BuildInterfaceFor(type);

context.AddSource(typeNamespace, code);
}
Expand Down Expand Up @@ -82,7 +79,7 @@ CancellationToken cancellationToken

var name = ExtractName(attribute.Name);

return name is DefaultAttributeName or "GenerateAutomaticInterfaceAttribute";
return name is DefaultAttributeName;
}

private static string? ExtractName(NameSyntax? name)
Expand All @@ -94,52 +91,4 @@ CancellationToken cancellationToken
_ => null
};
}

private static GeneratorOptions GetGeneratorOptions(
IncrementalGeneratorInitializationContext context
)
{
var opts = new GeneratorOptions();
context.AnalyzerConfigOptionsProvider.Select(
(options, _) =>
{
var enableLogging =
options.GlobalOptions.TryGetValue(
"build_property.AutomaticInterface_Logging_Enable",
out var loggerEnabledValue
) && IsFeatureEnabled(loggerEnabledValue);
options.GlobalOptions.TryGetValue(
"build_property.AutomaticInterface_Logging_Path",
out var logPath
);
options.GlobalOptions.TryGetValue(
"build_property.AutomaticInterface_AttributeName",
out var attributeName
);
opts.LoggerEnabled = enableLogging;
opts.LoggerPath = logPath ?? "";
opts.AttributeName = attributeName ?? DefaultAttributeName;
return opts;
}
);

return opts;
}

private static bool IsFeatureEnabled(string counterEnabledValue)
{
return StringComparer.OrdinalIgnoreCase.Equals("enable", counterEnabledValue)
|| StringComparer.OrdinalIgnoreCase.Equals("enabled", counterEnabledValue)
|| StringComparer.OrdinalIgnoreCase.Equals("true", counterEnabledValue);
}
}

public record GeneratorOptions
{
public bool LoggerEnabled { get; set; }
public string LoggerPath { get; set; } = "";
public string AttributeName { get; set; } = AutomaticInterfaceGenerator.DefaultAttributeName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,5 @@
<ItemGroup>
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false"/>
<None Include="../../README.md" Pack="true" PackagePath="\"/>
<None Update="AutomaticInterface.props" Pack="true" PackagePath="build" />
</ItemGroup>
</Project>

This file was deleted.

21 changes: 8 additions & 13 deletions AutomaticInterface/AutomaticInterface/Builder.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;

namespace AutomaticInterface;

public static class Builder
{
private const string InheritDoc = "/// <inheritdoc />"; // we use inheritdoc because that should be able to fetch documentation from base classes.
private const string InheritDoc = "/// <inheritdoc />"; // we use inherit doc because that should be able to fetch documentation from base classes.

public static string BuildInterfaceFor(GeneratorOptions options, ITypeSymbol typeSymbol)
public static string BuildInterfaceFor(ITypeSymbol typeSymbol)
{
var classSyntax =
typeSymbol.DeclaringSyntaxReferences.First().GetSyntax() as ClassDeclarationSyntax;

if (classSyntax == null)
if (
typeSymbol.DeclaringSyntaxReferences.First().GetSyntax()
is not ClassDeclarationSyntax classSyntax
)
{
// todo logging
// Interface was applied to non class
return string.Empty;
}

Expand All @@ -34,7 +30,7 @@ public static string BuildInterfaceFor(GeneratorOptions options, ITypeSymbol typ
interfaceGenerator.AddUsings(GetUsings(typeSymbol));
interfaceGenerator.AddClassDocumentation(GetDocumentationForClass(classSyntax));
interfaceGenerator.AddGeneric(GetGeneric(classSyntax));
AddPropertiesToInterface(typeSymbol, interfaceGenerator, classSyntax);
AddPropertiesToInterface(typeSymbol, interfaceGenerator);
AddMethodsToInterface(typeSymbol, interfaceGenerator);
AddEventsToInterface(typeSymbol, interfaceGenerator);

Expand Down Expand Up @@ -132,8 +128,7 @@ private static string GetMethodSignature(IParameterSymbol x)

private static void AddPropertiesToInterface(
ITypeSymbol classSymbol,
InterfaceBuilder interfaceGenerator,
ClassDeclarationSyntax classSyntax
InterfaceBuilder interfaceGenerator
)
{
classSymbol
Expand Down
8 changes: 4 additions & 4 deletions AutomaticInterface/AutomaticInterface/InterfaceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

namespace AutomaticInterface
{
public record PropertyInfo(
internal sealed record PropertyInfo(
string Name,
string Ttype,
bool HasGet,
bool HasSet,
string Documentation
);

public record MethodInfo(
internal sealed record MethodInfo(
string Name,
string ReturnType,
string Documentation,
Expand All @@ -24,7 +24,7 @@ public record EventInfo(string Name, string Type, string Documentation);

public class InterfaceBuilder(string nameSpaceName, string interfaceName)
{
private readonly string autogenerated = """
private const string Autogenerated = """
//--------------------------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
Expand Down Expand Up @@ -93,7 +93,7 @@ public void AddEventToInterface(string name, string type, string documentation)
public string Build()
{
var cb = new CodeBuilder();
cb.Append(autogenerated);
cb.Append(Autogenerated);

if (HasNullable)
{
Expand Down
1 change: 1 addition & 0 deletions AutomaticInterface/AutomaticInterface/IsExternalInit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace System.Runtime.CompilerServices
/// This class should not be used by developers in source code.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
// ReSharper disable once UnusedType.Global
internal static class IsExternalInit { }
}

Expand Down
166 changes: 0 additions & 166 deletions AutomaticInterface/AutomaticInterface/Logger.cs

This file was deleted.

Loading

0 comments on commit dbf4004

Please sign in to comment.