Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(462)

Side by Side Diff: pkg/analyzer/lib/src/dart/element/element.dart

Issue 1665353002: Use ElementAnnotation as the ConstantEvaluationTarget for annotations. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1555 matching lines...) Expand 10 before | Expand all | Expand 10 after
1566 1566
1567 /** 1567 /**
1568 * The element representing the field, variable, or constructor being used as 1568 * The element representing the field, variable, or constructor being used as
1569 * an annotation. 1569 * an annotation.
1570 */ 1570 */
1571 Element element; 1571 Element element;
1572 1572
1573 /** 1573 /**
1574 * The compliation unit in which this annotation appears. 1574 * The compliation unit in which this annotation appears.
1575 */ 1575 */
1576 final CompilationUnitElement compilationUnit; 1576 final CompilationUnitElementImpl compilationUnit;
1577
1578 /**
1579 * The AST of the annotation itself, cloned from the resolved AST for the
1580 * source code.
1581 */
1582 Annotation annotationAst;
1577 1583
1578 /** 1584 /**
1579 * The result of evaluating this annotation as a compile-time constant 1585 * The result of evaluating this annotation as a compile-time constant
1580 * expression, or `null` if the compilation unit containing the variable has 1586 * expression, or `null` if the compilation unit containing the variable has
1581 * not been resolved. 1587 * not been resolved.
1582 */ 1588 */
1583 EvaluationResultImpl evaluationResult; 1589 EvaluationResultImpl evaluationResult;
1584 1590
1585 /** 1591 /**
1586 * Initialize a newly created annotation. The given [compilationUnit] is the 1592 * Initialize a newly created annotation. The given [compilationUnit] is the
1587 * compilation unit in which the annotation appears. 1593 * compilation unit in which the annotation appears.
1588 */ 1594 */
1589 ElementAnnotationImpl(this.compilationUnit); 1595 ElementAnnotationImpl(this.compilationUnit);
1590 1596
1591 @override 1597 @override
1592 DartObject get constantValue => evaluationResult.value; 1598 DartObject get constantValue => evaluationResult.value;
1593 1599
1594 @override 1600 @override
1601 AnalysisContext get context => compilationUnit.library.context;
1602
1603 @override
1595 bool get isDeprecated { 1604 bool get isDeprecated {
1596 if (element != null) { 1605 if (element != null) {
1597 LibraryElement library = element.library; 1606 LibraryElement library = element.library;
1598 if (library != null && library.isDartCore) { 1607 if (library != null && library.isDartCore) {
1599 if (element is ConstructorElement) { 1608 if (element is ConstructorElement) {
1600 ConstructorElement constructorElement = element as ConstructorElement; 1609 ConstructorElement constructorElement = element as ConstructorElement;
1601 if (constructorElement.enclosingElement.name == 1610 if (constructorElement.enclosingElement.name ==
1602 _DEPRECATED_CLASS_NAME) { 1611 _DEPRECATED_CLASS_NAME) {
1603 return true; 1612 return true;
1604 } 1613 }
(...skipping 27 matching lines...) Expand all
1632 if (library != null && library.isDartCore) { 1641 if (library != null && library.isDartCore) {
1633 if (element is PropertyAccessorElement && 1642 if (element is PropertyAccessorElement &&
1634 element.name == PROXY_VARIABLE_NAME) { 1643 element.name == PROXY_VARIABLE_NAME) {
1635 return true; 1644 return true;
1636 } 1645 }
1637 } 1646 }
1638 } 1647 }
1639 return false; 1648 return false;
1640 } 1649 }
1641 1650
1651 /**
1652 * Get the library containing this annotation.
1653 */
1654 Source get librarySource => compilationUnit.librarySource;
1655
1656 @override
1657 Source get source => compilationUnit.source;
1658
1642 @override 1659 @override
1643 String toString() => '@$element'; 1660 String toString() => '@$element';
1644 } 1661 }
1645 1662
1646 /** 1663 /**
1647 * A base class for concrete implementations of an [Element]. 1664 * A base class for concrete implementations of an [Element].
1648 */ 1665 */
1649 abstract class ElementImpl implements Element { 1666 abstract class ElementImpl implements Element {
1650 /** 1667 /**
1651 * An Unicode right arrow. 1668 * An Unicode right arrow.
(...skipping 2452 matching lines...) Expand 10 before | Expand all | Expand 10 after
4104 ParameterElementImpl(String name, int nameOffset) : super(name, nameOffset); 4121 ParameterElementImpl(String name, int nameOffset) : super(name, nameOffset);
4105 4122
4106 /** 4123 /**
4107 * Initialize a newly created parameter element to have the given [name]. 4124 * Initialize a newly created parameter element to have the given [name].
4108 */ 4125 */
4109 ParameterElementImpl.forNode(Identifier name) : super.forNode(name); 4126 ParameterElementImpl.forNode(Identifier name) : super.forNode(name);
4110 4127
4111 /** 4128 /**
4112 * Creates a synthetic parameter with [name], [type] and [kind]. 4129 * Creates a synthetic parameter with [name], [type] and [kind].
4113 */ 4130 */
4114 factory ParameterElementImpl.synthetic(String name, DartType type, 4131 factory ParameterElementImpl.synthetic(
4115 ParameterKind kind) { 4132 String name, DartType type, ParameterKind kind) {
4116 ParameterElementImpl element = new ParameterElementImpl(name, -1); 4133 ParameterElementImpl element = new ParameterElementImpl(name, -1);
4117 element.type = type; 4134 element.type = type;
4118 element.synthetic = true; 4135 element.synthetic = true;
4119 element.parameterKind = kind; 4136 element.parameterKind = kind;
4120 return element; 4137 return element;
4121 } 4138 }
4122 4139
4123 @override 4140 @override
4124 String get defaultValueCode => _defaultValueCode; 4141 String get defaultValueCode => _defaultValueCode;
4125 4142
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
4772 4789
4773 @override 4790 @override
4774 void visitElement(Element element) { 4791 void visitElement(Element element) {
4775 int offset = element.nameOffset; 4792 int offset = element.nameOffset;
4776 if (offset != -1) { 4793 if (offset != -1) {
4777 map[offset] = element; 4794 map[offset] = element;
4778 } 4795 }
4779 super.visitElement(element); 4796 super.visitElement(element);
4780 } 4797 }
4781 } 4798 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/dart/element/element.dart ('k') | pkg/analyzer/lib/src/generated/constant.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698