Skip to content

Commit

Permalink
Fixes #75: Improves inheritdoc so that developer documentation is pro…
Browse files Browse the repository at this point in the history
…perly referenced on the autogenerated interfaces
  • Loading branch information
ChaseFlorell committed Nov 4, 2024
1 parent f30a718 commit 8728df6
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 71 deletions.
20 changes: 9 additions & 11 deletions AutomaticInterface/AutomaticInterface/Builder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ namespace AutomaticInterface;

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

private static readonly SymbolDisplayFormat MethodSignatureDisplayFormat =
new(
memberOptions: SymbolDisplayMemberOptions.IncludeParameters,
parameterOptions: SymbolDisplayParameterOptions.IncludeType
| SymbolDisplayParameterOptions.IncludeParamsRefOut
| SymbolDisplayParameterOptions.IncludeParamsRefOut
);

private static readonly SymbolDisplayFormat TypeDisplayFormat =
Expand All @@ -24,7 +24,7 @@ public static class Builder
typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces,
genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters,
miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes
| SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier
| SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier
);

public static string BuildInterfaceFor(ITypeSymbol typeSymbol)
Expand Down Expand Up @@ -67,6 +67,7 @@ private static string GetNameSpace(ISymbol typeSymbol)
{
return typeSymbol.ContainingNamespace.ToDisplayString();
}

var customNs = generationAttribute.ConstructorArguments.FirstOrDefault().Value?.ToString();

return string.IsNullOrWhiteSpace(customNs)
Expand All @@ -92,10 +93,7 @@ InterfaceBuilder codeGenerator
.GroupBy(x => x.ToDisplayString(MethodSignatureDisplayFormat))
.Select(g => g.First())
.ToList()
.ForEach(method =>
{
AddMethod(codeGenerator, method);
});
.ForEach(method => { AddMethod(codeGenerator, method); });
}

private static void AddMethod(InterfaceBuilder codeGenerator, IMethodSymbol method)
Expand All @@ -117,7 +115,7 @@ private static void AddMethod(InterfaceBuilder codeGenerator, IMethodSymbol meth
codeGenerator.AddMethodToInterface(
name,
returnType.ToDisplayString(TypeDisplayFormat),
InheritDoc,
InheritDoc(method.ToDisplayString()),
paramResult,
typedArgs
);
Expand Down Expand Up @@ -197,7 +195,7 @@ InterfaceBuilder codeGenerator
codeGenerator.AddEventToInterface(
name,
type.ToDisplayString(TypeDisplayFormat),
InheritDoc
InheritDoc(evt.ToDisplayString())
);
});
}
Expand Down Expand Up @@ -285,7 +283,7 @@ InterfaceBuilder interfaceGenerator
hasGet,
hasSet,
isRef,
InheritDoc
InheritDoc(prop.ToDisplayString())
);
});
}
Expand Down Expand Up @@ -351,4 +349,4 @@ private static string GetGeneric(TypeDeclarationSyntax classSyntax)

return formattedGeneric;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ namespace AutomaticInterfaceExample
)]
public class DemoClass2 : IDemoClass2
{
public void Test() { }
/// <summary>
/// This is a test method
/// </summary>
public void Test()
{
}
}
}
}
22 changes: 11 additions & 11 deletions AutomaticInterface/Tests/GeneratorTests.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc />
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.Hello" />
string Hello { get; }

}
Expand Down Expand Up @@ -85,7 +85,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc />
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.Hello" />
string Hello { get; }

}
Expand Down Expand Up @@ -139,7 +139,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc />
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.NullableProperty" />
string? NullableProperty { get; set; }

}
Expand Down Expand Up @@ -195,7 +195,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc />
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.NullableProperty" />
global::System.Threading.Tasks.Task<string?> NullableProperty { get; set; }

}
Expand Down Expand Up @@ -243,7 +243,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface ISecondClass
{
/// <inheritdoc />
/// <inheritdoc cref="AutomaticInterfaceExample.SecondClass.AProperty" />
int AProperty { get; set; }

}
Expand Down Expand Up @@ -288,7 +288,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc />
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.SomeProperty" />
string SomeProperty { get; set; }

}
Expand Down Expand Up @@ -334,7 +334,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc />
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.SomeProperty" />
string SomeProperty { get; set; }

}
Expand Down Expand Up @@ -377,7 +377,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc />
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.Hello" />
string Hello { get; set; }

}
Expand Down Expand Up @@ -421,7 +421,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc />
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.Hello" />
string Hello { set; }

}
Expand Down Expand Up @@ -465,7 +465,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc />
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.Hello" />
string Hello { get; }

}
Expand Down Expand Up @@ -508,7 +508,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc />
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.Hello" />
string Hello { get; init; }

}
Expand Down
16 changes: 8 additions & 8 deletions AutomaticInterface/Tests/GeneratorTests.TypeResolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc />
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.Hello" />
string Hello { get; set; }

}
Expand Down Expand Up @@ -77,7 +77,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc />
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.Hello" />
string Hello { get; set; }

}
Expand Down Expand Up @@ -120,7 +120,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc />
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.Hello" />
global::System.Threading.Tasks.Task Hello { get; set; }

}
Expand Down Expand Up @@ -169,10 +169,10 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface IModelManager
{
/// <inheritdoc />
/// <inheritdoc cref="AutomaticInterfaceExample.ModelManager.GetModel1()" />
global::AutomaticInterfaceExample.Models1.Model GetModel1();

/// <inheritdoc />
/// <inheritdoc cref="AutomaticInterfaceExample.ModelManager.GetModel2()" />
global::AutomaticInterfaceExample.Models2.Model GetModel2();

}
Expand Down Expand Up @@ -222,7 +222,7 @@ namespace RootNamespace.ModelManager
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface IModelManager
{
/// <inheritdoc />
/// <inheritdoc cref="RootNamespace.ModelManager.ModelManager.GetModel()" />
global::RootNamespace.Models.Model GetModel();

}
Expand Down Expand Up @@ -268,7 +268,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc />
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.GetTask()" />
global::System.Threading.Tasks.Task GetTask();

}
Expand Down Expand Up @@ -314,7 +314,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc />
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.GetClass()" />
global::GlobalNamespace.AClass GetClass();

}
Expand Down
Loading

0 comments on commit 8728df6

Please sign in to comment.