-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SG] Add support for Source Generator #2958
Conversation
# Conflicts: # Realm/Realm/DatabaseTypes/RealmObjectBase.cs # Realm/Realm/Dynamic/MetaRealmObject.cs # Realm/Realm/GlobalSuppressions.cs # Realm/Realm/Schema/ObjectSchema.cs
@@ -1985,7 +1985,7 @@ | |||
{ | |||
_realm.ThrowIfDisposed(); | |||
|
|||
var query = (RealmResults<RealmObject>)All(className); | |||
var query = (RealmResults<IRealmObject>)All(className); |
Check warning
Code scanning / CodeQL
Cast from abstract to concrete collection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went through a portion of this and have mostly stylistic comments. A few general comments which didn't have a concrete line number:
- All the changes to
Realm-Windows.sln
need to also be applied toRealm.sln
. - There seem to still be some places where we can end up with awkward spacing - while not critical, it does trigger my OCD and I'd like to do our best to generate code that is nice to look at.
|
||
internal {_accessorInterfaceName} Accessor => _accessor = _accessor ?? new {_unmanagedAccessorClassName}(typeof({_classInfo.Name})); | ||
|
||
[IgnoreDataMember, XmlIgnore] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have XmlIgnore
on many of these members in the RealmObjectBase
class - should we have it or should we remove it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that the reason why we added XmlIgnore
only to some data members was that in some cases IgnoreDataMember
was not enough. Given that adding it shouldn't be a problem, I've added it in all places in which we also have IgnoreDataMember
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think, is it fine to keep them?
Co-authored-by: Nikola Irinchev <irinchev@me.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is almost ready to go. I have some code cleanup comments and a bunch of places where I've commented on the generated class where we need to more carefully handle corner cases to ensure we generate beautiful code.
: IRealmAccessor | ||
// Should be used by generator and undocumented | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public abstract class UnmanagedAccessor : IRealmAccessor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we suppress this?
Tests/SourceGenerators/SourceGeneratorAssemblyToProcess/TestClasses/DifferentNamespaces.cs
Outdated
Show resolved
Hide resolved
Tests/SourceGenerators/SourceGeneratorAssemblyToProcess/TestClasses/DifferentNamespaces.cs
Outdated
Show resolved
Hide resolved
Tests/SourceGenerators/SourceGeneratorAssemblyToProcess/TestClasses/InnerClass.cs
Outdated
Show resolved
Hide resolved
Tests/SourceGenerators/SourceGeneratorAssemblyToProcess/TestClasses/PartialClass.cs
Outdated
Show resolved
Hide resolved
# Conflicts: # Realm/Realm/DatabaseTypes/Accessors/ManagedAccessor.cs # wrappers/realm-core
As a note, don't look at the CI. I've merged back into this branch only the changes I've done in the Realm folder, so they were easier to read here, so there's a lot of things missing that are in the other PR |
# Conflicts: # Realm/Realm/DatabaseTypes/Accessors/ManagedAccessor.cs # Realm/Realm/DatabaseTypes/Accessors/UnmanagedAccessor.cs # Tests/Realm.Tests/Sync/AsymmetricObjectTests.cs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CodeQL found more than 10 potential problems in the proposed changes. Check the Files changed tab for more details.
return; | ||
} | ||
|
||
if (classSymbol.IsAnyRealmObjectType()) |
Check warning
Code scanning / CodeQL
Dereferenced variable may be null
{ | ||
internal class DiagnosticsEmitter | ||
{ | ||
private GeneratorExecutionContext _context; |
Check notice
Code scanning / CodeQL
Missed 'readonly' opportunity
{ | ||
internal class Parser | ||
{ | ||
private GeneratorExecutionContext _context; |
Check notice
Code scanning / CodeQL
Missed 'readonly' opportunity
{ | ||
internal static class Utils | ||
{ | ||
private static List<SpecialType> _validRealmIntegerArgumentTypes = new() |
Check notice
Code scanning / CodeQL
Missed 'readonly' opportunity
SpecialType.System_Int64 | ||
}; | ||
|
||
private static List<SpecialType> _validIntegerTypes = new() |
Check notice
Code scanning / CodeQL
Missed 'readonly' opportunity
if (setValueLines.Length == 0) | ||
{ | ||
setValueBody = $@"throw new MissingMemberException($""The object does not have a settable Realm property with name {{propertyName}}"");"; | ||
} | ||
else | ||
{ | ||
setValueBody = $@"switch (propertyName) | ||
{{ | ||
{setValueLines.Indent(1, trimNewLines: true)} | ||
default: | ||
throw new MissingMemberException($""The object does not have a settable Realm property with name {{propertyName}}""); | ||
}}"; | ||
} |
Check notice
Code scanning / CodeQL
Missed ternary opportunity
if (getListValueLines.Length == 0) | ||
{ | ||
getListValueBody = $@"throw new MissingMemberException($""The object does not have a Realm list property with name {{propertyName}}"");"; | ||
} | ||
else | ||
{ | ||
getListValueBody = $@"return propertyName switch | ||
{{ | ||
{getListValueLines} | ||
_ => throw new MissingMemberException($""The object does not have a Realm list property with name {{propertyName}}""), | ||
}};"; | ||
} |
Check notice
Code scanning / CodeQL
Missed ternary opportunity
if (getSetValueLines.Length == 0) | ||
{ | ||
getSetValueBody = $@"throw new MissingMemberException($""The object does not have a Realm set property with name {{propertyName}}"");"; | ||
} | ||
else | ||
{ | ||
getSetValueBody = $@"return propertyName switch | ||
{{ | ||
{getSetValueLines} | ||
_ => throw new MissingMemberException($""The object does not have a Realm set property with name {{propertyName}}""), | ||
}};"; | ||
} |
Check notice
Code scanning / CodeQL
Missed ternary opportunity
if (getDictionaryValueLines.Length == 0) | ||
{ | ||
getDictionaryValueBody = $@"throw new MissingMemberException($""The object does not have a Realm dictionary property with name {{propertyName}}"");"; | ||
} | ||
else | ||
{ | ||
getDictionaryValueBody = $@"return propertyName switch | ||
{{ | ||
{getDictionaryValueLines.Indent(1, trimNewLines: true)} | ||
_ => throw new MissingMemberException($""The object does not have a Realm dictionary property with name {{propertyName}}""), | ||
}};"; | ||
} |
Check notice
Code scanning / CodeQL
Missed ternary opportunity
if (property.TypeInfo.IsBacklink) | ||
{ | ||
getFieldString = "GetBacklinks"; | ||
} | ||
else | ||
{ | ||
getFieldString = property.TypeInfo.CollectionType switch | ||
{ | ||
CollectionType.List => "GetListValue", | ||
CollectionType.Set => "GetSetValue", | ||
CollectionType.Dictionary => "GetDictionaryValue", | ||
_ => throw new NotImplementedException(), | ||
}; | ||
} |
Check notice
Code scanning / CodeQL
Missed ternary opportunity
# Conflicts: # .github/templates/common.lib.yml # .github/templates/test.lib.yml # .github/workflows/test-android.yml # .github/workflows/test-ios.yml # .github/workflows/test-macos.yml # .github/workflows/test-net-core.yml # .github/workflows/test-net-framework.yml # .github/workflows/test-uwp-managed.yml
No description provided.