OLD | NEW |
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 library engine.resolver; | 3 library engine.resolver; |
4 import 'dart:collection'; | 4 import 'dart:collection'; |
5 import 'java_core.dart'; | 5 import 'java_core.dart'; |
6 import 'java_engine.dart'; | 6 import 'java_engine.dart'; |
7 import 'instrumentation.dart'; | 7 import 'instrumentation.dart'; |
8 import 'source.dart'; | 8 import 'source.dart'; |
9 import 'error.dart'; | 9 import 'error.dart'; |
10 import 'scanner.dart' as sc; | 10 import 'scanner.dart' as sc; |
11 import 'utilities_dart.dart'; | 11 import 'utilities_dart.dart'; |
12 import 'ast.dart'; | 12 import 'ast.dart'; |
13 import 'parser.dart' show Parser, ParserErrorCode; | 13 import 'parser.dart' show Parser, ParserErrorCode; |
14 import 'sdk.dart' show DartSdk, SdkLibrary; | 14 import 'sdk.dart' show DartSdk, SdkLibrary; |
15 import 'element.dart'; | 15 import 'element.dart'; |
16 import 'html.dart' as ht; | 16 import 'html.dart' as ht; |
17 import 'engine.dart'; | 17 import 'engine.dart'; |
18 import 'constant.dart'; | 18 import 'constant.dart'; |
19 /** | 19 /** |
20 * Instances of the class `CompilationUnitBuilder` build an element model for a
single | 20 * Instances of the class `CompilationUnitBuilder` build an element model for a
single |
21 * compilation unit. | 21 * compilation unit. |
| 22 * |
22 * @coverage dart.engine.resolver | 23 * @coverage dart.engine.resolver |
23 */ | 24 */ |
24 class CompilationUnitBuilder { | 25 class CompilationUnitBuilder { |
25 | 26 |
26 /** | 27 /** |
27 * Build the compilation unit element for the given source. | 28 * Build the compilation unit element for the given source. |
| 29 * |
28 * @param source the source describing the compilation unit | 30 * @param source the source describing the compilation unit |
29 * @param unit the AST structure representing the compilation unit | 31 * @param unit the AST structure representing the compilation unit |
30 * @return the compilation unit element that was built | 32 * @return the compilation unit element that was built |
31 * @throws AnalysisException if the analysis could not be performed | 33 * @throws AnalysisException if the analysis could not be performed |
32 */ | 34 */ |
33 CompilationUnitElementImpl buildCompilationUnit(Source source2, CompilationUni
t unit) { | 35 CompilationUnitElementImpl buildCompilationUnit(Source source2, CompilationUni
t unit) { |
34 if (unit == null) { | 36 if (unit == null) { |
35 return null; | 37 return null; |
36 } | 38 } |
37 ElementHolder holder = new ElementHolder(); | 39 ElementHolder holder = new ElementHolder(); |
38 ElementBuilder builder = new ElementBuilder(holder); | 40 ElementBuilder builder = new ElementBuilder(holder); |
39 unit.accept(builder); | 41 unit.accept(builder); |
40 CompilationUnitElementImpl element = new CompilationUnitElementImpl(source2.
shortName); | 42 CompilationUnitElementImpl element = new CompilationUnitElementImpl(source2.
shortName); |
41 element.accessors = holder.accessors; | 43 element.accessors = holder.accessors; |
42 element.functions = holder.functions; | 44 element.functions = holder.functions; |
43 element.source = source2; | 45 element.source = source2; |
44 element.typeAliases = holder.typeAliases; | 46 element.typeAliases = holder.typeAliases; |
45 element.types = holder.types; | 47 element.types = holder.types; |
46 element.topLevelVariables = holder.topLevelVariables; | 48 element.topLevelVariables = holder.topLevelVariables; |
47 unit.element = element; | 49 unit.element = element; |
48 return element; | 50 return element; |
49 } | 51 } |
50 } | 52 } |
51 /** | 53 /** |
52 * Instances of the class `ElementBuilder` traverse an AST structure and build t
he element | 54 * Instances of the class `ElementBuilder` traverse an AST structure and build t
he element |
53 * model representing the AST structure. | 55 * model representing the AST structure. |
| 56 * |
54 * @coverage dart.engine.resolver | 57 * @coverage dart.engine.resolver |
55 */ | 58 */ |
56 class ElementBuilder extends RecursiveASTVisitor<Object> { | 59 class ElementBuilder extends RecursiveASTVisitor<Object> { |
57 | 60 |
58 /** | 61 /** |
59 * The element holder associated with the element that is currently being buil
t. | 62 * The element holder associated with the element that is currently being buil
t. |
60 */ | 63 */ |
61 ElementHolder _currentHolder; | 64 ElementHolder _currentHolder; |
62 | 65 |
63 /** | 66 /** |
(...skipping 13 matching lines...) Expand all Loading... |
77 | 80 |
78 /** | 81 /** |
79 * A collection holding the function types defined in a class that need to hav
e their type | 82 * A collection holding the function types defined in a class that need to hav
e their type |
80 * arguments set to the types of the type parameters for the class, or `null`
if we are not | 83 * arguments set to the types of the type parameters for the class, or `null`
if we are not |
81 * currently processing nodes within a class. | 84 * currently processing nodes within a class. |
82 */ | 85 */ |
83 List<FunctionTypeImpl> _functionTypesToFix = null; | 86 List<FunctionTypeImpl> _functionTypesToFix = null; |
84 | 87 |
85 /** | 88 /** |
86 * Initialize a newly created element builder to build the elements for a comp
ilation unit. | 89 * Initialize a newly created element builder to build the elements for a comp
ilation unit. |
| 90 * |
87 * @param initialHolder the element holder associated with the compilation uni
t being built | 91 * @param initialHolder the element holder associated with the compilation uni
t being built |
88 */ | 92 */ |
89 ElementBuilder(ElementHolder initialHolder) { | 93 ElementBuilder(ElementHolder initialHolder) { |
90 _currentHolder = initialHolder; | 94 _currentHolder = initialHolder; |
91 } | 95 } |
92 Object visitBlock(Block node) { | 96 Object visitBlock(Block node) { |
93 bool wasInField = _inFieldContext; | 97 bool wasInField = _inFieldContext; |
94 _inFieldContext = false; | 98 _inFieldContext = false; |
95 try { | 99 try { |
96 node.visitChildren(this); | 100 node.visitChildren(this); |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 setter.static = variable.isStatic; | 603 setter.static = variable.isStatic; |
600 _currentHolder.addAccessor(setter); | 604 _currentHolder.addAccessor(setter); |
601 variable.setter = setter; | 605 variable.setter = setter; |
602 } | 606 } |
603 } | 607 } |
604 return null; | 608 return null; |
605 } | 609 } |
606 | 610 |
607 /** | 611 /** |
608 * Creates the [ConstructorElement]s array with the single default constructor
element. | 612 * Creates the [ConstructorElement]s array with the single default constructor
element. |
| 613 * |
609 * @param interfaceType the interface type for which to create a default const
ructor | 614 * @param interfaceType the interface type for which to create a default const
ructor |
610 * @return the [ConstructorElement]s array with the single default constructor
element | 615 * @return the [ConstructorElement]s array with the single default constructor
element |
611 */ | 616 */ |
612 List<ConstructorElement> createDefaultConstructors(InterfaceTypeImpl interface
Type) { | 617 List<ConstructorElement> createDefaultConstructors(InterfaceTypeImpl interface
Type) { |
613 ConstructorElementImpl constructor = new ConstructorElementImpl(null); | 618 ConstructorElementImpl constructor = new ConstructorElementImpl(null); |
614 constructor.synthetic = true; | 619 constructor.synthetic = true; |
615 constructor.returnType = interfaceType; | 620 constructor.returnType = interfaceType; |
616 FunctionTypeImpl type = new FunctionTypeImpl.con1(constructor); | 621 FunctionTypeImpl type = new FunctionTypeImpl.con1(constructor); |
617 _functionTypesToFix.add(type); | 622 _functionTypesToFix.add(type); |
618 constructor.type = type; | 623 constructor.type = type; |
619 return <ConstructorElement> [constructor]; | 624 return <ConstructorElement> [constructor]; |
620 } | 625 } |
621 | 626 |
622 /** | 627 /** |
623 * Create the types associated with the given type variables, setting the type
of each type | 628 * Create the types associated with the given type variables, setting the type
of each type |
624 * variable, and return an array of types corresponding to the given variables
. | 629 * variable, and return an array of types corresponding to the given variables
. |
| 630 * |
625 * @param typeVariables the type variables for which types are to be created | 631 * @param typeVariables the type variables for which types are to be created |
626 * @return | 632 * @return |
627 */ | 633 */ |
628 List<Type2> createTypeVariableTypes(List<TypeVariableElement> typeVariables) { | 634 List<Type2> createTypeVariableTypes(List<TypeVariableElement> typeVariables) { |
629 int typeVariableCount = typeVariables.length; | 635 int typeVariableCount = typeVariables.length; |
630 List<Type2> typeArguments = new List<Type2>(typeVariableCount); | 636 List<Type2> typeArguments = new List<Type2>(typeVariableCount); |
631 for (int i = 0; i < typeVariableCount; i++) { | 637 for (int i = 0; i < typeVariableCount; i++) { |
632 TypeVariableElementImpl typeVariable = typeVariables[i] as TypeVariableEle
mentImpl; | 638 TypeVariableElementImpl typeVariable = typeVariables[i] as TypeVariableEle
mentImpl; |
633 TypeVariableTypeImpl typeArgument = new TypeVariableTypeImpl(typeVariable)
; | 639 TypeVariableTypeImpl typeArgument = new TypeVariableTypeImpl(typeVariable)
; |
634 typeVariable.type = typeArgument; | 640 typeVariable.type = typeArgument; |
635 typeArguments[i] = typeArgument; | 641 typeArguments[i] = typeArgument; |
636 } | 642 } |
637 return typeArguments; | 643 return typeArguments; |
638 } | 644 } |
639 | 645 |
640 /** | 646 /** |
641 * Return the body of the function that contains the given parameter, or `null
` if no | 647 * Return the body of the function that contains the given parameter, or `null
` if no |
642 * function body could be found. | 648 * function body could be found. |
| 649 * |
643 * @param node the parameter contained in the function whose body is to be ret
urned | 650 * @param node the parameter contained in the function whose body is to be ret
urned |
644 * @return the body of the function that contains the given parameter | 651 * @return the body of the function that contains the given parameter |
645 */ | 652 */ |
646 FunctionBody getFunctionBody(FormalParameter node) { | 653 FunctionBody getFunctionBody(FormalParameter node) { |
647 ASTNode parent = node.parent; | 654 ASTNode parent = node.parent; |
648 while (parent != null) { | 655 while (parent != null) { |
649 if (parent is FunctionExpression) { | 656 if (parent is FunctionExpression) { |
650 return ((parent as FunctionExpression)).body; | 657 return ((parent as FunctionExpression)).body; |
651 } else if (parent is MethodDeclaration) { | 658 } else if (parent is MethodDeclaration) { |
652 return ((parent as MethodDeclaration)).body; | 659 return ((parent as MethodDeclaration)).body; |
653 } | 660 } |
654 parent = parent.parent; | 661 parent = parent.parent; |
655 } | 662 } |
656 return null; | 663 return null; |
657 } | 664 } |
658 | 665 |
659 /** | 666 /** |
660 * Return `true` if the given token is a token for the given keyword. | 667 * Return `true` if the given token is a token for the given keyword. |
| 668 * |
661 * @param token the token being tested | 669 * @param token the token being tested |
662 * @param keyword the keyword being tested for | 670 * @param keyword the keyword being tested for |
663 * @return `true` if the given token is a token for the given keyword | 671 * @return `true` if the given token is a token for the given keyword |
664 */ | 672 */ |
665 bool matches(sc.Token token, sc.Keyword keyword2) => token != null && identica
l(token.type, sc.TokenType.KEYWORD) && identical(((token as sc.KeywordToken)).ke
yword, keyword2); | 673 bool matches(sc.Token token, sc.Keyword keyword2) => token != null && identica
l(token.type, sc.TokenType.KEYWORD) && identical(((token as sc.KeywordToken)).ke
yword, keyword2); |
666 | 674 |
667 /** | 675 /** |
668 * Make the given holder be the current holder while visiting the given node. | 676 * Make the given holder be the current holder while visiting the given node. |
| 677 * |
669 * @param holder the holder that will gather elements that are built while vis
iting the children | 678 * @param holder the holder that will gather elements that are built while vis
iting the children |
670 * @param node the node to be visited | 679 * @param node the node to be visited |
671 */ | 680 */ |
672 void visit(ElementHolder holder, ASTNode node) { | 681 void visit(ElementHolder holder, ASTNode node) { |
673 if (node != null) { | 682 if (node != null) { |
674 ElementHolder previousHolder = _currentHolder; | 683 ElementHolder previousHolder = _currentHolder; |
675 _currentHolder = holder; | 684 _currentHolder = holder; |
676 try { | 685 try { |
677 node.accept(this); | 686 node.accept(this); |
678 } finally { | 687 } finally { |
679 _currentHolder = previousHolder; | 688 _currentHolder = previousHolder; |
680 } | 689 } |
681 } | 690 } |
682 } | 691 } |
683 | 692 |
684 /** | 693 /** |
685 * Make the given holder be the current holder while visiting the children of
the given node. | 694 * Make the given holder be the current holder while visiting the children of
the given node. |
| 695 * |
686 * @param holder the holder that will gather elements that are built while vis
iting the children | 696 * @param holder the holder that will gather elements that are built while vis
iting the children |
687 * @param node the node whose children are to be visited | 697 * @param node the node whose children are to be visited |
688 */ | 698 */ |
689 void visitChildren(ElementHolder holder, ASTNode node) { | 699 void visitChildren(ElementHolder holder, ASTNode node) { |
690 if (node != null) { | 700 if (node != null) { |
691 ElementHolder previousHolder = _currentHolder; | 701 ElementHolder previousHolder = _currentHolder; |
692 _currentHolder = holder; | 702 _currentHolder = holder; |
693 try { | 703 try { |
694 node.visitChildren(this); | 704 node.visitChildren(this); |
695 } finally { | 705 } finally { |
696 _currentHolder = previousHolder; | 706 _currentHolder = previousHolder; |
697 } | 707 } |
698 } | 708 } |
699 } | 709 } |
700 } | 710 } |
701 /** | 711 /** |
702 * Instances of the class `ElementHolder` hold on to elements created while trav
ersing an AST | 712 * Instances of the class `ElementHolder` hold on to elements created while trav
ersing an AST |
703 * structure so that they can be accessed when creating their enclosing element. | 713 * structure so that they can be accessed when creating their enclosing element. |
| 714 * |
704 * @coverage dart.engine.resolver | 715 * @coverage dart.engine.resolver |
705 */ | 716 */ |
706 class ElementHolder { | 717 class ElementHolder { |
707 List<PropertyAccessorElement> _accessors; | 718 List<PropertyAccessorElement> _accessors; |
708 List<ConstructorElement> _constructors; | 719 List<ConstructorElement> _constructors; |
709 List<FieldElement> _fields; | 720 List<FieldElement> _fields; |
710 List<FunctionElement> _functions; | 721 List<FunctionElement> _functions; |
711 List<LabelElement> _labels; | 722 List<LabelElement> _labels; |
712 List<VariableElement> _localVariables; | 723 List<VariableElement> _localVariables; |
713 List<MethodElement> _methods; | 724 List<MethodElement> _methods; |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 * The analysis context in which the element model will be built. | 1008 * The analysis context in which the element model will be built. |
998 */ | 1009 */ |
999 InternalAnalysisContext _context; | 1010 InternalAnalysisContext _context; |
1000 | 1011 |
1001 /** | 1012 /** |
1002 * The error listener to which errors will be reported. | 1013 * The error listener to which errors will be reported. |
1003 */ | 1014 */ |
1004 RecordingErrorListener _errorListener; | 1015 RecordingErrorListener _errorListener; |
1005 | 1016 |
1006 /** | 1017 /** |
1007 * The line information associated with the source for which an element is bei
ng built, or`null` if we are not building an element. | 1018 * The line information associated with the source for which an element is bei
ng built, or |
| 1019 * `null` if we are not building an element. |
1008 */ | 1020 */ |
1009 LineInfo _lineInfo; | 1021 LineInfo _lineInfo; |
1010 | 1022 |
1011 /** | 1023 /** |
1012 * The HTML element being built. | 1024 * The HTML element being built. |
1013 */ | 1025 */ |
1014 HtmlElementImpl _htmlElement; | 1026 HtmlElementImpl _htmlElement; |
1015 | 1027 |
1016 /** | 1028 /** |
1017 * The elements in the path from the HTML unit to the current tag node. | 1029 * The elements in the path from the HTML unit to the current tag node. |
1018 */ | 1030 */ |
1019 List<ht.XmlTagNode> _parentNodes; | 1031 List<ht.XmlTagNode> _parentNodes; |
1020 | 1032 |
1021 /** | 1033 /** |
1022 * The script elements being built. | 1034 * The script elements being built. |
1023 */ | 1035 */ |
1024 List<HtmlScriptElement> _scripts; | 1036 List<HtmlScriptElement> _scripts; |
1025 | 1037 |
1026 /** | 1038 /** |
1027 * A set of the libraries that were resolved while resolving the HTML unit. | 1039 * A set of the libraries that were resolved while resolving the HTML unit. |
1028 */ | 1040 */ |
1029 Set<Library> _resolvedLibraries = new Set<Library>(); | 1041 Set<Library> _resolvedLibraries = new Set<Library>(); |
1030 | 1042 |
1031 /** | 1043 /** |
1032 * Initialize a newly created HTML unit builder. | 1044 * Initialize a newly created HTML unit builder. |
| 1045 * |
1033 * @param context the analysis context in which the element model will be buil
t | 1046 * @param context the analysis context in which the element model will be buil
t |
1034 */ | 1047 */ |
1035 HtmlUnitBuilder(InternalAnalysisContext context) { | 1048 HtmlUnitBuilder(InternalAnalysisContext context) { |
1036 this._context = context; | 1049 this._context = context; |
1037 this._errorListener = new RecordingErrorListener(); | 1050 this._errorListener = new RecordingErrorListener(); |
1038 } | 1051 } |
1039 | 1052 |
1040 /** | 1053 /** |
1041 * Build the HTML element for the given source. | 1054 * Build the HTML element for the given source. |
| 1055 * |
1042 * @param source the source describing the compilation unit | 1056 * @param source the source describing the compilation unit |
1043 * @return the HTML element that was built | 1057 * @return the HTML element that was built |
1044 * @throws AnalysisException if the analysis could not be performed | 1058 * @throws AnalysisException if the analysis could not be performed |
1045 */ | 1059 */ |
1046 HtmlElementImpl buildHtmlElement(Source source) => buildHtmlElement2(source, _
context.parseHtmlUnit(source)); | 1060 HtmlElementImpl buildHtmlElement(Source source) => buildHtmlElement2(source, _
context.parseHtmlUnit(source)); |
1047 | 1061 |
1048 /** | 1062 /** |
1049 * Build the HTML element for the given source. | 1063 * Build the HTML element for the given source. |
| 1064 * |
1050 * @param source the source describing the compilation unit | 1065 * @param source the source describing the compilation unit |
1051 * @param unit the AST structure representing the HTML | 1066 * @param unit the AST structure representing the HTML |
1052 * @throws AnalysisException if the analysis could not be performed | 1067 * @throws AnalysisException if the analysis could not be performed |
1053 */ | 1068 */ |
1054 HtmlElementImpl buildHtmlElement2(Source source2, ht.HtmlUnit unit) { | 1069 HtmlElementImpl buildHtmlElement2(Source source2, ht.HtmlUnit unit) { |
1055 _lineInfo = _context.computeLineInfo(source2); | 1070 _lineInfo = _context.computeLineInfo(source2); |
1056 HtmlElementImpl result = new HtmlElementImpl(_context, source2.shortName); | 1071 HtmlElementImpl result = new HtmlElementImpl(_context, source2.shortName); |
1057 result.source = source2; | 1072 result.source = source2; |
1058 _htmlElement = result; | 1073 _htmlElement = result; |
1059 unit.accept(this); | 1074 unit.accept(this); |
1060 _htmlElement = null; | 1075 _htmlElement = null; |
1061 unit.element = result; | 1076 unit.element = result; |
1062 return result; | 1077 return result; |
1063 } | 1078 } |
1064 | 1079 |
1065 /** | 1080 /** |
1066 * Return the listener to which analysis errors will be reported. | 1081 * Return the listener to which analysis errors will be reported. |
| 1082 * |
1067 * @return the listener to which analysis errors will be reported | 1083 * @return the listener to which analysis errors will be reported |
1068 */ | 1084 */ |
1069 RecordingErrorListener get errorListener => _errorListener; | 1085 RecordingErrorListener get errorListener => _errorListener; |
1070 | 1086 |
1071 /** | 1087 /** |
1072 * Return an array containing information about all of the libraries that were
resolved. | 1088 * Return an array containing information about all of the libraries that were
resolved. |
| 1089 * |
1073 * @return an array containing the libraries that were resolved | 1090 * @return an array containing the libraries that were resolved |
1074 */ | 1091 */ |
1075 Set<Library> get resolvedLibraries => _resolvedLibraries; | 1092 Set<Library> get resolvedLibraries => _resolvedLibraries; |
1076 Object visitHtmlUnit(ht.HtmlUnit node) { | 1093 Object visitHtmlUnit(ht.HtmlUnit node) { |
1077 _parentNodes = new List<ht.XmlTagNode>(); | 1094 _parentNodes = new List<ht.XmlTagNode>(); |
1078 _scripts = new List<HtmlScriptElement>(); | 1095 _scripts = new List<HtmlScriptElement>(); |
1079 try { | 1096 try { |
1080 node.visitChildren(this); | 1097 node.visitChildren(this); |
1081 _htmlElement.scripts = new List.from(_scripts); | 1098 _htmlElement.scripts = new List.from(_scripts); |
1082 } finally { | 1099 } finally { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 node.visitChildren(this); | 1174 node.visitChildren(this); |
1158 } | 1175 } |
1159 } finally { | 1176 } finally { |
1160 _parentNodes.remove(node); | 1177 _parentNodes.remove(node); |
1161 } | 1178 } |
1162 return null; | 1179 return null; |
1163 } | 1180 } |
1164 | 1181 |
1165 /** | 1182 /** |
1166 * Return the first source attribute for the given tag node, or `null` if it d
oes not exist. | 1183 * Return the first source attribute for the given tag node, or `null` if it d
oes not exist. |
| 1184 * |
1167 * @param node the node containing attributes | 1185 * @param node the node containing attributes |
1168 * @return the source attribute contained in the given tag | 1186 * @return the source attribute contained in the given tag |
1169 */ | 1187 */ |
1170 ht.XmlAttributeNode getScriptSourcePath(ht.XmlTagNode node) { | 1188 ht.XmlAttributeNode getScriptSourcePath(ht.XmlTagNode node) { |
1171 for (ht.XmlAttributeNode attribute in node.attributes) { | 1189 for (ht.XmlAttributeNode attribute in node.attributes) { |
1172 if (attribute.name.lexeme == _SRC) { | 1190 if (attribute.name.lexeme == _SRC) { |
1173 return attribute; | 1191 return attribute; |
1174 } | 1192 } |
1175 } | 1193 } |
1176 return null; | 1194 return null; |
1177 } | 1195 } |
1178 | 1196 |
1179 /** | 1197 /** |
1180 * Determine if the specified node is a Dart script. | 1198 * Determine if the specified node is a Dart script. |
| 1199 * |
1181 * @param node the node to be tested (not `null`) | 1200 * @param node the node to be tested (not `null`) |
1182 * @return `true` if the node is a Dart script | 1201 * @return `true` if the node is a Dart script |
1183 */ | 1202 */ |
1184 bool isScriptNode(ht.XmlTagNode node) { | 1203 bool isScriptNode(ht.XmlTagNode node) { |
1185 if (node.tagNodes.length != 0 || node.tag.lexeme != _SCRIPT) { | 1204 if (node.tagNodes.length != 0 || node.tag.lexeme != _SCRIPT) { |
1186 return false; | 1205 return false; |
1187 } | 1206 } |
1188 for (ht.XmlAttributeNode attribute in node.attributes) { | 1207 for (ht.XmlAttributeNode attribute in node.attributes) { |
1189 if (attribute.name.lexeme == _TYPE) { | 1208 if (attribute.name.lexeme == _TYPE) { |
1190 ht.Token valueToken = attribute.value; | 1209 ht.Token valueToken = attribute.value; |
1191 if (valueToken != null) { | 1210 if (valueToken != null) { |
1192 String value = valueToken.lexeme; | 1211 String value = valueToken.lexeme; |
1193 if (value == _APPLICATION_DART_IN_DOUBLE_QUOTES || value == _APPLICATI
ON_DART_IN_SINGLE_QUOTES) { | 1212 if (value == _APPLICATION_DART_IN_DOUBLE_QUOTES || value == _APPLICATI
ON_DART_IN_SINGLE_QUOTES) { |
1194 return true; | 1213 return true; |
1195 } | 1214 } |
1196 } | 1215 } |
1197 } | 1216 } |
1198 } | 1217 } |
1199 return false; | 1218 return false; |
1200 } | 1219 } |
1201 | 1220 |
1202 /** | 1221 /** |
1203 * Report an error with the given error code at the given location. Use the gi
ven arguments to | 1222 * Report an error with the given error code at the given location. Use the gi
ven arguments to |
1204 * compose the error message. | 1223 * compose the error message. |
| 1224 * |
1205 * @param errorCode the error code of the error to be reported | 1225 * @param errorCode the error code of the error to be reported |
1206 * @param offset the offset of the first character to be highlighted | 1226 * @param offset the offset of the first character to be highlighted |
1207 * @param length the number of characters to be highlighted | 1227 * @param length the number of characters to be highlighted |
1208 * @param arguments the arguments used to compose the error message | 1228 * @param arguments the arguments used to compose the error message |
1209 */ | 1229 */ |
1210 void reportError(ErrorCode errorCode, int offset, int length, List<Object> arg
uments) { | 1230 void reportError(ErrorCode errorCode, int offset, int length, List<Object> arg
uments) { |
1211 _errorListener.onError(new AnalysisError.con2(_htmlElement.source, offset, l
ength, errorCode, arguments)); | 1231 _errorListener.onError(new AnalysisError.con2(_htmlElement.source, offset, l
ength, errorCode, arguments)); |
1212 } | 1232 } |
1213 } | 1233 } |
1214 /** | 1234 /** |
(...skipping 27 matching lines...) Expand all Loading... |
1242 | 1262 |
1243 /** | 1263 /** |
1244 * The parameter containing the AST nodes being visited, or `null` if we are n
ot in the | 1264 * The parameter containing the AST nodes being visited, or `null` if we are n
ot in the |
1245 * scope of a parameter. | 1265 * scope of a parameter. |
1246 */ | 1266 */ |
1247 ParameterElement _enclosingParameter; | 1267 ParameterElement _enclosingParameter; |
1248 | 1268 |
1249 /** | 1269 /** |
1250 * Resolve the declarations within the given compilation unit to the elements
rooted at the given | 1270 * Resolve the declarations within the given compilation unit to the elements
rooted at the given |
1251 * element. | 1271 * element. |
| 1272 * |
1252 * @param unit the compilation unit to be resolved | 1273 * @param unit the compilation unit to be resolved |
1253 * @param element the root of the element model used to resolve the AST nodes | 1274 * @param element the root of the element model used to resolve the AST nodes |
1254 */ | 1275 */ |
1255 void resolve(CompilationUnit unit, CompilationUnitElement element2) { | 1276 void resolve(CompilationUnit unit, CompilationUnitElement element2) { |
1256 _enclosingUnit = element2; | 1277 _enclosingUnit = element2; |
1257 unit.element = element2; | 1278 unit.element = element2; |
1258 unit.accept(this); | 1279 unit.accept(this); |
1259 } | 1280 } |
1260 Object visitCatchClause(CatchClause node) { | 1281 Object visitCatchClause(CatchClause node) { |
1261 SimpleIdentifier exceptionParameter = node.exceptionParameter; | 1282 SimpleIdentifier exceptionParameter = node.exceptionParameter; |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1562 return super.visitVariableDeclaration(node); | 1583 return super.visitVariableDeclaration(node); |
1563 } finally { | 1584 } finally { |
1564 _enclosingExecutable = outerExecutable; | 1585 _enclosingExecutable = outerExecutable; |
1565 } | 1586 } |
1566 } | 1587 } |
1567 return super.visitVariableDeclaration(node); | 1588 return super.visitVariableDeclaration(node); |
1568 } | 1589 } |
1569 | 1590 |
1570 /** | 1591 /** |
1571 * Append the value of the given string literal to the given string builder. | 1592 * Append the value of the given string literal to the given string builder. |
| 1593 * |
1572 * @param builder the builder to which the string's value is to be appended | 1594 * @param builder the builder to which the string's value is to be appended |
1573 * @param literal the string literal whose value is to be appended to the buil
der | 1595 * @param literal the string literal whose value is to be appended to the buil
der |
1574 * @throws IllegalArgumentException if the string is not a constant string wit
hout any string | 1596 * @throws IllegalArgumentException if the string is not a constant string wit
hout any string |
1575 * interpolation | 1597 * interpolation |
1576 */ | 1598 */ |
1577 void appendStringValue(JavaStringBuilder builder, StringLiteral literal) { | 1599 void appendStringValue(JavaStringBuilder builder, StringLiteral literal) { |
1578 if (literal is SimpleStringLiteral) { | 1600 if (literal is SimpleStringLiteral) { |
1579 builder.append(((literal as SimpleStringLiteral)).value); | 1601 builder.append(((literal as SimpleStringLiteral)).value); |
1580 } else if (literal is AdjacentStrings) { | 1602 } else if (literal is AdjacentStrings) { |
1581 for (StringLiteral stringLiteral in ((literal as AdjacentStrings)).strings
) { | 1603 for (StringLiteral stringLiteral in ((literal as AdjacentStrings)).strings
) { |
1582 appendStringValue(builder, stringLiteral); | 1604 appendStringValue(builder, stringLiteral); |
1583 } | 1605 } |
1584 } else { | 1606 } else { |
1585 throw new IllegalArgumentException(); | 1607 throw new IllegalArgumentException(); |
1586 } | 1608 } |
1587 } | 1609 } |
1588 | 1610 |
1589 /** | 1611 /** |
1590 * Return the element for the part with the given source, or `null` if there i
s no element | 1612 * Return the element for the part with the given source, or `null` if there i
s no element |
1591 * for the given source. | 1613 * for the given source. |
| 1614 * |
1592 * @param parts the elements for the parts | 1615 * @param parts the elements for the parts |
1593 * @param partSource the source for the part whose element is to be returned | 1616 * @param partSource the source for the part whose element is to be returned |
1594 * @return the element for the part with the given source | 1617 * @return the element for the part with the given source |
1595 */ | 1618 */ |
1596 CompilationUnitElement find(List<CompilationUnitElement> parts, Source partSou
rce) { | 1619 CompilationUnitElement find(List<CompilationUnitElement> parts, Source partSou
rce) { |
1597 for (CompilationUnitElement part in parts) { | 1620 for (CompilationUnitElement part in parts) { |
1598 if (part.source == partSource) { | 1621 if (part.source == partSource) { |
1599 return part; | 1622 return part; |
1600 } | 1623 } |
1601 } | 1624 } |
1602 return null; | 1625 return null; |
1603 } | 1626 } |
1604 | 1627 |
1605 /** | 1628 /** |
1606 * Return the element in the given array of elements that was created for the
declaration at the | 1629 * Return the element in the given array of elements that was created for the
declaration at the |
1607 * given offset. This method should only be used when there is no name | 1630 * given offset. This method should only be used when there is no name |
| 1631 * |
1608 * @param elements the elements of the appropriate kind that exist in the curr
ent context | 1632 * @param elements the elements of the appropriate kind that exist in the curr
ent context |
1609 * @param offset the offset of the name of the element to be returned | 1633 * @param offset the offset of the name of the element to be returned |
1610 * @return the element at the given offset | 1634 * @return the element at the given offset |
1611 */ | 1635 */ |
1612 Element find2(List<Element> elements, int offset) => find4(elements, "", offse
t); | 1636 Element find2(List<Element> elements, int offset) => find4(elements, "", offse
t); |
1613 | 1637 |
1614 /** | 1638 /** |
1615 * Return the element in the given array of elements that was created for the
declaration with the | 1639 * Return the element in the given array of elements that was created for the
declaration with the |
1616 * given name. | 1640 * given name. |
| 1641 * |
1617 * @param elements the elements of the appropriate kind that exist in the curr
ent context | 1642 * @param elements the elements of the appropriate kind that exist in the curr
ent context |
1618 * @param identifier the name node in the declaration of the element to be ret
urned | 1643 * @param identifier the name node in the declaration of the element to be ret
urned |
1619 * @return the element created for the declaration with the given name | 1644 * @return the element created for the declaration with the given name |
1620 */ | 1645 */ |
1621 Element find3(List<Element> elements, SimpleIdentifier identifier) { | 1646 Element find3(List<Element> elements, SimpleIdentifier identifier) { |
1622 Element element = find4(elements, identifier.name, identifier.offset); | 1647 Element element = find4(elements, identifier.name, identifier.offset); |
1623 identifier.element = element; | 1648 identifier.element = element; |
1624 return element; | 1649 return element; |
1625 } | 1650 } |
1626 | 1651 |
1627 /** | 1652 /** |
1628 * Return the element in the given array of elements that was created for the
declaration with the | 1653 * Return the element in the given array of elements that was created for the
declaration with the |
1629 * given name at the given offset. | 1654 * given name at the given offset. |
| 1655 * |
1630 * @param elements the elements of the appropriate kind that exist in the curr
ent context | 1656 * @param elements the elements of the appropriate kind that exist in the curr
ent context |
1631 * @param name the name of the element to be returned | 1657 * @param name the name of the element to be returned |
1632 * @param offset the offset of the name of the element to be returned | 1658 * @param offset the offset of the name of the element to be returned |
1633 * @return the element with the given name and offset | 1659 * @return the element with the given name and offset |
1634 */ | 1660 */ |
1635 Element find4(List<Element> elements, String name, int offset) { | 1661 Element find4(List<Element> elements, String name, int offset) { |
1636 for (Element element in elements) { | 1662 for (Element element in elements) { |
1637 if (element.displayName == name && element.nameOffset == offset) { | 1663 if (element.displayName == name && element.nameOffset == offset) { |
1638 return element; | 1664 return element; |
1639 } | 1665 } |
1640 } | 1666 } |
1641 return null; | 1667 return null; |
1642 } | 1668 } |
1643 | 1669 |
1644 /** | 1670 /** |
1645 * Return the export element from the given array whose library has the given
source, or`null` if there is no such export. | 1671 * Return the export element from the given array whose library has the given
source, or |
| 1672 * `null` if there is no such export. |
| 1673 * |
1646 * @param exports the export elements being searched | 1674 * @param exports the export elements being searched |
1647 * @param source the source of the library associated with the export element
to being searched | 1675 * @param source the source of the library associated with the export element
to being searched |
1648 * for | 1676 * for |
1649 * @return the export element whose library has the given source | 1677 * @return the export element whose library has the given source |
1650 */ | 1678 */ |
1651 ExportElement find5(List<ExportElement> exports, Source source2) { | 1679 ExportElement find5(List<ExportElement> exports, Source source2) { |
1652 for (ExportElement export in exports) { | 1680 for (ExportElement export in exports) { |
1653 if (export.exportedLibrary.source == source2) { | 1681 if (export.exportedLibrary.source == source2) { |
1654 return export; | 1682 return export; |
1655 } | 1683 } |
1656 } | 1684 } |
1657 return null; | 1685 return null; |
1658 } | 1686 } |
1659 | 1687 |
1660 /** | 1688 /** |
1661 * Return the import element from the given array whose library has the given
source and that has | 1689 * Return the import element from the given array whose library has the given
source and that has |
1662 * the given prefix, or `null` if there is no such import. | 1690 * the given prefix, or `null` if there is no such import. |
| 1691 * |
1663 * @param imports the import elements being searched | 1692 * @param imports the import elements being searched |
1664 * @param source the source of the library associated with the import element
to being searched | 1693 * @param source the source of the library associated with the import element
to being searched |
1665 * for | 1694 * for |
1666 * @param prefix the prefix with which the library was imported | 1695 * @param prefix the prefix with which the library was imported |
1667 * @return the import element whose library has the given source and prefix | 1696 * @return the import element whose library has the given source and prefix |
1668 */ | 1697 */ |
1669 ImportElement find6(List<ImportElement> imports, Source source2, SimpleIdentif
ier prefix2) { | 1698 ImportElement find6(List<ImportElement> imports, Source source2, SimpleIdentif
ier prefix2) { |
1670 for (ImportElement element in imports) { | 1699 for (ImportElement element in imports) { |
1671 if (element.importedLibrary.source == source2) { | 1700 if (element.importedLibrary.source == source2) { |
1672 PrefixElement prefixElement = element.prefix; | 1701 PrefixElement prefixElement = element.prefix; |
1673 if (prefix2 == null) { | 1702 if (prefix2 == null) { |
1674 if (prefixElement == null) { | 1703 if (prefixElement == null) { |
1675 return element; | 1704 return element; |
1676 } | 1705 } |
1677 } else { | 1706 } else { |
1678 if (prefixElement != null && prefix2.name == prefixElement.displayName
) { | 1707 if (prefixElement != null && prefix2.name == prefixElement.displayName
) { |
1679 return element; | 1708 return element; |
1680 } | 1709 } |
1681 } | 1710 } |
1682 } | 1711 } |
1683 } | 1712 } |
1684 return null; | 1713 return null; |
1685 } | 1714 } |
1686 | 1715 |
1687 /** | 1716 /** |
1688 * Return the value of the given string literal, or `null` if the string is no
t a constant | 1717 * Return the value of the given string literal, or `null` if the string is no
t a constant |
1689 * string without any string interpolation. | 1718 * string without any string interpolation. |
| 1719 * |
1690 * @param literal the string literal whose value is to be returned | 1720 * @param literal the string literal whose value is to be returned |
1691 * @return the value of the given string literal | 1721 * @return the value of the given string literal |
1692 */ | 1722 */ |
1693 String getStringValue(StringLiteral literal) { | 1723 String getStringValue(StringLiteral literal) { |
1694 if (literal is StringInterpolation) { | 1724 if (literal is StringInterpolation) { |
1695 return null; | 1725 return null; |
1696 } | 1726 } |
1697 JavaStringBuilder builder = new JavaStringBuilder(); | 1727 JavaStringBuilder builder = new JavaStringBuilder(); |
1698 try { | 1728 try { |
1699 appendStringValue(builder, literal); | 1729 appendStringValue(builder, literal); |
1700 } on IllegalArgumentException catch (exception) { | 1730 } on IllegalArgumentException catch (exception) { |
1701 return null; | 1731 return null; |
1702 } | 1732 } |
1703 return builder.toString().trim(); | 1733 return builder.toString().trim(); |
1704 } | 1734 } |
1705 } | 1735 } |
1706 /** | 1736 /** |
1707 * Instances of the class `ElementResolver` are used by instances of [ResolverVi
sitor]to resolve references within the AST structure to the elements being refer
enced. The requirements | 1737 * Instances of the class `ElementResolver` are used by instances of [ResolverVi
sitor] |
| 1738 * to resolve references within the AST structure to the elements being referenc
ed. The requirements |
1708 * for the element resolver are: | 1739 * for the element resolver are: |
1709 * <ol> | 1740 * <ol> |
1710 * * Every [SimpleIdentifier] should be resolved to the element to which it refe
rs. | 1741 * * Every [SimpleIdentifier] should be resolved to the element to which it refe
rs. |
1711 * Specifically: | 1742 * Specifically: |
1712 * | 1743 * |
1713 * * An identifier within the declaration of that name should resolve to the ele
ment being | 1744 * * An identifier within the declaration of that name should resolve to the ele
ment being |
1714 * declared. | 1745 * declared. |
1715 * * An identifier denoting a prefix should resolve to the element representing
the import that | 1746 * * An identifier denoting a prefix should resolve to the element representing
the import that |
1716 * defines the prefix (an [ImportElement]). | 1747 * defines the prefix (an [ImportElement]). |
1717 * * An identifier denoting a variable should resolve to the element representin
g the variable (a[VariableElement]). | 1748 * * An identifier denoting a variable should resolve to the element representin
g the variable (a |
| 1749 * [VariableElement]). |
1718 * * An identifier denoting a parameter should resolve to the element representi
ng the parameter | 1750 * * An identifier denoting a parameter should resolve to the element representi
ng the parameter |
1719 * (a [ParameterElement]). | 1751 * (a [ParameterElement]). |
1720 * * An identifier denoting a field should resolve to the element representing t
he getter or | 1752 * * An identifier denoting a field should resolve to the element representing t
he getter or |
1721 * setter being invoked (a [PropertyAccessorElement]). | 1753 * setter being invoked (a [PropertyAccessorElement]). |
1722 * * An identifier denoting the name of a method or function being invoked shoul
d resolve to the | 1754 * * An identifier denoting the name of a method or function being invoked shoul
d resolve to the |
1723 * element representing the method or function (a [ExecutableElement]). | 1755 * element representing the method or function (a [ExecutableElement]). |
1724 * * An identifier denoting a label should resolve to the element representing t
he label (a[LabelElement]). | 1756 * * An identifier denoting a label should resolve to the element representing t
he label (a |
| 1757 * [LabelElement]). |
1725 * | 1758 * |
1726 * The identifiers within directives are exceptions to this rule and are covered
below. | 1759 * The identifiers within directives are exceptions to this rule and are covered
below. |
1727 * * Every node containing a token representing an operator that can be overridd
en ([BinaryExpression], [PrefixExpression], [PostfixExpression]) should resolve
to | 1760 * * Every node containing a token representing an operator that can be overridd
en ( |
| 1761 * [BinaryExpression], [PrefixExpression], [PostfixExpression]) should resolve t
o |
1728 * the element representing the method invoked by that operator (a [MethodElemen
t]). | 1762 * the element representing the method invoked by that operator (a [MethodElemen
t]). |
1729 * * Every [FunctionExpressionInvocation] should resolve to the element represen
ting the | 1763 * * Every [FunctionExpressionInvocation] should resolve to the element represen
ting the |
1730 * function being invoked (a [FunctionElement]). This will be the same element a
s that to | 1764 * function being invoked (a [FunctionElement]). This will be the same element a
s that to |
1731 * which the name is resolved if the function has a name, but is provided for th
ose cases where an | 1765 * which the name is resolved if the function has a name, but is provided for th
ose cases where an |
1732 * unnamed function is being invoked. | 1766 * unnamed function is being invoked. |
1733 * * Every [LibraryDirective] and [PartOfDirective] should resolve to the elemen
t | 1767 * * Every [LibraryDirective] and [PartOfDirective] should resolve to the elemen
t |
1734 * representing the library being specified by the directive (a [LibraryElement]
) unless, in | 1768 * representing the library being specified by the directive (a [LibraryElement]
) unless, in |
1735 * the case of a part-of directive, the specified library does not exist. | 1769 * the case of a part-of directive, the specified library does not exist. |
1736 * * Every [ImportDirective] and [ExportDirective] should resolve to the element | 1770 * * Every [ImportDirective] and [ExportDirective] should resolve to the element |
1737 * representing the library being specified by the directive unless the specifie
d library does not | 1771 * representing the library being specified by the directive unless the specifie
d library does not |
1738 * exist (an [ImportElement] or [ExportElement]). | 1772 * exist (an [ImportElement] or [ExportElement]). |
1739 * * The identifier representing the prefix in an [ImportDirective] should resol
ve to the | 1773 * * The identifier representing the prefix in an [ImportDirective] should resol
ve to the |
1740 * element representing the prefix (a [PrefixElement]). | 1774 * element representing the prefix (a [PrefixElement]). |
1741 * * The identifiers in the hide and show combinators in [ImportDirective]s and[
ExportDirective]s should resolve to the elements that are being hidden or shown, | 1775 * * The identifiers in the hide and show combinators in [ImportDirective]s and |
| 1776 * [ExportDirective]s should resolve to the elements that are being hidden or sh
own, |
1742 * respectively, unless those names are not defined in the specified library (or
the specified | 1777 * respectively, unless those names are not defined in the specified library (or
the specified |
1743 * library does not exist). | 1778 * library does not exist). |
1744 * * Every [PartDirective] should resolve to the element representing the compil
ation unit | 1779 * * Every [PartDirective] should resolve to the element representing the compil
ation unit |
1745 * being specified by the string unless the specified compilation unit does not
exist (a[CompilationUnitElement]). | 1780 * being specified by the string unless the specified compilation unit does not
exist (a |
| 1781 * [CompilationUnitElement]). |
1746 * </ol> | 1782 * </ol> |
1747 * Note that AST nodes that would represent elements that are not defined are no
t resolved to | 1783 * Note that AST nodes that would represent elements that are not defined are no
t resolved to |
1748 * anything. This includes such things as references to undeclared variables (wh
ich is an error) and | 1784 * anything. This includes such things as references to undeclared variables (wh
ich is an error) and |
1749 * names in hide and show combinators that are not defined in the imported libra
ry (which is not an | 1785 * names in hide and show combinators that are not defined in the imported libra
ry (which is not an |
1750 * error). | 1786 * error). |
| 1787 * |
1751 * @coverage dart.engine.resolver | 1788 * @coverage dart.engine.resolver |
1752 */ | 1789 */ |
1753 class ElementResolver extends SimpleASTVisitor<Object> { | 1790 class ElementResolver extends SimpleASTVisitor<Object> { |
1754 | 1791 |
1755 /** | 1792 /** |
1756 * @return `true` if the given identifier is the return type of a constructor
declaration. | 1793 * @return `true` if the given identifier is the return type of a constructor
declaration. |
1757 */ | 1794 */ |
1758 static bool isConstructorReturnType(SimpleIdentifier node) { | 1795 static bool isConstructorReturnType(SimpleIdentifier node) { |
1759 ASTNode parent = node.parent; | 1796 ASTNode parent = node.parent; |
1760 if (parent is ConstructorDeclaration) { | 1797 if (parent is ConstructorDeclaration) { |
1761 ConstructorDeclaration constructor = parent as ConstructorDeclaration; | 1798 ConstructorDeclaration constructor = parent as ConstructorDeclaration; |
1762 return identical(constructor.returnType, node); | 1799 return identical(constructor.returnType, node); |
1763 } | 1800 } |
1764 return false; | 1801 return false; |
1765 } | 1802 } |
1766 | 1803 |
1767 /** | 1804 /** |
1768 * @return `true` if the given identifier is the return type of a factory cons
tructor | 1805 * @return `true` if the given identifier is the return type of a factory cons
tructor |
1769 * declaration. | 1806 * declaration. |
1770 */ | 1807 */ |
1771 static bool isFactoryConstructorReturnType(SimpleIdentifier node) { | 1808 static bool isFactoryConstructorReturnType(SimpleIdentifier node) { |
1772 ASTNode parent = node.parent; | 1809 ASTNode parent = node.parent; |
1773 if (parent is ConstructorDeclaration) { | 1810 if (parent is ConstructorDeclaration) { |
1774 ConstructorDeclaration constructor = parent as ConstructorDeclaration; | 1811 ConstructorDeclaration constructor = parent as ConstructorDeclaration; |
1775 return identical(constructor.returnType, node) && constructor.factoryKeywo
rd != null; | 1812 return identical(constructor.returnType, node) && constructor.factoryKeywo
rd != null; |
1776 } | 1813 } |
1777 return false; | 1814 return false; |
1778 } | 1815 } |
1779 | 1816 |
1780 /** | 1817 /** |
1781 * Checks if the given 'super' expression is used in the valid context. | 1818 * Checks if the given 'super' expression is used in the valid context. |
| 1819 * |
1782 * @param node the 'super' expression to analyze | 1820 * @param node the 'super' expression to analyze |
1783 * @return `true` if the given 'super' expression is in the valid context | 1821 * @return `true` if the given 'super' expression is in the valid context |
1784 */ | 1822 */ |
1785 static bool isSuperInValidContext(SuperExpression node) { | 1823 static bool isSuperInValidContext(SuperExpression node) { |
1786 for (ASTNode n = node; n != null; n = n.parent) { | 1824 for (ASTNode n = node; n != null; n = n.parent) { |
1787 if (n is CompilationUnit) { | 1825 if (n is CompilationUnit) { |
1788 return false; | 1826 return false; |
1789 } | 1827 } |
1790 if (n is ConstructorDeclaration) { | 1828 if (n is ConstructorDeclaration) { |
1791 ConstructorDeclaration constructor = n as ConstructorDeclaration; | 1829 ConstructorDeclaration constructor = n as ConstructorDeclaration; |
(...skipping 28 matching lines...) Expand all Loading... |
1820 static String CALL_METHOD_NAME = "call"; | 1858 static String CALL_METHOD_NAME = "call"; |
1821 | 1859 |
1822 /** | 1860 /** |
1823 * The name of the method that will be invoked if an attempt is made to invoke
an undefined method | 1861 * The name of the method that will be invoked if an attempt is made to invoke
an undefined method |
1824 * on an object. | 1862 * on an object. |
1825 */ | 1863 */ |
1826 static String _NO_SUCH_METHOD_METHOD_NAME = "noSuchMethod"; | 1864 static String _NO_SUCH_METHOD_METHOD_NAME = "noSuchMethod"; |
1827 | 1865 |
1828 /** | 1866 /** |
1829 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 1867 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 1868 * |
1830 * @param resolver the resolver driving this participant | 1869 * @param resolver the resolver driving this participant |
1831 */ | 1870 */ |
1832 ElementResolver(ResolverVisitor resolver) { | 1871 ElementResolver(ResolverVisitor resolver) { |
1833 this._resolver = resolver; | 1872 this._resolver = resolver; |
1834 _strictMode = resolver.definingLibrary.context.analysisOptions.strictMode; | 1873 _strictMode = resolver.definingLibrary.context.analysisOptions.strictMode; |
1835 } | 1874 } |
1836 Object visitAssignmentExpression(AssignmentExpression node) { | 1875 Object visitAssignmentExpression(AssignmentExpression node) { |
1837 sc.Token operator = node.operator; | 1876 sc.Token operator = node.operator; |
1838 sc.TokenType operatorType = operator.type; | 1877 sc.TokenType operatorType = operator.type; |
1839 if (operatorType != sc.TokenType.EQ) { | 1878 if (operatorType != sc.TokenType.EQ) { |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2183 if (identical(errorCode, StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION))
{ | 2222 if (identical(errorCode, StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION))
{ |
2184 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION, me
thodName, [methodName.name]); | 2223 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION, me
thodName, [methodName.name]); |
2185 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_FUNCTION)) { | 2224 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_FUNCTION)) { |
2186 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_FUNCTION, methodName
, [methodName.name]); | 2225 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_FUNCTION, methodName
, [methodName.name]); |
2187 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_METHOD)) { | 2226 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_METHOD)) { |
2188 String targetTypeName; | 2227 String targetTypeName; |
2189 if (target == null) { | 2228 if (target == null) { |
2190 ClassElement enclosingClass = _resolver.enclosingClass; | 2229 ClassElement enclosingClass = _resolver.enclosingClass; |
2191 targetTypeName = enclosingClass.displayName; | 2230 targetTypeName = enclosingClass.displayName; |
2192 } else { | 2231 } else { |
2193 Type2 targetType = getPropagatedType(target); | 2232 Type2 targetType = getStaticType(target); |
2194 if (targetType == null) { | 2233 if (targetType != null && targetType.isDartCoreFunction && methodName.na
me == CALL_METHOD_NAME) { |
2195 targetType = getStaticType(target); | 2234 return null; |
2196 } | 2235 } |
2197 targetTypeName = targetType == null ? null : targetType.displayName; | 2236 targetTypeName = targetType == null ? null : targetType.displayName; |
2198 } | 2237 } |
2199 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_METHOD, methodName,
[methodName.name, targetTypeName]); | 2238 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_METHOD, methodName,
[methodName.name, targetTypeName]); |
2200 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_SUPER_METHOD
)) { | 2239 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_SUPER_METHOD
)) { |
2201 Type2 targetType = getPropagatedType(target); | 2240 Type2 targetType = getPropagatedType(target); |
2202 if (targetType == null) { | 2241 if (targetType == null) { |
2203 targetType = getStaticType(target); | 2242 targetType = getStaticType(target); |
2204 } | 2243 } |
2205 String targetTypeName = targetType == null ? null : targetType.name; | 2244 String targetTypeName = targetType == null ? null : targetType.name; |
(...skipping 23 matching lines...) Expand all Loading... |
2229 } | 2268 } |
2230 return null; | 2269 return null; |
2231 } | 2270 } |
2232 Object visitPrefixedIdentifier(PrefixedIdentifier node) { | 2271 Object visitPrefixedIdentifier(PrefixedIdentifier node) { |
2233 SimpleIdentifier prefix = node.prefix; | 2272 SimpleIdentifier prefix = node.prefix; |
2234 SimpleIdentifier identifier = node.identifier; | 2273 SimpleIdentifier identifier = node.identifier; |
2235 Element prefixElement = prefix.element; | 2274 Element prefixElement = prefix.element; |
2236 if (prefixElement is PrefixElement) { | 2275 if (prefixElement is PrefixElement) { |
2237 Element element = _resolver.nameScope.lookup(node, _resolver.definingLibra
ry); | 2276 Element element = _resolver.nameScope.lookup(node, _resolver.definingLibra
ry); |
2238 if (element == null) { | 2277 if (element == null) { |
| 2278 _resolver.reportError(StaticWarningCode.UNDEFINED_GETTER, identifier, [i
dentifier.name, prefixElement.name]); |
2239 return null; | 2279 return null; |
2240 } | 2280 } |
2241 if (element is PropertyAccessorElement && identifier.inSetterContext()) { | 2281 if (element is PropertyAccessorElement && identifier.inSetterContext()) { |
2242 PropertyInducingElement variable = ((element as PropertyAccessorElement)
).variable; | 2282 PropertyInducingElement variable = ((element as PropertyAccessorElement)
).variable; |
2243 if (variable != null) { | 2283 if (variable != null) { |
2244 PropertyAccessorElement setter = variable.setter; | 2284 PropertyAccessorElement setter = variable.setter; |
2245 if (setter != null) { | 2285 if (setter != null) { |
2246 element = setter; | 2286 element = setter; |
2247 } | 2287 } |
2248 } | 2288 } |
2249 } | 2289 } |
2250 recordResolution(identifier, element); | 2290 recordResolution(identifier, element); |
2251 return null; | 2291 return null; |
2252 } | 2292 } |
| 2293 if (node.parent is Annotation && prefixElement is ClassElement) { |
| 2294 Annotation annotation = node.parent as Annotation; |
| 2295 ConstructorElement constructor; |
| 2296 { |
| 2297 InterfaceType interfaceType = prefix.staticType as InterfaceType; |
| 2298 LibraryElement definingLibrary = _resolver.definingLibrary; |
| 2299 constructor = interfaceType.lookUpConstructor(identifier.name, definingL
ibrary); |
| 2300 } |
| 2301 recordResolution(identifier, constructor); |
| 2302 annotation.element = constructor; |
| 2303 resolveAnnotationConstructorInvocationArguments(annotation, constructor); |
| 2304 return null; |
| 2305 } |
2253 resolvePropertyAccess(prefix, identifier); | 2306 resolvePropertyAccess(prefix, identifier); |
2254 return null; | 2307 return null; |
2255 } | 2308 } |
2256 Object visitPrefixExpression(PrefixExpression node) { | 2309 Object visitPrefixExpression(PrefixExpression node) { |
2257 sc.Token operator = node.operator; | 2310 sc.Token operator = node.operator; |
2258 sc.TokenType operatorType = operator.type; | 2311 sc.TokenType operatorType = operator.type; |
2259 if (operatorType.isUserDefinableOperator || identical(operatorType, sc.Token
Type.PLUS_PLUS) || identical(operatorType, sc.TokenType.MINUS_MINUS)) { | 2312 if (operatorType.isUserDefinableOperator || identical(operatorType, sc.Token
Type.PLUS_PLUS) || identical(operatorType, sc.TokenType.MINUS_MINUS)) { |
2260 Expression operand = node.operand; | 2313 Expression operand = node.operand; |
2261 String methodName = getPrefixOperator(node); | 2314 String methodName = getPrefixOperator(node); |
2262 Type2 staticType = getStaticType(operand); | 2315 Type2 staticType = getStaticType(operand); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2315 if (isFactoryConstructorReturnType(node) && element != _resolver.enclosingCl
ass) { | 2368 if (isFactoryConstructorReturnType(node) && element != _resolver.enclosingCl
ass) { |
2316 _resolver.reportError(CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLAS
S, node, []); | 2369 _resolver.reportError(CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLAS
S, node, []); |
2317 } else if (element == null) { | 2370 } else if (element == null) { |
2318 if (isConstructorReturnType(node)) { | 2371 if (isConstructorReturnType(node)) { |
2319 _resolver.reportError(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, nod
e, []); | 2372 _resolver.reportError(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, nod
e, []); |
2320 } else if (!classDeclaresNoSuchMethod(_resolver.enclosingClass)) { | 2373 } else if (!classDeclaresNoSuchMethod(_resolver.enclosingClass)) { |
2321 _resolver.reportError(StaticWarningCode.UNDEFINED_IDENTIFIER, node, [nod
e.name]); | 2374 _resolver.reportError(StaticWarningCode.UNDEFINED_IDENTIFIER, node, [nod
e.name]); |
2322 } | 2375 } |
2323 } | 2376 } |
2324 recordResolution(node, element); | 2377 recordResolution(node, element); |
| 2378 if (node.parent is Annotation && element is ClassElement) { |
| 2379 Annotation annotation = node.parent as Annotation; |
| 2380 ConstructorElement constructor; |
| 2381 { |
| 2382 InterfaceType interfaceType = new InterfaceTypeImpl.con1((element as Cla
ssElement)); |
| 2383 LibraryElement definingLibrary = _resolver.definingLibrary; |
| 2384 constructor = interfaceType.lookUpConstructor(null, definingLibrary); |
| 2385 } |
| 2386 annotation.element = constructor; |
| 2387 resolveAnnotationConstructorInvocationArguments(annotation, constructor); |
| 2388 return null; |
| 2389 } |
2325 return null; | 2390 return null; |
2326 } | 2391 } |
2327 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { | 2392 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { |
2328 ClassElement enclosingClass = _resolver.enclosingClass; | 2393 ClassElement enclosingClass = _resolver.enclosingClass; |
2329 if (enclosingClass == null) { | 2394 if (enclosingClass == null) { |
2330 return null; | 2395 return null; |
2331 } | 2396 } |
2332 ClassElement superclass = getSuperclass(enclosingClass); | 2397 ClassElement superclass = getSuperclass(enclosingClass); |
2333 if (superclass == null) { | 2398 if (superclass == null) { |
2334 return null; | 2399 return null; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2382 return null; | 2447 return null; |
2383 } | 2448 } |
2384 Object visitVariableDeclaration(VariableDeclaration node) { | 2449 Object visitVariableDeclaration(VariableDeclaration node) { |
2385 setMetadata(node.element, node); | 2450 setMetadata(node.element, node); |
2386 return null; | 2451 return null; |
2387 } | 2452 } |
2388 | 2453 |
2389 /** | 2454 /** |
2390 * Generate annotation elements for each of the annotations in the given node
list and add them to | 2455 * Generate annotation elements for each of the annotations in the given node
list and add them to |
2391 * the given list of elements. | 2456 * the given list of elements. |
| 2457 * |
2392 * @param annotationList the list of elements to which new elements are to be
added | 2458 * @param annotationList the list of elements to which new elements are to be
added |
2393 * @param annotations the AST nodes used to generate new elements | 2459 * @param annotations the AST nodes used to generate new elements |
2394 */ | 2460 */ |
2395 void addAnnotations(List<ElementAnnotationImpl> annotationList, NodeList<Annot
ation> annotations) { | 2461 void addAnnotations(List<ElementAnnotationImpl> annotationList, NodeList<Annot
ation> annotations) { |
2396 for (Annotation annotationNode in annotations) { | 2462 for (Annotation annotationNode in annotations) { |
2397 Element resolvedElement = annotationNode.element; | 2463 Element resolvedElement = annotationNode.element; |
2398 if (resolvedElement != null) { | 2464 if (resolvedElement != null) { |
2399 annotationList.add(new ElementAnnotationImpl(resolvedElement)); | 2465 annotationList.add(new ElementAnnotationImpl(resolvedElement)); |
2400 } | 2466 } |
2401 } | 2467 } |
2402 } | 2468 } |
2403 | 2469 |
2404 /** | 2470 /** |
2405 * Given that we have found code to invoke the given element, return the error
code that should be | 2471 * Given that we have found code to invoke the given element, return the error
code that should be |
2406 * reported, or `null` if no error should be reported. | 2472 * reported, or `null` if no error should be reported. |
| 2473 * |
2407 * @param target the target of the invocation, or `null` if there was no targe
t | 2474 * @param target the target of the invocation, or `null` if there was no targe
t |
2408 * @param element the element to be invoked | 2475 * @param element the element to be invoked |
2409 * @return the error code that should be reported | 2476 * @return the error code that should be reported |
2410 */ | 2477 */ |
2411 ErrorCode checkForInvocationError(Expression target, Element element2) { | 2478 ErrorCode checkForInvocationError(Expression target, Element element2) { |
2412 if (element2 is PropertyAccessorElement) { | 2479 if (element2 is PropertyAccessorElement) { |
2413 FunctionType getterType = ((element2 as PropertyAccessorElement)).type; | 2480 FunctionType getterType = ((element2 as PropertyAccessorElement)).type; |
2414 if (getterType != null) { | 2481 if (getterType != null) { |
2415 Type2 returnType = getterType.returnType; | 2482 Type2 returnType = getterType.returnType; |
2416 if (!isExecutableType(returnType)) { | 2483 if (!isExecutableType(returnType)) { |
2417 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION; | 2484 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION; |
2418 } | 2485 } |
2419 } | 2486 } |
2420 } else if (element2 is ExecutableElement) { | 2487 } else if (element2 is ExecutableElement) { |
2421 return null; | 2488 return null; |
2422 } else if (element2 == null && target is SuperExpression) { | 2489 } else if (element2 == null && target is SuperExpression) { |
2423 return StaticTypeWarningCode.UNDEFINED_SUPER_METHOD; | 2490 return StaticTypeWarningCode.UNDEFINED_SUPER_METHOD; |
2424 } else { | 2491 } else { |
2425 if (element2 is PropertyInducingElement) { | 2492 if (element2 is PropertyInducingElement) { |
2426 PropertyAccessorElement getter = ((element2 as PropertyInducingElement))
.getter; | 2493 PropertyAccessorElement getter = ((element2 as PropertyInducingElement))
.getter; |
2427 FunctionType getterType = getter.type; | 2494 FunctionType getterType = getter.type; |
2428 if (getterType != null) { | 2495 if (getterType != null) { |
2429 Type2 returnType = getterType.returnType; | 2496 Type2 returnType = getterType.returnType; |
2430 if (!isExecutableType(returnType)) { | 2497 if (!isExecutableType(returnType)) { |
2431 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION; | 2498 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION; |
2432 } | 2499 } |
2433 } | 2500 } |
2434 } else if (element2 is VariableElement) { | 2501 } else if (element2 is VariableElement) { |
2435 Type2 variableType = _resolver.overrideManager.getType(element2); | 2502 Type2 variableType = ((element2 as VariableElement)).type; |
2436 if (variableType == null) { | |
2437 variableType = ((element2 as VariableElement)).type; | |
2438 } | |
2439 if (!isExecutableType(variableType)) { | 2503 if (!isExecutableType(variableType)) { |
2440 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION; | 2504 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION; |
2441 } | 2505 } |
2442 } else { | 2506 } else { |
2443 if (target == null) { | 2507 if (target == null) { |
2444 ClassElement enclosingClass = _resolver.enclosingClass; | 2508 ClassElement enclosingClass = _resolver.enclosingClass; |
2445 if (enclosingClass == null) { | 2509 if (enclosingClass == null) { |
2446 return StaticTypeWarningCode.UNDEFINED_FUNCTION; | 2510 return StaticTypeWarningCode.UNDEFINED_FUNCTION; |
2447 } else if (element2 == null) { | 2511 } else if (element2 == null) { |
2448 if (!classDeclaresNoSuchMethod(enclosingClass)) { | 2512 if (!classDeclaresNoSuchMethod(enclosingClass)) { |
(...skipping 11 matching lines...) Expand all Loading... |
2460 } | 2524 } |
2461 } | 2525 } |
2462 } | 2526 } |
2463 } | 2527 } |
2464 return null; | 2528 return null; |
2465 } | 2529 } |
2466 | 2530 |
2467 /** | 2531 /** |
2468 * Return `true` if the given class declares a method named "noSuchMethod" and
is not the | 2532 * Return `true` if the given class declares a method named "noSuchMethod" and
is not the |
2469 * class 'Object'. | 2533 * class 'Object'. |
| 2534 * |
2470 * @param element the class being tested | 2535 * @param element the class being tested |
2471 * @return `true` if the given class declares a method named "noSuchMethod" | 2536 * @return `true` if the given class declares a method named "noSuchMethod" |
2472 */ | 2537 */ |
2473 bool classDeclaresNoSuchMethod(ClassElement classElement) { | 2538 bool classDeclaresNoSuchMethod(ClassElement classElement) { |
2474 if (classElement == null) { | 2539 if (classElement == null) { |
2475 return false; | 2540 return false; |
2476 } | 2541 } |
2477 MethodElement methodElement = classElement.lookUpMethod(_NO_SUCH_METHOD_METH
OD_NAME, _resolver.definingLibrary); | 2542 MethodElement methodElement = classElement.lookUpMethod(_NO_SUCH_METHOD_METH
OD_NAME, _resolver.definingLibrary); |
2478 return methodElement != null && methodElement.enclosingElement.supertype !=
null; | 2543 return methodElement != null && methodElement.enclosingElement.supertype !=
null; |
2479 } | 2544 } |
2480 | 2545 |
2481 /** | 2546 /** |
2482 * Return `true` if the given element represents a class that declares a metho
d named | 2547 * Return `true` if the given element represents a class that declares a metho
d named |
2483 * "noSuchMethod" and is not the class 'Object'. | 2548 * "noSuchMethod" and is not the class 'Object'. |
| 2549 * |
2484 * @param element the element being tested | 2550 * @param element the element being tested |
2485 * @return `true` if the given element represents a class that declares a meth
od named | 2551 * @return `true` if the given element represents a class that declares a meth
od named |
2486 * "noSuchMethod" | 2552 * "noSuchMethod" |
2487 */ | 2553 */ |
2488 bool classDeclaresNoSuchMethod2(Element element) { | 2554 bool classDeclaresNoSuchMethod2(Element element) { |
2489 if (element is ClassElement) { | 2555 if (element is ClassElement) { |
2490 return classDeclaresNoSuchMethod((element as ClassElement)); | 2556 return classDeclaresNoSuchMethod((element as ClassElement)); |
2491 } | 2557 } |
2492 return false; | 2558 return false; |
2493 } | 2559 } |
2494 | 2560 |
2495 /** | 2561 /** |
2496 * Given a list of arguments and the element that will be invoked using those
argument, compute | 2562 * Given a list of arguments and the element that will be invoked using those
argument, compute |
2497 * the list of parameters that correspond to the list of arguments. Return the
parameters that | 2563 * the list of parameters that correspond to the list of arguments. Return the
parameters that |
2498 * correspond to the arguments, or `null` if no correspondence could be comput
ed. | 2564 * correspond to the arguments, or `null` if no correspondence could be comput
ed. |
| 2565 * |
2499 * @param argumentList the list of arguments being passed to the element | 2566 * @param argumentList the list of arguments being passed to the element |
2500 * @param executableElement the element that will be invoked with the argument
s | 2567 * @param executableElement the element that will be invoked with the argument
s |
2501 * @return the parameters that correspond to the arguments | 2568 * @return the parameters that correspond to the arguments |
2502 */ | 2569 */ |
2503 List<ParameterElement> computePropagatedParameters(ArgumentList argumentList,
Element element2) { | 2570 List<ParameterElement> computePropagatedParameters(ArgumentList argumentList,
Element element2) { |
2504 if (element2 is PropertyAccessorElement) { | 2571 if (element2 is PropertyAccessorElement) { |
2505 FunctionType getterType = ((element2 as PropertyAccessorElement)).type; | 2572 FunctionType getterType = ((element2 as PropertyAccessorElement)).type; |
2506 if (getterType != null) { | 2573 if (getterType != null) { |
2507 Type2 getterReturnType = getterType.returnType; | 2574 Type2 getterReturnType = getterType.returnType; |
2508 if (getterReturnType is InterfaceType) { | 2575 if (getterReturnType is InterfaceType) { |
(...skipping 24 matching lines...) Expand all Loading... |
2533 return resolveArgumentsToParameters2(false, argumentList, parameters); | 2600 return resolveArgumentsToParameters2(false, argumentList, parameters); |
2534 } | 2601 } |
2535 } | 2602 } |
2536 } | 2603 } |
2537 return null; | 2604 return null; |
2538 } | 2605 } |
2539 | 2606 |
2540 /** | 2607 /** |
2541 * If the given element is a setter, return the getter associated with it. Oth
erwise, return the | 2608 * If the given element is a setter, return the getter associated with it. Oth
erwise, return the |
2542 * element unchanged. | 2609 * element unchanged. |
| 2610 * |
2543 * @param element the element to be normalized | 2611 * @param element the element to be normalized |
2544 * @return a non-setter element derived from the given element | 2612 * @return a non-setter element derived from the given element |
2545 */ | 2613 */ |
2546 Element convertSetterToGetter(Element element) { | 2614 Element convertSetterToGetter(Element element) { |
2547 if (element is PropertyAccessorElement) { | 2615 if (element is PropertyAccessorElement) { |
2548 return ((element as PropertyAccessorElement)).variable.getter; | 2616 return ((element as PropertyAccessorElement)).variable.getter; |
2549 } | 2617 } |
2550 return element; | 2618 return element; |
2551 } | 2619 } |
2552 | 2620 |
2553 /** | 2621 /** |
2554 * Look for any declarations of the given identifier that are imported using a
prefix. Return the | 2622 * Look for any declarations of the given identifier that are imported using a
prefix. Return the |
2555 * element that was found, or `null` if the name is not imported using a prefi
x. | 2623 * element that was found, or `null` if the name is not imported using a prefi
x. |
| 2624 * |
2556 * @param identifier the identifier that might have been imported using a pref
ix | 2625 * @param identifier the identifier that might have been imported using a pref
ix |
2557 * @return the element that was found | 2626 * @return the element that was found |
2558 */ | 2627 */ |
2559 Element findImportWithoutPrefix(SimpleIdentifier identifier) { | 2628 Element findImportWithoutPrefix(SimpleIdentifier identifier) { |
2560 Element element = null; | 2629 Element element = null; |
2561 Scope nameScope = _resolver.nameScope; | 2630 Scope nameScope = _resolver.nameScope; |
2562 LibraryElement definingLibrary = _resolver.definingLibrary; | 2631 LibraryElement definingLibrary = _resolver.definingLibrary; |
2563 for (ImportElement importElement in definingLibrary.imports) { | 2632 for (ImportElement importElement in definingLibrary.imports) { |
2564 PrefixElement prefixElement = importElement.prefix; | 2633 PrefixElement prefixElement = importElement.prefix; |
2565 if (prefixElement != null) { | 2634 if (prefixElement != null) { |
2566 Identifier prefixedIdentifier = new ElementResolver_SyntheticIdentifier(
"${prefixElement.name}.${identifier.name}"); | 2635 Identifier prefixedIdentifier = new ElementResolver_SyntheticIdentifier(
"${prefixElement.name}.${identifier.name}"); |
2567 Element importedElement = nameScope.lookup(prefixedIdentifier, definingL
ibrary); | 2636 Element importedElement = nameScope.lookup(prefixedIdentifier, definingL
ibrary); |
2568 if (importedElement != null) { | 2637 if (importedElement != null) { |
2569 if (element == null) { | 2638 if (element == null) { |
2570 element = importedElement; | 2639 element = importedElement; |
2571 } else { | 2640 } else { |
2572 element = new MultiplyDefinedElementImpl(definingLibrary.context, el
ement, importedElement); | 2641 element = new MultiplyDefinedElementImpl(definingLibrary.context, el
ement, importedElement); |
2573 } | 2642 } |
2574 } | 2643 } |
2575 } | 2644 } |
2576 } | 2645 } |
2577 return element; | 2646 return element; |
2578 } | 2647 } |
2579 | 2648 |
2580 /** | 2649 /** |
2581 * Return the name of the method invoked by the given postfix expression. | 2650 * Return the name of the method invoked by the given postfix expression. |
| 2651 * |
2582 * @param node the postfix expression being invoked | 2652 * @param node the postfix expression being invoked |
2583 * @return the name of the method invoked by the expression | 2653 * @return the name of the method invoked by the expression |
2584 */ | 2654 */ |
2585 String getPostfixOperator(PostfixExpression node) => (identical(node.operator.
type, sc.TokenType.PLUS_PLUS)) ? sc.TokenType.PLUS.lexeme : sc.TokenType.MINUS.l
exeme; | 2655 String getPostfixOperator(PostfixExpression node) => (identical(node.operator.
type, sc.TokenType.PLUS_PLUS)) ? sc.TokenType.PLUS.lexeme : sc.TokenType.MINUS.l
exeme; |
2586 | 2656 |
2587 /** | 2657 /** |
2588 * Return the name of the method invoked by the given postfix expression. | 2658 * Return the name of the method invoked by the given postfix expression. |
| 2659 * |
2589 * @param node the postfix expression being invoked | 2660 * @param node the postfix expression being invoked |
2590 * @return the name of the method invoked by the expression | 2661 * @return the name of the method invoked by the expression |
2591 */ | 2662 */ |
2592 String getPrefixOperator(PrefixExpression node) { | 2663 String getPrefixOperator(PrefixExpression node) { |
2593 sc.Token operator = node.operator; | 2664 sc.Token operator = node.operator; |
2594 sc.TokenType operatorType = operator.type; | 2665 sc.TokenType operatorType = operator.type; |
2595 if (identical(operatorType, sc.TokenType.PLUS_PLUS)) { | 2666 if (identical(operatorType, sc.TokenType.PLUS_PLUS)) { |
2596 return sc.TokenType.PLUS.lexeme; | 2667 return sc.TokenType.PLUS.lexeme; |
2597 } else if (identical(operatorType, sc.TokenType.MINUS_MINUS)) { | 2668 } else if (identical(operatorType, sc.TokenType.MINUS_MINUS)) { |
2598 return sc.TokenType.MINUS.lexeme; | 2669 return sc.TokenType.MINUS.lexeme; |
2599 } else if (identical(operatorType, sc.TokenType.MINUS)) { | 2670 } else if (identical(operatorType, sc.TokenType.MINUS)) { |
2600 return "unary-"; | 2671 return "unary-"; |
2601 } else { | 2672 } else { |
2602 return operator.lexeme; | 2673 return operator.lexeme; |
2603 } | 2674 } |
2604 } | 2675 } |
2605 | 2676 |
2606 /** | 2677 /** |
2607 * Return the propagated type of the given expression that is to be used for t
ype analysis. | 2678 * Return the propagated type of the given expression that is to be used for t
ype analysis. |
| 2679 * |
2608 * @param expression the expression whose type is to be returned | 2680 * @param expression the expression whose type is to be returned |
2609 * @return the type of the given expression | 2681 * @return the type of the given expression |
2610 */ | 2682 */ |
2611 Type2 getPropagatedType(Expression expression) { | 2683 Type2 getPropagatedType(Expression expression) { |
2612 Type2 propagatedType = resolveTypeVariable(expression.propagatedType); | 2684 Type2 propagatedType = resolveTypeVariable(expression.propagatedType); |
2613 if (propagatedType is FunctionType) { | 2685 if (propagatedType is FunctionType) { |
2614 propagatedType = _resolver.typeProvider.functionType; | 2686 propagatedType = _resolver.typeProvider.functionType; |
2615 } | 2687 } |
2616 return propagatedType; | 2688 return propagatedType; |
2617 } | 2689 } |
2618 | 2690 |
2619 /** | 2691 /** |
2620 * Return the static type of the given expression that is to be used for type
analysis. | 2692 * Return the static type of the given expression that is to be used for type
analysis. |
| 2693 * |
2621 * @param expression the expression whose type is to be returned | 2694 * @param expression the expression whose type is to be returned |
2622 * @return the type of the given expression | 2695 * @return the type of the given expression |
2623 */ | 2696 */ |
2624 Type2 getStaticType(Expression expression) { | 2697 Type2 getStaticType(Expression expression) { |
2625 if (expression is NullLiteral) { | 2698 if (expression is NullLiteral) { |
2626 return _resolver.typeProvider.objectType; | 2699 return _resolver.typeProvider.objectType; |
2627 } | 2700 } |
2628 Type2 staticType = resolveTypeVariable(expression.staticType); | 2701 Type2 staticType = resolveTypeVariable(expression.staticType); |
2629 if (staticType is FunctionType) { | 2702 if (staticType is FunctionType) { |
2630 staticType = _resolver.typeProvider.functionType; | 2703 staticType = _resolver.typeProvider.functionType; |
2631 } | 2704 } |
2632 return staticType; | 2705 return staticType; |
2633 } | 2706 } |
2634 | 2707 |
2635 /** | 2708 /** |
2636 * Return the element representing the superclass of the given class. | 2709 * Return the element representing the superclass of the given class. |
| 2710 * |
2637 * @param targetClass the class whose superclass is to be returned | 2711 * @param targetClass the class whose superclass is to be returned |
2638 * @return the element representing the superclass of the given class | 2712 * @return the element representing the superclass of the given class |
2639 */ | 2713 */ |
2640 ClassElement getSuperclass(ClassElement targetClass) { | 2714 ClassElement getSuperclass(ClassElement targetClass) { |
2641 InterfaceType superType = targetClass.supertype; | 2715 InterfaceType superType = targetClass.supertype; |
2642 if (superType == null) { | 2716 if (superType == null) { |
2643 return null; | 2717 return null; |
2644 } | 2718 } |
2645 return superType.element; | 2719 return superType.element; |
2646 } | 2720 } |
2647 | 2721 |
2648 /** | 2722 /** |
2649 * Return `true` if the given type represents an object that could be invoked
using the call | 2723 * Return `true` if the given type represents an object that could be invoked
using the call |
2650 * operator '()'. | 2724 * operator '()'. |
| 2725 * |
2651 * @param type the type being tested | 2726 * @param type the type being tested |
2652 * @return `true` if the given type represents an object that could be invoked | 2727 * @return `true` if the given type represents an object that could be invoked |
2653 */ | 2728 */ |
2654 bool isExecutableType(Type2 type) { | 2729 bool isExecutableType(Type2 type) { |
2655 if (type.isDynamic || (type is FunctionType) || type.isDartCoreFunction) { | 2730 if (type.isDynamic || (type is FunctionType) || type.isDartCoreFunction || t
ype.isObject) { |
2656 return true; | 2731 return true; |
2657 } else if (type is InterfaceType) { | 2732 } else if (type is InterfaceType) { |
2658 ClassElement classElement = ((type as InterfaceType)).element; | 2733 ClassElement classElement = ((type as InterfaceType)).element; |
2659 MethodElement methodElement = classElement.lookUpMethod(CALL_METHOD_NAME,
_resolver.definingLibrary); | 2734 MethodElement methodElement = classElement.lookUpMethod(CALL_METHOD_NAME,
_resolver.definingLibrary); |
2660 return methodElement != null; | 2735 return methodElement != null; |
2661 } | 2736 } |
2662 return false; | 2737 return false; |
2663 } | 2738 } |
2664 | 2739 |
2665 /** | 2740 /** |
2666 * Return `true` if the given element is a static element. | 2741 * Return `true` if the given element is a static element. |
| 2742 * |
2667 * @param element the element being tested | 2743 * @param element the element being tested |
2668 * @return `true` if the given element is a static element | 2744 * @return `true` if the given element is a static element |
2669 */ | 2745 */ |
2670 bool isStatic(Element element) { | 2746 bool isStatic(Element element) { |
2671 if (element is ExecutableElement) { | 2747 if (element is ExecutableElement) { |
2672 return ((element as ExecutableElement)).isStatic; | 2748 return ((element as ExecutableElement)).isStatic; |
2673 } else if (element is PropertyInducingElement) { | 2749 } else if (element is PropertyInducingElement) { |
2674 return ((element as PropertyInducingElement)).isStatic; | 2750 return ((element as PropertyInducingElement)).isStatic; |
2675 } | 2751 } |
2676 return false; | 2752 return false; |
2677 } | 2753 } |
2678 | 2754 |
2679 /** | 2755 /** |
2680 * Looks up the method element with the given name for index expression, repor
ts[StaticWarningCode#UNDEFINED_OPERATOR] if not found. | 2756 * Looks up the method element with the given name for index expression, repor
ts |
| 2757 * [StaticWarningCode#UNDEFINED_OPERATOR] if not found. |
| 2758 * |
2681 * @param node the index expression to resolve | 2759 * @param node the index expression to resolve |
2682 * @param target the target of the expression | 2760 * @param target the target of the expression |
2683 * @param methodName the name of the operator associated with the context of u
sing of the given | 2761 * @param methodName the name of the operator associated with the context of u
sing of the given |
2684 * index expression | 2762 * index expression |
2685 * @return `true` if and only if an error code is generated on the passed node | 2763 * @return `true` if and only if an error code is generated on the passed node |
2686 */ | 2764 */ |
2687 bool lookUpCheckIndexOperator(IndexExpression node, Expression target, String
methodName, Type2 staticType, Type2 propagatedType) { | 2765 bool lookUpCheckIndexOperator(IndexExpression node, Expression target, String
methodName, Type2 staticType, Type2 propagatedType) { |
2688 MethodElement staticMethod = lookUpMethod(target, staticType, methodName); | 2766 MethodElement staticMethod = lookUpMethod(target, staticType, methodName); |
2689 MethodElement propagatedMethod = lookUpMethod(target, propagatedType, method
Name); | 2767 MethodElement propagatedMethod = lookUpMethod(target, propagatedType, method
Name); |
2690 node.staticElement = staticMethod; | 2768 node.staticElement = staticMethod; |
2691 node.element = select2(staticMethod, propagatedMethod); | 2769 node.element = select2(staticMethod, propagatedMethod); |
2692 if (shouldReportMissingMember(staticType, staticMethod) && (_strictMode || p
ropagatedType == null || shouldReportMissingMember(propagatedType, propagatedMet
hod))) { | 2770 if (shouldReportMissingMember(staticType, staticMethod) && (_strictMode || p
ropagatedType == null || shouldReportMissingMember(propagatedType, propagatedMet
hod))) { |
2693 sc.Token leftBracket = node.leftBracket; | 2771 sc.Token leftBracket = node.leftBracket; |
2694 sc.Token rightBracket = node.rightBracket; | 2772 sc.Token rightBracket = node.rightBracket; |
2695 if (leftBracket == null || rightBracket == null) { | 2773 if (leftBracket == null || rightBracket == null) { |
2696 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_OPERATOR, node, [m
ethodName, staticType.displayName]); | 2774 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_OPERATOR, node, [m
ethodName, staticType.displayName]); |
2697 return true; | 2775 return true; |
2698 } else { | 2776 } else { |
2699 int offset = leftBracket.offset; | 2777 int offset = leftBracket.offset; |
2700 int length = rightBracket.offset - offset + 1; | 2778 int length = rightBracket.offset - offset + 1; |
2701 _resolver.reportError5(StaticTypeWarningCode.UNDEFINED_OPERATOR, offset,
length, [methodName, staticType.displayName]); | 2779 _resolver.reportError5(StaticTypeWarningCode.UNDEFINED_OPERATOR, offset,
length, [methodName, staticType.displayName]); |
2702 return true; | 2780 return true; |
2703 } | 2781 } |
2704 } | 2782 } |
2705 return false; | 2783 return false; |
2706 } | 2784 } |
2707 | 2785 |
2708 /** | 2786 /** |
2709 * Look up the getter with the given name in the given type. Return the elemen
t representing the | 2787 * Look up the getter with the given name in the given type. Return the elemen
t representing the |
2710 * getter that was found, or `null` if there is no getter with the given name. | 2788 * getter that was found, or `null` if there is no getter with the given name. |
| 2789 * |
2711 * @param target the target of the invocation, or `null` if there is no target | 2790 * @param target the target of the invocation, or `null` if there is no target |
2712 * @param type the type in which the getter is defined | 2791 * @param type the type in which the getter is defined |
2713 * @param getterName the name of the getter being looked up | 2792 * @param getterName the name of the getter being looked up |
2714 * @return the element representing the getter that was found | 2793 * @return the element representing the getter that was found |
2715 */ | 2794 */ |
2716 PropertyAccessorElement lookUpGetter(Expression target, Type2 type, String get
terName) { | 2795 PropertyAccessorElement lookUpGetter(Expression target, Type2 type, String get
terName) { |
2717 type = resolveTypeVariable(type); | 2796 type = resolveTypeVariable(type); |
2718 if (type is InterfaceType) { | 2797 if (type is InterfaceType) { |
2719 InterfaceType interfaceType = type as InterfaceType; | 2798 InterfaceType interfaceType = type as InterfaceType; |
2720 PropertyAccessorElement accessor; | 2799 PropertyAccessorElement accessor; |
2721 if (target is SuperExpression) { | 2800 if (target is SuperExpression) { |
2722 accessor = interfaceType.lookUpGetterInSuperclass(getterName, _resolver.
definingLibrary); | 2801 accessor = interfaceType.lookUpGetterInSuperclass(getterName, _resolver.
definingLibrary); |
2723 } else { | 2802 } else { |
2724 accessor = interfaceType.lookUpGetter(getterName, _resolver.definingLibr
ary); | 2803 accessor = interfaceType.lookUpGetter(getterName, _resolver.definingLibr
ary); |
2725 } | 2804 } |
2726 if (accessor != null) { | 2805 if (accessor != null) { |
2727 return accessor; | 2806 return accessor; |
2728 } | 2807 } |
2729 return lookUpGetterInInterfaces(interfaceType, false, getterName, new Set<
ClassElement>()); | 2808 return lookUpGetterInInterfaces(interfaceType, false, getterName, new Set<
ClassElement>()); |
2730 } | 2809 } |
2731 return null; | 2810 return null; |
2732 } | 2811 } |
2733 | 2812 |
2734 /** | 2813 /** |
2735 * Look up the getter with the given name in the interfaces implemented by the
given type, either | 2814 * Look up the getter with the given name in the interfaces implemented by the
given type, either |
2736 * directly or indirectly. Return the element representing the getter that was
found, or`null` if there is no getter with the given name. | 2815 * directly or indirectly. Return the element representing the getter that was
found, or |
| 2816 * `null` if there is no getter with the given name. |
| 2817 * |
2737 * @param targetType the type in which the getter might be defined | 2818 * @param targetType the type in which the getter might be defined |
2738 * @param includeTargetType `true` if the search should include the target typ
e | 2819 * @param includeTargetType `true` if the search should include the target typ
e |
2739 * @param getterName the name of the getter being looked up | 2820 * @param getterName the name of the getter being looked up |
2740 * @param visitedInterfaces a set containing all of the interfaces that have b
een examined, used | 2821 * @param visitedInterfaces a set containing all of the interfaces that have b
een examined, used |
2741 * to prevent infinite recursion and to optimize the search | 2822 * to prevent infinite recursion and to optimize the search |
2742 * @return the element representing the getter that was found | 2823 * @return the element representing the getter that was found |
2743 */ | 2824 */ |
2744 PropertyAccessorElement lookUpGetterInInterfaces(InterfaceType targetType, boo
l includeTargetType, String getterName, Set<ClassElement> visitedInterfaces) { | 2825 PropertyAccessorElement lookUpGetterInInterfaces(InterfaceType targetType, boo
l includeTargetType, String getterName, Set<ClassElement> visitedInterfaces) { |
2745 ClassElement targetClass = targetType.element; | 2826 ClassElement targetClass = targetType.element; |
2746 if (visitedInterfaces.contains(targetClass)) { | 2827 if (visitedInterfaces.contains(targetClass)) { |
2747 return null; | 2828 return null; |
2748 } | 2829 } |
2749 javaSetAdd(visitedInterfaces, targetClass); | 2830 javaSetAdd(visitedInterfaces, targetClass); |
2750 if (includeTargetType) { | 2831 if (includeTargetType) { |
2751 PropertyAccessorElement getter = targetType.getGetter(getterName); | 2832 PropertyAccessorElement getter = targetType.getGetter(getterName); |
(...skipping 17 matching lines...) Expand all Loading... |
2769 if (superclass == null) { | 2850 if (superclass == null) { |
2770 return null; | 2851 return null; |
2771 } | 2852 } |
2772 return lookUpGetterInInterfaces(superclass, true, getterName, visitedInterfa
ces); | 2853 return lookUpGetterInInterfaces(superclass, true, getterName, visitedInterfa
ces); |
2773 } | 2854 } |
2774 | 2855 |
2775 /** | 2856 /** |
2776 * Look up the method or getter with the given name in the given type. Return
the element | 2857 * Look up the method or getter with the given name in the given type. Return
the element |
2777 * representing the method or getter that was found, or `null` if there is no
method or | 2858 * representing the method or getter that was found, or `null` if there is no
method or |
2778 * getter with the given name. | 2859 * getter with the given name. |
| 2860 * |
2779 * @param type the type in which the method or getter is defined | 2861 * @param type the type in which the method or getter is defined |
2780 * @param memberName the name of the method or getter being looked up | 2862 * @param memberName the name of the method or getter being looked up |
2781 * @return the element representing the method or getter that was found | 2863 * @return the element representing the method or getter that was found |
2782 */ | 2864 */ |
2783 ExecutableElement lookupGetterOrMethod(Type2 type, String memberName) { | 2865 ExecutableElement lookupGetterOrMethod(Type2 type, String memberName) { |
2784 type = resolveTypeVariable(type); | 2866 type = resolveTypeVariable(type); |
2785 if (type is InterfaceType) { | 2867 if (type is InterfaceType) { |
2786 InterfaceType interfaceType = type as InterfaceType; | 2868 InterfaceType interfaceType = type as InterfaceType; |
2787 ExecutableElement member = interfaceType.lookUpMethod(memberName, _resolve
r.definingLibrary); | 2869 ExecutableElement member = interfaceType.lookUpMethod(memberName, _resolve
r.definingLibrary); |
2788 if (member != null) { | 2870 if (member != null) { |
2789 return member; | 2871 return member; |
2790 } | 2872 } |
2791 member = interfaceType.lookUpGetter(memberName, _resolver.definingLibrary)
; | 2873 member = interfaceType.lookUpGetter(memberName, _resolver.definingLibrary)
; |
2792 if (member != null) { | 2874 if (member != null) { |
2793 return member; | 2875 return member; |
2794 } | 2876 } |
2795 return lookUpGetterOrMethodInInterfaces(interfaceType, false, memberName,
new Set<ClassElement>()); | 2877 return lookUpGetterOrMethodInInterfaces(interfaceType, false, memberName,
new Set<ClassElement>()); |
2796 } | 2878 } |
2797 return null; | 2879 return null; |
2798 } | 2880 } |
2799 | 2881 |
2800 /** | 2882 /** |
2801 * Look up the method or getter with the given name in the interfaces implemen
ted by the given | 2883 * Look up the method or getter with the given name in the interfaces implemen
ted by the given |
2802 * type, either directly or indirectly. Return the element representing the me
thod or getter that | 2884 * type, either directly or indirectly. Return the element representing the me
thod or getter that |
2803 * was found, or `null` if there is no method or getter with the given name. | 2885 * was found, or `null` if there is no method or getter with the given name. |
| 2886 * |
2804 * @param targetType the type in which the method or getter might be defined | 2887 * @param targetType the type in which the method or getter might be defined |
2805 * @param includeTargetType `true` if the search should include the target typ
e | 2888 * @param includeTargetType `true` if the search should include the target typ
e |
2806 * @param memberName the name of the method or getter being looked up | 2889 * @param memberName the name of the method or getter being looked up |
2807 * @param visitedInterfaces a set containing all of the interfaces that have b
een examined, used | 2890 * @param visitedInterfaces a set containing all of the interfaces that have b
een examined, used |
2808 * to prevent infinite recursion and to optimize the search | 2891 * to prevent infinite recursion and to optimize the search |
2809 * @return the element representing the method or getter that was found | 2892 * @return the element representing the method or getter that was found |
2810 */ | 2893 */ |
2811 ExecutableElement lookUpGetterOrMethodInInterfaces(InterfaceType targetType, b
ool includeTargetType, String memberName, Set<ClassElement> visitedInterfaces) { | 2894 ExecutableElement lookUpGetterOrMethodInInterfaces(InterfaceType targetType, b
ool includeTargetType, String memberName, Set<ClassElement> visitedInterfaces) { |
2812 ClassElement targetClass = targetType.element; | 2895 ClassElement targetClass = targetType.element; |
2813 if (visitedInterfaces.contains(targetClass)) { | 2896 if (visitedInterfaces.contains(targetClass)) { |
2814 return null; | 2897 return null; |
2815 } | 2898 } |
2816 javaSetAdd(visitedInterfaces, targetClass); | 2899 javaSetAdd(visitedInterfaces, targetClass); |
2817 if (includeTargetType) { | 2900 if (includeTargetType) { |
2818 ExecutableElement member = targetType.getMethod(memberName); | 2901 ExecutableElement member = targetType.getMethod(memberName); |
(...skipping 19 matching lines...) Expand all Loading... |
2838 } | 2921 } |
2839 InterfaceType superclass = targetType.superclass; | 2922 InterfaceType superclass = targetType.superclass; |
2840 if (superclass == null) { | 2923 if (superclass == null) { |
2841 return null; | 2924 return null; |
2842 } | 2925 } |
2843 return lookUpGetterOrMethodInInterfaces(superclass, true, memberName, visite
dInterfaces); | 2926 return lookUpGetterOrMethodInInterfaces(superclass, true, memberName, visite
dInterfaces); |
2844 } | 2927 } |
2845 | 2928 |
2846 /** | 2929 /** |
2847 * Find the element corresponding to the given label node in the current label
scope. | 2930 * Find the element corresponding to the given label node in the current label
scope. |
| 2931 * |
2848 * @param parentNode the node containing the given label | 2932 * @param parentNode the node containing the given label |
2849 * @param labelNode the node representing the label being looked up | 2933 * @param labelNode the node representing the label being looked up |
2850 * @return the element corresponding to the given label node in the current sc
ope | 2934 * @return the element corresponding to the given label node in the current sc
ope |
2851 */ | 2935 */ |
2852 LabelElementImpl lookupLabel(ASTNode parentNode, SimpleIdentifier labelNode) { | 2936 LabelElementImpl lookupLabel(ASTNode parentNode, SimpleIdentifier labelNode) { |
2853 LabelScope labelScope = _resolver.labelScope; | 2937 LabelScope labelScope = _resolver.labelScope; |
2854 LabelElementImpl labelElement = null; | 2938 LabelElementImpl labelElement = null; |
2855 if (labelNode == null) { | 2939 if (labelNode == null) { |
2856 if (labelScope == null) { | 2940 if (labelScope == null) { |
2857 } else { | 2941 } else { |
(...skipping 20 matching lines...) Expand all Loading... |
2878 _resolver.reportError(CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE, labelNo
de, [labelNode.name]); | 2962 _resolver.reportError(CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE, labelNo
de, [labelNode.name]); |
2879 labelElement = null; | 2963 labelElement = null; |
2880 } | 2964 } |
2881 } | 2965 } |
2882 return labelElement; | 2966 return labelElement; |
2883 } | 2967 } |
2884 | 2968 |
2885 /** | 2969 /** |
2886 * Look up the method with the given name in the given type. Return the elemen
t representing the | 2970 * Look up the method with the given name in the given type. Return the elemen
t representing the |
2887 * method that was found, or `null` if there is no method with the given name. | 2971 * method that was found, or `null` if there is no method with the given name. |
| 2972 * |
2888 * @param target the target of the invocation, or `null` if there is no target | 2973 * @param target the target of the invocation, or `null` if there is no target |
2889 * @param type the type in which the method is defined | 2974 * @param type the type in which the method is defined |
2890 * @param methodName the name of the method being looked up | 2975 * @param methodName the name of the method being looked up |
2891 * @return the element representing the method that was found | 2976 * @return the element representing the method that was found |
2892 */ | 2977 */ |
2893 MethodElement lookUpMethod(Expression target, Type2 type, String methodName) { | 2978 MethodElement lookUpMethod(Expression target, Type2 type, String methodName) { |
2894 type = resolveTypeVariable(type); | 2979 type = resolveTypeVariable(type); |
2895 if (type is InterfaceType) { | 2980 if (type is InterfaceType) { |
2896 InterfaceType interfaceType = type as InterfaceType; | 2981 InterfaceType interfaceType = type as InterfaceType; |
2897 MethodElement method; | 2982 MethodElement method; |
2898 if (target is SuperExpression) { | 2983 if (target is SuperExpression) { |
2899 method = interfaceType.lookUpMethodInSuperclass(methodName, _resolver.de
finingLibrary); | 2984 method = interfaceType.lookUpMethodInSuperclass(methodName, _resolver.de
finingLibrary); |
2900 } else { | 2985 } else { |
2901 method = interfaceType.lookUpMethod(methodName, _resolver.definingLibrar
y); | 2986 method = interfaceType.lookUpMethod(methodName, _resolver.definingLibrar
y); |
2902 } | 2987 } |
2903 if (method != null) { | 2988 if (method != null) { |
2904 return method; | 2989 return method; |
2905 } | 2990 } |
2906 return lookUpMethodInInterfaces(interfaceType, false, methodName, new Set<
ClassElement>()); | 2991 return lookUpMethodInInterfaces(interfaceType, false, methodName, new Set<
ClassElement>()); |
2907 } | 2992 } |
2908 return null; | 2993 return null; |
2909 } | 2994 } |
2910 | 2995 |
2911 /** | 2996 /** |
2912 * Look up the method with the given name in the interfaces implemented by the
given type, either | 2997 * Look up the method with the given name in the interfaces implemented by the
given type, either |
2913 * directly or indirectly. Return the element representing the method that was
found, or`null` if there is no method with the given name. | 2998 * directly or indirectly. Return the element representing the method that was
found, or |
| 2999 * `null` if there is no method with the given name. |
| 3000 * |
2914 * @param targetType the type in which the member might be defined | 3001 * @param targetType the type in which the member might be defined |
2915 * @param includeTargetType `true` if the search should include the target typ
e | 3002 * @param includeTargetType `true` if the search should include the target typ
e |
2916 * @param methodName the name of the method being looked up | 3003 * @param methodName the name of the method being looked up |
2917 * @param visitedInterfaces a set containing all of the interfaces that have b
een examined, used | 3004 * @param visitedInterfaces a set containing all of the interfaces that have b
een examined, used |
2918 * to prevent infinite recursion and to optimize the search | 3005 * to prevent infinite recursion and to optimize the search |
2919 * @return the element representing the method that was found | 3006 * @return the element representing the method that was found |
2920 */ | 3007 */ |
2921 MethodElement lookUpMethodInInterfaces(InterfaceType targetType, bool includeT
argetType, String methodName, Set<ClassElement> visitedInterfaces) { | 3008 MethodElement lookUpMethodInInterfaces(InterfaceType targetType, bool includeT
argetType, String methodName, Set<ClassElement> visitedInterfaces) { |
2922 ClassElement targetClass = targetType.element; | 3009 ClassElement targetClass = targetType.element; |
2923 if (visitedInterfaces.contains(targetClass)) { | 3010 if (visitedInterfaces.contains(targetClass)) { |
2924 return null; | 3011 return null; |
2925 } | 3012 } |
2926 javaSetAdd(visitedInterfaces, targetClass); | 3013 javaSetAdd(visitedInterfaces, targetClass); |
2927 if (includeTargetType) { | 3014 if (includeTargetType) { |
2928 MethodElement method = targetType.getMethod(methodName); | 3015 MethodElement method = targetType.getMethod(methodName); |
(...skipping 16 matching lines...) Expand all Loading... |
2945 InterfaceType superclass = targetType.superclass; | 3032 InterfaceType superclass = targetType.superclass; |
2946 if (superclass == null) { | 3033 if (superclass == null) { |
2947 return null; | 3034 return null; |
2948 } | 3035 } |
2949 return lookUpMethodInInterfaces(superclass, true, methodName, visitedInterfa
ces); | 3036 return lookUpMethodInInterfaces(superclass, true, methodName, visitedInterfa
ces); |
2950 } | 3037 } |
2951 | 3038 |
2952 /** | 3039 /** |
2953 * Look up the setter with the given name in the given type. Return the elemen
t representing the | 3040 * Look up the setter with the given name in the given type. Return the elemen
t representing the |
2954 * setter that was found, or `null` if there is no setter with the given name. | 3041 * setter that was found, or `null` if there is no setter with the given name. |
| 3042 * |
2955 * @param target the target of the invocation, or `null` if there is no target | 3043 * @param target the target of the invocation, or `null` if there is no target |
2956 * @param type the type in which the setter is defined | 3044 * @param type the type in which the setter is defined |
2957 * @param setterName the name of the setter being looked up | 3045 * @param setterName the name of the setter being looked up |
2958 * @return the element representing the setter that was found | 3046 * @return the element representing the setter that was found |
2959 */ | 3047 */ |
2960 PropertyAccessorElement lookUpSetter(Expression target, Type2 type, String set
terName) { | 3048 PropertyAccessorElement lookUpSetter(Expression target, Type2 type, String set
terName) { |
2961 type = resolveTypeVariable(type); | 3049 type = resolveTypeVariable(type); |
2962 if (type is InterfaceType) { | 3050 if (type is InterfaceType) { |
2963 InterfaceType interfaceType = type as InterfaceType; | 3051 InterfaceType interfaceType = type as InterfaceType; |
2964 PropertyAccessorElement accessor; | 3052 PropertyAccessorElement accessor; |
2965 if (target is SuperExpression) { | 3053 if (target is SuperExpression) { |
2966 accessor = interfaceType.lookUpSetterInSuperclass(setterName, _resolver.
definingLibrary); | 3054 accessor = interfaceType.lookUpSetterInSuperclass(setterName, _resolver.
definingLibrary); |
2967 } else { | 3055 } else { |
2968 accessor = interfaceType.lookUpSetter(setterName, _resolver.definingLibr
ary); | 3056 accessor = interfaceType.lookUpSetter(setterName, _resolver.definingLibr
ary); |
2969 } | 3057 } |
2970 if (accessor != null) { | 3058 if (accessor != null) { |
2971 return accessor; | 3059 return accessor; |
2972 } | 3060 } |
2973 return lookUpSetterInInterfaces(interfaceType, false, setterName, new Set<
ClassElement>()); | 3061 return lookUpSetterInInterfaces(interfaceType, false, setterName, new Set<
ClassElement>()); |
2974 } | 3062 } |
2975 return null; | 3063 return null; |
2976 } | 3064 } |
2977 | 3065 |
2978 /** | 3066 /** |
2979 * Look up the setter with the given name in the interfaces implemented by the
given type, either | 3067 * Look up the setter with the given name in the interfaces implemented by the
given type, either |
2980 * directly or indirectly. Return the element representing the setter that was
found, or`null` if there is no setter with the given name. | 3068 * directly or indirectly. Return the element representing the setter that was
found, or |
| 3069 * `null` if there is no setter with the given name. |
| 3070 * |
2981 * @param targetType the type in which the setter might be defined | 3071 * @param targetType the type in which the setter might be defined |
2982 * @param includeTargetType `true` if the search should include the target typ
e | 3072 * @param includeTargetType `true` if the search should include the target typ
e |
2983 * @param setterName the name of the setter being looked up | 3073 * @param setterName the name of the setter being looked up |
2984 * @param visitedInterfaces a set containing all of the interfaces that have b
een examined, used | 3074 * @param visitedInterfaces a set containing all of the interfaces that have b
een examined, used |
2985 * to prevent infinite recursion and to optimize the search | 3075 * to prevent infinite recursion and to optimize the search |
2986 * @return the element representing the setter that was found | 3076 * @return the element representing the setter that was found |
2987 */ | 3077 */ |
2988 PropertyAccessorElement lookUpSetterInInterfaces(InterfaceType targetType, boo
l includeTargetType, String setterName, Set<ClassElement> visitedInterfaces) { | 3078 PropertyAccessorElement lookUpSetterInInterfaces(InterfaceType targetType, boo
l includeTargetType, String setterName, Set<ClassElement> visitedInterfaces) { |
2989 ClassElement targetClass = targetType.element; | 3079 ClassElement targetClass = targetType.element; |
2990 if (visitedInterfaces.contains(targetClass)) { | 3080 if (visitedInterfaces.contains(targetClass)) { |
2991 return null; | 3081 return null; |
2992 } | 3082 } |
2993 javaSetAdd(visitedInterfaces, targetClass); | 3083 javaSetAdd(visitedInterfaces, targetClass); |
2994 if (includeTargetType) { | 3084 if (includeTargetType) { |
2995 PropertyAccessorElement setter = targetType.getSetter(setterName); | 3085 PropertyAccessorElement setter = targetType.getSetter(setterName); |
(...skipping 15 matching lines...) Expand all Loading... |
3011 } | 3101 } |
3012 InterfaceType superclass = targetType.superclass; | 3102 InterfaceType superclass = targetType.superclass; |
3013 if (superclass == null) { | 3103 if (superclass == null) { |
3014 return null; | 3104 return null; |
3015 } | 3105 } |
3016 return lookUpSetterInInterfaces(superclass, true, setterName, visitedInterfa
ces); | 3106 return lookUpSetterInInterfaces(superclass, true, setterName, visitedInterfa
ces); |
3017 } | 3107 } |
3018 | 3108 |
3019 /** | 3109 /** |
3020 * Return the binary operator that is invoked by the given compound assignment
operator. | 3110 * Return the binary operator that is invoked by the given compound assignment
operator. |
| 3111 * |
3021 * @param operator the assignment operator being mapped | 3112 * @param operator the assignment operator being mapped |
3022 * @return the binary operator that invoked by the given assignment operator | 3113 * @return the binary operator that invoked by the given assignment operator |
3023 */ | 3114 */ |
3024 sc.TokenType operatorFromCompoundAssignment(sc.TokenType operator) { | 3115 sc.TokenType operatorFromCompoundAssignment(sc.TokenType operator) { |
3025 while (true) { | 3116 while (true) { |
3026 if (operator == sc.TokenType.AMPERSAND_EQ) { | 3117 if (operator == sc.TokenType.AMPERSAND_EQ) { |
3027 return sc.TokenType.AMPERSAND; | 3118 return sc.TokenType.AMPERSAND; |
3028 } else if (operator == sc.TokenType.BAR_EQ) { | 3119 } else if (operator == sc.TokenType.BAR_EQ) { |
3029 return sc.TokenType.BAR; | 3120 return sc.TokenType.BAR; |
3030 } else if (operator == sc.TokenType.CARET_EQ) { | 3121 } else if (operator == sc.TokenType.CARET_EQ) { |
(...skipping 16 matching lines...) Expand all Loading... |
3047 return sc.TokenType.TILDE_SLASH; | 3138 return sc.TokenType.TILDE_SLASH; |
3048 } | 3139 } |
3049 break; | 3140 break; |
3050 } | 3141 } |
3051 AnalysisEngine.instance.logger.logError("Failed to map ${operator.lexeme} to
it's corresponding operator"); | 3142 AnalysisEngine.instance.logger.logError("Failed to map ${operator.lexeme} to
it's corresponding operator"); |
3052 return operator; | 3143 return operator; |
3053 } | 3144 } |
3054 | 3145 |
3055 /** | 3146 /** |
3056 * Record the fact that the given AST node was resolved to the given element. | 3147 * Record the fact that the given AST node was resolved to the given element. |
| 3148 * |
3057 * @param node the AST node that was resolved | 3149 * @param node the AST node that was resolved |
3058 * @param element the element to which the AST node was resolved | 3150 * @param element the element to which the AST node was resolved |
3059 */ | 3151 */ |
3060 void recordResolution(SimpleIdentifier node, Element element2) { | 3152 void recordResolution(SimpleIdentifier node, Element element2) { |
3061 node.staticElement = element2; | 3153 node.staticElement = element2; |
3062 node.element = element2; | 3154 node.element = element2; |
3063 } | 3155 } |
3064 | 3156 |
3065 /** | 3157 /** |
3066 * Record the fact that the given AST node was resolved to the given elements. | 3158 * Record the fact that the given AST node was resolved to the given elements. |
| 3159 * |
3067 * @param node the AST node that was resolved | 3160 * @param node the AST node that was resolved |
3068 * @param staticElement the element to which the AST node was resolved using s
tatic type | 3161 * @param staticElement the element to which the AST node was resolved using s
tatic type |
3069 * information | 3162 * information |
3070 * @param propagatedElement the element to which the AST node was resolved usi
ng propagated type | 3163 * @param propagatedElement the element to which the AST node was resolved usi
ng propagated type |
3071 * information | 3164 * information |
3072 * @return the element that was associated with the node | 3165 * @return the element that was associated with the node |
3073 */ | 3166 */ |
3074 void recordResolution2(SimpleIdentifier node, Element staticElement2, Element
propagatedElement) { | 3167 void recordResolution2(SimpleIdentifier node, Element staticElement2, Element
propagatedElement) { |
3075 node.staticElement = staticElement2; | 3168 node.staticElement = staticElement2; |
3076 node.element = propagatedElement == null ? staticElement2 : propagatedElemen
t; | 3169 node.element = propagatedElement == null ? staticElement2 : propagatedElemen
t; |
3077 } | 3170 } |
| 3171 void resolveAnnotationConstructorInvocationArguments(Annotation annotation, Co
nstructorElement constructor) { |
| 3172 ArgumentList argumentList = annotation.arguments; |
| 3173 if (argumentList == null) { |
| 3174 } else { |
| 3175 List<ParameterElement> parameters = resolveArgumentsToParameters(true, arg
umentList, constructor); |
| 3176 if (parameters != null) { |
| 3177 argumentList.correspondingStaticParameters = parameters; |
| 3178 } |
| 3179 } |
| 3180 } |
3078 | 3181 |
3079 /** | 3182 /** |
3080 * Given a list of arguments and the element that will be invoked using those
argument, compute | 3183 * Given a list of arguments and the element that will be invoked using those
argument, compute |
3081 * the list of parameters that correspond to the list of arguments. Return the
parameters that | 3184 * the list of parameters that correspond to the list of arguments. Return the
parameters that |
3082 * correspond to the arguments, or `null` if no correspondence could be comput
ed. | 3185 * correspond to the arguments, or `null` if no correspondence could be comput
ed. |
3083 * @param reportError if `true` then compile-time error should be reported; if
`false`then compile-time warning | 3186 * |
| 3187 * @param reportError if `true` then compile-time error should be reported; if
`false` |
| 3188 * then compile-time warning |
3084 * @param argumentList the list of arguments being passed to the element | 3189 * @param argumentList the list of arguments being passed to the element |
3085 * @param executableElement the element that will be invoked with the argument
s | 3190 * @param executableElement the element that will be invoked with the argument
s |
3086 * @return the parameters that correspond to the arguments | 3191 * @return the parameters that correspond to the arguments |
3087 */ | 3192 */ |
3088 List<ParameterElement> resolveArgumentsToParameters(bool reportError, Argument
List argumentList, ExecutableElement executableElement) { | 3193 List<ParameterElement> resolveArgumentsToParameters(bool reportError, Argument
List argumentList, ExecutableElement executableElement) { |
3089 if (executableElement == null) { | 3194 if (executableElement == null) { |
3090 return null; | 3195 return null; |
3091 } | 3196 } |
3092 List<ParameterElement> parameters = executableElement.parameters; | 3197 List<ParameterElement> parameters = executableElement.parameters; |
3093 return resolveArgumentsToParameters2(reportError, argumentList, parameters); | 3198 return resolveArgumentsToParameters2(reportError, argumentList, parameters); |
3094 } | 3199 } |
3095 | 3200 |
3096 /** | 3201 /** |
3097 * Given a list of arguments and the parameters related to the element that wi
ll be invoked using | 3202 * Given a list of arguments and the parameters related to the element that wi
ll be invoked using |
3098 * those argument, compute the list of parameters that correspond to the list
of arguments. Return | 3203 * those argument, compute the list of parameters that correspond to the list
of arguments. Return |
3099 * the parameters that correspond to the arguments. | 3204 * the parameters that correspond to the arguments. |
3100 * @param reportError if `true` then compile-time error should be reported; if
`false`then compile-time warning | 3205 * |
| 3206 * @param reportError if `true` then compile-time error should be reported; if
`false` |
| 3207 * then compile-time warning |
3101 * @param argumentList the list of arguments being passed to the element | 3208 * @param argumentList the list of arguments being passed to the element |
3102 * @param parameters the of the function that will be invoked with the argumen
ts | 3209 * @param parameters the of the function that will be invoked with the argumen
ts |
3103 * @return the parameters that correspond to the arguments | 3210 * @return the parameters that correspond to the arguments |
3104 */ | 3211 */ |
3105 List<ParameterElement> resolveArgumentsToParameters2(bool reportError2, Argume
ntList argumentList, List<ParameterElement> parameters) { | 3212 List<ParameterElement> resolveArgumentsToParameters2(bool reportError2, Argume
ntList argumentList, List<ParameterElement> parameters) { |
3106 List<ParameterElement> requiredParameters = new List<ParameterElement>(); | 3213 List<ParameterElement> requiredParameters = new List<ParameterElement>(); |
3107 List<ParameterElement> positionalParameters = new List<ParameterElement>(); | 3214 List<ParameterElement> positionalParameters = new List<ParameterElement>(); |
3108 Map<String, ParameterElement> namedParameters = new Map<String, ParameterEle
ment>(); | 3215 Map<String, ParameterElement> namedParameters = new Map<String, ParameterEle
ment>(); |
3109 for (ParameterElement parameter in parameters) { | 3216 for (ParameterElement parameter in parameters) { |
3110 ParameterKind kind = parameter.parameterKind; | 3217 ParameterKind kind = parameter.parameterKind; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3153 _resolver.reportError(errorCode, argumentList, [requiredParameters.length,
positionalArgumentCount]); | 3260 _resolver.reportError(errorCode, argumentList, [requiredParameters.length,
positionalArgumentCount]); |
3154 } else if (positionalArgumentCount > unnamedParameterCount) { | 3261 } else if (positionalArgumentCount > unnamedParameterCount) { |
3155 ErrorCode errorCode = reportError2 ? CompileTimeErrorCode.EXTRA_POSITIONAL
_ARGUMENTS : StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS; | 3262 ErrorCode errorCode = reportError2 ? CompileTimeErrorCode.EXTRA_POSITIONAL
_ARGUMENTS : StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS; |
3156 _resolver.reportError(errorCode, argumentList, [unnamedParameterCount, pos
itionalArgumentCount]); | 3263 _resolver.reportError(errorCode, argumentList, [unnamedParameterCount, pos
itionalArgumentCount]); |
3157 } | 3264 } |
3158 return resolvedParameters; | 3265 return resolvedParameters; |
3159 } | 3266 } |
3160 | 3267 |
3161 /** | 3268 /** |
3162 * Resolve the names in the given combinators in the scope of the given librar
y. | 3269 * Resolve the names in the given combinators in the scope of the given librar
y. |
| 3270 * |
3163 * @param library the library that defines the names | 3271 * @param library the library that defines the names |
3164 * @param combinators the combinators containing the names to be resolved | 3272 * @param combinators the combinators containing the names to be resolved |
3165 */ | 3273 */ |
3166 void resolveCombinators(LibraryElement library, NodeList<Combinator> combinato
rs) { | 3274 void resolveCombinators(LibraryElement library, NodeList<Combinator> combinato
rs) { |
3167 if (library == null) { | 3275 if (library == null) { |
3168 return; | 3276 return; |
3169 } | 3277 } |
3170 Namespace namespace = new NamespaceBuilder().createExportNamespace2(library)
; | 3278 Namespace namespace = new NamespaceBuilder().createExportNamespace2(library)
; |
3171 for (Combinator combinator in combinators) { | 3279 for (Combinator combinator in combinators) { |
3172 NodeList<SimpleIdentifier> names; | 3280 NodeList<SimpleIdentifier> names; |
3173 if (combinator is HideCombinator) { | 3281 if (combinator is HideCombinator) { |
3174 names = ((combinator as HideCombinator)).hiddenNames; | 3282 names = ((combinator as HideCombinator)).hiddenNames; |
3175 } else { | 3283 } else { |
3176 names = ((combinator as ShowCombinator)).shownNames; | 3284 names = ((combinator as ShowCombinator)).shownNames; |
3177 } | 3285 } |
3178 for (SimpleIdentifier name in names) { | 3286 for (SimpleIdentifier name in names) { |
3179 Element element = namespace.get(name.name); | 3287 Element element = namespace.get(name.name); |
3180 if (element != null) { | 3288 if (element != null) { |
3181 name.element = element; | 3289 name.element = element; |
3182 } | 3290 } |
3183 } | 3291 } |
3184 } | 3292 } |
3185 } | 3293 } |
3186 | 3294 |
3187 /** | 3295 /** |
3188 * Given an invocation of the form 'e.m(a1, ..., an)', resolve 'e.m' to the el
ement being invoked. | 3296 * Given an invocation of the form 'e.m(a1, ..., an)', resolve 'e.m' to the el
ement being invoked. |
3189 * If the returned element is a method, then the method will be invoked. If th
e returned element | 3297 * If the returned element is a method, then the method will be invoked. If th
e returned element |
3190 * is a getter, the getter will be invoked without arguments and the result of
that invocation | 3298 * is a getter, the getter will be invoked without arguments and the result of
that invocation |
3191 * will then be invoked with the arguments. | 3299 * will then be invoked with the arguments. |
| 3300 * |
3192 * @param target the target of the invocation ('e') | 3301 * @param target the target of the invocation ('e') |
3193 * @param targetType the type of the target | 3302 * @param targetType the type of the target |
3194 * @param methodName the name of the method being invoked ('m') | 3303 * @param methodName the name of the method being invoked ('m') |
3195 * @return the element being invoked | 3304 * @return the element being invoked |
3196 */ | 3305 */ |
3197 Element resolveInvokedElement(Expression target, Type2 targetType, SimpleIdent
ifier methodName) { | 3306 Element resolveInvokedElement(Expression target, Type2 targetType, SimpleIdent
ifier methodName) { |
3198 if (targetType is InterfaceType) { | 3307 if (targetType is InterfaceType) { |
3199 InterfaceType classType = targetType as InterfaceType; | 3308 InterfaceType classType = targetType as InterfaceType; |
3200 Element element = lookUpMethod(target, classType, methodName.name); | 3309 Element element = lookUpMethod(target, classType, methodName.name); |
3201 if (element == null) { | 3310 if (element == null) { |
3202 element = classType.getGetter(methodName.name); | 3311 element = lookUpGetter(target, classType, methodName.name); |
3203 } | 3312 } |
3204 return element; | 3313 return element; |
3205 } else if (target is SimpleIdentifier) { | 3314 } else if (target is SimpleIdentifier) { |
3206 Element targetElement = ((target as SimpleIdentifier)).element; | 3315 Element targetElement = ((target as SimpleIdentifier)).element; |
3207 if (targetElement is PrefixElement) { | 3316 if (targetElement is PrefixElement) { |
3208 String name = "${((target as SimpleIdentifier)).name}.${methodName}"; | 3317 String name = "${((target as SimpleIdentifier)).name}.${methodName}"; |
3209 Identifier functionName = new ElementResolver_SyntheticIdentifier(name); | 3318 Identifier functionName = new ElementResolver_SyntheticIdentifier(name); |
3210 Element element = _resolver.nameScope.lookup(functionName, _resolver.def
iningLibrary); | 3319 Element element = _resolver.nameScope.lookup(functionName, _resolver.def
iningLibrary); |
3211 if (element != null) { | 3320 if (element != null) { |
3212 return element; | 3321 return element; |
3213 } | 3322 } |
3214 } | 3323 } |
3215 } | 3324 } |
3216 return null; | 3325 return null; |
3217 } | 3326 } |
3218 | 3327 |
3219 /** | 3328 /** |
3220 * Given an invocation of the form 'm(a1, ..., an)', resolve 'm' to the elemen
t being invoked. If | 3329 * Given an invocation of the form 'm(a1, ..., an)', resolve 'm' to the elemen
t being invoked. If |
3221 * the returned element is a method, then the method will be invoked. If the r
eturned element is a | 3330 * the returned element is a method, then the method will be invoked. If the r
eturned element is a |
3222 * getter, the getter will be invoked without arguments and the result of that
invocation will | 3331 * getter, the getter will be invoked without arguments and the result of that
invocation will |
3223 * then be invoked with the arguments. | 3332 * then be invoked with the arguments. |
| 3333 * |
3224 * @param methodName the name of the method being invoked ('m') | 3334 * @param methodName the name of the method being invoked ('m') |
3225 * @return the element being invoked | 3335 * @return the element being invoked |
3226 */ | 3336 */ |
3227 Element resolveInvokedElement2(SimpleIdentifier methodName) { | 3337 Element resolveInvokedElement2(SimpleIdentifier methodName) { |
3228 Element element = _resolver.nameScope.lookup(methodName, _resolver.definingL
ibrary); | 3338 Element element = _resolver.nameScope.lookup(methodName, _resolver.definingL
ibrary); |
3229 if (element == null) { | 3339 if (element == null) { |
3230 ClassElement enclosingClass = _resolver.enclosingClass; | 3340 ClassElement enclosingClass = _resolver.enclosingClass; |
3231 if (enclosingClass != null) { | 3341 if (enclosingClass != null) { |
3232 InterfaceType enclosingType = enclosingClass.type; | 3342 InterfaceType enclosingType = enclosingClass.type; |
3233 element = lookUpMethod(null, enclosingType, methodName.name); | 3343 element = lookUpMethod(null, enclosingType, methodName.name); |
3234 if (element == null) { | 3344 if (element == null) { |
3235 element = lookUpGetter(null, enclosingType, methodName.name); | 3345 element = lookUpGetter(null, enclosingType, methodName.name); |
3236 } | 3346 } |
3237 } | 3347 } |
3238 } | 3348 } |
3239 return element; | 3349 return element; |
3240 } | 3350 } |
3241 | 3351 |
3242 /** | 3352 /** |
3243 * Given that we are accessing a property of the given type with the given nam
e, return the | 3353 * Given that we are accessing a property of the given type with the given nam
e, return the |
3244 * element that represents the property. | 3354 * element that represents the property. |
| 3355 * |
3245 * @param target the target of the invocation ('e') | 3356 * @param target the target of the invocation ('e') |
3246 * @param targetType the type in which the search for the property should begi
n | 3357 * @param targetType the type in which the search for the property should begi
n |
3247 * @param propertyName the name of the property being accessed | 3358 * @param propertyName the name of the property being accessed |
3248 * @return the element that represents the property | 3359 * @return the element that represents the property |
3249 */ | 3360 */ |
3250 ExecutableElement resolveProperty(Expression target, Type2 targetType, SimpleI
dentifier propertyName) { | 3361 ExecutableElement resolveProperty(Expression target, Type2 targetType, SimpleI
dentifier propertyName) { |
3251 ExecutableElement memberElement = null; | 3362 ExecutableElement memberElement = null; |
3252 if (propertyName.inSetterContext()) { | 3363 if (propertyName.inSetterContext()) { |
3253 memberElement = lookUpSetter(target, targetType, propertyName.name); | 3364 memberElement = lookUpSetter(target, targetType, propertyName.name); |
3254 } | 3365 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3289 _resolver.reportError(StaticWarningCode.UNDEFINED_IDENTIFIER, property
Name, [propertyName.name]); | 3400 _resolver.reportError(StaticWarningCode.UNDEFINED_IDENTIFIER, property
Name, [propertyName.name]); |
3290 } | 3401 } |
3291 } | 3402 } |
3292 } | 3403 } |
3293 } | 3404 } |
3294 | 3405 |
3295 /** | 3406 /** |
3296 * Resolve the given simple identifier if possible. Return the element to whic
h it could be | 3407 * Resolve the given simple identifier if possible. Return the element to whic
h it could be |
3297 * resolved, or `null` if it could not be resolved. This does not record the r
esults of the | 3408 * resolved, or `null` if it could not be resolved. This does not record the r
esults of the |
3298 * resolution. | 3409 * resolution. |
| 3410 * |
3299 * @param node the identifier to be resolved | 3411 * @param node the identifier to be resolved |
3300 * @return the element to which the identifier could be resolved | 3412 * @return the element to which the identifier could be resolved |
3301 */ | 3413 */ |
3302 Element resolveSimpleIdentifier(SimpleIdentifier node) { | 3414 Element resolveSimpleIdentifier(SimpleIdentifier node) { |
3303 Element element = _resolver.nameScope.lookup(node, _resolver.definingLibrary
); | 3415 Element element = _resolver.nameScope.lookup(node, _resolver.definingLibrary
); |
3304 if (element is PropertyAccessorElement && node.inSetterContext()) { | 3416 if (element is PropertyAccessorElement && node.inSetterContext()) { |
3305 PropertyInducingElement variable = ((element as PropertyAccessorElement)).
variable; | 3417 PropertyInducingElement variable = ((element as PropertyAccessorElement)).
variable; |
3306 if (variable != null) { | 3418 if (variable != null) { |
3307 PropertyAccessorElement setter = variable.setter; | 3419 PropertyAccessorElement setter = variable.setter; |
3308 if (setter == null) { | 3420 if (setter == null) { |
(...skipping 21 matching lines...) Expand all Loading... |
3330 if (element == null) { | 3442 if (element == null) { |
3331 element = lookUpMethod(null, enclosingType, node.name); | 3443 element = lookUpMethod(null, enclosingType, node.name); |
3332 } | 3444 } |
3333 } | 3445 } |
3334 return element; | 3446 return element; |
3335 } | 3447 } |
3336 | 3448 |
3337 /** | 3449 /** |
3338 * If the given type is a type variable, resolve it to the type that should be
used when looking | 3450 * If the given type is a type variable, resolve it to the type that should be
used when looking |
3339 * up members. Otherwise, return the original type. | 3451 * up members. Otherwise, return the original type. |
| 3452 * |
3340 * @param type the type that is to be resolved if it is a type variable | 3453 * @param type the type that is to be resolved if it is a type variable |
3341 * @return the type that should be used in place of the argument if it is a ty
pe variable, or the | 3454 * @return the type that should be used in place of the argument if it is a ty
pe variable, or the |
3342 * original argument if it isn't a type variable | 3455 * original argument if it isn't a type variable |
3343 */ | 3456 */ |
3344 Type2 resolveTypeVariable(Type2 type) { | 3457 Type2 resolveTypeVariable(Type2 type) { |
3345 if (type is TypeVariableType) { | 3458 if (type is TypeVariableType) { |
3346 Type2 bound = ((type as TypeVariableType)).element.bound; | 3459 Type2 bound = ((type as TypeVariableType)).element.bound; |
3347 if (bound == null) { | 3460 if (bound == null) { |
3348 return _resolver.typeProvider.objectType; | 3461 return _resolver.typeProvider.objectType; |
3349 } | 3462 } |
3350 return bound; | 3463 return bound; |
3351 } | 3464 } |
3352 return type; | 3465 return type; |
3353 } | 3466 } |
3354 | 3467 |
3355 /** | 3468 /** |
3356 * Return the propagated element if it is not `null`, or the static element if
it is. | 3469 * Return the propagated element if it is not `null`, or the static element if
it is. |
| 3470 * |
3357 * @param staticElement the element computed using static type information | 3471 * @param staticElement the element computed using static type information |
3358 * @param propagatedElement the element computed using propagated type informa
tion | 3472 * @param propagatedElement the element computed using propagated type informa
tion |
3359 * @return the more specific of the two elements | 3473 * @return the more specific of the two elements |
3360 */ | 3474 */ |
3361 ExecutableElement select(ExecutableElement staticElement, ExecutableElement pr
opagatedElement) => propagatedElement != null ? propagatedElement : staticElemen
t; | 3475 ExecutableElement select(ExecutableElement staticElement, ExecutableElement pr
opagatedElement) => propagatedElement != null ? propagatedElement : staticElemen
t; |
3362 | 3476 |
3363 /** | 3477 /** |
3364 * Return the propagated method if it is not `null`, or the static method if i
t is. | 3478 * Return the propagated method if it is not `null`, or the static method if i
t is. |
| 3479 * |
3365 * @param staticMethod the method computed using static type information | 3480 * @param staticMethod the method computed using static type information |
3366 * @param propagatedMethod the method computed using propagated type informati
on | 3481 * @param propagatedMethod the method computed using propagated type informati
on |
3367 * @return the more specific of the two methods | 3482 * @return the more specific of the two methods |
3368 */ | 3483 */ |
3369 MethodElement select2(MethodElement staticMethod, MethodElement propagatedMeth
od) => propagatedMethod != null ? propagatedMethod : staticMethod; | 3484 MethodElement select2(MethodElement staticMethod, MethodElement propagatedMeth
od) => propagatedMethod != null ? propagatedMethod : staticMethod; |
3370 | 3485 |
3371 /** | 3486 /** |
3372 * Given a node that can have annotations associated with it and the element t
o which that node | 3487 * Given a node that can have annotations associated with it and the element t
o which that node |
3373 * has been resolved, create the annotations in the element model representing
the annotations on | 3488 * has been resolved, create the annotations in the element model representing
the annotations on |
3374 * the node. | 3489 * the node. |
| 3490 * |
3375 * @param element the element to which the node has been resolved | 3491 * @param element the element to which the node has been resolved |
3376 * @param node the node that can have annotations associated with it | 3492 * @param node the node that can have annotations associated with it |
3377 */ | 3493 */ |
3378 void setMetadata(Element element, AnnotatedNode node) { | 3494 void setMetadata(Element element, AnnotatedNode node) { |
3379 if (element is! ElementImpl) { | 3495 if (element is! ElementImpl) { |
3380 return; | 3496 return; |
3381 } | 3497 } |
3382 List<ElementAnnotationImpl> annotationList = new List<ElementAnnotationImpl>
(); | 3498 List<ElementAnnotationImpl> annotationList = new List<ElementAnnotationImpl>
(); |
3383 addAnnotations(annotationList, node.metadata); | 3499 addAnnotations(annotationList, node.metadata); |
3384 if (node is VariableDeclaration && node.parent is VariableDeclarationList) { | 3500 if (node is VariableDeclaration && node.parent is VariableDeclarationList) { |
3385 VariableDeclarationList list = node.parent as VariableDeclarationList; | 3501 VariableDeclarationList list = node.parent as VariableDeclarationList; |
3386 addAnnotations(annotationList, list.metadata); | 3502 addAnnotations(annotationList, list.metadata); |
3387 if (list.parent is FieldDeclaration) { | 3503 if (list.parent is FieldDeclaration) { |
3388 FieldDeclaration fieldDeclaration = list.parent as FieldDeclaration; | 3504 FieldDeclaration fieldDeclaration = list.parent as FieldDeclaration; |
3389 addAnnotations(annotationList, fieldDeclaration.metadata); | 3505 addAnnotations(annotationList, fieldDeclaration.metadata); |
3390 } else if (list.parent is TopLevelVariableDeclaration) { | 3506 } else if (list.parent is TopLevelVariableDeclaration) { |
3391 TopLevelVariableDeclaration variableDeclaration = list.parent as TopLeve
lVariableDeclaration; | 3507 TopLevelVariableDeclaration variableDeclaration = list.parent as TopLeve
lVariableDeclaration; |
3392 addAnnotations(annotationList, variableDeclaration.metadata); | 3508 addAnnotations(annotationList, variableDeclaration.metadata); |
3393 } | 3509 } |
3394 } | 3510 } |
3395 if (!annotationList.isEmpty) { | 3511 if (!annotationList.isEmpty) { |
3396 ((element as ElementImpl)).metadata = new List.from(annotationList); | 3512 ((element as ElementImpl)).metadata = new List.from(annotationList); |
3397 } | 3513 } |
3398 } | 3514 } |
3399 | 3515 |
3400 /** | 3516 /** |
3401 * Return `true` if we should report an error as a result of looking up a memb
er in the | 3517 * Return `true` if we should report an error as a result of looking up a memb
er in the |
3402 * given type and not finding any member. | 3518 * given type and not finding any member. |
| 3519 * |
3403 * @param type the type in which we attempted to perform the look-up | 3520 * @param type the type in which we attempted to perform the look-up |
3404 * @param member the result of the look-up | 3521 * @param member the result of the look-up |
3405 * @return `true` if we should report an error | 3522 * @return `true` if we should report an error |
3406 */ | 3523 */ |
3407 bool shouldReportMissingMember(Type2 type, ExecutableElement member) { | 3524 bool shouldReportMissingMember(Type2 type, ExecutableElement member) { |
3408 if (member != null || type == null || type.isDynamic) { | 3525 if (member != null || type == null || type.isDynamic) { |
3409 return false; | 3526 return false; |
3410 } | 3527 } |
3411 if (type is InterfaceType) { | 3528 if (type is InterfaceType) { |
3412 return !classDeclaresNoSuchMethod(((type as InterfaceType)).element); | 3529 return !classDeclaresNoSuchMethod(((type as InterfaceType)).element); |
3413 } | 3530 } |
3414 return true; | 3531 return true; |
3415 } | 3532 } |
3416 } | 3533 } |
3417 /** | 3534 /** |
3418 * Instances of the class `SyntheticIdentifier` implement an identifier that can
be used to | 3535 * Instances of the class `SyntheticIdentifier` implement an identifier that can
be used to |
3419 * look up names in the lexical scope when there is no identifier in the AST str
ucture. There is | 3536 * look up names in the lexical scope when there is no identifier in the AST str
ucture. There is |
3420 * no identifier in the AST when the parser could not distinguish between a meth
od invocation and | 3537 * no identifier in the AST when the parser could not distinguish between a meth
od invocation and |
3421 * an invocation of a top-level function imported with a prefix. | 3538 * an invocation of a top-level function imported with a prefix. |
3422 */ | 3539 */ |
3423 class ElementResolver_SyntheticIdentifier extends Identifier { | 3540 class ElementResolver_SyntheticIdentifier extends Identifier { |
3424 | 3541 |
3425 /** | 3542 /** |
3426 * The name of the synthetic identifier. | 3543 * The name of the synthetic identifier. |
3427 */ | 3544 */ |
3428 String _name; | 3545 String _name; |
3429 | 3546 |
3430 /** | 3547 /** |
3431 * Initialize a newly created synthetic identifier to have the given name. | 3548 * Initialize a newly created synthetic identifier to have the given name. |
| 3549 * |
3432 * @param name the name of the synthetic identifier | 3550 * @param name the name of the synthetic identifier |
3433 */ | 3551 */ |
3434 ElementResolver_SyntheticIdentifier(String name) { | 3552 ElementResolver_SyntheticIdentifier(String name) { |
3435 this._name = name; | 3553 this._name = name; |
3436 } | 3554 } |
3437 accept(ASTVisitor visitor) => null; | 3555 accept(ASTVisitor visitor) => null; |
3438 sc.Token get beginToken => null; | 3556 sc.Token get beginToken => null; |
3439 Element get element => null; | 3557 Element get element => null; |
3440 sc.Token get endToken => null; | 3558 sc.Token get endToken => null; |
3441 String get name => _name; | 3559 String get name => _name; |
3442 Element get staticElement => null; | 3560 Element get staticElement => null; |
3443 void visitChildren(ASTVisitor<Object> visitor) { | 3561 void visitChildren(ASTVisitor<Object> visitor) { |
3444 } | 3562 } |
3445 } | 3563 } |
3446 /** | 3564 /** |
3447 * Instances of the class `InheritanceManager` manage the knowledge of where cla
ss members | 3565 * Instances of the class `InheritanceManager` manage the knowledge of where cla
ss members |
3448 * (methods, getters & setters) are inherited from. | 3566 * (methods, getters & setters) are inherited from. |
| 3567 * |
3449 * @coverage dart.engine.resolver | 3568 * @coverage dart.engine.resolver |
3450 */ | 3569 */ |
3451 class InheritanceManager { | 3570 class InheritanceManager { |
3452 | 3571 |
3453 /** | 3572 /** |
3454 * The [LibraryElement] that is managed by this manager. | 3573 * The [LibraryElement] that is managed by this manager. |
3455 */ | 3574 */ |
3456 LibraryElement _library; | 3575 LibraryElement _library; |
3457 | 3576 |
3458 /** | 3577 /** |
3459 * This is a mapping between each [ClassElement] and a map between the [String
] member | 3578 * This is a mapping between each [ClassElement] and a map between the [String
] member |
3460 * names and the associated [ExecutableElement] in the mixin and superclass ch
ain. | 3579 * names and the associated [ExecutableElement] in the mixin and superclass ch
ain. |
3461 */ | 3580 */ |
3462 Map<ClassElement, Map<String, ExecutableElement>> _classLookup; | 3581 Map<ClassElement, Map<String, ExecutableElement>> _classLookup; |
3463 | 3582 |
3464 /** | 3583 /** |
3465 * This is a mapping between each [ClassElement] and a map between the [String
] member | 3584 * This is a mapping between each [ClassElement] and a map between the [String
] member |
3466 * names and the associated [ExecutableElement] in the interface set. | 3585 * names and the associated [ExecutableElement] in the interface set. |
3467 */ | 3586 */ |
3468 Map<ClassElement, Map<String, ExecutableElement>> _interfaceLookup; | 3587 Map<ClassElement, Map<String, ExecutableElement>> _interfaceLookup; |
3469 | 3588 |
3470 /** | 3589 /** |
3471 * A map between each visited [ClassElement] and the set of [AnalysisError]s f
ound on | 3590 * A map between each visited [ClassElement] and the set of [AnalysisError]s f
ound on |
3472 * the class element. | 3591 * the class element. |
3473 */ | 3592 */ |
3474 Map<ClassElement, Set<AnalysisError>> _errorsInClassElement = new Map<ClassEle
ment, Set<AnalysisError>>(); | 3593 Map<ClassElement, Set<AnalysisError>> _errorsInClassElement = new Map<ClassEle
ment, Set<AnalysisError>>(); |
3475 | 3594 |
3476 /** | 3595 /** |
3477 * Initialize a newly created inheritance manager. | 3596 * Initialize a newly created inheritance manager. |
| 3597 * |
3478 * @param library the library element context that the inheritance mappings ar
e being generated | 3598 * @param library the library element context that the inheritance mappings ar
e being generated |
3479 */ | 3599 */ |
3480 InheritanceManager(LibraryElement library) { | 3600 InheritanceManager(LibraryElement library) { |
3481 this._library = library; | 3601 this._library = library; |
3482 _classLookup = new Map<ClassElement, Map<String, ExecutableElement>>(); | 3602 _classLookup = new Map<ClassElement, Map<String, ExecutableElement>>(); |
3483 _interfaceLookup = new Map<ClassElement, Map<String, ExecutableElement>>(); | 3603 _interfaceLookup = new Map<ClassElement, Map<String, ExecutableElement>>(); |
3484 } | 3604 } |
3485 | 3605 |
3486 /** | 3606 /** |
3487 * Return the set of [AnalysisError]s found on the passed [ClassElement], or`n
ull` if there are none. | 3607 * Return the set of [AnalysisError]s found on the passed [ClassElement], or |
| 3608 * `null` if there are none. |
| 3609 * |
3488 * @param classElt the class element to query | 3610 * @param classElt the class element to query |
3489 * @return the set of [AnalysisError]s found on the passed [ClassElement], or`
null` if there are none | 3611 * @return the set of [AnalysisError]s found on the passed [ClassElement], or |
| 3612 * `null` if there are none |
3490 */ | 3613 */ |
3491 Set<AnalysisError> getErrors(ClassElement classElt) => _errorsInClassElement[c
lassElt]; | 3614 Set<AnalysisError> getErrors(ClassElement classElt) => _errorsInClassElement[c
lassElt]; |
3492 | 3615 |
3493 /** | 3616 /** |
3494 * Get and return a mapping between the set of all string names of the members
inherited from the | 3617 * Get and return a mapping between the set of all string names of the members
inherited from the |
3495 * passed [ClassElement] superclass hierarchy, and the associated [ExecutableE
lement]. | 3618 * passed [ClassElement] superclass hierarchy, and the associated [ExecutableE
lement]. |
| 3619 * |
3496 * @param classElt the class element to query | 3620 * @param classElt the class element to query |
3497 * @return a mapping between the set of all members inherited from the passed
[ClassElement]superclass hierarchy, and the associated [ExecutableElement] | 3621 * @return a mapping between the set of all members inherited from the passed
[ClassElement] |
| 3622 * superclass hierarchy, and the associated [ExecutableElement] |
3498 */ | 3623 */ |
3499 Map<String, ExecutableElement> getMapOfMembersInheritedFromClasses(ClassElemen
t classElt) => computeClassChainLookupMap(classElt, new Set<ClassElement>()); | 3624 Map<String, ExecutableElement> getMapOfMembersInheritedFromClasses(ClassElemen
t classElt) => computeClassChainLookupMap(classElt, new Set<ClassElement>()); |
3500 | 3625 |
3501 /** | 3626 /** |
3502 * Get and return a mapping between the set of all string names of the members
inherited from the | 3627 * Get and return a mapping between the set of all string names of the members
inherited from the |
3503 * passed [ClassElement] interface hierarchy, and the associated [ExecutableEl
ement]. | 3628 * passed [ClassElement] interface hierarchy, and the associated [ExecutableEl
ement]. |
| 3629 * |
3504 * @param classElt the class element to query | 3630 * @param classElt the class element to query |
3505 * @return a mapping between the set of all string names of the members inheri
ted from the passed[ClassElement] interface hierarchy, and the associated [Execu
tableElement]. | 3631 * @return a mapping between the set of all string names of the members inheri
ted from the passed |
| 3632 * [ClassElement] interface hierarchy, and the associated [ExecutableE
lement]. |
3506 */ | 3633 */ |
3507 Map<String, ExecutableElement> getMapOfMembersInheritedFromInterfaces(ClassEle
ment classElt) => computeInterfaceLookupMap(classElt, new Set<ClassElement>()); | 3634 Map<String, ExecutableElement> getMapOfMembersInheritedFromInterfaces(ClassEle
ment classElt) => computeInterfaceLookupMap(classElt, new Set<ClassElement>()); |
3508 | 3635 |
3509 /** | 3636 /** |
3510 * Given some [ClassElement class element] and some member name, this returns
the[ExecutableElement executable element] that the class inherits from the mixin
s, | 3637 * Given some [ClassElement] and some member name, this returns the |
| 3638 * [ExecutableElement] that the class inherits from the mixins, |
3511 * superclasses or interfaces, that has the member name, if no member is inher
ited `null` is | 3639 * superclasses or interfaces, that has the member name, if no member is inher
ited `null` is |
3512 * returned. | 3640 * returned. |
| 3641 * |
3513 * @param classElt the class element to query | 3642 * @param classElt the class element to query |
3514 * @param memberName the name of the executable element to find and return | 3643 * @param memberName the name of the executable element to find and return |
3515 * @return the inherited executable element with the member name, or `null` if
no such | 3644 * @return the inherited executable element with the member name, or `null` if
no such |
3516 * member exists | 3645 * member exists |
3517 */ | 3646 */ |
3518 ExecutableElement lookupInheritance(ClassElement classElt, String memberName)
{ | 3647 ExecutableElement lookupInheritance(ClassElement classElt, String memberName)
{ |
3519 if (memberName == null || memberName.isEmpty) { | 3648 if (memberName == null || memberName.isEmpty) { |
3520 return null; | 3649 return null; |
3521 } | 3650 } |
3522 ExecutableElement executable = computeClassChainLookupMap(classElt, new Set<
ClassElement>())[memberName]; | 3651 ExecutableElement executable = computeClassChainLookupMap(classElt, new Set<
ClassElement>())[memberName]; |
3523 if (executable == null) { | 3652 if (executable == null) { |
3524 return computeInterfaceLookupMap(classElt, new Set<ClassElement>())[member
Name]; | 3653 return computeInterfaceLookupMap(classElt, new Set<ClassElement>())[member
Name]; |
3525 } | 3654 } |
3526 return executable; | 3655 return executable; |
3527 } | 3656 } |
3528 | 3657 |
3529 /** | 3658 /** |
3530 * Given some [ClassElement class element] and some member name, this returns
the[ExecutableElement executable element] that the class either declares itself,
or | 3659 * Given some [ClassElement] and some member name, this returns the |
| 3660 * [ExecutableElement] that the class either declares itself, or |
3531 * inherits, that has the member name, if no member is inherited `null` is ret
urned. | 3661 * inherits, that has the member name, if no member is inherited `null` is ret
urned. |
| 3662 * |
3532 * @param classElt the class element to query | 3663 * @param classElt the class element to query |
3533 * @param memberName the name of the executable element to find and return | 3664 * @param memberName the name of the executable element to find and return |
3534 * @return the inherited executable element with the member name, or `null` if
no such | 3665 * @return the inherited executable element with the member name, or `null` if
no such |
3535 * member exists | 3666 * member exists |
3536 */ | 3667 */ |
3537 ExecutableElement lookupMember(ClassElement classElt, String memberName) { | 3668 ExecutableElement lookupMember(ClassElement classElt, String memberName) { |
3538 ExecutableElement element = lookupMemberInClass(classElt, memberName); | 3669 ExecutableElement element = lookupMemberInClass(classElt, memberName); |
3539 if (element != null) { | 3670 if (element != null) { |
3540 return element; | 3671 return element; |
3541 } | 3672 } |
3542 return lookupInheritance(classElt, memberName); | 3673 return lookupInheritance(classElt, memberName); |
3543 } | 3674 } |
3544 | 3675 |
3545 /** | 3676 /** |
3546 * Set the new library element context. | 3677 * Set the new library element context. |
| 3678 * |
3547 * @param library the new library element | 3679 * @param library the new library element |
3548 */ | 3680 */ |
3549 void set libraryElement(LibraryElement library2) { | 3681 void set libraryElement(LibraryElement library2) { |
3550 this._library = library2; | 3682 this._library = library2; |
3551 } | 3683 } |
3552 | 3684 |
3553 /** | 3685 /** |
3554 * This method takes some inherited [FunctionType], and resolves all the param
eterized types | 3686 * This method takes some inherited [FunctionType], and resolves all the param
eterized types |
3555 * in the function type, dependent on the class in which it is being overridde
n. | 3687 * in the function type, dependent on the class in which it is being overridde
n. |
| 3688 * |
3556 * @param baseFunctionType the function type that is being overridden | 3689 * @param baseFunctionType the function type that is being overridden |
3557 * @param memberName the name of the member, this is used to lookup the inheri
tance path of the | 3690 * @param memberName the name of the member, this is used to lookup the inheri
tance path of the |
3558 * override | 3691 * override |
3559 * @param definingType the type that is overriding the member | 3692 * @param definingType the type that is overriding the member |
3560 * @return the passed function type with any parameterized types substituted | 3693 * @return the passed function type with any parameterized types substituted |
3561 */ | 3694 */ |
3562 FunctionType substituteTypeArgumentsInMemberFromInheritance(FunctionType baseF
unctionType, String memberName, InterfaceType definingType) { | 3695 FunctionType substituteTypeArgumentsInMemberFromInheritance(FunctionType baseF
unctionType, String memberName, InterfaceType definingType) { |
3563 if (baseFunctionType == null) { | 3696 if (baseFunctionType == null) { |
3564 return baseFunctionType; | 3697 return baseFunctionType; |
3565 } | 3698 } |
3566 Queue<InterfaceType> inheritancePath = new Queue<InterfaceType>(); | 3699 Queue<InterfaceType> inheritancePath = new Queue<InterfaceType>(); |
3567 computeInheritancePath(inheritancePath, definingType, memberName); | 3700 computeInheritancePath(inheritancePath, definingType, memberName); |
3568 if (inheritancePath == null || inheritancePath.length < 2) { | 3701 if (inheritancePath == null || inheritancePath.length < 2) { |
3569 return baseFunctionType; | 3702 return baseFunctionType; |
3570 } | 3703 } |
3571 FunctionType functionTypeToReturn = baseFunctionType; | 3704 FunctionType functionTypeToReturn = baseFunctionType; |
3572 InterfaceType lastType = inheritancePath.removeLast(); | 3705 InterfaceType lastType = inheritancePath.removeLast(); |
3573 while (inheritancePath.length > 0) { | 3706 while (inheritancePath.length > 0) { |
3574 List<Type2> parameterTypes = lastType.element.type.typeArguments; | 3707 List<Type2> parameterTypes = lastType.element.type.typeArguments; |
3575 List<Type2> argumentTypes = lastType.typeArguments; | 3708 List<Type2> argumentTypes = lastType.typeArguments; |
3576 functionTypeToReturn = functionTypeToReturn.substitute2(argumentTypes, par
ameterTypes); | 3709 functionTypeToReturn = functionTypeToReturn.substitute2(argumentTypes, par
ameterTypes); |
3577 lastType = inheritancePath.removeLast(); | 3710 lastType = inheritancePath.removeLast(); |
3578 } | 3711 } |
3579 return functionTypeToReturn; | 3712 return functionTypeToReturn; |
3580 } | 3713 } |
3581 | 3714 |
3582 /** | 3715 /** |
3583 * Compute and return a mapping between the set of all string names of the mem
bers inherited from | 3716 * Compute and return a mapping between the set of all string names of the mem
bers inherited from |
3584 * the passed [ClassElement] superclass hierarchy, and the associated[Executab
leElement]. | 3717 * the passed [ClassElement] superclass hierarchy, and the associated |
| 3718 * [ExecutableElement]. |
| 3719 * |
3585 * @param classElt the class element to query | 3720 * @param classElt the class element to query |
3586 * @param visitedClasses a set of visited classes passed back into this method
when it calls | 3721 * @param visitedClasses a set of visited classes passed back into this method
when it calls |
3587 * itself recursively | 3722 * itself recursively |
3588 * @return a mapping between the set of all string names of the members inheri
ted from the passed[ClassElement] superclass hierarchy, and the associated [Exec
utableElement] | 3723 * @return a mapping between the set of all string names of the members inheri
ted from the passed |
| 3724 * [ClassElement] superclass hierarchy, and the associated [Executable
Element] |
3589 */ | 3725 */ |
3590 Map<String, ExecutableElement> computeClassChainLookupMap(ClassElement classEl
t, Set<ClassElement> visitedClasses) { | 3726 Map<String, ExecutableElement> computeClassChainLookupMap(ClassElement classEl
t, Set<ClassElement> visitedClasses) { |
3591 Map<String, ExecutableElement> resultMap = _classLookup[classElt]; | 3727 Map<String, ExecutableElement> resultMap = _classLookup[classElt]; |
3592 if (resultMap != null) { | 3728 if (resultMap != null) { |
3593 return resultMap; | 3729 return resultMap; |
3594 } else { | 3730 } else { |
3595 resultMap = new Map<String, ExecutableElement>(); | 3731 resultMap = new Map<String, ExecutableElement>(); |
3596 } | 3732 } |
3597 ClassElement superclassElt = null; | 3733 ClassElement superclassElt = null; |
3598 InterfaceType supertype = classElt.supertype; | 3734 InterfaceType supertype = classElt.supertype; |
(...skipping 20 matching lines...) Expand all Loading... |
3619 recordMapWithClassMembers(resultMap, mixinElement); | 3755 recordMapWithClassMembers(resultMap, mixinElement); |
3620 } | 3756 } |
3621 } | 3757 } |
3622 _classLookup[classElt] = resultMap; | 3758 _classLookup[classElt] = resultMap; |
3623 return resultMap; | 3759 return resultMap; |
3624 } | 3760 } |
3625 | 3761 |
3626 /** | 3762 /** |
3627 * Compute and return the inheritance path given the context of a type and a m
ember that is | 3763 * Compute and return the inheritance path given the context of a type and a m
ember that is |
3628 * overridden in the inheritance path (for which the type is in the path). | 3764 * overridden in the inheritance path (for which the type is in the path). |
| 3765 * |
3629 * @param chain the inheritance path that is built up as this method calls its
elf recursively, | 3766 * @param chain the inheritance path that is built up as this method calls its
elf recursively, |
3630 * when this method is called an empty [LinkedList] should be provided | 3767 * when this method is called an empty [LinkedList] should be provide
d |
3631 * @param currentType the current type in the inheritance path | 3768 * @param currentType the current type in the inheritance path |
3632 * @param memberName the name of the member that is being looked up the inheri
tance path | 3769 * @param memberName the name of the member that is being looked up the inheri
tance path |
3633 */ | 3770 */ |
3634 void computeInheritancePath(Queue<InterfaceType> chain, InterfaceType currentT
ype, String memberName) { | 3771 void computeInheritancePath(Queue<InterfaceType> chain, InterfaceType currentT
ype, String memberName) { |
3635 chain.add(currentType); | 3772 chain.add(currentType); |
3636 ClassElement classElt = currentType.element; | 3773 ClassElement classElt = currentType.element; |
3637 InterfaceType supertype = classElt.supertype; | 3774 InterfaceType supertype = classElt.supertype; |
3638 if (supertype == null) { | 3775 if (supertype == null) { |
3639 return; | 3776 return; |
3640 } | 3777 } |
(...skipping 23 matching lines...) Expand all Loading... |
3664 ClassElement interfaceElement = interfaceType.element; | 3801 ClassElement interfaceElement = interfaceType.element; |
3665 if (interfaceElement != null && lookupMember(interfaceElement, memberName)
!= null) { | 3802 if (interfaceElement != null && lookupMember(interfaceElement, memberName)
!= null) { |
3666 computeInheritancePath(chain, interfaceType, memberName); | 3803 computeInheritancePath(chain, interfaceType, memberName); |
3667 return; | 3804 return; |
3668 } | 3805 } |
3669 } | 3806 } |
3670 } | 3807 } |
3671 | 3808 |
3672 /** | 3809 /** |
3673 * Compute and return a mapping between the set of all string names of the mem
bers inherited from | 3810 * Compute and return a mapping between the set of all string names of the mem
bers inherited from |
3674 * the passed [ClassElement] interface hierarchy, and the associated[Executabl
eElement]. | 3811 * the passed [ClassElement] interface hierarchy, and the associated |
| 3812 * [ExecutableElement]. |
| 3813 * |
3675 * @param classElt the class element to query | 3814 * @param classElt the class element to query |
3676 * @param visitedInterfaces a set of visited classes passed back into this met
hod when it calls | 3815 * @param visitedInterfaces a set of visited classes passed back into this met
hod when it calls |
3677 * itself recursively | 3816 * itself recursively |
3678 * @return a mapping between the set of all string names of the members inheri
ted from the passed[ClassElement] interface hierarchy, and the associated [Execu
tableElement] | 3817 * @return a mapping between the set of all string names of the members inheri
ted from the passed |
| 3818 * [ClassElement] interface hierarchy, and the associated [ExecutableE
lement] |
3679 */ | 3819 */ |
3680 Map<String, ExecutableElement> computeInterfaceLookupMap(ClassElement classElt
, Set<ClassElement> visitedInterfaces) { | 3820 Map<String, ExecutableElement> computeInterfaceLookupMap(ClassElement classElt
, Set<ClassElement> visitedInterfaces) { |
3681 Map<String, ExecutableElement> resultMap = _interfaceLookup[classElt]; | 3821 Map<String, ExecutableElement> resultMap = _interfaceLookup[classElt]; |
3682 if (resultMap != null) { | 3822 if (resultMap != null) { |
3683 return resultMap; | 3823 return resultMap; |
3684 } else { | 3824 } else { |
3685 resultMap = new Map<String, ExecutableElement>(); | 3825 resultMap = new Map<String, ExecutableElement>(); |
3686 } | 3826 } |
3687 InterfaceType supertype = classElt.supertype; | 3827 InterfaceType supertype = classElt.supertype; |
3688 ClassElement superclassElement = supertype != null ? supertype.element : nul
l; | 3828 ClassElement superclassElement = supertype != null ? supertype.element : nul
l; |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3869 } | 4009 } |
3870 } | 4010 } |
3871 _interfaceLookup[classElt] = resultMap; | 4011 _interfaceLookup[classElt] = resultMap; |
3872 return resultMap; | 4012 return resultMap; |
3873 } | 4013 } |
3874 | 4014 |
3875 /** | 4015 /** |
3876 * Given some [ClassElement], this method finds and returns the [ExecutableEle
ment] of | 4016 * Given some [ClassElement], this method finds and returns the [ExecutableEle
ment] of |
3877 * the passed name in the class element. Static members, members in super type
s and members not | 4017 * the passed name in the class element. Static members, members in super type
s and members not |
3878 * accessible from the current library are not considered. | 4018 * accessible from the current library are not considered. |
| 4019 * |
3879 * @param classElt the class element to query | 4020 * @param classElt the class element to query |
3880 * @param memberName the name of the member to lookup in the class | 4021 * @param memberName the name of the member to lookup in the class |
3881 * @return the found [ExecutableElement], or `null` if no such member was foun
d | 4022 * @return the found [ExecutableElement], or `null` if no such member was foun
d |
3882 */ | 4023 */ |
3883 ExecutableElement lookupMemberInClass(ClassElement classElt, String memberName
) { | 4024 ExecutableElement lookupMemberInClass(ClassElement classElt, String memberName
) { |
3884 List<MethodElement> methods = classElt.methods; | 4025 List<MethodElement> methods = classElt.methods; |
3885 for (MethodElement method in methods) { | 4026 for (MethodElement method in methods) { |
3886 if (memberName == method.name && method.isAccessibleIn(_library) && !metho
d.isStatic) { | 4027 if (memberName == method.name && method.isAccessibleIn(_library) && !metho
d.isStatic) { |
3887 return method; | 4028 return method; |
3888 } | 4029 } |
3889 } | 4030 } |
3890 List<PropertyAccessorElement> accessors = classElt.accessors; | 4031 List<PropertyAccessorElement> accessors = classElt.accessors; |
3891 for (PropertyAccessorElement accessor in accessors) { | 4032 for (PropertyAccessorElement accessor in accessors) { |
3892 if (memberName == accessor.name && accessor.isAccessibleIn(_library) && !a
ccessor.isStatic) { | 4033 if (memberName == accessor.name && accessor.isAccessibleIn(_library) && !a
ccessor.isStatic) { |
3893 return accessor; | 4034 return accessor; |
3894 } | 4035 } |
3895 } | 4036 } |
3896 return null; | 4037 return null; |
3897 } | 4038 } |
3898 | 4039 |
3899 /** | 4040 /** |
3900 * Record the passed map with the set of all members (methods, getters and set
ters) in the class | 4041 * Record the passed map with the set of all members (methods, getters and set
ters) in the class |
3901 * into the passed map. | 4042 * into the passed map. |
| 4043 * |
3902 * @param map some non-`null` | 4044 * @param map some non-`null` |
3903 * @param classElt the class element that will be recorded into the passed map | 4045 * @param classElt the class element that will be recorded into the passed map |
3904 */ | 4046 */ |
3905 void recordMapWithClassMembers(Map<String, ExecutableElement> map, ClassElemen
t classElt) { | 4047 void recordMapWithClassMembers(Map<String, ExecutableElement> map, ClassElemen
t classElt) { |
3906 List<MethodElement> methods = classElt.methods; | 4048 List<MethodElement> methods = classElt.methods; |
3907 for (MethodElement method in methods) { | 4049 for (MethodElement method in methods) { |
3908 if (method.isAccessibleIn(_library) && !method.isStatic) { | 4050 if (method.isAccessibleIn(_library) && !method.isStatic) { |
3909 map[method.name] = method; | 4051 map[method.name] = method; |
3910 } | 4052 } |
3911 } | 4053 } |
3912 List<PropertyAccessorElement> accessors = classElt.accessors; | 4054 List<PropertyAccessorElement> accessors = classElt.accessors; |
3913 for (PropertyAccessorElement accessor in accessors) { | 4055 for (PropertyAccessorElement accessor in accessors) { |
3914 if (accessor.isAccessibleIn(_library) && !accessor.isStatic) { | 4056 if (accessor.isAccessibleIn(_library) && !accessor.isStatic) { |
3915 map[accessor.name] = accessor; | 4057 map[accessor.name] = accessor; |
3916 } | 4058 } |
3917 } | 4059 } |
3918 } | 4060 } |
3919 | 4061 |
3920 /** | 4062 /** |
3921 * This method is used to report errors on when they are found computing inher
itance information. | 4063 * This method is used to report errors on when they are found computing inher
itance information. |
3922 * See [ErrorVerifier#checkForInconsistentMethodInheritance] to see where thes
e generated | 4064 * See [ErrorVerifier#checkForInconsistentMethodInheritance] to see where thes
e generated |
3923 * error codes are reported back into the analysis engine. | 4065 * error codes are reported back into the analysis engine. |
| 4066 * |
3924 * @param classElt the location of the source for which the exception occurred | 4067 * @param classElt the location of the source for which the exception occurred |
3925 * @param offset the offset of the location of the error | 4068 * @param offset the offset of the location of the error |
3926 * @param length the length of the location of the error | 4069 * @param length the length of the location of the error |
3927 * @param errorCode the error code to be associated with this error | 4070 * @param errorCode the error code to be associated with this error |
3928 * @param arguments the arguments used to build the error message | 4071 * @param arguments the arguments used to build the error message |
3929 */ | 4072 */ |
3930 void reportError(ClassElement classElt, int offset, int length, ErrorCode erro
rCode, List<Object> arguments) { | 4073 void reportError(ClassElement classElt, int offset, int length, ErrorCode erro
rCode, List<Object> arguments) { |
3931 Set<AnalysisError> errorSet = _errorsInClassElement[classElt]; | 4074 Set<AnalysisError> errorSet = _errorsInClassElement[classElt]; |
3932 if (errorSet == null) { | 4075 if (errorSet == null) { |
3933 errorSet = new Set<AnalysisError>(); | 4076 errorSet = new Set<AnalysisError>(); |
3934 _errorsInClassElement[classElt] = errorSet; | 4077 _errorsInClassElement[classElt] = errorSet; |
3935 } | 4078 } |
3936 javaSetAdd(errorSet, new AnalysisError.con2(classElt.source, offset, length,
errorCode, arguments)); | 4079 javaSetAdd(errorSet, new AnalysisError.con2(classElt.source, offset, length,
errorCode, arguments)); |
3937 } | 4080 } |
3938 } | 4081 } |
3939 /** | 4082 /** |
3940 * Instances of the class `Library` represent the data about a single library du
ring the | 4083 * Instances of the class `Library` represent the data about a single library du
ring the |
3941 * resolution of some (possibly different) library. They are not intended to be
used except during | 4084 * resolution of some (possibly different) library. They are not intended to be
used except during |
3942 * the resolution process. | 4085 * the resolution process. |
| 4086 * |
3943 * @coverage dart.engine.resolver | 4087 * @coverage dart.engine.resolver |
3944 */ | 4088 */ |
3945 class Library { | 4089 class Library { |
3946 | 4090 |
3947 /** | 4091 /** |
3948 * The analysis context in which this library is being analyzed. | 4092 * The analysis context in which this library is being analyzed. |
3949 */ | 4093 */ |
3950 InternalAnalysisContext _analysisContext; | 4094 InternalAnalysisContext _analysisContext; |
3951 | 4095 |
3952 /** | 4096 /** |
(...skipping 12 matching lines...) Expand all Loading... |
3965 Source _librarySource; | 4109 Source _librarySource; |
3966 | 4110 |
3967 /** | 4111 /** |
3968 * The library element representing this library. | 4112 * The library element representing this library. |
3969 */ | 4113 */ |
3970 LibraryElementImpl _libraryElement; | 4114 LibraryElementImpl _libraryElement; |
3971 | 4115 |
3972 /** | 4116 /** |
3973 * A list containing all of the libraries that are imported into this library. | 4117 * A list containing all of the libraries that are imported into this library. |
3974 */ | 4118 */ |
3975 Map<ImportDirective, Library> _importedLibraries = new Map<ImportDirective, Li
brary>(); | 4119 List<Library> _importedLibraries = _EMPTY_ARRAY; |
3976 | 4120 |
3977 /** | 4121 /** |
3978 * A table mapping URI-based directive to the actual URI value. | 4122 * A table mapping URI-based directive to the actual URI value. |
3979 */ | 4123 */ |
3980 Map<UriBasedDirective, String> _directiveUris = new Map<UriBasedDirective, Str
ing>(); | 4124 Map<UriBasedDirective, String> _directiveUris = new Map<UriBasedDirective, Str
ing>(); |
3981 | 4125 |
3982 /** | 4126 /** |
3983 * A flag indicating whether this library explicitly imports core. | 4127 * A flag indicating whether this library explicitly imports core. |
3984 */ | 4128 */ |
3985 bool _explicitlyImportsCore = false; | 4129 bool _explicitlyImportsCore = false; |
3986 | 4130 |
3987 /** | 4131 /** |
3988 * A list containing all of the libraries that are exported from this library. | 4132 * A list containing all of the libraries that are exported from this library. |
3989 */ | 4133 */ |
3990 Map<ExportDirective, Library> _exportedLibraries = new Map<ExportDirective, Li
brary>(); | 4134 List<Library> _exportedLibraries = _EMPTY_ARRAY; |
3991 | 4135 |
3992 /** | 4136 /** |
3993 * A table mapping the sources for the compilation units in this library to th
eir corresponding | 4137 * A table mapping the sources for the compilation units in this library to th
eir corresponding |
3994 * AST structures. | 4138 * AST structures. |
3995 */ | 4139 */ |
3996 Map<Source, CompilationUnit> _astMap = new Map<Source, CompilationUnit>(); | 4140 Map<Source, CompilationUnit> _astMap = new Map<Source, CompilationUnit>(); |
3997 | 4141 |
3998 /** | 4142 /** |
3999 * The library scope used when resolving elements within this library's compil
ation units. | 4143 * The library scope used when resolving elements within this library's compil
ation units. |
4000 */ | 4144 */ |
4001 LibraryScope _libraryScope; | 4145 LibraryScope _libraryScope; |
4002 | 4146 |
4003 /** | 4147 /** |
| 4148 * An empty array that can be used to initialize lists of libraries. |
| 4149 */ |
| 4150 static List<Library> _EMPTY_ARRAY = new List<Library>(0); |
| 4151 |
| 4152 /** |
4004 * Initialize a newly created data holder that can maintain the data associate
d with a library. | 4153 * Initialize a newly created data holder that can maintain the data associate
d with a library. |
| 4154 * |
4005 * @param analysisContext the analysis context in which this library is being
analyzed | 4155 * @param analysisContext the analysis context in which this library is being
analyzed |
4006 * @param errorListener the listener to which analysis errors will be reported | 4156 * @param errorListener the listener to which analysis errors will be reported |
4007 * @param librarySource the source specifying the defining compilation unit of
this library | 4157 * @param librarySource the source specifying the defining compilation unit of
this library |
4008 */ | 4158 */ |
4009 Library(InternalAnalysisContext analysisContext, AnalysisErrorListener errorLi
stener, Source librarySource) { | 4159 Library(InternalAnalysisContext analysisContext, AnalysisErrorListener errorLi
stener, Source librarySource) { |
4010 this._analysisContext = analysisContext; | 4160 this._analysisContext = analysisContext; |
4011 this._errorListener = errorListener; | 4161 this._errorListener = errorListener; |
4012 this._librarySource = librarySource; | 4162 this._librarySource = librarySource; |
4013 this._libraryElement = analysisContext.getLibraryElement(librarySource) as L
ibraryElementImpl; | 4163 this._libraryElement = analysisContext.getLibraryElement(librarySource) as L
ibraryElementImpl; |
4014 } | 4164 } |
4015 | 4165 |
4016 /** | 4166 /** |
4017 * Record that the given library is exported from this library. | |
4018 * @param importLibrary the library that is exported from this library | |
4019 */ | |
4020 void addExport(ExportDirective directive, Library exportLibrary) { | |
4021 _exportedLibraries[directive] = exportLibrary; | |
4022 } | |
4023 | |
4024 /** | |
4025 * Record that the given library is imported into this library. | |
4026 * @param importLibrary the library that is imported into this library | |
4027 */ | |
4028 void addImport(ImportDirective directive, Library importLibrary) { | |
4029 _importedLibraries[directive] = importLibrary; | |
4030 } | |
4031 | |
4032 /** | |
4033 * Return the AST structure associated with the given source. | 4167 * Return the AST structure associated with the given source. |
| 4168 * |
4034 * @param source the source representing the compilation unit whose AST is to
be returned | 4169 * @param source the source representing the compilation unit whose AST is to
be returned |
4035 * @return the AST structure associated with the given source | 4170 * @return the AST structure associated with the given source |
4036 * @throws AnalysisException if an AST structure could not be created for the
compilation unit | 4171 * @throws AnalysisException if an AST structure could not be created for the
compilation unit |
4037 */ | 4172 */ |
4038 CompilationUnit getAST(Source source) { | 4173 CompilationUnit getAST(Source source) { |
4039 CompilationUnit unit = _astMap[source]; | 4174 CompilationUnit unit = _astMap[source]; |
4040 if (unit == null) { | 4175 if (unit == null) { |
4041 unit = _analysisContext.computeResolvableCompilationUnit(source); | 4176 unit = _analysisContext.computeResolvableCompilationUnit(source); |
4042 _astMap[source] = unit; | 4177 _astMap[source] = unit; |
4043 } | 4178 } |
4044 return unit; | 4179 return unit; |
4045 } | 4180 } |
4046 | 4181 |
4047 /** | 4182 /** |
4048 * Return a collection containing the sources for the compilation units in thi
s library, including | 4183 * Return a collection containing the sources for the compilation units in thi
s library, including |
4049 * the defining compilation unit. | 4184 * the defining compilation unit. |
| 4185 * |
4050 * @return the sources for the compilation units in this library | 4186 * @return the sources for the compilation units in this library |
4051 */ | 4187 */ |
4052 Set<Source> get compilationUnitSources => _astMap.keys.toSet(); | 4188 Set<Source> get compilationUnitSources => _astMap.keys.toSet(); |
4053 | 4189 |
4054 /** | 4190 /** |
4055 * Return the AST structure associated with the defining compilation unit for
this library. | 4191 * Return the AST structure associated with the defining compilation unit for
this library. |
| 4192 * |
4056 * @return the AST structure associated with the defining compilation unit for
this library | 4193 * @return the AST structure associated with the defining compilation unit for
this library |
4057 * @throws AnalysisException if an AST structure could not be created for the
defining compilation | 4194 * @throws AnalysisException if an AST structure could not be created for the
defining compilation |
4058 * unit | 4195 * unit |
4059 */ | 4196 */ |
4060 CompilationUnit get definingCompilationUnit => getAST(librarySource); | 4197 CompilationUnit get definingCompilationUnit => getAST(librarySource); |
4061 | 4198 |
4062 /** | 4199 /** |
4063 * Return `true` if this library explicitly imports core. | 4200 * Return `true` if this library explicitly imports core. |
| 4201 * |
4064 * @return `true` if this library explicitly imports core | 4202 * @return `true` if this library explicitly imports core |
4065 */ | 4203 */ |
4066 bool get explicitlyImportsCore => _explicitlyImportsCore; | 4204 bool get explicitlyImportsCore => _explicitlyImportsCore; |
4067 | 4205 |
4068 /** | 4206 /** |
4069 * Return the library exported by the given directive. | |
4070 * @param directive the directive that exports the library to be returned | |
4071 * @return the library exported by the given directive | |
4072 */ | |
4073 Library getExport(ExportDirective directive) => _exportedLibraries[directive]; | |
4074 | |
4075 /** | |
4076 * Return an array containing the libraries that are exported from this librar
y. | 4207 * Return an array containing the libraries that are exported from this librar
y. |
| 4208 * |
4077 * @return an array containing the libraries that are exported from this libra
ry | 4209 * @return an array containing the libraries that are exported from this libra
ry |
4078 */ | 4210 */ |
4079 List<Library> get exports { | 4211 List<Library> get exports => _exportedLibraries; |
4080 Set<Library> libraries = new Set<Library>(); | |
4081 libraries.addAll(_exportedLibraries.values); | |
4082 return new List.from(libraries); | |
4083 } | |
4084 | |
4085 /** | |
4086 * Return the library imported by the given directive. | |
4087 * @param directive the directive that imports the library to be returned | |
4088 * @return the library imported by the given directive | |
4089 */ | |
4090 Library getImport(ImportDirective directive) => _importedLibraries[directive]; | |
4091 | 4212 |
4092 /** | 4213 /** |
4093 * Return an array containing the libraries that are imported into this librar
y. | 4214 * Return an array containing the libraries that are imported into this librar
y. |
| 4215 * |
4094 * @return an array containing the libraries that are imported into this libra
ry | 4216 * @return an array containing the libraries that are imported into this libra
ry |
4095 */ | 4217 */ |
4096 List<Library> get imports { | 4218 List<Library> get imports => _importedLibraries; |
4097 Set<Library> libraries = new Set<Library>(); | |
4098 libraries.addAll(_importedLibraries.values); | |
4099 return new List.from(libraries); | |
4100 } | |
4101 | 4219 |
4102 /** | 4220 /** |
4103 * Return an array containing the libraries that are either imported or export
ed from this | 4221 * Return an array containing the libraries that are either imported or export
ed from this |
4104 * library. | 4222 * library. |
| 4223 * |
4105 * @return the libraries that are either imported or exported from this librar
y | 4224 * @return the libraries that are either imported or exported from this librar
y |
4106 */ | 4225 */ |
4107 List<Library> get importsAndExports { | 4226 List<Library> get importsAndExports { |
4108 Set<Library> libraries = new Set<Library>(); | 4227 Set<Library> libraries = new Set<Library>(); |
4109 libraries.addAll(_importedLibraries.values); | 4228 for (Library library in _importedLibraries) { |
4110 libraries.addAll(_exportedLibraries.values); | 4229 javaSetAdd(libraries, library); |
| 4230 } |
| 4231 for (Library library in _exportedLibraries) { |
| 4232 javaSetAdd(libraries, library); |
| 4233 } |
4111 return new List.from(libraries); | 4234 return new List.from(libraries); |
4112 } | 4235 } |
4113 | 4236 |
4114 /** | 4237 /** |
4115 * Return the inheritance manager for this library. | 4238 * Return the inheritance manager for this library. |
| 4239 * |
4116 * @return the inheritance manager for this library | 4240 * @return the inheritance manager for this library |
4117 */ | 4241 */ |
4118 InheritanceManager get inheritanceManager { | 4242 InheritanceManager get inheritanceManager { |
4119 if (_inheritanceManager == null) { | 4243 if (_inheritanceManager == null) { |
4120 return _inheritanceManager = new InheritanceManager(_libraryElement); | 4244 return _inheritanceManager = new InheritanceManager(_libraryElement); |
4121 } | 4245 } |
4122 return _inheritanceManager; | 4246 return _inheritanceManager; |
4123 } | 4247 } |
4124 | 4248 |
4125 /** | 4249 /** |
4126 * Return the library element representing this library, creating it if necess
ary. | 4250 * Return the library element representing this library, creating it if necess
ary. |
| 4251 * |
4127 * @return the library element representing this library | 4252 * @return the library element representing this library |
4128 */ | 4253 */ |
4129 LibraryElementImpl get libraryElement { | 4254 LibraryElementImpl get libraryElement { |
4130 if (_libraryElement == null) { | 4255 if (_libraryElement == null) { |
4131 try { | 4256 try { |
4132 _libraryElement = _analysisContext.computeLibraryElement(_librarySource)
as LibraryElementImpl; | 4257 _libraryElement = _analysisContext.computeLibraryElement(_librarySource)
as LibraryElementImpl; |
4133 } on AnalysisException catch (exception) { | 4258 } on AnalysisException catch (exception) { |
4134 AnalysisEngine.instance.logger.logError2("Could not compute ilbrary elem
ent for ${_librarySource.fullName}", exception); | 4259 AnalysisEngine.instance.logger.logError2("Could not compute ilbrary elem
ent for ${_librarySource.fullName}", exception); |
4135 } | 4260 } |
4136 } | 4261 } |
4137 return _libraryElement; | 4262 return _libraryElement; |
4138 } | 4263 } |
4139 | 4264 |
4140 /** | 4265 /** |
4141 * Return the library scope used when resolving elements within this library's
compilation units. | 4266 * Return the library scope used when resolving elements within this library's
compilation units. |
| 4267 * |
4142 * @return the library scope used when resolving elements within this library'
s compilation units | 4268 * @return the library scope used when resolving elements within this library'
s compilation units |
4143 */ | 4269 */ |
4144 LibraryScope get libraryScope { | 4270 LibraryScope get libraryScope { |
4145 if (_libraryScope == null) { | 4271 if (_libraryScope == null) { |
4146 _libraryScope = new LibraryScope(_libraryElement, _errorListener); | 4272 _libraryScope = new LibraryScope(_libraryElement, _errorListener); |
4147 } | 4273 } |
4148 return _libraryScope; | 4274 return _libraryScope; |
4149 } | 4275 } |
4150 | 4276 |
4151 /** | 4277 /** |
4152 * Return the source specifying the defining compilation unit of this library. | 4278 * Return the source specifying the defining compilation unit of this library. |
| 4279 * |
4153 * @return the source specifying the defining compilation unit of this library | 4280 * @return the source specifying the defining compilation unit of this library |
4154 */ | 4281 */ |
4155 Source get librarySource => _librarySource; | 4282 Source get librarySource => _librarySource; |
4156 | 4283 |
4157 /** | 4284 /** |
4158 * Return the result of resolving the URI of the given URI-based directive aga
inst the URI of the | 4285 * Return the result of resolving the URI of the given URI-based directive aga
inst the URI of the |
4159 * library, or `null` if the URI is not valid. If the URI is not valid, report
the error. | 4286 * library, or `null` if the URI is not valid. If the URI is not valid, report
the error. |
| 4287 * |
4160 * @param directive the directive which URI should be resolved | 4288 * @param directive the directive which URI should be resolved |
4161 * @return the result of resolving the URI against the URI of the library | 4289 * @return the result of resolving the URI against the URI of the library |
4162 */ | 4290 */ |
4163 Source getSource(UriBasedDirective directive) { | 4291 Source getSource(UriBasedDirective directive) { |
4164 StringLiteral uriLiteral = directive.uri; | 4292 StringLiteral uriLiteral = directive.uri; |
4165 if (uriLiteral is StringInterpolation) { | 4293 if (uriLiteral is StringInterpolation) { |
4166 _errorListener.onError(new AnalysisError.con2(_librarySource, uriLiteral.o
ffset, uriLiteral.length, CompileTimeErrorCode.URI_WITH_INTERPOLATION, [])); | 4294 _errorListener.onError(new AnalysisError.con2(_librarySource, uriLiteral.o
ffset, uriLiteral.length, CompileTimeErrorCode.URI_WITH_INTERPOLATION, [])); |
4167 return null; | 4295 return null; |
4168 } | 4296 } |
4169 String uriContent = uriLiteral.stringValue.trim(); | 4297 String uriContent = uriLiteral.stringValue.trim(); |
(...skipping 12 matching lines...) Expand all Loading... |
4182 } | 4310 } |
4183 | 4311 |
4184 /** | 4312 /** |
4185 * Returns the URI value of the given directive. | 4313 * Returns the URI value of the given directive. |
4186 */ | 4314 */ |
4187 String getUri(UriBasedDirective directive) => _directiveUris[directive]; | 4315 String getUri(UriBasedDirective directive) => _directiveUris[directive]; |
4188 | 4316 |
4189 /** | 4317 /** |
4190 * Set the AST structure associated with the defining compilation unit for thi
s library to the | 4318 * Set the AST structure associated with the defining compilation unit for thi
s library to the |
4191 * given AST structure. | 4319 * given AST structure. |
| 4320 * |
4192 * @param unit the AST structure associated with the defining compilation unit
for this library | 4321 * @param unit the AST structure associated with the defining compilation unit
for this library |
4193 */ | 4322 */ |
4194 void set definingCompilationUnit(CompilationUnit unit) { | 4323 void set definingCompilationUnit(CompilationUnit unit) { |
4195 _astMap[librarySource] = unit; | 4324 _astMap[librarySource] = unit; |
4196 } | 4325 } |
4197 | 4326 |
4198 /** | 4327 /** |
4199 * Set whether this library explicitly imports core to match the given value. | 4328 * Set whether this library explicitly imports core to match the given value. |
| 4329 * |
4200 * @param explicitlyImportsCore `true` if this library explicitly imports core | 4330 * @param explicitlyImportsCore `true` if this library explicitly imports core |
4201 */ | 4331 */ |
4202 void set explicitlyImportsCore(bool explicitlyImportsCore2) { | 4332 void set explicitlyImportsCore(bool explicitlyImportsCore2) { |
4203 this._explicitlyImportsCore = explicitlyImportsCore2; | 4333 this._explicitlyImportsCore = explicitlyImportsCore2; |
4204 } | 4334 } |
4205 | 4335 |
4206 /** | 4336 /** |
| 4337 * Set the libraries that are exported by this library to be those in the give
n array. |
| 4338 * |
| 4339 * @param exportedLibraries the libraries that are exported by this library |
| 4340 */ |
| 4341 void set exportedLibraries(List<Library> exportedLibraries2) { |
| 4342 this._exportedLibraries = exportedLibraries2; |
| 4343 } |
| 4344 |
| 4345 /** |
| 4346 * Set the libraries that are imported into this library to be those in the gi
ven array. |
| 4347 * |
| 4348 * @param importedLibraries the libraries that are imported into this library |
| 4349 */ |
| 4350 void set importedLibraries(List<Library> importedLibraries2) { |
| 4351 this._importedLibraries = importedLibraries2; |
| 4352 } |
| 4353 |
| 4354 /** |
4207 * Set the library element representing this library to the given library elem
ent. | 4355 * Set the library element representing this library to the given library elem
ent. |
| 4356 * |
4208 * @param libraryElement the library element representing this library | 4357 * @param libraryElement the library element representing this library |
4209 */ | 4358 */ |
4210 void set libraryElement(LibraryElementImpl libraryElement2) { | 4359 void set libraryElement(LibraryElementImpl libraryElement2) { |
4211 this._libraryElement = libraryElement2; | 4360 this._libraryElement = libraryElement2; |
4212 if (_inheritanceManager != null) { | 4361 if (_inheritanceManager != null) { |
4213 _inheritanceManager.libraryElement = libraryElement2; | 4362 _inheritanceManager.libraryElement = libraryElement2; |
4214 } | 4363 } |
4215 } | 4364 } |
4216 String toString() => _librarySource.shortName; | 4365 String toString() => _librarySource.shortName; |
4217 | 4366 |
4218 /** | 4367 /** |
4219 * Return the result of resolving the given URI against the URI of the library
, or `null` if | 4368 * Return the result of resolving the given URI against the URI of the library
, or `null` if |
4220 * the URI is not valid. | 4369 * the URI is not valid. |
| 4370 * |
4221 * @param uri the URI to be resolved | 4371 * @param uri the URI to be resolved |
4222 * @return the result of resolving the given URI against the URI of the librar
y | 4372 * @return the result of resolving the given URI against the URI of the librar
y |
4223 */ | 4373 */ |
4224 Source getSource2(String uri) { | 4374 Source getSource2(String uri) { |
4225 if (uri == null) { | 4375 if (uri == null) { |
4226 return null; | 4376 return null; |
4227 } | 4377 } |
4228 return _analysisContext.sourceFactory.resolveUri(_librarySource, uri); | 4378 return _analysisContext.sourceFactory.resolveUri(_librarySource, uri); |
4229 } | 4379 } |
4230 } | 4380 } |
4231 /** | 4381 /** |
4232 * Instances of the class `LibraryElementBuilder` build an element model for a s
ingle library. | 4382 * Instances of the class `LibraryElementBuilder` build an element model for a s
ingle library. |
| 4383 * |
4233 * @coverage dart.engine.resolver | 4384 * @coverage dart.engine.resolver |
4234 */ | 4385 */ |
4235 class LibraryElementBuilder { | 4386 class LibraryElementBuilder { |
4236 | 4387 |
4237 /** | 4388 /** |
4238 * The analysis context in which the element model will be built. | 4389 * The analysis context in which the element model will be built. |
4239 */ | 4390 */ |
4240 InternalAnalysisContext _analysisContext; | 4391 InternalAnalysisContext _analysisContext; |
4241 | 4392 |
4242 /** | 4393 /** |
4243 * The listener to which errors will be reported. | 4394 * The listener to which errors will be reported. |
4244 */ | 4395 */ |
4245 AnalysisErrorListener _errorListener; | 4396 AnalysisErrorListener _errorListener; |
4246 | 4397 |
4247 /** | 4398 /** |
4248 * The name of the function used as an entry point. | 4399 * The name of the function used as an entry point. |
4249 */ | 4400 */ |
4250 static String _ENTRY_POINT_NAME = "main"; | 4401 static String _ENTRY_POINT_NAME = "main"; |
4251 | 4402 |
4252 /** | 4403 /** |
4253 * Initialize a newly created library element builder. | 4404 * Initialize a newly created library element builder. |
| 4405 * |
4254 * @param resolver the resolver for which the element model is being built | 4406 * @param resolver the resolver for which the element model is being built |
4255 */ | 4407 */ |
4256 LibraryElementBuilder(LibraryResolver resolver) { | 4408 LibraryElementBuilder(LibraryResolver resolver) { |
4257 this._analysisContext = resolver.analysisContext; | 4409 this._analysisContext = resolver.analysisContext; |
4258 this._errorListener = resolver.errorListener; | 4410 this._errorListener = resolver.errorListener; |
4259 } | 4411 } |
4260 | 4412 |
4261 /** | 4413 /** |
4262 * Build the library element for the given library. | 4414 * Build the library element for the given library. |
| 4415 * |
4263 * @param library the library for which an element model is to be built | 4416 * @param library the library for which an element model is to be built |
4264 * @return the library element that was built | 4417 * @return the library element that was built |
4265 * @throws AnalysisException if the analysis could not be performed | 4418 * @throws AnalysisException if the analysis could not be performed |
4266 */ | 4419 */ |
4267 LibraryElementImpl buildLibrary(Library library) { | 4420 LibraryElementImpl buildLibrary(Library library) { |
4268 CompilationUnitBuilder builder = new CompilationUnitBuilder(); | 4421 CompilationUnitBuilder builder = new CompilationUnitBuilder(); |
4269 Source librarySource = library.librarySource; | 4422 Source librarySource = library.librarySource; |
4270 CompilationUnit definingCompilationUnit = library.definingCompilationUnit; | 4423 CompilationUnit definingCompilationUnit = library.definingCompilationUnit; |
4271 CompilationUnitElementImpl definingCompilationUnitElement = builder.buildCom
pilationUnit(librarySource, definingCompilationUnit); | 4424 CompilationUnitElementImpl definingCompilationUnitElement = builder.buildCom
pilationUnit(librarySource, definingCompilationUnit); |
4272 NodeList<Directive> directives = definingCompilationUnit.directives; | 4425 NodeList<Directive> directives = definingCompilationUnit.directives; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4320 library.libraryElement = libraryElement; | 4473 library.libraryElement = libraryElement; |
4321 if (sourcedUnitCount > 0) { | 4474 if (sourcedUnitCount > 0) { |
4322 patchTopLevelAccessors(libraryElement); | 4475 patchTopLevelAccessors(libraryElement); |
4323 } | 4476 } |
4324 return libraryElement; | 4477 return libraryElement; |
4325 } | 4478 } |
4326 | 4479 |
4327 /** | 4480 /** |
4328 * Add all of the non-synthetic getters and setters defined in the given compi
lation unit that | 4481 * Add all of the non-synthetic getters and setters defined in the given compi
lation unit that |
4329 * have no corresponding accessor to one of the given collections. | 4482 * have no corresponding accessor to one of the given collections. |
| 4483 * |
4330 * @param getters the map to which getters are to be added | 4484 * @param getters the map to which getters are to be added |
4331 * @param setters the list to which setters are to be added | 4485 * @param setters the list to which setters are to be added |
4332 * @param unit the compilation unit defining the accessors that are potentiall
y being added | 4486 * @param unit the compilation unit defining the accessors that are potentiall
y being added |
4333 */ | 4487 */ |
4334 void collectAccessors(Map<String, PropertyAccessorElement> getters, List<Prope
rtyAccessorElement> setters, CompilationUnitElement unit) { | 4488 void collectAccessors(Map<String, PropertyAccessorElement> getters, List<Prope
rtyAccessorElement> setters, CompilationUnitElement unit) { |
4335 for (PropertyAccessorElement accessor in unit.accessors) { | 4489 for (PropertyAccessorElement accessor in unit.accessors) { |
4336 if (accessor.isGetter) { | 4490 if (accessor.isGetter) { |
4337 if (!accessor.isSynthetic && accessor.correspondingSetter == null) { | 4491 if (!accessor.isSynthetic && accessor.correspondingSetter == null) { |
4338 getters[accessor.displayName] = accessor; | 4492 getters[accessor.displayName] = accessor; |
4339 } | 4493 } |
4340 } else { | 4494 } else { |
4341 if (!accessor.isSynthetic && accessor.correspondingGetter == null) { | 4495 if (!accessor.isSynthetic && accessor.correspondingGetter == null) { |
4342 setters.add(accessor); | 4496 setters.add(accessor); |
4343 } | 4497 } |
4344 } | 4498 } |
4345 } | 4499 } |
4346 } | 4500 } |
4347 | 4501 |
4348 /** | 4502 /** |
4349 * Search the top-level functions defined in the given compilation unit for th
e entry point. | 4503 * Search the top-level functions defined in the given compilation unit for th
e entry point. |
| 4504 * |
4350 * @param element the compilation unit to be searched | 4505 * @param element the compilation unit to be searched |
4351 * @return the entry point that was found, or `null` if the compilation unit d
oes not define | 4506 * @return the entry point that was found, or `null` if the compilation unit d
oes not define |
4352 * an entry point | 4507 * an entry point |
4353 */ | 4508 */ |
4354 FunctionElement findEntryPoint(CompilationUnitElementImpl element) { | 4509 FunctionElement findEntryPoint(CompilationUnitElementImpl element) { |
4355 for (FunctionElement function in element.functions) { | 4510 for (FunctionElement function in element.functions) { |
4356 if (function.name == _ENTRY_POINT_NAME) { | 4511 if (function.name == _ENTRY_POINT_NAME) { |
4357 return function; | 4512 return function; |
4358 } | 4513 } |
4359 } | 4514 } |
4360 return null; | 4515 return null; |
4361 } | 4516 } |
4362 | 4517 |
4363 /** | 4518 /** |
4364 * Return the name of the library that the given part is declared to be a part
of, or `null`if the part does not contain a part-of directive. | 4519 * Return the name of the library that the given part is declared to be a part
of, or `null` |
| 4520 * if the part does not contain a part-of directive. |
| 4521 * |
4365 * @param library the library containing the part | 4522 * @param library the library containing the part |
4366 * @param partSource the source representing the part | 4523 * @param partSource the source representing the part |
4367 * @param directivesToResolve a list of directives that should be resolved to
the library being | 4524 * @param directivesToResolve a list of directives that should be resolved to
the library being |
4368 * built | 4525 * built |
4369 * @return the name of the library that the given part is declared to be a par
t of | 4526 * @return the name of the library that the given part is declared to be a par
t of |
4370 */ | 4527 */ |
4371 String getPartLibraryName(Library library, Source partSource, List<Directive>
directivesToResolve) { | 4528 String getPartLibraryName(Library library, Source partSource, List<Directive>
directivesToResolve) { |
4372 try { | 4529 try { |
4373 CompilationUnit partUnit = library.getAST(partSource); | 4530 CompilationUnit partUnit = library.getAST(partSource); |
4374 for (Directive directive in partUnit.directives) { | 4531 for (Directive directive in partUnit.directives) { |
4375 if (directive is PartOfDirective) { | 4532 if (directive is PartOfDirective) { |
4376 directivesToResolve.add(directive); | 4533 directivesToResolve.add(directive); |
4377 LibraryIdentifier libraryName = ((directive as PartOfDirective)).libra
ryName; | 4534 LibraryIdentifier libraryName = ((directive as PartOfDirective)).libra
ryName; |
4378 if (libraryName != null) { | 4535 if (libraryName != null) { |
4379 return libraryName.name; | 4536 return libraryName.name; |
4380 } | 4537 } |
4381 } | 4538 } |
4382 } | 4539 } |
4383 } on AnalysisException catch (exception) { | 4540 } on AnalysisException catch (exception) { |
4384 } | 4541 } |
4385 return null; | 4542 return null; |
4386 } | 4543 } |
4387 | 4544 |
4388 /** | 4545 /** |
4389 * Look through all of the compilation units defined for the given library, lo
oking for getters | 4546 * Look through all of the compilation units defined for the given library, lo
oking for getters |
4390 * and setters that are defined in different compilation units but that have t
he same names. If | 4547 * and setters that are defined in different compilation units but that have t
he same names. If |
4391 * any are found, make sure that they have the same variable element. | 4548 * any are found, make sure that they have the same variable element. |
| 4549 * |
4392 * @param libraryElement the library defining the compilation units to be proc
essed | 4550 * @param libraryElement the library defining the compilation units to be proc
essed |
4393 */ | 4551 */ |
4394 void patchTopLevelAccessors(LibraryElementImpl libraryElement) { | 4552 void patchTopLevelAccessors(LibraryElementImpl libraryElement) { |
4395 Map<String, PropertyAccessorElement> getters = new Map<String, PropertyAcces
sorElement>(); | 4553 Map<String, PropertyAccessorElement> getters = new Map<String, PropertyAcces
sorElement>(); |
4396 List<PropertyAccessorElement> setters = new List<PropertyAccessorElement>(); | 4554 List<PropertyAccessorElement> setters = new List<PropertyAccessorElement>(); |
4397 collectAccessors(getters, setters, libraryElement.definingCompilationUnit); | 4555 collectAccessors(getters, setters, libraryElement.definingCompilationUnit); |
4398 for (CompilationUnitElement unit in libraryElement.parts) { | 4556 for (CompilationUnitElement unit in libraryElement.parts) { |
4399 collectAccessors(getters, setters, unit); | 4557 collectAccessors(getters, setters, unit); |
4400 } | 4558 } |
4401 for (PropertyAccessorElement setter in setters) { | 4559 for (PropertyAccessorElement setter in setters) { |
4402 PropertyAccessorElement getter = getters[setter.displayName]; | 4560 PropertyAccessorElement getter = getters[setter.displayName]; |
4403 if (getter != null) { | 4561 if (getter != null) { |
4404 PropertyInducingElementImpl variable = getter.variable as PropertyInduci
ngElementImpl; | 4562 PropertyInducingElementImpl variable = getter.variable as PropertyInduci
ngElementImpl; |
4405 variable.setter = setter; | 4563 variable.setter = setter; |
4406 ((setter as PropertyAccessorElementImpl)).variable = variable; | 4564 ((setter as PropertyAccessorElementImpl)).variable = variable; |
4407 } | 4565 } |
4408 } | 4566 } |
4409 } | 4567 } |
4410 } | 4568 } |
4411 /** | 4569 /** |
4412 * Instances of the class `LibraryResolver` are used to resolve one or more mutu
ally dependent | 4570 * Instances of the class `LibraryResolver` are used to resolve one or more mutu
ally dependent |
4413 * libraries within a single context. | 4571 * libraries within a single context. |
| 4572 * |
4414 * @coverage dart.engine.resolver | 4573 * @coverage dart.engine.resolver |
4415 */ | 4574 */ |
4416 class LibraryResolver { | 4575 class LibraryResolver { |
4417 | 4576 |
4418 /** | 4577 /** |
4419 * The analysis context in which the libraries are being analyzed. | 4578 * The analysis context in which the libraries are being analyzed. |
4420 */ | 4579 */ |
4421 InternalAnalysisContext _analysisContext; | 4580 InternalAnalysisContext _analysisContext; |
4422 | 4581 |
4423 /** | 4582 /** |
4424 * The listener to which analysis errors will be reported, this error listener
is either | 4583 * The listener to which analysis errors will be reported, this error listener
is either |
4425 * references [recordingErrorListener], or it unions the passed[AnalysisErrorL
istener] with the [recordingErrorListener]. | 4584 * references [recordingErrorListener], or it unions the passed |
| 4585 * [AnalysisErrorListener] with the [recordingErrorListener]. |
4426 */ | 4586 */ |
4427 RecordingErrorListener _errorListener; | 4587 RecordingErrorListener _errorListener; |
4428 | 4588 |
4429 /** | 4589 /** |
4430 * A source object representing the core library (dart:core). | 4590 * A source object representing the core library (dart:core). |
4431 */ | 4591 */ |
4432 Source _coreLibrarySource; | 4592 Source _coreLibrarySource; |
4433 | 4593 |
4434 /** | 4594 /** |
4435 * The object representing the core library. | 4595 * The object representing the core library. |
4436 */ | 4596 */ |
4437 Library _coreLibrary; | 4597 Library _coreLibrary; |
4438 | 4598 |
4439 /** | 4599 /** |
| 4600 * A flag indicating whether analysis is to generate audit results (e.g. type
inference based |
| 4601 * information and pub best practices). |
| 4602 */ |
| 4603 bool _audit = false; |
| 4604 |
| 4605 /** |
4440 * The object used to access the types from the core library. | 4606 * The object used to access the types from the core library. |
4441 */ | 4607 */ |
4442 TypeProvider _typeProvider; | 4608 TypeProvider _typeProvider; |
4443 | 4609 |
4444 /** | 4610 /** |
4445 * A table mapping library sources to the information being maintained for tho
se libraries. | 4611 * A table mapping library sources to the information being maintained for tho
se libraries. |
4446 */ | 4612 */ |
4447 Map<Source, Library> _libraryMap = new Map<Source, Library>(); | 4613 Map<Source, Library> _libraryMap = new Map<Source, Library>(); |
4448 | 4614 |
4449 /** | 4615 /** |
4450 * A collection containing the libraries that are being resolved together. | 4616 * A collection containing the libraries that are being resolved together. |
4451 */ | 4617 */ |
4452 Set<Library> _librariesInCycles; | 4618 Set<Library> _librariesInCycles; |
4453 | 4619 |
4454 /** | 4620 /** |
4455 * Initialize a newly created library resolver to resolve libraries within the
given context. | 4621 * Initialize a newly created library resolver to resolve libraries within the
given context. |
| 4622 * |
4456 * @param analysisContext the analysis context in which the library is being a
nalyzed | 4623 * @param analysisContext the analysis context in which the library is being a
nalyzed |
4457 */ | 4624 */ |
4458 LibraryResolver(InternalAnalysisContext analysisContext) { | 4625 LibraryResolver(InternalAnalysisContext analysisContext) { |
4459 this._analysisContext = analysisContext; | 4626 this._analysisContext = analysisContext; |
4460 this._errorListener = new RecordingErrorListener(); | 4627 this._errorListener = new RecordingErrorListener(); |
4461 _coreLibrarySource = analysisContext.sourceFactory.forUri(DartSdk.DART_CORE)
; | 4628 _coreLibrarySource = analysisContext.sourceFactory.forUri(DartSdk.DART_CORE)
; |
| 4629 _audit = analysisContext.analysisOptions.audit; |
4462 } | 4630 } |
4463 | 4631 |
4464 /** | 4632 /** |
4465 * Return the analysis context in which the libraries are being analyzed. | 4633 * Return the analysis context in which the libraries are being analyzed. |
| 4634 * |
4466 * @return the analysis context in which the libraries are being analyzed | 4635 * @return the analysis context in which the libraries are being analyzed |
4467 */ | 4636 */ |
4468 InternalAnalysisContext get analysisContext => _analysisContext; | 4637 InternalAnalysisContext get analysisContext => _analysisContext; |
4469 | 4638 |
4470 /** | 4639 /** |
4471 * Return the listener to which analysis errors will be reported. | 4640 * Return the listener to which analysis errors will be reported. |
| 4641 * |
4472 * @return the listener to which analysis errors will be reported | 4642 * @return the listener to which analysis errors will be reported |
4473 */ | 4643 */ |
4474 RecordingErrorListener get errorListener => _errorListener; | 4644 RecordingErrorListener get errorListener => _errorListener; |
4475 | 4645 |
4476 /** | 4646 /** |
4477 * Return an array containing information about all of the libraries that were
resolved. | 4647 * Return an array containing information about all of the libraries that were
resolved. |
| 4648 * |
4478 * @return an array containing the libraries that were resolved | 4649 * @return an array containing the libraries that were resolved |
4479 */ | 4650 */ |
4480 Set<Library> get resolvedLibraries => _librariesInCycles; | 4651 Set<Library> get resolvedLibraries => _librariesInCycles; |
4481 | 4652 |
4482 /** | 4653 /** |
4483 * Resolve the library specified by the given source in the given context. The
library is assumed | 4654 * Resolve the library specified by the given source in the given context. The
library is assumed |
4484 * to be embedded in the given source. | 4655 * to be embedded in the given source. |
| 4656 * |
4485 * @param librarySource the source specifying the defining compilation unit of
the library to be | 4657 * @param librarySource the source specifying the defining compilation unit of
the library to be |
4486 * resolved | 4658 * resolved |
4487 * @param unit the compilation unit representing the embedded library | 4659 * @param unit the compilation unit representing the embedded library |
4488 * @param fullAnalysis `true` if a full analysis should be performed | 4660 * @param fullAnalysis `true` if a full analysis should be performed |
4489 * @return the element representing the resolved library | 4661 * @return the element representing the resolved library |
4490 * @throws AnalysisException if the library could not be resolved for some rea
son | 4662 * @throws AnalysisException if the library could not be resolved for some rea
son |
4491 */ | 4663 */ |
4492 LibraryElement resolveEmbeddedLibrary(Source librarySource, CompilationUnit un
it, bool fullAnalysis) { | 4664 LibraryElement resolveEmbeddedLibrary(Source librarySource, CompilationUnit un
it, bool fullAnalysis) { |
4493 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi
ne.LibraryResolver.resolveEmbeddedLibrary"); | 4665 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi
ne.LibraryResolver.resolveEmbeddedLibrary"); |
4494 try { | 4666 try { |
4495 instrumentation.metric("fullAnalysis", fullAnalysis); | 4667 instrumentation.metric("fullAnalysis", fullAnalysis); |
4496 instrumentation.data3("fullName", librarySource.fullName); | 4668 instrumentation.data3("fullName", librarySource.fullName); |
(...skipping 29 matching lines...) Expand all Loading... |
4526 instrumentation.log(); | 4698 instrumentation.log(); |
4527 } | 4699 } |
4528 } | 4700 } |
4529 | 4701 |
4530 /** | 4702 /** |
4531 * Resolve the library specified by the given source in the given context. | 4703 * Resolve the library specified by the given source in the given context. |
4532 * | 4704 * |
4533 * Note that because Dart allows circular imports between libraries, it is pos
sible that more than | 4705 * Note that because Dart allows circular imports between libraries, it is pos
sible that more than |
4534 * one library will need to be resolved. In such cases the error listener can
receive errors from | 4706 * one library will need to be resolved. In such cases the error listener can
receive errors from |
4535 * multiple libraries. | 4707 * multiple libraries. |
| 4708 * |
4536 * @param librarySource the source specifying the defining compilation unit of
the library to be | 4709 * @param librarySource the source specifying the defining compilation unit of
the library to be |
4537 * resolved | 4710 * resolved |
4538 * @param fullAnalysis `true` if a full analysis should be performed | 4711 * @param fullAnalysis `true` if a full analysis should be performed |
4539 * @return the element representing the resolved library | 4712 * @return the element representing the resolved library |
4540 * @throws AnalysisException if the library could not be resolved for some rea
son | 4713 * @throws AnalysisException if the library could not be resolved for some rea
son |
4541 */ | 4714 */ |
4542 LibraryElement resolveLibrary(Source librarySource, bool fullAnalysis) { | 4715 LibraryElement resolveLibrary(Source librarySource, bool fullAnalysis) { |
4543 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi
ne.LibraryResolver.resolveLibrary"); | 4716 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi
ne.LibraryResolver.resolveLibrary"); |
4544 try { | 4717 try { |
4545 instrumentation.metric("fullAnalysis", fullAnalysis); | 4718 instrumentation.metric("fullAnalysis", fullAnalysis); |
4546 instrumentation.data3("fullName", librarySource.fullName); | 4719 instrumentation.data3("fullName", librarySource.fullName); |
4547 Library targetLibrary = createLibrary(librarySource); | 4720 Library targetLibrary = createLibrary(librarySource); |
(...skipping 28 matching lines...) Expand all Loading... |
4576 instrumentation.metric2("librariesInCycles-CompilationUnitSources-Size",
lib.compilationUnitSources.length); | 4749 instrumentation.metric2("librariesInCycles-CompilationUnitSources-Size",
lib.compilationUnitSources.length); |
4577 } | 4750 } |
4578 return targetLibrary.libraryElement; | 4751 return targetLibrary.libraryElement; |
4579 } finally { | 4752 } finally { |
4580 instrumentation.log(); | 4753 instrumentation.log(); |
4581 } | 4754 } |
4582 } | 4755 } |
4583 | 4756 |
4584 /** | 4757 /** |
4585 * Add a dependency to the given map from the referencing library to the refer
enced library. | 4758 * Add a dependency to the given map from the referencing library to the refer
enced library. |
| 4759 * |
4586 * @param dependencyMap the map to which the dependency is to be added | 4760 * @param dependencyMap the map to which the dependency is to be added |
4587 * @param referencingLibrary the library that references the referenced librar
y | 4761 * @param referencingLibrary the library that references the referenced librar
y |
4588 * @param referencedLibrary the library referenced by the referencing library | 4762 * @param referencedLibrary the library referenced by the referencing library |
4589 */ | 4763 */ |
4590 void addDependencyToMap(Map<Library, List<Library>> dependencyMap, Library ref
erencingLibrary, Library referencedLibrary) { | 4764 void addDependencyToMap(Map<Library, List<Library>> dependencyMap, Library ref
erencingLibrary, Library referencedLibrary) { |
4591 List<Library> dependentLibraries = dependencyMap[referencedLibrary]; | 4765 List<Library> dependentLibraries = dependencyMap[referencedLibrary]; |
4592 if (dependentLibraries == null) { | 4766 if (dependentLibraries == null) { |
4593 dependentLibraries = new List<Library>(); | 4767 dependentLibraries = new List<Library>(); |
4594 dependencyMap[referencedLibrary] = dependentLibraries; | 4768 dependencyMap[referencedLibrary] = dependentLibraries; |
4595 } | 4769 } |
4596 dependentLibraries.add(referencingLibrary); | 4770 dependentLibraries.add(referencingLibrary); |
4597 } | 4771 } |
4598 | 4772 |
4599 /** | 4773 /** |
4600 * Given a library that is part of a cycle that includes the root library, add
to the given set of | 4774 * Given a library that is part of a cycle that includes the root library, add
to the given set of |
4601 * libraries all of the libraries reachable from the root library that are als
o included in the | 4775 * libraries all of the libraries reachable from the root library that are als
o included in the |
4602 * cycle. | 4776 * cycle. |
| 4777 * |
4603 * @param library the library to be added to the collection of libraries in cy
cles | 4778 * @param library the library to be added to the collection of libraries in cy
cles |
4604 * @param librariesInCycle a collection of the libraries that are in the cycle | 4779 * @param librariesInCycle a collection of the libraries that are in the cycle |
4605 * @param dependencyMap a table mapping libraries to the collection of librari
es from which those | 4780 * @param dependencyMap a table mapping libraries to the collection of librari
es from which those |
4606 * libraries are referenced | 4781 * libraries are referenced |
4607 */ | 4782 */ |
4608 void addLibrariesInCycle(Library library, Set<Library> librariesInCycle, Map<L
ibrary, List<Library>> dependencyMap) { | 4783 void addLibrariesInCycle(Library library, Set<Library> librariesInCycle, Map<L
ibrary, List<Library>> dependencyMap) { |
4609 if (javaSetAdd(librariesInCycle, library)) { | 4784 if (javaSetAdd(librariesInCycle, library)) { |
4610 List<Library> dependentLibraries = dependencyMap[library]; | 4785 List<Library> dependentLibraries = dependencyMap[library]; |
4611 if (dependentLibraries != null) { | 4786 if (dependentLibraries != null) { |
4612 for (Library dependentLibrary in dependentLibraries) { | 4787 for (Library dependentLibrary in dependentLibraries) { |
4613 addLibrariesInCycle(dependentLibrary, librariesInCycle, dependencyMap)
; | 4788 addLibrariesInCycle(dependentLibrary, librariesInCycle, dependencyMap)
; |
4614 } | 4789 } |
4615 } | 4790 } |
4616 } | 4791 } |
4617 } | 4792 } |
4618 | 4793 |
4619 /** | 4794 /** |
4620 * Add the given library, and all libraries reachable from it that have not al
ready been visited, | 4795 * Add the given library, and all libraries reachable from it that have not al
ready been visited, |
4621 * to the given dependency map. | 4796 * to the given dependency map. |
| 4797 * |
4622 * @param library the library currently being added to the dependency map | 4798 * @param library the library currently being added to the dependency map |
4623 * @param dependencyMap the dependency map being computed | 4799 * @param dependencyMap the dependency map being computed |
4624 * @param visitedLibraries the libraries that have already been visited, used
to prevent infinite | 4800 * @param visitedLibraries the libraries that have already been visited, used
to prevent infinite |
4625 * recursion | 4801 * recursion |
4626 */ | 4802 */ |
4627 void addToDependencyMap(Library library, Map<Library, List<Library>> dependenc
yMap, Set<Library> visitedLibraries) { | 4803 void addToDependencyMap(Library library, Map<Library, List<Library>> dependenc
yMap, Set<Library> visitedLibraries) { |
4628 if (javaSetAdd(visitedLibraries, library)) { | 4804 if (javaSetAdd(visitedLibraries, library)) { |
4629 for (Library referencedLibrary in library.importsAndExports) { | 4805 for (Library referencedLibrary in library.importsAndExports) { |
4630 addDependencyToMap(dependencyMap, library, referencedLibrary); | 4806 addDependencyToMap(dependencyMap, library, referencedLibrary); |
4631 addToDependencyMap(referencedLibrary, dependencyMap, visitedLibraries); | 4807 addToDependencyMap(referencedLibrary, dependencyMap, visitedLibraries); |
4632 } | 4808 } |
4633 if (!library.explicitlyImportsCore && library != _coreLibrary) { | 4809 if (!library.explicitlyImportsCore && library != _coreLibrary) { |
4634 addDependencyToMap(dependencyMap, library, _coreLibrary); | 4810 addDependencyToMap(dependencyMap, library, _coreLibrary); |
4635 } | 4811 } |
4636 } | 4812 } |
4637 } | 4813 } |
4638 | 4814 |
4639 /** | 4815 /** |
4640 * Build the element model representing the combinators declared by the given
directive. | 4816 * Build the element model representing the combinators declared by the given
directive. |
| 4817 * |
4641 * @param directive the directive that declares the combinators | 4818 * @param directive the directive that declares the combinators |
4642 * @return an array containing the import combinators that were built | 4819 * @return an array containing the import combinators that were built |
4643 */ | 4820 */ |
4644 List<NamespaceCombinator> buildCombinators(NamespaceDirective directive) { | 4821 List<NamespaceCombinator> buildCombinators(NamespaceDirective directive) { |
4645 List<NamespaceCombinator> combinators = new List<NamespaceCombinator>(); | 4822 List<NamespaceCombinator> combinators = new List<NamespaceCombinator>(); |
4646 for (Combinator combinator in directive.combinators) { | 4823 for (Combinator combinator in directive.combinators) { |
4647 if (combinator is HideCombinator) { | 4824 if (combinator is HideCombinator) { |
4648 HideElementCombinatorImpl hide = new HideElementCombinatorImpl(); | 4825 HideElementCombinatorImpl hide = new HideElementCombinatorImpl(); |
4649 hide.hiddenNames = getIdentifiers(((combinator as HideCombinator)).hidde
nNames); | 4826 hide.hiddenNames = getIdentifiers(((combinator as HideCombinator)).hidde
nNames); |
4650 combinators.add(hide); | 4827 combinators.add(hide); |
4651 } else { | 4828 } else { |
4652 ShowElementCombinatorImpl show = new ShowElementCombinatorImpl(); | 4829 ShowElementCombinatorImpl show = new ShowElementCombinatorImpl(); |
4653 show.shownNames = getIdentifiers(((combinator as ShowCombinator)).shownN
ames); | 4830 show.shownNames = getIdentifiers(((combinator as ShowCombinator)).shownN
ames); |
4654 combinators.add(show); | 4831 combinators.add(show); |
4655 } | 4832 } |
4656 } | 4833 } |
4657 return new List.from(combinators); | 4834 return new List.from(combinators); |
4658 } | 4835 } |
4659 | 4836 |
4660 /** | 4837 /** |
4661 * Every library now has a corresponding [LibraryElement], so it is now possib
le to resolve | 4838 * Every library now has a corresponding [LibraryElement], so it is now possib
le to resolve |
4662 * the import and export directives. | 4839 * the import and export directives. |
| 4840 * |
4663 * @throws AnalysisException if the defining compilation unit for any of the l
ibraries could not | 4841 * @throws AnalysisException if the defining compilation unit for any of the l
ibraries could not |
4664 * be accessed | 4842 * be accessed |
4665 */ | 4843 */ |
4666 void buildDirectiveModels() { | 4844 void buildDirectiveModels() { |
4667 for (Library library in _librariesInCycles) { | 4845 for (Library library in _librariesInCycles) { |
4668 Map<String, PrefixElementImpl> nameToPrefixMap = new Map<String, PrefixEle
mentImpl>(); | 4846 Map<String, PrefixElementImpl> nameToPrefixMap = new Map<String, PrefixEle
mentImpl>(); |
4669 List<ImportElement> imports = new List<ImportElement>(); | 4847 List<ImportElement> imports = new List<ImportElement>(); |
4670 List<ExportElement> exports = new List<ExportElement>(); | 4848 List<ExportElement> exports = new List<ExportElement>(); |
4671 for (Directive directive in library.definingCompilationUnit.directives) { | 4849 for (Directive directive in library.definingCompilationUnit.directives) { |
4672 if (directive is ImportDirective) { | 4850 if (directive is ImportDirective) { |
4673 ImportDirective importDirective = directive as ImportDirective; | 4851 ImportDirective importDirective = directive as ImportDirective; |
4674 Library importedLibrary = library.getImport(importDirective); | 4852 Source importedSource = library.getSource(importDirective); |
4675 if (importedLibrary != null) { | 4853 if (importedSource != null) { |
4676 ImportElementImpl importElement = new ImportElementImpl(); | 4854 Library importedLibrary = _libraryMap[importedSource]; |
4677 importElement.uri = library.getUri(importDirective); | 4855 if (importedLibrary != null) { |
4678 importElement.combinators = buildCombinators(importDirective); | 4856 ImportElementImpl importElement = new ImportElementImpl(); |
4679 LibraryElement importedLibraryElement = importedLibrary.libraryEleme
nt; | 4857 importElement.uri = library.getUri(importDirective); |
4680 if (importedLibraryElement != null) { | 4858 importElement.combinators = buildCombinators(importDirective); |
4681 importElement.importedLibrary = importedLibraryElement; | 4859 LibraryElement importedLibraryElement = importedLibrary.libraryEle
ment; |
| 4860 if (importedLibraryElement != null) { |
| 4861 importElement.importedLibrary = importedLibraryElement; |
| 4862 } |
| 4863 SimpleIdentifier prefixNode = ((directive as ImportDirective)).pre
fix; |
| 4864 if (prefixNode != null) { |
| 4865 String prefixName = prefixNode.name; |
| 4866 PrefixElementImpl prefix = nameToPrefixMap[prefixName]; |
| 4867 if (prefix == null) { |
| 4868 prefix = new PrefixElementImpl(prefixNode); |
| 4869 nameToPrefixMap[prefixName] = prefix; |
| 4870 } |
| 4871 importElement.prefix = prefix; |
| 4872 } |
| 4873 directive.element = importElement; |
| 4874 imports.add(importElement); |
| 4875 if (doesCompilationUnitHavePartOfDirective(importedLibrary.getAST(
importedSource))) { |
| 4876 StringLiteral uriLiteral = importDirective.uri; |
| 4877 _errorListener.onError(new AnalysisError.con2(library.librarySou
rce, uriLiteral.offset, uriLiteral.length, CompileTimeErrorCode.IMPORT_OF_NON_LI
BRARY, [uriLiteral.toSource()])); |
| 4878 } |
4682 } | 4879 } |
4683 SimpleIdentifier prefixNode = ((directive as ImportDirective)).prefi
x; | |
4684 if (prefixNode != null) { | |
4685 String prefixName = prefixNode.name; | |
4686 PrefixElementImpl prefix = nameToPrefixMap[prefixName]; | |
4687 if (prefix == null) { | |
4688 prefix = new PrefixElementImpl(prefixNode); | |
4689 nameToPrefixMap[prefixName] = prefix; | |
4690 } | |
4691 importElement.prefix = prefix; | |
4692 } | |
4693 directive.element = importElement; | |
4694 imports.add(importElement); | |
4695 } | 4880 } |
4696 } else if (directive is ExportDirective) { | 4881 } else if (directive is ExportDirective) { |
4697 ExportDirective exportDirective = directive as ExportDirective; | 4882 ExportDirective exportDirective = directive as ExportDirective; |
4698 ExportElementImpl exportElement = new ExportElementImpl(); | 4883 Source exportedSource = library.getSource(exportDirective); |
4699 exportElement.uri = library.getUri(exportDirective); | 4884 if (exportedSource != null) { |
4700 exportElement.combinators = buildCombinators(exportDirective); | 4885 Library exportedLibrary = _libraryMap[exportedSource]; |
4701 Library exportedLibrary = library.getExport(exportDirective); | 4886 if (exportedLibrary != null) { |
4702 if (exportedLibrary != null) { | 4887 ExportElementImpl exportElement = new ExportElementImpl(); |
4703 LibraryElement exportedLibraryElement = exportedLibrary.libraryEleme
nt; | 4888 exportElement.uri = library.getUri(exportDirective); |
4704 if (exportedLibraryElement != null) { | 4889 exportElement.combinators = buildCombinators(exportDirective); |
4705 exportElement.exportedLibrary = exportedLibraryElement; | 4890 LibraryElement exportedLibraryElement = exportedLibrary.libraryEle
ment; |
| 4891 if (exportedLibraryElement != null) { |
| 4892 exportElement.exportedLibrary = exportedLibraryElement; |
| 4893 } |
| 4894 directive.element = exportElement; |
| 4895 exports.add(exportElement); |
| 4896 if (doesCompilationUnitHavePartOfDirective(exportedLibrary.getAST(
exportedSource))) { |
| 4897 StringLiteral uriLiteral = exportDirective.uri; |
| 4898 _errorListener.onError(new AnalysisError.con2(library.librarySou
rce, uriLiteral.offset, uriLiteral.length, CompileTimeErrorCode.EXPORT_OF_NON_LI
BRARY, [uriLiteral.toSource()])); |
| 4899 } |
4706 } | 4900 } |
4707 directive.element = exportElement; | |
4708 exports.add(exportElement); | |
4709 } | 4901 } |
4710 } | 4902 } |
4711 } | 4903 } |
4712 Source librarySource = library.librarySource; | 4904 Source librarySource = library.librarySource; |
4713 if (!library.explicitlyImportsCore && _coreLibrarySource != librarySource)
{ | 4905 if (!library.explicitlyImportsCore && _coreLibrarySource != librarySource)
{ |
4714 ImportElementImpl importElement = new ImportElementImpl(); | 4906 ImportElementImpl importElement = new ImportElementImpl(); |
4715 importElement.importedLibrary = _coreLibrary.libraryElement; | 4907 importElement.importedLibrary = _coreLibrary.libraryElement; |
4716 importElement.synthetic = true; | 4908 importElement.synthetic = true; |
4717 imports.add(importElement); | 4909 imports.add(importElement); |
4718 } | 4910 } |
4719 LibraryElementImpl libraryElement = library.libraryElement; | 4911 LibraryElementImpl libraryElement = library.libraryElement; |
4720 libraryElement.imports = new List.from(imports); | 4912 libraryElement.imports = new List.from(imports); |
4721 libraryElement.exports = new List.from(exports); | 4913 libraryElement.exports = new List.from(exports); |
4722 } | 4914 } |
4723 } | 4915 } |
4724 | 4916 |
4725 /** | 4917 /** |
4726 * Build element models for all of the libraries in the current cycle. | 4918 * Build element models for all of the libraries in the current cycle. |
| 4919 * |
4727 * @throws AnalysisException if any of the element models cannot be built | 4920 * @throws AnalysisException if any of the element models cannot be built |
4728 */ | 4921 */ |
4729 void buildElementModels() { | 4922 void buildElementModels() { |
4730 for (Library library in _librariesInCycles) { | 4923 for (Library library in _librariesInCycles) { |
4731 LibraryElementBuilder builder = new LibraryElementBuilder(this); | 4924 LibraryElementBuilder builder = new LibraryElementBuilder(this); |
4732 LibraryElementImpl libraryElement = builder.buildLibrary(library); | 4925 LibraryElementImpl libraryElement = builder.buildLibrary(library); |
4733 library.libraryElement = libraryElement; | 4926 library.libraryElement = libraryElement; |
4734 } | 4927 } |
4735 } | 4928 } |
4736 | 4929 |
4737 /** | 4930 /** |
4738 * Resolve the type hierarchy across all of the types declared in the librarie
s in the current | 4931 * Resolve the type hierarchy across all of the types declared in the librarie
s in the current |
4739 * cycle. | 4932 * cycle. |
| 4933 * |
4740 * @throws AnalysisException if any of the type hierarchies could not be resol
ved | 4934 * @throws AnalysisException if any of the type hierarchies could not be resol
ved |
4741 */ | 4935 */ |
4742 void buildTypeHierarchies() { | 4936 void buildTypeHierarchies() { |
4743 for (Library library in _librariesInCycles) { | 4937 for (Library library in _librariesInCycles) { |
4744 for (Source source in library.compilationUnitSources) { | 4938 for (Source source in library.compilationUnitSources) { |
4745 TypeResolverVisitor visitor = new TypeResolverVisitor.con1(library, sour
ce, _typeProvider); | 4939 TypeResolverVisitor visitor = new TypeResolverVisitor.con1(library, sour
ce, _typeProvider); |
4746 library.getAST(source).accept(visitor); | 4940 library.getAST(source).accept(visitor); |
4747 } | 4941 } |
4748 } | 4942 } |
4749 } | 4943 } |
4750 | 4944 |
4751 /** | 4945 /** |
4752 * Compute a dependency map of libraries reachable from the given library. A d
ependency map is a | 4946 * Compute a dependency map of libraries reachable from the given library. A d
ependency map is a |
4753 * table that maps individual libraries to a list of the libraries that either
import or export | 4947 * table that maps individual libraries to a list of the libraries that either
import or export |
4754 * those libraries. | 4948 * those libraries. |
4755 * | 4949 * |
4756 * This map is used to compute all of the libraries involved in a cycle that i
nclude the root | 4950 * This map is used to compute all of the libraries involved in a cycle that i
nclude the root |
4757 * library. Given that we only add libraries that are reachable from the root
library, when we | 4951 * library. Given that we only add libraries that are reachable from the root
library, when we |
4758 * work backward we are guaranteed to only get libraries in the cycle. | 4952 * work backward we are guaranteed to only get libraries in the cycle. |
| 4953 * |
4759 * @param library the library currently being added to the dependency map | 4954 * @param library the library currently being added to the dependency map |
4760 */ | 4955 */ |
4761 Map<Library, List<Library>> computeDependencyMap(Library library) { | 4956 Map<Library, List<Library>> computeDependencyMap(Library library) { |
4762 Map<Library, List<Library>> dependencyMap = new Map<Library, List<Library>>(
); | 4957 Map<Library, List<Library>> dependencyMap = new Map<Library, List<Library>>(
); |
4763 addToDependencyMap(library, dependencyMap, new Set<Library>()); | 4958 addToDependencyMap(library, dependencyMap, new Set<Library>()); |
4764 return dependencyMap; | 4959 return dependencyMap; |
4765 } | 4960 } |
4766 | 4961 |
4767 /** | 4962 /** |
4768 * Return a collection containing all of the libraries reachable from the give
n library that are | 4963 * Return a collection containing all of the libraries reachable from the give
n library that are |
4769 * contained in a cycle that includes the given library. | 4964 * contained in a cycle that includes the given library. |
| 4965 * |
4770 * @param library the library that must be included in any cycles whose member
s are to be returned | 4966 * @param library the library that must be included in any cycles whose member
s are to be returned |
4771 * @return all of the libraries referenced by the given library that have a ci
rcular reference | 4967 * @return all of the libraries referenced by the given library that have a ci
rcular reference |
4772 * back to the given library | 4968 * back to the given library |
4773 */ | 4969 */ |
4774 Set<Library> computeLibrariesInCycles(Library library) { | 4970 Set<Library> computeLibrariesInCycles(Library library) { |
4775 Map<Library, List<Library>> dependencyMap = computeDependencyMap(library); | 4971 Map<Library, List<Library>> dependencyMap = computeDependencyMap(library); |
4776 Set<Library> librariesInCycle = new Set<Library>(); | 4972 Set<Library> librariesInCycle = new Set<Library>(); |
4777 addLibrariesInCycle(library, librariesInCycle, dependencyMap); | 4973 addLibrariesInCycle(library, librariesInCycle, dependencyMap); |
4778 return librariesInCycle; | 4974 return librariesInCycle; |
4779 } | 4975 } |
4780 | 4976 |
4781 /** | 4977 /** |
4782 * Recursively traverse the libraries reachable from the given library, creati
ng instances of the | 4978 * Recursively traverse the libraries reachable from the given library, creati
ng instances of the |
4783 * class [Library] to represent them, and record the references in the library
objects. | 4979 * class [Library] to represent them, and record the references in the library
objects. |
| 4980 * |
4784 * @param library the library to be processed to find libraries that have not
yet been traversed | 4981 * @param library the library to be processed to find libraries that have not
yet been traversed |
4785 * @throws AnalysisException if some portion of the library graph could not be
traversed | 4982 * @throws AnalysisException if some portion of the library graph could not be
traversed |
4786 */ | 4983 */ |
4787 void computeLibraryDependencies(Library library) { | 4984 void computeLibraryDependencies(Library library) { |
| 4985 Source librarySource = library.librarySource; |
| 4986 List<Library> importedLibraries = new List<Library>(); |
4788 bool explicitlyImportsCore = false; | 4987 bool explicitlyImportsCore = false; |
4789 CompilationUnit unit = library.definingCompilationUnit; | 4988 for (Source importedSource in _analysisContext.computeImportedLibraries(libr
arySource)) { |
4790 for (Directive directive in unit.directives) { | 4989 if (importedSource == _coreLibrarySource) { |
4791 if (directive is ImportDirective) { | 4990 explicitlyImportsCore = true; |
4792 ImportDirective importDirective = directive as ImportDirective; | 4991 } |
4793 Source importedSource = library.getSource(importDirective); | 4992 Library importedLibrary = _libraryMap[importedSource]; |
4794 if (importedSource != null) { | 4993 if (importedLibrary == null) { |
4795 if (importedSource == _coreLibrarySource) { | 4994 importedLibrary = createLibraryOrNull(importedSource); |
4796 explicitlyImportsCore = true; | 4995 if (importedLibrary != null) { |
4797 } | 4996 computeLibraryDependencies(importedLibrary); |
4798 Library importedLibrary = _libraryMap[importedSource]; | |
4799 if (importedLibrary == null) { | |
4800 importedLibrary = createLibraryOrNull(importedSource); | |
4801 if (importedLibrary != null) { | |
4802 computeLibraryDependencies(importedLibrary); | |
4803 } | |
4804 } | |
4805 if (importedLibrary != null) { | |
4806 library.addImport(importDirective, importedLibrary); | |
4807 if (doesCompilationUnitHavePartOfDirective(importedLibrary.getAST(im
portedSource))) { | |
4808 StringLiteral uriLiteral = importDirective.uri; | |
4809 _errorListener.onError(new AnalysisError.con2(library.librarySourc
e, uriLiteral.offset, uriLiteral.length, CompileTimeErrorCode.IMPORT_OF_NON_LIBR
ARY, [uriLiteral.toSource()])); | |
4810 } | |
4811 } | |
4812 } | |
4813 } else if (directive is ExportDirective) { | |
4814 ExportDirective exportDirective = directive as ExportDirective; | |
4815 Source exportedSource = library.getSource(exportDirective); | |
4816 if (exportedSource != null) { | |
4817 Library exportedLibrary = _libraryMap[exportedSource]; | |
4818 if (exportedLibrary == null) { | |
4819 exportedLibrary = createLibraryOrNull(exportedSource); | |
4820 if (exportedLibrary != null) { | |
4821 computeLibraryDependencies(exportedLibrary); | |
4822 } | |
4823 } | |
4824 if (exportedLibrary != null) { | |
4825 library.addExport(exportDirective, exportedLibrary); | |
4826 if (doesCompilationUnitHavePartOfDirective(exportedLibrary.getAST(ex
portedSource))) { | |
4827 StringLiteral uriLiteral = exportDirective.uri; | |
4828 _errorListener.onError(new AnalysisError.con2(library.librarySourc
e, uriLiteral.offset, uriLiteral.length, CompileTimeErrorCode.EXPORT_OF_NON_LIBR
ARY, [uriLiteral.toSource()])); | |
4829 } | |
4830 } | |
4831 } | 4997 } |
4832 } | 4998 } |
| 4999 if (importedLibrary != null) { |
| 5000 importedLibraries.add(importedLibrary); |
| 5001 } |
4833 } | 5002 } |
| 5003 library.importedLibraries = new List.from(importedLibraries); |
| 5004 List<Library> exportedLibraries = new List<Library>(); |
| 5005 for (Source exportedSource in _analysisContext.computeExportedLibraries(libr
arySource)) { |
| 5006 Library exportedLibrary = _libraryMap[exportedSource]; |
| 5007 if (exportedLibrary == null) { |
| 5008 exportedLibrary = createLibraryOrNull(exportedSource); |
| 5009 if (exportedLibrary != null) { |
| 5010 computeLibraryDependencies(exportedLibrary); |
| 5011 } |
| 5012 } |
| 5013 if (exportedLibrary != null) { |
| 5014 exportedLibraries.add(exportedLibrary); |
| 5015 } |
| 5016 } |
| 5017 library.exportedLibraries = new List.from(exportedLibraries); |
4834 library.explicitlyImportsCore = explicitlyImportsCore; | 5018 library.explicitlyImportsCore = explicitlyImportsCore; |
4835 if (!explicitlyImportsCore && _coreLibrarySource != library.librarySource) { | 5019 if (!explicitlyImportsCore && _coreLibrarySource != library.librarySource) { |
4836 Library importedLibrary = _libraryMap[_coreLibrarySource]; | 5020 Library importedLibrary = _libraryMap[_coreLibrarySource]; |
4837 if (importedLibrary == null) { | 5021 if (importedLibrary == null) { |
4838 importedLibrary = createLibraryOrNull(_coreLibrarySource); | 5022 importedLibrary = createLibraryOrNull(_coreLibrarySource); |
4839 if (importedLibrary != null) { | 5023 if (importedLibrary != null) { |
4840 computeLibraryDependencies(importedLibrary); | 5024 computeLibraryDependencies(importedLibrary); |
4841 } | 5025 } |
4842 } | 5026 } |
4843 } | 5027 } |
4844 } | 5028 } |
4845 | 5029 |
4846 /** | 5030 /** |
4847 * Create an object to represent the information about the library defined by
the compilation unit | 5031 * Create an object to represent the information about the library defined by
the compilation unit |
4848 * with the given source. | 5032 * with the given source. |
| 5033 * |
4849 * @param librarySource the source of the library's defining compilation unit | 5034 * @param librarySource the source of the library's defining compilation unit |
4850 * @return the library object that was created | 5035 * @return the library object that was created |
4851 * @throws AnalysisException if the library source is not valid | 5036 * @throws AnalysisException if the library source is not valid |
4852 */ | 5037 */ |
4853 Library createLibrary(Source librarySource) { | 5038 Library createLibrary(Source librarySource) { |
4854 Library library = new Library(_analysisContext, _errorListener, librarySourc
e); | 5039 Library library = new Library(_analysisContext, _errorListener, librarySourc
e); |
4855 library.definingCompilationUnit; | 5040 library.definingCompilationUnit; |
4856 _libraryMap[librarySource] = library; | 5041 _libraryMap[librarySource] = library; |
4857 return library; | 5042 return library; |
4858 } | 5043 } |
4859 | 5044 |
4860 /** | 5045 /** |
4861 * Create an object to represent the information about the library defined by
the compilation unit | 5046 * Create an object to represent the information about the library defined by
the compilation unit |
4862 * with the given source. | 5047 * with the given source. |
| 5048 * |
4863 * @param librarySource the source of the library's defining compilation unit | 5049 * @param librarySource the source of the library's defining compilation unit |
4864 * @return the library object that was created | 5050 * @return the library object that was created |
4865 * @throws AnalysisException if the library source is not valid | 5051 * @throws AnalysisException if the library source is not valid |
4866 */ | 5052 */ |
4867 Library createLibrary2(Source librarySource, CompilationUnit unit) { | 5053 Library createLibrary2(Source librarySource, CompilationUnit unit) { |
4868 Library library = new Library(_analysisContext, _errorListener, librarySourc
e); | 5054 Library library = new Library(_analysisContext, _errorListener, librarySourc
e); |
4869 library.definingCompilationUnit = unit; | 5055 library.definingCompilationUnit = unit; |
4870 _libraryMap[librarySource] = library; | 5056 _libraryMap[librarySource] = library; |
4871 return library; | 5057 return library; |
4872 } | 5058 } |
4873 | 5059 |
4874 /** | 5060 /** |
4875 * Create an object to represent the information about the library defined by
the compilation unit | 5061 * Create an object to represent the information about the library defined by
the compilation unit |
4876 * with the given source. Return the library object that was created, or `null
` if the | 5062 * with the given source. Return the library object that was created, or `null
` if the |
4877 * source is not valid. | 5063 * source is not valid. |
| 5064 * |
4878 * @param librarySource the source of the library's defining compilation unit | 5065 * @param librarySource the source of the library's defining compilation unit |
4879 * @return the library object that was created | 5066 * @return the library object that was created |
4880 */ | 5067 */ |
4881 Library createLibraryOrNull(Source librarySource) { | 5068 Library createLibraryOrNull(Source librarySource) { |
4882 if (!librarySource.exists()) { | 5069 if (!librarySource.exists()) { |
4883 return null; | 5070 return null; |
4884 } | 5071 } |
4885 Library library = new Library(_analysisContext, _errorListener, librarySourc
e); | 5072 Library library = new Library(_analysisContext, _errorListener, librarySourc
e); |
4886 try { | 5073 try { |
4887 library.definingCompilationUnit; | 5074 library.definingCompilationUnit; |
4888 } on AnalysisException catch (exception) { | 5075 } on AnalysisException catch (exception) { |
4889 return null; | 5076 return null; |
4890 } | 5077 } |
4891 _libraryMap[librarySource] = library; | 5078 _libraryMap[librarySource] = library; |
4892 return library; | 5079 return library; |
4893 } | 5080 } |
4894 | 5081 |
4895 /** | 5082 /** |
4896 * Return `true` if and only if the passed [CompilationUnit] has a part-of dir
ective. | 5083 * Return `true` if and only if the passed [CompilationUnit] has a part-of dir
ective. |
| 5084 * |
4897 * @param node the [CompilationUnit] to test | 5085 * @param node the [CompilationUnit] to test |
4898 * @return `true` if and only if the passed [CompilationUnit] has a part-of di
rective | 5086 * @return `true` if and only if the passed [CompilationUnit] has a part-of di
rective |
4899 */ | 5087 */ |
4900 bool doesCompilationUnitHavePartOfDirective(CompilationUnit node) { | 5088 bool doesCompilationUnitHavePartOfDirective(CompilationUnit node) { |
4901 NodeList<Directive> directives = node.directives; | 5089 NodeList<Directive> directives = node.directives; |
4902 for (Directive directive in directives) { | 5090 for (Directive directive in directives) { |
4903 if (directive is PartOfDirective) { | 5091 if (directive is PartOfDirective) { |
4904 return true; | 5092 return true; |
4905 } | 5093 } |
4906 } | 5094 } |
4907 return false; | 5095 return false; |
4908 } | 5096 } |
4909 | 5097 |
4910 /** | 5098 /** |
4911 * Return an array containing the lexical identifiers associated with the node
s in the given list. | 5099 * Return an array containing the lexical identifiers associated with the node
s in the given list. |
| 5100 * |
4912 * @param names the AST nodes representing the identifiers | 5101 * @param names the AST nodes representing the identifiers |
4913 * @return the lexical identifiers associated with the nodes in the list | 5102 * @return the lexical identifiers associated with the nodes in the list |
4914 */ | 5103 */ |
4915 List<String> getIdentifiers(NodeList<SimpleIdentifier> names) { | 5104 List<String> getIdentifiers(NodeList<SimpleIdentifier> names) { |
4916 int count = names.length; | 5105 int count = names.length; |
4917 List<String> identifiers = new List<String>(count); | 5106 List<String> identifiers = new List<String>(count); |
4918 for (int i = 0; i < count; i++) { | 5107 for (int i = 0; i < count; i++) { |
4919 identifiers[i] = names[i].name; | 5108 identifiers[i] = names[i].name; |
4920 } | 5109 } |
4921 return identifiers; | 5110 return identifiers; |
(...skipping 14 matching lines...) Expand all Loading... |
4936 } on AnalysisException catch (exception) { | 5125 } on AnalysisException catch (exception) { |
4937 AnalysisEngine.instance.logger.logError2("Internal Error: Could not ac
cess AST for ${source.fullName} during constant evaluation", exception); | 5126 AnalysisEngine.instance.logger.logError2("Internal Error: Could not ac
cess AST for ${source.fullName} during constant evaluation", exception); |
4938 } | 5127 } |
4939 } | 5128 } |
4940 } | 5129 } |
4941 computer.computeValues(); | 5130 computer.computeValues(); |
4942 } | 5131 } |
4943 | 5132 |
4944 /** | 5133 /** |
4945 * Resolve the identifiers and perform type analysis in the libraries in the c
urrent cycle. | 5134 * Resolve the identifiers and perform type analysis in the libraries in the c
urrent cycle. |
| 5135 * |
4946 * @throws AnalysisException if any of the identifiers could not be resolved o
r if any of the | 5136 * @throws AnalysisException if any of the identifiers could not be resolved o
r if any of the |
4947 * libraries could not have their types analyzed | 5137 * libraries could not have their types analyzed |
4948 */ | 5138 */ |
4949 void resolveReferencesAndTypes() { | 5139 void resolveReferencesAndTypes() { |
4950 for (Library library in _librariesInCycles) { | 5140 for (Library library in _librariesInCycles) { |
4951 resolveReferencesAndTypes2(library); | 5141 resolveReferencesAndTypes2(library); |
4952 } | 5142 } |
4953 } | 5143 } |
4954 | 5144 |
4955 /** | 5145 /** |
4956 * Resolve the identifiers and perform type analysis in the given library. | 5146 * Resolve the identifiers and perform type analysis in the given library. |
| 5147 * |
4957 * @param library the library to be resolved | 5148 * @param library the library to be resolved |
4958 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in | 5149 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in |
4959 * the library cannot be analyzed | 5150 * the library cannot be analyzed |
4960 */ | 5151 */ |
4961 void resolveReferencesAndTypes2(Library library) { | 5152 void resolveReferencesAndTypes2(Library library) { |
4962 for (Source source in library.compilationUnitSources) { | 5153 for (Source source in library.compilationUnitSources) { |
4963 ResolverVisitor visitor = new ResolverVisitor.con1(library, source, _typeP
rovider); | 5154 ResolverVisitor visitor = new ResolverVisitor.con1(library, source, _typeP
rovider); |
4964 library.getAST(source).accept(visitor); | 5155 library.getAST(source).accept(visitor); |
4965 } | 5156 } |
4966 } | 5157 } |
4967 | 5158 |
4968 /** | 5159 /** |
4969 * Run additional analyses, such as the [ConstantVerifier] and [ErrorVerifier]
analysis in the current cycle. | 5160 * Run additional analyses, such as the [ConstantVerifier] and [ErrorVerifier] |
| 5161 * analysis in the current cycle. |
| 5162 * |
4970 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in | 5163 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in |
4971 * the library cannot be analyzed | 5164 * the library cannot be analyzed |
4972 */ | 5165 */ |
4973 void runAdditionalAnalyses() { | 5166 void runAdditionalAnalyses() { |
4974 for (Library library in _librariesInCycles) { | 5167 for (Library library in _librariesInCycles) { |
4975 runAdditionalAnalyses2(library); | 5168 runAdditionalAnalyses2(library); |
4976 } | 5169 } |
4977 } | 5170 } |
4978 | 5171 |
4979 /** | 5172 /** |
4980 * Run additional analyses, such as the [ConstantVerifier] and [ErrorVerifier]
analysis in the given library. | 5173 * Run additional analyses, such as the [ConstantVerifier] and [ErrorVerifier] |
| 5174 * analysis in the given library. |
| 5175 * |
4981 * @param library the library to have the extra analyses processes run | 5176 * @param library the library to have the extra analyses processes run |
4982 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in | 5177 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in |
4983 * the library cannot be analyzed | 5178 * the library cannot be analyzed |
4984 */ | 5179 */ |
4985 void runAdditionalAnalyses2(Library library) { | 5180 void runAdditionalAnalyses2(Library library) { |
4986 for (Source source in library.compilationUnitSources) { | 5181 for (Source source in library.compilationUnitSources) { |
4987 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source); | 5182 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source); |
4988 CompilationUnit unit = library.getAST(source); | 5183 CompilationUnit unit = library.getAST(source); |
4989 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, _t
ypeProvider); | 5184 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, _t
ypeProvider); |
4990 unit.accept(constantVerifier); | 5185 unit.accept(constantVerifier); |
4991 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, library.lib
raryElement, _typeProvider, library.inheritanceManager); | 5186 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, library.lib
raryElement, _typeProvider, library.inheritanceManager); |
4992 unit.accept(errorVerifier); | 5187 unit.accept(errorVerifier); |
| 5188 if (_audit) { |
| 5189 unit.accept(new PubVerifier(_analysisContext, errorReporter)); |
| 5190 } |
4993 } | 5191 } |
4994 } | 5192 } |
4995 } | 5193 } |
4996 /** | 5194 /** |
4997 * Instances of the class `ResolverVisitor` are used to resolve the nodes within
a single | 5195 * Instances of the class `ResolverVisitor` are used to resolve the nodes within
a single |
4998 * compilation unit. | 5196 * compilation unit. |
| 5197 * |
4999 * @coverage dart.engine.resolver | 5198 * @coverage dart.engine.resolver |
5000 */ | 5199 */ |
5001 class ResolverVisitor extends ScopedVisitor { | 5200 class ResolverVisitor extends ScopedVisitor { |
5002 | 5201 |
5003 /** | 5202 /** |
5004 * The object used to resolve the element associated with the current node. | 5203 * The object used to resolve the element associated with the current node. |
5005 */ | 5204 */ |
5006 ElementResolver _elementResolver; | 5205 ElementResolver _elementResolver; |
5007 | 5206 |
5008 /** | 5207 /** |
(...skipping 13 matching lines...) Expand all Loading... |
5022 */ | 5221 */ |
5023 ExecutableElement _enclosingFunction = null; | 5222 ExecutableElement _enclosingFunction = null; |
5024 | 5223 |
5025 /** | 5224 /** |
5026 * The object keeping track of which elements have had their types overridden. | 5225 * The object keeping track of which elements have had their types overridden. |
5027 */ | 5226 */ |
5028 TypeOverrideManager _overrideManager = new TypeOverrideManager(); | 5227 TypeOverrideManager _overrideManager = new TypeOverrideManager(); |
5029 | 5228 |
5030 /** | 5229 /** |
5031 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 5230 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 5231 * |
5032 * @param library the library containing the compilation unit being resolved | 5232 * @param library the library containing the compilation unit being resolved |
5033 * @param source the source representing the compilation unit being visited | 5233 * @param source the source representing the compilation unit being visited |
5034 * @param typeProvider the object used to access the types from the core libra
ry | 5234 * @param typeProvider the object used to access the types from the core libra
ry |
5035 */ | 5235 */ |
5036 ResolverVisitor.con1(Library library, Source source, TypeProvider typeProvider
) : super.con1(library, source, typeProvider) { | 5236 ResolverVisitor.con1(Library library, Source source, TypeProvider typeProvider
) : super.con1(library, source, typeProvider) { |
5037 _jtd_constructor_274_impl(library, source, typeProvider); | 5237 _jtd_constructor_274_impl(library, source, typeProvider); |
5038 } | 5238 } |
5039 _jtd_constructor_274_impl(Library library, Source source, TypeProvider typePro
vider) { | 5239 _jtd_constructor_274_impl(Library library, Source source, TypeProvider typePro
vider) { |
5040 this._elementResolver = new ElementResolver(this); | 5240 this._elementResolver = new ElementResolver(this); |
5041 this._typeAnalyzer = new StaticTypeAnalyzer(this); | 5241 this._typeAnalyzer = new StaticTypeAnalyzer(this); |
5042 } | 5242 } |
5043 | 5243 |
5044 /** | 5244 /** |
5045 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 5245 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 5246 * |
5046 * @param definingLibrary the element for the library containing the compilati
on unit being | 5247 * @param definingLibrary the element for the library containing the compilati
on unit being |
5047 * visited | 5248 * visited |
5048 * @param source the source representing the compilation unit being visited | 5249 * @param source the source representing the compilation unit being visited |
5049 * @param typeProvider the object used to access the types from the core libra
ry | 5250 * @param typeProvider the object used to access the types from the core libra
ry |
5050 * @param errorListener the error listener that will be informed of any errors
that are found | 5251 * @param errorListener the error listener that will be informed of any errors
that are found |
5051 * during resolution | 5252 * during resolution |
5052 */ | 5253 */ |
5053 ResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypeProvid
er typeProvider, AnalysisErrorListener errorListener) : super.con2(definingLibra
ry, source, typeProvider, errorListener) { | 5254 ResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypeProvid
er typeProvider, AnalysisErrorListener errorListener) : super.con2(definingLibra
ry, source, typeProvider, errorListener) { |
5054 _jtd_constructor_275_impl(definingLibrary, source, typeProvider, errorListen
er); | 5255 _jtd_constructor_275_impl(definingLibrary, source, typeProvider, errorListen
er); |
5055 } | 5256 } |
5056 _jtd_constructor_275_impl(LibraryElement definingLibrary, Source source, TypeP
rovider typeProvider, AnalysisErrorListener errorListener) { | 5257 _jtd_constructor_275_impl(LibraryElement definingLibrary, Source source, TypeP
rovider typeProvider, AnalysisErrorListener errorListener) { |
5057 this._elementResolver = new ElementResolver(this); | 5258 this._elementResolver = new ElementResolver(this); |
5058 this._typeAnalyzer = new StaticTypeAnalyzer(this); | 5259 this._typeAnalyzer = new StaticTypeAnalyzer(this); |
5059 } | 5260 } |
5060 | 5261 |
5061 /** | 5262 /** |
5062 * Return the object keeping track of which elements have had their types over
ridden. | 5263 * Return the object keeping track of which elements have had their types over
ridden. |
| 5264 * |
5063 * @return the object keeping track of which elements have had their types ove
rridden | 5265 * @return the object keeping track of which elements have had their types ove
rridden |
5064 */ | 5266 */ |
5065 TypeOverrideManager get overrideManager => _overrideManager; | 5267 TypeOverrideManager get overrideManager => _overrideManager; |
5066 Object visitAsExpression(AsExpression node) { | 5268 Object visitAsExpression(AsExpression node) { |
5067 super.visitAsExpression(node); | 5269 super.visitAsExpression(node); |
5068 VariableElement element = getOverridableElement(node.expression); | 5270 VariableElement element = getOverridableElement(node.expression); |
5069 if (element != null) { | 5271 if (element != null) { |
5070 override(element, node.type.type); | 5272 override(element, node.type.type); |
5071 } | 5273 } |
5072 return null; | 5274 return null; |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5281 try { | 5483 try { |
5282 _enclosingFunction = node.element; | 5484 _enclosingFunction = node.element; |
5283 _overrideManager.enterScope(); | 5485 _overrideManager.enterScope(); |
5284 super.visitFunctionExpression(node); | 5486 super.visitFunctionExpression(node); |
5285 } finally { | 5487 } finally { |
5286 _overrideManager.exitScope(); | 5488 _overrideManager.exitScope(); |
5287 _enclosingFunction = outerFunction; | 5489 _enclosingFunction = outerFunction; |
5288 } | 5490 } |
5289 return null; | 5491 return null; |
5290 } | 5492 } |
| 5493 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { |
| 5494 safelyVisit(node.function); |
| 5495 node.accept(_elementResolver); |
| 5496 inferFunctionExpressionsParametersTypes(node.argumentList); |
| 5497 safelyVisit(node.argumentList); |
| 5498 node.accept(_typeAnalyzer); |
| 5499 return null; |
| 5500 } |
5291 Object visitHideCombinator(HideCombinator node) => null; | 5501 Object visitHideCombinator(HideCombinator node) => null; |
5292 Object visitIfStatement(IfStatement node) { | 5502 Object visitIfStatement(IfStatement node) { |
5293 Expression condition = node.condition; | 5503 Expression condition = node.condition; |
5294 safelyVisit(condition); | 5504 safelyVisit(condition); |
5295 Map<Element, Type2> thenOverrides = null; | 5505 Map<Element, Type2> thenOverrides = null; |
5296 Statement thenStatement = node.thenStatement; | 5506 Statement thenStatement = node.thenStatement; |
5297 if (thenStatement != null) { | 5507 if (thenStatement != null) { |
5298 try { | 5508 try { |
5299 _overrideManager.enterScope(); | 5509 _overrideManager.enterScope(); |
5300 propagateTrueState(condition); | 5510 propagateTrueState(condition); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5340 try { | 5550 try { |
5341 _enclosingFunction = node.element; | 5551 _enclosingFunction = node.element; |
5342 super.visitMethodDeclaration(node); | 5552 super.visitMethodDeclaration(node); |
5343 } finally { | 5553 } finally { |
5344 _enclosingFunction = outerFunction; | 5554 _enclosingFunction = outerFunction; |
5345 } | 5555 } |
5346 return null; | 5556 return null; |
5347 } | 5557 } |
5348 Object visitMethodInvocation(MethodInvocation node) { | 5558 Object visitMethodInvocation(MethodInvocation node) { |
5349 safelyVisit(node.target); | 5559 safelyVisit(node.target); |
| 5560 node.accept(_elementResolver); |
| 5561 inferFunctionExpressionsParametersTypes(node.argumentList); |
5350 safelyVisit(node.argumentList); | 5562 safelyVisit(node.argumentList); |
5351 node.accept(_elementResolver); | |
5352 node.accept(_typeAnalyzer); | 5563 node.accept(_typeAnalyzer); |
5353 return null; | 5564 return null; |
5354 } | 5565 } |
5355 Object visitNode(ASTNode node) { | 5566 Object visitNode(ASTNode node) { |
5356 node.visitChildren(this); | 5567 node.visitChildren(this); |
5357 node.accept(_elementResolver); | 5568 node.accept(_elementResolver); |
5358 node.accept(_typeAnalyzer); | 5569 node.accept(_typeAnalyzer); |
5359 return null; | 5570 return null; |
5360 } | 5571 } |
5361 Object visitPrefixedIdentifier(PrefixedIdentifier node) { | 5572 Object visitPrefixedIdentifier(PrefixedIdentifier node) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5427 } | 5638 } |
5428 } | 5639 } |
5429 node.accept(_elementResolver); | 5640 node.accept(_elementResolver); |
5430 node.accept(_typeAnalyzer); | 5641 node.accept(_typeAnalyzer); |
5431 return null; | 5642 return null; |
5432 } | 5643 } |
5433 | 5644 |
5434 /** | 5645 /** |
5435 * Return the class element representing the class containing the current node
, or `null` if | 5646 * Return the class element representing the class containing the current node
, or `null` if |
5436 * the current node is not contained in a class. | 5647 * the current node is not contained in a class. |
| 5648 * |
5437 * @return the class element representing the class containing the current nod
e | 5649 * @return the class element representing the class containing the current nod
e |
5438 */ | 5650 */ |
5439 ClassElement get enclosingClass => _enclosingClass; | 5651 ClassElement get enclosingClass => _enclosingClass; |
5440 | 5652 |
5441 /** | 5653 /** |
5442 * Return the element representing the function containing the current node, o
r `null` if | 5654 * Return the element representing the function containing the current node, o
r `null` if |
5443 * the current node is not contained in a function. | 5655 * the current node is not contained in a function. |
| 5656 * |
5444 * @return the element representing the function containing the current node | 5657 * @return the element representing the function containing the current node |
5445 */ | 5658 */ |
5446 ExecutableElement get enclosingFunction => _enclosingFunction; | 5659 ExecutableElement get enclosingFunction => _enclosingFunction; |
5447 | 5660 |
5448 /** | 5661 /** |
5449 * Return the element associated with the given expression whose type can be o
verridden, or`null` if there is no element whose type can be overridden. | 5662 * Return the element associated with the given expression whose type can be o
verridden, or |
| 5663 * `null` if there is no element whose type can be overridden. |
| 5664 * |
5450 * @param expression the expression with which the element is associated | 5665 * @param expression the expression with which the element is associated |
5451 * @return the element associated with the given expression | 5666 * @return the element associated with the given expression |
5452 */ | 5667 */ |
5453 VariableElement getOverridableElement(Expression expression) { | 5668 VariableElement getOverridableElement(Expression expression) { |
5454 Element element = null; | 5669 Element element = null; |
5455 if (expression is SimpleIdentifier) { | 5670 if (expression is SimpleIdentifier) { |
5456 element = ((expression as SimpleIdentifier)).element; | 5671 element = ((expression as SimpleIdentifier)).element; |
5457 } else if (expression is PrefixedIdentifier) { | 5672 } else if (expression is PrefixedIdentifier) { |
5458 element = ((expression as PrefixedIdentifier)).element; | 5673 element = ((expression as PrefixedIdentifier)).element; |
5459 } else if (expression is PropertyAccess) { | 5674 } else if (expression is PropertyAccess) { |
5460 element = ((expression as PropertyAccess)).propertyName.element; | 5675 element = ((expression as PropertyAccess)).propertyName.element; |
5461 } | 5676 } |
5462 if (element is VariableElement) { | 5677 if (element is VariableElement) { |
5463 return element as VariableElement; | 5678 return element as VariableElement; |
5464 } | 5679 } |
5465 return null; | 5680 return null; |
5466 } | 5681 } |
5467 | 5682 |
5468 /** | 5683 /** |
5469 * If it is appropriate to do so, override the current type of the given eleme
nt with the given | 5684 * If it is appropriate to do so, override the current type of the given eleme
nt with the given |
5470 * type. Generally speaking, it is appropriate if the given type is more speci
fic than the current | 5685 * type. Generally speaking, it is appropriate if the given type is more speci
fic than the current |
5471 * type. | 5686 * type. |
| 5687 * |
5472 * @param element the element whose type might be overridden | 5688 * @param element the element whose type might be overridden |
5473 * @param potentialType the potential type of the element | 5689 * @param potentialType the potential type of the element |
5474 */ | 5690 */ |
5475 void override(VariableElement element, Type2 potentialType) { | 5691 void override(VariableElement element, Type2 potentialType) { |
5476 if (potentialType == null || identical(potentialType, BottomTypeImpl.instanc
e)) { | 5692 if (potentialType == null || identical(potentialType, BottomTypeImpl.instanc
e)) { |
5477 return; | 5693 return; |
5478 } | 5694 } |
5479 if (element is PropertyInducingElement) { | 5695 if (element is PropertyInducingElement) { |
5480 PropertyInducingElement variable = element as PropertyInducingElement; | 5696 PropertyInducingElement variable = element as PropertyInducingElement; |
5481 if (!variable.isConst && !variable.isFinal) { | 5697 if (!variable.isConst && !variable.isFinal) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5520 safelyVisit(node.body); | 5736 safelyVisit(node.body); |
5521 node.updaters.accept(this); | 5737 node.updaters.accept(this); |
5522 } finally { | 5738 } finally { |
5523 _overrideManager.exitScope(); | 5739 _overrideManager.exitScope(); |
5524 } | 5740 } |
5525 } | 5741 } |
5526 | 5742 |
5527 /** | 5743 /** |
5528 * Return the best type information available for the given element. If the ty
pe of the element | 5744 * Return the best type information available for the given element. If the ty
pe of the element |
5529 * has been overridden, then return the overriding type. Otherwise, return the
static type. | 5745 * has been overridden, then return the overriding type. Otherwise, return the
static type. |
| 5746 * |
5530 * @param element the element for which type information is to be returned | 5747 * @param element the element for which type information is to be returned |
5531 * @return the best type information available for the given element | 5748 * @return the best type information available for the given element |
5532 */ | 5749 */ |
5533 Type2 getBestType(Element element) { | 5750 Type2 getBestType(Element element) { |
5534 Type2 bestType = _overrideManager.getType(element); | 5751 Type2 bestType = _overrideManager.getType(element); |
5535 if (bestType == null) { | 5752 if (bestType == null) { |
5536 if (element is LocalVariableElement) { | 5753 if (element is LocalVariableElement) { |
5537 bestType = ((element as LocalVariableElement)).type; | 5754 bestType = ((element as LocalVariableElement)).type; |
5538 } else if (element is ParameterElement) { | 5755 } else if (element is ParameterElement) { |
5539 bestType = ((element as ParameterElement)).type; | 5756 bestType = ((element as ParameterElement)).type; |
5540 } | 5757 } |
5541 } | 5758 } |
5542 return bestType; | 5759 return bestType; |
5543 } | 5760 } |
5544 | 5761 |
5545 /** | 5762 /** |
5546 * The given expression is the expression used to compute the iterator for a f
or-each statement. | 5763 * The given expression is the expression used to compute the iterator for a f
or-each statement. |
5547 * Attempt to compute the type of objects that will be assigned to the loop va
riable and return | 5764 * Attempt to compute the type of objects that will be assigned to the loop va
riable and return |
5548 * that type. Return `null` if the type could not be determined. | 5765 * that type. Return `null` if the type could not be determined. |
| 5766 * |
5549 * @param iterator the iterator for a for-each statement | 5767 * @param iterator the iterator for a for-each statement |
5550 * @return the type of objects that will be assigned to the loop variable | 5768 * @return the type of objects that will be assigned to the loop variable |
5551 */ | 5769 */ |
5552 Type2 getIteratorElementType(Expression iteratorExpression) { | 5770 Type2 getIteratorElementType(Expression iteratorExpression) { |
5553 Type2 expressionType = iteratorExpression.staticType; | 5771 Type2 expressionType = iteratorExpression.staticType; |
5554 if (expressionType is InterfaceType) { | 5772 if (expressionType is InterfaceType) { |
5555 PropertyAccessorElement iterator = ((expressionType as InterfaceType)).loo
kUpGetter("iterator", definingLibrary); | 5773 PropertyAccessorElement iterator = ((expressionType as InterfaceType)).loo
kUpGetter("iterator", definingLibrary); |
5556 if (iterator == null) { | 5774 if (iterator == null) { |
5557 return null; | 5775 return null; |
5558 } | 5776 } |
5559 Type2 iteratorType = iterator.type.returnType; | 5777 Type2 iteratorType = iterator.type.returnType; |
5560 if (iteratorType is InterfaceType) { | 5778 if (iteratorType is InterfaceType) { |
5561 PropertyAccessorElement current = ((iteratorType as InterfaceType)).look
UpGetter("current", definingLibrary); | 5779 PropertyAccessorElement current = ((iteratorType as InterfaceType)).look
UpGetter("current", definingLibrary); |
5562 if (current == null) { | 5780 if (current == null) { |
5563 return null; | 5781 return null; |
5564 } | 5782 } |
5565 return current.type.returnType; | 5783 return current.type.returnType; |
5566 } | 5784 } |
5567 } | 5785 } |
5568 return null; | 5786 return null; |
5569 } | 5787 } |
5570 | 5788 |
5571 /** | 5789 /** |
| 5790 * If given "mayBeClosure" is [FunctionExpression] without explicit parameters
types and its |
| 5791 * required type is [FunctionType], then infer parameters types from [Function
Type]. |
| 5792 */ |
| 5793 void inferFunctionExpressionParametersTypes(Expression mayBeClosure, Type2 may
ByFunctionType) { |
| 5794 if (mayBeClosure is! FunctionExpression) { |
| 5795 return; |
| 5796 } |
| 5797 FunctionExpression closure = mayBeClosure as FunctionExpression; |
| 5798 if (mayByFunctionType is! FunctionType) { |
| 5799 return; |
| 5800 } |
| 5801 FunctionType expectedClosureType = mayByFunctionType as FunctionType; |
| 5802 closure.propagatedType = expectedClosureType; |
| 5803 NodeList<FormalParameter> parameters = closure.parameters.parameters; |
| 5804 List<ParameterElement> expectedParameters = expectedClosureType.parameters; |
| 5805 for (int i = 0; i < parameters.length && i < expectedParameters.length; i++)
{ |
| 5806 FormalParameter parameter = parameters[i]; |
| 5807 ParameterElement element = parameter.element; |
| 5808 Type2 currentType = getBestType(element); |
| 5809 Type2 expectedType = expectedParameters[i].type; |
| 5810 if (currentType == null || expectedType.isMoreSpecificThan(currentType)) { |
| 5811 _overrideManager.setType(element, expectedType); |
| 5812 } |
| 5813 } |
| 5814 } |
| 5815 |
| 5816 /** |
| 5817 * Try to infer types of parameters of the [FunctionExpression] arguments. |
| 5818 */ |
| 5819 void inferFunctionExpressionsParametersTypes(ArgumentList argumentList) { |
| 5820 for (Expression argument in argumentList.arguments) { |
| 5821 ParameterElement parameter = argument.parameterElement; |
| 5822 if (parameter == null) { |
| 5823 parameter = argument.staticParameterElement; |
| 5824 } |
| 5825 if (parameter != null) { |
| 5826 inferFunctionExpressionParametersTypes(argument, parameter.type); |
| 5827 } |
| 5828 } |
| 5829 } |
| 5830 |
| 5831 /** |
5572 * Return `true` if the given expression terminates abruptly (that is, if any
expression | 5832 * Return `true` if the given expression terminates abruptly (that is, if any
expression |
5573 * following the given expression will not be reached). | 5833 * following the given expression will not be reached). |
| 5834 * |
5574 * @param expression the expression being tested | 5835 * @param expression the expression being tested |
5575 * @return `true` if the given expression terminates abruptly | 5836 * @return `true` if the given expression terminates abruptly |
5576 */ | 5837 */ |
5577 bool isAbruptTermination(Expression expression2) { | 5838 bool isAbruptTermination(Expression expression2) { |
5578 while (expression2 is ParenthesizedExpression) { | 5839 while (expression2 is ParenthesizedExpression) { |
5579 expression2 = ((expression2 as ParenthesizedExpression)).expression; | 5840 expression2 = ((expression2 as ParenthesizedExpression)).expression; |
5580 } | 5841 } |
5581 return expression2 is ThrowExpression || expression2 is RethrowExpression; | 5842 return expression2 is ThrowExpression || expression2 is RethrowExpression; |
5582 } | 5843 } |
5583 | 5844 |
5584 /** | 5845 /** |
5585 * Return `true` if the given statement terminates abruptly (that is, if any s
tatement | 5846 * Return `true` if the given statement terminates abruptly (that is, if any s
tatement |
5586 * following the given statement will not be reached). | 5847 * following the given statement will not be reached). |
| 5848 * |
5587 * @param statement the statement being tested | 5849 * @param statement the statement being tested |
5588 * @return `true` if the given statement terminates abruptly | 5850 * @return `true` if the given statement terminates abruptly |
5589 */ | 5851 */ |
5590 bool isAbruptTermination2(Statement statement) { | 5852 bool isAbruptTermination2(Statement statement) { |
5591 if (statement is ReturnStatement || statement is BreakStatement || statement
is ContinueStatement) { | 5853 if (statement is ReturnStatement || statement is BreakStatement || statement
is ContinueStatement) { |
5592 return true; | 5854 return true; |
5593 } else if (statement is ExpressionStatement) { | 5855 } else if (statement is ExpressionStatement) { |
5594 return isAbruptTermination(((statement as ExpressionStatement)).expression
); | 5856 return isAbruptTermination(((statement as ExpressionStatement)).expression
); |
5595 } else if (statement is Block) { | 5857 } else if (statement is Block) { |
5596 NodeList<Statement> statements = ((statement as Block)).statements; | 5858 NodeList<Statement> statements = ((statement as Block)).statements; |
5597 int size = statements.length; | 5859 int size = statements.length; |
5598 if (size == 0) { | 5860 if (size == 0) { |
5599 return false; | 5861 return false; |
5600 } | 5862 } |
5601 return isAbruptTermination2(statements[size - 1]); | 5863 return isAbruptTermination2(statements[size - 1]); |
5602 } | 5864 } |
5603 return false; | 5865 return false; |
5604 } | 5866 } |
5605 | 5867 |
5606 /** | 5868 /** |
5607 * Propagate any type information that results from knowing that the given con
dition will have | 5869 * Propagate any type information that results from knowing that the given con
dition will have |
5608 * been evaluated to 'false'. | 5870 * been evaluated to 'false'. |
| 5871 * |
5609 * @param condition the condition that will have evaluated to 'false' | 5872 * @param condition the condition that will have evaluated to 'false' |
5610 */ | 5873 */ |
5611 void propagateFalseState(Expression condition) { | 5874 void propagateFalseState(Expression condition) { |
5612 if (condition is BinaryExpression) { | 5875 if (condition is BinaryExpression) { |
5613 BinaryExpression binary = condition as BinaryExpression; | 5876 BinaryExpression binary = condition as BinaryExpression; |
5614 if (identical(binary.operator.type, sc.TokenType.BAR_BAR)) { | 5877 if (identical(binary.operator.type, sc.TokenType.BAR_BAR)) { |
5615 propagateFalseState(binary.leftOperand); | 5878 propagateFalseState(binary.leftOperand); |
5616 propagateFalseState(binary.rightOperand); | 5879 propagateFalseState(binary.rightOperand); |
5617 } | 5880 } |
5618 } else if (condition is IsExpression) { | 5881 } else if (condition is IsExpression) { |
(...skipping 10 matching lines...) Expand all Loading... |
5629 propagateTrueState(prefix.operand); | 5892 propagateTrueState(prefix.operand); |
5630 } | 5893 } |
5631 } else if (condition is ParenthesizedExpression) { | 5894 } else if (condition is ParenthesizedExpression) { |
5632 propagateFalseState(((condition as ParenthesizedExpression)).expression); | 5895 propagateFalseState(((condition as ParenthesizedExpression)).expression); |
5633 } | 5896 } |
5634 } | 5897 } |
5635 | 5898 |
5636 /** | 5899 /** |
5637 * Propagate any type information that results from knowing that the given exp
ression will have | 5900 * Propagate any type information that results from knowing that the given exp
ression will have |
5638 * been evaluated without altering the flow of execution. | 5901 * been evaluated without altering the flow of execution. |
| 5902 * |
5639 * @param expression the expression that will have been evaluated | 5903 * @param expression the expression that will have been evaluated |
5640 */ | 5904 */ |
5641 void propagateState(Expression expression) { | 5905 void propagateState(Expression expression) { |
5642 } | 5906 } |
5643 | 5907 |
5644 /** | 5908 /** |
5645 * Propagate any type information that results from knowing that the given con
dition will have | 5909 * Propagate any type information that results from knowing that the given con
dition will have |
5646 * been evaluated to 'true'. | 5910 * been evaluated to 'true'. |
| 5911 * |
5647 * @param condition the condition that will have evaluated to 'true' | 5912 * @param condition the condition that will have evaluated to 'true' |
5648 */ | 5913 */ |
5649 void propagateTrueState(Expression condition) { | 5914 void propagateTrueState(Expression condition) { |
5650 if (condition is BinaryExpression) { | 5915 if (condition is BinaryExpression) { |
5651 BinaryExpression binary = condition as BinaryExpression; | 5916 BinaryExpression binary = condition as BinaryExpression; |
5652 if (identical(binary.operator.type, sc.TokenType.AMPERSAND_AMPERSAND)) { | 5917 if (identical(binary.operator.type, sc.TokenType.AMPERSAND_AMPERSAND)) { |
5653 propagateTrueState(binary.leftOperand); | 5918 propagateTrueState(binary.leftOperand); |
5654 propagateTrueState(binary.rightOperand); | 5919 propagateTrueState(binary.rightOperand); |
5655 } | 5920 } |
5656 } else if (condition is IsExpression) { | 5921 } else if (condition is IsExpression) { |
(...skipping 20 matching lines...) Expand all Loading... |
5677 get nameScope_J2DAccessor => _nameScope; | 5942 get nameScope_J2DAccessor => _nameScope; |
5678 set nameScope_J2DAccessor(__v) => _nameScope = __v; | 5943 set nameScope_J2DAccessor(__v) => _nameScope = __v; |
5679 get typeAnalyzer_J2DAccessor => _typeAnalyzer; | 5944 get typeAnalyzer_J2DAccessor => _typeAnalyzer; |
5680 set typeAnalyzer_J2DAccessor(__v) => _typeAnalyzer = __v; | 5945 set typeAnalyzer_J2DAccessor(__v) => _typeAnalyzer = __v; |
5681 get enclosingClass_J2DAccessor => _enclosingClass; | 5946 get enclosingClass_J2DAccessor => _enclosingClass; |
5682 set enclosingClass_J2DAccessor(__v) => _enclosingClass = __v; | 5947 set enclosingClass_J2DAccessor(__v) => _enclosingClass = __v; |
5683 } | 5948 } |
5684 /** | 5949 /** |
5685 * The abstract class `ScopedVisitor` maintains name and label scopes as an AST
structure is | 5950 * The abstract class `ScopedVisitor` maintains name and label scopes as an AST
structure is |
5686 * being visited. | 5951 * being visited. |
| 5952 * |
5687 * @coverage dart.engine.resolver | 5953 * @coverage dart.engine.resolver |
5688 */ | 5954 */ |
5689 abstract class ScopedVisitor extends GeneralizingASTVisitor<Object> { | 5955 abstract class ScopedVisitor extends GeneralizingASTVisitor<Object> { |
5690 | 5956 |
5691 /** | 5957 /** |
5692 * The element for the library containing the compilation unit being visited. | 5958 * The element for the library containing the compilation unit being visited. |
5693 */ | 5959 */ |
5694 LibraryElement _definingLibrary; | 5960 LibraryElement _definingLibrary; |
5695 | 5961 |
5696 /** | 5962 /** |
(...skipping 10 matching lines...) Expand all Loading... |
5707 * The scope used to resolve identifiers. | 5973 * The scope used to resolve identifiers. |
5708 */ | 5974 */ |
5709 Scope _nameScope; | 5975 Scope _nameScope; |
5710 | 5976 |
5711 /** | 5977 /** |
5712 * The object used to access the types from the core library. | 5978 * The object used to access the types from the core library. |
5713 */ | 5979 */ |
5714 TypeProvider _typeProvider; | 5980 TypeProvider _typeProvider; |
5715 | 5981 |
5716 /** | 5982 /** |
5717 * The scope used to resolve labels for `break` and `continue` statements, or`
null` if no labels have been defined in the current context. | 5983 * The scope used to resolve labels for `break` and `continue` statements, or |
| 5984 * `null` if no labels have been defined in the current context. |
5718 */ | 5985 */ |
5719 LabelScope _labelScope; | 5986 LabelScope _labelScope; |
5720 | 5987 |
5721 /** | 5988 /** |
5722 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 5989 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 5990 * |
5723 * @param library the library containing the compilation unit being resolved | 5991 * @param library the library containing the compilation unit being resolved |
5724 * @param source the source representing the compilation unit being visited | 5992 * @param source the source representing the compilation unit being visited |
5725 * @param typeProvider the object used to access the types from the core libra
ry | 5993 * @param typeProvider the object used to access the types from the core libra
ry |
5726 */ | 5994 */ |
5727 ScopedVisitor.con1(Library library, Source source2, TypeProvider typeProvider2
) { | 5995 ScopedVisitor.con1(Library library, Source source2, TypeProvider typeProvider2
) { |
5728 _jtd_constructor_276_impl(library, source2, typeProvider2); | 5996 _jtd_constructor_276_impl(library, source2, typeProvider2); |
5729 } | 5997 } |
5730 _jtd_constructor_276_impl(Library library, Source source2, TypeProvider typePr
ovider2) { | 5998 _jtd_constructor_276_impl(Library library, Source source2, TypeProvider typePr
ovider2) { |
5731 this._definingLibrary = library.libraryElement; | 5999 this._definingLibrary = library.libraryElement; |
5732 this._source = source2; | 6000 this._source = source2; |
5733 LibraryScope libraryScope = library.libraryScope; | 6001 LibraryScope libraryScope = library.libraryScope; |
5734 this._errorListener = libraryScope.errorListener; | 6002 this._errorListener = libraryScope.errorListener; |
5735 this._nameScope = libraryScope; | 6003 this._nameScope = libraryScope; |
5736 this._typeProvider = typeProvider2; | 6004 this._typeProvider = typeProvider2; |
5737 } | 6005 } |
5738 | 6006 |
5739 /** | 6007 /** |
5740 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 6008 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 6009 * |
5741 * @param definingLibrary the element for the library containing the compilati
on unit being | 6010 * @param definingLibrary the element for the library containing the compilati
on unit being |
5742 * visited | 6011 * visited |
5743 * @param source the source representing the compilation unit being visited | 6012 * @param source the source representing the compilation unit being visited |
5744 * @param typeProvider the object used to access the types from the core libra
ry | 6013 * @param typeProvider the object used to access the types from the core libra
ry |
5745 * @param errorListener the error listener that will be informed of any errors
that are found | 6014 * @param errorListener the error listener that will be informed of any errors
that are found |
5746 * during resolution | 6015 * during resolution |
5747 */ | 6016 */ |
5748 ScopedVisitor.con2(LibraryElement definingLibrary2, Source source2, TypeProvid
er typeProvider2, AnalysisErrorListener errorListener2) { | 6017 ScopedVisitor.con2(LibraryElement definingLibrary2, Source source2, TypeProvid
er typeProvider2, AnalysisErrorListener errorListener2) { |
5749 _jtd_constructor_277_impl(definingLibrary2, source2, typeProvider2, errorLis
tener2); | 6018 _jtd_constructor_277_impl(definingLibrary2, source2, typeProvider2, errorLis
tener2); |
5750 } | 6019 } |
5751 _jtd_constructor_277_impl(LibraryElement definingLibrary2, Source source2, Typ
eProvider typeProvider2, AnalysisErrorListener errorListener2) { | 6020 _jtd_constructor_277_impl(LibraryElement definingLibrary2, Source source2, Typ
eProvider typeProvider2, AnalysisErrorListener errorListener2) { |
5752 this._definingLibrary = definingLibrary2; | 6021 this._definingLibrary = definingLibrary2; |
5753 this._source = source2; | 6022 this._source = source2; |
5754 this._errorListener = errorListener2; | 6023 this._errorListener = errorListener2; |
5755 this._nameScope = new LibraryScope(definingLibrary2, errorListener2); | 6024 this._nameScope = new LibraryScope(definingLibrary2, errorListener2); |
5756 this._typeProvider = typeProvider2; | 6025 this._typeProvider = typeProvider2; |
5757 } | 6026 } |
5758 | 6027 |
5759 /** | 6028 /** |
5760 * Return the library element for the library containing the compilation unit
being resolved. | 6029 * Return the library element for the library containing the compilation unit
being resolved. |
| 6030 * |
5761 * @return the library element for the library containing the compilation unit
being resolved | 6031 * @return the library element for the library containing the compilation unit
being resolved |
5762 */ | 6032 */ |
5763 LibraryElement get definingLibrary => _definingLibrary; | 6033 LibraryElement get definingLibrary => _definingLibrary; |
5764 | 6034 |
5765 /** | 6035 /** |
5766 * Return the object used to access the types from the core library. | 6036 * Return the object used to access the types from the core library. |
| 6037 * |
5767 * @return the object used to access the types from the core library | 6038 * @return the object used to access the types from the core library |
5768 */ | 6039 */ |
5769 TypeProvider get typeProvider => _typeProvider; | 6040 TypeProvider get typeProvider => _typeProvider; |
5770 Object visitBlock(Block node) { | 6041 Object visitBlock(Block node) { |
5771 Scope outerScope = _nameScope; | 6042 Scope outerScope = _nameScope; |
5772 _nameScope = new EnclosedScope(_nameScope); | 6043 _nameScope = new EnclosedScope(_nameScope); |
5773 try { | 6044 try { |
5774 super.visitBlock(node); | 6045 super.visitBlock(node); |
5775 } finally { | 6046 } finally { |
5776 _nameScope = outerScope; | 6047 _nameScope = outerScope; |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5984 try { | 6255 try { |
5985 super.visitWhileStatement(node); | 6256 super.visitWhileStatement(node); |
5986 } finally { | 6257 } finally { |
5987 _labelScope = outerScope; | 6258 _labelScope = outerScope; |
5988 } | 6259 } |
5989 return null; | 6260 return null; |
5990 } | 6261 } |
5991 | 6262 |
5992 /** | 6263 /** |
5993 * Return the label scope in which the current node is being resolved. | 6264 * Return the label scope in which the current node is being resolved. |
| 6265 * |
5994 * @return the label scope in which the current node is being resolved | 6266 * @return the label scope in which the current node is being resolved |
5995 */ | 6267 */ |
5996 LabelScope get labelScope => _labelScope; | 6268 LabelScope get labelScope => _labelScope; |
5997 | 6269 |
5998 /** | 6270 /** |
5999 * Return the name scope in which the current node is being resolved. | 6271 * Return the name scope in which the current node is being resolved. |
| 6272 * |
6000 * @return the name scope in which the current node is being resolved | 6273 * @return the name scope in which the current node is being resolved |
6001 */ | 6274 */ |
6002 Scope get nameScope => _nameScope; | 6275 Scope get nameScope => _nameScope; |
6003 | 6276 |
6004 /** | 6277 /** |
6005 * Report an error with the given error code and arguments. | 6278 * Report an error with the given error code and arguments. |
| 6279 * |
6006 * @param errorCode the error code of the error to be reported | 6280 * @param errorCode the error code of the error to be reported |
6007 * @param node the node specifying the location of the error | 6281 * @param node the node specifying the location of the error |
6008 * @param arguments the arguments to the error, used to compose the error mess
age | 6282 * @param arguments the arguments to the error, used to compose the error mess
age |
6009 */ | 6283 */ |
6010 void reportError(ErrorCode errorCode, ASTNode node, List<Object> arguments) { | 6284 void reportError(ErrorCode errorCode, ASTNode node, List<Object> arguments) { |
6011 _errorListener.onError(new AnalysisError.con2(_source, node.offset, node.len
gth, errorCode, arguments)); | 6285 _errorListener.onError(new AnalysisError.con2(_source, node.offset, node.len
gth, errorCode, arguments)); |
6012 } | 6286 } |
6013 | 6287 |
6014 /** | 6288 /** |
6015 * Report an error with the given error code and arguments. | 6289 * Report an error with the given error code and arguments. |
| 6290 * |
6016 * @param errorCode the error code of the error to be reported | 6291 * @param errorCode the error code of the error to be reported |
6017 * @param offset the offset of the location of the error | 6292 * @param offset the offset of the location of the error |
6018 * @param length the length of the location of the error | 6293 * @param length the length of the location of the error |
6019 * @param arguments the arguments to the error, used to compose the error mess
age | 6294 * @param arguments the arguments to the error, used to compose the error mess
age |
6020 */ | 6295 */ |
6021 void reportError5(ErrorCode errorCode, int offset, int length, List<Object> ar
guments) { | 6296 void reportError5(ErrorCode errorCode, int offset, int length, List<Object> ar
guments) { |
6022 _errorListener.onError(new AnalysisError.con2(_source, offset, length, error
Code, arguments)); | 6297 _errorListener.onError(new AnalysisError.con2(_source, offset, length, error
Code, arguments)); |
6023 } | 6298 } |
6024 | 6299 |
6025 /** | 6300 /** |
6026 * Report an error with the given error code and arguments. | 6301 * Report an error with the given error code and arguments. |
| 6302 * |
6027 * @param errorCode the error code of the error to be reported | 6303 * @param errorCode the error code of the error to be reported |
6028 * @param token the token specifying the location of the error | 6304 * @param token the token specifying the location of the error |
6029 * @param arguments the arguments to the error, used to compose the error mess
age | 6305 * @param arguments the arguments to the error, used to compose the error mess
age |
6030 */ | 6306 */ |
6031 void reportError6(ErrorCode errorCode, sc.Token token, List<Object> arguments)
{ | 6307 void reportError6(ErrorCode errorCode, sc.Token token, List<Object> arguments)
{ |
6032 _errorListener.onError(new AnalysisError.con2(_source, token.offset, token.l
ength, errorCode, arguments)); | 6308 _errorListener.onError(new AnalysisError.con2(_source, token.offset, token.l
ength, errorCode, arguments)); |
6033 } | 6309 } |
6034 | 6310 |
6035 /** | 6311 /** |
6036 * Visit the given AST node if it is not null. | 6312 * Visit the given AST node if it is not null. |
| 6313 * |
6037 * @param node the node to be visited | 6314 * @param node the node to be visited |
6038 */ | 6315 */ |
6039 void safelyVisit(ASTNode node) { | 6316 void safelyVisit(ASTNode node) { |
6040 if (node != null) { | 6317 if (node != null) { |
6041 node.accept(this); | 6318 node.accept(this); |
6042 } | 6319 } |
6043 } | 6320 } |
6044 | 6321 |
6045 /** | 6322 /** |
6046 * Visit the given statement after it's scope has been created. This replaces
the normal call to | 6323 * Visit the given statement after it's scope has been created. This replaces
the normal call to |
6047 * the inherited visit method so that ResolverVisitor can intervene when type
propagation is | 6324 * the inherited visit method so that ResolverVisitor can intervene when type
propagation is |
6048 * enabled. | 6325 * enabled. |
| 6326 * |
6049 * @param node the statement to be visited | 6327 * @param node the statement to be visited |
6050 */ | 6328 */ |
6051 void visitForEachStatementInScope(ForEachStatement node) { | 6329 void visitForEachStatementInScope(ForEachStatement node) { |
6052 safelyVisit(node.iterator); | 6330 safelyVisit(node.iterator); |
6053 safelyVisit(node.loopVariable); | 6331 safelyVisit(node.loopVariable); |
6054 safelyVisit(node.body); | 6332 safelyVisit(node.body); |
6055 } | 6333 } |
6056 | 6334 |
6057 /** | 6335 /** |
6058 * Visit the given statement after it's scope has been created. This replaces
the normal call to | 6336 * Visit the given statement after it's scope has been created. This replaces
the normal call to |
6059 * the inherited visit method so that ResolverVisitor can intervene when type
propagation is | 6337 * the inherited visit method so that ResolverVisitor can intervene when type
propagation is |
6060 * enabled. | 6338 * enabled. |
| 6339 * |
6061 * @param node the statement to be visited | 6340 * @param node the statement to be visited |
6062 */ | 6341 */ |
6063 void visitForStatementInScope(ForStatement node) { | 6342 void visitForStatementInScope(ForStatement node) { |
6064 super.visitForStatement(node); | 6343 super.visitForStatement(node); |
6065 } | 6344 } |
6066 | 6345 |
6067 /** | 6346 /** |
6068 * Add scopes for each of the given labels. | 6347 * Add scopes for each of the given labels. |
| 6348 * |
6069 * @param labels the labels for which new scopes are to be added | 6349 * @param labels the labels for which new scopes are to be added |
6070 * @return the scope that was in effect before the new scopes were added | 6350 * @return the scope that was in effect before the new scopes were added |
6071 */ | 6351 */ |
6072 LabelScope addScopesFor(NodeList<Label> labels) { | 6352 LabelScope addScopesFor(NodeList<Label> labels) { |
6073 LabelScope outerScope = _labelScope; | 6353 LabelScope outerScope = _labelScope; |
6074 for (Label label in labels) { | 6354 for (Label label in labels) { |
6075 SimpleIdentifier labelNameNode = label.label; | 6355 SimpleIdentifier labelNameNode = label.label; |
6076 String labelName = labelNameNode.name; | 6356 String labelName = labelNameNode.name; |
6077 LabelElement labelElement = labelNameNode.element as LabelElement; | 6357 LabelElement labelElement = labelNameNode.element as LabelElement; |
6078 _labelScope = new LabelScope.con2(_labelScope, labelName, labelElement); | 6358 _labelScope = new LabelScope.con2(_labelScope, labelName, labelElement); |
6079 } | 6359 } |
6080 return outerScope; | 6360 return outerScope; |
6081 } | 6361 } |
6082 } | 6362 } |
6083 /** | 6363 /** |
6084 * Instances of the class `StaticTypeAnalyzer` perform two type-related tasks. F
irst, they | 6364 * Instances of the class `StaticTypeAnalyzer` perform two type-related tasks. F
irst, they |
6085 * compute the static type of every expression. Second, they look for any static
type errors or | 6365 * compute the static type of every expression. Second, they look for any static
type errors or |
6086 * warnings that might need to be generated. The requirements for the type analy
zer are: | 6366 * warnings that might need to be generated. The requirements for the type analy
zer are: |
6087 * <ol> | 6367 * <ol> |
6088 * * Every element that refers to types should be fully populated. | 6368 * * Every element that refers to types should be fully populated. |
6089 * * Every node representing an expression should be resolved to the Type of the
expression. | 6369 * * Every node representing an expression should be resolved to the Type of the
expression. |
6090 * </ol> | 6370 * </ol> |
| 6371 * |
6091 * @coverage dart.engine.resolver | 6372 * @coverage dart.engine.resolver |
6092 */ | 6373 */ |
6093 class StaticTypeAnalyzer extends SimpleASTVisitor<Object> { | 6374 class StaticTypeAnalyzer extends SimpleASTVisitor<Object> { |
6094 | 6375 |
6095 /** | 6376 /** |
6096 * Create a table mapping HTML tag names to the names of the classes (in 'dart
:html') that | 6377 * Create a table mapping HTML tag names to the names of the classes (in 'dart
:html') that |
6097 * implement those tags. | 6378 * implement those tags. |
| 6379 * |
6098 * @return the table that was created | 6380 * @return the table that was created |
6099 */ | 6381 */ |
6100 static Map<String, String> createHtmlTagToClassMap() { | 6382 static Map<String, String> createHtmlTagToClassMap() { |
6101 Map<String, String> map = new Map<String, String>(); | 6383 Map<String, String> map = new Map<String, String>(); |
6102 map["a"] = "AnchorElement"; | 6384 map["a"] = "AnchorElement"; |
6103 map["area"] = "AreaElement"; | 6385 map["area"] = "AreaElement"; |
6104 map["br"] = "BRElement"; | 6386 map["br"] = "BRElement"; |
6105 map["base"] = "BaseElement"; | 6387 map["base"] = "BaseElement"; |
6106 map["body"] = "BodyElement"; | 6388 map["body"] = "BodyElement"; |
6107 map["button"] = "ButtonElement"; | 6389 map["button"] = "ButtonElement"; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6180 * nodes are not within a class. | 6462 * nodes are not within a class. |
6181 */ | 6463 */ |
6182 InterfaceType _thisType; | 6464 InterfaceType _thisType; |
6183 | 6465 |
6184 /** | 6466 /** |
6185 * The object keeping track of which elements have had their types overridden. | 6467 * The object keeping track of which elements have had their types overridden. |
6186 */ | 6468 */ |
6187 TypeOverrideManager _overrideManager; | 6469 TypeOverrideManager _overrideManager; |
6188 | 6470 |
6189 /** | 6471 /** |
| 6472 * A table mapping [ExecutableElement]s to their propagated return types. |
| 6473 */ |
| 6474 Map<ExecutableElement, Type2> _propagatedReturnTypes = new Map<ExecutableEleme
nt, Type2>(); |
| 6475 |
| 6476 /** |
6190 * A table mapping HTML tag names to the names of the classes (in 'dart:html')
that implement | 6477 * A table mapping HTML tag names to the names of the classes (in 'dart:html')
that implement |
6191 * those tags. | 6478 * those tags. |
6192 */ | 6479 */ |
6193 static Map<String, String> _HTML_ELEMENT_TO_CLASS_MAP = createHtmlTagToClassMa
p(); | 6480 static Map<String, String> _HTML_ELEMENT_TO_CLASS_MAP = createHtmlTagToClassMa
p(); |
6194 | 6481 |
6195 /** | 6482 /** |
6196 * Initialize a newly created type analyzer. | 6483 * Initialize a newly created type analyzer. |
| 6484 * |
6197 * @param resolver the resolver driving this participant | 6485 * @param resolver the resolver driving this participant |
6198 */ | 6486 */ |
6199 StaticTypeAnalyzer(ResolverVisitor resolver) { | 6487 StaticTypeAnalyzer(ResolverVisitor resolver) { |
6200 this._resolver = resolver; | 6488 this._resolver = resolver; |
6201 _typeProvider = resolver.typeProvider; | 6489 _typeProvider = resolver.typeProvider; |
6202 _dynamicType = _typeProvider.dynamicType; | 6490 _dynamicType = _typeProvider.dynamicType; |
6203 _overrideManager = resolver.overrideManager; | 6491 _overrideManager = resolver.overrideManager; |
6204 } | 6492 } |
6205 | 6493 |
6206 /** | 6494 /** |
6207 * Set the type of the class being analyzed to the given type. | 6495 * Set the type of the class being analyzed to the given type. |
| 6496 * |
6208 * @param thisType the type representing the class containing the nodes being
analyzed | 6497 * @param thisType the type representing the class containing the nodes being
analyzed |
6209 */ | 6498 */ |
6210 void set thisType(InterfaceType thisType2) { | 6499 void set thisType(InterfaceType thisType2) { |
6211 this._thisType = thisType2; | 6500 this._thisType = thisType2; |
6212 } | 6501 } |
6213 | 6502 |
6214 /** | 6503 /** |
6215 * The Dart Language Specification, 12.5: <blockquote>The static type of a str
ing literal is`String`.</blockquote> | 6504 * The Dart Language Specification, 12.5: <blockquote>The static type of a str
ing literal is |
| 6505 * `String`.</blockquote> |
6216 */ | 6506 */ |
6217 Object visitAdjacentStrings(AdjacentStrings node) { | 6507 Object visitAdjacentStrings(AdjacentStrings node) { |
6218 recordStaticType(node, _typeProvider.stringType); | 6508 recordStaticType(node, _typeProvider.stringType); |
6219 return null; | 6509 return null; |
6220 } | 6510 } |
6221 | 6511 |
6222 /** | 6512 /** |
6223 * The Dart Language Specification, 12.33: <blockquote>The static type of an a
rgument definition | 6513 * The Dart Language Specification, 12.33: <blockquote>The static type of an a
rgument definition |
6224 * test is `bool`.</blockquote> | 6514 * test is `bool`.</blockquote> |
6225 */ | 6515 */ |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6259 * | 6549 * |
6260 * ... an assignment of the form <i>e<sub>1</sub>.v = e<sub>2</sub></i> ... | 6550 * ... an assignment of the form <i>e<sub>1</sub>.v = e<sub>2</sub></i> ... |
6261 * | 6551 * |
6262 * Let <i>T</i> be the static type of <i>e<sub>1</sub></i>. It is a static typ
e warning if | 6552 * Let <i>T</i> be the static type of <i>e<sub>1</sub></i>. It is a static typ
e warning if |
6263 * <i>T</i> does not have an accessible instance setter named <i>v=</i>. It is
a static type | 6553 * <i>T</i> does not have an accessible instance setter named <i>v=</i>. It is
a static type |
6264 * warning if the static type of <i>e<sub>2</sub></i> may not be assigned to <
i>T</i>. | 6554 * warning if the static type of <i>e<sub>2</sub></i> may not be assigned to <
i>T</i>. |
6265 * | 6555 * |
6266 * The static type of the expression <i>e<sub>1</sub>.v = e<sub>2</sub></i> is
the static type of | 6556 * The static type of the expression <i>e<sub>1</sub>.v = e<sub>2</sub></i> is
the static type of |
6267 * <i>e<sub>2</sub></i>. | 6557 * <i>e<sub>2</sub></i>. |
6268 * | 6558 * |
6269 * ... an assignment of the form <i>e<sub>1</sub>\[e<sub>2</sub>\] = e<sub>3</
sub></i> ... | 6559 * ... an assignment of the form <i>e<sub>1</sub>[e<sub>2</sub>] = e<sub>3</su
b></i> ... |
6270 * | 6560 * |
6271 * The static type of the expression <i>e<sub>1</sub>\[e<sub>2</sub>\] = e<sub
>3</sub></i> is the | 6561 * The static type of the expression <i>e<sub>1</sub>[e<sub>2</sub>] = e<sub>3
</sub></i> is the |
6272 * static type of <i>e<sub>3</sub></i>. | 6562 * static type of <i>e<sub>3</sub></i>. |
6273 * | 6563 * |
6274 * A compound assignment of the form <i>v op= e</i> is equivalent to <i>v = v
op e</i>. A compound | 6564 * A compound assignment of the form <i>v op= e</i> is equivalent to <i>v = v
op e</i>. A compound |
6275 * assignment of the form <i>C.v op= e</i> is equivalent to <i>C.v = C.v op e<
/i>. A compound | 6565 * assignment of the form <i>C.v op= e</i> is equivalent to <i>C.v = C.v op e<
/i>. A compound |
6276 * assignment of the form <i>e<sub>1</sub>.v op= e<sub>2</sub></i> is equivale
nt to <i>((x) => x.v | 6566 * assignment of the form <i>e<sub>1</sub>.v op= e<sub>2</sub></i> is equivale
nt to <i>((x) => x.v |
6277 * = x.v op e<sub>2</sub>)(e<sub>1</sub>)</i> where <i>x</i> is a variable tha
t is not used in | 6567 * = x.v op e<sub>2</sub>)(e<sub>1</sub>)</i> where <i>x</i> is a variable tha
t is not used in |
6278 * <i>e<sub>2</sub></i>. A compound assignment of the form <i>e<sub>1</sub>\[e
<sub>2</sub>\] op= | 6568 * <i>e<sub>2</sub></i>. A compound assignment of the form <i>e<sub>1</sub>[e<
sub>2</sub>] op= |
6279 * e<sub>3</sub></i> is equivalent to <i>((a, i) => a\[i\] = a\[i\] op e<sub>3
</sub>)(e<sub>1</sub>, | 6569 * e<sub>3</sub></i> is equivalent to <i>((a, i) => a[i] = a[i] op e<sub>3</su
b>)(e<sub>1</sub>, |
6280 * e<sub>2</sub>)</i> where <i>a</i> and <i>i</i> are a variables that are not
used in | 6570 * e<sub>2</sub>)</i> where <i>a</i> and <i>i</i> are a variables that are not
used in |
6281 * <i>e<sub>3</sub></i>.</blockquote> | 6571 * <i>e<sub>3</sub></i>.</blockquote> |
6282 */ | 6572 */ |
6283 Object visitAssignmentExpression(AssignmentExpression node) { | 6573 Object visitAssignmentExpression(AssignmentExpression node) { |
6284 sc.TokenType operator = node.operator.type; | 6574 sc.TokenType operator = node.operator.type; |
6285 if (identical(operator, sc.TokenType.EQ)) { | 6575 if (identical(operator, sc.TokenType.EQ)) { |
6286 Expression rightHandSide = node.rightHandSide; | 6576 Expression rightHandSide = node.rightHandSide; |
6287 Type2 staticType = getStaticType(rightHandSide); | 6577 Type2 staticType = getStaticType(rightHandSide); |
6288 recordStaticType(node, staticType); | 6578 recordStaticType(node, staticType); |
6289 Type2 overrideType = staticType; | 6579 Type2 overrideType = staticType; |
6290 Type2 propagatedType = getPropagatedType(rightHandSide); | 6580 Type2 propagatedType = getPropagatedType(rightHandSide); |
6291 if (propagatedType != null) { | 6581 if (propagatedType != null) { |
6292 if (propagatedType.isMoreSpecificThan(staticType)) { | 6582 if (propagatedType.isMoreSpecificThan(staticType)) { |
6293 recordPropagatedType(node, propagatedType); | 6583 recordPropagatedType2(node, propagatedType); |
6294 } | 6584 } |
6295 overrideType = propagatedType; | 6585 overrideType = propagatedType; |
6296 } | 6586 } |
6297 VariableElement element = _resolver.getOverridableElement(node.leftHandSid
e); | 6587 VariableElement element = _resolver.getOverridableElement(node.leftHandSid
e); |
6298 if (element != null) { | 6588 if (element != null) { |
6299 _resolver.override(element, overrideType); | 6589 _resolver.override(element, overrideType); |
6300 } | 6590 } |
6301 } else { | 6591 } else { |
6302 ExecutableElement staticMethodElement = node.staticElement; | 6592 ExecutableElement staticMethodElement = node.staticElement; |
6303 Type2 staticType = computeReturnType(staticMethodElement); | 6593 Type2 staticType = computeStaticReturnType(staticMethodElement); |
6304 recordStaticType(node, staticType); | 6594 recordStaticType(node, staticType); |
6305 MethodElement propagatedMethodElement = node.element; | 6595 MethodElement propagatedMethodElement = node.element; |
6306 if (propagatedMethodElement != staticMethodElement) { | 6596 if (propagatedMethodElement != staticMethodElement) { |
6307 Type2 propagatedType = computeReturnType(propagatedMethodElement); | 6597 Type2 propagatedType = computeStaticReturnType(propagatedMethodElement); |
6308 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy
pe)) { | 6598 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy
pe)) { |
6309 recordPropagatedType(node, propagatedType); | 6599 recordPropagatedType2(node, propagatedType); |
6310 } | 6600 } |
6311 } | 6601 } |
6312 } | 6602 } |
6313 return null; | 6603 return null; |
6314 } | 6604 } |
6315 | 6605 |
6316 /** | 6606 /** |
6317 * The Dart Language Specification, 12.20: <blockquote>The static type of a lo
gical boolean | 6607 * The Dart Language Specification, 12.20: <blockquote>The static type of a lo
gical boolean |
6318 * expression is `bool`.</blockquote> | 6608 * expression is `bool`.</blockquote> |
6319 * | 6609 * |
(...skipping 25 matching lines...) Expand all Loading... |
6345 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> | 6635 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> |
6346 * | 6636 * |
6347 * The Dart Language Specification, 12.26: <blockquote>A multiplicative expres
sion of the form | 6637 * The Dart Language Specification, 12.26: <blockquote>A multiplicative expres
sion of the form |
6348 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio
n | 6638 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio
n |
6349 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. A multiplicative expression of the
form <i>super op | 6639 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. A multiplicative expression of the
form <i>super op |
6350 * e<sub>2</sub></i> is equivalent to the method invocation | 6640 * e<sub>2</sub></i> is equivalent to the method invocation |
6351 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> | 6641 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> |
6352 */ | 6642 */ |
6353 Object visitBinaryExpression(BinaryExpression node) { | 6643 Object visitBinaryExpression(BinaryExpression node) { |
6354 ExecutableElement staticMethodElement = node.staticElement; | 6644 ExecutableElement staticMethodElement = node.staticElement; |
6355 Type2 staticType = computeReturnType(staticMethodElement); | 6645 Type2 staticType = computeStaticReturnType(staticMethodElement); |
6356 staticType = refineBinaryExpressionType(node, staticType); | 6646 staticType = refineBinaryExpressionType(node, staticType); |
6357 recordStaticType(node, staticType); | 6647 recordStaticType(node, staticType); |
6358 MethodElement propagatedMethodElement = node.element; | 6648 MethodElement propagatedMethodElement = node.element; |
6359 if (propagatedMethodElement != staticMethodElement) { | 6649 if (propagatedMethodElement != staticMethodElement) { |
6360 Type2 propagatedType = computeReturnType(propagatedMethodElement); | 6650 Type2 propagatedType = computeStaticReturnType(propagatedMethodElement); |
6361 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType
)) { | 6651 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType
)) { |
6362 recordPropagatedType(node, propagatedType); | 6652 recordPropagatedType2(node, propagatedType); |
6363 } | 6653 } |
6364 } | 6654 } |
6365 return null; | 6655 return null; |
6366 } | 6656 } |
6367 | 6657 |
6368 /** | 6658 /** |
6369 * The Dart Language Specification, 12.4: <blockquote>The static type of a boo
lean literal is | 6659 * The Dart Language Specification, 12.4: <blockquote>The static type of a boo
lean literal is |
6370 * bool.</blockquote> | 6660 * bool.</blockquote> |
6371 */ | 6661 */ |
6372 Object visitBooleanLiteral(BooleanLiteral node) { | 6662 Object visitBooleanLiteral(BooleanLiteral node) { |
6373 recordStaticType(node, _typeProvider.boolType); | 6663 recordStaticType(node, _typeProvider.boolType); |
6374 return null; | 6664 return null; |
6375 } | 6665 } |
6376 | 6666 |
6377 /** | 6667 /** |
6378 * The Dart Language Specification, 12.15.2: <blockquote>A cascaded method inv
ocation expression | 6668 * The Dart Language Specification, 12.15.2: <blockquote>A cascaded method inv
ocation expression |
6379 * of the form <i>e..suffix</i> is equivalent to the expression <i>(t) {t.suff
ix; return | 6669 * of the form <i>e..suffix</i> is equivalent to the expression <i>(t) {t.suff
ix; return |
6380 * t;}(e)</i>.</blockquote> | 6670 * t;}(e)</i>.</blockquote> |
6381 */ | 6671 */ |
6382 Object visitCascadeExpression(CascadeExpression node) { | 6672 Object visitCascadeExpression(CascadeExpression node) { |
6383 recordStaticType(node, getStaticType(node.target)); | 6673 recordStaticType(node, getStaticType(node.target)); |
6384 recordPropagatedType(node, getPropagatedType(node.target)); | 6674 recordPropagatedType2(node, getPropagatedType(node.target)); |
6385 return null; | 6675 return null; |
6386 } | 6676 } |
6387 | 6677 |
6388 /** | 6678 /** |
6389 * The Dart Language Specification, 12.19: <blockquote> ... a conditional expr
ession <i>c</i> of | 6679 * The Dart Language Specification, 12.19: <blockquote> ... a conditional expr
ession <i>c</i> of |
6390 * the form <i>e<sub>1</sub> ? e<sub>2</sub> : e<sub>3</sub></i> ... | 6680 * the form <i>e<sub>1</sub> ? e<sub>2</sub> : e<sub>3</sub></i> ... |
6391 * | 6681 * |
6392 * It is a static type warning if the type of e<sub>1</sub> may not be assigne
d to `bool`. | 6682 * It is a static type warning if the type of e<sub>1</sub> may not be assigne
d to `bool`. |
6393 * | 6683 * |
6394 * The static type of <i>c</i> is the least upper bound of the static type of
<i>e<sub>2</sub></i> | 6684 * The static type of <i>c</i> is the least upper bound of the static type of
<i>e<sub>2</sub></i> |
(...skipping 17 matching lines...) Expand all Loading... |
6412 Type2 propagatedElseType = getPropagatedType(node.elseExpression); | 6702 Type2 propagatedElseType = getPropagatedType(node.elseExpression); |
6413 if (propagatedThenType != null || propagatedElseType != null) { | 6703 if (propagatedThenType != null || propagatedElseType != null) { |
6414 if (propagatedThenType == null) { | 6704 if (propagatedThenType == null) { |
6415 propagatedThenType = staticThenType; | 6705 propagatedThenType = staticThenType; |
6416 } | 6706 } |
6417 if (propagatedElseType == null) { | 6707 if (propagatedElseType == null) { |
6418 propagatedElseType = staticElseType; | 6708 propagatedElseType = staticElseType; |
6419 } | 6709 } |
6420 Type2 propagatedType = propagatedThenType.getLeastUpperBound(propagatedEls
eType); | 6710 Type2 propagatedType = propagatedThenType.getLeastUpperBound(propagatedEls
eType); |
6421 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType
)) { | 6711 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType
)) { |
6422 recordPropagatedType(node, propagatedType); | 6712 recordPropagatedType2(node, propagatedType); |
6423 } | 6713 } |
6424 } | 6714 } |
6425 return null; | 6715 return null; |
6426 } | 6716 } |
6427 | 6717 |
6428 /** | 6718 /** |
6429 * The Dart Language Specification, 12.3: <blockquote>The static type of a lit
eral double is | 6719 * The Dart Language Specification, 12.3: <blockquote>The static type of a lit
eral double is |
6430 * double.</blockquote> | 6720 * double.</blockquote> |
6431 */ | 6721 */ |
6432 Object visitDoubleLiteral(DoubleLiteral node) { | 6722 Object visitDoubleLiteral(DoubleLiteral node) { |
6433 recordStaticType(node, _typeProvider.doubleType); | 6723 recordStaticType(node, _typeProvider.doubleType); |
6434 return null; | 6724 return null; |
6435 } | 6725 } |
6436 Object visitFunctionDeclaration(FunctionDeclaration node) { | 6726 Object visitFunctionDeclaration(FunctionDeclaration node) { |
6437 FunctionExpression function = node.functionExpression; | 6727 FunctionExpression function = node.functionExpression; |
6438 ExecutableElementImpl functionElement = node.element as ExecutableElementImp
l; | 6728 ExecutableElementImpl functionElement = node.element as ExecutableElementImp
l; |
6439 functionElement.returnType = computeReturnType2(node); | 6729 functionElement.returnType = computeStaticReturnType2(node); |
| 6730 recordPropagatedType(functionElement, function.body); |
6440 FunctionTypeImpl functionType = functionElement.type as FunctionTypeImpl; | 6731 FunctionTypeImpl functionType = functionElement.type as FunctionTypeImpl; |
6441 setTypeInformation(functionType, function.parameters); | 6732 setTypeInformation(functionType, function.parameters); |
6442 recordStaticType(function, functionType); | 6733 recordStaticType(function, functionType); |
6443 return null; | 6734 return null; |
6444 } | 6735 } |
6445 | 6736 |
6446 /** | 6737 /** |
6447 * The Dart Language Specification, 12.9: <blockquote>The static type of a fun
ction literal of the | 6738 * The Dart Language Specification, 12.9: <blockquote>The static type of a fun
ction literal of the |
6448 * form <i>(T<sub>1</sub> a<sub>1</sub>, …, T<sub>n</sub> a<sub>n</sub>
, \[T<sub>n+1</sub> | 6739 * form <i>(T<sub>1</sub> a<sub>1</sub>, …, T<sub>n</sub> a<sub>n</sub>
, [T<sub>n+1</sub> |
6449 * x<sub>n+1</sub> = d1, …, T<sub>n+k</sub> x<sub>n+k</sub> = dk\]) =>
e</i> is | 6740 * x<sub>n+1</sub> = d1, …, T<sub>n+k</sub> x<sub>n+k</sub> = dk]) => e
</i> is |
6450 * <i>(T<sub>1</sub>, …, Tn, \[T<sub>n+1</sub> x<sub>n+1</sub>, &hellip
;, T<sub>n+k</sub> | 6741 * <i>(T<sub>1</sub>, …, Tn, [T<sub>n+1</sub> x<sub>n+1</sub>, …
, T<sub>n+k</sub> |
6451 * x<sub>n+k</sub>\]) → T<sub>0</sub></i>, where <i>T<sub>0</sub></i> is
the static type of | 6742 * x<sub>n+k</sub>]) → T<sub>0</sub></i>, where <i>T<sub>0</sub></i> is t
he static type of |
6452 * <i>e</i>. In any case where <i>T<sub>i</sub>, 1 <= i <= n</i>, is not
specified, it is | 6743 * <i>e</i>. In any case where <i>T<sub>i</sub>, 1 <= i <= n</i>, is not
specified, it is |
6453 * considered to have been specified as dynamic. | 6744 * considered to have been specified as dynamic. |
6454 * | 6745 * |
6455 * The static type of a function literal of the form <i>(T<sub>1</sub> a<sub>1
</sub>, …, | 6746 * The static type of a function literal of the form <i>(T<sub>1</sub> a<sub>1
</sub>, …, |
6456 * T<sub>n</sub> a<sub>n</sub>, {T<sub>n+1</sub> x<sub>n+1</sub> : d1, &hellip
;, T<sub>n+k</sub> | 6747 * T<sub>n</sub> a<sub>n</sub>, {T<sub>n+1</sub> x<sub>n+1</sub> : d1, &hellip
;, T<sub>n+k</sub> |
6457 * x<sub>n+k</sub> : dk}) => e</i> is <i>(T<sub>1</sub>, …, T<sub>n</su
b>, {T<sub>n+1</sub> | 6748 * x<sub>n+k</sub> : dk}) => e</i> is <i>(T<sub>1</sub>, …, T<sub>n</su
b>, {T<sub>n+1</sub> |
6458 * x<sub>n+1</sub>, …, T<sub>n+k</sub> x<sub>n+k</sub>}) → T<sub>0
</sub></i>, where | 6749 * x<sub>n+1</sub>, …, T<sub>n+k</sub> x<sub>n+k</sub>}) → T<sub>0
</sub></i>, where |
6459 * <i>T<sub>0</sub></i> is the static type of <i>e</i>. In any case where <i>T
<sub>i</sub>, 1 | 6750 * <i>T<sub>0</sub></i> is the static type of <i>e</i>. In any case where <i>T
<sub>i</sub>, 1 |
6460 * <= i <= n</i>, is not specified, it is considered to have been specif
ied as dynamic. | 6751 * <= i <= n</i>, is not specified, it is considered to have been specif
ied as dynamic. |
6461 * | 6752 * |
6462 * The static type of a function literal of the form <i>(T<sub>1</sub> a<sub>1
</sub>, …, | 6753 * The static type of a function literal of the form <i>(T<sub>1</sub> a<sub>1
</sub>, …, |
6463 * T<sub>n</sub> a<sub>n</sub>, \[T<sub>n+1</sub> x<sub>n+1</sub> = d1, &helli
p;, T<sub>n+k</sub> | 6754 * T<sub>n</sub> a<sub>n</sub>, [T<sub>n+1</sub> x<sub>n+1</sub> = d1, &hellip
;, T<sub>n+k</sub> |
6464 * x<sub>n+k</sub> = dk\]) {s}</i> is <i>(T<sub>1</sub>, …, T<sub>n</su
b>, \[T<sub>n+1</sub> | 6755 * x<sub>n+k</sub> = dk]) {s}</i> is <i>(T<sub>1</sub>, …, T<sub>n</sub
>, [T<sub>n+1</sub> |
6465 * x<sub>n+1</sub>, …, T<sub>n+k</sub> x<sub>n+k</sub>\]) → dynami
c</i>. In any case | 6756 * x<sub>n+1</sub>, …, T<sub>n+k</sub> x<sub>n+k</sub>]) → dynamic
</i>. In any case |
6466 * where <i>T<sub>i</sub>, 1 <= i <= n</i>, is not specified, it is cons
idered to have been | 6757 * where <i>T<sub>i</sub>, 1 <= i <= n</i>, is not specified, it is cons
idered to have been |
6467 * specified as dynamic. | 6758 * specified as dynamic. |
6468 * | 6759 * |
6469 * The static type of a function literal of the form <i>(T<sub>1</sub> a<sub>1
</sub>, …, | 6760 * The static type of a function literal of the form <i>(T<sub>1</sub> a<sub>1
</sub>, …, |
6470 * T<sub>n</sub> a<sub>n</sub>, {T<sub>n+1</sub> x<sub>n+1</sub> : d1, &hellip
;, T<sub>n+k</sub> | 6761 * T<sub>n</sub> a<sub>n</sub>, {T<sub>n+1</sub> x<sub>n+1</sub> : d1, &hellip
;, T<sub>n+k</sub> |
6471 * x<sub>n+k</sub> : dk}) {s}</i> is <i>(T<sub>1</sub>, …, T<sub>n</sub
>, {T<sub>n+1</sub> | 6762 * x<sub>n+k</sub> : dk}) {s}</i> is <i>(T<sub>1</sub>, …, T<sub>n</sub
>, {T<sub>n+1</sub> |
6472 * x<sub>n+1</sub>, …, T<sub>n+k</sub> x<sub>n+k</sub>}) → dynamic
</i>. In any case | 6763 * x<sub>n+1</sub>, …, T<sub>n+k</sub> x<sub>n+k</sub>}) → dynamic
</i>. In any case |
6473 * where <i>T<sub>i</sub>, 1 <= i <= n</i>, is not specified, it is cons
idered to have been | 6764 * where <i>T<sub>i</sub>, 1 <= i <= n</i>, is not specified, it is cons
idered to have been |
6474 * specified as dynamic.</blockquote> | 6765 * specified as dynamic.</blockquote> |
6475 */ | 6766 */ |
6476 Object visitFunctionExpression(FunctionExpression node) { | 6767 Object visitFunctionExpression(FunctionExpression node) { |
6477 if (node.parent is FunctionDeclaration) { | 6768 if (node.parent is FunctionDeclaration) { |
6478 return null; | 6769 return null; |
6479 } | 6770 } |
6480 ExecutableElementImpl functionElement = node.element as ExecutableElementImp
l; | 6771 ExecutableElementImpl functionElement = node.element as ExecutableElementImp
l; |
6481 functionElement.returnType = computeReturnType3(node); | 6772 functionElement.returnType = computeStaticReturnType3(node); |
| 6773 recordPropagatedType(functionElement, node.body); |
6482 FunctionTypeImpl functionType = node.element.type as FunctionTypeImpl; | 6774 FunctionTypeImpl functionType = node.element.type as FunctionTypeImpl; |
6483 setTypeInformation(functionType, node.parameters); | 6775 setTypeInformation(functionType, node.parameters); |
6484 recordStaticType(node, functionType); | 6776 recordStaticType(node, functionType); |
6485 return null; | 6777 return null; |
6486 } | 6778 } |
6487 | 6779 |
6488 /** | 6780 /** |
6489 * The Dart Language Specification, 12.14.4: <blockquote>A function expression
invocation <i>i</i> | 6781 * The Dart Language Specification, 12.14.4: <blockquote>A function expression
invocation <i>i</i> |
6490 * has the form <i>e<sub>f</sub>(a<sub>1</sub>, …, a<sub>n</sub>, x<sub
>n+1</sub>: | 6782 * has the form <i>e<sub>f</sub>(a<sub>1</sub>, …, a<sub>n</sub>, x<sub
>n+1</sub>: |
6491 * a<sub>n+1</sub>, …, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>, where <i>
e<sub>f</sub></i> is | 6783 * a<sub>n+1</sub>, …, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>, where <i>
e<sub>f</sub></i> is |
6492 * an expression. | 6784 * an expression. |
6493 * | 6785 * |
6494 * It is a static type warning if the static type <i>F</i> of <i>e<sub>f</sub>
</i> may not be | 6786 * It is a static type warning if the static type <i>F</i> of <i>e<sub>f</sub>
</i> may not be |
6495 * assigned to a function type. | 6787 * assigned to a function type. |
6496 * | 6788 * |
6497 * If <i>F</i> is not a function type, the static type of <i>i</i> is dynamic.
Otherwise the | 6789 * If <i>F</i> is not a function type, the static type of <i>i</i> is dynamic.
Otherwise the |
6498 * static type of <i>i</i> is the declared return type of <i>F</i>.</blockquot
e> | 6790 * static type of <i>i</i> is the declared return type of <i>F</i>.</blockquot
e> |
6499 */ | 6791 */ |
6500 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { | 6792 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { |
6501 ExecutableElement staticMethodElement = node.staticElement; | 6793 ExecutableElement staticMethodElement = node.staticElement; |
6502 Type2 staticType = computeReturnType(staticMethodElement); | 6794 Type2 staticStaticType = computeStaticReturnType(staticMethodElement); |
6503 recordStaticType(node, staticType); | 6795 recordStaticType(node, staticStaticType); |
| 6796 Type2 staticPropagatedType = computePropagatedReturnType(staticMethodElement
); |
| 6797 if (staticPropagatedType != null && (staticStaticType == null || staticPropa
gatedType.isMoreSpecificThan(staticStaticType))) { |
| 6798 recordPropagatedType2(node, staticPropagatedType); |
| 6799 } |
6504 ExecutableElement propagatedMethodElement = node.element; | 6800 ExecutableElement propagatedMethodElement = node.element; |
6505 Type2 propagatedType = computeReturnType(propagatedMethodElement); | 6801 if (propagatedMethodElement != staticMethodElement) { |
6506 if (staticType == null) { | 6802 Type2 propagatedStaticType = computeStaticReturnType(propagatedMethodEleme
nt); |
6507 recordStaticType(node, propagatedType); | 6803 if (propagatedStaticType != null && (staticStaticType == null || propagate
dStaticType.isMoreSpecificThan(staticStaticType)) && (staticPropagatedType == nu
ll || propagatedStaticType.isMoreSpecificThan(staticPropagatedType))) { |
6508 } else if (propagatedType != null && propagatedType.isMoreSpecificThan(stati
cType)) { | 6804 recordPropagatedType2(node, propagatedStaticType); |
6509 recordPropagatedType(node, propagatedType); | 6805 } |
| 6806 Type2 propagatedPropagatedType = computePropagatedReturnType(propagatedMet
hodElement); |
| 6807 if (propagatedPropagatedType != null && (staticStaticType == null || propa
gatedPropagatedType.isMoreSpecificThan(staticStaticType)) && (staticPropagatedTy
pe == null || propagatedPropagatedType.isMoreSpecificThan(staticPropagatedType))
&& (propagatedStaticType == null || propagatedPropagatedType.isMoreSpecificThan
(propagatedStaticType))) { |
| 6808 recordPropagatedType2(node, propagatedPropagatedType); |
| 6809 } |
6510 } | 6810 } |
6511 return null; | 6811 return null; |
6512 } | 6812 } |
6513 | 6813 |
6514 /** | 6814 /** |
6515 * The Dart Language Specification, 12.29: <blockquote>An assignable expressio
n of the form | 6815 * The Dart Language Specification, 12.29: <blockquote>An assignable expressio
n of the form |
6516 * <i>e<sub>1</sub>\[e<sub>2</sub>\]</i> is evaluated as a method invocation o
f the operator method | 6816 * <i>e<sub>1</sub>[e<sub>2</sub>]</i> is evaluated as a method invocation of
the operator method |
6517 * <i>\[\]</i> on <i>e<sub>1</sub></i> with argument <i>e<sub>2</sub></i>.</bl
ockquote> | 6817 * <i>[]</i> on <i>e<sub>1</sub></i> with argument <i>e<sub>2</sub></i>.</bloc
kquote> |
6518 */ | 6818 */ |
6519 Object visitIndexExpression(IndexExpression node) { | 6819 Object visitIndexExpression(IndexExpression node) { |
6520 if (node.inSetterContext()) { | 6820 if (node.inSetterContext()) { |
6521 ExecutableElement staticMethodElement = node.staticElement; | 6821 ExecutableElement staticMethodElement = node.staticElement; |
6522 Type2 staticType = computeArgumentType(staticMethodElement); | 6822 Type2 staticType = computeArgumentType(staticMethodElement); |
6523 recordStaticType(node, staticType); | 6823 recordStaticType(node, staticType); |
6524 MethodElement propagatedMethodElement = node.element; | 6824 MethodElement propagatedMethodElement = node.element; |
6525 if (propagatedMethodElement != staticMethodElement) { | 6825 if (propagatedMethodElement != staticMethodElement) { |
6526 Type2 propagatedType = computeArgumentType(propagatedMethodElement); | 6826 Type2 propagatedType = computeArgumentType(propagatedMethodElement); |
6527 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy
pe)) { | 6827 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy
pe)) { |
6528 recordPropagatedType(node, propagatedType); | 6828 recordPropagatedType2(node, propagatedType); |
6529 } | 6829 } |
6530 } | 6830 } |
6531 } else { | 6831 } else { |
6532 ExecutableElement staticMethodElement = node.staticElement; | 6832 ExecutableElement staticMethodElement = node.staticElement; |
6533 Type2 staticType = computeReturnType(staticMethodElement); | 6833 Type2 staticType = computeStaticReturnType(staticMethodElement); |
6534 recordStaticType(node, staticType); | 6834 recordStaticType(node, staticType); |
6535 MethodElement propagatedMethodElement = node.element; | 6835 MethodElement propagatedMethodElement = node.element; |
6536 if (propagatedMethodElement != staticMethodElement) { | 6836 if (propagatedMethodElement != staticMethodElement) { |
6537 Type2 propagatedType = computeReturnType(propagatedMethodElement); | 6837 Type2 propagatedType = computeStaticReturnType(propagatedMethodElement); |
6538 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy
pe)) { | 6838 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy
pe)) { |
6539 recordPropagatedType(node, propagatedType); | 6839 recordPropagatedType2(node, propagatedType); |
6540 } | 6840 } |
6541 } | 6841 } |
6542 } | 6842 } |
6543 return null; | 6843 return null; |
6544 } | 6844 } |
6545 | 6845 |
6546 /** | 6846 /** |
6547 * The Dart Language Specification, 12.11.1: <blockquote>The static type of a
new expression of | 6847 * The Dart Language Specification, 12.11.1: <blockquote>The static type of a
new expression of |
6548 * either the form <i>new T.id(a<sub>1</sub>, …, a<sub>n</sub>)</i> or
the form <i>new | 6848 * either the form <i>new T.id(a<sub>1</sub>, …, a<sub>n</sub>)</i> or
the form <i>new |
6549 * T(a<sub>1</sub>, …, a<sub>n</sub>)</i> is <i>T</i>.</blockquote> | 6849 * T(a<sub>1</sub>, …, a<sub>n</sub>)</i> is <i>T</i>.</blockquote> |
6550 * | 6850 * |
6551 * The Dart Language Specification, 12.11.2: <blockquote>The static type of a
constant object | 6851 * The Dart Language Specification, 12.11.2: <blockquote>The static type of a
constant object |
6552 * expression of either the form <i>const T.id(a<sub>1</sub>, …, a<sub>
n</sub>)</i> or the | 6852 * expression of either the form <i>const T.id(a<sub>1</sub>, …, a<sub>
n</sub>)</i> or the |
6553 * form <i>const T(a<sub>1</sub>, …, a<sub>n</sub>)</i> is <i>T</i>. </
blockquote> | 6853 * form <i>const T(a<sub>1</sub>, …, a<sub>n</sub>)</i> is <i>T</i>. </
blockquote> |
6554 */ | 6854 */ |
6555 Object visitInstanceCreationExpression(InstanceCreationExpression node) { | 6855 Object visitInstanceCreationExpression(InstanceCreationExpression node) { |
6556 recordStaticType(node, node.constructorName.type.type); | 6856 recordStaticType(node, node.constructorName.type.type); |
6557 ConstructorElement element = node.element; | 6857 ConstructorElement element = node.element; |
6558 if (element != null && "Element" == element.enclosingElement.name && "tag" =
= element.name) { | 6858 if (element != null && "Element" == element.enclosingElement.name && "tag" =
= element.name) { |
6559 LibraryElement library = element.library; | 6859 LibraryElement library = element.library; |
6560 if (isHtmlLibrary(library)) { | 6860 if (isHtmlLibrary(library)) { |
6561 Type2 returnType = getFirstArgumentAsType2(library, node.argumentList, _
HTML_ELEMENT_TO_CLASS_MAP); | 6861 Type2 returnType = getFirstArgumentAsType2(library, node.argumentList, _
HTML_ELEMENT_TO_CLASS_MAP); |
6562 if (returnType != null) { | 6862 if (returnType != null) { |
6563 recordPropagatedType(node, returnType); | 6863 recordPropagatedType2(node, returnType); |
6564 } | 6864 } |
6565 } | 6865 } |
6566 } | 6866 } |
6567 return null; | 6867 return null; |
6568 } | 6868 } |
6569 | 6869 |
6570 /** | 6870 /** |
6571 * The Dart Language Specification, 12.3: <blockquote>The static type of an in
teger literal is`int`.</blockquote> | 6871 * The Dart Language Specification, 12.3: <blockquote>The static type of an in
teger literal is |
| 6872 * `int`.</blockquote> |
6572 */ | 6873 */ |
6573 Object visitIntegerLiteral(IntegerLiteral node) { | 6874 Object visitIntegerLiteral(IntegerLiteral node) { |
6574 recordStaticType(node, _typeProvider.intType); | 6875 recordStaticType(node, _typeProvider.intType); |
6575 return null; | 6876 return null; |
6576 } | 6877 } |
6577 | 6878 |
6578 /** | 6879 /** |
6579 * The Dart Language Specification, 12.31: <blockquote>It is a static warning
if <i>T</i> does not | 6880 * The Dart Language Specification, 12.31: <blockquote>It is a static warning
if <i>T</i> does not |
6580 * denote a type available in the current lexical scope. | 6881 * denote a type available in the current lexical scope. |
6581 * | 6882 * |
6582 * The static type of an is-expression is `bool`.</blockquote> | 6883 * The static type of an is-expression is `bool`.</blockquote> |
6583 */ | 6884 */ |
6584 Object visitIsExpression(IsExpression node) { | 6885 Object visitIsExpression(IsExpression node) { |
6585 recordStaticType(node, _typeProvider.boolType); | 6886 recordStaticType(node, _typeProvider.boolType); |
6586 return null; | 6887 return null; |
6587 } | 6888 } |
6588 | 6889 |
6589 /** | 6890 /** |
6590 * The Dart Language Specification, 12.6: <blockquote>The static type of a lis
t literal of the | 6891 * The Dart Language Specification, 12.6: <blockquote>The static type of a lis
t literal of the |
6591 * form <i><b>const</b> <E>\[e<sub>1</sub>, …, e<sub>n</sub>\]</i
> or the form | 6892 * form <i><b>const</b> <E>[e<sub>1</sub>, …, e<sub>n</sub>]</i>
or the form |
6592 * <i><E>\[e<sub>1</sub>, …, e<sub>n</sub>\]</i> is `List<E>
;`. The static | 6893 * <i><E>[e<sub>1</sub>, …, e<sub>n</sub>]</i> is `List<E>`
. The static |
6593 * type a list literal of the form <i><b>const</b> \[e<sub>1</sub>, …,
e<sub>n</sub>\]</i> or | 6894 * type a list literal of the form <i><b>const</b> [e<sub>1</sub>, …, e
<sub>n</sub>]</i> or |
6594 * the form <i>\[e<sub>1</sub>, …, e<sub>n</sub>\]</i> is `List<dyna
mic>`.</blockquote> | 6895 * the form <i>[e<sub>1</sub>, …, e<sub>n</sub>]</i> is `List<dynami
c>` |
| 6896 * .</blockquote> |
6595 */ | 6897 */ |
6596 Object visitListLiteral(ListLiteral node) { | 6898 Object visitListLiteral(ListLiteral node) { |
6597 Type2 staticType = _dynamicType; | 6899 Type2 staticType = _dynamicType; |
6598 TypeArgumentList typeArguments = node.typeArguments; | 6900 TypeArgumentList typeArguments = node.typeArguments; |
6599 if (typeArguments != null) { | 6901 if (typeArguments != null) { |
6600 NodeList<TypeName> arguments = typeArguments.arguments; | 6902 NodeList<TypeName> arguments = typeArguments.arguments; |
6601 if (arguments != null && arguments.length == 1) { | 6903 if (arguments != null && arguments.length == 1) { |
6602 TypeName argumentTypeName = arguments[0]; | 6904 TypeName argumentTypeName = arguments[0]; |
6603 Type2 argumentType = getType2(argumentTypeName); | 6905 Type2 argumentType = getType2(argumentTypeName); |
6604 if (argumentType != null) { | 6906 if (argumentType != null) { |
(...skipping 11 matching lines...) Expand all Loading... |
6616 if (propagatedType != elementType) { | 6918 if (propagatedType != elementType) { |
6617 propagatedType = _dynamicType; | 6919 propagatedType = _dynamicType; |
6618 } else { | 6920 } else { |
6619 propagatedType = propagatedType.getLeastUpperBound(elementType); | 6921 propagatedType = propagatedType.getLeastUpperBound(elementType); |
6620 if (propagatedType == null) { | 6922 if (propagatedType == null) { |
6621 propagatedType = _dynamicType; | 6923 propagatedType = _dynamicType; |
6622 } | 6924 } |
6623 } | 6925 } |
6624 } | 6926 } |
6625 if (propagatedType.isMoreSpecificThan(staticType)) { | 6927 if (propagatedType.isMoreSpecificThan(staticType)) { |
6626 recordPropagatedType(node, _typeProvider.listType.substitute5(<Type2> [p
ropagatedType])); | 6928 recordPropagatedType2(node, _typeProvider.listType.substitute5(<Type2> [
propagatedType])); |
6627 } | 6929 } |
6628 } | 6930 } |
6629 return null; | 6931 return null; |
6630 } | 6932 } |
6631 | 6933 |
6632 /** | 6934 /** |
6633 * The Dart Language Specification, 12.7: <blockquote>The static type of a map
literal of the form | 6935 * The Dart Language Specification, 12.7: <blockquote>The static type of a map
literal of the form |
6634 * <i><b>const</b> <String, V> {k<sub>1</sub>:e<sub>1</sub>, …, | 6936 * <i><b>const</b> <String, V> {k<sub>1</sub>:e<sub>1</sub>, …, |
6635 * k<sub>n</sub>:e<sub>n</sub>}</i> or the form <i><String, V> {k<sub>1<
/sub>:e<sub>1</sub>, | 6937 * k<sub>n</sub>:e<sub>n</sub>}</i> or the form <i><String, V> {k<sub>1<
/sub>:e<sub>1</sub>, |
6636 * …, k<sub>n</sub>:e<sub>n</sub>}</i> is `Map<String, V>`. The s
tatic type a | 6938 * …, k<sub>n</sub>:e<sub>n</sub>}</i> is `Map<String, V>`. The s
tatic type a |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6690 } | 6992 } |
6691 bool betterKey = propagatedKeyType != null && propagatedKeyType.isMoreSpec
ificThan(staticKeyType); | 6993 bool betterKey = propagatedKeyType != null && propagatedKeyType.isMoreSpec
ificThan(staticKeyType); |
6692 bool betterValue = propagatedValueType != null && propagatedValueType.isMo
reSpecificThan(staticValueType); | 6994 bool betterValue = propagatedValueType != null && propagatedValueType.isMo
reSpecificThan(staticValueType); |
6693 if (betterKey || betterValue) { | 6995 if (betterKey || betterValue) { |
6694 if (!betterKey) { | 6996 if (!betterKey) { |
6695 propagatedKeyType = staticKeyType; | 6997 propagatedKeyType = staticKeyType; |
6696 } | 6998 } |
6697 if (!betterValue) { | 6999 if (!betterValue) { |
6698 propagatedValueType = staticValueType; | 7000 propagatedValueType = staticValueType; |
6699 } | 7001 } |
6700 recordPropagatedType(node, _typeProvider.mapType.substitute5(<Type2> [pr
opagatedKeyType, propagatedValueType])); | 7002 recordPropagatedType2(node, _typeProvider.mapType.substitute5(<Type2> [p
ropagatedKeyType, propagatedValueType])); |
6701 } | 7003 } |
6702 } | 7004 } |
6703 return null; | 7005 return null; |
6704 } | 7006 } |
6705 | 7007 |
6706 /** | 7008 /** |
6707 * The Dart Language Specification, 12.15.1: <blockquote>An ordinary method in
vocation <i>i</i> | 7009 * The Dart Language Specification, 12.15.1: <blockquote>An ordinary method in
vocation <i>i</i> |
6708 * has the form <i>o.m(a<sub>1</sub>, …, a<sub>n</sub>, x<sub>n+1</sub>
: a<sub>n+1</sub>, | 7010 * has the form <i>o.m(a<sub>1</sub>, …, a<sub>n</sub>, x<sub>n+1</sub>
: a<sub>n+1</sub>, |
6709 * …, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>. | 7011 * …, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>. |
6710 * | 7012 * |
(...skipping 27 matching lines...) Expand all Loading... |
6738 * If <i>S.m</i> does not exist, or if <i>F</i> is not a function type, the st
atic type of | 7040 * If <i>S.m</i> does not exist, or if <i>F</i> is not a function type, the st
atic type of |
6739 * <i>i</i> is dynamic. Otherwise the static type of <i>i</i> is the declared
return type of | 7041 * <i>i</i> is dynamic. Otherwise the static type of <i>i</i> is the declared
return type of |
6740 * <i>F</i>.</blockquote> | 7042 * <i>F</i>.</blockquote> |
6741 */ | 7043 */ |
6742 Object visitMethodInvocation(MethodInvocation node) { | 7044 Object visitMethodInvocation(MethodInvocation node) { |
6743 SimpleIdentifier methodNameNode = node.methodName; | 7045 SimpleIdentifier methodNameNode = node.methodName; |
6744 Element staticMethodElement = methodNameNode.staticElement; | 7046 Element staticMethodElement = methodNameNode.staticElement; |
6745 if (staticMethodElement == null) { | 7047 if (staticMethodElement == null) { |
6746 staticMethodElement = methodNameNode.element; | 7048 staticMethodElement = methodNameNode.element; |
6747 } | 7049 } |
6748 Type2 staticType = computeReturnType(staticMethodElement); | 7050 Type2 staticStaticType = computeStaticReturnType(staticMethodElement); |
6749 recordStaticType(node, staticType); | 7051 recordStaticType(node, staticStaticType); |
| 7052 Type2 staticPropagatedType = computePropagatedReturnType(staticMethodElement
); |
| 7053 if (staticPropagatedType != null && (staticStaticType == null || staticPropa
gatedType.isMoreSpecificThan(staticStaticType))) { |
| 7054 recordPropagatedType2(node, staticPropagatedType); |
| 7055 } |
6750 String methodName = methodNameNode.name; | 7056 String methodName = methodNameNode.name; |
| 7057 if (methodName == "then") { |
| 7058 Expression target = node.realTarget; |
| 7059 Type2 targetType = getBestType(target); |
| 7060 if (isAsyncFutureType(targetType)) { |
| 7061 NodeList<Expression> arguments = node.argumentList.arguments; |
| 7062 if (arguments.length == 1) { |
| 7063 Expression closureArg = arguments[0]; |
| 7064 if (closureArg is FunctionExpression) { |
| 7065 FunctionExpression closureExpr = closureArg as FunctionExpression; |
| 7066 Type2 returnType = computePropagatedReturnType(closureExpr.element); |
| 7067 if (returnType != null) { |
| 7068 InterfaceTypeImpl newFutureType; |
| 7069 if (isAsyncFutureType(returnType)) { |
| 7070 newFutureType = returnType as InterfaceTypeImpl; |
| 7071 } else { |
| 7072 InterfaceType futureType = targetType as InterfaceType; |
| 7073 newFutureType = new InterfaceTypeImpl.con1(futureType.element); |
| 7074 newFutureType.typeArguments = <Type2> [returnType]; |
| 7075 } |
| 7076 recordPropagatedType2(node, newFutureType); |
| 7077 return null; |
| 7078 } |
| 7079 } |
| 7080 } |
| 7081 } |
| 7082 } |
6751 if (methodName == "\$dom_createEvent") { | 7083 if (methodName == "\$dom_createEvent") { |
6752 Expression target = node.realTarget; | 7084 Expression target = node.realTarget; |
6753 if (target != null) { | 7085 if (target != null) { |
6754 Type2 targetType = getBestType(target); | 7086 Type2 targetType = getBestType(target); |
6755 if (targetType is InterfaceType && (targetType.name == "HtmlDocument" ||
targetType.name == "Document")) { | 7087 if (targetType is InterfaceType && (targetType.name == "HtmlDocument" ||
targetType.name == "Document")) { |
6756 LibraryElement library = targetType.element.library; | 7088 LibraryElement library = targetType.element.library; |
6757 if (isHtmlLibrary(library)) { | 7089 if (isHtmlLibrary(library)) { |
6758 Type2 returnType = getFirstArgumentAsType(library, node.argumentList
); | 7090 Type2 returnType = getFirstArgumentAsType(library, node.argumentList
); |
6759 if (returnType != null) { | 7091 if (returnType != null) { |
6760 recordPropagatedType(node, returnType); | 7092 recordPropagatedType2(node, returnType); |
6761 } | 7093 } |
6762 } | 7094 } |
6763 } | 7095 } |
6764 } | 7096 } |
6765 } else if (methodName == "query") { | 7097 } else if (methodName == "query") { |
6766 Expression target = node.realTarget; | 7098 Expression target = node.realTarget; |
6767 if (target == null) { | 7099 if (target == null) { |
6768 Element methodElement = methodNameNode.element; | 7100 Element methodElement = methodNameNode.element; |
6769 if (methodElement != null) { | 7101 if (methodElement != null) { |
6770 LibraryElement library = methodElement.library; | 7102 LibraryElement library = methodElement.library; |
6771 if (isHtmlLibrary(library)) { | 7103 if (isHtmlLibrary(library)) { |
6772 Type2 returnType = getFirstArgumentAsQuery(library, node.argumentLis
t); | 7104 Type2 returnType = getFirstArgumentAsQuery(library, node.argumentLis
t); |
6773 if (returnType != null) { | 7105 if (returnType != null) { |
6774 recordPropagatedType(node, returnType); | 7106 recordPropagatedType2(node, returnType); |
6775 } | 7107 } |
6776 } | 7108 } |
6777 } | 7109 } |
6778 } else { | 7110 } else { |
6779 Type2 targetType = getBestType(target); | 7111 Type2 targetType = getBestType(target); |
6780 if (targetType is InterfaceType && (targetType.name == "HtmlDocument" ||
targetType.name == "Document")) { | 7112 if (targetType is InterfaceType && (targetType.name == "HtmlDocument" ||
targetType.name == "Document")) { |
6781 LibraryElement library = targetType.element.library; | 7113 LibraryElement library = targetType.element.library; |
6782 if (isHtmlLibrary(library)) { | 7114 if (isHtmlLibrary(library)) { |
6783 Type2 returnType = getFirstArgumentAsQuery(library, node.argumentLis
t); | 7115 Type2 returnType = getFirstArgumentAsQuery(library, node.argumentLis
t); |
6784 if (returnType != null) { | 7116 if (returnType != null) { |
6785 recordPropagatedType(node, returnType); | 7117 recordPropagatedType2(node, returnType); |
6786 } | 7118 } |
6787 } | 7119 } |
6788 } | 7120 } |
6789 } | 7121 } |
6790 } else if (methodName == "\$dom_createElement") { | 7122 } else if (methodName == "\$dom_createElement") { |
6791 Expression target = node.realTarget; | 7123 Expression target = node.realTarget; |
6792 Type2 targetType = getBestType(target); | 7124 Type2 targetType = getBestType(target); |
6793 if (targetType is InterfaceType && (targetType.name == "HtmlDocument" || t
argetType.name == "Document")) { | 7125 if (targetType is InterfaceType && (targetType.name == "HtmlDocument" || t
argetType.name == "Document")) { |
6794 LibraryElement library = targetType.element.library; | 7126 LibraryElement library = targetType.element.library; |
6795 if (isHtmlLibrary(library)) { | 7127 if (isHtmlLibrary(library)) { |
6796 Type2 returnType = getFirstArgumentAsQuery(library, node.argumentList)
; | 7128 Type2 returnType = getFirstArgumentAsQuery(library, node.argumentList)
; |
6797 if (returnType != null) { | 7129 if (returnType != null) { |
6798 recordPropagatedType(node, returnType); | 7130 recordPropagatedType2(node, returnType); |
6799 } | 7131 } |
6800 } | 7132 } |
6801 } | 7133 } |
6802 } else if (methodName == "JS") { | 7134 } else if (methodName == "JS") { |
6803 Type2 returnType = getFirstArgumentAsType(_typeProvider.objectType.element
.library, node.argumentList); | 7135 Type2 returnType = getFirstArgumentAsType(_typeProvider.objectType.element
.library, node.argumentList); |
6804 if (returnType != null) { | 7136 if (returnType != null) { |
6805 recordPropagatedType(node, returnType); | 7137 recordPropagatedType2(node, returnType); |
6806 } | 7138 } |
6807 } else { | 7139 } else { |
6808 Element propagatedElement = methodNameNode.element; | 7140 Element propagatedElement = methodNameNode.element; |
6809 if (propagatedElement != staticMethodElement) { | 7141 if (propagatedElement != staticMethodElement) { |
6810 Type2 propagatedType = computeReturnType(propagatedElement); | 7142 Type2 propagatedStaticType = computeStaticReturnType(propagatedElement); |
6811 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy
pe)) { | 7143 if (propagatedStaticType != null && (staticStaticType == null || propaga
tedStaticType.isMoreSpecificThan(staticStaticType)) && (staticPropagatedType ==
null || propagatedStaticType.isMoreSpecificThan(staticPropagatedType))) { |
6812 recordPropagatedType(node, propagatedType); | 7144 recordPropagatedType2(node, propagatedStaticType); |
| 7145 } |
| 7146 Type2 propagatedPropagatedType = computePropagatedReturnType(propagatedE
lement); |
| 7147 if (propagatedPropagatedType != null && (staticStaticType == null || pro
pagatedPropagatedType.isMoreSpecificThan(staticStaticType)) && (staticPropagated
Type == null || propagatedPropagatedType.isMoreSpecificThan(staticPropagatedType
)) && (propagatedStaticType == null || propagatedPropagatedType.isMoreSpecificTh
an(propagatedStaticType))) { |
| 7148 recordPropagatedType2(node, propagatedPropagatedType); |
6813 } | 7149 } |
6814 } | 7150 } |
6815 } | 7151 } |
6816 return null; | 7152 return null; |
6817 } | 7153 } |
6818 Object visitNamedExpression(NamedExpression node) { | 7154 Object visitNamedExpression(NamedExpression node) { |
6819 Expression expression = node.expression; | 7155 Expression expression = node.expression; |
6820 recordStaticType(node, getStaticType(expression)); | 7156 recordStaticType(node, getStaticType(expression)); |
6821 recordPropagatedType(node, getPropagatedType(expression)); | 7157 recordPropagatedType2(node, getPropagatedType(expression)); |
6822 return null; | 7158 return null; |
6823 } | 7159 } |
6824 | 7160 |
6825 /** | 7161 /** |
6826 * The Dart Language Specification, 12.2: <blockquote>The static type of `null
` is bottom. | 7162 * The Dart Language Specification, 12.2: <blockquote>The static type of `null
` is bottom. |
6827 * </blockquote> | 7163 * </blockquote> |
6828 */ | 7164 */ |
6829 Object visitNullLiteral(NullLiteral node) { | 7165 Object visitNullLiteral(NullLiteral node) { |
6830 recordStaticType(node, _typeProvider.bottomType); | 7166 recordStaticType(node, _typeProvider.bottomType); |
6831 return null; | 7167 return null; |
6832 } | 7168 } |
6833 Object visitParenthesizedExpression(ParenthesizedExpression node) { | 7169 Object visitParenthesizedExpression(ParenthesizedExpression node) { |
6834 Expression expression = node.expression; | 7170 Expression expression = node.expression; |
6835 recordStaticType(node, getStaticType(expression)); | 7171 recordStaticType(node, getStaticType(expression)); |
6836 recordPropagatedType(node, getPropagatedType(expression)); | 7172 recordPropagatedType2(node, getPropagatedType(expression)); |
6837 return null; | 7173 return null; |
6838 } | 7174 } |
6839 | 7175 |
6840 /** | 7176 /** |
6841 * The Dart Language Specification, 12.28: <blockquote>A postfix expression of
the form | 7177 * The Dart Language Specification, 12.28: <blockquote>A postfix expression of
the form |
6842 * <i>v++</i>, where <i>v</i> is an identifier, is equivalent to <i>(){var r =
v; v = r + 1; | 7178 * <i>v++</i>, where <i>v</i> is an identifier, is equivalent to <i>(){var r =
v; v = r + 1; |
6843 * return r}()</i>. | 7179 * return r}()</i>. |
6844 * | 7180 * |
6845 * A postfix expression of the form <i>C.v++</i> is equivalent to <i>(){var r
= C.v; C.v = r + 1; | 7181 * A postfix expression of the form <i>C.v++</i> is equivalent to <i>(){var r
= C.v; C.v = r + 1; |
6846 * return r}()</i>. | 7182 * return r}()</i>. |
6847 * | 7183 * |
6848 * A postfix expression of the form <i>e1.v++</i> is equivalent to <i>(x){var
r = x.v; x.v = r + | 7184 * A postfix expression of the form <i>e1.v++</i> is equivalent to <i>(x){var
r = x.v; x.v = r + |
6849 * 1; return r}(e1)</i>. | 7185 * 1; return r}(e1)</i>. |
6850 * | 7186 * |
6851 * A postfix expression of the form <i>e1\[e2\]++</i> is equivalent to <i>(a,
i){var r = a\[i\]; a\[i\] | 7187 * A postfix expression of the form <i>e1[e2]++</i> is equivalent to <i>(a, i)
{var r = a[i]; a[i] |
6852 * = r + 1; return r}(e1, e2)</i> | 7188 * = r + 1; return r}(e1, e2)</i> |
6853 * | 7189 * |
6854 * A postfix expression of the form <i>v--</i>, where <i>v</i> is an identifie
r, is equivalent to | 7190 * A postfix expression of the form <i>v--</i>, where <i>v</i> is an identifie
r, is equivalent to |
6855 * <i>(){var r = v; v = r - 1; return r}()</i>. | 7191 * <i>(){var r = v; v = r - 1; return r}()</i>. |
6856 * | 7192 * |
6857 * A postfix expression of the form <i>C.v--</i> is equivalent to <i>(){var r
= C.v; C.v = r - 1; | 7193 * A postfix expression of the form <i>C.v--</i> is equivalent to <i>(){var r
= C.v; C.v = r - 1; |
6858 * return r}()</i>. | 7194 * return r}()</i>. |
6859 * | 7195 * |
6860 * A postfix expression of the form <i>e1.v--</i> is equivalent to <i>(x){var
r = x.v; x.v = r - | 7196 * A postfix expression of the form <i>e1.v--</i> is equivalent to <i>(x){var
r = x.v; x.v = r - |
6861 * 1; return r}(e1)</i>. | 7197 * 1; return r}(e1)</i>. |
6862 * | 7198 * |
6863 * A postfix expression of the form <i>e1\[e2\]--</i> is equivalent to <i>(a,
i){var r = a\[i\]; a\[i\] | 7199 * A postfix expression of the form <i>e1[e2]--</i> is equivalent to <i>(a, i)
{var r = a[i]; a[i] |
6864 * = r - 1; return r}(e1, e2)</i></blockquote> | 7200 * = r - 1; return r}(e1, e2)</i></blockquote> |
6865 */ | 7201 */ |
6866 Object visitPostfixExpression(PostfixExpression node) { | 7202 Object visitPostfixExpression(PostfixExpression node) { |
6867 Expression operand = node.operand; | 7203 Expression operand = node.operand; |
6868 Type2 staticType = getStaticType(operand); | 7204 Type2 staticType = getStaticType(operand); |
6869 sc.TokenType operator = node.operator.type; | 7205 sc.TokenType operator = node.operator.type; |
6870 if (identical(operator, sc.TokenType.MINUS_MINUS) || identical(operator, sc.
TokenType.PLUS_PLUS)) { | 7206 if (identical(operator, sc.TokenType.MINUS_MINUS) || identical(operator, sc.
TokenType.PLUS_PLUS)) { |
6871 Type2 intType = _typeProvider.intType; | 7207 Type2 intType = _typeProvider.intType; |
6872 if (identical(getStaticType(node.operand), intType)) { | 7208 if (identical(getStaticType(node.operand), intType)) { |
6873 staticType = intType; | 7209 staticType = intType; |
6874 } | 7210 } |
6875 } | 7211 } |
6876 recordStaticType(node, staticType); | 7212 recordStaticType(node, staticType); |
6877 recordPropagatedType(node, getPropagatedType(operand)); | 7213 recordPropagatedType2(node, getPropagatedType(operand)); |
6878 return null; | 7214 return null; |
6879 } | 7215 } |
6880 | 7216 |
6881 /** | 7217 /** |
6882 * See [visitSimpleIdentifier]. | 7218 * See [visitSimpleIdentifier]. |
6883 */ | 7219 */ |
6884 Object visitPrefixedIdentifier(PrefixedIdentifier node) { | 7220 Object visitPrefixedIdentifier(PrefixedIdentifier node) { |
6885 SimpleIdentifier prefixedIdentifier = node.identifier; | 7221 SimpleIdentifier prefixedIdentifier = node.identifier; |
6886 Element element = prefixedIdentifier.element; | 7222 Element element = prefixedIdentifier.element; |
6887 Type2 staticType = _dynamicType; | 7223 Type2 staticType = _dynamicType; |
(...skipping 13 matching lines...) Expand all Loading... |
6901 staticType = ((element as ExecutableElement)).type; | 7237 staticType = ((element as ExecutableElement)).type; |
6902 } else if (element is TypeVariableElement) { | 7238 } else if (element is TypeVariableElement) { |
6903 staticType = ((element as TypeVariableElement)).type; | 7239 staticType = ((element as TypeVariableElement)).type; |
6904 } else if (element is VariableElement) { | 7240 } else if (element is VariableElement) { |
6905 staticType = ((element as VariableElement)).type; | 7241 staticType = ((element as VariableElement)).type; |
6906 } | 7242 } |
6907 recordStaticType(prefixedIdentifier, staticType); | 7243 recordStaticType(prefixedIdentifier, staticType); |
6908 recordStaticType(node, staticType); | 7244 recordStaticType(node, staticType); |
6909 Type2 propagatedType = _overrideManager.getType(element); | 7245 Type2 propagatedType = _overrideManager.getType(element); |
6910 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType))
{ | 7246 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType))
{ |
6911 recordPropagatedType(prefixedIdentifier, propagatedType); | 7247 recordPropagatedType2(prefixedIdentifier, propagatedType); |
6912 recordPropagatedType(node, propagatedType); | 7248 recordPropagatedType2(node, propagatedType); |
6913 } | 7249 } |
6914 return null; | 7250 return null; |
6915 } | 7251 } |
6916 | 7252 |
6917 /** | 7253 /** |
6918 * The Dart Language Specification, 12.27: <blockquote>A unary expression <i>u
</i> of the form | 7254 * The Dart Language Specification, 12.27: <blockquote>A unary expression <i>u
</i> of the form |
6919 * <i>op e</i> is equivalent to a method invocation <i>expression e.op()</i>.
An expression of the | 7255 * <i>op e</i> is equivalent to a method invocation <i>expression e.op()</i>.
An expression of the |
6920 * form <i>op super</i> is equivalent to the method invocation <i>super.op()<i
>.</blockquote> | 7256 * form <i>op super</i> is equivalent to the method invocation <i>super.op()<i
>.</blockquote> |
6921 */ | 7257 */ |
6922 Object visitPrefixExpression(PrefixExpression node) { | 7258 Object visitPrefixExpression(PrefixExpression node) { |
6923 sc.TokenType operator = node.operator.type; | 7259 sc.TokenType operator = node.operator.type; |
6924 if (identical(operator, sc.TokenType.BANG)) { | 7260 if (identical(operator, sc.TokenType.BANG)) { |
6925 recordStaticType(node, _typeProvider.boolType); | 7261 recordStaticType(node, _typeProvider.boolType); |
6926 } else { | 7262 } else { |
6927 ExecutableElement staticMethodElement = node.staticElement; | 7263 ExecutableElement staticMethodElement = node.staticElement; |
6928 Type2 staticType = computeReturnType(staticMethodElement); | 7264 Type2 staticType = computeStaticReturnType(staticMethodElement); |
6929 if (identical(operator, sc.TokenType.MINUS_MINUS) || identical(operator, s
c.TokenType.PLUS_PLUS)) { | 7265 if (identical(operator, sc.TokenType.MINUS_MINUS) || identical(operator, s
c.TokenType.PLUS_PLUS)) { |
6930 Type2 intType = _typeProvider.intType; | 7266 Type2 intType = _typeProvider.intType; |
6931 if (identical(getStaticType(node.operand), intType)) { | 7267 if (identical(getStaticType(node.operand), intType)) { |
6932 staticType = intType; | 7268 staticType = intType; |
6933 } | 7269 } |
6934 } | 7270 } |
6935 recordStaticType(node, staticType); | 7271 recordStaticType(node, staticType); |
6936 MethodElement propagatedMethodElement = node.element; | 7272 MethodElement propagatedMethodElement = node.element; |
6937 if (propagatedMethodElement != staticMethodElement) { | 7273 if (propagatedMethodElement != staticMethodElement) { |
6938 Type2 propagatedType = computeReturnType(propagatedMethodElement); | 7274 Type2 propagatedType = computeStaticReturnType(propagatedMethodElement); |
6939 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy
pe)) { | 7275 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy
pe)) { |
6940 recordPropagatedType(node, propagatedType); | 7276 recordPropagatedType2(node, propagatedType); |
6941 } | 7277 } |
6942 } | 7278 } |
6943 } | 7279 } |
6944 return null; | 7280 return null; |
6945 } | 7281 } |
6946 | 7282 |
6947 /** | 7283 /** |
6948 * The Dart Language Specification, 12.13: <blockquote> Property extraction al
lows for a member of | 7284 * The Dart Language Specification, 12.13: <blockquote> Property extraction al
lows for a member of |
6949 * an object to be concisely extracted from the object. If <i>o</i> is an obje
ct, and if <i>m</i> | 7285 * an object to be concisely extracted from the object. If <i>o</i> is an obje
ct, and if <i>m</i> |
6950 * is the name of a method member of <i>o</i>, then | 7286 * is the name of a method member of <i>o</i>, then |
6951 * | 7287 * |
6952 * * <i>o.m</i> is defined to be equivalent to: <i>(r<sub>1</sub>, …, r
<sub>n</sub>, | 7288 * * <i>o.m</i> is defined to be equivalent to: <i>(r<sub>1</sub>, …, r
<sub>n</sub>, |
6953 * {p<sub>1</sub> : d<sub>1</sub>, …, p<sub>k</sub> : d<sub>k</sub>}){r
eturn | 7289 * {p<sub>1</sub> : d<sub>1</sub>, …, p<sub>k</sub> : d<sub>k</sub>}){r
eturn |
6954 * o.m(r<sub>1</sub>, …, r<sub>n</sub>, p<sub>1</sub>: p<sub>1</sub>, &
hellip;, | 7290 * o.m(r<sub>1</sub>, …, r<sub>n</sub>, p<sub>1</sub>: p<sub>1</sub>, &
hellip;, |
6955 * p<sub>k</sub>: p<sub>k</sub>);}</i> if <i>m</i> has required parameters <i>
r<sub>1</sub>, | 7291 * p<sub>k</sub>: p<sub>k</sub>);}</i> if <i>m</i> has required parameters <i>
r<sub>1</sub>, |
6956 * …, r<sub>n</sub></i>, and named parameters <i>p<sub>1</sub> …
p<sub>k</sub></i> | 7292 * …, r<sub>n</sub></i>, and named parameters <i>p<sub>1</sub> …
p<sub>k</sub></i> |
6957 * with defaults <i>d<sub>1</sub>, …, d<sub>k</sub></i>. | 7293 * with defaults <i>d<sub>1</sub>, …, d<sub>k</sub></i>. |
6958 * * <i>(r<sub>1</sub>, …, r<sub>n</sub>, \[p<sub>1</sub> = d<sub>1</su
b>, …, | 7294 * * <i>(r<sub>1</sub>, …, r<sub>n</sub>, [p<sub>1</sub> = d<sub>1</sub
>, …, |
6959 * p<sub>k</sub> = d<sub>k</sub>\]){return o.m(r<sub>1</sub>, …, r<sub>
n</sub>, | 7295 * p<sub>k</sub> = d<sub>k</sub>]){return o.m(r<sub>1</sub>, …, r<sub>n
</sub>, |
6960 * p<sub>1</sub>, …, p<sub>k</sub>);}</i> if <i>m</i> has required para
meters | 7296 * p<sub>1</sub>, …, p<sub>k</sub>);}</i> if <i>m</i> has required para
meters |
6961 * <i>r<sub>1</sub>, …, r<sub>n</sub></i>, and optional positional para
meters | 7297 * <i>r<sub>1</sub>, …, r<sub>n</sub></i>, and optional positional para
meters |
6962 * <i>p<sub>1</sub> … p<sub>k</sub></i> with defaults <i>d<sub>1</sub>,
…, | 7298 * <i>p<sub>1</sub> … p<sub>k</sub></i> with defaults <i>d<sub>1</sub>,
…, |
6963 * d<sub>k</sub></i>. | 7299 * d<sub>k</sub></i>. |
6964 * | 7300 * |
6965 * Otherwise, if <i>m</i> is the name of a getter member of <i>o</i> (declared
implicitly or | 7301 * Otherwise, if <i>m</i> is the name of a getter member of <i>o</i> (declared
implicitly or |
6966 * explicitly) then <i>o.m</i> evaluates to the result of invoking the getter.
</blockquote> | 7302 * explicitly) then <i>o.m</i> evaluates to the result of invoking the getter.
</blockquote> |
6967 * | 7303 * |
6968 * The Dart Language Specification, 12.17: <blockquote> ... a getter invocatio
n <i>i</i> of the | 7304 * The Dart Language Specification, 12.17: <blockquote> ... a getter invocatio
n <i>i</i> of the |
6969 * form <i>e.m</i> ... | 7305 * form <i>e.m</i> ... |
(...skipping 24 matching lines...) Expand all Loading... |
6994 if (element is MethodElement) { | 7330 if (element is MethodElement) { |
6995 staticType = ((element as MethodElement)).type; | 7331 staticType = ((element as MethodElement)).type; |
6996 } else if (element is PropertyAccessorElement) { | 7332 } else if (element is PropertyAccessorElement) { |
6997 staticType = getType((element as PropertyAccessorElement), node.target !=
null ? getStaticType(node.target) : null); | 7333 staticType = getType((element as PropertyAccessorElement), node.target !=
null ? getStaticType(node.target) : null); |
6998 } else { | 7334 } else { |
6999 } | 7335 } |
7000 recordStaticType(propertyName, staticType); | 7336 recordStaticType(propertyName, staticType); |
7001 recordStaticType(node, staticType); | 7337 recordStaticType(node, staticType); |
7002 Type2 propagatedType = _overrideManager.getType(element); | 7338 Type2 propagatedType = _overrideManager.getType(element); |
7003 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType))
{ | 7339 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType))
{ |
7004 recordPropagatedType(node, propagatedType); | 7340 recordPropagatedType2(node, propagatedType); |
7005 } | 7341 } |
7006 return null; | 7342 return null; |
7007 } | 7343 } |
7008 | 7344 |
7009 /** | 7345 /** |
7010 * The Dart Language Specification, 12.9: <blockquote>The static type of a ret
hrow expression is | 7346 * The Dart Language Specification, 12.9: <blockquote>The static type of a ret
hrow expression is |
7011 * bottom.</blockquote> | 7347 * bottom.</blockquote> |
7012 */ | 7348 */ |
7013 Object visitRethrowExpression(RethrowExpression node) { | 7349 Object visitRethrowExpression(RethrowExpression node) { |
7014 recordStaticType(node, _typeProvider.bottomType); | 7350 recordStaticType(node, _typeProvider.bottomType); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7079 } else if (element is VariableElement) { | 7415 } else if (element is VariableElement) { |
7080 staticType = ((element as VariableElement)).type; | 7416 staticType = ((element as VariableElement)).type; |
7081 } else if (element is PrefixElement) { | 7417 } else if (element is PrefixElement) { |
7082 return null; | 7418 return null; |
7083 } else { | 7419 } else { |
7084 staticType = _dynamicType; | 7420 staticType = _dynamicType; |
7085 } | 7421 } |
7086 recordStaticType(node, staticType); | 7422 recordStaticType(node, staticType); |
7087 Type2 propagatedType = _overrideManager.getType(element); | 7423 Type2 propagatedType = _overrideManager.getType(element); |
7088 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType))
{ | 7424 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType))
{ |
7089 recordPropagatedType(node, propagatedType); | 7425 recordPropagatedType2(node, propagatedType); |
7090 } | 7426 } |
7091 return null; | 7427 return null; |
7092 } | 7428 } |
7093 | 7429 |
7094 /** | 7430 /** |
7095 * The Dart Language Specification, 12.5: <blockquote>The static type of a str
ing literal is`String`.</blockquote> | 7431 * The Dart Language Specification, 12.5: <blockquote>The static type of a str
ing literal is |
| 7432 * `String`.</blockquote> |
7096 */ | 7433 */ |
7097 Object visitSimpleStringLiteral(SimpleStringLiteral node) { | 7434 Object visitSimpleStringLiteral(SimpleStringLiteral node) { |
7098 recordStaticType(node, _typeProvider.stringType); | 7435 recordStaticType(node, _typeProvider.stringType); |
7099 return null; | 7436 return null; |
7100 } | 7437 } |
7101 | 7438 |
7102 /** | 7439 /** |
7103 * The Dart Language Specification, 12.5: <blockquote>The static type of a str
ing literal is`String`.</blockquote> | 7440 * The Dart Language Specification, 12.5: <blockquote>The static type of a str
ing literal is |
| 7441 * `String`.</blockquote> |
7104 */ | 7442 */ |
7105 Object visitStringInterpolation(StringInterpolation node) { | 7443 Object visitStringInterpolation(StringInterpolation node) { |
7106 recordStaticType(node, _typeProvider.stringType); | 7444 recordStaticType(node, _typeProvider.stringType); |
7107 return null; | 7445 return null; |
7108 } | 7446 } |
7109 Object visitSuperExpression(SuperExpression node) { | 7447 Object visitSuperExpression(SuperExpression node) { |
7110 if (_thisType == null) { | 7448 if (_thisType == null) { |
7111 recordStaticType(node, _dynamicType); | 7449 recordStaticType(node, _dynamicType); |
7112 } else { | 7450 } else { |
7113 recordStaticType(node, _thisType); | 7451 recordStaticType(node, _thisType); |
(...skipping 19 matching lines...) Expand all Loading... |
7133 * bottom.</blockquote> | 7471 * bottom.</blockquote> |
7134 */ | 7472 */ |
7135 Object visitThrowExpression(ThrowExpression node) { | 7473 Object visitThrowExpression(ThrowExpression node) { |
7136 recordStaticType(node, _typeProvider.bottomType); | 7474 recordStaticType(node, _typeProvider.bottomType); |
7137 return null; | 7475 return null; |
7138 } | 7476 } |
7139 Object visitVariableDeclaration(VariableDeclaration node) { | 7477 Object visitVariableDeclaration(VariableDeclaration node) { |
7140 Expression initializer = node.initializer; | 7478 Expression initializer = node.initializer; |
7141 if (initializer != null) { | 7479 if (initializer != null) { |
7142 Type2 rightType = getBestType(initializer); | 7480 Type2 rightType = getBestType(initializer); |
7143 VariableElement element = node.name.element as VariableElement; | 7481 SimpleIdentifier name = node.name; |
| 7482 recordPropagatedType2(name, rightType); |
| 7483 VariableElement element = name.element as VariableElement; |
7144 if (element != null) { | 7484 if (element != null) { |
7145 _resolver.override(element, rightType); | 7485 _resolver.override(element, rightType); |
7146 } | 7486 } |
7147 } | 7487 } |
7148 return null; | 7488 return null; |
7149 } | 7489 } |
7150 | 7490 |
7151 /** | 7491 /** |
7152 * Record that the static type of the given node is the type of the second arg
ument to the method | 7492 * Record that the static type of the given node is the type of the second arg
ument to the method |
7153 * represented by the given element. | 7493 * represented by the given element. |
| 7494 * |
7154 * @param element the element representing the method invoked by the given nod
e | 7495 * @param element the element representing the method invoked by the given nod
e |
7155 */ | 7496 */ |
7156 Type2 computeArgumentType(ExecutableElement element) { | 7497 Type2 computeArgumentType(ExecutableElement element) { |
7157 if (element != null) { | 7498 if (element != null) { |
7158 List<ParameterElement> parameters = element.parameters; | 7499 List<ParameterElement> parameters = element.parameters; |
7159 if (parameters != null && parameters.length == 2) { | 7500 if (parameters != null && parameters.length == 2) { |
7160 return parameters[1].type; | 7501 return parameters[1].type; |
7161 } | 7502 } |
7162 } | 7503 } |
7163 return _dynamicType; | 7504 return _dynamicType; |
7164 } | 7505 } |
7165 | 7506 |
7166 /** | 7507 /** |
7167 * Compute the return type of the method or function represented by the given
element. | 7508 * Compute the propagated return type of the method or function represented by
the given element. |
| 7509 * |
7168 * @param element the element representing the method or function invoked by t
he given node | 7510 * @param element the element representing the method or function invoked by t
he given node |
7169 * @return the return type that was computed | 7511 * @return the propagated return type that was computed |
7170 */ | 7512 */ |
7171 Type2 computeReturnType(Element element) { | 7513 Type2 computePropagatedReturnType(Element element) { |
| 7514 if (element is ExecutableElement) { |
| 7515 return _propagatedReturnTypes[element]; |
| 7516 } |
| 7517 return null; |
| 7518 } |
| 7519 |
| 7520 /** |
| 7521 * Given a function body, compute the propagated return type of the function.
The propagated |
| 7522 * return type of functions with a block body is the least upper bound of all |
| 7523 * [ReturnStatement] expressions, with an expression body it is the type of th
e expression. |
| 7524 * |
| 7525 * @param body the boy of the function whose propagated return type is to be c
omputed |
| 7526 * @return the propagated return type that was computed |
| 7527 */ |
| 7528 Type2 computePropagatedReturnType2(FunctionBody body) { |
| 7529 if (body is ExpressionFunctionBody) { |
| 7530 ExpressionFunctionBody expressionBody = body as ExpressionFunctionBody; |
| 7531 return getBestType(expressionBody.expression); |
| 7532 } |
| 7533 if (body is BlockFunctionBody) { |
| 7534 List<Type2> result = [null]; |
| 7535 body.accept(new GeneralizingASTVisitor_8(this, result)); |
| 7536 return result[0]; |
| 7537 } |
| 7538 return null; |
| 7539 } |
| 7540 |
| 7541 /** |
| 7542 * Compute the static return type of the method or function represented by the
given element. |
| 7543 * |
| 7544 * @param element the element representing the method or function invoked by t
he given node |
| 7545 * @return the static return type that was computed |
| 7546 */ |
| 7547 Type2 computeStaticReturnType(Element element) { |
7172 if (element is PropertyAccessorElement) { | 7548 if (element is PropertyAccessorElement) { |
7173 FunctionType propertyType = ((element as PropertyAccessorElement)).type; | 7549 FunctionType propertyType = ((element as PropertyAccessorElement)).type; |
7174 if (propertyType != null) { | 7550 if (propertyType != null) { |
7175 Type2 returnType = propertyType.returnType; | 7551 Type2 returnType = propertyType.returnType; |
7176 if (returnType is InterfaceType) { | 7552 if (returnType is InterfaceType) { |
7177 if (identical(returnType, _typeProvider.functionType)) { | 7553 if (identical(returnType, _typeProvider.functionType)) { |
7178 return _dynamicType; | 7554 return _dynamicType; |
7179 } | 7555 } |
7180 MethodElement callMethod = ((returnType as InterfaceType)).lookUpMetho
d(ElementResolver.CALL_METHOD_NAME, _resolver.definingLibrary); | 7556 MethodElement callMethod = ((returnType as InterfaceType)).lookUpMetho
d(ElementResolver.CALL_METHOD_NAME, _resolver.definingLibrary); |
7181 if (callMethod != null) { | 7557 if (callMethod != null) { |
(...skipping 19 matching lines...) Expand all Loading... |
7201 } else if (element is VariableElement) { | 7577 } else if (element is VariableElement) { |
7202 Type2 variableType = ((element as VariableElement)).type; | 7578 Type2 variableType = ((element as VariableElement)).type; |
7203 if (variableType is FunctionType) { | 7579 if (variableType is FunctionType) { |
7204 return ((variableType as FunctionType)).returnType; | 7580 return ((variableType as FunctionType)).returnType; |
7205 } | 7581 } |
7206 } | 7582 } |
7207 return _dynamicType; | 7583 return _dynamicType; |
7208 } | 7584 } |
7209 | 7585 |
7210 /** | 7586 /** |
7211 * Given a function declaration, compute the return type of the function. The
return type of | 7587 * Given a function declaration, compute the return static type of the functio
n. The return type |
7212 * functions with a block body is `dynamicType`, with an expression body it is
the type of | 7588 * of functions with a block body is `dynamicType`, with an expression body it
is the type |
7213 * the expression. | 7589 * of the expression. |
7214 * @param node the function expression whose return type is to be computed | 7590 * |
7215 * @return the return type that was computed | 7591 * @param node the function expression whose static return type is to be compu
ted |
| 7592 * @return the static return type that was computed |
7216 */ | 7593 */ |
7217 Type2 computeReturnType2(FunctionDeclaration node) { | 7594 Type2 computeStaticReturnType2(FunctionDeclaration node) { |
7218 TypeName returnType = node.returnType; | 7595 TypeName returnType = node.returnType; |
7219 if (returnType == null) { | 7596 if (returnType == null) { |
7220 return _dynamicType; | 7597 return _dynamicType; |
7221 } | 7598 } |
7222 return returnType.type; | 7599 return returnType.type; |
7223 } | 7600 } |
7224 | 7601 |
7225 /** | 7602 /** |
7226 * Given a function expression, compute the return type of the function. The r
eturn type of | 7603 * Given a function expression, compute the return type of the function. The r
eturn type of |
7227 * functions with a block body is `dynamicType`, with an expression body it is
the type of | 7604 * functions with a block body is `dynamicType`, with an expression body it is
the type of |
7228 * the expression. | 7605 * the expression. |
| 7606 * |
7229 * @param node the function expression whose return type is to be computed | 7607 * @param node the function expression whose return type is to be computed |
7230 * @return the return type that was computed | 7608 * @return the return type that was computed |
7231 */ | 7609 */ |
7232 Type2 computeReturnType3(FunctionExpression node) { | 7610 Type2 computeStaticReturnType3(FunctionExpression node) { |
7233 FunctionBody body = node.body; | 7611 FunctionBody body = node.body; |
7234 if (body is ExpressionFunctionBody) { | 7612 if (body is ExpressionFunctionBody) { |
7235 return getStaticType(((body as ExpressionFunctionBody)).expression); | 7613 return getStaticType(((body as ExpressionFunctionBody)).expression); |
7236 } | 7614 } |
7237 return _dynamicType; | 7615 return _dynamicType; |
7238 } | 7616 } |
7239 | 7617 |
7240 /** | 7618 /** |
7241 * Return the propagated type of the given expression if it is available, or t
he static type if | 7619 * Return the propagated type of the given expression if it is available, or t
he static type if |
7242 * there is no propagated type. | 7620 * there is no propagated type. |
| 7621 * |
7243 * @param expression the expression whose type is to be returned | 7622 * @param expression the expression whose type is to be returned |
7244 * @return the propagated or static type of the given expression | 7623 * @return the propagated or static type of the given expression |
7245 */ | 7624 */ |
7246 Type2 getBestType(Expression expression) { | 7625 Type2 getBestType(Expression expression) { |
7247 Type2 type = expression.propagatedType; | 7626 Type2 type = expression.propagatedType; |
7248 if (type == null) { | 7627 if (type == null) { |
7249 type = expression.staticType; | 7628 type = expression.staticType; |
7250 if (type == null) { | 7629 if (type == null) { |
7251 return _dynamicType; | 7630 return _dynamicType; |
7252 } | 7631 } |
7253 } | 7632 } |
7254 return type; | 7633 return type; |
7255 } | 7634 } |
7256 | 7635 |
7257 /** | 7636 /** |
7258 * If the given argument list contains at least one argument, and if the argum
ent is a simple | 7637 * If the given argument list contains at least one argument, and if the argum
ent is a simple |
7259 * string literal, then parse that argument as a query string and return the t
ype specified by the | 7638 * string literal, then parse that argument as a query string and return the t
ype specified by the |
7260 * argument. | 7639 * argument. |
| 7640 * |
7261 * @param library the library in which the specified type would be defined | 7641 * @param library the library in which the specified type would be defined |
7262 * @param argumentList the list of arguments from which a type is to be extrac
ted | 7642 * @param argumentList the list of arguments from which a type is to be extrac
ted |
7263 * @return the type specified by the first argument in the argument list | 7643 * @return the type specified by the first argument in the argument list |
7264 */ | 7644 */ |
7265 Type2 getFirstArgumentAsQuery(LibraryElement library, ArgumentList argumentLis
t) { | 7645 Type2 getFirstArgumentAsQuery(LibraryElement library, ArgumentList argumentLis
t) { |
7266 String argumentValue = getFirstArgumentAsString(argumentList); | 7646 String argumentValue = getFirstArgumentAsString(argumentList); |
7267 if (argumentValue != null) { | 7647 if (argumentValue != null) { |
7268 if (argumentValue.contains(" ")) { | 7648 if (argumentValue.contains(" ")) { |
7269 return null; | 7649 return null; |
7270 } | 7650 } |
7271 String tag = argumentValue; | 7651 String tag = argumentValue; |
7272 tag = StringUtilities.substringBefore(tag, ":"); | 7652 tag = StringUtilities.substringBefore(tag, ":"); |
7273 tag = StringUtilities.substringBefore(tag, "["); | 7653 tag = StringUtilities.substringBefore(tag, "["); |
7274 tag = StringUtilities.substringBefore(tag, "."); | 7654 tag = StringUtilities.substringBefore(tag, "."); |
7275 tag = StringUtilities.substringBefore(tag, "#"); | 7655 tag = StringUtilities.substringBefore(tag, "#"); |
7276 tag = _HTML_ELEMENT_TO_CLASS_MAP[tag.toLowerCase()]; | 7656 tag = _HTML_ELEMENT_TO_CLASS_MAP[tag.toLowerCase()]; |
7277 ClassElement returnType = library.getType(tag); | 7657 ClassElement returnType = library.getType(tag); |
7278 if (returnType != null) { | 7658 if (returnType != null) { |
7279 return returnType.type; | 7659 return returnType.type; |
7280 } | 7660 } |
7281 } | 7661 } |
7282 return null; | 7662 return null; |
7283 } | 7663 } |
7284 | 7664 |
7285 /** | 7665 /** |
7286 * If the given argument list contains at least one argument, and if the argum
ent is a simple | 7666 * If the given argument list contains at least one argument, and if the argum
ent is a simple |
7287 * string literal, return the String value of the argument. | 7667 * string literal, return the String value of the argument. |
| 7668 * |
7288 * @param argumentList the list of arguments from which a string value is to b
e extracted | 7669 * @param argumentList the list of arguments from which a string value is to b
e extracted |
7289 * @return the string specified by the first argument in the argument list | 7670 * @return the string specified by the first argument in the argument list |
7290 */ | 7671 */ |
7291 String getFirstArgumentAsString(ArgumentList argumentList) { | 7672 String getFirstArgumentAsString(ArgumentList argumentList) { |
7292 NodeList<Expression> arguments = argumentList.arguments; | 7673 NodeList<Expression> arguments = argumentList.arguments; |
7293 if (arguments.length > 0) { | 7674 if (arguments.length > 0) { |
7294 Expression argument = arguments[0]; | 7675 Expression argument = arguments[0]; |
7295 if (argument is SimpleStringLiteral) { | 7676 if (argument is SimpleStringLiteral) { |
7296 return ((argument as SimpleStringLiteral)).value; | 7677 return ((argument as SimpleStringLiteral)).value; |
7297 } | 7678 } |
7298 } | 7679 } |
7299 return null; | 7680 return null; |
7300 } | 7681 } |
7301 | 7682 |
7302 /** | 7683 /** |
7303 * If the given argument list contains at least one argument, and if the argum
ent is a simple | 7684 * If the given argument list contains at least one argument, and if the argum
ent is a simple |
7304 * string literal, and if the value of the argument is the name of a class def
ined within the | 7685 * string literal, and if the value of the argument is the name of a class def
ined within the |
7305 * given library, return the type specified by the argument. | 7686 * given library, return the type specified by the argument. |
| 7687 * |
7306 * @param library the library in which the specified type would be defined | 7688 * @param library the library in which the specified type would be defined |
7307 * @param argumentList the list of arguments from which a type is to be extrac
ted | 7689 * @param argumentList the list of arguments from which a type is to be extrac
ted |
7308 * @return the type specified by the first argument in the argument list | 7690 * @return the type specified by the first argument in the argument list |
7309 */ | 7691 */ |
7310 Type2 getFirstArgumentAsType(LibraryElement library, ArgumentList argumentList
) => getFirstArgumentAsType2(library, argumentList, null); | 7692 Type2 getFirstArgumentAsType(LibraryElement library, ArgumentList argumentList
) => getFirstArgumentAsType2(library, argumentList, null); |
7311 | 7693 |
7312 /** | 7694 /** |
7313 * If the given argument list contains at least one argument, and if the argum
ent is a simple | 7695 * If the given argument list contains at least one argument, and if the argum
ent is a simple |
7314 * string literal, and if the value of the argument is the name of a class def
ined within the | 7696 * string literal, and if the value of the argument is the name of a class def
ined within the |
7315 * given library, return the type specified by the argument. | 7697 * given library, return the type specified by the argument. |
| 7698 * |
7316 * @param library the library in which the specified type would be defined | 7699 * @param library the library in which the specified type would be defined |
7317 * @param argumentList the list of arguments from which a type is to be extrac
ted | 7700 * @param argumentList the list of arguments from which a type is to be extrac
ted |
7318 * @return the type specified by the first argument in the argument list | 7701 * @return the type specified by the first argument in the argument list |
7319 */ | 7702 */ |
7320 Type2 getFirstArgumentAsType2(LibraryElement library, ArgumentList argumentLis
t, Map<String, String> nameMap) { | 7703 Type2 getFirstArgumentAsType2(LibraryElement library, ArgumentList argumentLis
t, Map<String, String> nameMap) { |
7321 String argumentValue = getFirstArgumentAsString(argumentList); | 7704 String argumentValue = getFirstArgumentAsString(argumentList); |
7322 if (argumentValue != null) { | 7705 if (argumentValue != null) { |
7323 if (nameMap != null) { | 7706 if (nameMap != null) { |
7324 argumentValue = nameMap[argumentValue.toLowerCase()]; | 7707 argumentValue = nameMap[argumentValue.toLowerCase()]; |
7325 } | 7708 } |
7326 ClassElement returnType = library.getType(argumentValue); | 7709 ClassElement returnType = library.getType(argumentValue); |
7327 if (returnType != null) { | 7710 if (returnType != null) { |
7328 return returnType.type; | 7711 return returnType.type; |
7329 } | 7712 } |
7330 } | 7713 } |
7331 return null; | 7714 return null; |
7332 } | 7715 } |
7333 | 7716 |
7334 /** | 7717 /** |
7335 * Return the propagated type of the given expression. | 7718 * Return the propagated type of the given expression. |
| 7719 * |
7336 * @param expression the expression whose type is to be returned | 7720 * @param expression the expression whose type is to be returned |
7337 * @return the propagated type of the given expression | 7721 * @return the propagated type of the given expression |
7338 */ | 7722 */ |
7339 Type2 getPropagatedType(Expression expression) { | 7723 Type2 getPropagatedType(Expression expression) { |
7340 Type2 type = expression.propagatedType; | 7724 Type2 type = expression.propagatedType; |
7341 return type; | 7725 return type; |
7342 } | 7726 } |
7343 | 7727 |
7344 /** | 7728 /** |
7345 * Return the static type of the given expression. | 7729 * Return the static type of the given expression. |
| 7730 * |
7346 * @param expression the expression whose type is to be returned | 7731 * @param expression the expression whose type is to be returned |
7347 * @return the static type of the given expression | 7732 * @return the static type of the given expression |
7348 */ | 7733 */ |
7349 Type2 getStaticType(Expression expression) { | 7734 Type2 getStaticType(Expression expression) { |
7350 Type2 type = expression.staticType; | 7735 Type2 type = expression.staticType; |
7351 if (type == null) { | 7736 if (type == null) { |
7352 return _dynamicType; | 7737 return _dynamicType; |
7353 } | 7738 } |
7354 return type; | 7739 return type; |
7355 } | 7740 } |
7356 | 7741 |
7357 /** | 7742 /** |
7358 * Return the type that should be recorded for a node that resolved to the giv
en accessor. | 7743 * Return the type that should be recorded for a node that resolved to the giv
en accessor. |
| 7744 * |
7359 * @param accessor the accessor that the node resolved to | 7745 * @param accessor the accessor that the node resolved to |
7360 * @param context if the accessor element has context \[by being the RHS of a[
PrefixedIdentifier] or [PropertyAccess]\], and the return type of the | 7746 * @param context if the accessor element has context [by being the RHS of a |
7361 * accessor is a parameter type, then the type of the LHS can be used to get m
ore | 7747 * [PrefixedIdentifier] or [PropertyAccess]], and the return type of
the |
7362 * specific type information | 7748 * accessor is a parameter type, then the type of the LHS can be used
to get more |
| 7749 * specific type information |
7363 * @return the type that should be recorded for a node that resolved to the gi
ven accessor | 7750 * @return the type that should be recorded for a node that resolved to the gi
ven accessor |
7364 */ | 7751 */ |
7365 Type2 getType(PropertyAccessorElement accessor, Type2 context) { | 7752 Type2 getType(PropertyAccessorElement accessor, Type2 context) { |
7366 FunctionType functionType = accessor.type; | 7753 FunctionType functionType = accessor.type; |
7367 if (functionType == null) { | 7754 if (functionType == null) { |
7368 return _dynamicType; | 7755 return _dynamicType; |
7369 } | 7756 } |
7370 if (accessor.isSetter) { | 7757 if (accessor.isSetter) { |
7371 List<Type2> parameterTypes = functionType.normalParameterTypes; | 7758 List<Type2> parameterTypes = functionType.normalParameterTypes; |
7372 if (parameterTypes != null && parameterTypes.length > 0) { | 7759 if (parameterTypes != null && parameterTypes.length > 0) { |
(...skipping 19 matching lines...) Expand all Loading... |
7392 return interfaceTypeContext.typeArguments[i]; | 7779 return interfaceTypeContext.typeArguments[i]; |
7393 } | 7780 } |
7394 } | 7781 } |
7395 } | 7782 } |
7396 } | 7783 } |
7397 return returnType; | 7784 return returnType; |
7398 } | 7785 } |
7399 | 7786 |
7400 /** | 7787 /** |
7401 * Return the type represented by the given type name. | 7788 * Return the type represented by the given type name. |
| 7789 * |
7402 * @param typeName the type name representing the type to be returned | 7790 * @param typeName the type name representing the type to be returned |
7403 * @return the type represented by the type name | 7791 * @return the type represented by the type name |
7404 */ | 7792 */ |
7405 Type2 getType2(TypeName typeName) { | 7793 Type2 getType2(TypeName typeName) { |
7406 Type2 type = typeName.type; | 7794 Type2 type = typeName.type; |
7407 if (type == null) { | 7795 if (type == null) { |
7408 return _dynamicType; | 7796 return _dynamicType; |
7409 } | 7797 } |
7410 return type; | 7798 return type; |
7411 } | 7799 } |
7412 | 7800 |
7413 /** | 7801 /** |
| 7802 * Return `true` if the given [Type] is the `Future` form the 'dart:async' |
| 7803 * library. |
| 7804 */ |
| 7805 bool isAsyncFutureType(Type2 type) => type is InterfaceType && type.name == "F
uture" && isAsyncLibrary(type.element.library); |
| 7806 |
| 7807 /** |
| 7808 * Return `true` if the given library is the 'dart:async' library. |
| 7809 * |
| 7810 * @param library the library being tested |
| 7811 * @return `true` if the library is 'dart:async' |
| 7812 */ |
| 7813 bool isAsyncLibrary(LibraryElement library) => library.name == "dart.async"; |
| 7814 |
| 7815 /** |
7414 * Return `true` if the given library is the 'dart:html' library. | 7816 * Return `true` if the given library is the 'dart:html' library. |
| 7817 * |
7415 * @param library the library being tested | 7818 * @param library the library being tested |
7416 * @return `true` if the library is 'dart:html' | 7819 * @return `true` if the library is 'dart:html' |
7417 */ | 7820 */ |
7418 bool isHtmlLibrary(LibraryElement library) => library.name == "dart.dom.html"; | 7821 bool isHtmlLibrary(LibraryElement library) => library.name == "dart.dom.html"; |
7419 | 7822 |
7420 /** | 7823 /** |
7421 * Return `true` if the given node is not a type literal. | 7824 * Return `true` if the given node is not a type literal. |
| 7825 * |
7422 * @param node the node being tested | 7826 * @param node the node being tested |
7423 * @return `true` if the given node is not a type literal | 7827 * @return `true` if the given node is not a type literal |
7424 */ | 7828 */ |
7425 bool isNotTypeLiteral(Identifier node) { | 7829 bool isNotTypeLiteral(Identifier node) { |
7426 ASTNode parent = node.parent; | 7830 ASTNode parent = node.parent; |
7427 return parent is TypeName || (parent is PrefixedIdentifier && (parent.parent
is TypeName || identical(((parent as PrefixedIdentifier)).prefix, node))) || (p
arent is PropertyAccess && identical(((parent as PropertyAccess)).target, node))
|| (parent is MethodInvocation && identical(node, ((parent as MethodInvocation)
).target)); | 7831 return parent is TypeName || (parent is PrefixedIdentifier && (parent.parent
is TypeName || identical(((parent as PrefixedIdentifier)).prefix, node))) || (p
arent is PropertyAccess && identical(((parent as PropertyAccess)).target, node))
|| (parent is MethodInvocation && identical(node, ((parent as MethodInvocation)
).target)); |
7428 } | 7832 } |
7429 | 7833 |
7430 /** | 7834 /** |
| 7835 * Given a function element and its body, compute and record the propagated re
turn type of the |
| 7836 * function. |
| 7837 * |
| 7838 * @param functionElement the function element to record propagated return typ
e for |
| 7839 * @param body the boy of the function whose propagated return type is to be c
omputed |
| 7840 * @return the propagated return type that was computed, may be `null` if it i
s not more |
| 7841 * specific than the static return type. |
| 7842 */ |
| 7843 void recordPropagatedType(ExecutableElement functionElement, FunctionBody body
) { |
| 7844 Type2 propagatedReturnType = computePropagatedReturnType2(body); |
| 7845 if (propagatedReturnType == null) { |
| 7846 return; |
| 7847 } |
| 7848 if (identical(propagatedReturnType, BottomTypeImpl.instance)) { |
| 7849 return; |
| 7850 } |
| 7851 Type2 staticReturnType = functionElement.returnType; |
| 7852 if (!propagatedReturnType.isMoreSpecificThan(staticReturnType)) { |
| 7853 return; |
| 7854 } |
| 7855 _propagatedReturnTypes[functionElement] = propagatedReturnType; |
| 7856 } |
| 7857 |
| 7858 /** |
7431 * Record that the propagated type of the given node is the given type. | 7859 * Record that the propagated type of the given node is the given type. |
| 7860 * |
7432 * @param expression the node whose type is to be recorded | 7861 * @param expression the node whose type is to be recorded |
7433 * @param type the propagated type of the node | 7862 * @param type the propagated type of the node |
7434 */ | 7863 */ |
7435 void recordPropagatedType(Expression expression, Type2 type) { | 7864 void recordPropagatedType2(Expression expression, Type2 type) { |
7436 if (type != null && !type.isDynamic) { | 7865 if (type != null && !type.isDynamic) { |
7437 expression.propagatedType = type; | 7866 expression.propagatedType = type; |
7438 } | 7867 } |
7439 } | 7868 } |
7440 | 7869 |
7441 /** | 7870 /** |
7442 * Record that the static type of the given node is the given type. | 7871 * Record that the static type of the given node is the given type. |
| 7872 * |
7443 * @param expression the node whose type is to be recorded | 7873 * @param expression the node whose type is to be recorded |
7444 * @param type the static type of the node | 7874 * @param type the static type of the node |
7445 */ | 7875 */ |
7446 void recordStaticType(Expression expression, Type2 type) { | 7876 void recordStaticType(Expression expression, Type2 type) { |
7447 if (type == null) { | 7877 if (type == null) { |
7448 expression.staticType = _dynamicType; | 7878 expression.staticType = _dynamicType; |
7449 } else { | 7879 } else { |
7450 expression.staticType = type; | 7880 expression.staticType = type; |
7451 } | 7881 } |
7452 } | 7882 } |
7453 | 7883 |
7454 /** | 7884 /** |
7455 * Attempts to make a better guess for the static type of the given binary exp
ression. | 7885 * Attempts to make a better guess for the static type of the given binary exp
ression. |
| 7886 * |
7456 * @param node the binary expression to analyze | 7887 * @param node the binary expression to analyze |
7457 * @param staticType the static type of the expression as resolved | 7888 * @param staticType the static type of the expression as resolved |
7458 * @return the better type guess, or the same static type as given | 7889 * @return the better type guess, or the same static type as given |
7459 */ | 7890 */ |
7460 Type2 refineBinaryExpressionType(BinaryExpression node, Type2 staticType) { | 7891 Type2 refineBinaryExpressionType(BinaryExpression node, Type2 staticType) { |
7461 sc.TokenType operator = node.operator.type; | 7892 sc.TokenType operator = node.operator.type; |
7462 if (identical(operator, sc.TokenType.AMPERSAND_AMPERSAND) || identical(opera
tor, sc.TokenType.BAR_BAR) || identical(operator, sc.TokenType.EQ_EQ) || identic
al(operator, sc.TokenType.BANG_EQ)) { | 7893 if (identical(operator, sc.TokenType.AMPERSAND_AMPERSAND) || identical(opera
tor, sc.TokenType.BAR_BAR) || identical(operator, sc.TokenType.EQ_EQ) || identic
al(operator, sc.TokenType.BANG_EQ)) { |
7463 return _typeProvider.boolType; | 7894 return _typeProvider.boolType; |
7464 } | 7895 } |
7465 if (identical(operator, sc.TokenType.MINUS) || identical(operator, sc.TokenT
ype.PERCENT) || identical(operator, sc.TokenType.PLUS) || identical(operator, sc
.TokenType.STAR)) { | 7896 if (identical(operator, sc.TokenType.MINUS) || identical(operator, sc.TokenT
ype.PERCENT) || identical(operator, sc.TokenType.PLUS) || identical(operator, sc
.TokenType.STAR)) { |
7466 Type2 doubleType = _typeProvider.doubleType; | 7897 Type2 doubleType = _typeProvider.doubleType; |
7467 if (identical(getStaticType(node.leftOperand), _typeProvider.intType) && i
dentical(getStaticType(node.rightOperand), doubleType)) { | 7898 if (identical(getStaticType(node.leftOperand), _typeProvider.intType) && i
dentical(getStaticType(node.rightOperand), doubleType)) { |
7468 return doubleType; | 7899 return doubleType; |
7469 } | 7900 } |
7470 } | 7901 } |
7471 if (identical(operator, sc.TokenType.MINUS) || identical(operator, sc.TokenT
ype.PERCENT) || identical(operator, sc.TokenType.PLUS) || identical(operator, sc
.TokenType.STAR) || identical(operator, sc.TokenType.TILDE_SLASH)) { | 7902 if (identical(operator, sc.TokenType.MINUS) || identical(operator, sc.TokenT
ype.PERCENT) || identical(operator, sc.TokenType.PLUS) || identical(operator, sc
.TokenType.STAR) || identical(operator, sc.TokenType.TILDE_SLASH)) { |
7472 Type2 intType = _typeProvider.intType; | 7903 Type2 intType = _typeProvider.intType; |
7473 if (identical(getStaticType(node.leftOperand), intType) && identical(getSt
aticType(node.rightOperand), intType)) { | 7904 if (identical(getStaticType(node.leftOperand), intType) && identical(getSt
aticType(node.rightOperand), intType)) { |
7474 staticType = intType; | 7905 staticType = intType; |
7475 } | 7906 } |
7476 } | 7907 } |
7477 return staticType; | 7908 return staticType; |
7478 } | 7909 } |
7479 | 7910 |
7480 /** | 7911 /** |
7481 * Set the return type and parameter type information for the given function t
ype based on the | 7912 * Set the return type and parameter type information for the given function t
ype based on the |
7482 * given return type and parameter elements. | 7913 * given return type and parameter elements. |
| 7914 * |
7483 * @param functionType the function type to be filled in | 7915 * @param functionType the function type to be filled in |
7484 * @param parameters the elements representing the parameters to the function | 7916 * @param parameters the elements representing the parameters to the function |
7485 */ | 7917 */ |
7486 void setTypeInformation(FunctionTypeImpl functionType, FormalParameterList par
ameterList) { | 7918 void setTypeInformation(FunctionTypeImpl functionType, FormalParameterList par
ameterList) { |
7487 List<Type2> normalParameterTypes = new List<Type2>(); | 7919 List<Type2> normalParameterTypes = new List<Type2>(); |
7488 List<Type2> optionalParameterTypes = new List<Type2>(); | 7920 List<Type2> optionalParameterTypes = new List<Type2>(); |
7489 LinkedHashMap<String, Type2> namedParameterTypes = new LinkedHashMap<String,
Type2>(); | 7921 LinkedHashMap<String, Type2> namedParameterTypes = new LinkedHashMap<String,
Type2>(); |
7490 if (parameterList != null) { | 7922 if (parameterList != null) { |
7491 for (ParameterElement parameter in parameterList.elements) { | 7923 for (ParameterElement parameter in parameterList.elements) { |
7492 while (true) { | 7924 while (true) { |
7493 if (parameter.parameterKind == ParameterKind.REQUIRED) { | 7925 if (parameter.parameterKind == ParameterKind.REQUIRED) { |
7494 normalParameterTypes.add(parameter.type); | 7926 normalParameterTypes.add(parameter.type); |
7495 } else if (parameter.parameterKind == ParameterKind.POSITIONAL) { | 7927 } else if (parameter.parameterKind == ParameterKind.POSITIONAL) { |
7496 optionalParameterTypes.add(parameter.type); | 7928 optionalParameterTypes.add(parameter.type); |
7497 } else if (parameter.parameterKind == ParameterKind.NAMED) { | 7929 } else if (parameter.parameterKind == ParameterKind.NAMED) { |
7498 namedParameterTypes[parameter.name] = parameter.type; | 7930 namedParameterTypes[parameter.name] = parameter.type; |
7499 } | 7931 } |
7500 break; | 7932 break; |
7501 } | 7933 } |
7502 } | 7934 } |
7503 } | 7935 } |
7504 functionType.normalParameterTypes = new List.from(normalParameterTypes); | 7936 functionType.normalParameterTypes = new List.from(normalParameterTypes); |
7505 functionType.optionalParameterTypes = new List.from(optionalParameterTypes); | 7937 functionType.optionalParameterTypes = new List.from(optionalParameterTypes); |
7506 functionType.namedParameterTypes = namedParameterTypes; | 7938 functionType.namedParameterTypes = namedParameterTypes; |
7507 } | 7939 } |
7508 get thisType_J2DAccessor => _thisType; | 7940 get thisType_J2DAccessor => _thisType; |
7509 set thisType_J2DAccessor(__v) => _thisType = __v; | 7941 set thisType_J2DAccessor(__v) => _thisType = __v; |
7510 } | 7942 } |
| 7943 class GeneralizingASTVisitor_8 extends GeneralizingASTVisitor<Object> { |
| 7944 final StaticTypeAnalyzer StaticTypeAnalyzer_this; |
| 7945 List<Type2> result; |
| 7946 GeneralizingASTVisitor_8(this.StaticTypeAnalyzer_this, this.result) : super(); |
| 7947 Object visitExpression(Expression node) => null; |
| 7948 Object visitReturnStatement(ReturnStatement node) { |
| 7949 Type2 type; |
| 7950 Expression expression = node.expression; |
| 7951 if (expression != null) { |
| 7952 type = StaticTypeAnalyzer_this.getBestType(expression); |
| 7953 } else { |
| 7954 type = BottomTypeImpl.instance; |
| 7955 } |
| 7956 if (result[0] == null) { |
| 7957 result[0] = type; |
| 7958 } else { |
| 7959 result[0] = result[0].getLeastUpperBound(type); |
| 7960 } |
| 7961 return null; |
| 7962 } |
| 7963 } |
7511 /** | 7964 /** |
7512 * Instances of the class `TypeOverrideManager` manage the ability to override t
he type of an | 7965 * Instances of the class `TypeOverrideManager` manage the ability to override t
he type of an |
7513 * element within a given context. | 7966 * element within a given context. |
7514 */ | 7967 */ |
7515 class TypeOverrideManager { | 7968 class TypeOverrideManager { |
7516 | 7969 |
7517 /** | 7970 /** |
7518 * The current override scope, or `null` if no scope has been entered. | 7971 * The current override scope, or `null` if no scope has been entered. |
7519 */ | 7972 */ |
7520 TypeOverrideManager_TypeOverrideScope _currentScope; | 7973 TypeOverrideManager_TypeOverrideScope _currentScope; |
7521 | 7974 |
7522 /** | 7975 /** |
7523 * Apply a set of overrides that were previously captured. | 7976 * Apply a set of overrides that were previously captured. |
| 7977 * |
7524 * @param overrides the overrides to be applied | 7978 * @param overrides the overrides to be applied |
7525 */ | 7979 */ |
7526 void applyOverrides(Map<Element, Type2> overrides) { | 7980 void applyOverrides(Map<Element, Type2> overrides) { |
7527 if (_currentScope == null) { | 7981 if (_currentScope == null) { |
7528 throw new IllegalStateException("Cannot apply overrides without a scope"); | 7982 throw new IllegalStateException("Cannot apply overrides without a scope"); |
7529 } | 7983 } |
7530 _currentScope.applyOverrides(overrides); | 7984 _currentScope.applyOverrides(overrides); |
7531 } | 7985 } |
7532 | 7986 |
7533 /** | 7987 /** |
7534 * Return a table mapping the elements whose type is overridden in the current
scope to the | 7988 * Return a table mapping the elements whose type is overridden in the current
scope to the |
7535 * overriding type. | 7989 * overriding type. |
| 7990 * |
7536 * @return the overrides in the current scope | 7991 * @return the overrides in the current scope |
7537 */ | 7992 */ |
7538 Map<Element, Type2> captureLocalOverrides() { | 7993 Map<Element, Type2> captureLocalOverrides() { |
7539 if (_currentScope == null) { | 7994 if (_currentScope == null) { |
7540 throw new IllegalStateException("Cannot capture local overrides without a
scope"); | 7995 throw new IllegalStateException("Cannot capture local overrides without a
scope"); |
7541 } | 7996 } |
7542 return _currentScope.captureLocalOverrides(); | 7997 return _currentScope.captureLocalOverrides(); |
7543 } | 7998 } |
7544 | 7999 |
7545 /** | 8000 /** |
7546 * Return a map from the elements for the variables in the given list that hav
e their types | 8001 * Return a map from the elements for the variables in the given list that hav
e their types |
7547 * overridden to the overriding type. | 8002 * overridden to the overriding type. |
| 8003 * |
7548 * @param variableList the list of variables whose overriding types are to be
captured | 8004 * @param variableList the list of variables whose overriding types are to be
captured |
7549 * @return a table mapping elements to their overriding types | 8005 * @return a table mapping elements to their overriding types |
7550 */ | 8006 */ |
7551 Map<Element, Type2> captureOverrides(VariableDeclarationList variableList) { | 8007 Map<Element, Type2> captureOverrides(VariableDeclarationList variableList) { |
7552 if (_currentScope == null) { | 8008 if (_currentScope == null) { |
7553 throw new IllegalStateException("Cannot capture overrides without a scope"
); | 8009 throw new IllegalStateException("Cannot capture overrides without a scope"
); |
7554 } | 8010 } |
7555 return _currentScope.captureOverrides(variableList); | 8011 return _currentScope.captureOverrides(variableList); |
7556 } | 8012 } |
7557 | 8013 |
(...skipping 10 matching lines...) Expand all Loading... |
7568 void exitScope() { | 8024 void exitScope() { |
7569 if (_currentScope == null) { | 8025 if (_currentScope == null) { |
7570 throw new IllegalStateException("No scope to exit"); | 8026 throw new IllegalStateException("No scope to exit"); |
7571 } | 8027 } |
7572 _currentScope = _currentScope._outerScope; | 8028 _currentScope = _currentScope._outerScope; |
7573 } | 8029 } |
7574 | 8030 |
7575 /** | 8031 /** |
7576 * Return the overridden type of the given element, or `null` if the type of t
he element has | 8032 * Return the overridden type of the given element, or `null` if the type of t
he element has |
7577 * not been overridden. | 8033 * not been overridden. |
| 8034 * |
7578 * @param element the element whose type might have been overridden | 8035 * @param element the element whose type might have been overridden |
7579 * @return the overridden type of the given element | 8036 * @return the overridden type of the given element |
7580 */ | 8037 */ |
7581 Type2 getType(Element element) { | 8038 Type2 getType(Element element) { |
7582 if (_currentScope == null) { | 8039 if (_currentScope == null) { |
7583 return null; | 8040 return null; |
7584 } | 8041 } |
7585 return _currentScope.getType(element); | 8042 return _currentScope.getType(element); |
7586 } | 8043 } |
7587 | 8044 |
7588 /** | 8045 /** |
7589 * Set the overridden type of the given element to the given type | 8046 * Set the overridden type of the given element to the given type |
| 8047 * |
7590 * @param element the element whose type might have been overridden | 8048 * @param element the element whose type might have been overridden |
7591 * @param type the overridden type of the given element | 8049 * @param type the overridden type of the given element |
7592 */ | 8050 */ |
7593 void setType(Element element, Type2 type) { | 8051 void setType(Element element, Type2 type) { |
7594 if (_currentScope == null) { | 8052 if (_currentScope == null) { |
7595 throw new IllegalStateException("Cannot override without a scope"); | 8053 throw new IllegalStateException("Cannot override without a scope"); |
7596 } | 8054 } |
7597 _currentScope.setType(element, type); | 8055 _currentScope.setType(element, type); |
7598 } | 8056 } |
7599 } | 8057 } |
7600 /** | 8058 /** |
7601 * Instances of the class `TypeOverrideScope` represent a scope in which the typ
es of | 8059 * Instances of the class `TypeOverrideScope` represent a scope in which the typ
es of |
7602 * elements can be overridden. | 8060 * elements can be overridden. |
7603 */ | 8061 */ |
7604 class TypeOverrideManager_TypeOverrideScope { | 8062 class TypeOverrideManager_TypeOverrideScope { |
7605 | 8063 |
7606 /** | 8064 /** |
7607 * The outer scope in which types might be overridden. | 8065 * The outer scope in which types might be overridden. |
7608 */ | 8066 */ |
7609 TypeOverrideManager_TypeOverrideScope _outerScope; | 8067 TypeOverrideManager_TypeOverrideScope _outerScope; |
7610 | 8068 |
7611 /** | 8069 /** |
7612 * A table mapping elements to the overridden type of that element. | 8070 * A table mapping elements to the overridden type of that element. |
7613 */ | 8071 */ |
7614 Map<Element, Type2> _overridenTypes = new Map<Element, Type2>(); | 8072 Map<Element, Type2> _overridenTypes = new Map<Element, Type2>(); |
7615 | 8073 |
7616 /** | 8074 /** |
7617 * Initialize a newly created scope to be an empty child of the given scope. | 8075 * Initialize a newly created scope to be an empty child of the given scope. |
| 8076 * |
7618 * @param outerScope the outer scope in which types might be overridden | 8077 * @param outerScope the outer scope in which types might be overridden |
7619 */ | 8078 */ |
7620 TypeOverrideManager_TypeOverrideScope(TypeOverrideManager_TypeOverrideScope ou
terScope) { | 8079 TypeOverrideManager_TypeOverrideScope(TypeOverrideManager_TypeOverrideScope ou
terScope) { |
7621 this._outerScope = outerScope; | 8080 this._outerScope = outerScope; |
7622 } | 8081 } |
7623 | 8082 |
7624 /** | 8083 /** |
7625 * Apply a set of overrides that were previously captured. | 8084 * Apply a set of overrides that were previously captured. |
| 8085 * |
7626 * @param overrides the overrides to be applied | 8086 * @param overrides the overrides to be applied |
7627 */ | 8087 */ |
7628 void applyOverrides(Map<Element, Type2> overrides) { | 8088 void applyOverrides(Map<Element, Type2> overrides) { |
7629 for (MapEntry<Element, Type2> entry in getMapEntrySet(overrides)) { | 8089 for (MapEntry<Element, Type2> entry in getMapEntrySet(overrides)) { |
7630 _overridenTypes[entry.getKey()] = entry.getValue(); | 8090 _overridenTypes[entry.getKey()] = entry.getValue(); |
7631 } | 8091 } |
7632 } | 8092 } |
7633 | 8093 |
7634 /** | 8094 /** |
7635 * Return a table mapping the elements whose type is overridden in the current
scope to the | 8095 * Return a table mapping the elements whose type is overridden in the current
scope to the |
7636 * overriding type. | 8096 * overriding type. |
| 8097 * |
7637 * @return the overrides in the current scope | 8098 * @return the overrides in the current scope |
7638 */ | 8099 */ |
7639 Map<Element, Type2> captureLocalOverrides() => _overridenTypes; | 8100 Map<Element, Type2> captureLocalOverrides() => _overridenTypes; |
7640 | 8101 |
7641 /** | 8102 /** |
7642 * Return a map from the elements for the variables in the given list that hav
e their types | 8103 * Return a map from the elements for the variables in the given list that hav
e their types |
7643 * overridden to the overriding type. | 8104 * overridden to the overriding type. |
| 8105 * |
7644 * @param variableList the list of variables whose overriding types are to be
captured | 8106 * @param variableList the list of variables whose overriding types are to be
captured |
7645 * @return a table mapping elements to their overriding types | 8107 * @return a table mapping elements to their overriding types |
7646 */ | 8108 */ |
7647 Map<Element, Type2> captureOverrides(VariableDeclarationList variableList) { | 8109 Map<Element, Type2> captureOverrides(VariableDeclarationList variableList) { |
7648 Map<Element, Type2> overrides = new Map<Element, Type2>(); | 8110 Map<Element, Type2> overrides = new Map<Element, Type2>(); |
7649 if (variableList.isConst || variableList.isFinal) { | 8111 if (variableList.isConst || variableList.isFinal) { |
7650 for (VariableDeclaration variable in variableList.variables) { | 8112 for (VariableDeclaration variable in variableList.variables) { |
7651 Element element = variable.element; | 8113 Element element = variable.element; |
7652 if (element != null) { | 8114 if (element != null) { |
7653 Type2 type = _overridenTypes[element]; | 8115 Type2 type = _overridenTypes[element]; |
7654 if (type != null) { | 8116 if (type != null) { |
7655 overrides[element] = type; | 8117 overrides[element] = type; |
7656 } | 8118 } |
7657 } | 8119 } |
7658 } | 8120 } |
7659 } | 8121 } |
7660 return overrides; | 8122 return overrides; |
7661 } | 8123 } |
7662 | 8124 |
7663 /** | 8125 /** |
7664 * Return the overridden type of the given element, or `null` if the type of t
he element | 8126 * Return the overridden type of the given element, or `null` if the type of t
he element |
7665 * has not been overridden. | 8127 * has not been overridden. |
| 8128 * |
7666 * @param element the element whose type might have been overridden | 8129 * @param element the element whose type might have been overridden |
7667 * @return the overridden type of the given element | 8130 * @return the overridden type of the given element |
7668 */ | 8131 */ |
7669 Type2 getType(Element element) { | 8132 Type2 getType(Element element) { |
7670 Type2 type = _overridenTypes[element]; | 8133 Type2 type = _overridenTypes[element]; |
7671 if (type == null && element is PropertyAccessorElement) { | 8134 if (type == null && element is PropertyAccessorElement) { |
7672 type = _overridenTypes[((element as PropertyAccessorElement)).variable]; | 8135 type = _overridenTypes[((element as PropertyAccessorElement)).variable]; |
7673 } | 8136 } |
7674 if (type != null) { | 8137 if (type != null) { |
7675 return type; | 8138 return type; |
7676 } else if (_outerScope != null) { | 8139 } else if (_outerScope != null) { |
7677 return _outerScope.getType(element); | 8140 return _outerScope.getType(element); |
7678 } | 8141 } |
7679 return null; | 8142 return null; |
7680 } | 8143 } |
7681 | 8144 |
7682 /** | 8145 /** |
7683 * Set the overridden type of the given element to the given type | 8146 * Set the overridden type of the given element to the given type |
| 8147 * |
7684 * @param element the element whose type might have been overridden | 8148 * @param element the element whose type might have been overridden |
7685 * @param type the overridden type of the given element | 8149 * @param type the overridden type of the given element |
7686 */ | 8150 */ |
7687 void setType(Element element, Type2 type) { | 8151 void setType(Element element, Type2 type) { |
7688 _overridenTypes[element] = type; | 8152 _overridenTypes[element] = type; |
7689 } | 8153 } |
7690 } | 8154 } |
7691 /** | 8155 /** |
7692 * The interface `TypeProvider` defines the behavior of objects that provide acc
ess to types | 8156 * The interface `TypeProvider` defines the behavior of objects that provide acc
ess to types |
7693 * defined by the language. | 8157 * defined by the language. |
| 8158 * |
7694 * @coverage dart.engine.resolver | 8159 * @coverage dart.engine.resolver |
7695 */ | 8160 */ |
7696 abstract class TypeProvider { | 8161 abstract class TypeProvider { |
7697 | 8162 |
7698 /** | 8163 /** |
7699 * Return the type representing the built-in type 'bool'. | 8164 * Return the type representing the built-in type 'bool'. |
| 8165 * |
7700 * @return the type representing the built-in type 'bool' | 8166 * @return the type representing the built-in type 'bool' |
7701 */ | 8167 */ |
7702 InterfaceType get boolType; | 8168 InterfaceType get boolType; |
7703 | 8169 |
7704 /** | 8170 /** |
7705 * Return the type representing the type 'bottom'. | 8171 * Return the type representing the type 'bottom'. |
| 8172 * |
7706 * @return the type representing the type 'bottom' | 8173 * @return the type representing the type 'bottom' |
7707 */ | 8174 */ |
7708 Type2 get bottomType; | 8175 Type2 get bottomType; |
7709 | 8176 |
7710 /** | 8177 /** |
7711 * Return the type representing the built-in type 'double'. | 8178 * Return the type representing the built-in type 'double'. |
| 8179 * |
7712 * @return the type representing the built-in type 'double' | 8180 * @return the type representing the built-in type 'double' |
7713 */ | 8181 */ |
7714 InterfaceType get doubleType; | 8182 InterfaceType get doubleType; |
7715 | 8183 |
7716 /** | 8184 /** |
7717 * Return the type representing the built-in type 'dynamic'. | 8185 * Return the type representing the built-in type 'dynamic'. |
| 8186 * |
7718 * @return the type representing the built-in type 'dynamic' | 8187 * @return the type representing the built-in type 'dynamic' |
7719 */ | 8188 */ |
7720 Type2 get dynamicType; | 8189 Type2 get dynamicType; |
7721 | 8190 |
7722 /** | 8191 /** |
7723 * Return the type representing the built-in type 'Function'. | 8192 * Return the type representing the built-in type 'Function'. |
| 8193 * |
7724 * @return the type representing the built-in type 'Function' | 8194 * @return the type representing the built-in type 'Function' |
7725 */ | 8195 */ |
7726 InterfaceType get functionType; | 8196 InterfaceType get functionType; |
7727 | 8197 |
7728 /** | 8198 /** |
7729 * Return the type representing the built-in type 'int'. | 8199 * Return the type representing the built-in type 'int'. |
| 8200 * |
7730 * @return the type representing the built-in type 'int' | 8201 * @return the type representing the built-in type 'int' |
7731 */ | 8202 */ |
7732 InterfaceType get intType; | 8203 InterfaceType get intType; |
7733 | 8204 |
7734 /** | 8205 /** |
7735 * Return the type representing the built-in type 'List'. | 8206 * Return the type representing the built-in type 'List'. |
| 8207 * |
7736 * @return the type representing the built-in type 'List' | 8208 * @return the type representing the built-in type 'List' |
7737 */ | 8209 */ |
7738 InterfaceType get listType; | 8210 InterfaceType get listType; |
7739 | 8211 |
7740 /** | 8212 /** |
7741 * Return the type representing the built-in type 'Map'. | 8213 * Return the type representing the built-in type 'Map'. |
| 8214 * |
7742 * @return the type representing the built-in type 'Map' | 8215 * @return the type representing the built-in type 'Map' |
7743 */ | 8216 */ |
7744 InterfaceType get mapType; | 8217 InterfaceType get mapType; |
7745 | 8218 |
7746 /** | 8219 /** |
7747 * Return the type representing the built-in type 'num'. | 8220 * Return the type representing the built-in type 'num'. |
| 8221 * |
7748 * @return the type representing the built-in type 'num' | 8222 * @return the type representing the built-in type 'num' |
7749 */ | 8223 */ |
7750 InterfaceType get numType; | 8224 InterfaceType get numType; |
7751 | 8225 |
7752 /** | 8226 /** |
7753 * Return the type representing the built-in type 'Object'. | 8227 * Return the type representing the built-in type 'Object'. |
| 8228 * |
7754 * @return the type representing the built-in type 'Object' | 8229 * @return the type representing the built-in type 'Object' |
7755 */ | 8230 */ |
7756 InterfaceType get objectType; | 8231 InterfaceType get objectType; |
7757 | 8232 |
7758 /** | 8233 /** |
7759 * Return the type representing the built-in type 'StackTrace'. | 8234 * Return the type representing the built-in type 'StackTrace'. |
| 8235 * |
7760 * @return the type representing the built-in type 'StackTrace' | 8236 * @return the type representing the built-in type 'StackTrace' |
7761 */ | 8237 */ |
7762 InterfaceType get stackTraceType; | 8238 InterfaceType get stackTraceType; |
7763 | 8239 |
7764 /** | 8240 /** |
7765 * Return the type representing the built-in type 'String'. | 8241 * Return the type representing the built-in type 'String'. |
| 8242 * |
7766 * @return the type representing the built-in type 'String' | 8243 * @return the type representing the built-in type 'String' |
7767 */ | 8244 */ |
7768 InterfaceType get stringType; | 8245 InterfaceType get stringType; |
7769 | 8246 |
7770 /** | 8247 /** |
| 8248 * Return the type representing the built-in type 'Symbol'. |
| 8249 * |
| 8250 * @return the type representing the built-in type 'Symbol' |
| 8251 */ |
| 8252 InterfaceType get symbolType; |
| 8253 |
| 8254 /** |
7771 * Return the type representing the built-in type 'Type'. | 8255 * Return the type representing the built-in type 'Type'. |
| 8256 * |
7772 * @return the type representing the built-in type 'Type' | 8257 * @return the type representing the built-in type 'Type' |
7773 */ | 8258 */ |
7774 InterfaceType get typeType; | 8259 InterfaceType get typeType; |
7775 } | 8260 } |
7776 /** | 8261 /** |
7777 * Instances of the class `TypeProviderImpl` provide access to types defined by
the language | 8262 * Instances of the class `TypeProviderImpl` provide access to types defined by
the language |
7778 * by looking for those types in the element model for the core library. | 8263 * by looking for those types in the element model for the core library. |
| 8264 * |
7779 * @coverage dart.engine.resolver | 8265 * @coverage dart.engine.resolver |
7780 */ | 8266 */ |
7781 class TypeProviderImpl implements TypeProvider { | 8267 class TypeProviderImpl implements TypeProvider { |
7782 | 8268 |
7783 /** | 8269 /** |
7784 * The type representing the built-in type 'bool'. | 8270 * The type representing the built-in type 'bool'. |
7785 */ | 8271 */ |
7786 InterfaceType _boolType; | 8272 InterfaceType _boolType; |
7787 | 8273 |
7788 /** | 8274 /** |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7834 * The type representing the built-in type 'StackTrace'. | 8320 * The type representing the built-in type 'StackTrace'. |
7835 */ | 8321 */ |
7836 InterfaceType _stackTraceType; | 8322 InterfaceType _stackTraceType; |
7837 | 8323 |
7838 /** | 8324 /** |
7839 * The type representing the built-in type 'String'. | 8325 * The type representing the built-in type 'String'. |
7840 */ | 8326 */ |
7841 InterfaceType _stringType; | 8327 InterfaceType _stringType; |
7842 | 8328 |
7843 /** | 8329 /** |
| 8330 * The type representing the built-in type 'Symbol'. |
| 8331 */ |
| 8332 InterfaceType _symbolType; |
| 8333 |
| 8334 /** |
7844 * The type representing the built-in type 'Type'. | 8335 * The type representing the built-in type 'Type'. |
7845 */ | 8336 */ |
7846 InterfaceType _typeType; | 8337 InterfaceType _typeType; |
7847 | 8338 |
7848 /** | 8339 /** |
7849 * Initialize a newly created type provider to provide the types defined in th
e given library. | 8340 * Initialize a newly created type provider to provide the types defined in th
e given library. |
| 8341 * |
7850 * @param coreLibrary the element representing the core library (dart:core). | 8342 * @param coreLibrary the element representing the core library (dart:core). |
7851 */ | 8343 */ |
7852 TypeProviderImpl(LibraryElement coreLibrary) { | 8344 TypeProviderImpl(LibraryElement coreLibrary) { |
7853 initializeFrom(coreLibrary); | 8345 initializeFrom(coreLibrary); |
7854 } | 8346 } |
7855 InterfaceType get boolType => _boolType; | 8347 InterfaceType get boolType => _boolType; |
7856 Type2 get bottomType => _bottomType; | 8348 Type2 get bottomType => _bottomType; |
7857 InterfaceType get doubleType => _doubleType; | 8349 InterfaceType get doubleType => _doubleType; |
7858 Type2 get dynamicType => _dynamicType; | 8350 Type2 get dynamicType => _dynamicType; |
7859 InterfaceType get functionType => _functionType; | 8351 InterfaceType get functionType => _functionType; |
7860 InterfaceType get intType => _intType; | 8352 InterfaceType get intType => _intType; |
7861 InterfaceType get listType => _listType; | 8353 InterfaceType get listType => _listType; |
7862 InterfaceType get mapType => _mapType; | 8354 InterfaceType get mapType => _mapType; |
7863 InterfaceType get numType => _numType; | 8355 InterfaceType get numType => _numType; |
7864 InterfaceType get objectType => _objectType; | 8356 InterfaceType get objectType => _objectType; |
7865 InterfaceType get stackTraceType => _stackTraceType; | 8357 InterfaceType get stackTraceType => _stackTraceType; |
7866 InterfaceType get stringType => _stringType; | 8358 InterfaceType get stringType => _stringType; |
| 8359 InterfaceType get symbolType => _symbolType; |
7867 InterfaceType get typeType => _typeType; | 8360 InterfaceType get typeType => _typeType; |
7868 | 8361 |
7869 /** | 8362 /** |
7870 * Return the type with the given name from the given namespace, or `null` if
there is no | 8363 * Return the type with the given name from the given namespace, or `null` if
there is no |
7871 * class with the given name. | 8364 * class with the given name. |
| 8365 * |
7872 * @param namespace the namespace in which to search for the given name | 8366 * @param namespace the namespace in which to search for the given name |
7873 * @param typeName the name of the type being searched for | 8367 * @param typeName the name of the type being searched for |
7874 * @return the type that was found | 8368 * @return the type that was found |
7875 */ | 8369 */ |
7876 InterfaceType getType(Namespace namespace, String typeName) { | 8370 InterfaceType getType(Namespace namespace, String typeName) { |
7877 Element element = namespace.get(typeName); | 8371 Element element = namespace.get(typeName); |
7878 if (element == null) { | 8372 if (element == null) { |
7879 AnalysisEngine.instance.logger.logInformation("No definition of type ${typ
eName}"); | 8373 AnalysisEngine.instance.logger.logInformation("No definition of type ${typ
eName}"); |
7880 return null; | 8374 return null; |
7881 } | 8375 } |
7882 return ((element as ClassElement)).type; | 8376 return ((element as ClassElement)).type; |
7883 } | 8377 } |
7884 | 8378 |
7885 /** | 8379 /** |
7886 * Initialize the types provided by this type provider from the given library. | 8380 * Initialize the types provided by this type provider from the given library. |
| 8381 * |
7887 * @param library the library containing the definitions of the core types | 8382 * @param library the library containing the definitions of the core types |
7888 */ | 8383 */ |
7889 void initializeFrom(LibraryElement library) { | 8384 void initializeFrom(LibraryElement library) { |
7890 Namespace namespace = new NamespaceBuilder().createPublicNamespace(library); | 8385 Namespace namespace = new NamespaceBuilder().createPublicNamespace(library); |
7891 _boolType = getType(namespace, "bool"); | 8386 _boolType = getType(namespace, "bool"); |
7892 _bottomType = BottomTypeImpl.instance; | 8387 _bottomType = BottomTypeImpl.instance; |
7893 _doubleType = getType(namespace, "double"); | 8388 _doubleType = getType(namespace, "double"); |
7894 _dynamicType = DynamicTypeImpl.instance; | 8389 _dynamicType = DynamicTypeImpl.instance; |
7895 _functionType = getType(namespace, "Function"); | 8390 _functionType = getType(namespace, "Function"); |
7896 _intType = getType(namespace, "int"); | 8391 _intType = getType(namespace, "int"); |
7897 _listType = getType(namespace, "List"); | 8392 _listType = getType(namespace, "List"); |
7898 _mapType = getType(namespace, "Map"); | 8393 _mapType = getType(namespace, "Map"); |
7899 _numType = getType(namespace, "num"); | 8394 _numType = getType(namespace, "num"); |
7900 _objectType = getType(namespace, "Object"); | 8395 _objectType = getType(namespace, "Object"); |
7901 _stackTraceType = getType(namespace, "StackTrace"); | 8396 _stackTraceType = getType(namespace, "StackTrace"); |
7902 _stringType = getType(namespace, "String"); | 8397 _stringType = getType(namespace, "String"); |
| 8398 _symbolType = getType(namespace, "Symbol"); |
7903 _typeType = getType(namespace, "Type"); | 8399 _typeType = getType(namespace, "Type"); |
7904 } | 8400 } |
7905 } | 8401 } |
7906 /** | 8402 /** |
7907 * Instances of the class `TypeResolverVisitor` are used to resolve the types as
sociated with | 8403 * Instances of the class `TypeResolverVisitor` are used to resolve the types as
sociated with |
7908 * the elements in the element model. This includes the types of superclasses, m
ixins, interfaces, | 8404 * the elements in the element model. This includes the types of superclasses, m
ixins, interfaces, |
7909 * fields, methods, parameters, and local variables. As a side-effect, this also
finishes building | 8405 * fields, methods, parameters, and local variables. As a side-effect, this also
finishes building |
7910 * the type hierarchy. | 8406 * the type hierarchy. |
| 8407 * |
7911 * @coverage dart.engine.resolver | 8408 * @coverage dart.engine.resolver |
7912 */ | 8409 */ |
7913 class TypeResolverVisitor extends ScopedVisitor { | 8410 class TypeResolverVisitor extends ScopedVisitor { |
7914 | 8411 |
7915 /** | 8412 /** |
7916 * The type representing the type 'dynamic'. | 8413 * The type representing the type 'dynamic'. |
7917 */ | 8414 */ |
7918 Type2 _dynamicType; | 8415 Type2 _dynamicType; |
7919 | 8416 |
7920 /** | 8417 /** |
7921 * The flag specifying if currently visited class references 'super' expressio
n. | 8418 * The flag specifying if currently visited class references 'super' expressio
n. |
7922 */ | 8419 */ |
7923 bool _hasReferenceToSuper = false; | 8420 bool _hasReferenceToSuper = false; |
7924 | 8421 |
7925 /** | 8422 /** |
7926 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 8423 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 8424 * |
7927 * @param library the library containing the compilation unit being resolved | 8425 * @param library the library containing the compilation unit being resolved |
7928 * @param source the source representing the compilation unit being visited | 8426 * @param source the source representing the compilation unit being visited |
7929 * @param typeProvider the object used to access the types from the core libra
ry | 8427 * @param typeProvider the object used to access the types from the core libra
ry |
7930 */ | 8428 */ |
7931 TypeResolverVisitor.con1(Library library, Source source, TypeProvider typeProv
ider) : super.con1(library, source, typeProvider) { | 8429 TypeResolverVisitor.con1(Library library, Source source, TypeProvider typeProv
ider) : super.con1(library, source, typeProvider) { |
7932 _jtd_constructor_282_impl(library, source, typeProvider); | 8430 _jtd_constructor_282_impl(library, source, typeProvider); |
7933 } | 8431 } |
7934 _jtd_constructor_282_impl(Library library, Source source, TypeProvider typePro
vider) { | 8432 _jtd_constructor_282_impl(Library library, Source source, TypeProvider typePro
vider) { |
7935 _dynamicType = typeProvider.dynamicType; | 8433 _dynamicType = typeProvider.dynamicType; |
7936 } | 8434 } |
7937 | 8435 |
7938 /** | 8436 /** |
7939 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 8437 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 8438 * |
7940 * @param definingLibrary the element for the library containing the compilati
on unit being | 8439 * @param definingLibrary the element for the library containing the compilati
on unit being |
7941 * visited | 8440 * visited |
7942 * @param source the source representing the compilation unit being visited | 8441 * @param source the source representing the compilation unit being visited |
7943 * @param typeProvider the object used to access the types from the core libra
ry | 8442 * @param typeProvider the object used to access the types from the core libra
ry |
7944 * @param errorListener the error listener that will be informed of any errors
that are found | 8443 * @param errorListener the error listener that will be informed of any errors
that are found |
7945 * during resolution | 8444 * during resolution |
7946 */ | 8445 */ |
7947 TypeResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypePr
ovider typeProvider, AnalysisErrorListener errorListener) : super.con2(definingL
ibrary, source, typeProvider, errorListener) { | 8446 TypeResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypePr
ovider typeProvider, AnalysisErrorListener errorListener) : super.con2(definingL
ibrary, source, typeProvider, errorListener) { |
7948 _jtd_constructor_283_impl(definingLibrary, source, typeProvider, errorListen
er); | 8447 _jtd_constructor_283_impl(definingLibrary, source, typeProvider, errorListen
er); |
7949 } | 8448 } |
7950 _jtd_constructor_283_impl(LibraryElement definingLibrary, Source source, TypeP
rovider typeProvider, AnalysisErrorListener errorListener) { | 8449 _jtd_constructor_283_impl(LibraryElement definingLibrary, Source source, TypeP
rovider typeProvider, AnalysisErrorListener errorListener) { |
7951 _dynamicType = typeProvider.dynamicType; | 8450 _dynamicType = typeProvider.dynamicType; |
7952 } | 8451 } |
7953 Object visitCatchClause(CatchClause node) { | 8452 Object visitCatchClause(CatchClause node) { |
7954 super.visitCatchClause(node); | 8453 super.visitCatchClause(node); |
7955 SimpleIdentifier exception = node.exceptionParameter; | 8454 SimpleIdentifier exception = node.exceptionParameter; |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8169 if (argumentList != null) { | 8668 if (argumentList != null) { |
8170 } | 8669 } |
8171 typeName.staticType = voidType; | 8670 typeName.staticType = voidType; |
8172 node.type = voidType; | 8671 node.type = voidType; |
8173 return null; | 8672 return null; |
8174 } | 8673 } |
8175 ASTNode parent = node.parent; | 8674 ASTNode parent = node.parent; |
8176 if (typeName is PrefixedIdentifier && parent is ConstructorName && argumen
tList == null) { | 8675 if (typeName is PrefixedIdentifier && parent is ConstructorName && argumen
tList == null) { |
8177 ConstructorName name = parent as ConstructorName; | 8676 ConstructorName name = parent as ConstructorName; |
8178 if (name.name == null) { | 8677 if (name.name == null) { |
8179 SimpleIdentifier prefix = ((typeName as PrefixedIdentifier)).prefix; | 8678 PrefixedIdentifier prefixedIdentifier = typeName as PrefixedIdentifier
; |
| 8679 SimpleIdentifier prefix = prefixedIdentifier.prefix; |
8180 element = nameScope.lookup(prefix, definingLibrary); | 8680 element = nameScope.lookup(prefix, definingLibrary); |
8181 if (element is PrefixElement) { | 8681 if (element is PrefixElement) { |
| 8682 if (parent.parent is InstanceCreationExpression && ((parent.parent a
s InstanceCreationExpression)).isConst) { |
| 8683 reportError(CompileTimeErrorCode.CONST_WITH_NON_TYPE, prefixedIden
tifier.identifier, [prefixedIdentifier.identifier.name]); |
| 8684 } else { |
| 8685 reportError(StaticWarningCode.NEW_WITH_NON_TYPE, prefixedIdentifie
r.identifier, [prefixedIdentifier.identifier.name]); |
| 8686 } |
8182 return null; | 8687 return null; |
8183 } else if (element != null) { | 8688 } else if (element != null) { |
8184 name.name = ((typeName as PrefixedIdentifier)).identifier; | 8689 name.name = prefixedIdentifier.identifier; |
8185 name.period = ((typeName as PrefixedIdentifier)).period; | 8690 name.period = prefixedIdentifier.period; |
8186 node.name = prefix; | 8691 node.name = prefix; |
8187 typeName = prefix; | 8692 typeName = prefix; |
8188 } | 8693 } |
8189 } | 8694 } |
8190 } | 8695 } |
8191 } | 8696 } |
8192 bool elementValid = element is! MultiplyDefinedElement; | 8697 bool elementValid = element is! MultiplyDefinedElement; |
8193 if (elementValid && element is! ClassElement && isTypeNameInInstanceCreation
Expression(node)) { | 8698 if (elementValid && element is! ClassElement && isTypeNameInInstanceCreation
Expression(node)) { |
8194 SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName); | 8699 SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName); |
8195 InstanceCreationExpression creation = node.parent.parent as InstanceCreati
onExpression; | 8700 InstanceCreationExpression creation = node.parent.parent as InstanceCreati
onExpression; |
(...skipping 16 matching lines...) Expand all Loading... |
8212 if (typeNameSimple.name == "boolean") { | 8717 if (typeNameSimple.name == "boolean") { |
8213 reportError(StaticWarningCode.UNDEFINED_CLASS_BOOLEAN, typeNameSimple, [
]); | 8718 reportError(StaticWarningCode.UNDEFINED_CLASS_BOOLEAN, typeNameSimple, [
]); |
8214 } else if (isTypeNameInCatchClause(node)) { | 8719 } else if (isTypeNameInCatchClause(node)) { |
8215 reportError(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [typeN
ame.name]); | 8720 reportError(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [typeN
ame.name]); |
8216 } else if (isTypeNameInAsExpression(node)) { | 8721 } else if (isTypeNameInAsExpression(node)) { |
8217 reportError(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.name
]); | 8722 reportError(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.name
]); |
8218 } else if (isTypeNameInIsExpression(node)) { | 8723 } else if (isTypeNameInIsExpression(node)) { |
8219 reportError(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [typeName.na
me]); | 8724 reportError(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [typeName.na
me]); |
8220 } else if (isTypeNameTargetInRedirectedConstructor(node)) { | 8725 } else if (isTypeNameTargetInRedirectedConstructor(node)) { |
8221 reportError(StaticWarningCode.REDIRECT_TO_NON_CLASS, typeName, [typeName
.name]); | 8726 reportError(StaticWarningCode.REDIRECT_TO_NON_CLASS, typeName, [typeName
.name]); |
| 8727 } else if (isTypeNameInTypeArgumentList(node)) { |
| 8728 reportError(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, typeName, [
typeName.name]); |
8222 } else { | 8729 } else { |
8223 reportError(StaticWarningCode.UNDEFINED_CLASS, typeName, [typeName.name]
); | 8730 reportError(StaticWarningCode.UNDEFINED_CLASS, typeName, [typeName.name]
); |
8224 } | 8731 } |
8225 elementValid = false; | 8732 elementValid = false; |
8226 } | 8733 } |
8227 if (!elementValid) { | 8734 if (!elementValid) { |
8228 setElement(typeName, _dynamicType.element); | 8735 setElement(typeName, _dynamicType.element); |
8229 typeName.staticType = _dynamicType; | 8736 typeName.staticType = _dynamicType; |
8230 node.type = _dynamicType; | 8737 node.type = _dynamicType; |
8231 return null; | 8738 return null; |
(...skipping 16 matching lines...) Expand all Loading... |
8248 if (type != null) { | 8755 if (type != null) { |
8249 node.type = type; | 8756 node.type = type; |
8250 } | 8757 } |
8251 } else { | 8758 } else { |
8252 if (isTypeNameInCatchClause(node)) { | 8759 if (isTypeNameInCatchClause(node)) { |
8253 reportError(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [typeN
ame.name]); | 8760 reportError(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [typeN
ame.name]); |
8254 } else if (isTypeNameInAsExpression(node)) { | 8761 } else if (isTypeNameInAsExpression(node)) { |
8255 reportError(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.name
]); | 8762 reportError(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.name
]); |
8256 } else if (isTypeNameInIsExpression(node)) { | 8763 } else if (isTypeNameInIsExpression(node)) { |
8257 reportError(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [typeName.na
me]); | 8764 reportError(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [typeName.na
me]); |
| 8765 } else if (isTypeNameTargetInRedirectedConstructor(node)) { |
| 8766 reportError(StaticWarningCode.REDIRECT_TO_NON_CLASS, typeName, [typeName
.name]); |
| 8767 } else if (isTypeNameInTypeArgumentList(node)) { |
| 8768 reportError(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, typeName, [
typeName.name]); |
8258 } else { | 8769 } else { |
8259 ASTNode parent = typeName.parent; | 8770 ASTNode parent = typeName.parent; |
8260 while (parent is TypeName) { | 8771 while (parent is TypeName) { |
8261 parent = parent.parent; | 8772 parent = parent.parent; |
8262 } | 8773 } |
8263 if (parent is ExtendsClause || parent is ImplementsClause || parent is W
ithClause || parent is ClassTypeAlias) { | 8774 if (parent is ExtendsClause || parent is ImplementsClause || parent is W
ithClause || parent is ClassTypeAlias) { |
8264 } else { | 8775 } else { |
8265 reportError(StaticWarningCode.NOT_A_TYPE, typeName, [typeName.name]); | 8776 reportError(StaticWarningCode.NOT_A_TYPE, typeName, [typeName.name]); |
8266 } | 8777 } |
8267 } | 8778 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8350 } | 8861 } |
8351 } | 8862 } |
8352 } else { | 8863 } else { |
8353 } | 8864 } |
8354 return null; | 8865 return null; |
8355 } | 8866 } |
8356 | 8867 |
8357 /** | 8868 /** |
8358 * Given a type name representing the return type of a function, compute the r
eturn type of the | 8869 * Given a type name representing the return type of a function, compute the r
eturn type of the |
8359 * function. | 8870 * function. |
| 8871 * |
8360 * @param returnType the type name representing the return type of the functio
n | 8872 * @param returnType the type name representing the return type of the functio
n |
8361 * @return the return type that was computed | 8873 * @return the return type that was computed |
8362 */ | 8874 */ |
8363 Type2 computeReturnType(TypeName returnType) { | 8875 Type2 computeReturnType(TypeName returnType) { |
8364 if (returnType == null) { | 8876 if (returnType == null) { |
8365 return _dynamicType; | 8877 return _dynamicType; |
8366 } else { | 8878 } else { |
8367 return returnType.type; | 8879 return returnType.type; |
8368 } | 8880 } |
8369 } | 8881 } |
8370 | 8882 |
8371 /** | 8883 /** |
8372 * Return the class element that represents the class whose name was provided. | 8884 * Return the class element that represents the class whose name was provided. |
| 8885 * |
8373 * @param identifier the name from the declaration of a class | 8886 * @param identifier the name from the declaration of a class |
8374 * @return the class element that represents the class | 8887 * @return the class element that represents the class |
8375 */ | 8888 */ |
8376 ClassElementImpl getClassElement(SimpleIdentifier identifier) { | 8889 ClassElementImpl getClassElement(SimpleIdentifier identifier) { |
8377 if (identifier == null) { | 8890 if (identifier == null) { |
8378 return null; | 8891 return null; |
8379 } | 8892 } |
8380 Element element = identifier.element; | 8893 Element element = identifier.element; |
8381 if (element is! ClassElementImpl) { | 8894 if (element is! ClassElementImpl) { |
8382 return null; | 8895 return null; |
8383 } | 8896 } |
8384 return element as ClassElementImpl; | 8897 return element as ClassElementImpl; |
8385 } | 8898 } |
8386 | 8899 |
8387 /** | 8900 /** |
8388 * Return an array containing all of the elements associated with the paramete
rs in the given | 8901 * Return an array containing all of the elements associated with the paramete
rs in the given |
8389 * list. | 8902 * list. |
| 8903 * |
8390 * @param parameterList the list of parameters whose elements are to be return
ed | 8904 * @param parameterList the list of parameters whose elements are to be return
ed |
8391 * @return the elements associated with the parameters | 8905 * @return the elements associated with the parameters |
8392 */ | 8906 */ |
8393 List<ParameterElement> getElements(FormalParameterList parameterList) { | 8907 List<ParameterElement> getElements(FormalParameterList parameterList) { |
8394 List<ParameterElement> elements = new List<ParameterElement>(); | 8908 List<ParameterElement> elements = new List<ParameterElement>(); |
8395 for (FormalParameter parameter in parameterList.parameters) { | 8909 for (FormalParameter parameter in parameterList.parameters) { |
8396 ParameterElement element = parameter.identifier.element as ParameterElemen
t; | 8910 ParameterElement element = parameter.identifier.element as ParameterElemen
t; |
8397 if (element != null) { | 8911 if (element != null) { |
8398 elements.add(element); | 8912 elements.add(element); |
8399 } | 8913 } |
8400 } | 8914 } |
8401 return new List.from(elements); | 8915 return new List.from(elements); |
8402 } | 8916 } |
8403 | 8917 |
8404 /** | 8918 /** |
8405 * The number of type arguments in the given type name does not match the numb
er of parameters in | 8919 * The number of type arguments in the given type name does not match the numb
er of parameters in |
8406 * the corresponding class element. Return the error code that should be used
to report this | 8920 * the corresponding class element. Return the error code that should be used
to report this |
8407 * error. | 8921 * error. |
| 8922 * |
8408 * @param node the type name with the wrong number of type arguments | 8923 * @param node the type name with the wrong number of type arguments |
8409 * @return the error code that should be used to report that the wrong number
of type arguments | 8924 * @return the error code that should be used to report that the wrong number
of type arguments |
8410 * were provided | 8925 * were provided |
8411 */ | 8926 */ |
8412 ErrorCode getInvalidTypeParametersErrorCode(TypeName node) { | 8927 ErrorCode getInvalidTypeParametersErrorCode(TypeName node) { |
8413 ASTNode parent = node.parent; | 8928 ASTNode parent = node.parent; |
8414 if (parent is ConstructorName) { | 8929 if (parent is ConstructorName) { |
8415 parent = parent.parent; | 8930 parent = parent.parent; |
8416 if (parent is InstanceCreationExpression) { | 8931 if (parent is InstanceCreationExpression) { |
8417 if (((parent as InstanceCreationExpression)).isConst) { | 8932 if (((parent as InstanceCreationExpression)).isConst) { |
8418 return CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS; | 8933 return CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS; |
8419 } else { | 8934 } else { |
8420 return CompileTimeErrorCode.NEW_WITH_INVALID_TYPE_PARAMETERS; | 8935 return CompileTimeErrorCode.NEW_WITH_INVALID_TYPE_PARAMETERS; |
8421 } | 8936 } |
8422 } | 8937 } |
8423 } | 8938 } |
8424 return StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS; | 8939 return StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS; |
8425 } | 8940 } |
8426 | 8941 |
8427 /** | 8942 /** |
8428 * Given the multiple elements to which a single name could potentially be res
olved, return the | 8943 * Given the multiple elements to which a single name could potentially be res
olved, return the |
8429 * single interface type that should be used, or `null` if there is no clear c
hoice. | 8944 * single interface type that should be used, or `null` if there is no clear c
hoice. |
| 8945 * |
8430 * @param elements the elements to which a single name could potentially be re
solved | 8946 * @param elements the elements to which a single name could potentially be re
solved |
8431 * @return the single interface type that should be used for the type name | 8947 * @return the single interface type that should be used for the type name |
8432 */ | 8948 */ |
8433 InterfaceType getType(List<Element> elements) { | 8949 InterfaceType getType(List<Element> elements) { |
8434 InterfaceType type = null; | 8950 InterfaceType type = null; |
8435 for (Element element in elements) { | 8951 for (Element element in elements) { |
8436 if (element is ClassElement) { | 8952 if (element is ClassElement) { |
8437 if (type != null) { | 8953 if (type != null) { |
8438 return null; | 8954 return null; |
8439 } | 8955 } |
8440 type = ((element as ClassElement)).type; | 8956 type = ((element as ClassElement)).type; |
8441 } | 8957 } |
8442 } | 8958 } |
8443 return type; | 8959 return type; |
8444 } | 8960 } |
8445 | 8961 |
8446 /** | 8962 /** |
8447 * Return the type represented by the given type name. | 8963 * Return the type represented by the given type name. |
| 8964 * |
8448 * @param typeName the type name representing the type to be returned | 8965 * @param typeName the type name representing the type to be returned |
8449 * @return the type represented by the type name | 8966 * @return the type represented by the type name |
8450 */ | 8967 */ |
8451 Type2 getType3(TypeName typeName) { | 8968 Type2 getType3(TypeName typeName) { |
8452 Type2 type = typeName.type; | 8969 Type2 type = typeName.type; |
8453 if (type == null) { | 8970 if (type == null) { |
8454 return _dynamicType; | 8971 return _dynamicType; |
8455 } | 8972 } |
8456 return type; | 8973 return type; |
8457 } | 8974 } |
8458 | 8975 |
8459 /** | 8976 /** |
8460 * Return the type arguments associated with the given type. | 8977 * Return the type arguments associated with the given type. |
| 8978 * |
8461 * @param type the type whole type arguments are to be returned | 8979 * @param type the type whole type arguments are to be returned |
8462 * @return the type arguments associated with the given type | 8980 * @return the type arguments associated with the given type |
8463 */ | 8981 */ |
8464 List<Type2> getTypeArguments(Type2 type) { | 8982 List<Type2> getTypeArguments(Type2 type) { |
8465 if (type is InterfaceType) { | 8983 if (type is InterfaceType) { |
8466 return ((type as InterfaceType)).typeArguments; | 8984 return ((type as InterfaceType)).typeArguments; |
8467 } else if (type is FunctionType) { | 8985 } else if (type is FunctionType) { |
8468 return ((type as FunctionType)).typeArguments; | 8986 return ((type as FunctionType)).typeArguments; |
8469 } | 8987 } |
8470 return TypeImpl.EMPTY_ARRAY; | 8988 return TypeImpl.EMPTY_ARRAY; |
8471 } | 8989 } |
8472 | 8990 |
8473 /** | 8991 /** |
8474 * Returns the simple identifier of the given (may be qualified) type name. | 8992 * Returns the simple identifier of the given (may be qualified) type name. |
| 8993 * |
8475 * @param typeName the (may be qualified) qualified type name | 8994 * @param typeName the (may be qualified) qualified type name |
8476 * @return the simple identifier of the given (may be qualified) type name. | 8995 * @return the simple identifier of the given (may be qualified) type name. |
8477 */ | 8996 */ |
8478 SimpleIdentifier getTypeSimpleIdentifier(Identifier typeName) { | 8997 SimpleIdentifier getTypeSimpleIdentifier(Identifier typeName) { |
8479 if (typeName is SimpleIdentifier) { | 8998 if (typeName is SimpleIdentifier) { |
8480 return typeName as SimpleIdentifier; | 8999 return typeName as SimpleIdentifier; |
8481 } else { | 9000 } else { |
8482 return ((typeName as PrefixedIdentifier)).identifier; | 9001 return ((typeName as PrefixedIdentifier)).identifier; |
8483 } | 9002 } |
8484 } | 9003 } |
8485 | 9004 |
8486 /** | 9005 /** |
8487 * Checks if the given type name is used as the type in an as expression. | 9006 * Checks if the given type name is used as the type in an as expression. |
| 9007 * |
8488 * @param typeName the type name to analyzer | 9008 * @param typeName the type name to analyzer |
8489 * @return `true` if the given type name is used as the type in an as expressi
on | 9009 * @return `true` if the given type name is used as the type in an as expressi
on |
8490 */ | 9010 */ |
8491 bool isTypeNameInAsExpression(TypeName typeName) { | 9011 bool isTypeNameInAsExpression(TypeName typeName) { |
8492 ASTNode parent = typeName.parent; | 9012 ASTNode parent = typeName.parent; |
8493 if (parent is AsExpression) { | 9013 if (parent is AsExpression) { |
8494 AsExpression asExpression = parent as AsExpression; | 9014 AsExpression asExpression = parent as AsExpression; |
8495 return identical(asExpression.type, typeName); | 9015 return identical(asExpression.type, typeName); |
8496 } | 9016 } |
8497 return false; | 9017 return false; |
8498 } | 9018 } |
8499 | 9019 |
8500 /** | 9020 /** |
8501 * Checks if the given type name is used as the exception type in a catch clau
se. | 9021 * Checks if the given type name is used as the exception type in a catch clau
se. |
| 9022 * |
8502 * @param typeName the type name to analyzer | 9023 * @param typeName the type name to analyzer |
8503 * @return `true` if the given type name is used as the exception type in a ca
tch clause | 9024 * @return `true` if the given type name is used as the exception type in a ca
tch clause |
8504 */ | 9025 */ |
8505 bool isTypeNameInCatchClause(TypeName typeName) { | 9026 bool isTypeNameInCatchClause(TypeName typeName) { |
8506 ASTNode parent = typeName.parent; | 9027 ASTNode parent = typeName.parent; |
8507 if (parent is CatchClause) { | 9028 if (parent is CatchClause) { |
8508 CatchClause catchClause = parent as CatchClause; | 9029 CatchClause catchClause = parent as CatchClause; |
8509 return identical(catchClause.exceptionType, typeName); | 9030 return identical(catchClause.exceptionType, typeName); |
8510 } | 9031 } |
8511 return false; | 9032 return false; |
8512 } | 9033 } |
8513 | 9034 |
8514 /** | 9035 /** |
8515 * Checks if the given type name is used as the type in an instance creation e
xpression. | 9036 * Checks if the given type name is used as the type in an instance creation e
xpression. |
| 9037 * |
8516 * @param typeName the type name to analyzer | 9038 * @param typeName the type name to analyzer |
8517 * @return `true` if the given type name is used as the type in an instance cr
eation | 9039 * @return `true` if the given type name is used as the type in an instance cr
eation |
8518 * expression | 9040 * expression |
8519 */ | 9041 */ |
8520 bool isTypeNameInInstanceCreationExpression(TypeName typeName) { | 9042 bool isTypeNameInInstanceCreationExpression(TypeName typeName) { |
8521 ASTNode parent = typeName.parent; | 9043 ASTNode parent = typeName.parent; |
8522 if (parent is ConstructorName && parent.parent is InstanceCreationExpression
) { | 9044 if (parent is ConstructorName && parent.parent is InstanceCreationExpression
) { |
8523 ConstructorName constructorName = parent as ConstructorName; | 9045 ConstructorName constructorName = parent as ConstructorName; |
8524 return constructorName != null && identical(constructorName.type, typeName
); | 9046 return constructorName != null && identical(constructorName.type, typeName
); |
8525 } | 9047 } |
8526 return false; | 9048 return false; |
8527 } | 9049 } |
8528 | 9050 |
8529 /** | 9051 /** |
8530 * Checks if the given type name is used as the type in an is expression. | 9052 * Checks if the given type name is used as the type in an is expression. |
| 9053 * |
8531 * @param typeName the type name to analyzer | 9054 * @param typeName the type name to analyzer |
8532 * @return `true` if the given type name is used as the type in an is expressi
on | 9055 * @return `true` if the given type name is used as the type in an is expressi
on |
8533 */ | 9056 */ |
8534 bool isTypeNameInIsExpression(TypeName typeName) { | 9057 bool isTypeNameInIsExpression(TypeName typeName) { |
8535 ASTNode parent = typeName.parent; | 9058 ASTNode parent = typeName.parent; |
8536 if (parent is IsExpression) { | 9059 if (parent is IsExpression) { |
8537 IsExpression isExpression = parent as IsExpression; | 9060 IsExpression isExpression = parent as IsExpression; |
8538 return identical(isExpression.type, typeName); | 9061 return identical(isExpression.type, typeName); |
8539 } | 9062 } |
8540 return false; | 9063 return false; |
8541 } | 9064 } |
8542 | 9065 |
8543 /** | 9066 /** |
| 9067 * Checks if the given type name used in a type argument list. |
| 9068 * |
| 9069 * @param typeName the type name to analyzer |
| 9070 * @return `true` if the given type name is in a type argument list |
| 9071 */ |
| 9072 bool isTypeNameInTypeArgumentList(TypeName typeName) => typeName.parent is Typ
eArgumentList; |
| 9073 |
| 9074 /** |
8544 * Checks if the given type name is the target in a redirected constructor. | 9075 * Checks if the given type name is the target in a redirected constructor. |
| 9076 * |
8545 * @param typeName the type name to analyzer | 9077 * @param typeName the type name to analyzer |
8546 * @return `true` if the given type name is used as the type in a redirected c
onstructor | 9078 * @return `true` if the given type name is used as the type in a redirected c
onstructor |
8547 */ | 9079 */ |
8548 bool isTypeNameTargetInRedirectedConstructor(TypeName typeName) { | 9080 bool isTypeNameTargetInRedirectedConstructor(TypeName typeName) { |
8549 ASTNode parent = typeName.parent; | 9081 ASTNode parent = typeName.parent; |
8550 if (parent is ConstructorName) { | 9082 if (parent is ConstructorName) { |
8551 ConstructorName constructorName = parent as ConstructorName; | 9083 ConstructorName constructorName = parent as ConstructorName; |
8552 parent = constructorName.parent; | 9084 parent = constructorName.parent; |
8553 if (parent is ConstructorDeclaration) { | 9085 if (parent is ConstructorDeclaration) { |
8554 ConstructorDeclaration constructorDeclaration = parent as ConstructorDec
laration; | 9086 ConstructorDeclaration constructorDeclaration = parent as ConstructorDec
laration; |
8555 return constructorName == constructorDeclaration.redirectedConstructor; | 9087 return constructorName == constructorDeclaration.redirectedConstructor; |
8556 } | 9088 } |
8557 } | 9089 } |
8558 return false; | 9090 return false; |
8559 } | 9091 } |
8560 | 9092 |
8561 /** | 9093 /** |
8562 * Record that the static type of the given node is the given type. | 9094 * Record that the static type of the given node is the given type. |
| 9095 * |
8563 * @param expression the node whose type is to be recorded | 9096 * @param expression the node whose type is to be recorded |
8564 * @param type the static type of the node | 9097 * @param type the static type of the node |
8565 */ | 9098 */ |
8566 Object recordType(Expression expression, Type2 type) { | 9099 Object recordType(Expression expression, Type2 type) { |
8567 if (type == null) { | 9100 if (type == null) { |
8568 expression.staticType = _dynamicType; | 9101 expression.staticType = _dynamicType; |
8569 } else { | 9102 } else { |
8570 expression.staticType = type; | 9103 expression.staticType = type; |
8571 } | 9104 } |
8572 return null; | 9105 return null; |
8573 } | 9106 } |
8574 | 9107 |
8575 /** | 9108 /** |
8576 * Resolve the types in the given with and implements clauses and associate th
ose types with the | 9109 * Resolve the types in the given with and implements clauses and associate th
ose types with the |
8577 * given class element. | 9110 * given class element. |
| 9111 * |
8578 * @param classElement the class element with which the mixin and interface ty
pes are to be | 9112 * @param classElement the class element with which the mixin and interface ty
pes are to be |
8579 * associated | 9113 * associated |
8580 * @param withClause the with clause to be resolved | 9114 * @param withClause the with clause to be resolved |
8581 * @param implementsClause the implements clause to be resolved | 9115 * @param implementsClause the implements clause to be resolved |
8582 */ | 9116 */ |
8583 void resolve(ClassElementImpl classElement, WithClause withClause, ImplementsC
lause implementsClause) { | 9117 void resolve(ClassElementImpl classElement, WithClause withClause, ImplementsC
lause implementsClause) { |
8584 if (withClause != null) { | 9118 if (withClause != null) { |
8585 List<InterfaceType> mixinTypes = resolveTypes(withClause.mixinTypes, Compi
leTimeErrorCode.MIXIN_OF_NON_CLASS); | 9119 List<InterfaceType> mixinTypes = resolveTypes(withClause.mixinTypes, Compi
leTimeErrorCode.MIXIN_OF_NON_CLASS); |
8586 if (classElement != null) { | 9120 if (classElement != null) { |
8587 classElement.mixins = mixinTypes; | 9121 classElement.mixins = mixinTypes; |
8588 } | 9122 } |
8589 } | 9123 } |
(...skipping 27 matching lines...) Expand all Loading... |
8617 } | 9151 } |
8618 } | 9152 } |
8619 if (classElement != null) { | 9153 if (classElement != null) { |
8620 classElement.interfaces = interfaceTypes; | 9154 classElement.interfaces = interfaceTypes; |
8621 } | 9155 } |
8622 } | 9156 } |
8623 } | 9157 } |
8624 | 9158 |
8625 /** | 9159 /** |
8626 * Return the type specified by the given name. | 9160 * Return the type specified by the given name. |
| 9161 * |
8627 * @param typeName the type name specifying the type to be returned | 9162 * @param typeName the type name specifying the type to be returned |
8628 * @param nonTypeError the error to produce if the type name is defined to be
something other than | 9163 * @param nonTypeError the error to produce if the type name is defined to be
something other than |
8629 * a type | 9164 * a type |
8630 * @return the type specified by the type name | 9165 * @return the type specified by the type name |
8631 */ | 9166 */ |
8632 InterfaceType resolveType(TypeName typeName, ErrorCode nonTypeError) { | 9167 InterfaceType resolveType(TypeName typeName, ErrorCode nonTypeError) { |
8633 Type2 type = typeName.type; | 9168 Type2 type = typeName.type; |
8634 if (type is InterfaceType) { | 9169 if (type is InterfaceType) { |
8635 return type as InterfaceType; | 9170 return type as InterfaceType; |
8636 } | 9171 } |
8637 Identifier name = typeName.name; | 9172 Identifier name = typeName.name; |
8638 if (name.name != sc.Keyword.DYNAMIC.syntax) { | 9173 if (name.name != sc.Keyword.DYNAMIC.syntax) { |
8639 reportError(nonTypeError, name, [name.name]); | 9174 reportError(nonTypeError, name, [name.name]); |
8640 } | 9175 } |
8641 return null; | 9176 return null; |
8642 } | 9177 } |
8643 | 9178 |
8644 /** | 9179 /** |
8645 * Resolve the types in the given list of type names. | 9180 * Resolve the types in the given list of type names. |
| 9181 * |
8646 * @param typeNames the type names to be resolved | 9182 * @param typeNames the type names to be resolved |
8647 * @param nonTypeError the error to produce if the type name is defined to be
something other than | 9183 * @param nonTypeError the error to produce if the type name is defined to be
something other than |
8648 * a type | 9184 * a type |
8649 * @return an array containing all of the types that were resolved. | 9185 * @return an array containing all of the types that were resolved. |
8650 */ | 9186 */ |
8651 List<InterfaceType> resolveTypes(NodeList<TypeName> typeNames, ErrorCode nonTy
peError) { | 9187 List<InterfaceType> resolveTypes(NodeList<TypeName> typeNames, ErrorCode nonTy
peError) { |
8652 List<InterfaceType> types = new List<InterfaceType>(); | 9188 List<InterfaceType> types = new List<InterfaceType>(); |
8653 for (TypeName typeName in typeNames) { | 9189 for (TypeName typeName in typeNames) { |
8654 InterfaceType type = resolveType(typeName, nonTypeError); | 9190 InterfaceType type = resolveType(typeName, nonTypeError); |
8655 if (type != null) { | 9191 if (type != null) { |
8656 types.add(type); | 9192 types.add(type); |
8657 } | 9193 } |
8658 } | 9194 } |
(...skipping 14 matching lines...) Expand all Loading... |
8673 prefix.staticElement = prefixElement; | 9209 prefix.staticElement = prefixElement; |
8674 prefix.element = prefixElement; | 9210 prefix.element = prefixElement; |
8675 } | 9211 } |
8676 } | 9212 } |
8677 } | 9213 } |
8678 } | 9214 } |
8679 | 9215 |
8680 /** | 9216 /** |
8681 * Set the return type and parameter type information for the given function t
ype based on the | 9217 * Set the return type and parameter type information for the given function t
ype based on the |
8682 * given return type and parameter elements. | 9218 * given return type and parameter elements. |
| 9219 * |
8683 * @param functionType the function type to be filled in | 9220 * @param functionType the function type to be filled in |
8684 * @param parameters the elements representing the parameters to the function | 9221 * @param parameters the elements representing the parameters to the function |
8685 */ | 9222 */ |
8686 void setTypeInformation(FunctionTypeImpl functionType, List<ParameterElement>
parameters) { | 9223 void setTypeInformation(FunctionTypeImpl functionType, List<ParameterElement>
parameters) { |
8687 List<Type2> normalParameterTypes = new List<Type2>(); | 9224 List<Type2> normalParameterTypes = new List<Type2>(); |
8688 List<Type2> optionalParameterTypes = new List<Type2>(); | 9225 List<Type2> optionalParameterTypes = new List<Type2>(); |
8689 LinkedHashMap<String, Type2> namedParameterTypes = new LinkedHashMap<String,
Type2>(); | 9226 LinkedHashMap<String, Type2> namedParameterTypes = new LinkedHashMap<String,
Type2>(); |
8690 for (ParameterElement parameter in parameters) { | 9227 for (ParameterElement parameter in parameters) { |
8691 while (true) { | 9228 while (true) { |
8692 if (parameter.parameterKind == ParameterKind.REQUIRED) { | 9229 if (parameter.parameterKind == ParameterKind.REQUIRED) { |
(...skipping 12 matching lines...) Expand all Loading... |
8705 if (!optionalParameterTypes.isEmpty) { | 9242 if (!optionalParameterTypes.isEmpty) { |
8706 functionType.optionalParameterTypes = new List.from(optionalParameterTypes
); | 9243 functionType.optionalParameterTypes = new List.from(optionalParameterTypes
); |
8707 } | 9244 } |
8708 if (!namedParameterTypes.isEmpty) { | 9245 if (!namedParameterTypes.isEmpty) { |
8709 functionType.namedParameterTypes = namedParameterTypes; | 9246 functionType.namedParameterTypes = namedParameterTypes; |
8710 } | 9247 } |
8711 } | 9248 } |
8712 } | 9249 } |
8713 /** | 9250 /** |
8714 * Instances of the class `ClassScope` implement the scope defined by a class. | 9251 * Instances of the class `ClassScope` implement the scope defined by a class. |
| 9252 * |
8715 * @coverage dart.engine.resolver | 9253 * @coverage dart.engine.resolver |
8716 */ | 9254 */ |
8717 class ClassScope extends EnclosedScope { | 9255 class ClassScope extends EnclosedScope { |
8718 | 9256 |
8719 /** | 9257 /** |
8720 * Initialize a newly created scope enclosed within another scope. | 9258 * Initialize a newly created scope enclosed within another scope. |
| 9259 * |
8721 * @param enclosingScope the scope in which this scope is lexically enclosed | 9260 * @param enclosingScope the scope in which this scope is lexically enclosed |
8722 * @param typeElement the element representing the type represented by this sc
ope | 9261 * @param typeElement the element representing the type represented by this sc
ope |
8723 */ | 9262 */ |
8724 ClassScope(Scope enclosingScope, ClassElement typeElement) : super(new Enclose
dScope(enclosingScope)) { | 9263 ClassScope(Scope enclosingScope, ClassElement typeElement) : super(new Enclose
dScope(enclosingScope)) { |
8725 defineTypeParameters(typeElement); | 9264 defineTypeParameters(typeElement); |
8726 defineMembers(typeElement); | 9265 defineMembers(typeElement); |
8727 } | 9266 } |
8728 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { | 9267 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { |
8729 if (existing is PropertyAccessorElement && duplicate is MethodElement) { | 9268 if (existing is PropertyAccessorElement && duplicate is MethodElement) { |
8730 if (existing.nameOffset < duplicate.nameOffset) { | 9269 if (existing.nameOffset < duplicate.nameOffset) { |
8731 return new AnalysisError.con2(duplicate.source, duplicate.nameOffset, du
plicate.displayName.length, CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAM
E, [existing.displayName]); | 9270 return new AnalysisError.con2(duplicate.source, duplicate.nameOffset, du
plicate.displayName.length, CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAM
E, [existing.displayName]); |
8732 } else { | 9271 } else { |
8733 return new AnalysisError.con2(existing.source, existing.nameOffset, exis
ting.displayName.length, CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME,
[existing.displayName]); | 9272 return new AnalysisError.con2(existing.source, existing.nameOffset, exis
ting.displayName.length, CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME,
[existing.displayName]); |
8734 } | 9273 } |
8735 } | 9274 } |
8736 return super.getErrorForDuplicate(existing, duplicate); | 9275 return super.getErrorForDuplicate(existing, duplicate); |
8737 } | 9276 } |
8738 | 9277 |
8739 /** | 9278 /** |
8740 * Define the instance members defined by the class. | 9279 * Define the instance members defined by the class. |
| 9280 * |
8741 * @param typeElement the element representing the type represented by this sc
ope | 9281 * @param typeElement the element representing the type represented by this sc
ope |
8742 */ | 9282 */ |
8743 void defineMembers(ClassElement typeElement) { | 9283 void defineMembers(ClassElement typeElement) { |
8744 for (PropertyAccessorElement accessor in typeElement.accessors) { | 9284 for (PropertyAccessorElement accessor in typeElement.accessors) { |
8745 define(accessor); | 9285 define(accessor); |
8746 } | 9286 } |
8747 for (MethodElement method in typeElement.methods) { | 9287 for (MethodElement method in typeElement.methods) { |
8748 define(method); | 9288 define(method); |
8749 } | 9289 } |
8750 } | 9290 } |
8751 | 9291 |
8752 /** | 9292 /** |
8753 * Define the type parameters for the class. | 9293 * Define the type parameters for the class. |
| 9294 * |
8754 * @param typeElement the element representing the type represented by this sc
ope | 9295 * @param typeElement the element representing the type represented by this sc
ope |
8755 */ | 9296 */ |
8756 void defineTypeParameters(ClassElement typeElement) { | 9297 void defineTypeParameters(ClassElement typeElement) { |
8757 Scope parameterScope = enclosingScope; | 9298 Scope parameterScope = enclosingScope; |
8758 for (TypeVariableElement parameter in typeElement.typeVariables) { | 9299 for (TypeVariableElement parameter in typeElement.typeVariables) { |
8759 parameterScope.define(parameter); | 9300 parameterScope.define(parameter); |
8760 } | 9301 } |
8761 } | 9302 } |
8762 } | 9303 } |
8763 /** | 9304 /** |
8764 * Instances of the class `EnclosedScope` implement a scope that is lexically en
closed in | 9305 * Instances of the class `EnclosedScope` implement a scope that is lexically en
closed in |
8765 * another scope. | 9306 * another scope. |
| 9307 * |
8766 * @coverage dart.engine.resolver | 9308 * @coverage dart.engine.resolver |
8767 */ | 9309 */ |
8768 class EnclosedScope extends Scope { | 9310 class EnclosedScope extends Scope { |
8769 | 9311 |
8770 /** | 9312 /** |
8771 * The scope in which this scope is lexically enclosed. | 9313 * The scope in which this scope is lexically enclosed. |
8772 */ | 9314 */ |
8773 Scope _enclosingScope; | 9315 Scope _enclosingScope; |
8774 | 9316 |
8775 /** | 9317 /** |
8776 * Initialize a newly created scope enclosed within another scope. | 9318 * Initialize a newly created scope enclosed within another scope. |
| 9319 * |
8777 * @param enclosingScope the scope in which this scope is lexically enclosed | 9320 * @param enclosingScope the scope in which this scope is lexically enclosed |
8778 */ | 9321 */ |
8779 EnclosedScope(Scope enclosingScope) { | 9322 EnclosedScope(Scope enclosingScope) { |
8780 this._enclosingScope = enclosingScope; | 9323 this._enclosingScope = enclosingScope; |
8781 } | 9324 } |
8782 LibraryElement get definingLibrary => _enclosingScope.definingLibrary; | 9325 LibraryElement get definingLibrary => _enclosingScope.definingLibrary; |
8783 AnalysisErrorListener get errorListener => _enclosingScope.errorListener; | 9326 AnalysisErrorListener get errorListener => _enclosingScope.errorListener; |
8784 | 9327 |
8785 /** | 9328 /** |
8786 * Return the scope in which this scope is lexically enclosed. | 9329 * Return the scope in which this scope is lexically enclosed. |
| 9330 * |
8787 * @return the scope in which this scope is lexically enclosed | 9331 * @return the scope in which this scope is lexically enclosed |
8788 */ | 9332 */ |
8789 Scope get enclosingScope => _enclosingScope; | 9333 Scope get enclosingScope => _enclosingScope; |
8790 Element lookup3(Identifier identifier, String name, LibraryElement referencing
Library) { | 9334 Element lookup3(Identifier identifier, String name, LibraryElement referencing
Library) { |
8791 Element element = localLookup(name, referencingLibrary); | 9335 Element element = localLookup(name, referencingLibrary); |
8792 if (element != null) { | 9336 if (element != null) { |
8793 return element; | 9337 return element; |
8794 } | 9338 } |
8795 return _enclosingScope.lookup3(identifier, name, referencingLibrary); | 9339 return _enclosingScope.lookup3(identifier, name, referencingLibrary); |
8796 } | 9340 } |
8797 } | 9341 } |
8798 /** | 9342 /** |
8799 * Instances of the class `FunctionScope` implement the scope defined by a funct
ion. | 9343 * Instances of the class `FunctionScope` implement the scope defined by a funct
ion. |
| 9344 * |
8800 * @coverage dart.engine.resolver | 9345 * @coverage dart.engine.resolver |
8801 */ | 9346 */ |
8802 class FunctionScope extends EnclosedScope { | 9347 class FunctionScope extends EnclosedScope { |
8803 | 9348 |
8804 /** | 9349 /** |
8805 * Initialize a newly created scope enclosed within another scope. | 9350 * Initialize a newly created scope enclosed within another scope. |
| 9351 * |
8806 * @param enclosingScope the scope in which this scope is lexically enclosed | 9352 * @param enclosingScope the scope in which this scope is lexically enclosed |
8807 * @param functionElement the element representing the type represented by thi
s scope | 9353 * @param functionElement the element representing the type represented by thi
s scope |
8808 */ | 9354 */ |
8809 FunctionScope(Scope enclosingScope, ExecutableElement functionElement) : super
(new EnclosedScope(enclosingScope)) { | 9355 FunctionScope(Scope enclosingScope, ExecutableElement functionElement) : super
(new EnclosedScope(enclosingScope)) { |
8810 defineParameters(functionElement); | 9356 defineParameters(functionElement); |
8811 } | 9357 } |
8812 | 9358 |
8813 /** | 9359 /** |
8814 * Define the parameters for the given function in the scope that encloses thi
s function. | 9360 * Define the parameters for the given function in the scope that encloses thi
s function. |
| 9361 * |
8815 * @param functionElement the element representing the function represented by
this scope | 9362 * @param functionElement the element representing the function represented by
this scope |
8816 */ | 9363 */ |
8817 void defineParameters(ExecutableElement functionElement) { | 9364 void defineParameters(ExecutableElement functionElement) { |
8818 Scope parameterScope = enclosingScope; | 9365 Scope parameterScope = enclosingScope; |
8819 if (functionElement.enclosingElement is ExecutableElement) { | 9366 if (functionElement.enclosingElement is ExecutableElement) { |
8820 String name = functionElement.name; | 9367 String name = functionElement.name; |
8821 if (name != null && !name.isEmpty) { | 9368 if (name != null && !name.isEmpty) { |
8822 parameterScope.define(functionElement); | 9369 parameterScope.define(functionElement); |
8823 } | 9370 } |
8824 } | 9371 } |
8825 for (ParameterElement parameter in functionElement.parameters) { | 9372 for (ParameterElement parameter in functionElement.parameters) { |
8826 if (!parameter.isInitializingFormal) { | 9373 if (!parameter.isInitializingFormal) { |
8827 parameterScope.define(parameter); | 9374 parameterScope.define(parameter); |
8828 } | 9375 } |
8829 } | 9376 } |
8830 } | 9377 } |
8831 } | 9378 } |
8832 /** | 9379 /** |
8833 * Instances of the class `FunctionTypeScope` implement the scope defined by a f
unction type | 9380 * Instances of the class `FunctionTypeScope` implement the scope defined by a f
unction type |
8834 * alias. | 9381 * alias. |
| 9382 * |
8835 * @coverage dart.engine.resolver | 9383 * @coverage dart.engine.resolver |
8836 */ | 9384 */ |
8837 class FunctionTypeScope extends EnclosedScope { | 9385 class FunctionTypeScope extends EnclosedScope { |
8838 | 9386 |
8839 /** | 9387 /** |
8840 * Initialize a newly created scope enclosed within another scope. | 9388 * Initialize a newly created scope enclosed within another scope. |
| 9389 * |
8841 * @param enclosingScope the scope in which this scope is lexically enclosed | 9390 * @param enclosingScope the scope in which this scope is lexically enclosed |
8842 * @param typeElement the element representing the type alias represented by t
his scope | 9391 * @param typeElement the element representing the type alias represented by t
his scope |
8843 */ | 9392 */ |
8844 FunctionTypeScope(Scope enclosingScope, FunctionTypeAliasElement typeElement)
: super(new EnclosedScope(enclosingScope)) { | 9393 FunctionTypeScope(Scope enclosingScope, FunctionTypeAliasElement typeElement)
: super(new EnclosedScope(enclosingScope)) { |
8845 defineTypeVariables(typeElement); | 9394 defineTypeVariables(typeElement); |
8846 defineParameters(typeElement); | 9395 defineParameters(typeElement); |
8847 } | 9396 } |
8848 | 9397 |
8849 /** | 9398 /** |
8850 * Define the parameters for the function type alias. | 9399 * Define the parameters for the function type alias. |
| 9400 * |
8851 * @param typeElement the element representing the type represented by this sc
ope | 9401 * @param typeElement the element representing the type represented by this sc
ope |
8852 */ | 9402 */ |
8853 void defineParameters(FunctionTypeAliasElement typeElement) { | 9403 void defineParameters(FunctionTypeAliasElement typeElement) { |
8854 for (ParameterElement parameter in typeElement.parameters) { | 9404 for (ParameterElement parameter in typeElement.parameters) { |
8855 define(parameter); | 9405 define(parameter); |
8856 } | 9406 } |
8857 } | 9407 } |
8858 | 9408 |
8859 /** | 9409 /** |
8860 * Define the type variables for the function type alias. | 9410 * Define the type variables for the function type alias. |
| 9411 * |
8861 * @param typeElement the element representing the type represented by this sc
ope | 9412 * @param typeElement the element representing the type represented by this sc
ope |
8862 */ | 9413 */ |
8863 void defineTypeVariables(FunctionTypeAliasElement typeElement) { | 9414 void defineTypeVariables(FunctionTypeAliasElement typeElement) { |
8864 Scope typeVariableScope = enclosingScope; | 9415 Scope typeVariableScope = enclosingScope; |
8865 for (TypeVariableElement typeVariable in typeElement.typeVariables) { | 9416 for (TypeVariableElement typeVariable in typeElement.typeVariables) { |
8866 typeVariableScope.define(typeVariable); | 9417 typeVariableScope.define(typeVariable); |
8867 } | 9418 } |
8868 } | 9419 } |
8869 } | 9420 } |
8870 /** | 9421 /** |
8871 * Instances of the class `LabelScope` represent a scope in which a single label
is defined. | 9422 * Instances of the class `LabelScope` represent a scope in which a single label
is defined. |
| 9423 * |
8872 * @coverage dart.engine.resolver | 9424 * @coverage dart.engine.resolver |
8873 */ | 9425 */ |
8874 class LabelScope { | 9426 class LabelScope { |
8875 | 9427 |
8876 /** | 9428 /** |
8877 * The label scope enclosing this label scope. | 9429 * The label scope enclosing this label scope. |
8878 */ | 9430 */ |
8879 LabelScope _outerScope; | 9431 LabelScope _outerScope; |
8880 | 9432 |
8881 /** | 9433 /** |
8882 * The label defined in this scope. | 9434 * The label defined in this scope. |
8883 */ | 9435 */ |
8884 String _label; | 9436 String _label; |
8885 | 9437 |
8886 /** | 9438 /** |
8887 * The element to which the label resolves. | 9439 * The element to which the label resolves. |
8888 */ | 9440 */ |
8889 LabelElement _element; | 9441 LabelElement _element; |
8890 | 9442 |
8891 /** | 9443 /** |
8892 * The marker used to look up a label element for an unlabeled `break` or `con
tinue`. | 9444 * The marker used to look up a label element for an unlabeled `break` or `con
tinue`. |
8893 */ | 9445 */ |
8894 static String EMPTY_LABEL = ""; | 9446 static String EMPTY_LABEL = ""; |
8895 | 9447 |
8896 /** | 9448 /** |
8897 * The label element returned for scopes that can be the target of an unlabele
d `break` or`continue`. | 9449 * The label element returned for scopes that can be the target of an unlabele
d `break` or |
| 9450 * `continue`. |
8898 */ | 9451 */ |
8899 static SimpleIdentifier _EMPTY_LABEL_IDENTIFIER = new SimpleIdentifier.full(ne
w sc.StringToken(sc.TokenType.IDENTIFIER, "", 0)); | 9452 static SimpleIdentifier _EMPTY_LABEL_IDENTIFIER = new SimpleIdentifier.full(ne
w sc.StringToken(sc.TokenType.IDENTIFIER, "", 0)); |
8900 | 9453 |
8901 /** | 9454 /** |
8902 * Initialize a newly created scope to represent the potential target of an un
labeled`break` or `continue`. | 9455 * Initialize a newly created scope to represent the potential target of an un
labeled |
| 9456 * `break` or `continue`. |
| 9457 * |
8903 * @param outerScope the label scope enclosing the new label scope | 9458 * @param outerScope the label scope enclosing the new label scope |
8904 * @param onSwitchStatement `true` if this label is associated with a `switch`
statement | 9459 * @param onSwitchStatement `true` if this label is associated with a `switch` |
| 9460 * statement |
8905 * @param onSwitchMember `true` if this label is associated with a `switch` me
mber | 9461 * @param onSwitchMember `true` if this label is associated with a `switch` me
mber |
8906 */ | 9462 */ |
8907 LabelScope.con1(LabelScope outerScope, bool onSwitchStatement, bool onSwitchMe
mber) { | 9463 LabelScope.con1(LabelScope outerScope, bool onSwitchStatement, bool onSwitchMe
mber) { |
8908 _jtd_constructor_288_impl(outerScope, onSwitchStatement, onSwitchMember); | 9464 _jtd_constructor_288_impl(outerScope, onSwitchStatement, onSwitchMember); |
8909 } | 9465 } |
8910 _jtd_constructor_288_impl(LabelScope outerScope, bool onSwitchStatement, bool
onSwitchMember) { | 9466 _jtd_constructor_288_impl(LabelScope outerScope, bool onSwitchStatement, bool
onSwitchMember) { |
8911 _jtd_constructor_289_impl(outerScope, EMPTY_LABEL, new LabelElementImpl(_EMP
TY_LABEL_IDENTIFIER, onSwitchStatement, onSwitchMember)); | 9467 _jtd_constructor_289_impl(outerScope, EMPTY_LABEL, new LabelElementImpl(_EMP
TY_LABEL_IDENTIFIER, onSwitchStatement, onSwitchMember)); |
8912 } | 9468 } |
8913 | 9469 |
8914 /** | 9470 /** |
8915 * Initialize a newly created scope to represent the given label. | 9471 * Initialize a newly created scope to represent the given label. |
| 9472 * |
8916 * @param outerScope the label scope enclosing the new label scope | 9473 * @param outerScope the label scope enclosing the new label scope |
8917 * @param label the label defined in this scope | 9474 * @param label the label defined in this scope |
8918 * @param element the element to which the label resolves | 9475 * @param element the element to which the label resolves |
8919 */ | 9476 */ |
8920 LabelScope.con2(LabelScope outerScope2, String label2, LabelElement element2)
{ | 9477 LabelScope.con2(LabelScope outerScope2, String label2, LabelElement element2)
{ |
8921 _jtd_constructor_289_impl(outerScope2, label2, element2); | 9478 _jtd_constructor_289_impl(outerScope2, label2, element2); |
8922 } | 9479 } |
8923 _jtd_constructor_289_impl(LabelScope outerScope2, String label2, LabelElement
element2) { | 9480 _jtd_constructor_289_impl(LabelScope outerScope2, String label2, LabelElement
element2) { |
8924 this._outerScope = outerScope2; | 9481 this._outerScope = outerScope2; |
8925 this._label = label2; | 9482 this._label = label2; |
8926 this._element = element2; | 9483 this._element = element2; |
8927 } | 9484 } |
8928 | 9485 |
8929 /** | 9486 /** |
8930 * Return the label element corresponding to the given label, or `null` if the
given label | 9487 * Return the label element corresponding to the given label, or `null` if the
given label |
8931 * is not defined in this scope. | 9488 * is not defined in this scope. |
| 9489 * |
8932 * @param targetLabel the label being looked up | 9490 * @param targetLabel the label being looked up |
8933 * @return the label element corresponding to the given label | 9491 * @return the label element corresponding to the given label |
8934 */ | 9492 */ |
8935 LabelElement lookup(SimpleIdentifier targetLabel) => lookup2(targetLabel.name)
; | 9493 LabelElement lookup(SimpleIdentifier targetLabel) => lookup2(targetLabel.name)
; |
8936 | 9494 |
8937 /** | 9495 /** |
8938 * Return the label element corresponding to the given label, or `null` if the
given label | 9496 * Return the label element corresponding to the given label, or `null` if the
given label |
8939 * is not defined in this scope. | 9497 * is not defined in this scope. |
| 9498 * |
8940 * @param targetLabel the label being looked up | 9499 * @param targetLabel the label being looked up |
8941 * @return the label element corresponding to the given label | 9500 * @return the label element corresponding to the given label |
8942 */ | 9501 */ |
8943 LabelElement lookup2(String targetLabel) { | 9502 LabelElement lookup2(String targetLabel) { |
8944 if (_label == targetLabel) { | 9503 if (_label == targetLabel) { |
8945 return _element; | 9504 return _element; |
8946 } else if (_outerScope != null) { | 9505 } else if (_outerScope != null) { |
8947 return _outerScope.lookup2(targetLabel); | 9506 return _outerScope.lookup2(targetLabel); |
8948 } else { | 9507 } else { |
8949 return null; | 9508 return null; |
8950 } | 9509 } |
8951 } | 9510 } |
8952 } | 9511 } |
8953 /** | 9512 /** |
8954 * Instances of the class `LibraryImportScope` represent the scope containing al
l of the names | 9513 * Instances of the class `LibraryImportScope` represent the scope containing al
l of the names |
8955 * available from imported libraries. | 9514 * available from imported libraries. |
| 9515 * |
8956 * @coverage dart.engine.resolver | 9516 * @coverage dart.engine.resolver |
8957 */ | 9517 */ |
8958 class LibraryImportScope extends Scope { | 9518 class LibraryImportScope extends Scope { |
8959 | 9519 |
8960 /** | 9520 /** |
8961 * @return `true` if the given [Identifier] is the part of type annotation. | 9521 * @return `true` if the given [Identifier] is the part of type annotation. |
8962 */ | 9522 */ |
8963 static bool isTypeAnnotation(Identifier identifier) { | 9523 static bool isTypeAnnotation(Identifier identifier) { |
8964 ASTNode parent = identifier.parent; | 9524 ASTNode parent = identifier.parent; |
8965 if (parent is TypeName) { | 9525 if (parent is TypeName) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9013 AnalysisErrorListener _errorListener; | 9573 AnalysisErrorListener _errorListener; |
9014 | 9574 |
9015 /** | 9575 /** |
9016 * A list of the namespaces representing the names that are available in this
scope from imported | 9576 * A list of the namespaces representing the names that are available in this
scope from imported |
9017 * libraries. | 9577 * libraries. |
9018 */ | 9578 */ |
9019 List<Namespace> _importedNamespaces = new List<Namespace>(); | 9579 List<Namespace> _importedNamespaces = new List<Namespace>(); |
9020 | 9580 |
9021 /** | 9581 /** |
9022 * Initialize a newly created scope representing the names imported into the g
iven library. | 9582 * Initialize a newly created scope representing the names imported into the g
iven library. |
| 9583 * |
9023 * @param definingLibrary the element representing the library that imports th
e names defined in | 9584 * @param definingLibrary the element representing the library that imports th
e names defined in |
9024 * this scope | 9585 * this scope |
9025 * @param errorListener the listener that is to be informed when an error is e
ncountered | 9586 * @param errorListener the listener that is to be informed when an error is e
ncountered |
9026 */ | 9587 */ |
9027 LibraryImportScope(LibraryElement definingLibrary, AnalysisErrorListener error
Listener) { | 9588 LibraryImportScope(LibraryElement definingLibrary, AnalysisErrorListener error
Listener) { |
9028 this._definingLibrary = definingLibrary; | 9589 this._definingLibrary = definingLibrary; |
9029 this._errorListener = errorListener; | 9590 this._errorListener = errorListener; |
9030 createImportedNamespaces(definingLibrary); | 9591 createImportedNamespaces(definingLibrary); |
9031 } | 9592 } |
9032 void define(Element element) { | 9593 void define(Element element) { |
9033 if (!Scope.isPrivateName(element.displayName)) { | 9594 if (!Scope.isPrivateName(element.displayName)) { |
9034 super.define(element); | 9595 super.define(element); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9069 } | 9630 } |
9070 if (foundElement != null) { | 9631 if (foundElement != null) { |
9071 defineWithoutChecking2(name, foundElement); | 9632 defineWithoutChecking2(name, foundElement); |
9072 } | 9633 } |
9073 return foundElement; | 9634 return foundElement; |
9074 } | 9635 } |
9075 | 9636 |
9076 /** | 9637 /** |
9077 * Create all of the namespaces associated with the libraries imported into th
is library. The | 9638 * Create all of the namespaces associated with the libraries imported into th
is library. The |
9078 * names are not added to this scope, but are stored for later reference. | 9639 * names are not added to this scope, but are stored for later reference. |
| 9640 * |
9079 * @param definingLibrary the element representing the library that imports th
e libraries for | 9641 * @param definingLibrary the element representing the library that imports th
e libraries for |
9080 * which namespaces will be created | 9642 * which namespaces will be created |
9081 */ | 9643 */ |
9082 void createImportedNamespaces(LibraryElement definingLibrary) { | 9644 void createImportedNamespaces(LibraryElement definingLibrary) { |
9083 NamespaceBuilder builder = new NamespaceBuilder(); | 9645 NamespaceBuilder builder = new NamespaceBuilder(); |
9084 for (ImportElement element in definingLibrary.imports) { | 9646 for (ImportElement element in definingLibrary.imports) { |
9085 _importedNamespaces.add(builder.createImportNamespace(element)); | 9647 _importedNamespaces.add(builder.createImportNamespace(element)); |
9086 } | 9648 } |
9087 } | 9649 } |
9088 } | 9650 } |
9089 /** | 9651 /** |
9090 * Instances of the class `LibraryScope` implement a scope containing all of the
names defined | 9652 * Instances of the class `LibraryScope` implement a scope containing all of the
names defined |
9091 * in a given library. | 9653 * in a given library. |
| 9654 * |
9092 * @coverage dart.engine.resolver | 9655 * @coverage dart.engine.resolver |
9093 */ | 9656 */ |
9094 class LibraryScope extends EnclosedScope { | 9657 class LibraryScope extends EnclosedScope { |
9095 | 9658 |
9096 /** | 9659 /** |
9097 * Initialize a newly created scope representing the names defined in the give
n library. | 9660 * Initialize a newly created scope representing the names defined in the give
n library. |
| 9661 * |
9098 * @param definingLibrary the element representing the library represented by
this scope | 9662 * @param definingLibrary the element representing the library represented by
this scope |
9099 * @param errorListener the listener that is to be informed when an error is e
ncountered | 9663 * @param errorListener the listener that is to be informed when an error is e
ncountered |
9100 */ | 9664 */ |
9101 LibraryScope(LibraryElement definingLibrary, AnalysisErrorListener errorListen
er) : super(new LibraryImportScope(definingLibrary, errorListener)) { | 9665 LibraryScope(LibraryElement definingLibrary, AnalysisErrorListener errorListen
er) : super(new LibraryImportScope(definingLibrary, errorListener)) { |
9102 defineTopLevelNames(definingLibrary); | 9666 defineTopLevelNames(definingLibrary); |
9103 } | 9667 } |
9104 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { | 9668 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { |
9105 if (existing is PrefixElement) { | 9669 if (existing is PrefixElement) { |
9106 int offset = duplicate.nameOffset; | 9670 int offset = duplicate.nameOffset; |
9107 if (duplicate is PropertyAccessorElement) { | 9671 if (duplicate is PropertyAccessorElement) { |
9108 PropertyAccessorElement accessor = duplicate as PropertyAccessorElement; | 9672 PropertyAccessorElement accessor = duplicate as PropertyAccessorElement; |
9109 if (accessor.isSynthetic) { | 9673 if (accessor.isSynthetic) { |
9110 offset = accessor.variable.nameOffset; | 9674 offset = accessor.variable.nameOffset; |
9111 } | 9675 } |
9112 } | 9676 } |
9113 return new AnalysisError.con2(source, offset, duplicate.displayName.length
, CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER, [existing.displayN
ame]); | 9677 return new AnalysisError.con2(source, offset, duplicate.displayName.length
, CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER, [existing.displayN
ame]); |
9114 } | 9678 } |
9115 return super.getErrorForDuplicate(existing, duplicate); | 9679 return super.getErrorForDuplicate(existing, duplicate); |
9116 } | 9680 } |
9117 | 9681 |
9118 /** | 9682 /** |
9119 * Add to this scope all of the public top-level names that are defined in the
given compilation | 9683 * Add to this scope all of the public top-level names that are defined in the
given compilation |
9120 * unit. | 9684 * unit. |
| 9685 * |
9121 * @param compilationUnit the compilation unit defining the top-level names to
be added to this | 9686 * @param compilationUnit the compilation unit defining the top-level names to
be added to this |
9122 * scope | 9687 * scope |
9123 */ | 9688 */ |
9124 void defineLocalNames(CompilationUnitElement compilationUnit) { | 9689 void defineLocalNames(CompilationUnitElement compilationUnit) { |
9125 for (PropertyAccessorElement element in compilationUnit.accessors) { | 9690 for (PropertyAccessorElement element in compilationUnit.accessors) { |
9126 define(element); | 9691 define(element); |
9127 } | 9692 } |
9128 for (FunctionElement element in compilationUnit.functions) { | 9693 for (FunctionElement element in compilationUnit.functions) { |
9129 define(element); | 9694 define(element); |
9130 } | 9695 } |
9131 for (FunctionTypeAliasElement element in compilationUnit.functionTypeAliases
) { | 9696 for (FunctionTypeAliasElement element in compilationUnit.functionTypeAliases
) { |
9132 define(element); | 9697 define(element); |
9133 } | 9698 } |
9134 for (ClassElement element in compilationUnit.types) { | 9699 for (ClassElement element in compilationUnit.types) { |
9135 define(element); | 9700 define(element); |
9136 } | 9701 } |
9137 } | 9702 } |
9138 | 9703 |
9139 /** | 9704 /** |
9140 * Add to this scope all of the names that are explicitly defined in the given
library. | 9705 * Add to this scope all of the names that are explicitly defined in the given
library. |
| 9706 * |
9141 * @param definingLibrary the element representing the library that defines th
e names in this | 9707 * @param definingLibrary the element representing the library that defines th
e names in this |
9142 * scope | 9708 * scope |
9143 */ | 9709 */ |
9144 void defineTopLevelNames(LibraryElement definingLibrary) { | 9710 void defineTopLevelNames(LibraryElement definingLibrary) { |
9145 for (PrefixElement prefix in definingLibrary.prefixes) { | 9711 for (PrefixElement prefix in definingLibrary.prefixes) { |
9146 define(prefix); | 9712 define(prefix); |
9147 } | 9713 } |
9148 defineLocalNames(definingLibrary.definingCompilationUnit); | 9714 defineLocalNames(definingLibrary.definingCompilationUnit); |
9149 for (CompilationUnitElement compilationUnit in definingLibrary.parts) { | 9715 for (CompilationUnitElement compilationUnit in definingLibrary.parts) { |
9150 defineLocalNames(compilationUnit); | 9716 defineLocalNames(compilationUnit); |
9151 } | 9717 } |
9152 } | 9718 } |
9153 } | 9719 } |
9154 /** | 9720 /** |
9155 * Instances of the class `Namespace` implement a mapping of identifiers to the
elements | 9721 * Instances of the class `Namespace` implement a mapping of identifiers to the
elements |
9156 * represented by those identifiers. Namespaces are the building blocks for scop
es. | 9722 * represented by those identifiers. Namespaces are the building blocks for scop
es. |
| 9723 * |
9157 * @coverage dart.engine.resolver | 9724 * @coverage dart.engine.resolver |
9158 */ | 9725 */ |
9159 class Namespace { | 9726 class Namespace { |
9160 | 9727 |
9161 /** | 9728 /** |
9162 * A table mapping names that are defined in this namespace to the element rep
resenting the thing | 9729 * A table mapping names that are defined in this namespace to the element rep
resenting the thing |
9163 * declared with that name. | 9730 * declared with that name. |
9164 */ | 9731 */ |
9165 Map<String, Element> _definedNames; | 9732 Map<String, Element> _definedNames; |
9166 | 9733 |
9167 /** | 9734 /** |
9168 * An empty namespace. | 9735 * An empty namespace. |
9169 */ | 9736 */ |
9170 static Namespace EMPTY = new Namespace(new Map<String, Element>()); | 9737 static Namespace EMPTY = new Namespace(new Map<String, Element>()); |
9171 | 9738 |
9172 /** | 9739 /** |
9173 * Initialize a newly created namespace to have the given defined names. | 9740 * Initialize a newly created namespace to have the given defined names. |
| 9741 * |
9174 * @param definedNames the mapping from names that are defined in this namespa
ce to the | 9742 * @param definedNames the mapping from names that are defined in this namespa
ce to the |
9175 * corresponding elements | 9743 * corresponding elements |
9176 */ | 9744 */ |
9177 Namespace(Map<String, Element> definedNames) { | 9745 Namespace(Map<String, Element> definedNames) { |
9178 this._definedNames = definedNames; | 9746 this._definedNames = definedNames; |
9179 } | 9747 } |
9180 | 9748 |
9181 /** | 9749 /** |
9182 * Return the element in this namespace that is available to the containing sc
ope using the given | 9750 * Return the element in this namespace that is available to the containing sc
ope using the given |
9183 * name. | 9751 * name. |
| 9752 * |
9184 * @param name the name used to reference the | 9753 * @param name the name used to reference the |
9185 * @return the element represented by the given identifier | 9754 * @return the element represented by the given identifier |
9186 */ | 9755 */ |
9187 Element get(String name) => _definedNames[name]; | 9756 Element get(String name) => _definedNames[name]; |
9188 | 9757 |
9189 /** | 9758 /** |
9190 * Return a table containing the same mappings as those defined by this namesp
ace. | 9759 * Return a table containing the same mappings as those defined by this namesp
ace. |
| 9760 * |
9191 * @return a table containing the same mappings as those defined by this names
pace | 9761 * @return a table containing the same mappings as those defined by this names
pace |
9192 */ | 9762 */ |
9193 Map<String, Element> get definedNames => new Map<String, Element>.from(_define
dNames); | 9763 Map<String, Element> get definedNames => new Map<String, Element>.from(_define
dNames); |
9194 } | 9764 } |
9195 /** | 9765 /** |
9196 * Instances of the class `NamespaceBuilder` are used to build a `Namespace`. Na
mespace | 9766 * Instances of the class `NamespaceBuilder` are used to build a `Namespace`. Na
mespace |
9197 * builders are thread-safe and re-usable. | 9767 * builders are thread-safe and re-usable. |
| 9768 * |
9198 * @coverage dart.engine.resolver | 9769 * @coverage dart.engine.resolver |
9199 */ | 9770 */ |
9200 class NamespaceBuilder { | 9771 class NamespaceBuilder { |
9201 | 9772 |
9202 /** | 9773 /** |
9203 * Create a namespace representing the export namespace of the given [ExportEl
ement]. | 9774 * Create a namespace representing the export namespace of the given [ExportEl
ement]. |
| 9775 * |
9204 * @param element the export element whose export namespace is to be created | 9776 * @param element the export element whose export namespace is to be created |
9205 * @return the export namespace that was created | 9777 * @return the export namespace that was created |
9206 */ | 9778 */ |
9207 Namespace createExportNamespace(ExportElement element) { | 9779 Namespace createExportNamespace(ExportElement element) { |
9208 LibraryElement exportedLibrary = element.exportedLibrary; | 9780 LibraryElement exportedLibrary = element.exportedLibrary; |
9209 if (exportedLibrary == null) { | 9781 if (exportedLibrary == null) { |
9210 return Namespace.EMPTY; | 9782 return Namespace.EMPTY; |
9211 } | 9783 } |
9212 Map<String, Element> definedNames = createExportMapping(exportedLibrary, new
Set<LibraryElement>()); | 9784 Map<String, Element> definedNames = createExportMapping(exportedLibrary, new
Set<LibraryElement>()); |
9213 definedNames = apply(definedNames, element.combinators); | 9785 definedNames = apply(definedNames, element.combinators); |
9214 return new Namespace(definedNames); | 9786 return new Namespace(definedNames); |
9215 } | 9787 } |
9216 | 9788 |
9217 /** | 9789 /** |
9218 * Create a namespace representing the export namespace of the given library. | 9790 * Create a namespace representing the export namespace of the given library. |
| 9791 * |
9219 * @param library the library whose export namespace is to be created | 9792 * @param library the library whose export namespace is to be created |
9220 * @return the export namespace that was created | 9793 * @return the export namespace that was created |
9221 */ | 9794 */ |
9222 Namespace createExportNamespace2(LibraryElement library) => new Namespace(crea
teExportMapping(library, new Set<LibraryElement>())); | 9795 Namespace createExportNamespace2(LibraryElement library) => new Namespace(crea
teExportMapping(library, new Set<LibraryElement>())); |
9223 | 9796 |
9224 /** | 9797 /** |
9225 * Create a namespace representing the import namespace of the given library. | 9798 * Create a namespace representing the import namespace of the given library. |
| 9799 * |
9226 * @param library the library whose import namespace is to be created | 9800 * @param library the library whose import namespace is to be created |
9227 * @return the import namespace that was created | 9801 * @return the import namespace that was created |
9228 */ | 9802 */ |
9229 Namespace createImportNamespace(ImportElement element) { | 9803 Namespace createImportNamespace(ImportElement element) { |
9230 LibraryElement importedLibrary = element.importedLibrary; | 9804 LibraryElement importedLibrary = element.importedLibrary; |
9231 if (importedLibrary == null) { | 9805 if (importedLibrary == null) { |
9232 return Namespace.EMPTY; | 9806 return Namespace.EMPTY; |
9233 } | 9807 } |
9234 Map<String, Element> definedNames = createExportMapping(importedLibrary, new
Set<LibraryElement>()); | 9808 Map<String, Element> definedNames = createExportMapping(importedLibrary, new
Set<LibraryElement>()); |
9235 definedNames = apply(definedNames, element.combinators); | 9809 definedNames = apply(definedNames, element.combinators); |
9236 definedNames = apply2(definedNames, element.prefix); | 9810 definedNames = apply2(definedNames, element.prefix); |
9237 return new Namespace(definedNames); | 9811 return new Namespace(definedNames); |
9238 } | 9812 } |
9239 | 9813 |
9240 /** | 9814 /** |
9241 * Create a namespace representing the public namespace of the given library. | 9815 * Create a namespace representing the public namespace of the given library. |
| 9816 * |
9242 * @param library the library whose public namespace is to be created | 9817 * @param library the library whose public namespace is to be created |
9243 * @return the public namespace that was created | 9818 * @return the public namespace that was created |
9244 */ | 9819 */ |
9245 Namespace createPublicNamespace(LibraryElement library) { | 9820 Namespace createPublicNamespace(LibraryElement library) { |
9246 Map<String, Element> definedNames = new Map<String, Element>(); | 9821 Map<String, Element> definedNames = new Map<String, Element>(); |
9247 addPublicNames(definedNames, library.definingCompilationUnit); | 9822 addPublicNames(definedNames, library.definingCompilationUnit); |
9248 for (CompilationUnitElement compilationUnit in library.parts) { | 9823 for (CompilationUnitElement compilationUnit in library.parts) { |
9249 addPublicNames(definedNames, compilationUnit); | 9824 addPublicNames(definedNames, compilationUnit); |
9250 } | 9825 } |
9251 return new Namespace(definedNames); | 9826 return new Namespace(definedNames); |
9252 } | 9827 } |
9253 | 9828 |
9254 /** | 9829 /** |
9255 * Add all of the names in the given namespace to the given mapping table. | 9830 * Add all of the names in the given namespace to the given mapping table. |
| 9831 * |
9256 * @param definedNames the mapping table to which the names in the given names
pace are to be added | 9832 * @param definedNames the mapping table to which the names in the given names
pace are to be added |
9257 * @param namespace the namespace containing the names to be added to this nam
espace | 9833 * @param namespace the namespace containing the names to be added to this nam
espace |
9258 */ | 9834 */ |
9259 void addAll(Map<String, Element> definedNames, Map<String, Element> newNames)
{ | 9835 void addAll(Map<String, Element> definedNames, Map<String, Element> newNames)
{ |
9260 for (MapEntry<String, Element> entry in getMapEntrySet(newNames)) { | 9836 for (MapEntry<String, Element> entry in getMapEntrySet(newNames)) { |
9261 definedNames[entry.getKey()] = entry.getValue(); | 9837 definedNames[entry.getKey()] = entry.getValue(); |
9262 } | 9838 } |
9263 } | 9839 } |
9264 | 9840 |
9265 /** | 9841 /** |
9266 * Add all of the names in the given namespace to the given mapping table. | 9842 * Add all of the names in the given namespace to the given mapping table. |
| 9843 * |
9267 * @param definedNames the mapping table to which the names in the given names
pace are to be added | 9844 * @param definedNames the mapping table to which the names in the given names
pace are to be added |
9268 * @param namespace the namespace containing the names to be added to this nam
espace | 9845 * @param namespace the namespace containing the names to be added to this nam
espace |
9269 */ | 9846 */ |
9270 void addAll2(Map<String, Element> definedNames2, Namespace namespace) { | 9847 void addAll2(Map<String, Element> definedNames2, Namespace namespace) { |
9271 if (namespace != null) { | 9848 if (namespace != null) { |
9272 addAll(definedNames2, namespace.definedNames); | 9849 addAll(definedNames2, namespace.definedNames); |
9273 } | 9850 } |
9274 } | 9851 } |
9275 | 9852 |
9276 /** | 9853 /** |
9277 * Add the given element to the given mapping table if it has a publicly visib
le name. | 9854 * Add the given element to the given mapping table if it has a publicly visib
le name. |
| 9855 * |
9278 * @param definedNames the mapping table to which the public name is to be add
ed | 9856 * @param definedNames the mapping table to which the public name is to be add
ed |
9279 * @param element the element to be added | 9857 * @param element the element to be added |
9280 */ | 9858 */ |
9281 void addIfPublic(Map<String, Element> definedNames, Element element) { | 9859 void addIfPublic(Map<String, Element> definedNames, Element element) { |
9282 String name = element.name; | 9860 String name = element.name; |
9283 if (name != null && !Scope.isPrivateName(name)) { | 9861 if (name != null && !Scope.isPrivateName(name)) { |
9284 definedNames[name] = element; | 9862 definedNames[name] = element; |
9285 } | 9863 } |
9286 } | 9864 } |
9287 | 9865 |
9288 /** | 9866 /** |
9289 * Add to the given mapping table all of the public top-level names that are d
efined in the given | 9867 * Add to the given mapping table all of the public top-level names that are d
efined in the given |
9290 * compilation unit. | 9868 * compilation unit. |
| 9869 * |
9291 * @param definedNames the mapping table to which the public names are to be a
dded | 9870 * @param definedNames the mapping table to which the public names are to be a
dded |
9292 * @param compilationUnit the compilation unit defining the top-level names to
be added to this | 9871 * @param compilationUnit the compilation unit defining the top-level names to
be added to this |
9293 * namespace | 9872 * namespace |
9294 */ | 9873 */ |
9295 void addPublicNames(Map<String, Element> definedNames, CompilationUnitElement
compilationUnit) { | 9874 void addPublicNames(Map<String, Element> definedNames, CompilationUnitElement
compilationUnit) { |
9296 for (PropertyAccessorElement element in compilationUnit.accessors) { | 9875 for (PropertyAccessorElement element in compilationUnit.accessors) { |
9297 addIfPublic(definedNames, element); | 9876 addIfPublic(definedNames, element); |
9298 } | 9877 } |
9299 for (FunctionElement element in compilationUnit.functions) { | 9878 for (FunctionElement element in compilationUnit.functions) { |
9300 addIfPublic(definedNames, element); | 9879 addIfPublic(definedNames, element); |
9301 } | 9880 } |
9302 for (FunctionTypeAliasElement element in compilationUnit.functionTypeAliases
) { | 9881 for (FunctionTypeAliasElement element in compilationUnit.functionTypeAliases
) { |
9303 addIfPublic(definedNames, element); | 9882 addIfPublic(definedNames, element); |
9304 } | 9883 } |
9305 for (ClassElement element in compilationUnit.types) { | 9884 for (ClassElement element in compilationUnit.types) { |
9306 addIfPublic(definedNames, element); | 9885 addIfPublic(definedNames, element); |
9307 } | 9886 } |
9308 } | 9887 } |
9309 | 9888 |
9310 /** | 9889 /** |
9311 * Apply the given combinators to all of the names in the given mapping table. | 9890 * Apply the given combinators to all of the names in the given mapping table. |
| 9891 * |
9312 * @param definedNames the mapping table to which the namespace operations are
to be applied | 9892 * @param definedNames the mapping table to which the namespace operations are
to be applied |
9313 * @param combinators the combinators to be applied | 9893 * @param combinators the combinators to be applied |
9314 */ | 9894 */ |
9315 Map<String, Element> apply(Map<String, Element> definedNames, List<NamespaceCo
mbinator> combinators) { | 9895 Map<String, Element> apply(Map<String, Element> definedNames, List<NamespaceCo
mbinator> combinators) { |
9316 for (NamespaceCombinator combinator in combinators) { | 9896 for (NamespaceCombinator combinator in combinators) { |
9317 if (combinator is HideElementCombinator) { | 9897 if (combinator is HideElementCombinator) { |
9318 hide(definedNames, ((combinator as HideElementCombinator)).hiddenNames); | 9898 hide(definedNames, ((combinator as HideElementCombinator)).hiddenNames); |
9319 } else if (combinator is ShowElementCombinator) { | 9899 } else if (combinator is ShowElementCombinator) { |
9320 definedNames = show(definedNames, ((combinator as ShowElementCombinator)
).shownNames); | 9900 definedNames = show(definedNames, ((combinator as ShowElementCombinator)
).shownNames); |
9321 } else { | 9901 } else { |
9322 AnalysisEngine.instance.logger.logError("Unknown type of combinator: ${c
ombinator.runtimeType.toString()}"); | 9902 AnalysisEngine.instance.logger.logError("Unknown type of combinator: ${c
ombinator.runtimeType.toString()}"); |
9323 } | 9903 } |
9324 } | 9904 } |
9325 return definedNames; | 9905 return definedNames; |
9326 } | 9906 } |
9327 | 9907 |
9328 /** | 9908 /** |
9329 * Apply the given prefix to all of the names in the table of defined names. | 9909 * Apply the given prefix to all of the names in the table of defined names. |
| 9910 * |
9330 * @param definedNames the names that were defined before this operation | 9911 * @param definedNames the names that were defined before this operation |
9331 * @param prefixElement the element defining the prefix to be added to the nam
es | 9912 * @param prefixElement the element defining the prefix to be added to the nam
es |
9332 */ | 9913 */ |
9333 Map<String, Element> apply2(Map<String, Element> definedNames, PrefixElement p
refixElement) { | 9914 Map<String, Element> apply2(Map<String, Element> definedNames, PrefixElement p
refixElement) { |
9334 if (prefixElement != null) { | 9915 if (prefixElement != null) { |
9335 String prefix = prefixElement.name; | 9916 String prefix = prefixElement.name; |
9336 Map<String, Element> newNames = new Map<String, Element>(); | 9917 Map<String, Element> newNames = new Map<String, Element>(); |
9337 for (MapEntry<String, Element> entry in getMapEntrySet(definedNames)) { | 9918 for (MapEntry<String, Element> entry in getMapEntrySet(definedNames)) { |
9338 newNames["${prefix}.${entry.getKey()}"] = entry.getValue(); | 9919 newNames["${prefix}.${entry.getKey()}"] = entry.getValue(); |
9339 } | 9920 } |
9340 return newNames; | 9921 return newNames; |
9341 } else { | 9922 } else { |
9342 return definedNames; | 9923 return definedNames; |
9343 } | 9924 } |
9344 } | 9925 } |
9345 | 9926 |
9346 /** | 9927 /** |
9347 * Create a mapping table representing the export namespace of the given libra
ry. | 9928 * Create a mapping table representing the export namespace of the given libra
ry. |
| 9929 * |
9348 * @param library the library whose public namespace is to be created | 9930 * @param library the library whose public namespace is to be created |
9349 * @param visitedElements a set of libraries that do not need to be visited wh
en processing the | 9931 * @param visitedElements a set of libraries that do not need to be visited wh
en processing the |
9350 * export directives of the given library because all of the names defined by
them will | 9932 * export directives of the given library because all of the names de
fined by them will |
9351 * be added by another library | 9933 * be added by another library |
9352 * @return the mapping table that was created | 9934 * @return the mapping table that was created |
9353 */ | 9935 */ |
9354 Map<String, Element> createExportMapping(LibraryElement library, Set<LibraryEl
ement> visitedElements) { | 9936 Map<String, Element> createExportMapping(LibraryElement library, Set<LibraryEl
ement> visitedElements) { |
9355 javaSetAdd(visitedElements, library); | 9937 javaSetAdd(visitedElements, library); |
9356 try { | 9938 try { |
9357 Map<String, Element> definedNames = new Map<String, Element>(); | 9939 Map<String, Element> definedNames = new Map<String, Element>(); |
9358 for (ExportElement element in library.exports) { | 9940 for (ExportElement element in library.exports) { |
9359 LibraryElement exportedLibrary = element.exportedLibrary; | 9941 LibraryElement exportedLibrary = element.exportedLibrary; |
9360 if (exportedLibrary != null && !visitedElements.contains(exportedLibrary
)) { | 9942 if (exportedLibrary != null && !visitedElements.contains(exportedLibrary
)) { |
9361 Map<String, Element> exportedNames = createExportMapping(exportedLibra
ry, visitedElements); | 9943 Map<String, Element> exportedNames = createExportMapping(exportedLibra
ry, visitedElements); |
9362 exportedNames = apply(exportedNames, element.combinators); | 9944 exportedNames = apply(exportedNames, element.combinators); |
9363 addAll(definedNames, exportedNames); | 9945 addAll(definedNames, exportedNames); |
9364 } | 9946 } |
9365 } | 9947 } |
9366 addAll2(definedNames, ((library.context as InternalAnalysisContext)).getPu
blicNamespace(library)); | 9948 addAll2(definedNames, ((library.context as InternalAnalysisContext)).getPu
blicNamespace(library)); |
9367 return definedNames; | 9949 return definedNames; |
9368 } finally { | 9950 } finally { |
9369 visitedElements.remove(library); | 9951 visitedElements.remove(library); |
9370 } | 9952 } |
9371 } | 9953 } |
9372 | 9954 |
9373 /** | 9955 /** |
9374 * Hide all of the given names by removing them from the given collection of d
efined names. | 9956 * Hide all of the given names by removing them from the given collection of d
efined names. |
| 9957 * |
9375 * @param definedNames the names that were defined before this operation | 9958 * @param definedNames the names that were defined before this operation |
9376 * @param hiddenNames the names to be hidden | 9959 * @param hiddenNames the names to be hidden |
9377 */ | 9960 */ |
9378 void hide(Map<String, Element> definedNames, List<String> hiddenNames) { | 9961 void hide(Map<String, Element> definedNames, List<String> hiddenNames) { |
9379 for (String name in hiddenNames) { | 9962 for (String name in hiddenNames) { |
9380 definedNames.remove(name); | 9963 definedNames.remove(name); |
9381 definedNames.remove("${name}="); | 9964 definedNames.remove("${name}="); |
9382 } | 9965 } |
9383 } | 9966 } |
9384 | 9967 |
9385 /** | 9968 /** |
9386 * Show only the given names by removing all other names from the given collec
tion of defined | 9969 * Show only the given names by removing all other names from the given collec
tion of defined |
9387 * names. | 9970 * names. |
| 9971 * |
9388 * @param definedNames the names that were defined before this operation | 9972 * @param definedNames the names that were defined before this operation |
9389 * @param shownNames the names to be shown | 9973 * @param shownNames the names to be shown |
9390 */ | 9974 */ |
9391 Map<String, Element> show(Map<String, Element> definedNames, List<String> show
nNames) { | 9975 Map<String, Element> show(Map<String, Element> definedNames, List<String> show
nNames) { |
9392 Map<String, Element> newNames = new Map<String, Element>(); | 9976 Map<String, Element> newNames = new Map<String, Element>(); |
9393 for (String name in shownNames) { | 9977 for (String name in shownNames) { |
9394 Element element = definedNames[name]; | 9978 Element element = definedNames[name]; |
9395 if (element != null) { | 9979 if (element != null) { |
9396 newNames[name] = element; | 9980 newNames[name] = element; |
9397 } | 9981 } |
9398 String setterName = "${name}="; | 9982 String setterName = "${name}="; |
9399 element = definedNames[setterName]; | 9983 element = definedNames[setterName]; |
9400 if (element != null) { | 9984 if (element != null) { |
9401 newNames[setterName] = element; | 9985 newNames[setterName] = element; |
9402 } | 9986 } |
9403 } | 9987 } |
9404 return newNames; | 9988 return newNames; |
9405 } | 9989 } |
9406 } | 9990 } |
9407 /** | 9991 /** |
9408 * The abstract class `Scope` defines the behavior common to name scopes used by
the resolver | 9992 * The abstract class `Scope` defines the behavior common to name scopes used by
the resolver |
9409 * to determine which names are visible at any given point in the code. | 9993 * to determine which names are visible at any given point in the code. |
| 9994 * |
9410 * @coverage dart.engine.resolver | 9995 * @coverage dart.engine.resolver |
9411 */ | 9996 */ |
9412 abstract class Scope { | 9997 abstract class Scope { |
9413 | 9998 |
9414 /** | 9999 /** |
9415 * The prefix used to mark an identifier as being private to its library. | 10000 * The prefix used to mark an identifier as being private to its library. |
9416 */ | 10001 */ |
9417 static String PRIVATE_NAME_PREFIX = "_"; | 10002 static String PRIVATE_NAME_PREFIX = "_"; |
9418 | 10003 |
9419 /** | 10004 /** |
9420 * The suffix added to the declared name of a setter when looking up the sette
r. Used to | 10005 * The suffix added to the declared name of a setter when looking up the sette
r. Used to |
9421 * disambiguate between a getter and a setter that have the same name. | 10006 * disambiguate between a getter and a setter that have the same name. |
9422 */ | 10007 */ |
9423 static String SETTER_SUFFIX = "="; | 10008 static String SETTER_SUFFIX = "="; |
9424 | 10009 |
9425 /** | 10010 /** |
9426 * The name used to look up the method used to implement the unary minus opera
tor. Used to | 10011 * The name used to look up the method used to implement the unary minus opera
tor. Used to |
9427 * disambiguate between the unary and binary operators. | 10012 * disambiguate between the unary and binary operators. |
9428 */ | 10013 */ |
9429 static String UNARY_MINUS = "unary-"; | 10014 static String UNARY_MINUS = "unary-"; |
9430 | 10015 |
9431 /** | 10016 /** |
9432 * Return `true` if the given name is a library-private name. | 10017 * Return `true` if the given name is a library-private name. |
| 10018 * |
9433 * @param name the name being tested | 10019 * @param name the name being tested |
9434 * @return `true` if the given name is a library-private name | 10020 * @return `true` if the given name is a library-private name |
9435 */ | 10021 */ |
9436 static bool isPrivateName(String name) => name != null && name.startsWith(PRIV
ATE_NAME_PREFIX); | 10022 static bool isPrivateName(String name) => name != null && name.startsWith(PRIV
ATE_NAME_PREFIX); |
9437 | 10023 |
9438 /** | 10024 /** |
9439 * A table mapping names that are defined in this scope to the element represe
nting the thing | 10025 * A table mapping names that are defined in this scope to the element represe
nting the thing |
9440 * declared with that name. | 10026 * declared with that name. |
9441 */ | 10027 */ |
9442 Map<String, Element> _definedNames = new Map<String, Element>(); | 10028 Map<String, Element> _definedNames = new Map<String, Element>(); |
9443 | 10029 |
9444 /** | 10030 /** |
9445 * Add the given element to this scope. If there is already an element with th
e given name defined | 10031 * Add the given element to this scope. If there is already an element with th
e given name defined |
9446 * in this scope, then an error will be generated and the original element wil
l continue to be | 10032 * in this scope, then an error will be generated and the original element wil
l continue to be |
9447 * mapped to the name. If there is an element with the given name in an enclos
ing scope, then a | 10033 * mapped to the name. If there is an element with the given name in an enclos
ing scope, then a |
9448 * warning will be generated but the given element will hide the inherited ele
ment. | 10034 * warning will be generated but the given element will hide the inherited ele
ment. |
| 10035 * |
9449 * @param element the element to be added to this scope | 10036 * @param element the element to be added to this scope |
9450 */ | 10037 */ |
9451 void define(Element element) { | 10038 void define(Element element) { |
9452 String name = getName(element); | 10039 String name = getName(element); |
9453 if (name != null && !name.isEmpty) { | 10040 if (name != null && !name.isEmpty) { |
9454 if (_definedNames.containsKey(name)) { | 10041 if (_definedNames.containsKey(name)) { |
9455 errorListener.onError(getErrorForDuplicate(_definedNames[name], element)
); | 10042 errorListener.onError(getErrorForDuplicate(_definedNames[name], element)
); |
9456 } else { | 10043 } else { |
9457 _definedNames[name] = element; | 10044 _definedNames[name] = element; |
9458 } | 10045 } |
9459 } | 10046 } |
9460 } | 10047 } |
9461 | 10048 |
9462 /** | 10049 /** |
9463 * Return the element with which the given identifier is associated, or `null`
if the name | 10050 * Return the element with which the given identifier is associated, or `null`
if the name |
9464 * is not defined within this scope. | 10051 * is not defined within this scope. |
| 10052 * |
9465 * @param identifier the identifier associated with the element to be returned | 10053 * @param identifier the identifier associated with the element to be returned |
9466 * @param referencingLibrary the library that contains the reference to the na
me, used to | 10054 * @param referencingLibrary the library that contains the reference to the na
me, used to |
9467 * implement library-level privacy | 10055 * implement library-level privacy |
9468 * @return the element with which the given identifier is associated | 10056 * @return the element with which the given identifier is associated |
9469 */ | 10057 */ |
9470 Element lookup(Identifier identifier, LibraryElement referencingLibrary) => lo
okup3(identifier, identifier.name, referencingLibrary); | 10058 Element lookup(Identifier identifier, LibraryElement referencingLibrary) => lo
okup3(identifier, identifier.name, referencingLibrary); |
9471 | 10059 |
9472 /** | 10060 /** |
9473 * Add the given element to this scope without checking for duplication or hid
ing. | 10061 * Add the given element to this scope without checking for duplication or hid
ing. |
| 10062 * |
9474 * @param element the element to be added to this scope | 10063 * @param element the element to be added to this scope |
9475 */ | 10064 */ |
9476 void defineWithoutChecking(Element element) { | 10065 void defineWithoutChecking(Element element) { |
9477 _definedNames[getName(element)] = element; | 10066 _definedNames[getName(element)] = element; |
9478 } | 10067 } |
9479 | 10068 |
9480 /** | 10069 /** |
9481 * Add the given element to this scope without checking for duplication or hid
ing. | 10070 * Add the given element to this scope without checking for duplication or hid
ing. |
| 10071 * |
9482 * @param name the name of the element to be added | 10072 * @param name the name of the element to be added |
9483 * @param element the element to be added to this scope | 10073 * @param element the element to be added to this scope |
9484 */ | 10074 */ |
9485 void defineWithoutChecking2(String name, Element element) { | 10075 void defineWithoutChecking2(String name, Element element) { |
9486 _definedNames[name] = element; | 10076 _definedNames[name] = element; |
9487 } | 10077 } |
9488 | 10078 |
9489 /** | 10079 /** |
9490 * Return the element representing the library in which this scope is enclosed
. | 10080 * Return the element representing the library in which this scope is enclosed
. |
| 10081 * |
9491 * @return the element representing the library in which this scope is enclose
d | 10082 * @return the element representing the library in which this scope is enclose
d |
9492 */ | 10083 */ |
9493 LibraryElement get definingLibrary; | 10084 LibraryElement get definingLibrary; |
9494 | 10085 |
9495 /** | 10086 /** |
9496 * Return the error code to be used when reporting that a name being defined l
ocally conflicts | 10087 * Return the error code to be used when reporting that a name being defined l
ocally conflicts |
9497 * with another element of the same name in the local scope. | 10088 * with another element of the same name in the local scope. |
| 10089 * |
9498 * @param existing the first element to be declared with the conflicting name | 10090 * @param existing the first element to be declared with the conflicting name |
9499 * @param duplicate another element declared with the conflicting name | 10091 * @param duplicate another element declared with the conflicting name |
9500 * @return the error code used to report duplicate names within a scope | 10092 * @return the error code used to report duplicate names within a scope |
9501 */ | 10093 */ |
9502 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { | 10094 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { |
9503 Source source = duplicate.source; | 10095 Source source = duplicate.source; |
9504 if (source == null) { | 10096 if (source == null) { |
9505 source = source; | 10097 source = source; |
9506 } | 10098 } |
9507 return new AnalysisError.con2(source, duplicate.nameOffset, duplicate.displa
yName.length, CompileTimeErrorCode.DUPLICATE_DEFINITION, [existing.displayName])
; | 10099 return new AnalysisError.con2(source, duplicate.nameOffset, duplicate.displa
yName.length, CompileTimeErrorCode.DUPLICATE_DEFINITION, [existing.displayName])
; |
9508 } | 10100 } |
9509 | 10101 |
9510 /** | 10102 /** |
9511 * Return the listener that is to be informed when an error is encountered. | 10103 * Return the listener that is to be informed when an error is encountered. |
| 10104 * |
9512 * @return the listener that is to be informed when an error is encountered | 10105 * @return the listener that is to be informed when an error is encountered |
9513 */ | 10106 */ |
9514 AnalysisErrorListener get errorListener; | 10107 AnalysisErrorListener get errorListener; |
9515 | 10108 |
9516 /** | 10109 /** |
9517 * Return the source object representing the compilation unit with which error
s related to this | 10110 * Return the source object representing the compilation unit with which error
s related to this |
9518 * scope should be associated. | 10111 * scope should be associated. |
| 10112 * |
9519 * @return the source object with which errors should be associated | 10113 * @return the source object with which errors should be associated |
9520 */ | 10114 */ |
9521 Source get source => definingLibrary.definingCompilationUnit.source; | 10115 Source get source => definingLibrary.definingCompilationUnit.source; |
9522 | 10116 |
9523 /** | 10117 /** |
9524 * Return the element with which the given name is associated, or `null` if th
e name is not | 10118 * Return the element with which the given name is associated, or `null` if th
e name is not |
9525 * defined within this scope. This method only returns elements that are direc
tly defined within | 10119 * defined within this scope. This method only returns elements that are direc
tly defined within |
9526 * this scope, not elements that are defined in an enclosing scope. | 10120 * this scope, not elements that are defined in an enclosing scope. |
| 10121 * |
9527 * @param name the name associated with the element to be returned | 10122 * @param name the name associated with the element to be returned |
9528 * @param referencingLibrary the library that contains the reference to the na
me, used to | 10123 * @param referencingLibrary the library that contains the reference to the na
me, used to |
9529 * implement library-level privacy | 10124 * implement library-level privacy |
9530 * @return the element with which the given name is associated | 10125 * @return the element with which the given name is associated |
9531 */ | 10126 */ |
9532 Element localLookup(String name, LibraryElement referencingLibrary) => _define
dNames[name]; | 10127 Element localLookup(String name, LibraryElement referencingLibrary) => _define
dNames[name]; |
9533 | 10128 |
9534 /** | 10129 /** |
9535 * Return the element with which the given name is associated, or `null` if th
e name is not | 10130 * Return the element with which the given name is associated, or `null` if th
e name is not |
9536 * defined within this scope. | 10131 * defined within this scope. |
| 10132 * |
9537 * @param identifier the identifier node to lookup element for, used to report
correct kind of a | 10133 * @param identifier the identifier node to lookup element for, used to report
correct kind of a |
9538 * problem and associate problem with | 10134 * problem and associate problem with |
9539 * @param name the name associated with the element to be returned | 10135 * @param name the name associated with the element to be returned |
9540 * @param referencingLibrary the library that contains the reference to the na
me, used to | 10136 * @param referencingLibrary the library that contains the reference to the na
me, used to |
9541 * implement library-level privacy | 10137 * implement library-level privacy |
9542 * @return the element with which the given name is associated | 10138 * @return the element with which the given name is associated |
9543 */ | 10139 */ |
9544 Element lookup3(Identifier identifier, String name, LibraryElement referencing
Library); | 10140 Element lookup3(Identifier identifier, String name, LibraryElement referencing
Library); |
9545 | 10141 |
9546 /** | 10142 /** |
9547 * Return the name that will be used to look up the given element. | 10143 * Return the name that will be used to look up the given element. |
| 10144 * |
9548 * @param element the element whose look-up name is to be returned | 10145 * @param element the element whose look-up name is to be returned |
9549 * @return the name that will be used to look up the given element | 10146 * @return the name that will be used to look up the given element |
9550 */ | 10147 */ |
9551 String getName(Element element) { | 10148 String getName(Element element) { |
9552 if (element is MethodElement) { | 10149 if (element is MethodElement) { |
9553 MethodElement method = element as MethodElement; | 10150 MethodElement method = element as MethodElement; |
9554 if (method.name == "-" && method.parameters.length == 0) { | 10151 if (method.name == "-" && method.parameters.length == 0) { |
9555 return UNARY_MINUS; | 10152 return UNARY_MINUS; |
9556 } | 10153 } |
9557 } | 10154 } |
9558 return element.name; | 10155 return element.name; |
9559 } | 10156 } |
9560 } | 10157 } |
9561 /** | 10158 /** |
9562 * Instances of the class `ConstantVerifier` traverse an AST structure looking f
or additional | 10159 * Instances of the class `ConstantVerifier` traverse an AST structure looking f
or additional |
9563 * errors and warnings not covered by the parser and resolver. In particular, it
looks for errors | 10160 * errors and warnings not covered by the parser and resolver. In particular, it
looks for errors |
9564 * and warnings related to constant expressions. | 10161 * and warnings related to constant expressions. |
| 10162 * |
9565 * @coverage dart.engine.resolver | 10163 * @coverage dart.engine.resolver |
9566 */ | 10164 */ |
9567 class ConstantVerifier extends RecursiveASTVisitor<Object> { | 10165 class ConstantVerifier extends RecursiveASTVisitor<Object> { |
9568 | 10166 |
9569 /** | 10167 /** |
9570 * The error reporter by which errors will be reported. | 10168 * The error reporter by which errors will be reported. |
9571 */ | 10169 */ |
9572 ErrorReporter _errorReporter; | 10170 ErrorReporter _errorReporter; |
9573 | 10171 |
9574 /** | 10172 /** |
(...skipping 11 matching lines...) Expand all Loading... |
9586 */ | 10184 */ |
9587 InterfaceType _numType; | 10185 InterfaceType _numType; |
9588 | 10186 |
9589 /** | 10187 /** |
9590 * The type representing the type 'string'. | 10188 * The type representing the type 'string'. |
9591 */ | 10189 */ |
9592 InterfaceType _stringType; | 10190 InterfaceType _stringType; |
9593 | 10191 |
9594 /** | 10192 /** |
9595 * Initialize a newly created constant verifier. | 10193 * Initialize a newly created constant verifier. |
| 10194 * |
9596 * @param errorReporter the error reporter by which errors will be reported | 10195 * @param errorReporter the error reporter by which errors will be reported |
9597 */ | 10196 */ |
9598 ConstantVerifier(ErrorReporter errorReporter, TypeProvider typeProvider) { | 10197 ConstantVerifier(ErrorReporter errorReporter, TypeProvider typeProvider) { |
9599 this._errorReporter = errorReporter; | 10198 this._errorReporter = errorReporter; |
9600 this._boolType = typeProvider.boolType; | 10199 this._boolType = typeProvider.boolType; |
9601 this._intType = typeProvider.intType; | 10200 this._intType = typeProvider.intType; |
9602 this._numType = typeProvider.numType; | 10201 this._numType = typeProvider.numType; |
9603 this._stringType = typeProvider.stringType; | 10202 this._stringType = typeProvider.stringType; |
9604 } | 10203 } |
9605 Object visitConstructorDeclaration(ConstructorDeclaration node) { | 10204 Object visitConstructorDeclaration(ConstructorDeclaration node) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9690 reportErrors(result, CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CON
STANT_VALUE); | 10289 reportErrors(result, CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CON
STANT_VALUE); |
9691 } | 10290 } |
9692 } | 10291 } |
9693 return null; | 10292 return null; |
9694 } | 10293 } |
9695 | 10294 |
9696 /** | 10295 /** |
9697 * Return `true` if the given value is the result of evaluating an expression
whose value is | 10296 * Return `true` if the given value is the result of evaluating an expression
whose value is |
9698 * a valid key in a const map literal. Keys in const map literals must be eith
er a string, number, | 10297 * a valid key in a const map literal. Keys in const map literals must be eith
er a string, number, |
9699 * boolean, list, map, or null. | 10298 * boolean, list, map, or null. |
| 10299 * |
9700 * @param value | 10300 * @param value |
9701 * @return `true` if the given value is a valid key in a const map literal | 10301 * @return `true` if the given value is a valid key in a const map literal |
9702 */ | 10302 */ |
9703 bool isValidConstMapKey(Object value) => true; | 10303 bool isValidConstMapKey(Object value) => true; |
9704 | 10304 |
9705 /** | 10305 /** |
9706 * If the given result represents one or more errors, report those errors. Exc
ept for special | 10306 * If the given result represents one or more errors, report those errors. Exc
ept for special |
9707 * cases, use the given error code rather than the one reported in the error. | 10307 * cases, use the given error code rather than the one reported in the error. |
| 10308 * |
9708 * @param result the result containing any errors that need to be reported | 10309 * @param result the result containing any errors that need to be reported |
9709 * @param errorCode the error code to be used if the result represents an erro
r | 10310 * @param errorCode the error code to be used if the result represents an erro
r |
9710 */ | 10311 */ |
9711 void reportErrors(EvaluationResultImpl result, ErrorCode errorCode2) { | 10312 void reportErrors(EvaluationResultImpl result, ErrorCode errorCode2) { |
9712 if (result is ErrorResult) { | 10313 if (result is ErrorResult) { |
9713 for (ErrorResult_ErrorData data in ((result as ErrorResult)).errorData) { | 10314 for (ErrorResult_ErrorData data in ((result as ErrorResult)).errorData) { |
9714 ErrorCode dataErrorCode = data.errorCode; | 10315 ErrorCode dataErrorCode = data.errorCode; |
9715 if (identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCE
PTION) || identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM
_STRING) || identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL)
|| identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_INT) || identic
al(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM)) { | 10316 if (identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCE
PTION) || identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE)
|| identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRIN
G) || identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL) || ide
ntical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_INT) || identical(dat
aErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM)) { |
9716 _errorReporter.reportError2(dataErrorCode, data.node, []); | 10317 _errorReporter.reportError2(dataErrorCode, data.node, []); |
9717 } else { | 10318 } else { |
9718 _errorReporter.reportError2(errorCode2, data.node, []); | 10319 _errorReporter.reportError2(errorCode2, data.node, []); |
9719 } | 10320 } |
9720 } | 10321 } |
9721 } | 10322 } |
9722 } | 10323 } |
9723 | 10324 |
9724 /** | 10325 /** |
9725 * Validate that the given expression is a compile time constant. Return the v
alue of the compile | 10326 * Validate that the given expression is a compile time constant. Return the v
alue of the compile |
9726 * time constant, or `null` if the expression is not a compile time constant. | 10327 * time constant, or `null` if the expression is not a compile time constant. |
| 10328 * |
9727 * @param expression the expression to be validated | 10329 * @param expression the expression to be validated |
9728 * @param errorCode the error code to be used if the expression is not a compi
le time constant | 10330 * @param errorCode the error code to be used if the expression is not a compi
le time constant |
9729 * @return the value of the compile time constant | 10331 * @return the value of the compile time constant |
9730 */ | 10332 */ |
9731 EvaluationResultImpl validate(Expression expression, ErrorCode errorCode) { | 10333 EvaluationResultImpl validate(Expression expression, ErrorCode errorCode) { |
9732 EvaluationResultImpl result = expression.accept(new ConstantVisitor()); | 10334 EvaluationResultImpl result = expression.accept(new ConstantVisitor()); |
9733 reportErrors(result, errorCode); | 10335 reportErrors(result, errorCode); |
9734 return result; | 10336 return result; |
9735 } | 10337 } |
9736 | 10338 |
9737 /** | 10339 /** |
9738 * Validate that if the passed instance creation is 'const' then all its argum
ents are constant | 10340 * Validate that if the passed instance creation is 'const' then all its argum
ents are constant |
9739 * expressions. | 10341 * expressions. |
| 10342 * |
9740 * @param node the instance creation evaluate | 10343 * @param node the instance creation evaluate |
9741 */ | 10344 */ |
9742 void validateConstantArguments(InstanceCreationExpression node) { | 10345 void validateConstantArguments(InstanceCreationExpression node) { |
9743 if (!node.isConst) { | 10346 if (!node.isConst) { |
9744 return; | 10347 return; |
9745 } | 10348 } |
9746 ArgumentList argumentList = node.argumentList; | 10349 ArgumentList argumentList = node.argumentList; |
9747 if (argumentList == null) { | 10350 if (argumentList == null) { |
9748 return; | 10351 return; |
9749 } | 10352 } |
9750 for (Expression argument in argumentList.arguments) { | 10353 for (Expression argument in argumentList.arguments) { |
9751 if (argument is NamedExpression) { | 10354 if (argument is NamedExpression) { |
9752 argument = ((argument as NamedExpression)).expression; | 10355 argument = ((argument as NamedExpression)).expression; |
9753 } | 10356 } |
9754 validate(argument, CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT); | 10357 validate(argument, CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT); |
9755 } | 10358 } |
9756 } | 10359 } |
9757 | 10360 |
9758 /** | 10361 /** |
9759 * Validate that the default value associated with each of the parameters in t
he given list is a | 10362 * Validate that the default value associated with each of the parameters in t
he given list is a |
9760 * compile time constant. | 10363 * compile time constant. |
| 10364 * |
9761 * @param parameters the list of parameters to be validated | 10365 * @param parameters the list of parameters to be validated |
9762 */ | 10366 */ |
9763 void validateDefaultValues(FormalParameterList parameters2) { | 10367 void validateDefaultValues(FormalParameterList parameters2) { |
9764 if (parameters2 == null) { | 10368 if (parameters2 == null) { |
9765 return; | 10369 return; |
9766 } | 10370 } |
9767 for (FormalParameter parameter in parameters2.parameters) { | 10371 for (FormalParameter parameter in parameters2.parameters) { |
9768 if (parameter is DefaultFormalParameter) { | 10372 if (parameter is DefaultFormalParameter) { |
9769 DefaultFormalParameter defaultParameter = parameter as DefaultFormalPara
meter; | 10373 DefaultFormalParameter defaultParameter = parameter as DefaultFormalPara
meter; |
9770 Expression defaultValue = defaultParameter.defaultValue; | 10374 Expression defaultValue = defaultParameter.defaultValue; |
9771 if (defaultValue != null) { | 10375 if (defaultValue != null) { |
9772 EvaluationResultImpl result = validate(defaultValue, CompileTimeErrorC
ode.NON_CONSTANT_DEFAULT_VALUE); | 10376 EvaluationResultImpl result = validate(defaultValue, CompileTimeErrorC
ode.NON_CONSTANT_DEFAULT_VALUE); |
9773 VariableElementImpl element = parameter.element as VariableElementImpl
; | 10377 VariableElementImpl element = parameter.element as VariableElementImpl
; |
9774 element.evaluationResult = result; | 10378 element.evaluationResult = result; |
9775 } | 10379 } |
9776 } | 10380 } |
9777 } | 10381 } |
9778 } | 10382 } |
9779 | 10383 |
9780 /** | 10384 /** |
9781 * Validates that the given expression is a compile time constant. | 10385 * Validates that the given expression is a compile time constant. |
| 10386 * |
9782 * @param parameterElements the elements of parameters of constant constructor
, they are | 10387 * @param parameterElements the elements of parameters of constant constructor
, they are |
9783 * considered as a valid potentially constant expressions | 10388 * considered as a valid potentially constant expressions |
9784 * @param expression the expression to validate | 10389 * @param expression the expression to validate |
9785 */ | 10390 */ |
9786 void validateInitializerExpression(List<ParameterElement> parameterElements, E
xpression expression) { | 10391 void validateInitializerExpression(List<ParameterElement> parameterElements, E
xpression expression) { |
9787 EvaluationResultImpl result = expression.accept(new ConstantVisitor_9(this,
parameterElements)); | 10392 EvaluationResultImpl result = expression.accept(new ConstantVisitor_10(this,
parameterElements)); |
9788 reportErrors(result, CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER)
; | 10393 reportErrors(result, CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER)
; |
9789 } | 10394 } |
9790 | 10395 |
9791 /** | 10396 /** |
9792 * Validates that all of the arguments of a constructor initializer are compil
e time constants. | 10397 * Validates that all of the arguments of a constructor initializer are compil
e time constants. |
| 10398 * |
9793 * @param parameterElements the elements of parameters of constant constructor
, they are | 10399 * @param parameterElements the elements of parameters of constant constructor
, they are |
9794 * considered as a valid potentially constant expressions | 10400 * considered as a valid potentially constant expressions |
9795 * @param argumentList the argument list to validate | 10401 * @param argumentList the argument list to validate |
9796 */ | 10402 */ |
9797 void validateInitializerInvocationArguments(List<ParameterElement> parameterEl
ements, ArgumentList argumentList) { | 10403 void validateInitializerInvocationArguments(List<ParameterElement> parameterEl
ements, ArgumentList argumentList) { |
9798 if (argumentList == null) { | 10404 if (argumentList == null) { |
9799 return; | 10405 return; |
9800 } | 10406 } |
9801 for (Expression argument in argumentList.arguments) { | 10407 for (Expression argument in argumentList.arguments) { |
9802 validateInitializerExpression(parameterElements, argument); | 10408 validateInitializerExpression(parameterElements, argument); |
9803 } | 10409 } |
9804 } | 10410 } |
9805 | 10411 |
9806 /** | 10412 /** |
9807 * Validates that the expressions of the given initializers (of a constant con
structor) are all | 10413 * Validates that the expressions of the given initializers (of a constant con
structor) are all |
9808 * compile time constants. | 10414 * compile time constants. |
| 10415 * |
9809 * @param constructor the constant constructor declaration to validate | 10416 * @param constructor the constant constructor declaration to validate |
9810 */ | 10417 */ |
9811 void validateInitializers(ConstructorDeclaration constructor) { | 10418 void validateInitializers(ConstructorDeclaration constructor) { |
9812 List<ParameterElement> parameterElements = constructor.parameters.elements; | 10419 List<ParameterElement> parameterElements = constructor.parameters.elements; |
9813 NodeList<ConstructorInitializer> initializers = constructor.initializers; | 10420 NodeList<ConstructorInitializer> initializers = constructor.initializers; |
9814 for (ConstructorInitializer initializer in initializers) { | 10421 for (ConstructorInitializer initializer in initializers) { |
9815 if (initializer is ConstructorFieldInitializer) { | 10422 if (initializer is ConstructorFieldInitializer) { |
9816 ConstructorFieldInitializer fieldInitializer = initializer as Constructo
rFieldInitializer; | 10423 ConstructorFieldInitializer fieldInitializer = initializer as Constructo
rFieldInitializer; |
9817 validateInitializerExpression(parameterElements, fieldInitializer.expres
sion); | 10424 validateInitializerExpression(parameterElements, fieldInitializer.expres
sion); |
9818 } | 10425 } |
9819 if (initializer is RedirectingConstructorInvocation) { | 10426 if (initializer is RedirectingConstructorInvocation) { |
9820 RedirectingConstructorInvocation invocation = initializer as Redirecting
ConstructorInvocation; | 10427 RedirectingConstructorInvocation invocation = initializer as Redirecting
ConstructorInvocation; |
9821 validateInitializerInvocationArguments(parameterElements, invocation.arg
umentList); | 10428 validateInitializerInvocationArguments(parameterElements, invocation.arg
umentList); |
9822 } | 10429 } |
9823 if (initializer is SuperConstructorInvocation) { | 10430 if (initializer is SuperConstructorInvocation) { |
9824 SuperConstructorInvocation invocation = initializer as SuperConstructorI
nvocation; | 10431 SuperConstructorInvocation invocation = initializer as SuperConstructorI
nvocation; |
9825 validateInitializerInvocationArguments(parameterElements, invocation.arg
umentList); | 10432 validateInitializerInvocationArguments(parameterElements, invocation.arg
umentList); |
9826 } | 10433 } |
9827 } | 10434 } |
9828 } | 10435 } |
9829 } | 10436 } |
9830 class ConstantVisitor_9 extends ConstantVisitor { | 10437 class ConstantVisitor_10 extends ConstantVisitor { |
9831 final ConstantVerifier ConstantVerifier_this; | 10438 final ConstantVerifier ConstantVerifier_this; |
9832 List<ParameterElement> parameterElements; | 10439 List<ParameterElement> parameterElements; |
9833 ConstantVisitor_9(this.ConstantVerifier_this, this.parameterElements) : super(
); | 10440 ConstantVisitor_10(this.ConstantVerifier_this, this.parameterElements) : super
(); |
9834 EvaluationResultImpl visitSimpleIdentifier(SimpleIdentifier node) { | 10441 EvaluationResultImpl visitSimpleIdentifier(SimpleIdentifier node) { |
9835 Element element = node.element; | 10442 Element element = node.element; |
9836 for (ParameterElement parameterElement in parameterElements) { | 10443 for (ParameterElement parameterElement in parameterElements) { |
9837 if (identical(parameterElement, element) && parameterElement != null) { | 10444 if (identical(parameterElement, element) && parameterElement != null) { |
9838 Type2 type = parameterElement.type; | 10445 Type2 type = parameterElement.type; |
9839 if (type != null) { | 10446 if (type != null) { |
9840 if (type.isDynamic) { | 10447 if (type.isDynamic) { |
9841 return ValidResult.RESULT_DYNAMIC; | 10448 return ValidResult.RESULT_DYNAMIC; |
9842 } | 10449 } |
9843 if (type.isSubtypeOf(ConstantVerifier_this._boolType)) { | 10450 if (type.isSubtypeOf(ConstantVerifier_this._boolType)) { |
(...skipping 11 matching lines...) Expand all Loading... |
9855 } | 10462 } |
9856 return ValidResult.RESULT_OBJECT; | 10463 return ValidResult.RESULT_OBJECT; |
9857 } | 10464 } |
9858 } | 10465 } |
9859 return super.visitSimpleIdentifier(node); | 10466 return super.visitSimpleIdentifier(node); |
9860 } | 10467 } |
9861 } | 10468 } |
9862 /** | 10469 /** |
9863 * Instances of the class `ErrorVerifier` traverse an AST structure looking for
additional | 10470 * Instances of the class `ErrorVerifier` traverse an AST structure looking for
additional |
9864 * errors and warnings not covered by the parser and resolver. | 10471 * errors and warnings not covered by the parser and resolver. |
| 10472 * |
9865 * @coverage dart.engine.resolver | 10473 * @coverage dart.engine.resolver |
9866 */ | 10474 */ |
9867 class ErrorVerifier extends RecursiveASTVisitor<Object> { | 10475 class ErrorVerifier extends RecursiveASTVisitor<Object> { |
9868 | 10476 |
9869 /** | 10477 /** |
9870 * Checks if the given expression is the reference to the type. | 10478 * Checks if the given expression is the reference to the type. |
| 10479 * |
9871 * @param expr the expression to evaluate | 10480 * @param expr the expression to evaluate |
9872 * @return `true` if the given expression is the reference to the type | 10481 * @return `true` if the given expression is the reference to the type |
9873 */ | 10482 */ |
9874 static bool isTypeReference(Expression expr) { | 10483 static bool isTypeReference(Expression expr) { |
9875 if (expr is Identifier) { | 10484 if (expr is Identifier) { |
9876 Identifier identifier = expr as Identifier; | 10485 Identifier identifier = expr as Identifier; |
9877 return identifier.element is ClassElement; | 10486 return identifier.element is ClassElement; |
9878 } | 10487 } |
9879 return false; | 10488 return false; |
9880 } | 10489 } |
(...skipping 23 matching lines...) Expand all Loading... |
9904 */ | 10513 */ |
9905 InheritanceManager _inheritanceManager; | 10514 InheritanceManager _inheritanceManager; |
9906 | 10515 |
9907 /** | 10516 /** |
9908 * A flag indicating whether we are running in strict mode. In strict mode, er
ror reporting is | 10517 * A flag indicating whether we are running in strict mode. In strict mode, er
ror reporting is |
9909 * based exclusively on the static type information. | 10518 * based exclusively on the static type information. |
9910 */ | 10519 */ |
9911 bool _strictMode = false; | 10520 bool _strictMode = false; |
9912 | 10521 |
9913 /** | 10522 /** |
9914 * This is set to `true` iff the visitor is currently visiting children nodes
of a[ConstructorDeclaration] and the constructor is 'const'. | 10523 * This is set to `true` iff the visitor is currently visiting children nodes
of a |
| 10524 * [ConstructorDeclaration] and the constructor is 'const'. |
| 10525 * |
9915 * @see #visitConstructorDeclaration(ConstructorDeclaration) | 10526 * @see #visitConstructorDeclaration(ConstructorDeclaration) |
9916 */ | 10527 */ |
9917 bool _isEnclosingConstructorConst = false; | 10528 bool _isEnclosingConstructorConst = false; |
9918 | 10529 |
9919 /** | 10530 /** |
9920 * This is set to `true` iff the visitor is currently visiting children nodes
of a[CatchClause]. | 10531 * This is set to `true` iff the visitor is currently visiting children nodes
of a |
| 10532 * [CatchClause]. |
| 10533 * |
9921 * @see #visitCatchClause(CatchClause) | 10534 * @see #visitCatchClause(CatchClause) |
9922 */ | 10535 */ |
9923 bool _isInCatchClause = false; | 10536 bool _isInCatchClause = false; |
9924 | 10537 |
9925 /** | 10538 /** |
9926 * This is set to `true` iff the visitor is currently visiting a[ConstructorIn
itializer]. | 10539 * This is set to `true` iff the visitor is currently visiting an instance var
iable |
| 10540 * declaration. |
| 10541 */ |
| 10542 bool _isInInstanceVariableDeclaration = false; |
| 10543 |
| 10544 /** |
| 10545 * This is set to `true` iff the visitor is currently visiting an instance var
iable |
| 10546 * initializer. |
| 10547 */ |
| 10548 bool _isInInstanceVariableInitializer = false; |
| 10549 |
| 10550 /** |
| 10551 * This is set to `true` iff the visitor is currently visiting a |
| 10552 * [ConstructorInitializer]. |
9927 */ | 10553 */ |
9928 bool _isInConstructorInitializer = false; | 10554 bool _isInConstructorInitializer = false; |
9929 | 10555 |
9930 /** | 10556 /** |
| 10557 * This is set to `true` iff the visitor is currently visiting a static method
. |
| 10558 */ |
| 10559 bool _isInStaticMethod = false; |
| 10560 |
| 10561 /** |
9931 * This is set to `true` iff the visitor is currently visiting code in the SDK
. | 10562 * This is set to `true` iff the visitor is currently visiting code in the SDK
. |
9932 */ | 10563 */ |
9933 bool _isInSystemLibrary = false; | 10564 bool _isInSystemLibrary = false; |
9934 | 10565 |
9935 /** | 10566 /** |
9936 * The class containing the AST nodes being visited, or `null` if we are not i
n the scope of | 10567 * The class containing the AST nodes being visited, or `null` if we are not i
n the scope of |
9937 * a class. | 10568 * a class. |
9938 */ | 10569 */ |
9939 ClassElement _enclosingClass; | 10570 ClassElement _enclosingClass; |
9940 | 10571 |
9941 /** | 10572 /** |
9942 * The method or function that we are currently visiting, or `null` if we are
not inside a | 10573 * The method or function that we are currently visiting, or `null` if we are
not inside a |
9943 * method or function. | 10574 * method or function. |
9944 */ | 10575 */ |
9945 ExecutableElement _enclosingFunction; | 10576 ExecutableElement _enclosingFunction; |
9946 | 10577 |
9947 /** | 10578 /** |
9948 * This map is initialized when visiting the contents of a class declaration.
If the visitor is | 10579 * This map is initialized when visiting the contents of a class declaration.
If the visitor is |
9949 * not in an enclosing class declaration, then the map is set to `null`. | 10580 * not in an enclosing class declaration, then the map is set to `null`. |
9950 * | 10581 * |
9951 * When set the map maps the set of [FieldElement]s in the class to an[INIT_ST
ATE#NOT_INIT] or [INIT_STATE#INIT_IN_DECLARATION]. <code>checkFor*</code> | 10582 * When set the map maps the set of [FieldElement]s in the class to an |
| 10583 * [INIT_STATE#NOT_INIT] or [INIT_STATE#INIT_IN_DECLARATION]. <code>checkFor*<
/code> |
9952 * methods, specifically [checkForAllFinalInitializedErrorCodes], | 10584 * methods, specifically [checkForAllFinalInitializedErrorCodes], |
9953 * can make a copy of the map to compute error code states. <code>checkFor*</c
ode> methods should | 10585 * can make a copy of the map to compute error code states. <code>checkFor*</c
ode> methods should |
9954 * only ever make a copy, or read from this map after it has been set in[visit
ClassDeclaration]. | 10586 * only ever make a copy, or read from this map after it has been set in |
| 10587 * [visitClassDeclaration]. |
| 10588 * |
9955 * @see #visitClassDeclaration(ClassDeclaration) | 10589 * @see #visitClassDeclaration(ClassDeclaration) |
9956 * @see #checkForAllFinalInitializedErrorCodes(ConstructorDeclaration) | 10590 * @see #checkForAllFinalInitializedErrorCodes(ConstructorDeclaration) |
9957 */ | 10591 */ |
9958 Map<FieldElement, INIT_STATE> _initialFieldElementsMap; | 10592 Map<FieldElement, INIT_STATE> _initialFieldElementsMap; |
9959 | 10593 |
9960 /** | 10594 /** |
9961 * A table mapping name of the library to the export directive which export th
is library. | 10595 * A table mapping name of the library to the export directive which export th
is library. |
9962 */ | 10596 */ |
9963 Map<String, LibraryElement> _nameToExportElement = new Map<String, LibraryElem
ent>(); | 10597 Map<String, LibraryElement> _nameToExportElement = new Map<String, LibraryElem
ent>(); |
9964 | 10598 |
9965 /** | 10599 /** |
9966 * A table mapping name of the library to the import directive which import th
is library. | 10600 * A table mapping name of the library to the import directive which import th
is library. |
9967 */ | 10601 */ |
9968 Map<String, LibraryElement> _nameToImportElement = new Map<String, LibraryElem
ent>(); | 10602 Map<String, LibraryElement> _nameToImportElement = new Map<String, LibraryElem
ent>(); |
9969 | 10603 |
9970 /** | 10604 /** |
9971 * A table mapping names to the export elements exported them. | 10605 * A table mapping names to the export elements exported them. |
9972 */ | 10606 */ |
9973 Map<String, ExportElement> _exportedNames = new Map<String, ExportElement>(); | 10607 Map<String, ExportElement> _exportedNames = new Map<String, ExportElement>(); |
9974 | 10608 |
9975 /** | 10609 /** |
9976 * A set of the names of the variable initializers we are visiting now. | 10610 * A set of the names of the variable initializers we are visiting now. |
9977 */ | 10611 */ |
9978 Set<String> _namesForReferenceToDeclaredVariableInInitializer = new Set<String
>(); | 10612 Set<String> _namesForReferenceToDeclaredVariableInInitializer = new Set<String
>(); |
9979 | 10613 |
9980 /** | 10614 /** |
9981 * A list of types used by the [CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS]
and[CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS] error codes. | 10615 * A list of types used by the [CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS]
and |
| 10616 * [CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS] error codes. |
9982 */ | 10617 */ |
9983 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT; | 10618 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT; |
9984 ErrorVerifier(ErrorReporter errorReporter, LibraryElement currentLibrary, Type
Provider typeProvider, InheritanceManager inheritanceManager) { | 10619 ErrorVerifier(ErrorReporter errorReporter, LibraryElement currentLibrary, Type
Provider typeProvider, InheritanceManager inheritanceManager) { |
9985 this._errorReporter = errorReporter; | 10620 this._errorReporter = errorReporter; |
9986 this._currentLibrary = currentLibrary; | 10621 this._currentLibrary = currentLibrary; |
9987 this._isInSystemLibrary = currentLibrary.source.isInSystemLibrary; | 10622 this._isInSystemLibrary = currentLibrary.source.isInSystemLibrary; |
9988 this._typeProvider = typeProvider; | 10623 this._typeProvider = typeProvider; |
9989 this._inheritanceManager = inheritanceManager; | 10624 this._inheritanceManager = inheritanceManager; |
9990 _strictMode = currentLibrary.context.analysisOptions.strictMode; | 10625 _strictMode = currentLibrary.context.analysisOptions.strictMode; |
9991 _isEnclosingConstructorConst = false; | 10626 _isEnclosingConstructorConst = false; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10051 if (classElement != null) { | 10686 if (classElement != null) { |
10052 List<FieldElement> fieldElements = classElement.fields; | 10687 List<FieldElement> fieldElements = classElement.fields; |
10053 _initialFieldElementsMap = new Map<FieldElement, INIT_STATE>(); | 10688 _initialFieldElementsMap = new Map<FieldElement, INIT_STATE>(); |
10054 for (FieldElement fieldElement in fieldElements) { | 10689 for (FieldElement fieldElement in fieldElements) { |
10055 if (!fieldElement.isSynthetic) { | 10690 if (!fieldElement.isSynthetic) { |
10056 _initialFieldElementsMap[fieldElement] = fieldElement.initializer ==
null ? INIT_STATE.NOT_INIT : INIT_STATE.INIT_IN_DECLARATION; | 10691 _initialFieldElementsMap[fieldElement] = fieldElement.initializer ==
null ? INIT_STATE.NOT_INIT : INIT_STATE.INIT_IN_DECLARATION; |
10057 } | 10692 } |
10058 } | 10693 } |
10059 } | 10694 } |
10060 checkForFinalNotInitialized(node); | 10695 checkForFinalNotInitialized(node); |
| 10696 checkForDuplicateDefinitionInheritance(); |
| 10697 checkForConflictingGetterAndMethod(); |
10061 return super.visitClassDeclaration(node); | 10698 return super.visitClassDeclaration(node); |
10062 } finally { | 10699 } finally { |
10063 _initialFieldElementsMap = null; | 10700 _initialFieldElementsMap = null; |
10064 _enclosingClass = outerClass; | 10701 _enclosingClass = outerClass; |
10065 } | 10702 } |
10066 } | 10703 } |
10067 Object visitClassTypeAlias(ClassTypeAlias node) { | 10704 Object visitClassTypeAlias(ClassTypeAlias node) { |
10068 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE
NTIFIER_AS_TYPEDEF_NAME); | 10705 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE
NTIFIER_AS_TYPEDEF_NAME); |
10069 checkForAllMixinErrorCodes(node.withClause); | 10706 checkForAllMixinErrorCodes(node.withClause); |
10070 ClassElement outerClassElement = _enclosingClass; | 10707 ClassElement outerClassElement = _enclosingClass; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10130 checkForReturnOfInvalidType(node.expression, expectedReturnType); | 10767 checkForReturnOfInvalidType(node.expression, expectedReturnType); |
10131 return super.visitExpressionFunctionBody(node); | 10768 return super.visitExpressionFunctionBody(node); |
10132 } | 10769 } |
10133 Object visitFieldDeclaration(FieldDeclaration node) { | 10770 Object visitFieldDeclaration(FieldDeclaration node) { |
10134 if (!node.isStatic) { | 10771 if (!node.isStatic) { |
10135 VariableDeclarationList variables = node.fields; | 10772 VariableDeclarationList variables = node.fields; |
10136 if (variables.isConst) { | 10773 if (variables.isConst) { |
10137 _errorReporter.reportError4(CompileTimeErrorCode.CONST_INSTANCE_FIELD, v
ariables.keyword, []); | 10774 _errorReporter.reportError4(CompileTimeErrorCode.CONST_INSTANCE_FIELD, v
ariables.keyword, []); |
10138 } | 10775 } |
10139 } | 10776 } |
10140 return super.visitFieldDeclaration(node); | 10777 _isInInstanceVariableDeclaration = !node.isStatic; |
| 10778 try { |
| 10779 return super.visitFieldDeclaration(node); |
| 10780 } finally { |
| 10781 _isInInstanceVariableDeclaration = false; |
| 10782 } |
10141 } | 10783 } |
10142 Object visitFieldFormalParameter(FieldFormalParameter node) { | 10784 Object visitFieldFormalParameter(FieldFormalParameter node) { |
10143 checkForConstFormalParameter(node); | 10785 checkForConstFormalParameter(node); |
10144 checkForFieldInitializingFormalRedirectingConstructor(node); | 10786 checkForFieldInitializingFormalRedirectingConstructor(node); |
10145 return super.visitFieldFormalParameter(node); | 10787 return super.visitFieldFormalParameter(node); |
10146 } | 10788 } |
10147 Object visitFunctionDeclaration(FunctionDeclaration node) { | 10789 Object visitFunctionDeclaration(FunctionDeclaration node) { |
10148 ExecutableElement outerFunction = _enclosingFunction; | 10790 ExecutableElement outerFunction = _enclosingFunction; |
10149 try { | 10791 try { |
10150 SimpleIdentifier identifier = node.name; | 10792 SimpleIdentifier identifier = node.name; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10207 if (type is InterfaceType) { | 10849 if (type is InterfaceType) { |
10208 InterfaceType interfaceType = type as InterfaceType; | 10850 InterfaceType interfaceType = type as InterfaceType; |
10209 checkForConstOrNewWithAbstractClass(node, typeName, interfaceType); | 10851 checkForConstOrNewWithAbstractClass(node, typeName, interfaceType); |
10210 if (node.isConst) { | 10852 if (node.isConst) { |
10211 checkForConstWithNonConst(node); | 10853 checkForConstWithNonConst(node); |
10212 checkForConstWithUndefinedConstructor(node); | 10854 checkForConstWithUndefinedConstructor(node); |
10213 checkForConstWithTypeParameters(node); | 10855 checkForConstWithTypeParameters(node); |
10214 } else { | 10856 } else { |
10215 checkForNewWithUndefinedConstructor(node); | 10857 checkForNewWithUndefinedConstructor(node); |
10216 } | 10858 } |
10217 checkForTypeArgumentNotMatchingBounds(node, constructorName.element, typeN
ame); | |
10218 } | 10859 } |
10219 return super.visitInstanceCreationExpression(node); | 10860 return super.visitInstanceCreationExpression(node); |
10220 } | 10861 } |
10221 Object visitListLiteral(ListLiteral node) { | 10862 Object visitListLiteral(ListLiteral node) { |
10222 if (node.modifier != null) { | 10863 if (node.modifier != null) { |
10223 TypeArgumentList typeArguments = node.typeArguments; | 10864 TypeArgumentList typeArguments = node.typeArguments; |
10224 if (typeArguments != null) { | 10865 if (typeArguments != null) { |
10225 NodeList<TypeName> arguments = typeArguments.arguments; | 10866 NodeList<TypeName> arguments = typeArguments.arguments; |
10226 if (arguments.length != 0) { | 10867 if (arguments.length != 0) { |
10227 checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTimeE
rrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST); | 10868 checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTimeE
rrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST); |
(...skipping 12 matching lines...) Expand all Loading... |
10240 checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTimeE
rrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP); | 10881 checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTimeE
rrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP); |
10241 } | 10882 } |
10242 } | 10883 } |
10243 } | 10884 } |
10244 checkForNonConstMapAsExpressionStatement(node); | 10885 checkForNonConstMapAsExpressionStatement(node); |
10245 return super.visitMapLiteral(node); | 10886 return super.visitMapLiteral(node); |
10246 } | 10887 } |
10247 Object visitMethodDeclaration(MethodDeclaration node) { | 10888 Object visitMethodDeclaration(MethodDeclaration node) { |
10248 ExecutableElement previousFunction = _enclosingFunction; | 10889 ExecutableElement previousFunction = _enclosingFunction; |
10249 try { | 10890 try { |
| 10891 _isInStaticMethod = node.isStatic; |
10250 _enclosingFunction = node.element; | 10892 _enclosingFunction = node.element; |
10251 SimpleIdentifier identifier = node.name; | 10893 SimpleIdentifier identifier = node.name; |
10252 String methoName = ""; | 10894 String methodName = ""; |
10253 if (identifier != null) { | 10895 if (identifier != null) { |
10254 methoName = identifier.name; | 10896 methodName = identifier.name; |
10255 } | 10897 } |
10256 if (node.isSetter || node.isGetter) { | 10898 if (node.isSetter || node.isGetter) { |
10257 checkForMismatchedAccessorTypes(node, methoName); | 10899 checkForMismatchedAccessorTypes(node, methodName); |
10258 checkForConflictingInstanceGetterAndSuperclassMember(node); | 10900 checkForConflictingInstanceGetterAndSuperclassMember(node); |
10259 } | 10901 } |
10260 if (node.isGetter) { | 10902 if (node.isGetter) { |
10261 checkForConflictingStaticGetterAndInstanceSetter(node); | 10903 checkForConflictingStaticGetterAndInstanceSetter(node); |
10262 } else if (node.isSetter) { | 10904 } else if (node.isSetter) { |
10263 checkForWrongNumberOfParametersForSetter(node.name, node.parameters); | 10905 checkForWrongNumberOfParametersForSetter(node.name, node.parameters); |
10264 checkForNonVoidReturnTypeForSetter(node.returnType); | 10906 checkForNonVoidReturnTypeForSetter(node.returnType); |
10265 checkForConflictingStaticSetterAndInstanceMember(node); | 10907 checkForConflictingStaticSetterAndInstanceMember(node); |
10266 } else if (node.isOperator) { | 10908 } else if (node.isOperator) { |
10267 checkForOptionalParameterInOperator(node); | 10909 checkForOptionalParameterInOperator(node); |
10268 checkForWrongNumberOfParametersForOperator(node); | 10910 checkForWrongNumberOfParametersForOperator(node); |
10269 checkForNonVoidReturnTypeForOperator(node); | 10911 checkForNonVoidReturnTypeForOperator(node); |
10270 } | 10912 } |
10271 checkForConcreteClassWithAbstractMember(node); | 10913 checkForConcreteClassWithAbstractMember(node); |
10272 checkForAllInvalidOverrideErrorCodes(node); | 10914 checkForAllInvalidOverrideErrorCodes(node); |
10273 return super.visitMethodDeclaration(node); | 10915 return super.visitMethodDeclaration(node); |
10274 } finally { | 10916 } finally { |
10275 _enclosingFunction = previousFunction; | 10917 _enclosingFunction = previousFunction; |
| 10918 _isInStaticMethod = false; |
10276 } | 10919 } |
10277 } | 10920 } |
10278 Object visitMethodInvocation(MethodInvocation node) { | 10921 Object visitMethodInvocation(MethodInvocation node) { |
10279 checkForStaticAccessToInstanceMember(node.target, node.methodName); | 10922 checkForStaticAccessToInstanceMember(node.target, node.methodName); |
10280 return super.visitMethodInvocation(node); | 10923 return super.visitMethodInvocation(node); |
10281 } | 10924 } |
10282 Object visitNativeFunctionBody(NativeFunctionBody node) { | 10925 Object visitNativeFunctionBody(NativeFunctionBody node) { |
10283 checkForNativeFunctionBodyInNonSDKCode(node); | 10926 checkForNativeFunctionBodyInNonSDKCode(node); |
10284 return super.visitNativeFunctionBody(node); | 10927 return super.visitNativeFunctionBody(node); |
10285 } | 10928 } |
10286 Object visitPostfixExpression(PostfixExpression node) { | 10929 Object visitPostfixExpression(PostfixExpression node) { |
10287 checkForAssignmentToFinal2(node.operand); | 10930 checkForAssignmentToFinal2(node.operand); |
10288 return super.visitPostfixExpression(node); | 10931 return super.visitPostfixExpression(node); |
10289 } | 10932 } |
10290 Object visitPrefixedIdentifier(PrefixedIdentifier node) { | 10933 Object visitPrefixedIdentifier(PrefixedIdentifier node) { |
10291 checkForStaticAccessToInstanceMember(node.prefix, node.identifier); | 10934 if (node.parent is! Annotation) { |
| 10935 checkForStaticAccessToInstanceMember(node.prefix, node.identifier); |
| 10936 } |
10292 return super.visitPrefixedIdentifier(node); | 10937 return super.visitPrefixedIdentifier(node); |
10293 } | 10938 } |
10294 Object visitPrefixExpression(PrefixExpression node) { | 10939 Object visitPrefixExpression(PrefixExpression node) { |
10295 if (node.operator.type.isIncrementOperator) { | 10940 if (node.operator.type.isIncrementOperator) { |
10296 checkForAssignmentToFinal2(node.operand); | 10941 checkForAssignmentToFinal2(node.operand); |
10297 } | 10942 } |
10298 return super.visitPrefixExpression(node); | 10943 return super.visitPrefixExpression(node); |
10299 } | 10944 } |
10300 Object visitPropertyAccess(PropertyAccess node) { | 10945 Object visitPropertyAccess(PropertyAccess node) { |
10301 checkForStaticAccessToInstanceMember(node.target, node.propertyName); | 10946 checkForStaticAccessToInstanceMember(node.target, node.propertyName); |
(...skipping 26 matching lines...) Expand all Loading... |
10328 } | 10973 } |
10329 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { | 10974 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { |
10330 _isInConstructorInitializer = true; | 10975 _isInConstructorInitializer = true; |
10331 try { | 10976 try { |
10332 return super.visitSuperConstructorInvocation(node); | 10977 return super.visitSuperConstructorInvocation(node); |
10333 } finally { | 10978 } finally { |
10334 _isInConstructorInitializer = false; | 10979 _isInConstructorInitializer = false; |
10335 } | 10980 } |
10336 } | 10981 } |
10337 Object visitSwitchStatement(SwitchStatement node) { | 10982 Object visitSwitchStatement(SwitchStatement node) { |
10338 checkForCaseExpressionTypeImplementsEquals(node); | |
10339 checkForInconsistentCaseExpressionTypes(node); | 10983 checkForInconsistentCaseExpressionTypes(node); |
10340 checkForSwitchExpressionNotAssignable(node); | 10984 checkForSwitchExpressionNotAssignable(node); |
10341 checkForCaseBlocksNotTerminated(node); | 10985 checkForCaseBlocksNotTerminated(node); |
10342 return super.visitSwitchStatement(node); | 10986 return super.visitSwitchStatement(node); |
10343 } | 10987 } |
10344 Object visitThisExpression(ThisExpression node) { | 10988 Object visitThisExpression(ThisExpression node) { |
10345 checkForInvalidReferenceToThis(node); | 10989 checkForInvalidReferenceToThis(node); |
10346 return super.visitThisExpression(node); | 10990 return super.visitThisExpression(node); |
10347 } | 10991 } |
10348 Object visitThrowExpression(ThrowExpression node) { | 10992 Object visitThrowExpression(ThrowExpression node) { |
10349 checkForConstEvalThrowsException(node); | 10993 checkForConstEvalThrowsException(node); |
10350 return super.visitThrowExpression(node); | 10994 return super.visitThrowExpression(node); |
10351 } | 10995 } |
10352 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { | 10996 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { |
10353 checkForFinalNotInitialized2(node.variables); | 10997 checkForFinalNotInitialized2(node.variables); |
10354 return super.visitTopLevelVariableDeclaration(node); | 10998 return super.visitTopLevelVariableDeclaration(node); |
10355 } | 10999 } |
| 11000 Object visitTypeName(TypeName node) { |
| 11001 checkForTypeArgumentNotMatchingBounds(node); |
| 11002 return super.visitTypeName(node); |
| 11003 } |
10356 Object visitTypeParameter(TypeParameter node) { | 11004 Object visitTypeParameter(TypeParameter node) { |
10357 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE
NTIFIER_AS_TYPE_VARIABLE_NAME); | 11005 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE
NTIFIER_AS_TYPE_VARIABLE_NAME); |
10358 return super.visitTypeParameter(node); | 11006 return super.visitTypeParameter(node); |
10359 } | 11007 } |
10360 Object visitVariableDeclaration(VariableDeclaration node) { | 11008 Object visitVariableDeclaration(VariableDeclaration node) { |
10361 SimpleIdentifier nameNode = node.name; | 11009 SimpleIdentifier nameNode = node.name; |
10362 Expression initializerNode = node.initializer; | 11010 Expression initializerNode = node.initializer; |
10363 checkForInvalidAssignment2(nameNode, initializerNode); | 11011 checkForInvalidAssignment2(nameNode, initializerNode); |
10364 nameNode.accept(this); | 11012 nameNode.accept(this); |
10365 String name = nameNode.name; | 11013 String name = nameNode.name; |
10366 javaSetAdd(_namesForReferenceToDeclaredVariableInInitializer, name); | 11014 javaSetAdd(_namesForReferenceToDeclaredVariableInInitializer, name); |
| 11015 _isInInstanceVariableInitializer = _isInInstanceVariableDeclaration; |
10367 try { | 11016 try { |
10368 if (initializerNode != null) { | 11017 if (initializerNode != null) { |
10369 initializerNode.accept(this); | 11018 initializerNode.accept(this); |
10370 } | 11019 } |
10371 } finally { | 11020 } finally { |
| 11021 _isInInstanceVariableInitializer = false; |
10372 _namesForReferenceToDeclaredVariableInInitializer.remove(name); | 11022 _namesForReferenceToDeclaredVariableInInitializer.remove(name); |
10373 } | 11023 } |
10374 return null; | 11024 return null; |
10375 } | 11025 } |
10376 Object visitVariableDeclarationList(VariableDeclarationList node) { | 11026 Object visitVariableDeclarationList(VariableDeclarationList node) { |
10377 checkForBuiltInIdentifierAsName2(node); | 11027 checkForBuiltInIdentifierAsName2(node); |
10378 return super.visitVariableDeclarationList(node); | 11028 return super.visitVariableDeclarationList(node); |
10379 } | 11029 } |
10380 Object visitVariableDeclarationStatement(VariableDeclarationStatement node) { | 11030 Object visitVariableDeclarationStatement(VariableDeclarationStatement node) { |
10381 checkForFinalNotInitialized2(node.variables); | 11031 checkForFinalNotInitialized2(node.variables); |
10382 return super.visitVariableDeclarationStatement(node); | 11032 return super.visitVariableDeclarationStatement(node); |
10383 } | 11033 } |
10384 Object visitWhileStatement(WhileStatement node) { | 11034 Object visitWhileStatement(WhileStatement node) { |
10385 checkForNonBoolCondition(node.condition); | 11035 checkForNonBoolCondition(node.condition); |
10386 return super.visitWhileStatement(node); | 11036 return super.visitWhileStatement(node); |
10387 } | 11037 } |
10388 | 11038 |
10389 /** | 11039 /** |
10390 * This verifies that the passed constructor declaration does not violate any
of the error codes | 11040 * This verifies that the passed constructor declaration does not violate any
of the error codes |
10391 * relating to the initialization of fields in the enclosing class. | 11041 * relating to the initialization of fields in the enclosing class. |
| 11042 * |
10392 * @param node the [ConstructorDeclaration] to evaluate | 11043 * @param node the [ConstructorDeclaration] to evaluate |
10393 * @return `true` if and only if an error code is generated on the passed node | 11044 * @return `true` if and only if an error code is generated on the passed node |
10394 * @see #initialFieldElementsMap | 11045 * @see #initialFieldElementsMap |
10395 * @see CompileTimeErrorCode#FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR | 11046 * @see CompileTimeErrorCode#FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR |
10396 * @see CompileTimeErrorCode#FINAL_INITIALIZED_MULTIPLE_TIMES | 11047 * @see CompileTimeErrorCode#FINAL_INITIALIZED_MULTIPLE_TIMES |
10397 */ | 11048 */ |
10398 bool checkForAllFinalInitializedErrorCodes(ConstructorDeclaration node) { | 11049 bool checkForAllFinalInitializedErrorCodes(ConstructorDeclaration node) { |
10399 if (node.factoryKeyword != null || node.redirectedConstructor != null || nod
e.externalKeyword != null) { | 11050 if (node.factoryKeyword != null || node.redirectedConstructor != null || nod
e.externalKeyword != null) { |
10400 return false; | 11051 return false; |
10401 } | 11052 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10449 foundError = true; | 11100 foundError = true; |
10450 } | 11101 } |
10451 } | 11102 } |
10452 } | 11103 } |
10453 } | 11104 } |
10454 return foundError; | 11105 return foundError; |
10455 } | 11106 } |
10456 | 11107 |
10457 /** | 11108 /** |
10458 * This checks the passed method declaration against override-error codes. | 11109 * This checks the passed method declaration against override-error codes. |
| 11110 * |
10459 * @param node the [MethodDeclaration] to evaluate | 11111 * @param node the [MethodDeclaration] to evaluate |
10460 * @return `true` if and only if an error code is generated on the passed node | 11112 * @return `true` if and only if an error code is generated on the passed node |
10461 * @see StaticWarningCode#INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC | 11113 * @see StaticWarningCode#INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC |
10462 * @see CompileTimeErrorCode#INVALID_OVERRIDE_REQUIRED | 11114 * @see CompileTimeErrorCode#INVALID_OVERRIDE_REQUIRED |
10463 * @see CompileTimeErrorCode#INVALID_OVERRIDE_POSITIONAL | 11115 * @see CompileTimeErrorCode#INVALID_OVERRIDE_POSITIONAL |
10464 * @see CompileTimeErrorCode#INVALID_OVERRIDE_NAMED | 11116 * @see CompileTimeErrorCode#INVALID_OVERRIDE_NAMED |
10465 * @see StaticWarningCode#INVALID_GETTER_OVERRIDE_RETURN_TYPE | 11117 * @see StaticWarningCode#INVALID_GETTER_OVERRIDE_RETURN_TYPE |
10466 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_RETURN_TYPE | 11118 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_RETURN_TYPE |
10467 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE | 11119 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE |
10468 * @see StaticWarningCode#INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE | 11120 * @see StaticWarningCode#INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10656 foundError = true; | 11308 foundError = true; |
10657 } | 11309 } |
10658 } | 11310 } |
10659 } | 11311 } |
10660 } | 11312 } |
10661 return foundError; | 11313 return foundError; |
10662 } | 11314 } |
10663 | 11315 |
10664 /** | 11316 /** |
10665 * This verifies that all classes of the passed 'with' clause are valid. | 11317 * This verifies that all classes of the passed 'with' clause are valid. |
| 11318 * |
10666 * @param node the 'with' clause to evaluate | 11319 * @param node the 'with' clause to evaluate |
10667 * @return `true` if and only if an error code is generated on the passed node | 11320 * @return `true` if and only if an error code is generated on the passed node |
10668 * @see CompileTimeErrorCode#MIXIN_DECLARES_CONSTRUCTOR | 11321 * @see CompileTimeErrorCode#MIXIN_DECLARES_CONSTRUCTOR |
10669 * @see CompileTimeErrorCode#MIXIN_INHERITS_FROM_NOT_OBJECT | 11322 * @see CompileTimeErrorCode#MIXIN_INHERITS_FROM_NOT_OBJECT |
10670 * @see CompileTimeErrorCode#MIXIN_REFERENCES_SUPER | 11323 * @see CompileTimeErrorCode#MIXIN_REFERENCES_SUPER |
10671 */ | 11324 */ |
10672 bool checkForAllMixinErrorCodes(WithClause withClause) { | 11325 bool checkForAllMixinErrorCodes(WithClause withClause) { |
10673 if (withClause == null) { | 11326 if (withClause == null) { |
10674 return false; | 11327 return false; |
10675 } | 11328 } |
10676 bool problemReported = false; | 11329 bool problemReported = false; |
10677 for (TypeName mixinName in withClause.mixinTypes) { | 11330 for (TypeName mixinName in withClause.mixinTypes) { |
10678 Type2 mixinType = mixinName.type; | 11331 Type2 mixinType = mixinName.type; |
10679 if (mixinType is! InterfaceType) { | 11332 if (mixinType is! InterfaceType) { |
10680 continue; | 11333 continue; |
10681 } | 11334 } |
10682 ClassElement mixinElement = ((mixinType as InterfaceType)).element; | 11335 ClassElement mixinElement = ((mixinType as InterfaceType)).element; |
10683 problemReported = javaBooleanOr(problemReported, checkForMixinDeclaresCons
tructor(mixinName, mixinElement)); | 11336 problemReported = javaBooleanOr(problemReported, checkForMixinDeclaresCons
tructor(mixinName, mixinElement)); |
10684 problemReported = javaBooleanOr(problemReported, checkForMixinInheritsNotF
romObject(mixinName, mixinElement)); | 11337 problemReported = javaBooleanOr(problemReported, checkForMixinInheritsNotF
romObject(mixinName, mixinElement)); |
10685 problemReported = javaBooleanOr(problemReported, checkForMixinReferencesSu
per(mixinName, mixinElement)); | 11338 problemReported = javaBooleanOr(problemReported, checkForMixinReferencesSu
per(mixinName, mixinElement)); |
10686 } | 11339 } |
10687 return problemReported; | 11340 return problemReported; |
10688 } | 11341 } |
10689 | 11342 |
10690 /** | 11343 /** |
10691 * This checks error related to the redirected constructors. | 11344 * This checks error related to the redirected constructors. |
| 11345 * |
10692 * @param node the constructor declaration to evaluate | 11346 * @param node the constructor declaration to evaluate |
10693 * @return `true` if and only if an error code is generated on the passed node | 11347 * @return `true` if and only if an error code is generated on the passed node |
10694 * @see StaticWarningCode#REDIRECT_TO_INVALID_RETURN_TYPE | 11348 * @see StaticWarningCode#REDIRECT_TO_INVALID_RETURN_TYPE |
10695 * @see StaticWarningCode#REDIRECT_TO_INVALID_FUNCTION_TYPE | 11349 * @see StaticWarningCode#REDIRECT_TO_INVALID_FUNCTION_TYPE |
10696 * @see StaticWarningCode#REDIRECT_TO_MISSING_CONSTRUCTOR | 11350 * @see StaticWarningCode#REDIRECT_TO_MISSING_CONSTRUCTOR |
10697 */ | 11351 */ |
10698 bool checkForAllRedirectConstructorErrorCodes(ConstructorDeclaration node) { | 11352 bool checkForAllRedirectConstructorErrorCodes(ConstructorDeclaration node) { |
10699 ConstructorName redirectedNode = node.redirectedConstructor; | 11353 ConstructorName redirectedNode = node.redirectedConstructor; |
10700 if (redirectedNode == null) { | 11354 if (redirectedNode == null) { |
10701 return false; | 11355 return false; |
(...skipping 30 matching lines...) Expand all Loading... |
10732 /** | 11386 /** |
10733 * This checks that the return statement of the form <i>return e;</i> is not i
n a generative | 11387 * This checks that the return statement of the form <i>return e;</i> is not i
n a generative |
10734 * constructor. | 11388 * constructor. |
10735 * | 11389 * |
10736 * This checks that return statements without expressions are not in a generat
ive constructor and | 11390 * This checks that return statements without expressions are not in a generat
ive constructor and |
10737 * the return type is not assignable to `null`; that is, we don't have `return
;` if | 11391 * the return type is not assignable to `null`; that is, we don't have `return
;` if |
10738 * the enclosing method has a return type. | 11392 * the enclosing method has a return type. |
10739 * | 11393 * |
10740 * This checks that the return type matches the type of the declared return ty
pe in the enclosing | 11394 * This checks that the return type matches the type of the declared return ty
pe in the enclosing |
10741 * method or function. | 11395 * method or function. |
| 11396 * |
10742 * @param node the return statement to evaluate | 11397 * @param node the return statement to evaluate |
10743 * @return `true` if and only if an error code is generated on the passed node | 11398 * @return `true` if and only if an error code is generated on the passed node |
10744 * @see CompileTimeErrorCode#RETURN_IN_GENERATIVE_CONSTRUCTOR | 11399 * @see CompileTimeErrorCode#RETURN_IN_GENERATIVE_CONSTRUCTOR |
10745 * @see StaticWarningCode#RETURN_WITHOUT_VALUE | 11400 * @see StaticWarningCode#RETURN_WITHOUT_VALUE |
10746 * @see StaticTypeWarningCode#RETURN_OF_INVALID_TYPE | 11401 * @see StaticTypeWarningCode#RETURN_OF_INVALID_TYPE |
10747 */ | 11402 */ |
10748 bool checkForAllReturnStatementErrorCodes(ReturnStatement node) { | 11403 bool checkForAllReturnStatementErrorCodes(ReturnStatement node) { |
10749 FunctionType functionType = _enclosingFunction == null ? null : _enclosingFu
nction.type; | 11404 FunctionType functionType = _enclosingFunction == null ? null : _enclosingFu
nction.type; |
10750 Type2 expectedReturnType = functionType == null ? DynamicTypeImpl.instance :
functionType.returnType; | 11405 Type2 expectedReturnType = functionType == null ? DynamicTypeImpl.instance :
functionType.returnType; |
10751 Expression returnExpression = node.expression; | 11406 Expression returnExpression = node.expression; |
(...skipping 11 matching lines...) Expand all Loading... |
10763 } | 11418 } |
10764 _errorReporter.reportError2(StaticWarningCode.RETURN_WITHOUT_VALUE, node,
[]); | 11419 _errorReporter.reportError2(StaticWarningCode.RETURN_WITHOUT_VALUE, node,
[]); |
10765 return true; | 11420 return true; |
10766 } | 11421 } |
10767 return checkForReturnOfInvalidType(returnExpression, expectedReturnType); | 11422 return checkForReturnOfInvalidType(returnExpression, expectedReturnType); |
10768 } | 11423 } |
10769 | 11424 |
10770 /** | 11425 /** |
10771 * This verifies that the export namespace of the passed export directive does
not export any name | 11426 * This verifies that the export namespace of the passed export directive does
not export any name |
10772 * already exported by other export directive. | 11427 * already exported by other export directive. |
| 11428 * |
10773 * @param node the export directive node to report problem on | 11429 * @param node the export directive node to report problem on |
10774 * @return `true` if and only if an error code is generated on the passed node | 11430 * @return `true` if and only if an error code is generated on the passed node |
10775 * @see CompileTimeErrorCode#AMBIGUOUS_EXPORT | 11431 * @see CompileTimeErrorCode#AMBIGUOUS_EXPORT |
10776 */ | 11432 */ |
10777 bool checkForAmbiguousExport(ExportDirective node) { | 11433 bool checkForAmbiguousExport(ExportDirective node) { |
10778 if (node.element is! ExportElement) { | 11434 if (node.element is! ExportElement) { |
10779 return false; | 11435 return false; |
10780 } | 11436 } |
10781 ExportElement exportElement = node.element as ExportElement; | 11437 ExportElement exportElement = node.element as ExportElement; |
10782 LibraryElement exportedLibrary = exportElement.exportedLibrary; | 11438 LibraryElement exportedLibrary = exportElement.exportedLibrary; |
10783 if (exportedLibrary == null) { | 11439 if (exportedLibrary == null) { |
10784 return false; | 11440 return false; |
10785 } | 11441 } |
10786 Namespace namespace = new NamespaceBuilder().createExportNamespace(exportEle
ment); | 11442 Namespace namespace = new NamespaceBuilder().createExportNamespace(exportEle
ment); |
10787 Set<String> newNames = namespace.definedNames.keys.toSet(); | 11443 Set<String> newNames = namespace.definedNames.keys.toSet(); |
10788 for (String name in newNames) { | 11444 for (String name in newNames) { |
10789 ExportElement prevElement = _exportedNames[name]; | 11445 ExportElement prevElement = _exportedNames[name]; |
10790 if (prevElement != null && prevElement != exportElement) { | 11446 if (prevElement != null && prevElement != exportElement) { |
10791 _errorReporter.reportError2(CompileTimeErrorCode.AMBIGUOUS_EXPORT, node,
[name, prevElement.exportedLibrary.definingCompilationUnit.displayName, exporte
dLibrary.definingCompilationUnit.displayName]); | 11447 _errorReporter.reportError2(CompileTimeErrorCode.AMBIGUOUS_EXPORT, node,
[name, prevElement.exportedLibrary.definingCompilationUnit.displayName, exporte
dLibrary.definingCompilationUnit.displayName]); |
10792 return true; | 11448 return true; |
10793 } else { | 11449 } else { |
10794 _exportedNames[name] = exportElement; | 11450 _exportedNames[name] = exportElement; |
10795 } | 11451 } |
10796 } | 11452 } |
10797 return false; | 11453 return false; |
10798 } | 11454 } |
10799 | 11455 |
10800 /** | 11456 /** |
10801 * This verifies that the passed argument definition test identifier is a para
meter. | 11457 * This verifies that the passed argument definition test identifier is a para
meter. |
| 11458 * |
10802 * @param node the [ArgumentDefinitionTest] to evaluate | 11459 * @param node the [ArgumentDefinitionTest] to evaluate |
10803 * @return `true` if and only if an error code is generated on the passed node | 11460 * @return `true` if and only if an error code is generated on the passed node |
10804 * @see CompileTimeErrorCode#ARGUMENT_DEFINITION_TEST_NON_PARAMETER | 11461 * @see CompileTimeErrorCode#ARGUMENT_DEFINITION_TEST_NON_PARAMETER |
10805 */ | 11462 */ |
10806 bool checkForArgumentDefinitionTestNonParameter(ArgumentDefinitionTest node) { | 11463 bool checkForArgumentDefinitionTestNonParameter(ArgumentDefinitionTest node) { |
10807 SimpleIdentifier identifier = node.identifier; | 11464 SimpleIdentifier identifier = node.identifier; |
10808 Element element = identifier.element; | 11465 Element element = identifier.element; |
10809 if (element != null && element is! ParameterElement) { | 11466 if (element != null && element is! ParameterElement) { |
10810 _errorReporter.reportError2(CompileTimeErrorCode.ARGUMENT_DEFINITION_TEST_
NON_PARAMETER, identifier, [identifier.name]); | 11467 _errorReporter.reportError2(CompileTimeErrorCode.ARGUMENT_DEFINITION_TEST_
NON_PARAMETER, identifier, [identifier.name]); |
10811 return true; | 11468 return true; |
10812 } | 11469 } |
10813 return false; | 11470 return false; |
10814 } | 11471 } |
10815 | 11472 |
10816 /** | 11473 /** |
10817 * This verifies that the passed arguments can be assigned to their correspond
ing parameters. | 11474 * This verifies that the passed arguments can be assigned to their correspond
ing parameters. |
| 11475 * |
10818 * @param node the arguments to evaluate | 11476 * @param node the arguments to evaluate |
10819 * @return `true` if and only if an error code is generated on the passed node | 11477 * @return `true` if and only if an error code is generated on the passed node |
10820 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE | 11478 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE |
10821 */ | 11479 */ |
10822 bool checkForArgumentTypeNotAssignable(ArgumentList argumentList) { | 11480 bool checkForArgumentTypeNotAssignable(ArgumentList argumentList) { |
10823 if (argumentList == null) { | 11481 if (argumentList == null) { |
10824 return false; | 11482 return false; |
10825 } | 11483 } |
10826 bool problemReported = false; | 11484 bool problemReported = false; |
10827 for (Expression argument in argumentList.arguments) { | 11485 for (Expression argument in argumentList.arguments) { |
10828 problemReported = javaBooleanOr(problemReported, checkForArgumentTypeNotAs
signable2(argument)); | 11486 problemReported = javaBooleanOr(problemReported, checkForArgumentTypeNotAs
signable2(argument)); |
10829 } | 11487 } |
10830 return problemReported; | 11488 return problemReported; |
10831 } | 11489 } |
10832 | 11490 |
10833 /** | 11491 /** |
10834 * This verifies that the passed argument can be assigned to their correspondi
ng parameters. | 11492 * This verifies that the passed argument can be assigned to their correspondi
ng parameters. |
| 11493 * |
10835 * @param node the argument to evaluate | 11494 * @param node the argument to evaluate |
10836 * @return `true` if and only if an error code is generated on the passed node | 11495 * @return `true` if and only if an error code is generated on the passed node |
10837 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE | 11496 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE |
10838 */ | 11497 */ |
10839 bool checkForArgumentTypeNotAssignable2(Expression argument) { | 11498 bool checkForArgumentTypeNotAssignable2(Expression argument) { |
10840 if (argument == null) { | 11499 if (argument == null) { |
10841 return false; | 11500 return false; |
10842 } | 11501 } |
10843 ParameterElement staticParameterElement = argument.staticParameterElement; | 11502 ParameterElement staticParameterElement = argument.staticParameterElement; |
10844 Type2 staticParameterType = staticParameterElement == null ? null : staticPa
rameterElement.type; | 11503 Type2 staticParameterType = staticParameterElement == null ? null : staticPa
rameterElement.type; |
(...skipping 20 matching lines...) Expand all Loading... |
10865 } | 11524 } |
10866 if (staticArgumentType.isAssignableTo(staticParameterType) || staticArgument
Type.isAssignableTo(propagatedParameterType) || propagatedArgumentType.isAssigna
bleTo(staticParameterType) || propagatedArgumentType.isAssignableTo(propagatedPa
rameterType)) { | 11525 if (staticArgumentType.isAssignableTo(staticParameterType) || staticArgument
Type.isAssignableTo(propagatedParameterType) || propagatedArgumentType.isAssigna
bleTo(staticParameterType) || propagatedArgumentType.isAssignableTo(propagatedPa
rameterType)) { |
10867 return false; | 11526 return false; |
10868 } | 11527 } |
10869 _errorReporter.reportError2(StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE,
argument, [(propagatedArgumentType == null ? staticArgumentType : propagatedArgu
mentType).displayName, (propagatedParameterType == null ? staticParameterType :
propagatedParameterType).displayName]); | 11528 _errorReporter.reportError2(StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE,
argument, [(propagatedArgumentType == null ? staticArgumentType : propagatedArgu
mentType).displayName, (propagatedParameterType == null ? staticParameterType :
propagatedParameterType).displayName]); |
10870 return true; | 11529 return true; |
10871 } | 11530 } |
10872 | 11531 |
10873 /** | 11532 /** |
10874 * This verifies that left hand side of the passed assignment expression is no
t final. | 11533 * This verifies that left hand side of the passed assignment expression is no
t final. |
| 11534 * |
10875 * @param node the assignment expression to evaluate | 11535 * @param node the assignment expression to evaluate |
10876 * @return `true` if and only if an error code is generated on the passed node | 11536 * @return `true` if and only if an error code is generated on the passed node |
10877 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL | 11537 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL |
10878 */ | 11538 */ |
10879 bool checkForAssignmentToFinal(AssignmentExpression node) { | 11539 bool checkForAssignmentToFinal(AssignmentExpression node) { |
10880 Expression leftExpression = node.leftHandSide; | 11540 Expression leftExpression = node.leftHandSide; |
10881 return checkForAssignmentToFinal2(leftExpression); | 11541 return checkForAssignmentToFinal2(leftExpression); |
10882 } | 11542 } |
10883 | 11543 |
10884 /** | 11544 /** |
10885 * This verifies that the passed expression is not final. | 11545 * This verifies that the passed expression is not final. |
| 11546 * |
10886 * @param node the expression to evaluate | 11547 * @param node the expression to evaluate |
10887 * @return `true` if and only if an error code is generated on the passed node | 11548 * @return `true` if and only if an error code is generated on the passed node |
10888 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL | 11549 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL |
10889 */ | 11550 */ |
10890 bool checkForAssignmentToFinal2(Expression expression) { | 11551 bool checkForAssignmentToFinal2(Expression expression) { |
10891 Element element = null; | 11552 Element element = null; |
10892 if (expression is Identifier) { | 11553 if (expression is Identifier) { |
10893 element = ((expression as Identifier)).element; | 11554 element = ((expression as Identifier)).element; |
10894 } | 11555 } |
10895 if (expression is PropertyAccess) { | 11556 if (expression is PropertyAccess) { |
(...skipping 14 matching lines...) Expand all Loading... |
10910 return true; | 11571 return true; |
10911 } | 11572 } |
10912 return false; | 11573 return false; |
10913 } | 11574 } |
10914 return false; | 11575 return false; |
10915 } | 11576 } |
10916 | 11577 |
10917 /** | 11578 /** |
10918 * This verifies that the passed identifier is not a keyword, and generates th
e passed error code | 11579 * This verifies that the passed identifier is not a keyword, and generates th
e passed error code |
10919 * on the identifier if it is a keyword. | 11580 * on the identifier if it is a keyword. |
| 11581 * |
10920 * @param identifier the identifier to check to ensure that it is not a keywor
d | 11582 * @param identifier the identifier to check to ensure that it is not a keywor
d |
10921 * @param errorCode if the passed identifier is a keyword then this error code
is created on the | 11583 * @param errorCode if the passed identifier is a keyword then this error code
is created on the |
10922 * identifier, the error code will be one of[CompileTimeErrorCode#BUILT_IN_IDE
NTIFIER_AS_TYPE_NAME],[CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_VARIABLE
_NAME] or[CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME] | 11584 * identifier, the error code will be one of |
| 11585 * [CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_NAME], |
| 11586 * [CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_VARIABLE_NAME] o
r |
| 11587 * [CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME] |
10923 * @return `true` if and only if an error code is generated on the passed node | 11588 * @return `true` if and only if an error code is generated on the passed node |
10924 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_NAME | 11589 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_NAME |
10925 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_VARIABLE_NAME | 11590 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_VARIABLE_NAME |
10926 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME | 11591 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME |
10927 */ | 11592 */ |
10928 bool checkForBuiltInIdentifierAsName(SimpleIdentifier identifier, ErrorCode er
rorCode) { | 11593 bool checkForBuiltInIdentifierAsName(SimpleIdentifier identifier, ErrorCode er
rorCode) { |
10929 sc.Token token = identifier.token; | 11594 sc.Token token = identifier.token; |
10930 if (identical(token.type, sc.TokenType.KEYWORD)) { | 11595 if (identical(token.type, sc.TokenType.KEYWORD)) { |
10931 _errorReporter.reportError2(errorCode, identifier, [identifier.name]); | 11596 _errorReporter.reportError2(errorCode, identifier, [identifier.name]); |
10932 return true; | 11597 return true; |
10933 } | 11598 } |
10934 return false; | 11599 return false; |
10935 } | 11600 } |
10936 | 11601 |
10937 /** | 11602 /** |
10938 * This verifies that the passed variable declaration list does not have a bui
lt-in identifier. | 11603 * This verifies that the passed variable declaration list does not have a bui
lt-in identifier. |
| 11604 * |
10939 * @param node the variable declaration list to check | 11605 * @param node the variable declaration list to check |
10940 * @return `true` if and only if an error code is generated on the passed node | 11606 * @return `true` if and only if an error code is generated on the passed node |
10941 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE | 11607 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE |
10942 */ | 11608 */ |
10943 bool checkForBuiltInIdentifierAsName2(VariableDeclarationList node) { | 11609 bool checkForBuiltInIdentifierAsName2(VariableDeclarationList node) { |
10944 TypeName typeName = node.type; | 11610 TypeName typeName = node.type; |
10945 if (typeName != null) { | 11611 if (typeName != null) { |
10946 Identifier identifier = typeName.name; | 11612 Identifier identifier = typeName.name; |
10947 if (identifier is SimpleIdentifier) { | 11613 if (identifier is SimpleIdentifier) { |
10948 SimpleIdentifier simpleIdentifier = identifier as SimpleIdentifier; | 11614 SimpleIdentifier simpleIdentifier = identifier as SimpleIdentifier; |
10949 sc.Token token = simpleIdentifier.token; | 11615 sc.Token token = simpleIdentifier.token; |
10950 if (identical(token.type, sc.TokenType.KEYWORD)) { | 11616 if (identical(token.type, sc.TokenType.KEYWORD)) { |
10951 if (((token as sc.KeywordToken)).keyword != sc.Keyword.DYNAMIC) { | 11617 if (((token as sc.KeywordToken)).keyword != sc.Keyword.DYNAMIC) { |
10952 _errorReporter.reportError2(CompileTimeErrorCode.BUILT_IN_IDENTIFIER
_AS_TYPE, identifier, [identifier.name]); | 11618 _errorReporter.reportError2(CompileTimeErrorCode.BUILT_IN_IDENTIFIER
_AS_TYPE, identifier, [identifier.name]); |
10953 return true; | 11619 return true; |
10954 } | 11620 } |
10955 } | 11621 } |
10956 } | 11622 } |
10957 } | 11623 } |
10958 return false; | 11624 return false; |
10959 } | 11625 } |
10960 | 11626 |
10961 /** | 11627 /** |
10962 * This verifies that the given switch case is terminated with 'break', 'conti
nue', 'return' or | 11628 * This verifies that the given switch case is terminated with 'break', 'conti
nue', 'return' or |
10963 * 'throw'. | 11629 * 'throw'. |
| 11630 * |
10964 * @param node the switch case to evaluate | 11631 * @param node the switch case to evaluate |
10965 * @return `true` if and only if an error code is generated on the passed node | 11632 * @return `true` if and only if an error code is generated on the passed node |
10966 * @see StaticWarningCode#CASE_BLOCK_NOT_TERMINATED | 11633 * @see StaticWarningCode#CASE_BLOCK_NOT_TERMINATED |
10967 */ | 11634 */ |
10968 bool checkForCaseBlockNotTerminated(SwitchCase node) { | 11635 bool checkForCaseBlockNotTerminated(SwitchCase node) { |
10969 NodeList<Statement> statements = node.statements; | 11636 NodeList<Statement> statements = node.statements; |
10970 if (statements.isEmpty) { | 11637 if (statements.isEmpty) { |
10971 ASTNode parent = node.parent; | 11638 ASTNode parent = node.parent; |
10972 if (parent is SwitchStatement) { | 11639 if (parent is SwitchStatement) { |
10973 SwitchStatement switchStatement = parent as SwitchStatement; | 11640 SwitchStatement switchStatement = parent as SwitchStatement; |
(...skipping 15 matching lines...) Expand all Loading... |
10989 } | 11656 } |
10990 } | 11657 } |
10991 } | 11658 } |
10992 _errorReporter.reportError4(StaticWarningCode.CASE_BLOCK_NOT_TERMINATED, nod
e.keyword, []); | 11659 _errorReporter.reportError4(StaticWarningCode.CASE_BLOCK_NOT_TERMINATED, nod
e.keyword, []); |
10993 return true; | 11660 return true; |
10994 } | 11661 } |
10995 | 11662 |
10996 /** | 11663 /** |
10997 * This verifies that the switch cases in the given switch statement is termin
ated with 'break', | 11664 * This verifies that the switch cases in the given switch statement is termin
ated with 'break', |
10998 * 'continue', 'return' or 'throw'. | 11665 * 'continue', 'return' or 'throw'. |
| 11666 * |
10999 * @param node the switch statement containing the cases to be checked | 11667 * @param node the switch statement containing the cases to be checked |
11000 * @return `true` if and only if an error code is generated on the passed node | 11668 * @return `true` if and only if an error code is generated on the passed node |
11001 * @see StaticWarningCode#CASE_BLOCK_NOT_TERMINATED | 11669 * @see StaticWarningCode#CASE_BLOCK_NOT_TERMINATED |
11002 */ | 11670 */ |
11003 bool checkForCaseBlocksNotTerminated(SwitchStatement node) { | 11671 bool checkForCaseBlocksNotTerminated(SwitchStatement node) { |
11004 bool foundError = false; | 11672 bool foundError = false; |
11005 NodeList<SwitchMember> members = node.members; | 11673 NodeList<SwitchMember> members = node.members; |
11006 int lastMember = members.length - 1; | 11674 int lastMember = members.length - 1; |
11007 for (int i = 0; i < lastMember; i++) { | 11675 for (int i = 0; i < lastMember; i++) { |
11008 SwitchMember member = members[i]; | 11676 SwitchMember member = members[i]; |
11009 if (member is SwitchCase) { | 11677 if (member is SwitchCase) { |
11010 foundError = javaBooleanOr(foundError, checkForCaseBlockNotTerminated((m
ember as SwitchCase))); | 11678 foundError = javaBooleanOr(foundError, checkForCaseBlockNotTerminated((m
ember as SwitchCase))); |
11011 } | 11679 } |
11012 } | 11680 } |
11013 return foundError; | 11681 return foundError; |
11014 } | 11682 } |
11015 | 11683 |
11016 /** | 11684 /** |
11017 * This verifies that the passed switch statement does not have a case express
ion with the | 11685 * This verifies that the passed switch statement does not have a case express
ion with the |
11018 * operator '==' overridden. | 11686 * operator '==' overridden. |
| 11687 * |
11019 * @param node the switch statement to evaluate | 11688 * @param node the switch statement to evaluate |
| 11689 * @param type the common type of all 'case' expressions |
11020 * @return `true` if and only if an error code is generated on the passed node | 11690 * @return `true` if and only if an error code is generated on the passed node |
11021 * @see CompileTimeErrorCode#CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS | 11691 * @see CompileTimeErrorCode#CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS |
11022 */ | 11692 */ |
11023 bool checkForCaseExpressionTypeImplementsEquals(SwitchStatement node) { | 11693 bool checkForCaseExpressionTypeImplementsEquals(SwitchStatement node, Type2 ty
pe2) { |
11024 Expression expression = node.expression; | 11694 if (type2 == null || type2 == _typeProvider.intType || type2 == _typeProvide
r.stringType) { |
11025 Type2 type = getStaticType(expression); | 11695 return false; |
11026 if (type != null && type != _typeProvider.intType && type != _typeProvider.s
tringType) { | |
11027 Element element = type.element; | |
11028 if (element is ClassElement) { | |
11029 ClassElement classElement = element as ClassElement; | |
11030 MethodElement method = classElement.lookUpMethod("==", _currentLibrary); | |
11031 if (method != null && method.enclosingElement.type != _typeProvider.obje
ctType) { | |
11032 _errorReporter.reportError2(CompileTimeErrorCode.CASE_EXPRESSION_TYPE_
IMPLEMENTS_EQUALS, expression, [element.displayName]); | |
11033 return true; | |
11034 } | |
11035 } | |
11036 } | 11696 } |
11037 return false; | 11697 Element element = type2.element; |
| 11698 if (element is! ClassElement) { |
| 11699 return false; |
| 11700 } |
| 11701 ClassElement classElement = element as ClassElement; |
| 11702 MethodElement method = classElement.lookUpMethod("==", _currentLibrary); |
| 11703 if (method == null || method.enclosingElement.type.isObject) { |
| 11704 return false; |
| 11705 } |
| 11706 _errorReporter.reportError4(CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEM
ENTS_EQUALS, node.keyword, [element.displayName]); |
| 11707 return true; |
11038 } | 11708 } |
11039 | 11709 |
11040 /** | 11710 /** |
11041 * This verifies that the passed method declaration is abstract only if the en
closing class is | 11711 * This verifies that the passed method declaration is abstract only if the en
closing class is |
11042 * also abstract. | 11712 * also abstract. |
| 11713 * |
11043 * @param node the method declaration to evaluate | 11714 * @param node the method declaration to evaluate |
11044 * @return `true` if and only if an error code is generated on the passed node | 11715 * @return `true` if and only if an error code is generated on the passed node |
11045 * @see StaticWarningCode#CONCRETE_CLASS_WITH_ABSTRACT_MEMBER | 11716 * @see StaticWarningCode#CONCRETE_CLASS_WITH_ABSTRACT_MEMBER |
11046 */ | 11717 */ |
11047 bool checkForConcreteClassWithAbstractMember(MethodDeclaration node) { | 11718 bool checkForConcreteClassWithAbstractMember(MethodDeclaration node) { |
11048 if (node.isAbstract && _enclosingClass != null && !_enclosingClass.isAbstrac
t) { | 11719 if (node.isAbstract && _enclosingClass != null && !_enclosingClass.isAbstrac
t) { |
11049 SimpleIdentifier methodName = node.name; | 11720 SimpleIdentifier methodName = node.name; |
11050 _errorReporter.reportError2(StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT
_MEMBER, methodName, [methodName.name, _enclosingClass.displayName]); | 11721 _errorReporter.reportError2(StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT
_MEMBER, methodName, [methodName.name, _enclosingClass.displayName]); |
11051 return true; | 11722 return true; |
11052 } | 11723 } |
11053 return false; | 11724 return false; |
11054 } | 11725 } |
11055 | 11726 |
11056 /** | 11727 /** |
11057 * This verifies all possible conflicts of the constructor name with other con
structors and | 11728 * This verifies all possible conflicts of the constructor name with other con
structors and |
11058 * members of the same class. | 11729 * members of the same class. |
| 11730 * |
11059 * @param node the constructor declaration to evaluate | 11731 * @param node the constructor declaration to evaluate |
11060 * @return `true` if and only if an error code is generated on the passed node | 11732 * @return `true` if and only if an error code is generated on the passed node |
11061 * @see CompileTimeErrorCode#DUPLICATE_CONSTRUCTOR_DEFAULT | 11733 * @see CompileTimeErrorCode#DUPLICATE_CONSTRUCTOR_DEFAULT |
11062 * @see CompileTimeErrorCode#DUPLICATE_CONSTRUCTOR_NAME | 11734 * @see CompileTimeErrorCode#DUPLICATE_CONSTRUCTOR_NAME |
11063 * @see CompileTimeErrorCode#CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD | 11735 * @see CompileTimeErrorCode#CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD |
11064 * @see CompileTimeErrorCode#CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD | 11736 * @see CompileTimeErrorCode#CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD |
11065 */ | 11737 */ |
11066 bool checkForConflictingConstructorNameAndMember(ConstructorDeclaration node)
{ | 11738 bool checkForConflictingConstructorNameAndMember(ConstructorDeclaration node)
{ |
11067 ConstructorElement constructorElement = node.element; | 11739 ConstructorElement constructorElement = node.element; |
11068 SimpleIdentifier constructorName = node.name; | 11740 SimpleIdentifier constructorName = node.name; |
(...skipping 26 matching lines...) Expand all Loading... |
11095 if (method.name == name) { | 11767 if (method.name == name) { |
11096 _errorReporter.reportError2(CompileTimeErrorCode.CONFLICTING_CONSTRUCT
OR_NAME_AND_METHOD, node, [name]); | 11768 _errorReporter.reportError2(CompileTimeErrorCode.CONFLICTING_CONSTRUCT
OR_NAME_AND_METHOD, node, [name]); |
11097 return true; | 11769 return true; |
11098 } | 11770 } |
11099 } | 11771 } |
11100 } | 11772 } |
11101 return false; | 11773 return false; |
11102 } | 11774 } |
11103 | 11775 |
11104 /** | 11776 /** |
| 11777 * This verifies that the [enclosingClass] does not have method and getter wit
h the same |
| 11778 * names. |
| 11779 * |
| 11780 * @return `true` if and only if an error code is generated on the passed node |
| 11781 * @see CompileTimeErrorCode#CONFLICTING_GETTER_AND_METHOD |
| 11782 * @see CompileTimeErrorCode#CONFLICTING_METHOD_AND_GETTER |
| 11783 */ |
| 11784 bool checkForConflictingGetterAndMethod() { |
| 11785 if (_enclosingClass == null) { |
| 11786 return false; |
| 11787 } |
| 11788 bool hasProblem = false; |
| 11789 for (MethodElement method in _enclosingClass.methods) { |
| 11790 String name = method.name; |
| 11791 ExecutableElement inherited = _inheritanceManager.lookupInheritance(_enclo
singClass, name); |
| 11792 if (inherited is! PropertyAccessorElement) { |
| 11793 continue; |
| 11794 } |
| 11795 hasProblem = true; |
| 11796 _errorReporter.reportError3(CompileTimeErrorCode.CONFLICTING_GETTER_AND_ME
THOD, method.nameOffset, name.length, [_enclosingClass.displayName, inherited.en
closingElement.displayName, name]); |
| 11797 } |
| 11798 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { |
| 11799 if (!accessor.isGetter) { |
| 11800 continue; |
| 11801 } |
| 11802 String name = accessor.name; |
| 11803 ExecutableElement inherited = _inheritanceManager.lookupInheritance(_enclo
singClass, name); |
| 11804 if (inherited is! MethodElement) { |
| 11805 continue; |
| 11806 } |
| 11807 hasProblem = true; |
| 11808 _errorReporter.reportError3(CompileTimeErrorCode.CONFLICTING_METHOD_AND_GE
TTER, accessor.nameOffset, name.length, [_enclosingClass.displayName, inherited.
enclosingElement.displayName, name]); |
| 11809 } |
| 11810 return hasProblem; |
| 11811 } |
| 11812 |
| 11813 /** |
11105 * This verifies that the superclass of the enclosing class does not declare a
ccessible static | 11814 * This verifies that the superclass of the enclosing class does not declare a
ccessible static |
11106 * member with the same name as the passed instance getter/setter method decla
ration. | 11815 * member with the same name as the passed instance getter/setter method decla
ration. |
| 11816 * |
11107 * @param node the method declaration to evaluate | 11817 * @param node the method declaration to evaluate |
11108 * @return `true` if and only if an error code is generated on the passed node | 11818 * @return `true` if and only if an error code is generated on the passed node |
11109 * @see StaticWarningCode#CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER | 11819 * @see StaticWarningCode#CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER |
11110 * @see StaticWarningCode#CONFLICTING_INSTANCE_SETTER_AND_SUPERCLASS_MEMBER | 11820 * @see StaticWarningCode#CONFLICTING_INSTANCE_SETTER_AND_SUPERCLASS_MEMBER |
11111 */ | 11821 */ |
11112 bool checkForConflictingInstanceGetterAndSuperclassMember(MethodDeclaration no
de) { | 11822 bool checkForConflictingInstanceGetterAndSuperclassMember(MethodDeclaration no
de) { |
11113 if (node.isStatic) { | 11823 if (node.isStatic) { |
11114 return false; | 11824 return false; |
11115 } | 11825 } |
11116 SimpleIdentifier nameNode = node.name; | 11826 SimpleIdentifier nameNode = node.name; |
(...skipping 25 matching lines...) Expand all Loading... |
11142 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_INSTANCE_GETTER_
AND_SUPERCLASS_MEMBER, nameNode, [superElementType.displayName]); | 11852 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_INSTANCE_GETTER_
AND_SUPERCLASS_MEMBER, nameNode, [superElementType.displayName]); |
11143 } else { | 11853 } else { |
11144 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_INSTANCE_SETTER_
AND_SUPERCLASS_MEMBER, nameNode, [superElementType.displayName]); | 11854 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_INSTANCE_SETTER_
AND_SUPERCLASS_MEMBER, nameNode, [superElementType.displayName]); |
11145 } | 11855 } |
11146 return true; | 11856 return true; |
11147 } | 11857 } |
11148 | 11858 |
11149 /** | 11859 /** |
11150 * This verifies that the enclosing class does not have an instance member wit
h the same name as | 11860 * This verifies that the enclosing class does not have an instance member wit
h the same name as |
11151 * the passed static getter method declaration. | 11861 * the passed static getter method declaration. |
| 11862 * |
11152 * @param node the method declaration to evaluate | 11863 * @param node the method declaration to evaluate |
11153 * @return `true` if and only if an error code is generated on the passed node | 11864 * @return `true` if and only if an error code is generated on the passed node |
11154 * @see StaticWarningCode#CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER | 11865 * @see StaticWarningCode#CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER |
11155 */ | 11866 */ |
11156 bool checkForConflictingStaticGetterAndInstanceSetter(MethodDeclaration node)
{ | 11867 bool checkForConflictingStaticGetterAndInstanceSetter(MethodDeclaration node)
{ |
11157 if (!node.isStatic) { | 11868 if (!node.isStatic) { |
11158 return false; | 11869 return false; |
11159 } | 11870 } |
11160 SimpleIdentifier nameNode = node.name; | 11871 SimpleIdentifier nameNode = node.name; |
11161 if (nameNode == null) { | 11872 if (nameNode == null) { |
(...skipping 13 matching lines...) Expand all Loading... |
11175 } | 11886 } |
11176 ClassElement setterClass = setter.enclosingElement as ClassElement; | 11887 ClassElement setterClass = setter.enclosingElement as ClassElement; |
11177 InterfaceType setterType = setterClass.type; | 11888 InterfaceType setterType = setterClass.type; |
11178 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_
INSTANCE_SETTER, nameNode, [setterType.displayName]); | 11889 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_
INSTANCE_SETTER, nameNode, [setterType.displayName]); |
11179 return true; | 11890 return true; |
11180 } | 11891 } |
11181 | 11892 |
11182 /** | 11893 /** |
11183 * This verifies that the enclosing class does not have an instance member wit
h the same name as | 11894 * This verifies that the enclosing class does not have an instance member wit
h the same name as |
11184 * the passed static getter method declaration. | 11895 * the passed static getter method declaration. |
| 11896 * |
11185 * @param node the method declaration to evaluate | 11897 * @param node the method declaration to evaluate |
11186 * @return `true` if and only if an error code is generated on the passed node | 11898 * @return `true` if and only if an error code is generated on the passed node |
11187 * @see StaticWarningCode#CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER | 11899 * @see StaticWarningCode#CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER |
11188 */ | 11900 */ |
11189 bool checkForConflictingStaticSetterAndInstanceMember(MethodDeclaration node)
{ | 11901 bool checkForConflictingStaticSetterAndInstanceMember(MethodDeclaration node)
{ |
11190 if (!node.isStatic) { | 11902 if (!node.isStatic) { |
11191 return false; | 11903 return false; |
11192 } | 11904 } |
11193 SimpleIdentifier nameNode = node.name; | 11905 SimpleIdentifier nameNode = node.name; |
11194 if (nameNode == null) { | 11906 if (nameNode == null) { |
(...skipping 20 matching lines...) Expand all Loading... |
11215 } | 11927 } |
11216 ClassElement memberClass = member.enclosingElement as ClassElement; | 11928 ClassElement memberClass = member.enclosingElement as ClassElement; |
11217 InterfaceType memberType = memberClass.type; | 11929 InterfaceType memberType = memberClass.type; |
11218 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_
INSTANCE_MEMBER, nameNode, [memberType.displayName]); | 11930 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_
INSTANCE_MEMBER, nameNode, [memberType.displayName]); |
11219 return true; | 11931 return true; |
11220 } | 11932 } |
11221 | 11933 |
11222 /** | 11934 /** |
11223 * This verifies that the passed constructor declaration is 'const' then there
are no non-final | 11935 * This verifies that the passed constructor declaration is 'const' then there
are no non-final |
11224 * instance variable. | 11936 * instance variable. |
| 11937 * |
11225 * @param node the constructor declaration to evaluate | 11938 * @param node the constructor declaration to evaluate |
11226 * @return `true` if and only if an error code is generated on the passed node | 11939 * @return `true` if and only if an error code is generated on the passed node |
11227 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD | 11940 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD |
11228 */ | 11941 */ |
11229 bool checkForConstConstructorWithNonFinalField(ConstructorDeclaration node) { | 11942 bool checkForConstConstructorWithNonFinalField(ConstructorDeclaration node) { |
11230 if (!_isEnclosingConstructorConst) { | 11943 if (!_isEnclosingConstructorConst) { |
11231 return false; | 11944 return false; |
11232 } | 11945 } |
11233 ConstructorElement constructorElement = node.element; | 11946 ConstructorElement constructorElement = node.element; |
11234 ClassElement classElement = constructorElement.enclosingElement; | 11947 ClassElement classElement = constructorElement.enclosingElement; |
11235 if (!classElement.hasNonFinalField()) { | 11948 if (!classElement.hasNonFinalField()) { |
11236 return false; | 11949 return false; |
11237 } | 11950 } |
11238 _errorReporter.reportError2(CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_
FINAL_FIELD, node, []); | 11951 _errorReporter.reportError2(CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_
FINAL_FIELD, node, []); |
11239 return true; | 11952 return true; |
11240 } | 11953 } |
11241 | 11954 |
11242 /** | 11955 /** |
11243 * This verifies that the passed throw expression is not enclosed in a 'const'
constructor | 11956 * This verifies that the passed throw expression is not enclosed in a 'const'
constructor |
11244 * declaration. | 11957 * declaration. |
| 11958 * |
11245 * @param node the throw expression expression to evaluate | 11959 * @param node the throw expression expression to evaluate |
11246 * @return `true` if and only if an error code is generated on the passed node | 11960 * @return `true` if and only if an error code is generated on the passed node |
11247 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_THROWS_EXCEPTION | 11961 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_THROWS_EXCEPTION |
11248 */ | 11962 */ |
11249 bool checkForConstEvalThrowsException(ThrowExpression node) { | 11963 bool checkForConstEvalThrowsException(ThrowExpression node) { |
11250 if (_isEnclosingConstructorConst) { | 11964 if (_isEnclosingConstructorConst) { |
11251 _errorReporter.reportError2(CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_
EXCEPTION, node, []); | 11965 _errorReporter.reportError2(CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_
EXCEPTION, node, []); |
11252 return true; | 11966 return true; |
11253 } | 11967 } |
11254 return false; | 11968 return false; |
11255 } | 11969 } |
11256 | 11970 |
11257 /** | 11971 /** |
11258 * This verifies that the passed normal formal parameter is not 'const'. | 11972 * This verifies that the passed normal formal parameter is not 'const'. |
| 11973 * |
11259 * @param node the normal formal parameter to evaluate | 11974 * @param node the normal formal parameter to evaluate |
11260 * @return `true` if and only if an error code is generated on the passed node | 11975 * @return `true` if and only if an error code is generated on the passed node |
11261 * @see CompileTimeErrorCode#CONST_FORMAL_PARAMETER | 11976 * @see CompileTimeErrorCode#CONST_FORMAL_PARAMETER |
11262 */ | 11977 */ |
11263 bool checkForConstFormalParameter(NormalFormalParameter node) { | 11978 bool checkForConstFormalParameter(NormalFormalParameter node) { |
11264 if (node.isConst) { | 11979 if (node.isConst) { |
11265 _errorReporter.reportError2(CompileTimeErrorCode.CONST_FORMAL_PARAMETER, n
ode, []); | 11980 _errorReporter.reportError2(CompileTimeErrorCode.CONST_FORMAL_PARAMETER, n
ode, []); |
11266 return true; | 11981 return true; |
11267 } | 11982 } |
11268 return false; | 11983 return false; |
11269 } | 11984 } |
11270 | 11985 |
11271 /** | 11986 /** |
11272 * This verifies that the passed instance creation expression is not being inv
oked on an abstract | 11987 * This verifies that the passed instance creation expression is not being inv
oked on an abstract |
11273 * class. | 11988 * class. |
| 11989 * |
11274 * @param node the instance creation expression to evaluate | 11990 * @param node the instance creation expression to evaluate |
11275 * @param typeName the [TypeName] of the [ConstructorName] from the[InstanceCr
eationExpression], this is the AST node that the error is attached to | 11991 * @param typeName the [TypeName] of the [ConstructorName] from the |
| 11992 * [InstanceCreationExpression], this is the AST node that the error
is attached to |
11276 * @param type the type being constructed with this [InstanceCreationExpressio
n] | 11993 * @param type the type being constructed with this [InstanceCreationExpressio
n] |
11277 * @return `true` if and only if an error code is generated on the passed node | 11994 * @return `true` if and only if an error code is generated on the passed node |
11278 * @see StaticWarningCode#CONST_WITH_ABSTRACT_CLASS | 11995 * @see StaticWarningCode#CONST_WITH_ABSTRACT_CLASS |
11279 * @see StaticWarningCode#NEW_WITH_ABSTRACT_CLASS | 11996 * @see StaticWarningCode#NEW_WITH_ABSTRACT_CLASS |
11280 */ | 11997 */ |
11281 bool checkForConstOrNewWithAbstractClass(InstanceCreationExpression node, Type
Name typeName, InterfaceType type) { | 11998 bool checkForConstOrNewWithAbstractClass(InstanceCreationExpression node, Type
Name typeName, InterfaceType type) { |
11282 if (type.element.isAbstract) { | 11999 if (type.element.isAbstract) { |
11283 ConstructorElement element = node.element; | 12000 ConstructorElement element = node.element; |
11284 if (element != null && !element.isFactory) { | 12001 if (element != null && !element.isFactory) { |
11285 if (identical(((node.keyword as sc.KeywordToken)).keyword, sc.Keyword.CO
NST)) { | 12002 if (identical(((node.keyword as sc.KeywordToken)).keyword, sc.Keyword.CO
NST)) { |
11286 _errorReporter.reportError2(StaticWarningCode.CONST_WITH_ABSTRACT_CLAS
S, typeName, []); | 12003 _errorReporter.reportError2(StaticWarningCode.CONST_WITH_ABSTRACT_CLAS
S, typeName, []); |
11287 } else { | 12004 } else { |
11288 _errorReporter.reportError2(StaticWarningCode.NEW_WITH_ABSTRACT_CLASS,
typeName, []); | 12005 _errorReporter.reportError2(StaticWarningCode.NEW_WITH_ABSTRACT_CLASS,
typeName, []); |
11289 } | 12006 } |
11290 return true; | 12007 return true; |
11291 } | 12008 } |
11292 } | 12009 } |
11293 return false; | 12010 return false; |
11294 } | 12011 } |
11295 | 12012 |
11296 /** | 12013 /** |
11297 * This verifies that the passed 'const' instance creation expression is not b
eing invoked on a | 12014 * This verifies that the passed 'const' instance creation expression is not b
eing invoked on a |
11298 * constructor that is not 'const'. | 12015 * constructor that is not 'const'. |
11299 * | 12016 * |
11300 * This method assumes that the instance creation was tested to be 'const' bef
ore being called. | 12017 * This method assumes that the instance creation was tested to be 'const' bef
ore being called. |
| 12018 * |
11301 * @param node the instance creation expression to evaluate | 12019 * @param node the instance creation expression to evaluate |
11302 * @return `true` if and only if an error code is generated on the passed node | 12020 * @return `true` if and only if an error code is generated on the passed node |
11303 * @see CompileTimeErrorCode#CONST_WITH_NON_CONST | 12021 * @see CompileTimeErrorCode#CONST_WITH_NON_CONST |
11304 */ | 12022 */ |
11305 bool checkForConstWithNonConst(InstanceCreationExpression node) { | 12023 bool checkForConstWithNonConst(InstanceCreationExpression node) { |
11306 ConstructorElement constructorElement = node.element; | 12024 ConstructorElement constructorElement = node.element; |
11307 if (constructorElement != null && !constructorElement.isConst) { | 12025 if (constructorElement != null && !constructorElement.isConst) { |
11308 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_NON_CONST, nod
e, []); | 12026 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_NON_CONST, nod
e, []); |
11309 return true; | 12027 return true; |
11310 } | 12028 } |
11311 return false; | 12029 return false; |
11312 } | 12030 } |
11313 | 12031 |
11314 /** | 12032 /** |
11315 * This verifies that the passed 'const' instance creation expression does not
reference any type | 12033 * This verifies that the passed 'const' instance creation expression does not
reference any type |
11316 * parameters. | 12034 * parameters. |
11317 * | 12035 * |
11318 * This method assumes that the instance creation was tested to be 'const' bef
ore being called. | 12036 * This method assumes that the instance creation was tested to be 'const' bef
ore being called. |
| 12037 * |
11319 * @param node the instance creation expression to evaluate | 12038 * @param node the instance creation expression to evaluate |
11320 * @return `true` if and only if an error code is generated on the passed node | 12039 * @return `true` if and only if an error code is generated on the passed node |
11321 * @see CompileTimeErrorCode#CONST_WITH_TYPE_PARAMETERS | 12040 * @see CompileTimeErrorCode#CONST_WITH_TYPE_PARAMETERS |
11322 */ | 12041 */ |
11323 bool checkForConstWithTypeParameters(InstanceCreationExpression node) { | 12042 bool checkForConstWithTypeParameters(InstanceCreationExpression node) { |
11324 ConstructorName constructorName = node.constructorName; | 12043 ConstructorName constructorName = node.constructorName; |
11325 if (constructorName == null) { | 12044 if (constructorName == null) { |
11326 return false; | 12045 return false; |
11327 } | 12046 } |
11328 TypeName typeName = constructorName.type; | 12047 TypeName typeName = constructorName.type; |
11329 return checkForConstWithTypeParameters2(typeName); | 12048 return checkForConstWithTypeParameters2(typeName); |
11330 } | 12049 } |
11331 | 12050 |
11332 /** | 12051 /** |
11333 * This verifies that the passed type name does not reference any type paramet
ers. | 12052 * This verifies that the passed type name does not reference any type paramet
ers. |
| 12053 * |
11334 * @param typeName the type name to evaluate | 12054 * @param typeName the type name to evaluate |
11335 * @return `true` if and only if an error code is generated on the passed node | 12055 * @return `true` if and only if an error code is generated on the passed node |
11336 * @see CompileTimeErrorCode#CONST_WITH_TYPE_PARAMETERS | 12056 * @see CompileTimeErrorCode#CONST_WITH_TYPE_PARAMETERS |
11337 */ | 12057 */ |
11338 bool checkForConstWithTypeParameters2(TypeName typeName) { | 12058 bool checkForConstWithTypeParameters2(TypeName typeName) { |
11339 if (typeName == null) { | 12059 if (typeName == null) { |
11340 return false; | 12060 return false; |
11341 } | 12061 } |
11342 Identifier name = typeName.name; | 12062 Identifier name = typeName.name; |
11343 if (name == null) { | 12063 if (name == null) { |
(...skipping 11 matching lines...) Expand all Loading... |
11355 return hasError; | 12075 return hasError; |
11356 } | 12076 } |
11357 return false; | 12077 return false; |
11358 } | 12078 } |
11359 | 12079 |
11360 /** | 12080 /** |
11361 * This verifies that if the passed 'const' instance creation expression is be
ing invoked on the | 12081 * This verifies that if the passed 'const' instance creation expression is be
ing invoked on the |
11362 * resolved constructor. | 12082 * resolved constructor. |
11363 * | 12083 * |
11364 * This method assumes that the instance creation was tested to be 'const' bef
ore being called. | 12084 * This method assumes that the instance creation was tested to be 'const' bef
ore being called. |
| 12085 * |
11365 * @param node the instance creation expression to evaluate | 12086 * @param node the instance creation expression to evaluate |
11366 * @return `true` if and only if an error code is generated on the passed node | 12087 * @return `true` if and only if an error code is generated on the passed node |
11367 * @see CompileTimeErrorCode#CONST_WITH_UNDEFINED_CONSTRUCTOR | 12088 * @see CompileTimeErrorCode#CONST_WITH_UNDEFINED_CONSTRUCTOR |
11368 * @see CompileTimeErrorCode#CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT | 12089 * @see CompileTimeErrorCode#CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT |
11369 */ | 12090 */ |
11370 bool checkForConstWithUndefinedConstructor(InstanceCreationExpression node) { | 12091 bool checkForConstWithUndefinedConstructor(InstanceCreationExpression node) { |
11371 if (node.element != null) { | 12092 if (node.element != null) { |
11372 return false; | 12093 return false; |
11373 } | 12094 } |
11374 ConstructorName constructorName = node.constructorName; | 12095 ConstructorName constructorName = node.constructorName; |
11375 if (constructorName == null) { | 12096 if (constructorName == null) { |
11376 return false; | 12097 return false; |
11377 } | 12098 } |
11378 TypeName type = constructorName.type; | 12099 TypeName type = constructorName.type; |
11379 if (type == null) { | 12100 if (type == null) { |
11380 return false; | 12101 return false; |
11381 } | 12102 } |
11382 Identifier className = type.name; | 12103 Identifier className = type.name; |
11383 SimpleIdentifier name = constructorName.name; | 12104 SimpleIdentifier name = constructorName.name; |
11384 if (name != null) { | 12105 if (name != null) { |
11385 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONS
TRUCTOR, name, [className, name]); | 12106 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONS
TRUCTOR, name, [className, name]); |
11386 } else { | 12107 } else { |
11387 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONS
TRUCTOR_DEFAULT, constructorName, [className]); | 12108 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONS
TRUCTOR_DEFAULT, constructorName, [className]); |
11388 } | 12109 } |
11389 return true; | 12110 return true; |
11390 } | 12111 } |
11391 | 12112 |
11392 /** | 12113 /** |
11393 * This verifies that there are no default parameters in the passed function t
ype alias. | 12114 * This verifies that there are no default parameters in the passed function t
ype alias. |
| 12115 * |
11394 * @param node the function type alias to evaluate | 12116 * @param node the function type alias to evaluate |
11395 * @return `true` if and only if an error code is generated on the passed node | 12117 * @return `true` if and only if an error code is generated on the passed node |
11396 * @see CompileTimeErrorCode#DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS | 12118 * @see CompileTimeErrorCode#DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS |
11397 */ | 12119 */ |
11398 bool checkForDefaultValueInFunctionTypeAlias(FunctionTypeAlias node) { | 12120 bool checkForDefaultValueInFunctionTypeAlias(FunctionTypeAlias node) { |
11399 bool result = false; | 12121 bool result = false; |
11400 FormalParameterList formalParameterList = node.parameters; | 12122 FormalParameterList formalParameterList = node.parameters; |
11401 NodeList<FormalParameter> parameters = formalParameterList.parameters; | 12123 NodeList<FormalParameter> parameters = formalParameterList.parameters; |
11402 for (FormalParameter formalParameter in parameters) { | 12124 for (FormalParameter formalParameter in parameters) { |
11403 if (formalParameter is DefaultFormalParameter) { | 12125 if (formalParameter is DefaultFormalParameter) { |
11404 DefaultFormalParameter defaultFormalParameter = formalParameter as Defau
ltFormalParameter; | 12126 DefaultFormalParameter defaultFormalParameter = formalParameter as Defau
ltFormalParameter; |
11405 if (defaultFormalParameter.defaultValue != null) { | 12127 if (defaultFormalParameter.defaultValue != null) { |
11406 _errorReporter.reportError2(CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNC
TION_TYPE_ALIAS, node, []); | 12128 _errorReporter.reportError2(CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNC
TION_TYPE_ALIAS, node, []); |
11407 result = true; | 12129 result = true; |
11408 } | 12130 } |
11409 } | 12131 } |
11410 } | 12132 } |
11411 return result; | 12133 return result; |
11412 } | 12134 } |
11413 | 12135 |
11414 /** | 12136 /** |
| 12137 * This verifies that the enclosing class does not have an instance member wit
h the given name of |
| 12138 * the static member. |
| 12139 * |
| 12140 * @return `true` if and only if an error code is generated on the passed node |
| 12141 * @see CompileTimeErrorCode#DUPLICATE_DEFINITION_INHERITANCE |
| 12142 */ |
| 12143 bool checkForDuplicateDefinitionInheritance() { |
| 12144 if (_enclosingClass == null) { |
| 12145 return false; |
| 12146 } |
| 12147 bool hasProblem = false; |
| 12148 for (MethodElement method in _enclosingClass.methods) { |
| 12149 if (!method.isStatic) { |
| 12150 continue; |
| 12151 } |
| 12152 hasProblem = javaBooleanOr(hasProblem, checkForDuplicateDefinitionInherita
nce2(method)); |
| 12153 } |
| 12154 return hasProblem; |
| 12155 } |
| 12156 |
| 12157 /** |
| 12158 * This verifies that the enclosing class does not have an instance member wit
h the given name of |
| 12159 * the static member. |
| 12160 * |
| 12161 * @param staticMember the static member to check conflict for |
| 12162 * @return `true` if and only if an error code is generated on the passed node |
| 12163 * @see CompileTimeErrorCode#DUPLICATE_DEFINITION_INHERITANCE |
| 12164 */ |
| 12165 bool checkForDuplicateDefinitionInheritance2(ExecutableElement staticMember) { |
| 12166 String name = staticMember.name; |
| 12167 if (name == null) { |
| 12168 return false; |
| 12169 } |
| 12170 ExecutableElement inheritedMember = _inheritanceManager.lookupInheritance(_e
nclosingClass, name); |
| 12171 if (inheritedMember == null) { |
| 12172 return false; |
| 12173 } |
| 12174 if (inheritedMember.isStatic) { |
| 12175 return false; |
| 12176 } |
| 12177 _errorReporter.reportError3(CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERI
TANCE, staticMember.nameOffset, name.length, [name, inheritedMember.enclosingEle
ment.displayName]); |
| 12178 return true; |
| 12179 } |
| 12180 |
| 12181 /** |
11415 * This verifies the passed import has unique name among other exported librar
ies. | 12182 * This verifies the passed import has unique name among other exported librar
ies. |
| 12183 * |
11416 * @param node the export directive to evaluate | 12184 * @param node the export directive to evaluate |
11417 * @return `true` if and only if an error code is generated on the passed node | 12185 * @return `true` if and only if an error code is generated on the passed node |
11418 * @see CompileTimeErrorCode#EXPORT_DUPLICATED_LIBRARY_NAME | 12186 * @see CompileTimeErrorCode#EXPORT_DUPLICATED_LIBRARY_NAME |
11419 */ | 12187 */ |
11420 bool checkForExportDuplicateLibraryName(ExportDirective node) { | 12188 bool checkForExportDuplicateLibraryName(ExportDirective node) { |
11421 Element nodeElement = node.element; | 12189 Element nodeElement = node.element; |
11422 if (nodeElement is! ExportElement) { | 12190 if (nodeElement is! ExportElement) { |
11423 return false; | 12191 return false; |
11424 } | 12192 } |
11425 ExportElement nodeExportElement = nodeElement as ExportElement; | 12193 ExportElement nodeExportElement = nodeElement as ExportElement; |
(...skipping 10 matching lines...) Expand all Loading... |
11436 } | 12204 } |
11437 } else { | 12205 } else { |
11438 _nameToExportElement[name] = nodeLibrary; | 12206 _nameToExportElement[name] = nodeLibrary; |
11439 } | 12207 } |
11440 return false; | 12208 return false; |
11441 } | 12209 } |
11442 | 12210 |
11443 /** | 12211 /** |
11444 * Check that if the visiting library is not system, then any passed library s
hould not be SDK | 12212 * Check that if the visiting library is not system, then any passed library s
hould not be SDK |
11445 * internal library. | 12213 * internal library. |
| 12214 * |
11446 * @param node the export directive to evaluate | 12215 * @param node the export directive to evaluate |
11447 * @return `true` if and only if an error code is generated on the passed node | 12216 * @return `true` if and only if an error code is generated on the passed node |
11448 * @see CompileTimeErrorCode#EXPORT_INTERNAL_LIBRARY | 12217 * @see CompileTimeErrorCode#EXPORT_INTERNAL_LIBRARY |
11449 */ | 12218 */ |
11450 bool checkForExportInternalLibrary(ExportDirective node) { | 12219 bool checkForExportInternalLibrary(ExportDirective node) { |
11451 if (_isInSystemLibrary) { | 12220 if (_isInSystemLibrary) { |
11452 return false; | 12221 return false; |
11453 } | 12222 } |
11454 Element element = node.element; | 12223 Element element = node.element; |
11455 if (element is! ExportElement) { | 12224 if (element is! ExportElement) { |
11456 return false; | 12225 return false; |
11457 } | 12226 } |
11458 ExportElement exportElement = element as ExportElement; | 12227 ExportElement exportElement = element as ExportElement; |
11459 DartSdk sdk = _currentLibrary.context.sourceFactory.dartSdk; | 12228 DartSdk sdk = _currentLibrary.context.sourceFactory.dartSdk; |
11460 String uri = exportElement.uri; | 12229 String uri = exportElement.uri; |
11461 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); | 12230 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); |
11462 if (sdkLibrary == null) { | 12231 if (sdkLibrary == null) { |
11463 return false; | 12232 return false; |
11464 } | 12233 } |
11465 if (!sdkLibrary.isInternal) { | 12234 if (!sdkLibrary.isInternal) { |
11466 return false; | 12235 return false; |
11467 } | 12236 } |
11468 _errorReporter.reportError2(CompileTimeErrorCode.EXPORT_INTERNAL_LIBRARY, no
de, [node.uri]); | 12237 _errorReporter.reportError2(CompileTimeErrorCode.EXPORT_INTERNAL_LIBRARY, no
de, [node.uri]); |
11469 return true; | 12238 return true; |
11470 } | 12239 } |
11471 | 12240 |
11472 /** | 12241 /** |
11473 * This verifies that the passed extends clause does not extend classes such a
s num or String. | 12242 * This verifies that the passed extends clause does not extend classes such a
s num or String. |
| 12243 * |
11474 * @param node the extends clause to test | 12244 * @param node the extends clause to test |
11475 * @return `true` if and only if an error code is generated on the passed node | 12245 * @return `true` if and only if an error code is generated on the passed node |
11476 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS | 12246 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS |
11477 */ | 12247 */ |
11478 bool checkForExtendsDisallowedClass(ExtendsClause extendsClause) { | 12248 bool checkForExtendsDisallowedClass(ExtendsClause extendsClause) { |
11479 if (extendsClause == null) { | 12249 if (extendsClause == null) { |
11480 return false; | 12250 return false; |
11481 } | 12251 } |
11482 return checkForExtendsOrImplementsDisallowedClass(extendsClause.superclass,
CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS); | 12252 return checkForExtendsOrImplementsDisallowedClass(extendsClause.superclass,
CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS); |
11483 } | 12253 } |
11484 | 12254 |
11485 /** | 12255 /** |
11486 * This verifies that the passed type name does not extend or implement classe
s such as 'num' or | 12256 * This verifies that the passed type name does not extend or implement classe
s such as 'num' or |
11487 * 'String'. | 12257 * 'String'. |
| 12258 * |
11488 * @param node the type name to test | 12259 * @param node the type name to test |
11489 * @return `true` if and only if an error code is generated on the passed node | 12260 * @return `true` if and only if an error code is generated on the passed node |
11490 * @see #checkForExtendsDisallowedClass(ExtendsClause) | 12261 * @see #checkForExtendsDisallowedClass(ExtendsClause) |
11491 * @see #checkForImplementsDisallowedClass(ImplementsClause) | 12262 * @see #checkForImplementsDisallowedClass(ImplementsClause) |
11492 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS | 12263 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS |
11493 * @see CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS | 12264 * @see CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS |
11494 */ | 12265 */ |
11495 bool checkForExtendsOrImplementsDisallowedClass(TypeName typeName, ErrorCode e
rrorCode) { | 12266 bool checkForExtendsOrImplementsDisallowedClass(TypeName typeName, ErrorCode e
rrorCode) { |
11496 if (typeName.isSynthetic) { | 12267 if (typeName.isSynthetic) { |
11497 return false; | 12268 return false; |
(...skipping 14 matching lines...) Expand all Loading... |
11512 _errorReporter.reportError2(errorCode, typeName, [disallowedType.display
Name]); | 12283 _errorReporter.reportError2(errorCode, typeName, [disallowedType.display
Name]); |
11513 return true; | 12284 return true; |
11514 } | 12285 } |
11515 } | 12286 } |
11516 return false; | 12287 return false; |
11517 } | 12288 } |
11518 | 12289 |
11519 /** | 12290 /** |
11520 * This verifies that the passed constructor field initializer has compatible
field and | 12291 * This verifies that the passed constructor field initializer has compatible
field and |
11521 * initializer expression types. | 12292 * initializer expression types. |
| 12293 * |
11522 * @param node the constructor field initializer to test | 12294 * @param node the constructor field initializer to test |
11523 * @return `true` if and only if an error code is generated on the passed node | 12295 * @return `true` if and only if an error code is generated on the passed node |
11524 * @see CompileTimeErrorCode#CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE | 12296 * @see CompileTimeErrorCode#CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE |
11525 * @see StaticWarningCode#FIELD_INITIALIZER_NOT_ASSIGNABLE | 12297 * @see StaticWarningCode#FIELD_INITIALIZER_NOT_ASSIGNABLE |
11526 */ | 12298 */ |
11527 bool checkForFieldInitializerNotAssignable(ConstructorFieldInitializer node) { | 12299 bool checkForFieldInitializerNotAssignable(ConstructorFieldInitializer node) { |
11528 Element fieldNameElement = node.fieldName.element; | 12300 Element fieldNameElement = node.fieldName.element; |
11529 if (fieldNameElement is! FieldElement) { | 12301 if (fieldNameElement is! FieldElement) { |
11530 return false; | 12302 return false; |
11531 } | 12303 } |
(...skipping 24 matching lines...) Expand all Loading... |
11556 if (_isEnclosingConstructorConst) { | 12328 if (_isEnclosingConstructorConst) { |
11557 _errorReporter.reportError2(CompileTimeErrorCode.CONST_FIELD_INITIALIZER_N
OT_ASSIGNABLE, expression, [(propagatedType == null ? staticType : propagatedTyp
e).displayName, fieldType.displayName]); | 12329 _errorReporter.reportError2(CompileTimeErrorCode.CONST_FIELD_INITIALIZER_N
OT_ASSIGNABLE, expression, [(propagatedType == null ? staticType : propagatedTyp
e).displayName, fieldType.displayName]); |
11558 } else { | 12330 } else { |
11559 _errorReporter.reportError2(StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGN
ABLE, expression, [(propagatedType == null ? staticType : propagatedType).displa
yName, fieldType.displayName]); | 12331 _errorReporter.reportError2(StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGN
ABLE, expression, [(propagatedType == null ? staticType : propagatedType).displa
yName, fieldType.displayName]); |
11560 } | 12332 } |
11561 return true; | 12333 return true; |
11562 } | 12334 } |
11563 | 12335 |
11564 /** | 12336 /** |
11565 * This verifies that the passed field formal parameter is in a constructor de
claration. | 12337 * This verifies that the passed field formal parameter is in a constructor de
claration. |
| 12338 * |
11566 * @param node the field formal parameter to test | 12339 * @param node the field formal parameter to test |
11567 * @return `true` if and only if an error code is generated on the passed node | 12340 * @return `true` if and only if an error code is generated on the passed node |
11568 * @see CompileTimeErrorCode#FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR | 12341 * @see CompileTimeErrorCode#FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR |
11569 */ | 12342 */ |
11570 bool checkForFieldInitializingFormalRedirectingConstructor(FieldFormalParamete
r node) { | 12343 bool checkForFieldInitializingFormalRedirectingConstructor(FieldFormalParamete
r node) { |
11571 ConstructorDeclaration constructor = node.getAncestor(ConstructorDeclaration
); | 12344 ConstructorDeclaration constructor = node.getAncestor(ConstructorDeclaration
); |
11572 if (constructor == null) { | 12345 if (constructor == null) { |
11573 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE
_CONSTRUCTOR, node, []); | 12346 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE
_CONSTRUCTOR, node, []); |
11574 return true; | 12347 return true; |
11575 } | 12348 } |
11576 if (constructor.factoryKeyword != null) { | 12349 if (constructor.factoryKeyword != null) { |
11577 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY
_CONSTRUCTOR, node, []); | 12350 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY
_CONSTRUCTOR, node, []); |
11578 return true; | 12351 return true; |
11579 } | 12352 } |
11580 for (ConstructorInitializer initializer in constructor.initializers) { | 12353 for (ConstructorInitializer initializer in constructor.initializers) { |
11581 if (initializer is RedirectingConstructorInvocation) { | 12354 if (initializer is RedirectingConstructorInvocation) { |
11582 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_REDIR
ECTING_CONSTRUCTOR, node, []); | 12355 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_REDIR
ECTING_CONSTRUCTOR, node, []); |
11583 return true; | 12356 return true; |
11584 } | 12357 } |
11585 } | 12358 } |
11586 return false; | 12359 return false; |
11587 } | 12360 } |
11588 | 12361 |
11589 /** | 12362 /** |
11590 * This verifies that final fields that are declared, without any constructors
in the enclosing | 12363 * This verifies that final fields that are declared, without any constructors
in the enclosing |
11591 * class, are initialized. Cases in which there is at least one constructor ar
e handled at the end | 12364 * class, are initialized. Cases in which there is at least one constructor ar
e handled at the end |
11592 * of [checkForAllFinalInitializedErrorCodes]. | 12365 * of [checkForAllFinalInitializedErrorCodes]. |
| 12366 * |
11593 * @param node the class declaration to test | 12367 * @param node the class declaration to test |
11594 * @return `true` if and only if an error code is generated on the passed node | 12368 * @return `true` if and only if an error code is generated on the passed node |
11595 * @see CompileTimeErrorCode#FINAL_NOT_INITIALIZED | 12369 * @see CompileTimeErrorCode#FINAL_NOT_INITIALIZED |
11596 */ | 12370 */ |
11597 bool checkForFinalNotInitialized(ClassDeclaration node) { | 12371 bool checkForFinalNotInitialized(ClassDeclaration node) { |
11598 NodeList<ClassMember> classMembers = node.members; | 12372 NodeList<ClassMember> classMembers = node.members; |
11599 for (ClassMember classMember in classMembers) { | 12373 for (ClassMember classMember in classMembers) { |
11600 if (classMember is ConstructorDeclaration) { | 12374 if (classMember is ConstructorDeclaration) { |
11601 return false; | 12375 return false; |
11602 } | 12376 } |
11603 } | 12377 } |
11604 bool foundError = false; | 12378 bool foundError = false; |
11605 for (ClassMember classMember in classMembers) { | 12379 for (ClassMember classMember in classMembers) { |
11606 if (classMember is FieldDeclaration) { | 12380 if (classMember is FieldDeclaration) { |
11607 FieldDeclaration field = classMember as FieldDeclaration; | 12381 FieldDeclaration field = classMember as FieldDeclaration; |
11608 foundError = javaBooleanOr(foundError, checkForFinalNotInitialized2(fiel
d.fields)); | 12382 foundError = javaBooleanOr(foundError, checkForFinalNotInitialized2(fiel
d.fields)); |
11609 } | 12383 } |
11610 } | 12384 } |
11611 return foundError; | 12385 return foundError; |
11612 } | 12386 } |
11613 | 12387 |
11614 /** | 12388 /** |
11615 * This verifies that the passed variable declaration list has only initialize
d variables if the | 12389 * This verifies that the passed variable declaration list has only initialize
d variables if the |
11616 * list is final or const. This method is called by[checkForFinalNotInitialize
d],[visitTopLevelVariableDeclaration] and[visitVariableDeclarationStatement]. | 12390 * list is final or const. This method is called by |
| 12391 * [checkForFinalNotInitialized], |
| 12392 * [visitTopLevelVariableDeclaration] and |
| 12393 * [visitVariableDeclarationStatement]. |
| 12394 * |
11617 * @param node the class declaration to test | 12395 * @param node the class declaration to test |
11618 * @return `true` if and only if an error code is generated on the passed node | 12396 * @return `true` if and only if an error code is generated on the passed node |
11619 * @see CompileTimeErrorCode#FINAL_NOT_INITIALIZED | 12397 * @see CompileTimeErrorCode#FINAL_NOT_INITIALIZED |
11620 */ | 12398 */ |
11621 bool checkForFinalNotInitialized2(VariableDeclarationList node) { | 12399 bool checkForFinalNotInitialized2(VariableDeclarationList node) { |
11622 bool foundError = false; | 12400 bool foundError = false; |
11623 if (!node.isSynthetic && (node.isConst || node.isFinal)) { | 12401 if (!node.isSynthetic && (node.isConst || node.isFinal)) { |
11624 NodeList<VariableDeclaration> variables = node.variables; | 12402 NodeList<VariableDeclaration> variables = node.variables; |
11625 for (VariableDeclaration variable in variables) { | 12403 for (VariableDeclaration variable in variables) { |
11626 if (variable.initializer == null) { | 12404 if (variable.initializer == null) { |
11627 _errorReporter.reportError2(StaticWarningCode.FINAL_NOT_INITIALIZED, v
ariable, [variable.name.name]); | 12405 _errorReporter.reportError2(StaticWarningCode.FINAL_NOT_INITIALIZED, v
ariable, [variable.name.name]); |
11628 foundError = true; | 12406 foundError = true; |
11629 } | 12407 } |
11630 } | 12408 } |
11631 } | 12409 } |
11632 return foundError; | 12410 return foundError; |
11633 } | 12411 } |
11634 | 12412 |
11635 /** | 12413 /** |
11636 * This verifies that the passed implements clause does not implement classes
such as 'num' or | 12414 * This verifies that the passed implements clause does not implement classes
such as 'num' or |
11637 * 'String'. | 12415 * 'String'. |
| 12416 * |
11638 * @param node the implements clause to test | 12417 * @param node the implements clause to test |
11639 * @return `true` if and only if an error code is generated on the passed node | 12418 * @return `true` if and only if an error code is generated on the passed node |
11640 * @see CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS | 12419 * @see CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS |
11641 */ | 12420 */ |
11642 bool checkForImplementsDisallowedClass(ImplementsClause implementsClause) { | 12421 bool checkForImplementsDisallowedClass(ImplementsClause implementsClause) { |
11643 if (implementsClause == null) { | 12422 if (implementsClause == null) { |
11644 return false; | 12423 return false; |
11645 } | 12424 } |
11646 bool foundError = false; | 12425 bool foundError = false; |
11647 for (TypeName type in implementsClause.interfaces) { | 12426 for (TypeName type in implementsClause.interfaces) { |
11648 foundError = javaBooleanOr(foundError, checkForExtendsOrImplementsDisallow
edClass(type, CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS)); | 12427 foundError = javaBooleanOr(foundError, checkForExtendsOrImplementsDisallow
edClass(type, CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS)); |
11649 } | 12428 } |
11650 return foundError; | 12429 return foundError; |
11651 } | 12430 } |
11652 | 12431 |
11653 /** | 12432 /** |
11654 * This verifies that if the passed identifier is part of constructor initiali
zer, then it does | 12433 * This verifies that if the passed identifier is part of constructor initiali
zer, then it does |
11655 * not reference implicitly 'this' expression. | 12434 * not reference implicitly 'this' expression. |
| 12435 * |
11656 * @param node the simple identifier to test | 12436 * @param node the simple identifier to test |
11657 * @return `true` if and only if an error code is generated on the passed node | 12437 * @return `true` if and only if an error code is generated on the passed node |
11658 * @see CompileTimeErrorCode#IMPLICIT_THIS_REFERENCE_IN_INITIALIZER | 12438 * @see CompileTimeErrorCode#IMPLICIT_THIS_REFERENCE_IN_INITIALIZER |
| 12439 * @see CompileTimeErrorCode#INSTANCE_MEMBER_ACCESS_FROM_STATIC TODO(scheglov)
rename thid method |
11659 */ | 12440 */ |
11660 bool checkForImplicitThisReferenceInInitializer(SimpleIdentifier node) { | 12441 bool checkForImplicitThisReferenceInInitializer(SimpleIdentifier node) { |
11661 if (!_isInConstructorInitializer) { | 12442 if (!_isInConstructorInitializer && !_isInStaticMethod && !_isInInstanceVari
ableInitializer) { |
11662 return false; | 12443 return false; |
11663 } | 12444 } |
11664 Element element = node.element; | 12445 Element element = node.element; |
11665 if (!(element is MethodElement || element is PropertyAccessorElement)) { | 12446 if (!(element is MethodElement || element is PropertyAccessorElement)) { |
11666 return false; | 12447 return false; |
11667 } | 12448 } |
11668 ExecutableElement executableElement = element as ExecutableElement; | 12449 ExecutableElement executableElement = element as ExecutableElement; |
11669 if (executableElement.isStatic) { | 12450 if (executableElement.isStatic) { |
11670 return false; | 12451 return false; |
11671 } | 12452 } |
11672 Element enclosingElement = element.enclosingElement; | 12453 Element enclosingElement = element.enclosingElement; |
11673 if (enclosingElement is! ClassElement) { | 12454 if (enclosingElement is! ClassElement) { |
11674 return false; | 12455 return false; |
11675 } | 12456 } |
11676 ASTNode parent = node.parent; | 12457 ASTNode parent = node.parent; |
| 12458 if (parent is CommentReference) { |
| 12459 return false; |
| 12460 } |
11677 if (parent is MethodInvocation) { | 12461 if (parent is MethodInvocation) { |
11678 MethodInvocation invocation = parent as MethodInvocation; | 12462 MethodInvocation invocation = parent as MethodInvocation; |
11679 if (identical(invocation.methodName, node) && invocation.realTarget != nul
l) { | 12463 if (identical(invocation.methodName, node) && invocation.realTarget != nul
l) { |
11680 return false; | 12464 return false; |
11681 } | 12465 } |
11682 } | 12466 } |
11683 { | 12467 { |
11684 if (parent is PropertyAccess) { | 12468 if (parent is PropertyAccess) { |
11685 PropertyAccess access = parent as PropertyAccess; | 12469 PropertyAccess access = parent as PropertyAccess; |
11686 if (identical(access.propertyName, node) && access.realTarget != null) { | 12470 if (identical(access.propertyName, node) && access.realTarget != null) { |
11687 return false; | 12471 return false; |
11688 } | 12472 } |
11689 } | 12473 } |
11690 if (parent is PrefixedIdentifier) { | 12474 if (parent is PrefixedIdentifier) { |
11691 PrefixedIdentifier prefixed = parent as PrefixedIdentifier; | 12475 PrefixedIdentifier prefixed = parent as PrefixedIdentifier; |
11692 if (identical(prefixed.identifier, node)) { | 12476 if (identical(prefixed.identifier, node)) { |
11693 return false; | 12477 return false; |
11694 } | 12478 } |
11695 } | 12479 } |
11696 } | 12480 } |
11697 _errorReporter.reportError2(CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_
INITIALIZER, node, []); | 12481 if (_isInConstructorInitializer || _isInInstanceVariableInitializer) { |
| 12482 _errorReporter.reportError2(CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_I
N_INITIALIZER, node, []); |
| 12483 } else if (_isInStaticMethod) { |
| 12484 _errorReporter.reportError2(CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FR
OM_STATIC, node, []); |
| 12485 } |
11698 return true; | 12486 return true; |
11699 } | 12487 } |
11700 | 12488 |
11701 /** | 12489 /** |
11702 * This verifies the passed import has unique name among other imported librar
ies. | 12490 * This verifies the passed import has unique name among other imported librar
ies. |
| 12491 * |
11703 * @param node the import directive to evaluate | 12492 * @param node the import directive to evaluate |
11704 * @return `true` if and only if an error code is generated on the passed node | 12493 * @return `true` if and only if an error code is generated on the passed node |
11705 * @see CompileTimeErrorCode#IMPORT_DUPLICATED_LIBRARY_NAME | 12494 * @see CompileTimeErrorCode#IMPORT_DUPLICATED_LIBRARY_NAME |
11706 */ | 12495 */ |
11707 bool checkForImportDuplicateLibraryName(ImportDirective node) { | 12496 bool checkForImportDuplicateLibraryName(ImportDirective node) { |
11708 Element nodeElement = node.element; | 12497 Element nodeElement = node.element; |
11709 if (nodeElement is! ImportElement) { | 12498 if (nodeElement is! ImportElement) { |
11710 return false; | 12499 return false; |
11711 } | 12500 } |
11712 ImportElement nodeImportElement = nodeElement as ImportElement; | 12501 ImportElement nodeImportElement = nodeElement as ImportElement; |
(...skipping 10 matching lines...) Expand all Loading... |
11723 } | 12512 } |
11724 } else { | 12513 } else { |
11725 _nameToImportElement[name] = nodeLibrary; | 12514 _nameToImportElement[name] = nodeLibrary; |
11726 } | 12515 } |
11727 return false; | 12516 return false; |
11728 } | 12517 } |
11729 | 12518 |
11730 /** | 12519 /** |
11731 * Check that if the visiting library is not system, then any passed library s
hould not be SDK | 12520 * Check that if the visiting library is not system, then any passed library s
hould not be SDK |
11732 * internal library. | 12521 * internal library. |
| 12522 * |
11733 * @param node the import directive to evaluate | 12523 * @param node the import directive to evaluate |
11734 * @return `true` if and only if an error code is generated on the passed node | 12524 * @return `true` if and only if an error code is generated on the passed node |
11735 * @see CompileTimeErrorCode#IMPORT_INTERNAL_LIBRARY | 12525 * @see CompileTimeErrorCode#IMPORT_INTERNAL_LIBRARY |
11736 */ | 12526 */ |
11737 bool checkForImportInternalLibrary(ImportDirective node) { | 12527 bool checkForImportInternalLibrary(ImportDirective node) { |
11738 if (_isInSystemLibrary) { | 12528 if (_isInSystemLibrary) { |
11739 return false; | 12529 return false; |
11740 } | 12530 } |
11741 Element element = node.element; | 12531 Element element = node.element; |
11742 if (element is! ImportElement) { | 12532 if (element is! ImportElement) { |
11743 return false; | 12533 return false; |
11744 } | 12534 } |
11745 ImportElement importElement = element as ImportElement; | 12535 ImportElement importElement = element as ImportElement; |
11746 DartSdk sdk = _currentLibrary.context.sourceFactory.dartSdk; | 12536 DartSdk sdk = _currentLibrary.context.sourceFactory.dartSdk; |
11747 String uri = importElement.uri; | 12537 String uri = importElement.uri; |
11748 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); | 12538 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); |
11749 if (sdkLibrary == null) { | 12539 if (sdkLibrary == null) { |
11750 return false; | 12540 return false; |
11751 } | 12541 } |
11752 if (!sdkLibrary.isInternal) { | 12542 if (!sdkLibrary.isInternal) { |
11753 return false; | 12543 return false; |
11754 } | 12544 } |
11755 _errorReporter.reportError2(CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, no
de, [node.uri]); | 12545 _errorReporter.reportError2(CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, no
de, [node.uri]); |
11756 return true; | 12546 return true; |
11757 } | 12547 } |
11758 | 12548 |
11759 /** | 12549 /** |
11760 * This verifies that the passed switch statement case expressions all have th
e same type. | 12550 * This verifies that the passed switch statement case expressions all have th
e same type. |
| 12551 * |
11761 * @param node the switch statement to evaluate | 12552 * @param node the switch statement to evaluate |
11762 * @return `true` if and only if an error code is generated on the passed node | 12553 * @return `true` if and only if an error code is generated on the passed node |
11763 * @see CompileTimeErrorCode#INCONSISTENT_CASE_EXPRESSION_TYPES | 12554 * @see CompileTimeErrorCode#INCONSISTENT_CASE_EXPRESSION_TYPES |
11764 */ | 12555 */ |
11765 bool checkForInconsistentCaseExpressionTypes(SwitchStatement node) { | 12556 bool checkForInconsistentCaseExpressionTypes(SwitchStatement node) { |
11766 NodeList<SwitchMember> switchMembers = node.members; | 12557 NodeList<SwitchMember> switchMembers = node.members; |
11767 bool foundError = false; | 12558 bool foundError = false; |
11768 Type2 firstType = null; | 12559 Type2 firstType = null; |
11769 for (SwitchMember switchMember in switchMembers) { | 12560 for (SwitchMember switchMember in switchMembers) { |
11770 if (switchMember is SwitchCase) { | 12561 if (switchMember is SwitchCase) { |
11771 SwitchCase switchCase = switchMember as SwitchCase; | 12562 SwitchCase switchCase = switchMember as SwitchCase; |
11772 Expression expression = switchCase.expression; | 12563 Expression expression = switchCase.expression; |
11773 if (firstType == null) { | 12564 if (firstType == null) { |
11774 firstType = getBestType(expression); | 12565 firstType = getBestType(expression); |
11775 } else { | 12566 } else { |
11776 Type2 nType = getBestType(expression); | 12567 Type2 nType = getBestType(expression); |
11777 if (firstType != nType) { | 12568 if (firstType != nType) { |
11778 _errorReporter.reportError2(CompileTimeErrorCode.INCONSISTENT_CASE_E
XPRESSION_TYPES, expression, [expression.toSource(), firstType.displayName]); | 12569 _errorReporter.reportError2(CompileTimeErrorCode.INCONSISTENT_CASE_E
XPRESSION_TYPES, expression, [expression.toSource(), firstType.displayName]); |
11779 foundError = true; | 12570 foundError = true; |
11780 } | 12571 } |
11781 } | 12572 } |
11782 } | 12573 } |
11783 } | 12574 } |
| 12575 if (!foundError) { |
| 12576 checkForCaseExpressionTypeImplementsEquals(node, firstType); |
| 12577 } |
11784 return foundError; | 12578 return foundError; |
11785 } | 12579 } |
11786 | 12580 |
11787 /** | 12581 /** |
11788 * For each class declaration, this method is called which verifies that all i
nherited members are | 12582 * For each class declaration, this method is called which verifies that all i
nherited members are |
11789 * inherited consistently. | 12583 * inherited consistently. |
| 12584 * |
11790 * @return `true` if and only if an error code is generated on the passed node | 12585 * @return `true` if and only if an error code is generated on the passed node |
11791 * @see StaticTypeWarningCode#INCONSISTENT_METHOD_INHERITANCE | 12586 * @see StaticTypeWarningCode#INCONSISTENT_METHOD_INHERITANCE |
11792 */ | 12587 */ |
11793 bool checkForInconsistentMethodInheritance() { | 12588 bool checkForInconsistentMethodInheritance() { |
11794 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(_enclosingClass); | 12589 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(_enclosingClass); |
11795 Set<AnalysisError> errors = _inheritanceManager.getErrors(_enclosingClass); | 12590 Set<AnalysisError> errors = _inheritanceManager.getErrors(_enclosingClass); |
11796 if (errors == null || errors.isEmpty) { | 12591 if (errors == null || errors.isEmpty) { |
11797 return false; | 12592 return false; |
11798 } | 12593 } |
11799 for (AnalysisError error in errors) { | 12594 for (AnalysisError error in errors) { |
11800 _errorReporter.reportError(error); | 12595 _errorReporter.reportError(error); |
11801 } | 12596 } |
11802 return true; | 12597 return true; |
11803 } | 12598 } |
11804 | 12599 |
11805 /** | 12600 /** |
11806 * Given an assignment using a compound assignment operator, this verifies tha
t the given | 12601 * Given an assignment using a compound assignment operator, this verifies tha
t the given |
11807 * assignment is valid. | 12602 * assignment is valid. |
| 12603 * |
11808 * @param node the assignment expression being tested | 12604 * @param node the assignment expression being tested |
11809 * @return `true` if and only if an error code is generated on the passed node | 12605 * @return `true` if and only if an error code is generated on the passed node |
11810 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT | 12606 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT |
11811 */ | 12607 */ |
11812 bool checkForInvalidAssignment(AssignmentExpression node) { | 12608 bool checkForInvalidAssignment(AssignmentExpression node) { |
11813 Expression lhs = node.leftHandSide; | 12609 Expression lhs = node.leftHandSide; |
11814 if (lhs == null) { | 12610 if (lhs == null) { |
11815 return false; | 12611 return false; |
11816 } | 12612 } |
11817 VariableElement leftElement = getVariableElement(lhs); | 12613 VariableElement leftElement = getVariableElement(lhs); |
11818 Type2 leftType = (leftElement == null) ? getStaticType(lhs) : leftElement.ty
pe; | 12614 Type2 leftType = (leftElement == null) ? getStaticType(lhs) : leftElement.ty
pe; |
11819 MethodElement invokedMethod = node.element; | 12615 MethodElement invokedMethod = node.element; |
11820 if (invokedMethod == null) { | 12616 if (invokedMethod == null) { |
11821 return false; | 12617 return false; |
11822 } | 12618 } |
11823 Type2 rightType = invokedMethod.type.returnType; | 12619 Type2 rightType = invokedMethod.type.returnType; |
11824 if (leftType == null || rightType == null) { | 12620 if (leftType == null || rightType == null) { |
11825 return false; | 12621 return false; |
11826 } | 12622 } |
11827 if (!rightType.isAssignableTo(leftType)) { | 12623 if (!rightType.isAssignableTo(leftType)) { |
11828 _errorReporter.reportError2(StaticTypeWarningCode.INVALID_ASSIGNMENT, node
.rightHandSide, [rightType.displayName, leftType.displayName]); | 12624 _errorReporter.reportError2(StaticTypeWarningCode.INVALID_ASSIGNMENT, node
.rightHandSide, [rightType.displayName, leftType.displayName]); |
11829 return true; | 12625 return true; |
11830 } | 12626 } |
11831 return false; | 12627 return false; |
11832 } | 12628 } |
11833 | 12629 |
11834 /** | 12630 /** |
11835 * This verifies that the passed left hand side and right hand side represent
a valid assignment. | 12631 * This verifies that the passed left hand side and right hand side represent
a valid assignment. |
| 12632 * |
11836 * @param lhs the left hand side expression | 12633 * @param lhs the left hand side expression |
11837 * @param rhs the right hand side expression | 12634 * @param rhs the right hand side expression |
11838 * @return `true` if and only if an error code is generated on the passed node | 12635 * @return `true` if and only if an error code is generated on the passed node |
11839 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT | 12636 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT |
11840 */ | 12637 */ |
11841 bool checkForInvalidAssignment2(Expression lhs, Expression rhs) { | 12638 bool checkForInvalidAssignment2(Expression lhs, Expression rhs) { |
11842 if (lhs == null || rhs == null) { | 12639 if (lhs == null || rhs == null) { |
11843 return false; | 12640 return false; |
11844 } | 12641 } |
11845 VariableElement leftElement = getVariableElement(lhs); | 12642 VariableElement leftElement = getVariableElement(lhs); |
(...skipping 11 matching lines...) Expand all Loading... |
11857 if (!isStaticAssignable && !isPropagatedAssignable) { | 12654 if (!isStaticAssignable && !isPropagatedAssignable) { |
11858 _errorReporter.reportError2(StaticTypeWarningCode.INVALID_ASSIGNMENT, rh
s, [staticRightType.displayName, leftType.displayName]); | 12655 _errorReporter.reportError2(StaticTypeWarningCode.INVALID_ASSIGNMENT, rh
s, [staticRightType.displayName, leftType.displayName]); |
11859 return true; | 12656 return true; |
11860 } | 12657 } |
11861 } | 12658 } |
11862 return false; | 12659 return false; |
11863 } | 12660 } |
11864 | 12661 |
11865 /** | 12662 /** |
11866 * This verifies that the usage of the passed 'this' is valid. | 12663 * This verifies that the usage of the passed 'this' is valid. |
| 12664 * |
11867 * @param node the 'this' expression to evaluate | 12665 * @param node the 'this' expression to evaluate |
11868 * @return `true` if and only if an error code is generated on the passed node | 12666 * @return `true` if and only if an error code is generated on the passed node |
11869 * @see CompileTimeErrorCode#INVALID_REFERENCE_TO_THIS | 12667 * @see CompileTimeErrorCode#INVALID_REFERENCE_TO_THIS |
11870 */ | 12668 */ |
11871 bool checkForInvalidReferenceToThis(ThisExpression node) { | 12669 bool checkForInvalidReferenceToThis(ThisExpression node) { |
11872 if (!isThisInValidContext(node)) { | 12670 if (!isThisInValidContext(node)) { |
11873 _errorReporter.reportError2(CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS
, node, []); | 12671 _errorReporter.reportError2(CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS
, node, []); |
11874 return true; | 12672 return true; |
11875 } | 12673 } |
11876 return false; | 12674 return false; |
11877 } | 12675 } |
11878 | 12676 |
11879 /** | 12677 /** |
11880 * Checks to ensure that first type argument to a map literal must be the 'Str
ing' type. | 12678 * Checks to ensure that first type argument to a map literal must be the 'Str
ing' type. |
11881 * @param arguments a non-`null`, non-empty [TypeName] node list from the resp
ective[MapLiteral] | 12679 * |
| 12680 * @param arguments a non-`null`, non-empty [TypeName] node list from the resp
ective |
| 12681 * [MapLiteral] |
11882 * @return `true` if and only if an error code is generated on the passed node | 12682 * @return `true` if and only if an error code is generated on the passed node |
11883 * @see CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_FOR_KEY | 12683 * @see CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_FOR_KEY |
11884 */ | 12684 */ |
11885 bool checkForInvalidTypeArgumentForKey(NodeList<TypeName> arguments) { | 12685 bool checkForInvalidTypeArgumentForKey(NodeList<TypeName> arguments) { |
11886 TypeName firstArgument = arguments[0]; | 12686 TypeName firstArgument = arguments[0]; |
11887 Type2 firstArgumentType = firstArgument.type; | 12687 Type2 firstArgumentType = firstArgument.type; |
11888 if (firstArgumentType != null && firstArgumentType != _typeProvider.stringTy
pe) { | 12688 if (firstArgumentType != null && firstArgumentType != _typeProvider.stringTy
pe) { |
11889 _errorReporter.reportError2(CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_FOR
_KEY, firstArgument, []); | 12689 _errorReporter.reportError2(CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_FOR
_KEY, firstArgument, []); |
11890 return true; | 12690 return true; |
11891 } | 12691 } |
11892 return false; | 12692 return false; |
11893 } | 12693 } |
11894 | 12694 |
11895 /** | 12695 /** |
11896 * Checks to ensure that the passed [ListLiteral] or [MapLiteral] does not hav
e a type | 12696 * Checks to ensure that the passed [ListLiteral] or [MapLiteral] does not hav
e a type |
11897 * parameter as a type argument. | 12697 * parameter as a type argument. |
11898 * @param arguments a non-`null`, non-empty [TypeName] node list from the resp
ective[ListLiteral] or [MapLiteral] | 12698 * |
11899 * @param errorCode either [CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_IN_CONS
T_LIST] or[CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_IN_CONST_MAP] | 12699 * @param arguments a non-`null`, non-empty [TypeName] node list from the resp
ective |
| 12700 * [ListLiteral] or [MapLiteral] |
| 12701 * @param errorCode either [CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_IN_CONS
T_LIST] or |
| 12702 * [CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_IN_CONST_MAP] |
11900 * @return `true` if and only if an error code is generated on the passed node | 12703 * @return `true` if and only if an error code is generated on the passed node |
11901 */ | 12704 */ |
11902 bool checkForInvalidTypeArgumentInConstTypedLiteral(NodeList<TypeName> argumen
ts, ErrorCode errorCode) { | 12705 bool checkForInvalidTypeArgumentInConstTypedLiteral(NodeList<TypeName> argumen
ts, ErrorCode errorCode) { |
11903 bool foundError = false; | 12706 bool foundError = false; |
11904 for (TypeName typeName in arguments) { | 12707 for (TypeName typeName in arguments) { |
11905 if (typeName.type is TypeVariableType) { | 12708 if (typeName.type is TypeVariableType) { |
11906 _errorReporter.reportError2(errorCode, typeName, [typeName.name]); | 12709 _errorReporter.reportError2(errorCode, typeName, [typeName.name]); |
11907 foundError = true; | 12710 foundError = true; |
11908 } | 12711 } |
11909 } | 12712 } |
11910 return foundError; | 12713 return foundError; |
11911 } | 12714 } |
11912 | 12715 |
11913 /** | 12716 /** |
11914 * This verifies that the [enclosingClass] does not define members with the sa
me name as | 12717 * This verifies that the [enclosingClass] does not define members with the sa
me name as |
11915 * the enclosing class. | 12718 * the enclosing class. |
| 12719 * |
11916 * @return `true` if and only if an error code is generated on the passed node | 12720 * @return `true` if and only if an error code is generated on the passed node |
11917 * @see CompileTimeErrorCode#MEMBER_WITH_CLASS_NAME | 12721 * @see CompileTimeErrorCode#MEMBER_WITH_CLASS_NAME |
11918 */ | 12722 */ |
11919 bool checkForMemberWithClassName() { | 12723 bool checkForMemberWithClassName() { |
11920 if (_enclosingClass == null) { | 12724 if (_enclosingClass == null) { |
11921 return false; | 12725 return false; |
11922 } | 12726 } |
11923 String className = _enclosingClass.name; | 12727 String className = _enclosingClass.name; |
11924 if (className == null) { | 12728 if (className == null) { |
11925 return false; | 12729 return false; |
11926 } | 12730 } |
11927 bool problemReported = false; | 12731 bool problemReported = false; |
11928 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { | 12732 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { |
11929 if (className == accessor.name) { | 12733 if (className == accessor.name) { |
11930 _errorReporter.reportError3(CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME,
accessor.nameOffset, className.length, []); | 12734 _errorReporter.reportError3(CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME,
accessor.nameOffset, className.length, []); |
11931 problemReported = true; | 12735 problemReported = true; |
11932 } | 12736 } |
11933 } | 12737 } |
11934 return problemReported; | 12738 return problemReported; |
11935 } | 12739 } |
11936 | 12740 |
11937 /** | 12741 /** |
11938 * Check to make sure that all similarly typed accessors are of the same type
(including inherited | 12742 * Check to make sure that all similarly typed accessors are of the same type
(including inherited |
11939 * accessors). | 12743 * accessors). |
| 12744 * |
11940 * @param node The accessor currently being visited. | 12745 * @param node The accessor currently being visited. |
11941 */ | 12746 */ |
11942 void checkForMismatchedAccessorTypes(Declaration accessorDeclaration, String a
ccessorTextName) { | 12747 void checkForMismatchedAccessorTypes(Declaration accessorDeclaration, String a
ccessorTextName) { |
11943 PropertyAccessorElement counterpartAccessor = null; | 12748 PropertyAccessorElement counterpartAccessor = null; |
11944 ExecutableElement accessorElement = accessorDeclaration.element as Executabl
eElement; | 12749 ExecutableElement accessorElement = accessorDeclaration.element as Executabl
eElement; |
11945 if (accessorElement is! PropertyAccessorElement) { | 12750 if (accessorElement is! PropertyAccessorElement) { |
11946 return; | 12751 return; |
11947 } | 12752 } |
11948 PropertyAccessorElement propertyAccessorElement = accessorElement as Propert
yAccessorElement; | 12753 PropertyAccessorElement propertyAccessorElement = accessorElement as Propert
yAccessorElement; |
11949 counterpartAccessor = propertyAccessorElement.correspondingSetter; | 12754 counterpartAccessor = propertyAccessorElement.correspondingSetter; |
(...skipping 10 matching lines...) Expand all Loading... |
11960 counterpartAccessor = propertyAccessorElement.correspondingGetter; | 12765 counterpartAccessor = propertyAccessorElement.correspondingGetter; |
11961 getterType = getGetterType(counterpartAccessor); | 12766 getterType = getGetterType(counterpartAccessor); |
11962 } | 12767 } |
11963 if (setterType != null && getterType != null && !getterType.isAssignableTo(s
etterType)) { | 12768 if (setterType != null && getterType != null && !getterType.isAssignableTo(s
etterType)) { |
11964 _errorReporter.reportError2(StaticWarningCode.MISMATCHED_GETTER_AND_SETTER
_TYPES, accessorDeclaration, [accessorTextName, setterType.displayName, getterTy
pe.displayName]); | 12769 _errorReporter.reportError2(StaticWarningCode.MISMATCHED_GETTER_AND_SETTER
_TYPES, accessorDeclaration, [accessorTextName, setterType.displayName, getterTy
pe.displayName]); |
11965 } | 12770 } |
11966 } | 12771 } |
11967 | 12772 |
11968 /** | 12773 /** |
11969 * This verifies that the passed mixin does not have an explicitly declared co
nstructor. | 12774 * This verifies that the passed mixin does not have an explicitly declared co
nstructor. |
| 12775 * |
11970 * @param mixinName the node to report problem on | 12776 * @param mixinName the node to report problem on |
11971 * @param mixinElement the mixing to evaluate | 12777 * @param mixinElement the mixing to evaluate |
11972 * @return `true` if and only if an error code is generated on the passed node | 12778 * @return `true` if and only if an error code is generated on the passed node |
11973 * @see CompileTimeErrorCode#MIXIN_DECLARES_CONSTRUCTOR | 12779 * @see CompileTimeErrorCode#MIXIN_DECLARES_CONSTRUCTOR |
11974 */ | 12780 */ |
11975 bool checkForMixinDeclaresConstructor(TypeName mixinName, ClassElement mixinEl
ement) { | 12781 bool checkForMixinDeclaresConstructor(TypeName mixinName, ClassElement mixinEl
ement) { |
11976 for (ConstructorElement constructor in mixinElement.constructors) { | 12782 for (ConstructorElement constructor in mixinElement.constructors) { |
11977 if (!constructor.isSynthetic && !constructor.isFactory) { | 12783 if (!constructor.isSynthetic && !constructor.isFactory) { |
11978 _errorReporter.reportError2(CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUC
TOR, mixinName, [mixinElement.name]); | 12784 _errorReporter.reportError2(CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUC
TOR, mixinName, [mixinElement.name]); |
11979 return true; | 12785 return true; |
11980 } | 12786 } |
11981 } | 12787 } |
11982 return false; | 12788 return false; |
11983 } | 12789 } |
11984 | 12790 |
11985 /** | 12791 /** |
11986 * This verifies that the passed mixin has the 'Object' superclass. | 12792 * This verifies that the passed mixin has the 'Object' superclass. |
| 12793 * |
11987 * @param mixinName the node to report problem on | 12794 * @param mixinName the node to report problem on |
11988 * @param mixinElement the mixing to evaluate | 12795 * @param mixinElement the mixing to evaluate |
11989 * @return `true` if and only if an error code is generated on the passed node | 12796 * @return `true` if and only if an error code is generated on the passed node |
11990 * @see CompileTimeErrorCode#MIXIN_INHERITS_FROM_NOT_OBJECT | 12797 * @see CompileTimeErrorCode#MIXIN_INHERITS_FROM_NOT_OBJECT |
11991 */ | 12798 */ |
11992 bool checkForMixinInheritsNotFromObject(TypeName mixinName, ClassElement mixin
Element) { | 12799 bool checkForMixinInheritsNotFromObject(TypeName mixinName, ClassElement mixin
Element) { |
11993 InterfaceType mixinSupertype = mixinElement.supertype; | 12800 InterfaceType mixinSupertype = mixinElement.supertype; |
11994 if (mixinSupertype != null) { | 12801 if (mixinSupertype != null) { |
11995 if (!mixinSupertype.isObject || !mixinElement.isTypedef && mixinElement.mi
xins.length != 0) { | 12802 if (!mixinSupertype.isObject || !mixinElement.isTypedef && mixinElement.mi
xins.length != 0) { |
11996 _errorReporter.reportError2(CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT
_OBJECT, mixinName, [mixinElement.name]); | 12803 _errorReporter.reportError2(CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT
_OBJECT, mixinName, [mixinElement.name]); |
11997 return true; | 12804 return true; |
11998 } | 12805 } |
11999 } | 12806 } |
12000 return false; | 12807 return false; |
12001 } | 12808 } |
12002 | 12809 |
12003 /** | 12810 /** |
12004 * This verifies that the passed mixin does not reference 'super'. | 12811 * This verifies that the passed mixin does not reference 'super'. |
| 12812 * |
12005 * @param mixinName the node to report problem on | 12813 * @param mixinName the node to report problem on |
12006 * @param mixinElement the mixing to evaluate | 12814 * @param mixinElement the mixing to evaluate |
12007 * @return `true` if and only if an error code is generated on the passed node | 12815 * @return `true` if and only if an error code is generated on the passed node |
12008 * @see CompileTimeErrorCode#MIXIN_REFERENCES_SUPER | 12816 * @see CompileTimeErrorCode#MIXIN_REFERENCES_SUPER |
12009 */ | 12817 */ |
12010 bool checkForMixinReferencesSuper(TypeName mixinName, ClassElement mixinElemen
t) { | 12818 bool checkForMixinReferencesSuper(TypeName mixinName, ClassElement mixinElemen
t) { |
12011 if (mixinElement.hasReferenceToSuper()) { | 12819 if (mixinElement.hasReferenceToSuper()) { |
12012 _errorReporter.reportError2(CompileTimeErrorCode.MIXIN_REFERENCES_SUPER, m
ixinName, [mixinElement.name]); | 12820 _errorReporter.reportError2(CompileTimeErrorCode.MIXIN_REFERENCES_SUPER, m
ixinName, [mixinElement.name]); |
12013 } | 12821 } |
12014 return false; | 12822 return false; |
12015 } | 12823 } |
12016 | 12824 |
12017 /** | 12825 /** |
12018 * This verifies that the passed constructor has at most one 'super' initializ
er. | 12826 * This verifies that the passed constructor has at most one 'super' initializ
er. |
| 12827 * |
12019 * @param node the constructor declaration to evaluate | 12828 * @param node the constructor declaration to evaluate |
12020 * @return `true` if and only if an error code is generated on the passed node | 12829 * @return `true` if and only if an error code is generated on the passed node |
12021 * @see CompileTimeErrorCode#MULTIPLE_SUPER_INITIALIZERS | 12830 * @see CompileTimeErrorCode#MULTIPLE_SUPER_INITIALIZERS |
12022 */ | 12831 */ |
12023 bool checkForMultipleSuperInitializers(ConstructorDeclaration node) { | 12832 bool checkForMultipleSuperInitializers(ConstructorDeclaration node) { |
12024 int numSuperInitializers = 0; | 12833 int numSuperInitializers = 0; |
12025 for (ConstructorInitializer initializer in node.initializers) { | 12834 for (ConstructorInitializer initializer in node.initializers) { |
12026 if (initializer is SuperConstructorInvocation) { | 12835 if (initializer is SuperConstructorInvocation) { |
12027 numSuperInitializers++; | 12836 numSuperInitializers++; |
12028 if (numSuperInitializers > 1) { | 12837 if (numSuperInitializers > 1) { |
12029 _errorReporter.reportError2(CompileTimeErrorCode.MULTIPLE_SUPER_INITIA
LIZERS, initializer, []); | 12838 _errorReporter.reportError2(CompileTimeErrorCode.MULTIPLE_SUPER_INITIA
LIZERS, initializer, []); |
12030 } | 12839 } |
12031 } | 12840 } |
12032 } | 12841 } |
12033 return numSuperInitializers > 0; | 12842 return numSuperInitializers > 0; |
12034 } | 12843 } |
12035 | 12844 |
12036 /** | 12845 /** |
12037 * Checks to ensure that native function bodies can only in SDK code. | 12846 * Checks to ensure that native function bodies can only in SDK code. |
| 12847 * |
12038 * @param node the native function body to test | 12848 * @param node the native function body to test |
12039 * @return `true` if and only if an error code is generated on the passed node | 12849 * @return `true` if and only if an error code is generated on the passed node |
12040 * @see ParserErrorCode#NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE | 12850 * @see ParserErrorCode#NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE |
12041 */ | 12851 */ |
12042 bool checkForNativeFunctionBodyInNonSDKCode(NativeFunctionBody node) { | 12852 bool checkForNativeFunctionBodyInNonSDKCode(NativeFunctionBody node) { |
12043 if (!_isInSystemLibrary) { | 12853 if (!_isInSystemLibrary) { |
12044 _errorReporter.reportError2(ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SD
K_CODE, node, []); | 12854 _errorReporter.reportError2(ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SD
K_CODE, node, []); |
12045 return true; | 12855 return true; |
12046 } | 12856 } |
12047 return false; | 12857 return false; |
12048 } | 12858 } |
12049 | 12859 |
12050 /** | 12860 /** |
12051 * This verifies that the passed 'new' instance creation expression invokes ex
isting constructor. | 12861 * This verifies that the passed 'new' instance creation expression invokes ex
isting constructor. |
12052 * | 12862 * |
12053 * This method assumes that the instance creation was tested to be 'new' befor
e being called. | 12863 * This method assumes that the instance creation was tested to be 'new' befor
e being called. |
| 12864 * |
12054 * @param node the instance creation expression to evaluate | 12865 * @param node the instance creation expression to evaluate |
12055 * @return `true` if and only if an error code is generated on the passed node | 12866 * @return `true` if and only if an error code is generated on the passed node |
12056 * @see StaticWarningCode#NEW_WITH_UNDEFINED_CONSTRUCTOR | 12867 * @see StaticWarningCode#NEW_WITH_UNDEFINED_CONSTRUCTOR |
12057 */ | 12868 */ |
12058 bool checkForNewWithUndefinedConstructor(InstanceCreationExpression node) { | 12869 bool checkForNewWithUndefinedConstructor(InstanceCreationExpression node) { |
12059 if (node.element != null) { | 12870 if (node.element != null) { |
12060 return false; | 12871 return false; |
12061 } | 12872 } |
12062 ConstructorName constructorName = node.constructorName; | 12873 ConstructorName constructorName = node.constructorName; |
12063 if (constructorName == null) { | 12874 if (constructorName == null) { |
12064 return false; | 12875 return false; |
12065 } | 12876 } |
12066 TypeName type = constructorName.type; | 12877 TypeName type = constructorName.type; |
12067 if (type == null) { | 12878 if (type == null) { |
12068 return false; | 12879 return false; |
12069 } | 12880 } |
12070 Identifier className = type.name; | 12881 Identifier className = type.name; |
12071 SimpleIdentifier name = constructorName.name; | 12882 SimpleIdentifier name = constructorName.name; |
12072 if (name != null) { | 12883 if (name != null) { |
12073 _errorReporter.reportError2(StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCT
OR, name, [className, name]); | 12884 _errorReporter.reportError2(StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCT
OR, name, [className, name]); |
12074 } else { | 12885 } else { |
12075 _errorReporter.reportError2(StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCT
OR_DEFAULT, constructorName, [className]); | 12886 _errorReporter.reportError2(StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCT
OR_DEFAULT, constructorName, [className]); |
12076 } | 12887 } |
12077 return true; | 12888 return true; |
12078 } | 12889 } |
12079 | 12890 |
12080 /** | 12891 /** |
12081 * This checks that passed if the passed class declaration implicitly calls de
fault constructor of | 12892 * This checks that if the passed class declaration implicitly calls default c
onstructor of its |
12082 * its superclass, there should be such default constructor - implicit or expl
icit. | 12893 * superclass, there should be such default constructor - implicit or explicit
. |
| 12894 * |
12083 * @param node the [ClassDeclaration] to evaluate | 12895 * @param node the [ClassDeclaration] to evaluate |
12084 * @return `true` if and only if an error code is generated on the passed node | 12896 * @return `true` if and only if an error code is generated on the passed node |
12085 * @see StaticWarningCode#NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT | 12897 * @see CompileTimeErrorCode#NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT |
12086 */ | 12898 */ |
12087 bool checkForNoDefaultSuperConstructorImplicit(ClassDeclaration node) { | 12899 bool checkForNoDefaultSuperConstructorImplicit(ClassDeclaration node) { |
12088 List<ConstructorElement> constructors = _enclosingClass.constructors; | 12900 List<ConstructorElement> constructors = _enclosingClass.constructors; |
12089 if (!constructors[0].isSynthetic) { | 12901 if (!constructors[0].isSynthetic) { |
12090 return false; | 12902 return false; |
12091 } | 12903 } |
12092 InterfaceType superType = _enclosingClass.supertype; | 12904 InterfaceType superType = _enclosingClass.supertype; |
12093 if (superType == null) { | 12905 if (superType == null) { |
12094 return false; | 12906 return false; |
12095 } | 12907 } |
12096 ClassElement superClass = superType.element; | 12908 ClassElement superElement = superType.element; |
12097 if (superClass.hasDefaultConstructor()) { | 12909 ConstructorElement superUnnamedConstructor = superElement.unnamedConstructor
; |
12098 return false; | 12910 if (superUnnamedConstructor != null) { |
| 12911 if (superUnnamedConstructor.isFactory) { |
| 12912 _errorReporter.reportError2(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUC
TOR, node.name, [superUnnamedConstructor]); |
| 12913 return true; |
| 12914 } |
| 12915 if (superUnnamedConstructor.isDefaultConstructor) { |
| 12916 return true; |
| 12917 } |
12099 } | 12918 } |
12100 _errorReporter.reportError2(StaticWarningCode.NO_DEFAULT_SUPER_CONSTRUCTOR_I
MPLICIT, node.name, [superType.displayName]); | 12919 _errorReporter.reportError2(CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTO
R_IMPLICIT, node.name, [superType.displayName]); |
12101 return true; | 12920 return true; |
12102 } | 12921 } |
12103 | 12922 |
12104 /** | 12923 /** |
12105 * This checks that passed class declaration overrides all members required by
its superclasses | 12924 * This checks that passed class declaration overrides all members required by
its superclasses |
12106 * and interfaces. | 12925 * and interfaces. |
| 12926 * |
12107 * @param node the [ClassDeclaration] to evaluate | 12927 * @param node the [ClassDeclaration] to evaluate |
12108 * @return `true` if and only if an error code is generated on the passed node | 12928 * @return `true` if and only if an error code is generated on the passed node |
12109 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE | 12929 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE |
12110 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO | 12930 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO |
12111 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE | 12931 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE |
12112 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR | 12932 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR |
12113 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLU
S | 12933 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLU
S |
12114 */ | 12934 */ |
12115 bool checkForNonAbstractClassInheritsAbstractMember(ClassDeclaration node) { | 12935 bool checkForNonAbstractClassInheritsAbstractMember(ClassDeclaration node) { |
12116 if (_enclosingClass.isAbstract) { | 12936 if (_enclosingClass.isAbstract) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12169 if (!accessorsInEnclosingClass.contains(accessorName)) { | 12989 if (!accessorsInEnclosingClass.contains(accessorName)) { |
12170 javaSetAdd(missingOverrides, executableElt); | 12990 javaSetAdd(missingOverrides, executableElt); |
12171 } | 12991 } |
12172 } | 12992 } |
12173 } | 12993 } |
12174 int missingOverridesSize = missingOverrides.length; | 12994 int missingOverridesSize = missingOverrides.length; |
12175 if (missingOverridesSize == 0) { | 12995 if (missingOverridesSize == 0) { |
12176 return false; | 12996 return false; |
12177 } | 12997 } |
12178 List<ExecutableElement> missingOverridesArray = new List.from(missingOverrid
es); | 12998 List<ExecutableElement> missingOverridesArray = new List.from(missingOverrid
es); |
12179 List<String> stringTypeArray = new List<String>(Math.min(missingOverridesSiz
e, 4)); | 12999 List<String> stringMembersArrayListSet = new List<String>(); |
12180 String GET = "get "; | 13000 for (int i = 0; i < missingOverridesArray.length; i++) { |
12181 String SET = "set "; | 13001 String newStrMember = "${missingOverridesArray[i].enclosingElement.display
Name}.${missingOverridesArray[i].displayName}"; |
12182 for (int i = 0; i < stringTypeArray.length; i++) { | 13002 if (!stringMembersArrayListSet.contains(newStrMember)) { |
12183 stringTypeArray[i] = StringUtilities.EMPTY; | 13003 stringMembersArrayListSet.add(newStrMember); |
12184 if (missingOverridesArray[i] is PropertyAccessorElement) { | |
12185 stringTypeArray[i] = ((missingOverridesArray[i] as PropertyAccessorEleme
nt)).isGetter ? GET : SET; | |
12186 } | 13004 } |
12187 } | 13005 } |
| 13006 List<String> stringMembersArray = new List.from(stringMembersArrayListSet); |
12188 AnalysisErrorWithProperties analysisError; | 13007 AnalysisErrorWithProperties analysisError; |
12189 if (missingOverridesSize == 1) { | 13008 if (stringMembersArray.length == 1) { |
12190 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO
N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE, node.name, [stringTypeArray[0], m
issingOverridesArray[0].enclosingElement.displayName, missingOverridesArray[0].d
isplayName]); | 13009 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO
N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE, node.name, [stringMembersArray[0]
]); |
12191 } else if (missingOverridesSize == 2) { | 13010 } else if (stringMembersArray.length == 2) { |
12192 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO
N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO, node.name, [stringTypeArray[0], m
issingOverridesArray[0].enclosingElement.displayName, missingOverridesArray[0].d
isplayName, stringTypeArray[1], missingOverridesArray[1].enclosingElement.displa
yName, missingOverridesArray[1].displayName]); | 13011 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO
N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO, node.name, [stringMembersArray[0]
, stringMembersArray[1]]); |
12193 } else if (missingOverridesSize == 3) { | 13012 } else if (stringMembersArray.length == 3) { |
12194 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO
N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE, node.name, [stringTypeArray[0],
missingOverridesArray[0].enclosingElement.displayName, missingOverridesArray[0]
.displayName, stringTypeArray[1], missingOverridesArray[1].enclosingElement.disp
layName, missingOverridesArray[1].displayName, stringTypeArray[2], missingOverri
desArray[2].enclosingElement.displayName, missingOverridesArray[2].displayName])
; | 13013 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO
N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE, node.name, [stringMembersArray[
0], stringMembersArray[1], stringMembersArray[2]]); |
12195 } else if (missingOverridesSize == 4) { | 13014 } else if (stringMembersArray.length == 4) { |
12196 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO
N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR, node.name, [stringTypeArray[0],
missingOverridesArray[0].enclosingElement.displayName, missingOverridesArray[0].
displayName, stringTypeArray[1], missingOverridesArray[1].enclosingElement.displ
ayName, missingOverridesArray[1].displayName, stringTypeArray[2], missingOverrid
esArray[2].enclosingElement.displayName, missingOverridesArray[2].displayName, s
tringTypeArray[3], missingOverridesArray[3].enclosingElement.displayName, missin
gOverridesArray[3].displayName]); | 13015 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO
N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR, node.name, [stringMembersArray[0
], stringMembersArray[1], stringMembersArray[2], stringMembersArray[3]]); |
12197 } else { | 13016 } else { |
12198 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO
N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLUS, node.name, [stringTypeArray
[0], missingOverridesArray[0].enclosingElement.displayName, missingOverridesArra
y[0].displayName, stringTypeArray[1], missingOverridesArray[1].enclosingElement.
displayName, missingOverridesArray[1].displayName, stringTypeArray[2], missingOv
erridesArray[2].enclosingElement.displayName, missingOverridesArray[2].displayNa
me, stringTypeArray[3], missingOverridesArray[3].enclosingElement.displayName, m
issingOverridesArray[3].displayName, missingOverridesArray.length - 4]); | 13017 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO
N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLUS, node.name, [stringMembersAr
ray[0], stringMembersArray[1], stringMembersArray[2], stringMembersArray[3], str
ingMembersArray.length - 4]); |
12199 } | 13018 } |
12200 analysisError.setProperty(ErrorProperty.UNIMPLEMENTED_METHODS, missingOverri
desArray); | 13019 analysisError.setProperty(ErrorProperty.UNIMPLEMENTED_METHODS, missingOverri
desArray); |
12201 _errorReporter.reportError(analysisError); | 13020 _errorReporter.reportError(analysisError); |
12202 return true; | 13021 return true; |
12203 } | 13022 } |
12204 | 13023 |
12205 /** | 13024 /** |
12206 * Checks to ensure that the expressions that need to be of type bool, are. Ot
herwise an error is | 13025 * Checks to ensure that the expressions that need to be of type bool, are. Ot
herwise an error is |
12207 * reported on the expression. | 13026 * reported on the expression. |
| 13027 * |
12208 * @param condition the conditional expression to test | 13028 * @param condition the conditional expression to test |
12209 * @return `true` if and only if an error code is generated on the passed node | 13029 * @return `true` if and only if an error code is generated on the passed node |
12210 * @see StaticTypeWarningCode#NON_BOOL_CONDITION | 13030 * @see StaticTypeWarningCode#NON_BOOL_CONDITION |
12211 */ | 13031 */ |
12212 bool checkForNonBoolCondition(Expression condition) { | 13032 bool checkForNonBoolCondition(Expression condition) { |
12213 Type2 conditionType = getStaticType(condition); | 13033 Type2 conditionType = getStaticType(condition); |
12214 if (conditionType != null && !conditionType.isAssignableTo(_typeProvider.boo
lType)) { | 13034 if (conditionType != null && !conditionType.isAssignableTo(_typeProvider.boo
lType)) { |
12215 _errorReporter.reportError2(StaticTypeWarningCode.NON_BOOL_CONDITION, cond
ition, []); | 13035 _errorReporter.reportError2(StaticTypeWarningCode.NON_BOOL_CONDITION, cond
ition, []); |
12216 return true; | 13036 return true; |
12217 } | 13037 } |
12218 return false; | 13038 return false; |
12219 } | 13039 } |
12220 | 13040 |
12221 /** | 13041 /** |
12222 * This verifies that the passed assert statement has either a 'bool' or '() -
> bool' input. | 13042 * This verifies that the passed assert statement has either a 'bool' or '() -
> bool' input. |
| 13043 * |
12223 * @param node the assert statement to evaluate | 13044 * @param node the assert statement to evaluate |
12224 * @return `true` if and only if an error code is generated on the passed node | 13045 * @return `true` if and only if an error code is generated on the passed node |
12225 * @see StaticTypeWarningCode#NON_BOOL_EXPRESSION | 13046 * @see StaticTypeWarningCode#NON_BOOL_EXPRESSION |
12226 */ | 13047 */ |
12227 bool checkForNonBoolExpression(AssertStatement node) { | 13048 bool checkForNonBoolExpression(AssertStatement node) { |
12228 Expression expression = node.condition; | 13049 Expression expression = node.condition; |
12229 Type2 type = getStaticType(expression); | 13050 Type2 type = getStaticType(expression); |
12230 if (type is InterfaceType) { | 13051 if (type is InterfaceType) { |
12231 if (!type.isAssignableTo(_typeProvider.boolType)) { | 13052 if (!type.isAssignableTo(_typeProvider.boolType)) { |
12232 _errorReporter.reportError2(StaticTypeWarningCode.NON_BOOL_EXPRESSION, e
xpression, []); | 13053 _errorReporter.reportError2(StaticTypeWarningCode.NON_BOOL_EXPRESSION, e
xpression, []); |
12233 return true; | 13054 return true; |
12234 } | 13055 } |
12235 } else if (type is FunctionType) { | 13056 } else if (type is FunctionType) { |
12236 FunctionType functionType = type as FunctionType; | 13057 FunctionType functionType = type as FunctionType; |
12237 if (functionType.typeArguments.length == 0 && !functionType.returnType.isA
ssignableTo(_typeProvider.boolType)) { | 13058 if (functionType.typeArguments.length == 0 && !functionType.returnType.isA
ssignableTo(_typeProvider.boolType)) { |
12238 _errorReporter.reportError2(StaticTypeWarningCode.NON_BOOL_EXPRESSION, e
xpression, []); | 13059 _errorReporter.reportError2(StaticTypeWarningCode.NON_BOOL_EXPRESSION, e
xpression, []); |
12239 return true; | 13060 return true; |
12240 } | 13061 } |
12241 } | 13062 } |
12242 return false; | 13063 return false; |
12243 } | 13064 } |
12244 | 13065 |
12245 /** | 13066 /** |
12246 * This verifies the passed map literal either: | 13067 * This verifies the passed map literal either: |
12247 * | 13068 * |
12248 * * has `const modifier` | 13069 * * has `const modifier` |
12249 * * has explicit type arguments | 13070 * * has explicit type arguments |
12250 * * is not start of the statement | 13071 * * is not start of the statement |
12251 * | 13072 * |
| 13073 * |
12252 * @param node the map literal to evaluate | 13074 * @param node the map literal to evaluate |
12253 * @return `true` if and only if an error code is generated on the passed node | 13075 * @return `true` if and only if an error code is generated on the passed node |
12254 * @see CompileTimeErrorCode#NON_CONST_MAP_AS_EXPRESSION_STATEMENT | 13076 * @see CompileTimeErrorCode#NON_CONST_MAP_AS_EXPRESSION_STATEMENT |
12255 */ | 13077 */ |
12256 bool checkForNonConstMapAsExpressionStatement(MapLiteral node) { | 13078 bool checkForNonConstMapAsExpressionStatement(MapLiteral node) { |
12257 if (node.modifier != null) { | 13079 if (node.modifier != null) { |
12258 return false; | 13080 return false; |
12259 } | 13081 } |
12260 if (node.typeArguments != null) { | 13082 if (node.typeArguments != null) { |
12261 return false; | 13083 return false; |
12262 } | 13084 } |
12263 Statement statement = node.getAncestor(ExpressionStatement); | 13085 Statement statement = node.getAncestor(ExpressionStatement); |
12264 if (statement == null) { | 13086 if (statement == null) { |
12265 return false; | 13087 return false; |
12266 } | 13088 } |
12267 if (statement.beginToken != node.beginToken) { | 13089 if (statement.beginToken != node.beginToken) { |
12268 return false; | 13090 return false; |
12269 } | 13091 } |
12270 _errorReporter.reportError2(CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION
_STATEMENT, node, []); | 13092 _errorReporter.reportError2(CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION
_STATEMENT, node, []); |
12271 return true; | 13093 return true; |
12272 } | 13094 } |
12273 | 13095 |
12274 /** | 13096 /** |
12275 * This verifies the passed method declaration of operator `\[\]=`, has `void`
return | 13097 * This verifies the passed method declaration of operator `[]=`, has `void` r
eturn |
12276 * type. | 13098 * type. |
| 13099 * |
12277 * @param node the method declaration to evaluate | 13100 * @param node the method declaration to evaluate |
12278 * @return `true` if and only if an error code is generated on the passed node | 13101 * @return `true` if and only if an error code is generated on the passed node |
12279 * @see StaticWarningCode#NON_VOID_RETURN_FOR_OPERATOR | 13102 * @see StaticWarningCode#NON_VOID_RETURN_FOR_OPERATOR |
12280 */ | 13103 */ |
12281 bool checkForNonVoidReturnTypeForOperator(MethodDeclaration node) { | 13104 bool checkForNonVoidReturnTypeForOperator(MethodDeclaration node) { |
12282 SimpleIdentifier name = node.name; | 13105 SimpleIdentifier name = node.name; |
12283 if (name.name != "[]=") { | 13106 if (name.name != "[]=") { |
12284 return false; | 13107 return false; |
12285 } | 13108 } |
12286 TypeName typeName = node.returnType; | 13109 TypeName typeName = node.returnType; |
12287 if (typeName != null) { | 13110 if (typeName != null) { |
12288 Type2 type = typeName.type; | 13111 Type2 type = typeName.type; |
12289 if (type != null && !type.isVoid) { | 13112 if (type != null && !type.isVoid) { |
12290 _errorReporter.reportError2(StaticWarningCode.NON_VOID_RETURN_FOR_OPERAT
OR, typeName, []); | 13113 _errorReporter.reportError2(StaticWarningCode.NON_VOID_RETURN_FOR_OPERAT
OR, typeName, []); |
12291 } | 13114 } |
12292 } | 13115 } |
12293 return false; | 13116 return false; |
12294 } | 13117 } |
12295 | 13118 |
12296 /** | 13119 /** |
12297 * This verifies the passed setter has no return type or the `void` return typ
e. | 13120 * This verifies the passed setter has no return type or the `void` return typ
e. |
| 13121 * |
12298 * @param typeName the type name to evaluate | 13122 * @param typeName the type name to evaluate |
12299 * @return `true` if and only if an error code is generated on the passed node | 13123 * @return `true` if and only if an error code is generated on the passed node |
12300 * @see StaticWarningCode#NON_VOID_RETURN_FOR_SETTER | 13124 * @see StaticWarningCode#NON_VOID_RETURN_FOR_SETTER |
12301 */ | 13125 */ |
12302 bool checkForNonVoidReturnTypeForSetter(TypeName typeName) { | 13126 bool checkForNonVoidReturnTypeForSetter(TypeName typeName) { |
12303 if (typeName != null) { | 13127 if (typeName != null) { |
12304 Type2 type = typeName.type; | 13128 Type2 type = typeName.type; |
12305 if (type != null && !type.isVoid) { | 13129 if (type != null && !type.isVoid) { |
12306 _errorReporter.reportError2(StaticWarningCode.NON_VOID_RETURN_FOR_SETTER
, typeName, []); | 13130 _errorReporter.reportError2(StaticWarningCode.NON_VOID_RETURN_FOR_SETTER
, typeName, []); |
12307 } | 13131 } |
12308 } | 13132 } |
12309 return false; | 13133 return false; |
12310 } | 13134 } |
12311 | 13135 |
12312 /** | 13136 /** |
12313 * This verifies the passed operator-method declaration, does not have an opti
onal parameter. | 13137 * This verifies the passed operator-method declaration, does not have an opti
onal parameter. |
12314 * | 13138 * |
12315 * This method assumes that the method declaration was tested to be an operato
r declaration before | 13139 * This method assumes that the method declaration was tested to be an operato
r declaration before |
12316 * being called. | 13140 * being called. |
| 13141 * |
12317 * @param node the method declaration to evaluate | 13142 * @param node the method declaration to evaluate |
12318 * @return `true` if and only if an error code is generated on the passed node | 13143 * @return `true` if and only if an error code is generated on the passed node |
12319 * @see CompileTimeErrorCode#OPTIONAL_PARAMETER_IN_OPERATOR | 13144 * @see CompileTimeErrorCode#OPTIONAL_PARAMETER_IN_OPERATOR |
12320 */ | 13145 */ |
12321 bool checkForOptionalParameterInOperator(MethodDeclaration node) { | 13146 bool checkForOptionalParameterInOperator(MethodDeclaration node) { |
12322 FormalParameterList parameterList = node.parameters; | 13147 FormalParameterList parameterList = node.parameters; |
12323 if (parameterList == null) { | 13148 if (parameterList == null) { |
12324 return false; | 13149 return false; |
12325 } | 13150 } |
12326 bool foundError = false; | 13151 bool foundError = false; |
12327 NodeList<FormalParameter> formalParameters = parameterList.parameters; | 13152 NodeList<FormalParameter> formalParameters = parameterList.parameters; |
12328 for (FormalParameter formalParameter in formalParameters) { | 13153 for (FormalParameter formalParameter in formalParameters) { |
12329 if (formalParameter.kind.isOptional) { | 13154 if (formalParameter.kind.isOptional) { |
12330 _errorReporter.reportError2(CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_O
PERATOR, formalParameter, []); | 13155 _errorReporter.reportError2(CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_O
PERATOR, formalParameter, []); |
12331 foundError = true; | 13156 foundError = true; |
12332 } | 13157 } |
12333 } | 13158 } |
12334 return foundError; | 13159 return foundError; |
12335 } | 13160 } |
12336 | 13161 |
12337 /** | 13162 /** |
12338 * This checks for named optional parameters that begin with '_'. | 13163 * This checks for named optional parameters that begin with '_'. |
| 13164 * |
12339 * @param node the default formal parameter to evaluate | 13165 * @param node the default formal parameter to evaluate |
12340 * @return `true` if and only if an error code is generated on the passed node | 13166 * @return `true` if and only if an error code is generated on the passed node |
12341 * @see CompileTimeErrorCode#PRIVATE_OPTIONAL_PARAMETER | 13167 * @see CompileTimeErrorCode#PRIVATE_OPTIONAL_PARAMETER |
12342 */ | 13168 */ |
12343 bool checkForPrivateOptionalParameter(DefaultFormalParameter node) { | 13169 bool checkForPrivateOptionalParameter(DefaultFormalParameter node) { |
12344 sc.Token separator = node.separator; | 13170 sc.Token separator = node.separator; |
12345 if (separator != null && separator.lexeme == ":") { | 13171 if (separator != null && separator.lexeme == ":") { |
12346 NormalFormalParameter parameter = node.parameter; | 13172 NormalFormalParameter parameter = node.parameter; |
12347 SimpleIdentifier name = parameter.identifier; | 13173 SimpleIdentifier name = parameter.identifier; |
12348 if (!name.isSynthetic && name.name.startsWith("_")) { | 13174 if (!name.isSynthetic && name.name.startsWith("_")) { |
12349 _errorReporter.reportError2(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAME
TER, node, []); | 13175 _errorReporter.reportError2(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAME
TER, node, []); |
12350 return true; | 13176 return true; |
12351 } | 13177 } |
12352 } | 13178 } |
12353 return false; | 13179 return false; |
12354 } | 13180 } |
12355 | 13181 |
12356 /** | 13182 /** |
12357 * This checks if the passed constructor declaration is the redirecting genera
tive constructor and | 13183 * This checks if the passed constructor declaration is the redirecting genera
tive constructor and |
12358 * references itself directly or indirectly. | 13184 * references itself directly or indirectly. |
| 13185 * |
12359 * @param node the constructor declaration to evaluate | 13186 * @param node the constructor declaration to evaluate |
12360 * @return `true` if and only if an error code is generated on the passed node | 13187 * @return `true` if and only if an error code is generated on the passed node |
12361 * @see CompileTimeErrorCode#RECURSIVE_CONSTRUCTOR_REDIRECT | 13188 * @see CompileTimeErrorCode#RECURSIVE_CONSTRUCTOR_REDIRECT |
12362 */ | 13189 */ |
12363 bool checkForRecursiveConstructorRedirect(ConstructorDeclaration node) { | 13190 bool checkForRecursiveConstructorRedirect(ConstructorDeclaration node) { |
12364 if (node.factoryKeyword != null) { | 13191 if (node.factoryKeyword != null) { |
12365 return false; | 13192 return false; |
12366 } | 13193 } |
12367 for (ConstructorInitializer initializer in node.initializers) { | 13194 for (ConstructorInitializer initializer in node.initializers) { |
12368 if (initializer is RedirectingConstructorInvocation) { | 13195 if (initializer is RedirectingConstructorInvocation) { |
12369 ConstructorElement element = node.element; | 13196 ConstructorElement element = node.element; |
12370 if (!hasRedirectingFactoryConstructorCycle(element)) { | 13197 if (!hasRedirectingFactoryConstructorCycle(element)) { |
12371 return false; | 13198 return false; |
12372 } | 13199 } |
12373 _errorReporter.reportError2(CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_R
EDIRECT, initializer, []); | 13200 _errorReporter.reportError2(CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_R
EDIRECT, initializer, []); |
12374 return true; | 13201 return true; |
12375 } | 13202 } |
12376 } | 13203 } |
12377 return false; | 13204 return false; |
12378 } | 13205 } |
12379 | 13206 |
12380 /** | 13207 /** |
12381 * This checks if the passed constructor declaration has redirected constructo
r and references | 13208 * This checks if the passed constructor declaration has redirected constructo
r and references |
12382 * itself directly or indirectly. | 13209 * itself directly or indirectly. |
| 13210 * |
12383 * @param node the constructor declaration to evaluate | 13211 * @param node the constructor declaration to evaluate |
12384 * @return `true` if and only if an error code is generated on the passed node | 13212 * @return `true` if and only if an error code is generated on the passed node |
12385 * @see CompileTimeErrorCode#RECURSIVE_FACTORY_REDIRECT | 13213 * @see CompileTimeErrorCode#RECURSIVE_FACTORY_REDIRECT |
12386 */ | 13214 */ |
12387 bool checkForRecursiveFactoryRedirect(ConstructorDeclaration node) { | 13215 bool checkForRecursiveFactoryRedirect(ConstructorDeclaration node) { |
12388 ConstructorName redirectedConstructorNode = node.redirectedConstructor; | 13216 ConstructorName redirectedConstructorNode = node.redirectedConstructor; |
12389 if (redirectedConstructorNode == null) { | 13217 if (redirectedConstructorNode == null) { |
12390 return false; | 13218 return false; |
12391 } | 13219 } |
12392 ConstructorElement element = node.element; | 13220 ConstructorElement element = node.element; |
12393 if (!hasRedirectingFactoryConstructorCycle(element)) { | 13221 if (!hasRedirectingFactoryConstructorCycle(element)) { |
12394 return false; | 13222 return false; |
12395 } | 13223 } |
12396 _errorReporter.reportError2(CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
redirectedConstructorNode, []); | 13224 _errorReporter.reportError2(CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
redirectedConstructorNode, []); |
12397 return true; | 13225 return true; |
12398 } | 13226 } |
12399 | 13227 |
12400 /** | 13228 /** |
12401 * This checks the class declaration is not a superinterface to itself. | 13229 * This checks the class declaration is not a superinterface to itself. |
| 13230 * |
12402 * @param classElt the class element to test | 13231 * @param classElt the class element to test |
12403 * @param list a list containing the potentially cyclic implements path | 13232 * @param list a list containing the potentially cyclic implements path |
12404 * @return `true` if and only if an error code is generated on the passed elem
ent | 13233 * @return `true` if and only if an error code is generated on the passed elem
ent |
12405 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE | 13234 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE |
12406 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS | 13235 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS |
12407 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEME
NTS | 13236 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEME
NTS |
12408 */ | 13237 */ |
12409 bool checkForRecursiveInterfaceInheritance(ClassElement classElt, List<ClassEl
ement> list) { | 13238 bool checkForRecursiveInterfaceInheritance(ClassElement classElt, List<ClassEl
ement> list) { |
12410 if (classElt == null) { | 13239 if (classElt == null) { |
12411 return false; | 13240 return false; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12457 return true; | 13286 return true; |
12458 } | 13287 } |
12459 } | 13288 } |
12460 list.removeAt(list.length - 1); | 13289 list.removeAt(list.length - 1); |
12461 return false; | 13290 return false; |
12462 } | 13291 } |
12463 | 13292 |
12464 /** | 13293 /** |
12465 * This checks the passed constructor declaration has a valid combination of r
edirected | 13294 * This checks the passed constructor declaration has a valid combination of r
edirected |
12466 * constructor invocation(s), super constructor invocations and field initiali
zers. | 13295 * constructor invocation(s), super constructor invocations and field initiali
zers. |
| 13296 * |
12467 * @param node the constructor declaration to evaluate | 13297 * @param node the constructor declaration to evaluate |
12468 * @return `true` if and only if an error code is generated on the passed node | 13298 * @return `true` if and only if an error code is generated on the passed node |
12469 * @see CompileTimeErrorCode#MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS | 13299 * @see CompileTimeErrorCode#MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS |
12470 * @see CompileTimeErrorCode#SUPER_IN_REDIRECTING_CONSTRUCTOR | 13300 * @see CompileTimeErrorCode#SUPER_IN_REDIRECTING_CONSTRUCTOR |
12471 * @see CompileTimeErrorCode#FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR | 13301 * @see CompileTimeErrorCode#FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR |
12472 */ | 13302 */ |
12473 bool checkForRedirectingConstructorErrorCodes(ConstructorDeclaration node) { | 13303 bool checkForRedirectingConstructorErrorCodes(ConstructorDeclaration node) { |
12474 int numProblems = 0; | 13304 int numProblems = 0; |
12475 int numRedirections = 0; | 13305 int numRedirections = 0; |
12476 for (ConstructorInitializer initializer in node.initializers) { | 13306 for (ConstructorInitializer initializer in node.initializers) { |
(...skipping 15 matching lines...) Expand all Loading... |
12492 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_RED
IRECTING_CONSTRUCTOR, initializer, []); | 13322 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_RED
IRECTING_CONSTRUCTOR, initializer, []); |
12493 numProblems++; | 13323 numProblems++; |
12494 } | 13324 } |
12495 } | 13325 } |
12496 } | 13326 } |
12497 return numProblems != 0; | 13327 return numProblems != 0; |
12498 } | 13328 } |
12499 | 13329 |
12500 /** | 13330 /** |
12501 * This checks if the passed constructor declaration has redirected constructo
r and references | 13331 * This checks if the passed constructor declaration has redirected constructo
r and references |
12502 * itself directly or indirectly. TODO(scheglov) | 13332 * itself directly or indirectly. |
| 13333 * |
12503 * @param node the constructor declaration to evaluate | 13334 * @param node the constructor declaration to evaluate |
12504 * @return `true` if and only if an error code is generated on the passed node | 13335 * @return `true` if and only if an error code is generated on the passed node |
12505 * @see CompileTimeErrorCode#REDIRECT_TO_NON_CONST_CONSTRUCTOR | 13336 * @see CompileTimeErrorCode#REDIRECT_TO_NON_CONST_CONSTRUCTOR |
12506 */ | 13337 */ |
12507 bool checkForRedirectToNonConstConstructor(ConstructorDeclaration node) { | 13338 bool checkForRedirectToNonConstConstructor(ConstructorDeclaration node) { |
12508 ConstructorName redirectedConstructorNode = node.redirectedConstructor; | 13339 ConstructorName redirectedConstructorNode = node.redirectedConstructor; |
12509 if (redirectedConstructorNode == null) { | 13340 if (redirectedConstructorNode == null) { |
12510 return false; | 13341 return false; |
12511 } | 13342 } |
12512 ConstructorElement element = node.element; | 13343 ConstructorElement element = node.element; |
(...skipping 10 matching lines...) Expand all Loading... |
12523 if (redirectedConstructor.isConst) { | 13354 if (redirectedConstructor.isConst) { |
12524 return false; | 13355 return false; |
12525 } | 13356 } |
12526 _errorReporter.reportError2(CompileTimeErrorCode.REDIRECT_TO_NON_CONST_CONST
RUCTOR, redirectedConstructorNode, []); | 13357 _errorReporter.reportError2(CompileTimeErrorCode.REDIRECT_TO_NON_CONST_CONST
RUCTOR, redirectedConstructorNode, []); |
12527 return true; | 13358 return true; |
12528 } | 13359 } |
12529 | 13360 |
12530 /** | 13361 /** |
12531 * This checks if the passed identifier is banned because it is part of the va
riable declaration | 13362 * This checks if the passed identifier is banned because it is part of the va
riable declaration |
12532 * with the same name. | 13363 * with the same name. |
| 13364 * |
12533 * @param node the identifier to evaluate | 13365 * @param node the identifier to evaluate |
12534 * @return `true` if and only if an error code is generated on the passed node | 13366 * @return `true` if and only if an error code is generated on the passed node |
12535 * @see CompileTimeErrorCode#REFERENCE_TO_DECLARED_VARIABLE_IN_INITIALIZER | 13367 * @see CompileTimeErrorCode#REFERENCE_TO_DECLARED_VARIABLE_IN_INITIALIZER |
12536 */ | 13368 */ |
12537 bool checkForReferenceToDeclaredVariableInInitializer(SimpleIdentifier node) { | 13369 bool checkForReferenceToDeclaredVariableInInitializer(SimpleIdentifier node) { |
12538 ASTNode parent = node.parent; | 13370 ASTNode parent = node.parent; |
12539 if (parent is PrefixedIdentifier) { | 13371 if (parent is PrefixedIdentifier) { |
12540 PrefixedIdentifier prefixedIdentifier = parent as PrefixedIdentifier; | 13372 PrefixedIdentifier prefixedIdentifier = parent as PrefixedIdentifier; |
12541 if (identical(prefixedIdentifier.identifier, node)) { | 13373 if (identical(prefixedIdentifier.identifier, node)) { |
12542 return false; | 13374 return false; |
(...skipping 26 matching lines...) Expand all Loading... |
12569 String name = node.name; | 13401 String name = node.name; |
12570 if (!_namesForReferenceToDeclaredVariableInInitializer.contains(name)) { | 13402 if (!_namesForReferenceToDeclaredVariableInInitializer.contains(name)) { |
12571 return false; | 13403 return false; |
12572 } | 13404 } |
12573 _errorReporter.reportError2(CompileTimeErrorCode.REFERENCE_TO_DECLARED_VARIA
BLE_IN_INITIALIZER, node, [name]); | 13405 _errorReporter.reportError2(CompileTimeErrorCode.REFERENCE_TO_DECLARED_VARIA
BLE_IN_INITIALIZER, node, [name]); |
12574 return true; | 13406 return true; |
12575 } | 13407 } |
12576 | 13408 |
12577 /** | 13409 /** |
12578 * This checks that the rethrow is inside of a catch clause. | 13410 * This checks that the rethrow is inside of a catch clause. |
| 13411 * |
12579 * @param node the rethrow expression to evaluate | 13412 * @param node the rethrow expression to evaluate |
12580 * @return `true` if and only if an error code is generated on the passed node | 13413 * @return `true` if and only if an error code is generated on the passed node |
12581 * @see CompileTimeErrorCode#RETHROW_OUTSIDE_CATCH | 13414 * @see CompileTimeErrorCode#RETHROW_OUTSIDE_CATCH |
12582 */ | 13415 */ |
12583 bool checkForRethrowOutsideCatch(RethrowExpression node) { | 13416 bool checkForRethrowOutsideCatch(RethrowExpression node) { |
12584 if (!_isInCatchClause) { | 13417 if (!_isInCatchClause) { |
12585 _errorReporter.reportError2(CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH, no
de, []); | 13418 _errorReporter.reportError2(CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH, no
de, []); |
12586 return true; | 13419 return true; |
12587 } | 13420 } |
12588 return false; | 13421 return false; |
12589 } | 13422 } |
12590 | 13423 |
12591 /** | 13424 /** |
12592 * This checks that a type mis-match between the return type and the expressed
return type by the | 13425 * This checks that a type mis-match between the return type and the expressed
return type by the |
12593 * enclosing method or function. | 13426 * enclosing method or function. |
12594 * | 13427 * |
12595 * This method is called both by [checkForAllReturnStatementErrorCodes]and [vi
sitExpressionFunctionBody]. | 13428 * This method is called both by [checkForAllReturnStatementErrorCodes] |
| 13429 * and [visitExpressionFunctionBody]. |
| 13430 * |
12596 * @param returnExpression the returned expression to evaluate | 13431 * @param returnExpression the returned expression to evaluate |
12597 * @param expectedReturnType the expressed return type by the enclosing method
or function | 13432 * @param expectedReturnType the expressed return type by the enclosing method
or function |
12598 * @return `true` if and only if an error code is generated on the passed node | 13433 * @return `true` if and only if an error code is generated on the passed node |
12599 * @see StaticTypeWarningCode#RETURN_OF_INVALID_TYPE | 13434 * @see StaticTypeWarningCode#RETURN_OF_INVALID_TYPE |
12600 */ | 13435 */ |
12601 bool checkForReturnOfInvalidType(Expression returnExpression, Type2 expectedRe
turnType) { | 13436 bool checkForReturnOfInvalidType(Expression returnExpression, Type2 expectedRe
turnType) { |
12602 Type2 staticReturnType = getStaticType(returnExpression); | 13437 Type2 staticReturnType = getStaticType(returnExpression); |
12603 if (expectedReturnType.isVoid) { | 13438 if (expectedReturnType.isVoid) { |
12604 if (staticReturnType.isVoid || staticReturnType.isDynamic || identical(sta
ticReturnType, BottomTypeImpl.instance)) { | 13439 if (staticReturnType.isVoid || staticReturnType.isDynamic || identical(sta
ticReturnType, BottomTypeImpl.instance)) { |
12605 return false; | 13440 return false; |
(...skipping 15 matching lines...) Expand all Loading... |
12621 return false; | 13456 return false; |
12622 } | 13457 } |
12623 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
returnExpression, [staticReturnType.displayName, expectedReturnType.displayName,
_enclosingFunction.displayName]); | 13458 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
returnExpression, [staticReturnType.displayName, expectedReturnType.displayName,
_enclosingFunction.displayName]); |
12624 return true; | 13459 return true; |
12625 } | 13460 } |
12626 } | 13461 } |
12627 | 13462 |
12628 /** | 13463 /** |
12629 * This checks that if the given "target" is the type reference then the "name
" is not the | 13464 * This checks that if the given "target" is the type reference then the "name
" is not the |
12630 * reference to a instance member. | 13465 * reference to a instance member. |
| 13466 * |
12631 * @param target the target of the name access to evaluate | 13467 * @param target the target of the name access to evaluate |
12632 * @param name the accessed name to evaluate | 13468 * @param name the accessed name to evaluate |
12633 * @return `true` if and only if an error code is generated on the passed node | 13469 * @return `true` if and only if an error code is generated on the passed node |
12634 * @see StaticWarningCode#STATIC_ACCESS_TO_INSTANCE_MEMBER | 13470 * @see StaticWarningCode#STATIC_ACCESS_TO_INSTANCE_MEMBER |
12635 */ | 13471 */ |
12636 bool checkForStaticAccessToInstanceMember(Expression target, SimpleIdentifier
name2) { | 13472 bool checkForStaticAccessToInstanceMember(Expression target, SimpleIdentifier
name2) { |
12637 Element element = name2.element; | 13473 Element element = name2.element; |
12638 if (element is! ExecutableElement) { | 13474 if (element is! ExecutableElement) { |
12639 return false; | 13475 return false; |
12640 } | 13476 } |
12641 ExecutableElement memberElement = element as ExecutableElement; | 13477 ExecutableElement memberElement = element as ExecutableElement; |
12642 if (memberElement.isStatic) { | 13478 if (memberElement.isStatic) { |
12643 return false; | 13479 return false; |
12644 } | 13480 } |
12645 if (!isTypeReference(target)) { | 13481 if (!isTypeReference(target)) { |
12646 return false; | 13482 return false; |
12647 } | 13483 } |
12648 _errorReporter.reportError2(StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMB
ER, name2, [name2.name]); | 13484 _errorReporter.reportError2(StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMB
ER, name2, [name2.name]); |
12649 return true; | 13485 return true; |
12650 } | 13486 } |
12651 | 13487 |
12652 /** | 13488 /** |
12653 * This checks that the type of the passed 'switch' expression is assignable t
o the type of the | 13489 * This checks that the type of the passed 'switch' expression is assignable t
o the type of the |
12654 * 'case' members. | 13490 * 'case' members. |
| 13491 * |
12655 * @param node the 'switch' statement to evaluate | 13492 * @param node the 'switch' statement to evaluate |
12656 * @return `true` if and only if an error code is generated on the passed node | 13493 * @return `true` if and only if an error code is generated on the passed node |
12657 * @see StaticWarningCode#SWITCH_EXPRESSION_NOT_ASSIGNABLE | 13494 * @see StaticWarningCode#SWITCH_EXPRESSION_NOT_ASSIGNABLE |
12658 */ | 13495 */ |
12659 bool checkForSwitchExpressionNotAssignable(SwitchStatement node) { | 13496 bool checkForSwitchExpressionNotAssignable(SwitchStatement node) { |
12660 Expression expression = node.expression; | 13497 Expression expression = node.expression; |
12661 Type2 expressionType = getStaticType(expression); | 13498 Type2 expressionType = getStaticType(expression); |
12662 if (expressionType == null) { | 13499 if (expressionType == null) { |
12663 return false; | 13500 return false; |
12664 } | 13501 } |
12665 NodeList<SwitchMember> members = node.members; | 13502 NodeList<SwitchMember> members = node.members; |
12666 for (SwitchMember switchMember in members) { | 13503 for (SwitchMember switchMember in members) { |
12667 if (switchMember is! SwitchCase) { | 13504 if (switchMember is! SwitchCase) { |
12668 continue; | 13505 continue; |
12669 } | 13506 } |
12670 SwitchCase switchCase = switchMember as SwitchCase; | 13507 SwitchCase switchCase = switchMember as SwitchCase; |
12671 Expression caseExpression = switchCase.expression; | 13508 Expression caseExpression = switchCase.expression; |
12672 Type2 caseType = getStaticType(caseExpression); | 13509 Type2 caseType = getStaticType(caseExpression); |
12673 if (expressionType.isAssignableTo(caseType)) { | 13510 if (expressionType.isAssignableTo(caseType)) { |
12674 return false; | 13511 return false; |
12675 } | 13512 } |
12676 _errorReporter.reportError2(StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGN
ABLE, expression, [expressionType, caseType]); | 13513 _errorReporter.reportError2(StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGN
ABLE, expression, [expressionType, caseType]); |
12677 return true; | 13514 return true; |
12678 } | 13515 } |
12679 return false; | 13516 return false; |
12680 } | 13517 } |
12681 | 13518 |
12682 /** | 13519 /** |
12683 * This verifies that the type arguments in the passed instance creation expre
ssion are all within | 13520 * This verifies that the type arguments in the passed type name are all withi
n their bounds. |
12684 * their bounds as specified by the class element where the constructor \[that
is being invoked\] is | 13521 * |
12685 * declared. | 13522 * @param node the [TypeName] to evaluate |
12686 * @param node the instance creation expression to evaluate | |
12687 * @param typeName the [TypeName] of the [ConstructorName] from the[InstanceCr
eationExpression], this is the AST node that the error is attached to | |
12688 * @param constructorElement the [ConstructorElement] from the instance creati
on expression | |
12689 * @return `true` if and only if an error code is generated on the passed node | 13523 * @return `true` if and only if an error code is generated on the passed node |
12690 * @see StaticTypeWarningCode#TYPE_ARGUMENT_NOT_MATCHING_BOUNDS | 13524 * @see StaticTypeWarningCode#TYPE_ARGUMENT_NOT_MATCHING_BOUNDS |
12691 */ | 13525 */ |
12692 bool checkForTypeArgumentNotMatchingBounds(InstanceCreationExpression node, Co
nstructorElement constructorElement, TypeName typeName) { | 13526 bool checkForTypeArgumentNotMatchingBounds(TypeName node) { |
12693 if (typeName.typeArguments != null && constructorElement != null) { | 13527 if (node.typeArguments == null) { |
12694 NodeList<TypeName> typeNameArgList = typeName.typeArguments.arguments; | 13528 return false; |
12695 List<TypeVariableElement> boundingElts = constructorElement.enclosingEleme
nt.typeVariables; | 13529 } |
12696 int loopThroughIndex = Math.min(typeNameArgList.length, boundingElts.lengt
h); | 13530 List<TypeVariableElement> boundingElts = null; |
12697 for (int i = 0; i < loopThroughIndex; i++) { | 13531 Type2 type = node.type; |
12698 TypeName argTypeName = typeNameArgList[i]; | 13532 if (type == null) { |
12699 Type2 argType = argTypeName.type; | 13533 return false; |
12700 Type2 boundType = boundingElts[i].bound; | 13534 } |
12701 if (argType != null && boundType != null) { | 13535 Element element = type.element; |
12702 if (!argType.isSubtypeOf(boundType)) { | 13536 if (element is ClassElement) { |
12703 _errorReporter.reportError2(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_
MATCHING_BOUNDS, argTypeName, [argTypeName.name, boundingElts[i].displayName]); | 13537 boundingElts = ((element as ClassElement)).typeVariables; |
12704 return true; | 13538 } else { |
12705 } | 13539 return false; |
| 13540 } |
| 13541 NodeList<TypeName> typeNameArgList = node.typeArguments.arguments; |
| 13542 int loopThroughIndex = Math.min(typeNameArgList.length, boundingElts.length)
; |
| 13543 bool foundError = false; |
| 13544 for (int i = 0; i < loopThroughIndex; i++) { |
| 13545 TypeName argTypeName = typeNameArgList[i]; |
| 13546 Type2 argType = argTypeName.type; |
| 13547 Type2 boundType = boundingElts[i].bound; |
| 13548 if (argType != null && boundType != null) { |
| 13549 if (!argType.isSubtypeOf(boundType)) { |
| 13550 _errorReporter.reportError2(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MA
TCHING_BOUNDS, argTypeName, [argTypeName.name, boundingElts[i].bound.displayName
]); |
| 13551 foundError = true; |
12706 } | 13552 } |
12707 } | 13553 } |
12708 } | 13554 } |
12709 return false; | 13555 return foundError; |
12710 } | 13556 } |
12711 | 13557 |
12712 /** | 13558 /** |
12713 * This checks that if the passed generative constructor has neither an explic
it super constructor | 13559 * This checks that if the passed generative constructor has neither an explic
it super constructor |
12714 * invocation nor a redirecting constructor invocation, that the superclass ha
s a default | 13560 * invocation nor a redirecting constructor invocation, that the superclass ha
s a default |
12715 * generative constructor. | 13561 * generative constructor. |
| 13562 * |
12716 * @param node the constructor declaration to evaluate | 13563 * @param node the constructor declaration to evaluate |
12717 * @return `true` if and only if an error code is generated on the passed node | 13564 * @return `true` if and only if an error code is generated on the passed node |
12718 * @see CompileTimeErrorCode#UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT | 13565 * @see CompileTimeErrorCode#UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT |
12719 * @see CompileTimeErrorCode#NON_GENERATIVE_CONSTRUCTOR | 13566 * @see CompileTimeErrorCode#NON_GENERATIVE_CONSTRUCTOR |
12720 * @see StaticWarningCode#NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT | 13567 * @see StaticWarningCode#NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT |
12721 */ | 13568 */ |
12722 bool checkForUndefinedConstructorInInitializerImplicit(ConstructorDeclaration
node) { | 13569 bool checkForUndefinedConstructorInInitializerImplicit(ConstructorDeclaration
node) { |
12723 if (node.factoryKeyword != null) { | 13570 if (node.factoryKeyword != null) { |
12724 return false; | 13571 return false; |
12725 } | 13572 } |
(...skipping 18 matching lines...) Expand all Loading... |
12744 } | 13591 } |
12745 if (!superUnnamedConstructor.isDefaultConstructor) { | 13592 if (!superUnnamedConstructor.isDefaultConstructor) { |
12746 int offset; | 13593 int offset; |
12747 int length; | 13594 int length; |
12748 { | 13595 { |
12749 Identifier returnType = node.returnType; | 13596 Identifier returnType = node.returnType; |
12750 SimpleIdentifier name = node.name; | 13597 SimpleIdentifier name = node.name; |
12751 offset = returnType.offset; | 13598 offset = returnType.offset; |
12752 length = (name != null ? name.end : returnType.end) - offset; | 13599 length = (name != null ? name.end : returnType.end) - offset; |
12753 } | 13600 } |
12754 _errorReporter.reportError3(StaticWarningCode.NO_DEFAULT_SUPER_CONSTRUCT
OR_EXPLICIT, offset, length, [superType.displayName]); | 13601 _errorReporter.reportError3(CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTR
UCTOR_EXPLICIT, offset, length, [superType.displayName]); |
12755 } | 13602 } |
12756 return false; | 13603 return false; |
12757 } | 13604 } |
12758 _errorReporter.reportError2(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_IN
ITIALIZER_DEFAULT, node.returnType, [superElement.name]); | 13605 _errorReporter.reportError2(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_IN
ITIALIZER_DEFAULT, node.returnType, [superElement.name]); |
12759 return true; | 13606 return true; |
12760 } | 13607 } |
12761 | 13608 |
12762 /** | 13609 /** |
12763 * This verifies the passed operator-method declaration, has correct number of
parameters. | 13610 * This verifies the passed operator-method declaration, has correct number of
parameters. |
12764 * | 13611 * |
12765 * This method assumes that the method declaration was tested to be an operato
r declaration before | 13612 * This method assumes that the method declaration was tested to be an operato
r declaration before |
12766 * being called. | 13613 * being called. |
| 13614 * |
12767 * @param node the method declaration to evaluate | 13615 * @param node the method declaration to evaluate |
12768 * @return `true` if and only if an error code is generated on the passed node | 13616 * @return `true` if and only if an error code is generated on the passed node |
12769 * @see CompileTimeErrorCode#WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR | 13617 * @see CompileTimeErrorCode#WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR |
12770 */ | 13618 */ |
12771 bool checkForWrongNumberOfParametersForOperator(MethodDeclaration node) { | 13619 bool checkForWrongNumberOfParametersForOperator(MethodDeclaration node) { |
12772 FormalParameterList parameterList = node.parameters; | 13620 FormalParameterList parameterList = node.parameters; |
12773 if (parameterList == null) { | 13621 if (parameterList == null) { |
12774 return false; | 13622 return false; |
12775 } | 13623 } |
12776 int numParameters = parameterList.parameters.length; | 13624 int numParameters = parameterList.parameters.length; |
(...skipping 15 matching lines...) Expand all Loading... |
12792 return true; | 13640 return true; |
12793 } | 13641 } |
12794 if ("-" == name && numParameters > 1) { | 13642 if ("-" == name && numParameters > 1) { |
12795 _errorReporter.reportError2(CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETER
S_FOR_OPERATOR_MINUS, nameNode, [numParameters]); | 13643 _errorReporter.reportError2(CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETER
S_FOR_OPERATOR_MINUS, nameNode, [numParameters]); |
12796 return true; | 13644 return true; |
12797 } | 13645 } |
12798 return false; | 13646 return false; |
12799 } | 13647 } |
12800 | 13648 |
12801 /** | 13649 /** |
12802 * This verifies if the passed setter parameter list have only one parameter. | 13650 * This verifies if the passed setter parameter list have only one required pa
rameter. |
12803 * | 13651 * |
12804 * This method assumes that the method declaration was tested to be a setter b
efore being called. | 13652 * This method assumes that the method declaration was tested to be a setter b
efore being called. |
| 13653 * |
12805 * @param setterName the name of the setter to report problems on | 13654 * @param setterName the name of the setter to report problems on |
12806 * @param parameterList the parameter list to evaluate | 13655 * @param parameterList the parameter list to evaluate |
12807 * @return `true` if and only if an error code is generated on the passed node | 13656 * @return `true` if and only if an error code is generated on the passed node |
12808 * @see CompileTimeErrorCode#WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER | 13657 * @see CompileTimeErrorCode#WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER |
12809 */ | 13658 */ |
12810 bool checkForWrongNumberOfParametersForSetter(SimpleIdentifier setterName, For
malParameterList parameterList) { | 13659 bool checkForWrongNumberOfParametersForSetter(SimpleIdentifier setterName, For
malParameterList parameterList) { |
12811 if (setterName == null) { | 13660 if (setterName == null) { |
12812 return false; | 13661 return false; |
12813 } | 13662 } |
12814 if (parameterList == null) { | 13663 if (parameterList == null) { |
12815 return false; | 13664 return false; |
12816 } | 13665 } |
12817 int numberOfParameters = parameterList.parameters.length; | 13666 NodeList<FormalParameter> parameters = parameterList.parameters; |
12818 if (numberOfParameters != 1) { | 13667 if (parameters.length != 1 || parameters[0].kind != ParameterKind.REQUIRED)
{ |
12819 _errorReporter.reportError2(CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETER
S_FOR_SETTER, setterName, [numberOfParameters]); | 13668 _errorReporter.reportError2(CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETER
S_FOR_SETTER, setterName, []); |
12820 return true; | 13669 return true; |
12821 } | 13670 } |
12822 return false; | 13671 return false; |
12823 } | 13672 } |
12824 | 13673 |
12825 /** | 13674 /** |
12826 * Return the propagated type of the given expression, or the static type if t
here is no | 13675 * Return the propagated type of the given expression, or the static type if t
here is no |
12827 * propagated type information. | 13676 * propagated type information. |
| 13677 * |
12828 * @param expression the expression whose type is to be returned | 13678 * @param expression the expression whose type is to be returned |
12829 * @return the propagated or static type of the given expression, whichever is
best | 13679 * @return the propagated or static type of the given expression, whichever is
best |
12830 */ | 13680 */ |
12831 Type2 getBestType(Expression expression) { | 13681 Type2 getBestType(Expression expression) { |
12832 Type2 type = getPropagatedType(expression); | 13682 Type2 type = getPropagatedType(expression); |
12833 if (type == null) { | 13683 if (type == null) { |
12834 type = getStaticType(expression); | 13684 type = getStaticType(expression); |
12835 } | 13685 } |
12836 return type; | 13686 return type; |
12837 } | 13687 } |
12838 | 13688 |
12839 /** | 13689 /** |
12840 * Returns the Type (return type) for a given getter. | 13690 * Returns the Type (return type) for a given getter. |
| 13691 * |
12841 * @param propertyAccessorElement | 13692 * @param propertyAccessorElement |
12842 * @return The type of the given getter. | 13693 * @return The type of the given getter. |
12843 */ | 13694 */ |
12844 Type2 getGetterType(PropertyAccessorElement propertyAccessorElement) { | 13695 Type2 getGetterType(PropertyAccessorElement propertyAccessorElement) { |
12845 FunctionType functionType = propertyAccessorElement.type; | 13696 FunctionType functionType = propertyAccessorElement.type; |
12846 if (functionType != null) { | 13697 if (functionType != null) { |
12847 return functionType.returnType; | 13698 return functionType.returnType; |
12848 } else { | 13699 } else { |
12849 return null; | 13700 return null; |
12850 } | 13701 } |
12851 } | 13702 } |
12852 | 13703 |
12853 /** | 13704 /** |
12854 * Return the propagated type of the given expression that is to be used for t
ype analysis. | 13705 * Return the propagated type of the given expression that is to be used for t
ype analysis. |
| 13706 * |
12855 * @param expression the expression whose type is to be returned | 13707 * @param expression the expression whose type is to be returned |
12856 * @return the propagated type of the given expression | 13708 * @return the propagated type of the given expression |
12857 */ | 13709 */ |
12858 Type2 getPropagatedType(Expression expression) => expression.propagatedType; | 13710 Type2 getPropagatedType(Expression expression) => expression.propagatedType; |
12859 | 13711 |
12860 /** | 13712 /** |
12861 * Returns the Type (first and only parameter) for a given setter. | 13713 * Returns the Type (first and only parameter) for a given setter. |
| 13714 * |
12862 * @param propertyAccessorElement | 13715 * @param propertyAccessorElement |
12863 * @return The type of the given setter. | 13716 * @return The type of the given setter. |
12864 */ | 13717 */ |
12865 Type2 getSetterType(PropertyAccessorElement propertyAccessorElement) { | 13718 Type2 getSetterType(PropertyAccessorElement propertyAccessorElement) { |
12866 List<ParameterElement> setterParameters = propertyAccessorElement.parameters
; | 13719 List<ParameterElement> setterParameters = propertyAccessorElement.parameters
; |
12867 if (setterParameters.length == 0) { | 13720 if (setterParameters.length == 0) { |
12868 return null; | 13721 return null; |
12869 } | 13722 } |
12870 return setterParameters[0].type; | 13723 return setterParameters[0].type; |
12871 } | 13724 } |
12872 | 13725 |
12873 /** | 13726 /** |
12874 * Return the static type of the given expression that is to be used for type
analysis. | 13727 * Return the static type of the given expression that is to be used for type
analysis. |
| 13728 * |
12875 * @param expression the expression whose type is to be returned | 13729 * @param expression the expression whose type is to be returned |
12876 * @return the static type of the given expression | 13730 * @return the static type of the given expression |
12877 */ | 13731 */ |
12878 Type2 getStaticType(Expression expression) { | 13732 Type2 getStaticType(Expression expression) { |
12879 Type2 type = expression.staticType; | 13733 Type2 type = expression.staticType; |
12880 if (type == null) { | 13734 if (type == null) { |
12881 return _dynamicType; | 13735 return _dynamicType; |
12882 } | 13736 } |
12883 return type; | 13737 return type; |
12884 } | 13738 } |
12885 | 13739 |
12886 /** | 13740 /** |
12887 * Return the variable element represented by the given expression, or `null`
if there is no | 13741 * Return the variable element represented by the given expression, or `null`
if there is no |
12888 * such element. | 13742 * such element. |
| 13743 * |
12889 * @param expression the expression whose element is to be returned | 13744 * @param expression the expression whose element is to be returned |
12890 * @return the variable element represented by the expression | 13745 * @return the variable element represented by the expression |
12891 */ | 13746 */ |
12892 VariableElement getVariableElement(Expression expression) { | 13747 VariableElement getVariableElement(Expression expression) { |
12893 if (expression is Identifier) { | 13748 if (expression is Identifier) { |
12894 Element element = ((expression as Identifier)).element; | 13749 Element element = ((expression as Identifier)).element; |
12895 if (element is VariableElement) { | 13750 if (element is VariableElement) { |
12896 return element as VariableElement; | 13751 return element as VariableElement; |
12897 } | 13752 } |
12898 } | 13753 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12987 this._errorReporter = errorReporter; | 13842 this._errorReporter = errorReporter; |
12988 } | 13843 } |
12989 Object visitImportDirective(ImportDirective directive) { | 13844 Object visitImportDirective(ImportDirective directive) { |
12990 return null; | 13845 return null; |
12991 } | 13846 } |
12992 | 13847 |
12993 /** | 13848 /** |
12994 * This verifies that the passed file import directive is not contained in a s
ource inside a | 13849 * This verifies that the passed file import directive is not contained in a s
ource inside a |
12995 * package "lib" directory hierarchy referencing a source outside that package
"lib" directory | 13850 * package "lib" directory hierarchy referencing a source outside that package
"lib" directory |
12996 * hierarchy. | 13851 * hierarchy. |
| 13852 * |
12997 * @param uriLiteral the import URL (not `null`) | 13853 * @param uriLiteral the import URL (not `null`) |
12998 * @param path the file path being verified (not `null`) | 13854 * @param path the file path being verified (not `null`) |
12999 * @return `true` if and only if an error code is generated on the passed node | 13855 * @return `true` if and only if an error code is generated on the passed node |
13000 * @see PubSuggestionCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE | 13856 * @see PubSuggestionCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE |
13001 */ | 13857 */ |
13002 bool checkForFileImportInsideLibReferencesFileOutside(StringLiteral uriLiteral
, String path) { | 13858 bool checkForFileImportInsideLibReferencesFileOutside(StringLiteral uriLiteral
, String path) { |
13003 Source source = getSource(uriLiteral); | 13859 Source source = getSource(uriLiteral); |
13004 String fullName = getSourceFullName(source); | 13860 String fullName = getSourceFullName(source); |
13005 if (fullName != null) { | 13861 if (fullName != null) { |
13006 int pathIndex = 0; | 13862 int pathIndex = 0; |
(...skipping 14 matching lines...) Expand all Loading... |
13021 pathIndex += 3; | 13877 pathIndex += 3; |
13022 } | 13878 } |
13023 } | 13879 } |
13024 return false; | 13880 return false; |
13025 } | 13881 } |
13026 | 13882 |
13027 /** | 13883 /** |
13028 * This verifies that the passed file import directive is not contained in a s
ource outside a | 13884 * This verifies that the passed file import directive is not contained in a s
ource outside a |
13029 * package "lib" directory hierarchy referencing a source inside that package
"lib" directory | 13885 * package "lib" directory hierarchy referencing a source inside that package
"lib" directory |
13030 * hierarchy. | 13886 * hierarchy. |
| 13887 * |
13031 * @param uriLiteral the import URL (not `null`) | 13888 * @param uriLiteral the import URL (not `null`) |
13032 * @param path the file path being verified (not `null`) | 13889 * @param path the file path being verified (not `null`) |
13033 * @return `true` if and only if an error code is generated on the passed node | 13890 * @return `true` if and only if an error code is generated on the passed node |
13034 * @see PubSuggestionCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE | 13891 * @see PubSuggestionCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE |
13035 */ | 13892 */ |
13036 bool checkForFileImportOutsideLibReferencesFileInside(StringLiteral uriLiteral
, String path) { | 13893 bool checkForFileImportOutsideLibReferencesFileInside(StringLiteral uriLiteral
, String path) { |
13037 if (path.startsWith("lib/")) { | 13894 if (path.startsWith("lib/")) { |
13038 if (checkForFileImportOutsideLibReferencesFileInside2(uriLiteral, path, 0)
) { | 13895 if (checkForFileImportOutsideLibReferencesFileInside2(uriLiteral, path, 0)
) { |
13039 return true; | 13896 return true; |
13040 } | 13897 } |
(...skipping 19 matching lines...) Expand all Loading... |
13060 if (!fullName.contains("/lib/")) { | 13917 if (!fullName.contains("/lib/")) { |
13061 _errorReporter.reportError2(PubSuggestionCode.FILE_IMPORT_OUTSIDE_LIB_RE
FERENCES_FILE_INSIDE, uriLiteral, []); | 13918 _errorReporter.reportError2(PubSuggestionCode.FILE_IMPORT_OUTSIDE_LIB_RE
FERENCES_FILE_INSIDE, uriLiteral, []); |
13062 return true; | 13919 return true; |
13063 } | 13920 } |
13064 } | 13921 } |
13065 return false; | 13922 return false; |
13066 } | 13923 } |
13067 | 13924 |
13068 /** | 13925 /** |
13069 * This verifies that the passed package import directive does not contain "..
" | 13926 * This verifies that the passed package import directive does not contain "..
" |
| 13927 * |
13070 * @param uriLiteral the import URL (not `null`) | 13928 * @param uriLiteral the import URL (not `null`) |
13071 * @param path the path to be validated (not `null`) | 13929 * @param path the path to be validated (not `null`) |
13072 * @return `true` if and only if an error code is generated on the passed node | 13930 * @return `true` if and only if an error code is generated on the passed node |
13073 * @see PubSuggestionCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT | 13931 * @see PubSuggestionCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT |
13074 */ | 13932 */ |
13075 bool checkForPackageImportContainsDotDot(StringLiteral uriLiteral, String path
) { | 13933 bool checkForPackageImportContainsDotDot(StringLiteral uriLiteral, String path
) { |
13076 if (path.startsWith("../") || path.contains("/../")) { | 13934 if (path.startsWith("../") || path.contains("/../")) { |
13077 _errorReporter.reportError2(PubSuggestionCode.PACKAGE_IMPORT_CONTAINS_DOT_
DOT, uriLiteral, []); | 13935 _errorReporter.reportError2(PubSuggestionCode.PACKAGE_IMPORT_CONTAINS_DOT_
DOT, uriLiteral, []); |
13078 return true; | 13936 return true; |
13079 } | 13937 } |
13080 return false; | 13938 return false; |
13081 } | 13939 } |
13082 | 13940 |
13083 /** | 13941 /** |
13084 * Answer the source associated with the compilation unit containing the given
AST node. | 13942 * Answer the source associated with the compilation unit containing the given
AST node. |
| 13943 * |
13085 * @param node the node (not `null`) | 13944 * @param node the node (not `null`) |
13086 * @return the source or `null` if it could not be determined | 13945 * @return the source or `null` if it could not be determined |
13087 */ | 13946 */ |
13088 Source getSource(ASTNode node) { | 13947 Source getSource(ASTNode node) { |
13089 Source source = null; | 13948 Source source = null; |
13090 CompilationUnit unit = node.getAncestor(CompilationUnit); | 13949 CompilationUnit unit = node.getAncestor(CompilationUnit); |
13091 if (unit != null) { | 13950 if (unit != null) { |
13092 CompilationUnitElement element = unit.element; | 13951 CompilationUnitElement element = unit.element; |
13093 if (element != null) { | 13952 if (element != null) { |
13094 source = element.source; | 13953 source = element.source; |
13095 } | 13954 } |
13096 } | 13955 } |
13097 return source; | 13956 return source; |
13098 } | 13957 } |
13099 | 13958 |
13100 /** | 13959 /** |
13101 * Answer the full name of the given source. The returned value will have all[
File#separatorChar] replace by '/'. | 13960 * Answer the full name of the given source. The returned value will have all |
| 13961 * [File#separatorChar] replace by '/'. |
| 13962 * |
13102 * @param source the source | 13963 * @param source the source |
13103 * @return the full name or `null` if it could not be determined | 13964 * @return the full name or `null` if it could not be determined |
13104 */ | 13965 */ |
13105 String getSourceFullName(Source source) { | 13966 String getSourceFullName(Source source) { |
13106 if (source != null) { | 13967 if (source != null) { |
13107 String fullName = source.fullName; | 13968 String fullName = source.fullName; |
13108 if (fullName != null) { | 13969 if (fullName != null) { |
13109 return fullName.replaceAll(r'\', '/'); | 13970 return fullName.replaceAll(r'\', '/'); |
13110 } | 13971 } |
13111 } | 13972 } |
13112 return null; | 13973 return null; |
13113 } | 13974 } |
13114 } | 13975 } |
13115 /** | 13976 /** |
13116 * The enumeration `ResolverErrorCode` defines the error codes used for errors d
etected by the | 13977 * The enumeration `ResolverErrorCode` defines the error codes used for errors d
etected by the |
13117 * resolver. The convention for this class is for the name of the error code to
indicate the problem | 13978 * resolver. The convention for this class is for the name of the error code to
indicate the problem |
13118 * that caused the error to be generated and for the error message to explain wh
at is wrong and, | 13979 * that caused the error to be generated and for the error message to explain wh
at is wrong and, |
13119 * when appropriate, how the problem can be corrected. | 13980 * when appropriate, how the problem can be corrected. |
| 13981 * |
13120 * @coverage dart.engine.resolver | 13982 * @coverage dart.engine.resolver |
13121 */ | 13983 */ |
13122 class ResolverErrorCode implements Comparable<ResolverErrorCode>, ErrorCode { | 13984 class ResolverErrorCode implements Comparable<ResolverErrorCode>, ErrorCode { |
13123 static final ResolverErrorCode BREAK_LABEL_ON_SWITCH_MEMBER = new ResolverErro
rCode('BREAK_LABEL_ON_SWITCH_MEMBER', 0, ErrorType.COMPILE_TIME_ERROR, "Break la
bel resolves to case or default statement"); | 13985 static final ResolverErrorCode BREAK_LABEL_ON_SWITCH_MEMBER = new ResolverErro
rCode('BREAK_LABEL_ON_SWITCH_MEMBER', 0, ErrorType.COMPILE_TIME_ERROR, "Break la
bel resolves to case or default statement"); |
13124 static final ResolverErrorCode CONTINUE_LABEL_ON_SWITCH = new ResolverErrorCod
e('CONTINUE_LABEL_ON_SWITCH', 1, ErrorType.COMPILE_TIME_ERROR, "A continue label
resolves to switch, must be loop or switch member"); | 13986 static final ResolverErrorCode CONTINUE_LABEL_ON_SWITCH = new ResolverErrorCod
e('CONTINUE_LABEL_ON_SWITCH', 1, ErrorType.COMPILE_TIME_ERROR, "A continue label
resolves to switch, must be loop or switch member"); |
13125 static final ResolverErrorCode MISSING_LIBRARY_DIRECTIVE_WITH_PART = new Resol
verErrorCode('MISSING_LIBRARY_DIRECTIVE_WITH_PART', 2, ErrorType.COMPILE_TIME_ER
ROR, "Libraries that have parts must have a library directive"); | 13987 static final ResolverErrorCode MISSING_LIBRARY_DIRECTIVE_WITH_PART = new Resol
verErrorCode('MISSING_LIBRARY_DIRECTIVE_WITH_PART', 2, ErrorType.COMPILE_TIME_ER
ROR, "Libraries that have parts must have a library directive"); |
13126 static final List<ResolverErrorCode> values = [BREAK_LABEL_ON_SWITCH_MEMBER, C
ONTINUE_LABEL_ON_SWITCH, MISSING_LIBRARY_DIRECTIVE_WITH_PART]; | 13988 static final List<ResolverErrorCode> values = [BREAK_LABEL_ON_SWITCH_MEMBER, C
ONTINUE_LABEL_ON_SWITCH, MISSING_LIBRARY_DIRECTIVE_WITH_PART]; |
13127 | 13989 |
13128 /// The name of this enum constant, as declared in the enum declaration. | 13990 /// The name of this enum constant, as declared in the enum declaration. |
13129 final String name; | 13991 final String name; |
13130 | 13992 |
13131 /// The position in the enum declaration. | 13993 /// The position in the enum declaration. |
13132 final int ordinal; | 13994 final int ordinal; |
13133 | 13995 |
13134 /** | 13996 /** |
13135 * The type of this error. | 13997 * The type of this error. |
13136 */ | 13998 */ |
13137 ErrorType _type; | 13999 ErrorType _type; |
13138 | 14000 |
13139 /** | 14001 /** |
13140 * The message template used to create the message to be displayed for this er
ror. | 14002 * The message template used to create the message to be displayed for this er
ror. |
13141 */ | 14003 */ |
13142 String _message; | 14004 String _message; |
13143 | 14005 |
13144 /** | 14006 /** |
13145 * Initialize a newly created error code to have the given type and message. | 14007 * Initialize a newly created error code to have the given type and message. |
| 14008 * |
13146 * @param type the type of this error | 14009 * @param type the type of this error |
13147 * @param message the message template used to create the message to be displa
yed for the error | 14010 * @param message the message template used to create the message to be displa
yed for the error |
13148 */ | 14011 */ |
13149 ResolverErrorCode(this.name, this.ordinal, ErrorType type, String message) { | 14012 ResolverErrorCode(this.name, this.ordinal, ErrorType type, String message) { |
13150 this._type = type; | 14013 this._type = type; |
13151 this._message = message; | 14014 this._message = message; |
13152 } | 14015 } |
13153 ErrorSeverity get errorSeverity => _type.severity; | 14016 ErrorSeverity get errorSeverity => _type.severity; |
13154 String get message => _message; | 14017 String get message => _message; |
13155 ErrorType get type => _type; | 14018 ErrorType get type => _type; |
13156 int compareTo(ResolverErrorCode other) => ordinal - other.ordinal; | 14019 int compareTo(ResolverErrorCode other) => ordinal - other.ordinal; |
13157 int get hashCode => ordinal; | 14020 int get hashCode => ordinal; |
13158 String toString() => name; | 14021 String toString() => name; |
13159 } | 14022 } |
OLD | NEW |