| 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.element; | 5 library engine.element; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:math' show min; | 8 import 'dart:math' show min; |
| 9 | 9 |
| 10 import 'package:analyzer/src/generated/utilities_general.dart'; | 10 import 'package:analyzer/src/generated/utilities_general.dart'; |
| (...skipping 7610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7621 } while (cur != library); | 7621 } while (cur != library); |
| 7622 } | 7622 } |
| 7623 return root; | 7623 return root; |
| 7624 } | 7624 } |
| 7625 scc(library); | 7625 scc(library); |
| 7626 return _libraryCycle; | 7626 return _libraryCycle; |
| 7627 } | 7627 } |
| 7628 | 7628 |
| 7629 @override | 7629 @override |
| 7630 FunctionElement get loadLibraryFunction { | 7630 FunctionElement get loadLibraryFunction { |
| 7631 if (_loadLibraryFunction == null) { | 7631 assert(_loadLibraryFunction != null); |
| 7632 FunctionElementImpl function = | |
| 7633 new FunctionElementImpl(FunctionElement.LOAD_LIBRARY_NAME, -1); | |
| 7634 function.synthetic = true; | |
| 7635 function.enclosingElement = this; | |
| 7636 function.returnType = loadLibraryReturnType; | |
| 7637 function.type = new FunctionTypeImpl(function); | |
| 7638 _loadLibraryFunction = function; | |
| 7639 } | |
| 7640 return _loadLibraryFunction; | 7632 return _loadLibraryFunction; |
| 7641 } | 7633 } |
| 7642 | 7634 |
| 7643 /** | |
| 7644 * Return the object representing the type 'Future' from the 'dart:async' | |
| 7645 * library, or the type 'void' if the type 'Future' cannot be accessed. | |
| 7646 */ | |
| 7647 DartType get loadLibraryReturnType { | |
| 7648 try { | |
| 7649 Source asyncSource = context.sourceFactory.forUri(DartSdk.DART_ASYNC); | |
| 7650 if (asyncSource == null) { | |
| 7651 AnalysisEngine.instance.logger | |
| 7652 .logError("Could not create a source for dart:async"); | |
| 7653 return VoidTypeImpl.instance; | |
| 7654 } | |
| 7655 LibraryElement asyncElement = context.computeLibraryElement(asyncSource); | |
| 7656 if (asyncElement == null) { | |
| 7657 AnalysisEngine.instance.logger | |
| 7658 .logError("Could not build the element model for dart:async"); | |
| 7659 return VoidTypeImpl.instance; | |
| 7660 } | |
| 7661 ClassElement futureElement = asyncElement.getType("Future"); | |
| 7662 if (futureElement == null) { | |
| 7663 AnalysisEngine.instance.logger | |
| 7664 .logError("Could not find type Future in dart:async"); | |
| 7665 return VoidTypeImpl.instance; | |
| 7666 } | |
| 7667 InterfaceType futureType = futureElement.type; | |
| 7668 return futureType.substitute4(<DartType>[DynamicTypeImpl.instance]); | |
| 7669 } on AnalysisException catch (exception, stackTrace) { | |
| 7670 AnalysisEngine.instance.logger.logError( | |
| 7671 "Could not build the element model for dart:async", | |
| 7672 new CaughtException(exception, stackTrace)); | |
| 7673 return VoidTypeImpl.instance; | |
| 7674 } | |
| 7675 } | |
| 7676 | |
| 7677 @override | 7635 @override |
| 7678 List<CompilationUnitElement> get parts => _parts; | 7636 List<CompilationUnitElement> get parts => _parts; |
| 7679 | 7637 |
| 7680 /** | 7638 /** |
| 7681 * Set the compilation units that are included in this library using a `part` | 7639 * Set the compilation units that are included in this library using a `part` |
| 7682 * directive to the given list of [parts]. | 7640 * directive to the given list of [parts]. |
| 7683 */ | 7641 */ |
| 7684 void set parts(List<CompilationUnitElement> parts) { | 7642 void set parts(List<CompilationUnitElement> parts) { |
| 7685 for (CompilationUnitElement compilationUnit in parts) { | 7643 for (CompilationUnitElement compilationUnit in parts) { |
| 7686 assert((compilationUnit as CompilationUnitElementImpl).librarySource == | 7644 assert((compilationUnit as CompilationUnitElementImpl).librarySource == |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7725 return new List.from(visibleLibraries); | 7683 return new List.from(visibleLibraries); |
| 7726 } | 7684 } |
| 7727 | 7685 |
| 7728 @override | 7686 @override |
| 7729 bool operator ==(Object object) => object is LibraryElementImpl && | 7687 bool operator ==(Object object) => object is LibraryElementImpl && |
| 7730 _definingCompilationUnit == object.definingCompilationUnit; | 7688 _definingCompilationUnit == object.definingCompilationUnit; |
| 7731 | 7689 |
| 7732 @override | 7690 @override |
| 7733 accept(ElementVisitor visitor) => visitor.visitLibraryElement(this); | 7691 accept(ElementVisitor visitor) => visitor.visitLibraryElement(this); |
| 7734 | 7692 |
| 7693 /** |
| 7694 * Create the [FunctionElement] to be returned by [loadLibraryFunction], |
| 7695 * using types provided by [typeProvider]. |
| 7696 */ |
| 7697 void createLoadLibraryFunction(TypeProvider typeProvider) { |
| 7698 FunctionElementImpl function = |
| 7699 new FunctionElementImpl(FunctionElement.LOAD_LIBRARY_NAME, -1); |
| 7700 function.synthetic = true; |
| 7701 function.enclosingElement = this; |
| 7702 function.returnType = typeProvider.futureDynamicType; |
| 7703 function.type = new FunctionTypeImpl(function); |
| 7704 _loadLibraryFunction = function; |
| 7705 } |
| 7706 |
| 7735 @override | 7707 @override |
| 7736 ElementImpl getChild(String identifier) { | 7708 ElementImpl getChild(String identifier) { |
| 7737 if ((_definingCompilationUnit as CompilationUnitElementImpl).identifier == | 7709 if ((_definingCompilationUnit as CompilationUnitElementImpl).identifier == |
| 7738 identifier) { | 7710 identifier) { |
| 7739 return _definingCompilationUnit as CompilationUnitElementImpl; | 7711 return _definingCompilationUnit as CompilationUnitElementImpl; |
| 7740 } | 7712 } |
| 7741 for (CompilationUnitElement part in _parts) { | 7713 for (CompilationUnitElement part in _parts) { |
| 7742 if ((part as CompilationUnitElementImpl).identifier == identifier) { | 7714 if ((part as CompilationUnitElementImpl).identifier == identifier) { |
| 7743 return part as CompilationUnitElementImpl; | 7715 return part as CompilationUnitElementImpl; |
| 7744 } | 7716 } |
| (...skipping 3213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10958 | 10930 |
| 10959 @override | 10931 @override |
| 10960 void visitElement(Element element) { | 10932 void visitElement(Element element) { |
| 10961 int offset = element.nameOffset; | 10933 int offset = element.nameOffset; |
| 10962 if (offset != -1) { | 10934 if (offset != -1) { |
| 10963 map[offset] = element; | 10935 map[offset] = element; |
| 10964 } | 10936 } |
| 10965 super.visitElement(element); | 10937 super.visitElement(element); |
| 10966 } | 10938 } |
| 10967 } | 10939 } |
| OLD | NEW |