| 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 analyzer.src.dart.element.element; | 5 library analyzer.src.dart.element.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/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 2839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2850 implements ExecutableElement { | 2850 implements ExecutableElement { |
| 2851 /** | 2851 /** |
| 2852 * The unlinked representation of the executable in the summary. | 2852 * The unlinked representation of the executable in the summary. |
| 2853 */ | 2853 */ |
| 2854 final UnlinkedExecutable serializedExecutable; | 2854 final UnlinkedExecutable serializedExecutable; |
| 2855 | 2855 |
| 2856 /** | 2856 /** |
| 2857 * A list containing all of the functions defined within this executable | 2857 * A list containing all of the functions defined within this executable |
| 2858 * element. | 2858 * element. |
| 2859 */ | 2859 */ |
| 2860 List<FunctionElement> _functions = FunctionElement.EMPTY_LIST; | 2860 List<FunctionElement> _functions; |
| 2861 | 2861 |
| 2862 /** | 2862 /** |
| 2863 * A list containing all of the labels defined within this executable element. | 2863 * A list containing all of the labels defined within this executable element. |
| 2864 */ | 2864 */ |
| 2865 List<LabelElement> _labels; | 2865 List<LabelElement> _labels; |
| 2866 | 2866 |
| 2867 /** | 2867 /** |
| 2868 * A list containing all of the local variables defined within this executable | 2868 * A list containing all of the local variables defined within this executable |
| 2869 * element. | 2869 * element. |
| 2870 */ | 2870 */ |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2967 | 2967 |
| 2968 /** | 2968 /** |
| 2969 * Set whether this executable element is external. | 2969 * Set whether this executable element is external. |
| 2970 */ | 2970 */ |
| 2971 void set external(bool isExternal) { | 2971 void set external(bool isExternal) { |
| 2972 assert(serializedExecutable == null); | 2972 assert(serializedExecutable == null); |
| 2973 setModifier(Modifier.EXTERNAL, isExternal); | 2973 setModifier(Modifier.EXTERNAL, isExternal); |
| 2974 } | 2974 } |
| 2975 | 2975 |
| 2976 @override | 2976 @override |
| 2977 List<FunctionElement> get functions => _functions; | 2977 List<FunctionElement> get functions { |
| 2978 if (serializedExecutable != null) { |
| 2979 _functions ??= FunctionElementImpl.resynthesizeList( |
| 2980 this, serializedExecutable.localFunctions); |
| 2981 } |
| 2982 return _functions ?? const <FunctionElement>[]; |
| 2983 } |
| 2978 | 2984 |
| 2979 /** | 2985 /** |
| 2980 * Set the functions defined within this executable element to the given | 2986 * Set the functions defined within this executable element to the given |
| 2981 * [functions]. | 2987 * [functions]. |
| 2982 */ | 2988 */ |
| 2983 void set functions(List<FunctionElement> functions) { | 2989 void set functions(List<FunctionElement> functions) { |
| 2990 assert(serializedExecutable == null); |
| 2984 for (FunctionElement function in functions) { | 2991 for (FunctionElement function in functions) { |
| 2985 (function as FunctionElementImpl).enclosingElement = this; | 2992 (function as FunctionElementImpl).enclosingElement = this; |
| 2986 } | 2993 } |
| 2987 this._functions = functions; | 2994 this._functions = functions; |
| 2988 } | 2995 } |
| 2989 | 2996 |
| 2990 /** | 2997 /** |
| 2991 * Set whether this method's body is a generator. | 2998 * Set whether this method's body is a generator. |
| 2992 */ | 2999 */ |
| 2993 void set generator(bool isGenerator) { | 3000 void set generator(bool isGenerator) { |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3661 } | 3668 } |
| 3662 | 3669 |
| 3663 @override | 3670 @override |
| 3664 bool get isStatic => enclosingElement is CompilationUnitElement; | 3671 bool get isStatic => enclosingElement is CompilationUnitElement; |
| 3665 | 3672 |
| 3666 @override | 3673 @override |
| 3667 ElementKind get kind => ElementKind.FUNCTION; | 3674 ElementKind get kind => ElementKind.FUNCTION; |
| 3668 | 3675 |
| 3669 @override | 3676 @override |
| 3670 SourceRange get visibleRange { | 3677 SourceRange get visibleRange { |
| 3678 if (serializedExecutable != null) { |
| 3679 if (serializedExecutable.visibleLength == 0) { |
| 3680 return null; |
| 3681 } |
| 3682 return new SourceRange(serializedExecutable.visibleOffset, |
| 3683 serializedExecutable.visibleLength); |
| 3684 } |
| 3671 if (_visibleRangeLength < 0) { | 3685 if (_visibleRangeLength < 0) { |
| 3672 return null; | 3686 return null; |
| 3673 } | 3687 } |
| 3674 return new SourceRange(_visibleRangeOffset, _visibleRangeLength); | 3688 return new SourceRange(_visibleRangeOffset, _visibleRangeLength); |
| 3675 } | 3689 } |
| 3676 | 3690 |
| 3677 @override | 3691 @override |
| 3678 accept(ElementVisitor visitor) => visitor.visitFunctionElement(this); | 3692 accept(ElementVisitor visitor) => visitor.visitFunctionElement(this); |
| 3679 | 3693 |
| 3680 @override | 3694 @override |
| 3681 void appendTo(StringBuffer buffer) { | 3695 void appendTo(StringBuffer buffer) { |
| 3682 String name = displayName; | 3696 String name = displayName; |
| 3683 if (name != null) { | 3697 if (name != null) { |
| 3684 buffer.write(name); | 3698 buffer.write(name); |
| 3685 } | 3699 } |
| 3686 super.appendTo(buffer); | 3700 super.appendTo(buffer); |
| 3687 } | 3701 } |
| 3688 | 3702 |
| 3689 @override | 3703 @override |
| 3690 FunctionDeclaration computeNode() => | 3704 FunctionDeclaration computeNode() => |
| 3691 getNodeMatching((node) => node is FunctionDeclaration); | 3705 getNodeMatching((node) => node is FunctionDeclaration); |
| 3692 | 3706 |
| 3693 /** | 3707 /** |
| 3694 * Set the visible range for this element to the range starting at the given | 3708 * Set the visible range for this element to the range starting at the given |
| 3695 * [offset] with the given [length]. | 3709 * [offset] with the given [length]. |
| 3696 */ | 3710 */ |
| 3697 void setVisibleRange(int offset, int length) { | 3711 void setVisibleRange(int offset, int length) { |
| 3712 assert(serializedExecutable == null); |
| 3698 _visibleRangeOffset = offset; | 3713 _visibleRangeOffset = offset; |
| 3699 _visibleRangeLength = length; | 3714 _visibleRangeLength = length; |
| 3700 } | 3715 } |
| 3701 | 3716 |
| 3702 /** | 3717 /** |
| 3703 * Set the parameters defined by this type alias to the given [parameters] | 3718 * Set the parameters defined by this type alias to the given [parameters] |
| 3704 * without becoming the parent of the parameters. This should only be used by | 3719 * without becoming the parent of the parameters. This should only be used by |
| 3705 * the [TypeResolverVisitor] when creating a synthetic type alias. | 3720 * the [TypeResolverVisitor] when creating a synthetic type alias. |
| 3706 */ | 3721 */ |
| 3707 void shareParameters(List<ParameterElement> parameters) { | 3722 void shareParameters(List<ParameterElement> parameters) { |
| 3708 this._parameters = parameters; | 3723 this._parameters = parameters; |
| 3709 } | 3724 } |
| 3710 | 3725 |
| 3711 /** | 3726 /** |
| 3712 * Set the type parameters defined by this type alias to the given | 3727 * Set the type parameters defined by this type alias to the given |
| 3713 * [parameters] without becoming the parent of the parameters. This should | 3728 * [parameters] without becoming the parent of the parameters. This should |
| 3714 * only be used by the [TypeResolverVisitor] when creating a synthetic type | 3729 * only be used by the [TypeResolverVisitor] when creating a synthetic type |
| 3715 * alias. | 3730 * alias. |
| 3716 */ | 3731 */ |
| 3717 void shareTypeParameters(List<TypeParameterElement> typeParameters) { | 3732 void shareTypeParameters(List<TypeParameterElement> typeParameters) { |
| 3718 this._typeParameters = typeParameters; | 3733 this._typeParameters = typeParameters; |
| 3719 } | 3734 } |
| 3735 |
| 3736 /** |
| 3737 * Create and return [FunctionElement]s for the given [unlinkedFunctions]. |
| 3738 */ |
| 3739 static List<FunctionElement> resynthesizeList( |
| 3740 ExecutableElementImpl executableElement, |
| 3741 List<UnlinkedExecutable> unlinkedFunctions) { |
| 3742 int length = unlinkedFunctions.length; |
| 3743 if (length != 0) { |
| 3744 List<FunctionElement> elements = new List<FunctionElement>(length); |
| 3745 for (int i = 0; i < length; i++) { |
| 3746 elements[i] = new FunctionElementImpl.forSerialized( |
| 3747 unlinkedFunctions[i], executableElement); |
| 3748 } |
| 3749 return elements; |
| 3750 } else { |
| 3751 return const <FunctionElement>[]; |
| 3752 } |
| 3753 } |
| 3720 } | 3754 } |
| 3721 | 3755 |
| 3722 /** | 3756 /** |
| 3723 * Implementation of [FunctionElementImpl] for a function typed parameter. | 3757 * Implementation of [FunctionElementImpl] for a function typed parameter. |
| 3724 */ | 3758 */ |
| 3725 class FunctionElementImpl_forFunctionTypedParameter | 3759 class FunctionElementImpl_forFunctionTypedParameter |
| 3726 extends FunctionElementImpl { | 3760 extends FunctionElementImpl { |
| 3727 @override | 3761 @override |
| 3728 final CompilationUnitElementImpl enclosingUnit; | 3762 final CompilationUnitElementImpl enclosingUnit; |
| 3729 | 3763 |
| (...skipping 3932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7662 | 7696 |
| 7663 @override | 7697 @override |
| 7664 void visitElement(Element element) { | 7698 void visitElement(Element element) { |
| 7665 int offset = element.nameOffset; | 7699 int offset = element.nameOffset; |
| 7666 if (offset != -1) { | 7700 if (offset != -1) { |
| 7667 map[offset] = element; | 7701 map[offset] = element; |
| 7668 } | 7702 } |
| 7669 super.visitElement(element); | 7703 super.visitElement(element); |
| 7670 } | 7704 } |
| 7671 } | 7705 } |
| OLD | NEW |