Skip to content

Commit

Permalink
[Rgen] Add helper properties to determine if a code change was for a …
Browse files Browse the repository at this point in the history
…static, abstract or partial class. (#21875)

We precalculate the values form the modifiers, this later makes is
simpler when writing the code generator to check those modifiers we are
interested in without falling in the trap of executing the same LINQ
query over an over.

---------

Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
  • Loading branch information
mandel-macaque and GitHub Actions Autoformatter authored Dec 31, 2024
1 parent 1e729bf commit 5974821
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/rgen/Microsoft.Macios.Generator/DataModel/CodeChanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,34 @@ readonly struct CodeChanges {
/// </summary>
public ImmutableArray<AttributeCodeChange> Attributes { get; init; } = [];

/// <summary>
/// True if the code changes are for a static symbol.
/// </summary>
public bool IsStatic { get; private init; }

/// <summary>
/// True if the code changes are for a partial symbol.
/// </summary>
public bool IsPartial { get; private init; }

/// <summary>
/// True if the code changes are for an abstract symbol.
/// </summary>
public bool IsAbstract { get; private init; }

readonly ImmutableArray<SyntaxToken> modifiers = [];
/// <summary>
/// Modifiers list.
/// </summary>
public ImmutableArray<SyntaxToken> Modifiers { get; init; } = [];
public ImmutableArray<SyntaxToken> Modifiers {
get => modifiers;
init {
modifiers = value;
IsStatic = value.Any (m => m.IsKind (SyntaxKind.StaticKeyword));
IsPartial = value.Any (m => m.IsKind (SyntaxKind.PartialKeyword));
IsAbstract = value.Any (m => m.IsKind (SyntaxKind.AbstractKeyword));
}
}

readonly ImmutableArray<EnumMember> enumMembers = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,4 +810,85 @@ void CodeChangesFromClassDeclaration (ApplePlatform platform, string inputText,
Assert.NotNull (changes);
Assert.Equal (expected, changes.Value, comparer);
}

[Fact]
public void IsStaticPropertyTest ()
{
var changes = new CodeChanges (
bindingType: BindingType.SmartEnum,
name: "name1",
@namespace: ["NS"],
fullyQualifiedSymbol: "NS.name1",
symbolAvailability: new ());

Assert.False (changes.IsStatic);

changes = new CodeChanges (
bindingType: BindingType.SmartEnum,
name: "name1",
@namespace: ["NS"],
fullyQualifiedSymbol: "NS.name1",
symbolAvailability: new ()) {
Modifiers = [
SyntaxFactory.Token (SyntaxKind.PublicKeyword),
SyntaxFactory.Token (SyntaxKind.StaticKeyword),
]
};

Assert.True (changes.IsStatic);
}

[Fact]
public void IsPartialPropertyTest ()
{
var changes = new CodeChanges (
bindingType: BindingType.SmartEnum,
name: "name1",
@namespace: ["NS"],
fullyQualifiedSymbol: "NS.name1",
symbolAvailability: new ());

Assert.False (changes.IsPartial);

changes = new CodeChanges (
bindingType: BindingType.SmartEnum,
name: "name1",
@namespace: ["NS"],
fullyQualifiedSymbol: "NS.name1",
symbolAvailability: new ()) {
Modifiers = [
SyntaxFactory.Token (SyntaxKind.PublicKeyword),
SyntaxFactory.Token (SyntaxKind.PartialKeyword),
]
};

Assert.True (changes.IsPartial);
}

[Fact]
public void IsAbstractPropertyTest ()
{
var changes = new CodeChanges (
bindingType: BindingType.SmartEnum,
name: "name1",
@namespace: ["NS"],
fullyQualifiedSymbol: "NS.name1",
symbolAvailability: new ());

Assert.False (changes.IsAbstract);

changes = new CodeChanges (
bindingType: BindingType.SmartEnum,
name: "name1",
@namespace: ["NS"],
fullyQualifiedSymbol: "NS.name1",
symbolAvailability: new ()) {
Modifiers = [
SyntaxFactory.Token (SyntaxKind.PublicKeyword),
SyntaxFactory.Token (SyntaxKind.AbstractKeyword),
]
};

Assert.True (changes.IsAbstract);
}
}

9 comments on commit 5974821

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ [CI Build] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 597482108cc49713ffabd1eb511adaf7b319d9c6 [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ [CI Build] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 597482108cc49713ffabd1eb511adaf7b319d9c6 [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ [CI Build] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 597482108cc49713ffabd1eb511adaf7b319d9c6 [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ API diff for current PR / commit

.NET (No breaking changes)

❗ API diff vs stable (Breaking changes)

.NET (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • iOS: vsdrops gist (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • tvOS: vsdrops gist (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • MacCatalyst: vsdrops gist (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • macOS: vsdrops gist (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 597482108cc49713ffabd1eb511adaf7b319d9c6 [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💻 [CI Build] Tests on macOS M1 - Mac Monterey (12) passed 💻

All tests on macOS M1 - Mac Monterey (12) passed.

Pipeline on Agent
Hash: 597482108cc49713ffabd1eb511adaf7b319d9c6 [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💻 [CI Build] Tests on macOS X64 - Mac Sonoma (14) passed 💻

All tests on macOS X64 - Mac Sonoma (14) passed.

Pipeline on Agent
Hash: 597482108cc49713ffabd1eb511adaf7b319d9c6 [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💻 [CI Build] Tests on macOS arm64 - Mac Sequoia (15) passed 💻

All tests on macOS arm64 - Mac Sequoia (15) passed.

Pipeline on Agent
Hash: 597482108cc49713ffabd1eb511adaf7b319d9c6 [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💻 [CI Build] Tests on macOS M1 - Mac Ventura (13) passed 💻

All tests on macOS M1 - Mac Ventura (13) passed.

Pipeline on Agent
Hash: 597482108cc49713ffabd1eb511adaf7b319d9c6 [CI build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 [CI Build] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 107 tests passed 🎉

Tests counts

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ linker: All 40 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 8 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 10 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 9 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 8 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: 597482108cc49713ffabd1eb511adaf7b319d9c6 [CI build]

Please sign in to comment.