Version 2.13.0-200.0.dev
Merge commit '99814617b066ba8d1578946b8b7d18430a268a7a' into 'dev'
diff --git a/pkg/analysis_server/lib/src/computer/computer_closingLabels.dart b/pkg/analysis_server/lib/src/computer/computer_closingLabels.dart
index 6c4c5ed..856e20d 100644
--- a/pkg/analysis_server/lib/src/computer/computer_closingLabels.dart
+++ b/pkg/analysis_server/lib/src/computer/computer_closingLabels.dart
@@ -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.
-// @dart = 2.9
-
import 'package:analysis_server/protocol/protocol_generated.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
@@ -48,23 +46,21 @@
_DartUnitClosingLabelsComputerVisitor(this.computer);
- ClosingLabel get _currentLabel => labelStack.isEmpty ? null : labelStack.last;
+ ClosingLabel? get _currentLabel =>
+ labelStack.isEmpty ? null : labelStack.last;
@override
void visitInstanceCreationExpression(InstanceCreationExpression node) {
- ClosingLabel label;
-
- if (node.argumentList != null) {
- var labelText = node.constructorName.type.name.name;
- if (node.constructorName.name != null) {
- labelText += '.${node.constructorName.name.name}';
- }
- // We override the node used for doing line calculations because otherwise
- // constructors that split over multiple lines (but have parens on same
- // line) would incorrectly get labels, because node.start on an instance
- // creation expression starts at the start of the expression.
- label = _addLabel(node, labelText, checkLinesUsing: node.argumentList);
+ var labelText = node.constructorName.type.name.name;
+ var name = node.constructorName.name;
+ if (name != null) {
+ labelText += '.${name.name}';
}
+ // We override the node used for doing line calculations because otherwise
+ // constructors that split over multiple lines (but have parens on same
+ // line) would incorrectly get labels, because node.start on an instance
+ // creation expression starts at the start of the expression.
+ var label = _addLabel(node, labelText, checkLinesUsing: node.argumentList);
if (label != null) _pushLabel(label);
@@ -78,9 +74,9 @@
@override
void visitListLiteral(ListLiteral node) {
var args = node.typeArguments?.arguments;
- var typeName = args != null ? args[0]?.toString() : null;
+ var typeName = args != null ? args[0].toString() : null;
- ClosingLabel label;
+ ClosingLabel? label;
if (typeName != null) {
label = _addLabel(node, '<$typeName>[]');
@@ -105,8 +101,8 @@
}
}
- ClosingLabel _addLabel(AstNode node, String label,
- {AstNode checkLinesUsing}) {
+ ClosingLabel? _addLabel(AstNode node, String label,
+ {AstNode? checkLinesUsing}) {
// Never add labels if we're inside strings.
if (interpolatedStringsEntered > 0) {
return null;
@@ -114,10 +110,8 @@
checkLinesUsing = checkLinesUsing ?? node;
- final CharacterLocation start =
- computer._lineInfo.getLocation(checkLinesUsing.offset);
- final CharacterLocation end =
- computer._lineInfo.getLocation(checkLinesUsing.end - 1);
+ var start = computer._lineInfo.getLocation(checkLinesUsing.offset);
+ var end = computer._lineInfo.getLocation(checkLinesUsing.end - 1);
var closingLabel = ClosingLabel(node.offset, node.length, label);
diff --git a/pkg/analysis_server/lib/src/computer/computer_outline.dart b/pkg/analysis_server/lib/src/computer/computer_outline.dart
index 20e3278..fedd848 100644
--- a/pkg/analysis_server/lib/src/computer/computer_outline.dart
+++ b/pkg/analysis_server/lib/src/computer/computer_outline.dart
@@ -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.
-// @dart = 2.9
-
import 'package:analysis_server/src/collections.dart';
import 'package:analysis_server/src/utilities/flutter.dart';
import 'package:analyzer/dart/analysis/results.dart';
@@ -19,10 +17,19 @@
DartUnitOutlineComputer(this.resolvedUnit, {this.withBasicFlutter = false});
+ CompilationUnit get _unit {
+ var unit = resolvedUnit.unit;
+ if (unit == null) {
+ throw StateError('DartUnitOutlineComputer created with invalid result');
+ }
+ return unit;
+ }
+
/// Returns the computed outline, not `null`.
Outline compute() {
+ var unit = _unit;
var unitContents = <Outline>[];
- for (var unitMember in resolvedUnit.unit.declarations) {
+ for (var unitMember in unit.declarations) {
if (unitMember is ClassDeclaration) {
unitContents.add(_newClassOutline(
unitMember, _outlinesForMembers(unitMember.members)));
@@ -42,13 +49,11 @@
} else if (unitMember is TopLevelVariableDeclaration) {
var fieldDeclaration = unitMember;
var fields = fieldDeclaration.variables;
- if (fields != null) {
- var fieldType = fields.type;
- var fieldTypeName = _safeToSource(fieldType);
- for (var field in fields.variables) {
- unitContents.add(_newVariableOutline(
- fieldTypeName, ElementKind.TOP_LEVEL_VARIABLE, field, false));
- }
+ var fieldType = fields.type;
+ var fieldTypeName = _safeToSource(fieldType);
+ for (var field in fields.variables) {
+ unitContents.add(_newVariableOutline(
+ fieldTypeName, ElementKind.TOP_LEVEL_VARIABLE, field, false));
}
} else if (unitMember is FunctionDeclaration) {
var functionDeclaration = unitMember;
@@ -81,14 +86,18 @@
}
Location _getLocationOffsetLength(int offset, int length) {
+ var path = resolvedUnit.path;
+ if (path == null) {
+ throw StateError('DartUnitOutlineComputer called with invalid result');
+ }
var startLocation = resolvedUnit.lineInfo.getLocation(offset);
var startLine = startLocation.lineNumber;
var startColumn = startLocation.columnNumber;
var endLocation = resolvedUnit.lineInfo.getLocation(offset + length);
var endLine = endLocation.lineNumber;
var endColumn = endLocation.columnNumber;
- return Location(resolvedUnit.path, offset, length, startLine, startColumn,
- endLine, endColumn);
+ return Location(
+ path, offset, length, startLine, startColumn, endLine, endColumn);
}
Outline _newClassOutline(ClassDeclaration node, List<Outline> classContents) {
@@ -319,10 +328,11 @@
}
Outline _newUnitOutline(List<Outline> unitContents) {
+ var unit = _unit;
var element = Element(
ElementKind.COMPILATION_UNIT, '<unit>', Element.makeFlags(),
- location: _getLocationNode(resolvedUnit.unit));
- return _nodeOutline(resolvedUnit.unit, element, unitContents);
+ location: _getLocationNode(unit));
+ return _nodeOutline(unit, element, unitContents);
}
Outline _newVariableOutline(String typeName, ElementKind kind,
@@ -344,17 +354,20 @@
}
Outline _nodeOutline(AstNode node, Element element,
- [List<Outline> children]) {
+ [List<Outline>? children]) {
var offset = node.offset;
var end = node.end;
if (node is VariableDeclaration) {
var parent = node.parent;
- if (parent is VariableDeclarationList && parent.variables.isNotEmpty) {
+ var grandParent = parent?.parent;
+ if (grandParent != null &&
+ parent is VariableDeclarationList &&
+ parent.variables.isNotEmpty) {
if (parent.variables[0] == node) {
- offset = parent.parent.offset;
+ offset = grandParent.offset;
}
if (parent.variables.last == node) {
- end = parent.parent.end;
+ end = grandParent.end;
}
}
}
@@ -380,13 +393,11 @@
if (classMember is FieldDeclaration) {
var fieldDeclaration = classMember;
var fields = fieldDeclaration.fields;
- if (fields != null) {
- var fieldType = fields.type;
- var fieldTypeName = _safeToSource(fieldType);
- for (var field in fields.variables) {
- memberOutlines.add(_newVariableOutline(fieldTypeName,
- ElementKind.FIELD, field, fieldDeclaration.isStatic));
- }
+ var fieldType = fields.type;
+ var fieldTypeName = _safeToSource(fieldType);
+ for (var field in fields.variables) {
+ memberOutlines.add(_newVariableOutline(fieldTypeName,
+ ElementKind.FIELD, field, fieldDeclaration.isStatic));
}
}
if (classMember is MethodDeclaration) {
@@ -397,7 +408,7 @@
return memberOutlines;
}
- static String _getTypeParametersStr(TypeParameterList parameters) {
+ static String? _getTypeParametersStr(TypeParameterList? parameters) {
if (parameters == null) {
return null;
}
@@ -410,7 +421,7 @@
return element != null && element.hasDeprecated;
}
- static String _safeToSource(AstNode node) =>
+ static String _safeToSource(AstNode? node) =>
node == null ? '' : node.toSource();
}
@@ -425,7 +436,7 @@
/// Return `true` if the given [element] is the method 'group' defined in the
/// test package.
- bool isGroup(engine.ExecutableElement element) {
+ bool isGroup(engine.ExecutableElement? element) {
if (element != null && element.hasIsTestGroup) {
return true;
}
@@ -436,7 +447,7 @@
/// Return `true` if the given [element] is the method 'test' defined in the
/// test package.
- bool isTest(engine.ExecutableElement element) {
+ bool isTest(engine.ExecutableElement? element) {
if (element != null && element.hasIsTest) {
return true;
}
@@ -457,7 +468,9 @@
node.argumentList
.accept(_FunctionBodyOutlinesVisitor(outlineComputer, children));
- var text = _flutter.getWidgetPresentationText(node);
+ // The method `getWidgetPresentationText` should not return `null` when
+ // `isWidgetCreation` returns `true`.
+ var text = _flutter.getWidgetPresentationText(node) ?? '<unknown>';
var element = Element(ElementKind.CONSTRUCTOR_INVOCATION, text, 0,
location: outlineComputer._getLocationOffsetLength(node.offset, 0));
@@ -477,9 +490,8 @@
if (nameElement is! engine.ExecutableElement) {
return;
}
- engine.ExecutableElement executableElement = nameElement;
- String extractString(NodeList<Expression> arguments) {
+ String extractString(NodeList<Expression>? arguments) {
if (arguments != null && arguments.isNotEmpty) {
var argument = arguments[0];
if (argument is StringLiteral) {
@@ -493,9 +505,9 @@
return 'unnamed';
}
- void addOutlineNode(ElementKind kind, [List<Outline> children]) {
+ void addOutlineNode(ElementKind kind, [List<Outline>? children]) {
var executableName = nameNode.name;
- var description = extractString(node.argumentList?.arguments);
+ var description = extractString(node.argumentList.arguments);
var name = '$executableName("$description")';
var element = Element(kind, name, 0,
location: outlineComputer._getLocationNode(nameNode));
@@ -504,12 +516,12 @@
children: nullIfEmpty(children)));
}
- if (isGroup(executableElement)) {
+ if (isGroup(nameElement)) {
var groupContents = <Outline>[];
node.argumentList
.accept(_FunctionBodyOutlinesVisitor(outlineComputer, groupContents));
addOutlineNode(ElementKind.UNIT_TEST_GROUP, groupContents);
- } else if (isTest(executableElement)) {
+ } else if (isTest(nameElement)) {
addOutlineNode(ElementKind.UNIT_TEST_TEST);
} else {
super.visitMethodInvocation(node);
diff --git a/pkg/analysis_server/lib/src/computer/import_elements_computer.dart b/pkg/analysis_server/lib/src/computer/import_elements_computer.dart
index 59a251a..3a2ec51 100644
--- a/pkg/analysis_server/lib/src/computer/import_elements_computer.dart
+++ b/pkg/analysis_server/lib/src/computer/import_elements_computer.dart
@@ -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.
-// @dart = 2.9
-
import 'package:analysis_server/protocol/protocol_generated.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/ast/ast.dart';
@@ -33,19 +31,26 @@
/// imported into the library at the given [path].
Future<SourceChange> createEdits(
List<ImportedElements> importedElementsList) async {
+ var unit = libraryResult.unit;
+ var path = libraryResult.path;
+ if (unit == null || path == null) {
+ // We should never reach this point because the libraryResult should be
+ // valid.
+ return SourceChange('');
+ }
var filteredImportedElements =
_filterImportedElements(importedElementsList);
var libraryElement = libraryResult.libraryElement;
var uriConverter = libraryResult.session.uriConverter;
var existingImports = <ImportDirective>[];
- for (var directive in libraryResult.unit.directives) {
+ for (var directive in unit.directives) {
if (directive is ImportDirective) {
existingImports.add(directive);
}
}
var builder = ChangeBuilder(session: libraryResult.session);
- await builder.addDartFileEdit(libraryResult.path, (builder) {
+ await builder.addDartFileEdit(path, (builder) {
for (var importedElements in filteredImportedElements) {
var matchingImports =
_findMatchingImports(existingImports, importedElements);
@@ -90,8 +95,9 @@
//
// Apply the edits.
//
- for (var directive in updateMap.keys) {
- var update = updateMap[directive];
+ for (var entry in updateMap.entries) {
+ var directive = entry.key;
+ var update = entry.value;
var namesToUnhide = update.namesToUnhide;
var namesToShow = update.namesToShow;
namesToShow.sort();
@@ -129,12 +135,8 @@
var precedingNode = directive.prefix ??
directive.deferredKeyword ??
directive.uri;
- if (precedingNode == null) {
- builder.addDeletion(range.node(combinator));
- } else {
- builder.addDeletion(
- range.endEnd(precedingNode, combinator));
- }
+ builder
+ .addDeletion(range.endEnd(precedingNode, combinator));
}
} else {
builder.addDeletion(range.endEnd(
@@ -186,7 +188,7 @@
return false;
}
- ImportDirective preferredDirective;
+ late ImportDirective preferredDirective;
var bestEditCount = -1;
var deleteHide = false;
var addShow = false;
@@ -278,7 +280,12 @@
/// Partially copied from DartFileEditBuilderImpl.
_InsertionDescription _getInsertionDescription(String importUri) {
var unit = libraryResult.unit;
- LibraryDirective libraryDirective;
+ if (unit == null) {
+ // We should never reach this point because the libraryResult should be
+ // valid.
+ return _InsertionDescription(0, after: 2);
+ }
+ LibraryDirective? libraryDirective;
var importDirectives = <ImportDirective>[];
var otherDirectives = <Directive>[];
for (var directive in unit.directives) {
@@ -343,7 +350,11 @@
/// [importedElements]. They will match if they import the same library using
/// the same prefix.
bool _matches(ImportDirective import, ImportedElements importedElements) {
- var library = import.element.importedLibrary;
+ var importElement = import.element;
+ if (importElement == null) {
+ return false;
+ }
+ var library = importElement.importedLibrary;
return library != null &&
library.source.fullName == importedElements.path &&
(import.prefix?.name ?? '') == importedElements.prefix;
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/probability_range.dart b/pkg/analysis_server/lib/src/services/completion/dart/probability_range.dart
index 2c5de16..5b6d32e 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/probability_range.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/probability_range.dart
@@ -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.
-// @dart = 2.9
-
/// A range of probabilities that a given event has occurred.
class ProbabilityRange {
/// The lower bound of the range.
@@ -14,7 +12,7 @@
/// Initialize a newly created probability range to have the given [lower] and
/// [upper] bounds.
- const ProbabilityRange({this.lower, this.upper});
+ const ProbabilityRange({required this.lower, required this.upper});
/// The middle of the range.
double get middle => (upper + lower) / 2;
diff --git a/pkg/analysis_server/lib/src/services/correction/change_workspace.dart b/pkg/analysis_server/lib/src/services/correction/change_workspace.dart
index 579a614..c206924 100644
--- a/pkg/analysis_server/lib/src/services/correction/change_workspace.dart
+++ b/pkg/analysis_server/lib/src/services/correction/change_workspace.dart
@@ -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.
-// @dart = 2.9
-
import 'package:analyzer/dart/analysis/session.dart';
import 'package:analyzer_plugin/utilities/change_builder/change_workspace.dart';
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_missing_parameter.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_missing_parameter.dart
index 0d40bea..4d7c4db 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/add_missing_parameter.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/add_missing_parameter.dart
@@ -18,7 +18,8 @@
if (node.parent is! ArgumentList) {
return;
}
- var context = ExecutableParameters(sessionHelper, node.parent.parent);
+ var context =
+ ExecutableParameters.forInvocation(sessionHelper, node.parent.parent);
if (context == null) {
return;
}
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_missing_parameter_named.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_missing_parameter_named.dart
index e06b063..cc53b3f 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/add_missing_parameter_named.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/add_missing_parameter_named.dart
@@ -42,7 +42,8 @@
var argumentList = namedExpression.parent;
// Prepare the invoked element.
- var context = ExecutableParameters(sessionHelper, argumentList.parent);
+ var context =
+ ExecutableParameters.forInvocation(sessionHelper, argumentList.parent);
if (context == null) {
return;
}
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/change_argument_name.dart b/pkg/analysis_server/lib/src/services/correction/dart/change_argument_name.dart
index 32a7ec0..c7ff25f 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/change_argument_name.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/change_argument_name.dart
@@ -53,10 +53,8 @@
namedExpression is NamedExpression &&
namedExpression.name == node.parent &&
namedExpression.parent is ArgumentList) {
- var parameters = ExecutableParameters(
- sessionHelper,
- namedExpression.parent.parent,
- );
+ var parameters = ExecutableParameters.forInvocation(
+ sessionHelper, namedExpression.parent.parent);
return parameters?.namedNames;
}
return null;
diff --git a/pkg/analysis_server/lib/src/services/correction/executable_parameters.dart b/pkg/analysis_server/lib/src/services/correction/executable_parameters.dart
index 7fc7558..30c2497 100644
--- a/pkg/analysis_server/lib/src/services/correction/executable_parameters.dart
+++ b/pkg/analysis_server/lib/src/services/correction/executable_parameters.dart
@@ -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.
-// @dart = 2.9
-
import 'dart:core';
import 'package:analyzer/dart/ast/ast.dart';
@@ -19,26 +17,6 @@
final List<ParameterElement> optionalPositional = [];
final List<ParameterElement> named = [];
- factory ExecutableParameters(
- AnalysisSessionHelper sessionHelper, AstNode invocation) {
- Element element;
- // This doesn't handle FunctionExpressionInvocation.
- if (invocation is Annotation) {
- element = invocation.element;
- } else if (invocation is InstanceCreationExpression) {
- element = invocation.constructorName.staticElement;
- } else if (invocation is MethodInvocation) {
- element = invocation.methodName.staticElement;
- } else if (invocation is ConstructorReferenceNode) {
- element = invocation.staticElement;
- }
- if (element is ExecutableElement && !element.isSynthetic) {
- return ExecutableParameters._(sessionHelper, element);
- } else {
- return null;
- }
- }
-
ExecutableParameters._(this.sessionHelper, this.executable) {
for (var parameter in executable.parameters) {
if (parameter.isRequiredPositional) {
@@ -61,7 +39,7 @@
/// Return the [FormalParameterList] of the [executable], or `null` if it
/// can't be found.
- Future<FormalParameterList> getParameterList() async {
+ Future<FormalParameterList?> getParameterList() async {
var result = await sessionHelper.getElementDeclaration(executable);
var targetDeclaration = result?.node;
if (targetDeclaration is ConstructorDeclaration) {
@@ -77,7 +55,7 @@
/// Return the [FormalParameter] of the [element] in [FormalParameterList],
/// or `null` if it can't be found.
- Future<FormalParameter> getParameterNode(ParameterElement element) async {
+ Future<FormalParameter?> getParameterNode(ParameterElement element) async {
var result = await sessionHelper.getElementDeclaration(element);
var declaration = result?.node;
for (var node = declaration; node != null; node = node.parent) {
@@ -87,4 +65,24 @@
}
return null;
}
+
+ static ExecutableParameters? forInvocation(
+ AnalysisSessionHelper sessionHelper, AstNode invocation) {
+ Element? element;
+ // This doesn't handle FunctionExpressionInvocation.
+ if (invocation is Annotation) {
+ element = invocation.element;
+ } else if (invocation is InstanceCreationExpression) {
+ element = invocation.constructorName.staticElement;
+ } else if (invocation is MethodInvocation) {
+ element = invocation.methodName.staticElement;
+ } else if (invocation is ConstructorReferenceNode) {
+ element = invocation.staticElement;
+ }
+ if (element is ExecutableElement && !element.isSynthetic) {
+ return ExecutableParameters._(sessionHelper, element);
+ } else {
+ return null;
+ }
+ }
}
diff --git a/pkg/analysis_server/lib/src/services/correction/fix/dart/top_level_declarations.dart b/pkg/analysis_server/lib/src/services/correction/fix/dart/top_level_declarations.dart
index ecfca96..e53d57d 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix/dart/top_level_declarations.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix/dart/top_level_declarations.dart
@@ -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.
-// @dart = 2.9
-
import 'package:analyzer/dart/analysis/analysis_context.dart';
import 'package:analyzer/src/services/available_declarations.dart';
@@ -87,7 +85,7 @@
return declarations;
}
- TopLevelDeclarationKind _getTopKind(DeclarationKind kind) {
+ TopLevelDeclarationKind? _getTopKind(DeclarationKind kind) {
switch (kind) {
case DeclarationKind.CLASS:
case DeclarationKind.CLASS_TYPE_ALIAS:
@@ -95,18 +93,14 @@
case DeclarationKind.FUNCTION_TYPE_ALIAS:
case DeclarationKind.MIXIN:
return TopLevelDeclarationKind.type;
- break;
case DeclarationKind.EXTENSION:
return TopLevelDeclarationKind.extension;
- break;
case DeclarationKind.FUNCTION:
return TopLevelDeclarationKind.function;
- break;
case DeclarationKind.GETTER:
case DeclarationKind.SETTER:
case DeclarationKind.VARIABLE:
return TopLevelDeclarationKind.variable;
- break;
default:
return null;
}
diff --git a/pkg/analysis_server/lib/src/services/correction/fix/manifest/fix_generator.dart b/pkg/analysis_server/lib/src/services/correction/fix/manifest/fix_generator.dart
index b2d0854..1cc8e81 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix/manifest/fix_generator.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix/manifest/fix_generator.dart
@@ -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.
-// @dart = 2.9
-
import 'dart:math' as math;
import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
@@ -16,7 +14,6 @@
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
import 'package:html/dom.dart';
-import 'package:meta/meta.dart';
/// An object used to locate the HTML [Node] associated with a source range.
/// More specifically, it will return the deepest HTML [Node] which completely
@@ -33,7 +30,7 @@
///
/// If the [end] offset is not provided, then it is considered the same as the
/// [start] offset.
- HtmlNodeLocator({@required int start, int end})
+ HtmlNodeLocator({required int start, int? end})
: _startOffset = start,
_endOffset = end ?? start;
@@ -49,8 +46,10 @@
void _searchWithin(List<Node> path, Node node) {
var span = node.sourceSpan;
- if (span.start.offset > _endOffset || span.end.offset < _startOffset) {
- return;
+ if (span != null) {
+ if (span.start.offset > _endOffset || span.end.offset < _startOffset) {
+ return;
+ }
}
for (var element in node.children) {
_searchWithin(path, element);
@@ -79,7 +78,7 @@
final List<Fix> fixes = <Fix>[];
- List<Node> coveringNodePath;
+ // List<Node> coveringNodePath;
ManifestFixGenerator(this.error, this.content, this.document)
: errorOffset = error.offset,
@@ -92,12 +91,12 @@
/// Return the list of fixes that apply to the error being fixed.
Future<List<Fix>> computeFixes() async {
- var locator =
- HtmlNodeLocator(start: errorOffset, end: errorOffset + errorLength - 1);
- coveringNodePath = locator.searchWithin(document);
- if (coveringNodePath.isEmpty) {
- return fixes;
- }
+ // var locator =
+ // HtmlNodeLocator(start: errorOffset, end: errorOffset + errorLength - 1);
+ // coveringNodePath = locator.searchWithin(document);
+ // if (coveringNodePath.isEmpty) {
+ // return fixes;
+ // }
var errorCode = error.errorCode;
if (errorCode == ManifestWarningCode.UNSUPPORTED_CHROME_OS_HARDWARE) {
@@ -112,7 +111,7 @@
/// [kind]. If [args] are provided, they will be used to fill in the message
/// for the fix.
// ignore: unused_element
- void _addFixFromBuilder(ChangeBuilder builder, FixKind kind, {List args}) {
+ void _addFixFromBuilder(ChangeBuilder builder, FixKind kind, {List? args}) {
var change = builder.sourceChange;
if (change.edits.isEmpty) {
return;
@@ -131,9 +130,9 @@
// ignore: unused_element
SourceRange _lines(int start, int end) {
- CharacterLocation startLocation = lineInfo.getLocation(start);
+ var startLocation = lineInfo.getLocation(start);
var startOffset = lineInfo.getOffsetOfLine(startLocation.lineNumber - 1);
- CharacterLocation endLocation = lineInfo.getLocation(end);
+ var endLocation = lineInfo.getLocation(end);
var endOffset = lineInfo.getOffsetOfLine(
math.min(endLocation.lineNumber, lineInfo.lineCount - 1));
return SourceRange(startOffset, endOffset - startOffset);
diff --git a/pkg/analysis_server/lib/src/services/correction/fix/pubspec/fix_generator.dart b/pkg/analysis_server/lib/src/services/correction/fix/pubspec/fix_generator.dart
index 62130a9..f21a745 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix/pubspec/fix_generator.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix/pubspec/fix_generator.dart
@@ -2,13 +2,10 @@
// 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.
-// @dart = 2.9
-
import 'dart:math' as math;
import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
import 'package:analysis_server/src/utilities/strings.dart';
-import 'package:analysis_server/src/utilities/yaml_node_locator.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/source/line_info.dart';
import 'package:analyzer/src/generated/java_core.dart';
@@ -34,7 +31,7 @@
final List<Fix> fixes = <Fix>[];
- List<YamlNode> coveringNodePath;
+ // List<YamlNode> coveringNodePath;
PubspecFixGenerator(this.error, this.content, this.options)
: errorOffset = error.offset,
@@ -47,12 +44,12 @@
/// Return the list of fixes that apply to the error being fixed.
Future<List<Fix>> computeFixes() async {
- var locator =
- YamlNodeLocator(start: errorOffset, end: errorOffset + errorLength - 1);
- coveringNodePath = locator.searchWithin(options);
- if (coveringNodePath.isEmpty) {
- return fixes;
- }
+ // var locator =
+ // YamlNodeLocator(start: errorOffset, end: errorOffset + errorLength - 1);
+ // coveringNodePath = locator.searchWithin(options);
+ // if (coveringNodePath.isEmpty) {
+ // return fixes;
+ // }
var errorCode = error.errorCode;
if (errorCode == PubspecWarningCode.ASSET_DOES_NOT_EXIST) {
@@ -71,7 +68,7 @@
/// [kind]. If [args] are provided, they will be used to fill in the message
/// for the fix.
// ignore: unused_element
- void _addFixFromBuilder(ChangeBuilder builder, FixKind kind, {List args}) {
+ void _addFixFromBuilder(ChangeBuilder builder, FixKind kind, {List? args}) {
var change = builder.sourceChange;
if (change.edits.isEmpty) {
return;
@@ -90,9 +87,9 @@
// ignore: unused_element
SourceRange _lines(int start, int end) {
- CharacterLocation startLocation = lineInfo.getLocation(start);
+ var startLocation = lineInfo.getLocation(start);
var startOffset = lineInfo.getOffsetOfLine(startLocation.lineNumber - 1);
- CharacterLocation endLocation = lineInfo.getLocation(end);
+ var endLocation = lineInfo.getLocation(end);
var endOffset = lineInfo.getOffsetOfLine(
math.min(endLocation.lineNumber, lineInfo.lineCount - 1));
return SourceRange(startOffset, endOffset - startOffset);
diff --git a/pkg/analysis_server/lib/src/services/correction/levenshtein.dart b/pkg/analysis_server/lib/src/services/correction/levenshtein.dart
index 7146b2d..8f0e934 100644
--- a/pkg/analysis_server/lib/src/services/correction/levenshtein.dart
+++ b/pkg/analysis_server/lib/src/services/correction/levenshtein.dart
@@ -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.
-// @dart = 2.9
-
import 'dart:math' as math;
/// The value returned by [levenshtein] if the distance is determined
@@ -24,9 +22,6 @@
/// distance algorithm.
int levenshtein(String s, String t, int threshold,
{bool caseSensitive = true}) {
- if (s == null || t == null) {
- throw ArgumentError('Strings must not be null');
- }
if (threshold < 0) {
throw ArgumentError('Threshold must not be negative');
}
diff --git a/pkg/analysis_server/lib/src/services/correction/name_suggestion.dart b/pkg/analysis_server/lib/src/services/correction/name_suggestion.dart
index b52a410..f501ed0 100644
--- a/pkg/analysis_server/lib/src/services/correction/name_suggestion.dart
+++ b/pkg/analysis_server/lib/src/services/correction/name_suggestion.dart
@@ -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.
-// @dart = 2.9
-
import 'package:analysis_server/src/utilities/strings.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
@@ -27,17 +25,17 @@
/// Returns possible names for a variable with the given expected type and
/// expression assigned.
-List<String> getVariableNameSuggestionsForExpression(
- DartType expectedType, Expression assignedExpression, Set<String> excluded,
+List<String> getVariableNameSuggestionsForExpression(DartType? expectedType,
+ Expression? assignedExpression, Set<String> excluded,
{bool isMethod = false}) {
- String prefix;
+ String? prefix;
if (isMethod) {
// If we're in a build() method, use 'build' as the name prefix.
- var method = assignedExpression.thisOrAncestorOfType<MethodDeclaration>();
+ var method = assignedExpression?.thisOrAncestorOfType<MethodDeclaration>();
if (method != null) {
- var enclosingName = method.name?.name;
- if (enclosingName != null && enclosingName.startsWith('build')) {
+ var enclosingName = method.name.name;
+ if (enclosingName.startsWith('build')) {
prefix = 'build';
}
}
@@ -48,7 +46,9 @@
if (assignedExpression != null) {
var nameFromExpression = _getBaseNameFromExpression(assignedExpression);
if (nameFromExpression != null) {
- nameFromExpression = removeStart(nameFromExpression, '_');
+ if (nameFromExpression.startsWith('_')) {
+ nameFromExpression = nameFromExpression.substring(1);
+ }
_addAll(excluded, res, getCamelWordCombinations(nameFromExpression),
prefix: prefix);
}
@@ -95,7 +95,8 @@
for (var i = 0; i < words.length; i++) {
var word = words[i];
if (i > 0) {
- word = capitalize(word);
+ // `capitalize` won't return `null` unless `null` is passed in.
+ word = capitalize(word)!;
}
sb.write(word);
}
@@ -109,7 +110,7 @@
/// Adds [toAdd] items which are not excluded.
void _addAll(Set<String> excluded, Set<String> result, Iterable<String> toAdd,
- {String prefix}) {
+ {String? prefix}) {
for (var item in toAdd) {
// add name based on "item", but not "excluded"
for (var suffix = 1;; suffix++) {
@@ -141,7 +142,7 @@
}
}
-String _getBaseNameFromExpression(Expression expression) {
+String? _getBaseNameFromExpression(Expression expression) {
if (expression is AsExpression) {
return _getBaseNameFromExpression(expression.expression);
} else if (expression is ParenthesizedExpression) {
@@ -150,7 +151,7 @@
return _getBaseNameFromUnwrappedExpression(expression);
}
-String _getBaseNameFromLocationInParent(Expression expression) {
+String? _getBaseNameFromLocationInParent(Expression expression) {
// value in named expression
if (expression.parent is NamedExpression) {
var namedExpression = expression.parent as NamedExpression;
@@ -167,8 +168,8 @@
return null;
}
-String _getBaseNameFromUnwrappedExpression(Expression expression) {
- String name;
+String? _getBaseNameFromUnwrappedExpression(Expression expression) {
+ String? name;
// analyze expressions
if (expression is SimpleIdentifier) {
return expression.name;
@@ -181,22 +182,20 @@
} else if (expression is InstanceCreationExpression) {
var constructorName = expression.constructorName;
var typeName = constructorName.type;
- if (typeName != null) {
- var typeNameIdentifier = typeName.name;
- // new ClassName()
- if (typeNameIdentifier is SimpleIdentifier) {
- return typeNameIdentifier.name;
+ var typeNameIdentifier = typeName.name;
+ // new ClassName()
+ if (typeNameIdentifier is SimpleIdentifier) {
+ return typeNameIdentifier.name;
+ }
+ // new prefix.name();
+ if (typeNameIdentifier is PrefixedIdentifier) {
+ var prefixed = typeNameIdentifier;
+ // new prefix.ClassName()
+ if (prefixed.prefix.staticElement is PrefixElement) {
+ return prefixed.identifier.name;
}
- // new prefix.name();
- if (typeNameIdentifier is PrefixedIdentifier) {
- var prefixed = typeNameIdentifier;
- // new prefix.ClassName()
- if (prefixed.prefix.staticElement is PrefixElement) {
- return prefixed.identifier.name;
- }
- // new ClassName.constructorName()
- return prefixed.prefix.name;
- }
+ // new ClassName.constructorName()
+ return prefixed.prefix.name;
}
} else if (expression is IndexExpression) {
name = _getBaseNameFromExpression(expression.realTarget);
diff --git a/pkg/analysis_server/lib/src/services/correction/namespace.dart b/pkg/analysis_server/lib/src/services/correction/namespace.dart
index 98423a2..affc53d 100644
--- a/pkg/analysis_server/lib/src/services/correction/namespace.dart
+++ b/pkg/analysis_server/lib/src/services/correction/namespace.dart
@@ -2,35 +2,33 @@
// 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.
-// @dart = 2.9
-
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/src/dart/resolver/scope.dart';
/// Returns the [Element] exported from the given [LibraryElement].
-Element getExportedElement(LibraryElement library, String name) {
+Element? getExportedElement(LibraryElement? library, String name) {
if (library == null) {
return null;
}
- return getExportNamespaceForLibrary(library)[name];
-}
-
-/// Returns the export namespace of the given [LibraryElement].
-Map<String, Element> getExportNamespaceForLibrary(LibraryElement library) {
- var namespace = NamespaceBuilder().createExportNamespaceForLibrary(library);
- return namespace.definedNames;
+ return _getExportNamespaceForLibrary(library)[name];
}
/// Return the [ImportElement] that is referenced by [prefixNode], or `null` if
/// the node does not reference a prefix or if we cannot determine which import
/// is being referenced.
-ImportElement getImportElement(SimpleIdentifier prefixNode) {
+ImportElement? getImportElement(SimpleIdentifier prefixNode) {
var parent = prefixNode.parent;
if (parent is ImportDirective) {
return parent.element;
}
- return internal_getImportElementInfo(prefixNode);
+ return _getImportElementInfo(prefixNode);
+}
+
+/// Returns the export namespace of the given [LibraryElement].
+Map<String, Element> _getExportNamespaceForLibrary(LibraryElement library) {
+ var namespace = NamespaceBuilder().createExportNamespaceForLibrary(library);
+ return namespace.definedNames;
}
/// Return the [ImportElement] that declared [prefix] and imports [element].
@@ -39,21 +37,14 @@
/// [prefix] - the import prefix, maybe `null`.
/// [element] - the referenced element.
/// [importElementsMap] - the cache of [Element]s imported by [ImportElement]s.
-ImportElement internal_getImportElement(
- LibraryElement libraryElement,
- String prefix,
- Element element,
- Map<ImportElement, Set<Element>> importElementsMap) {
- // validate Element
- if (element == null) {
- return null;
- }
+ImportElement? _getImportElement(LibraryElement libraryElement, String prefix,
+ Element element, Map<ImportElement, Set<Element>> importElementsMap) {
if (element.enclosingElement is! CompilationUnitElement) {
return null;
}
var usedLibrary = element.library;
// find ImportElement that imports used library with used prefix
- List<ImportElement> candidates;
+ List<ImportElement>? candidates;
for (var importElement in libraryElement.imports) {
// required library
if (importElement.importedLibrary != usedLibrary) {
@@ -61,17 +52,11 @@
}
// required prefix
var prefixElement = importElement.prefix;
- if (prefix == null) {
- if (prefixElement != null) {
- continue;
- }
- } else {
- if (prefixElement == null) {
- continue;
- }
- if (prefix != prefixElement.name) {
- continue;
- }
+ if (prefixElement == null) {
+ continue;
+ }
+ if (prefix != prefixElement.name) {
+ continue;
}
// no combinators => only possible candidate
if (importElement.combinators.isEmpty) {
@@ -99,8 +84,9 @@
importElementsMap[importElement] = elements;
}
// use import namespace to choose correct one
- for (var importElement in importElementsMap.keys) {
- var elements = importElementsMap[importElement];
+ for (var entry in importElementsMap.entries) {
+ var importElement = entry.key;
+ var elements = entry.value;
if (elements.contains(element)) {
return importElement;
}
@@ -111,20 +97,22 @@
/// Returns the [ImportElement] that is referenced by [prefixNode] with a
/// [PrefixElement], maybe `null`.
-ImportElement internal_getImportElementInfo(SimpleIdentifier prefixNode) {
+ImportElement? _getImportElementInfo(SimpleIdentifier prefixNode) {
// prepare environment
var parent = prefixNode.parent;
var unit = prefixNode.thisOrAncestorOfType<CompilationUnit>();
- var libraryElement = unit.declaredElement.library;
+ var libraryElement = unit?.declaredElement?.library;
+ if (libraryElement == null) {
+ return null;
+ }
// prepare used element
- Element usedElement;
+ Element? usedElement;
if (parent is PrefixedIdentifier) {
var prefixed = parent;
if (prefixed.prefix == prefixNode) {
usedElement = prefixed.staticElement;
}
- }
- if (parent is MethodInvocation) {
+ } else if (parent is MethodInvocation) {
var invocation = parent;
if (invocation.target == prefixNode) {
usedElement = invocation.methodName.staticElement;
@@ -137,6 +125,6 @@
// find ImportElement
var prefix = prefixNode.name;
var importElementsMap = <ImportElement, Set<Element>>{};
- return internal_getImportElement(
+ return _getImportElement(
libraryElement, prefix, usedElement, importElementsMap);
}
diff --git a/pkg/analysis_server/lib/src/services/correction/source_buffer.dart b/pkg/analysis_server/lib/src/services/correction/source_buffer.dart
index 55dcdc00..488743e 100644
--- a/pkg/analysis_server/lib/src/services/correction/source_buffer.dart
+++ b/pkg/analysis_server/lib/src/services/correction/source_buffer.dart
@@ -2,24 +2,23 @@
// 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.
-// @dart = 2.9
-
/// Helper for building Dart source with linked positions.
class SourceBuilder {
final String file;
final int offset;
final StringBuffer _buffer = StringBuffer();
- int _exitOffset;
+ int? _exitOffset;
SourceBuilder(this.file, this.offset);
/// Returns the exit offset, maybe `null` if not set.
- int get exitOffset {
- if (_exitOffset == null) {
+ int? get exitOffset {
+ var exitOffset = _exitOffset;
+ if (exitOffset == null) {
return null;
}
- return offset + _exitOffset;
+ return offset + exitOffset;
}
int get length => _buffer.length;
diff --git a/pkg/analysis_server/lib/src/services/kythe/schema.dart b/pkg/analysis_server/lib/src/services/kythe/schema.dart
index dfd091e..3016742 100644
--- a/pkg/analysis_server/lib/src/services/kythe/schema.dart
+++ b/pkg/analysis_server/lib/src/services/kythe/schema.dart
@@ -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.
-// @dart = 2.9
-
/// This file gathers constant strings from the Kythe Schema:
/// kythe.io/docs/schema/
diff --git a/pkg/analysis_server/lib/src/services/linter/lint_names.dart b/pkg/analysis_server/lib/src/services/linter/lint_names.dart
index cfaf553..cc4823f 100644
--- a/pkg/analysis_server/lib/src/services/linter/lint_names.dart
+++ b/pkg/analysis_server/lib/src/services/linter/lint_names.dart
@@ -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.
-// @dart = 2.9
-
/// An enumeration of lint names.
class LintNames {
static const String always_declare_return_types =
diff --git a/pkg/analysis_server/test/services/correction/levenshtein_test.dart b/pkg/analysis_server/test/services/correction/levenshtein_test.dart
index 24826fd..fb1f656 100644
--- a/pkg/analysis_server/test/services/correction/levenshtein_test.dart
+++ b/pkg/analysis_server/test/services/correction/levenshtein_test.dart
@@ -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.
-// @dart = 2.9
-
import 'package:analysis_server/src/services/correction/levenshtein.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -48,15 +46,6 @@
}, throwsArgumentError);
}
- void test_null() {
- expect(() {
- levenshtein('', null, 5);
- }, throwsArgumentError);
- expect(() {
- levenshtein(null, '', 5);
- }, throwsArgumentError);
- }
-
void test_same() {
expect(levenshtein('', '', 5), 0);
expect(levenshtein('test', 'test', 5), 0);
diff --git a/pkg/analysis_server/test/services/correction/name_suggestion_test.dart b/pkg/analysis_server/test/services/correction/name_suggestion_test.dart
index 7216dcd..243fd9b 100644
--- a/pkg/analysis_server/test/services/correction/name_suggestion_test.dart
+++ b/pkg/analysis_server/test/services/correction/name_suggestion_test.dart
@@ -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.
-// @dart = 2.9
-
import 'package:analysis_server/src/services/correction/name_suggestion.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
diff --git a/pkg/analysis_server/test/src/computer/closing_labels_computer_test.dart b/pkg/analysis_server/test/src/computer/closing_labels_computer_test.dart
index 47c1a01..c79006b 100644
--- a/pkg/analysis_server/test/src/computer/closing_labels_computer_test.dart
+++ b/pkg/analysis_server/test/src/computer/closing_labels_computer_test.dart
@@ -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.
-// @dart = 2.9
-
import 'package:analysis_server/protocol/protocol_generated.dart';
import 'package:analysis_server/src/computer/computer_closingLabels.dart';
import 'package:test/test.dart';
@@ -19,7 +17,7 @@
@reflectiveTest
class ClosingLabelsComputerTest extends AbstractContextTest {
- String sourcePath;
+ late String sourcePath;
@override
void setUp() {
@@ -366,7 +364,7 @@
/// Compares provided closing labels with expected
/// labels extracted from the comments in the provided content.
void _compareLabels(List<ClosingLabel> labels, String content,
- {int expectedLabelCount}) {
+ {int? expectedLabelCount}) {
// Require the test pass us the expected count to guard
// against expected annotations being mistyped and not
// extracted by the regex.
@@ -385,11 +383,11 @@
expectedLabels.forEach((m) {
var i = m.group(1);
// Find the end marker.
- var endMatch = RegExp('/\\*$i:(.+?)\\*/').firstMatch(content);
+ var endMatch = RegExp('/\\*$i:(.+?)\\*/').firstMatch(content)!;
var expectedStart = m.end;
var expectedLength = endMatch.start - expectedStart;
- var expectedLabel = endMatch.group(1);
+ var expectedLabel = endMatch.group(1)!;
expect(labels,
contains(ClosingLabel(expectedStart, expectedLength, expectedLabel)));
@@ -399,7 +397,7 @@
Future<List<ClosingLabel>> _computeElements(String sourceContent) async {
newFile(sourcePath, content: sourceContent);
var result = await session.getResolvedUnit(sourcePath);
- var computer = DartUnitClosingLabelsComputer(result.lineInfo, result.unit);
+ var computer = DartUnitClosingLabelsComputer(result.lineInfo, result.unit!);
return computer.compute();
}
}
diff --git a/pkg/analysis_server/test/src/computer/import_elements_computer_test.dart b/pkg/analysis_server/test/src/computer/import_elements_computer_test.dart
index cc30a93..19bb89e 100644
--- a/pkg/analysis_server/test/src/computer/import_elements_computer_test.dart
+++ b/pkg/analysis_server/test/src/computer/import_elements_computer_test.dart
@@ -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.
-// @dart = 2.9
-
import 'package:analysis_server/protocol/protocol_generated.dart';
import 'package:analysis_server/src/computer/import_elements_computer.dart';
import 'package:analyzer/src/test_utilities/package_config_file_builder.dart';
@@ -21,14 +19,14 @@
@reflectiveTest
class ImportElementsComputerTest extends AbstractContextTest {
- String path;
- String originalContent;
- ImportElementsComputer computer;
- SourceFileEdit sourceFileEdit;
+ late String path;
+ late String originalContent;
+ late ImportElementsComputer computer;
+ late SourceFileEdit? sourceFileEdit;
void assertChanges(String expectedContent) {
var resultCode =
- SourceEdit.applySequence(originalContent, sourceFileEdit.edits);
+ SourceEdit.applySequence(originalContent, sourceFileEdit!.edits);
expect(resultCode, expectedContent);
}
diff --git a/pkg/analysis_server/test/src/computer/outline_computer_test.dart b/pkg/analysis_server/test/src/computer/outline_computer_test.dart
index 191bade..08abb6d 100644
--- a/pkg/analysis_server/test/src/computer/outline_computer_test.dart
+++ b/pkg/analysis_server/test/src/computer/outline_computer_test.dart
@@ -2,11 +2,8 @@
// 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.
-// @dart = 2.9
-
import 'package:analysis_server/src/computer/computer_outline.dart';
import 'package:analyzer_plugin/protocol/protocol_common.dart';
-import 'package:meta/meta.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -21,8 +18,8 @@
class AbstractOutlineComputerTest extends AbstractContextTest
with WithNonFunctionTypeAliasesMixin {
- String testPath;
- String testCode;
+ late String testPath;
+ late String testCode;
@override
void setUp() {
@@ -70,10 +67,10 @@
Text('aaa')
Text('bbb')
''');
- var myWidget = unitOutline.children[0];
- var build = myWidget.children[0];
+ var myWidget = unitOutline.children![0];
+ var build = myWidget.children![0];
- var columnOutline = build.children[0];
+ var columnOutline = build.children![0];
{
var offset = testCode.indexOf('new Column');
var length = testCode.indexOf('; // Column') - offset;
@@ -85,7 +82,7 @@
}
{
- var textOutline = columnOutline.children[0];
+ var textOutline = columnOutline.children![0];
var text = "const Text('aaa')";
var offset = testCode.indexOf(text);
_expect(textOutline,
@@ -96,7 +93,7 @@
}
{
- var textOutline = columnOutline.children[1];
+ var textOutline = columnOutline.children![1];
var text = "const Text('bbb')";
var offset = testCode.indexOf(text);
_expect(textOutline,
@@ -108,13 +105,13 @@
}
void _expect(Outline outline,
- {@required String name,
- @required int elementOffset,
- @required int offset,
- @required int length}) {
+ {required String name,
+ required int elementOffset,
+ required int offset,
+ required int length}) {
var element = outline.element;
expect(element.name, name);
- expect(element.location.offset, elementOffset);
+ expect(element.location!.offset, elementOffset);
expect(outline.offset, offset);
expect(outline.length, length);
}
@@ -130,7 +127,7 @@
}
}
- for (var child in outline.children) {
+ for (var child in outline.children!) {
writeOutline(child, '');
}
return buffer.toString();
@@ -159,7 +156,7 @@
String fa(int pa) => null;
R fb<R, P>(P p) {}
''');
- var topOutlines = unitOutline.children;
+ var topOutlines = unitOutline.children!;
expect(topOutlines, hasLength(4));
// A
{
@@ -169,14 +166,14 @@
expect(element_A.name, 'A');
expect(element_A.typeParameters, '<K, V>');
{
- var location = element_A.location;
+ var location = element_A.location!;
expect(location.offset, testCode.indexOf('A<K, V> {'));
expect(location.length, 1);
}
expect(element_A.parameters, null);
expect(element_A.returnType, null);
// A children
- var outlines_A = outline_A.children;
+ var outlines_A = outline_A.children!;
expect(outlines_A, hasLength(11));
{
var outline = outlines_A[0];
@@ -208,7 +205,7 @@
expect(element.kind, ElementKind.CONSTRUCTOR);
expect(element.name, 'A');
{
- var location = element.location;
+ var location = element.location!;
expect(location.offset, testCode.indexOf('A(int i, String s);'));
expect(location.length, 'A'.length);
}
@@ -223,7 +220,7 @@
expect(element.kind, ElementKind.CONSTRUCTOR);
expect(element.name, 'A.name');
{
- var location = element.location;
+ var location = element.location!;
expect(location.offset, testCode.indexOf('name(num p);'));
expect(location.length, 'name'.length);
}
@@ -238,7 +235,7 @@
expect(element.kind, ElementKind.CONSTRUCTOR);
expect(element.name, 'A._privateName');
{
- var location = element.location;
+ var location = element.location!;
expect(location.offset, testCode.indexOf('_privateName(num p);'));
expect(location.length, '_privateName'.length);
}
@@ -253,7 +250,7 @@
expect(element.kind, ElementKind.METHOD);
expect(element.name, 'ma');
{
- var location = element.location;
+ var location = element.location!;
expect(location.offset, testCode.indexOf('ma(int pa) => null;'));
expect(location.length, 'ma'.length);
}
@@ -268,7 +265,7 @@
expect(element.kind, ElementKind.METHOD);
expect(element.name, '_mb');
{
- var location = element.location;
+ var location = element.location!;
expect(location.offset, testCode.indexOf('_mb(int pb);'));
expect(location.length, '_mb'.length);
}
@@ -283,7 +280,7 @@
expect(element.kind, ElementKind.METHOD);
expect(element.name, 'mc');
{
- var location = element.location;
+ var location = element.location!;
expect(location.offset, testCode.indexOf('mc<R, P>'));
expect(location.length, 'mc'.length);
}
@@ -299,7 +296,7 @@
expect(element.kind, ElementKind.GETTER);
expect(element.name, 'propA');
{
- var location = element.location;
+ var location = element.location!;
expect(location.offset, testCode.indexOf('propA => null;'));
expect(location.length, 'propA'.length);
}
@@ -312,7 +309,7 @@
expect(element.kind, ElementKind.SETTER);
expect(element.name, 'propB');
{
- var location = element.location;
+ var location = element.location!;
expect(location.offset, testCode.indexOf('propB(int v) {}'));
expect(location.length, 'propB'.length);
}
@@ -328,14 +325,14 @@
expect(element_B.name, 'B');
expect(element_B.typeParameters, isNull);
{
- var location = element_B.location;
+ var location = element_B.location!;
expect(location.offset, testCode.indexOf('B {'));
expect(location.length, 1);
}
expect(element_B.parameters, null);
expect(element_B.returnType, null);
// B children
- var outlines_B = outline_B.children;
+ var outlines_B = outline_B.children!;
expect(outlines_B, hasLength(1));
{
var outline = outlines_B[0];
@@ -343,7 +340,7 @@
expect(element.kind, ElementKind.CONSTRUCTOR);
expect(element.name, 'B');
{
- var location = element.location;
+ var location = element.location!;
expect(location.offset, testCode.indexOf('B(int p);'));
expect(location.length, 'B'.length);
}
@@ -357,7 +354,7 @@
expect(element.kind, ElementKind.FUNCTION);
expect(element.name, 'fa');
{
- var location = element.location;
+ var location = element.location!;
expect(location.offset, testCode.indexOf('fa(int pa)'));
expect(location.length, 'ma'.length);
}
@@ -372,7 +369,7 @@
expect(element.kind, ElementKind.FUNCTION);
expect(element.name, 'fb');
{
- var location = element.location;
+ var location = element.location!;
expect(location.offset, testCode.indexOf('fb<R, P>'));
expect(location.length, 'fb'.length);
}
@@ -390,7 +387,7 @@
A, B, C
}
''');
- var topOutlines = unitOutline.children;
+ var topOutlines = unitOutline.children!;
expect(topOutlines, hasLength(1));
// MyEnum
{
@@ -399,14 +396,14 @@
expect(element_MyEnum.kind, ElementKind.ENUM);
expect(element_MyEnum.name, 'MyEnum');
{
- var location = element_MyEnum.location;
+ var location = element_MyEnum.location!;
expect(location.offset, testCode.indexOf('MyEnum {'));
expect(location.length, 'MyEnum'.length);
}
expect(element_MyEnum.parameters, null);
expect(element_MyEnum.returnType, null);
// MyEnum children
- var outlines_MyEnum = outline_MyEnum.children;
+ var outlines_MyEnum = outline_MyEnum.children!;
expect(outlines_MyEnum, hasLength(3));
_isEnumConstant(outlines_MyEnum[0], 'A');
_isEnumConstant(outlines_MyEnum[1], 'B');
@@ -423,7 +420,7 @@
}
}
''');
- var topOutlines = unitOutline.children;
+ var topOutlines = unitOutline.children!;
expect(topOutlines, hasLength(1));
// MyExt
{
@@ -432,7 +429,7 @@
expect(element_MyExt.kind, ElementKind.EXTENSION);
expect(element_MyExt.name, 'MyExt');
{
- var location = element_MyExt.location;
+ var location = element_MyExt.location!;
expect(location.offset, testCode.indexOf('MyExt on'));
expect(location.length, 'MyExt'.length);
}
@@ -453,7 +450,7 @@
}
}
''');
- var topOutlines = unitOutline.children;
+ var topOutlines = unitOutline.children!;
expect(topOutlines, hasLength(1));
// MyExt
{
@@ -462,7 +459,7 @@
expect(element_MyExt.kind, ElementKind.EXTENSION);
expect(element_MyExt.name, '');
{
- var location = element_MyExt.location;
+ var location = element_MyExt.location!;
expect(location.offset, testCode.indexOf('String'));
expect(location.length, 'String'.length);
}
@@ -478,7 +475,7 @@
var unitOutline = await _computeOutline('''
typedef F = void Function();
''');
- var topOutlines = unitOutline.children;
+ var topOutlines = unitOutline.children!;
expect(topOutlines, hasLength(1));
// F
var outline_F = topOutlines[0];
@@ -486,7 +483,7 @@
expect(element_F.kind, ElementKind.FUNCTION_TYPE_ALIAS);
expect(element_F.name, 'F');
{
- var location = element_F.location;
+ var location = element_F.location!;
expect(location.offset, testCode.indexOf('F ='));
expect(location.length, 'F'.length);
}
@@ -500,7 +497,7 @@
var unitOutline = await _computeOutline('''
typedef F = Function();
''');
- var topOutlines = unitOutline.children;
+ var topOutlines = unitOutline.children!;
expect(topOutlines, hasLength(1));
// F
var outline_F = topOutlines[0];
@@ -508,7 +505,7 @@
expect(element_F.kind, ElementKind.FUNCTION_TYPE_ALIAS);
expect(element_F.name, 'F');
{
- var location = element_F.location;
+ var location = element_F.location!;
expect(location.offset, testCode.indexOf('F ='));
expect(location.length, 'F'.length);
}
@@ -522,7 +519,7 @@
var unitOutline = await _computeOutline('''
typedef F<T> = Map<int, T>;
''');
- var topOutlines = unitOutline.children;
+ var topOutlines = unitOutline.children!;
expect(topOutlines, hasLength(1));
// F
var outline_F = topOutlines[0];
@@ -530,7 +527,7 @@
expect(element_F.kind, ElementKind.TYPE_ALIAS);
expect(element_F.name, 'F');
{
- var location = element_F.location;
+ var location = element_F.location!;
expect(location.offset, testCode.indexOf('F<T> ='));
expect(location.length, 'F'.length);
}
@@ -561,7 +558,7 @@
}
''');
// unit
- var unit_children = outline.children;
+ var unit_children = outline.children!;
expect(unit_children, hasLength(3));
// main
var main_outline = unit_children[2];
@@ -571,7 +568,7 @@
offset: testCode.indexOf('main() {'),
parameters: '()',
returnType: 'void');
- var main_children = main_outline.children;
+ var main_children = main_outline.children!;
expect(main_children, hasLength(2));
// group1
var group1_outline = main_children[0];
@@ -580,7 +577,7 @@
length: 5,
name: 'group("group1")',
offset: testCode.indexOf("group('group1'"));
- var group1_children = group1_outline.children;
+ var group1_children = group1_outline.children!;
expect(group1_children, hasLength(2));
// group1_1
var group1_1_outline = group1_children[0];
@@ -589,7 +586,7 @@
length: 5,
name: 'group("group1_1")',
offset: testCode.indexOf("group('group1_1'"));
- var group1_1_children = group1_1_outline.children;
+ var group1_1_children = group1_1_outline.children!;
expect(group1_1_children, hasLength(2));
// test1_1_1
var test1_1_1_outline = group1_1_children[0];
@@ -614,7 +611,7 @@
length: 5,
name: 'group("group1_2")',
offset: testCode.indexOf("group('group1_2'"));
- var group1_2_children = group1_2_outline.children;
+ var group1_2_children = group1_2_outline.children!;
expect(group1_2_children, hasLength(1));
// test2_1
var test1_2_1_outline = group1_2_children[0];
@@ -631,7 +628,7 @@
length: 5,
name: 'group("group2")',
offset: testCode.indexOf("group('group2'"));
- var group2_children = group2_outline.children;
+ var group2_children = group2_outline.children!;
expect(group2_children, hasLength(2));
// test2_1
var test2_1_outline = group2_children[0];
@@ -707,7 +704,7 @@
}
''');
// unit
- var unit_children = outline.children;
+ var unit_children = outline.children!;
expect(unit_children, hasLength(3));
// main
var main_outline = unit_children[2];
@@ -717,7 +714,7 @@
offset: testCode.indexOf('main() {'),
parameters: '()',
returnType: 'void');
- var main_children = main_outline.children;
+ var main_children = main_outline.children!;
expect(main_children, hasLength(2));
// group1
var group1_outline = main_children[0];
@@ -726,7 +723,7 @@
length: 7,
name: 'myGroup("group1")',
offset: testCode.indexOf("myGroup('group1'"));
- var group1_children = group1_outline.children;
+ var group1_children = group1_outline.children!;
expect(group1_children, hasLength(2));
// group1_1
var group1_1_outline = group1_children[0];
@@ -735,7 +732,7 @@
length: 7,
name: 'myGroup("group1_1")',
offset: testCode.indexOf("myGroup('group1_1'"));
- var group1_1_children = group1_1_outline.children;
+ var group1_1_children = group1_1_outline.children!;
expect(group1_1_children, hasLength(2));
// test1_1_1
var test1_1_1_outline = group1_1_children[0];
@@ -760,7 +757,7 @@
length: 7,
name: 'myGroup("group1_2")',
offset: testCode.indexOf("myGroup('group1_2'"));
- var group1_2_children = group1_2_outline.children;
+ var group1_2_children = group1_2_outline.children!;
expect(group1_2_children, hasLength(1));
// test2_1
var test1_2_1_outline = group1_2_children[0];
@@ -777,7 +774,7 @@
length: 7,
name: 'myGroup("group2")',
offset: testCode.indexOf("myGroup('group2'"));
- var group2_children = group2_outline.children;
+ var group2_children = group2_outline.children!;
expect(group2_children, hasLength(2));
// test2_1
var test2_1_outline = group2_children[0];
@@ -814,7 +811,7 @@
}
}
''');
- var topOutlines = unitOutline.children;
+ var topOutlines = unitOutline.children!;
expect(topOutlines, hasLength(2));
// A
{
@@ -823,14 +820,14 @@
expect(element_A.kind, ElementKind.CLASS);
expect(element_A.name, 'A');
{
- var location = element_A.location;
+ var location = element_A.location!;
expect(location.offset, testCode.indexOf('A {'));
expect(location.length, 'A'.length);
}
expect(element_A.parameters, null);
expect(element_A.returnType, null);
// A children
- var outlines_A = outline_A.children;
+ var outlines_A = outline_A.children!;
expect(outlines_A, hasLength(2));
{
var constructorOutline = outlines_A[0];
@@ -838,14 +835,14 @@
expect(constructorElement.kind, ElementKind.CONSTRUCTOR);
expect(constructorElement.name, 'A');
{
- var location = constructorElement.location;
+ var location = constructorElement.location!;
expect(location.offset, testCode.indexOf('A() {'));
expect(location.length, 'A'.length);
}
expect(constructorElement.parameters, '()');
expect(constructorElement.returnType, isNull);
// local function
- var outlines_constructor = constructorOutline.children;
+ var outlines_constructor = constructorOutline.children!;
expect(outlines_constructor, hasLength(1));
{
var outline = outlines_constructor[0];
@@ -853,7 +850,7 @@
expect(element.kind, ElementKind.FUNCTION);
expect(element.name, 'local_A');
{
- var location = element.location;
+ var location = element.location!;
expect(location.offset, testCode.indexOf('local_A() {}'));
expect(location.length, 'local_A'.length);
}
@@ -867,14 +864,14 @@
expect(element_m.kind, ElementKind.METHOD);
expect(element_m.name, 'm');
{
- var location = element_m.location;
+ var location = element_m.location!;
expect(location.offset, testCode.indexOf('m() {'));
expect(location.length, 'm'.length);
}
expect(element_m.parameters, '()');
expect(element_m.returnType, '');
// local function
- var methodChildren = outline_m.children;
+ var methodChildren = outline_m.children!;
expect(methodChildren, hasLength(1));
{
var outline = methodChildren[0];
@@ -882,7 +879,7 @@
expect(element.kind, ElementKind.FUNCTION);
expect(element.name, 'local_m');
{
- var location = element.location;
+ var location = element.location!;
expect(location.offset, testCode.indexOf('local_m() {}'));
expect(location.length, 'local_m'.length);
}
@@ -898,14 +895,14 @@
expect(element_f.kind, ElementKind.FUNCTION);
expect(element_f.name, 'f');
{
- var location = element_f.location;
+ var location = element_f.location!;
expect(location.offset, testCode.indexOf('f() {'));
expect(location.length, 'f'.length);
}
expect(element_f.parameters, '()');
expect(element_f.returnType, '');
// f() children
- var outlines_f = outline_f.children;
+ var outlines_f = outline_f.children!;
expect(outlines_f, hasLength(2));
{
var outline_f1 = outlines_f[0];
@@ -913,7 +910,7 @@
expect(element_f1.kind, ElementKind.FUNCTION);
expect(element_f1.name, 'local_f1');
{
- var location = element_f1.location;
+ var location = element_f1.location!;
expect(location.offset, testCode.indexOf('local_f1(int i) {}'));
expect(location.length, 'local_f1'.length);
}
@@ -926,14 +923,14 @@
expect(element_f2.kind, ElementKind.FUNCTION);
expect(element_f2.name, 'local_f2');
{
- var location = element_f2.location;
+ var location = element_f2.location!;
expect(location.offset, testCode.indexOf('local_f2(String s) {'));
expect(location.length, 'local_f2'.length);
}
expect(element_f2.parameters, '(String s)');
expect(element_f2.returnType, '');
// local_f2() local function
- var outlines_f2 = outline_f2.children;
+ var outlines_f2 = outline_f2.children!;
expect(outlines_f2, hasLength(1));
{
var outline_f21 = outlines_f2[0];
@@ -941,7 +938,7 @@
expect(element_f21.kind, ElementKind.FUNCTION);
expect(element_f21.name, 'local_f21');
{
- var location = element_f21.location;
+ var location = element_f21.location!;
expect(location.offset, testCode.indexOf('local_f21(int p) {'));
expect(location.length, 'local_f21'.length);
}
@@ -960,7 +957,7 @@
set f(int g) {}
}
''');
- var topOutlines = unitOutline.children;
+ var topOutlines = unitOutline.children!;
expect(topOutlines, hasLength(1));
// M
{
@@ -970,14 +967,14 @@
expect(element_M.name, 'M');
expect(element_M.typeParameters, '<N>');
{
- var location = element_M.location;
+ var location = element_M.location!;
expect(location.offset, testCode.indexOf('M<N>'));
expect(location.length, 1);
}
expect(element_M.parameters, isNull);
expect(element_M.returnType, isNull);
// M children
- var outlines_M = outline_M.children;
+ var outlines_M = outline_M.children!;
expect(outlines_M, hasLength(3));
{
var outline = outlines_M[0];
@@ -985,7 +982,7 @@
expect(element.kind, ElementKind.METHOD);
expect(element.name, 'c');
{
- var location = element.location;
+ var location = element.location!;
expect(location.offset, testCode.indexOf('c(int d)'));
expect(location.length, 1);
}
@@ -1000,7 +997,7 @@
expect(element.kind, ElementKind.GETTER);
expect(element.name, 'e');
{
- var location = element.location;
+ var location = element.location!;
expect(location.offset, testCode.indexOf('e => null'));
expect(location.length, 1);
}
@@ -1013,7 +1010,7 @@
expect(element.kind, ElementKind.SETTER);
expect(element.name, 'f');
{
- var location = element.location;
+ var location = element.location!;
expect(location.offset, testCode.indexOf('f(int g)'));
expect(location.length, 1);
}
@@ -1034,7 +1031,7 @@
int fieldD;
}
''');
- var outlines = unitOutline.children[0].children;
+ var outlines = unitOutline.children![0].children!;
expect(outlines, hasLength(4));
// fieldA
@@ -1101,7 +1098,7 @@
class B {}
''');
- var topOutlines = unitOutline.children;
+ var topOutlines = unitOutline.children!;
expect(topOutlines, hasLength(2));
// A
@@ -1143,7 +1140,7 @@
int methodB() {}
}
''');
- var outlines = unitOutline.children[0].children;
+ var outlines = unitOutline.children![0].children!;
expect(outlines, hasLength(2));
// methodA
@@ -1189,7 +1186,7 @@
String get propA => null;
set propB(int v) {}
''');
- var topOutlines = unitOutline.children;
+ var topOutlines = unitOutline.children!;
expect(topOutlines, hasLength(11));
// FTA
{
@@ -1199,7 +1196,7 @@
expect(element.name, 'FTA');
expect(element.typeParameters, '<K, V>');
{
- var location = element.location;
+ var location = element.location!;
expect(location.offset, testCode.indexOf('FTA<K, V>('));
expect(location.length, 'FTA'.length);
}
@@ -1214,7 +1211,7 @@
expect(element.name, 'FTB');
expect(element.typeParameters, isNull);
{
- var location = element.location;
+ var location = element.location!;
expect(location.offset, testCode.indexOf('FTB('));
expect(location.length, 'FTB'.length);
}
@@ -1229,7 +1226,7 @@
expect(element.name, 'GTAF');
expect(element.typeParameters, '<T>');
{
- var location = element.location;
+ var location = element.location!;
expect(location.offset, testCode.indexOf('GTAF<T> ='));
expect(location.length, 'GTAF'.length);
}
@@ -1244,7 +1241,7 @@
expect(element.name, 'CTA');
expect(element.typeParameters, '<T>');
{
- var location = element.location;
+ var location = element.location!;
expect(location.offset, testCode.indexOf('CTA<T> ='));
expect(location.length, 'CTA'.length);
}
@@ -1267,7 +1264,7 @@
expect(element.kind, ElementKind.FUNCTION);
expect(element.name, 'fA');
{
- var location = element.location;
+ var location = element.location!;
expect(location.offset, testCode.indexOf('fA('));
expect(location.length, 'fA'.length);
}
@@ -1281,7 +1278,7 @@
expect(element.kind, ElementKind.FUNCTION);
expect(element.name, 'fB');
{
- var location = element.location;
+ var location = element.location!;
expect(location.offset, testCode.indexOf('fB('));
expect(location.length, 'fB'.length);
}
@@ -1295,7 +1292,7 @@
expect(element.kind, ElementKind.GETTER);
expect(element.name, 'propA');
{
- var location = element.location;
+ var location = element.location!;
expect(location.offset, testCode.indexOf('propA => null;'));
expect(location.length, 'propA'.length);
}
@@ -1309,7 +1306,7 @@
expect(element.kind, ElementKind.SETTER);
expect(element.name, 'propB');
{
- var location = element.location;
+ var location = element.location!;
expect(location.offset, testCode.indexOf('propB(int v) {}'));
expect(location.length, 'propB'.length);
}
@@ -1319,15 +1316,15 @@
}
void _expect(Outline outline,
- {ElementKind kind,
+ {ElementKind? kind,
bool leaf = false,
- int length,
- String name,
- int offset,
- String parameters,
- String returnType}) {
+ int? length,
+ String? name,
+ int? offset,
+ String? parameters,
+ String? returnType}) {
var element = outline.element;
- var location = element.location;
+ var location = element.location!;
if (kind != null) {
expect(element.kind, kind);
diff --git a/tools/VERSION b/tools/VERSION
index f94b5ca..5e77d8c 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
MAJOR 2
MINOR 13
PATCH 0
-PRERELEASE 199
+PRERELEASE 200
PRERELEASE_PATCH 0
\ No newline at end of file