@@ -18,6 +18,7 @@ import 'package:analyzer/error/listener.dart';
1818import 'package:analyzer/exception/exception.dart' ;
1919import 'package:analyzer/src/dart/ast/ast.dart' ;
2020import 'package:analyzer/src/dart/ast/ast_factory.dart' ;
21+ import 'package:analyzer/src/dart/ast/token.dart' ;
2122import 'package:analyzer/src/dart/ast/utilities.dart' ;
2223import 'package:analyzer/src/dart/element/element.dart' ;
2324import 'package:analyzer/src/dart/element/member.dart' show ConstructorMember;
@@ -44,12 +45,14 @@ export 'package:analyzer/src/generated/type_system.dart';
4445 * feature.
4546 */
4647class AstRewriteVisitor extends ScopedVisitor {
48+ final bool addConstKeyword;
49+
4750 /**
4851 * Initialize a newly created visitor.
4952 */
5053 AstRewriteVisitor (LibraryElement definingLibrary, Source source,
5154 TypeProvider typeProvider, AnalysisErrorListener errorListener,
52- {Scope nameScope})
55+ {Scope nameScope, this .addConstKeyword : false })
5356 : super (definingLibrary, source, typeProvider, errorListener,
5457 nameScope: nameScope);
5558
@@ -77,7 +80,7 @@ class AstRewriteVisitor extends ScopedVisitor {
7780 TypeName typeName = astFactory.typeName (methodName, node.typeArguments);
7881 InstanceCreationExpression instanceCreationExpression =
7982 astFactory.instanceCreationExpression (
80- null ,
83+ _getKeyword (node) ,
8184 astFactory.constructorName (typeName, null , null ),
8285 node.argumentList);
8386 DartType type = _getType (element, node.typeArguments);
@@ -100,7 +103,7 @@ class AstRewriteVisitor extends ScopedVisitor {
100103 TypeName typeName = astFactory.typeName (target, node.typeArguments);
101104 InstanceCreationExpression instanceCreationExpression =
102105 astFactory.instanceCreationExpression (
103- null ,
106+ _getKeyword (node) ,
104107 astFactory.constructorName (
105108 typeName, node.operator , methodName),
106109 node.argumentList);
@@ -124,7 +127,7 @@ class AstRewriteVisitor extends ScopedVisitor {
124127 node.typeArguments);
125128 InstanceCreationExpression instanceCreationExpression =
126129 astFactory.instanceCreationExpression (
127- null ,
130+ _getKeyword (node) ,
128131 astFactory.constructorName (typeName, null , null ),
129132 node.argumentList);
130133 DartType type = _getType (prefixedElement, node.typeArguments);
@@ -145,7 +148,7 @@ class AstRewriteVisitor extends ScopedVisitor {
145148 TypeName typeName = astFactory.typeName (target, node.typeArguments);
146149 InstanceCreationExpression instanceCreationExpression =
147150 astFactory.instanceCreationExpression (
148- null ,
151+ _getKeyword (node) ,
149152 astFactory.constructorName (
150153 typeName, node.operator , methodName),
151154 node.argumentList);
@@ -161,6 +164,16 @@ class AstRewriteVisitor extends ScopedVisitor {
161164 return null ;
162165 }
163166
167+ /**
168+ * Return the token that should be used in the [InstanceCreationExpression]
169+ * that corresponds to the given invocation [node] .
170+ */
171+ Token _getKeyword (MethodInvocation node) {
172+ return addConstKeyword
173+ ? new KeywordToken (Keyword .CONST , node.offset)
174+ : null ;
175+ }
176+
164177 /**
165178 * Return the type of the given class [element] after substituting any type
166179 * arguments from the list of [typeArguments] for the class' type parameters.
0 commit comments