| 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/visitor.dart'; | 10 import 'package:analyzer/dart/ast/visitor.dart'; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 final ConstructorElement currentFactoryConstructor; | 89 final ConstructorElement currentFactoryConstructor; |
| 90 | 90 |
| 91 _ElementNamer(this.currentFactoryConstructor); | 91 _ElementNamer(this.currentFactoryConstructor); |
| 92 | 92 |
| 93 void appendElementName(StringBuffer buffer, Element element) { | 93 void appendElementName(StringBuffer buffer, Element element) { |
| 94 // Synthetic FunctionElement(s) don't have a name or enclosing library. | 94 // Synthetic FunctionElement(s) don't have a name or enclosing library. |
| 95 if (element.isSynthetic && element is FunctionElement) { | 95 if (element.isSynthetic && element is FunctionElement) { |
| 96 return; | 96 return; |
| 97 } | 97 } |
| 98 | 98 |
| 99 LibraryElement library = element.library; | 99 var enclosing = element.enclosingElement; |
| 100 if (library == null) { | 100 if (enclosing is CompilationUnitElement) { |
| 101 throw new StateError('Unexpected element without library: $element'); | 101 enclosing = enclosing.enclosingElement; |
| 102 } else if (enclosing is ClassElement && |
| 103 currentFactoryConstructor != null && |
| 104 identical(enclosing, currentFactoryConstructor.enclosingElement) && |
| 105 element is TypeParameterElement) { |
| 106 enclosing = currentFactoryConstructor; |
| 102 } | 107 } |
| 103 String libraryName = library.name; | 108 if (enclosing != null) { |
| 109 if (enclosing is LibraryElement && |
| 110 (enclosing.name == 'dart.core' || |
| 111 enclosing.name == 'dart.async' || |
| 112 enclosing.name == 'test')) { |
| 113 // For brevity, omit library name |
| 114 } else { |
| 115 appendElementName(buffer, enclosing); |
| 116 buffer.write('::'); |
| 117 } |
| 118 } |
| 104 | 119 |
| 105 String name = element.name ?? ''; | 120 String name = element.name ?? ''; |
| 106 if (name.endsWith('=') && | 121 if (element is ConstructorElement && name == '') { |
| 122 name = '•'; |
| 123 } else if (name.endsWith('=') && |
| 107 element is PropertyAccessorElement && | 124 element is PropertyAccessorElement && |
| 108 element.isSetter) { | 125 element.isSetter) { |
| 109 name = name.substring(0, name.length - 1); | 126 name = name.substring(0, name.length - 1); |
| 110 } | 127 } |
| 111 if (libraryName != 'dart.core' && | 128 buffer.write(name); |
| 112 libraryName != 'dart.async' && | |
| 113 libraryName != 'test') { | |
| 114 buffer.write('$libraryName::'); | |
| 115 } | |
| 116 var enclosing = element.enclosingElement; | |
| 117 if (enclosing is ClassElement) { | |
| 118 buffer.write('${enclosing.name}::'); | |
| 119 if (currentFactoryConstructor != null && | |
| 120 identical(enclosing, currentFactoryConstructor.enclosingElement) && | |
| 121 element is TypeParameterElement) { | |
| 122 String factoryConstructorName = currentFactoryConstructor.name; | |
| 123 if (factoryConstructorName == '') { | |
| 124 factoryConstructorName = '•'; | |
| 125 } | |
| 126 buffer.write('$factoryConstructorName::'); | |
| 127 } | |
| 128 } | |
| 129 buffer.write('$name'); | |
| 130 } | 129 } |
| 131 } | 130 } |
| 132 | 131 |
| 133 class _FrontEndInferenceTest extends BaseAnalysisDriverTest { | 132 class _FrontEndInferenceTest extends BaseAnalysisDriverTest { |
| 134 Future<String> runTest(String path, String code) async { | 133 Future<String> runTest(String path, String code) async { |
| 135 Uri uri = provider.pathContext.toUri(path); | 134 Uri uri = provider.pathContext.toUri(path); |
| 136 | 135 |
| 137 List<int> lineStarts = new LineInfo.fromContent(code).lineStarts; | 136 List<int> lineStarts = new LineInfo.fromContent(code).lineStarts; |
| 138 fasta.CompilerContext.current.uriToSource[relativizeUri(uri).toString()] = | 137 fasta.CompilerContext.current.uriToSource[relativizeUri(uri).toString()] = |
| 139 new fasta.Source(lineStarts, UTF8.encode(code)); | 138 new fasta.Source(lineStarts, UTF8.encode(code)); |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 | 522 |
| 524 /// Based on DDC code generator's `_recoverTypeArguments` | 523 /// Based on DDC code generator's `_recoverTypeArguments` |
| 525 Iterable<DartType> _recoverTypeArguments(FunctionType g, FunctionType f) { | 524 Iterable<DartType> _recoverTypeArguments(FunctionType g, FunctionType f) { |
| 526 assert(identical(g.element, f.element)); | 525 assert(identical(g.element, f.element)); |
| 527 assert(g.typeFormals.isNotEmpty && f.typeFormals.isEmpty); | 526 assert(g.typeFormals.isNotEmpty && f.typeFormals.isEmpty); |
| 528 assert(g.typeFormals.length + g.typeArguments.length == | 527 assert(g.typeFormals.length + g.typeArguments.length == |
| 529 f.typeArguments.length); | 528 f.typeArguments.length); |
| 530 return f.typeArguments.skip(g.typeArguments.length); | 529 return f.typeArguments.skip(g.typeArguments.length); |
| 531 } | 530 } |
| 532 } | 531 } |
| OLD | NEW |