Skip to content

Commit

Permalink
fix: ignore abstract classes in code generation
Browse files Browse the repository at this point in the history
  • Loading branch information
jonisavo committed Oct 23, 2022
1 parent 11a52fc commit b53523b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public Task It_Generates_Layout_Call()
{
var source = @"
using UIComponents;
using UIComponents.Experimental;
[Layout(""Components/LayoutTestComponent"")]
public partial class LayoutTestComponent : UIComponent {}
Expand All @@ -23,20 +22,31 @@ public partial class LayoutTestComponent : UIComponent {}
public Task It_Does_Not_Generate_A_Call_For_Non_UIComponent_Class()
{
var source = @"
using UIComponents.Experimental;
using UIComponents;
[Layout(""Components/LayoutTestComponent"")]
public partial class LayoutTestComponent {}
";
return GeneratorTester.Verify<LayoutAugmentGenerator>(source);
}

[Fact]
public Task It_Does_Not_Generate_For_Abstract_Class()
{
var source = @"
using UIComponents;
[Layout(""Components/LayoutTestComponent"")]
public partial abstract class AbstractLayoutComponent : UIComponent {}
";
return GeneratorTester.Verify<LayoutAugmentGenerator>(source);
}

[Fact]
public Task It_Takes_AssetPrefixAttribute_Into_Account()
{
var source = @"
using UIComponents;
using UIComponents.Experimental;
[AssetPrefix(""UI/"")]
[Layout(""Components/LayoutTestComponent"")]
Expand All @@ -50,7 +60,6 @@ public Task It_Uses_Base_Class_Attribute()
{
var source = @"
using UIComponents;
using UIComponents.Experimental;
[Layout(""Components/BaseLayoutComponent"")]
public partial class BaseLayoutComponent : UIComponent {}
Expand All @@ -67,7 +76,6 @@ public Task It_Allows_Overriding_Base_Class_Attribute()
{
var source = @"
using UIComponents;
using UIComponents.Experimental;
[Layout(""Components/BaseLayoutComponent"")]
public partial class BaseLayoutComponent : UIComponent {}
Expand All @@ -83,7 +91,6 @@ public Task It_Handles_Nested_Types()
{
var source = @"
using UIComponents;
using UIComponents.Experimental;
public partial class ParentClass
{
Expand All @@ -101,7 +108,6 @@ public Task Does_Not_Generate_If_Layout_Type_Is_Missing()
{
var source = @"
using UIComponents;
using UIComponents.Experimental;
[Layout(""Components/LayoutTestComponent"")]
public partial class LayoutTestComponent : UIComponent {}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public Task It_Generates_Stylesheet_Call()
{
var source = @"
using UIComponents;
using UIComponents.Experimental;
[Stylesheet(""Components/StylesheetTestComponentStyle"")]
public partial class StylesheetTestComponent : UIComponent {}
Expand All @@ -23,7 +22,7 @@ public partial class StylesheetTestComponent : UIComponent {}
public Task It_Does_Not_Generate_A_Call_For_Non_UIComponent_Class()
{
var source = @"
using UIComponents.Experimental;
using UIComponents;
[Stylesheet(""Components/StylesheetTestComponentStyle"")]
public partial class StylesheetTestComponent {}
Expand All @@ -36,7 +35,6 @@ public Task It_Takes_AssetPrefixAttribute_Into_Account()
{
var source = @"
using UIComponents;
using UIComponents.Experimental;
[AssetPrefix(""UI/"")]
[Stylesheet(""Components/StylesheetTestComponentStyle"")]
Expand All @@ -50,7 +48,6 @@ public Task It_Inherits_Base_Class_Stylesheets()
{
var source = @"
using UIComponents;
using UIComponents.Experimental;
[Stylesheet(""Components/BaseStylesheet"")]
public abstract partial class BaseStylesheetComponent : UIComponent {}
Expand All @@ -70,7 +67,6 @@ public Task It_Handles_Nested_Types()
{
var source = @"
using UIComponents;
using UIComponents.Experimental;
public partial class ParentClass
{
Expand All @@ -88,7 +84,6 @@ public Task Does_Not_Generate_If_Stylesheet_Type_Is_Missing()
{
var source = @"
using UIComponents;
using UIComponents.Experimental;
[Stylesheet(""Components/StylesheetTestComponentStyle"")]
public partial class StylesheetTestComponent : UIComponent {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ protected override bool ShouldGenerateSource(AugmentGenerationContext context)
if (UIComponentSymbol == null || AssetPrefixAttributeSymbol == null)
return false;

if (context.CurrentTypeSymbol.IsAbstract)
return false;

CurrentAssetPrefix = GetPathAttributeValue(AssetPrefixAttributeSymbol, context);

return RoslynUtilities.HasBaseType(context.CurrentTypeSymbol, UIComponentSymbol);
Expand Down

0 comments on commit b53523b

Please sign in to comment.