| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 engine.resolver; | 5 library engine.resolver; |
| 6 | 6 |
| 7 import "dart:math" as math; | 7 import "dart:math" as math; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analyzer/src/generated/utilities_collection.dart'; | 10 import 'package:analyzer/src/generated/utilities_collection.dart'; |
| (...skipping 8492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8503 CompilationUnit ast = library.getAST(source); | 8503 CompilationUnit ast = library.getAST(source); |
| 8504 ast.accept( | 8504 ast.accept( |
| 8505 new VariableResolverVisitor.con1(library, source, _typeProvider)); | 8505 new VariableResolverVisitor.con1(library, source, _typeProvider)); |
| 8506 ResolverVisitor visitor = | 8506 ResolverVisitor visitor = |
| 8507 new ResolverVisitor.con1(library, source, _typeProvider); | 8507 new ResolverVisitor.con1(library, source, _typeProvider); |
| 8508 ast.accept(visitor); | 8508 ast.accept(visitor); |
| 8509 } | 8509 } |
| 8510 } finally { | 8510 } finally { |
| 8511 timeCounter.stop(); | 8511 timeCounter.stop(); |
| 8512 } | 8512 } |
| 8513 // Polymer | |
| 8514 timeCounter = PerformanceStatistics.polymer.start(); | |
| 8515 try { | |
| 8516 for (Source source in library.compilationUnitSources) { | |
| 8517 CompilationUnit ast = library.getAST(source); | |
| 8518 new PolymerCompilationUnitBuilder(ast).build(); | |
| 8519 } | |
| 8520 } finally { | |
| 8521 timeCounter.stop(); | |
| 8522 } | |
| 8523 } | 8513 } |
| 8524 | 8514 |
| 8525 /** | 8515 /** |
| 8526 * Return the result of resolving the URI of the given URI-based directive aga
inst the URI of the | 8516 * Return the result of resolving the URI of the given URI-based directive aga
inst the URI of the |
| 8527 * given library, or `null` if the URI is not valid. | 8517 * given library, or `null` if the URI is not valid. |
| 8528 * | 8518 * |
| 8529 * @param librarySource the source representing the library containing the dir
ective | 8519 * @param librarySource the source representing the library containing the dir
ective |
| 8530 * @param directive the directive which URI should be resolved | 8520 * @param directive the directive which URI should be resolved |
| 8531 * @return the result of resolving the URI against the URI of the library | 8521 * @return the result of resolving the URI against the URI of the library |
| 8532 */ | 8522 */ |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9066 CompilationUnit ast = unit.compilationUnit; | 9056 CompilationUnit ast = unit.compilationUnit; |
| 9067 ast.accept( | 9057 ast.accept( |
| 9068 new VariableResolverVisitor.con3(library, source, _typeProvider)); | 9058 new VariableResolverVisitor.con3(library, source, _typeProvider)); |
| 9069 ResolverVisitor visitor = | 9059 ResolverVisitor visitor = |
| 9070 new ResolverVisitor.con4(library, source, _typeProvider); | 9060 new ResolverVisitor.con4(library, source, _typeProvider); |
| 9071 ast.accept(visitor); | 9061 ast.accept(visitor); |
| 9072 } | 9062 } |
| 9073 } finally { | 9063 } finally { |
| 9074 timeCounter.stop(); | 9064 timeCounter.stop(); |
| 9075 } | 9065 } |
| 9076 // Polymer | |
| 9077 timeCounter = PerformanceStatistics.polymer.start(); | |
| 9078 try { | |
| 9079 for (Source source in library.compilationUnitSources) { | |
| 9080 CompilationUnit ast = library.getAST(source); | |
| 9081 new PolymerCompilationUnitBuilder(ast).build(); | |
| 9082 } | |
| 9083 } finally { | |
| 9084 timeCounter.stop(); | |
| 9085 } | |
| 9086 } | 9066 } |
| 9087 | 9067 |
| 9088 /** | 9068 /** |
| 9089 * Report that the core library could not be resolved in the given analysis co
ntext and throw an | 9069 * Report that the core library could not be resolved in the given analysis co
ntext and throw an |
| 9090 * exception. | 9070 * exception. |
| 9091 * | 9071 * |
| 9092 * @param analysisContext the analysis context in which the failure occurred | 9072 * @param analysisContext the analysis context in which the failure occurred |
| 9093 * @param coreLibrarySource the source representing the core library | 9073 * @param coreLibrarySource the source representing the core library |
| 9094 * @throws AnalysisException always | 9074 * @throws AnalysisException always |
| 9095 */ | 9075 */ |
| (...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9754 /** | 9734 /** |
| 9755 * Return `true` if the given element has an override annotation associated wi
th it. | 9735 * Return `true` if the given element has an override annotation associated wi
th it. |
| 9756 * | 9736 * |
| 9757 * @param element the element being tested | 9737 * @param element the element being tested |
| 9758 * @return `true` if the element has an override annotation associated with it | 9738 * @return `true` if the element has an override annotation associated with it |
| 9759 */ | 9739 */ |
| 9760 bool _isOverride(Element element) => element != null && element.isOverride; | 9740 bool _isOverride(Element element) => element != null && element.isOverride; |
| 9761 } | 9741 } |
| 9762 | 9742 |
| 9763 /** | 9743 /** |
| 9764 * Instances of the class `PolymerCompilationUnitBuilder` build a Polymer specif
ic element | |
| 9765 * model for a single compilation unit. | |
| 9766 */ | |
| 9767 class PolymerCompilationUnitBuilder { | |
| 9768 static String _CUSTOM_TAG = "CustomTag"; | |
| 9769 | |
| 9770 /** | |
| 9771 * The compilation unit with built Dart element models. | |
| 9772 */ | |
| 9773 final CompilationUnit _unit; | |
| 9774 | |
| 9775 /** | |
| 9776 * The [ClassDeclaration] that is currently being analyzed. | |
| 9777 */ | |
| 9778 ClassDeclaration _classDeclaration; | |
| 9779 | |
| 9780 /** | |
| 9781 * The [ClassElementImpl] that is currently being analyzed. | |
| 9782 */ | |
| 9783 ClassElementImpl _classElement; | |
| 9784 | |
| 9785 /** | |
| 9786 * The [Annotation] that is currently being analyzed. | |
| 9787 */ | |
| 9788 Annotation _annotation; | |
| 9789 | |
| 9790 /** | |
| 9791 * Initialize a newly created compilation unit element builder. | |
| 9792 * | |
| 9793 * @param unit the compilation unit with built Dart element models | |
| 9794 */ | |
| 9795 PolymerCompilationUnitBuilder(this._unit); | |
| 9796 | |
| 9797 /** | |
| 9798 * Builds Polymer specific element models and adds them to the existing Dart e
lements. | |
| 9799 */ | |
| 9800 void build() { | |
| 9801 // process classes | |
| 9802 for (CompilationUnitMember unitMember in _unit.declarations) { | |
| 9803 if (unitMember is ClassDeclaration) { | |
| 9804 this._classDeclaration = unitMember; | |
| 9805 this._classElement = _classDeclaration.element as ClassElementImpl; | |
| 9806 // process annotations | |
| 9807 NodeList<Annotation> annotations = _classDeclaration.metadata; | |
| 9808 for (Annotation annotation in annotations) { | |
| 9809 // verify annotation | |
| 9810 if (annotation.arguments == null) { | |
| 9811 continue; | |
| 9812 } | |
| 9813 this._annotation = annotation; | |
| 9814 // @CustomTag | |
| 9815 if (_isAnnotation(annotation, _CUSTOM_TAG)) { | |
| 9816 _parseCustomTag(); | |
| 9817 continue; | |
| 9818 } | |
| 9819 } | |
| 9820 } | |
| 9821 } | |
| 9822 } | |
| 9823 | |
| 9824 /** | |
| 9825 * Checks if given [Annotation] is an annotation with required name. | |
| 9826 */ | |
| 9827 bool _isAnnotation(Annotation annotation, String name) { | |
| 9828 Element element = annotation.element; | |
| 9829 if (element is ConstructorElement) { | |
| 9830 ConstructorElement constructorElement = element; | |
| 9831 return constructorElement.returnType.displayName == name; | |
| 9832 } | |
| 9833 return false; | |
| 9834 } | |
| 9835 | |
| 9836 void _parseCustomTag() { | |
| 9837 List<Expression> arguments = _annotation.arguments.arguments; | |
| 9838 if (arguments.length == 1) { | |
| 9839 Expression nameExpression = arguments[0]; | |
| 9840 if (nameExpression is SimpleStringLiteral) { | |
| 9841 SimpleStringLiteral nameLiteral = nameExpression; | |
| 9842 String name = nameLiteral.value; | |
| 9843 int nameOffset = nameLiteral.contentsOffset; | |
| 9844 PolymerTagDartElementImpl element = | |
| 9845 new PolymerTagDartElementImpl(name, nameOffset, _classElement); | |
| 9846 _classElement.addToolkitObjects(element); | |
| 9847 nameLiteral.toolkitElement = element; | |
| 9848 } | |
| 9849 } | |
| 9850 } | |
| 9851 | |
| 9852 static Element getElement(AstNode node, int offset) { | |
| 9853 // maybe node is not SimpleStringLiteral | |
| 9854 if (node is! SimpleStringLiteral) { | |
| 9855 return null; | |
| 9856 } | |
| 9857 SimpleStringLiteral literal = node as SimpleStringLiteral; | |
| 9858 // maybe has PolymerElement | |
| 9859 { | |
| 9860 Element element = literal.toolkitElement; | |
| 9861 if (element is PolymerElement) { | |
| 9862 return element; | |
| 9863 } | |
| 9864 } | |
| 9865 // no Element | |
| 9866 return null; | |
| 9867 } | |
| 9868 } | |
| 9869 | |
| 9870 /** | |
| 9871 * Instances of the class `PubVerifier` traverse an AST structure looking for de
viations from | 9744 * Instances of the class `PubVerifier` traverse an AST structure looking for de
viations from |
| 9872 * pub best practices. | 9745 * pub best practices. |
| 9873 */ | 9746 */ |
| 9874 class PubVerifier extends RecursiveAstVisitor<Object> { | 9747 class PubVerifier extends RecursiveAstVisitor<Object> { |
| 9875 // static String _PUBSPEC_YAML = "pubspec.yaml"; | 9748 // static String _PUBSPEC_YAML = "pubspec.yaml"; |
| 9876 | 9749 |
| 9877 /** | 9750 /** |
| 9878 * The analysis context containing the sources to be analyzed | 9751 * The analysis context containing the sources to be analyzed |
| 9879 */ | 9752 */ |
| 9880 final AnalysisContext _context; | 9753 final AnalysisContext _context; |
| (...skipping 5703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15584 * library. | 15457 * library. |
| 15585 */ | 15458 */ |
| 15586 final HashSet<String> members = new HashSet<String>(); | 15459 final HashSet<String> members = new HashSet<String>(); |
| 15587 | 15460 |
| 15588 /** | 15461 /** |
| 15589 * Names of resolved or unresolved class members that are read in the | 15462 * Names of resolved or unresolved class members that are read in the |
| 15590 * library. | 15463 * library. |
| 15591 */ | 15464 */ |
| 15592 final HashSet<String> readMembers = new HashSet<String>(); | 15465 final HashSet<String> readMembers = new HashSet<String>(); |
| 15593 } | 15466 } |
| OLD | NEW |