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 5452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5463 return const <NamespaceCombinator>[]; | 5463 return const <NamespaceCombinator>[]; |
5464 } | 5464 } |
5465 } | 5465 } |
5466 } | 5466 } |
5467 | 5467 |
5468 /** | 5468 /** |
5469 * A concrete implementation of a [LabelElement]. | 5469 * A concrete implementation of a [LabelElement]. |
5470 */ | 5470 */ |
5471 class LabelElementImpl extends ElementImpl implements LabelElement { | 5471 class LabelElementImpl extends ElementImpl implements LabelElement { |
5472 /** | 5472 /** |
5473 * The unlinked representation of the label in the summary. | |
5474 */ | |
5475 final UnlinkedLabel _unlinkedLabel; | |
5476 | |
5477 /** | |
5478 * A flag indicating whether this label is associated with a `switch` | 5473 * A flag indicating whether this label is associated with a `switch` |
5479 * statement. | 5474 * statement. |
5480 */ | 5475 */ |
5481 // TODO(brianwilkerson) Make this a modifier. | 5476 // TODO(brianwilkerson) Make this a modifier. |
5482 final bool _onSwitchStatement; | 5477 final bool _onSwitchStatement; |
5483 | 5478 |
5484 /** | 5479 /** |
5485 * A flag indicating whether this label is associated with a `switch` member | 5480 * A flag indicating whether this label is associated with a `switch` member |
5486 * (`case` or `default`). | 5481 * (`case` or `default`). |
5487 */ | 5482 */ |
5488 // TODO(brianwilkerson) Make this a modifier. | 5483 // TODO(brianwilkerson) Make this a modifier. |
5489 final bool _onSwitchMember; | 5484 final bool _onSwitchMember; |
5490 | 5485 |
5491 /** | 5486 /** |
5492 * Initialize a newly created label element to have the given [name]. | 5487 * Initialize a newly created label element to have the given [name]. |
5493 * [onSwitchStatement] should be `true` if this label is associated with a | 5488 * [onSwitchStatement] should be `true` if this label is associated with a |
5494 * `switch` statement and [onSwitchMember] should be `true` if this label is | 5489 * `switch` statement and [onSwitchMember] should be `true` if this label is |
5495 * associated with a `switch` member. | 5490 * associated with a `switch` member. |
5496 */ | 5491 */ |
5497 LabelElementImpl(String name, int nameOffset, this._onSwitchStatement, | 5492 LabelElementImpl(String name, int nameOffset, this._onSwitchStatement, |
5498 this._onSwitchMember) | 5493 this._onSwitchMember) |
5499 : _unlinkedLabel = null, | 5494 : super(name, nameOffset); |
5500 super(name, nameOffset); | |
5501 | 5495 |
5502 /** | 5496 /** |
5503 * Initialize a newly created label element to have the given [name]. | 5497 * Initialize a newly created label element to have the given [name]. |
5504 * [_onSwitchStatement] should be `true` if this label is associated with a | 5498 * [_onSwitchStatement] should be `true` if this label is associated with a |
5505 * `switch` statement and [_onSwitchMember] should be `true` if this label is | 5499 * `switch` statement and [_onSwitchMember] should be `true` if this label is |
5506 * associated with a `switch` member. | 5500 * associated with a `switch` member. |
5507 */ | 5501 */ |
5508 LabelElementImpl.forNode( | 5502 LabelElementImpl.forNode( |
5509 Identifier name, this._onSwitchStatement, this._onSwitchMember) | 5503 Identifier name, this._onSwitchStatement, this._onSwitchMember) |
5510 : _unlinkedLabel = null, | 5504 : super.forNode(name); |
5511 super.forNode(name); | |
5512 | |
5513 /** | |
5514 * Initialize using the given serialized information. | |
5515 */ | |
5516 LabelElementImpl.forSerialized( | |
5517 UnlinkedLabel unlinkedLabel, ExecutableElementImpl enclosingExecutable) | |
5518 : _unlinkedLabel = unlinkedLabel, | |
5519 _onSwitchStatement = unlinkedLabel.isOnSwitchStatement, | |
5520 _onSwitchMember = unlinkedLabel.isOnSwitchMember, | |
5521 super.forSerialized(enclosingExecutable); | |
5522 | 5505 |
5523 @override | 5506 @override |
5524 String get displayName => name; | 5507 String get displayName => name; |
5525 | 5508 |
5526 @override | 5509 @override |
5527 ExecutableElement get enclosingElement => | 5510 ExecutableElement get enclosingElement => |
5528 super.enclosingElement as ExecutableElement; | 5511 super.enclosingElement as ExecutableElement; |
5529 | 5512 |
5530 /** | 5513 /** |
5531 * Return `true` if this label is associated with a `switch` member (`case` or | 5514 * Return `true` if this label is associated with a `switch` member (`case` or |
5532 * `default`). | 5515 * `default`). |
5533 */ | 5516 */ |
5534 bool get isOnSwitchMember => _onSwitchMember; | 5517 bool get isOnSwitchMember => _onSwitchMember; |
5535 | 5518 |
5536 /** | 5519 /** |
5537 * Return `true` if this label is associated with a `switch` statement. | 5520 * Return `true` if this label is associated with a `switch` statement. |
5538 */ | 5521 */ |
5539 bool get isOnSwitchStatement => _onSwitchStatement; | 5522 bool get isOnSwitchStatement => _onSwitchStatement; |
5540 | 5523 |
5541 @override | 5524 @override |
5542 ElementKind get kind => ElementKind.LABEL; | 5525 ElementKind get kind => ElementKind.LABEL; |
5543 | 5526 |
5544 @override | 5527 @override |
5545 String get name { | |
5546 if (_unlinkedLabel != null) { | |
5547 return _unlinkedLabel.name; | |
5548 } | |
5549 return super.name; | |
5550 } | |
5551 | |
5552 @override | |
5553 int get nameOffset { | |
5554 int offset = super.nameOffset; | |
5555 if (offset == 0 && | |
5556 _unlinkedLabel != null && | |
5557 _unlinkedLabel.nameOffset != 0) { | |
5558 return _unlinkedLabel.nameOffset; | |
5559 } | |
5560 return offset; | |
5561 } | |
5562 | |
5563 @override | |
5564 T accept<T>(ElementVisitor<T> visitor) => throw new UnimplementedError(); | 5528 T accept<T>(ElementVisitor<T> visitor) => throw new UnimplementedError(); |
5565 | |
5566 /** | |
5567 * Create and return [LabelElement]s for the given [unlinkedLabels]. | |
5568 */ | |
5569 static List<LabelElement> resynthesizeList( | |
5570 ExecutableElementImpl enclosingExecutable, | |
5571 List<UnlinkedLabel> unlinkedLabels) { | |
5572 int length = unlinkedLabels.length; | |
5573 if (length != 0) { | |
5574 List<LabelElement> elements = new List<LabelElement>(length); | |
5575 for (int i = 0; i < length; i++) { | |
5576 elements[i] = new LabelElementImpl.forSerialized( | |
5577 unlinkedLabels[i], enclosingExecutable); | |
5578 } | |
5579 return elements; | |
5580 } else { | |
5581 return const <LabelElement>[]; | |
5582 } | |
5583 } | |
5584 } | 5529 } |
5585 | 5530 |
5586 /** | 5531 /** |
5587 * A concrete implementation of a [LibraryElement]. | 5532 * A concrete implementation of a [LibraryElement]. |
5588 */ | 5533 */ |
5589 class LibraryElementImpl extends ElementImpl implements LibraryElement { | 5534 class LibraryElementImpl extends ElementImpl implements LibraryElement { |
5590 /** | 5535 /** |
5591 * The analysis context in which this library is defined. | 5536 * The analysis context in which this library is defined. |
5592 */ | 5537 */ |
5593 final AnalysisContext context; | 5538 final AnalysisContext context; |
(...skipping 3339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8933 | 8878 |
8934 @override | 8879 @override |
8935 DartObject computeConstantValue() => null; | 8880 DartObject computeConstantValue() => null; |
8936 | 8881 |
8937 @override | 8882 @override |
8938 void visitChildren(ElementVisitor visitor) { | 8883 void visitChildren(ElementVisitor visitor) { |
8939 super.visitChildren(visitor); | 8884 super.visitChildren(visitor); |
8940 _initializer?.accept(visitor); | 8885 _initializer?.accept(visitor); |
8941 } | 8886 } |
8942 } | 8887 } |
OLD | NEW |