OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library web_components.build.html_import_recorder_inliner; | 4 library web_components.build.html_import_recorder_inliner; |
5 | 5 |
6 import 'package:analyzer/analyzer.dart'; | 6 import 'package:analyzer/analyzer.dart'; |
7 import 'package:analyzer/src/generated/ast.dart'; | 7 import 'package:analyzer/src/generated/ast.dart'; |
8 import 'package:analyzer/src/generated/element.dart'; | 8 import 'package:analyzer/src/generated/element.dart'; |
9 import 'package:barback/barback.dart'; | 9 import 'package:barback/barback.dart'; |
10 import 'package:initialize/transformer.dart'; | 10 import 'package:initialize/transformer.dart'; |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 /// Applies to anything named `HtmlImport` which annotates a library. | 28 /// Applies to anything named `HtmlImport` which annotates a library. |
29 bool shouldApply(InitializerPluginData pluginData) { | 29 bool shouldApply(InitializerPluginData pluginData) { |
30 var annotationElement = pluginData.initializer.annotationNode.element; | 30 var annotationElement = pluginData.initializer.annotationNode.element; |
31 var logger = pluginData.logger; | 31 var logger = pluginData.logger; |
32 DartType type; | 32 DartType type; |
33 if (annotationElement is ConstructorElement) { | 33 if (annotationElement is ConstructorElement) { |
34 type = annotationElement.returnType; | 34 type = annotationElement.returnType; |
35 } else if (annotationElement is PropertyAccessorElement) { | 35 } else if (annotationElement is PropertyAccessorElement) { |
36 type = annotationElement.variable.propagatedType; | 36 type = annotationElement.variable.propagatedType; |
| 37 if (type == null) { |
| 38 type = pluginData.resolver.evaluateConstant(annotationElement.library, |
| 39 pluginData.initializer.annotationNode.name).value.type; |
| 40 } |
37 } else { | 41 } else { |
38 logger.error('Unsupported annotation type. Only constructors and ' | 42 logger.error('Unsupported annotation type. Only constructors and ' |
39 'properties are supported as initializers.'); | 43 'properties are supported as initializers.'); |
40 return false; | 44 return false; |
41 } | 45 } |
42 if (type.name != 'HtmlImport') return false; | 46 if (type.name != 'HtmlImport') return false; |
43 if (pluginData.initializer.targetElement is! LibraryElement) { | 47 if (pluginData.initializer.targetElement is! LibraryElement) { |
44 logger.error('Invalid HtmlImport annotation on non-library element.'); | 48 logger.error('Invalid HtmlImport annotation on non-library element.'); |
45 return false; | 49 return false; |
46 } | 50 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 return null; | 91 return null; |
88 } | 92 } |
89 | 93 |
90 importPaths | 94 importPaths |
91 .add(normalizeHtmlImportPath(originalImportPath, package, libPath)); | 95 .add(normalizeHtmlImportPath(originalImportPath, package, libPath)); |
92 | 96 |
93 // Don't emit an InitEntry. | 97 // Don't emit an InitEntry. |
94 return null; | 98 return null; |
95 } | 99 } |
96 } | 100 } |
OLD | NEW |