Further cleanups to annotation elements now that #25706 is fixed.

This CL fixes the following issues:

- In an annotation like @prefix.ClassName.foo or
  @prefix.ClassName.foo(), if "foo" couldn't be resolved, the class
  element would be returned as the annotation element.

- ConstantAstCloner wasn't properly cloning annotation elements,
  leading to weird issues in summary resynthesis tests.

- The summary resynthesizer wasn't setting AnnotationImpl.element.

R=brianwilkerson@google.com, scheglov@google.com

Review URL: https://codereview.chromium.org/2391783002 .
This commit is contained in:
Paul Berry 2016-10-03 15:00:34 -07:00
parent e9bd78fa8e
commit 7c666425a1
4 changed files with 11 additions and 15 deletions

View file

@ -283,7 +283,7 @@ class AnnotationImpl extends AstNodeImpl implements Annotation {
Element get element {
if (_element != null) {
return _element;
} else if (_name != null) {
} else if (_constructorName == null && _name != null) {
return _name.staticElement;
}
return null;

View file

@ -45,6 +45,13 @@ class ConstantAstCloner extends AstCloner {
return name;
}
@override
Annotation visitAnnotation(Annotation node) {
Annotation annotation = super.visitAnnotation(node);
annotation.element = node.element;
return annotation;
}
@override
FunctionExpression visitFunctionExpression(FunctionExpression node) {
FunctionExpression expression = super.visitFunctionExpression(node);

View file

@ -1511,7 +1511,8 @@ class _UnitResynthesizer {
constructorName = null;
}
elementAnnotation.annotationAst = AstFactory.annotation2(
typeName, constructorName, constExpr.argumentList);
typeName, constructorName, constExpr.argumentList)
..element = constExpr.staticElement;
} else {
throw new StateError(
'Unexpected annotation type: ${constExpr.runtimeType}');

View file

@ -542,18 +542,7 @@ abstract class AbstractResynthesizeTest extends AbstractSingleUnitTest {
}
compareConstAstLists(
r.arguments?.arguments, o.arguments?.arguments, desc);
Element expectedElement = o.element;
if (oName is PrefixedIdentifier &&
o.constructorName != null &&
o.element != null) {
// Due to dartbug.com/25706, [o.element] incorrectly points to the
// class rather than the named constructor. Hack around this.
// TODO(paulberry): when dartbug.com/25706 is fixed, remove this.
expectedElement = (expectedElement as ClassElement)
.getNamedConstructor(o.constructorName.name);
expect(expectedElement, isNotNull, reason: desc);
}
compareElements(r.element, expectedElement, desc);
compareElements(r.element, o.element, desc);
// elementAnnotation should be null; it is only used in the full AST.
expect(o.elementAnnotation, isNull);
expect(r.elementAnnotation, isNull);
@ -4492,7 +4481,6 @@ typedef F();''');
checkLibrary('import "dart:async" as foo; @foo.bar.baz() class C {}');
}
@failingTest // See dartbug.com/25706
test_unresolved_annotation_prefixedNamedConstructorCall_noConstructor() {
checkLibrary('import "dart:async" as foo; @foo.Future.bar() class C {}');
}