0349520b98
No more flag, always parse into the new AST, always visit new AST nodes,
always return them as child entities, parent-child structure reflects
the new AST.
So, use `namePart` and `body` where possible. Deprecate previous
properties.
This is still de jure a breaking change, because `parent` of deprecated
properties changes. De facto this required very few changes in google3.
Once this CL lands, I will publish `analyzer 10.0.0`, migrate everything
to new properties, delete deprecated properties, and publish `analyzer
11.0.0`.
Maybe deprecate `NamedCompilationUnitMember.name` and migrate to
subclass specific `name` or `namePart` properties before publishing
`analyzer 10.0.0`. This part is not breaking per se.
* Deprecations in `ClassDeclaration`:
* Properties `leftBracket`, `members`, `rightBracket` are deprecated, use `body` instead.
* Properties `name`, `typeParameters` are deprecated, use `namePart` instead.
* Deprecations in `EnumDeclaration`:
* Properties `leftBracket`, `constants`, `members`, `rightBracket` are deprecated, use `body` instead.
* Properties `name`, `typeParameters` are deprecated, use `namePart` instead.
* Deprecations in `ExtensionDeclaration`:
* Properties `leftBracket`, `members`, `rightBracket` are deprecated, use `body` instead.
* Deprecations in `ExtensionTypeDeclaration`:
* Properties `leftBracket`, `constants`, `members`, `rightBracket` are deprecated, use `body` instead.
* Properties `constKeyword`, `name`, `representation`, `typeParameters` are deprecated,
use `primaryConstructor` instead.
* **Breaking Change:** While the deprecated members mentioned above still exist in the AST,
their parent nodes have changed. This means that code relying on specific parent-child
relationships for these nodes might break.
Bug: https://github.com/dart-lang/sdk/issues/61701
Change-Id: Ic48104da8b029c9b454bbd2336574b7823025565
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/461841
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
83 lines
3.1 KiB
Dart
83 lines
3.1 KiB
Dart
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'dart:io';
|
|
|
|
import 'package:analysis_server/src/utilities/extensions/ast.dart';
|
|
import 'package:analyzer/dart/analysis/analysis_context_collection.dart';
|
|
import 'package:analyzer/dart/analysis/results.dart';
|
|
import 'package:analyzer/dart/ast/ast.dart';
|
|
import 'package:analyzer/file_system/physical_file_system.dart';
|
|
import 'package:analyzer_testing/package_root.dart';
|
|
|
|
class BulkFixDetails {
|
|
Future<Map<String, CorrectionDetails>> collectOverrides() async {
|
|
var overrideDetails = <String, CorrectionDetails>{};
|
|
|
|
var pkgRootPath = PhysicalResourceProvider.INSTANCE.pathContext.normalize(
|
|
packageRoot,
|
|
);
|
|
var directory = Directory(
|
|
'$pkgRootPath/analysis_server/lib/src/services/correction/dart',
|
|
);
|
|
var collection = AnalysisContextCollection(
|
|
includedPaths: [directory.absolute.path],
|
|
resourceProvider: PhysicalResourceProvider.INSTANCE,
|
|
);
|
|
var context = collection.contexts[0];
|
|
|
|
for (var file in directory.listSync()) {
|
|
var resolvedFile =
|
|
await context.currentSession.getResolvedUnit(file.absolute.path)
|
|
as ResolvedUnitResult;
|
|
for (var classDecl
|
|
in resolvedFile.unit.declarations.whereType<ClassDeclaration>()) {
|
|
var classElement = classDecl.declaredFragment?.element;
|
|
if (classElement != null &&
|
|
classElement.allSupertypes.any(
|
|
(element) => element.element.name == 'CorrectionProducer',
|
|
)) {
|
|
var correctionName = classDecl.namePart.typeName.lexeme;
|
|
|
|
for (var method
|
|
in classDecl.members2.whereType<MethodDeclaration>()) {
|
|
if (method.name.lexeme == 'canBeAppliedInBulk') {
|
|
var hasComment =
|
|
method.returnType?.beginToken.precedingComments != null;
|
|
|
|
var body = method.body;
|
|
if (body is BlockFunctionBody) {
|
|
var last = body.block.statements.last;
|
|
if (last is ReturnStatement) {
|
|
var canBeBulkApplied =
|
|
(last.expression as BooleanLiteral).value;
|
|
overrideDetails[correctionName] = CorrectionDetails(
|
|
canBeBulkApplied: canBeBulkApplied,
|
|
hasComment: hasComment,
|
|
);
|
|
}
|
|
} else if (body is ExpressionFunctionBody) {
|
|
var expression = body.expression;
|
|
var canBeBulkApplied = (expression as BooleanLiteral).value;
|
|
overrideDetails[correctionName] = CorrectionDetails(
|
|
canBeBulkApplied: canBeBulkApplied,
|
|
hasComment: hasComment,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return overrideDetails;
|
|
}
|
|
}
|
|
|
|
class CorrectionDetails {
|
|
bool canBeBulkApplied;
|
|
bool hasComment;
|
|
|
|
CorrectionDetails({required this.canBeBulkApplied, required this.hasComment});
|
|
}
|