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

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

Issue 1450073002: Fixes pkg/analysis_server/test/analysis/get_hover_test (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.resolver; 5 library engine.resolver;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'ast.dart'; 9 import 'ast.dart';
10 import 'constant.dart'; 10 import 'constant.dart';
(...skipping 2535 matching lines...) Expand 10 before | Expand all | Expand 10 after
2546 * A flag indicating whether a variable declaration is within the body of a me thod or function. 2546 * A flag indicating whether a variable declaration is within the body of a me thod or function.
2547 */ 2547 */
2548 bool _inFunction = false; 2548 bool _inFunction = false;
2549 2549
2550 /** 2550 /**
2551 * A flag indicating whether the class currently being visited can be used as a mixin. 2551 * A flag indicating whether the class currently being visited can be used as a mixin.
2552 */ 2552 */
2553 bool _isValidMixin = false; 2553 bool _isValidMixin = false;
2554 2554
2555 /** 2555 /**
2556 * A collection holding the elements defined in a class that need to have
2557 * their function type fixed to take into account type parameters of the
2558 * enclosing class, or `null` if we are not currently processing nodes within
2559 * a class.
2560 */
2561 List<ExecutableElementImpl> _functionTypesToFix = null;
2562
2563 /**
2556 * A table mapping field names to field elements for the fields defined in the current class, or 2564 * A table mapping field names to field elements for the fields defined in the current class, or
2557 * `null` if we are not in the scope of a class. 2565 * `null` if we are not in the scope of a class.
2558 */ 2566 */
2559 HashMap<String, FieldElement> _fieldMap; 2567 HashMap<String, FieldElement> _fieldMap;
2560 2568
2561 /** 2569 /**
2562 * Initialize a newly created element builder to build the elements for a comp ilation unit. 2570 * Initialize a newly created element builder to build the elements for a comp ilation unit.
2563 * 2571 *
2564 * @param initialHolder the element holder associated with the compilation uni t being built 2572 * @param initialHolder the element holder associated with the compilation uni t being built
2565 */ 2573 */
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2600 stackTraceParameter.staticElement = stackTrace; 2608 stackTraceParameter.staticElement = stackTrace;
2601 } 2609 }
2602 } 2610 }
2603 return super.visitCatchClause(node); 2611 return super.visitCatchClause(node);
2604 } 2612 }
2605 2613
2606 @override 2614 @override
2607 Object visitClassDeclaration(ClassDeclaration node) { 2615 Object visitClassDeclaration(ClassDeclaration node) {
2608 ElementHolder holder = new ElementHolder(); 2616 ElementHolder holder = new ElementHolder();
2609 _isValidMixin = true; 2617 _isValidMixin = true;
2618 _functionTypesToFix = new List<ExecutableElementImpl>();
2610 // 2619 //
2611 // Process field declarations before constructors and methods so that field 2620 // Process field declarations before constructors and methods so that field
2612 // formal parameters can be correctly resolved to their fields. 2621 // formal parameters can be correctly resolved to their fields.
2613 // 2622 //
2614 ElementHolder previousHolder = _currentHolder; 2623 ElementHolder previousHolder = _currentHolder;
2615 _currentHolder = holder; 2624 _currentHolder = holder;
2616 try { 2625 try {
2617 List<ClassMember> nonFields = new List<ClassMember>(); 2626 List<ClassMember> nonFields = new List<ClassMember>();
2618 node.visitChildren( 2627 node.visitChildren(
2619 new _ElementBuilder_visitClassDeclaration(this, nonFields)); 2628 new _ElementBuilder_visitClassDeclaration(this, nonFields));
2620 _buildFieldMap(holder.fieldsWithoutFlushing); 2629 _buildFieldMap(holder.fieldsWithoutFlushing);
2621 int count = nonFields.length; 2630 int count = nonFields.length;
2622 for (int i = 0; i < count; i++) { 2631 for (int i = 0; i < count; i++) {
2623 nonFields[i].accept(this); 2632 nonFields[i].accept(this);
2624 } 2633 }
2625 } finally { 2634 } finally {
2626 _currentHolder = previousHolder; 2635 _currentHolder = previousHolder;
2627 } 2636 }
2628 SimpleIdentifier className = node.name; 2637 SimpleIdentifier className = node.name;
2629 ClassElementImpl element = new ClassElementImpl.forNode(className); 2638 ClassElementImpl element = new ClassElementImpl.forNode(className);
2630 List<TypeParameterElement> typeParameters = holder.typeParameters; 2639 List<TypeParameterElement> typeParameters = holder.typeParameters;
2631 List<DartType> typeArguments = _createTypeParameterTypes(typeParameters); 2640 List<DartType> typeArguments = _createTypeParameterTypes(typeParameters);
2632 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl(element); 2641 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl(element);
2633 interfaceType.typeArguments = typeArguments; 2642 interfaceType.typeArguments = typeArguments;
2634 element.type = interfaceType; 2643 element.type = interfaceType;
2635 List<ConstructorElement> constructors = holder.constructors; 2644 element.typeParameters = typeParameters;
2636 if (constructors.length == 0) {
2637 //
2638 // Create the default constructor.
2639 //
2640 constructors = _createDefaultConstructors(interfaceType);
2641 }
2642 _setDocRange(element, node); 2645 _setDocRange(element, node);
2643 element.abstract = node.isAbstract; 2646 element.abstract = node.isAbstract;
2644 element.accessors = holder.accessors; 2647 element.accessors = holder.accessors;
2648 List<ConstructorElement> constructors = holder.constructors;
2649 if (constructors.isEmpty) {
2650 constructors = _createDefaultConstructors(element);
2651 }
2645 element.constructors = constructors; 2652 element.constructors = constructors;
2646 element.fields = holder.fields; 2653 element.fields = holder.fields;
2647 element.methods = holder.methods; 2654 element.methods = holder.methods;
2648 element.typeParameters = typeParameters;
2649 element.validMixin = _isValidMixin; 2655 element.validMixin = _isValidMixin;
2656 // Function types must be initialized after the enclosing element has been
2657 // set, for them to pick up the type parameters.
2658 for (ExecutableElementImpl e in _functionTypesToFix) {
2659 e.type = new FunctionTypeImpl(e);
2660 }
2661 _functionTypesToFix = null;
2650 _currentHolder.addType(element); 2662 _currentHolder.addType(element);
2651 className.staticElement = element; 2663 className.staticElement = element;
2652 _fieldMap = null; 2664 _fieldMap = null;
2653 holder.validate(); 2665 holder.validate();
2654 return null; 2666 return null;
2655 } 2667 }
2656 2668
2657 /** 2669 /**
2658 * Implementation of this method should be synchronized with 2670 * Implementation of this method should be synchronized with
2659 * [visitClassDeclaration]. 2671 * [visitClassDeclaration].
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
3012 element.generator = true; 3024 element.generator = true;
3013 } 3025 }
3014 if (_inFunction) { 3026 if (_inFunction) {
3015 Block enclosingBlock = node.getAncestor((node) => node is Block); 3027 Block enclosingBlock = node.getAncestor((node) => node is Block);
3016 if (enclosingBlock != null) { 3028 if (enclosingBlock != null) {
3017 int functionEnd = node.offset + node.length; 3029 int functionEnd = node.offset + node.length;
3018 int blockEnd = enclosingBlock.offset + enclosingBlock.length; 3030 int blockEnd = enclosingBlock.offset + enclosingBlock.length;
3019 element.setVisibleRange(functionEnd, blockEnd - functionEnd - 1); 3031 element.setVisibleRange(functionEnd, blockEnd - functionEnd - 1);
3020 } 3032 }
3021 } 3033 }
3022 element.type = new FunctionTypeImpl(element); 3034 if (_functionTypesToFix != null) {
3035 _functionTypesToFix.add(element);
3036 } else {
3037 // TODO(jmesserly): for local functions inside of top-level generic
3038 // functions, this is probably not right. The function type should be set
3039 // after the enclosingElement is set, otherwise we won't be able to
3040 // substitute those type parameters later.
3041 element.type = new FunctionTypeImpl(element);
3042 }
3023 element.hasImplicitReturnType = true; 3043 element.hasImplicitReturnType = true;
3024 _currentHolder.addFunction(element); 3044 _currentHolder.addFunction(element);
3025 node.element = element; 3045 node.element = element;
3026 holder.validate(); 3046 holder.validate();
3027 return null; 3047 return null;
3028 } 3048 }
3029 3049
3030 @override 3050 @override
3031 Object visitFunctionTypeAlias(FunctionTypeAlias node) { 3051 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
3032 ElementHolder holder = new ElementHolder(); 3052 ElementHolder holder = new ElementHolder();
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
3415 } 3435 }
3416 } 3436 }
3417 3437
3418 /** 3438 /**
3419 * Creates the [ConstructorElement]s array with the single default constructor element. 3439 * Creates the [ConstructorElement]s array with the single default constructor element.
3420 * 3440 *
3421 * @param interfaceType the interface type for which to create a default const ructor 3441 * @param interfaceType the interface type for which to create a default const ructor
3422 * @return the [ConstructorElement]s array with the single default constructor element 3442 * @return the [ConstructorElement]s array with the single default constructor element
3423 */ 3443 */
3424 List<ConstructorElement> _createDefaultConstructors( 3444 List<ConstructorElement> _createDefaultConstructors(
3425 InterfaceTypeImpl interfaceType) { 3445 ClassElementImpl definingClass) {
3426 ConstructorElementImpl constructor = 3446 ConstructorElementImpl constructor =
3427 new ConstructorElementImpl.forNode(null); 3447 new ConstructorElementImpl.forNode(null);
3428 constructor.synthetic = true; 3448 constructor.synthetic = true;
3429 constructor.returnType = interfaceType; 3449 constructor.returnType = definingClass.type;
3450 constructor.enclosingElement = definingClass;
3430 constructor.type = new FunctionTypeImpl(constructor); 3451 constructor.type = new FunctionTypeImpl(constructor);
3431 return <ConstructorElement>[constructor]; 3452 return <ConstructorElement>[constructor];
3432 } 3453 }
3433 3454
3434 /** 3455 /**
3435 * Create the types associated with the given type parameters, setting the typ e of each type 3456 * Create the types associated with the given type parameters, setting the typ e of each type
3436 * parameter, and return an array of types corresponding to the given paramete rs. 3457 * parameter, and return an array of types corresponding to the given paramete rs.
3437 * 3458 *
3438 * @param typeParameters the type parameters for which types are to be created 3459 * @param typeParameters the type parameters for which types are to be created
3439 * @return an array of types corresponding to the given parameters 3460 * @return an array of types corresponding to the given parameters
(...skipping 12109 matching lines...) Expand 10 before | Expand all | Expand 10 after
15549 nonFields.add(node); 15570 nonFields.add(node);
15550 return null; 15571 return null;
15551 } 15572 }
15552 15573
15553 @override 15574 @override
15554 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); 15575 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this);
15555 15576
15556 @override 15577 @override
15557 Object visitWithClause(WithClause node) => null; 15578 Object visitWithClause(WithClause node) => null;
15558 } 15579 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698