| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:convert'; | 6 import 'dart:convert'; |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| 11 import 'package:analyzer/dart/ast/visitor.dart'; | 11 import 'package:analyzer/dart/ast/visitor.dart'; |
| 12 import 'package:analyzer/dart/element/element.dart'; | 12 import 'package:analyzer/dart/element/element.dart'; |
| 13 import 'package:analyzer/dart/element/type.dart'; | 13 import 'package:analyzer/dart/element/type.dart'; |
| 14 import 'package:analyzer/src/dart/analysis/driver.dart'; | 14 import 'package:analyzer/src/dart/analysis/driver.dart'; |
| 15 import 'package:analyzer/src/generated/parser.dart'; | 15 import 'package:analyzer/src/generated/parser.dart'; |
| 16 import 'package:analyzer/src/generated/scanner.dart'; | 16 import 'package:analyzer/src/generated/scanner.dart'; |
| 17 import 'package:analyzer/src/generated/source.dart'; | 17 import 'package:analyzer/src/generated/source.dart'; |
| 18 import 'package:analyzer/src/generated/utilities_dart.dart'; | 18 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 19 import 'package:front_end/src/base/instrumentation.dart' as fasta; | 19 import 'package:front_end/src/base/instrumentation.dart' as fasta; |
| 20 import 'package:front_end/src/fasta/compiler_context.dart' as fasta; | 20 import 'package:front_end/src/fasta/compiler_context.dart' as fasta; |
| 21 import 'package:front_end/src/fasta/compiler_command_line.dart' as fasta; |
| 21 import 'package:front_end/src/fasta/testing/validating_instrumentation.dart' | 22 import 'package:front_end/src/fasta/testing/validating_instrumentation.dart' |
| 22 as fasta; | 23 as fasta; |
| 23 import 'package:front_end/src/fasta/util/relativize.dart' show relativizeUri; | 24 import 'package:front_end/src/fasta/util/relativize.dart' show relativizeUri; |
| 24 import 'package:kernel/kernel.dart' as fasta; | 25 import 'package:kernel/kernel.dart' as fasta; |
| 25 import 'package:path/path.dart' as pathos; | 26 import 'package:path/path.dart' as pathos; |
| 26 import 'package:test/test.dart'; | 27 import 'package:test/test.dart'; |
| 27 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 28 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 28 | 29 |
| 29 import '../../dart/analysis/base.dart'; | 30 import '../../dart/analysis/base.dart'; |
| 30 | 31 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 } else if (name.endsWith('=') && | 127 } else if (name.endsWith('=') && |
| 127 element is PropertyAccessorElement && | 128 element is PropertyAccessorElement && |
| 128 element.isSetter) { | 129 element.isSetter) { |
| 129 name = name.substring(0, name.length - 1); | 130 name = name.substring(0, name.length - 1); |
| 130 } | 131 } |
| 131 buffer.write(name); | 132 buffer.write(name); |
| 132 } | 133 } |
| 133 } | 134 } |
| 134 | 135 |
| 135 class _FrontEndInferenceTest extends BaseAnalysisDriverTest { | 136 class _FrontEndInferenceTest extends BaseAnalysisDriverTest { |
| 136 Future<String> runTest(String path, String code) async { | 137 Future<String> runTest(String path, String code) { |
| 137 Uri uri = provider.pathContext.toUri(path); | 138 return fasta.CompilerCommandLine.withGlobalOptions("", [""], (_) async { |
| 139 Uri uri = provider.pathContext.toUri(path); |
| 138 | 140 |
| 139 List<int> lineStarts = new LineInfo.fromContent(code).lineStarts; | 141 List<int> lineStarts = new LineInfo.fromContent(code).lineStarts; |
| 140 fasta.CompilerContext.current.uriToSource[relativizeUri(uri).toString()] = | 142 fasta.CompilerContext.current.uriToSource[relativizeUri(uri).toString()] = |
| 141 new fasta.Source(lineStarts, UTF8.encode(code)); | 143 new fasta.Source(lineStarts, UTF8.encode(code)); |
| 142 | 144 |
| 143 var validation = new fasta.ValidatingInstrumentation(); | 145 var validation = new fasta.ValidatingInstrumentation(); |
| 144 await validation.loadExpectations(uri); | 146 await validation.loadExpectations(uri); |
| 145 | 147 |
| 146 _addFileAndImports(path, code); | 148 _addFileAndImports(path, code); |
| 147 | 149 |
| 148 AnalysisResult result = await driver.getResult(path); | 150 AnalysisResult result = await driver.getResult(path); |
| 149 result.unit.accept(new _InstrumentationVisitor(validation, uri)); | 151 result.unit.accept(new _InstrumentationVisitor(validation, uri)); |
| 150 | 152 |
| 151 validation.finish(); | 153 validation.finish(); |
| 152 | 154 |
| 153 if (validation.hasProblems) { | 155 if (validation.hasProblems) { |
| 154 if (fixProblems) { | 156 if (fixProblems) { |
| 155 validation.fixSource(uri, true); | 157 validation.fixSource(uri, true); |
| 158 return null; |
| 159 } else { |
| 160 return validation.problemsAsString; |
| 161 } |
| 162 } else { |
| 156 return null; | 163 return null; |
| 157 } else { | |
| 158 return validation.problemsAsString; | |
| 159 } | 164 } |
| 160 } else { | 165 }); |
| 161 return null; | |
| 162 } | |
| 163 } | 166 } |
| 164 | 167 |
| 165 void _addFileAndImports(String path, String code) { | 168 void _addFileAndImports(String path, String code) { |
| 166 provider.newFile(path, code); | 169 provider.newFile(path, code); |
| 167 var source = null; | 170 var source = null; |
| 168 var analysisErrorListener = null; | 171 var analysisErrorListener = null; |
| 169 var scanner = new Scanner( | 172 var scanner = new Scanner( |
| 170 source, new CharSequenceReader(code), analysisErrorListener); | 173 source, new CharSequenceReader(code), analysisErrorListener); |
| 171 var token = scanner.tokenize(); | 174 var token = scanner.tokenize(); |
| 172 var compilationUnit = | 175 var compilationUnit = |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 | 637 |
| 635 /// Based on DDC code generator's `_recoverTypeArguments` | 638 /// Based on DDC code generator's `_recoverTypeArguments` |
| 636 Iterable<DartType> _recoverTypeArguments(FunctionType g, FunctionType f) { | 639 Iterable<DartType> _recoverTypeArguments(FunctionType g, FunctionType f) { |
| 637 assert(identical(g.element, f.element)); | 640 assert(identical(g.element, f.element)); |
| 638 assert(g.typeFormals.isNotEmpty && f.typeFormals.isEmpty); | 641 assert(g.typeFormals.isNotEmpty && f.typeFormals.isEmpty); |
| 639 assert(g.typeFormals.length + g.typeArguments.length == | 642 assert(g.typeFormals.length + g.typeArguments.length == |
| 640 f.typeArguments.length); | 643 f.typeArguments.length); |
| 641 return f.typeArguments.skip(g.typeArguments.length); | 644 return f.typeArguments.skip(g.typeArguments.length); |
| 642 } | 645 } |
| 643 } | 646 } |
| OLD | NEW |