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

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

Issue 1131423002: Clean up many generated constructors (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Comment change Created 5 years, 7 months 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
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | pkg/analyzer/lib/src/generated/scanner.dart » ('j') | 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:math" as math; 7 import "dart:math" as math;
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/src/generated/utilities_collection.dart'; 10 import 'package:analyzer/src/generated/utilities_collection.dart';
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 if (typeElement == null) { 736 if (typeElement == null) {
737 throw new IllegalArgumentException("class element cannot be null"); 737 throw new IllegalArgumentException("class element cannot be null");
738 } 738 }
739 _defineMembers(typeElement); 739 _defineMembers(typeElement);
740 } 740 }
741 741
742 @override 742 @override
743 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { 743 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) {
744 if (existing is PropertyAccessorElement && duplicate is MethodElement) { 744 if (existing is PropertyAccessorElement && duplicate is MethodElement) {
745 if (existing.nameOffset < duplicate.nameOffset) { 745 if (existing.nameOffset < duplicate.nameOffset) {
746 return new AnalysisError.con2(duplicate.source, duplicate.nameOffset, 746 return new AnalysisError(duplicate.source, duplicate.nameOffset,
747 duplicate.displayName.length, 747 duplicate.displayName.length,
748 CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAME, 748 CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAME,
749 [existing.displayName]); 749 [existing.displayName]);
750 } else { 750 } else {
751 return new AnalysisError.con2(existing.source, existing.nameOffset, 751 return new AnalysisError(existing.source, existing.nameOffset,
752 existing.displayName.length, 752 existing.displayName.length,
753 CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME, 753 CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME,
754 [existing.displayName]); 754 [existing.displayName]);
755 } 755 }
756 } 756 }
757 return super.getErrorForDuplicate(existing, duplicate); 757 return super.getErrorForDuplicate(existing, duplicate);
758 } 758 }
759 759
760 /** 760 /**
761 * Define the instance members defined by the class. 761 * Define the instance members defined by the class.
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 new DartObjectImpl(_typeProvider.nullType, NullState.NULL_STATE); 1261 new DartObjectImpl(_typeProvider.nullType, NullState.NULL_STATE);
1262 } else { 1262 } else {
1263 result = _validate( 1263 result = _validate(
1264 defaultValue, CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE); 1264 defaultValue, CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE);
1265 if (result != null) { 1265 if (result != null) {
1266 _reportErrorIfFromDeferredLibrary(defaultValue, 1266 _reportErrorIfFromDeferredLibrary(defaultValue,
1267 CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE_FROM_DEFERRED_LI BRARY); 1267 CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE_FROM_DEFERRED_LI BRARY);
1268 } 1268 }
1269 } 1269 }
1270 VariableElementImpl element = parameter.element as VariableElementImpl; 1270 VariableElementImpl element = parameter.element as VariableElementImpl;
1271 element.evaluationResult = new EvaluationResultImpl.con1(result); 1271 element.evaluationResult = new EvaluationResultImpl(result);
1272 } 1272 }
1273 } 1273 }
1274 } 1274 }
1275 1275
1276 /** 1276 /**
1277 * Validates that the expressions of any field initializers in the class decla ration are all 1277 * Validates that the expressions of any field initializers in the class decla ration are all
1278 * compile time constants. Since this is only required if the class has a cons tant constructor, 1278 * compile time constants. Since this is only required if the class has a cons tant constructor,
1279 * the error is reported at the constructor site. 1279 * the error is reported at the constructor site.
1280 * 1280 *
1281 * @param classDeclaration the class which should be validated 1281 * @param classDeclaration the class which should be validated
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
1709 * expression is not a constant boolean value. 1709 * expression is not a constant boolean value.
1710 * 1710 *
1711 * @param expression the expression to evaluate 1711 * @param expression the expression to evaluate
1712 * @return [ValidResult.RESULT_TRUE] if it is `true`, [ValidResult.RESULT_FALS E] 1712 * @return [ValidResult.RESULT_TRUE] if it is `true`, [ValidResult.RESULT_FALS E]
1713 * if it is `false`, or `null` if the expression is not a constant boo lean 1713 * if it is `false`, or `null` if the expression is not a constant boo lean
1714 * value 1714 * value
1715 */ 1715 */
1716 EvaluationResultImpl _getConstantBooleanValue(Expression expression) { 1716 EvaluationResultImpl _getConstantBooleanValue(Expression expression) {
1717 if (expression is BooleanLiteral) { 1717 if (expression is BooleanLiteral) {
1718 if (expression.value) { 1718 if (expression.value) {
1719 return new EvaluationResultImpl.con1( 1719 return new EvaluationResultImpl(
1720 new DartObjectImpl(null, BoolState.from(true))); 1720 new DartObjectImpl(null, BoolState.from(true)));
1721 } else { 1721 } else {
1722 return new EvaluationResultImpl.con1( 1722 return new EvaluationResultImpl(
1723 new DartObjectImpl(null, BoolState.from(false))); 1723 new DartObjectImpl(null, BoolState.from(false)));
1724 } 1724 }
1725 } 1725 }
1726 // Don't consider situations where we could evaluate to a constant boolean 1726 // Don't consider situations where we could evaluate to a constant boolean
1727 // expression with the ConstantVisitor 1727 // expression with the ConstantVisitor
1728 // else { 1728 // else {
1729 // EvaluationResultImpl result = expression.accept(new ConstantVisitor()); 1729 // EvaluationResultImpl result = expression.accept(new ConstantVisitor());
1730 // if (result == ValidResult.RESULT_TRUE) { 1730 // if (result == ValidResult.RESULT_TRUE) {
1731 // return ValidResult.RESULT_TRUE; 1731 // return ValidResult.RESULT_TRUE;
1732 // } else if (result == ValidResult.RESULT_FALSE) { 1732 // } else if (result == ValidResult.RESULT_FALSE) {
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
2443 for (int i = 0; i < count; i++) { 2443 for (int i = 0; i < count; i++) {
2444 nonFields[i].accept(this); 2444 nonFields[i].accept(this);
2445 } 2445 }
2446 } finally { 2446 } finally {
2447 _currentHolder = previousHolder; 2447 _currentHolder = previousHolder;
2448 } 2448 }
2449 SimpleIdentifier className = node.name; 2449 SimpleIdentifier className = node.name;
2450 ClassElementImpl element = new ClassElementImpl.forNode(className); 2450 ClassElementImpl element = new ClassElementImpl.forNode(className);
2451 List<TypeParameterElement> typeParameters = holder.typeParameters; 2451 List<TypeParameterElement> typeParameters = holder.typeParameters;
2452 List<DartType> typeArguments = _createTypeParameterTypes(typeParameters); 2452 List<DartType> typeArguments = _createTypeParameterTypes(typeParameters);
2453 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl.con1(element); 2453 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl(element);
2454 interfaceType.typeArguments = typeArguments; 2454 interfaceType.typeArguments = typeArguments;
2455 element.type = interfaceType; 2455 element.type = interfaceType;
2456 List<ConstructorElement> constructors = holder.constructors; 2456 List<ConstructorElement> constructors = holder.constructors;
2457 if (constructors.length == 0) { 2457 if (constructors.length == 0) {
2458 // 2458 //
2459 // Create the default constructor. 2459 // Create the default constructor.
2460 // 2460 //
2461 constructors = _createDefaultConstructors(interfaceType); 2461 constructors = _createDefaultConstructors(interfaceType);
2462 } 2462 }
2463 element.abstract = node.isAbstract; 2463 element.abstract = node.isAbstract;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2498 _functionTypesToFix = new List<FunctionTypeImpl>(); 2498 _functionTypesToFix = new List<FunctionTypeImpl>();
2499 _visitChildren(holder, node); 2499 _visitChildren(holder, node);
2500 SimpleIdentifier className = node.name; 2500 SimpleIdentifier className = node.name;
2501 ClassElementImpl element = new ClassElementImpl.forNode(className); 2501 ClassElementImpl element = new ClassElementImpl.forNode(className);
2502 element.abstract = node.abstractKeyword != null; 2502 element.abstract = node.abstractKeyword != null;
2503 element.mixinApplication = true; 2503 element.mixinApplication = true;
2504 element.typedef = true; 2504 element.typedef = true;
2505 List<TypeParameterElement> typeParameters = holder.typeParameters; 2505 List<TypeParameterElement> typeParameters = holder.typeParameters;
2506 element.typeParameters = typeParameters; 2506 element.typeParameters = typeParameters;
2507 List<DartType> typeArguments = _createTypeParameterTypes(typeParameters); 2507 List<DartType> typeArguments = _createTypeParameterTypes(typeParameters);
2508 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl.con1(element); 2508 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl(element);
2509 interfaceType.typeArguments = typeArguments; 2509 interfaceType.typeArguments = typeArguments;
2510 element.type = interfaceType; 2510 element.type = interfaceType;
2511 // set default constructor 2511 // set default constructor
2512 element.constructors = _createDefaultConstructors(interfaceType); 2512 element.constructors = _createDefaultConstructors(interfaceType);
2513 for (FunctionTypeImpl functionType in _functionTypesToFix) { 2513 for (FunctionTypeImpl functionType in _functionTypesToFix) {
2514 functionType.typeArguments = typeArguments; 2514 functionType.typeArguments = typeArguments;
2515 } 2515 }
2516 _functionTypesToFix = null; 2516 _functionTypesToFix = null;
2517 _currentHolder.addType(element); 2517 _currentHolder.addType(element);
2518 className.staticElement = element; 2518 className.staticElement = element;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
2622 normalParameter.accept(this); 2622 normalParameter.accept(this);
2623 holder.validate(); 2623 holder.validate();
2624 return null; 2624 return null;
2625 } 2625 }
2626 2626
2627 @override 2627 @override
2628 Object visitEnumDeclaration(EnumDeclaration node) { 2628 Object visitEnumDeclaration(EnumDeclaration node) {
2629 SimpleIdentifier enumName = node.name; 2629 SimpleIdentifier enumName = node.name;
2630 ClassElementImpl enumElement = new ClassElementImpl.forNode(enumName); 2630 ClassElementImpl enumElement = new ClassElementImpl.forNode(enumName);
2631 enumElement.enum2 = true; 2631 enumElement.enum2 = true;
2632 InterfaceTypeImpl enumType = new InterfaceTypeImpl.con1(enumElement); 2632 InterfaceTypeImpl enumType = new InterfaceTypeImpl(enumElement);
2633 enumElement.type = enumType; 2633 enumElement.type = enumType;
2634 _currentHolder.addEnum(enumElement); 2634 _currentHolder.addEnum(enumElement);
2635 enumName.staticElement = enumElement; 2635 enumName.staticElement = enumElement;
2636 return super.visitEnumDeclaration(node); 2636 return super.visitEnumDeclaration(node);
2637 } 2637 }
2638 2638
2639 @override 2639 @override
2640 Object visitFieldDeclaration(FieldDeclaration node) { 2640 Object visitFieldDeclaration(FieldDeclaration node) {
2641 bool wasInField = _inFieldContext; 2641 bool wasInField = _inFieldContext;
2642 _inFieldContext = true; 2642 _inFieldContext = true;
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
2806 element.generator = true; 2806 element.generator = true;
2807 } 2807 }
2808 if (_inFunction) { 2808 if (_inFunction) {
2809 Block enclosingBlock = node.getAncestor((node) => node is Block); 2809 Block enclosingBlock = node.getAncestor((node) => node is Block);
2810 if (enclosingBlock != null) { 2810 if (enclosingBlock != null) {
2811 int functionEnd = node.offset + node.length; 2811 int functionEnd = node.offset + node.length;
2812 int blockEnd = enclosingBlock.offset + enclosingBlock.length; 2812 int blockEnd = enclosingBlock.offset + enclosingBlock.length;
2813 element.setVisibleRange(functionEnd, blockEnd - functionEnd - 1); 2813 element.setVisibleRange(functionEnd, blockEnd - functionEnd - 1);
2814 } 2814 }
2815 } 2815 }
2816 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); 2816 FunctionTypeImpl type = new FunctionTypeImpl(element);
2817 if (_functionTypesToFix != null) { 2817 if (_functionTypesToFix != null) {
2818 _functionTypesToFix.add(type); 2818 _functionTypesToFix.add(type);
2819 } 2819 }
2820 element.type = type; 2820 element.type = type;
2821 _currentHolder.addFunction(element); 2821 _currentHolder.addFunction(element);
2822 node.element = element; 2822 node.element = element;
2823 holder.validate(); 2823 holder.validate();
2824 return null; 2824 return null;
2825 } 2825 }
2826 2826
2827 @override 2827 @override
2828 Object visitFunctionTypeAlias(FunctionTypeAlias node) { 2828 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
2829 ElementHolder holder = new ElementHolder(); 2829 ElementHolder holder = new ElementHolder();
2830 _visitChildren(holder, node); 2830 _visitChildren(holder, node);
2831 SimpleIdentifier aliasName = node.name; 2831 SimpleIdentifier aliasName = node.name;
2832 List<ParameterElement> parameters = holder.parameters; 2832 List<ParameterElement> parameters = holder.parameters;
2833 List<TypeParameterElement> typeParameters = holder.typeParameters; 2833 List<TypeParameterElement> typeParameters = holder.typeParameters;
2834 FunctionTypeAliasElementImpl element = 2834 FunctionTypeAliasElementImpl element =
2835 new FunctionTypeAliasElementImpl.forNode(aliasName); 2835 new FunctionTypeAliasElementImpl.forNode(aliasName);
2836 element.parameters = parameters; 2836 element.parameters = parameters;
2837 element.typeParameters = typeParameters; 2837 element.typeParameters = typeParameters;
2838 FunctionTypeImpl type = new FunctionTypeImpl.con2(element); 2838 FunctionTypeImpl type = new FunctionTypeImpl.forTypedef(element);
2839 type.typeArguments = _createTypeParameterTypes(typeParameters); 2839 type.typeArguments = _createTypeParameterTypes(typeParameters);
2840 element.type = type; 2840 element.type = type;
2841 _currentHolder.addTypeAlias(element); 2841 _currentHolder.addTypeAlias(element);
2842 aliasName.staticElement = element; 2842 aliasName.staticElement = element;
2843 holder.validate(); 2843 holder.validate();
2844 return null; 2844 return null;
2845 } 2845 }
2846 2846
2847 @override 2847 @override
2848 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { 2848 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
3067 @override 3067 @override
3068 Object visitVariableDeclaration(VariableDeclaration node) { 3068 Object visitVariableDeclaration(VariableDeclaration node) {
3069 bool isConst = node.isConst; 3069 bool isConst = node.isConst;
3070 bool isFinal = node.isFinal; 3070 bool isFinal = node.isFinal;
3071 bool hasInitializer = node.initializer != null; 3071 bool hasInitializer = node.initializer != null;
3072 VariableElementImpl element; 3072 VariableElementImpl element;
3073 if (_inFieldContext) { 3073 if (_inFieldContext) {
3074 SimpleIdentifier fieldName = node.name; 3074 SimpleIdentifier fieldName = node.name;
3075 FieldElementImpl field; 3075 FieldElementImpl field;
3076 if ((isConst || isFinal) && hasInitializer) { 3076 if ((isConst || isFinal) && hasInitializer) {
3077 field = new ConstFieldElementImpl.con1(fieldName); 3077 field = new ConstFieldElementImpl.forNode(fieldName);
3078 } else { 3078 } else {
3079 field = new FieldElementImpl.forNode(fieldName); 3079 field = new FieldElementImpl.forNode(fieldName);
3080 } 3080 }
3081 element = field; 3081 element = field;
3082 _currentHolder.addField(field); 3082 _currentHolder.addField(field);
3083 fieldName.staticElement = field; 3083 fieldName.staticElement = field;
3084 } else if (_inFunction) { 3084 } else if (_inFunction) {
3085 SimpleIdentifier variableName = node.name; 3085 SimpleIdentifier variableName = node.name;
3086 LocalVariableElementImpl variable; 3086 LocalVariableElementImpl variable;
3087 if (isConst && hasInitializer) { 3087 if (isConst && hasInitializer) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
3174 * 3174 *
3175 * @param interfaceType the interface type for which to create a default const ructor 3175 * @param interfaceType the interface type for which to create a default const ructor
3176 * @return the [ConstructorElement]s array with the single default constructor element 3176 * @return the [ConstructorElement]s array with the single default constructor element
3177 */ 3177 */
3178 List<ConstructorElement> _createDefaultConstructors( 3178 List<ConstructorElement> _createDefaultConstructors(
3179 InterfaceTypeImpl interfaceType) { 3179 InterfaceTypeImpl interfaceType) {
3180 ConstructorElementImpl constructor = 3180 ConstructorElementImpl constructor =
3181 new ConstructorElementImpl.forNode(null); 3181 new ConstructorElementImpl.forNode(null);
3182 constructor.synthetic = true; 3182 constructor.synthetic = true;
3183 constructor.returnType = interfaceType; 3183 constructor.returnType = interfaceType;
3184 FunctionTypeImpl type = new FunctionTypeImpl.con1(constructor); 3184 FunctionTypeImpl type = new FunctionTypeImpl(constructor);
3185 _functionTypesToFix.add(type); 3185 _functionTypesToFix.add(type);
3186 constructor.type = type; 3186 constructor.type = type;
3187 return <ConstructorElement>[constructor]; 3187 return <ConstructorElement>[constructor];
3188 } 3188 }
3189 3189
3190 /** 3190 /**
3191 * Create the types associated with the given type parameters, setting the typ e of each type 3191 * Create the types associated with the given type parameters, setting the typ e of each type
3192 * parameter, and return an array of types corresponding to the given paramete rs. 3192 * parameter, and return an array of types corresponding to the given paramete rs.
3193 * 3193 *
3194 * @param typeParameters the type parameters for which types are to be created 3194 * @param typeParameters the type parameters for which types are to be created
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
3743 List<FieldElement> fields = new List<FieldElement>(); 3743 List<FieldElement> fields = new List<FieldElement>();
3744 List<PropertyAccessorElement> getters = new List<PropertyAccessorElement>(); 3744 List<PropertyAccessorElement> getters = new List<PropertyAccessorElement>();
3745 InterfaceType intType = _typeProvider.intType; 3745 InterfaceType intType = _typeProvider.intType;
3746 String indexFieldName = "index"; 3746 String indexFieldName = "index";
3747 FieldElementImpl indexField = new FieldElementImpl(indexFieldName, -1); 3747 FieldElementImpl indexField = new FieldElementImpl(indexFieldName, -1);
3748 indexField.final2 = true; 3748 indexField.final2 = true;
3749 indexField.synthetic = true; 3749 indexField.synthetic = true;
3750 indexField.type = intType; 3750 indexField.type = intType;
3751 fields.add(indexField); 3751 fields.add(indexField);
3752 getters.add(_createGetter(indexField)); 3752 getters.add(_createGetter(indexField));
3753 ConstFieldElementImpl valuesField = 3753 ConstFieldElementImpl valuesField = new ConstFieldElementImpl("values", -1);
3754 new ConstFieldElementImpl.con2("values", -1);
3755 valuesField.static = true; 3754 valuesField.static = true;
3756 valuesField.const3 = true; 3755 valuesField.const3 = true;
3757 valuesField.synthetic = true; 3756 valuesField.synthetic = true;
3758 valuesField.type = _typeProvider.listType.substitute4(<DartType>[enumType]); 3757 valuesField.type = _typeProvider.listType.substitute4(<DartType>[enumType]);
3759 fields.add(valuesField); 3758 fields.add(valuesField);
3760 getters.add(_createGetter(valuesField)); 3759 getters.add(_createGetter(valuesField));
3761 // 3760 //
3762 // Build the enum constants. 3761 // Build the enum constants.
3763 // 3762 //
3764 NodeList<EnumConstantDeclaration> constants = node.constants; 3763 NodeList<EnumConstantDeclaration> constants = node.constants;
3765 List<DartObjectImpl> constantValues = new List<DartObjectImpl>(); 3764 List<DartObjectImpl> constantValues = new List<DartObjectImpl>();
3766 int constantCount = constants.length; 3765 int constantCount = constants.length;
3767 for (int i = 0; i < constantCount; i++) { 3766 for (int i = 0; i < constantCount; i++) {
3768 SimpleIdentifier constantName = constants[i].name; 3767 SimpleIdentifier constantName = constants[i].name;
3769 FieldElementImpl constantField = 3768 FieldElementImpl constantField =
3770 new ConstFieldElementImpl.con1(constantName); 3769 new ConstFieldElementImpl.forNode(constantName);
3771 constantField.static = true; 3770 constantField.static = true;
3772 constantField.const3 = true; 3771 constantField.const3 = true;
3773 constantField.type = enumType; 3772 constantField.type = enumType;
3774 // 3773 //
3775 // Create a value for the constant. 3774 // Create a value for the constant.
3776 // 3775 //
3777 HashMap<String, DartObjectImpl> fieldMap = 3776 HashMap<String, DartObjectImpl> fieldMap =
3778 new HashMap<String, DartObjectImpl>(); 3777 new HashMap<String, DartObjectImpl>();
3779 fieldMap[indexFieldName] = new DartObjectImpl(intType, new IntState(i)); 3778 fieldMap[indexFieldName] = new DartObjectImpl(intType, new IntState(i));
3780 DartObjectImpl value = 3779 DartObjectImpl value =
3781 new DartObjectImpl(enumType, new GenericState(fieldMap)); 3780 new DartObjectImpl(enumType, new GenericState(fieldMap));
3782 constantValues.add(value); 3781 constantValues.add(value);
3783 constantField.evaluationResult = new EvaluationResultImpl.con1(value); 3782 constantField.evaluationResult = new EvaluationResultImpl(value);
3784 fields.add(constantField); 3783 fields.add(constantField);
3785 getters.add(_createGetter(constantField)); 3784 getters.add(_createGetter(constantField));
3786 constantName.staticElement = constantField; 3785 constantName.staticElement = constantField;
3787 } 3786 }
3788 // 3787 //
3789 // Build the value of the 'values' field. 3788 // Build the value of the 'values' field.
3790 // 3789 //
3791 valuesField.evaluationResult = new EvaluationResultImpl.con1( 3790 valuesField.evaluationResult = new EvaluationResultImpl(
3792 new DartObjectImpl(valuesField.type, new ListState(constantValues))); 3791 new DartObjectImpl(valuesField.type, new ListState(constantValues)));
3793 // 3792 //
3794 // Finish building the enum. 3793 // Finish building the enum.
3795 // 3794 //
3796 enumElement.fields = fields; 3795 enumElement.fields = fields;
3797 enumElement.accessors = getters; 3796 enumElement.accessors = getters;
3798 // Client code isn't allowed to invoke the constructor, so we do not model 3797 // Client code isn't allowed to invoke the constructor, so we do not model
3799 // it. 3798 // it.
3800 return super.visitEnumDeclaration(node); 3799 return super.visitEnumDeclaration(node);
3801 } 3800 }
3802 3801
3803 /** 3802 /**
3804 * Create a getter that corresponds to the given field. 3803 * Create a getter that corresponds to the given field.
3805 * 3804 *
3806 * @param field the field for which a getter is to be created 3805 * @param field the field for which a getter is to be created
3807 * @return the getter that was created 3806 * @return the getter that was created
3808 */ 3807 */
3809 PropertyAccessorElement _createGetter(FieldElementImpl field) { 3808 PropertyAccessorElement _createGetter(FieldElementImpl field) {
3810 PropertyAccessorElementImpl getter = 3809 PropertyAccessorElementImpl getter =
3811 new PropertyAccessorElementImpl.forVariable(field); 3810 new PropertyAccessorElementImpl.forVariable(field);
3812 getter.getter = true; 3811 getter.getter = true;
3813 getter.returnType = field.type; 3812 getter.returnType = field.type;
3814 getter.type = new FunctionTypeImpl.con1(getter); 3813 getter.type = new FunctionTypeImpl(getter);
3815 field.getter = getter; 3814 field.getter = getter;
3816 return getter; 3815 return getter;
3817 } 3816 }
3818 } 3817 }
3819 3818
3820 /** 3819 /**
3821 * Instances of the class `ExitDetector` determine whether the visited AST node is guaranteed 3820 * Instances of the class `ExitDetector` determine whether the visited AST node is guaranteed
3822 * to terminate by executing a `return` statement, `throw` expression, `rethrow` 3821 * to terminate by executing a `return` statement, `throw` expression, `rethrow`
3823 * expression, or simple infinite loop such as `while(true)`. 3822 * expression, or simple infinite loop such as `while(true)`.
3824 */ 3823 */
(...skipping 1380 matching lines...) Expand 10 before | Expand all | Expand 10 after
5205 implicitParameter.const3 = explicitParameter.isConst; 5204 implicitParameter.const3 = explicitParameter.isConst;
5206 implicitParameter.final2 = explicitParameter.isFinal; 5205 implicitParameter.final2 = explicitParameter.isFinal;
5207 implicitParameter.parameterKind = explicitParameter.parameterKind; 5206 implicitParameter.parameterKind = explicitParameter.parameterKind;
5208 implicitParameter.synthetic = true; 5207 implicitParameter.synthetic = true;
5209 implicitParameter.type = 5208 implicitParameter.type =
5210 explicitParameter.type.substitute2(argumentTypes, parameterTypes); 5209 explicitParameter.type.substitute2(argumentTypes, parameterTypes);
5211 implicitParameters[i] = implicitParameter; 5210 implicitParameters[i] = implicitParameter;
5212 } 5211 }
5213 implicitConstructor.parameters = implicitParameters; 5212 implicitConstructor.parameters = implicitParameters;
5214 } 5213 }
5215 FunctionTypeImpl type = new FunctionTypeImpl.con1(implicitConstructor); 5214 FunctionTypeImpl type = new FunctionTypeImpl(implicitConstructor);
5216 type.typeArguments = classType.typeArguments; 5215 type.typeArguments = classType.typeArguments;
5217 implicitConstructor.type = type; 5216 implicitConstructor.type = type;
5218 return implicitConstructor; 5217 return implicitConstructor;
5219 } 5218 }
5220 5219
5221 /** 5220 /**
5222 * Find all the constructors that should be forwarded from the given 5221 * Find all the constructors that should be forwarded from the given
5223 * [superType], to the class or mixin application [classElement], 5222 * [superType], to the class or mixin application [classElement],
5224 * and pass information about them to [callback]. 5223 * and pass information about them to [callback].
5225 * 5224 *
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
5288 if (superElement != null) { 5287 if (superElement != null) {
5289 _callback(classElement, superElement, () { 5288 _callback(classElement, superElement, () {
5290 bool constructorFound = false; 5289 bool constructorFound = false;
5291 void callback(ConstructorElement explicitConstructor, 5290 void callback(ConstructorElement explicitConstructor,
5292 List<DartType> parameterTypes, List<DartType> argumentTypes) { 5291 List<DartType> parameterTypes, List<DartType> argumentTypes) {
5293 constructorFound = true; 5292 constructorFound = true;
5294 } 5293 }
5295 if (_findForwardedConstructors(classElement, superType, callback) && 5294 if (_findForwardedConstructors(classElement, superType, callback) &&
5296 !constructorFound) { 5295 !constructorFound) {
5297 SourceRange withRange = classElement.withClauseRange; 5296 SourceRange withRange = classElement.withClauseRange;
5298 errorListener.onError(new AnalysisError.con2(classElement.source, 5297 errorListener.onError(new AnalysisError(classElement.source,
5299 withRange.offset, withRange.length, 5298 withRange.offset, withRange.length,
5300 CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS, 5299 CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS,
5301 [superElement.name])); 5300 [superElement.name]));
5302 classElement.mixinErrorsReported = true; 5301 classElement.mixinErrorsReported = true;
5303 } 5302 }
5304 }); 5303 });
5305 } 5304 }
5306 } 5305 }
5307 } 5306 }
5308 5307
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
5963 superclassElt = supertype.element; 5962 superclassElt = supertype.element;
5964 } else { 5963 } else {
5965 // classElt is Object 5964 // classElt is Object
5966 _classLookup[classElt] = resultMap; 5965 _classLookup[classElt] = resultMap;
5967 return resultMap; 5966 return resultMap;
5968 } 5967 }
5969 if (superclassElt != null) { 5968 if (superclassElt != null) {
5970 if (!visitedClasses.contains(superclassElt)) { 5969 if (!visitedClasses.contains(superclassElt)) {
5971 visitedClasses.add(superclassElt); 5970 visitedClasses.add(superclassElt);
5972 try { 5971 try {
5973 resultMap = new MemberMap.con2( 5972 resultMap = new MemberMap.from(
5974 _computeClassChainLookupMap(superclassElt, visitedClasses)); 5973 _computeClassChainLookupMap(superclassElt, visitedClasses));
5975 // 5974 //
5976 // Substitute the super types down the hierarchy. 5975 // Substitute the super types down the hierarchy.
5977 // 5976 //
5978 _substituteTypeParametersDownHierarchy(supertype, resultMap); 5977 _substituteTypeParametersDownHierarchy(supertype, resultMap);
5979 // 5978 //
5980 // Include the members from the superclass in the resultMap. 5979 // Include the members from the superclass in the resultMap.
5981 // 5980 //
5982 _recordMapWithClassMembers(resultMap, supertype, false); 5981 _recordMapWithClassMembers(resultMap, supertype, false);
5983 } finally { 5982 } finally {
(...skipping 12 matching lines...) Expand all
5996 // multiple mixins, visit them in the order listed so that methods in later 5995 // multiple mixins, visit them in the order listed so that methods in later
5997 // mixins will overwrite identically-named methods in earlier mixins. 5996 // mixins will overwrite identically-named methods in earlier mixins.
5998 // 5997 //
5999 List<InterfaceType> mixins = classElt.mixins; 5998 List<InterfaceType> mixins = classElt.mixins;
6000 for (InterfaceType mixin in mixins) { 5999 for (InterfaceType mixin in mixins) {
6001 ClassElement mixinElement = mixin.element; 6000 ClassElement mixinElement = mixin.element;
6002 if (mixinElement != null) { 6001 if (mixinElement != null) {
6003 if (!visitedClasses.contains(mixinElement)) { 6002 if (!visitedClasses.contains(mixinElement)) {
6004 visitedClasses.add(mixinElement); 6003 visitedClasses.add(mixinElement);
6005 try { 6004 try {
6006 MemberMap map = new MemberMap.con2( 6005 MemberMap map = new MemberMap.from(
6007 _computeClassChainLookupMap(mixinElement, visitedClasses)); 6006 _computeClassChainLookupMap(mixinElement, visitedClasses));
6008 // 6007 //
6009 // Substitute the super types down the hierarchy. 6008 // Substitute the super types down the hierarchy.
6010 // 6009 //
6011 _substituteTypeParametersDownHierarchy(mixin, map); 6010 _substituteTypeParametersDownHierarchy(mixin, map);
6012 // 6011 //
6013 // Include the members from the superclass in the resultMap. 6012 // Include the members from the superclass in the resultMap.
6014 // 6013 //
6015 _recordMapWithClassMembers(map, mixin, false); 6014 _recordMapWithClassMembers(map, mixin, false);
6016 // 6015 //
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
6164 // 6163 //
6165 if (superclassElement != null) { 6164 if (superclassElement != null) {
6166 if (!visitedInterfaces.contains(superclassElement)) { 6165 if (!visitedInterfaces.contains(superclassElement)) {
6167 try { 6166 try {
6168 visitedInterfaces.add(superclassElement); 6167 visitedInterfaces.add(superclassElement);
6169 // 6168 //
6170 // Recursively compute the map for the super type. 6169 // Recursively compute the map for the super type.
6171 // 6170 //
6172 MemberMap map = 6171 MemberMap map =
6173 _computeInterfaceLookupMap(superclassElement, visitedInterfaces); 6172 _computeInterfaceLookupMap(superclassElement, visitedInterfaces);
6174 map = new MemberMap.con2(map); 6173 map = new MemberMap.from(map);
6175 // 6174 //
6176 // Substitute the super type down the hierarchy. 6175 // Substitute the super type down the hierarchy.
6177 // 6176 //
6178 _substituteTypeParametersDownHierarchy(supertype, map); 6177 _substituteTypeParametersDownHierarchy(supertype, map);
6179 // 6178 //
6180 // Add any members from the super type into the map as well. 6179 // Add any members from the super type into the map as well.
6181 // 6180 //
6182 _recordMapWithClassMembers(map, supertype, true); 6181 _recordMapWithClassMembers(map, supertype, true);
6183 lookupMaps.add(map); 6182 lookupMaps.add(map);
6184 } finally { 6183 } finally {
(...skipping 11 matching lines...) Expand all
6196 ClassElement mixinElement = mixinType.element; 6195 ClassElement mixinElement = mixinType.element;
6197 if (mixinElement != null) { 6196 if (mixinElement != null) {
6198 if (!visitedInterfaces.contains(mixinElement)) { 6197 if (!visitedInterfaces.contains(mixinElement)) {
6199 try { 6198 try {
6200 visitedInterfaces.add(mixinElement); 6199 visitedInterfaces.add(mixinElement);
6201 // 6200 //
6202 // Recursively compute the map for the mixin. 6201 // Recursively compute the map for the mixin.
6203 // 6202 //
6204 MemberMap map = 6203 MemberMap map =
6205 _computeInterfaceLookupMap(mixinElement, visitedInterfaces); 6204 _computeInterfaceLookupMap(mixinElement, visitedInterfaces);
6206 map = new MemberMap.con2(map); 6205 map = new MemberMap.from(map);
6207 // 6206 //
6208 // Substitute the mixin type down the hierarchy. 6207 // Substitute the mixin type down the hierarchy.
6209 // 6208 //
6210 _substituteTypeParametersDownHierarchy(mixinType, map); 6209 _substituteTypeParametersDownHierarchy(mixinType, map);
6211 // 6210 //
6212 // Add any members from the mixin type into the map as well. 6211 // Add any members from the mixin type into the map as well.
6213 // 6212 //
6214 _recordMapWithClassMembers(map, mixinType, true); 6213 _recordMapWithClassMembers(map, mixinType, true);
6215 lookupMaps.add(map); 6214 lookupMaps.add(map);
6216 } finally { 6215 } finally {
(...skipping 11 matching lines...) Expand all
6228 ClassElement interfaceElement = interfaceType.element; 6227 ClassElement interfaceElement = interfaceType.element;
6229 if (interfaceElement != null) { 6228 if (interfaceElement != null) {
6230 if (!visitedInterfaces.contains(interfaceElement)) { 6229 if (!visitedInterfaces.contains(interfaceElement)) {
6231 try { 6230 try {
6232 visitedInterfaces.add(interfaceElement); 6231 visitedInterfaces.add(interfaceElement);
6233 // 6232 //
6234 // Recursively compute the map for the interfaces. 6233 // Recursively compute the map for the interfaces.
6235 // 6234 //
6236 MemberMap map = 6235 MemberMap map =
6237 _computeInterfaceLookupMap(interfaceElement, visitedInterfaces); 6236 _computeInterfaceLookupMap(interfaceElement, visitedInterfaces);
6238 map = new MemberMap.con2(map); 6237 map = new MemberMap.from(map);
6239 // 6238 //
6240 // Substitute the supertypes down the hierarchy 6239 // Substitute the supertypes down the hierarchy
6241 // 6240 //
6242 _substituteTypeParametersDownHierarchy(interfaceType, map); 6241 _substituteTypeParametersDownHierarchy(interfaceType, map);
6243 // 6242 //
6244 // And add any members from the interface into the map as well. 6243 // And add any members from the interface into the map as well.
6245 // 6244 //
6246 _recordMapWithClassMembers(map, interfaceType, true); 6245 _recordMapWithClassMembers(map, interfaceType, true);
6247 lookupMaps.add(map); 6246 lookupMaps.add(map);
6248 } finally { 6247 } finally {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
6329 * @param errorCode the error code to be associated with this error 6328 * @param errorCode the error code to be associated with this error
6330 * @param arguments the arguments used to build the error message 6329 * @param arguments the arguments used to build the error message
6331 */ 6330 */
6332 void _reportError(ClassElement classElt, int offset, int length, 6331 void _reportError(ClassElement classElt, int offset, int length,
6333 ErrorCode errorCode, List<Object> arguments) { 6332 ErrorCode errorCode, List<Object> arguments) {
6334 HashSet<AnalysisError> errorSet = _errorsInClassElement[classElt]; 6333 HashSet<AnalysisError> errorSet = _errorsInClassElement[classElt];
6335 if (errorSet == null) { 6334 if (errorSet == null) {
6336 errorSet = new HashSet<AnalysisError>(); 6335 errorSet = new HashSet<AnalysisError>();
6337 _errorsInClassElement[classElt] = errorSet; 6336 _errorsInClassElement[classElt] = errorSet;
6338 } 6337 }
6339 errorSet.add(new AnalysisError.con2( 6338 errorSet.add(new AnalysisError(
6340 classElt.source, offset, length, errorCode, arguments)); 6339 classElt.source, offset, length, errorCode, arguments));
6341 } 6340 }
6342 6341
6343 /** 6342 /**
6344 * Given the set of methods defined by classes above [classElt] in the class h ierarchy, 6343 * Given the set of methods defined by classes above [classElt] in the class h ierarchy,
6345 * apply the appropriate inheritance rules to determine those methods inherite d by or overridden 6344 * apply the appropriate inheritance rules to determine those methods inherite d by or overridden
6346 * by [classElt]. Also report static warnings 6345 * by [classElt]. Also report static warnings
6347 * [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE] and 6346 * [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE] and
6348 * [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD] if ap propriate. 6347 * [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD] if ap propriate.
6349 * 6348 *
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
6675 } 6674 }
6676 for (int m = 0; m < namedParameters.length; m++, i++) { 6675 for (int m = 0; m < namedParameters.length; m++, i++) {
6677 ParameterElementImpl parameter = 6676 ParameterElementImpl parameter =
6678 new ParameterElementImpl(namedParameters[m], 0); 6677 new ParameterElementImpl(namedParameters[m], 0);
6679 parameter.type = dynamicType; 6678 parameter.type = dynamicType;
6680 parameter.parameterKind = ParameterKind.NAMED; 6679 parameter.parameterKind = ParameterKind.NAMED;
6681 parameters[i] = parameter; 6680 parameters[i] = parameter;
6682 } 6681 }
6683 executable.returnType = dynamicType; 6682 executable.returnType = dynamicType;
6684 executable.parameters = parameters; 6683 executable.parameters = parameters;
6685 FunctionTypeImpl methodType = new FunctionTypeImpl.con1(executable); 6684 FunctionTypeImpl methodType = new FunctionTypeImpl(executable);
6686 executable.type = methodType; 6685 executable.type = methodType;
6687 return executable; 6686 return executable;
6688 } 6687 }
6689 6688
6690 /** 6689 /**
6691 * Given some [ExecutableElement], return the list of named parameters. 6690 * Given some [ExecutableElement], return the list of named parameters.
6692 */ 6691 */
6693 static List<String> _getNamedParameterNames( 6692 static List<String> _getNamedParameterNames(
6694 ExecutableElement executableElement) { 6693 ExecutableElement executableElement) {
6695 List<String> namedParameterNames = new List<String>(); 6694 List<String> namedParameterNames = new List<String>();
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
7088 if (directive is ImportDirective && 7087 if (directive is ImportDirective &&
7089 uriContent.startsWith(_DART_EXT_SCHEME)) { 7088 uriContent.startsWith(_DART_EXT_SCHEME)) {
7090 _libraryElement.hasExtUri = true; 7089 _libraryElement.hasExtUri = true;
7091 return null; 7090 return null;
7092 } 7091 }
7093 try { 7092 try {
7094 parseUriWithException(uriContent); 7093 parseUriWithException(uriContent);
7095 Source source = 7094 Source source =
7096 _analysisContext.sourceFactory.resolveUri(librarySource, uriContent); 7095 _analysisContext.sourceFactory.resolveUri(librarySource, uriContent);
7097 if (!_analysisContext.exists(source)) { 7096 if (!_analysisContext.exists(source)) {
7098 _errorListener.onError(new AnalysisError.con2(librarySource, 7097 _errorListener.onError(new AnalysisError(librarySource,
7099 uriLiteral.offset, uriLiteral.length, 7098 uriLiteral.offset, uriLiteral.length,
7100 CompileTimeErrorCode.URI_DOES_NOT_EXIST, [uriContent])); 7099 CompileTimeErrorCode.URI_DOES_NOT_EXIST, [uriContent]));
7101 } 7100 }
7102 return source; 7101 return source;
7103 } on URISyntaxException { 7102 } on URISyntaxException {
7104 _errorListener.onError(new AnalysisError.con2(librarySource, 7103 _errorListener.onError(new AnalysisError(librarySource, uriLiteral.offset,
7105 uriLiteral.offset, uriLiteral.length, 7104 uriLiteral.length, CompileTimeErrorCode.INVALID_URI, [uriContent]));
7106 CompileTimeErrorCode.INVALID_URI, [uriContent]));
7107 } 7105 }
7108 return null; 7106 return null;
7109 } 7107 }
7110 7108
7111 /** 7109 /**
7112 * Returns the URI value of the given directive. 7110 * Returns the URI value of the given directive.
7113 */ 7111 */
7114 String getUri(UriBasedDirective directive) => _directiveUris[directive]; 7112 String getUri(UriBasedDirective directive) => _directiveUris[directive];
7115 7113
7116 /** 7114 /**
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
7195 part.uriOffset = partUri.offset; 7193 part.uriOffset = partUri.offset;
7196 part.uriEnd = partUri.end; 7194 part.uriEnd = partUri.end;
7197 part.uri = partDirective.uriContent; 7195 part.uri = partDirective.uriContent;
7198 // 7196 //
7199 // Validate that the part contains a part-of directive with the same 7197 // Validate that the part contains a part-of directive with the same
7200 // name as the library. 7198 // name as the library.
7201 // 7199 //
7202 String partLibraryName = 7200 String partLibraryName =
7203 _getPartLibraryName(partSource, partUnit, directivesToResolve); 7201 _getPartLibraryName(partSource, partUnit, directivesToResolve);
7204 if (partLibraryName == null) { 7202 if (partLibraryName == null) {
7205 _errorListener.onError(new AnalysisError.con2(librarySource, 7203 _errorListener.onError(new AnalysisError(librarySource,
7206 partUri.offset, partUri.length, 7204 partUri.offset, partUri.length,
7207 CompileTimeErrorCode.PART_OF_NON_PART, [partUri.toSource()])); 7205 CompileTimeErrorCode.PART_OF_NON_PART, [partUri.toSource()]));
7208 } else if (libraryNameNode == null) { 7206 } else if (libraryNameNode == null) {
7209 // TODO(brianwilkerson) Collect the names declared by the part. 7207 // TODO(brianwilkerson) Collect the names declared by the part.
7210 // If they are all the same then we can use that name as the 7208 // If they are all the same then we can use that name as the
7211 // inferred name of the library and present it in a quick-fix. 7209 // inferred name of the library and present it in a quick-fix.
7212 // partLibraryNames.add(partLibraryName); 7210 // partLibraryNames.add(partLibraryName);
7213 } else if (libraryNameNode.name != partLibraryName) { 7211 } else if (libraryNameNode.name != partLibraryName) {
7214 _errorListener.onError(new AnalysisError.con2(librarySource, 7212 _errorListener.onError(new AnalysisError(librarySource,
7215 partUri.offset, partUri.length, 7213 partUri.offset, partUri.length,
7216 StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, [ 7214 StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, [
7217 libraryNameNode.name, 7215 libraryNameNode.name,
7218 partLibraryName 7216 partLibraryName
7219 ])); 7217 ]));
7220 } 7218 }
7221 if (entryPoint == null) { 7219 if (entryPoint == null) {
7222 entryPoint = _findEntryPoint(part); 7220 entryPoint = _findEntryPoint(part);
7223 } 7221 }
7224 directive.element = part; 7222 directive.element = part;
7225 sourcedCompilationUnits.add(part); 7223 sourcedCompilationUnits.add(part);
7226 } 7224 }
7227 } 7225 }
7228 } 7226 }
7229 if (hasPartDirective && libraryNameNode == null) { 7227 if (hasPartDirective && libraryNameNode == null) {
7230 _errorListener.onError(new AnalysisError.con1(librarySource, 7228 _errorListener.onError(new AnalysisError(librarySource, 0, 0,
7231 ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART)); 7229 ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART));
7232 } 7230 }
7233 // 7231 //
7234 // Create and populate the library element. 7232 // Create and populate the library element.
7235 // 7233 //
7236 LibraryElementImpl libraryElement = new LibraryElementImpl.forNode( 7234 LibraryElementImpl libraryElement = new LibraryElementImpl.forNode(
7237 _analysisContext.getContextFor(librarySource), libraryNameNode); 7235 _analysisContext.getContextFor(librarySource), libraryNameNode);
7238 libraryElement.definingCompilationUnit = definingCompilationUnitElement; 7236 libraryElement.definingCompilationUnit = definingCompilationUnitElement;
7239 if (entryPoint != null) { 7237 if (entryPoint != null) {
7240 libraryElement.entryPoint = entryPoint; 7238 libraryElement.entryPoint = entryPoint;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
7298 part.uriOffset = partUri.offset; 7296 part.uriOffset = partUri.offset;
7299 part.uriEnd = partUri.end; 7297 part.uriEnd = partUri.end;
7300 part.uri = partDirective.uriContent; 7298 part.uri = partDirective.uriContent;
7301 // 7299 //
7302 // Validate that the part contains a part-of directive with the same 7300 // Validate that the part contains a part-of directive with the same
7303 // name as the library. 7301 // name as the library.
7304 // 7302 //
7305 String partLibraryName = 7303 String partLibraryName =
7306 _getPartLibraryName(partSource, partUnit, directivesToResolve); 7304 _getPartLibraryName(partSource, partUnit, directivesToResolve);
7307 if (partLibraryName == null) { 7305 if (partLibraryName == null) {
7308 _errorListener.onError(new AnalysisError.con2(librarySource, 7306 _errorListener.onError(new AnalysisError(librarySource,
7309 partUri.offset, partUri.length, 7307 partUri.offset, partUri.length,
7310 CompileTimeErrorCode.PART_OF_NON_PART, [partUri.toSource()])); 7308 CompileTimeErrorCode.PART_OF_NON_PART, [partUri.toSource()]));
7311 } else if (libraryNameNode == null) { 7309 } else if (libraryNameNode == null) {
7312 // TODO(brianwilkerson) Collect the names declared by the part. 7310 // TODO(brianwilkerson) Collect the names declared by the part.
7313 // If they are all the same then we can use that name as the 7311 // If they are all the same then we can use that name as the
7314 // inferred name of the library and present it in a quick-fix. 7312 // inferred name of the library and present it in a quick-fix.
7315 // partLibraryNames.add(partLibraryName); 7313 // partLibraryNames.add(partLibraryName);
7316 } else if (libraryNameNode.name != partLibraryName) { 7314 } else if (libraryNameNode.name != partLibraryName) {
7317 _errorListener.onError(new AnalysisError.con2(librarySource, 7315 _errorListener.onError(new AnalysisError(librarySource,
7318 partUri.offset, partUri.length, 7316 partUri.offset, partUri.length,
7319 StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, [ 7317 StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, [
7320 libraryNameNode.name, 7318 libraryNameNode.name,
7321 partLibraryName 7319 partLibraryName
7322 ])); 7320 ]));
7323 } 7321 }
7324 if (entryPoint == null) { 7322 if (entryPoint == null) {
7325 entryPoint = _findEntryPoint(part); 7323 entryPoint = _findEntryPoint(part);
7326 } 7324 }
7327 directive.element = part; 7325 directive.element = part;
7328 sourcedCompilationUnits.add(part); 7326 sourcedCompilationUnits.add(part);
7329 } 7327 }
7330 } 7328 }
7331 } 7329 }
7332 } 7330 }
7333 if (hasPartDirective && libraryNameNode == null) { 7331 if (hasPartDirective && libraryNameNode == null) {
7334 _errorListener.onError(new AnalysisError.con1(librarySource, 7332 _errorListener.onError(new AnalysisError(librarySource, 0, 0,
7335 ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART)); 7333 ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART));
7336 } 7334 }
7337 // 7335 //
7338 // Create and populate the library element. 7336 // Create and populate the library element.
7339 // 7337 //
7340 LibraryElementImpl libraryElement = new LibraryElementImpl.forNode( 7338 LibraryElementImpl libraryElement = new LibraryElementImpl.forNode(
7341 _analysisContext.getContextFor(librarySource), libraryNameNode); 7339 _analysisContext.getContextFor(librarySource), libraryNameNode);
7342 libraryElement.definingCompilationUnit = definingCompilationUnitElement; 7340 libraryElement.definingCompilationUnit = definingCompilationUnitElement;
7343 if (entryPoint != null) { 7341 if (entryPoint != null) {
7344 libraryElement.entryPoint = entryPoint; 7342 libraryElement.entryPoint = entryPoint;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
7517 } 7515 }
7518 if (foundElement is MultiplyDefinedElementImpl) { 7516 if (foundElement is MultiplyDefinedElementImpl) {
7519 String foundEltName = foundElement.displayName; 7517 String foundEltName = foundElement.displayName;
7520 List<Element> conflictingMembers = foundElement.conflictingElements; 7518 List<Element> conflictingMembers = foundElement.conflictingElements;
7521 int count = conflictingMembers.length; 7519 int count = conflictingMembers.length;
7522 List<String> libraryNames = new List<String>(count); 7520 List<String> libraryNames = new List<String>(count);
7523 for (int i = 0; i < count; i++) { 7521 for (int i = 0; i < count; i++) {
7524 libraryNames[i] = _getLibraryName(conflictingMembers[i]); 7522 libraryNames[i] = _getLibraryName(conflictingMembers[i]);
7525 } 7523 }
7526 libraryNames.sort(); 7524 libraryNames.sort();
7527 errorListener.onError(new AnalysisError.con2(getSource(identifier), 7525 errorListener.onError(new AnalysisError(getSource(identifier),
7528 identifier.offset, identifier.length, 7526 identifier.offset, identifier.length,
7529 StaticWarningCode.AMBIGUOUS_IMPORT, [ 7527 StaticWarningCode.AMBIGUOUS_IMPORT, [
7530 foundEltName, 7528 foundEltName,
7531 StringUtilities.printListOfQuotedNames(libraryNames) 7529 StringUtilities.printListOfQuotedNames(libraryNames)
7532 ])); 7530 ]));
7533 return foundElement; 7531 return foundElement;
7534 } 7532 }
7535 if (foundElement != null) { 7533 if (foundElement != null) {
7536 defineNameWithoutChecking(name, foundElement); 7534 defineNameWithoutChecking(name, foundElement);
7537 } 7535 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
7619 for (Element member in conflictingElements) { 7617 for (Element member in conflictingElements) {
7620 if (member.library.isInSdk) { 7618 if (member.library.isInSdk) {
7621 sdkElement = member; 7619 sdkElement = member;
7622 } else { 7620 } else {
7623 nonSdkElements.add(member); 7621 nonSdkElements.add(member);
7624 } 7622 }
7625 } 7623 }
7626 if (sdkElement != null && nonSdkElements.length > 0) { 7624 if (sdkElement != null && nonSdkElements.length > 0) {
7627 String sdkLibName = _getLibraryName(sdkElement); 7625 String sdkLibName = _getLibraryName(sdkElement);
7628 String otherLibName = _getLibraryName(nonSdkElements[0]); 7626 String otherLibName = _getLibraryName(nonSdkElements[0]);
7629 errorListener.onError(new AnalysisError.con2(getSource(identifier), 7627 errorListener.onError(new AnalysisError(getSource(identifier),
7630 identifier.offset, identifier.length, 7628 identifier.offset, identifier.length,
7631 StaticWarningCode.CONFLICTING_DART_IMPORT, [ 7629 StaticWarningCode.CONFLICTING_DART_IMPORT, [
7632 name, 7630 name,
7633 sdkLibName, 7631 sdkLibName,
7634 otherLibName 7632 otherLibName
7635 ])); 7633 ]));
7636 } 7634 }
7637 if (nonSdkElements.length == conflictingElements.length) { 7635 if (nonSdkElements.length == conflictingElements.length) {
7638 // None of the members were removed 7636 // None of the members were removed
7639 return foundElement; 7637 return foundElement;
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
8082 importElement.prefix = prefix; 8080 importElement.prefix = prefix;
8083 prefixNode.staticElement = prefix; 8081 prefixNode.staticElement = prefix;
8084 } 8082 }
8085 directive.element = importElement; 8083 directive.element = importElement;
8086 imports.add(importElement); 8084 imports.add(importElement);
8087 if (analysisContext.computeKindOf(importedSource) != 8085 if (analysisContext.computeKindOf(importedSource) !=
8088 SourceKind.LIBRARY) { 8086 SourceKind.LIBRARY) {
8089 ErrorCode errorCode = (importElement.isDeferred 8087 ErrorCode errorCode = (importElement.isDeferred
8090 ? StaticWarningCode.IMPORT_OF_NON_LIBRARY 8088 ? StaticWarningCode.IMPORT_OF_NON_LIBRARY
8091 : CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY); 8089 : CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY);
8092 _errorListener.onError(new AnalysisError.con2( 8090 _errorListener.onError(new AnalysisError(library.librarySource,
8093 library.librarySource, uriLiteral.offset, uriLiteral.length, 8091 uriLiteral.offset, uriLiteral.length, errorCode,
8094 errorCode, [uriLiteral.toSource()])); 8092 [uriLiteral.toSource()]));
8095 } 8093 }
8096 } 8094 }
8097 } 8095 }
8098 } else if (directive is ExportDirective) { 8096 } else if (directive is ExportDirective) {
8099 ExportDirective exportDirective = directive; 8097 ExportDirective exportDirective = directive;
8100 Source exportedSource = exportDirective.source; 8098 Source exportedSource = exportDirective.source;
8101 if (exportedSource != null) { 8099 if (exportedSource != null) {
8102 // The exported source will be null if the URI in the export 8100 // The exported source will be null if the URI in the export
8103 // directive was invalid. 8101 // directive was invalid.
8104 Library exportedLibrary = _libraryMap[exportedSource]; 8102 Library exportedLibrary = _libraryMap[exportedSource];
8105 if (exportedLibrary != null) { 8103 if (exportedLibrary != null) {
8106 ExportElementImpl exportElement = 8104 ExportElementImpl exportElement =
8107 new ExportElementImpl(directive.offset); 8105 new ExportElementImpl(directive.offset);
8108 StringLiteral uriLiteral = exportDirective.uri; 8106 StringLiteral uriLiteral = exportDirective.uri;
8109 exportElement.uriOffset = uriLiteral.offset; 8107 exportElement.uriOffset = uriLiteral.offset;
8110 exportElement.uriEnd = uriLiteral.end; 8108 exportElement.uriEnd = uriLiteral.end;
8111 exportElement.uri = exportDirective.uriContent; 8109 exportElement.uri = exportDirective.uriContent;
8112 exportElement.combinators = _buildCombinators(exportDirective); 8110 exportElement.combinators = _buildCombinators(exportDirective);
8113 LibraryElement exportedLibraryElement = 8111 LibraryElement exportedLibraryElement =
8114 exportedLibrary.libraryElement; 8112 exportedLibrary.libraryElement;
8115 if (exportedLibraryElement != null) { 8113 if (exportedLibraryElement != null) {
8116 exportElement.exportedLibrary = exportedLibraryElement; 8114 exportElement.exportedLibrary = exportedLibraryElement;
8117 } 8115 }
8118 directive.element = exportElement; 8116 directive.element = exportElement;
8119 exports.add(exportElement); 8117 exports.add(exportElement);
8120 if (analysisContext.computeKindOf(exportedSource) != 8118 if (analysisContext.computeKindOf(exportedSource) !=
8121 SourceKind.LIBRARY) { 8119 SourceKind.LIBRARY) {
8122 _errorListener.onError(new AnalysisError.con2( 8120 _errorListener.onError(new AnalysisError(library.librarySource,
8123 library.librarySource, uriLiteral.offset, uriLiteral.length, 8121 uriLiteral.offset, uriLiteral.length,
8124 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY, 8122 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY,
8125 [uriLiteral.toSource()])); 8123 [uriLiteral.toSource()]));
8126 } 8124 }
8127 } 8125 }
8128 } 8126 }
8129 } 8127 }
8130 } 8128 }
8131 Source librarySource = library.librarySource; 8129 Source librarySource = library.librarySource;
8132 if (!library.explicitlyImportsCore && 8130 if (!library.explicitlyImportsCore &&
8133 _coreLibrarySource != librarySource) { 8131 _coreLibrarySource != librarySource) {
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
8770 importElement.prefix = prefix; 8768 importElement.prefix = prefix;
8771 prefixNode.staticElement = prefix; 8769 prefixNode.staticElement = prefix;
8772 } 8770 }
8773 directive.element = importElement; 8771 directive.element = importElement;
8774 imports.add(importElement); 8772 imports.add(importElement);
8775 if (analysisContext.computeKindOf(importedSource) != 8773 if (analysisContext.computeKindOf(importedSource) !=
8776 SourceKind.LIBRARY) { 8774 SourceKind.LIBRARY) {
8777 ErrorCode errorCode = (importElement.isDeferred 8775 ErrorCode errorCode = (importElement.isDeferred
8778 ? StaticWarningCode.IMPORT_OF_NON_LIBRARY 8776 ? StaticWarningCode.IMPORT_OF_NON_LIBRARY
8779 : CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY); 8777 : CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY);
8780 _errorListener.onError(new AnalysisError.con2( 8778 _errorListener.onError(new AnalysisError(library.librarySource,
8781 library.librarySource, uriLiteral.offset, uriLiteral.length, 8779 uriLiteral.offset, uriLiteral.length, errorCode,
8782 errorCode, [uriLiteral.toSource()])); 8780 [uriLiteral.toSource()]));
8783 } 8781 }
8784 } 8782 }
8785 } 8783 }
8786 } else if (directive is ExportDirective) { 8784 } else if (directive is ExportDirective) {
8787 ExportDirective exportDirective = directive; 8785 ExportDirective exportDirective = directive;
8788 Source exportedSource = exportDirective.source; 8786 Source exportedSource = exportDirective.source;
8789 if (exportedSource != null && 8787 if (exportedSource != null &&
8790 analysisContext.exists(exportedSource)) { 8788 analysisContext.exists(exportedSource)) {
8791 // The exported source will be null if the URI in the export 8789 // The exported source will be null if the URI in the export
8792 // directive was invalid. 8790 // directive was invalid.
(...skipping 10 matching lines...) Expand all
8803 exportElement.combinators = _buildCombinators(exportDirective); 8801 exportElement.combinators = _buildCombinators(exportDirective);
8804 LibraryElement exportedLibraryElement = 8802 LibraryElement exportedLibraryElement =
8805 exportedLibrary.libraryElement; 8803 exportedLibrary.libraryElement;
8806 if (exportedLibraryElement != null) { 8804 if (exportedLibraryElement != null) {
8807 exportElement.exportedLibrary = exportedLibraryElement; 8805 exportElement.exportedLibrary = exportedLibraryElement;
8808 } 8806 }
8809 directive.element = exportElement; 8807 directive.element = exportElement;
8810 exports.add(exportElement); 8808 exports.add(exportElement);
8811 if (analysisContext.computeKindOf(exportedSource) != 8809 if (analysisContext.computeKindOf(exportedSource) !=
8812 SourceKind.LIBRARY) { 8810 SourceKind.LIBRARY) {
8813 _errorListener.onError(new AnalysisError.con2( 8811 _errorListener.onError(new AnalysisError(library.librarySource,
8814 library.librarySource, uriLiteral.offset, uriLiteral.length, 8812 uriLiteral.offset, uriLiteral.length,
8815 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY, 8813 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY,
8816 [uriLiteral.toSource()])); 8814 [uriLiteral.toSource()]));
8817 } 8815 }
8818 } 8816 }
8819 } 8817 }
8820 } 8818 }
8821 } 8819 }
8822 Source librarySource = library.librarySource; 8820 Source librarySource = library.librarySource;
8823 if (!library.explicitlyImportsCore && 8821 if (!library.explicitlyImportsCore &&
8824 _coreLibrarySource != librarySource) { 8822 _coreLibrarySource != librarySource) {
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
9129 if (existing is PrefixElement) { 9127 if (existing is PrefixElement) {
9130 // TODO(scheglov) consider providing actual 'nameOffset' from the 9128 // TODO(scheglov) consider providing actual 'nameOffset' from the
9131 // synthetic accessor 9129 // synthetic accessor
9132 int offset = duplicate.nameOffset; 9130 int offset = duplicate.nameOffset;
9133 if (duplicate is PropertyAccessorElement) { 9131 if (duplicate is PropertyAccessorElement) {
9134 PropertyAccessorElement accessor = duplicate; 9132 PropertyAccessorElement accessor = duplicate;
9135 if (accessor.isSynthetic) { 9133 if (accessor.isSynthetic) {
9136 offset = accessor.variable.nameOffset; 9134 offset = accessor.variable.nameOffset;
9137 } 9135 }
9138 } 9136 }
9139 return new AnalysisError.con2(duplicate.source, offset, 9137 return new AnalysisError(duplicate.source, offset,
9140 duplicate.displayName.length, 9138 duplicate.displayName.length,
9141 CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER, 9139 CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER,
9142 [existing.displayName]); 9140 [existing.displayName]);
9143 } 9141 }
9144 return super.getErrorForDuplicate(existing, duplicate); 9142 return super.getErrorForDuplicate(existing, duplicate);
9145 } 9143 }
9146 9144
9147 /** 9145 /**
9148 * Add to this scope all of the public top-level names that are defined in the given compilation 9146 * Add to this scope all of the public top-level names that are defined in the given compilation
9149 * unit. 9147 * unit.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
9181 define(prefix); 9179 define(prefix);
9182 } 9180 }
9183 _defineLocalNames(definingLibrary.definingCompilationUnit); 9181 _defineLocalNames(definingLibrary.definingCompilationUnit);
9184 for (CompilationUnitElement compilationUnit in definingLibrary.parts) { 9182 for (CompilationUnitElement compilationUnit in definingLibrary.parts) {
9185 _defineLocalNames(compilationUnit); 9183 _defineLocalNames(compilationUnit);
9186 } 9184 }
9187 } 9185 }
9188 } 9186 }
9189 9187
9190 /** 9188 /**
9191 * This class is used to replace uses of `HashMap<String, ExecutableElement>` wh ich are not as 9189 * This class is used to replace uses of `HashMap<String, ExecutableElement>`
9192 * performant as this class. 9190 * which are not as performant as this class.
9193 */ 9191 */
9194 class MemberMap { 9192 class MemberMap {
9195 /** 9193 /**
9196 * The current size of this map. 9194 * The current size of this map.
9197 */ 9195 */
9198 int _size = 0; 9196 int _size = 0;
9199 9197
9200 /** 9198 /**
9201 * The array of keys. 9199 * The array of keys.
9202 */ 9200 */
9203 List<String> _keys; 9201 List<String> _keys;
9204 9202
9205 /** 9203 /**
9206 * The array of ExecutableElement values. 9204 * The array of ExecutableElement values.
9207 */ 9205 */
9208 List<ExecutableElement> _values; 9206 List<ExecutableElement> _values;
9209 9207
9210 /** 9208 /**
9211 * Default constructor. 9209 * Initialize a newly created member map to have the given [initialCapacity].
9210 * The map will grow if needed.
9212 */ 9211 */
9213 MemberMap() : this.con1(10); 9212 MemberMap([int initialCapacity = 10]) {
9213 _initArrays(initialCapacity);
9214 }
9214 9215
9215 /** 9216 /**
9216 * This constructor takes an initial capacity of the map. 9217 * This constructor takes an initial capacity of the map.
9217 * 9218 *
9218 * @param initialCapacity the initial capacity 9219 * @param initialCapacity the initial capacity
9219 */ 9220 */
9221 @deprecated // Use new MemberMap(initialCapacity)
9220 MemberMap.con1(int initialCapacity) { 9222 MemberMap.con1(int initialCapacity) {
9221 _initArrays(initialCapacity); 9223 _initArrays(initialCapacity);
9222 } 9224 }
9223 9225
9224 /** 9226 /**
9225 * Copy constructor. 9227 * Copy constructor.
9226 */ 9228 */
9229 @deprecated // Use new MemberMap.from(memberMap)
9227 MemberMap.con2(MemberMap memberMap) { 9230 MemberMap.con2(MemberMap memberMap) {
9228 _initArrays(memberMap._size + 5); 9231 _initArrays(memberMap._size + 5);
9229 for (int i = 0; i < memberMap._size; i++) { 9232 for (int i = 0; i < memberMap._size; i++) {
9230 _keys[i] = memberMap._keys[i]; 9233 _keys[i] = memberMap._keys[i];
9231 _values[i] = memberMap._values[i]; 9234 _values[i] = memberMap._values[i];
9232 } 9235 }
9233 _size = memberMap._size; 9236 _size = memberMap._size;
9234 } 9237 }
9235 9238
9236 /** 9239 /**
9240 * Initialize a newly created member map to contain the same members as the
9241 * given [memberMap].
9242 */
9243 MemberMap.from(MemberMap memberMap) {
9244 _initArrays(memberMap._size + 5);
9245 for (int i = 0; i < memberMap._size; i++) {
9246 _keys[i] = memberMap._keys[i];
9247 _values[i] = memberMap._values[i];
9248 }
9249 _size = memberMap._size;
9250 }
9251
9252 /**
9237 * The size of the map. 9253 * The size of the map.
9238 * 9254 *
9239 * @return the size of the map. 9255 * @return the size of the map.
9240 */ 9256 */
9241 int get size => _size; 9257 int get size => _size;
9242 9258
9243 /** 9259 /**
9244 * Given some key, return the ExecutableElement value from the map, if the key does not exist in 9260 * Given some key, return the ExecutableElement value from the map, if the key does not exist in
9245 * the map, `null` is returned. 9261 * the map, `null` is returned.
9246 * 9262 *
(...skipping 2599 matching lines...) Expand 10 before | Expand all | Expand 10 after
11846 * @param existing the first element to be declared with the conflicting name 11862 * @param existing the first element to be declared with the conflicting name
11847 * @param duplicate another element declared with the conflicting name 11863 * @param duplicate another element declared with the conflicting name
11848 * @return the error code used to report duplicate names within a scope 11864 * @return the error code used to report duplicate names within a scope
11849 */ 11865 */
11850 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { 11866 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) {
11851 // TODO(brianwilkerson) Customize the error message based on the types of 11867 // TODO(brianwilkerson) Customize the error message based on the types of
11852 // elements that share the same name. 11868 // elements that share the same name.
11853 // TODO(jwren) There are 4 error codes for duplicate, but only 1 is being 11869 // TODO(jwren) There are 4 error codes for duplicate, but only 1 is being
11854 // generated. 11870 // generated.
11855 Source source = duplicate.source; 11871 Source source = duplicate.source;
11856 return new AnalysisError.con2(source, duplicate.nameOffset, 11872 return new AnalysisError(source, duplicate.nameOffset,
11857 duplicate.displayName.length, CompileTimeErrorCode.DUPLICATE_DEFINITION, 11873 duplicate.displayName.length, CompileTimeErrorCode.DUPLICATE_DEFINITION,
11858 [existing.displayName]); 11874 [existing.displayName]);
11859 } 11875 }
11860 11876
11861 /** 11877 /**
11862 * Return the source that contains the given identifier, or the source associa ted with this scope 11878 * Return the source that contains the given identifier, or the source associa ted with this scope
11863 * if the source containing the identifier could not be determined. 11879 * if the source containing the identifier could not be determined.
11864 * 11880 *
11865 * @param identifier the identifier whose source is to be returned 11881 * @param identifier the identifier whose source is to be returned
11866 * @return the source that contains the given identifier 11882 * @return the source that contains the given identifier
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
12092 12108
12093 /** 12109 /**
12094 * Report an error with the given error code and arguments. 12110 * Report an error with the given error code and arguments.
12095 * 12111 *
12096 * @param errorCode the error code of the error to be reported 12112 * @param errorCode the error code of the error to be reported
12097 * @param node the node specifying the location of the error 12113 * @param node the node specifying the location of the error
12098 * @param arguments the arguments to the error, used to compose the error mess age 12114 * @param arguments the arguments to the error, used to compose the error mess age
12099 */ 12115 */
12100 void reportErrorForNode(ErrorCode errorCode, AstNode node, 12116 void reportErrorForNode(ErrorCode errorCode, AstNode node,
12101 [List<Object> arguments]) { 12117 [List<Object> arguments]) {
12102 _errorListener.onError(new AnalysisError.con2( 12118 _errorListener.onError(new AnalysisError(
12103 source, node.offset, node.length, errorCode, arguments)); 12119 source, node.offset, node.length, errorCode, arguments));
12104 } 12120 }
12105 12121
12106 /** 12122 /**
12107 * Report an error with the given error code and arguments. 12123 * Report an error with the given error code and arguments.
12108 * 12124 *
12109 * @param errorCode the error code of the error to be reported 12125 * @param errorCode the error code of the error to be reported
12110 * @param offset the offset of the location of the error 12126 * @param offset the offset of the location of the error
12111 * @param length the length of the location of the error 12127 * @param length the length of the location of the error
12112 * @param arguments the arguments to the error, used to compose the error mess age 12128 * @param arguments the arguments to the error, used to compose the error mess age
12113 */ 12129 */
12114 void reportErrorForOffset(ErrorCode errorCode, int offset, int length, 12130 void reportErrorForOffset(ErrorCode errorCode, int offset, int length,
12115 [List<Object> arguments]) { 12131 [List<Object> arguments]) {
12116 _errorListener.onError( 12132 _errorListener.onError(
12117 new AnalysisError.con2(source, offset, length, errorCode, arguments)); 12133 new AnalysisError(source, offset, length, errorCode, arguments));
12118 } 12134 }
12119 12135
12120 /** 12136 /**
12121 * Report an error with the given error code and arguments. 12137 * Report an error with the given error code and arguments.
12122 * 12138 *
12123 * @param errorCode the error code of the error to be reported 12139 * @param errorCode the error code of the error to be reported
12124 * @param token the token specifying the location of the error 12140 * @param token the token specifying the location of the error
12125 * @param arguments the arguments to the error, used to compose the error mess age 12141 * @param arguments the arguments to the error, used to compose the error mess age
12126 */ 12142 */
12127 void reportErrorForToken(ErrorCode errorCode, sc.Token token, 12143 void reportErrorForToken(ErrorCode errorCode, sc.Token token,
12128 [List<Object> arguments]) { 12144 [List<Object> arguments]) {
12129 _errorListener.onError(new AnalysisError.con2( 12145 _errorListener.onError(new AnalysisError(
12130 source, token.offset, token.length, errorCode, arguments)); 12146 source, token.offset, token.length, errorCode, arguments));
12131 } 12147 }
12132 12148
12133 /** 12149 /**
12134 * Visit the given AST node if it is not null. 12150 * Visit the given AST node if it is not null.
12135 * 12151 *
12136 * @param node the node to be visited 12152 * @param node the node to be visited
12137 */ 12153 */
12138 void safelyVisit(AstNode node) { 12154 void safelyVisit(AstNode node) {
12139 if (node != null) { 12155 if (node != null) {
(...skipping 1773 matching lines...) Expand 10 before | Expand all | Expand 10 after
13913 buffer.write(classNode.name.name); 13929 buffer.write(classNode.name.name);
13914 } 13930 }
13915 buffer.write(" in "); 13931 buffer.write(" in ");
13916 buffer.write(source.fullName); 13932 buffer.write(source.fullName);
13917 buffer.write(" was not set while trying to resolve types."); 13933 buffer.write(" was not set while trying to resolve types.");
13918 AnalysisEngine.instance.logger.logError(buffer.toString(), 13934 AnalysisEngine.instance.logger.logError(buffer.toString(),
13919 new CaughtException(new AnalysisException(), null)); 13935 new CaughtException(new AnalysisException(), null));
13920 } else { 13936 } else {
13921 ClassElement definingClass = element.enclosingElement as ClassElement; 13937 ClassElement definingClass = element.enclosingElement as ClassElement;
13922 element.returnType = definingClass.type; 13938 element.returnType = definingClass.type;
13923 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); 13939 FunctionTypeImpl type = new FunctionTypeImpl(element);
13924 type.typeArguments = definingClass.type.typeArguments; 13940 type.typeArguments = definingClass.type.typeArguments;
13925 element.type = type; 13941 element.type = type;
13926 } 13942 }
13927 return null; 13943 return null;
13928 } 13944 }
13929 13945
13930 @override 13946 @override
13931 Object visitDeclaredIdentifier(DeclaredIdentifier node) { 13947 Object visitDeclaredIdentifier(DeclaredIdentifier node) {
13932 super.visitDeclaredIdentifier(node); 13948 super.visitDeclaredIdentifier(node);
13933 DartType declaredType; 13949 DartType declaredType;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
13982 StringBuffer buffer = new StringBuffer(); 13998 StringBuffer buffer = new StringBuffer();
13983 buffer.write("The element for the top-level function "); 13999 buffer.write("The element for the top-level function ");
13984 buffer.write(node.name); 14000 buffer.write(node.name);
13985 buffer.write(" in "); 14001 buffer.write(" in ");
13986 buffer.write(source.fullName); 14002 buffer.write(source.fullName);
13987 buffer.write(" was not set while trying to resolve types."); 14003 buffer.write(" was not set while trying to resolve types.");
13988 AnalysisEngine.instance.logger.logError(buffer.toString(), 14004 AnalysisEngine.instance.logger.logError(buffer.toString(),
13989 new CaughtException(new AnalysisException(), null)); 14005 new CaughtException(new AnalysisException(), null));
13990 } 14006 }
13991 element.returnType = _computeReturnType(node.returnType); 14007 element.returnType = _computeReturnType(node.returnType);
13992 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); 14008 FunctionTypeImpl type = new FunctionTypeImpl(element);
13993 ClassElement definingClass = 14009 ClassElement definingClass =
13994 element.getAncestor((element) => element is ClassElement); 14010 element.getAncestor((element) => element is ClassElement);
13995 if (definingClass != null) { 14011 if (definingClass != null) {
13996 type.typeArguments = definingClass.type.typeArguments; 14012 type.typeArguments = definingClass.type.typeArguments;
13997 } 14013 }
13998 element.type = type; 14014 element.type = type;
13999 return null; 14015 return null;
14000 } 14016 }
14001 14017
14002 @override 14018 @override
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
14039 } else { 14055 } else {
14040 buffer.write(classNode.name.name); 14056 buffer.write(classNode.name.name);
14041 } 14057 }
14042 buffer.write(" in "); 14058 buffer.write(" in ");
14043 buffer.write(source.fullName); 14059 buffer.write(source.fullName);
14044 buffer.write(" was not set while trying to resolve types."); 14060 buffer.write(" was not set while trying to resolve types.");
14045 AnalysisEngine.instance.logger.logError(buffer.toString(), 14061 AnalysisEngine.instance.logger.logError(buffer.toString(),
14046 new CaughtException(new AnalysisException(), null)); 14062 new CaughtException(new AnalysisException(), null));
14047 } 14063 }
14048 element.returnType = _computeReturnType(node.returnType); 14064 element.returnType = _computeReturnType(node.returnType);
14049 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); 14065 FunctionTypeImpl type = new FunctionTypeImpl(element);
14050 ClassElement definingClass = 14066 ClassElement definingClass =
14051 element.getAncestor((element) => element is ClassElement); 14067 element.getAncestor((element) => element is ClassElement);
14052 if (definingClass != null) { 14068 if (definingClass != null) {
14053 type.typeArguments = definingClass.type.typeArguments; 14069 type.typeArguments = definingClass.type.typeArguments;
14054 } 14070 }
14055 element.type = type; 14071 element.type = type;
14056 if (element is PropertyAccessorElement) { 14072 if (element is PropertyAccessorElement) {
14057 PropertyAccessorElement accessor = element as PropertyAccessorElement; 14073 PropertyAccessorElement accessor = element as PropertyAccessorElement;
14058 PropertyInducingElementImpl variable = 14074 PropertyInducingElementImpl variable =
14059 accessor.variable as PropertyInducingElementImpl; 14075 accessor.variable as PropertyInducingElementImpl;
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
14395 declaredType = _getType(typeName); 14411 declaredType = _getType(typeName);
14396 } 14412 }
14397 Element element = node.name.staticElement; 14413 Element element = node.name.staticElement;
14398 if (element is VariableElement) { 14414 if (element is VariableElement) {
14399 (element as VariableElementImpl).type = declaredType; 14415 (element as VariableElementImpl).type = declaredType;
14400 if (element is PropertyInducingElement) { 14416 if (element is PropertyInducingElement) {
14401 PropertyInducingElement variableElement = element; 14417 PropertyInducingElement variableElement = element;
14402 PropertyAccessorElementImpl getter = 14418 PropertyAccessorElementImpl getter =
14403 variableElement.getter as PropertyAccessorElementImpl; 14419 variableElement.getter as PropertyAccessorElementImpl;
14404 getter.returnType = declaredType; 14420 getter.returnType = declaredType;
14405 FunctionTypeImpl getterType = new FunctionTypeImpl.con1(getter); 14421 FunctionTypeImpl getterType = new FunctionTypeImpl(getter);
14406 ClassElement definingClass = 14422 ClassElement definingClass =
14407 element.getAncestor((element) => element is ClassElement); 14423 element.getAncestor((element) => element is ClassElement);
14408 if (definingClass != null) { 14424 if (definingClass != null) {
14409 getterType.typeArguments = definingClass.type.typeArguments; 14425 getterType.typeArguments = definingClass.type.typeArguments;
14410 } 14426 }
14411 getter.type = getterType; 14427 getter.type = getterType;
14412 PropertyAccessorElementImpl setter = 14428 PropertyAccessorElementImpl setter =
14413 variableElement.setter as PropertyAccessorElementImpl; 14429 variableElement.setter as PropertyAccessorElementImpl;
14414 if (setter != null) { 14430 if (setter != null) {
14415 List<ParameterElement> parameters = setter.parameters; 14431 List<ParameterElement> parameters = setter.parameters;
14416 if (parameters.length > 0) { 14432 if (parameters.length > 0) {
14417 (parameters[0] as ParameterElementImpl).type = declaredType; 14433 (parameters[0] as ParameterElementImpl).type = declaredType;
14418 } 14434 }
14419 setter.returnType = VoidTypeImpl.instance; 14435 setter.returnType = VoidTypeImpl.instance;
14420 FunctionTypeImpl setterType = new FunctionTypeImpl.con1(setter); 14436 FunctionTypeImpl setterType = new FunctionTypeImpl(setter);
14421 if (definingClass != null) { 14437 if (definingClass != null) {
14422 setterType.typeArguments = definingClass.type.typeArguments; 14438 setterType.typeArguments = definingClass.type.typeArguments;
14423 } 14439 }
14424 setter.type = setterType; 14440 setter.type = setterType;
14425 } 14441 }
14426 } 14442 }
14427 } else { 14443 } else {
14428 // TODO(brianwilkerson) Report the internal error. 14444 // TODO(brianwilkerson) Report the internal error.
14429 } 14445 }
14430 return null; 14446 return null;
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
14831 new FunctionTypeAliasElementImpl.forNode(null); 14847 new FunctionTypeAliasElementImpl.forNode(null);
14832 aliasElement.synthetic = true; 14848 aliasElement.synthetic = true;
14833 aliasElement.shareParameters(parameters); 14849 aliasElement.shareParameters(parameters);
14834 aliasElement.returnType = _computeReturnType(returnType); 14850 aliasElement.returnType = _computeReturnType(returnType);
14835 // FunctionTypeAliasElementImpl assumes the enclosing element is a 14851 // FunctionTypeAliasElementImpl assumes the enclosing element is a
14836 // CompilationUnitElement (because non-synthetic function types can only be 14852 // CompilationUnitElement (because non-synthetic function types can only be
14837 // declared at top level), so to avoid breaking things, go find the 14853 // declared at top level), so to avoid breaking things, go find the
14838 // compilation unit element. 14854 // compilation unit element.
14839 aliasElement.enclosingElement = 14855 aliasElement.enclosingElement =
14840 element.getAncestor((element) => element is CompilationUnitElement); 14856 element.getAncestor((element) => element is CompilationUnitElement);
14841 FunctionTypeImpl type = new FunctionTypeImpl.con2(aliasElement); 14857 FunctionTypeImpl type = new FunctionTypeImpl.forTypedef(aliasElement);
14842 ClassElement definingClass = 14858 ClassElement definingClass =
14843 element.getAncestor((element) => element is ClassElement); 14859 element.getAncestor((element) => element is ClassElement);
14844 if (definingClass != null) { 14860 if (definingClass != null) {
14845 aliasElement.shareTypeParameters(definingClass.typeParameters); 14861 aliasElement.shareTypeParameters(definingClass.typeParameters);
14846 type.typeArguments = definingClass.type.typeArguments; 14862 type.typeArguments = definingClass.type.typeArguments;
14847 } else { 14863 } else {
14848 FunctionTypeAliasElement alias = 14864 FunctionTypeAliasElement alias =
14849 element.getAncestor((element) => element is FunctionTypeAliasElement); 14865 element.getAncestor((element) => element is FunctionTypeAliasElement);
14850 while (alias != null && alias.isSynthetic) { 14866 while (alias != null && alias.isSynthetic) {
14851 alias = 14867 alias =
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
15035 } 15051 }
15036 if (_usedElements.members.contains(element.displayName)) { 15052 if (_usedElements.members.contains(element.displayName)) {
15037 return true; 15053 return true;
15038 } 15054 }
15039 return _usedElements.elements.contains(element); 15055 return _usedElements.elements.contains(element);
15040 } 15056 }
15041 15057
15042 void _reportErrorForElement( 15058 void _reportErrorForElement(
15043 ErrorCode errorCode, Element element, List<Object> arguments) { 15059 ErrorCode errorCode, Element element, List<Object> arguments) {
15044 if (element != null) { 15060 if (element != null) {
15045 _errorListener.onError(new AnalysisError.con2(element.source, 15061 _errorListener.onError(new AnalysisError(element.source,
15046 element.nameOffset, element.displayName.length, errorCode, 15062 element.nameOffset, element.displayName.length, errorCode,
15047 arguments)); 15063 arguments));
15048 } 15064 }
15049 } 15065 }
15050 } 15066 }
15051 15067
15052 /** 15068 /**
15053 * A container with information about used imports prefixes and used imported 15069 * A container with information about used imports prefixes and used imported
15054 * elements. 15070 * elements.
15055 */ 15071 */
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
15451 nonFields.add(node); 15467 nonFields.add(node);
15452 return null; 15468 return null;
15453 } 15469 }
15454 15470
15455 @override 15471 @override
15456 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); 15472 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this);
15457 15473
15458 @override 15474 @override
15459 Object visitWithClause(WithClause node) => null; 15475 Object visitWithClause(WithClause node) => null;
15460 } 15476 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | pkg/analyzer/lib/src/generated/scanner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698