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

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

Issue 12543003: Use limited JavaStringBuilder implementation instead of Dart StringBuffer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tweak JavaStringBuilder. Created 7 years, 9 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
OLDNEW
1 // This code was auto-generated, is not intended to be edited, and is subject to 1 // This code was auto-generated, is not intended to be edited, and is subject to
2 // significant change. Please see the README file for more information. 2 // significant change. Please see the README file for more information.
3 3
4 library engine.resolver; 4 library engine.resolver;
5 5
6 import 'dart:collection'; 6 import 'dart:collection';
7 import 'java_core.dart'; 7 import 'java_core.dart';
8 import 'java_engine.dart'; 8 import 'java_engine.dart';
9 import 'source.dart'; 9 import 'source.dart';
10 import 'error.dart'; 10 import 'error.dart';
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 return super.visitCatchClause(node); 110 return super.visitCatchClause(node);
111 } 111 }
112 Object visitClassDeclaration(ClassDeclaration node) { 112 Object visitClassDeclaration(ClassDeclaration node) {
113 ElementHolder holder = new ElementHolder(); 113 ElementHolder holder = new ElementHolder();
114 _isValidMixin = true; 114 _isValidMixin = true;
115 visitChildren(holder, node); 115 visitChildren(holder, node);
116 SimpleIdentifier className = node.name; 116 SimpleIdentifier className = node.name;
117 ClassElementImpl element = new ClassElementImpl(className); 117 ClassElementImpl element = new ClassElementImpl(className);
118 List<TypeVariableElement> typeVariables4 = holder.typeVariables; 118 List<TypeVariableElement> typeVariables4 = holder.typeVariables;
119 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl.con1(element); 119 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl.con1(element);
120 int typeVariableCount = typeVariables4.length; 120 interfaceType.typeArguments = createTypeVariableTypes(typeVariables4);
121 List<Type2> typeArguments = new List<Type2>(typeVariableCount);
122 for (int i = 0; i < typeVariableCount; i++) {
123 TypeVariableElementImpl typeVariable = typeVariables4[i] as TypeVariableEl ementImpl;
124 TypeVariableTypeImpl typeArgument = new TypeVariableTypeImpl(typeVariable) ;
125 typeVariable.type = typeArgument;
126 typeArguments[i] = typeArgument;
127 }
128 interfaceType.typeArguments = typeArguments;
129 element.type = interfaceType; 121 element.type = interfaceType;
130 List<ConstructorElement> constructors3 = holder.constructors; 122 List<ConstructorElement> constructors3 = holder.constructors;
131 if (constructors3.length == 0) { 123 if (constructors3.length == 0) {
132 ConstructorElementImpl constructor = new ConstructorElementImpl(null); 124 ConstructorElementImpl constructor = new ConstructorElementImpl(null);
133 constructor.synthetic = true; 125 constructor.synthetic = true;
134 FunctionTypeImpl type = new FunctionTypeImpl.con1(constructor); 126 FunctionTypeImpl type = new FunctionTypeImpl.con1(constructor);
135 type.returnType = interfaceType; 127 type.returnType = interfaceType;
136 constructor.type = type; 128 constructor.type = type;
137 constructors3 = <ConstructorElement> [constructor]; 129 constructors3 = <ConstructorElement> [constructor];
138 } 130 }
(...skipping 11 matching lines...) Expand all
150 Object visitClassTypeAlias(ClassTypeAlias node) { 142 Object visitClassTypeAlias(ClassTypeAlias node) {
151 ElementHolder holder = new ElementHolder(); 143 ElementHolder holder = new ElementHolder();
152 visitChildren(holder, node); 144 visitChildren(holder, node);
153 SimpleIdentifier className = node.name; 145 SimpleIdentifier className = node.name;
154 ClassElementImpl element = new ClassElementImpl(className); 146 ClassElementImpl element = new ClassElementImpl(className);
155 element.abstract = node.abstractKeyword != null; 147 element.abstract = node.abstractKeyword != null;
156 element.typedef = true; 148 element.typedef = true;
157 List<TypeVariableElement> typeVariables5 = holder.typeVariables; 149 List<TypeVariableElement> typeVariables5 = holder.typeVariables;
158 element.typeVariables = typeVariables5; 150 element.typeVariables = typeVariables5;
159 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl.con1(element); 151 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl.con1(element);
160 int typeVariableCount = typeVariables5.length; 152 interfaceType.typeArguments = createTypeVariableTypes(typeVariables5);
161 List<Type2> typeArguments = new List<Type2>(typeVariableCount);
162 for (int i = 0; i < typeVariableCount; i++) {
163 TypeVariableElementImpl typeVariable = typeVariables5[i] as TypeVariableEl ementImpl;
164 TypeVariableTypeImpl typeArgument = new TypeVariableTypeImpl(typeVariable) ;
165 typeVariable.type = typeArgument;
166 typeArguments[i] = typeArgument;
167 }
168 interfaceType.typeArguments = typeArguments;
169 element.type = interfaceType; 153 element.type = interfaceType;
170 _currentHolder.addType(element); 154 _currentHolder.addType(element);
171 className.element = element; 155 className.element = element;
172 return null; 156 return null;
173 } 157 }
174 Object visitConstructorDeclaration(ConstructorDeclaration node) { 158 Object visitConstructorDeclaration(ConstructorDeclaration node) {
175 _isValidMixin = false; 159 _isValidMixin = false;
176 ElementHolder holder = new ElementHolder(); 160 ElementHolder holder = new ElementHolder();
177 visitChildren(holder, node); 161 visitChildren(holder, node);
178 SimpleIdentifier constructorName = node.name; 162 SimpleIdentifier constructorName = node.name;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 element.type = type; 311 element.type = type;
328 _currentHolder.addFunction(element); 312 _currentHolder.addFunction(element);
329 node.element = element; 313 node.element = element;
330 return null; 314 return null;
331 } 315 }
332 Object visitFunctionTypeAlias(FunctionTypeAlias node) { 316 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
333 ElementHolder holder = new ElementHolder(); 317 ElementHolder holder = new ElementHolder();
334 visitChildren(holder, node); 318 visitChildren(holder, node);
335 SimpleIdentifier aliasName = node.name; 319 SimpleIdentifier aliasName = node.name;
336 List<ParameterElement> parameters10 = holder.parameters; 320 List<ParameterElement> parameters10 = holder.parameters;
321 List<TypeVariableElement> typeVariables6 = holder.typeVariables;
337 TypeAliasElementImpl element = new TypeAliasElementImpl(aliasName); 322 TypeAliasElementImpl element = new TypeAliasElementImpl(aliasName);
338 element.parameters = parameters10; 323 element.parameters = parameters10;
339 element.typeVariables = holder.typeVariables; 324 element.typeVariables = typeVariables6;
340 FunctionTypeImpl type = new FunctionTypeImpl.con2(element); 325 FunctionTypeImpl type = new FunctionTypeImpl.con2(element);
326 type.typeArguments = createTypeVariableTypes(typeVariables6);
341 element.type = type; 327 element.type = type;
342 _currentHolder.addTypeAlias(element); 328 _currentHolder.addTypeAlias(element);
343 aliasName.element = element; 329 aliasName.element = element;
344 return null; 330 return null;
345 } 331 }
346 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { 332 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
347 if (node.parent is! DefaultFormalParameter) { 333 if (node.parent is! DefaultFormalParameter) {
348 SimpleIdentifier parameterName = node.identifier; 334 SimpleIdentifier parameterName = node.identifier;
349 ParameterElementImpl parameter = new ParameterElementImpl(parameterName); 335 ParameterElementImpl parameter = new ParameterElementImpl(parameterName);
350 parameter.parameterKind = node.kind; 336 parameter.parameterKind = node.kind;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 setter.setter = true; 509 setter.setter = true;
524 _currentHolder.addAccessor(setter); 510 _currentHolder.addAccessor(setter);
525 variable.setter = setter; 511 variable.setter = setter;
526 } 512 }
527 if (_inFieldContext) { 513 if (_inFieldContext) {
528 ((variable as FieldElementImpl)).static = matches(((node.parent.parent a s FieldDeclaration)).keyword, Keyword.STATIC); 514 ((variable as FieldElementImpl)).static = matches(((node.parent.parent a s FieldDeclaration)).keyword, Keyword.STATIC);
529 } 515 }
530 } 516 }
531 return super.visitVariableDeclaration(node); 517 return super.visitVariableDeclaration(node);
532 } 518 }
519 List<Type2> createTypeVariableTypes(List<TypeVariableElement> typeVariables) {
520 int typeVariableCount = typeVariables.length;
521 List<Type2> typeArguments = new List<Type2>(typeVariableCount);
522 for (int i = 0; i < typeVariableCount; i++) {
523 TypeVariableElementImpl typeVariable = typeVariables[i] as TypeVariableEle mentImpl;
524 TypeVariableTypeImpl typeArgument = new TypeVariableTypeImpl(typeVariable) ;
525 typeVariable.type = typeArgument;
526 typeArguments[i] = typeArgument;
527 }
528 return typeArguments;
529 }
533 /** 530 /**
534 * Return the body of the function that contains the given parameter, or {@cod e null} if no 531 * Return the body of the function that contains the given parameter, or {@cod e null} if no
535 * function body could be found. 532 * function body could be found.
536 * @param node the parameter contained in the function whose body is to be ret urned 533 * @param node the parameter contained in the function whose body is to be ret urned
537 * @return the body of the function that contains the given parameter 534 * @return the body of the function that contains the given parameter
538 */ 535 */
539 FunctionBody getFunctionBody(FormalParameter node) { 536 FunctionBody getFunctionBody(FormalParameter node) {
540 ASTNode parent13 = node.parent; 537 ASTNode parent13 = node.parent;
541 while (parent13 != null) { 538 while (parent13 != null) {
542 if (parent13 is FunctionExpression) { 539 if (parent13 is FunctionExpression) {
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 return null; 859 return null;
863 } 860 }
864 Object visitMethodInvocation(MethodInvocation node) { 861 Object visitMethodInvocation(MethodInvocation node) {
865 SimpleIdentifier methodName2 = node.methodName; 862 SimpleIdentifier methodName2 = node.methodName;
866 Expression target = node.realTarget; 863 Expression target = node.realTarget;
867 Element element; 864 Element element;
868 if (target == null) { 865 if (target == null) {
869 element = _resolver.nameScope.lookup(methodName2, _resolver.definingLibrar y); 866 element = _resolver.nameScope.lookup(methodName2, _resolver.definingLibrar y);
870 if (element == null) { 867 if (element == null) {
871 element = lookUpMethod(_resolver.enclosingClass, methodName2.name); 868 element = lookUpMethod(_resolver.enclosingClass, methodName2.name);
869 if (element == null) {
870 PropertyAccessorElement getter = lookUpGetter(_resolver.enclosingClass , methodName2.name);
871 if (getter != null) {
872 FunctionType getterType = getter.type;
873 if (getterType != null) {
874 Type2 returnType4 = getterType.returnType;
875 if (!returnType4.isDynamic() && returnType4 is! FunctionType && !r eturnType4.isDartCoreFunction()) {
876 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FU NCTION, methodName2, [methodName2.name]);
877 }
878 }
879 recordResolution(methodName2, getter);
880 return null;
881 }
882 }
872 } 883 }
873 } else { 884 } else {
874 Type2 targetType = getType(target); 885 Type2 targetType = getType(target);
875 if (targetType is InterfaceType) { 886 if (targetType is InterfaceType) {
876 element = lookUpMethod(targetType.element, methodName2.name); 887 element = lookUpMethod(targetType.element, methodName2.name);
877 if (element == null) { 888 if (element == null) {
878 PropertyAccessorElement accessor = lookUpGetterInType((targetType.elem ent as ClassElement), methodName2.name); 889 PropertyAccessorElement accessor = lookUpGetterInType((targetType.elem ent as ClassElement), methodName2.name);
879 if (accessor != null) { 890 if (accessor != null) {
880 Type2 returnType4 = accessor.type.returnType; 891 Type2 returnType5 = accessor.type.returnType;
881 if (!returnType4.isDynamic() && returnType4 is! FunctionType) { 892 if (!returnType5.isDynamic() && returnType5 is! FunctionType && !ret urnType5.isDartCoreFunction()) {
882 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNC TION, methodName2, [methodName2.name]); 893 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNC TION, methodName2, [methodName2.name]);
883 return null; 894 return null;
884 } 895 }
885 element = accessor; 896 element = accessor;
886 } 897 }
887 } 898 }
888 if (element == null && target is SuperExpression) { 899 if (element == null && target is SuperExpression) {
889 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_SUPER_METHOD, me thodName2, [methodName2.name, targetType.element.name]); 900 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_SUPER_METHOD, me thodName2, [methodName2.name, targetType.element.name]);
890 return null; 901 return null;
891 } 902 }
(...skipping 11 matching lines...) Expand all
903 } 914 }
904 } 915 }
905 ExecutableElement invokedMethod = null; 916 ExecutableElement invokedMethod = null;
906 if (element is ExecutableElement) { 917 if (element is ExecutableElement) {
907 invokedMethod = element as ExecutableElement; 918 invokedMethod = element as ExecutableElement;
908 } else { 919 } else {
909 if (element is PropertyInducingElement) { 920 if (element is PropertyInducingElement) {
910 PropertyAccessorElement getter3 = ((element as PropertyInducingElement)) .getter; 921 PropertyAccessorElement getter3 = ((element as PropertyInducingElement)) .getter;
911 FunctionType getterType = getter3.type; 922 FunctionType getterType = getter3.type;
912 if (getterType != null) { 923 if (getterType != null) {
913 Type2 returnType5 = getterType.returnType; 924 Type2 returnType6 = getterType.returnType;
914 if (!returnType5.isDynamic() && returnType5 is! FunctionType) { 925 if (!returnType6.isDynamic() && returnType6 is! FunctionType && !retur nType6.isDartCoreFunction()) {
915 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTI ON, methodName2, [methodName2.name]); 926 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTI ON, methodName2, [methodName2.name]);
916 } 927 }
917 } 928 }
918 recordResolution(methodName2, element); 929 recordResolution(methodName2, element);
919 return null; 930 return null;
920 } else if (element is VariableElement) { 931 } else if (element is VariableElement) {
921 Type2 variableType = ((element as VariableElement)).type; 932 Type2 variableType = ((element as VariableElement)).type;
922 if (!variableType.isDynamic() && variableType is! FunctionType) { 933 if (!variableType.isDynamic() && variableType is! FunctionType && !varia bleType.isDartCoreFunction()) {
923 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION , methodName2, [methodName2.name]); 934 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION , methodName2, [methodName2.name]);
924 } 935 }
925 recordResolution(methodName2, element); 936 recordResolution(methodName2, element);
926 return null; 937 return null;
927 } else { 938 } else {
928 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION, methodName2, [methodName2.name]); 939 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION, methodName2, [methodName2.name]);
929 return null; 940 return null;
930 } 941 }
931 } 942 }
932 recordResolution(methodName2, invokedMethod); 943 recordResolution(methodName2, invokedMethod);
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after
1782 this._libraryElement = libraryElement2; 1793 this._libraryElement = libraryElement2;
1783 } 1794 }
1784 String toString() => _librarySource.shortName; 1795 String toString() => _librarySource.shortName;
1785 /** 1796 /**
1786 * Append the value of the given string literal to the given string builder. 1797 * Append the value of the given string literal to the given string builder.
1787 * @param builder the builder to which the string's value is to be appended 1798 * @param builder the builder to which the string's value is to be appended
1788 * @param literal the string literal whose value is to be appended to the buil der 1799 * @param literal the string literal whose value is to be appended to the buil der
1789 * @throws IllegalArgumentException if the string is not a constant string wit hout any string 1800 * @throws IllegalArgumentException if the string is not a constant string wit hout any string
1790 * interpolation 1801 * interpolation
1791 */ 1802 */
1792 void appendStringValue(StringBuffer builder, StringLiteral literal) { 1803 void appendStringValue(JavaStringBuilder builder, StringLiteral literal) {
1793 if (literal is SimpleStringLiteral) { 1804 if (literal is SimpleStringLiteral) {
1794 builder.write(((literal as SimpleStringLiteral)).value); 1805 builder.append(((literal as SimpleStringLiteral)).value);
1795 } else if (literal is AdjacentStrings) { 1806 } else if (literal is AdjacentStrings) {
1796 for (StringLiteral stringLiteral in ((literal as AdjacentStrings)).strings ) { 1807 for (StringLiteral stringLiteral in ((literal as AdjacentStrings)).strings ) {
1797 appendStringValue(builder, stringLiteral); 1808 appendStringValue(builder, stringLiteral);
1798 } 1809 }
1799 } else { 1810 } else {
1800 throw new IllegalArgumentException(); 1811 throw new IllegalArgumentException();
1801 } 1812 }
1802 } 1813 }
1803 /** 1814 /**
1804 * Return the result of resolving the given URI against the URI of the library , or {@code null} if 1815 * Return the result of resolving the given URI against the URI of the library , or {@code null} if
1805 * the URI is not valid. 1816 * the URI is not valid.
1806 * @param uri the URI to be resolved 1817 * @param uri the URI to be resolved
1807 * @return the result of resolving the given URI against the URI of the librar y 1818 * @return the result of resolving the given URI against the URI of the librar y
1808 */ 1819 */
1809 Source getSource2(String uri) { 1820 Source getSource2(String uri) {
1810 if (uri == null) { 1821 if (uri == null) {
1811 return null; 1822 return null;
1812 } 1823 }
1813 return _librarySource.resolve(uri); 1824 return _librarySource.resolve(uri);
1814 } 1825 }
1815 /** 1826 /**
1816 * Return the value of the given string literal, or {@code null} if the string is not a constant 1827 * Return the value of the given string literal, or {@code null} if the string is not a constant
1817 * string without any string interpolation. 1828 * string without any string interpolation.
1818 * @param literal the string literal whose value is to be returned 1829 * @param literal the string literal whose value is to be returned
1819 * @return the value of the given string literal 1830 * @return the value of the given string literal
1820 */ 1831 */
1821 String getStringValue(StringLiteral literal) { 1832 String getStringValue(StringLiteral literal) {
1822 StringBuffer builder = new StringBuffer(); 1833 JavaStringBuilder builder = new JavaStringBuilder();
1823 try { 1834 try {
1824 appendStringValue(builder, literal); 1835 appendStringValue(builder, literal);
1825 } on IllegalArgumentException catch (exception) { 1836 } on IllegalArgumentException catch (exception) {
1826 return null; 1837 return null;
1827 } 1838 }
1828 return builder.toString().trim(); 1839 return builder.toString().trim();
1829 } 1840 }
1830 } 1841 }
1831 /** 1842 /**
1832 * Instances of the class {@code LibraryElementBuilder} build an element model f or a single library. 1843 * Instances of the class {@code LibraryElementBuilder} build an element model f or a single library.
(...skipping 1613 matching lines...) Expand 10 before | Expand all | Expand 10 after
3446 */ 3457 */
3447 Object visitThrowExpression(ThrowExpression node) => recordType(node, _typePro vider.bottomType); 3458 Object visitThrowExpression(ThrowExpression node) => recordType(node, _typePro vider.bottomType);
3448 /** 3459 /**
3449 * Given a function declaration, compute the return type of the function. The return type of 3460 * Given a function declaration, compute the return type of the function. The return type of
3450 * functions with a block body is {@code dynamicType}, with an expression body it is the type of 3461 * functions with a block body is {@code dynamicType}, with an expression body it is the type of
3451 * the expression. 3462 * the expression.
3452 * @param node the function expression whose return type is to be computed 3463 * @param node the function expression whose return type is to be computed
3453 * @return the return type that was computed 3464 * @return the return type that was computed
3454 */ 3465 */
3455 Type2 computeReturnType(FunctionDeclaration node) { 3466 Type2 computeReturnType(FunctionDeclaration node) {
3456 TypeName returnType6 = node.returnType; 3467 TypeName returnType7 = node.returnType;
3457 if (returnType6 == null) { 3468 if (returnType7 == null) {
3458 return computeReturnType2(node.functionExpression); 3469 return computeReturnType2(node.functionExpression);
3459 } 3470 }
3460 return returnType6.type; 3471 return returnType7.type;
3461 } 3472 }
3462 /** 3473 /**
3463 * Given a function expression, compute the return type of the function. The r eturn type of 3474 * Given a function expression, compute the return type of the function. The r eturn type of
3464 * functions with a block body is {@code dynamicType}, with an expression body it is the type of 3475 * functions with a block body is {@code dynamicType}, with an expression body it is the type of
3465 * the expression. 3476 * the expression.
3466 * @param node the function expression whose return type is to be computed 3477 * @param node the function expression whose return type is to be computed
3467 * @return the return type that was computed 3478 * @return the return type that was computed
3468 */ 3479 */
3469 Type2 computeReturnType2(FunctionExpression node) { 3480 Type2 computeReturnType2(FunctionExpression node) {
3470 FunctionBody body4 = node.body; 3481 FunctionBody body4 = node.body;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
3577 } 3588 }
3578 return null; 3589 return null;
3579 } 3590 }
3580 /** 3591 /**
3581 * Set the return type and parameter type information for the given function t ype based on the 3592 * Set the return type and parameter type information for the given function t ype based on the
3582 * given return type and parameter elements. 3593 * given return type and parameter elements.
3583 * @param functionType the function type to be filled in 3594 * @param functionType the function type to be filled in
3584 * @param returnType the return type of the function, or {@code null} if no ty pe was declared 3595 * @param returnType the return type of the function, or {@code null} if no ty pe was declared
3585 * @param parameters the elements representing the parameters to the function 3596 * @param parameters the elements representing the parameters to the function
3586 */ 3597 */
3587 void setTypeInformation(FunctionTypeImpl functionType, Type2 returnType9, Form alParameterList parameterList) { 3598 void setTypeInformation(FunctionTypeImpl functionType, Type2 returnType10, For malParameterList parameterList) {
3588 List<Type2> normalParameterTypes = new List<Type2>(); 3599 List<Type2> normalParameterTypes = new List<Type2>();
3589 List<Type2> optionalParameterTypes = new List<Type2>(); 3600 List<Type2> optionalParameterTypes = new List<Type2>();
3590 LinkedHashMap<String, Type2> namedParameterTypes = new LinkedHashMap<String, Type2>(); 3601 LinkedHashMap<String, Type2> namedParameterTypes = new LinkedHashMap<String, Type2>();
3591 if (parameterList != null) { 3602 if (parameterList != null) {
3592 for (ParameterElement parameter in parameterList.elements) { 3603 for (ParameterElement parameter in parameterList.elements) {
3593 while (true) { 3604 while (true) {
3594 if (parameter.parameterKind == ParameterKind.REQUIRED) { 3605 if (parameter.parameterKind == ParameterKind.REQUIRED) {
3595 normalParameterTypes.add(parameter.type); 3606 normalParameterTypes.add(parameter.type);
3596 } else if (parameter.parameterKind == ParameterKind.POSITIONAL) { 3607 } else if (parameter.parameterKind == ParameterKind.POSITIONAL) {
3597 optionalParameterTypes.add(parameter.type); 3608 optionalParameterTypes.add(parameter.type);
3598 } else if (parameter.parameterKind == ParameterKind.NAMED) { 3609 } else if (parameter.parameterKind == ParameterKind.NAMED) {
3599 namedParameterTypes[parameter.name] = parameter.type; 3610 namedParameterTypes[parameter.name] = parameter.type;
3600 } 3611 }
3601 break; 3612 break;
3602 } 3613 }
3603 } 3614 }
3604 } 3615 }
3605 functionType.normalParameterTypes = new List.from(normalParameterTypes); 3616 functionType.normalParameterTypes = new List.from(normalParameterTypes);
3606 functionType.optionalParameterTypes = new List.from(optionalParameterTypes); 3617 functionType.optionalParameterTypes = new List.from(optionalParameterTypes);
3607 functionType.namedParameterTypes = namedParameterTypes; 3618 functionType.namedParameterTypes = namedParameterTypes;
3608 functionType.returnType = returnType9; 3619 functionType.returnType = returnType10;
3609 } 3620 }
3610 } 3621 }
3611 /** 3622 /**
3612 * The interface {@code TypeProvider} defines the behavior of objects that provi de access to types 3623 * The interface {@code TypeProvider} defines the behavior of objects that provi de access to types
3613 * defined by the language. 3624 * defined by the language.
3614 */ 3625 */
3615 abstract class TypeProvider { 3626 abstract class TypeProvider {
3616 /** 3627 /**
3617 * Return the type representing the built-in type 'bool'. 3628 * Return the type representing the built-in type 'bool'.
3618 * @return the type representing the built-in type 'bool' 3629 * @return the type representing the built-in type 'bool'
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
4286 } 4297 }
4287 } 4298 }
4288 } 4299 }
4289 /** 4300 /**
4290 * Set the return type and parameter type information for the given function t ype based on the 4301 * Set the return type and parameter type information for the given function t ype based on the
4291 * given return type and parameter elements. 4302 * given return type and parameter elements.
4292 * @param functionType the function type to be filled in 4303 * @param functionType the function type to be filled in
4293 * @param returnType the return type of the function, or {@code null} if no ty pe was declared 4304 * @param returnType the return type of the function, or {@code null} if no ty pe was declared
4294 * @param parameters the elements representing the parameters to the function 4305 * @param parameters the elements representing the parameters to the function
4295 */ 4306 */
4296 void setTypeInformation(FunctionTypeImpl functionType, TypeName returnType10, List<ParameterElement> parameters) { 4307 void setTypeInformation(FunctionTypeImpl functionType, TypeName returnType11, List<ParameterElement> parameters) {
4297 List<Type2> normalParameterTypes = new List<Type2>(); 4308 List<Type2> normalParameterTypes = new List<Type2>();
4298 List<Type2> optionalParameterTypes = new List<Type2>(); 4309 List<Type2> optionalParameterTypes = new List<Type2>();
4299 LinkedHashMap<String, Type2> namedParameterTypes = new LinkedHashMap<String, Type2>(); 4310 LinkedHashMap<String, Type2> namedParameterTypes = new LinkedHashMap<String, Type2>();
4300 for (ParameterElement parameter in parameters) { 4311 for (ParameterElement parameter in parameters) {
4301 while (true) { 4312 while (true) {
4302 if (parameter.parameterKind == ParameterKind.REQUIRED) { 4313 if (parameter.parameterKind == ParameterKind.REQUIRED) {
4303 normalParameterTypes.add(parameter.type); 4314 normalParameterTypes.add(parameter.type);
4304 } else if (parameter.parameterKind == ParameterKind.POSITIONAL) { 4315 } else if (parameter.parameterKind == ParameterKind.POSITIONAL) {
4305 optionalParameterTypes.add(parameter.type); 4316 optionalParameterTypes.add(parameter.type);
4306 } else if (parameter.parameterKind == ParameterKind.NAMED) { 4317 } else if (parameter.parameterKind == ParameterKind.NAMED) {
4307 namedParameterTypes[parameter.name] = parameter.type; 4318 namedParameterTypes[parameter.name] = parameter.type;
4308 } 4319 }
4309 break; 4320 break;
4310 } 4321 }
4311 } 4322 }
4312 if (!normalParameterTypes.isEmpty) { 4323 if (!normalParameterTypes.isEmpty) {
4313 functionType.normalParameterTypes = new List.from(normalParameterTypes); 4324 functionType.normalParameterTypes = new List.from(normalParameterTypes);
4314 } 4325 }
4315 if (!optionalParameterTypes.isEmpty) { 4326 if (!optionalParameterTypes.isEmpty) {
4316 functionType.optionalParameterTypes = new List.from(optionalParameterTypes ); 4327 functionType.optionalParameterTypes = new List.from(optionalParameterTypes );
4317 } 4328 }
4318 if (!namedParameterTypes.isEmpty) { 4329 if (!namedParameterTypes.isEmpty) {
4319 functionType.namedParameterTypes = namedParameterTypes; 4330 functionType.namedParameterTypes = namedParameterTypes;
4320 } 4331 }
4321 if (returnType10 == null) { 4332 if (returnType11 == null) {
4322 functionType.returnType = _dynamicType; 4333 functionType.returnType = _dynamicType;
4323 } else { 4334 } else {
4324 functionType.returnType = returnType10.type; 4335 functionType.returnType = returnType11.type;
4325 } 4336 }
4326 } 4337 }
4327 } 4338 }
4328 /** 4339 /**
4329 * Instances of the class {@code ClassScope} implement the scope defined by a cl ass. 4340 * Instances of the class {@code ClassScope} implement the scope defined by a cl ass.
4330 */ 4341 */
4331 class ClassScope extends EnclosedScope { 4342 class ClassScope extends EnclosedScope {
4332 /** 4343 /**
4333 * Initialize a newly created scope enclosed within another scope. 4344 * Initialize a newly created scope enclosed within another scope.
4334 * @param enclosingScope the scope in which this scope is lexically enclosed 4345 * @param enclosingScope the scope in which this scope is lexically enclosed
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
5160 Object visitAssignmentExpression(AssignmentExpression node) { 5171 Object visitAssignmentExpression(AssignmentExpression node) {
5161 Expression lhs = node.leftHandSide; 5172 Expression lhs = node.leftHandSide;
5162 Expression rhs = node.rightHandSide; 5173 Expression rhs = node.rightHandSide;
5163 Type2 leftType = getType(lhs); 5174 Type2 leftType = getType(lhs);
5164 Type2 rightType = getType(rhs); 5175 Type2 rightType = getType(rhs);
5165 if (!rightType.isAssignableTo(leftType)) { 5176 if (!rightType.isAssignableTo(leftType)) {
5166 _errorReporter.reportError(StaticTypeWarningCode.INVALID_ASSIGNMENT, rhs, [leftType.name, rightType.name]); 5177 _errorReporter.reportError(StaticTypeWarningCode.INVALID_ASSIGNMENT, rhs, [leftType.name, rightType.name]);
5167 } 5178 }
5168 return super.visitAssignmentExpression(node); 5179 return super.visitAssignmentExpression(node);
5169 } 5180 }
5181 Object visitClassDeclaration(ClassDeclaration node) {
5182 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPE_NAME);
5183 return super.visitClassDeclaration(node);
5184 }
5185 Object visitClassTypeAlias(ClassTypeAlias node) {
5186 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPEDEF_NAME);
5187 return super.visitClassTypeAlias(node);
5188 }
5170 Object visitConditionalExpression(ConditionalExpression node) { 5189 Object visitConditionalExpression(ConditionalExpression node) {
5171 checkForNonBoolCondition(node.condition); 5190 checkForNonBoolCondition(node.condition);
5172 return super.visitConditionalExpression(node); 5191 return super.visitConditionalExpression(node);
5173 } 5192 }
5174 Object visitConstructorDeclaration(ConstructorDeclaration node) { 5193 Object visitConstructorDeclaration(ConstructorDeclaration node) {
5175 ExecutableElement previousFunction = _currentFunction; 5194 ExecutableElement previousFunction = _currentFunction;
5176 try { 5195 try {
5177 _currentFunction = node.element; 5196 _currentFunction = node.element;
5178 return super.visitConstructorDeclaration(node); 5197 return super.visitConstructorDeclaration(node);
5179 } finally { 5198 } finally {
(...skipping 15 matching lines...) Expand all
5195 } 5214 }
5196 Object visitFunctionExpression(FunctionExpression node) { 5215 Object visitFunctionExpression(FunctionExpression node) {
5197 ExecutableElement previousFunction = _currentFunction; 5216 ExecutableElement previousFunction = _currentFunction;
5198 try { 5217 try {
5199 _currentFunction = node.element; 5218 _currentFunction = node.element;
5200 return super.visitFunctionExpression(node); 5219 return super.visitFunctionExpression(node);
5201 } finally { 5220 } finally {
5202 _currentFunction = previousFunction; 5221 _currentFunction = previousFunction;
5203 } 5222 }
5204 } 5223 }
5224 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
5225 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPEDEF_NAME);
5226 return super.visitFunctionTypeAlias(node);
5227 }
5205 Object visitIfStatement(IfStatement node) { 5228 Object visitIfStatement(IfStatement node) {
5206 checkForNonBoolCondition(node.condition); 5229 checkForNonBoolCondition(node.condition);
5207 return super.visitIfStatement(node); 5230 return super.visitIfStatement(node);
5208 } 5231 }
5209 Object visitInstanceCreationExpression(InstanceCreationExpression node) { 5232 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
5210 ConstructorName constructorName4 = node.constructorName; 5233 ConstructorName constructorName4 = node.constructorName;
5211 TypeName typeName = constructorName4.type; 5234 TypeName typeName = constructorName4.type;
5212 Type2 createdType = typeName.type; 5235 Type2 createdType = typeName.type;
5213 if (createdType is InterfaceType) { 5236 if (createdType is InterfaceType) {
5214 if (((createdType as InterfaceType)).element.isAbstract()) { 5237 if (((createdType as InterfaceType)).element.isAbstract()) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
5258 Type2 expectedReturnType = functionType == null ? null : functionType.return Type; 5281 Type2 expectedReturnType = functionType == null ? null : functionType.return Type;
5259 Expression returnExpression = node.expression; 5282 Expression returnExpression = node.expression;
5260 if (expectedReturnType != null && !expectedReturnType.isVoid() && returnExpr ession != null) { 5283 if (expectedReturnType != null && !expectedReturnType.isVoid() && returnExpr ession != null) {
5261 Type2 actualReturnType = getType(returnExpression); 5284 Type2 actualReturnType = getType(returnExpression);
5262 if (!actualReturnType.isAssignableTo(expectedReturnType)) { 5285 if (!actualReturnType.isAssignableTo(expectedReturnType)) {
5263 _errorReporter.reportError(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [actualReturnType.name, expectedReturnType.name]); 5286 _errorReporter.reportError(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [actualReturnType.name, expectedReturnType.name]);
5264 } 5287 }
5265 } 5288 }
5266 return super.visitReturnStatement(node); 5289 return super.visitReturnStatement(node);
5267 } 5290 }
5291 Object visitTypeParameter(TypeParameter node) {
5292 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPE_VARIABLE_NAME);
5293 return super.visitTypeParameter(node);
5294 }
5295 Object visitVariableDeclarationList(VariableDeclarationList node) {
5296 TypeName typeName = node.type;
5297 if (typeName != null) {
5298 Identifier identifier = typeName.name;
5299 if (identifier is SimpleIdentifier) {
5300 SimpleIdentifier simpleIdentifier = identifier as SimpleIdentifier;
5301 Token token13 = simpleIdentifier.token;
5302 if (identical(token13.type, TokenType.KEYWORD)) {
5303 if (((token13 as KeywordToken)).keyword != Keyword.DYNAMIC) {
5304 _errorReporter.reportError(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_ AS_TYPE, identifier, [identifier.name]);
5305 }
5306 }
5307 }
5308 }
5309 return super.visitVariableDeclarationList(node);
5310 }
5268 Object visitWhileStatement(WhileStatement node) { 5311 Object visitWhileStatement(WhileStatement node) {
5269 checkForNonBoolCondition(node.condition); 5312 checkForNonBoolCondition(node.condition);
5270 return super.visitWhileStatement(node); 5313 return super.visitWhileStatement(node);
5271 } 5314 }
5272 /** 5315 /**
5316 * This verifies that the passed identifier is not a keyword, and generates th e passed error code
5317 * on the identifier if it is a keyword.
5318 * @param identifier the identifier to check to ensure that it is not a keywor d
5319 * @param errorCode if the passed identifier is a keyword then this error code is created on the
5320 * identifier, the error code will be one of{@link CompileTimeErrorCode#BUILT_ IN_IDENTIFIER_AS_TYPE_NAME},{@link CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_T YPE_VARIABLE_NAME} or{@link CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_ NAME}
5321 */
5322 void checkForBuiltInIdentifierAsName(SimpleIdentifier identifier, ErrorCode er rorCode) {
5323 Token token14 = identifier.token;
5324 if (identical(token14.type, TokenType.KEYWORD)) {
5325 _errorReporter.reportError(errorCode, identifier, [identifier.name]);
5326 }
5327 }
5328 /**
5273 * Checks to ensure that the expressions that need to be of type bool, are. Ot herwise an error is 5329 * Checks to ensure that the expressions that need to be of type bool, are. Ot herwise an error is
5274 * reported on the expression. 5330 * reported on the expression.
5275 * @see StaticTypeWarningCode#NON_BOOL_CONDITION 5331 * @see StaticTypeWarningCode#NON_BOOL_CONDITION
5276 * @param condition the conditional expression to test 5332 * @param condition the conditional expression to test
5277 */ 5333 */
5278 void checkForNonBoolCondition(Expression condition) { 5334 void checkForNonBoolCondition(Expression condition) {
5279 Type2 conditionType = getType(condition); 5335 Type2 conditionType = getType(condition);
5280 if (conditionType != null && !conditionType.isAssignableTo(_typeProvider.boo lType)) { 5336 if (conditionType != null && !conditionType.isAssignableTo(_typeProvider.boo lType)) {
5281 _errorReporter.reportError(StaticTypeWarningCode.NON_BOOL_CONDITION, condi tion, []); 5337 _errorReporter.reportError(StaticTypeWarningCode.NON_BOOL_CONDITION, condi tion, []);
5282 } 5338 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
5322 ResolverErrorCode(this.__name, this.__ordinal, ErrorType type, String message) { 5378 ResolverErrorCode(this.__name, this.__ordinal, ErrorType type, String message) {
5323 this._type = type; 5379 this._type = type;
5324 this._message = message; 5380 this._message = message;
5325 } 5381 }
5326 ErrorSeverity get errorSeverity => _type.severity; 5382 ErrorSeverity get errorSeverity => _type.severity;
5327 String get message => _message; 5383 String get message => _message;
5328 ErrorType get type => _type; 5384 ErrorType get type => _type;
5329 bool needsRecompilation() => true; 5385 bool needsRecompilation() => true;
5330 String toString() => __name; 5386 String toString() => __name;
5331 } 5387 }
OLDNEW
« no previous file with comments | « pkg/analyzer-experimental/lib/src/generated/parser.dart ('k') | pkg/analyzer-experimental/lib/src/generated/source.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698