-
Notifications
You must be signed in to change notification settings - Fork 547
[RGen] Add an analyzer error for views that miss initWithFrame. #23788
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e7bdc2e
[RGen] Add an analyzer error for views that miss initWithFrame.
mandel-macaque a39e9ae
Auto-format source code
3f8302c
Update src/rgen/Microsoft.Macios.Bindings.Analyzer/Resources.resx
mandel-macaque 5ad11aa
It has to be initWithCoder: not initWithFrame:
mandel-macaque fe99867
Merge branch 'main' into dev/mandel/constructors-uikit
mandel-macaque b31a96a
Update the analyzer to deal with hidden inline protocol constructors
mandel-macaque 98dc8d2
Auto-format source code
cf1ba86
Merge remote-tracking branch 'origin/main' into dev/mandel/constructo…
rolfbjarne f20a288
Address code review:
mandel-macaque 769e2f2
Auto-format source code
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/rgen/Microsoft.Macios.Bindings.Analyzer/Resources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -318,6 +318,42 @@ bool ValidAsyncMethods (Binding binding, RootContext context, | |
return diagnostics.Length == 0; | ||
} | ||
|
||
bool ValidProtocolInlineConstructors (Binding binding, RootContext context, | ||
out ImmutableArray<Diagnostic> diagnostics, Location? location = null) | ||
{ | ||
diagnostics = []; | ||
// ensure that if there are any constructors that are going to be inlined from the protocols that they | ||
// do not conflict with the constructors that are already defined in the class. This is a warning, and we only | ||
// are about those constructors that have the same selectors. The user can disable the warning if he really has | ||
var builder = ImmutableArray.CreateBuilder<Diagnostic> (); | ||
// get all the selectors from the constructors defined in the class as well as the protocol ones and find | ||
// the duplicates | ||
var constructorSelectorsSet = binding.Constructors.ToDictionary (x => x.Selector!, x => x); | ||
var duplicates = binding.ProtocolConstructors | ||
.Where (x => x.Selector is not null && constructorSelectorsSet.ContainsKey (x.Selector)) | ||
.Select (x => (Selector: x.Selector!, Constructor: x)) | ||
.ToArray (); | ||
if (duplicates.Length > 0) { | ||
// we have duplicates, create a warning for each of them | ||
foreach (var (selector, protocolConstructor) in duplicates) { | ||
// use the class constructor location | ||
var constructorLocation = constructorSelectorsSet.TryGetValue (selector, out var constructor) | ||
? constructor.Location : location; | ||
var protocolName = protocolConstructor.IsProtocolConstructor ? protocolConstructor.ProtocolType : "unknown"; | ||
builder.Add (Diagnostic.Create ( | ||
descriptor: RBI0041, // The class '{0}' contains a constructor with the selector '{1}' that hides a inline constructor from a protocol | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you include the name/location of the protocol that brings in the conflicting constructor? |
||
location: constructorLocation, | ||
messageArgs: [ | ||
binding.Name, | ||
selector, | ||
protocolName | ||
])); | ||
} | ||
} | ||
diagnostics = builder.ToImmutable (); | ||
return diagnostics.Length == 0; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ClassValidator"/> class. | ||
/// </summary> | ||
|
@@ -332,6 +368,9 @@ public ClassValidator () | |
// validate that the selectors are not duplicated, this includes properties and methods | ||
AddGlobalStrategy ([RBI0034], SelectorsAreUnique); | ||
|
||
// validate that we have the required constructors for certain base classes like UIView | ||
AddGlobalStrategy ([RBI0041], ValidProtocolInlineConstructors); | ||
|
||
// validate async methods. This is a global strategy because it needs to look at all the methods in the binding | ||
// are validated together so that async methods do not have the same names | ||
AddGlobalStrategy ([RBI0035, RBI0036, RBI0037, RBI0038, RBI0039, RBI0040], ValidAsyncMethods); | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.