Skip to content

Commit

Permalink
Version 2.19.0-227.0.dev
Browse files Browse the repository at this point in the history
Merge 46bc947 into dev
  • Loading branch information
Dart CI committed Sep 21, 2022
2 parents 66b1c83 + 46bc947 commit 5d47306
Show file tree
Hide file tree
Showing 33 changed files with 504 additions and 343 deletions.
10 changes: 10 additions & 0 deletions pkg/analyzer/lib/dart/analysis/code_style_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +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.

import 'package:analyzer/dart/ast/ast.dart';

/// A set of options related to coding style that apply to the code within a
/// single analysis context.
///
Expand All @@ -14,6 +16,10 @@ abstract class CodeStyleOptions {
/// Return `true` if local variables should be `final` whenever possible.
bool get makeLocalsFinal;

/// Return the preferred quote based on the enabled lints,otherwise a single
/// quote.
String get preferredQuoteForStrings;

/// Return `true` if constructors should be sorted first, before other
/// class members.
bool get sortConstructorsFirst;
Expand All @@ -25,4 +31,8 @@ abstract class CodeStyleOptions {
/// Return `true` if URIs should be "relative", meaning without a scheme,
/// whenever possible.
bool get useRelativeUris;

/// Return the preferred quote based on the enabled lints, otherwise based
/// on the first directive, otherwise a single quote.
String preferredQuoteForUris(List<ImportDirective> directives);
}
24 changes: 24 additions & 0 deletions pkg/analyzer/lib/src/analysis_options/code_style_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import 'package:analyzer/dart/analysis/analysis_options.dart';
import 'package:analyzer/dart/analysis/code_style_options.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:collection/collection.dart';

/// The concrete implementation of [CodeStyleOptions].
class CodeStyleOptionsImpl implements CodeStyleOptions {
Expand All @@ -22,12 +24,34 @@ class CodeStyleOptionsImpl implements CodeStyleOptions {
@override
bool get makeLocalsFinal => _isLintEnabled('prefer_final_locals');

@override
String get preferredQuoteForStrings => _lintQuote() ?? "'";

@override
bool get sortConstructorsFirst => _isLintEnabled('sort_constructors_first');

@override
bool get useRelativeUris => _isLintEnabled('prefer_relative_imports');

@override
String preferredQuoteForUris(List<ImportDirective> directives) {
var lintQuote = _lintQuote();
if (lintQuote != null) {
return lintQuote;
}
var uri = directives.firstOrNull?.uri;
var doubleQuote = uri is SimpleStringLiteral &&
uri.literal.value().toString().startsWith('"');
return doubleQuote ? '"' : "'";
}

/// Return `true` if the lint with the given [name] is enabled.
bool _isLintEnabled(String name) => options.isLintEnabled(name);

/// Return the preferred lint quote, otherwise `null`.
String? _lintQuote() => _isLintEnabled("prefer_single_quotes")
? "'"
: _isLintEnabled("prefer_double_quotes")
? '"'
: null;
}
38 changes: 19 additions & 19 deletions pkg/analyzer/lib/src/dart/ast/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8833,31 +8833,26 @@ abstract class NamespaceDirectiveImpl extends UriBasedDirectiveImpl
/// nativeClause ::=
/// 'native' [StringLiteral]
class NativeClauseImpl extends AstNodeImpl implements NativeClause {
/// The token representing the 'native' keyword.
@override
Token nativeKeyword;
final Token nativeKeyword;

/// The name of the native object that implements the class.
StringLiteralImpl? _name;
@override
final StringLiteralImpl? name;

/// Initialize a newly created native clause.
NativeClauseImpl(this.nativeKeyword, this._name) {
_becomeParentOf(_name);
NativeClauseImpl({
required this.nativeKeyword,
required this.name,
}) {
_becomeParentOf(name);
}

@override
Token get beginToken => nativeKeyword;

@override
Token get endToken {
return _name?.endToken ?? nativeKeyword;
}

@override
StringLiteralImpl? get name => _name;

set name(StringLiteral? name) {
_name = _becomeParentOf(name as StringLiteralImpl?);
return name?.endToken ?? nativeKeyword;
}

@override
Expand All @@ -8870,7 +8865,7 @@ class NativeClauseImpl extends AstNodeImpl implements NativeClause {

@override
void visitChildren(AstVisitor visitor) {
_name?.accept(visitor);
name?.accept(visitor);
}
}

Expand Down Expand Up @@ -9154,10 +9149,12 @@ abstract class NormalFormalParameterImpl extends FormalParameterImpl
class NullLiteralImpl extends LiteralImpl implements NullLiteral {
/// The token representing the literal.
@override
Token literal;
final Token literal;

/// Initialize a newly created null literal.
NullLiteralImpl(this.literal);
NullLiteralImpl({
required this.literal,
});

@override
Token get beginToken => literal;
Expand Down Expand Up @@ -9216,13 +9213,16 @@ mixin NullShortableExpressionImpl implements NullShortableExpression {
/// 'on' [TypeName] (',' [TypeName])*
class OnClauseImpl extends AstNodeImpl implements OnClause {
@override
Token onKeyword;
final Token onKeyword;

/// The classes are super-class constraints for the mixin.
final NodeListImpl<NamedType> _superclassConstraints = NodeListImpl._();

/// Initialize a newly created on clause.
OnClauseImpl(this.onKeyword, List<NamedType> superclassConstraints) {
OnClauseImpl({
required this.onKeyword,
required List<NamedType> superclassConstraints,
}) {
_superclassConstraints._initialize(this, superclassConstraints);
}

Expand Down
9 changes: 0 additions & 9 deletions pkg/analyzer/lib/src/dart/ast/ast_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,6 @@ class AstFactoryImpl {
rightBracket);
}

NativeClauseImpl nativeClause(Token nativeKeyword, StringLiteral? name) =>
NativeClauseImpl(nativeKeyword, name as StringLiteralImpl?);

NativeFunctionBodyImpl nativeFunctionBody(
Token nativeKeyword, StringLiteral? stringLiteral, Token semicolon) =>
NativeFunctionBodyImpl(
Expand All @@ -194,12 +191,6 @@ class AstFactoryImpl {
NodeListImpl<E> nodeList<E extends AstNode>(AstNode owner) =>
NodeListImpl<E>(owner as AstNodeImpl);

NullLiteralImpl nullLiteral(Token literal) => NullLiteralImpl(literal);

OnClauseImpl onClause(
Token onKeyword, List<NamedType> superclassConstraints) =>
OnClauseImpl(onKeyword, superclassConstraints);

ParenthesizedExpressionImpl parenthesizedExpression(Token leftParenthesis,
Expression expression, Token rightParenthesis) =>
ParenthesizedExpressionImpl(
Expand Down
9 changes: 0 additions & 9 deletions pkg/analyzer/lib/src/dart/ast/utilities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2904,15 +2904,6 @@ class NodeReplacer extends ThrowingAstVisitor<bool> {
return visitUriBasedDirective(node);
}

@override
bool visitNativeClause(covariant NativeClauseImpl node) {
if (identical(node.name, _oldNode)) {
node.name = _newNode as StringLiteral;
return true;
}
return visitNode(node);
}

@override
bool visitNativeFunctionBody(covariant NativeFunctionBodyImpl node) {
if (identical(node.stringLiteral, _oldNode)) {
Expand Down
10 changes: 10 additions & 0 deletions pkg/analyzer/lib/src/dart/constant/potentially_constant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ class _Collector {
return;
}

if (node is RecordLiteral) {
return _recordLiteral(node);
}

if (node is MethodInvocation) {
return _methodInvocation(node);
}
Expand Down Expand Up @@ -309,6 +313,12 @@ class _Collector {
nodes.add(node);
}

void _recordLiteral(RecordLiteral node) {
for (final field in node.fields) {
collect(field);
}
}

void _typeArgumentList(TypeArgumentList? typeArgumentList) {
var typeArguments = typeArgumentList?.arguments;
if (typeArguments != null) {
Expand Down
26 changes: 19 additions & 7 deletions pkg/analyzer/lib/src/fasta/ast_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class AstBuilder extends StackListener {
// * The current library has an import that uses the scheme "dart-ext".
bool allowNativeClause = false;

StringLiteral? nativeName;
StringLiteralImpl? nativeName;

bool parseFunctionBodies = true;

Expand Down Expand Up @@ -3247,7 +3247,10 @@ class AstBuilder extends StackListener {

NativeClauseImpl? nativeClause;
if (nativeToken != null) {
nativeClause = ast.nativeClause(nativeToken, nativeName);
nativeClause = NativeClauseImpl(
nativeKeyword: nativeToken,
name: nativeName,
);
}
var implementsClause =
pop(NullValue.IdentifierList) as ImplementsClauseImpl?;
Expand Down Expand Up @@ -4039,7 +4042,11 @@ class AstBuilder extends StackListener {
assert(optional('null', token));
debugEvent("LiteralNull");

push(ast.nullLiteral(token));
push(
NullLiteralImpl(
literal: token,
),
);
}

@override
Expand Down Expand Up @@ -4103,7 +4110,12 @@ class AstBuilder extends StackListener {
final onTypes = _popNamedTypeList(
errorCode: ParserErrorCode.EXPECTED_NAMED_TYPE_ON,
);
push(ast.onClause(onKeyword, onTypes));
push(
OnClauseImpl(
onKeyword: onKeyword,
superclassConstraints: onTypes,
),
);
} else {
push(NullValue.IdentifierList);
}
Expand Down Expand Up @@ -4144,7 +4156,7 @@ class AstBuilder extends StackListener {
debugEvent("NativeClause");

if (hasName) {
nativeName = pop() as StringLiteral; // StringLiteral
nativeName = pop() as StringLiteralImpl;
} else {
nativeName = null;
}
Expand Down Expand Up @@ -4390,8 +4402,8 @@ class AstBuilder extends StackListener {
builder.onClause = onClause;
} else {
builder.onClause = OnClauseImpl(
existingClause.onKeyword,
[
onKeyword: existingClause.onKeyword,
superclassConstraints: [
...existingClause.superclassConstraints,
...onClause.superclassConstraints,
],
Expand Down
7 changes: 0 additions & 7 deletions pkg/analyzer/lib/src/generated/testing/ast_test_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -463,19 +463,12 @@ class AstTestFactory {
),
);

static NativeClauseImpl nativeClause(String nativeCode) =>
astFactory.nativeClause(
TokenFactory.tokenFromString("native"), string2(nativeCode));

static NativeFunctionBodyImpl nativeFunctionBody(String nativeMethodName) =>
astFactory.nativeFunctionBody(
TokenFactory.tokenFromString("native"),
string2(nativeMethodName),
TokenFactory.tokenFromType(TokenType.SEMICOLON));

static NullLiteralImpl nullLiteral() =>
astFactory.nullLiteral(TokenFactory.tokenFromKeyword(Keyword.NULL));

static ParenthesizedExpressionImpl parenthesizedExpression(
Expression expression) =>
astFactory.parenthesizedExpression(
Expand Down
4 changes: 2 additions & 2 deletions pkg/analyzer/lib/src/summary2/ast_binary_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -902,8 +902,8 @@ class AstBinaryReader {
}

NullLiteral _readNullLiteral() {
var node = astFactory.nullLiteral(
Tokens.null_(),
final node = NullLiteralImpl(
literal: Tokens.null_(),
);
_readExpressionResolution(node);
return node;
Expand Down
Loading

0 comments on commit 5d47306

Please sign in to comment.