Introduce AstFactory.compilationUnit2 with a required featureSet argument.
Change-Id: I8d709fcb9be1b3a89e617a0c7b35f47813787f06
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/99966
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analyzer/CHANGELOG.md b/pkg/analyzer/CHANGELOG.md
index 59af6b3..9107c6e 100644
--- a/pkg/analyzer/CHANGELOG.md
+++ b/pkg/analyzer/CHANGELOG.md
@@ -1,3 +1,9 @@
+## (not yet released)
+* Deprecated `AstFactory.compilationUnit`. In a future analyzer release, this
+ method will be changed so that all its parameters are named parameters.
+ Clients wishing to prepare for this should switch to using
+ `AstFactory.compilationUnit2`.
+
## 0.36.2
* Bug fixes: #36724.
diff --git a/pkg/analyzer/lib/dart/ast/ast_factory.dart b/pkg/analyzer/lib/dart/ast/ast_factory.dart
index aae0910..815ad03 100644
--- a/pkg/analyzer/lib/dart/ast/ast_factory.dart
+++ b/pkg/analyzer/lib/dart/ast/ast_factory.dart
@@ -156,6 +156,7 @@
/// in the compilation unit. The list of [directives] can be `null` if there
/// are no directives in the compilation unit. The list of [declarations] can
/// be `null` if there are no declarations in the compilation unit.
+ @Deprecated('Use compilationUnit2')
CompilationUnit compilationUnit(
Token beginToken,
ScriptTag scriptTag,
@@ -164,6 +165,22 @@
Token endToken,
[FeatureSet featureSet]);
+ /// Returns a newly created compilation unit to have the given directives and
+ /// declarations. The [scriptTag] can be `null` (or omitted) if there is no
+ /// script tag in the compilation unit. The list of [declarations] can be
+ /// `null` (or omitted) if there are no directives in the compilation unit.
+ /// The list of `declarations` can be `null` (or omitted) if there are no
+ /// declarations in the compilation unit. The [featureSet] can be `null` if
+ /// the set of features for this compilation unit is not known (this
+ /// restricts what analysis can be done of the compilation unit).
+ CompilationUnit compilationUnit2(
+ {@required Token beginToken,
+ ScriptTag scriptTag,
+ List<Directive> directives,
+ List<CompilationUnitMember> declarations,
+ @required Token endToken,
+ @required FeatureSet featureSet});
+
/// Returns a newly created conditional expression.
ConditionalExpression conditionalExpression(
Expression condition,
diff --git a/pkg/analyzer/lib/src/dart/analysis/file_state.dart b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
index 4a24208..8395eb7 100644
--- a/pkg/analyzer/lib/src/dart/analysis/file_state.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
@@ -654,7 +654,8 @@
CompilationUnit _createEmptyCompilationUnit(FeatureSet featureSet) {
var token = new Token.eof(0);
- return astFactory.compilationUnit(token, null, [], [], token, featureSet)
+ return astFactory.compilationUnit2(
+ beginToken: token, endToken: token, featureSet: featureSet)
..lineInfo = new LineInfo(const <int>[0]);
}
diff --git a/pkg/analyzer/lib/src/dart/ast/ast_factory.dart b/pkg/analyzer/lib/src/dart/ast/ast_factory.dart
index 69bee9e..95b5867 100644
--- a/pkg/analyzer/lib/src/dart/ast/ast_factory.dart
+++ b/pkg/analyzer/lib/src/dart/ast/ast_factory.dart
@@ -179,6 +179,7 @@
new CommentReferenceImpl(newKeyword, identifier);
@override
+ @deprecated
CompilationUnit compilationUnit(
Token beginToken,
ScriptTag scriptTag,
@@ -190,6 +191,17 @@
endToken, featureSet);
@override
+ CompilationUnit compilationUnit2(
+ {Token beginToken,
+ ScriptTag scriptTag,
+ List<Directive> directives,
+ List<CompilationUnitMember> declarations,
+ Token endToken,
+ FeatureSet featureSet}) =>
+ new CompilationUnitImpl(beginToken, scriptTag, directives, declarations,
+ endToken, featureSet);
+
+ @override
ConditionalExpression conditionalExpression(
Expression condition,
Token question,
diff --git a/pkg/analyzer/lib/src/dart/ast/utilities.dart b/pkg/analyzer/lib/src/dart/ast/utilities.dart
index f5d309f..5ac34d1 100644
--- a/pkg/analyzer/lib/src/dart/ast/utilities.dart
+++ b/pkg/analyzer/lib/src/dart/ast/utilities.dart
@@ -285,13 +285,13 @@
@override
CompilationUnit visitCompilationUnit(CompilationUnit node) {
- CompilationUnit clone = astFactory.compilationUnit(
- cloneToken(node.beginToken),
- cloneNode(node.scriptTag),
- cloneNodeList(node.directives),
- cloneNodeList(node.declarations),
- cloneToken(node.endToken),
- node.featureSet);
+ CompilationUnit clone = astFactory.compilationUnit2(
+ beginToken: cloneToken(node.beginToken),
+ scriptTag: cloneNode(node.scriptTag),
+ directives: cloneNodeList(node.directives),
+ declarations: cloneNodeList(node.declarations),
+ endToken: cloneToken(node.endToken),
+ featureSet: node.featureSet);
clone.lineInfo = node.lineInfo;
return clone;
}
@@ -2643,13 +2643,13 @@
@override
CompilationUnit visitCompilationUnit(CompilationUnit node) {
- CompilationUnitImpl copy = astFactory.compilationUnit(
- _mapToken(node.beginToken),
- _cloneNode(node.scriptTag),
- _cloneNodeList(node.directives),
- _cloneNodeList(node.declarations),
- _mapToken(node.endToken),
- node.featureSet);
+ CompilationUnitImpl copy = astFactory.compilationUnit2(
+ beginToken: _mapToken(node.beginToken),
+ scriptTag: _cloneNode(node.scriptTag),
+ directives: _cloneNodeList(node.directives),
+ declarations: _cloneNodeList(node.declarations),
+ endToken: _mapToken(node.endToken),
+ featureSet: node.featureSet);
copy.lineInfo = node.lineInfo;
copy.declaredElement = node.declaredElement;
return copy;
diff --git a/pkg/analyzer/lib/src/fasta/ast_builder.dart b/pkg/analyzer/lib/src/fasta/ast_builder.dart
index c0c5c95..6622274 100644
--- a/pkg/analyzer/lib/src/fasta/ast_builder.dart
+++ b/pkg/analyzer/lib/src/fasta/ast_builder.dart
@@ -506,8 +506,13 @@
Token beginToken = pop();
checkEmpty(endToken.charOffset);
- CompilationUnitImpl unit = ast.compilationUnit(beginToken, scriptTag,
- directives, declarations, endToken, _featureSet) as CompilationUnitImpl;
+ CompilationUnitImpl unit = ast.compilationUnit2(
+ beginToken: beginToken,
+ scriptTag: scriptTag,
+ directives: directives,
+ declarations: declarations,
+ endToken: endToken,
+ featureSet: _featureSet) as CompilationUnitImpl;
unit.languageVersion = languageVersion;
unit.isNonNullable = enableNonNullable;
push(unit);
diff --git a/pkg/analyzer/lib/src/generated/parser.dart b/pkg/analyzer/lib/src/generated/parser.dart
index d572753..b0072a9 100644
--- a/pkg/analyzer/lib/src/generated/parser.dart
+++ b/pkg/analyzer/lib/src/generated/parser.dart
@@ -1936,8 +1936,8 @@
} on _TooDeepTreeError {
_reportErrorForToken(ParserErrorCode.STACK_OVERFLOW, _currentToken);
Token eof = new Token.eof(0);
- return astFactory.compilationUnit(
- eof, null, null, null, eof, _featureSet);
+ return astFactory.compilationUnit2(
+ beginToken: eof, endToken: eof, featureSet: _featureSet);
}
if (member != null) {
declarations.add(member);
@@ -1986,8 +1986,13 @@
// }
}
}
- return astFactory.compilationUnit(firstToken, scriptTag, directives,
- declarations, _currentToken, _featureSet);
+ return astFactory.compilationUnit2(
+ beginToken: firstToken,
+ scriptTag: scriptTag,
+ directives: directives,
+ declarations: declarations,
+ endToken: _currentToken,
+ featureSet: _featureSet);
}
/// Parse a compilation unit member. The [commentAndMetadata] is the metadata
@@ -2437,12 +2442,20 @@
while (!_matches(TokenType.EOF)) {
_advance();
}
- return astFactory.compilationUnit(firstToken, scriptTag, directives,
- null, _currentToken, _featureSet);
+ return astFactory.compilationUnit2(
+ beginToken: firstToken,
+ scriptTag: scriptTag,
+ directives: directives,
+ endToken: _currentToken,
+ featureSet: _featureSet);
}
}
- return astFactory.compilationUnit(
- firstToken, scriptTag, directives, null, _currentToken, _featureSet);
+ return astFactory.compilationUnit2(
+ beginToken: firstToken,
+ scriptTag: scriptTag,
+ directives: directives,
+ endToken: _currentToken,
+ featureSet: _featureSet);
}
/// Parse a documentation comment based on the given list of documentation
diff --git a/pkg/analyzer/lib/src/generated/testing/ast_test_factory.dart b/pkg/analyzer/lib/src/generated/testing/ast_test_factory.dart
index 9c88eee..ab12e27 100644
--- a/pkg/analyzer/lib/src/generated/testing/ast_test_factory.dart
+++ b/pkg/analyzer/lib/src/generated/testing/ast_test_factory.dart
@@ -275,15 +275,16 @@
String scriptTag,
List<Directive> directives,
List<CompilationUnitMember> declarations) =>
- astFactory.compilationUnit(
- TokenFactory.tokenFromType(TokenType.EOF),
- scriptTag == null ? null : AstTestFactory.scriptTag(scriptTag),
- directives == null ? new List<Directive>() : directives,
- declarations == null
+ astFactory.compilationUnit2(
+ beginToken: TokenFactory.tokenFromType(TokenType.EOF),
+ scriptTag:
+ scriptTag == null ? null : AstTestFactory.scriptTag(scriptTag),
+ directives: directives == null ? new List<Directive>() : directives,
+ declarations: declarations == null
? new List<CompilationUnitMember>()
: declarations,
- TokenFactory.tokenFromType(TokenType.EOF),
- null);
+ endToken: TokenFactory.tokenFromType(TokenType.EOF),
+ featureSet: null);
static ConditionalExpression conditionalExpression(Expression condition,
Expression thenExpression, Expression elseExpression) =>
diff --git a/pkg/analyzer/lib/src/summary2/ast_binary_reader.dart b/pkg/analyzer/lib/src/summary2/ast_binary_reader.dart
index b4d0434..80f6709 100644
--- a/pkg/analyzer/lib/src/summary2/ast_binary_reader.dart
+++ b/pkg/analyzer/lib/src/summary2/ast_binary_reader.dart
@@ -278,13 +278,13 @@
}
CompilationUnit _read_compilationUnit(LinkedNode data) {
- return astFactory.compilationUnit(
- _getToken(data.compilationUnit_beginToken),
- _readNode(data.compilationUnit_scriptTag),
- _readNodeList(data.compilationUnit_directives),
- _readNodeList(data.compilationUnit_declarations),
- _getToken(data.compilationUnit_endToken),
- null);
+ return astFactory.compilationUnit2(
+ beginToken: _getToken(data.compilationUnit_beginToken),
+ scriptTag: _readNode(data.compilationUnit_scriptTag),
+ directives: _readNodeList(data.compilationUnit_directives),
+ declarations: _readNodeList(data.compilationUnit_declarations),
+ endToken: _getToken(data.compilationUnit_endToken),
+ featureSet: null);
}
ConditionalExpression _read_conditionalExpression(LinkedNode data) {
diff --git a/pkg/analyzer/test/dart/element/builder_test.dart b/pkg/analyzer/test/dart/element/builder_test.dart
index de788e1..a7de7ad 100644
--- a/pkg/analyzer/test/dart/element/builder_test.dart
+++ b/pkg/analyzer/test/dart/element/builder_test.dart
@@ -274,13 +274,11 @@
null,
AstTestFactory.typeName4('int'),
[AstTestFactory.variableDeclaration('V')]);
- CompilationUnit unit = astFactory.compilationUnit(
- topLevelVariableDeclaration.beginToken,
- null,
- [],
- [topLevelVariableDeclaration],
- topLevelVariableDeclaration.endToken,
- null);
+ CompilationUnit unit = astFactory.compilationUnit2(
+ beginToken: topLevelVariableDeclaration.beginToken,
+ declarations: [topLevelVariableDeclaration],
+ endToken: topLevelVariableDeclaration.endToken,
+ featureSet: null);
ElementHolder holder = new ElementHolder();
ElementBuilder builder = _makeBuilder(holder);
unit.beginToken.offset = 10;