[analysis_server] Do not offer CreateClass for method invocations on non-prefix targets - #64193
Conversation
…non-prefix targets Fixes dart-lang#64192 Work towards dart-lang#63444
|
Thank you for your contribution! This project uses Gerrit for code reviews. Your pull request has automatically been converted into a code review at: https://dart-review.googlesource.com/c/sdk/+/545180 Please wait for a developer to review your code review at the above link; you can speed up the review if you sign into Gerrit and manually add a reviewer that has recently worked on the relevant code. See CONTRIBUTING.md to learn how to upload changes to Gerrit directly. Additional commits pushed to this PR will update both the PR and the corresponding Gerrit CL. After the review is complete on the CL, your reviewer will merge the CL (automatically closing this PR). |
|
Gerrit CL has been approved, please wait for a reviewer to merge it. |
|
Gerrit CL has been approved, please wait for a reviewer to merge it. |
Summary
Do not offer the
Create classquick fix on method invocations where the target is not an import prefix.In Dart, an invocation of the form
target.name()can only be a class instantiation iftargetis an import prefix (PrefixElement). Previously, when calling an undefined member on a class (e.g.C.m()),target.staticTypeevaluated tonull, causingCreateClassto erroneously offer to create a top-levelclass m.Fixes #64192
Work towards #63444
Changes
CreateClass.producersinpkg/analysis_server/lib/src/services/correction/dart/create_class.dartto verify that whentargetNode == methodName,targetmust either benull(unqualified invocation) or aPrefixElement. Iftarget != nulland not an import prefix, creating a class is rejected.pkg/analysis_server/test/src/services/correction/fix/create_class_test.dartcovering lowercase and uppercase static method invocations, as well as preserving support for undefined target invocations (e.g.Foo.bar()).