6 Commits

Author SHA1 Message Date
Sam Rawlins 8546b2e4e6 analyzer_testing: Move Spelunker into this package
The Spelunker class is only used by analyzer_testing's
PubPackageResolutionTest class, and by a utility script. So I believe
the best place for this class is in analyzer_testing, for two reasons:

* Would we also move the utility script
  (`pkg/linter/tool/spelunk.dart`)? This is a script that lets you see
  a visual tree of the syntax nodes of a Dart script. It has been
  helpful to people writing lint rules, as it helps you understand how
  you need to walk up or down the tree to check conditions. Therefore,
  it will be at least as helpful to people writing analysis rules in
  analyzer plugins (the primary consumers of PubPackageResolutionTest).
  It doesn't need to live in `bin` (though that's one possibility). It
  can live in `analyzer_testing/tool`.
* Then if the utility script lives in analyzer_testing, and
  PubPackageResolutionTest lives in analyzer_testing, and these are the
  sole consumers of Spelunker, it makes sense to move it into
  analyzer_testing. It does not need to be public API; just live in the
  source code.

Change-Id: Id607091b35ab83c96b8cd73f0ece63923c934fb4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444240
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2025-08-07 12:29:10 -07:00
Paul Berry 6610e5cbfe [analyzer] Break dependency between analyzer message codegen and analyzer.
This fixes a bootstrapping problem: previously we could get into a
situation where the generated files for analyzer diagnostic messages
were out of date, but the code generator for those messages couldn't
be run, because it imported the analyzer itself, which contained
compiled errors due to the generated files being out of date.

There were two problematic dependencies:

- The `GeneratedContent.check` and `GeneratedContent.checkAll` methods
  relied on invoking the Dart formatter as a library (rather than
  invoking `dart format` as a subprocess); the Dart formatter library
  imports the analyzer. Fortunately, this functionality is not needed
  by the code generators themselves. It's only needed by the _tests_
  that verify that code generation has run. So I was able to break the
  dependency by moving this functionality into a new file,
  `package:analyzer_utilities/generated_content_check.dart`, which is
  imported only by the code generation tests. The new API is slightly
  different: `GeneratedContent.checkAll` has been replaced by an
  extension method `check` on `Iterable<GeneratedContent>`.

- The diagnostic message code generator used to have a post-processing
  step that made use of the scanner to find error messages used by the
  parser that needed to be translated, and issued a warning if it
  found any. This check was useful a long time ago, when we were
  unifying the analyzer and CFE parsers, and is no longer useful, so
  I've removed it.

Change-Id: I509b741faca3b9ae21c23936001105ded731b490
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442241
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2025-07-25 13:18:00 -07:00
Paul Berry fb2d1171e5 Reference all genearted file paths to pkg directory.
Modifies `GeneratedDirectory.outputDirPath` and
`GeneratedFile.outputPath` to be relative to the SDK's `pkg` directory
rather than relative to the containing package. Accordingly, modifies
the `GeneratedContent` methods `check`, `checkAll`, `generate`,
`generateAll`, `output`, as well as the `DirectoryContentsComputer`
and `FileContentsComputer` callbacks, so that their first parameter is
the path to the `pkg` directory rather than the path to the containing
package.

Also modifies the `readApi` functions in `pkg/analysis_server` and
`pkg/analyzer_plugin` to accept a path to the `pkg` directory rather
than a path to the containing package, since these functions are
called by code generation callbacks.

These changes should make code generation logic easier to reason
about. They also will make it easier to move the outputs of code
generation from one package to another, which will pave the way for
some follow-up work in which I intend to start sharing error message
representations belonging to `pkg/analyzer`, `pkg/front_end`, and
`pkg/_fe_analyzer_shared`.

Change-Id: Ia9b369b16f2df931c8a472f91400f2c5a0b8be9d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/438480
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2025-07-04 05:04:50 -07:00
Paul Berry 5c091e010f Separate allTargets variables for api.txt code generators.
This change removes the top level variable `allTargets` from
`pkg/analyzer_utilities/lib/tool/api.dart` and replaces it with a
method `allTargetsForPackage`, parameterized by the name of the
package for which an `api.txt` file is generated. The individual code
generators that make use of this function now all have their own top
level variable `allTargets`.

In addition to being conceptually clearer (since we no longer have a
single `allTargets` variable with different meanings depending on
where it's used), this paves the way for a CL I am working on that
will change the `GeneratedContent` based code generators so that they
use paths relative to the `pkg` directory. That in turn should make it
simpler to move some of the code generated files that have to do with
error messages from `pkg/analyzer` to `pkg/_fe_analyzer_shared`.

Change-Id: Id636ddbca27c46ae4242bbf8e4b6f7b8dae4d4e9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/438481
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-07-02 14:31:33 -07:00
Sam Rawlins 78c2181b3c analysis_server_plugin: Check-in the current api.txt file
Change-Id: Ia88f755e6b92559ad15aa53ec612d92597fb0dc3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428928
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-05-19 12:24:39 -07:00
Sam Rawlins fafad4e03d analyzer: Move the API tool so that it can generate API for other packages
Also, add some scripts to generate the analyzer_testing API, and checkin
the api.txt file for analyzer_testing.

In order to avoid a private analyzer import, I add `isExperimental` and
`hasExperimental` support for `@experimental` annotation, and switch
to using public APIs in `_dumpElement`.

Change-Id: I44319270d4e6083b80973b45933268c472876232
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426282
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2025-05-02 14:22:31 -07:00