Commit Graph

24 Commits

Author SHA1 Message Date
Robert Nystrom 81059a1b79 Migrate pkg/scrape to the new constructor syntax.
Change-Id: I45dcedb1ce90d7a9700a57767ae01fff5721ccfc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/506602
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
2026-05-27 12:21:23 -07:00
Konstantin Shcheglov 921ec7f507 CQ. Simplify Scanner constructors.
Replace the positional Scanner constructors with a single constructor
that takes the input text and error reporting callback as named required
arguments.

Remove the unused fasta forwarding constructor, reader offset handling,
and stored first token. The scanner now keeps only the input text and
returns the token stream directly from tokenize.

Update analyzer, analysis server, plugin, CLI, scrape, and scanner test
call sites to use the named constructor arguments.

Change-Id: Ieabb7b28570d4a963563fb2d1c5ef5ac0c89032a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/500340
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2026-05-05 14:04:00 -07:00
Konstantin Shcheglov 245f876407 CQ. Abstract Scanner away from DiagnosticReporter, so that we don't need Source to scan.
Change-Id: I377a49a7997f416acdfde3a05616715abaa84ad8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/499780
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
2026-05-01 09:17:00 -07:00
Konstantin Shcheglov 5273f91b95 CQ. Scan from strings and drop scanner reader shim.
Remove the analyzer-only `scanner/reader.dart` re-export and refactor
`Scanner` to accept source text directly.

* Delete `pkg/analyzer/src/dart/scanner/reader.dart`, which only re-exported
  `_fe_analyzer_shared` reader types.
* Replace the `Scanner(CharacterReader, ...)` factory with
  `Scanner(String contents, ...)`, aligning the API with the underlying
  `scanString` implementation.
* Update analyzer, analysis_server, analyzer_cli, analyzer_plugin, and scrape
  call sites to pass the source string directly instead of constructing
  `CharSequenceReader`.

This removes an unnecessary abstraction layer, reduces
imports/indirection, and makes scanner usage simpler and more uniform
across the repo.

Change-Id: I380b365676c8a62971a3700deadb695d1519d653
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/477600
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-02-02 11:20:31 -08:00
Paul Berry cf1d8b96db [messages] Make Scanner and Parser take a DiagnosticReporter.
Changes the signature of the following constructors:
- Scanner
- Scanner.fasta
- Parser

So that they accept a `DiagnosticReporter` object rather than a
`DiagnosticListener` object. This brings the scanner and the parser
into alignment with the majority of the rest of the analyzer (which
reports errors using `DiagnosticReporter` rather than by talking to
`DiagnosticListener` directly).

It also makes the `source` parameter of these constructors
unnecessary, because the `source` can be obtained from the
`DiagnosticReporter`.

Change-Id: I6a6a6964607ffb52a8332a6e618dc0c9a1e48c5c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/473442
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-16 13:34:50 -08:00
Sam Rawlins ee69f45a1f analyzer: rework AnalysisErrorListener deprecation
Work towards #60635

In this change, we rework the AnalysisErrorListener deprecation to
better support users who have their own class that implements
AnalysisErrorListener. This change introduces a sealed supertype,
DiagnosticOrErrorListener, with the old implementation,
AnalysisErrorListener, and the new implementation, DiagnosticListener,
as its sole direct subclasses. Users who have implemented
AnalysisErrorListener should be able to instead implement
DiagnosticListener, and their class is an acceptable instance of
DiagnosticOrErrorListener, wherever that is needed.

In a breaking change we can drop AnalysisErrorListener and deprecate
DiagnosticOrErrorListener, and in the next breaking change, we can drop
DiagnosticOrErrorListener.

For reference, see the first API difference when deprecating AnalysisErrorListener and introducing DiagnosticListener: https://github.com/dart-lang/sdk/commit/903d77cc8229972a424941dcb7b7b79741e833eb#diff-dec15868961d7eadcd009f49d129bebcdb747aaa8dbfde5f5a08884e0cf11e32

Change-Id: I3ccf11d54b41fbca98d020d89978d250c16b4c04
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/436480
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-06-25 06:54:20 -07:00
Sam Rawlins 903d77cc82 analyzer: Rename ErrorListener classes to DiagnosticListener
Work towards https://github.com/dart-lang/sdk/issues/60635

I tried to keep this minimal but still sensible:

* Rename AnalysisErrorListener and all subtypes to use 'Diagnostic'.
* Rename all instantiations of such classes if they previously
  contained the word 'error'.
* Rename `RecordingDiagnosticListener.errors` to `.diagnostics`.
* Rename some _testing_ instance members that had the word 'error'
  to instead use 'diagnostic'.

Change-Id: I3948e27ba28ac2494092e04f4e1d201a20cc1135
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433004
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-06-05 14:05:40 -07:00
Sam Rawlins 8a17ad9f05 analyzer: Deprecate AnalysisError in favor of Diagnostic
Work towards https://github.com/dart-lang/sdk/issues/60635

Change-Id: If9bbc96beed95129b099588c5bd9728afda8e392
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426902
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2025-05-08 14:02:16 -07:00
Danny Tuppeny 27b52a3f82 Add languageVersion to CompilationUnit and make non-null
Change-Id: Ice6f866929f1f028d9b4e64685c2e815a08279f6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392000
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-10-31 18:49:03 +00:00
Parker Lougheed 2a98f98098 [scrape] Use dart_flutter_team_lints as base for analysis
Change-Id: Ief30fb79b2afcbb3f50d9127eb622fac362b07b1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340141
Commit-Queue: Devon Carew <devoncarew@google.com>
Auto-Submit: Parker Lougheed <parlough@gmail.com>
Reviewed-by: Devon Carew <devoncarew@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
2023-12-07 17:57:31 +00:00
Robert Nystrom dd26d7875f Add a few tweaks to the scrape package.
- Create histograms automatically so that you can just call record()
  and it will work even if you didn't pre-define the histogram.

- Expose an API for printing a range of lines.

- Expose the source code being parsed.

Change-Id: I486f75c75451871778ffe24389633f4c7d8c7736
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340024
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2023-12-06 02:39:38 +00:00
asiva e0fa7f9d0f [VM] Remove observatory_2 directory and all references to it.
TEST=ci

Change-Id: I4e95e59fc909c01517ae59f39d04c38bb353b85a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330525
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
2023-10-16 17:45:46 +00:00
Parker Lougheed 8d5dfeadf6 [analyzer] Remove unused, old feature methods from old parser
Change-Id: I08d3aa5b76546e449af42caffc2372e25bdd350a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/320440
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-08-15 19:14:17 +00:00
Robert Nystrom 9057fcbc11 Couple of tweaks to the scrape package.
- Trim output lines to 80 characters. This makes it overwrite the line
  correctly instead of scrolling unnecessarily.

- Make the tokens for each parsed file available to a scrape class.

Change-Id: Ib986ec548ac3f8ba1c3c55b1a00673f49d45c0d0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280055
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
2023-02-01 22:40:38 +00:00
Konstantin Shcheglov 01173e2aa2 Deprecate 'name' in AST, use 'name2' token instead.
Change-Id: I867f009dca12208f835199297d2ea85c203c8556
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/252566
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-08-02 16:25:34 +00:00
Devon Carew 2acf036023 move the third_party/pkg_tested packages into third_party/pkg
Change-Id: I7e2499aafb1ae85da4699358909ac67337593a11
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/247927
Reviewed-by: Jonas Termansen <sortie@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2022-06-13 17:04:36 +00:00
Carolyn Qu 21b07646f5 Fixing typo in comment
Change-Id: I3a64ee58f2d3d5c23492c799a8cf50876fe8b4a1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/246987
Reviewed-by: Elliott Brooks <elliottbrooks@google.com>
Reviewed-by: Carolyn Qu <carolynqu@google.com>
Commit-Queue: Islina Shan <islinashan@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Islina Shan <islinashan@google.com>
2022-06-04 00:35:16 +00:00
Robert Nystrom e5c83a3961 Update the set of directories scrape ignores containing language tests.
Since tests of our internal tools often deliberately contain edge cases
and unusual code constructs, scrape supports ignoring Dart files in
those directories in order to focus on more representative code.

This updates that ignore list to handle all of the various
compiler-related packages I could find.

Change-Id: I4006d2b3b14a81572f27db0b65e6c6194c4f7f54
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241506
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2022-04-19 18:06:47 +00:00
Devon Carew 26043c95cf Move pkg/scrape to package:lints.
Change-Id: I56eb8d0410ab529a434c540a67028f8ebe441c4d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/240913
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2022-04-18 22:09:50 +00:00
Danny Tuppeny 1e9fb81697 [analysis_server] Make CompilationUnit.lineInfo non-nullable
Change-Id: Ib628751a14dc3257cf7325432ab20f2bdb9d6f3b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/234290
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-03-03 06:59:00 +00:00
Robert Nystrom dcec42f0b5 Add script to scrape metadata annotation arguments.
Change-Id: Icbe5c84cfa5cb2fe376679b267452d6dcfe61ac8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/206582
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
2021-07-12 23:41:32 +00:00
Robert Nystrom 86ccb1fb6e Migrate pkg/scrape to null safety.
Change-Id: I5c9857090eed7bf521ba581d0c9051606ed45304
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/205940
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2021-07-07 22:08:53 +00:00
Robert Nystrom c755ef4ac6 Fix some error handling in scrape.
- Ensure the lexer is running at the latest language version. Before, it
  would fail to handle files that used extension methods since it didn't
  tokenize "extension" correctly.

- Don't visit files that produce parse errors. It was reporting the
  errors but still going ahead and parsing them... which actually
  worked surprisingly well (yay error recovery) but could lead to
  dubious results.

Change-Id: I0e94b5c56efaeb3c2ccde0fbf20c09733aac4998
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174021
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2020-11-30 15:19:30 +00:00
Robert Nystrom 891a8a1aa3 Add new "scrape" package.
The README explains, it but, in short, this is a little library I
harvested from the scripts I wrote during ui-as-code. It makes it easier
to write scripts to gather bits of statistical data from Dart syntax.

Change-Id: Ia33797f582c4d4f9f966b7f6dc7b58ca2414601e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166788
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
2020-10-19 22:24:28 +00:00