Because of the reversed condition, the priority for primary constructor
bodies wasn't being added when the lint was disabled, causing it to not
be moved, resulting in seemingly inconsistent results.
Change-Id: I5110e39e066414e04bb69f61b3aa7189875469f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/507460
Reviewed-by: Samuel Rawlins <srawlins@google.com>
(Part of https://github.com/dart-lang/sdk/issues/63288)
This change migrates the packages owned by the developer experience
team to use the new constructor declaration syntax, described in
https://github.com/dart-lang/language/blob/main/accepted/future-releases/primary-constructors/feature-specification.md#abbreviations-of-in-body-constructor-declarations.
This change was performed in an automated fashion, by (a) bumping the
packages' SDK constraints to `3.13.0-0`, (b) enabling the lints
`unnecessary_type_name_in_constructor` and
`unnecessary_const_in_enum_constructor`, (c) fixing the resulting lint
failures using `dart fix`, and then (d) reformatting the affected
files.
To ease code review, I've reverted unrelated formatting changes.
Since this change requires bumping SDK constaints to `3.13.0-0`, it
was only performed on packages that are *not* published on
pub. (Packages that *are* published on pub should remain on lower
language versions until at least after the stable version of 3.13 is
released, so that we don't block users on the stable channel from
receiving updates to those packages.)
Change-Id: Ibb4daebafd239da58251e838ea6a3f336a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505046
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
SLSA-Policy-Verified: SLSA Policy Verification Service <devtools-gerritcodereview-exitgate@google.com>
This fixes an exeception when code completing before the `new` or
`factory` keyword in a constructor and the type name is not explicitly
used. The exception prevents any suggestions from being returned, so
it's fairly serious.
Change-Id: I2f5028812ee1945ac9635f55953fb800b19a48c5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505620
Auto-Submit: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
This impacted the placement of the imports, but I think the new results
are better. If nothing else, it's more consistent.
I thought it might be easier to review as two separate changes.
- The first patchset includes the basic transformation.
- The second patchset removes the old code to add the imports.
Change-Id: Ia0a3745152a14ce32fb757e797d0848b9f8d47cb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/499320
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This updates the `showUserPrompt` method to accept a cancellation token so that if requests are cancelled (by the client, or something like a second refactor cancelling the first), the prompt is also cancelled (and when the response arrives, it can be ignored).
Note: Unfortunately the protocol (and VS Code) don't actually allow for the prompt to be cancelled/hidden from the user, this is mainly to avoid us keeping the request "alive" on the server if the user ignores a prompt and we know the parent request was cancelled anyway.
Fixes https://github.com/dart-lang/sdk/issues/63285
Change-Id: Ia77880a749b284a2ff31c8cf560307ad908d2175
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/499360
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Move PackageConfigFileBuilder into the analyzer_testing public API and
deprecate the copy exposed from package:analyzer. The builder is only
used by test infrastructure, so keeping it in analyzer_testing makes the
ownership clearer and avoids exposing test-only utilities from analyzer.
Update the builder API to accept a rootFolder instead of a rootPath.
This lets callers pass the resource-provider folder directly, so the
generated rootUri is derived from the same file-system abstraction that
created the test files. This avoids accidentally passing POSIX paths
where resource provider paths are required, such as on Windows.
Update existing test utilities and callers to import the new library and
pass Folder objects. Remove the production analysis server dependency on
the builder by emitting the temporary plugin package config JSON
directly.
Change-Id: I46b14710626e0d6d5884afcdc5a05b23077acfc9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/499081
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This continues the effort to move all of the legacy refactors over to
using the ChangeBuilder rather than creating legacy edit objects
directly. This should make it easier to atomically convert all of the
refactors to produce a protocol-agnostic representation as part of the
move to remove the legacy protocol.
Change-Id: I659c14966b543f21ecc94248a2c0dda5692473fb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/499045
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Replace the generic mutable reference tree with typed reference classes
for roots, libraries, top-level declarations, member containers,
members, and built-in elements.
The previous API was shallow. It offered a small primitive,
`getChild(String)`, but pushed too much knowledge to every caller: which
sentinel names exist, which paths are valid for each declaration kind,
which references may contain members, and which references are not real
declarations at all. That kept the reference implementation simple by
spreading its complexity across the analyzer.
Make the reference model deeper instead. Callers now ask for the
semantic role they need, such as a library, constructor, method, field,
or top-level declaration. The reference layer owns the representation,
lookup, creation, and serialization details. This concentrates the
complexity behind a narrower interface, makes the common cases clearer,
and makes invalid reference shapes harder to construct.
This is a strategic cleanup rather than a local simplification. The
reference graph is used by element construction, summary reading and
writing, scopes, exports, and fine-grained dependency manifests. Giving
it explicit concepts reduces the amount of convention each subsystem
must remember and preserves a simpler mental model at the call sites.
Update summary serialization to write semantic reference rows with a
tag, enclosing reference, kind, key, and URI payload. Bump the analyzer
data version because this changes the linked summary format.
Represent exported declarations as export entries that carry the
exported name, reference, and export locations. Use those entries when
building scopes, filtering deprecated exports, and updating fine-grained
library manifests.
Keep import prefixes out of the declaration reference tree. Bind prefix
fragments through fragment-local ids so prefixes can be restored and
merged without fabricating declaration references.
Bug: https://github.com/dart-lang/sdk/issues/63227
Change-Id: If28f8b779faa78bdf023bc69b714555fae57ccb3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/497621
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Permit `abstract` on top-level variable declarations when the
augmentations feature is enabled. Previously the parser always reported
`abstract` as extraneous at the top level, which rejected valid syntax
and dropped the modifier before later stages could see it.
Thread the abstract token through top-level field parsing, record it on
`TopLevelVariableDeclaration`, and pass it through the front-end
builders. Reorder the field callback arguments so `augment` precedes
`abstract`, matching the augmentation grammar for incomplete top-level
variables and keeping the parser, listener, and outline plumbing
consistent.
Change-Id: I680414a746b707d483e485702685c95f28a9c9ac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/494564
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Fixes https://github.com/dart-lang/sdk/issues/62539
I'm calling this one fixed after this change; we started with ~1850
analysis option reads for the `dependency_resolution` repository in the
issue. The previous changes cached reads, knocking the number of reads
down to ~1000. This change knocks it down to ~300.
Change-Id: Ia8be5880e63cb299e73f72403c3943d115da8e1d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/493201
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
The `Match.operator[]` does the same thing and is
generally recommended (and shorter).
(I want to deprecate `group` and `groups`)
Tested: Refactoring.
CoreLibraryReviewExempt: Calling equivalent function.
Change-Id: I4c758968ae622fe16b7322be1b29b05b91e7fcd9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/489021
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
We don't appear to have any end-to-end tests of the rename refactor (and
maybe not of other legacy refactors). We need to fix that, but that's a
bigger task than I want to include in this CL. For now I've locally built
and tested the rename on a primary constructor and verified that it
works as expected.
Change-Id: Icec20f3204c58fa219ff7df117511ed47629bd1f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/489120
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
In order to support primary constructors we need to have two new
refactors that will add and remove a constructor name. Rather than
duplicate the logic in the RenameConstructor class, I want to reuse it.
In order to do that, I need to be able to pass in a ChangeBuilder.
This CL accomplishes that goal by making it possible to pass in a
ChangeBuilder to any refactoring, even though in most cases the
ChangeBuilder will be ignored. In the future I intend that all of the
refactors will be updated to use the passed in ChangeBuilder, but that
would have been too big for a single CL.
Beyond that, I did make one other change, which is that the refactor
now supports classes with an empty body (`;`). I added a test for the
new functionality, but I believe that the existing tests should be
adequate to ensure that there was no loss of functionality.
This does not add support to RenameConstructor to deal with primary
constructors. That will also happen in a follow-on CL.
Change-Id: I51749e9cd1d775744dc6e64c1dc67967ef492d45
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/488527
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Primary constructors introduces the ability to use `new` in place of
a class name in a constructor. The previous changes to code completion
missed this, but this CL causes `new` to be suggested at the beginning
of a member.
Change-Id: I56ac6d3d8649e55de264f6e4f91b4c5db2e37c92
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/483322
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
When a getter is referenced from a pattern field (e.g. `A(test: ...)` or
`A(:var test)`), converting the getter to a method changes the meaning
of the pattern: it will match the method tear-off rather than the
getter’s evaluated result. This can silently break code that relies on
pattern matching behavior.
Update the refactoring to detect these references and report a warning
during final condition checks, including a precise source location for
the affected pattern field.
Also refactor the implementation to:
- Collect all relevant getter elements up front (top-level getter or the
corresponding hierarchy getters for a field) and reuse that list for
both condition checking and change creation.
- Skip inserting `()` for references in pattern fields, as before.
Bug: https://github.com/dart-lang/sdk/issues/62139
Change-Id: I81170b7c39ae77148b7bc0a0979c390b5f5afe7d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/475704
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This requires some changes to tests, where fields should be final. In
tests where it seemed like the mutability of a field was important, I
just ignored the warning. Otherwise, I made fields final.
I do like keeping this stub in-line with the real Widget class. If
anything, it keeps in mind that flutter Widgets should generally no
have mutable fields.
Change-Id: Ib7dc1fbd6aa013dc72925404c4be8186ddcddaa4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/475400
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Primary constructors repurpose `var`/`final` in formal parameter lists
as declaring parameters, which makes many older snippets erroneous.
Update tests to avoid these keywords unless they are the subject under
test:
- Remove redundant `var` from untyped formal parameters across analyzer,
analysis_server, and linter tests (e.g., `f(var x)` -> `f(x)`), and rename affected tests from “...Var” to “...Untyped” where appropriate.
- Add `// @dart = 3.10` to test snippets and documentation examples that
intentionally use legacy `final`/`var` constructor parameters so they remain parsed and analyzed under the pre-DeCo language version.
- Adjust expected diagnostic offsets and resolved-node expectations where code changed due to keyword removal or inserted language-version markers.
- Update mock SDK declarations to avoid `var` in parameter positions.
Change-Id: Ic0a2b129cda75d542f8229bc65b44bf6ad26ae22
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/475180
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
They already do the right thing, but this pins it down.
Also added a little functionality in AbstractSingleUnit to allow ignoring expected diagnostics in the input code. I did that instead of adding another diagnostic to the blanket ignores because diag.privateNamedNonFieldParameter felt like an error we wouldn't want to always ignore. I also like tests generally being specific in what they permit. Let me know what you think of this approach.
BUG: https://github.com/dart-lang/sdk/issues/62434
Change-Id: I344aa665aeed0b766d6c2d97608dc4eedf14b2f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/473925
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
With these changes, primary constructor bodies will sort with
constructors (based on whether `sort_members_first` is enabled), but
will always be before other constructors.
Change-Id: If6719dedd5178c384712a5d08b4e74a38aaf54a1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471280
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Previously, the AST builder enforced strict constraints on extension
type primary constructors during parsing, often discarding or
transforming invalid parameters (e.g., multiple, optional, or named
parameters) to force a valid representation field structure. This
limited recovery and resulted in inaccurate element models for invalid
code.
This change updates the AST builder to parse and build elements for the
primary constructor's formal parameters exactly as written. The
validation logic ensuring a single, positional representation field has
been moved to `ErrorVerifier`.
To maintain the invariant that an extension type has a representation, a
synthetic "recovery" representation field is now added to the element
model if the parsed parameters do not provide a valid one.
Bug: https://github.com/dart-lang/sdk/issues/61701
Change-Id: I37b7eaf2c085db6317b2c2b0bf35ff31423f9738
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465180
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>