Another fix incremental constants - annotations should use the old unit element.
R=brianwilkerson@google.com BUG= Review URL: https://codereview.chromium.org/2160673002 .
This commit is contained in:
@@ -2533,7 +2533,7 @@ class ElementAnnotationImpl implements ElementAnnotation {
|
||||
/**
|
||||
* The compilation unit in which this annotation appears.
|
||||
*/
|
||||
final CompilationUnitElementImpl compilationUnit;
|
||||
CompilationUnitElementImpl compilationUnit;
|
||||
|
||||
/**
|
||||
* The AST of the annotation itself, cloned from the resolved AST for the
|
||||
|
||||
@@ -162,6 +162,12 @@ class IncrementalCompilationUnitElementBuilder {
|
||||
ConstantFinder finder = new ConstantFinder();
|
||||
oldUnit.accept(finder);
|
||||
unitConstants.addAll(finder.constantsToCompute);
|
||||
// Update annotation constants to using the old unit element.
|
||||
for (ConstantEvaluationTarget constant in unitConstants) {
|
||||
if (constant is ElementAnnotationImpl) {
|
||||
constant.compilationUnit = unitElement;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ClassElementDelta _processClassMembers(
|
||||
|
||||
@@ -3312,6 +3312,30 @@ int B = _A + 1;
|
||||
_assertInvalid(b, LIBRARY_ERRORS_READY);
|
||||
}
|
||||
|
||||
void test_sequence_add_annotation() {
|
||||
Source a = addSource(
|
||||
'/a.dart',
|
||||
r'''
|
||||
const myAnnotation = const Object();
|
||||
class A {}
|
||||
''');
|
||||
_performPendingAnalysisTasks();
|
||||
// Add a new annotation.
|
||||
context.setContents(
|
||||
a,
|
||||
r'''
|
||||
const myAnnotation = const Object();
|
||||
@myAnnotation
|
||||
class A {}
|
||||
''');
|
||||
_assertValidForChangedLibrary(a);
|
||||
_assertInvalid(a, LIBRARY_ERRORS_READY);
|
||||
// Analysis is done successfully.
|
||||
_performPendingAnalysisTasks();
|
||||
_assertValid(a, LIBRARY_ERRORS_READY);
|
||||
_assertValid(a, READY_RESOLVED_UNIT);
|
||||
}
|
||||
|
||||
void test_sequence_applyChanges_changedSource() {
|
||||
Source a = addSource(
|
||||
'/a.dart',
|
||||
|
||||
@@ -1649,6 +1649,18 @@ class A {
|
||||
''');
|
||||
}
|
||||
|
||||
test_update_annotation_add() {
|
||||
_buildOldUnit(r'''
|
||||
const myAnnotation = const Object();
|
||||
foo() {}
|
||||
''');
|
||||
_buildNewUnit(r'''
|
||||
const myAnnotation = const Object();
|
||||
@myAnnotation
|
||||
foo() {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_update_beforeClassWithDelta_nameOffset() {
|
||||
_buildOldUnit(r'''
|
||||
class A {}
|
||||
@@ -1866,6 +1878,16 @@ class _BuiltElementsValidator extends AstComparator {
|
||||
actual.getAncestor((n) => n is ClassDeclaration);
|
||||
expect(element.enclosingElement, same(classNode.element));
|
||||
}
|
||||
// ElementAnnotationImpl must use the enclosing CompilationUnitElement.
|
||||
if (actual is Annotation) {
|
||||
AstNode parent = actual.parent;
|
||||
if (parent is Declaration) {
|
||||
ElementAnnotationImpl actualElement = actual.elementAnnotation;
|
||||
CompilationUnitElement enclosingUnitElement =
|
||||
parent.element.getAncestor((a) => a is CompilationUnitElement);
|
||||
expect(actualElement.compilationUnit, same(enclosingUnitElement));
|
||||
}
|
||||
}
|
||||
// Identifiers like 'a.b' in 'new a.b()' might be rewritten if resolver
|
||||
// sees that 'a' is actually a class name, so 'b' is a constructor name.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user