mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 08:44:27 +00:00
Remove DeclaredSimpleIdentifier and AstFactoryImpl.
Change-Id: Ifaf4d2c134a4be075afe75c3b8c841644b14da3d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308500 Reviewed-by: Samuel Rawlins <srawlins@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
5698c12549
commit
ecec8e70cd
11 changed files with 54 additions and 93 deletions
|
@ -30,10 +30,7 @@ class RemoveLeadingUnderscore extends CorrectionProducer {
|
|||
final node = this.node;
|
||||
final Token? nameToken;
|
||||
final Element? element;
|
||||
if (node is DeclaredSimpleIdentifier) {
|
||||
nameToken = node.token;
|
||||
element = node.staticElement;
|
||||
} else if (node is SimpleIdentifier) {
|
||||
if (node is SimpleIdentifier) {
|
||||
nameToken = node.token;
|
||||
element = node.staticElement;
|
||||
} else if (node is FormalParameter) {
|
||||
|
|
|
@ -5332,22 +5332,6 @@ final class DeclaredIdentifierImpl extends DeclarationImpl
|
|||
}
|
||||
}
|
||||
|
||||
/// A simple identifier that declares a name.
|
||||
// TODO(rnystrom): Consider making this distinct from [SimpleIdentifier] and
|
||||
// get rid of all of the:
|
||||
//
|
||||
// if (node.inDeclarationContext()) { ... }
|
||||
//
|
||||
// code and instead visit this separately. A declaration is semantically pretty
|
||||
// different from a use, so using the same node type doesn't seem to buy us
|
||||
// much.
|
||||
final class DeclaredSimpleIdentifier extends SimpleIdentifierImpl {
|
||||
DeclaredSimpleIdentifier(super.token);
|
||||
|
||||
@override
|
||||
bool inDeclarationContext() => true;
|
||||
}
|
||||
|
||||
/// A variable pattern that declares a variable.
|
||||
///
|
||||
/// variablePattern ::=
|
||||
|
@ -16894,7 +16878,17 @@ final class SimpleIdentifierImpl extends IdentifierImpl
|
|||
E? accept<E>(AstVisitor<E> visitor) => visitor.visitSimpleIdentifier(this);
|
||||
|
||||
@override
|
||||
bool inDeclarationContext() => false;
|
||||
bool inDeclarationContext() {
|
||||
final parent = this.parent;
|
||||
switch (parent) {
|
||||
case ImportDirective():
|
||||
return parent.prefix == this;
|
||||
case Label():
|
||||
final parent2 = parent.parent;
|
||||
return parent2 is Statement || parent2 is SwitchMember;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
bool inGetterContext() {
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
||||
// 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:_fe_analyzer_shared/src/scanner/token.dart';
|
||||
import 'package:analyzer/src/dart/ast/ast.dart';
|
||||
|
||||
/// The instance of [AstFactoryImpl].
|
||||
final AstFactoryImpl astFactory = AstFactoryImpl();
|
||||
|
||||
class AstFactoryImpl {
|
||||
SimpleIdentifierImpl simpleIdentifier(Token token,
|
||||
{bool isDeclaration = false}) {
|
||||
if (isDeclaration) {
|
||||
return DeclaredSimpleIdentifier(token);
|
||||
}
|
||||
return SimpleIdentifierImpl(token);
|
||||
}
|
||||
}
|
|
@ -15,7 +15,6 @@ import 'package:analyzer/dart/element/type_provider.dart';
|
|||
import 'package:analyzer/error/error.dart';
|
||||
import 'package:analyzer/error/listener.dart';
|
||||
import 'package:analyzer/src/dart/ast/ast.dart';
|
||||
import 'package:analyzer/src/dart/ast/ast_factory.dart';
|
||||
import 'package:analyzer/src/dart/ast/extensions.dart';
|
||||
import 'package:analyzer/src/dart/ast/token.dart';
|
||||
import 'package:analyzer/src/dart/constant/from_environment_evaluator.dart';
|
||||
|
@ -2459,7 +2458,7 @@ class _InstanceCreationEvaluator {
|
|||
var positionalIndex = 0;
|
||||
for (var parameter in _constructor.parameters) {
|
||||
if (parameter is SuperFormalParameterElement) {
|
||||
var value = astFactory.simpleIdentifier(
|
||||
var value = SimpleIdentifierImpl(
|
||||
StringToken(TokenType.STRING, parameter.name, -1),
|
||||
)
|
||||
..staticElement = parameter
|
||||
|
@ -2470,7 +2469,7 @@ class _InstanceCreationEvaluator {
|
|||
superArguments.add(
|
||||
NamedExpressionImpl(
|
||||
name: LabelImpl(
|
||||
label: astFactory.simpleIdentifier(
|
||||
label: SimpleIdentifierImpl(
|
||||
StringToken(TokenType.STRING, parameter.name, -1),
|
||||
)..staticElement = parameter,
|
||||
colon: StringToken(TokenType.COLON, ':', -1),
|
||||
|
|
|
@ -21,7 +21,6 @@ import 'package:analyzer/error/error.dart';
|
|||
import 'package:analyzer/src/dart/analysis/experiments.dart';
|
||||
import 'package:analyzer/src/dart/analysis/session.dart';
|
||||
import 'package:analyzer/src/dart/ast/ast.dart';
|
||||
import 'package:analyzer/src/dart/ast/ast_factory.dart';
|
||||
import 'package:analyzer/src/dart/ast/token.dart';
|
||||
import 'package:analyzer/src/dart/constant/compute.dart';
|
||||
import 'package:analyzer/src/dart/constant/evaluation.dart';
|
||||
|
@ -970,7 +969,7 @@ class ClassElementImpl extends ClassOrMixinElementImpl implements ClassElement {
|
|||
substitution.substituteType(superParameter.type);
|
||||
implicitParameters.add(implicitParameter);
|
||||
argumentsForSuperInvocation.add(
|
||||
astFactory.simpleIdentifier(
|
||||
SimpleIdentifierImpl(
|
||||
StringToken(TokenType.STRING, implicitParameter.name, -1),
|
||||
)
|
||||
..staticElement = implicitParameter
|
||||
|
@ -990,7 +989,7 @@ class ClassElementImpl extends ClassOrMixinElementImpl implements ClassElement {
|
|||
superKeyword: Tokens.super_(),
|
||||
period: isNamed ? Tokens.period() : null,
|
||||
constructorName: isNamed
|
||||
? (astFactory.simpleIdentifier(
|
||||
? (SimpleIdentifierImpl(
|
||||
StringToken(TokenType.STRING, superclassConstructor.name, -1),
|
||||
)..staticElement = superclassConstructor)
|
||||
: null,
|
||||
|
|
|
@ -15,9 +15,6 @@ Element? getElementOfNode(AstNode? node) {
|
|||
if (node == null) {
|
||||
return null;
|
||||
}
|
||||
if (node is DeclaredSimpleIdentifier) {
|
||||
node = node.parent;
|
||||
}
|
||||
if (node is SimpleIdentifier && node.parent is LibraryIdentifier) {
|
||||
node = node.parent;
|
||||
}
|
||||
|
|
|
@ -60,7 +60,6 @@ import 'package:analyzer/error/listener.dart';
|
|||
import 'package:analyzer/source/line_info.dart';
|
||||
import 'package:analyzer/src/dart/analysis/experiments.dart';
|
||||
import 'package:analyzer/src/dart/ast/ast.dart';
|
||||
import 'package:analyzer/src/dart/ast/ast_factory.dart';
|
||||
import 'package:analyzer/src/dart/ast/extensions.dart';
|
||||
import 'package:analyzer/src/dart/error/syntactic_errors.dart';
|
||||
import 'package:analyzer/src/fasta/error_converter.dart';
|
||||
|
@ -71,8 +70,6 @@ import 'package:pub_semver/pub_semver.dart';
|
|||
|
||||
/// A parser listener that builds the analyzer's AST structure.
|
||||
class AstBuilder extends StackListener {
|
||||
final AstFactoryImpl ast = astFactory;
|
||||
|
||||
final FastaErrorReporter errorReporter;
|
||||
final Uri fileUri;
|
||||
ScriptTagImpl? scriptTag;
|
||||
|
@ -332,16 +329,11 @@ class AstBuilder extends StackListener {
|
|||
var metadata = pop() as List<AnnotationImpl>?;
|
||||
var comment = _findComment(metadata, extensionKeyword);
|
||||
|
||||
SimpleIdentifierImpl? name;
|
||||
if (nameToken != null) {
|
||||
name = ast.simpleIdentifier(nameToken, isDeclaration: true);
|
||||
}
|
||||
|
||||
_classLikeBuilder = _ExtensionDeclarationBuilder(
|
||||
comment: comment,
|
||||
metadata: metadata,
|
||||
extensionKeyword: extensionKeyword,
|
||||
name: name?.token,
|
||||
name: nameToken,
|
||||
typeParameters: typeParameters,
|
||||
leftBracket: Tokens.openCurlyBracket(),
|
||||
rightBracket: Tokens.closeCurlyBracket(),
|
||||
|
@ -662,7 +654,9 @@ class AstBuilder extends StackListener {
|
|||
// Recovery:
|
||||
// Parser has reported invalid assignment.
|
||||
var superExpression = left as SuperExpressionImpl;
|
||||
fieldName = ast.simpleIdentifier(superExpression.superKeyword);
|
||||
fieldName = SimpleIdentifierImpl(
|
||||
superExpression.superKeyword,
|
||||
);
|
||||
}
|
||||
return ConstructorFieldInitializerImpl(
|
||||
thisKeyword: thisKeyword,
|
||||
|
@ -815,8 +809,7 @@ class AstBuilder extends StackListener {
|
|||
// upon the type of expression. e.g. "x.this" -> templateThisAsIdentifier
|
||||
handleRecoverableError(
|
||||
templateExpectedIdentifier.withArguments(token), token, token);
|
||||
SimpleIdentifierImpl identifier =
|
||||
ast.simpleIdentifier(token, isDeclaration: false);
|
||||
SimpleIdentifierImpl identifier = SimpleIdentifierImpl(token);
|
||||
push(
|
||||
PropertyAccessImpl(
|
||||
target: receiver,
|
||||
|
@ -916,7 +909,7 @@ class AstBuilder extends StackListener {
|
|||
}
|
||||
push(
|
||||
FunctionExpressionInvocationImpl(
|
||||
function: ast.simpleIdentifier(assertKeyword),
|
||||
function: SimpleIdentifierImpl(assertKeyword),
|
||||
typeArguments: null,
|
||||
argumentList: ArgumentListImpl(
|
||||
leftParenthesis: leftParenthesis,
|
||||
|
@ -1219,7 +1212,7 @@ class AstBuilder extends StackListener {
|
|||
externalKeyword: modifiers?.externalKeyword,
|
||||
constKeyword: modifiers?.finalConstOrVarKeyword,
|
||||
factoryKeyword: null,
|
||||
returnType: ast.simpleIdentifier(prefixOrName.token),
|
||||
returnType: SimpleIdentifierImpl(prefixOrName.token),
|
||||
period: period,
|
||||
name: nameOrNull?.token,
|
||||
parameters: parameters,
|
||||
|
@ -1290,15 +1283,14 @@ class AstBuilder extends StackListener {
|
|||
// the actual constructor name.
|
||||
SimpleIdentifierImpl returnType;
|
||||
Token? period;
|
||||
SimpleIdentifierImpl? name;
|
||||
Token? nameToken;
|
||||
IdentifierImpl typeName = constructorName;
|
||||
if (typeName is SimpleIdentifierImpl) {
|
||||
returnType = typeName;
|
||||
} else if (typeName is PrefixedIdentifierImpl) {
|
||||
returnType = typeName.prefix;
|
||||
period = typeName.period;
|
||||
name =
|
||||
ast.simpleIdentifier(typeName.identifier.token, isDeclaration: true);
|
||||
nameToken = typeName.identifier.token;
|
||||
} else {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
@ -1310,9 +1302,9 @@ class AstBuilder extends StackListener {
|
|||
externalKeyword: modifiers?.externalKeyword,
|
||||
constKeyword: modifiers?.finalConstOrVarKeyword,
|
||||
factoryKeyword: factoryKeyword,
|
||||
returnType: ast.simpleIdentifier(returnType.token),
|
||||
returnType: SimpleIdentifierImpl(returnType.token),
|
||||
period: period,
|
||||
name: name?.token,
|
||||
name: nameToken,
|
||||
parameters: parameters,
|
||||
separator: separator,
|
||||
initializers: null,
|
||||
|
@ -3915,12 +3907,12 @@ class AstBuilder extends StackListener {
|
|||
Token? secondPeriod,
|
||||
Token thirdToken,
|
||||
) {
|
||||
var identifier = ast.simpleIdentifier(thirdToken);
|
||||
var identifier = SimpleIdentifierImpl(thirdToken);
|
||||
if (firstToken != null) {
|
||||
var target = PrefixedIdentifierImpl(
|
||||
prefix: ast.simpleIdentifier(firstToken),
|
||||
prefix: SimpleIdentifierImpl(firstToken),
|
||||
period: firstPeriod!,
|
||||
identifier: ast.simpleIdentifier(secondToken!),
|
||||
identifier: SimpleIdentifierImpl(secondToken!),
|
||||
);
|
||||
var expression = PropertyAccessImpl(
|
||||
target: target,
|
||||
|
@ -3935,7 +3927,7 @@ class AstBuilder extends StackListener {
|
|||
);
|
||||
} else if (secondToken != null) {
|
||||
var expression = PrefixedIdentifierImpl(
|
||||
prefix: ast.simpleIdentifier(secondToken),
|
||||
prefix: SimpleIdentifierImpl(secondToken),
|
||||
period: secondPeriod!,
|
||||
identifier: identifier,
|
||||
);
|
||||
|
@ -4319,7 +4311,7 @@ class AstBuilder extends StackListener {
|
|||
if (!leftParenthesis.next!.isIdentifier) {
|
||||
parser.rewriter.insertSyntheticIdentifier(leftParenthesis);
|
||||
}
|
||||
variableOrDeclaration = ast.simpleIdentifier(leftParenthesis.next!);
|
||||
variableOrDeclaration = SimpleIdentifierImpl(leftParenthesis.next!);
|
||||
}
|
||||
forLoopParts = ForEachPartsWithIdentifierImpl(
|
||||
identifier: variableOrDeclaration,
|
||||
|
@ -4407,8 +4399,7 @@ class AstBuilder extends StackListener {
|
|||
return;
|
||||
}
|
||||
|
||||
final identifier =
|
||||
ast.simpleIdentifier(token, isDeclaration: context.inDeclaration);
|
||||
final identifier = SimpleIdentifierImpl(token);
|
||||
if (context.inLibraryOrPartOfDeclaration) {
|
||||
if (!context.isContinuation) {
|
||||
push([identifier]);
|
||||
|
@ -4567,8 +4558,12 @@ class AstBuilder extends StackListener {
|
|||
assert(optional('operator', operatorKeyword));
|
||||
debugEvent("InvalidOperatorName");
|
||||
|
||||
push(_OperatorName(
|
||||
operatorKeyword, ast.simpleIdentifier(token, isDeclaration: true)));
|
||||
push(
|
||||
_OperatorName(
|
||||
operatorKeyword,
|
||||
SimpleIdentifierImpl(token),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -4984,7 +4979,9 @@ class AstBuilder extends StackListener {
|
|||
debugEvent("NoTypeNameInConstructorReference");
|
||||
final builder = _classLikeBuilder as _EnumDeclarationBuilder;
|
||||
|
||||
push(ast.simpleIdentifier(builder.name));
|
||||
push(
|
||||
SimpleIdentifierImpl(builder.name),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -5077,8 +5074,12 @@ class AstBuilder extends StackListener {
|
|||
assert(token.type.isUserDefinableOperator);
|
||||
debugEvent("OperatorName");
|
||||
|
||||
push(_OperatorName(
|
||||
operatorKeyword, ast.simpleIdentifier(token, isDeclaration: true)));
|
||||
push(
|
||||
_OperatorName(
|
||||
operatorKeyword,
|
||||
SimpleIdentifierImpl(token),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -5800,7 +5801,7 @@ class AstBuilder extends StackListener {
|
|||
}
|
||||
|
||||
SimpleIdentifierImpl _tmpSimpleIdentifier() {
|
||||
return ast.simpleIdentifier(
|
||||
return SimpleIdentifierImpl(
|
||||
StringToken(TokenType.STRING, '__tmp', -1),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import 'package:analyzer/dart/ast/token.dart';
|
|||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
import 'package:analyzer/src/dart/ast/ast.dart';
|
||||
import 'package:analyzer/src/dart/ast/ast_factory.dart';
|
||||
import 'package:analyzer/src/dart/ast/token.dart';
|
||||
import 'package:analyzer/src/dart/element/element.dart';
|
||||
import 'package:analyzer/src/dart/element/type.dart';
|
||||
|
@ -889,7 +888,7 @@ class AstBinaryReader {
|
|||
NamedExpression _readNamedExpression() {
|
||||
var name = _readStringReference();
|
||||
var nameNode = LabelImpl(
|
||||
label: astFactory.simpleIdentifier(
|
||||
label: SimpleIdentifierImpl(
|
||||
StringToken(TokenType.STRING, name, -1),
|
||||
),
|
||||
colon: Tokens.colon(),
|
||||
|
@ -1186,7 +1185,7 @@ class AstBinaryReader {
|
|||
|
||||
SimpleIdentifier _readSimpleIdentifier() {
|
||||
var name = _readStringReference();
|
||||
var node = astFactory.simpleIdentifier(
|
||||
var node = SimpleIdentifierImpl(
|
||||
StringToken(TokenType.STRING, name, -1),
|
||||
);
|
||||
node.staticElement = _reader.readElement();
|
||||
|
|
|
@ -6,7 +6,6 @@ import 'package:analyzer/dart/ast/token.dart';
|
|||
import 'package:analyzer/dart/ast/visitor.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/src/dart/ast/ast.dart';
|
||||
import 'package:analyzer/src/dart/ast/ast_factory.dart';
|
||||
import 'package:analyzer/src/dart/ast/invokes_super_self.dart';
|
||||
import 'package:analyzer/src/dart/ast/token.dart';
|
||||
import 'package:analyzer/src/dart/element/element.dart';
|
||||
|
@ -263,7 +262,7 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
|
|||
),
|
||||
period: constructorName != null ? Tokens.period() : null,
|
||||
name: constructorName != null
|
||||
? astFactory.simpleIdentifier(
|
||||
? SimpleIdentifierImpl(
|
||||
StringToken(TokenType.STRING, constructorName, -1),
|
||||
)
|
||||
: null,
|
||||
|
@ -296,7 +295,7 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
|
|||
field.constantInitializer = initializer;
|
||||
holder.addNonSyntheticField(field);
|
||||
valuesElements.add(
|
||||
astFactory.simpleIdentifier(
|
||||
SimpleIdentifierImpl(
|
||||
StringToken(TokenType.STRING, name, -1),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
import 'package:analyzer/dart/ast/token.dart';
|
||||
import 'package:analyzer/dart/ast/visitor.dart';
|
||||
import 'package:analyzer/src/dart/ast/ast.dart';
|
||||
import 'package:analyzer/src/dart/ast/ast_factory.dart';
|
||||
import 'package:analyzer/src/dart/ast/token.dart';
|
||||
|
||||
const _notSerializableName = '_notSerializableExpression';
|
||||
|
@ -22,7 +21,7 @@ ExpressionImpl replaceNotSerializableNode(ExpressionImpl node) {
|
|||
if (visitor.result) {
|
||||
return node;
|
||||
}
|
||||
return astFactory.simpleIdentifier(
|
||||
return SimpleIdentifierImpl(
|
||||
StringToken(TokenType.STRING, _notSerializableName, -1),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -216,10 +216,6 @@ class ResolutionVerifier extends RecursiveAstVisitor<void> {
|
|||
return;
|
||||
}
|
||||
|
||||
if (node is DeclaredSimpleIdentifier) {
|
||||
return;
|
||||
}
|
||||
|
||||
var staticType = node.staticType;
|
||||
if (staticType is DynamicType && node.staticElement == null) {
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue