| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. |
| 7 |
| 8 library engine.testing.ast_factory; |
| 9 |
| 10 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 11 import 'package:analyzer/src/generated/ast.dart'; |
| 12 import 'package:analyzer/src/generated/element.dart'; |
| 13 import 'package:analyzer/src/generated/scanner.dart'; |
| 14 import 'package:analyzer/src/generated/testing/token_factory.dart'; |
| 15 |
| 16 /** |
| 17 * The class `AstFactory` defines utility methods that can be used to create AST
nodes. The |
| 18 * nodes that are created are complete in the sense that all of the tokens that
would have been |
| 19 * associated with the nodes by a parser are also created, but the token stream
is not constructed. |
| 20 * None of the nodes are resolved. |
| 21 * |
| 22 * The general pattern is for the name of the factory method to be the same as t
he name of the class |
| 23 * of AST node being created. There are two notable exceptions. The first is for
methods creating |
| 24 * nodes that are part of a cascade expression. These methods are all prefixed w
ith 'cascaded'. The |
| 25 * second is places where a shorter name seemed unambiguous and easier to read,
such as using |
| 26 * 'identifier' rather than 'prefixedIdentifier', or 'integer' rather than 'inte
gerLiteral'. |
| 27 */ |
| 28 class AstFactory { |
| 29 static AdjacentStrings adjacentStrings(List<StringLiteral> strings) => new Adj
acentStrings(list(strings)); |
| 30 |
| 31 static Annotation annotation(Identifier name) => new Annotation(TokenFactory.t
okenFromType(TokenType.AT), name, null, null, null); |
| 32 |
| 33 static Annotation annotation2(Identifier name, SimpleIdentifier constructorNam
e, ArgumentList arguments) => new Annotation(TokenFactory.tokenFromType(TokenTyp
e.AT), name, TokenFactory.tokenFromType(TokenType.PERIOD), constructorName, argu
ments); |
| 34 |
| 35 static ArgumentList argumentList(List<Expression> arguments) => new ArgumentLi
st(TokenFactory.tokenFromType(TokenType.OPEN_PAREN), list(arguments), TokenFacto
ry.tokenFromType(TokenType.CLOSE_PAREN)); |
| 36 |
| 37 static AsExpression asExpression(Expression expression, TypeName type) => new
AsExpression(expression, TokenFactory.tokenFromKeyword(Keyword.AS), type); |
| 38 |
| 39 static AssertStatement assertStatement(Expression condition) => new AssertStat
ement(TokenFactory.tokenFromKeyword(Keyword.ASSERT), TokenFactory.tokenFromType(
TokenType.OPEN_PAREN), condition, TokenFactory.tokenFromType(TokenType.CLOSE_PAR
EN), TokenFactory.tokenFromType(TokenType.SEMICOLON)); |
| 40 |
| 41 static AssignmentExpression assignmentExpression(Expression leftHandSide, Toke
nType operator, Expression rightHandSide) => new AssignmentExpression(leftHandSi
de, TokenFactory.tokenFromType(operator), rightHandSide); |
| 42 |
| 43 static BinaryExpression binaryExpression(Expression leftOperand, TokenType ope
rator, Expression rightOperand) => new BinaryExpression(leftOperand, TokenFactor
y.tokenFromType(operator), rightOperand); |
| 44 |
| 45 static Block block(List<Statement> statements) => new Block(TokenFactory.token
FromType(TokenType.OPEN_CURLY_BRACKET), list(statements), TokenFactory.tokenFrom
Type(TokenType.CLOSE_CURLY_BRACKET)); |
| 46 |
| 47 static BlockFunctionBody blockFunctionBody(Block block) => new BlockFunctionBo
dy(block); |
| 48 |
| 49 static BlockFunctionBody blockFunctionBody2(List<Statement> statements) => new
BlockFunctionBody(block(statements)); |
| 50 |
| 51 static BooleanLiteral booleanLiteral(bool value) => new BooleanLiteral(value ?
TokenFactory.tokenFromKeyword(Keyword.TRUE) : TokenFactory.tokenFromKeyword(Key
word.FALSE), value); |
| 52 |
| 53 static BreakStatement breakStatement() => new BreakStatement(TokenFactory.toke
nFromKeyword(Keyword.BREAK), null, TokenFactory.tokenFromType(TokenType.SEMICOLO
N)); |
| 54 |
| 55 static BreakStatement breakStatement2(String label) => new BreakStatement(Toke
nFactory.tokenFromKeyword(Keyword.BREAK), identifier3(label), TokenFactory.token
FromType(TokenType.SEMICOLON)); |
| 56 |
| 57 static IndexExpression cascadedIndexExpression(Expression index) => new IndexE
xpression.forCascade(TokenFactory.tokenFromType(TokenType.PERIOD_PERIOD), TokenF
actory.tokenFromType(TokenType.OPEN_SQUARE_BRACKET), index, TokenFactory.tokenFr
omType(TokenType.CLOSE_SQUARE_BRACKET)); |
| 58 |
| 59 static MethodInvocation cascadedMethodInvocation(String methodName, List<Expre
ssion> arguments) => new MethodInvocation(null, TokenFactory.tokenFromType(Token
Type.PERIOD_PERIOD), identifier3(methodName), argumentList(arguments)); |
| 60 |
| 61 static PropertyAccess cascadedPropertyAccess(String propertyName) => new Prope
rtyAccess(null, TokenFactory.tokenFromType(TokenType.PERIOD_PERIOD), identifier3
(propertyName)); |
| 62 |
| 63 static CascadeExpression cascadeExpression(Expression target, List<Expression>
cascadeSections) => new CascadeExpression(target, list(cascadeSections)); |
| 64 |
| 65 static CatchClause catchClause(String exceptionParameter, List<Statement> stat
ements) => catchClause5(null, exceptionParameter, null, statements); |
| 66 |
| 67 static CatchClause catchClause2(String exceptionParameter, String stackTracePa
rameter, List<Statement> statements) => catchClause5(null, exceptionParameter, s
tackTraceParameter, statements); |
| 68 |
| 69 static CatchClause catchClause3(TypeName exceptionType, List<Statement> statem
ents) => catchClause5(exceptionType, null, null, statements); |
| 70 |
| 71 static CatchClause catchClause4(TypeName exceptionType, String exceptionParame
ter, List<Statement> statements) => catchClause5(exceptionType, exceptionParamet
er, null, statements); |
| 72 |
| 73 static CatchClause catchClause5(TypeName exceptionType, String exceptionParame
ter, String stackTraceParameter, List<Statement> statements) => new CatchClause(
exceptionType == null ? null : TokenFactory.tokenFromTypeAndString(TokenType.IDE
NTIFIER, "on"), exceptionType, exceptionParameter == null ? null : TokenFactory.
tokenFromKeyword(Keyword.CATCH), exceptionParameter == null ? null : TokenFactor
y.tokenFromType(TokenType.OPEN_PAREN), exceptionParameter == null ? null : ident
ifier3(exceptionParameter), stackTraceParameter == null ? null : TokenFactory.to
kenFromType(TokenType.COMMA), stackTraceParameter == null ? null : identifier3(s
tackTraceParameter), exceptionParameter == null ? null : TokenFactory.tokenFromT
ype(TokenType.CLOSE_PAREN), block(statements)); |
| 74 |
| 75 static ClassDeclaration classDeclaration(Keyword abstractKeyword, String name,
TypeParameterList typeParameters, ExtendsClause extendsClause, WithClause withC
lause, ImplementsClause implementsClause, List<ClassMember> members) => new Clas
sDeclaration(null, null, abstractKeyword == null ? null : TokenFactory.tokenFrom
Keyword(abstractKeyword), TokenFactory.tokenFromKeyword(Keyword.CLASS), identifi
er3(name), typeParameters, extendsClause, withClause, implementsClause, TokenFac
tory.tokenFromType(TokenType.OPEN_CURLY_BRACKET), list(members), TokenFactory.to
kenFromType(TokenType.CLOSE_CURLY_BRACKET)); |
| 76 |
| 77 static ClassTypeAlias classTypeAlias(String name, TypeParameterList typeParame
ters, Keyword abstractKeyword, TypeName superclass, WithClause withClause, Imple
mentsClause implementsClause) => new ClassTypeAlias(null, null, TokenFactory.tok
enFromKeyword(Keyword.CLASS), identifier3(name), typeParameters, TokenFactory.to
kenFromType(TokenType.EQ), abstractKeyword == null ? null : TokenFactory.tokenFr
omKeyword(abstractKeyword), superclass, withClause, implementsClause, TokenFacto
ry.tokenFromType(TokenType.SEMICOLON)); |
| 78 |
| 79 static CompilationUnit compilationUnit() => compilationUnit8(null, null, null)
; |
| 80 |
| 81 static CompilationUnit compilationUnit2(List<CompilationUnitMember> declaratio
ns) => compilationUnit8(null, null, list(declarations)); |
| 82 |
| 83 static CompilationUnit compilationUnit3(List<Directive> directives) => compila
tionUnit8(null, list(directives), null); |
| 84 |
| 85 static CompilationUnit compilationUnit4(List<Directive> directives, List<Compi
lationUnitMember> declarations) => compilationUnit8(null, directives, declaratio
ns); |
| 86 |
| 87 static CompilationUnit compilationUnit5(String scriptTag) => compilationUnit8(
scriptTag, null, null); |
| 88 |
| 89 static CompilationUnit compilationUnit6(String scriptTag, List<CompilationUnit
Member> declarations) => compilationUnit8(scriptTag, null, list(declarations)); |
| 90 |
| 91 static CompilationUnit compilationUnit7(String scriptTag, List<Directive> dire
ctives) => compilationUnit8(scriptTag, list(directives), null); |
| 92 |
| 93 static CompilationUnit compilationUnit8(String scriptTag, List<Directive> dire
ctives, List<CompilationUnitMember> declarations) => new CompilationUnit(TokenFa
ctory.tokenFromType(TokenType.EOF), scriptTag == null ? null : AstFactory.script
Tag(scriptTag), directives == null ? new List<Directive>() : directives, declara
tions == null ? new List<CompilationUnitMember>() : declarations, TokenFactory.t
okenFromType(TokenType.EOF)); |
| 94 |
| 95 static ConditionalExpression conditionalExpression(Expression condition, Expre
ssion thenExpression, Expression elseExpression) => new ConditionalExpression(co
ndition, TokenFactory.tokenFromType(TokenType.QUESTION), thenExpression, TokenFa
ctory.tokenFromType(TokenType.COLON), elseExpression); |
| 96 |
| 97 static ConstructorDeclaration constructorDeclaration(Identifier returnType, St
ring name, FormalParameterList parameters, List<ConstructorInitializer> initiali
zers) => new ConstructorDeclaration(null, null, TokenFactory.tokenFromKeyword(Ke
yword.EXTERNAL), null, null, returnType, name == null ? null : TokenFactory.toke
nFromType(TokenType.PERIOD), name == null ? null : identifier3(name), parameters
, initializers == null || initializers.isEmpty ? null : TokenFactory.tokenFromTy
pe(TokenType.PERIOD), initializers == null ? new List<ConstructorInitializer>()
: initializers, null, emptyFunctionBody()); |
| 98 |
| 99 static ConstructorDeclaration constructorDeclaration2(Keyword constKeyword, Ke
yword factoryKeyword, Identifier returnType, String name, FormalParameterList pa
rameters, List<ConstructorInitializer> initializers, FunctionBody body) => new C
onstructorDeclaration(null, null, null, constKeyword == null ? null : TokenFacto
ry.tokenFromKeyword(constKeyword), factoryKeyword == null ? null : TokenFactory.
tokenFromKeyword(factoryKeyword), returnType, name == null ? null : TokenFactory
.tokenFromType(TokenType.PERIOD), name == null ? null : identifier3(name), param
eters, initializers == null || initializers.isEmpty ? null : TokenFactory.tokenF
romType(TokenType.PERIOD), initializers == null ? new List<ConstructorInitialize
r>() : initializers, null, body); |
| 100 |
| 101 static ConstructorFieldInitializer constructorFieldInitializer(bool prefixedWi
thThis, String fieldName, Expression expression) => new ConstructorFieldInitiali
zer(prefixedWithThis ? TokenFactory.tokenFromKeyword(Keyword.THIS) : null, prefi
xedWithThis ? TokenFactory.tokenFromType(TokenType.PERIOD) : null, identifier3(f
ieldName), TokenFactory.tokenFromType(TokenType.EQ), expression); |
| 102 |
| 103 static ConstructorName constructorName(TypeName type, String name) => new Cons
tructorName(type, name == null ? null : TokenFactory.tokenFromType(TokenType.PER
IOD), name == null ? null : identifier3(name)); |
| 104 |
| 105 static ContinueStatement continueStatement([String label]) { |
| 106 SimpleIdentifier labelNode = label == null ? null : identifier3(label); |
| 107 return new ContinueStatement(TokenFactory.tokenFromKeyword(Keyword.CONTINUE)
, labelNode, TokenFactory.tokenFromType(TokenType.SEMICOLON)); |
| 108 } |
| 109 |
| 110 static DeclaredIdentifier declaredIdentifier(Keyword keyword, String identifie
r) => declaredIdentifier2(keyword, null, identifier); |
| 111 |
| 112 static DeclaredIdentifier declaredIdentifier2(Keyword keyword, TypeName type,
String identifier) => new DeclaredIdentifier(null, null, keyword == null ? null
: TokenFactory.tokenFromKeyword(keyword), type, identifier3(identifier)); |
| 113 |
| 114 static DeclaredIdentifier declaredIdentifier3(String identifier) => declaredId
entifier2(null, null, identifier); |
| 115 |
| 116 static DeclaredIdentifier declaredIdentifier4(TypeName type, String identifier
) => declaredIdentifier2(null, type, identifier); |
| 117 |
| 118 static DoStatement doStatement(Statement body, Expression condition) => new Do
Statement(TokenFactory.tokenFromKeyword(Keyword.DO), body, TokenFactory.tokenFro
mKeyword(Keyword.WHILE), TokenFactory.tokenFromType(TokenType.OPEN_PAREN), condi
tion, TokenFactory.tokenFromType(TokenType.CLOSE_PAREN), TokenFactory.tokenFromT
ype(TokenType.SEMICOLON)); |
| 119 |
| 120 static DoubleLiteral doubleLiteral(double value) => new DoubleLiteral(TokenFac
tory.tokenFromString(value.toString()), value); |
| 121 |
| 122 static EmptyFunctionBody emptyFunctionBody() => new EmptyFunctionBody(TokenFac
tory.tokenFromType(TokenType.SEMICOLON)); |
| 123 |
| 124 static EmptyStatement emptyStatement() => new EmptyStatement(TokenFactory.toke
nFromType(TokenType.SEMICOLON)); |
| 125 |
| 126 static ExportDirective exportDirective(List<Annotation> metadata, String uri,
List<Combinator> combinators) => new ExportDirective(null, metadata, TokenFactor
y.tokenFromKeyword(Keyword.EXPORT), string2(uri), list(combinators), TokenFactor
y.tokenFromType(TokenType.SEMICOLON)); |
| 127 |
| 128 static ExportDirective exportDirective2(String uri, List<Combinator> combinato
rs) => exportDirective(new List<Annotation>(), uri, combinators); |
| 129 |
| 130 static ExpressionFunctionBody expressionFunctionBody(Expression expression) =>
new ExpressionFunctionBody(TokenFactory.tokenFromType(TokenType.FUNCTION), expr
ession, TokenFactory.tokenFromType(TokenType.SEMICOLON)); |
| 131 |
| 132 static ExpressionStatement expressionStatement(Expression expression) => new E
xpressionStatement(expression, TokenFactory.tokenFromType(TokenType.SEMICOLON)); |
| 133 |
| 134 static ExtendsClause extendsClause(TypeName type) => new ExtendsClause(TokenFa
ctory.tokenFromKeyword(Keyword.EXTENDS), type); |
| 135 |
| 136 static FieldDeclaration fieldDeclaration(bool isStatic, Keyword keyword, TypeN
ame type, List<VariableDeclaration> variables) => new FieldDeclaration(null, nul
l, isStatic ? TokenFactory.tokenFromKeyword(Keyword.STATIC) : null, variableDecl
arationList(keyword, type, variables), TokenFactory.tokenFromType(TokenType.SEMI
COLON)); |
| 137 |
| 138 static FieldDeclaration fieldDeclaration2(bool isStatic, Keyword keyword, List
<VariableDeclaration> variables) => fieldDeclaration(isStatic, keyword, null, va
riables); |
| 139 |
| 140 static FieldFormalParameter fieldFormalParameter(Keyword keyword, TypeName typ
e, String identifier, [FormalParameterList parameterList]) => new FieldFormalPar
ameter(null, null, keyword == null ? null : TokenFactory.tokenFromKeyword(keywor
d), type, TokenFactory.tokenFromKeyword(Keyword.THIS), TokenFactory.tokenFromTyp
e(TokenType.PERIOD), identifier3(identifier), parameterList); |
| 141 |
| 142 static FieldFormalParameter fieldFormalParameter2(String identifier) => fieldF
ormalParameter(null, null, identifier); |
| 143 |
| 144 static ForEachStatement forEachStatement(DeclaredIdentifier loopVariable, Expr
ession iterator, Statement body) => new ForEachStatement.con1(TokenFactory.token
FromKeyword(Keyword.FOR), TokenFactory.tokenFromType(TokenType.OPEN_PAREN), loop
Variable, TokenFactory.tokenFromKeyword(Keyword.IN), iterator, TokenFactory.toke
nFromType(TokenType.CLOSE_PAREN), body); |
| 145 |
| 146 static ForEachStatement forEachStatement2(SimpleIdentifier identifier, Express
ion iterator, Statement body) => new ForEachStatement.con2(TokenFactory.tokenFro
mKeyword(Keyword.FOR), TokenFactory.tokenFromType(TokenType.OPEN_PAREN), identif
ier, TokenFactory.tokenFromKeyword(Keyword.IN), iterator, TokenFactory.tokenFrom
Type(TokenType.CLOSE_PAREN), body); |
| 147 |
| 148 static FormalParameterList formalParameterList(List<FormalParameter> parameter
s) => new FormalParameterList(TokenFactory.tokenFromType(TokenType.OPEN_PAREN),
list(parameters), null, null, TokenFactory.tokenFromType(TokenType.CLOSE_PAREN))
; |
| 149 |
| 150 static ForStatement forStatement(Expression initialization, Expression conditi
on, List<Expression> updaters, Statement body) => new ForStatement(TokenFactory.
tokenFromKeyword(Keyword.FOR), TokenFactory.tokenFromType(TokenType.OPEN_PAREN),
null, initialization, TokenFactory.tokenFromType(TokenType.SEMICOLON), conditio
n, TokenFactory.tokenFromType(TokenType.SEMICOLON), updaters, TokenFactory.token
FromType(TokenType.CLOSE_PAREN), body); |
| 151 |
| 152 static ForStatement forStatement2(VariableDeclarationList variableList, Expres
sion condition, List<Expression> updaters, Statement body) => new ForStatement(T
okenFactory.tokenFromKeyword(Keyword.FOR), TokenFactory.tokenFromType(TokenType.
OPEN_PAREN), variableList, null, TokenFactory.tokenFromType(TokenType.SEMICOLON)
, condition, TokenFactory.tokenFromType(TokenType.SEMICOLON), updaters, TokenFac
tory.tokenFromType(TokenType.CLOSE_PAREN), body); |
| 153 |
| 154 static FunctionDeclaration functionDeclaration(TypeName type, Keyword keyword,
String name, FunctionExpression functionExpression) => new FunctionDeclaration(
null, null, null, type, keyword == null ? null : TokenFactory.tokenFromKeyword(k
eyword), identifier3(name), functionExpression); |
| 155 |
| 156 static FunctionDeclarationStatement functionDeclarationStatement(TypeName type
, Keyword keyword, String name, FunctionExpression functionExpression) => new Fu
nctionDeclarationStatement(functionDeclaration(type, keyword, name, functionExpr
ession)); |
| 157 |
| 158 static FunctionExpression functionExpression() => new FunctionExpression(forma
lParameterList([]), blockFunctionBody2([])); |
| 159 |
| 160 static FunctionExpression functionExpression2(FormalParameterList parameters,
FunctionBody body) => new FunctionExpression(parameters, body); |
| 161 |
| 162 static FunctionExpressionInvocation functionExpressionInvocation(Expression fu
nction, List<Expression> arguments) => new FunctionExpressionInvocation(function
, argumentList(arguments)); |
| 163 |
| 164 static FunctionTypedFormalParameter functionTypedFormalParameter(TypeName retu
rnType, String identifier, List<FormalParameter> parameters) => new FunctionType
dFormalParameter(null, null, returnType, identifier3(identifier), formalParamete
rList(parameters)); |
| 165 |
| 166 static HideCombinator hideCombinator(List<SimpleIdentifier> identifiers) => ne
w HideCombinator(TokenFactory.tokenFromString("hide"), list(identifiers)); |
| 167 |
| 168 static HideCombinator hideCombinator2(List<String> identifiers) { |
| 169 List<SimpleIdentifier> identifierList = new List<SimpleIdentifier>(); |
| 170 for (String identifier in identifiers) { |
| 171 identifierList.add(identifier3(identifier)); |
| 172 } |
| 173 return new HideCombinator(TokenFactory.tokenFromString("hide"), identifierLi
st); |
| 174 } |
| 175 |
| 176 static PrefixedIdentifier identifier(SimpleIdentifier prefix, SimpleIdentifier
identifier) => new PrefixedIdentifier(prefix, TokenFactory.tokenFromType(TokenT
ype.PERIOD), identifier); |
| 177 |
| 178 static SimpleIdentifier identifier3(String lexeme) => new SimpleIdentifier(Tok
enFactory.tokenFromTypeAndString(TokenType.IDENTIFIER, lexeme)); |
| 179 |
| 180 static PrefixedIdentifier identifier4(String prefix, SimpleIdentifier identifi
er) => new PrefixedIdentifier(identifier3(prefix), TokenFactory.tokenFromType(To
kenType.PERIOD), identifier); |
| 181 |
| 182 static PrefixedIdentifier identifier5(String prefix, String identifier) => new
PrefixedIdentifier(identifier3(prefix), TokenFactory.tokenFromType(TokenType.PE
RIOD), identifier3(identifier)); |
| 183 |
| 184 static IfStatement ifStatement(Expression condition, Statement thenStatement)
=> ifStatement2(condition, thenStatement, null); |
| 185 |
| 186 static IfStatement ifStatement2(Expression condition, Statement thenStatement,
Statement elseStatement) => new IfStatement(TokenFactory.tokenFromKeyword(Keywo
rd.IF), TokenFactory.tokenFromType(TokenType.OPEN_PAREN), condition, TokenFactor
y.tokenFromType(TokenType.CLOSE_PAREN), thenStatement, elseStatement == null ? n
ull : TokenFactory.tokenFromKeyword(Keyword.ELSE), elseStatement); |
| 187 |
| 188 static ImplementsClause implementsClause(List<TypeName> types) => new Implemen
tsClause(TokenFactory.tokenFromKeyword(Keyword.IMPLEMENTS), list(types)); |
| 189 |
| 190 static ImportDirective importDirective(List<Annotation> metadata, String uri,
bool isDeferred, String prefix, List<Combinator> combinators) => new ImportDirec
tive(null, metadata, TokenFactory.tokenFromKeyword(Keyword.IMPORT), string2(uri)
, !isDeferred ? null : TokenFactory.tokenFromKeyword(Keyword.DEFERRED), prefix =
= null ? null : TokenFactory.tokenFromKeyword(Keyword.AS), prefix == null ? null
: identifier3(prefix), list(combinators), TokenFactory.tokenFromType(TokenType.
SEMICOLON)); |
| 191 |
| 192 static ImportDirective importDirective2(String uri, bool isDeferred, String pr
efix, List<Combinator> combinators) => importDirective(new List<Annotation>(), u
ri, isDeferred, prefix, combinators); |
| 193 |
| 194 static ImportDirective importDirective3(String uri, String prefix, List<Combin
ator> combinators) => importDirective(new List<Annotation>(), uri, false, prefix
, combinators); |
| 195 |
| 196 static IndexExpression indexExpression(Expression array, Expression index) =>
new IndexExpression.forTarget(array, TokenFactory.tokenFromType(TokenType.OPEN_S
QUARE_BRACKET), index, TokenFactory.tokenFromType(TokenType.CLOSE_SQUARE_BRACKET
)); |
| 197 |
| 198 static InstanceCreationExpression instanceCreationExpression(Keyword keyword,
ConstructorName name, List<Expression> arguments) => new InstanceCreationExpress
ion(keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), name, argum
entList(arguments)); |
| 199 |
| 200 static InstanceCreationExpression instanceCreationExpression2(Keyword keyword,
TypeName type, List<Expression> arguments) => instanceCreationExpression3(keywo
rd, type, null, arguments); |
| 201 |
| 202 static InstanceCreationExpression instanceCreationExpression3(Keyword keyword,
TypeName type, String identifier, List<Expression> arguments) => instanceCreati
onExpression(keyword, new ConstructorName(type, identifier == null ? null : Toke
nFactory.tokenFromType(TokenType.PERIOD), identifier == null ? null : identifier
3(identifier)), arguments); |
| 203 |
| 204 static IntegerLiteral integer(int value) => new IntegerLiteral(TokenFactory.to
kenFromTypeAndString(TokenType.INT, value.toString()), value); |
| 205 |
| 206 static InterpolationExpression interpolationExpression(Expression expression)
=> new InterpolationExpression(TokenFactory.tokenFromType(TokenType.STRING_INTER
POLATION_EXPRESSION), expression, TokenFactory.tokenFromType(TokenType.CLOSE_CUR
LY_BRACKET)); |
| 207 |
| 208 static InterpolationExpression interpolationExpression2(String identifier) =>
new InterpolationExpression(TokenFactory.tokenFromType(TokenType.STRING_INTERPOL
ATION_IDENTIFIER), identifier3(identifier), null); |
| 209 |
| 210 static InterpolationString interpolationString(String contents, String value)
=> new InterpolationString(TokenFactory.tokenFromString(contents), value); |
| 211 |
| 212 static IsExpression isExpression(Expression expression, bool negated, TypeName
type) => new IsExpression(expression, TokenFactory.tokenFromKeyword(Keyword.IS)
, negated ? TokenFactory.tokenFromType(TokenType.BANG) : null, type); |
| 213 |
| 214 static Label label(SimpleIdentifier label) => new Label(label, TokenFactory.to
kenFromType(TokenType.COLON)); |
| 215 |
| 216 static Label label2(String label) => AstFactory.label(identifier3(label)); |
| 217 |
| 218 static LabeledStatement labeledStatement(List<Label> labels, Statement stateme
nt) => new LabeledStatement(labels, statement); |
| 219 |
| 220 static LibraryDirective libraryDirective(List<Annotation> metadata, LibraryIde
ntifier libraryName) => new LibraryDirective(null, metadata, TokenFactory.tokenF
romKeyword(Keyword.LIBRARY), libraryName, TokenFactory.tokenFromType(TokenType.S
EMICOLON)); |
| 221 |
| 222 static LibraryDirective libraryDirective2(String libraryName) => libraryDirect
ive(new List<Annotation>(), libraryIdentifier2([libraryName])); |
| 223 |
| 224 static LibraryIdentifier libraryIdentifier(List<SimpleIdentifier> components)
=> new LibraryIdentifier(list(components)); |
| 225 |
| 226 static LibraryIdentifier libraryIdentifier2(List<String> components) { |
| 227 List<SimpleIdentifier> componentList = new List<SimpleIdentifier>(); |
| 228 for (String component in components) { |
| 229 componentList.add(identifier3(component)); |
| 230 } |
| 231 return new LibraryIdentifier(componentList); |
| 232 } |
| 233 |
| 234 static List list(List<Object> elements) { |
| 235 List elementList = new List(); |
| 236 for (Object element in elements) { |
| 237 elementList.add(element); |
| 238 } |
| 239 return elementList; |
| 240 } |
| 241 |
| 242 static ListLiteral listLiteral(List<Expression> elements) => listLiteral2(null
, null, elements); |
| 243 |
| 244 static ListLiteral listLiteral2(Keyword keyword, TypeArgumentList typeArgument
s, List<Expression> elements) => new ListLiteral(keyword == null ? null : TokenF
actory.tokenFromKeyword(keyword), typeArguments, TokenFactory.tokenFromType(Toke
nType.OPEN_SQUARE_BRACKET), list(elements), TokenFactory.tokenFromType(TokenType
.CLOSE_SQUARE_BRACKET)); |
| 245 |
| 246 static MapLiteral mapLiteral(Keyword keyword, TypeArgumentList typeArguments,
List<MapLiteralEntry> entries) => new MapLiteral(keyword == null ? null : TokenF
actory.tokenFromKeyword(keyword), typeArguments, TokenFactory.tokenFromType(Toke
nType.OPEN_CURLY_BRACKET), list(entries), TokenFactory.tokenFromType(TokenType.C
LOSE_CURLY_BRACKET)); |
| 247 |
| 248 static MapLiteral mapLiteral2(List<MapLiteralEntry> entries) => mapLiteral(nul
l, null, entries); |
| 249 |
| 250 static MapLiteralEntry mapLiteralEntry(String key, Expression value) => new Ma
pLiteralEntry(string2(key), TokenFactory.tokenFromType(TokenType.COLON), value); |
| 251 |
| 252 static MethodDeclaration methodDeclaration(Keyword modifier, TypeName returnTy
pe, Keyword property, Keyword operator, SimpleIdentifier name, FormalParameterLi
st parameters) => new MethodDeclaration(null, null, TokenFactory.tokenFromKeywor
d(Keyword.EXTERNAL), modifier == null ? null : TokenFactory.tokenFromKeyword(mod
ifier), returnType, property == null ? null : TokenFactory.tokenFromKeyword(prop
erty), operator == null ? null : TokenFactory.tokenFromKeyword(operator), name,
parameters, emptyFunctionBody()); |
| 253 |
| 254 static MethodDeclaration methodDeclaration2(Keyword modifier, TypeName returnT
ype, Keyword property, Keyword operator, SimpleIdentifier name, FormalParameterL
ist parameters, FunctionBody body) => new MethodDeclaration(null, null, null, mo
difier == null ? null : TokenFactory.tokenFromKeyword(modifier), returnType, pro
perty == null ? null : TokenFactory.tokenFromKeyword(property), operator == null
? null : TokenFactory.tokenFromKeyword(operator), name, parameters, body); |
| 255 |
| 256 static MethodInvocation methodInvocation(Expression target, String methodName,
List<Expression> arguments) => new MethodInvocation(target, target == null ? nu
ll : TokenFactory.tokenFromType(TokenType.PERIOD), identifier3(methodName), argu
mentList(arguments)); |
| 257 |
| 258 static MethodInvocation methodInvocation2(String methodName, List<Expression>
arguments) => methodInvocation(null, methodName, arguments); |
| 259 |
| 260 static NamedExpression namedExpression(Label label, Expression expression) =>
new NamedExpression(label, expression); |
| 261 |
| 262 static NamedExpression namedExpression2(String label, Expression expression) =
> namedExpression(label2(label), expression); |
| 263 |
| 264 static DefaultFormalParameter namedFormalParameter(NormalFormalParameter param
eter, Expression expression) => new DefaultFormalParameter(parameter, ParameterK
ind.NAMED, expression == null ? null : TokenFactory.tokenFromType(TokenType.COLO
N), expression); |
| 265 |
| 266 static NativeClause nativeClause(String nativeCode) => new NativeClause(TokenF
actory.tokenFromString("native"), string2(nativeCode)); |
| 267 |
| 268 static NativeFunctionBody nativeFunctionBody(String nativeMethodName) => new N
ativeFunctionBody(TokenFactory.tokenFromString("native"), string2(nativeMethodNa
me), TokenFactory.tokenFromType(TokenType.SEMICOLON)); |
| 269 |
| 270 static NullLiteral nullLiteral() => new NullLiteral(TokenFactory.tokenFromKeyw
ord(Keyword.NULL)); |
| 271 |
| 272 static ParenthesizedExpression parenthesizedExpression(Expression expression)
=> new ParenthesizedExpression(TokenFactory.tokenFromType(TokenType.OPEN_PAREN),
expression, TokenFactory.tokenFromType(TokenType.CLOSE_PAREN)); |
| 273 |
| 274 static PartDirective partDirective(List<Annotation> metadata, String url) => n
ew PartDirective(null, metadata, TokenFactory.tokenFromKeyword(Keyword.PART), st
ring2(url), TokenFactory.tokenFromType(TokenType.SEMICOLON)); |
| 275 |
| 276 static PartDirective partDirective2(String url) => partDirective(new List<Anno
tation>(), url); |
| 277 |
| 278 static PartOfDirective partOfDirective(LibraryIdentifier libraryName) => partO
fDirective2(new List<Annotation>(), libraryName); |
| 279 |
| 280 static PartOfDirective partOfDirective2(List<Annotation> metadata, LibraryIden
tifier libraryName) => new PartOfDirective(null, metadata, TokenFactory.tokenFro
mKeyword(Keyword.PART), TokenFactory.tokenFromString("of"), libraryName, TokenFa
ctory.tokenFromType(TokenType.SEMICOLON)); |
| 281 |
| 282 static DefaultFormalParameter positionalFormalParameter(NormalFormalParameter
parameter, Expression expression) => new DefaultFormalParameter(parameter, Param
eterKind.POSITIONAL, expression == null ? null : TokenFactory.tokenFromType(Toke
nType.EQ), expression); |
| 283 |
| 284 static PostfixExpression postfixExpression(Expression expression, TokenType op
erator) => new PostfixExpression(expression, TokenFactory.tokenFromType(operator
)); |
| 285 |
| 286 static PrefixExpression prefixExpression(TokenType operator, Expression expres
sion) => new PrefixExpression(TokenFactory.tokenFromType(operator), expression); |
| 287 |
| 288 static PropertyAccess propertyAccess(Expression target, SimpleIdentifier prope
rtyName) => new PropertyAccess(target, TokenFactory.tokenFromType(TokenType.PERI
OD), propertyName); |
| 289 |
| 290 static PropertyAccess propertyAccess2(Expression target, String propertyName)
=> new PropertyAccess(target, TokenFactory.tokenFromType(TokenType.PERIOD), iden
tifier3(propertyName)); |
| 291 |
| 292 static RedirectingConstructorInvocation redirectingConstructorInvocation(List<
Expression> arguments) => redirectingConstructorInvocation2(null, arguments); |
| 293 |
| 294 static RedirectingConstructorInvocation redirectingConstructorInvocation2(Stri
ng constructorName, List<Expression> arguments) => new RedirectingConstructorInv
ocation(TokenFactory.tokenFromKeyword(Keyword.THIS), constructorName == null ? n
ull : TokenFactory.tokenFromType(TokenType.PERIOD), constructorName == null ? nu
ll : identifier3(constructorName), argumentList(arguments)); |
| 295 |
| 296 static RethrowExpression rethrowExpression() => new RethrowExpression(TokenFac
tory.tokenFromKeyword(Keyword.RETHROW)); |
| 297 |
| 298 static ReturnStatement returnStatement() => returnStatement2(null); |
| 299 |
| 300 static ReturnStatement returnStatement2(Expression expression) => new ReturnSt
atement(TokenFactory.tokenFromKeyword(Keyword.RETURN), expression, TokenFactory.
tokenFromType(TokenType.SEMICOLON)); |
| 301 |
| 302 static ScriptTag scriptTag(String scriptTag) => new ScriptTag(TokenFactory.tok
enFromString(scriptTag)); |
| 303 |
| 304 static ShowCombinator showCombinator(List<SimpleIdentifier> identifiers) => ne
w ShowCombinator(TokenFactory.tokenFromString("show"), list(identifiers)); |
| 305 |
| 306 static ShowCombinator showCombinator2(List<String> identifiers) { |
| 307 List<SimpleIdentifier> identifierList = new List<SimpleIdentifier>(); |
| 308 for (String identifier in identifiers) { |
| 309 identifierList.add(identifier3(identifier)); |
| 310 } |
| 311 return new ShowCombinator(TokenFactory.tokenFromString("show"), identifierLi
st); |
| 312 } |
| 313 |
| 314 static SimpleFormalParameter simpleFormalParameter(Keyword keyword, String par
ameterName) => simpleFormalParameter2(keyword, null, parameterName); |
| 315 |
| 316 static SimpleFormalParameter simpleFormalParameter2(Keyword keyword, TypeName
type, String parameterName) => new SimpleFormalParameter(null, null, keyword ==
null ? null : TokenFactory.tokenFromKeyword(keyword), type, identifier3(paramete
rName)); |
| 317 |
| 318 static SimpleFormalParameter simpleFormalParameter3(String parameterName) => s
impleFormalParameter2(null, null, parameterName); |
| 319 |
| 320 static SimpleFormalParameter simpleFormalParameter4(TypeName type, String para
meterName) => simpleFormalParameter2(null, type, parameterName); |
| 321 |
| 322 static StringInterpolation string(List<InterpolationElement> elements) => new
StringInterpolation(list(elements)); |
| 323 |
| 324 static SimpleStringLiteral string2(String content) => new SimpleStringLiteral(
TokenFactory.tokenFromString("'${content}'"), content); |
| 325 |
| 326 static SuperConstructorInvocation superConstructorInvocation(List<Expression>
arguments) => superConstructorInvocation2(null, arguments); |
| 327 |
| 328 static SuperConstructorInvocation superConstructorInvocation2(String name, Lis
t<Expression> arguments) => new SuperConstructorInvocation(TokenFactory.tokenFro
mKeyword(Keyword.SUPER), name == null ? null : TokenFactory.tokenFromType(TokenT
ype.PERIOD), name == null ? null : identifier3(name), argumentList(arguments)); |
| 329 |
| 330 static SuperExpression superExpression() => new SuperExpression(TokenFactory.t
okenFromKeyword(Keyword.SUPER)); |
| 331 |
| 332 static SwitchCase switchCase(Expression expression, List<Statement> statements
) => switchCase2(new List<Label>(), expression, statements); |
| 333 |
| 334 static SwitchCase switchCase2(List<Label> labels, Expression expression, List<
Statement> statements) => new SwitchCase(labels, TokenFactory.tokenFromKeyword(K
eyword.CASE), expression, TokenFactory.tokenFromType(TokenType.COLON), list(stat
ements)); |
| 335 |
| 336 static SwitchDefault switchDefault(List<Label> labels, List<Statement> stateme
nts) => new SwitchDefault(labels, TokenFactory.tokenFromKeyword(Keyword.DEFAULT)
, TokenFactory.tokenFromType(TokenType.COLON), list(statements)); |
| 337 |
| 338 static SwitchDefault switchDefault2(List<Statement> statements) => switchDefau
lt(new List<Label>(), statements); |
| 339 |
| 340 static SwitchStatement switchStatement(Expression expression, List<SwitchMembe
r> members) => new SwitchStatement(TokenFactory.tokenFromKeyword(Keyword.SWITCH)
, TokenFactory.tokenFromType(TokenType.OPEN_PAREN), expression, TokenFactory.tok
enFromType(TokenType.CLOSE_PAREN), TokenFactory.tokenFromType(TokenType.OPEN_CUR
LY_BRACKET), list(members), TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRA
CKET)); |
| 341 |
| 342 static SymbolLiteral symbolLiteral(List<String> components) { |
| 343 List<Token> identifierList = new List<Token>(); |
| 344 for (String component in components) { |
| 345 identifierList.add(TokenFactory.tokenFromTypeAndString(TokenType.IDENTIFIE
R, component)); |
| 346 } |
| 347 return new SymbolLiteral(TokenFactory.tokenFromType(TokenType.HASH), new Lis
t.from(identifierList)); |
| 348 } |
| 349 |
| 350 static ThisExpression thisExpression() => new ThisExpression(TokenFactory.toke
nFromKeyword(Keyword.THIS)); |
| 351 |
| 352 static ThrowExpression throwExpression() => throwExpression2(null); |
| 353 |
| 354 static ThrowExpression throwExpression2(Expression expression) => new ThrowExp
ression(TokenFactory.tokenFromKeyword(Keyword.THROW), expression); |
| 355 |
| 356 static TopLevelVariableDeclaration topLevelVariableDeclaration(Keyword keyword
, TypeName type, List<VariableDeclaration> variables) => new TopLevelVariableDec
laration(null, null, variableDeclarationList(keyword, type, variables), TokenFac
tory.tokenFromType(TokenType.SEMICOLON)); |
| 357 |
| 358 static TopLevelVariableDeclaration topLevelVariableDeclaration2(Keyword keywor
d, List<VariableDeclaration> variables) => new TopLevelVariableDeclaration(null,
null, variableDeclarationList(keyword, null, variables), TokenFactory.tokenFrom
Type(TokenType.SEMICOLON)); |
| 359 |
| 360 static TryStatement tryStatement(Block body, Block finallyClause) => tryStatem
ent3(body, new List<CatchClause>(), finallyClause); |
| 361 |
| 362 static TryStatement tryStatement2(Block body, List<CatchClause> catchClauses)
=> tryStatement3(body, list(catchClauses), null); |
| 363 |
| 364 static TryStatement tryStatement3(Block body, List<CatchClause> catchClauses,
Block finallyClause) => new TryStatement(TokenFactory.tokenFromKeyword(Keyword.T
RY), body, catchClauses, finallyClause == null ? null : TokenFactory.tokenFromKe
yword(Keyword.FINALLY), finallyClause); |
| 365 |
| 366 static FunctionTypeAlias typeAlias(TypeName returnType, String name, TypeParam
eterList typeParameters, FormalParameterList parameters) => new FunctionTypeAlia
s(null, null, TokenFactory.tokenFromKeyword(Keyword.TYPEDEF), returnType, identi
fier3(name), typeParameters, parameters, TokenFactory.tokenFromType(TokenType.SE
MICOLON)); |
| 367 |
| 368 static TypeArgumentList typeArgumentList(List<TypeName> typeNames) => new Type
ArgumentList(TokenFactory.tokenFromType(TokenType.LT), list(typeNames), TokenFac
tory.tokenFromType(TokenType.GT)); |
| 369 |
| 370 /** |
| 371 * Create a type name whose name has been resolved to the given element and wh
ose type has been |
| 372 * resolved to the type of the given element. |
| 373 * |
| 374 * <b>Note:</b> This method does not correctly handle class elements that have
type parameters. |
| 375 * |
| 376 * @param element the element defining the type represented by the type name |
| 377 * @return the type name that was created |
| 378 */ |
| 379 static TypeName typeName(ClassElement element, List<TypeName> arguments) { |
| 380 SimpleIdentifier name = identifier3(element.name); |
| 381 name.staticElement = element; |
| 382 TypeName typeName = typeName3(name, arguments); |
| 383 typeName.type = element.type; |
| 384 return typeName; |
| 385 } |
| 386 |
| 387 static TypeName typeName3(Identifier name, List<TypeName> arguments) { |
| 388 if (arguments.length == 0) { |
| 389 return new TypeName(name, null); |
| 390 } |
| 391 return new TypeName(name, typeArgumentList(arguments)); |
| 392 } |
| 393 |
| 394 static TypeName typeName4(String name, List<TypeName> arguments) { |
| 395 if (arguments.length == 0) { |
| 396 return new TypeName(identifier3(name), null); |
| 397 } |
| 398 return new TypeName(identifier3(name), typeArgumentList(arguments)); |
| 399 } |
| 400 |
| 401 static TypeParameter typeParameter(String name) => new TypeParameter(null, nul
l, identifier3(name), null, null); |
| 402 |
| 403 static TypeParameter typeParameter2(String name, TypeName bound) => new TypePa
rameter(null, null, identifier3(name), TokenFactory.tokenFromKeyword(Keyword.EXT
ENDS), bound); |
| 404 |
| 405 static TypeParameterList typeParameterList(List<String> typeNames) { |
| 406 List<TypeParameter> typeParameters = new List<TypeParameter>(); |
| 407 for (String typeName in typeNames) { |
| 408 typeParameters.add(typeParameter(typeName)); |
| 409 } |
| 410 return new TypeParameterList(TokenFactory.tokenFromType(TokenType.LT), typeP
arameters, TokenFactory.tokenFromType(TokenType.GT)); |
| 411 } |
| 412 |
| 413 static VariableDeclaration variableDeclaration(String name) => new VariableDec
laration(null, null, identifier3(name), null, null); |
| 414 |
| 415 static VariableDeclaration variableDeclaration2(String name, Expression initia
lizer) => new VariableDeclaration(null, null, identifier3(name), TokenFactory.to
kenFromType(TokenType.EQ), initializer); |
| 416 |
| 417 static VariableDeclarationList variableDeclarationList(Keyword keyword, TypeNa
me type, List<VariableDeclaration> variables) => new VariableDeclarationList(nul
l, null, keyword == null ? null : TokenFactory.tokenFromKeyword(keyword), type,
list(variables)); |
| 418 |
| 419 static VariableDeclarationList variableDeclarationList2(Keyword keyword, List<
VariableDeclaration> variables) => variableDeclarationList(keyword, null, variab
les); |
| 420 |
| 421 static VariableDeclarationStatement variableDeclarationStatement(Keyword keywo
rd, TypeName type, List<VariableDeclaration> variables) => new VariableDeclarati
onStatement(variableDeclarationList(keyword, type, variables), TokenFactory.toke
nFromType(TokenType.SEMICOLON)); |
| 422 |
| 423 static VariableDeclarationStatement variableDeclarationStatement2(Keyword keyw
ord, List<VariableDeclaration> variables) => variableDeclarationStatement(keywor
d, null, variables); |
| 424 |
| 425 static WhileStatement whileStatement(Expression condition, Statement body) =>
new WhileStatement(TokenFactory.tokenFromKeyword(Keyword.WHILE), TokenFactory.to
kenFromType(TokenType.OPEN_PAREN), condition, TokenFactory.tokenFromType(TokenTy
pe.CLOSE_PAREN), body); |
| 426 |
| 427 static WithClause withClause(List<TypeName> types) => new WithClause(TokenFact
ory.tokenFromKeyword(Keyword.WITH), list(types)); |
| 428 } |
| OLD | NEW |