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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 return; | 95 return; |
96 } | 96 } |
97 | 97 |
98 LibraryElement library = element.library; | 98 LibraryElement library = element.library; |
99 if (library == null) { | 99 if (library == null) { |
100 throw new StateError('Unexpected element without library: $element'); | 100 throw new StateError('Unexpected element without library: $element'); |
101 } | 101 } |
102 String libraryName = library.name; | 102 String libraryName = library.name; |
103 | 103 |
104 String name = element.name ?? ''; | 104 String name = element.name ?? ''; |
| 105 if (name.endsWith('=') && |
| 106 element is PropertyAccessorElement && |
| 107 element.isSetter) { |
| 108 name = name.substring(0, name.length - 1); |
| 109 } |
105 if (libraryName != 'dart.core' && | 110 if (libraryName != 'dart.core' && |
106 libraryName != 'dart.async' && | 111 libraryName != 'dart.async' && |
107 libraryName != 'test') { | 112 libraryName != 'test') { |
108 buffer.write('$libraryName::'); | 113 buffer.write('$libraryName::'); |
109 } | 114 } |
110 var enclosing = element.enclosingElement; | 115 var enclosing = element.enclosingElement; |
111 if (enclosing is ClassElement) { | 116 if (enclosing is ClassElement) { |
112 buffer.write('${enclosing.name}::'); | 117 buffer.write('${enclosing.name}::'); |
113 if (currentFactoryConstructor != null && | 118 if (currentFactoryConstructor != null && |
114 identical(enclosing, currentFactoryConstructor.enclosingElement)) { | 119 identical(enclosing, currentFactoryConstructor.enclosingElement) && |
| 120 element is TypeParameterElement) { |
115 String factoryConstructorName = currentFactoryConstructor.name; | 121 String factoryConstructorName = currentFactoryConstructor.name; |
116 if (factoryConstructorName == '') { | 122 if (factoryConstructorName == '') { |
117 factoryConstructorName = '•'; | 123 factoryConstructorName = '•'; |
118 } | 124 } |
119 buffer.write('$factoryConstructorName::'); | 125 buffer.write('$factoryConstructorName::'); |
120 } | 126 } |
121 } | 127 } |
122 buffer.write('$name'); | 128 buffer.write('$name'); |
123 } | 129 } |
124 } | 130 } |
(...skipping 11 matching lines...) Expand all Loading... |
136 | 142 |
137 provider.newFile(path, code); | 143 provider.newFile(path, code); |
138 | 144 |
139 AnalysisResult result = await driver.getResult(path); | 145 AnalysisResult result = await driver.getResult(path); |
140 result.unit.accept(new _InstrumentationVisitor(validation, uri)); | 146 result.unit.accept(new _InstrumentationVisitor(validation, uri)); |
141 | 147 |
142 validation.finish(); | 148 validation.finish(); |
143 | 149 |
144 if (validation.hasProblems) { | 150 if (validation.hasProblems) { |
145 if (fixProblems) { | 151 if (fixProblems) { |
146 validation.fixSource(uri); | 152 validation.fixSource(uri, true); |
147 return null; | 153 return null; |
148 } else { | 154 } else { |
149 return validation.problemsAsString; | 155 return validation.problemsAsString; |
150 } | 156 } |
151 } else { | 157 } else { |
152 return null; | 158 return null; |
153 } | 159 } |
154 } | 160 } |
155 } | 161 } |
156 | 162 |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 _recordTypeArguments(node.methodName.offset, inferredTypeArguments); | 393 _recordTypeArguments(node.methodName.offset, inferredTypeArguments); |
388 } | 394 } |
389 } | 395 } |
390 } | 396 } |
391 | 397 |
392 @override | 398 @override |
393 visitPrefixedIdentifier(PrefixedIdentifier node) { | 399 visitPrefixedIdentifier(PrefixedIdentifier node) { |
394 super.visitPrefixedIdentifier(node); | 400 super.visitPrefixedIdentifier(node); |
395 if (node.prefix.staticElement is! PrefixElement && | 401 if (node.prefix.staticElement is! PrefixElement && |
396 node.prefix.staticElement is! ClassElement) { | 402 node.prefix.staticElement is! ClassElement) { |
397 if (node.identifier.inGetterContext()) { | 403 if (node.identifier.inGetterContext() || |
| 404 node.identifier.inSetterContext()) { |
398 _recordTarget(node.identifier.offset, node.identifier.staticElement); | 405 _recordTarget(node.identifier.offset, node.identifier.staticElement); |
399 } | 406 } |
400 } | 407 } |
401 } | 408 } |
402 | 409 |
403 visitPrefixExpression(PrefixExpression node) { | 410 visitPrefixExpression(PrefixExpression node) { |
404 super.visitPrefixExpression(node); | 411 super.visitPrefixExpression(node); |
405 _recordTarget(node.operator.charOffset, node.staticElement); | 412 _recordTarget(node.operator.charOffset, node.staticElement); |
406 } | 413 } |
407 | 414 |
408 @override | 415 @override |
409 visitPropertyAccess(PropertyAccess node) { | 416 visitPropertyAccess(PropertyAccess node) { |
410 super.visitPropertyAccess(node); | 417 super.visitPropertyAccess(node); |
411 if (node.propertyName.inGetterContext()) { | 418 if (node.propertyName.inGetterContext() || |
| 419 node.propertyName.inSetterContext()) { |
412 _recordTarget(node.propertyName.offset, node.propertyName.staticElement); | 420 _recordTarget(node.propertyName.offset, node.propertyName.staticElement); |
413 } | 421 } |
414 } | 422 } |
415 | 423 |
416 visitSimpleIdentifier(SimpleIdentifier node) { | 424 visitSimpleIdentifier(SimpleIdentifier node) { |
417 super.visitSimpleIdentifier(node); | 425 super.visitSimpleIdentifier(node); |
418 Element element = node.staticElement; | 426 Element element = node.staticElement; |
419 void recordPromotions(DartType elementType) { | 427 void recordPromotions(DartType elementType) { |
420 if (node.inGetterContext() && !node.inDeclarationContext()) { | 428 if (node.inGetterContext() && !node.inDeclarationContext()) { |
421 int offset = node.offset; | 429 int offset = node.offset; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 | 493 |
486 /// Based on DDC code generator's `_recoverTypeArguments` | 494 /// Based on DDC code generator's `_recoverTypeArguments` |
487 Iterable<DartType> _recoverTypeArguments(FunctionType g, FunctionType f) { | 495 Iterable<DartType> _recoverTypeArguments(FunctionType g, FunctionType f) { |
488 assert(identical(g.element, f.element)); | 496 assert(identical(g.element, f.element)); |
489 assert(g.typeFormals.isNotEmpty && f.typeFormals.isEmpty); | 497 assert(g.typeFormals.isNotEmpty && f.typeFormals.isEmpty); |
490 assert(g.typeFormals.length + g.typeArguments.length == | 498 assert(g.typeFormals.length + g.typeArguments.length == |
491 f.typeArguments.length); | 499 f.typeArguments.length); |
492 return f.typeArguments.skip(g.typeArguments.length); | 500 return f.typeArguments.skip(g.typeArguments.length); |
493 } | 501 } |
494 } | 502 } |
OLD | NEW |