mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 12:57:42 +00:00
Use named parameters for more AST implementations.
Change-Id: I710f37870699d728d1ea45bafee47b822418e1ed Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/253601 Commit-Queue: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
a4255f3246
commit
8e1224da23
|
@ -26,9 +26,9 @@ ExpressionStatement fixCascadeByParenthesizingTarget({
|
|||
);
|
||||
|
||||
return astFactory.expressionStatement(
|
||||
astFactory.cascadeExpression(
|
||||
newTarget,
|
||||
cascadeExpression.cascadeSections,
|
||||
CascadeExpressionImpl(
|
||||
target: newTarget,
|
||||
cascadeSections: cascadeExpression.cascadeSections,
|
||||
),
|
||||
expressionStatement.semicolon,
|
||||
);
|
||||
|
|
|
@ -1231,7 +1231,10 @@ class BooleanLiteralImpl extends LiteralImpl implements BooleanLiteral {
|
|||
bool value = false;
|
||||
|
||||
/// Initialize a newly created boolean literal.
|
||||
BooleanLiteralImpl(this.literal, this.value);
|
||||
BooleanLiteralImpl({
|
||||
required this.literal,
|
||||
required this.value,
|
||||
});
|
||||
|
||||
@override
|
||||
Token get beginToken => literal;
|
||||
|
@ -1288,7 +1291,11 @@ class BreakStatementImpl extends StatementImpl implements BreakStatement {
|
|||
|
||||
/// Initialize a newly created break statement. The [label] can be `null` if
|
||||
/// there is no label associated with the statement.
|
||||
BreakStatementImpl(this.breakKeyword, this._label, this.semicolon) {
|
||||
BreakStatementImpl({
|
||||
required this.breakKeyword,
|
||||
required SimpleIdentifierImpl? label,
|
||||
required this.semicolon,
|
||||
}) : _label = label {
|
||||
_becomeParentOf(_label);
|
||||
}
|
||||
|
||||
|
@ -1345,7 +1352,10 @@ class CascadeExpressionImpl extends ExpressionImpl
|
|||
|
||||
/// Initialize a newly created cascade expression. The list of
|
||||
/// [cascadeSections] must contain at least one element.
|
||||
CascadeExpressionImpl(this._target, List<Expression> cascadeSections) {
|
||||
CascadeExpressionImpl({
|
||||
required ExpressionImpl target,
|
||||
required List<Expression> cascadeSections,
|
||||
}) : _target = target {
|
||||
_becomeParentOf(_target);
|
||||
_cascadeSections._initialize(this, cascadeSections);
|
||||
}
|
||||
|
@ -1453,17 +1463,21 @@ class CatchClauseImpl extends AstNodeImpl implements CatchClause {
|
|||
/// [exceptionType] can be `null` if the clause will catch all exceptions. The
|
||||
/// [comma] and [_stackTraceParameter] can be `null` if the stack trace
|
||||
/// parameter is not defined.
|
||||
CatchClauseImpl(
|
||||
this.onKeyword,
|
||||
this._exceptionType,
|
||||
this.catchKeyword,
|
||||
this.leftParenthesis,
|
||||
this._exceptionParameter,
|
||||
this.comma,
|
||||
this._stackTraceParameter,
|
||||
this.rightParenthesis,
|
||||
this._body)
|
||||
: assert(onKeyword != null || catchKeyword != null) {
|
||||
CatchClauseImpl({
|
||||
required this.onKeyword,
|
||||
required TypeAnnotationImpl? exceptionType,
|
||||
required this.catchKeyword,
|
||||
required this.leftParenthesis,
|
||||
required CatchClauseParameterImpl? exceptionParameter,
|
||||
required this.comma,
|
||||
required CatchClauseParameterImpl? stackTraceParameter,
|
||||
required this.rightParenthesis,
|
||||
required BlockImpl body,
|
||||
}) : assert(onKeyword != null || catchKeyword != null),
|
||||
_exceptionType = exceptionType,
|
||||
_exceptionParameter = exceptionParameter,
|
||||
_stackTraceParameter = stackTraceParameter,
|
||||
_body = body {
|
||||
_becomeParentOf(_exceptionType);
|
||||
_becomeParentOf(_exceptionParameter);
|
||||
_becomeParentOf(_stackTraceParameter);
|
||||
|
@ -2124,7 +2138,11 @@ class CommentImpl extends AstNodeImpl implements Comment {
|
|||
/// least one token. The [_type] is the type of the comment. The list of
|
||||
/// [references] can be empty if the comment does not contain any embedded
|
||||
/// references.
|
||||
CommentImpl(this.tokens, this._type, List<CommentReference> references) {
|
||||
CommentImpl({
|
||||
required this.tokens,
|
||||
required CommentType type,
|
||||
required List<CommentReference> references,
|
||||
}) : _type = type {
|
||||
_references._initialize(this, references);
|
||||
}
|
||||
|
||||
|
@ -2160,23 +2178,42 @@ class CommentImpl extends AstNodeImpl implements Comment {
|
|||
}
|
||||
|
||||
/// Create a block comment consisting of the given [tokens].
|
||||
static CommentImpl createBlockComment(List<Token> tokens) =>
|
||||
CommentImpl(tokens, CommentType.BLOCK, const <CommentReference>[]);
|
||||
static CommentImpl createBlockComment(List<Token> tokens) {
|
||||
return CommentImpl(
|
||||
tokens: tokens,
|
||||
type: CommentType.BLOCK,
|
||||
references: const <CommentReference>[],
|
||||
);
|
||||
}
|
||||
|
||||
/// Create a documentation comment consisting of the given [tokens].
|
||||
static CommentImpl createDocumentationComment(List<Token> tokens) =>
|
||||
CommentImpl(
|
||||
tokens, CommentType.DOCUMENTATION, const <CommentReference>[]);
|
||||
static CommentImpl createDocumentationComment(List<Token> tokens) {
|
||||
return CommentImpl(
|
||||
tokens: tokens,
|
||||
type: CommentType.DOCUMENTATION,
|
||||
references: const <CommentReference>[],
|
||||
);
|
||||
}
|
||||
|
||||
/// Create a documentation comment consisting of the given [tokens] and having
|
||||
/// the given [references] embedded within it.
|
||||
static CommentImpl createDocumentationCommentWithReferences(
|
||||
List<Token> tokens, List<CommentReference> references) =>
|
||||
CommentImpl(tokens, CommentType.DOCUMENTATION, references);
|
||||
List<Token> tokens, List<CommentReference> references) {
|
||||
return CommentImpl(
|
||||
tokens: tokens,
|
||||
type: CommentType.DOCUMENTATION,
|
||||
references: references,
|
||||
);
|
||||
}
|
||||
|
||||
/// Create an end-of-line comment consisting of the given [tokens].
|
||||
static CommentImpl createEndOfLineComment(List<Token> tokens) =>
|
||||
CommentImpl(tokens, CommentType.END_OF_LINE, const <CommentReference>[]);
|
||||
static CommentImpl createEndOfLineComment(List<Token> tokens) {
|
||||
return CommentImpl(
|
||||
tokens: tokens,
|
||||
type: CommentType.END_OF_LINE,
|
||||
references: const <CommentReference>[],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class CommentReferableExpressionImpl extends ExpressionImpl
|
||||
|
@ -2197,7 +2234,10 @@ class CommentReferenceImpl extends AstNodeImpl implements CommentReference {
|
|||
|
||||
/// Initialize a newly created reference to a Dart element. The [newKeyword]
|
||||
/// can be `null` if the reference is not to a constructor.
|
||||
CommentReferenceImpl(this.newKeyword, this._expression) {
|
||||
CommentReferenceImpl({
|
||||
required this.newKeyword,
|
||||
required CommentReferableExpressionImpl expression,
|
||||
}) : _expression = expression {
|
||||
_becomeParentOf(_expression);
|
||||
}
|
||||
|
||||
|
@ -2483,8 +2523,15 @@ class ConditionalExpressionImpl extends ExpressionImpl
|
|||
ExpressionImpl _elseExpression;
|
||||
|
||||
/// Initialize a newly created conditional expression.
|
||||
ConditionalExpressionImpl(this._condition, this.question,
|
||||
this._thenExpression, this.colon, this._elseExpression) {
|
||||
ConditionalExpressionImpl({
|
||||
required ExpressionImpl condition,
|
||||
required this.question,
|
||||
required ExpressionImpl thenExpression,
|
||||
required this.colon,
|
||||
required ExpressionImpl elseExpression,
|
||||
}) : _condition = condition,
|
||||
_thenExpression = thenExpression,
|
||||
_elseExpression = elseExpression {
|
||||
_becomeParentOf(_condition);
|
||||
_becomeParentOf(_thenExpression);
|
||||
_becomeParentOf(_elseExpression);
|
||||
|
@ -2577,8 +2624,17 @@ class ConfigurationImpl extends AstNodeImpl implements Configuration {
|
|||
@override
|
||||
DirectiveUri? resolvedUri;
|
||||
|
||||
ConfigurationImpl(this.ifKeyword, this.leftParenthesis, this._name,
|
||||
this.equalToken, this._value, this.rightParenthesis, this._uri) {
|
||||
ConfigurationImpl({
|
||||
required this.ifKeyword,
|
||||
required this.leftParenthesis,
|
||||
required DottedNameImpl name,
|
||||
required this.equalToken,
|
||||
required StringLiteralImpl? value,
|
||||
required this.rightParenthesis,
|
||||
required StringLiteralImpl uri,
|
||||
}) : _name = name,
|
||||
_value = value,
|
||||
_uri = uri {
|
||||
_becomeParentOf(_name);
|
||||
_becomeParentOf(_value);
|
||||
_becomeParentOf(_uri);
|
||||
|
@ -2884,8 +2940,14 @@ class ConstructorFieldInitializerImpl extends ConstructorInitializerImpl
|
|||
/// Initialize a newly created field initializer to initialize the field with
|
||||
/// the given name to the value of the given expression. The [thisKeyword] and
|
||||
/// [period] can be `null` if the 'this' keyword was not specified.
|
||||
ConstructorFieldInitializerImpl(this.thisKeyword, this.period,
|
||||
this._fieldName, this.equals, this._expression) {
|
||||
ConstructorFieldInitializerImpl({
|
||||
required this.thisKeyword,
|
||||
required this.period,
|
||||
required SimpleIdentifierImpl fieldName,
|
||||
required this.equals,
|
||||
required ExpressionImpl expression,
|
||||
}) : _fieldName = fieldName,
|
||||
_expression = expression {
|
||||
_becomeParentOf(_fieldName);
|
||||
_becomeParentOf(_expression);
|
||||
}
|
||||
|
@ -2968,7 +3030,12 @@ class ConstructorNameImpl extends AstNodeImpl implements ConstructorName {
|
|||
|
||||
/// Initialize a newly created constructor name. The [period] and [name] can
|
||||
/// be`null` if the constructor being named is the unnamed constructor.
|
||||
ConstructorNameImpl(this._type, this.period, this._name) {
|
||||
ConstructorNameImpl({
|
||||
required NamedTypeImpl type,
|
||||
required this.period,
|
||||
required SimpleIdentifierImpl? name,
|
||||
}) : _type = type,
|
||||
_name = name {
|
||||
_becomeParentOf(_type);
|
||||
_becomeParentOf(_name);
|
||||
}
|
||||
|
@ -3028,7 +3095,9 @@ class ConstructorReferenceImpl extends CommentReferableExpressionImpl
|
|||
implements ConstructorReference {
|
||||
ConstructorNameImpl _constructorName;
|
||||
|
||||
ConstructorReferenceImpl(this._constructorName) {
|
||||
ConstructorReferenceImpl({
|
||||
required ConstructorNameImpl constructorName,
|
||||
}) : _constructorName = constructorName {
|
||||
_becomeParentOf(_constructorName);
|
||||
}
|
||||
|
||||
|
@ -3129,7 +3198,11 @@ class ContinueStatementImpl extends StatementImpl implements ContinueStatement {
|
|||
|
||||
/// Initialize a newly created continue statement. The [label] can be `null`
|
||||
/// if there is no label associated with the statement.
|
||||
ContinueStatementImpl(this.continueKeyword, this._label, this.semicolon) {
|
||||
ContinueStatementImpl({
|
||||
required this.continueKeyword,
|
||||
required SimpleIdentifierImpl? label,
|
||||
required this.semicolon,
|
||||
}) : _label = label {
|
||||
_becomeParentOf(_label);
|
||||
}
|
||||
|
||||
|
@ -3309,8 +3382,13 @@ class DefaultFormalParameterImpl extends FormalParameterImpl
|
|||
|
||||
/// Initialize a newly created default formal parameter. The [separator] and
|
||||
/// [defaultValue] can be `null` if there is no default value.
|
||||
DefaultFormalParameterImpl(
|
||||
this._parameter, this.kind, this.separator, this._defaultValue) {
|
||||
DefaultFormalParameterImpl({
|
||||
required NormalFormalParameterImpl parameter,
|
||||
required this.kind,
|
||||
required this.separator,
|
||||
required ExpressionImpl? defaultValue,
|
||||
}) : _parameter = parameter,
|
||||
_defaultValue = defaultValue {
|
||||
_becomeParentOf(_parameter);
|
||||
_becomeParentOf(_defaultValue);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import 'package:analyzer/dart/element/element.dart';
|
|||
import 'package:analyzer/dart/element/type.dart';
|
||||
import 'package:analyzer/source/line_info.dart';
|
||||
import 'package:analyzer/src/dart/ast/ast.dart';
|
||||
import 'package:analyzer/src/generated/utilities_dart.dart';
|
||||
|
||||
/// The instance of [AstFactoryImpl].
|
||||
final AstFactoryImpl astFactory = AstFactoryImpl();
|
||||
|
@ -18,23 +17,6 @@ class AstFactoryImpl {
|
|||
CommentImpl blockComment(List<Token> tokens) =>
|
||||
CommentImpl.createBlockComment(tokens);
|
||||
|
||||
BooleanLiteralImpl booleanLiteral(Token literal, bool value) =>
|
||||
BooleanLiteralImpl(literal, value);
|
||||
|
||||
BreakStatementImpl breakStatement(
|
||||
Token breakKeyword, SimpleIdentifier? label, Token semicolon) =>
|
||||
BreakStatementImpl(
|
||||
breakKeyword, label as SimpleIdentifierImpl?, semicolon);
|
||||
|
||||
CascadeExpressionImpl cascadeExpression(
|
||||
Expression target, List<Expression> cascadeSections) =>
|
||||
CascadeExpressionImpl(target as ExpressionImpl, cascadeSections);
|
||||
|
||||
CommentReferenceImpl commentReference(
|
||||
Token? newKeyword, CommentReferableExpression expression) =>
|
||||
CommentReferenceImpl(
|
||||
newKeyword, expression as CommentReferableExpressionImpl);
|
||||
|
||||
CompilationUnitImpl compilationUnit(
|
||||
{required Token beginToken,
|
||||
ScriptTag? scriptTag,
|
||||
|
@ -50,71 +32,6 @@ class AstFactoryImpl {
|
|||
CompilationUnitImpl(beginToken, scriptTag as ScriptTagImpl?, directives,
|
||||
declarations, endToken, featureSet, lineInfo ?? LineInfo([0]));
|
||||
|
||||
ConditionalExpressionImpl conditionalExpression(
|
||||
Expression condition,
|
||||
Token question,
|
||||
Expression thenExpression,
|
||||
Token colon,
|
||||
Expression elseExpression) =>
|
||||
ConditionalExpressionImpl(
|
||||
condition as ExpressionImpl,
|
||||
question,
|
||||
thenExpression as ExpressionImpl,
|
||||
colon,
|
||||
elseExpression as ExpressionImpl);
|
||||
|
||||
ConfigurationImpl configuration(
|
||||
Token ifKeyword,
|
||||
Token leftParenthesis,
|
||||
DottedName name,
|
||||
Token? equalToken,
|
||||
StringLiteral? value,
|
||||
Token rightParenthesis,
|
||||
StringLiteral libraryUri) =>
|
||||
ConfigurationImpl(
|
||||
ifKeyword,
|
||||
leftParenthesis,
|
||||
name as DottedNameImpl,
|
||||
equalToken,
|
||||
value as StringLiteralImpl?,
|
||||
rightParenthesis,
|
||||
libraryUri as StringLiteralImpl);
|
||||
|
||||
ConstructorFieldInitializerImpl constructorFieldInitializer(
|
||||
Token? thisKeyword,
|
||||
Token? period,
|
||||
SimpleIdentifier fieldName,
|
||||
Token equals,
|
||||
Expression expression) =>
|
||||
ConstructorFieldInitializerImpl(
|
||||
thisKeyword,
|
||||
period,
|
||||
fieldName as SimpleIdentifierImpl,
|
||||
equals,
|
||||
expression as ExpressionImpl);
|
||||
|
||||
ConstructorNameImpl constructorName(
|
||||
NamedType type, Token? period, SimpleIdentifier? name) =>
|
||||
ConstructorNameImpl(
|
||||
type as NamedTypeImpl, period, name as SimpleIdentifierImpl?);
|
||||
|
||||
ConstructorReferenceImpl constructorReference(
|
||||
{required ConstructorName constructorName}) =>
|
||||
ConstructorReferenceImpl(constructorName as ConstructorNameImpl);
|
||||
|
||||
ContinueStatementImpl continueStatement(
|
||||
Token continueKeyword, SimpleIdentifier? label, Token semicolon) =>
|
||||
ContinueStatementImpl(
|
||||
continueKeyword, label as SimpleIdentifierImpl?, semicolon);
|
||||
|
||||
DefaultFormalParameterImpl defaultFormalParameter(
|
||||
NormalFormalParameter parameter,
|
||||
ParameterKind kind,
|
||||
Token? separator,
|
||||
Expression? defaultValue) =>
|
||||
DefaultFormalParameterImpl(parameter as NormalFormalParameterImpl, kind,
|
||||
separator, defaultValue as ExpressionImpl?);
|
||||
|
||||
CommentImpl documentationComment(List<Token> tokens,
|
||||
[List<CommentReference>? references]) =>
|
||||
CommentImpl.createDocumentationCommentWithReferences(
|
||||
|
|
|
@ -97,8 +97,8 @@ class AstRewriter {
|
|||
|
||||
/// Possibly rewrites [node] as an [ExtensionOverride] or as an
|
||||
/// [InstanceCreationExpression].
|
||||
AstNode methodInvocation(Scope nameScope, MethodInvocation node) {
|
||||
SimpleIdentifier methodName = node.methodName;
|
||||
AstNode methodInvocation(Scope nameScope, MethodInvocationImpl node) {
|
||||
final methodName = node.methodName;
|
||||
if (methodName.isSynthetic) {
|
||||
// This isn't a constructor invocation because the method name is
|
||||
// synthetic.
|
||||
|
@ -132,7 +132,7 @@ class AstRewriter {
|
|||
typeIdentifier: methodName,
|
||||
);
|
||||
}
|
||||
} else if (target is SimpleIdentifier) {
|
||||
} else if (target is SimpleIdentifierImpl) {
|
||||
// Possible cases: C.n(), p.C() or p.C<>()
|
||||
if (node.isNullAware) {
|
||||
// This isn't a constructor invocation because a null aware operator is
|
||||
|
@ -224,19 +224,19 @@ class AstRewriter {
|
|||
/// [PrefixedIdentifier] with 'prefix' of `List` and 'identifier' of `filled`.
|
||||
/// The [PrefixedIdentifier] may need to be rewritten as a
|
||||
/// [ConstructorReference].
|
||||
AstNode prefixedIdentifier(Scope nameScope, PrefixedIdentifier node) {
|
||||
AstNode prefixedIdentifier(Scope nameScope, PrefixedIdentifierImpl node) {
|
||||
var parent = node.parent;
|
||||
if (parent is Annotation) {
|
||||
// An annotations which is a const constructor invocation can initially be
|
||||
// represented with a [PrefixedIdentifier]. Do not rewrite such nodes.
|
||||
return node;
|
||||
}
|
||||
if (parent is CommentReference) {
|
||||
if (parent is CommentReferenceImpl) {
|
||||
// TODO(srawlins): This probably should be allowed to be rewritten to a
|
||||
// [ConstructorReference] at some point.
|
||||
return node;
|
||||
}
|
||||
if (parent is AssignmentExpression && parent.leftHandSide == node) {
|
||||
if (parent is AssignmentExpressionImpl && parent.leftHandSide == node) {
|
||||
// A constructor cannot be assigned to, in some expression like
|
||||
// `C.new = foo`; do not rewrite.
|
||||
return node;
|
||||
|
@ -275,29 +275,29 @@ class AstRewriter {
|
|||
/// 'prefix' of `List` and 'identifier' of `filled`) and a 'propertyName' of
|
||||
/// `value`. The [PropertyAccess] may need to be rewritten as a
|
||||
/// [ConstructorReference].
|
||||
AstNode propertyAccess(Scope nameScope, PropertyAccess node) {
|
||||
AstNode propertyAccess(Scope nameScope, PropertyAccessImpl node) {
|
||||
if (node.isCascaded) {
|
||||
// For example, `List..filled`: this is a property access on an instance
|
||||
// `Type`.
|
||||
return node;
|
||||
}
|
||||
if (node.parent is CommentReference) {
|
||||
if (node.parent is CommentReferenceImpl) {
|
||||
// TODO(srawlins): This probably should be allowed to be rewritten to a
|
||||
// [ConstructorReference] at some point.
|
||||
return node;
|
||||
}
|
||||
var receiver = node.target!;
|
||||
|
||||
Identifier receiverIdentifier;
|
||||
TypeArgumentList? typeArguments;
|
||||
if (receiver is PrefixedIdentifier) {
|
||||
IdentifierImpl receiverIdentifier;
|
||||
TypeArgumentListImpl? typeArguments;
|
||||
if (receiver is PrefixedIdentifierImpl) {
|
||||
receiverIdentifier = receiver;
|
||||
} else if (receiver is FunctionReference) {
|
||||
} else if (receiver is FunctionReferenceImpl) {
|
||||
// A [ConstructorReference] with explicit type arguments is initially
|
||||
// parsed as a [PropertyAccess] with a [FunctionReference] target; for
|
||||
// example: `List<int>.filled` or `core.List<int>.filled`.
|
||||
var function = receiver.function;
|
||||
if (function is! Identifier) {
|
||||
if (function is! IdentifierImpl) {
|
||||
// If [receiverIdentifier] is not an Identifier then [node] is not a
|
||||
// ConstructorReference.
|
||||
return node;
|
||||
|
@ -311,9 +311,9 @@ class AstRewriter {
|
|||
}
|
||||
|
||||
Element? element;
|
||||
if (receiverIdentifier is SimpleIdentifier) {
|
||||
if (receiverIdentifier is SimpleIdentifierImpl) {
|
||||
element = nameScope.lookup(receiverIdentifier.name).getter;
|
||||
} else if (receiverIdentifier is PrefixedIdentifier) {
|
||||
} else if (receiverIdentifier is PrefixedIdentifierImpl) {
|
||||
var prefixElement =
|
||||
nameScope.lookup(receiverIdentifier.prefix.name).getter;
|
||||
if (prefixElement is PrefixElement) {
|
||||
|
@ -371,9 +371,9 @@ class AstRewriter {
|
|||
}
|
||||
|
||||
AstNode _instanceCreation_prefix_type_name({
|
||||
required MethodInvocation node,
|
||||
required PrefixedIdentifier typeNameIdentifier,
|
||||
required SimpleIdentifier constructorIdentifier,
|
||||
required MethodInvocationImpl node,
|
||||
required PrefixedIdentifierImpl typeNameIdentifier,
|
||||
required SimpleIdentifierImpl constructorIdentifier,
|
||||
required ClassElement classElement,
|
||||
}) {
|
||||
var constructorElement = classElement.getNamedConstructor(
|
||||
|
@ -395,16 +395,21 @@ class AstRewriter {
|
|||
name: typeNameIdentifier,
|
||||
typeArguments: typeArguments,
|
||||
);
|
||||
var constructorName = astFactory.constructorName(
|
||||
typeName, node.operator, constructorIdentifier);
|
||||
var constructorName = ConstructorNameImpl(
|
||||
type: typeName,
|
||||
period: node.operator,
|
||||
name: constructorIdentifier,
|
||||
);
|
||||
var instanceCreationExpression = astFactory.instanceCreationExpression(
|
||||
null, constructorName, node.argumentList);
|
||||
NodeReplacer.replace(node, instanceCreationExpression);
|
||||
return instanceCreationExpression;
|
||||
}
|
||||
|
||||
AstNode _toConstructorReference_prefixed(
|
||||
{required PrefixedIdentifier node, required ClassElement classElement}) {
|
||||
AstNode _toConstructorReference_prefixed({
|
||||
required PrefixedIdentifierImpl node,
|
||||
required ClassElement classElement,
|
||||
}) {
|
||||
var name = node.identifier.name;
|
||||
var constructorElement = name == 'new'
|
||||
? classElement.unnamedConstructor
|
||||
|
@ -414,18 +419,22 @@ class AstRewriter {
|
|||
}
|
||||
|
||||
var typeName = astFactory.namedType(name: node.prefix);
|
||||
var constructorName =
|
||||
astFactory.constructorName(typeName, node.period, node.identifier);
|
||||
var constructorReference =
|
||||
astFactory.constructorReference(constructorName: constructorName);
|
||||
var constructorName = ConstructorNameImpl(
|
||||
type: typeName,
|
||||
period: node.period,
|
||||
name: node.identifier,
|
||||
);
|
||||
var constructorReference = ConstructorReferenceImpl(
|
||||
constructorName: constructorName,
|
||||
);
|
||||
NodeReplacer.replace(node, constructorReference);
|
||||
return constructorReference;
|
||||
}
|
||||
|
||||
AstNode _toConstructorReference_propertyAccess({
|
||||
required PropertyAccess node,
|
||||
required Identifier receiver,
|
||||
required TypeArgumentList? typeArguments,
|
||||
required PropertyAccessImpl node,
|
||||
required IdentifierImpl receiver,
|
||||
required TypeArgumentListImpl? typeArguments,
|
||||
required ClassElement classElement,
|
||||
}) {
|
||||
var name = node.propertyName.name;
|
||||
|
@ -446,18 +455,22 @@ class AstRewriter {
|
|||
name: receiver,
|
||||
typeArguments: typeArguments,
|
||||
);
|
||||
var constructorName =
|
||||
astFactory.constructorName(typeName, operator, node.propertyName);
|
||||
var constructorReference =
|
||||
astFactory.constructorReference(constructorName: constructorName);
|
||||
var constructorName = ConstructorNameImpl(
|
||||
type: typeName,
|
||||
period: operator,
|
||||
name: node.propertyName,
|
||||
);
|
||||
var constructorReference = ConstructorReferenceImpl(
|
||||
constructorName: constructorName,
|
||||
);
|
||||
NodeReplacer.replace(node, constructorReference);
|
||||
return constructorReference;
|
||||
}
|
||||
|
||||
InstanceCreationExpression _toInstanceCreation_prefix_type({
|
||||
required MethodInvocation node,
|
||||
required SimpleIdentifier prefixIdentifier,
|
||||
required SimpleIdentifier typeIdentifier,
|
||||
required MethodInvocationImpl node,
|
||||
required SimpleIdentifierImpl prefixIdentifier,
|
||||
required SimpleIdentifierImpl typeIdentifier,
|
||||
}) {
|
||||
var typeName = astFactory.namedType(
|
||||
name: astFactory.prefixedIdentifier(
|
||||
|
@ -467,7 +480,11 @@ class AstRewriter {
|
|||
),
|
||||
typeArguments: node.typeArguments,
|
||||
);
|
||||
var constructorName = astFactory.constructorName(typeName, null, null);
|
||||
var constructorName = ConstructorNameImpl(
|
||||
type: typeName,
|
||||
period: null,
|
||||
name: null,
|
||||
);
|
||||
var instanceCreationExpression = astFactory.instanceCreationExpression(
|
||||
null, constructorName, node.argumentList);
|
||||
NodeReplacer.replace(node, instanceCreationExpression);
|
||||
|
@ -482,7 +499,11 @@ class AstRewriter {
|
|||
name: typeIdentifier,
|
||||
typeArguments: node.typeArguments,
|
||||
);
|
||||
var constructorName = astFactory.constructorName(typeName, null, null);
|
||||
var constructorName = ConstructorNameImpl(
|
||||
type: typeName,
|
||||
period: null,
|
||||
name: null,
|
||||
);
|
||||
var instanceCreationExpression = astFactory.instanceCreationExpression(
|
||||
null, constructorName, node.argumentList);
|
||||
NodeReplacer.replace(node, instanceCreationExpression);
|
||||
|
@ -490,9 +511,9 @@ class AstRewriter {
|
|||
}
|
||||
|
||||
AstNode _toInstanceCreation_type_constructor({
|
||||
required MethodInvocation node,
|
||||
required SimpleIdentifier typeIdentifier,
|
||||
required SimpleIdentifier constructorIdentifier,
|
||||
required MethodInvocationImpl node,
|
||||
required SimpleIdentifierImpl typeIdentifier,
|
||||
required SimpleIdentifierImpl constructorIdentifier,
|
||||
required ClassElement classElement,
|
||||
}) {
|
||||
var name = constructorIdentifier.name;
|
||||
|
@ -509,8 +530,11 @@ class AstRewriter {
|
|||
[typeIdentifier.name, constructorIdentifier.name]);
|
||||
}
|
||||
var typeName = astFactory.namedType(name: typeIdentifier);
|
||||
var constructorName = astFactory.constructorName(
|
||||
typeName, node.operator, constructorIdentifier);
|
||||
var constructorName = ConstructorNameImpl(
|
||||
type: typeName,
|
||||
period: node.operator,
|
||||
name: constructorIdentifier,
|
||||
);
|
||||
// TODO(scheglov) I think we should drop "typeArguments" below.
|
||||
var instanceCreationExpression = astFactory.instanceCreationExpression(
|
||||
null, constructorName, node.argumentList,
|
||||
|
|
|
@ -885,7 +885,7 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
}
|
||||
|
||||
@override
|
||||
void visitMethodInvocation(MethodInvocation node) {
|
||||
void visitMethodInvocation(covariant MethodInvocationImpl node) {
|
||||
var newNode = _astRewriter.methodInvocation(_nameScope, node);
|
||||
if (newNode != node) {
|
||||
return newNode.accept(this);
|
||||
|
@ -948,7 +948,7 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
}
|
||||
|
||||
@override
|
||||
void visitPrefixedIdentifier(PrefixedIdentifier node) {
|
||||
void visitPrefixedIdentifier(covariant PrefixedIdentifierImpl node) {
|
||||
var newNode = _astRewriter.prefixedIdentifier(_nameScope, node);
|
||||
if (newNode != node) {
|
||||
return newNode.accept(this);
|
||||
|
@ -958,7 +958,7 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
|
|||
}
|
||||
|
||||
@override
|
||||
void visitPropertyAccess(PropertyAccess node) {
|
||||
void visitPropertyAccess(covariant PropertyAccessImpl node) {
|
||||
var newNode = _astRewriter.propertyAccess(_nameScope, node);
|
||||
if (newNode != node) {
|
||||
return newNode.accept(this);
|
||||
|
|
|
@ -229,12 +229,17 @@ class AstBuilder extends StackListener {
|
|||
assert(optional('..', token) || optional('?..', token));
|
||||
debugEvent("beginCascade");
|
||||
|
||||
var expression = pop() as Expression;
|
||||
var expression = pop() as ExpressionImpl;
|
||||
push(token);
|
||||
if (expression is CascadeExpression) {
|
||||
push(expression);
|
||||
} else {
|
||||
push(ast.cascadeExpression(expression, <Expression>[]));
|
||||
push(
|
||||
CascadeExpressionImpl(
|
||||
target: expression,
|
||||
cascadeSections: <Expression>[],
|
||||
),
|
||||
);
|
||||
}
|
||||
push(NullValue.CascadeReceiver);
|
||||
}
|
||||
|
@ -491,14 +496,14 @@ class AstBuilder extends StackListener {
|
|||
initializerObject.target, initializerObject);
|
||||
}
|
||||
|
||||
if (initializerObject is AssignmentExpression) {
|
||||
if (initializerObject is AssignmentExpressionImpl) {
|
||||
Token? thisKeyword;
|
||||
Token? period;
|
||||
SimpleIdentifier fieldName;
|
||||
SimpleIdentifierImpl fieldName;
|
||||
Expression left = initializerObject.leftHandSide;
|
||||
if (left is PropertyAccess) {
|
||||
if (left is PropertyAccessImpl) {
|
||||
var target = left.target;
|
||||
if (target is ThisExpression) {
|
||||
if (target is ThisExpressionImpl) {
|
||||
thisKeyword = target.thisKeyword;
|
||||
period = left.operator;
|
||||
} else {
|
||||
|
@ -507,7 +512,7 @@ class AstBuilder extends StackListener {
|
|||
// Parser has reported FieldInitializedOutsideDeclaringClass.
|
||||
}
|
||||
fieldName = left.propertyName;
|
||||
} else if (left is SimpleIdentifier) {
|
||||
} else if (left is SimpleIdentifierImpl) {
|
||||
fieldName = left;
|
||||
} else {
|
||||
// Recovery:
|
||||
|
@ -515,8 +520,13 @@ class AstBuilder extends StackListener {
|
|||
var superExpression = left as SuperExpression;
|
||||
fieldName = ast.simpleIdentifier(superExpression.superKeyword);
|
||||
}
|
||||
return ast.constructorFieldInitializer(thisKeyword, period, fieldName,
|
||||
initializerObject.operator, initializerObject.rightHandSide);
|
||||
return ConstructorFieldInitializerImpl(
|
||||
thisKeyword: thisKeyword,
|
||||
period: period,
|
||||
fieldName: fieldName,
|
||||
equals: initializerObject.operator,
|
||||
expression: initializerObject.rightHandSide,
|
||||
);
|
||||
}
|
||||
|
||||
if (initializerObject is AssertInitializer) {
|
||||
|
@ -1190,13 +1200,20 @@ class AstBuilder extends StackListener {
|
|||
assert(optional(':', colon));
|
||||
debugEvent("ConditionalExpression");
|
||||
|
||||
var elseExpression = pop() as Expression;
|
||||
var thenExpression = pop() as Expression;
|
||||
var condition = pop() as Expression;
|
||||
var elseExpression = pop() as ExpressionImpl;
|
||||
var thenExpression = pop() as ExpressionImpl;
|
||||
var condition = pop() as ExpressionImpl;
|
||||
reportErrorIfSuper(elseExpression);
|
||||
reportErrorIfSuper(thenExpression);
|
||||
push(ast.conditionalExpression(
|
||||
condition, question, thenExpression, colon, elseExpression));
|
||||
push(
|
||||
ConditionalExpressionImpl(
|
||||
condition: condition,
|
||||
question: question,
|
||||
thenExpression: thenExpression,
|
||||
colon: colon,
|
||||
elseExpression: elseExpression,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -1206,9 +1223,9 @@ class AstBuilder extends StackListener {
|
|||
assert(optionalOrNull('==', equalSign));
|
||||
debugEvent("ConditionalUri");
|
||||
|
||||
var libraryUri = pop() as StringLiteral;
|
||||
var value = popIfNotNull(equalSign) as StringLiteral?;
|
||||
if (value is StringInterpolation) {
|
||||
var libraryUri = pop() as StringLiteralImpl;
|
||||
var value = popIfNotNull(equalSign) as StringLiteralImpl?;
|
||||
if (value is StringInterpolationImpl) {
|
||||
for (var child in value.childEntities) {
|
||||
if (child is InterpolationExpression) {
|
||||
// This error is reported in OutlineBuilder.endLiteralString
|
||||
|
@ -1218,9 +1235,18 @@ class AstBuilder extends StackListener {
|
|||
}
|
||||
}
|
||||
}
|
||||
var name = pop() as DottedName;
|
||||
push(ast.configuration(ifKeyword, leftParen, name, equalSign, value,
|
||||
leftParen.endGroup!, libraryUri));
|
||||
var name = pop() as DottedNameImpl;
|
||||
push(
|
||||
ConfigurationImpl(
|
||||
ifKeyword: ifKeyword,
|
||||
leftParenthesis: leftParen,
|
||||
name: name,
|
||||
equalToken: equalSign,
|
||||
value: value,
|
||||
rightParenthesis: leftParen.endGroup!,
|
||||
uri: libraryUri,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -1249,17 +1275,17 @@ class AstBuilder extends StackListener {
|
|||
assert(optionalOrNull('.', periodBeforeName));
|
||||
debugEvent("ConstructorReference");
|
||||
|
||||
var constructorName = pop() as SimpleIdentifier?;
|
||||
var typeArguments = pop() as TypeArgumentList?;
|
||||
var typeNameIdentifier = pop() as Identifier;
|
||||
var constructorName = pop() as SimpleIdentifierImpl?;
|
||||
var typeArguments = pop() as TypeArgumentListImpl?;
|
||||
var typeNameIdentifier = pop() as IdentifierImpl;
|
||||
push(
|
||||
ast.constructorName(
|
||||
ast.namedType(
|
||||
ConstructorNameImpl(
|
||||
type: ast.namedType(
|
||||
name: typeNameIdentifier,
|
||||
typeArguments: typeArguments,
|
||||
),
|
||||
periodBeforeName,
|
||||
constructorName,
|
||||
period: periodBeforeName,
|
||||
name: constructorName,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -1594,8 +1620,8 @@ class AstBuilder extends StackListener {
|
|||
var comment = _findComment(metadata,
|
||||
thisKeyword ?? typeOrFunctionTypedParameter?.beginToken ?? nameToken);
|
||||
|
||||
NormalFormalParameter node;
|
||||
if (typeOrFunctionTypedParameter is FunctionTypedFormalParameter) {
|
||||
NormalFormalParameterImpl node;
|
||||
if (typeOrFunctionTypedParameter is FunctionTypedFormalParameterImpl) {
|
||||
// This is a temporary AST node that was constructed in
|
||||
// [endFunctionTypedFormalParameter]. We now deconstruct it and create
|
||||
// the final AST node.
|
||||
|
@ -1691,13 +1717,21 @@ class AstBuilder extends StackListener {
|
|||
ParameterKind analyzerKind = _toAnalyzerParameterKind(kind);
|
||||
FormalParameter parameter = node;
|
||||
if (analyzerKind != ParameterKind.REQUIRED) {
|
||||
parameter = ast.defaultFormalParameter(
|
||||
node, analyzerKind, defaultValue?.separator, defaultValue?.value);
|
||||
parameter = DefaultFormalParameterImpl(
|
||||
parameter: node,
|
||||
kind: analyzerKind,
|
||||
separator: defaultValue?.separator,
|
||||
defaultValue: defaultValue?.value,
|
||||
);
|
||||
} else if (defaultValue != null) {
|
||||
// An error is reported if a required parameter has a default value.
|
||||
// Record it as named parameter for recovery.
|
||||
parameter = ast.defaultFormalParameter(node, ParameterKind.NAMED,
|
||||
defaultValue.separator, defaultValue.value);
|
||||
parameter = DefaultFormalParameterImpl(
|
||||
parameter: node,
|
||||
kind: ParameterKind.NAMED,
|
||||
separator: defaultValue.separator,
|
||||
defaultValue: defaultValue.value,
|
||||
);
|
||||
}
|
||||
push(parameter);
|
||||
}
|
||||
|
@ -2842,8 +2876,14 @@ class AstBuilder extends StackListener {
|
|||
assert(optional(';', semicolon));
|
||||
debugEvent("BreakStatement");
|
||||
|
||||
var label = hasTarget ? pop() as SimpleIdentifier : null;
|
||||
push(ast.breakStatement(breakKeyword, label, semicolon));
|
||||
var label = hasTarget ? pop() as SimpleIdentifierImpl : null;
|
||||
push(
|
||||
BreakStatementImpl(
|
||||
breakKeyword: breakKeyword,
|
||||
label: label,
|
||||
semicolon: semicolon,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -2882,23 +2922,23 @@ class AstBuilder extends StackListener {
|
|||
}
|
||||
push(
|
||||
CatchClauseImpl(
|
||||
onKeyword,
|
||||
type as TypeAnnotationImpl?,
|
||||
catchKeyword,
|
||||
catchParameterList?.leftParenthesis,
|
||||
exception != null
|
||||
onKeyword: onKeyword,
|
||||
exceptionType: type as TypeAnnotationImpl?,
|
||||
catchKeyword: catchKeyword,
|
||||
leftParenthesis: catchParameterList?.leftParenthesis,
|
||||
exceptionParameter: exception != null
|
||||
? CatchClauseParameterImpl(
|
||||
nameNode: exception as SimpleIdentifierImpl,
|
||||
)
|
||||
: null,
|
||||
comma,
|
||||
stackTrace != null
|
||||
comma: comma,
|
||||
stackTraceParameter: stackTrace != null
|
||||
? CatchClauseParameterImpl(
|
||||
nameNode: stackTrace as SimpleIdentifierImpl,
|
||||
)
|
||||
: null,
|
||||
catchParameterList?.rightParenthesis,
|
||||
body as BlockImpl,
|
||||
rightParenthesis: catchParameterList?.rightParenthesis,
|
||||
body: body as BlockImpl,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -2994,13 +3034,28 @@ class AstBuilder extends StackListener {
|
|||
var target = ast.prefixedIdentifier(ast.simpleIdentifier(firstToken),
|
||||
firstPeriod!, ast.simpleIdentifier(secondToken!));
|
||||
var expression = ast.propertyAccess(target, secondPeriod!, identifier);
|
||||
push(ast.commentReference(newKeyword, expression));
|
||||
push(
|
||||
CommentReferenceImpl(
|
||||
newKeyword: newKeyword,
|
||||
expression: expression,
|
||||
),
|
||||
);
|
||||
} else if (secondToken != null) {
|
||||
var expression = ast.prefixedIdentifier(
|
||||
ast.simpleIdentifier(secondToken), secondPeriod!, identifier);
|
||||
push(ast.commentReference(newKeyword, expression));
|
||||
push(
|
||||
CommentReferenceImpl(
|
||||
newKeyword: newKeyword,
|
||||
expression: expression,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
push(ast.commentReference(newKeyword, identifier));
|
||||
push(
|
||||
CommentReferenceImpl(
|
||||
newKeyword: newKeyword,
|
||||
expression: identifier,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3024,8 +3079,14 @@ class AstBuilder extends StackListener {
|
|||
assert(optional(';', semicolon));
|
||||
debugEvent("ContinueStatement");
|
||||
|
||||
var label = hasTarget ? pop() as SimpleIdentifier : null;
|
||||
push(ast.continueStatement(continueKeyword, label, semicolon));
|
||||
var label = hasTarget ? pop() as SimpleIdentifierImpl : null;
|
||||
push(
|
||||
ContinueStatementImpl(
|
||||
continueKeyword: continueKeyword,
|
||||
label: label,
|
||||
semicolon: semicolon,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -3598,7 +3659,12 @@ class AstBuilder extends StackListener {
|
|||
assert(value || identical(token.stringValue, "false"));
|
||||
debugEvent("LiteralBool");
|
||||
|
||||
push(ast.booleanLiteral(token, value));
|
||||
push(
|
||||
BooleanLiteralImpl(
|
||||
literal: token,
|
||||
value: value,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -4252,7 +4318,7 @@ class AstBuilder extends StackListener {
|
|||
assert(optional('=', equals) || optional(':', equals));
|
||||
debugEvent("ValuedFormalParameter");
|
||||
|
||||
var value = pop() as Expression;
|
||||
var value = pop() as ExpressionImpl;
|
||||
push(_ParameterDefaultValue(equals, value));
|
||||
}
|
||||
|
||||
|
@ -4631,7 +4697,7 @@ class _OptionalFormalParameters {
|
|||
/// value with the separator token.
|
||||
class _ParameterDefaultValue {
|
||||
final Token separator;
|
||||
final Expression value;
|
||||
final ExpressionImpl value;
|
||||
|
||||
_ParameterDefaultValue(this.separator, this.value);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ import 'package:analyzer/src/dart/ast/ast.dart';
|
|||
import 'package:analyzer/src/dart/ast/ast_factory.dart';
|
||||
import 'package:analyzer/src/dart/element/type.dart';
|
||||
import 'package:analyzer/src/generated/testing/token_factory.dart';
|
||||
import 'package:analyzer/src/generated/utilities_dart.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
/// The class `AstTestFactory` defines utility methods that can be used to
|
||||
|
@ -68,23 +67,6 @@ class AstTestFactory {
|
|||
semicolon: TokenFactory.tokenFromType(TokenType.SEMICOLON),
|
||||
);
|
||||
|
||||
static BooleanLiteralImpl booleanLiteral(
|
||||
bool value) =>
|
||||
astFactory.booleanLiteral(
|
||||
value
|
||||
? TokenFactory.tokenFromKeyword(Keyword.TRUE)
|
||||
: TokenFactory.tokenFromKeyword(Keyword.FALSE),
|
||||
value);
|
||||
|
||||
static BreakStatementImpl breakStatement() => astFactory.breakStatement(
|
||||
TokenFactory.tokenFromKeyword(Keyword.BREAK),
|
||||
null,
|
||||
TokenFactory.tokenFromType(TokenType.SEMICOLON));
|
||||
|
||||
static BreakStatementImpl breakStatement2(String label) =>
|
||||
astFactory.breakStatement(TokenFactory.tokenFromKeyword(Keyword.BREAK),
|
||||
identifier3(label), TokenFactory.tokenFromType(TokenType.SEMICOLON));
|
||||
|
||||
static IndexExpressionImpl cascadedIndexExpression(Expression index) =>
|
||||
astFactory.indexExpressionForCascade2(
|
||||
period: TokenFactory.tokenFromType(TokenType.PERIOD_PERIOD),
|
||||
|
@ -109,13 +91,6 @@ class AstTestFactory {
|
|||
TokenFactory.tokenFromType(TokenType.PERIOD_PERIOD),
|
||||
identifier3(propertyName));
|
||||
|
||||
static CascadeExpressionImpl cascadeExpression(Expression target,
|
||||
[List<Expression> cascadeSections = const []]) {
|
||||
var cascade = astFactory.cascadeExpression(target, cascadeSections);
|
||||
cascade.target.endToken.next = cascadeSections.first.beginToken;
|
||||
return cascade;
|
||||
}
|
||||
|
||||
static ClassDeclarationImpl classDeclaration(
|
||||
Keyword? abstractKeyword,
|
||||
String name,
|
||||
|
@ -228,15 +203,6 @@ class AstTestFactory {
|
|||
featureSet: featureSet,
|
||||
lineInfo: LineInfo.fromContent(''));
|
||||
|
||||
static ConditionalExpressionImpl conditionalExpression(Expression condition,
|
||||
Expression thenExpression, Expression elseExpression) =>
|
||||
astFactory.conditionalExpression(
|
||||
condition,
|
||||
TokenFactory.tokenFromType(TokenType.QUESTION),
|
||||
thenExpression,
|
||||
TokenFactory.tokenFromType(TokenType.COLON),
|
||||
elseExpression);
|
||||
|
||||
static ConstructorDeclarationImpl constructorDeclaration(
|
||||
Identifier returnType,
|
||||
String? name,
|
||||
|
@ -292,29 +258,6 @@ class AstTestFactory {
|
|||
body: body as FunctionBodyImpl,
|
||||
);
|
||||
|
||||
static ConstructorFieldInitializerImpl constructorFieldInitializer(
|
||||
bool prefixedWithThis, String fieldName, Expression expression) =>
|
||||
astFactory.constructorFieldInitializer(
|
||||
prefixedWithThis ? TokenFactory.tokenFromKeyword(Keyword.THIS) : null,
|
||||
prefixedWithThis
|
||||
? TokenFactory.tokenFromType(TokenType.PERIOD)
|
||||
: null,
|
||||
identifier3(fieldName),
|
||||
TokenFactory.tokenFromType(TokenType.EQ),
|
||||
expression);
|
||||
|
||||
static ConstructorNameImpl constructorName(NamedType type, String? name) =>
|
||||
astFactory.constructorName(
|
||||
type,
|
||||
name == null ? null : TokenFactory.tokenFromType(TokenType.PERIOD),
|
||||
name == null ? null : identifier3(name));
|
||||
|
||||
static ContinueStatementImpl continueStatement([String? label]) =>
|
||||
astFactory.continueStatement(
|
||||
TokenFactory.tokenFromKeyword(Keyword.CONTINUE),
|
||||
label == null ? null : identifier3(label),
|
||||
TokenFactory.tokenFromType(TokenType.SEMICOLON));
|
||||
|
||||
static DeclaredIdentifierImpl declaredIdentifier(
|
||||
Keyword keyword, String identifier) =>
|
||||
declaredIdentifier2(keyword, null, identifier);
|
||||
|
@ -751,24 +694,6 @@ class AstTestFactory {
|
|||
name,
|
||||
argumentList(arguments));
|
||||
|
||||
static InstanceCreationExpressionImpl instanceCreationExpression2(
|
||||
Keyword? keyword, NamedType type,
|
||||
[List<Expression> arguments = const []]) =>
|
||||
instanceCreationExpression3(keyword, type, null, arguments);
|
||||
|
||||
static InstanceCreationExpressionImpl instanceCreationExpression3(
|
||||
Keyword? keyword, NamedType type, String? identifier,
|
||||
[List<Expression> arguments = const []]) =>
|
||||
instanceCreationExpression(
|
||||
keyword,
|
||||
astFactory.constructorName(
|
||||
type,
|
||||
identifier == null
|
||||
? null
|
||||
: TokenFactory.tokenFromType(TokenType.PERIOD),
|
||||
identifier == null ? null : identifier3(identifier)),
|
||||
arguments);
|
||||
|
||||
static IntegerLiteralImpl integer(int value) => astFactory.integerLiteral(
|
||||
TokenFactory.tokenFromTypeAndString(TokenType.INT, value.toString()),
|
||||
value);
|
||||
|
@ -997,16 +922,6 @@ class AstTestFactory {
|
|||
String label, Expression expression) =>
|
||||
namedExpression(label2(label), expression);
|
||||
|
||||
static DefaultFormalParameterImpl namedFormalParameter(
|
||||
NormalFormalParameter parameter, Expression? expression) =>
|
||||
astFactory.defaultFormalParameter(
|
||||
parameter,
|
||||
ParameterKind.NAMED,
|
||||
expression == null
|
||||
? null
|
||||
: TokenFactory.tokenFromType(TokenType.COLON),
|
||||
expression);
|
||||
|
||||
/// Create a type name whose name has been resolved to the given [element] and
|
||||
/// whose type has been resolved to the type of the given element.
|
||||
///
|
||||
|
@ -1091,14 +1006,6 @@ class AstTestFactory {
|
|||
semicolon: TokenFactory.tokenFromType(TokenType.SEMICOLON),
|
||||
);
|
||||
|
||||
static DefaultFormalParameterImpl positionalFormalParameter(
|
||||
NormalFormalParameter parameter, Expression? expression) =>
|
||||
astFactory.defaultFormalParameter(
|
||||
parameter,
|
||||
ParameterKind.POSITIONAL,
|
||||
expression == null ? null : TokenFactory.tokenFromType(TokenType.EQ),
|
||||
expression);
|
||||
|
||||
static PostfixExpressionImpl postfixExpression(
|
||||
Expression expression, TokenType operator) =>
|
||||
astFactory.postfixExpression(
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
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';
|
||||
import 'package:analyzer/dart/element/nullability_suffix.dart';
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
|
@ -14,7 +13,6 @@ import 'package:analyzer/src/dart/element/type.dart';
|
|||
import 'package:analyzer/src/dart/resolver/variance.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer/src/generated/testing/ast_test_factory.dart';
|
||||
import 'package:analyzer/src/generated/utilities_dart.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
@ -334,38 +332,6 @@ class ElementFactory {
|
|||
static TopLevelVariableElementImpl topLevelVariableElement(Identifier name) =>
|
||||
TopLevelVariableElementImpl(name.name, name.offset);
|
||||
|
||||
static TopLevelVariableElementImpl topLevelVariableElement2(String name) =>
|
||||
topLevelVariableElement3(name, false, false, DynamicTypeImpl.instance);
|
||||
|
||||
static TopLevelVariableElementImpl topLevelVariableElement3(
|
||||
String name, bool isConst, bool isFinal, DartType type) {
|
||||
TopLevelVariableElementImpl variable;
|
||||
if (isConst) {
|
||||
ConstTopLevelVariableElementImpl constant =
|
||||
ConstTopLevelVariableElementImpl(name, -1);
|
||||
var typeElement = type.element as ClassElement;
|
||||
var initializer = AstTestFactory.instanceCreationExpression2(
|
||||
Keyword.CONST, AstTestFactory.namedType(typeElement));
|
||||
if (type is InterfaceType) {
|
||||
var element = typeElement.unnamedConstructor;
|
||||
initializer.constructorName.staticElement = element;
|
||||
}
|
||||
constant.constantInitializer = initializer;
|
||||
variable = constant;
|
||||
} else {
|
||||
variable = TopLevelVariableElementImpl(name, -1);
|
||||
}
|
||||
variable.isConst = isConst;
|
||||
variable.isFinal = isFinal;
|
||||
variable.isSynthetic = false;
|
||||
variable.type = type;
|
||||
PropertyAccessorElementImpl_ImplicitGetter(variable);
|
||||
if (!isConst && !isFinal) {
|
||||
PropertyAccessorElementImpl_ImplicitSetter(variable);
|
||||
}
|
||||
return variable;
|
||||
}
|
||||
|
||||
static TypeParameterElementImpl typeParameterElement(String name) {
|
||||
return TypeParameterElementImpl(name, 0);
|
||||
}
|
||||
|
|
|
@ -293,7 +293,10 @@ class AstBinaryReader {
|
|||
|
||||
BooleanLiteral _readBooleanLiteral() {
|
||||
var value = _readByte() == 1;
|
||||
var node = AstTestFactory.booleanLiteral(value);
|
||||
var node = BooleanLiteralImpl(
|
||||
literal: value ? Tokens.true_() : Tokens.false_(),
|
||||
value: value,
|
||||
);
|
||||
_readExpressionResolution(node);
|
||||
return node;
|
||||
}
|
||||
|
@ -303,23 +306,26 @@ class AstBinaryReader {
|
|||
}
|
||||
|
||||
CascadeExpression _readCascadeExpression() {
|
||||
var target = readNode() as Expression;
|
||||
var target = readNode() as ExpressionImpl;
|
||||
var sections = _readNodeList<Expression>();
|
||||
var node = astFactory.cascadeExpression(target, sections);
|
||||
var node = CascadeExpressionImpl(
|
||||
target: target,
|
||||
cascadeSections: sections,
|
||||
);
|
||||
node.staticType = target.staticType;
|
||||
return node;
|
||||
}
|
||||
|
||||
ConditionalExpression _readConditionalExpression() {
|
||||
var condition = readNode() as Expression;
|
||||
var thenExpression = readNode() as Expression;
|
||||
var elseExpression = readNode() as Expression;
|
||||
var node = astFactory.conditionalExpression(
|
||||
condition,
|
||||
Tokens.question(),
|
||||
thenExpression,
|
||||
Tokens.colon(),
|
||||
elseExpression,
|
||||
var condition = readNode() as ExpressionImpl;
|
||||
var thenExpression = readNode() as ExpressionImpl;
|
||||
var elseExpression = readNode() as ExpressionImpl;
|
||||
var node = ConditionalExpressionImpl(
|
||||
condition: condition,
|
||||
question: Tokens.question(),
|
||||
thenExpression: thenExpression,
|
||||
colon: Tokens.colon(),
|
||||
elseExpression: elseExpression,
|
||||
);
|
||||
_readExpressionResolution(node);
|
||||
return node;
|
||||
|
@ -327,34 +333,34 @@ class AstBinaryReader {
|
|||
|
||||
ConstructorFieldInitializer _readConstructorFieldInitializer() {
|
||||
var flags = _readByte();
|
||||
var fieldName = readNode() as SimpleIdentifier;
|
||||
var expression = readNode() as Expression;
|
||||
var fieldName = readNode() as SimpleIdentifierImpl;
|
||||
var expression = readNode() as ExpressionImpl;
|
||||
var hasThis = AstBinaryFlags.hasThis(flags);
|
||||
return astFactory.constructorFieldInitializer(
|
||||
hasThis ? Tokens.this_() : null,
|
||||
hasThis ? Tokens.period() : null,
|
||||
fieldName,
|
||||
Tokens.eq(),
|
||||
expression,
|
||||
return ConstructorFieldInitializerImpl(
|
||||
thisKeyword: hasThis ? Tokens.this_() : null,
|
||||
period: hasThis ? Tokens.period() : null,
|
||||
fieldName: fieldName,
|
||||
equals: Tokens.eq(),
|
||||
expression: expression,
|
||||
);
|
||||
}
|
||||
|
||||
ConstructorName _readConstructorName() {
|
||||
var type = readNode() as NamedType;
|
||||
var name = _readOptionalNode() as SimpleIdentifier?;
|
||||
var type = readNode() as NamedTypeImpl;
|
||||
var name = _readOptionalNode() as SimpleIdentifierImpl?;
|
||||
|
||||
var node = astFactory.constructorName(
|
||||
type,
|
||||
name != null ? Tokens.period() : null,
|
||||
name,
|
||||
var node = ConstructorNameImpl(
|
||||
type: type,
|
||||
period: name != null ? Tokens.period() : null,
|
||||
name: name,
|
||||
);
|
||||
node.staticElement = _reader.readElement() as ConstructorElement?;
|
||||
return node;
|
||||
}
|
||||
|
||||
ConstructorReference _readConstructorReference() {
|
||||
var constructorName = readNode() as ConstructorName;
|
||||
var node = astFactory.constructorReference(
|
||||
var constructorName = readNode() as ConstructorNameImpl;
|
||||
var node = ConstructorReferenceImpl(
|
||||
constructorName: constructorName,
|
||||
);
|
||||
_readExpressionResolution(node);
|
||||
|
@ -391,8 +397,8 @@ class AstBinaryReader {
|
|||
|
||||
DefaultFormalParameter _readDefaultFormalParameter() {
|
||||
var flags = _readByte();
|
||||
var parameter = readNode() as NormalFormalParameter;
|
||||
var defaultValue = _readOptionalNode() as Expression?;
|
||||
var parameter = readNode() as NormalFormalParameterImpl;
|
||||
var defaultValue = _readOptionalNode() as ExpressionImpl?;
|
||||
|
||||
ParameterKind kind;
|
||||
if (AstBinaryFlags.isPositional(flags)) {
|
||||
|
@ -405,11 +411,11 @@ class AstBinaryReader {
|
|||
: ParameterKind.NAMED;
|
||||
}
|
||||
|
||||
var node = astFactory.defaultFormalParameter(
|
||||
parameter,
|
||||
kind,
|
||||
AstBinaryFlags.hasInitializer(flags) ? Tokens.colon() : null,
|
||||
defaultValue,
|
||||
var node = DefaultFormalParameterImpl(
|
||||
parameter: parameter,
|
||||
kind: kind,
|
||||
separator: AstBinaryFlags.hasInitializer(flags) ? Tokens.colon() : null,
|
||||
defaultValue: defaultValue,
|
||||
);
|
||||
|
||||
var nonDefaultElement = parameter.declaredElement!;
|
||||
|
|
|
@ -75,6 +75,8 @@ class Tokens {
|
|||
|
||||
static Token factory_() => TokenFactory.tokenFromKeyword(Keyword.FACTORY);
|
||||
|
||||
static Token false_() => TokenFactory.tokenFromKeyword(Keyword.FALSE);
|
||||
|
||||
static Token final_() => TokenFactory.tokenFromKeyword(Keyword.FINAL);
|
||||
|
||||
static Token finally_() => TokenFactory.tokenFromKeyword(Keyword.FINALLY);
|
||||
|
@ -186,6 +188,8 @@ class Tokens {
|
|||
|
||||
static Token throw_() => TokenFactory.tokenFromKeyword(Keyword.THROW);
|
||||
|
||||
static Token true_() => TokenFactory.tokenFromKeyword(Keyword.TRUE);
|
||||
|
||||
static Token try_() => TokenFactory.tokenFromKeyword(Keyword.TRY);
|
||||
|
||||
static Token typedef_() => TokenFactory.tokenFromKeyword(Keyword.TYPEDEF);
|
||||
|
|
|
@ -242,15 +242,15 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
|
|||
|
||||
var initializer = astFactory.instanceCreationExpression(
|
||||
null,
|
||||
astFactory.constructorName(
|
||||
astFactory.namedType(
|
||||
ConstructorNameImpl(
|
||||
type: astFactory.namedType(
|
||||
name: astFactory.simpleIdentifier(
|
||||
StringToken(TokenType.STRING, element.name, -1),
|
||||
),
|
||||
typeArguments: constant.arguments?.typeArguments,
|
||||
),
|
||||
constructorName != null ? Tokens.period() : null,
|
||||
constructorName != null
|
||||
period: constructorName != null ? Tokens.period() : null,
|
||||
name: constructorName != null
|
||||
? astFactory.simpleIdentifier(
|
||||
StringToken(TokenType.STRING, constructorName, -1),
|
||||
)
|
||||
|
|
|
@ -930,22 +930,19 @@ class _MockSdkElementsBuilder {
|
|||
]),
|
||||
];
|
||||
|
||||
var deprecatedVariable = _topLevelVariable(
|
||||
var deprecatedVariable = _topLevelVariableConst(
|
||||
'deprecated',
|
||||
_interfaceType(deprecatedElement),
|
||||
isConst: true,
|
||||
);
|
||||
|
||||
var overrideVariable = _topLevelVariable(
|
||||
var overrideVariable = _topLevelVariableConst(
|
||||
'override',
|
||||
_interfaceType(overrideElement),
|
||||
isConst: true,
|
||||
);
|
||||
|
||||
var proxyVariable = _topLevelVariable(
|
||||
var proxyVariable = _topLevelVariableConst(
|
||||
'proxy',
|
||||
_interfaceType(proxyElement),
|
||||
isConst: true,
|
||||
);
|
||||
|
||||
coreUnit.accessors = <PropertyAccessorElement>[
|
||||
|
@ -1121,14 +1118,12 @@ class _MockSdkElementsBuilder {
|
|||
.toList();
|
||||
}
|
||||
|
||||
TopLevelVariableElement _topLevelVariable(
|
||||
String name,
|
||||
DartType type, {
|
||||
bool isConst = false,
|
||||
bool isFinal = false,
|
||||
}) {
|
||||
return ElementFactory.topLevelVariableElement3(
|
||||
name, isConst, isFinal, type);
|
||||
TopLevelVariableElement _topLevelVariableConst(String name, DartType type) {
|
||||
final variable = ConstTopLevelVariableElementImpl(name, -1)
|
||||
..isConst = true
|
||||
..type = type;
|
||||
PropertyAccessorElementImpl_ImplicitGetter(variable);
|
||||
return variable;
|
||||
}
|
||||
|
||||
TypeParameterElementImpl _typeParameter(String name) {
|
||||
|
|
|
@ -12,6 +12,7 @@ import 'package:analyzer/src/dart/ast/utilities.dart';
|
|||
import 'package:analyzer/src/generated/testing/ast_test_factory.dart';
|
||||
import 'package:analyzer/src/generated/testing/token_factory.dart';
|
||||
import 'package:analyzer/src/summary2/ast_binary_tokens.dart';
|
||||
import 'package:analyzer/src/test_utilities/find_node.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
|
@ -790,28 +791,22 @@ var v = ^a[b] + c;
|
|||
}
|
||||
|
||||
void test_isNullAware_cascade_false() {
|
||||
final expression = AstTestFactory.indexExpressionForCascade(
|
||||
AstTestFactory.nullLiteral(),
|
||||
AstTestFactory.nullLiteral(),
|
||||
TokenType.PERIOD_PERIOD,
|
||||
TokenType.OPEN_SQUARE_BRACKET);
|
||||
AstTestFactory.cascadeExpression(
|
||||
AstTestFactory.nullLiteral(),
|
||||
[expression],
|
||||
);
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f() {
|
||||
a..[0];
|
||||
}
|
||||
''');
|
||||
final expression = findNode.index('[0]');
|
||||
expect(expression.isNullAware, isFalse);
|
||||
}
|
||||
|
||||
void test_isNullAware_cascade_true() {
|
||||
final expression = AstTestFactory.indexExpressionForCascade(
|
||||
AstTestFactory.nullLiteral(),
|
||||
AstTestFactory.nullLiteral(),
|
||||
TokenType.QUESTION_PERIOD_PERIOD,
|
||||
TokenType.OPEN_SQUARE_BRACKET);
|
||||
AstTestFactory.cascadeExpression(
|
||||
AstTestFactory.nullLiteral(),
|
||||
[expression],
|
||||
);
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f() {
|
||||
a?..[0];
|
||||
}
|
||||
''');
|
||||
final expression = findNode.index('[0]');
|
||||
expect(expression.isNullAware, isTrue);
|
||||
}
|
||||
|
||||
|
@ -1042,34 +1037,24 @@ class MethodDeclarationTest {
|
|||
}
|
||||
|
||||
@reflectiveTest
|
||||
class MethodInvocationTest extends ParserTestCase {
|
||||
class MethodInvocationTest extends _AstTest {
|
||||
void test_isNullAware_cascade() {
|
||||
var invocation = astFactory.methodInvocation(
|
||||
null,
|
||||
TokenFactory.tokenFromType(TokenType.PERIOD_PERIOD),
|
||||
AstTestFactory.identifier3('foo'),
|
||||
null,
|
||||
AstTestFactory.argumentList(),
|
||||
);
|
||||
AstTestFactory.cascadeExpression(
|
||||
AstTestFactory.nullLiteral(),
|
||||
[invocation],
|
||||
);
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f() {
|
||||
a..foo();
|
||||
}
|
||||
''');
|
||||
final invocation = findNode.methodInvocation('foo');
|
||||
expect(invocation.isNullAware, isFalse);
|
||||
}
|
||||
|
||||
void test_isNullAware_cascade_true() {
|
||||
var invocation = astFactory.methodInvocation(
|
||||
null,
|
||||
TokenFactory.tokenFromType(TokenType.QUESTION_PERIOD_PERIOD),
|
||||
AstTestFactory.identifier3('foo'),
|
||||
null,
|
||||
AstTestFactory.argumentList(),
|
||||
);
|
||||
AstTestFactory.cascadeExpression(
|
||||
AstTestFactory.nullLiteral(),
|
||||
[invocation],
|
||||
);
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f() {
|
||||
a?..foo();
|
||||
}
|
||||
''');
|
||||
final invocation = findNode.methodInvocation('foo');
|
||||
expect(invocation.isNullAware, isTrue);
|
||||
}
|
||||
|
||||
|
@ -1094,8 +1079,8 @@ class MethodInvocationTest extends ParserTestCase {
|
|||
class NodeListTest {
|
||||
void test_add() {
|
||||
AstNode parent = AstTestFactory.argumentList();
|
||||
AstNode firstNode = AstTestFactory.booleanLiteral(true);
|
||||
AstNode secondNode = AstTestFactory.booleanLiteral(false);
|
||||
AstNode firstNode = true_();
|
||||
AstNode secondNode = false_();
|
||||
NodeList<AstNode> list = astFactory.nodeList<AstNode>(parent);
|
||||
list.insert(0, secondNode);
|
||||
list.insert(0, firstNode);
|
||||
|
@ -1104,7 +1089,7 @@ class NodeListTest {
|
|||
expect(list[1], same(secondNode));
|
||||
expect(firstNode.parent, same(parent));
|
||||
expect(secondNode.parent, same(parent));
|
||||
AstNode thirdNode = AstTestFactory.booleanLiteral(false);
|
||||
AstNode thirdNode = false_();
|
||||
list.insert(1, thirdNode);
|
||||
expect(list, hasLength(3));
|
||||
expect(list[0], same(firstNode));
|
||||
|
@ -1119,7 +1104,7 @@ class NodeListTest {
|
|||
NodeList<AstNode> list =
|
||||
astFactory.nodeList<AstNode>(AstTestFactory.argumentList());
|
||||
try {
|
||||
list.insert(-1, AstTestFactory.booleanLiteral(true));
|
||||
list.insert(-1, true_());
|
||||
fail("Expected IndexOutOfBoundsException");
|
||||
} on RangeError {
|
||||
// Expected
|
||||
|
@ -1130,7 +1115,7 @@ class NodeListTest {
|
|||
NodeList<AstNode> list =
|
||||
astFactory.nodeList<AstNode>(AstTestFactory.argumentList());
|
||||
try {
|
||||
list.insert(1, AstTestFactory.booleanLiteral(true));
|
||||
list.insert(1, true_());
|
||||
fail("Expected IndexOutOfBoundsException");
|
||||
} on RangeError {
|
||||
// Expected
|
||||
|
@ -1140,8 +1125,8 @@ class NodeListTest {
|
|||
void test_addAll() {
|
||||
AstNode parent = AstTestFactory.argumentList();
|
||||
List<AstNode> firstNodes = <AstNode>[];
|
||||
AstNode firstNode = AstTestFactory.booleanLiteral(true);
|
||||
AstNode secondNode = AstTestFactory.booleanLiteral(false);
|
||||
AstNode firstNode = true_();
|
||||
AstNode secondNode = false_();
|
||||
firstNodes.add(firstNode);
|
||||
firstNodes.add(secondNode);
|
||||
NodeList<AstNode> list = astFactory.nodeList<AstNode>(parent);
|
||||
|
@ -1152,8 +1137,8 @@ class NodeListTest {
|
|||
expect(firstNode.parent, same(parent));
|
||||
expect(secondNode.parent, same(parent));
|
||||
List<AstNode> secondNodes = <AstNode>[];
|
||||
AstNode thirdNode = AstTestFactory.booleanLiteral(true);
|
||||
AstNode fourthNode = AstTestFactory.booleanLiteral(false);
|
||||
AstNode thirdNode = true_();
|
||||
AstNode fourthNode = false_();
|
||||
secondNodes.add(thirdNode);
|
||||
secondNodes.add(fourthNode);
|
||||
list.addAll(secondNodes);
|
||||
|
@ -1207,8 +1192,7 @@ class NodeListTest {
|
|||
void test_getBeginToken_nonEmpty() {
|
||||
NodeList<AstNode> list =
|
||||
astFactory.nodeList<AstNode>(AstTestFactory.argumentList());
|
||||
AstNode node = AstTestFactory.parenthesizedExpression(
|
||||
AstTestFactory.booleanLiteral(true));
|
||||
AstNode node = AstTestFactory.parenthesizedExpression(true_());
|
||||
list.add(node);
|
||||
expect(list.beginToken, same(node.beginToken));
|
||||
}
|
||||
|
@ -1222,18 +1206,17 @@ class NodeListTest {
|
|||
void test_getEndToken_nonEmpty() {
|
||||
NodeList<AstNode> list =
|
||||
astFactory.nodeList<AstNode>(AstTestFactory.argumentList());
|
||||
AstNode node = AstTestFactory.parenthesizedExpression(
|
||||
AstTestFactory.booleanLiteral(true));
|
||||
AstNode node = AstTestFactory.parenthesizedExpression(true_());
|
||||
list.add(node);
|
||||
expect(list.endToken, same(node.endToken));
|
||||
}
|
||||
|
||||
void test_indexOf() {
|
||||
List<AstNode> nodes = <AstNode>[];
|
||||
AstNode firstNode = AstTestFactory.booleanLiteral(true);
|
||||
AstNode secondNode = AstTestFactory.booleanLiteral(false);
|
||||
AstNode thirdNode = AstTestFactory.booleanLiteral(true);
|
||||
AstNode fourthNode = AstTestFactory.booleanLiteral(false);
|
||||
AstNode firstNode = true_();
|
||||
AstNode secondNode = false_();
|
||||
AstNode thirdNode = true_();
|
||||
AstNode fourthNode = false_();
|
||||
nodes.add(firstNode);
|
||||
nodes.add(secondNode);
|
||||
nodes.add(thirdNode);
|
||||
|
@ -1249,9 +1232,9 @@ class NodeListTest {
|
|||
|
||||
void test_remove() {
|
||||
List<AstNode> nodes = <AstNode>[];
|
||||
AstNode firstNode = AstTestFactory.booleanLiteral(true);
|
||||
AstNode secondNode = AstTestFactory.booleanLiteral(false);
|
||||
AstNode thirdNode = AstTestFactory.booleanLiteral(true);
|
||||
AstNode firstNode = true_();
|
||||
AstNode secondNode = false_();
|
||||
AstNode thirdNode = true_();
|
||||
nodes.add(firstNode);
|
||||
nodes.add(secondNode);
|
||||
nodes.add(thirdNode);
|
||||
|
@ -1289,9 +1272,9 @@ class NodeListTest {
|
|||
|
||||
void test_set() {
|
||||
List<AstNode> nodes = <AstNode>[];
|
||||
AstNode firstNode = AstTestFactory.booleanLiteral(true);
|
||||
AstNode secondNode = AstTestFactory.booleanLiteral(false);
|
||||
AstNode thirdNode = AstTestFactory.booleanLiteral(true);
|
||||
AstNode firstNode = true_();
|
||||
AstNode secondNode = false_();
|
||||
AstNode thirdNode = true_();
|
||||
nodes.add(firstNode);
|
||||
nodes.add(secondNode);
|
||||
nodes.add(thirdNode);
|
||||
|
@ -1307,7 +1290,7 @@ class NodeListTest {
|
|||
}
|
||||
|
||||
void test_set_negative() {
|
||||
AstNode node = AstTestFactory.booleanLiteral(true);
|
||||
AstNode node = true_();
|
||||
var list = astFactory.nodeList<AstNode>(AstTestFactory.argumentList());
|
||||
try {
|
||||
list[-1] = node;
|
||||
|
@ -1318,7 +1301,7 @@ class NodeListTest {
|
|||
}
|
||||
|
||||
void test_set_tooBig() {
|
||||
AstNode node = AstTestFactory.booleanLiteral(true);
|
||||
AstNode node = true_();
|
||||
var list = astFactory.nodeList<AstNode>(AstTestFactory.argumentList());
|
||||
try {
|
||||
list[1] = node;
|
||||
|
@ -1327,6 +1310,20 @@ class NodeListTest {
|
|||
// Expected
|
||||
}
|
||||
}
|
||||
|
||||
static BooleanLiteralImpl false_() {
|
||||
return BooleanLiteralImpl(
|
||||
literal: Tokens.true_(),
|
||||
value: true,
|
||||
);
|
||||
}
|
||||
|
||||
static BooleanLiteralImpl true_() {
|
||||
return BooleanLiteralImpl(
|
||||
literal: Tokens.true_(),
|
||||
value: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
|
@ -1431,24 +1428,24 @@ E f() => g;
|
|||
}
|
||||
|
||||
@reflectiveTest
|
||||
class PropertyAccessTest extends ParserTestCase {
|
||||
class PropertyAccessTest extends _AstTest {
|
||||
void test_isNullAware_cascade() {
|
||||
final invocation = AstTestFactory.propertyAccess2(
|
||||
AstTestFactory.nullLiteral(), 'foo', TokenType.PERIOD_PERIOD);
|
||||
AstTestFactory.cascadeExpression(
|
||||
AstTestFactory.nullLiteral(),
|
||||
[invocation],
|
||||
);
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f() {
|
||||
a..foo;
|
||||
}
|
||||
''');
|
||||
final invocation = findNode.propertyAccess('foo');
|
||||
expect(invocation.isNullAware, isFalse);
|
||||
}
|
||||
|
||||
void test_isNullAware_cascade_true() {
|
||||
final invocation = AstTestFactory.propertyAccess2(
|
||||
null, 'foo', TokenType.QUESTION_PERIOD_PERIOD);
|
||||
AstTestFactory.cascadeExpression(
|
||||
AstTestFactory.nullLiteral(),
|
||||
[invocation],
|
||||
);
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f() {
|
||||
a?..foo;
|
||||
}
|
||||
''');
|
||||
final invocation = findNode.propertyAccess('foo');
|
||||
expect(invocation.isNullAware, isTrue);
|
||||
}
|
||||
|
||||
|
@ -1487,9 +1484,11 @@ class SimpleIdentifierTest extends _AstTest {
|
|||
}
|
||||
|
||||
void test_inGetterContext_constructorFieldInitializer() {
|
||||
ConstructorFieldInitializer initializer =
|
||||
AstTestFactory.constructorFieldInitializer(
|
||||
false, 'f', AstTestFactory.integer(0));
|
||||
final initializer = _parseStringToNode<ConstructorFieldInitializer>('''
|
||||
class A {
|
||||
A() : ^f = 0;
|
||||
}
|
||||
''');
|
||||
SimpleIdentifier identifier = initializer.fieldName;
|
||||
expect(identifier.inGetterContext(), isFalse);
|
||||
}
|
||||
|
@ -1560,9 +1559,10 @@ class SimpleIdentifierTest extends _AstTest {
|
|||
}
|
||||
|
||||
void test_isQualified_inConstructorName() {
|
||||
ConstructorName constructor = AstTestFactory.constructorName(
|
||||
AstTestFactory.namedType4('MyClass'), "test");
|
||||
SimpleIdentifier name = constructor.name!;
|
||||
final constructor = _parseStringToNode<ConstructorName>(r'''
|
||||
final x = List<String>.^foo();
|
||||
''');
|
||||
final name = constructor.name!;
|
||||
expect(name.isQualified, isTrue);
|
||||
}
|
||||
|
||||
|
@ -2207,6 +2207,14 @@ class _AssignmentKind {
|
|||
}
|
||||
|
||||
class _AstTest {
|
||||
FindNode _parseStringToFindNode(String content) {
|
||||
var parseResult = parseString(
|
||||
content: content,
|
||||
featureSet: FeatureSets.latestWithExperiments,
|
||||
);
|
||||
return FindNode(parseResult.content, parseResult.unit);
|
||||
}
|
||||
|
||||
T _parseStringToNode<T extends AstNode>(String codeWithMark) {
|
||||
var offset = codeWithMark.indexOf('^');
|
||||
expect(offset, isNot(equals(-1)), reason: 'missing ^');
|
||||
|
|
|
@ -200,46 +200,73 @@ void f() $code
|
|||
}
|
||||
|
||||
void test_visitBooleanLiteral_false() {
|
||||
_assertSource("false", AstTestFactory.booleanLiteral(false));
|
||||
final code = 'false';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
final v = $code;
|
||||
''');
|
||||
_assertSource(code, findNode.booleanLiteral(code));
|
||||
}
|
||||
|
||||
void test_visitBooleanLiteral_true() {
|
||||
_assertSource("true", AstTestFactory.booleanLiteral(true));
|
||||
final code = 'true';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
final v = $code;
|
||||
''');
|
||||
_assertSource(code, findNode.booleanLiteral(code));
|
||||
}
|
||||
|
||||
void test_visitBreakStatement_label() {
|
||||
_assertSource("break l;", AstTestFactory.breakStatement2("l"));
|
||||
final code = 'break L;';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f() {
|
||||
L: while (true) {
|
||||
$code
|
||||
}
|
||||
}
|
||||
''');
|
||||
_assertSource(code, findNode.breakStatement(code));
|
||||
}
|
||||
|
||||
void test_visitBreakStatement_noLabel() {
|
||||
_assertSource("break;", AstTestFactory.breakStatement());
|
||||
final code = 'break;';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f() {
|
||||
while (true) {
|
||||
$code
|
||||
}
|
||||
}
|
||||
''');
|
||||
_assertSource(code, findNode.breakStatement(code));
|
||||
}
|
||||
|
||||
void test_visitCascadeExpression_field() {
|
||||
_assertSource(
|
||||
"a..b..c",
|
||||
AstTestFactory.cascadeExpression(AstTestFactory.identifier3("a"), [
|
||||
AstTestFactory.cascadedPropertyAccess("b"),
|
||||
AstTestFactory.cascadedPropertyAccess("c")
|
||||
]));
|
||||
final code = 'a..b..c';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f() {
|
||||
$code;
|
||||
}
|
||||
''');
|
||||
_assertSource(code, findNode.cascade(code));
|
||||
}
|
||||
|
||||
void test_visitCascadeExpression_index() {
|
||||
_assertSource(
|
||||
"a..[0]..[1]",
|
||||
AstTestFactory.cascadeExpression(AstTestFactory.identifier3("a"), [
|
||||
AstTestFactory.cascadedIndexExpression(AstTestFactory.integer(0)),
|
||||
AstTestFactory.cascadedIndexExpression(AstTestFactory.integer(1))
|
||||
]));
|
||||
final code = 'a..[0]..[1]';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f() {
|
||||
$code;
|
||||
}
|
||||
''');
|
||||
_assertSource(code, findNode.cascade(code));
|
||||
}
|
||||
|
||||
void test_visitCascadeExpression_method() {
|
||||
_assertSource(
|
||||
"a..b()..c()",
|
||||
AstTestFactory.cascadeExpression(AstTestFactory.identifier3("a"), [
|
||||
AstTestFactory.cascadedMethodInvocation("b"),
|
||||
AstTestFactory.cascadedMethodInvocation("c")
|
||||
]));
|
||||
final code = 'a..b()..c()';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f() {
|
||||
$code;
|
||||
}
|
||||
''');
|
||||
_assertSource(code, findNode.cascade(code));
|
||||
}
|
||||
|
||||
void test_visitCatchClause_catch_noStack() {
|
||||
|
@ -640,8 +667,12 @@ macro class A = S with M;
|
|||
}
|
||||
|
||||
void test_visitCommentReference() {
|
||||
_assertSource(
|
||||
"", astFactory.commentReference(null, AstTestFactory.identifier3("a")));
|
||||
final code = 'x';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
/// [$code]
|
||||
void f() {}
|
||||
''');
|
||||
_assertSource('', findNode.commentReference(code));
|
||||
}
|
||||
|
||||
void test_visitCompilationUnit_declaration() {
|
||||
|
@ -708,10 +739,13 @@ macro class A = S with M;
|
|||
}
|
||||
|
||||
void test_visitConditionalExpression() {
|
||||
_assertSource(
|
||||
"a ? b : c",
|
||||
AstTestFactory.conditionalExpression(AstTestFactory.identifier3("a"),
|
||||
AstTestFactory.identifier3("b"), AstTestFactory.identifier3("c")));
|
||||
final code = 'a ? b : c';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f() {
|
||||
$code;
|
||||
}
|
||||
''');
|
||||
_assertSource(code, findNode.conditionalExpression(code));
|
||||
}
|
||||
|
||||
void test_visitConstructorDeclaration_const() {
|
||||
|
@ -792,45 +826,71 @@ class C {
|
|||
}
|
||||
|
||||
void test_visitConstructorFieldInitializer_withoutThis() {
|
||||
_assertSource(
|
||||
"a = b",
|
||||
AstTestFactory.constructorFieldInitializer(
|
||||
false, "a", AstTestFactory.identifier3("b")));
|
||||
final code = 'a = 0';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
class C {
|
||||
C() : $code;
|
||||
}
|
||||
''');
|
||||
_assertSource(code, findNode.constructorFieldInitializer(code));
|
||||
}
|
||||
|
||||
void test_visitConstructorFieldInitializer_withThis() {
|
||||
_assertSource(
|
||||
"this.a = b",
|
||||
AstTestFactory.constructorFieldInitializer(
|
||||
true, "a", AstTestFactory.identifier3("b")));
|
||||
final code = 'this.a = 0';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
class C {
|
||||
C() : $code;
|
||||
}
|
||||
''');
|
||||
_assertSource(code, findNode.constructorFieldInitializer(code));
|
||||
}
|
||||
|
||||
void test_visitConstructorName_named_prefix() {
|
||||
_assertSource(
|
||||
"p.C.n",
|
||||
AstTestFactory.constructorName(
|
||||
AstTestFactory.namedType4("p.C.n"), null));
|
||||
final code = 'prefix.A.foo';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
final x = new $code();
|
||||
''');
|
||||
_assertSource(code, findNode.constructorName(code));
|
||||
}
|
||||
|
||||
void test_visitConstructorName_unnamed_noPrefix() {
|
||||
_assertSource("C",
|
||||
AstTestFactory.constructorName(AstTestFactory.namedType4("C"), null));
|
||||
final code = 'A';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
final x = new $code();
|
||||
''');
|
||||
_assertSource(code, findNode.constructorName(code));
|
||||
}
|
||||
|
||||
void test_visitConstructorName_unnamed_prefix() {
|
||||
_assertSource(
|
||||
"p.C",
|
||||
AstTestFactory.constructorName(
|
||||
AstTestFactory.namedType3(AstTestFactory.identifier5("p", "C")),
|
||||
null));
|
||||
final code = 'prefix.A';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
final x = new $code();
|
||||
''');
|
||||
_assertSource(code, findNode.constructorName(code));
|
||||
}
|
||||
|
||||
void test_visitContinueStatement_label() {
|
||||
_assertSource("continue l;", AstTestFactory.continueStatement("l"));
|
||||
final code = 'continue L;';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f() {
|
||||
L: while (true) {
|
||||
$code
|
||||
}
|
||||
}
|
||||
''');
|
||||
_assertSource(code, findNode.continueStatement('continue'));
|
||||
}
|
||||
|
||||
void test_visitContinueStatement_noLabel() {
|
||||
_assertSource("continue;", AstTestFactory.continueStatement());
|
||||
final code = 'continue;';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f() {
|
||||
while (true) {
|
||||
$code
|
||||
}
|
||||
}
|
||||
''');
|
||||
_assertSource(code, findNode.continueStatement('continue'));
|
||||
}
|
||||
|
||||
void test_visitDefaultFormalParameter_annotation() {
|
||||
|
@ -842,33 +902,35 @@ void f([$code]) {}
|
|||
}
|
||||
|
||||
void test_visitDefaultFormalParameter_named_noValue() {
|
||||
_assertSource(
|
||||
"p",
|
||||
AstTestFactory.namedFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter3("p"), null));
|
||||
final code = 'int? a';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f({$code}) {}
|
||||
''');
|
||||
_assertSource(code, findNode.defaultParameter(code));
|
||||
}
|
||||
|
||||
void test_visitDefaultFormalParameter_named_value() {
|
||||
_assertSource(
|
||||
"p: 0",
|
||||
AstTestFactory.namedFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter3("p"),
|
||||
AstTestFactory.integer(0)));
|
||||
final code = 'int? a = 0';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f({$code}) {}
|
||||
''');
|
||||
_assertSource(code, findNode.defaultParameter(code));
|
||||
}
|
||||
|
||||
void test_visitDefaultFormalParameter_positional_noValue() {
|
||||
_assertSource(
|
||||
"p",
|
||||
AstTestFactory.positionalFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter3("p"), null));
|
||||
final code = 'int? a';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f([$code]) {}
|
||||
''');
|
||||
_assertSource(code, findNode.defaultParameter(code));
|
||||
}
|
||||
|
||||
void test_visitDefaultFormalParameter_positional_value() {
|
||||
_assertSource(
|
||||
"p = 0",
|
||||
AstTestFactory.positionalFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter3("p"),
|
||||
AstTestFactory.integer(0)));
|
||||
final code = 'int? a = 0';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f([$code]) {}
|
||||
''');
|
||||
_assertSource(code, findNode.defaultParameter(code));
|
||||
}
|
||||
|
||||
void test_visitDoStatement() {
|
||||
|
@ -1546,67 +1608,43 @@ void f() async {
|
|||
}
|
||||
|
||||
void test_visitFormalParameterList_n() {
|
||||
_assertSource(
|
||||
"({a: 0})",
|
||||
AstTestFactory.formalParameterList([
|
||||
AstTestFactory.namedFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter3("a"),
|
||||
AstTestFactory.integer(0))
|
||||
]));
|
||||
final code = '({a = 0})';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f$code {}
|
||||
''');
|
||||
_assertSource(code, findNode.formalParameterList(code));
|
||||
}
|
||||
|
||||
void test_visitFormalParameterList_namedRequired() {
|
||||
_assertSource(
|
||||
"({required a, required A b})",
|
||||
AstTestFactory.formalParameterList([
|
||||
AstTestFactory.namedFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter3("a")
|
||||
..requiredKeyword =
|
||||
TokenFactory.tokenFromKeyword(Keyword.REQUIRED),
|
||||
null),
|
||||
AstTestFactory.namedFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter2(
|
||||
null, AstTestFactory.namedType4('A'), "b")
|
||||
..requiredKeyword =
|
||||
TokenFactory.tokenFromKeyword(Keyword.REQUIRED),
|
||||
null),
|
||||
]));
|
||||
final code = '({required a, required int b})';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f$code {}
|
||||
''');
|
||||
_assertSource(code, findNode.formalParameterList(code));
|
||||
}
|
||||
|
||||
void test_visitFormalParameterList_nn() {
|
||||
_assertSource(
|
||||
"({a: 0, b: 1})",
|
||||
AstTestFactory.formalParameterList([
|
||||
AstTestFactory.namedFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter3("a"),
|
||||
AstTestFactory.integer(0)),
|
||||
AstTestFactory.namedFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter3("b"),
|
||||
AstTestFactory.integer(1))
|
||||
]));
|
||||
final code = '({int a = 0, b = 1})';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f$code {}
|
||||
''');
|
||||
_assertSource(code, findNode.formalParameterList(code));
|
||||
}
|
||||
|
||||
void test_visitFormalParameterList_p() {
|
||||
_assertSource(
|
||||
"([a = 0])",
|
||||
AstTestFactory.formalParameterList([
|
||||
AstTestFactory.positionalFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter3("a"),
|
||||
AstTestFactory.integer(0))
|
||||
]));
|
||||
final code = '([a = 0])';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f$code {}
|
||||
''');
|
||||
_assertSource(code, findNode.formalParameterList(code));
|
||||
}
|
||||
|
||||
void test_visitFormalParameterList_pp() {
|
||||
_assertSource(
|
||||
"([a = 0, b = 1])",
|
||||
AstTestFactory.formalParameterList([
|
||||
AstTestFactory.positionalFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter3("a"),
|
||||
AstTestFactory.integer(0)),
|
||||
AstTestFactory.positionalFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter3("b"),
|
||||
AstTestFactory.integer(1))
|
||||
]));
|
||||
final code = '([a = 0, b = 1])';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f$code {}
|
||||
''');
|
||||
_assertSource(code, findNode.formalParameterList(code));
|
||||
}
|
||||
|
||||
void test_visitFormalParameterList_r() {
|
||||
|
@ -1617,53 +1655,35 @@ void f() async {
|
|||
}
|
||||
|
||||
void test_visitFormalParameterList_rn() {
|
||||
_assertSource(
|
||||
"(a, {b: 1})",
|
||||
AstTestFactory.formalParameterList([
|
||||
AstTestFactory.simpleFormalParameter3("a"),
|
||||
AstTestFactory.namedFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter3("b"),
|
||||
AstTestFactory.integer(1))
|
||||
]));
|
||||
final code = '(a, {b = 1})';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f$code {}
|
||||
''');
|
||||
_assertSource(code, findNode.formalParameterList(code));
|
||||
}
|
||||
|
||||
void test_visitFormalParameterList_rnn() {
|
||||
_assertSource(
|
||||
"(a, {b: 1, c: 2})",
|
||||
AstTestFactory.formalParameterList([
|
||||
AstTestFactory.simpleFormalParameter3("a"),
|
||||
AstTestFactory.namedFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter3("b"),
|
||||
AstTestFactory.integer(1)),
|
||||
AstTestFactory.namedFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter3("c"),
|
||||
AstTestFactory.integer(2))
|
||||
]));
|
||||
final code = '(a, {b = 1, c = 2})';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f$code {}
|
||||
''');
|
||||
_assertSource(code, findNode.formalParameterList(code));
|
||||
}
|
||||
|
||||
void test_visitFormalParameterList_rp() {
|
||||
_assertSource(
|
||||
"(a, [b = 1])",
|
||||
AstTestFactory.formalParameterList([
|
||||
AstTestFactory.simpleFormalParameter3("a"),
|
||||
AstTestFactory.positionalFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter3("b"),
|
||||
AstTestFactory.integer(1))
|
||||
]));
|
||||
final code = '(a, [b = 1])';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f$code {}
|
||||
''');
|
||||
_assertSource(code, findNode.formalParameterList(code));
|
||||
}
|
||||
|
||||
void test_visitFormalParameterList_rpp() {
|
||||
_assertSource(
|
||||
"(a, [b = 1, c = 2])",
|
||||
AstTestFactory.formalParameterList([
|
||||
AstTestFactory.simpleFormalParameter3("a"),
|
||||
AstTestFactory.positionalFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter3("b"),
|
||||
AstTestFactory.integer(1)),
|
||||
AstTestFactory.positionalFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter3("c"),
|
||||
AstTestFactory.integer(2))
|
||||
]));
|
||||
final code = '(a, [b = 1, c = 2])';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f$code {}
|
||||
''');
|
||||
_assertSource(code, findNode.formalParameterList(code));
|
||||
}
|
||||
|
||||
void test_visitFormalParameterList_rr() {
|
||||
|
@ -1676,57 +1696,35 @@ void f() async {
|
|||
}
|
||||
|
||||
void test_visitFormalParameterList_rrn() {
|
||||
_assertSource(
|
||||
"(a, b, {c: 3})",
|
||||
AstTestFactory.formalParameterList([
|
||||
AstTestFactory.simpleFormalParameter3("a"),
|
||||
AstTestFactory.simpleFormalParameter3("b"),
|
||||
AstTestFactory.namedFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter3("c"),
|
||||
AstTestFactory.integer(3))
|
||||
]));
|
||||
final code = '(a, b, {c = 2})';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f$code {}
|
||||
''');
|
||||
_assertSource(code, findNode.formalParameterList(code));
|
||||
}
|
||||
|
||||
void test_visitFormalParameterList_rrnn() {
|
||||
_assertSource(
|
||||
"(a, b, {c: 3, d: 4})",
|
||||
AstTestFactory.formalParameterList([
|
||||
AstTestFactory.simpleFormalParameter3("a"),
|
||||
AstTestFactory.simpleFormalParameter3("b"),
|
||||
AstTestFactory.namedFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter3("c"),
|
||||
AstTestFactory.integer(3)),
|
||||
AstTestFactory.namedFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter3("d"),
|
||||
AstTestFactory.integer(4))
|
||||
]));
|
||||
final code = '(a, b, {c = 2, d = 3})';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f$code {}
|
||||
''');
|
||||
_assertSource(code, findNode.formalParameterList(code));
|
||||
}
|
||||
|
||||
void test_visitFormalParameterList_rrp() {
|
||||
_assertSource(
|
||||
"(a, b, [c = 3])",
|
||||
AstTestFactory.formalParameterList([
|
||||
AstTestFactory.simpleFormalParameter3("a"),
|
||||
AstTestFactory.simpleFormalParameter3("b"),
|
||||
AstTestFactory.positionalFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter3("c"),
|
||||
AstTestFactory.integer(3))
|
||||
]));
|
||||
final code = '(a, b, [c = 2])';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f$code {}
|
||||
''');
|
||||
_assertSource(code, findNode.formalParameterList(code));
|
||||
}
|
||||
|
||||
void test_visitFormalParameterList_rrpp() {
|
||||
_assertSource(
|
||||
"(a, b, [c = 3, d = 4])",
|
||||
AstTestFactory.formalParameterList([
|
||||
AstTestFactory.simpleFormalParameter3("a"),
|
||||
AstTestFactory.simpleFormalParameter3("b"),
|
||||
AstTestFactory.positionalFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter3("c"),
|
||||
AstTestFactory.integer(3)),
|
||||
AstTestFactory.positionalFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter3("d"),
|
||||
AstTestFactory.integer(4))
|
||||
]));
|
||||
final code = '(a, b, [c = 2, d = 3])';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f$code {}
|
||||
''');
|
||||
_assertSource(code, findNode.formalParameterList(code));
|
||||
}
|
||||
|
||||
void test_visitForPartsWithDeclarations() {
|
||||
|
@ -2257,24 +2255,27 @@ import 'foo.dart'
|
|||
}
|
||||
|
||||
void test_visitInstanceCreationExpression_const() {
|
||||
_assertSource(
|
||||
"const C()",
|
||||
AstTestFactory.instanceCreationExpression2(
|
||||
Keyword.CONST, AstTestFactory.namedType4("C")));
|
||||
final code = 'const A()';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
final x = $code;
|
||||
''');
|
||||
_assertSource(code, findNode.instanceCreation(code));
|
||||
}
|
||||
|
||||
void test_visitInstanceCreationExpression_named() {
|
||||
_assertSource(
|
||||
"new C.c()",
|
||||
AstTestFactory.instanceCreationExpression3(
|
||||
Keyword.NEW, AstTestFactory.namedType4("C"), "c"));
|
||||
final code = 'new A.foo()';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
final x = $code;
|
||||
''');
|
||||
_assertSource(code, findNode.instanceCreation(code));
|
||||
}
|
||||
|
||||
void test_visitInstanceCreationExpression_unnamed() {
|
||||
_assertSource(
|
||||
"new C()",
|
||||
AstTestFactory.instanceCreationExpression2(
|
||||
Keyword.NEW, AstTestFactory.namedType4("C")));
|
||||
final code = 'new A()';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
final x = $code;
|
||||
''');
|
||||
_assertSource(code, findNode.instanceCreation(code));
|
||||
}
|
||||
|
||||
void test_visitIntegerLiteral() {
|
||||
|
@ -2666,11 +2667,11 @@ class A {
|
|||
}
|
||||
|
||||
void test_visitNamedFormalParameter() {
|
||||
_assertSource(
|
||||
"var a: 0",
|
||||
AstTestFactory.namedFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter(Keyword.VAR, "a"),
|
||||
AstTestFactory.integer(0)));
|
||||
final code = 'var a = 0';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f({$code}) {}
|
||||
''');
|
||||
_assertSource(code, findNode.defaultParameter(code));
|
||||
}
|
||||
|
||||
void test_visitNativeClause() {
|
||||
|
@ -2721,11 +2722,11 @@ class A {
|
|||
}
|
||||
|
||||
void test_visitPositionalFormalParameter() {
|
||||
_assertSource(
|
||||
"var a = 0",
|
||||
AstTestFactory.positionalFormalParameter(
|
||||
AstTestFactory.simpleFormalParameter(Keyword.VAR, "a"),
|
||||
AstTestFactory.integer(0)));
|
||||
final code = 'var a = 0';
|
||||
final findNode = _parseStringToFindNode('''
|
||||
void f([$code]) {}
|
||||
''');
|
||||
_assertSource(code, findNode.defaultParameter(code));
|
||||
}
|
||||
|
||||
void test_visitPostfixExpression() {
|
||||
|
|
Loading…
Reference in a new issue