Commit graph

1164 commits

Author SHA1 Message Date
Paul Berry 9de69a94e0 Eliminate context arg from MigrationCliRunner.shouldBeMigrated
This is non-breaking since `shouldBeMigrated` is unreferenced outside
the nnbd_migration package).  Once this lands, we can switch clients
from overriding/calling `shouldBeMigrated2` back to `shouldBeMigrated`
and then eliminate `shouldBeMigrated2`.

Change-Id: I1235113bda6f7609de17ec05e7120b312f201536
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/178762
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-01-16 16:58:43 +00:00
Sam Rawlins bdb60329e9 dart migrate: handle an SDK constraint with no min
Fixed https://github.com/dart-lang/sdk/issues/43989

Change-Id: Iddc5e5f0b53a5ec0540b002654bc46b40dc8a46a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/179421
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2021-01-15 18:03:07 +00:00
Devon Carew 70a88e9c4f update the documentation url for the nnbd migration tool
Change-Id: Idb898c0b4c831d7304db7b7a5251b9c8e7e66589
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/179402
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2021-01-15 16:35:02 +00:00
Nate Bosch 58e7e7eb26 Prepare for breaking change in package:http
The `url` argument is changing from `Object`, accepting either `String`
or `Uri` at runtime, to `Uri` for better static help.
https://github.com/dart-lang/http/pull/507

- Switch to using `Uri` for requests. Where sensible push this type into
  the signature of the surrounding method.
- Make some updated method private where they were unnecessarily public
  which makes it harder to have confidence when looking for usages.
  Rename a method with an unnecessary `get` name.

Change-Id: Ibf075741d6b9d292349b15f1dc84004981729aca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/179368
Auto-Submit: Nate Bosch <nbosch@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
2021-01-15 16:35:01 +00:00
Sam Rawlins 6735d3c693 dart migrate: shutdown the process after applying a migration
Change-Id: Ifdb42cffa703912d541d61ba4386d7df96fda718
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/179240
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2021-01-15 03:32:52 +00:00
Sam Rawlins c5e0e73df5 dart migrate: Fix rendering overlay offset issue in Firefox
Fixes https://github.com/dart-lang/sdk/issues/44635

Change-Id: Id6e0518b86859605c5cfacb9091f7e1ed612b71c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/178724
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2021-01-12 23:17:33 +00:00
Paul Berry 9370651773 Prepare to eliminate context arg from MigrationCliRunner.shouldBeMigrated
This change changes `MigrationCliRunner.shouldBeMigrated` to forward
to a transitional method `MigrationCliRunner.shouldBeMigrated2`, which
lacks the now-unused `context` argument.  After this lands, internal
clients will be switched to overriding/calling `shouldBeMigrated2`
instead of `shouldBeMigrated`.

Once no clients remain that refer to `shouldBeMigrated`, the `context`
argument will be removed from it (this will be non-breaking since
`shouldBeMigrated` will at that point be unreferenced outside the
nnbd_migration package).  After that, we will switch clients back to
overriding/calling `shouldBeMigrated` and eliminate
`shouldBeMigrated2`.

Change-Id: If9b476878260a5777f3346486d44c805dc361691
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/178761
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-01-12 16:11:21 +00:00
Sam Rawlins 9488ea4c7e dart migrate: support files-to-be-migrated initial state in google3
* Rename isPreviewServerRunnning to isPreviewServerRunning
* Fix top "Migrating" checkbox upon navigation.

This change does not completely solve google3-compatibility, just the
web preview UI portion.

Work to improve any opt-out `// @dart=2.9` comments will follow.

Change-Id: Iee38650ab732179d82060b14bc7b657e3c560543
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/178160
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2021-01-12 05:54:50 +00:00
Brian Wilkerson 6143fb5668 Improve some diagnostic messages
Change-Id: Ic351c2addff76dea8fe49c7e2ce68b46043f0814
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/177480
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2021-01-04 16:43:08 +00:00
Paul Berry 5c19c9f5e4 Flow analysis: store ExpressionInfo in SSA nodes.
This CL modifies flow analysis API so that when a variable is written
or initialized, if the written expression has non-trivial flow
analysis information, it is captured in the SsaNode associated with
the variable.

The stored information is not yet used; in a follow-up CL, I will add
the ability to retrieve it on a read and use it for promotions.

Bug: https://github.com/dart-lang/language/issues/1274
Change-Id: I1e2590205d4a0c59f4400a119f3d6b380a11414c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/176460
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2020-12-17 15:16:04 +00:00
Sam Rawlins 6eddd878c0 dart migrate: Fix preview_site_test on windows
Change-Id: Ib0fc934eb1620017da20a444ced58a8d9e63f540
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/176380
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-12-15 23:45:01 +00:00
Sam Rawlins fe2205ebde dart migrate: Simplify final output code
Change-Id: Ib472bf14d8dd06efeeb17b2c81fdb97bb886b214
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/176340
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-12-15 22:01:11 +00:00
Sam Rawlins 56fb42cb62 dart migrate: enable incremental migration workflow
Also:
* Print out details when applying migration
* Also fix title text position to not scroll out of view.

Change-Id: Idc4b703535400956f78d76ab7959f40cf77a0bc9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175860
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2020-12-15 17:59:41 +00:00
Konstantin Shcheglov c11039702c Replace FindElement.functionTypeAlias() with typeAlias().
Change-Id: I88a5b889310df8a39b54318907ba8bbd68b26b9b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/176183
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-12-15 07:13:41 +00:00
Devon Carew b782d5815f [pkg/nnbd_migration] add types to public API
Change-Id: Ie4a7bbe75dd8045b20361c3fa1e08784b990e951
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/176142
Commit-Queue: Devon Carew <devoncarew@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-12-15 01:34:29 +00:00
Konstantin Shcheglov 9717c775e4 Deprecate FunctionTypeAliasElement.function
Change-Id: Id629afa92c6681ba796aed75b24c4251fd86810f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/176140
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-12-14 22:26:29 +00:00
Sam Rawlins 451bd1183b dart migrate: Support Windows newlines in opt out
Also sort test file.

Change-Id: Id8133d699ae1a71d1852ef29ce1f843c7ede98cc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175561
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-12-10 00:34:50 +00:00
Sam Rawlins 88de6b438e dart migrate: Implement incremental migration in backend
This is still hiding behind a flag pending final review.

Bug: https://github.com/dart-lang/sdk/issues/44101 and
Change-Id: I01b7cb07b3fde7ac67105034b0c4057cb8a69771
     https://github.com/dart-lang/sdk/issues/44124
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175402
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2020-12-09 15:21:50 +00:00
Lasse R.H. Nielsen 6e29700e16 Update List constructor documentation, deprecate constructor.
Emphasize that the operation is going away,
and mark constructor as deprecated.

TEST= Refactoring+deprecation only, covered by existing tests.

Change-Id: I82aa044cd2cf7bf347b624371399f44bda8f4a07
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/173261
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
2020-12-07 16:20:28 +00:00
Devon Carew 8cba879f46 Add additional validations to the pkg/ package pubspecs.
TEST=these are additional validations that we run on the bots

Redux of https://dart-review.googlesource.com/c/sdk/+/161040

Change-Id: Ia32ced5d48fbfeafacfa9e51dc4774d2e9425091
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174601
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2020-12-02 17:27:18 +00:00
Paul Berry 1bfcc2d8da Migration: handle for-each loops where the loop variable is not local.
Fixes #44071.

Bug: https://github.com/dart-lang/sdk/issues/44071
Change-Id: I6a1a9df22f70086860c36108e529f189d3d24875
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174565
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-12-02 15:00:53 +00:00
Sam Rawlins 89811d9a92 Reland "dart migrate: Move title bar and add 'Migrate' check box next to title"
This is a reland of 17226bbbff

Remove generated files

Original change's description:
> dart migrate: Move title bar and add 'Migrate' check box next to title
>
> This check box displays whether a file is migrating, opting out, or
> already migrated. The check box can be clicked to toggle between
> migrating and opting out. Clicking the check box updates status in the
> navigation tree. Clicking on check boxes updates the status in the
> title bar.
>
> Screenshot here: https://screenshot.googleplex.com/9z9v9L5DHhBXzEU.png
>
> In terms of the HTML, a new parent above '.content' div was added:
> the '.file' div, which includes a '.title-bar' div above the '.content'
> div.
>
> Bug: https://github.com/dart-lang/sdk/issues/44101 and
> Change-Id: I021f0dd873119ae801e29faa92e97fe48d03ef3c
> https://github.com/dart-lang/sdk/issues/44124
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174440
> Commit-Queue: Samuel Rawlins <srawlins@google.com>
> Reviewed-by: Paul Berry <paulberry@google.com>

Bug: https://github.com/dart-lang/sdk/issues/44101 and
Change-Id: Iefada3e2fc8cbbc767cfc539204dc51b369888a2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174720
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2020-12-02 14:40:07 +00:00
Paul Berry 52acf2e8ac Migration: fixes to exception handling.
Since the EdgeBuilder overrides VisitNode, it wasn't getting the
benefit of the error recovery behavior provided by the
PermissiveModeVisitor mixin.  This CL replicates some of the
functionality of PermissiveModeVisitor in the EdgeBuilder._dispatch
method so that it applies throughout the EdgeBuilder's visiting
process.

This uncovered a second bug: when an exception is reported, and the
user hasn't passed in the `--ignore-exceptions` flag, the migration
tool tries to exit immediately by throwing an error of type
MigrationExit, but this was being caught by the error recovery logic,
so the tool wouldn't actually stop reliably.  This CL changes the
exception reporting code so that it re-throws MigrationExit when
necessary to ensure quick termination.

Change-Id: Ifd2faf8edb7cd0087c45e20a747ab7f1790ef1c2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174420
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-12-01 16:08:55 +00:00
Konstantin Shcheglov 7c5df72b27 Revert "dart migrate: Move title bar and add 'Migrate' check box next to title"
This reverts commit 17226bbbff.

Reason for revert: has unrelated tools/abiversions changes

Original change's description:
> dart migrate: Move title bar and add 'Migrate' check box next to title
>
> This check box displays whether a file is migrating, opting out, or
> already migrated. The check box can be clicked to toggle between
> migrating and opting out. Clicking the check box updates status in the
> navigation tree. Clicking on check boxes updates the status in the
> title bar.
>
> Screenshot here: https://screenshot.googleplex.com/9z9v9L5DHhBXzEU.png
>
> In terms of the HTML, a new parent above '.content' div was added:
> the '.file' div, which includes a '.title-bar' div above the '.content'
> div.
>
> Bug: https://github.com/dart-lang/sdk/issues/44101 and
> Change-Id: I021f0dd873119ae801e29faa92e97fe48d03ef3c
> https://github.com/dart-lang/sdk/issues/44124
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174440
> Commit-Queue: Samuel Rawlins <srawlins@google.com>
> Reviewed-by: Paul Berry <paulberry@google.com>

TBR=paulberry@google.com,srawlins@google.com

Change-Id: I8b8433d47390df91201a365f5aa54c7fb835d997
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: https://github.com/dart-lang/sdk/issues/44101 and
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174385
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-12-01 03:30:32 +00:00
Sam Rawlins 17226bbbff dart migrate: Move title bar and add 'Migrate' check box next to title
This check box displays whether a file is migrating, opting out, or
already migrated. The check box can be clicked to toggle between
migrating and opting out. Clicking the check box updates status in the
navigation tree. Clicking on check boxes updates the status in the
title bar.

Screenshot here: https://screenshot.googleplex.com/9z9v9L5DHhBXzEU.png

In terms of the HTML, a new parent above '.content' div was added:
the '.file' div, which includes a '.title-bar' div above the '.content'
div.

Bug: https://github.com/dart-lang/sdk/issues/44101 and
Change-Id: I021f0dd873119ae801e29faa92e97fe48d03ef3c
https://github.com/dart-lang/sdk/issues/44124
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174440
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2020-12-01 01:36:25 +00:00
Devon Carew 81986f4a36 [dartdev] add a --format option to dart analyze
Change-Id: Iad7d14b12892ce2121430f0cd94a2b0cd0d8e978
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174384
Commit-Queue: Devon Carew <devoncarew@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-12-01 01:32:34 +00:00
Paul Berry 4185e7ccd2 Migration: disable code highlighting for very large files.
This avoids an apparent hang when visiting the SDK file
`html_dart2js.dart` (which happens anytime the user clicks on a link
like `HtmlElement`).

Bug: https://buganizer.corp.google.com/issues/168936042
Change-Id: I52bb535b6a2ca1a74071e272b1276520048a67bd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174441
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-30 21:30:04 +00:00
Paul Berry e047dd60d6 Ensure that function elements inside local variable elements have unique locations.
Fixes #44216.

Bug: https://github.com/dart-lang/sdk/issues/44216
Change-Id: I5ccf8bb5f90396eabfec470a289a193d2aef16ec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/173881
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-25 13:39:04 +00:00
Sam Rawlins 1b07887853 Migrator: Implement check boxes on directories
Checking and unchecking a directory toggles the status of all child files which
are 'migrating' or 'opting out.' Files which are already migrated do not
change.

Checking and unchecking a file updates the status of all parent directories.
Directories with both 'migrating' and 'opting out' files are 'indeterminate'.

The difference between 'file' and 'directory' NavigationTreeNodes was
getting too hairy so I split into two subclasses.

Removed the keepingOptedOut status and added the indeterminate status.

Bug: https://github.com/dart-lang/sdk/issues/44101
Change-Id: Iea1a8c07b08c3d7956db51ca372437093457fe7f
     https://github.com/dart-lang/sdk/issues/44124
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/173600
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2020-11-25 02:32:59 +00:00
Paul Berry f0d56055b6 Migration: handle is expressions where the type is a function type.
Change-Id: Ibdcb4a49bd51e218e58a52a3e2f32bef55bce61e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/173020
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-20 12:26:36 +00:00
Sam Rawlins db0a23faa0 Migrator: Land front-end support for 'migration status' check boxes
These check boxes are hidden behind a parameter that must be changed during
development; it is not wired to a public-facing flag.

The check boxes are styled, and are connected to the starting status of each
compilation unit (already migrated, opted out, migrating).

The check boxes can be toggled, but just for mocking purposes; their status is
not connected to the back end. The directory check boxes are not wired to the
status of their children.

Screenshot of checkboxes w/o colors: https://screenshot.googleplex.com/43XBRWsMPgbQXik

Screenshot of check boxes w/ colors: https://screenshot.googleplex.com/3bhJqcnmeV4sGNm
* dark green - already migrated; file is not being changed.
* light green - file is being migrated now.
* orange un-checked - file is being opted out, initial migration,
  file will gain opt-out comment.
* grey un-checked - staying opted out, file is not being changed.
* indeterminate - folder has multiple states inside.

Bug: https://github.com/dart-lang/sdk/issues/44124 and
Change-Id: I49daf1f52544024ec1c6d8d5cf3c59515c7db3a7
     https://github.com/dart-lang/sdk/issues/44101
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/172821
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2020-11-19 19:32:25 +00:00
Paul Berry d0a23d8106 Add a triage document for the dart migrate tool.
Change-Id: I4ba33889c6171d012fc6a4239f4409c5fe9de005
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/172661
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Devon Carew <devoncarew@google.com>
2020-11-17 21:39:48 +00:00
Sam Rawlins 95e4e03f88 Migrator: do not generate edit details twice on rerun
Fixes https://github.com/dart-lang/sdk/issues/44086

Change-Id: I99a23e5922a716bbd0c83e7c0f620686840ccd4c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/172300
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-11-17 05:05:00 +00:00
Nate Bosch aaf13b5247 Update to the latest package:yaml
Expand the range allowed by the dep from `package:analyzer`.

Switch dependencies to `any` for the packages which are `publish_to:
none`. The actual constraints aren't useful in these packages since they
are always pinned exactly by DEPS and so we can't trust they are kept up
to date.

Change-Id: Ibd937e8646574d49105f4dd0de2529e7ab30862a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/172380
Auto-Submit: Nate Bosch <nbosch@google.com>
Commit-Queue: Nate Bosch <nbosch@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
2020-11-16 22:16:50 +00:00
Paul Berry 4bde77e3c4 Migration: fix test_this_inside_extension.
This functionality is working now, the test was just broken.

Bug: https://github.com/dart-lang/sdk/issues/39387
Change-Id: I088a3bd40ac438d0a9cd2356badfaf9513aa4bbb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/172280
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-16 21:21:06 +00:00
Paul Berry c0586277d7 Migration: fix handling of extensions on generic and function types
Bug: https://github.com/dart-lang/sdk/issues/39387
Change-Id: I037d29355dc86c071acc8dcc6f417a95e96e9728
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/172200
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-16 17:11:58 +00:00
Paul Berry 3103e1e0f6 Migration: don't overcount "whereOrNull" fixes.
Fixes #44174.

Bug: https://github.com/dart-lang/sdk/issues/44174
Change-Id: Ida53a11afc2e265cd510b0ac63c50f6b5ac93fdd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171962
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-13 18:51:30 +00:00
Paul Berry 8abc99d07a Migration: encourage user to include SDK version when filing bugs
Change-Id: Ib8056827595470d8c3c8b2cb8371ab08dcc3e651
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/172040
Auto-Submit: Paul Berry <paulberry@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Commit-Queue: Kevin Moore <kevmoo@google.com>
Reviewed-by: Kevin Moore <kevmoo@google.com>
2020-11-13 18:18:10 +00:00
Paul Berry 7d3bc4862d Rename pkg/analysis_tool to pkg/analyzer_utilities.
It's no longer just for the tools in the `tool` directory; it also
contains test utilities for use by the analyzer and related packages.

Change-Id: I0f8cf57f24ea7aad8e2177e43ee2bcb2ab3030da
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171704
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-11-13 17:46:30 +00:00
Paul Berry b3120a6170 Sort declarations in messages.dart.
Change-Id: I07840b0818f36d6db9e099c69e02083ed3a8845d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171980
Reviewed-by: Devon Carew <devoncarew@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-13 17:38:10 +00:00
Paul Berry cf4d300c0b Migration: handle "already migrated" case more gracefully.
If all the user's code has already been migrated and there are no
errors, instead of crashing, produce a friendly message indicating
that there's nothing to do, and exit cleanly.

Fixes #44193.

Bug: https://github.com/dart-lang/sdk/issues/44193
Change-Id: I9da9ab0221d4e13a61985eaa3fec0e74b86e9072
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171960
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2020-11-13 17:38:10 +00:00
Paul Berry 0258778e3b Migration: explain that user may make edits in their IDE
Change-Id: I8289aa274a7882a41a5411739999f1db77fc196f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/172000
Auto-Submit: Paul Berry <paulberry@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Commit-Queue: Michael Thomsen <mit@google.com>
Reviewed-by: Michael Thomsen <mit@google.com>
2020-11-13 15:44:10 +00:00
Paul Berry 02b2e5398d Migration: permanently enable "transform where or null" feature.
This feature is now working reliably enough that we no longer need the
option of turning it off.

Change-Id: I2bbeb114ca1bd4e0dc8e94ac6775ec5e2fa8718e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171705
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2020-11-12 21:12:20 +00:00
Paul Berry 80ac9c999b Migration: update pubspec when adding import of package:collection.
Change-Id: Ia9e5090bafa7f67be87aa01367bec16f4fd80ee9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171701
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2020-11-12 21:12:20 +00:00
Paul Berry fdfcab8581 Rework DartFixListener callbacks to use an interface class.
I will need to add another callback in a follow-up CL, and it seems
silly to pass a bunch of closures to the DartFixListener constructor.

Change-Id: I969d1d90fca0889b131589248aaa1cec343a9059
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171700
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2020-11-12 21:12:20 +00:00
Paul Berry 95940f8963 Sort declarations in migration_cli.dart and nnbd_migration.dart
Change-Id: I4e2904a40dcc0f7ece94ee6aa823743455f46b4e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171633
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-12 18:07:09 +00:00
Paul Berry 83cf6d67dc Migration: improve error/warning text when there are analysis errors.
Fixes #44144

Bug: https://github.com/dart-lang/sdk/issues/44144
Change-Id: I54ef9ca8f38335df2082d730ba558fd407a07767
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171643
Commit-Queue: Kathy Walrath <kathyw@google.com>
Reviewed-by: Kathy Walrath <kathyw@google.com>
Auto-Submit: Paul Berry <paulberry@google.com>
2020-11-12 17:59:07 +00:00
Paul Berry e205acb506 Migration: stop recommending --prereleases with pub outdated --mode=null-safety.
As of
5fba201573,
`--mode=null-safety` implies `--prereleases`.

Change-Id: I34bc827ddd3579e968276f826c0420ffadc0eac3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171661
Auto-Submit: Paul Berry <paulberry@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
Reviewed-by: Devon Carew <devoncarew@google.com>
2020-11-11 21:00:49 +00:00
Paul Berry 5f6d30da26 Add a verify_tests_test.dart to pkg/nnbd_migration.
This would have caught the need for
https://dart-review.googlesource.com/c/sdk/+/168462 and
https://dart-review.googlesource.com/c/sdk/+/171261.

Change-Id: I8da1f24cac5eb9df36ae1ca7299c0aeddbd80149
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171301
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-11-11 18:09:18 +00:00
Paul Berry da029c6ef3 Migration: try to help users who update their pubspec before migrating.
Fixes #44144.

Bug: https://github.com/dart-lang/sdk/issues/44144
Change-Id: I5db52426ba4e6a4cde803ae38fbc479cb8bbb862
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171624
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-11 18:03:52 +00:00
Paul Berry 05750310c9 Migration: rework fatal error reporting when pubspec cannot be parsed.
Previously, the user experience was an `UnimplementedError` with no
further information.  Now the user gets an error message telling them
how they need to update the pubspec, which I believe was the original
implementation intent.

Note that the field `_packageIsNNBD` has been removed.  Although the
comment for this field said it was tracking whether the package was
opted in to null safety, it actually had no effect (since the only
code path that would set it to `false` was after the
`UnimplementedError` and thus unreachable).

Change-Id: I3cef2f0a7203941b22e37e3ae1bee14806cfc9c0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171621
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-11 17:49:02 +00:00
Sam Rawlins e0ef383234 Migrator: Add a summary_stats script
The script's Usage text has the best description.

Change-Id: I6baf747a13a7655e40bc0158cb40ad965fa6ee3a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171422
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-11-11 16:56:42 +00:00
Paul Berry 50274ada87 Migration: add migration_summary_test.dart to test_all.dart.
Change-Id: I478ab5491fb3cbc32646d4ec3a76be838113bff1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171261
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-10 15:09:26 +00:00
Paul Berry 3e5f021579 Migration: add a test case for #44118.
Bug: https://github.com/dart-lang/sdk/issues/44118
Change-Id: I9c62d8d90240458c8609a74a2cd49b703da0fb29
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171240
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-10 15:07:06 +00:00
Paul Berry 785c3258f6 Migration: remove deprecated code related to flag --skip-pub-outdated.
This flag was removed in
https://dart-review.googlesource.com/c/sdk/+/170561, but some of the
code related to it was deprecated and retained in order to avoid
breaking an internal client.  The internal client has now been
updated, so we no longer need the deprecated code.

Bug: https://github.com/dart-lang/sdk/issues/44061
Change-Id: I08cbb7a617a349c2a4debbe342643de817bc86b7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171000
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-09 14:36:38 +00:00
Paul Berry f4001df118 Migration: include exports when checking that imports are migrated.
When I first implemented this I thought that checking exports wasn't
needed, since it's not allowed for a migrated library to re-export
symbols defined in an unmigtated library.  But it turns out we still
do need to include exports in the check, since there might be migrated
libraries that are only reachable in the transitive dependency graph
via an export, and we need to check that *those* libraries don't
import unmigrated code.

Bug: https://github.com/dart-lang/sdk/issues/44061
Change-Id: I280b4117373a3320fc1efe65abe24e344199754c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170840
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-09 13:16:34 +00:00
Paul Berry 9b4cbf46b8 Migration: clarify the "unmigrated dependencies" warning text.
The old phrasing was confusing because it was unclear which libraries
were being referred to.

Bug: https://github.com/dart-lang/sdk/issues/44061
Change-Id: Id68f28fcd8ba5a80763e7bf86d6774289701d381
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170841
Auto-Submit: Paul Berry <paulberry@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
Reviewed-by: Devon Carew <devoncarew@google.com>
2020-11-08 17:00:17 +00:00
Devon Carew beb56d51f6 [pkg/nnbd_migration] remove a leading space from a message
Change-Id: Ida7bc63a1aa90e252b3bd65263f5d0a72e906c87
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170747
Auto-Submit: Devon Carew <devoncarew@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-07 22:02:26 +00:00
Paul Berry 7322bc027e Migration: replace pub outdated check with a check on transitive imports.
Instead of running `pub outdated` to see if the user's dependencies
have been migrated yet, the migration tool now examines all of the
transitive import dependencies of the user's code to see if they are
opted in to null safety.  This produces a more accurate result than
`pub outdated`, because it is able to ignore files in transitive
package dependencies that aren't reachable via imports
(e.g. references to `package:analyzer` brought in by `package:test`).

Fixes #44061.

Bug: https://github.com/dart-lang/sdk/issues/44061
Change-Id: I38465bcbf35e8552f0060b5d51c0f1cfc5d18c7f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170561
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-11-05 23:05:51 +00:00
Sam Rawlins 40cfccda6f Migrator: Add a progress bar for explainMigration, which can take a long time.
This shows progress for work which happens after the migration suggestions have
been generated. This work is generating instrumentation details for the front
end.

When migrating the analyzer package, the progress indicated by this third
progress bar takes approximately the same time as generating suggestions (on
the same order of magnitude).

Fixes https://github.com/dart-lang/sdk/issues/44074

Change-Id: I0b40dd5e587b718bd1ef56d64f03929924cc430a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170563
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-11-05 22:10:51 +00:00
Paul Berry 9d3b932640 Migration: fix handling of .call tearoff on a function-typed expression.
Change-Id: I18b102ae83afdb051decfc26762619fb5746f73f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170364
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-05 19:18:54 +00:00
Sam Rawlins d01694d8aa Migrator: Do not overflow progress bar, or print warnings before ticks
Fixes https://github.com/dart-lang/sdk/issues/43752

Change-Id: I538b283b1cabe2b2212ada30317c14e76e182a06
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170562
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-11-05 19:08:14 +00:00
Paul Berry e8c8e51139 Migration: opt in dependencies in migration unit tests
Early in the development of the migration tool, due to language
versioning support being incomplete, it didn't have a good way to
distinguish opted in from opted out code, so we had the convention
that any code not being migrated was opted in.  Now that we have
language versioning support, we need to explicitly opt that code in.

Without this change, we'll get bogus failures when we add logic to
detect unmigrated dependencies.

Bug: https://github.com/dart-lang/sdk/issues/44061
Change-Id: I12920ea75b8af2142a044314b89b76bb602897c6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170560
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-05 18:16:57 +00:00
Paul Berry 221c697f31 Migration: fix handling of .call on a function-typed expression.
Change-Id: Ibdee57d455215cd974ea34c8aeab578bd801f87b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170361
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-04 18:28:17 +00:00
Paul Berry a44fe3f778 Migration: set SDK min constraint appropriately.
As discussed in
https://github.com/dart-lang/sdk/issues/44031#issuecomment-720967259,
we want to encourage users to publish null safe packages with an SDK
min constraint matching the SDK version that was used for the
migration, e.g. `2.12.0-18.0.beta`.  However, we also want to make
sure that users doing migration via internal, dev, or bleeding edge
builds publish their null safe packages don't wind up inadvertently
publishing packages that are un-resolvable with the latest beta SDK,
so if the user is on one of those versions, we'll set their SDK min
constraint to `2.12.0-0`.

And of course, once the feature ships to stable, we'll want users to
publish their null safe packages with an SDK min constraint matching
the version in which null safety shipped to stable.

This CL implements all of that functionality, and tests it by
overriding the `version` file in the analyzer's mock SDK.

Change-Id: Ib9ed97e691271da0ed391a6c1a5fe209aa959dce
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170380
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-04 18:26:57 +00:00
Ivan Inozemtsev 4a46b6511e Revert "[pkg/dartdev] refactor the migrate command to subclass DartdevCommand"
This reverts commit c10be63d51.

Reason for revert: this creates a circular dependency between nnbd_migration and dartdev which is hard to support internally

Original change's description:
> [pkg/dartdev] refactor the migrate command to subclass DartdevCommand
>
> Change-Id: I60f91f14e066b3a173f45b3c988830d5b435f2ed
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170206
> Reviewed-by: Ben Konyi <bkonyi@google.com>
> Commit-Queue: Devon Carew <devoncarew@google.com>

TBR=devoncarew@google.com,bkonyi@google.com,sigurdm@google.com

Change-Id: I3ba4648ea7f879ea4a893df2a9d75581a6f48dec
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170348
Reviewed-by: Ivan Inozemtsev <iinozemtsev@google.com>
Reviewed-by: Devon Carew <devoncarew@google.com>
Commit-Queue: Ivan Inozemtsev <iinozemtsev@google.com>
2020-11-04 17:22:59 +00:00
Devon Carew c10be63d51 [pkg/dartdev] refactor the migrate command to subclass DartdevCommand
Change-Id: I60f91f14e066b3a173f45b3c988830d5b435f2ed
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170206
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2020-11-04 16:28:47 +00:00
Paul Berry 92587baee5 Migration: fix "whereOrNull" transformation to handle complex targets.
Previously, when analyzing a call to an iterable method that could
potentially be transformed into an `OrNull` extension, such as:

  allMatches(str).firstWhere(..., orElse: () => null);

the migration tool would erroneously identify some subexpressions of
the call target (`str` in this example) as the argument supplied to
`orElse`, resulting in a crash.

This CL fixes the logic so that we use an `identical` check to verify
when we are looking at the argument to `orElse`.

Fixes #43956.

Bug: https://github.com/dart-lang/sdk/issues/43956
Change-Id: I2f4a0e81becf789cab5334d4926e014bda2772f4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170162
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-03 22:48:17 +00:00
Paul Berry 4c59c39648 Migration: set SDK max constraint appropriately.
After further discussion, we've decided to reverse the decision from
https://dart-review.googlesource.com/c/sdk/+/169143 and have the
migration tool generate packages with a max SDK constraint of 3.0.0.
See
https://github.com/dart-lang/sdk/issues/44031#issuecomment-720967259.

Bug: https://github.com/dart-lang/sdk/issues/44031
Change-Id: I37b43dfb1f13dd0fe08ab81f4ac01bcc46016bc5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170160
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-03 16:16:06 +00:00
Sam Rawlins 4097d3024a Migrator: Insert required keyword in correct position
Previously, migration might change:

m({@required @deprecated x}) {}

to

m({required @deprecated x}) {}

Which is illegal syntax.

Change-Id: Ib8397e9e22dbb951758a04c085c40905860a7cb3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170026
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2020-11-02 23:40:25 +00:00
Paul Berry 3eb34ef646 Migration: programmatically generate package_config.json in unit tests.
Previously, we hard a hard-coded set that included all packages added
by unit tests, which created confusion when writing new unit tests.
Now, `addPackageFile` records a list of all packages and
`package_config.json` is automatically generated just before analysis
begins.

Change-Id: I3393c0266a54d051ffa7601e74753a75857635e2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170024
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-02 19:55:39 +00:00
Sam Rawlins 416cfa7c41 Migrator: Add /*required*/ hints when meta not imported.
Currently the migrator can add `@required` from the preview, which will crash
the preview upon rerunning, if package:meta is not imported.

This change instead adds a /*required*/ hint when meta is not imported.

Additionally, /*required*/ is understood by the migrator just as if it were
`@required`.

Fixes https://github.com/dart-lang/sdk/issues/43751

Change-Id: I1ea532246b956feacedd179146372b13c65003df
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169900
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2020-11-02 17:30:59 +00:00
Paul Berry 531ffd0e45 Migration: add repro for #44012
Bug: https://github.com/dart-lang/sdk/issues/44012
Change-Id: Iabddb6de213aa70feb42b273f0e48fc2b5fa582d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170020
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-11-02 14:43:29 +00:00
Sigurd Meldgaard ea7e27cfeb Roll dart_style 1.3.8+1 into the SDK.
There are no formatting changes in this release. The only change is the
fix for https://github.com/dart-lang/dart_style/issues/964.

Includes corresponding adaptations of dartdev/dart CLI.

Change-Id: I1c97f0b7009b98ae609b258401522453faa35c64
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170083
Reviewed-by: Jonas Jensen <jonasfj@google.com>
Commit-Queue: Sigurd Meldgaard <sigurdm@google.com>
2020-11-02 13:42:19 +00:00
Paul Berry 0b0454f9e2 Migration: don't add experiment flag to analysis_options.yaml anymore.
Now that the flag is on by default, we no longer need to supply it
when migrating.

Bug: https://github.com/dart-lang/sdk/issues/43806
Change-Id: Ib2e4ae6cb0573cd2e28d61634c63a424aebfc60d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169145
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-10-29 20:05:10 +00:00
Paul Berry 53c31dbe22 Update migration tool to set pubspec/package_config appropriately for beta.
In the beta release, we plan to recommend that people set their
pubspec SDK constraints to `>=2.12.0-0 <2.12.0`, so this change
updates the migration tool to have that behavior.

In the second beta release we'll change switch the upper bound to
`<3.0.0`.

Change-Id: Ib90e893bebaebea968b19e7de663cbbbca570f84
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169143
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-10-29 20:05:10 +00:00
Paul Berry a44bbfbfb5 Revert "Migrator: Disable 'pub outdated' check temporarily"
This was a temporary measure to prevent user frustration with the
migration tool while null safety was not yet enabled by default.  With
null safety enabled by default, it's no longer needed.

This reverts commit f2b94295d3.

Fixes #41769.
Fixes #43774.

Bug: https://github.com/dart-lang/sdk/issues/43774
Change-Id: I4f7fbf0b980311d33428bc2a132b548a1c35c675
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169124
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-10-29 20:05:10 +00:00
Paul Berry 65eb643181 Migration: don't produce null!.
Instead, produce `null /*no valid migration*/`.  This should lead to
less user confusion (`null!` seems crazy, since obviously a null
literal will fail a `!` check).  Note that this will be a static
error, which will give the user a better chance of noticing and fixing
the problem.

Fixes #43972.

Bug: https://github.com/dart-lang/sdk/issues/43972
Change-Id: Ibf83b786dc486b14c001c17ca2ba902dafcb8a18
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169600
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-29 18:34:36 +00:00
Paul Berry 33b7f1425e Migration: remove unreachable break statements
Change-Id: Id37990606eaa1caa3fe37b9df70b861fe7a00049
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169720
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-29 16:05:33 +00:00
Paul Berry 68fe2649f3 Migration: remove 2 pixel offset from CSS for .region.informative-region.
This was causing visual clutter by making informative regions offset
from regular code.  Worse yet, there was a "double vision" effect
because the top of the underlying non-offsetted text could sometimes
be seen behind the informative region overlay.

Change-Id: I206c74b3d91f305a21494b767ec27f396a8513b0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169700
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-10-29 16:05:33 +00:00
Sam Rawlins 5ac5b710ee Migration --apply-changes implies --no-web-preview
* `--apply-changes` and no value passed for `web-preview`: assume
  `--no-web-preview`
* `--apply-changes` and `--web-preview` (each explicitly passed): error
* no value for `apply-changes` and no value passed for `web-preview`: assume
  `--web-preview`

Bug: https://github.com/dart-lang/sdk/issues/43866
Change-Id: I518f20f8095a6c9a11109fd9ae0f7c0e16050ddd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169521
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-10-29 13:15:23 +00:00
Devon Carew 80f0976e02 [pkg/nnbd_migration] mark package:nnbd_migration as not publishable
Change-Id: Iac9b8dd83ebd66bb9b2421584fd7fdd1ee364a73
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169285
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2020-10-28 17:30:20 +00:00
Paul Berry 68c50f7f92 Migration: re-work test_informationalRegion_containsTraceLinks_separateDrive.
Previously, we were switching test paths to drive `D` at the start of
the test, after the `package_config.json` file had already been
generated to drive `C`; as a result, it didn't apply.  We will need
the `package_config.json` to apply when we flip the null safety flag
(so that the inputs to the migration tool are considered opted out
prior to migration).  This CL reworks the test so that the paths are
modified as part of test set-up, so `package_config.json` gets put in
the right place.

Fixes #43883.

Bug: https://github.com/dart-lang/sdk/issues/43883
Change-Id: I08f79ddb07d7a5ecf640370a32334a7ceb92ceff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169421
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-28 16:35:30 +00:00
Paul Berry 9181570513 Migration: Work around null reference exception with complex type parameters.
Change-Id: Ib3f081225f9ec7cb8714ca0aa789d4dea1a378db
Bug: https://github.com/dart-lang/sdk/issues/43945
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169252
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-28 14:01:57 +00:00
Paul Berry a777d2b798 Sort declarations in api_test.dart
Change-Id: Ia82546a1654ac11334fee380d358862385c17ed7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169253
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-10-28 14:01:57 +00:00
Devon Carew 297fb8606a Un-hide the dart migrate command from stable.
Bug: https://github.com/dart-lang/sdk/issues/43194
Change-Id: I04db8cc9f34e812ca2e6569edd86f37c1f4fcdd9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169281
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2020-10-27 20:50:29 +00:00
Devon Carew dac61ff879 Remove a message for pre-nnbd sdks.
Bug: https://github.com/dart-lang/sdk/issues/43924
Change-Id: I900f03ebf67f9b4fe5bb9277555293d03295a34c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169241
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2020-10-27 20:27:57 +00:00
Paul Berry a666ac7ffa Migration: add preview info when changing iterable method calls.
With this change, the functionality of changing iterable method calls
such as `.firstWhere` into extension method calls such as
`.firstWhereOrNull` is working well enough that I think we can switch
it on.

We don't update the pubspec properly yet; that will be addressed in
follow-up CLs.

Change-Id: I758332e9752b12d399ecb5c70cf37bbc8da77d6c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168988
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-10-25 18:57:35 +00:00
Paul Berry 5e2e2235ac Migration: handle inserted lines in UnitRenderer._computeRegionContent.
We don't want inserted lines to receive their own line number for two reasons:

- It makes the line numbers displayed by the migration preview fail to
  line up with the line numbers in the user's editor (since the lines
  haven't been added yet)

- It makes navigation links within the migration tool point to the
  wrong place, since these links are computed based on analysis of the
  pre-migration code.

So instead, we supply a line number string of `(new)` for inserted lines.

This required refactoring the algorithm for
`UnitRenderer._computeRegionContent` a bit.  Now, instead of trying to
accumulate the output HTML string all at once, we produce it one row
at a time, first accumulating the line text in a StringBuffer, and
then once the end of the line is reached, attaching the line number to
form a table row.  Then we join together all the rows into a table
when we're done.

Change-Id: Ie18632186ddd0f4f5f33d4da41b4943759699e1f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168987
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-10-25 18:57:35 +00:00
Paul Berry 3ff14f19d3 Migration: include unimportant edits in UnitInfo.regions.
Previously UnitInfo.regions contained just information about edits
that we wanted to alert the user about; it didn't contain information
about unimportant edits like adjusting whitespace.

This caused problems when trying to make complex edits (like those
necessary to transform a `.firstWhere` call into a `.firstWhereOrNull`
call) because it interfered with UnitRenderer._computeRegionContent's
ability to properly compute file offsets.

So we now include all edits in UnitInfo.regions, and we distinguish
the unimportant ones by seeing that their `kind` and `explanation`
fields are `null`.

To ensure that important edits never wind up with `null` values for
these fields, we add assertions to the `NullabilityFixDescription`
constructor.

Change-Id: I89928150eb507524222d03acfae0b4770363443c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168985
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-10-25 18:57:35 +00:00
Paul Berry e20415403a Fix InfoBuilder._explainUnit to handle iterable method call renames.
The method we use to rename method calls to Iterable
(e.g. `firstWhere` -> `firstWhereOrNull`) causes a pair of consecutive
AtomicEdit objects to be generated: one to remove the old name
followed by one to add the new name.  This was causing
InfoBuilder._explainUnit to update its output offsets incorrectly,
because it waited until after processing all of the AtomicEdit objects
pointing to a single source offset before updating the output offset.
What it needs to do instead is update the output offset (in the
variable called `offset`) after processing every single AtomicEdit.

Change-Id: I8ad51e20d4021c62c45542cec7f0f54a9ff3cf26
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169000
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-25 16:23:45 +00:00
Sam Rawlins 9598c7b108 Migrator: Prepare migration_cli_test for the flip CL.
This is a weird CL because it strives to keep tests passing before and after
the CL, when they include a lot of error-path tests with weird pubspec files
and package config files.

Bug: https://github.com/dart-lang/sdk/issues/43883
Change-Id: I55dd4b398f3b1b53b8f2df95b2dcf880104ec7b6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168901
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-10-23 21:07:12 +00:00
Sam Rawlins 360363efc1 Migrator: opt all test files _out_ of null safety.
Well not quite all; migration_cli_test tests are a bit of a different
beast so I am going to tackle them separately. But this fixes over
1000 test failures, and should clean up test output for further
debugging of the flip CL.

Each test file needs to be in a package with a package config file
which spells out that it is _opted out_ of null safety.

Bug: https://github.com/dart-lang/sdk/issues/43883
Change-Id: I583f66119df57031fd80824111923e15e0f91782
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168900
Reviewed-by: Leaf Petersen <leafp@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-10-23 21:07:04 +00:00
Paul Berry d751681647 Sort declarations in info_builder_test.dart
Change-Id: I00caa1860f93f2fb8cfcdf9fa571f9cd0cc880b3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168980
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-23 20:01:22 +00:00
Paul Berry 7fde117f83 Sort declarations in migration_info.dart
Change-Id: I449c55bd570f60f4190be25a42e36d8c2b22a29e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168781
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-22 11:19:00 +00:00
Paul Berry f1843b0abe Add special case migration logic for iterator methods.
This logic allows us to migrate code like this:

    int firstEven(Iterable<int> values)
        => values.firstWhere((i) => i.isEven, orElse: () => null);

Into:

    import 'package:collection/collection.dart' show IterableExtension;

    int? firstEven(Iterable<int> values)
        => values.firstWhereOrNull((i) => i.isEven);

Rather than the default behavior, which would migrate it to:

    int? firsteven(Iterable<int?> values)
        => values.firstWhere((i) => i!.isEven, orElse: () => null);

(The new migration is far superior because it doesn't require the
input iterable to accept null).

This functionality is disabled at the moment, because:
- The changes it makes don't show up properly in the web preview.
- The pubspec is not yet properly updated.

I will address these issues in follow-up CLs and then enable the
feature.

Change-Id: I96f3b12d682c586631920b38406bad6aa3f4789e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168500
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-20 17:45:04 +00:00
Paul Berry 265ecc7488 Make test tolerant of changes to mock sdk
Change-Id: I5c2e6c964b666157977c66d8ad8a19ea41b09e58
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168520
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-10-20 17:45:04 +00:00
Paul Berry 5898fefb92 Add missing invocation to test_all.dart
Change-Id: Ibcbe7f50555a66360b563ae3915d2567567dd025
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168462
Reviewed-by: Janice Collins <jcollins@google.com>
2020-10-20 17:45:04 +00:00
Paul Berry 43166018a9 Nomenclature fix: migration diff output is not a summary.
The output the migration tool generates when the web preview is
disabled shows a complete diff of all changes the tool will make, so
it's really a misnomer to call it a "summary".

Change-Id: I8c7d9f9870bf8beffb62f1d10d36a65b66c32657
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168381
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-20 16:16:03 +00:00
Lasse Reichstein Holst Nielsen 92e52a1874 Remove direct dependencies on package:charcode from SDK.
Change-Id: I9ef36e8a6890a70baac6c18f0be2252dcf5453df
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163941
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2020-10-20 13:07:53 +00:00
Paul Berry 98ccfc33df Sort declarations in pkg/nnbd_migration/test/api_test.dart
Change-Id: Ic4990bbb40fe571a5fcba3a9b03366266cd565db
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167725
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-17 01:11:43 +00:00
Sam Rawlins 7c01226470 Fix navigation scrolling with big projects
Change-Id: Ie5fb3f79225354aef956e71467c0fe34b5e4cbc2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168122
Reviewed-by: Devon Carew <devoncarew@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-10-16 21:56:52 +00:00
Sam Rawlins 33e7bae759 Migrator: Fix issue with map node under 'analyzer:'
Without this fix, the tool inserts an enable-experiment
section indented at the wrong spot:

analyzer:
  exclude:
    foo:
      bar: 1
    enable-experiment:
      - non-nullable

Change-Id: Ib6601733221e77a4028f3c0ac87b36c258db6ec0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168120
Reviewed-by: Devon Carew <devoncarew@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-10-16 21:37:02 +00:00
Konstantin Shcheglov 3a97c9f602 Use legacy TypeProvider in AssignmentCheckerTest.
I'm looking into enabling NullSafetyUnderstandingFlag in the next
analyzer breaking change.

test_function_void_to_function_object() fails, and it seems that
the test class should use legacy TypeProvider, because `Object` is not
assignable to `void`, but `Object*` is.

Change-Id: Ib867e0eec7a387ed3ed1379a7ef34a58b16e54ae
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168125
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-10-16 21:10:03 +00:00
Sam Rawlins a23dbf7417 Migration: do not wrap navigation items
Change-Id: I6b3a2c41d4df9cc0f789d04f74cdddf79f7759d7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168060
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-10-16 15:29:22 +00:00
Sam Rawlins 3191b45998 Edit analysis_options.yaml to enable the non-nullable experiment.
The file might be edited in one of a few ways, depending on what it contains.

Previously we read and edited pubspec, which is also YAML, so this
implementation borrows a lot of that, and renames several "pubspec" elements to
be "yaml" elements.

I try to cover in tests various odd existing analysis_options.yaml situations,
so that we try to never crash, or corrupt on weird input here.

Fixes https://github.com/dart-lang/sdk/issues/43806

Change-Id: Ifc57d583e98d798fd7bca748bbe4afef272edab5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167862
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-10-16 12:58:32 +00:00
Paul Berry 6282572479 Remove deprecated method MigrationCli.addCoreOptions.
The internal code that was using this method has been updated to use
MigrationCli.options instead.

Change-Id: I46941b3a2b8dc65a66a3235052bc5c2110a9ab99
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167820
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-15 16:09:56 +00:00
Konstantin Shcheglov aad1a677c0 Deprecate GenericTypeAliasElement
See also https://dart-review.googlesource.com/c/sdk/+/166680

Change-Id: I6018f3bf5796dcc8ab059aab5b29d01e7336581b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167727
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-10-15 16:03:26 +00:00
Paul Berry acef33fd08 Avoid using http: URIs with relative paths in the migration tool.
Such URIs fail when the connection between the migration tool and the
user's web browser is proxied over https.

Fixes #43545.

Bug: https://github.com/dart-lang/sdk/issues/43545
Change-Id: Id457851d5c074ff707a2829c928401a766e15ece
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167660
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-14 18:52:48 +00:00
Konstantin Shcheglov fbfc723de7 Use CompoundAssignmentExpression instead of LHS element/type.
This adds some technical debt in form of using writeOrReadElement in
clients, which can be paid incrementally by migrating these places to
handling assignment like expressions one by one. Doing it all in one
CL was too much. But now the underlaying AST resolution will be
sound.

In the next breaking change we will remove
setAssignmentBackwardCompatibility(), so stop setting elements/types
for assignment targets.

Change-Id: I11626876cfed25653edb0cc18544aba51cef5965
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165622
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-10-14 18:45:08 +00:00
Devon Carew 7d994c106a Add a migration tool notice for TP2.
Change-Id: I3f882bc47c372e196186d6c9c539cc572d406f43
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167620
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2020-10-14 17:30:17 +00:00
Paul Berry 63a406d78b Restore addCoreOptions functionality and create more robust replacement.
This CL unblocks the internal SDK roll by restoring the migration
tool's `MigrationCli.addCoreOptions` method (which is currently used
internally).  It also adds a replacement, `MigrationCli.options`,
which is more robust because it allows the client to choose which
options to include and which options to exclude.

Once this CL has rolled in, I'll update the internal code base to use
the new `MigrationCli.options` method and then remove the deprecated
`addCoreOptions` method.

Change-Id: I3ddbd935c3858c3302a2ad2b825b97df96249043
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167443
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-14 00:27:47 +00:00
Paul Berry acf440fe42 Sort declarations in migration_cli.dart
Change-Id: I14c4b9b77eec3fef5a23f76877a8d291ca217198
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167423
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-10-14 00:27:47 +00:00
Paul Berry ad82b437f4 Prepare to publish package nnbd_migration version 0.1.1.
This will be the last published version, and is only being published
so that we can include a README entry indicating why the package is
not to be used.  After publishing, I will mark the package as
discontinued.

Change-Id: I95cb6d8d6ec41415edd2c8da300c165a0c4cfb93
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167444
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-13 22:53:04 +00:00
Sam Rawlins cddea627a7 Migrator: Accept 'late final' hint; same as 'late' hint
`late final` is not functionally different from `late`, as far
as the migrator is concerned; it is just an indication of late
in the face of missing initialization.

Fixes https://github.com/dart-lang/sdk/issues/41655

Change-Id: I1b0efd3de3b5c7064784ebd1e86c7d12436b1319
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167203
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-10-13 19:41:58 +00:00
Sam Rawlins b9e8f6f09c Migrator: Use 2.10 as a lower bound for null safety to allow 2.11 dev versions
Fixes https://github.com/dart-lang/sdk/issues/43757

Change-Id: I989b1542d2c6746513cc88dcfeff995873536ac5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167400
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-10-13 19:41:18 +00:00
Sam Rawlins f2b94295d3 Migrator: Disable 'pub outdated' check temporarily
Bug: https://github.com/dart-lang/sdk/issues/43774
Change-Id: I128d0e24aa6b8c972f393d3e91aae418a44ed8ef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167380
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-10-13 18:29:58 +00:00
Sam Rawlins 5c17af0843 Migrator: Refactor currentScrollPosition to be a function
Bug: https://github.com/dart-lang/sdk/issues/43546
Change-Id: Ie79b00b6471f4d5416e78fb6ca04e4c7f46d7231
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167381
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2020-10-13 17:54:08 +00:00
Paul Berry d6292f99c2 Add a notice to the nnbd_migration package README.
I plan to publish this on pub, and then mark the package as
discontinued.  Customers should invoke NNBD migration using the `dart
migrate` command.

Change-Id: Ia871e71258e3951ac7fd866e46ae97043a6fa93c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167364
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-13 16:29:08 +00:00
Sam Rawlins 284c78d338 Fix scrolling when clicking the "Add hint" buttons.
The fix is just to capture the scroll position when the button was clicked,
then rescroll to that pixel after reloading the file.

I also sorted migration.dart.

I also added comments while investigating migration.dart.

Fixes https://github.com/dart-lang/sdk/issues/43546

Change-Id: Iac0a7bf10a671fd6e6b5f02ee0609b7e36fc985a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167360
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-10-13 15:24:18 +00:00
Paul Berry 626c865a3e Support migration of partially migrated packages.
Rather than produce an error immediately upon encountering an
alredy-migrated library, we simply skip processing it; this causes its
elements to be added to the nullability graph on demand, just like for
already-migrated dependencies.

We still check for the possibility that *every* file in the user's
package has already been migrated, and issue an error if so (rather
than just doing nothing); this should help avoid user confusion if the
user tries to re-migrate an already-migrated package.

Bug: https://github.com/dart-lang/sdk/issues/42308
Change-Id: I8dd81a9c6ff2bb23ede91e89d1152bd7726dec32
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167202
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-12 23:58:32 +00:00
Sam Rawlins ef30beda17 Migrator: Print less output in tests
Change-Id: I8add1a75de71a4b979399be821a4baa803bc0165
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167180
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-10-12 17:48:32 +00:00
Sam Rawlins a5455694d5 migrator: Bump opt-in null safety version
Fixes: https://github.com/dart-lang/sdk/issues/43757

Change-Id: Iabcb0ef088d94b29cad4663763a1a842a8c49dcd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167160
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2020-10-12 17:23:22 +00:00
Devon Carew 07e2973f60 [pkg/nnbd_migration] some updates to the command line messaging for dart migrate
Change-Id: I780f7d6ec1e6985179f69ceb105519d5be838e80
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167120
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2020-10-12 15:53:32 +00:00
Paul Berry 2601fa6d78 Ensure that && and || expressions promote properly in unreachable code.
Bug: https://github.com/dart-lang/sdk/issues/40009
Change-Id: Ib06449624de9320f5229957511ebaaee92c75ec8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166606
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2020-10-08 21:42:14 +00:00
Paul Berry 57932cfb4f Ensure that conditional expressions promote properly in unreachable code
Change-Id: I8680b81b44be789a047238b1e2d008ff240e59c2
Bug: https://github.com/dart-lang/sdk/issues/40009
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165405
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2020-10-07 18:16:52 +00:00
Paul Berry ed2f45d56d Ensure that if statements promote properly in unreachable code
Bug: https://github.com/dart-lang/sdk/issues/40009
Change-Id: I04a5af558bb70b861d92b5379a8fb84489d5c9f4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165402
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2020-10-07 15:32:25 +00:00
Paul Berry e933e91aaa Reland "Flow analysis: promote to non-nullable on initialization"
This is a reland of 6a1c54ec30

Original change's description:
> Flow analysis: promote to non-nullable on initialization
>
> When flow analysis encounters a variable declaration of the form `T? x
> = expr;`, if the type of `expr` is `T`, then the variable is
> immediately promoted to type `T`.
>
> Fixes #43099.
>
> Change-Id: Ia206fe0d50e2fdd9bdf637e13c85633d8490dbcc
> Bug: https://github.com/dart-lang/sdk/issues/43099
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163841
> Commit-Queue: Paul Berry <paulberry@google.com>
> Reviewed-by: Bob Nystrom <rnystrom@google.com>
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>

Bug: https://github.com/dart-lang/sdk/issues/43099
Change-Id: I7530bb0f7c24674a7b500558b89d50b35e045aca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166305
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-07 13:14:55 +00:00
Clement Skau b4f49dc255 Revert "Flow analysis: promote to non-nullable on initialization"
This reverts commit 6a1c54ec30.

Reason for revert: Triggers test failure:
https://ci.chromium.org/p/dart/builders/ci.sandbox/vm-kernel-precomp-linux-debug-x64/8247

Original change's description:
> Flow analysis: promote to non-nullable on initialization
>
> When flow analysis encounters a variable declaration of the form `T? x
> = expr;`, if the type of `expr` is `T`, then the variable is
> immediately promoted to type `T`.
>
> Fixes #43099.
>
> Change-Id: Ia206fe0d50e2fdd9bdf637e13c85633d8490dbcc
> Bug: https://github.com/dart-lang/sdk/issues/43099
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163841
> Commit-Queue: Paul Berry <paulberry@google.com>
> Reviewed-by: Bob Nystrom <rnystrom@google.com>
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>

TBR=paulberry@google.com,scheglov@google.com,rnystrom@google.com,johnniwinther@google.com

Change-Id: I8549b48a734f527194ce11d82235b9d5c6e58185
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: https://github.com/dart-lang/sdk/issues/43099
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165564
Reviewed-by: Clement Skau <cskau@google.com>
Commit-Queue: Clement Skau <cskau@google.com>
2020-10-01 08:41:15 +00:00
Paul Berry 6a1c54ec30 Flow analysis: promote to non-nullable on initialization
When flow analysis encounters a variable declaration of the form `T? x
= expr;`, if the type of `expr` is `T`, then the variable is
immediately promoted to type `T`.

Fixes #43099.

Change-Id: Ia206fe0d50e2fdd9bdf637e13c85633d8490dbcc
Bug: https://github.com/dart-lang/sdk/issues/43099
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163841
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2020-10-01 01:15:31 +00:00
Konstantin Shcheglov 8de1bc0a07 Stop using getReadType() in nnbd_migration.
The packages 'analyzer' and 'nnbd_migration' tightly depend on each
other via MigrationResolutionHooks. I will publish analyzer 0.40.4
shortly after this CL lands.

Change-Id: I6f5e51f88e0020a1674ffb251712658e896170e7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164900
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2020-09-29 17:18:25 +00:00
Konstantin Shcheglov e3fcb1a646 Remove unnecessary convertPath() invocations.
Change-Id: I57d0d2204df02bd9a5fc97986347ac0218442d39
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164722
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-09-26 18:25:00 +00:00
Konstantin Shcheglov f9e6e38b21 Straighten up invocation of an Object method on dynamic.
Fixes https://github.com/dart-lang/sdk/issues/39609

Change-Id: I9b98d9bff8d4e9b75ab7625323f62eb6b6701a94
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164256
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-09-25 16:46:04 +00:00
Konstantin Shcheglov d219bde703 Enforce await_only_futures and fix violations (in more packages).
Change-Id: I1812f7721915178e42956f988b9276bf8db0bfaa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164281
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-09-24 16:58:50 +00:00
Paul Berry f860868740 Flow analysis: remove old "promotable via initialization" logic.
This logic was removed from the spec in
b70bb3f906.

Only a few places in the SDK itself were relying on this promotion
logic; I've fixed those places by adding explicit types.

Change-Id: Iaeaebe8dd5ab3e848699bc8ebc64a1ae80c1027a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163681
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-09-22 12:22:13 +00:00
John Ryan 90ff5d0af6 Add favicon to nnbd_migration tool
Uses the existing dart_192.png image.

Alternatively this could have been done using a favicon.ico file but
that would have required more boilerplate, so I went with a simpler
approach.

fixes #43438
https://github.com/dart-lang/sdk/issues/43438

Change-Id: I91e0c28a2c0a28db58dbf5189aae4d099c19b23c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163500
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: John Ryan <ryjohn@google.com>
2020-09-21 17:51:47 +00:00
Konstantin Shcheglov 9ef060886e Fix lints in nnbd_migration.
Change-Id: I57a8de216709beb1c65877bb228e1a0365ac6976
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163461
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-09-18 18:32:06 +00:00
Sam Rawlins 475ffb96c0 Migrator: Use pedantic 1.9.0
Change-Id: Ia53e84ac6b2f3ab0679710c14453fd65c8f9c00d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163161
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-09-17 20:52:43 +00:00
Paul Berry a3c10e3653 Migration: clear regions at the top of InfoBuilder._explainUnit.
There are certain rare conditions involving generated code in a bazel
workspace that can cause a source file to get processed more than once
by the migration tool (sometimes with a correct URI, sometimes with an
incorrect URI that corresponds to a file path in the `bazel-out`
directory).  For the most part the migration tool is tolerant of this
situation, but it can cause InfoBuilder._explainUnit to get called
twice for the same unit.  To avoid this creating user-visible
problems, we need to ensure that any regions left over from the
previous invocation of InfoBuilder._explainUnit are cleared out before
we re-populate the region list.

Bug: https://b.corp.google.com/issues/168295421
Change-Id: I18936b03261c30b8c9062b4a568e1a1e094ec867
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162800
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-09-14 23:58:58 +00:00
Sam Rawlins 151292572c Migrator: Check analysis results before re-running.
* Refactor MigrationCliRunner, mostly simplification.
* Add AnalysisResult class to track analysis errors.
* MigrationState now contains an AnalysisResult, and the previewUrls.
* Add logic in the UI to display analysis results.
* Add logic to the backend to display analysis results.


Fixes https://github.com/dart-lang/sdk/issues/41712
Fixes https://github.com/dart-lang/sdk/issues/43138

Change-Id: I3304467955cfa81820f0010d32e17931b3c68b08
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162400
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-09-10 20:55:14 +00:00
Sam Rawlins 8035d5a0a7 Migrator: Switch styles for un-changed NN type and inserted "?", "!", etc.
Fixes https://github.com/dart-lang/sdk/issues/43125

Some screens:

Old: https://screenshot.googleplex.com/6dqJeWEvX2pYSi4
New w/o position change: https://screenshot.googleplex.com/8HorAjqMw2tMshk
New + bold font (not included in CL; just for reference): https://screenshot.googleplex.com/3N9cMr4RijXv5sM
New w/ position change (included in CL): https://screenshot.googleplex.com/9TfLKpHCCZkzLXX

Change-Id: Ib8aaf3ae56e645beaa01b2cf9e78db68544441b0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162242
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2020-09-10 18:57:58 +00:00
Paul Berry a4b2047d9d Reland "Flow analysis changes to fix mixed-mode unsoundness loophole."
This is a reland of d833f2f65c

Original change's description:
> Flow analysis changes to fix mixed-mode unsoundness loophole.
> 
> This is the flow analysis portion of the fix to
> https://github.com/dart-lang/language/issues/1143.  Follow-up changes
> will be needed in the CFE and/or backends to ensure that exceptions
> are thrown under appropriate circumstances.
> 
> This CL also makes some improvements to flow analysis's reachability
> analysis so that it accounts for nullability of the target when
> analyzing the reachability of `??=` and `?.`.  Hopefully these
> improvements should make the fix to
> https://github.com/dart-lang/language/issues/1143 clearer and more
> consistent.
> 
> Change-Id: I5fa5c070f13fd57ac4c2fb87f2d67588861594b0
> Bug: https://github.com/dart-lang/language/issues/1143
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/160440
> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Commit-Queue: Paul Berry <paulberry@google.com>

Bug: https://github.com/dart-lang/language/issues/1143
Change-Id: If9c45649c1e9f4b19f7c282e7a1c4c956a7bc17f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161622
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2020-09-03 01:01:43 +00:00
Konstantin Shcheglov 1b26394a63 Upgrade nnbd_migration to analyzer 0.40.1, switch to VariableElement.hasInitializer
Change-Id: Iddcc04a8b86dc9e24df003fd8bbd090f025aeef6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161443
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-09-02 19:46:22 +00:00
Mike Fairhurst 30cfb228c0 [nnbd_migration] Remove unused dart:async imports
Change-Id: Ie370dc43312bc872712e1cf811eb7194a30c9945
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161468
Auto-Submit: Mike Fairhurst <mfairhurst@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2020-09-02 17:30:32 +00:00
Paul Berry ab16d79af9 Revert "Flow analysis changes to fix mixed-mode unsoundness loophole."
This reverts commit d833f2f65c.

Reason for revert: Broke build, e.g. https://ci.chromium.org/p/dart/builders/ci/dart-sdk-mac/12688

Original change's description:
> Flow analysis changes to fix mixed-mode unsoundness loophole.
> 
> This is the flow analysis portion of the fix to
> https://github.com/dart-lang/language/issues/1143.  Follow-up changes
> will be needed in the CFE and/or backends to ensure that exceptions
> are thrown under appropriate circumstances.
> 
> This CL also makes some improvements to flow analysis's reachability
> analysis so that it accounts for nullability of the target when
> analyzing the reachability of `??=` and `?.`.  Hopefully these
> improvements should make the fix to
> https://github.com/dart-lang/language/issues/1143 clearer and more
> consistent.
> 
> Change-Id: I5fa5c070f13fd57ac4c2fb87f2d67588861594b0
> Bug: https://github.com/dart-lang/language/issues/1143
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/160440
> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Commit-Queue: Paul Berry <paulberry@google.com>

TBR=paulberry@google.com,scheglov@google.com,johnniwinther@google.com

Change-Id: If1215b19975e0958d612dd69767088095d853879
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: https://github.com/dart-lang/language/issues/1143
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161580
Reviewed-by: Paul Berry <paulberry@google.com>
2020-09-02 15:02:46 +00:00
Paul Berry d833f2f65c Flow analysis changes to fix mixed-mode unsoundness loophole.
This is the flow analysis portion of the fix to
https://github.com/dart-lang/language/issues/1143.  Follow-up changes
will be needed in the CFE and/or backends to ensure that exceptions
are thrown under appropriate circumstances.

This CL also makes some improvements to flow analysis's reachability
analysis so that it accounts for nullability of the target when
analyzing the reachability of `??=` and `?.`.  Hopefully these
improvements should make the fix to
https://github.com/dart-lang/language/issues/1143 clearer and more
consistent.

Change-Id: I5fa5c070f13fd57ac4c2fb87f2d67588861594b0
Bug: https://github.com/dart-lang/language/issues/1143
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/160440
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-09-02 14:27:52 +00:00
Paul Berry e8201aa761 Migration: fix a crash when downcasting to the Null type.
Change-Id: I905e5fe658989969fe72953485f86de1689c5b51
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161140
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-08-31 20:38:48 +00:00
Paul Berry a832289de6 Migration: fix handling of late hints followed by an underscore.
Change-Id: If22d3b398c53912d0de8f5a9977c13411884840c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161142
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-08-31 20:38:29 +00:00
Devon Carew f81dadfa32 [dartdev] update the help text for dartdev and related commands
Change-Id: Ia7139b109872575e58fa8f1cbc4aa72bef44bee5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161020
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2020-08-31 20:17:48 +00:00
Sam Rawlins 4e7848d17a Migrator: Fix windows path failure.
Fixes https://github.com/dart-lang/sdk/issues/43178

Change-Id: I9b41c7bf3f317abfe8f06b37a40ebd9a3d63a813
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/160960
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-08-31 18:16:28 +00:00