This function was defined once in analyzer testing code, once in
linter testing code, and once in analysis_server testing code. In this
change, all three are combined into one function in analyzer_utilities.
Change-Id: Ib2daa7b3d14aae6ca2aa09f6f9bdeaf76bc72d10
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/423068
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
The purpose for this change is to make it easier to use `TestCode` to
parse the code under test. This, in turn, will allow us to use the same
markdown in all of our test code, making it easier to write and read
our tests. This biggest blocker to that goal is the fact that we assign
to `testCode` in several places, and that's the problem solved by this
change.
Change-Id: Id88463925587ff0839fe75faf6a1d083a1b3320c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415700
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
There are still lots of declarations whose name ends in a trailing
digit, but most of them are unrelated to the migration, and some
are required in order to not break internal code.
I'm happy to break this up into smaller CLs if it's hard to review.
Mostly it's just renaming some declarations, although there are one or
two places where I did a little more clean-up.
Change-Id: I50d32316e82e48c6a5a47aec630b4ffee2ead2c8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/410922
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
* Move the only 3 files from server_plugin to analysis_server_plugin.
* Copy some test infra into analysis_server_plugin. This is temporary,
as we need some shared test infra location.
Change-Id: If2b41d436c9d3051e590f60ae2eb7ab31e529321
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364161
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
The big one is `getIndent`, which I think can be simpler, and also used a handwritten implementation of `String.operator *`. It turns out:
* > 90% of calls to `getIndent` were `getIndent(1)`, which can be
replaced with a constant `' '`.
* Then 4 calls to `getIndent` were `getIndent(2)`, which can be replaced
with a constant `' ' + ' '`.
* Then one last call, in CorrectionUtils itself, used a variable number
of indents which can be replaced with `' ' * n`. This is in the
`indentRight` function.
Also:
* Privatize `getInsertionLocationTop`, `isClassWithEmptyBody`, `isJustWhitespaceOrComment`, `skipEmptyLinesLeft`
* Rewrite CorrectionUtils.findSimplePrintInvocation as an extension
method on AstNode; does not need the `_buffer`.
Change-Id: I15c19b8c0cc354adcd4ffea5803b3a182cf28336
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358400
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Makes behaviour of changing leading indent or trailing newlines opt-in.
There are only slightly more uses of this method that don't want this (now opt-in) behaviour, although I think this is slightly less surprising (for example the trailing newline behaviour was to "add a trailing newline only if it didn't already exist" which I don't think was obvious).
Mostly this was just changing the defaults and all of the call sites. However, some call sites were getting the old behaviour (inc leading/trailing whitespace), but then calling `.trim()`, so I didn't add the opt-in there because it would then be removed (they won't show up in the diff because they didn't actually get any changes).
Change-Id: I2f05b3a6266aaad5ee510ce2a8bf269b26d42d5d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329540
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
The original goal of this change was to add the `switchExpression` test in `flutter_wrap_center_test.dart`, but it failed on Windows and exposed a bug that affected a number of assists/fixes.
The issue was that indentation was being rewritten using a regex:
src.replaceAll(RegExp('^$indentOld', multiLine: true), indentNew)
On Windows, when `indentOld` is an empty string, both `\r` and `\n` are matched individually, resulting in indentation being inserted between them:
foo\r \n bar
To fix this, I changed all places using a regex for replacement like this to call the existing `CorrectionUtils.replaceSourceIndent` method which did not have this problem. However, it made two different assumptions:
1. Indentation should always be updated on the first line (which if `indentOld` is an empty string, results in extra unwanted indentation being prepended to the string)
2. A new EOL should always be added at the end of the new code
To handle this, I added two new parameters and kept the original behaviour the same (although, I'm not sure if defaulting to adding a newline makes a lot of sense).
Change-Id: Ifa714da62c2541ba54a5376aa67149c90396dec2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/328220
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
- Make CorrectionProducer as base class for {Parsed/Resolved}CorrectionProducer.
- Use ParsedCorrectionProducer for ConvertDocumentationIntoLine
- Move sort imports test to used ParsedUnitResult
- Add getter to LintRule to indicate that rule can be run using just parsed AST
Change-Id: Id11466c445e6e505ea752d097b57143f18c47060
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310484
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
This would be a breaking change, so for now it is disabled, but
the method `applyPendingFileChanges()` can be added, and the clients
will call it to be ready for the switching the flag.
Only clients that call methods like `changeFile` have to await applying
the file changes. Other clients can continue using synchronous
`currentSession`.
Change-Id: I0f8d4cc874f485776f611790f6c80fd7e07c8051
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/236041
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>