Remove tests for the non-nullable feature from server

Change-Id: I79608f35ca03ff27714dcc15ae372a19066af724
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/349140
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Brian Wilkerson 2024-01-29 21:15:47 +00:00 committed by Commit Queue
parent 23aff1c23e
commit 4cd6c05544
12 changed files with 33 additions and 100 deletions

View file

@ -1968,8 +1968,7 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
if (node.externalKeyword == null) {
keywordHelper.addKeyword(Keyword.EXTERNAL);
}
if (variableDeclarationList.lateKeyword == null &&
featureSet.isEnabled(Feature.non_nullable)) {
if (variableDeclarationList.lateKeyword == null) {
keywordHelper.addKeyword(Keyword.LATE);
}
if (!variables.first.isConst) {

View file

@ -60,9 +60,7 @@ class KeywordHelper {
addKeyword(Keyword.STATIC);
addKeyword(Keyword.VAR);
addKeyword(Keyword.VOID);
if (featureSet.isEnabled(Feature.non_nullable)) {
addKeyword(Keyword.LATE);
}
addKeyword(Keyword.LATE);
}
/// Add the keywords that are appropriate when the selection is in a class
@ -149,9 +147,7 @@ class KeywordHelper {
if (featureSet.isEnabled(Feature.extension_methods)) {
addKeyword(Keyword.EXTENSION);
}
if (featureSet.isEnabled(Feature.non_nullable)) {
addKeyword(Keyword.LATE);
}
addKeyword(Keyword.LATE);
if (featureSet.isEnabled(Feature.class_modifiers)) {
addKeyword(Keyword.BASE);
addKeyword(Keyword.INTERFACE);
@ -380,9 +376,7 @@ class KeywordHelper {
keyword != Keyword.COVARIANT) {
addKeyword(Keyword.COVARIANT);
}
if (_isAbsentOrIn(fields.lateKeyword) &&
keyword != Keyword.LATE &&
featureSet.isEnabled(Feature.non_nullable)) {
if (_isAbsentOrIn(fields.lateKeyword) && keyword != Keyword.LATE) {
addKeyword(Keyword.LATE);
}
addKeyword(Keyword.STATIC);
@ -516,9 +510,7 @@ class KeywordHelper {
addKeyword(Keyword.STATIC);
addKeyword(Keyword.VAR);
addKeyword(Keyword.VOID);
if (featureSet.isEnabled(Feature.non_nullable)) {
addKeyword(Keyword.LATE);
}
addKeyword(Keyword.LATE);
}
/// Add the keywords that are appropriate when the selection is in a mixin
@ -585,9 +577,7 @@ class KeywordHelper {
addKeyword(Keyword.YIELD);
addKeywordFromText(Keyword.YIELD, '*');
}
if (featureSet.isEnabled(Feature.non_nullable)) {
addKeyword(Keyword.LATE);
}
addKeyword(Keyword.LATE);
}
/// Add the keywords that are appropriate when the selection is after the

View file

@ -17,7 +17,6 @@ import 'package:analysis_server/src/services/completion/dart/utilities.dart';
import 'package:analysis_server/src/utilities/extensions/ast.dart';
import 'package:analysis_server/src/utilities/extensions/element.dart';
import 'package:analysis_server/src/utilities/flutter.dart';
import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/dart/element/element.dart';
@ -1590,14 +1589,9 @@ class SuggestionBuilder {
var neverType = request.libraryElement.typeProvider.neverType;
typeArguments = List.filled(typeParameters.length, neverType);
}
var nullabilitySuffix = request.featureSet.isEnabled(Feature.non_nullable)
? NullabilitySuffix.none
: NullabilitySuffix.star;
return element.instantiate(
typeArguments: typeArguments,
nullabilitySuffix: nullabilitySuffix,
nullabilitySuffix: NullabilitySuffix.none,
);
}
@ -1608,14 +1602,9 @@ class SuggestionBuilder {
var neverType = request.libraryElement.typeProvider.neverType;
typeArguments = List.filled(typeParameters.length, neverType);
}
var nullabilitySuffix = request.featureSet.isEnabled(Feature.non_nullable)
? NullabilitySuffix.none
: NullabilitySuffix.star;
return element.instantiate(
typeArguments: typeArguments,
nullabilitySuffix: nullabilitySuffix,
nullabilitySuffix: NullabilitySuffix.none,
);
}

View file

@ -9,7 +9,6 @@ import 'package:analysis_server/plugin/edit/fix/fix_dart.dart';
import 'package:analysis_server/src/services/correction/util.dart';
import 'package:analysis_server/src/utilities/selection.dart';
import 'package:analyzer/dart/analysis/code_style_options.dart';
import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/analysis/session.dart';
import 'package:analyzer/dart/element/element.dart';
@ -168,9 +167,6 @@ class CorrectionProducerContext<UnitResult extends ParsedUnitResult> {
typeProvider =
unitResult is ResolvedUnitResult ? unitResult.typeProvider : null;
bool get isNonNullableByDefault =>
unit.featureSet.isEnabled(Feature.non_nullable);
static CorrectionProducerContext<ParsedUnitResult> createParsed({
required ParsedUnitResult resolvedResult,
required ChangeWorkspace workspace,
@ -593,7 +589,7 @@ abstract class _AbstractCorrectionProducer<T extends ParsedUnitResult> {
/// Return the text that should be displayed to users when referring to the
/// given [type].
String displayStringForType(DartType type) =>
type.getDisplayString(withNullability: _context.isNonNullableByDefault);
type.getDisplayString(withNullability: true);
CodeStyleOptions getCodeStyleOptions(File file) =>
sessionHelper.session.analysisContext

View file

@ -5,7 +5,6 @@
import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart';
import 'package:analysis_server/src/services/correction/fix.dart';
import 'package:analysis_server/src/utilities/flutter.dart';
import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/src/generated/error_verifier.dart';
@ -43,11 +42,9 @@ class AddFieldFormalParameters extends ResolvedCorrectionProducer {
if (Flutter.isExactlyStatelessWidgetType(superType) ||
Flutter.isExactlyStatefulWidgetType(superType)) {
if (parameters.isNotEmpty && parameters.last.isNamed) {
var isNullSafe =
libraryElement.featureSet.isEnabled(Feature.non_nullable);
String parameterForField(FieldElement field) {
var prefix = '';
if (isNullSafe && typeSystem.isPotentiallyNonNullable(field.type)) {
if (typeSystem.isPotentiallyNonNullable(field.type)) {
prefix = 'required ';
}
return '${prefix}this.${field.name}';

View file

@ -170,12 +170,9 @@ class AddKeyToConstructors extends ResolvedCorrectionProducer {
if (keyClass == null) {
return null;
}
var isNonNullable =
unitResult.libraryElement.featureSet.isEnabled(Feature.non_nullable);
return keyClass.instantiate(
typeArguments: const [],
nullabilitySuffix:
isNonNullable ? NullabilitySuffix.question : NullabilitySuffix.star,
nullabilitySuffix: NullabilitySuffix.question,
);
}

View file

@ -4,7 +4,6 @@
import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart';
import 'package:analysis_server/src/services/correction/fix.dart';
import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/nullability_suffix.dart';
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
@ -25,12 +24,10 @@ class AddNeNull extends CorrectionProducerWithDiagnostic {
@override
Future<void> compute(ChangeBuilder builder) async {
if (unit.featureSet.isEnabled(Feature.non_nullable)) {
final node = this.node;
if (node is Expression &&
node.staticType?.nullabilitySuffix == NullabilitySuffix.none) {
return;
}
final node = this.node;
if (node is Expression &&
node.staticType?.nullabilitySuffix == NullabilitySuffix.none) {
return;
}
var problemMessage = diagnostic.problemMessage;
await builder.addDartFileEdit(file, (builder) {

View file

@ -4,7 +4,6 @@
import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart';
import 'package:analysis_server/src/services/correction/fix.dart';
import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/precedence.dart';
import 'package:analyzer/dart/ast/token.dart';
@ -37,11 +36,6 @@ class AddNullCheck extends ResolvedCorrectionProducer {
@override
Future<void> compute(ChangeBuilder builder) async {
if (!unit.featureSet.isEnabled(Feature.non_nullable)) {
// Don't suggest a feature that isn't supported.
return;
}
Expression? target;
final coveredNode = this.coveredNode;
var coveredNodeParent = coveredNode?.parent;

View file

@ -37,10 +37,6 @@ class CreateConstructorForFinalFields extends ResolvedCorrectionProducer {
return null;
}
bool get _hasNonNullableFeature {
return unit.featureSet.isEnabled(Feature.non_nullable);
}
@override
Future<void> compute(ChangeBuilder builder) async {
final fieldDeclaration = _errorFieldDeclaration;
@ -188,9 +184,7 @@ class CreateConstructorForFinalFields extends ResolvedCorrectionProducer {
builder.writeType(
keyClass.instantiate(
typeArguments: const [],
nullabilitySuffix: _hasNonNullableFeature
? NullabilitySuffix.question
: NullabilitySuffix.star,
nullabilitySuffix: NullabilitySuffix.question,
),
);
builder.write(' key');
@ -362,7 +356,7 @@ class CreateConstructorForFinalFields extends ResolvedCorrectionProducer {
for (final field in childrenLast) {
builder.write(', ');
if (_hasNonNullableFeature && field.hasNonNullableType) {
if (field.hasNonNullableType) {
builder.write('required ');
}
builder.write('this.');

View file

@ -4,7 +4,6 @@
import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart';
import 'package:analysis_server/src/services/correction/fix.dart';
import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/src/dart/ast/extensions.dart';
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
@ -16,10 +15,6 @@ class MakeReturnTypeNullable extends ResolvedCorrectionProducer {
@override
Future<void> compute(ChangeBuilder builder) async {
if (!unit.featureSet.isEnabled(Feature.non_nullable)) {
return;
}
final node = this.node;
if (node is! Expression) {
return;

View file

@ -4,7 +4,6 @@
import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart';
import 'package:analysis_server/src/services/correction/fix.dart';
import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/dart/element/element.dart';
@ -29,23 +28,20 @@ class MakeVariableNullable extends ResolvedCorrectionProducer {
@override
Future<void> compute(ChangeBuilder builder) async {
final node = this.node;
if (unit.featureSet.isEnabled(Feature.non_nullable)) {
if (node is SimpleFormalParameter) {
await _forSimpleFormalParameter(builder, node);
} else if (node is FunctionTypedFormalParameter) {
await _forFunctionTypedFormalParameter(builder, node);
} else if (node is FieldFormalParameter) {
await _forFieldFormalParameter(builder, node);
} else if (node is SuperFormalParameter) {
await _forSuperFormalParameter(builder, node);
} else if (node is Expression) {
final parent = node.parent;
if (parent is AssignmentExpression && parent.rightHandSide == node) {
await _forAssignment(builder, node, parent);
} else if (parent is VariableDeclaration &&
parent.initializer == node) {
await _forVariableDeclaration(builder, node, parent);
}
if (node is SimpleFormalParameter) {
await _forSimpleFormalParameter(builder, node);
} else if (node is FunctionTypedFormalParameter) {
await _forFunctionTypedFormalParameter(builder, node);
} else if (node is FieldFormalParameter) {
await _forFieldFormalParameter(builder, node);
} else if (node is SuperFormalParameter) {
await _forSuperFormalParameter(builder, node);
} else if (node is Expression) {
final parent = node.parent;
if (parent is AssignmentExpression && parent.rightHandSide == node) {
await _forAssignment(builder, node, parent);
} else if (parent is VariableDeclaration && parent.initializer == node) {
await _forVariableDeclaration(builder, node, parent);
}
}
}

View file

@ -89,8 +89,6 @@ class ExtractWidgetRefactoringImpl extends RefactoringImpl
return resolveResult.unit.featureSet;
}
bool get _isNonNullable => _featureSet.isEnabled(Feature.non_nullable);
@override
Future<RefactoringStatus> checkFinalConditions() async {
var result = RefactoringStatus();
@ -427,9 +425,7 @@ class ExtractWidgetRefactoringImpl extends RefactoringImpl
'key',
type: classKey!.instantiate(
typeArguments: const [],
nullabilitySuffix: _isNonNullable
? NullabilitySuffix.question
: NullabilitySuffix.star,
nullabilitySuffix: NullabilitySuffix.question,
),
);
}
@ -437,14 +433,7 @@ class ExtractWidgetRefactoringImpl extends RefactoringImpl
// Add parameters for fields, local, and method parameters.
for (var parameter in _parameters) {
builder.write(' ');
if (_isNonNullable) {
builder.write('required');
} else {
builder.write('@');
builder.writeReference(accessorRequired!);
}
builder.write(' ');
builder.write(' required ');
if (parameter.constructorName != parameter.name) {
builder.writeType(parameter.type);
builder.write(' ');