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

Side by Side Diff: pkg/analyzer/lib/src/generated/incremental_resolver.dart

Issue 756453002: Incremental resolution: rename function/constructor/method parameters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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 | Annotate | Revision Log
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 engine.incremental_resolver; 5 library engine.incremental_resolver;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'ast.dart'; 9 import 'ast.dart';
10 import 'element.dart'; 10 import 'element.dart';
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 } 140 }
141 141
142 @override 142 @override
143 visitConstructorDeclaration(ConstructorDeclaration node) { 143 visitConstructorDeclaration(ConstructorDeclaration node) {
144 _hasConstructor = true; 144 _hasConstructor = true;
145 SimpleIdentifier constructorName = node.name; 145 SimpleIdentifier constructorName = node.name;
146 ConstructorElement element = constructorName == null ? 146 ConstructorElement element = constructorName == null ?
147 _enclosingClass.unnamedConstructor : 147 _enclosingClass.unnamedConstructor :
148 _enclosingClass.getNamedConstructor(constructorName.name); 148 _enclosingClass.getNamedConstructor(constructorName.name);
149 _processElement(element); 149 _processElement(element);
150 node.element = element;
150 _assertCompatibleParameters(node.parameters, element.parameters); 151 _assertCompatibleParameters(node.parameters, element.parameters);
151 } 152 }
152 153
153 @override 154 @override
154 visitEnumConstantDeclaration(EnumConstantDeclaration node) { 155 visitEnumConstantDeclaration(EnumConstantDeclaration node) {
155 String name = node.name.name; 156 String name = node.name.name;
156 FieldElement element = _findElement(_enclosingClass.fields, name); 157 FieldElement element = _findElement(_enclosingClass.fields, name);
157 _processElement(element); 158 _processElement(element);
158 } 159 }
159 160
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 } 200 }
200 201
201 @override 202 @override
202 visitFunctionDeclaration(FunctionDeclaration node) { 203 visitFunctionDeclaration(FunctionDeclaration node) {
203 String name = node.name.name; 204 String name = node.name.name;
204 Token property = node.propertyKeyword; 205 Token property = node.propertyKeyword;
205 ExecutableElement element; 206 ExecutableElement element;
206 if (property == null) { 207 if (property == null) {
207 element = _findElement(_enclosingUnit.functions, name); 208 element = _findElement(_enclosingUnit.functions, name);
208 _processElement(element); 209 _processElement(element);
210 node.name.staticElement = element;
211 node.functionExpression.element = element;
209 } else { 212 } else {
210 PropertyAccessorElement accessor = 213 PropertyAccessorElement accessor =
211 _findElement(_enclosingUnit.accessors, name); 214 _findElement(_enclosingUnit.accessors, name);
212 _assertNotNull(accessor); 215 _assertNotNull(accessor);
213 _assertFalse(element.isSynthetic); 216 _assertFalse(element.isSynthetic);
214 _assertEquals(node.isGetter, accessor.isGetter); 217 _assertEquals(node.isGetter, accessor.isGetter);
215 _assertEquals(node.isSetter, accessor.isSetter); 218 _assertEquals(node.isSetter, accessor.isSetter);
216 element = accessor; 219 element = accessor;
217 } 220 }
218 _processElement(element); 221 _processElement(element);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 PropertyAccessorElement accessor = 285 PropertyAccessorElement accessor =
283 _findElement(_enclosingClass.accessors, name); 286 _findElement(_enclosingClass.accessors, name);
284 _assertNotNull(accessor); 287 _assertNotNull(accessor);
285 _assertFalse(element.isSynthetic); 288 _assertFalse(element.isSynthetic);
286 _assertEquals(node.isGetter, accessor.isGetter); 289 _assertEquals(node.isGetter, accessor.isGetter);
287 _assertEquals(node.isSetter, accessor.isSetter); 290 _assertEquals(node.isSetter, accessor.isSetter);
288 element = accessor; 291 element = accessor;
289 } 292 }
290 // process element 293 // process element
291 _processElement(element); 294 _processElement(element);
295 node.name.staticElement = element;
292 // TODO(scheglov) test returnType 296 // TODO(scheglov) test returnType
293 _assertSameType(node.returnType, element.returnType); 297 _assertSameType(node.returnType, element.returnType);
294 _assertCompatibleParameters(node.parameters, element.parameters); 298 _assertCompatibleParameters(node.parameters, element.parameters);
295 } 299 }
296 300
297 @override 301 @override
298 visitPartDirective(PartDirective node) { 302 visitPartDirective(PartDirective node) {
299 String uri = _getStringValue(node.uri); 303 String uri = _getStringValue(node.uri);
300 if (uri != null) { 304 if (uri != null) {
301 CompilationUnitElement element = 305 CompilationUnitElement element =
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 } 389 }
386 } 390 }
387 _assertTrue(showNames.isEmpty); 391 _assertTrue(showNames.isEmpty);
388 _assertTrue(hideNames.isEmpty); 392 _assertTrue(hideNames.isEmpty);
389 } 393 }
390 394
391 void _assertCompatibleParameter(FormalParameter node, 395 void _assertCompatibleParameter(FormalParameter node,
392 ParameterElement element) { 396 ParameterElement element) {
393 if (node is SimpleFormalParameter) { 397 if (node is SimpleFormalParameter) {
394 _assertSameType(node.type, element.type); 398 _assertSameType(node.type, element.type);
399 node.identifier.staticElement = element;
400 element.nameOffset = node.identifier.offset;
401 (element as ElementImpl).name = node.identifier.name;
395 } else { 402 } else {
396 // TODO(scheglov) support other parameter types 403 // TODO(scheglov) support other parameter types
397 _assertTrue(false); 404 _assertTrue(false);
398 } 405 }
399 // TODO(scheglov) check names of named parameters 406 // TODO(scheglov) check names of named parameters
400 } 407 }
401 408
402 void _assertCompatibleParameters(FormalParameterList nodes, 409 void _assertCompatibleParameters(FormalParameterList nodes,
403 List<ParameterElement> elements) { 410 List<ParameterElement> elements) {
404 List<FormalParameter> parameters = nodes.parameters; 411 List<FormalParameter> parameters = nodes.parameters;
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 * 661 *
655 * [node] - the root of the AST structure to be resolved. 662 * [node] - the root of the AST structure to be resolved.
656 */ 663 */
657 void resolve(AstNode node) { 664 void resolve(AstNode node) {
658 AstNode rootNode = _findResolutionRoot(node); 665 AstNode rootNode = _findResolutionRoot(node);
659 // update elements 666 // update elements
660 _definingUnit.accept( 667 _definingUnit.accept(
661 new _ElementNameOffsetUpdater( 668 new _ElementNameOffsetUpdater(
662 _updateOffset, 669 _updateOffset,
663 _updateNewLength - _updateOldLength)); 670 _updateNewLength - _updateOldLength));
664 _updateElements(rootNode);
665 if (_elementModelChanged(rootNode)) { 671 if (_elementModelChanged(rootNode)) {
666 throw new AnalysisException("Cannot resolve node: element model changed"); 672 throw new AnalysisException("Cannot resolve node: element model changed");
667 } 673 }
674 _updateElements(rootNode);
668 // resolve root in scope 675 // resolve root in scope
669 ResolutionContext context = 676 ResolutionContext context =
670 ResolutionContextBuilder.contextFor(rootNode, _errorListener); 677 ResolutionContextBuilder.contextFor(rootNode, _errorListener);
671 Scope scope = context.scope; 678 Scope scope = context.scope;
672 _resolveTypes(rootNode, scope); 679 _resolveTypes(rootNode, scope);
673 _resolveVariables(rootNode, scope); 680 _resolveVariables(rootNode, scope);
674 _resolveReferences(rootNode, context); 681 _resolveReferences(rootNode, context);
675 } 682 }
676 683
677 /** 684 /**
(...skipping 17 matching lines...) Expand all
695 /** 702 /**
696 * Return `true` if the portion of the element model defined by the given node 703 * Return `true` if the portion of the element model defined by the given node
697 * has changed. 704 * has changed.
698 * 705 *
699 * [node] - the node defining the portion of the element model being tested. 706 * [node] - the node defining the portion of the element model being tested.
700 * 707 *
701 * Throws [AnalysisException] if the correctness of the element model cannot 708 * Throws [AnalysisException] if the correctness of the element model cannot
702 * be determined. 709 * be determined.
703 */ 710 */
704 bool _elementModelChanged(AstNode node) { 711 bool _elementModelChanged(AstNode node) {
712 // If we are replacing the whole declaration (e.g. rename a parameter), we
713 // can try to find the corresponding Element in the enclosing one, see if it
714 // is compatible, and if 'yes', then restore and update it.
715 if (node is Declaration) {
716 node = node.parent;
717 }
705 Element element = _getElement(node); 718 Element element = _getElement(node);
706 if (element == null) { 719 if (element == null) {
707 throw new AnalysisException( 720 throw new AnalysisException(
708 "Cannot resolve node: a ${node.runtimeType} does not define an element "); 721 "Cannot resolve node: a ${node.runtimeType} does not define an element ");
709 } 722 }
710 DeclarationMatcher matcher = new DeclarationMatcher(); 723 DeclarationMatcher matcher = new DeclarationMatcher();
711 return !matcher.matches(node, element); 724 return !matcher.matches(node, element);
712 } 725 }
713 726
714 /** 727 /**
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 visitFunctionExpression(FunctionExpression node) { 1086 visitFunctionExpression(FunctionExpression node) {
1074 _elements[node] = node.element; 1087 _elements[node] = node.element;
1075 super.visitFunctionExpression(node); 1088 super.visitFunctionExpression(node);
1076 } 1089 }
1077 1090
1078 @override 1091 @override
1079 visitSimpleIdentifier(SimpleIdentifier node) { 1092 visitSimpleIdentifier(SimpleIdentifier node) {
1080 _elements[node] = node.staticElement; 1093 _elements[node] = node.staticElement;
1081 } 1094 }
1082 } 1095 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/element.dart ('k') | pkg/analyzer/test/generated/incremental_resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698