Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .run/Stryker for PR.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Stryker for PR" type="ShConfigurationType">
<option name="SCRIPT_TEXT" value=".\Run-Stryker.ps1" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="" />
<option name="SCRIPT_OPTIONS" value="" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
<option name="INTERPRETER_PATH" value="powershell.exe" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="EXECUTE_IN_TERMINAL" value="true" />
<option name="EXECUTE_SCRIPT_FILE" value="false" />
<envs />
<method v="2" />
</configuration>
</component>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public class SerializationFieldAccessibilityAnalyzer : DiagnosticAnalyzer
{
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics =>
ImmutableArray.Create(
DiagnosticDescriptors.FieldCannotBeReadonly,
DiagnosticDescriptors.FieldCannotBePublic
);

Expand All @@ -37,15 +36,6 @@ private static void AnalyzeField(SymbolAnalysisContext context)
var attrName = attribute.AttributeClass?.Name;
if (attrName == "DeserializedFieldAttribute" || attrName == "SerializedFieldAttribute")
{
if (fieldSymbol.IsReadOnly)
{
var diag = Diagnostic.Create(
DiagnosticDescriptors.FieldCannotBeReadonly,
fieldSymbol.Locations[0],
fieldSymbol.Name
);
context.ReportDiagnostic(diag);
}
if (fieldSymbol.DeclaredAccessibility == Accessibility.Public)
{
var diag = Diagnostic.Create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace AtemSharp.CodeGenerators.Analyzers
public class SerializationFieldAccessibilityCodeFixProvider : CodeFixProvider
{
public override ImmutableArray<string> FixableDiagnosticIds =>
ImmutableArray.Create("GEN008", "GEN009");
ImmutableArray.Create("GEN009");

public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer;

Expand All @@ -35,16 +35,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
return;
}

if (diagnostic.Id == "GEN008")
{
context.RegisterCodeFix(
CodeAction.Create(
"Remove readonly modifier",
c => RemoveReadonlyAsync(context.Document, fieldDecl, c),
nameof(SerializationFieldAccessibilityCodeFixProvider) + ".RemoveReadonly"),
diagnostic);
}
else if (diagnostic.Id == "GEN009")
if (diagnostic.Id == "GEN009")
{
// Offer to make private, internal, or protected
context.RegisterCodeFix(
Expand All @@ -68,20 +59,6 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
}
}

private async Task<Document> RemoveReadonlyAsync(Document document, FieldDeclarationSyntax fieldDecl, CancellationToken cancellationToken)
{
var newModifiers = fieldDecl.Modifiers.Where(m => !m.IsKind(SyntaxKind.ReadOnlyKeyword));
var newField = fieldDecl.WithModifiers(SyntaxFactory.TokenList(newModifiers));
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
if (root == null)
{
return document;
}

var newRoot = root.ReplaceNode(fieldDecl, newField);
return document.WithSyntaxRoot(newRoot);
}

private async Task<Document> ChangeAccessibilityAsync(Document document, FieldDeclarationSyntax fieldDecl, SyntaxKind newAccessibility, CancellationToken cancellationToken)
{
var modifiers = fieldDecl.Modifiers;
Expand Down
11 changes: 0 additions & 11 deletions AtemSharp.CodeGenerators/DiagnosticDescriptors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,6 @@ public static DiagnosticDescriptor CreateFieldTypeError(IFieldSymbol f)
isEnabledByDefault: true,
description: "Custom serialization methods named SerializeInternal must have a first parameter of type byte[] and optionally a second parameter of type ProtocolVersion and return void.");


public static readonly DiagnosticDescriptor FieldCannotBeReadonly = new(
"GEN008",
"Field with Serialization Attribute Cannot Be Readonly",
"Field '{0}' is marked with DeserializedFieldAttribute or SerializedFieldAttribute and cannot be readonly",
"Usage",
DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "Fields marked with DeserializedFieldAttribute or SerializedFieldAttribute must not be readonly."
);

public static readonly DiagnosticDescriptor FieldCannotBePublic = new(
"GEN009",
"Field with Serialization Attribute Cannot Be Public",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,25 @@ private static string GetPropertyCode(IFieldSymbol f)
var validationCode = validationMethod is null ? string.Empty : $"{validationMethod}(value);";
var fieldType = Helpers.GetFieldType(f);
var docComment = Helpers.GetFieldMsDocComment(f);
var visibility = f.GetAttributes().Any(a => a.AttributeClass?.Name == "InternalPropertyAttribute") ? "internal" : "public";

var setter = f.IsReadOnly
? string.Empty
: $$"""
set {
{{validationCode}}
{{f.Name}} = value;
{{flagCode}}
}
""";

return $$"""
{{docComment}}
public {{fieldType}} {{propertyName}}
{{visibility}} {{fieldType}} {{propertyName}}
{
[ExcludeFromCodeCoverage]
[ExcludeFromCodeCoverage]
get => {{f.Name}};
set {
{{validationCode}}
{{f.Name}} = value;
{{flagCode}}
}
{{setter}}
}
""";
}
Expand Down
3 changes: 2 additions & 1 deletion AtemSharp.CodeGenerators/State/StateGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ protected override void ProcessClass(SourceProductionContext spc, INamedTypeSymb
.OfType<IFieldSymbol>()
.Where(f => f.AssociatedSymbol is null)
.Where(f => !f.GetAttributes().Any(a => a.AttributeClass?.Name is "IgnoreDataMember" or "IgnoreDataMemberAttribute"))
.Where(f => !f.Name.Contains("<"))
.Select(ProcessField)
.ToArray();

Expand Down Expand Up @@ -53,7 +54,7 @@ protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName
private ProcessedField ProcessField(IFieldSymbol field)
{
var propertyName = Helpers.GetPropertyName(field);
var isReadOnly = field.GetAttributes().Any(a => a.AttributeClass?.Name is "ReadOnly" or "ReadOnlyAttribute");
var isReadOnly = field.IsReadOnly || field.GetAttributes().Any(a => a.AttributeClass?.Name is "ReadOnly" or "ReadOnlyAttribute");
var type = Helpers.GetFieldType(field);

var setterCode = isReadOnly
Expand Down
8 changes: 4 additions & 4 deletions AtemSharp.Tests/AtemSwitcherTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public async Task ReceiveCommand_ShouldUpdateState()

var evt = new SemaphoreSlim(0);

data.Atem.Macros.CurrentlyPlayingChanged += (_, _) => evt.Release();
data.Atem.Macros.Player.CurrentlyPlayingChanged += (_, _) => evt.Release();

data.Services.ClientFake.SimulateReceivedCommand(new MacroRunStatusUpdateCommand()
{
Expand All @@ -319,9 +319,9 @@ public async Task ReceiveCommand_ShouldUpdateState()

Assert.Multiple(() =>
{
Assert.That(data.Atem.Macros.CurrentlyPlaying, Is.SameAs(data.Atem.Macros[2]));
Assert.That(data.Atem.Macros.PlayLooped, Is.True);
Assert.That(data.Atem.Macros.PlaybackIsWaiting, Is.False);
Assert.That(data.Atem.Macros.Player.CurrentlyPlaying, Is.SameAs(data.Atem.Macros[2]));
Assert.That(data.Atem.Macros.Player.PlayLooped, Is.True);
Assert.That(data.Atem.Macros.Player.PlaybackIsWaiting, Is.False);
});
}

Expand Down
11 changes: 7 additions & 4 deletions AtemSharp.Tests/Commands/Macro/MacroPropertiesCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ public class CommandData : CommandDataBase

protected override MacroPropertiesCommand CreateSut(TestUtilities.CommandTests.TestCaseData<CommandData> testCase)
{
return new MacroPropertiesCommand(new AtemSharp.State.Macro.Macro(Substitute.For<IAtemSwitcher>())
var macro = new AtemSharp.State.Macro.Macro(Substitute.For<IAtemSwitcher>())
{
Id = testCase.Command.Index,
Name = testCase.Command.Name,
Description = testCase.Command.Description
});
};

macro.UpdateName(testCase.Command.Name);
macro.UpdateDescription(testCase.Command.Description);

return new MacroPropertiesCommand(macro);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ public void EmptyNameAndDescription()
var state = new TestStateHolder();
var macro = state.Macros.GetOrCreate(0);
macro.Id = 0;
macro.IsUsed = true;
macro.HasUnsupportedOps = true;
macro.Name = "WrongName";
macro.Description = "WrongDescription";
macro.UpdateIsUsed(true);
macro.UpdateHasUnsupportedOps(true);
macro.UpdateName("WrongName");
macro.UpdateDescription("WrongDescription");

command.Apply(state);
Assert.That(state.Macros.Count, Is.EqualTo(1));
Expand Down
11 changes: 7 additions & 4 deletions AtemSharp.Tests/Commands/Macro/MacroRecordCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ public class CommandData : CommandDataBase

protected override MacroRecordCommand CreateSut(TestUtilities.CommandTests.TestCaseData<CommandData> testCase)
{
return new MacroRecordCommand(new AtemSharp.State.Macro.Macro(Substitute.For<IAtemSwitcher>())
var macro = new AtemSharp.State.Macro.Macro(Substitute.For<IAtemSwitcher>())
{
Id = testCase.Command.Index,
Name = testCase.Command.Name,
Description = testCase.Command.Description,
});
};

macro.UpdateName(testCase.Command.Name);
macro.UpdateDescription(testCase.Command.Description);

return new MacroRecordCommand(macro);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ protected override void CompareStateProperties(IStateHolder state, CommandData e
{
if (expectedData.IsRecording)
{
Assert.That(state.Macros.CurrentlyRecording, Is.SameAs(state.Macros[expectedData.Index]));
Assert.That(state.Macros.Recorder.CurrentlyRecording, Is.SameAs(state.Macros[expectedData.Index]));
}
else
{
Assert.That(state.Macros.CurrentlyRecording, Is.Null);
Assert.That(state.Macros.Recorder.CurrentlyRecording, Is.Null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ protected override void CompareStateProperties(IStateHolder state, CommandData e
{
if (expectedData.IsRunning)
{
Assert.That(state.Macros.CurrentlyPlaying, Is.SameAs(state.Macros[expectedData.Index]));
Assert.That(state.Macros.Player.CurrentlyPlaying, Is.SameAs(state.Macros[expectedData.Index]));
}
else
{
Assert.That(state.Macros.CurrentlyPlaying, Is.Null);
Assert.That(state.Macros.Player.CurrentlyPlaying, Is.Null);
}

Assert.That(state.Macros.PlayLooped, Is.EqualTo(expectedData.Loop));
Assert.That(state.Macros.PlaybackIsWaiting, Is.EqualTo(expectedData.IsWaiting));
Assert.That(state.Macros.Player.PlayLooped, Is.EqualTo(expectedData.Loop));
Assert.That(state.Macros.Player.PlaybackIsWaiting, Is.EqualTo(expectedData.IsWaiting));
}
}
Loading