OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.task.incremental_element_builder; | 5 library analyzer.src.task.incremental_element_builder; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 123 |
124 /** | 124 /** |
125 * Updates [oldUnit] to have the same directives and declarations, in the | 125 * Updates [oldUnit] to have the same directives and declarations, in the |
126 * same order as in [newUnit]. Existing resolution is kept where possible. | 126 * same order as in [newUnit]. Existing resolution is kept where possible. |
127 * | 127 * |
128 * Updates [unitElement] by adding/removing elements as needed. | 128 * Updates [unitElement] by adding/removing elements as needed. |
129 * | 129 * |
130 * Fills [unitDelta] with added/remove elements. | 130 * Fills [unitDelta] with added/remove elements. |
131 */ | 131 */ |
132 void build() { | 132 void build() { |
| 133 _materializeLazyElements(); |
133 new CompilationUnitBuilder() | 134 new CompilationUnitBuilder() |
134 .buildCompilationUnit(unitSource, newUnit, librarySource); | 135 .buildCompilationUnit(unitSource, newUnit, librarySource); |
135 _processDirectives(); | 136 _processDirectives(); |
136 _processUnitMembers(); | 137 _processUnitMembers(); |
137 _replaceUnitContents(oldUnit, newUnit); | 138 _replaceUnitContents(oldUnit, newUnit); |
138 _findConstants(); | 139 _findConstants(); |
139 newUnit.element = unitElement; | 140 newUnit.element = unitElement; |
140 unitElement.setCodeRange(0, newUnit.endToken.end); | 141 unitElement.setCodeRange(0, newUnit.endToken.end); |
141 } | 142 } |
142 | 143 |
(...skipping 20 matching lines...) Expand all Loading... |
163 oldUnit.accept(finder); | 164 oldUnit.accept(finder); |
164 unitConstants.addAll(finder.constantsToCompute); | 165 unitConstants.addAll(finder.constantsToCompute); |
165 // Update annotation constants to using the old unit element. | 166 // Update annotation constants to using the old unit element. |
166 for (ConstantEvaluationTarget constant in unitConstants) { | 167 for (ConstantEvaluationTarget constant in unitConstants) { |
167 if (constant is ElementAnnotationImpl) { | 168 if (constant is ElementAnnotationImpl) { |
168 constant.compilationUnit = unitElement; | 169 constant.compilationUnit = unitElement; |
169 } | 170 } |
170 } | 171 } |
171 } | 172 } |
172 | 173 |
| 174 void _materializeLazyElements() { |
| 175 unitElement.accept(new RecursiveElementVisitor()); |
| 176 } |
| 177 |
173 ClassElementDelta _processClassMembers( | 178 ClassElementDelta _processClassMembers( |
174 ClassDeclaration oldClass, ClassDeclaration newClass) { | 179 ClassDeclaration oldClass, ClassDeclaration newClass) { |
175 // If the class hierarchy or type parameters are changed, | 180 // If the class hierarchy or type parameters are changed, |
176 // then the class changed too much - don't compute the delta. | 181 // then the class changed too much - don't compute the delta. |
177 if (newClass.abstractKeyword != null && oldClass.abstractKeyword == null || | 182 if (newClass.abstractKeyword != null && oldClass.abstractKeyword == null || |
178 newClass.abstractKeyword == null && oldClass.abstractKeyword != null || | 183 newClass.abstractKeyword == null && oldClass.abstractKeyword != null || |
179 TokenUtils.getFullCode(newClass.typeParameters) != | 184 TokenUtils.getFullCode(newClass.typeParameters) != |
180 TokenUtils.getFullCode(oldClass.typeParameters) || | 185 TokenUtils.getFullCode(oldClass.typeParameters) || |
181 TokenUtils.getFullCode(newClass.extendsClause) != | 186 TokenUtils.getFullCode(newClass.extendsClause) != |
182 TokenUtils.getFullCode(oldClass.extendsClause) || | 187 TokenUtils.getFullCode(oldClass.extendsClause) || |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 */ | 681 */ |
677 class _UpdateElementOffsetsVisitor extends GeneralizingElementVisitor { | 682 class _UpdateElementOffsetsVisitor extends GeneralizingElementVisitor { |
678 final Map<int, int> map; | 683 final Map<int, int> map; |
679 | 684 |
680 _UpdateElementOffsetsVisitor(this.map); | 685 _UpdateElementOffsetsVisitor(this.map); |
681 | 686 |
682 void visitElement(Element element) { | 687 void visitElement(Element element) { |
683 if (element is LibraryElement) { | 688 if (element is LibraryElement) { |
684 return; | 689 return; |
685 } | 690 } |
686 if (element.isSynthetic && !_isVariableInitializer(element)) { | |
687 return; | |
688 } | |
689 if (element is ElementImpl) { | 691 if (element is ElementImpl) { |
690 // name offset | 692 // name offset |
691 { | 693 { |
692 int oldOffset = element.nameOffset; | 694 int oldOffset = element.nameOffset; |
693 int newOffset = map[oldOffset]; | 695 int newOffset = map[oldOffset]; |
694 assert(newOffset != null); | 696 // Some synthetic elements have new offsets, e.g. synthetic accessors |
| 697 // of property inducing elements. But some are purely synthetic, e.g. |
| 698 // synthetic enum fields and their accessors. |
| 699 if (newOffset == null) { |
| 700 assert(element.isSynthetic); |
| 701 return; |
| 702 } |
695 element.nameOffset = newOffset; | 703 element.nameOffset = newOffset; |
696 } | 704 } |
697 // code range | 705 // code range |
698 { | 706 { |
699 int oldOffset = element.codeOffset; | 707 int oldOffset = element.codeOffset; |
700 if (oldOffset != null) { | 708 if (oldOffset != null) { |
701 int oldEnd = oldOffset + element.codeLength; | 709 int oldEnd = oldOffset + element.codeLength; |
702 int newOffset = map[oldOffset]; | 710 int newOffset = map[oldOffset]; |
703 int newEnd = map[oldEnd]; | 711 int newEnd = map[oldEnd]; |
704 assert(newOffset != null); | 712 assert(newOffset != null); |
(...skipping 21 matching lines...) Expand all Loading... |
726 element.setVisibleRange(newOffset, newLength); | 734 element.setVisibleRange(newOffset, newLength); |
727 } else if (element is ParameterElementImpl) { | 735 } else if (element is ParameterElementImpl) { |
728 element.setVisibleRange(newOffset, newLength); | 736 element.setVisibleRange(newOffset, newLength); |
729 } | 737 } |
730 } | 738 } |
731 } | 739 } |
732 } | 740 } |
733 } | 741 } |
734 super.visitElement(element); | 742 super.visitElement(element); |
735 } | 743 } |
736 | |
737 static bool _isVariableInitializer(Element element) { | |
738 return element is FunctionElement && | |
739 element.enclosingElement is VariableElement; | |
740 } | |
741 } | 744 } |
OLD | NEW |