mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 02:07:06 +00:00
Fix hints and lints after migration of the migration tool.
Change-Id: I90ac7e88686ba6db9b9e64538663ae2044638894 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/204483 Reviewed-by: Samuel Rawlins <srawlins@google.com>
This commit is contained in:
parent
768104377b
commit
730cbcbe6e
|
@ -1151,6 +1151,5 @@ extension on Severity {
|
|||
case Severity.info:
|
||||
return 'info';
|
||||
}
|
||||
return '???';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import 'package:analyzer/dart/ast/ast.dart';
|
|||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer/src/generated/utilities_general.dart';
|
||||
import 'package:analyzer_plugin/protocol/protocol_common.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:nnbd_migration/instrumentation.dart';
|
||||
import 'package:nnbd_migration/src/nullability_migration_impl.dart';
|
||||
import 'package:pub_semver/pub_semver.dart';
|
||||
|
@ -246,9 +245,7 @@ class NullabilityFixDescription {
|
|||
);
|
||||
|
||||
const NullabilityFixDescription._(
|
||||
{required this.appliedMessage, required this.kind})
|
||||
: assert(appliedMessage != null),
|
||||
assert(kind != null);
|
||||
{required this.appliedMessage, required this.kind});
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
|
|
|
@ -41,8 +41,6 @@ class DecoratedTypeOperations
|
|||
DecoratedType from,
|
||||
List<DecoratedType>? promotedTypes,
|
||||
List<DecoratedType>? newPromotedTypes) {
|
||||
assert(to != null);
|
||||
assert(from != null);
|
||||
// Do not force promotion if it appears that the element's type was just
|
||||
// demoted.
|
||||
if (promotedTypes != null &&
|
||||
|
|
|
@ -1753,11 +1753,7 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType>
|
|||
class_.declaredElement!, callee.enclosingElement);
|
||||
var typeArguments = decoratedSupertype.typeArguments;
|
||||
Iterable<DartType?> typeArgumentTypes;
|
||||
if (typeArguments != null) {
|
||||
typeArgumentTypes = typeArguments.map((t) => t!.type);
|
||||
} else {
|
||||
typeArgumentTypes = [];
|
||||
}
|
||||
typeArgumentTypes = typeArguments.map((t) => t!.type);
|
||||
var createdType = DecoratedType(callee.returnType, nullabilityNode,
|
||||
typeArguments: typeArguments);
|
||||
var calleeType =
|
||||
|
@ -1884,10 +1880,6 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType>
|
|||
if (typeArguments == null) {
|
||||
var instantiatedType =
|
||||
_variables!.decoratedTypeAnnotation(source, typeName);
|
||||
if (instantiatedType == null) {
|
||||
throw StateError('No type annotation for type name '
|
||||
'${typeName.toSource()}, offset=${typeName.offset}');
|
||||
}
|
||||
var origin = InstantiateToBoundsOrigin(source, typeName);
|
||||
for (int i = 0; i < instantiatedType.typeArguments.length; i++) {
|
||||
_linkDecoratedTypes(
|
||||
|
@ -1905,10 +1897,6 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType>
|
|||
assert(bound != null);
|
||||
var argumentType =
|
||||
_variables!.decoratedTypeAnnotation(source, typeArguments[i]);
|
||||
if (argumentType == null) {
|
||||
_unimplemented(typeName,
|
||||
'No decorated type for type argument ${typeArguments[i]} ($i)');
|
||||
}
|
||||
_checkAssignment(
|
||||
TypeParameterInstantiationOrigin(source, typeArguments[i]),
|
||||
FixReasonTarget.root,
|
||||
|
@ -2858,7 +2846,7 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType>
|
|||
DecoratedType? getType;
|
||||
if (getter.isSynthetic) {
|
||||
var field = getter.variable;
|
||||
if (field == null || field.isSynthetic) return;
|
||||
if (field.isSynthetic) return;
|
||||
getType = _variables!.decoratedElementType(field);
|
||||
} else {
|
||||
getType = _variables!.decoratedElementType(getter).returnType;
|
||||
|
@ -2866,7 +2854,7 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType>
|
|||
DecoratedType? setType;
|
||||
if (setter.isSynthetic) {
|
||||
var field = setter.variable;
|
||||
if (field == null || field.isSynthetic) return;
|
||||
if (field.isSynthetic) return;
|
||||
setType = _variables!.decoratedElementType(field);
|
||||
} else {
|
||||
setType =
|
||||
|
@ -3451,7 +3439,6 @@ mixin _AssignmentChecker {
|
|||
required bool hard,
|
||||
bool checkable = true,
|
||||
bool sourceIsFunctionLiteral = false}) {
|
||||
assert(origin != null);
|
||||
var sourceType = source.type!;
|
||||
var destinationType = destination.type!;
|
||||
if (!_typeSystem.isSubtypeOf(sourceType, destinationType)) {
|
||||
|
|
|
@ -41,7 +41,6 @@ Map<int?, List<AtomicEdit>>? _removeCode(
|
|||
end: [AtomicEdit.insert(' */', info: info)]
|
||||
};
|
||||
}
|
||||
throw StateError('Null value for removalStyle');
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -189,9 +189,7 @@ class FixAggregator extends UnifyingAstVisitor<void> {
|
|||
var change = _changes[node];
|
||||
if (change != null) {
|
||||
var innerPlan = change._apply(node, this);
|
||||
if (innerPlan != null) {
|
||||
_plans.add(innerPlan);
|
||||
}
|
||||
_plans.add(innerPlan);
|
||||
} else {
|
||||
node.visitChildren(this);
|
||||
}
|
||||
|
@ -344,9 +342,8 @@ class NodeChangeForAnnotation extends NodeChange<Annotation> {
|
|||
if (name is PrefixedIdentifier) {
|
||||
name = name.identifier;
|
||||
}
|
||||
if (name != null &&
|
||||
aggregator.planner.sourceText!.substring(name.offset, name.end) ==
|
||||
'required') {
|
||||
if (aggregator.planner.sourceText!.substring(name.offset, name.end) ==
|
||||
'required') {
|
||||
// The text `required` already exists in the annotation; we can just
|
||||
// extract it.
|
||||
return aggregator.planner.extract(
|
||||
|
@ -552,7 +549,6 @@ class NodeChangeForCompilationUnit extends NodeChange<CompilationUnit> {
|
|||
List<EditPlan> innerPlans = [];
|
||||
if (removeLanguageVersionComment) {
|
||||
final comment = (node as CompilationUnitImpl).languageVersionToken!;
|
||||
assert(comment != null);
|
||||
innerPlans.add(aggregator.planner.replaceToken(node, comment, '',
|
||||
info: AtomicEditInfo(
|
||||
NullabilityFixDescription.removeLanguageVersionComment,
|
||||
|
@ -933,9 +929,9 @@ class NodeChangeForMethodInvocation
|
|||
var innerPlans = [
|
||||
if (targetPlan != null) targetPlan,
|
||||
if (nullAwarePlan != null) nullAwarePlan,
|
||||
if (methodNamePlan != null) methodNamePlan,
|
||||
methodNamePlan,
|
||||
if (typeArgumentsPlan != null) typeArgumentsPlan,
|
||||
if (argumentListPlan != null) argumentListPlan
|
||||
argumentListPlan
|
||||
];
|
||||
return _applyExpression(aggregator,
|
||||
aggregator.planner.passThrough(node, innerPlans: innerPlans));
|
||||
|
@ -1062,7 +1058,7 @@ class NodeChangeForPropertyAccess
|
|||
var innerPlans = [
|
||||
if (targetPlan != null) targetPlan,
|
||||
if (nullAwarePlan != null) nullAwarePlan,
|
||||
if (propertyNamePlan != null) propertyNamePlan
|
||||
propertyNamePlan
|
||||
];
|
||||
return _applyExpression(aggregator,
|
||||
aggregator.planner.passThrough(node, innerPlans: innerPlans));
|
||||
|
|
|
@ -626,9 +626,7 @@ class MigrationResolutionHooksImpl
|
|||
if (_fixBuilder!._typeSystem.isSubtypeOf(nonNullType, contextType)) {
|
||||
return _createNullCheckChange(node, expressionType);
|
||||
} else {
|
||||
if (node != null) {
|
||||
_flowAnalysis!.asExpression_end(node, contextType);
|
||||
}
|
||||
_flowAnalysis!.asExpression_end(node, contextType);
|
||||
return IntroduceAsChange(contextType,
|
||||
isDowncast: _fixBuilder!._typeSystem
|
||||
.isSubtypeOf(contextType, expressionType));
|
||||
|
@ -1225,7 +1223,7 @@ class _FixBuilderPreVisitor extends GeneralizingAstVisitor<void>
|
|||
cls.name, method.name, element.name),
|
||||
{FixReasonTarget.root: node});
|
||||
var metadata = parameter.metadata;
|
||||
if (metadata != null && metadata.isNotEmpty) {
|
||||
if (metadata.isNotEmpty) {
|
||||
// Only the last annotation can be changed into a `required` keyword;
|
||||
// changing an earlier annotation into a keyword would be illegal.
|
||||
var lastAnnotation = metadata.last;
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer_plugin/protocol/protocol_common.dart'
|
||||
hide AnalysisError;
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:nnbd_migration/src/front_end/driver_provider_impl.dart';
|
||||
import 'package:pub_semver/src/version.dart';
|
||||
|
||||
|
|
|
@ -229,8 +229,7 @@ class TraceEntryInfo {
|
|||
final List<HintAction> hintActions;
|
||||
|
||||
TraceEntryInfo(this.description, this.function, this.target,
|
||||
{this.hintActions = const []})
|
||||
: assert(hintActions != null);
|
||||
{this.hintActions = const []});
|
||||
}
|
||||
|
||||
/// Information about a nullability trace.
|
||||
|
|
|
@ -62,8 +62,7 @@ class MigrationState {
|
|||
this.instrumentationListener,
|
||||
this.neededPackages,
|
||||
this.shouldBeMigratedFunction,
|
||||
[this.analysisResult])
|
||||
: assert(neededPackages != null);
|
||||
[this.analysisResult]);
|
||||
|
||||
/// If the migration has been applied to disk.
|
||||
bool get hasBeenApplied => _hasBeenApplied;
|
||||
|
|
|
@ -38,10 +38,8 @@ class MigrationSummary {
|
|||
var hint = info.hintComment;
|
||||
if (hint == null || hintsSeen.add(hint)) {
|
||||
var description = info.description;
|
||||
if (description != null) {
|
||||
var key = _keyForKind(description.kind);
|
||||
changeSummary[key] = (changeSummary[key] ?? 0) + 1;
|
||||
}
|
||||
var key = _keyForKind(description.kind);
|
||||
changeSummary[key] = (changeSummary[key] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,6 +114,5 @@ class MigrationSummary {
|
|||
case NullabilityFixKind.typeNotMadeNullableDueToHint:
|
||||
return 'typeNotMadeNullableDueToHint';
|
||||
}
|
||||
return '???';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,11 +84,6 @@ class RegionRenderer {
|
|||
|
||||
/// Returns the URL that will navigate to the given [target].
|
||||
String _relativePathToTarget(NavigationTarget target, String unitDir) {
|
||||
if (target == null) {
|
||||
// TODO(brianwilkerson) This is temporary support until we can get targets
|
||||
// for all nodes.
|
||||
return '';
|
||||
}
|
||||
return pathMapper!
|
||||
.map(pathContext.relative(target.filePath, from: unitDir));
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -242,7 +242,6 @@ class UnitRenderer {
|
|||
case RegionType.informative:
|
||||
return 'informative-region';
|
||||
}
|
||||
throw StateError('Unexpected RegionType $type');
|
||||
}
|
||||
|
||||
var previousOffset = 0;
|
||||
|
@ -312,10 +311,8 @@ class UnitRenderer {
|
|||
'source)';
|
||||
case NullabilityFixKind.conditionTrueInStrongMode:
|
||||
return '$count condition$s will be true in strong checking mode';
|
||||
break;
|
||||
case NullabilityFixKind.conditionFalseInStrongMode:
|
||||
return '$count condition$s will be false in strong checking mode';
|
||||
break;
|
||||
case NullabilityFixKind.makeTypeNullable:
|
||||
return '$count type$s made nullable';
|
||||
case NullabilityFixKind.makeTypeNullableDueToHint:
|
||||
|
@ -341,7 +338,6 @@ class UnitRenderer {
|
|||
case NullabilityFixKind.typeNotMadeNullableDueToHint:
|
||||
return '$count type$s not made nullable due to hint$s';
|
||||
}
|
||||
throw StateError('Null kind');
|
||||
}
|
||||
|
||||
/// Returns the URL that will navigate to the given [target] in the file at
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
// 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 'package:meta/meta.dart';
|
||||
import 'package:nnbd_migration/src/hint_action.dart';
|
||||
|
||||
/// Information about what should be populated into the "Edit Details" view of
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// 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 'package:meta/meta.dart';
|
||||
|
||||
/// Information about an item that should show up in the "proposed edits" panel.
|
||||
class EditListItem {
|
||||
/// Line number of this edit.
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// 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 'package:meta/meta.dart';
|
||||
|
||||
class NavigationTreeDirectoryNode extends NavigationTreeNode {
|
||||
/// If this is a directory node, list of nodes nested under this one.
|
||||
/// Otherwise `null`.
|
||||
|
|
|
@ -64,8 +64,5 @@ extension HintActionKindBehaviors on HintActionKind {
|
|||
case HintActionKind.changeToNonNullableHint:
|
||||
return 'Change to /*!*/ hint';
|
||||
}
|
||||
|
||||
assert(false);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -215,15 +215,12 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
|
|||
var target = NullabilityNodeTarget.element(declaredElement, _getLineInfo);
|
||||
DecoratedType? type =
|
||||
_pushNullabilityNodeTarget(target, () => node.type?.accept(this));
|
||||
if (node.identifier != null) {
|
||||
if (type == null) {
|
||||
type = DecoratedType.forImplicitType(
|
||||
_typeProvider, declaredElement.type, _graph, target);
|
||||
instrumentation?.implicitType(source, node, type);
|
||||
}
|
||||
_variables!
|
||||
.recordDecoratedElementType(node.identifier.staticElement, type);
|
||||
if (type == null) {
|
||||
type = DecoratedType.forImplicitType(
|
||||
_typeProvider, declaredElement.type, _graph, target);
|
||||
instrumentation?.implicitType(source, node, type);
|
||||
}
|
||||
_variables!.recordDecoratedElementType(node.identifier.staticElement, type);
|
||||
return type;
|
||||
}
|
||||
|
||||
|
@ -510,7 +507,6 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
|
|||
|
||||
@override
|
||||
DecoratedType visitTypeAnnotation(TypeAnnotation node) {
|
||||
assert(node != null); // TODO(paulberry)
|
||||
var type = node.type!;
|
||||
var target = safeTarget.withCodeRef(node);
|
||||
if (type.isVoid || type.isDynamic) {
|
||||
|
|
|
@ -37,17 +37,14 @@ class SubprocessLauncher {
|
|||
/// From flutter:dev/tools/dartdoc.dart, modified.
|
||||
static Future<void> _printStream(Stream<List<int>> stream, Stdout output,
|
||||
{String prefix = '', Iterable<String> Function(String line)? filter}) {
|
||||
assert(prefix != null);
|
||||
filter ??= (line) => [line];
|
||||
return stream
|
||||
.transform(utf8.decoder)
|
||||
.transform(const LineSplitter())
|
||||
.expand(filter)
|
||||
.listen((String line) {
|
||||
if (line != null) {
|
||||
output.write('$prefix$line'.trim());
|
||||
output.write('\n');
|
||||
}
|
||||
output.write('$prefix$line'.trim());
|
||||
output.write('\n');
|
||||
}).asFuture();
|
||||
}
|
||||
|
||||
|
@ -140,16 +137,14 @@ class SubprocessLauncher {
|
|||
|
||||
stderr.write('$prefix+ ');
|
||||
if (workingDirectory != null) stderr.write('(cd "$workingDirectory" && ');
|
||||
if (environment != null) {
|
||||
stderr.write(environment.keys.map((String key) {
|
||||
if (environment![key]!.contains(quotables)) {
|
||||
return "$key='${environment[key]}'";
|
||||
} else {
|
||||
return '$key=${environment[key]}';
|
||||
}
|
||||
}).join(' '));
|
||||
stderr.write(' ');
|
||||
}
|
||||
stderr.write(environment.keys.map((String key) {
|
||||
if (environment![key]!.contains(quotables)) {
|
||||
return "$key='${environment[key]}'";
|
||||
} else {
|
||||
return '$key=${environment[key]}';
|
||||
}
|
||||
}).join(' '));
|
||||
stderr.write(' ');
|
||||
stderr.write('$executable');
|
||||
if (arguments.isNotEmpty) {
|
||||
for (String arg in arguments) {
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
import 'package:analyzer/dart/analysis/results.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:nnbd_migration/nnbd_migration.dart';
|
||||
import 'package:nnbd_migration/src/front_end/info_builder.dart';
|
||||
import 'package:nnbd_migration/src/front_end/migration_info.dart';
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
import 'package:analyzer/dart/analysis/results.dart';
|
||||
import 'package:analyzer/source/line_info.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:nnbd_migration/instrumentation.dart';
|
||||
import 'package:nnbd_migration/nnbd_migration.dart';
|
||||
import 'package:nnbd_migration/src/front_end/dartfix_listener.dart';
|
||||
|
@ -119,16 +118,12 @@ class NnbdMigrationTestBase extends AbstractAnalysisTest {
|
|||
void assertTraceEntry(UnitInfo unit, TraceEntryInfo entryInfo,
|
||||
String function, int offset, Object descriptionMatcher,
|
||||
{Set<HintActionKind>? hintActions}) {
|
||||
if (offset == null) {
|
||||
expect(entryInfo.target, isNull);
|
||||
} else {
|
||||
assert(offset >= 0);
|
||||
var lineInfo = LineInfo.fromContent(unit.content!);
|
||||
var expectedLocation = lineInfo.getLocation(offset);
|
||||
expect(entryInfo.target!.filePath, unit.path);
|
||||
expect(entryInfo.target!.line, expectedLocation.lineNumber);
|
||||
expect(unit.offsetMapper.map(entryInfo.target!.offset), offset);
|
||||
}
|
||||
assert(offset >= 0);
|
||||
var lineInfo = LineInfo.fromContent(unit.content!);
|
||||
var expectedLocation = lineInfo.getLocation(offset);
|
||||
expect(entryInfo.target!.filePath, unit.path);
|
||||
expect(entryInfo.target!.line, expectedLocation.lineNumber);
|
||||
expect(unit.offsetMapper.map(entryInfo.target!.offset), offset);
|
||||
expect(entryInfo.function, function);
|
||||
expect(entryInfo.description, descriptionMatcher);
|
||||
if (hintActions != null) {
|
||||
|
|
|
@ -17,7 +17,6 @@ import 'package:analyzer/src/test_utilities/mock_sdk.dart' as mock_sdk;
|
|||
import 'package:args/args.dart';
|
||||
import 'package:cli_util/cli_logging.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:nnbd_migration/instrumentation.dart';
|
||||
import 'package:nnbd_migration/migration_cli.dart';
|
||||
import 'package:nnbd_migration/src/front_end/dartfix_listener.dart';
|
||||
|
|
|
@ -11,7 +11,6 @@ import 'package:analyzer/src/dart/element/type.dart';
|
|||
import 'package:analyzer/src/dart/element/type_system.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer/src/generated/utilities_dart.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:nnbd_migration/instrumentation.dart';
|
||||
import 'package:nnbd_migration/src/conditional_discard.dart';
|
||||
import 'package:nnbd_migration/src/decorated_class_hierarchy.dart';
|
||||
|
|
|
@ -12,7 +12,6 @@ import 'dart:math' as math;
|
|||
|
||||
import 'package:args/args.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
void main(List<String> args) async {
|
||||
|
|
|
@ -12,7 +12,7 @@ import 'package:path/path.dart' as path;
|
|||
/// Return a resolved path including the home directory in place of tilde
|
||||
/// references.
|
||||
String resolveTildePath(String originalPath) {
|
||||
if (originalPath == null || !originalPath.startsWith('~/')) {
|
||||
if (!originalPath.startsWith('~/')) {
|
||||
return originalPath;
|
||||
}
|
||||
|
||||
|
@ -183,9 +183,6 @@ class SdkPackage extends Package {
|
|||
_packagePath = potentialPath;
|
||||
}
|
||||
}
|
||||
if (_packagePath == null) {
|
||||
throw ArgumentError('Package $name not found in SDK');
|
||||
}
|
||||
}
|
||||
|
||||
late final String _packagePath;
|
||||
|
|
Loading…
Reference in a new issue