| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.test.constant_test; | 5 library analyzer.test.constant_test; |
| 6 | 6 |
| 7 import 'package:analyzer/context/declared_variables.dart'; | 7 import 'package:analyzer/context/declared_variables.dart'; |
| 8 import 'package:analyzer/dart/ast/ast.dart'; | 8 import 'package:analyzer/dart/ast/ast.dart'; |
| 9 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 9 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
| 10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| (...skipping 1563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1574 expect(result.type.name, "int"); | 1574 expect(result.type.name, "int"); |
| 1575 expect(result.toIntValue(), expectedValue); | 1575 expect(result.toIntValue(), expectedValue); |
| 1576 } | 1576 } |
| 1577 | 1577 |
| 1578 NonExistingSource _dummySource() { | 1578 NonExistingSource _dummySource() { |
| 1579 String path = '/test.dart'; | 1579 String path = '/test.dart'; |
| 1580 return new NonExistingSource(path, toUri(path), UriKind.FILE_URI); | 1580 return new NonExistingSource(path, toUri(path), UriKind.FILE_URI); |
| 1581 } | 1581 } |
| 1582 | 1582 |
| 1583 DartObjectImpl _evaluate(Expression expression, ErrorReporter errorReporter) { | 1583 DartObjectImpl _evaluate(Expression expression, ErrorReporter errorReporter) { |
| 1584 TestTypeProvider typeProvider = new TestTypeProvider(); |
| 1584 return expression.accept(new ConstantVisitor( | 1585 return expression.accept(new ConstantVisitor( |
| 1585 new ConstantEvaluationEngine( | 1586 new ConstantEvaluationEngine(typeProvider, new DeclaredVariables(), |
| 1586 new TestTypeProvider(), new DeclaredVariables(), | 1587 typeSystem: new TypeSystemImpl(typeProvider)), |
| 1587 typeSystem: new TypeSystemImpl()), | |
| 1588 errorReporter)); | 1588 errorReporter)); |
| 1589 } | 1589 } |
| 1590 | 1590 |
| 1591 DartObjectImpl _evaluateConstant(CompilationUnit compilationUnit, String name, | 1591 DartObjectImpl _evaluateConstant(CompilationUnit compilationUnit, String name, |
| 1592 Map<String, DartObjectImpl> lexicalEnvironment) { | 1592 Map<String, DartObjectImpl> lexicalEnvironment) { |
| 1593 Source source = | 1593 Source source = |
| 1594 resolutionMap.elementDeclaredByCompilationUnit(compilationUnit).source; | 1594 resolutionMap.elementDeclaredByCompilationUnit(compilationUnit).source; |
| 1595 Expression expression = | 1595 Expression expression = |
| 1596 findTopLevelConstantExpression(compilationUnit, name); | 1596 findTopLevelConstantExpression(compilationUnit, name); |
| 1597 GatheringErrorListener errorListener = new GatheringErrorListener(); | 1597 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 1598 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); | 1598 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); |
| 1599 DartObjectImpl result = expression.accept(new ConstantVisitor( | 1599 DartObjectImpl result = expression.accept(new ConstantVisitor( |
| 1600 new ConstantEvaluationEngine(typeProvider, new DeclaredVariables(), | 1600 new ConstantEvaluationEngine(typeProvider, new DeclaredVariables(), |
| 1601 typeSystem: typeSystem), | 1601 typeSystem: typeSystem), |
| 1602 errorReporter, | 1602 errorReporter, |
| 1603 lexicalEnvironment: lexicalEnvironment)); | 1603 lexicalEnvironment: lexicalEnvironment)); |
| 1604 errorListener.assertNoErrors(); | 1604 errorListener.assertNoErrors(); |
| 1605 return result; | 1605 return result; |
| 1606 } | 1606 } |
| 1607 } | 1607 } |
| 1608 | 1608 |
| 1609 @reflectiveTest | 1609 @reflectiveTest |
| 1610 class StrongConstantValueComputerTest extends ConstantValueComputerTest { | 1610 class StrongConstantValueComputerTest extends ConstantValueComputerTest { |
| 1611 void setUp() { | 1611 void setUp() { |
| 1612 super.setUp(); | 1612 super.setUp(); |
| 1613 resetWithOptions(new AnalysisOptionsImpl()..strongMode = true); | 1613 resetWithOptions(new AnalysisOptionsImpl()..strongMode = true); |
| 1614 } | 1614 } |
| 1615 } | 1615 } |
| OLD | NEW |