| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.src.dart.constant.evaluation; | 5 library analyzer.src.dart.constant.evaluation; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/context/declared_variables.dart'; | 9 import 'package:analyzer/context/declared_variables.dart'; |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 1340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1351 if (elementResult == null) { | 1351 if (elementResult == null) { |
| 1352 errorOccurred = true; | 1352 errorOccurred = true; |
| 1353 } else { | 1353 } else { |
| 1354 elements.add(elementResult); | 1354 elements.add(elementResult); |
| 1355 } | 1355 } |
| 1356 } | 1356 } |
| 1357 if (errorOccurred) { | 1357 if (errorOccurred) { |
| 1358 return null; | 1358 return null; |
| 1359 } | 1359 } |
| 1360 DartType elementType = _typeProvider.dynamicType; | 1360 DartType elementType = _typeProvider.dynamicType; |
| 1361 NodeList<TypeName> typeArgs = node.typeArguments?.arguments; | 1361 NodeList<TypeAnnotation> typeArgs = node.typeArguments?.arguments; |
| 1362 if (typeArgs?.length == 1) { | 1362 if (typeArgs?.length == 1) { |
| 1363 DartType type = visitTypeName(typeArgs[0])?.toTypeValue(); | 1363 DartType type = visitTypeAnnotation(typeArgs[0])?.toTypeValue(); |
| 1364 if (type != null) { | 1364 if (type != null) { |
| 1365 elementType = type; | 1365 elementType = type; |
| 1366 } | 1366 } |
| 1367 } | 1367 } |
| 1368 InterfaceType listType = _typeProvider.listType.instantiate([elementType]); | 1368 InterfaceType listType = _typeProvider.listType.instantiate([elementType]); |
| 1369 return new DartObjectImpl(listType, new ListState(elements)); | 1369 return new DartObjectImpl(listType, new ListState(elements)); |
| 1370 } | 1370 } |
| 1371 | 1371 |
| 1372 @override | 1372 @override |
| 1373 DartObjectImpl visitMapLiteral(MapLiteral node) { | 1373 DartObjectImpl visitMapLiteral(MapLiteral node) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1386 errorOccurred = true; | 1386 errorOccurred = true; |
| 1387 } else { | 1387 } else { |
| 1388 map[keyResult] = valueResult; | 1388 map[keyResult] = valueResult; |
| 1389 } | 1389 } |
| 1390 } | 1390 } |
| 1391 if (errorOccurred) { | 1391 if (errorOccurred) { |
| 1392 return null; | 1392 return null; |
| 1393 } | 1393 } |
| 1394 DartType keyType = _typeProvider.dynamicType; | 1394 DartType keyType = _typeProvider.dynamicType; |
| 1395 DartType valueType = _typeProvider.dynamicType; | 1395 DartType valueType = _typeProvider.dynamicType; |
| 1396 NodeList<TypeName> typeArgs = node.typeArguments?.arguments; | 1396 NodeList<TypeAnnotation> typeArgs = node.typeArguments?.arguments; |
| 1397 if (typeArgs?.length == 2) { | 1397 if (typeArgs?.length == 2) { |
| 1398 DartType keyTypeCandidate = visitTypeName(typeArgs[0])?.toTypeValue(); | 1398 DartType keyTypeCandidate = |
| 1399 visitTypeAnnotation(typeArgs[0])?.toTypeValue(); |
| 1399 if (keyTypeCandidate != null) { | 1400 if (keyTypeCandidate != null) { |
| 1400 keyType = keyTypeCandidate; | 1401 keyType = keyTypeCandidate; |
| 1401 } | 1402 } |
| 1402 DartType valueTypeCandidate = visitTypeName(typeArgs[1])?.toTypeValue(); | 1403 DartType valueTypeCandidate = |
| 1404 visitTypeAnnotation(typeArgs[1])?.toTypeValue(); |
| 1403 if (valueTypeCandidate != null) { | 1405 if (valueTypeCandidate != null) { |
| 1404 valueType = valueTypeCandidate; | 1406 valueType = valueTypeCandidate; |
| 1405 } | 1407 } |
| 1406 } | 1408 } |
| 1407 InterfaceType mapType = | 1409 InterfaceType mapType = |
| 1408 _typeProvider.mapType.instantiate([keyType, valueType]); | 1410 _typeProvider.mapType.instantiate([keyType, valueType]); |
| 1409 return new DartObjectImpl(mapType, new MapState(map)); | 1411 return new DartObjectImpl(mapType, new MapState(map)); |
| 1410 } | 1412 } |
| 1411 | 1413 |
| 1412 @override | 1414 @override |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1542 for (int i = 0; i < components.length; i++) { | 1544 for (int i = 0; i < components.length; i++) { |
| 1543 if (i > 0) { | 1545 if (i > 0) { |
| 1544 buffer.writeCharCode(0x2E); | 1546 buffer.writeCharCode(0x2E); |
| 1545 } | 1547 } |
| 1546 buffer.write(components[i].lexeme); | 1548 buffer.write(components[i].lexeme); |
| 1547 } | 1549 } |
| 1548 return new DartObjectImpl( | 1550 return new DartObjectImpl( |
| 1549 _typeProvider.symbolType, new SymbolState(buffer.toString())); | 1551 _typeProvider.symbolType, new SymbolState(buffer.toString())); |
| 1550 } | 1552 } |
| 1551 | 1553 |
| 1552 @override | 1554 DartObjectImpl visitTypeAnnotation(TypeAnnotation node) { |
| 1553 DartObjectImpl visitTypeName(TypeName node) { | |
| 1554 DartType type = evaluateType(node.type); | 1555 DartType type = evaluateType(node.type); |
| 1555 if (type == null) { | 1556 if (type == null) { |
| 1556 return super.visitTypeName(node); | 1557 return super.visitTypeName(node); |
| 1557 } | 1558 } |
| 1558 return typeConstant(type); | 1559 return typeConstant(type); |
| 1559 } | 1560 } |
| 1560 | 1561 |
| 1562 @override |
| 1563 DartObjectImpl visitTypeName(TypeName node) => visitTypeAnnotation(node); |
| 1564 |
| 1561 /** | 1565 /** |
| 1562 * Create an error associated with the given [node]. The error will have the | 1566 * Create an error associated with the given [node]. The error will have the |
| 1563 * given error [code]. | 1567 * given error [code]. |
| 1564 */ | 1568 */ |
| 1565 void _error(AstNode node, ErrorCode code) { | 1569 void _error(AstNode node, ErrorCode code) { |
| 1566 _errorReporter.reportErrorForNode( | 1570 _errorReporter.reportErrorForNode( |
| 1567 code ?? CompileTimeErrorCode.INVALID_CONSTANT, node); | 1571 code ?? CompileTimeErrorCode.INVALID_CONSTANT, node); |
| 1568 } | 1572 } |
| 1569 | 1573 |
| 1570 /** | 1574 /** |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2080 } | 2084 } |
| 2081 | 2085 |
| 2082 @override | 2086 @override |
| 2083 String toString() { | 2087 String toString() { |
| 2084 if (value == null) { | 2088 if (value == null) { |
| 2085 return "error"; | 2089 return "error"; |
| 2086 } | 2090 } |
| 2087 return value.toString(); | 2091 return value.toString(); |
| 2088 } | 2092 } |
| 2089 } | 2093 } |
| OLD | NEW |