| Index: pkg/analyzer/lib/src/generated/constant.dart
|
| diff --git a/pkg/analyzer/lib/src/generated/constant.dart b/pkg/analyzer/lib/src/generated/constant.dart
|
| index 1f5635ca66e684e42499041f47562833a39d40e9..fe641dba075c7d993a63135fd4ce936ea53db7f7 100644
|
| --- a/pkg/analyzer/lib/src/generated/constant.dart
|
| +++ b/pkg/analyzer/lib/src/generated/constant.dart
|
| @@ -384,52 +384,44 @@ class ConstantEvaluationEngine {
|
| // code will know that it is safe to evaluate.
|
| (constant as ConstructorElementImpl).isCycleFree = true;
|
| }
|
| - } else if (constant is ConstantEvaluationTarget_Annotation) {
|
| - Annotation constNode = constant.annotation;
|
| - ElementAnnotationImpl elementAnnotation = constNode.elementAnnotation;
|
| - // elementAnnotation is null if the annotation couldn't be resolved, in
|
| - // which case we skip it.
|
| - if (elementAnnotation != null) {
|
| - Element element = elementAnnotation.element;
|
| - if (element is PropertyAccessorElement &&
|
| - element.variable is VariableElementImpl) {
|
| - // The annotation is a reference to a compile-time constant variable.
|
| - // Just copy the evaluation result.
|
| - VariableElementImpl variableElement =
|
| - element.variable as VariableElementImpl;
|
| - if (variableElement.evaluationResult != null) {
|
| - elementAnnotation.evaluationResult =
|
| - variableElement.evaluationResult;
|
| - } else {
|
| - // This could happen in the event that the annotation refers to a
|
| - // non-constant. The error is detected elsewhere, so just silently
|
| - // ignore it here.
|
| - elementAnnotation.evaluationResult = new EvaluationResultImpl(null);
|
| - }
|
| - } else if (element is ConstructorElementImpl &&
|
| - element.isConst &&
|
| - constNode.arguments != null) {
|
| - RecordingErrorListener errorListener = new RecordingErrorListener();
|
| - CompilationUnit sourceCompilationUnit =
|
| - constNode.getAncestor((node) => node is CompilationUnit);
|
| - ErrorReporter errorReporter = new ErrorReporter(
|
| - errorListener, sourceCompilationUnit.element.source);
|
| - ConstantVisitor constantVisitor =
|
| - new ConstantVisitor(this, errorReporter);
|
| - DartObjectImpl result = evaluateConstructorCall(
|
| - constNode,
|
| - constNode.arguments.arguments,
|
| - element,
|
| - constantVisitor,
|
| - errorReporter);
|
| - elementAnnotation.evaluationResult =
|
| - new EvaluationResultImpl(result, errorListener.errors);
|
| + } else if (constant is ElementAnnotationImpl) {
|
| + Annotation constNode = constant.annotationAst;
|
| + Element element = constant.element;
|
| + if (element is PropertyAccessorElement &&
|
| + element.variable is VariableElementImpl) {
|
| + // The annotation is a reference to a compile-time constant variable.
|
| + // Just copy the evaluation result.
|
| + VariableElementImpl variableElement =
|
| + element.variable as VariableElementImpl;
|
| + if (variableElement.evaluationResult != null) {
|
| + constant.evaluationResult = variableElement.evaluationResult;
|
| } else {
|
| - // This may happen for invalid code (e.g. failing to pass arguments
|
| - // to an annotation which references a const constructor). The error
|
| - // is detected elsewhere, so just silently ignore it here.
|
| - elementAnnotation.evaluationResult = new EvaluationResultImpl(null);
|
| + // This could happen in the event that the annotation refers to a
|
| + // non-constant. The error is detected elsewhere, so just silently
|
| + // ignore it here.
|
| + constant.evaluationResult = new EvaluationResultImpl(null);
|
| }
|
| + } else if (element is ConstructorElementImpl &&
|
| + element.isConst &&
|
| + constNode.arguments != null) {
|
| + RecordingErrorListener errorListener = new RecordingErrorListener();
|
| + ErrorReporter errorReporter =
|
| + new ErrorReporter(errorListener, constant.source);
|
| + ConstantVisitor constantVisitor =
|
| + new ConstantVisitor(this, errorReporter);
|
| + DartObjectImpl result = evaluateConstructorCall(
|
| + constNode,
|
| + constNode.arguments.arguments,
|
| + element,
|
| + constantVisitor,
|
| + errorReporter);
|
| + constant.evaluationResult =
|
| + new EvaluationResultImpl(result, errorListener.errors);
|
| + } else {
|
| + // This may happen for invalid code (e.g. failing to pass arguments
|
| + // to an annotation which references a const constructor). The error
|
| + // is detected elsewhere, so just silently ignore it here.
|
| + constant.evaluationResult = new EvaluationResultImpl(null);
|
| }
|
| } else if (constant is VariableElement) {
|
| // constant is a VariableElement but not a VariableElementImpl. This can
|
| @@ -522,26 +514,21 @@ class ConstantEvaluationEngine {
|
| callback(parameterElement);
|
| }
|
| }
|
| - } else if (constant is ConstantEvaluationTarget_Annotation) {
|
| - Annotation constNode = constant.annotation;
|
| - ElementAnnotationImpl elementAnnotation = constNode.elementAnnotation;
|
| - // elementAnnotation is null if the annotation couldn't be resolved, in
|
| - // which case we skip it.
|
| - if (elementAnnotation != null) {
|
| - Element element = elementAnnotation.element;
|
| - if (element is PropertyAccessorElement &&
|
| - element.variable is VariableElementImpl) {
|
| - // The annotation is a reference to a compile-time constant variable,
|
| - // so it depends on the variable.
|
| - callback(element.variable);
|
| - } else if (element is ConstructorElementImpl) {
|
| - // The annotation is a constructor invocation, so it depends on the
|
| - // constructor.
|
| - callback(element);
|
| - } else {
|
| - // This could happen in the event of invalid code. The error will be
|
| - // reported at constant evaluation time.
|
| - }
|
| + } else if (constant is ElementAnnotationImpl) {
|
| + Annotation constNode = constant.annotationAst;
|
| + Element element = constant.element;
|
| + if (element is PropertyAccessorElement &&
|
| + element.variable is VariableElementImpl) {
|
| + // The annotation is a reference to a compile-time constant variable,
|
| + // so it depends on the variable.
|
| + callback(element.variable);
|
| + } else if (element is ConstructorElementImpl) {
|
| + // The annotation is a constructor invocation, so it depends on the
|
| + // constructor.
|
| + callback(element);
|
| + } else {
|
| + // This could happen in the event of invalid code. The error will be
|
| + // reported at constant evaluation time.
|
| }
|
| if (constNode.arguments != null) {
|
| constNode.arguments.accept(referenceFinder);
|
| @@ -1023,39 +1010,6 @@ class ConstantEvaluationEngine {
|
| }
|
|
|
| /**
|
| - * Wrapper around an [Annotation] which can be used as a
|
| - * [ConstantEvaluationTarget].
|
| - */
|
| -class ConstantEvaluationTarget_Annotation implements ConstantEvaluationTarget {
|
| - final AnalysisContext context;
|
| - final Source source;
|
| - final Source librarySource;
|
| - final Annotation annotation;
|
| -
|
| - ConstantEvaluationTarget_Annotation(
|
| - this.context, this.source, this.librarySource, this.annotation);
|
| -
|
| - @override
|
| - int get hashCode => JenkinsSmiHash.hash3(
|
| - source.hashCode, librarySource.hashCode, annotation.hashCode);
|
| -
|
| - @override
|
| - bool operator ==(other) {
|
| - if (other is ConstantEvaluationTarget_Annotation) {
|
| - return this.context == other.context &&
|
| - this.source == other.source &&
|
| - this.librarySource == other.librarySource &&
|
| - this.annotation == other.annotation;
|
| - } else {
|
| - return false;
|
| - }
|
| - }
|
| -
|
| - @override
|
| - String toString() => 'Constant: $annotation';
|
| -}
|
| -
|
| -/**
|
| * Interface used by unit tests to verify correct dependency analysis during
|
| * constant evaluation.
|
| */
|
| @@ -1310,9 +1264,13 @@ class ConstantFinder extends RecursiveAstVisitor<Object> {
|
| @override
|
| Object visitAnnotation(Annotation node) {
|
| super.visitAnnotation(node);
|
| - AnalysisContext owningContext = _getOwningContext();
|
| - constantsToCompute.add(new ConstantEvaluationTarget_Annotation(
|
| - owningContext, source, librarySource, node));
|
| + ElementAnnotation elementAnnotation = node.elementAnnotation;
|
| + if (elementAnnotation == null) {
|
| + // Analyzer ignores annotations on "part of" directives.
|
| + assert(node.parent is PartOfDirective);
|
| + } else {
|
| + constantsToCompute.add(elementAnnotation);
|
| + }
|
| return null;
|
| }
|
|
|
|
|