Skip to content

Commit

Permalink
fix: Added GeneratedCode/ExcludeFromCodeCoverage attributes to genera…
Browse files Browse the repository at this point in the history
…ted code.
  • Loading branch information
HavenDV committed Sep 23, 2023
1 parent dfcf042 commit 2433936
Show file tree
Hide file tree
Showing 237 changed files with 1,594 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace {@class.Namespace}
public{GenerateModifiers(@class)} partial class {@class.Name}{GenerateBaseType(@class)}
{{
{GenerateXmlDocumentationFrom(property.XmlDocumentation, property, isProperty: false)}
{GenerateGeneratedCodeAttribute()}
{GeneratePropertyModifier(property)} static readonly {GeneratePropertyType(@class, property)} {GenerateDependencyPropertyName(property)} =
{GenerateManagerType(@class)}.{GenerateRegisterMethod(@class, property)}(
{GenerateRegisterAttachedMethodArguments(@class, property)});
Expand All @@ -28,6 +29,8 @@ namespace {@class.Namespace}
{GenerateDesignerSerializationVisibilityAttribute(property.DesignerSerializationVisibility)}
{GenerateClsCompliantAttribute(property.ClsCompliant)}
{GenerateLocalizabilityAttribute(property.Localizability, @class.Framework)}
{GenerateGeneratedCodeAttribute()}
{GenerateExcludeFromCodeCoverageAttribute()}
{(property.IsReadOnly ? "internal" : "public")} static void Set{property.Name}({GenerateDependencyObjectType(@class.Framework)} element, {GenerateType(property)} value)
{{
element = element ?? throw new global::System.ArgumentNullException(nameof(element));
Expand All @@ -45,6 +48,8 @@ namespace {@class.Namespace}
{GenerateBrowsableForTypeAttribute(property)}
{GenerateClsCompliantAttribute(property.ClsCompliant)}
{GenerateLocalizabilityAttribute(property.Localizability, @class.Framework)}
{GenerateGeneratedCodeAttribute()}
{GenerateExcludeFromCodeCoverageAttribute()}
public static {GenerateType(property)} Get{property.Name}({GenerateDependencyObjectType(@class.Framework)} element)
{{
element = element ?? throw new global::System.ArgumentNullException(nameof(element));
Expand Down
18 changes: 18 additions & 0 deletions src/libs/DependencyPropertyGenerator/Sources/Sources.Attributes.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
using System.ComponentModel;
using System.Reflection;
using H.Generators.Extensions;

namespace H.Generators;

internal static partial class Sources
{
private static string Version { get; } = $"{Assembly.GetExecutingAssembly().GetName().Version}";

private static string GenerateAttribute(string name)
{
return $" [global::{name}]";
}

private static string GenerateAttribute(string name, string? value)
{
if (value == null)
Expand Down Expand Up @@ -100,6 +108,16 @@ private static string GenerateClsCompliantAttribute(bool? value)
return GenerateAttribute("System.CLSCompliant", value?.ToBooleanKeyword());
}

private static string GenerateGeneratedCodeAttribute()
{
return GenerateAttribute("System.CodeDom.Compiler.GeneratedCode", $"\"DependencyPropertyGenerator\", \"{Version}\"");
}

private static string GenerateExcludeFromCodeCoverageAttribute()
{
return GenerateAttribute("System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage");
}

private static string GenerateLocalizabilityAttribute(string? value, Framework framework)
{
if (value == null || framework != Framework.Wpf)
Expand Down
14 changes: 14 additions & 0 deletions src/libs/DependencyPropertyGenerator/Sources/Sources.Callbacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@ private static string GenerateOnChangedMethods(DependencyPropertyData property)

return property.IsAttached
? $@"
{GenerateGeneratedCodeAttribute()}
static partial void On{property.Name}Changed();
{GenerateGeneratedCodeAttribute()}
static partial void On{property.Name}Changed({GenerateBrowsableForType(property)} {GenerateBrowsableForTypeParameterName(property)});
{GenerateGeneratedCodeAttribute()}
static partial void On{property.Name}Changed({GenerateBrowsableForType(property)} {GenerateBrowsableForTypeParameterName(property)}, {GenerateType(property)} newValue);
{GenerateGeneratedCodeAttribute()}
static partial void On{property.Name}Changed({GenerateBrowsableForType(property)} {GenerateBrowsableForTypeParameterName(property)}, {GenerateType(property)} oldValue, {GenerateType(property)} newValue);"
: $@"
{GenerateGeneratedCodeAttribute()}
partial void On{property.Name}Changed();
{GenerateGeneratedCodeAttribute()}
partial void On{property.Name}Changed({GenerateType(property)} newValue);
{GenerateGeneratedCodeAttribute()}
partial void On{property.Name}Changed({GenerateType(property)} oldValue, {GenerateType(property)} newValue);";
}

Expand All @@ -31,13 +38,20 @@ private static string GenerateOnChangingMethods(DependencyPropertyData property)

return property.IsAttached
? $@"
{GenerateGeneratedCodeAttribute()}
static partial void On{property.Name}Changing();
{GenerateGeneratedCodeAttribute()}
static partial void On{property.Name}Changing({GenerateBrowsableForType(property)} {GenerateBrowsableForTypeParameterName(property)});
{GenerateGeneratedCodeAttribute()}
static partial void On{property.Name}Changing({GenerateBrowsableForType(property)} {GenerateBrowsableForTypeParameterName(property)}, {GenerateType(property)} newValue);
{GenerateGeneratedCodeAttribute()}
static partial void On{property.Name}Changing({GenerateBrowsableForType(property)} {GenerateBrowsableForTypeParameterName(property)}, {GenerateType(property)} oldValue, {GenerateType(property)} newValue);"
: $@"
{GenerateGeneratedCodeAttribute()}
partial void On{property.Name}Changing();
{GenerateGeneratedCodeAttribute()}
partial void On{property.Name}Changing({GenerateType(property)} newValue);
{GenerateGeneratedCodeAttribute()}
partial void On{property.Name}Changing({GenerateType(property)} oldValue, {GenerateType(property)} newValue);";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace {@class.Namespace}
public{@class.Modifiers} partial class {@class.Name}
{{
{GenerateXmlDocumentationFrom(property.XmlDocumentation, property, isProperty: false)}
{GenerateGeneratedCodeAttribute()}
{GeneratePropertyModifier(property)} static readonly {GeneratePropertyType(@class, property)} {GenerateDependencyPropertyName(property)} =
{GenerateDependencyPropertyCreateCall(@class, property)}
Expand All @@ -29,6 +30,8 @@ namespace {@class.Namespace}
{GenerateDesignerSerializationVisibilityAttribute(property.DesignerSerializationVisibility)}
{GenerateClsCompliantAttribute(property.ClsCompliant)}
{GenerateLocalizabilityAttribute(property.Localizability, @class.Framework)}
{GenerateGeneratedCodeAttribute()}
{GenerateExcludeFromCodeCoverageAttribute()}
public {GenerateType(property)} {property.Name}
{{
{GenerateGetter(property)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ namespace {@class.Namespace}
public{@class.Modifiers} partial class {@class.Name}
{{
{GenerateXmlDocumentationFrom(@event.XmlDocumentation, @event)}
{GenerateGeneratedCodeAttribute()}
public static readonly {GenerateRoutedEventType(@class)} {@event.Name}Event =
{GenerateEventManagerType(@class)}.{GenerateRegisterMethod(@class)}(
{GenerateRegisterRoutedEventMethodArguments(@class, @event)});
{GenerateXmlDocumentationFrom(@event.EventXmlDocumentation, @event)}
{GenerateCategoryAttribute(@event.Category)}
{GenerateDescriptionAttribute(@event.Description)}
{GenerateGeneratedCodeAttribute()}
{GenerateExcludeFromCodeCoverageAttribute()}
public event {GenerateRouterEventType(@class, @event)} {@event.Name}
{{
add => AddHandler({@event.Name}Event, value);
Expand All @@ -38,6 +41,8 @@ namespace {@class.Namespace}
/// <summary>
/// A helper method to raise the {@event.Name} event.
/// </summary>
{GenerateGeneratedCodeAttribute()}
{GenerateExcludeFromCodeCoverageAttribute()}
protected {GenerateRoutedEventArgsType(@class)} On{@event.Name}()
{{
var args = new {GenerateRoutedEventArgsType(@class)}({@event.Name}Event);
Expand Down Expand Up @@ -197,8 +202,8 @@ private static string GenerateRegisterRoutedEventMethodArguments(ClassData @clas
if (@class.Framework == Framework.Avalonia)
{
return @$"
name: ""{@event.Name}"",
routingStrategy: {GenerateRoutingStrategyType(@class)}.{@event.Strategy}";
name: ""{@event.Name}"",
routingStrategy: {GenerateRoutingStrategyType(@class)}.{@event.Strategy}";
}

return @$"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ namespace {@class.Namespace}
{{
public{@class.Modifiers} partial class {@class.Name}
{{
{GenerateGeneratedCodeAttribute()}
{GenerateExcludeFromCodeCoverageAttribute()}
private class {@event.Name}WeakEventManager : global::System.Windows.WeakEventManager
{{
private {@event.Name}WeakEventManager()
Expand Down Expand Up @@ -91,6 +93,8 @@ protected override void StopListening(object? source)
}}
{GenerateXmlDocumentationFrom(@event.EventXmlDocumentation, @event)}
{GenerateGeneratedCodeAttribute()}
{GenerateExcludeFromCodeCoverageAttribute()}
public{modifiers} event {GenerateEventHandlerType(@event)} {@event.Name}
{{
add => {@event.Name}WeakEventManager.AddHandler(null, value);
Expand All @@ -100,6 +104,8 @@ protected override void StopListening(object? source)
/// <summary>
/// A helper method to raise the {@event.Name} event.
/// </summary>
{GenerateGeneratedCodeAttribute()}
{GenerateExcludeFromCodeCoverageAttribute()}
internal{modifiers} void Raise{@event.Name}Event(object? sender{additionalParameters})
{{
{@event.Name}WeakEventManager.CurrentManager.On{@event.Name}(sender, {args});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,27 @@ public partial class UnrelatedStateControl
/// Identifies the <see cref="Text"/> dependency property.<br/>
/// Default value: default(string)
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
public static readonly global::Avalonia.StyledProperty<string?> TextProperty =
global::Avalonia.Controls.TextBox.TextProperty.AddOwner<global::H.Generators.IntegrationTests.UnrelatedStateControl>(
null);

/// <summary>
/// Default value: default(string)
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public string? Text
{
get => (string?)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}

[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
partial void OnTextChanged();
[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
partial void OnTextChanged(string? newValue);
[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
partial void OnTextChanged(string? oldValue, string? newValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public partial class UnrelatedStateControl
/// Identifies the <see cref="Text"/> dependency property.<br/>
/// Default value: default(string)
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
public static readonly global::System.Windows.DependencyProperty TextProperty =
global::System.Windows.Controls.TextBox.TextProperty.AddOwner(
ownerType: typeof(global::H.Generators.IntegrationTests.UnrelatedStateControl),
Expand All @@ -18,14 +19,19 @@ public partial class UnrelatedStateControl
/// <summary>
/// Default value: default(string)
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public string? Text
{
get => (string?)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}

[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
partial void OnTextChanged();
[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
partial void OnTextChanged(string? newValue);
[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
partial void OnTextChanged(string? oldValue, string? newValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,27 @@ public partial class UnrelatedStateControl
/// Identifies the <see cref="Background"/> dependency property.<br/>
/// Default value: default(IBrush)
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
public static readonly global::Avalonia.StyledProperty<global::Avalonia.Media.IBrush?> BackgroundProperty =
global::Avalonia.Controls.Border.BackgroundProperty.AddOwner<global::H.Generators.IntegrationTests.UnrelatedStateControl>(
null);

/// <summary>
/// Default value: default(IBrush)
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public global::Avalonia.Media.IBrush? Background
{
get => (global::Avalonia.Media.IBrush?)GetValue(BackgroundProperty);
set => SetValue(BackgroundProperty, value);
}

[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
partial void OnBackgroundChanged();
[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
partial void OnBackgroundChanged(global::Avalonia.Media.IBrush? newValue);
[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
partial void OnBackgroundChanged(global::Avalonia.Media.IBrush? oldValue, global::Avalonia.Media.IBrush? newValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public partial class UnrelatedStateControl
/// Identifies the <see cref="Background"/> dependency property.<br/>
/// Default value: default(Brush)
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
public static readonly global::System.Windows.DependencyProperty BackgroundProperty =
global::System.Windows.Controls.Border.BackgroundProperty.AddOwner(
ownerType: typeof(global::H.Generators.IntegrationTests.UnrelatedStateControl),
Expand All @@ -18,14 +19,19 @@ public partial class UnrelatedStateControl
/// <summary>
/// Default value: default(Brush)
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public global::System.Windows.Media.Brush? Background
{
get => (global::System.Windows.Media.Brush?)GetValue(BackgroundProperty);
set => SetValue(BackgroundProperty, value);
}

[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
partial void OnBackgroundChanged();
[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
partial void OnBackgroundChanged(global::System.Windows.Media.Brush? newValue);
[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
partial void OnBackgroundChanged(global::System.Windows.Media.Brush? oldValue, global::System.Windows.Media.Brush? newValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public partial class GridExtensions : global::Avalonia.AvaloniaObject
/// Identifies the SomeProperty dependency property.<br/>
/// Default value: default(object)
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
public static readonly global::Avalonia.AttachedProperty<object?> SomePropertyProperty =
global::Avalonia.AvaloniaProperty.RegisterAttached<global::H.Generators.IntegrationTests.GridExtensions, global::Avalonia.AvaloniaObject, object?>(
name: "SomeProperty",
Expand All @@ -22,6 +23,8 @@ public partial class GridExtensions : global::Avalonia.AvaloniaObject
/// <summary>
/// Default value: default(object)
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public static void SetSomeProperty(global::Avalonia.AvaloniaObject element, object? value)
{
element = element ?? throw new global::System.ArgumentNullException(nameof(element));
Expand All @@ -32,16 +35,22 @@ public static void SetSomeProperty(global::Avalonia.AvaloniaObject element, obje
/// <summary>
/// Default value: default(object)
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public static object? GetSomeProperty(global::Avalonia.AvaloniaObject element)
{
element = element ?? throw new global::System.ArgumentNullException(nameof(element));

return (object?)element.GetValue(SomePropertyProperty);
}

[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
static partial void OnSomePropertyChanged();
[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
static partial void OnSomePropertyChanged(global::Avalonia.AvaloniaObject avaloniaObject);
[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
static partial void OnSomePropertyChanged(global::Avalonia.AvaloniaObject avaloniaObject, object? newValue);
[global::System.CodeDom.Compiler.GeneratedCode("DependencyPropertyGenerator", "1.3.1.0")]
static partial void OnSomePropertyChanged(global::Avalonia.AvaloniaObject avaloniaObject, object? oldValue, object? newValue);
}
}
Loading

0 comments on commit 2433936

Please sign in to comment.