We still have `late ResolvedUnitResultImpl result` for now, but many
tests migrated to explicit `TestResolvedUnitResult` and its getters.
Start migrating analyzer resolution tests away from the implicit
ResolutionTest state. Store the TestResolvedUnitResult returned by
resolve helpers in local variables, then read nodes and elements through
that result.
Update helper methods to take the resolved result explicitly when they
need access to findNode or findElement. Also return resolved results
from small wrapper helpers so their callers do not have to depend on
shared state.
This keeps each test tied to the unit it resolved and prepares the test
harness for removing the remaining stored resolution result.
Change-Id: I5e9331fb574d962473e5d36922107f674d7340cc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505621
SLSA-Policy-Verified: SLSA Policy Verification Service <devtools-gerritcodereview-exitgate@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Use FileSource backed by analyzer_testing resources instead of the
test-only Source implementations in analyzer tests.
Update the lightweight TestAnalysisContext to receive a
ResourceProviderMixin and install a URI resolver that produces real
FileSource instances for the dart: and package: URIs used by mock SDK
elements. Convert scanner, diagnostic, options, constant, type system,
and workspace tests to create sources from in-memory files.
Remove the remaining Source mock helpers, including TestSource,
TestSourceWithUri, local Source mocks, and the unused TestTypeProvider.
This keeps test sources closer to production Source behavior and avoids
partial mock implementations that rely on noSuchMethod stubs.
Change-Id: Iad600fb7f5ea00d2c015191df548e0d66a424940
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/499422
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Converts the code that reports diagnostic codes `invalidAssignment`
and `argumentTypeNotAssignable` to use the literate diagnostic
reporting API.
This was challenging because some of the code for reporting these
diagnostics (specifically the method
`ErrorDetectionHelpers.checkForAssignableExpressionAtType`) was
parameterized by diagnostic code, but the two diagnostics accepted a
different number of parameters. To get the type safety of the literate
diagnostic API while preserving the existing behavior, I've created an
abstract base class, `NonAssignabilityReporter`, with a method
`createDiagnostic`, that encapsulates the differences in how to handle
the two diagnostic codes.
Change-Id: I6a6a69649e53f6980b5033771b14dbfdaa5895d6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/467481
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Translates uses of the old diagnostic reporting API, e.g.:
_diagnosticReporter.atNode(
node,
diag.deprecatedExtend,
arguments: [element.name!],
);
To use the new "literate" diagnostic reporting API, e.g.:
_diagnosticReporter.report(
diag.deprecatedExtend.withArguments(typeName: element.name!).at(node),
);
This CL was created by the following steps:
- Run the script
`pkg/analyzer_utilities/tool/messages/use_literate_api_in_analyzer.dart`
- Execute `dart fix --apply --code=unnecessary_import` on the
`pkg/analyzer` directory (this removes imports that are no longer
necessary due to the change)
Not all call sites have been updated at this point. Complex cases were
skipped by the tool and will have to be updated manually. Also,
diagnostic messages that still have the old placeholder parameter
names `p0`, `p1`, `p2`, etc. are still reported using the old API; I
plan to migrate these call sites at the time that I update the
parameter names (by re-running the script).
Change-Id: I6a6a6964671ac6e2ad5acc9ed55658cd6c02e4b5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/467460
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Changes the analyzer and related packages so that when they refer to
diagnostic constants, they do so via the import prefix `diag`, which
refers to the appropriate `diagnostic.dart` file containing the top
level diagnostic constant declarations, rather than the static
declarations inside `DiagnosticCode`-derived classes (which will soon
be removed).
This CL was created by the following steps:
- Run the script
`pkg/analyzer_utilities/tool/messages/switch_to_toplevel_diagnostics.dart`.
- Execute `dart fix --apply --code=unused_import,unnecessary_import`
on the following directories (this removes imports that are no
longer necessary due to the change):
- `pkg/analysis_server`
- `pkg/analyzer`
- `pkg/linter`
- `pkg/analysis_server_plugin`
- `pkg/analyzer_plugin`
- `pkg/analyzer_testing`
- `pkg/front_end`
- `pkg/analyzer_cli`
- Execute `dart format` on the following files and directories:
- `pkg/analysis_server`
- `pkg/analyzer`
- `pkg/linter`
- `pkg/analysis_server_plugin`
- `pkg/analyzer_plugin`
- `pkg/analyzer_testing`
- `pkg/front_end/test/scanner_test.dart`
(Note that `pkg/front_end` and `pkg/analyzer_cli` are not
re-formatted as whole directories because they contain `.dart` files
that are test cases rather than source code, and reformatting those
files might change test expectations.)
- Manually add `diag` to
pkg/front_end/test/spell_checking_list_tests.txt.
- Manually fix the ignore comment in
`pkg/analyzer_testing/lib/src/analysis_rule/pub_package_resolution.dart`. (The
script `switch_to_toplevel_diagnostics.dart` automatically adds it
after `import 'package:analyzer/src/diagnostic/diagnostic.dart' as
diag;`, but then executing `dart format` bumps the ignore comment to
the following line, where it has no effect.)
Change-Id: I6a6a69643022aab2b5a6224fb4124eead243260d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/461521
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
* Remove AnalysisErrorListener, `RecordingDiagnosticListener.errors`,
and `RecordingDiagnosticListener.getErrorsForSource`.
* Deprecate `BooleanDiagnosticListener.onError` and
`RecordingDiagnosticListener.onError` in favor of `.onDiagnostic`.
* Deprecate DiagnosticOrErrorListener. Where this class is used in
private API, replace it with DiagnosticListener. Where this class is
used in public API, keep it and ignore the deprecation lint.
Change-Id: Ie9c89008269db8f42e4ebd161df2764d27dfe0da
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/456100
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
This change was generated by the following process:
- The script `pkg/analyzer/tool/messages/rename_error_constants.dart`
was run. This generated the vast majority of the diffs.
- Then all modified files were reformatted using
`tools/sdk/dart-sdk/bin/dart/format`.
- Finally, the script `pkg/analyzer/tool/messages/generate.dart` was
run, to rebuild generated code.
Change-Id: I6a6a69644ed8740ad6269d98cb169076151824ed
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444921
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
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>
Replace index / search of `CompilationUnitElement` with special
`referencesLibraryFragment(LibraryFragment)`, because they are not
elements.
Change-Id: I4de4ce42270bdad92996bedbd06f108a7c71dffe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412681
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
For `InterfaceType` keep `element2` deprecated and define
`InterfaceElement get element2` instead. Most changes are because
of this.
Change-Id: I13b888610fc707438c3c97b676f1460e7fc2b040
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/253564
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Cases where `null` was being passed as an argument to formatting a
message have all been fixed in previous CLs; all that remains to do is
change the type system to reflect that, and insert `!`s in a few
places.
This brings us one step closer to being able to make analyzer message
formatting type safe.
Change-Id: Id9e0d0b32f29cde0fdc5227417b7a2e3fc3b443d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/216272
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Each of the *_Fasta test cases has a lot of test cases from the
corresponding *Mixin mixin. I started to combine _all_ of these
in parser_test.dart, but the file became too long; the formatter
was freezing IntelliJ.
So I've extracted out the non-test classes into parser_test_base.dart.
I'd like to extract each test class into its own file. For now, I
reduce half a dozen *_Fasta/*Mixin pairs into individual test classes.
Change-Id: I8dd7f28a6fe23e31f956cdb2f1d221669db376dc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/176064
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Fields initialized in `setUp` are late.
Variables initialized with implicit casts like:
ClassDeclaration clazz = unit.declarations[0];
would need a cast:
ClassDeclaration clazz = unit.declarations[0] as ClassDeclaration;
so they are updated to use var, which is more idiomatic:
var clazz = unit.declarations[0] as ClassDeclaration;
Change-Id: I4e4ae814a814d3a4200c5078a6904dbac0a8140c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170520
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>