| 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 | |
| 4 library engine.resolver; | 3 library engine.resolver; |
| 5 | |
| 6 import 'dart:collection'; | 4 import 'dart:collection'; |
| 7 import 'java_core.dart'; | 5 import 'java_core.dart'; |
| 8 import 'java_engine.dart'; | 6 import 'java_engine.dart'; |
| 9 import 'instrumentation.dart'; | 7 import 'instrumentation.dart'; |
| 10 import 'source.dart'; | 8 import 'source.dart'; |
| 11 import 'error.dart'; | 9 import 'error.dart'; |
| 12 import 'scanner.dart' as sc; | 10 import 'scanner.dart' as sc; |
| 13 import 'utilities_dart.dart'; | 11 import 'utilities_dart.dart'; |
| 14 import 'ast.dart'; | 12 import 'ast.dart'; |
| 15 import 'parser.dart' show Parser, ParserErrorCode; | 13 import 'parser.dart' show Parser, ParserErrorCode; |
| 16 import 'sdk.dart' show DartSdk, SdkLibrary; | 14 import 'sdk.dart' show DartSdk, SdkLibrary; |
| 17 import 'element.dart' hide Annotation, HideCombinator, ShowCombinator; | 15 import 'element.dart' hide Annotation, HideCombinator, ShowCombinator; |
| 18 import 'html.dart' as ht; | 16 import 'html.dart' as ht; |
| 19 import 'engine.dart'; | 17 import 'engine.dart'; |
| 20 import 'constant.dart'; | 18 import 'constant.dart'; |
| 21 import 'element.dart' as __imp_combi show HideCombinator, ShowCombinator; | 19 import 'element.dart' as __imp_combi show HideCombinator, ShowCombinator; |
| 22 | |
| 23 | |
| 24 /** | 20 /** |
| 25 * Instances of the class {@code CompilationUnitBuilder} build an element model
for a single | 21 * Instances of the class {@code CompilationUnitBuilder} build an element model
for a single |
| 26 * compilation unit. | 22 * compilation unit. |
| 27 * @coverage dart.engine.resolver | 23 * @coverage dart.engine.resolver |
| 28 */ | 24 */ |
| 29 class CompilationUnitBuilder { | 25 class CompilationUnitBuilder { |
| 30 | 26 |
| 31 /** | 27 /** |
| 32 * Build the compilation unit element for the given source. | 28 * Build the compilation unit element for the given source. |
| 33 * @param source the source describing the compilation unit | 29 * @param source the source describing the compilation unit |
| 34 * @param unit the AST structure representing the compilation unit | 30 * @param unit the AST structure representing the compilation unit |
| 35 * @return the compilation unit element that was built | 31 * @return the compilation unit element that was built |
| 36 * @throws AnalysisException if the analysis could not be performed | 32 * @throws AnalysisException if the analysis could not be performed |
| 37 */ | 33 */ |
| 38 CompilationUnitElementImpl buildCompilationUnit(Source source2, CompilationUni
t unit) { | 34 CompilationUnitElementImpl buildCompilationUnit(Source source2, CompilationUni
t unit) { |
| 39 if (unit == null) { | 35 if (unit == null) { |
| 40 return null; | 36 return null; |
| 41 } | 37 } |
| 42 ElementHolder holder = new ElementHolder(); | 38 ElementHolder holder = new ElementHolder(); |
| 43 ElementBuilder builder = new ElementBuilder(holder); | 39 ElementBuilder builder = new ElementBuilder(holder); |
| 44 unit.accept(builder); | 40 unit.accept(builder); |
| 45 CompilationUnitElementImpl element = new CompilationUnitElementImpl(source2.
shortName); | 41 CompilationUnitElementImpl element = new CompilationUnitElementImpl(source2.
shortName); |
| 46 element.accessors = holder.accessors; | 42 element.accessors = holder.accessors; |
| 47 element.functions = holder.functions; | 43 element.functions = holder.functions; |
| 48 element.source = source2; | 44 element.source = source2; |
| 49 element.typeAliases = holder.typeAliases; | 45 element.typeAliases = holder.typeAliases; |
| 50 element.types = holder.types; | 46 element.types = holder.types; |
| 51 element.topLevelVariables = holder.topLevelVariables; | 47 element.topLevelVariables = holder.topLevelVariables; |
| 52 unit.element = element; | 48 unit.element = element; |
| 53 return element; | 49 return element; |
| 54 } | 50 } |
| 55 } | 51 } |
| 56 | |
| 57 /** | 52 /** |
| 58 * Instances of the class {@code ElementBuilder} traverse an AST structure and b
uild the element | 53 * Instances of the class {@code ElementBuilder} traverse an AST structure and b
uild the element |
| 59 * model representing the AST structure. | 54 * model representing the AST structure. |
| 60 * @coverage dart.engine.resolver | 55 * @coverage dart.engine.resolver |
| 61 */ | 56 */ |
| 62 class ElementBuilder extends RecursiveASTVisitor<Object> { | 57 class ElementBuilder extends RecursiveASTVisitor<Object> { |
| 63 | 58 |
| 64 /** | 59 /** |
| 65 * The element holder associated with the element that is currently being buil
t. | 60 * The element holder associated with the element that is currently being buil
t. |
| 66 */ | 61 */ |
| 67 ElementHolder _currentHolder; | 62 ElementHolder _currentHolder; |
| 68 | 63 |
| 69 /** | 64 /** |
| 70 * A flag indicating whether a variable declaration is in the context of a fie
ld declaration. | 65 * A flag indicating whether a variable declaration is in the context of a fie
ld declaration. |
| 71 */ | 66 */ |
| 72 bool _inFieldContext = false; | 67 bool _inFieldContext = false; |
| 73 | 68 |
| 74 /** | 69 /** |
| 75 * A flag indicating whether a variable declaration is within the body of a me
thod or function. | 70 * A flag indicating whether a variable declaration is within the body of a me
thod or function. |
| 76 */ | 71 */ |
| 77 bool _inFunction = false; | 72 bool _inFunction = false; |
| 78 | 73 |
| 79 /** | 74 /** |
| 80 * A flag indicating whether the class currently being visited can be used as
a mixin. | 75 * A flag indicating whether the class currently being visited can be used as
a mixin. |
| 81 */ | 76 */ |
| 82 bool _isValidMixin = false; | 77 bool _isValidMixin = false; |
| 83 | 78 |
| 84 /** | 79 /** |
| 85 * Initialize a newly created element builder to build the elements for a comp
ilation unit. | 80 * Initialize a newly created element builder to build the elements for a comp
ilation unit. |
| 86 * @param initialHolder the element holder associated with the compilation uni
t being built | 81 * @param initialHolder the element holder associated with the compilation uni
t being built |
| 87 */ | 82 */ |
| 88 ElementBuilder(ElementHolder initialHolder) { | 83 ElementBuilder(ElementHolder initialHolder) { |
| 89 _currentHolder = initialHolder; | 84 _currentHolder = initialHolder; |
| 90 } | 85 } |
| 91 Object visitBlock(Block node) { | 86 Object visitBlock(Block node) { |
| 92 bool wasInField = _inFieldContext; | 87 bool wasInField = _inFieldContext; |
| 93 _inFieldContext = false; | 88 _inFieldContext = false; |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 if (!isFinal) { | 565 if (!isFinal) { |
| 571 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl.con
2(variable); | 566 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl.con
2(variable); |
| 572 setter.setter = true; | 567 setter.setter = true; |
| 573 setter.static = variable.isStatic(); | 568 setter.static = variable.isStatic(); |
| 574 _currentHolder.addAccessor(setter); | 569 _currentHolder.addAccessor(setter); |
| 575 variable.setter = setter; | 570 variable.setter = setter; |
| 576 } | 571 } |
| 577 } | 572 } |
| 578 return null; | 573 return null; |
| 579 } | 574 } |
| 580 | 575 |
| 581 /** | 576 /** |
| 582 * Creates the {@link ConstructorElement}s array with the single default const
ructor element. | 577 * Creates the {@link ConstructorElement}s array with the single default const
ructor element. |
| 583 * @param interfaceType the interface type for which to create a default const
ructor | 578 * @param interfaceType the interface type for which to create a default const
ructor |
| 584 * @return the {@link ConstructorElement}s array with the single default const
ructor element | 579 * @return the {@link ConstructorElement}s array with the single default const
ructor element |
| 585 */ | 580 */ |
| 586 List<ConstructorElement> createDefaultConstructors(InterfaceTypeImpl interface
Type) { | 581 List<ConstructorElement> createDefaultConstructors(InterfaceTypeImpl interface
Type) { |
| 587 ConstructorElementImpl constructor = new ConstructorElementImpl(null); | 582 ConstructorElementImpl constructor = new ConstructorElementImpl(null); |
| 588 constructor.synthetic = true; | 583 constructor.synthetic = true; |
| 589 FunctionTypeImpl type = new FunctionTypeImpl.con1(constructor); | 584 FunctionTypeImpl type = new FunctionTypeImpl.con1(constructor); |
| 590 type.returnType = interfaceType; | 585 type.returnType = interfaceType; |
| 591 constructor.type = type; | 586 constructor.type = type; |
| 592 return <ConstructorElement> [constructor]; | 587 return <ConstructorElement> [constructor]; |
| 593 } | 588 } |
| 594 List<Type2> createTypeVariableTypes(List<TypeVariableElement> typeVariables) { | 589 List<Type2> createTypeVariableTypes(List<TypeVariableElement> typeVariables) { |
| 595 int typeVariableCount = typeVariables.length; | 590 int typeVariableCount = typeVariables.length; |
| 596 List<Type2> typeArguments = new List<Type2>(typeVariableCount); | 591 List<Type2> typeArguments = new List<Type2>(typeVariableCount); |
| 597 for (int i = 0; i < typeVariableCount; i++) { | 592 for (int i = 0; i < typeVariableCount; i++) { |
| 598 TypeVariableElementImpl typeVariable = typeVariables[i] as TypeVariableEle
mentImpl; | 593 TypeVariableElementImpl typeVariable = typeVariables[i] as TypeVariableEle
mentImpl; |
| 599 TypeVariableTypeImpl typeArgument = new TypeVariableTypeImpl(typeVariable)
; | 594 TypeVariableTypeImpl typeArgument = new TypeVariableTypeImpl(typeVariable)
; |
| 600 typeVariable.type = typeArgument; | 595 typeVariable.type = typeArgument; |
| 601 typeArguments[i] = typeArgument; | 596 typeArguments[i] = typeArgument; |
| 602 } | 597 } |
| 603 return typeArguments; | 598 return typeArguments; |
| 604 } | 599 } |
| 605 | 600 |
| 606 /** | 601 /** |
| 607 * Return the body of the function that contains the given parameter, or {@cod
e null} if no | 602 * Return the body of the function that contains the given parameter, or {@cod
e null} if no |
| 608 * function body could be found. | 603 * function body could be found. |
| 609 * @param node the parameter contained in the function whose body is to be ret
urned | 604 * @param node the parameter contained in the function whose body is to be ret
urned |
| 610 * @return the body of the function that contains the given parameter | 605 * @return the body of the function that contains the given parameter |
| 611 */ | 606 */ |
| 612 FunctionBody getFunctionBody(FormalParameter node) { | 607 FunctionBody getFunctionBody(FormalParameter node) { |
| 613 ASTNode parent2 = node.parent; | 608 ASTNode parent2 = node.parent; |
| 614 while (parent2 != null) { | 609 while (parent2 != null) { |
| 615 if (parent2 is FunctionExpression) { | 610 if (parent2 is FunctionExpression) { |
| 616 return ((parent2 as FunctionExpression)).body; | 611 return ((parent2 as FunctionExpression)).body; |
| 617 } else if (parent2 is MethodDeclaration) { | 612 } else if (parent2 is MethodDeclaration) { |
| 618 return ((parent2 as MethodDeclaration)).body; | 613 return ((parent2 as MethodDeclaration)).body; |
| 619 } | 614 } |
| 620 parent2 = parent2.parent; | 615 parent2 = parent2.parent; |
| 621 } | 616 } |
| 622 return null; | 617 return null; |
| 623 } | 618 } |
| 624 | 619 |
| 625 /** | 620 /** |
| 626 * Return {@code true} if the given token is a token for the given keyword. | 621 * Return {@code true} if the given token is a token for the given keyword. |
| 627 * @param token the token being tested | 622 * @param token the token being tested |
| 628 * @param keyword the keyword being tested for | 623 * @param keyword the keyword being tested for |
| 629 * @return {@code true} if the given token is a token for the given keyword | 624 * @return {@code true} if the given token is a token for the given keyword |
| 630 */ | 625 */ |
| 631 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); | 626 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); |
| 632 | 627 |
| 633 /** | 628 /** |
| 634 * Make the given holder be the current holder while visiting the given node. | 629 * Make the given holder be the current holder while visiting the given node. |
| 635 * @param holder the holder that will gather elements that are built while vis
iting the children | 630 * @param holder the holder that will gather elements that are built while vis
iting the children |
| 636 * @param node the node to be visited | 631 * @param node the node to be visited |
| 637 */ | 632 */ |
| 638 void visit(ElementHolder holder, ASTNode node) { | 633 void visit(ElementHolder holder, ASTNode node) { |
| 639 if (node != null) { | 634 if (node != null) { |
| 640 ElementHolder previousHolder = _currentHolder; | 635 ElementHolder previousHolder = _currentHolder; |
| 641 _currentHolder = holder; | 636 _currentHolder = holder; |
| 642 try { | 637 try { |
| 643 node.accept(this); | 638 node.accept(this); |
| 644 } finally { | 639 } finally { |
| 645 _currentHolder = previousHolder; | 640 _currentHolder = previousHolder; |
| 646 } | 641 } |
| 647 } | 642 } |
| 648 } | 643 } |
| 649 | 644 |
| 650 /** | 645 /** |
| 651 * Make the given holder be the current holder while visiting the children of
the given node. | 646 * Make the given holder be the current holder while visiting the children of
the given node. |
| 652 * @param holder the holder that will gather elements that are built while vis
iting the children | 647 * @param holder the holder that will gather elements that are built while vis
iting the children |
| 653 * @param node the node whose children are to be visited | 648 * @param node the node whose children are to be visited |
| 654 */ | 649 */ |
| 655 void visitChildren(ElementHolder holder, ASTNode node) { | 650 void visitChildren(ElementHolder holder, ASTNode node) { |
| 656 if (node != null) { | 651 if (node != null) { |
| 657 ElementHolder previousHolder = _currentHolder; | 652 ElementHolder previousHolder = _currentHolder; |
| 658 _currentHolder = holder; | 653 _currentHolder = holder; |
| 659 try { | 654 try { |
| 660 node.visitChildren(this); | 655 node.visitChildren(this); |
| 661 } finally { | 656 } finally { |
| 662 _currentHolder = previousHolder; | 657 _currentHolder = previousHolder; |
| 663 } | 658 } |
| 664 } | 659 } |
| 665 } | 660 } |
| 666 } | 661 } |
| 667 | |
| 668 /** | 662 /** |
| 669 * Instances of the class {@code ElementHolder} hold on to elements created whil
e traversing an AST | 663 * Instances of the class {@code ElementHolder} hold on to elements created whil
e traversing an AST |
| 670 * structure so that they can be accessed when creating their enclosing element. | 664 * structure so that they can be accessed when creating their enclosing element. |
| 671 * @coverage dart.engine.resolver | 665 * @coverage dart.engine.resolver |
| 672 */ | 666 */ |
| 673 class ElementHolder { | 667 class ElementHolder { |
| 674 List<PropertyAccessorElement> _accessors = new List<PropertyAccessorElement>()
; | 668 List<PropertyAccessorElement> _accessors = new List<PropertyAccessorElement>()
; |
| 675 List<ConstructorElement> _constructors = new List<ConstructorElement>(); | 669 List<ConstructorElement> _constructors = new List<ConstructorElement>(); |
| 676 List<FieldElement> _fields = new List<FieldElement>(); | 670 List<FieldElement> _fields = new List<FieldElement>(); |
| 677 List<FunctionElement> _functions = new List<FunctionElement>(); | 671 List<FunctionElement> _functions = new List<FunctionElement>(); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 } | 787 } |
| 794 return new List.from(_types); | 788 return new List.from(_types); |
| 795 } | 789 } |
| 796 List<TypeVariableElement> get typeVariables { | 790 List<TypeVariableElement> get typeVariables { |
| 797 if (_typeVariables.isEmpty) { | 791 if (_typeVariables.isEmpty) { |
| 798 return TypeVariableElementImpl.EMPTY_ARRAY; | 792 return TypeVariableElementImpl.EMPTY_ARRAY; |
| 799 } | 793 } |
| 800 return new List.from(_typeVariables); | 794 return new List.from(_typeVariables); |
| 801 } | 795 } |
| 802 } | 796 } |
| 803 | |
| 804 /** | 797 /** |
| 805 * Instances of the class {@code HtmlUnitBuilder} build an element model for a s
ingle HTML unit. | 798 * Instances of the class {@code HtmlUnitBuilder} build an element model for a s
ingle HTML unit. |
| 806 */ | 799 */ |
| 807 class HtmlUnitBuilder implements ht.XmlVisitor<Object> { | 800 class HtmlUnitBuilder implements ht.XmlVisitor<Object> { |
| 808 static String _APPLICATION_DART_IN_DOUBLE_QUOTES = "\"application/dart\""; | 801 static String _APPLICATION_DART_IN_DOUBLE_QUOTES = "\"application/dart\""; |
| 809 static String _APPLICATION_DART_IN_SINGLE_QUOTES = "'application/dart'"; | 802 static String _APPLICATION_DART_IN_SINGLE_QUOTES = "'application/dart'"; |
| 810 static String _SCRIPT = "script"; | 803 static String _SCRIPT = "script"; |
| 811 static String _SRC = "src"; | 804 static String _SRC = "src"; |
| 812 static String _TYPE = "type"; | 805 static String _TYPE = "type"; |
| 813 | 806 |
| 814 /** | 807 /** |
| 815 * The analysis context in which the element model will be built. | 808 * The analysis context in which the element model will be built. |
| 816 */ | 809 */ |
| 817 InternalAnalysisContext _context; | 810 InternalAnalysisContext _context; |
| 818 | 811 |
| 819 /** | 812 /** |
| 820 * The error listener to which errors will be reported. | 813 * The error listener to which errors will be reported. |
| 821 */ | 814 */ |
| 822 RecordingErrorListener _errorListener; | 815 RecordingErrorListener _errorListener; |
| 823 | 816 |
| 824 /** | 817 /** |
| 825 * The line information associated with the source for which an element is bei
ng built, or{@code null} if we are not building an element. | 818 * The line information associated with the source for which an element is bei
ng built, or{@code null} if we are not building an element. |
| 826 */ | 819 */ |
| 827 LineInfo _lineInfo; | 820 LineInfo _lineInfo; |
| 828 | 821 |
| 829 /** | 822 /** |
| 830 * The HTML element being built. | 823 * The HTML element being built. |
| 831 */ | 824 */ |
| 832 HtmlElementImpl _htmlElement; | 825 HtmlElementImpl _htmlElement; |
| 833 | 826 |
| 834 /** | 827 /** |
| 835 * The elements in the path from the HTML unit to the current tag node. | 828 * The elements in the path from the HTML unit to the current tag node. |
| 836 */ | 829 */ |
| 837 List<ht.XmlTagNode> _parentNodes; | 830 List<ht.XmlTagNode> _parentNodes; |
| 838 | 831 |
| 839 /** | 832 /** |
| 840 * The script elements being built. | 833 * The script elements being built. |
| 841 */ | 834 */ |
| 842 List<HtmlScriptElement> _scripts; | 835 List<HtmlScriptElement> _scripts; |
| 843 | 836 |
| 844 /** | 837 /** |
| 845 * A set of the libraries that were resolved while resolving the HTML unit. | 838 * A set of the libraries that were resolved while resolving the HTML unit. |
| 846 */ | 839 */ |
| 847 Set<Library> _resolvedLibraries = new Set<Library>(); | 840 Set<Library> _resolvedLibraries = new Set<Library>(); |
| 848 | 841 |
| 849 /** | 842 /** |
| 850 * Initialize a newly created HTML unit builder. | 843 * Initialize a newly created HTML unit builder. |
| 851 * @param context the analysis context in which the element model will be buil
t | 844 * @param context the analysis context in which the element model will be buil
t |
| 852 */ | 845 */ |
| 853 HtmlUnitBuilder(InternalAnalysisContext context) { | 846 HtmlUnitBuilder(InternalAnalysisContext context) { |
| 854 this._context = context; | 847 this._context = context; |
| 855 this._errorListener = new RecordingErrorListener(); | 848 this._errorListener = new RecordingErrorListener(); |
| 856 } | 849 } |
| 857 | 850 |
| 858 /** | 851 /** |
| 859 * Build the HTML element for the given source. | 852 * Build the HTML element for the given source. |
| 860 * @param source the source describing the compilation unit | 853 * @param source the source describing the compilation unit |
| 861 * @return the HTML element that was built | 854 * @return the HTML element that was built |
| 862 * @throws AnalysisException if the analysis could not be performed | 855 * @throws AnalysisException if the analysis could not be performed |
| 863 */ | 856 */ |
| 864 HtmlElementImpl buildHtmlElement(Source source) => buildHtmlElement2(source, _
context.parseHtmlUnit(source)); | 857 HtmlElementImpl buildHtmlElement(Source source) => buildHtmlElement2(source, _
context.parseHtmlUnit(source)); |
| 865 | 858 |
| 866 /** | 859 /** |
| 867 * Build the HTML element for the given source. | 860 * Build the HTML element for the given source. |
| 868 * @param source the source describing the compilation unit | 861 * @param source the source describing the compilation unit |
| 869 * @param unit the AST structure representing the HTML | 862 * @param unit the AST structure representing the HTML |
| 870 * @throws AnalysisException if the analysis could not be performed | 863 * @throws AnalysisException if the analysis could not be performed |
| 871 */ | 864 */ |
| 872 HtmlElementImpl buildHtmlElement2(Source source2, ht.HtmlUnit unit) { | 865 HtmlElementImpl buildHtmlElement2(Source source2, ht.HtmlUnit unit) { |
| 873 _lineInfo = _context.computeLineInfo(source2); | 866 _lineInfo = _context.computeLineInfo(source2); |
| 874 HtmlElementImpl result = new HtmlElementImpl(_context, source2.shortName); | 867 HtmlElementImpl result = new HtmlElementImpl(_context, source2.shortName); |
| 875 result.source = source2; | 868 result.source = source2; |
| 876 _htmlElement = result; | 869 _htmlElement = result; |
| 877 unit.accept(this); | 870 unit.accept(this); |
| 878 _htmlElement = null; | 871 _htmlElement = null; |
| 879 unit.element = result; | 872 unit.element = result; |
| 880 return result; | 873 return result; |
| 881 } | 874 } |
| 882 | 875 |
| 883 /** | 876 /** |
| 884 * Return the listener to which analysis errors will be reported. | 877 * Return the listener to which analysis errors will be reported. |
| 885 * @return the listener to which analysis errors will be reported | 878 * @return the listener to which analysis errors will be reported |
| 886 */ | 879 */ |
| 887 RecordingErrorListener get errorListener => _errorListener; | 880 RecordingErrorListener get errorListener => _errorListener; |
| 888 | 881 |
| 889 /** | 882 /** |
| 890 * Return an array containing information about all of the libraries that were
resolved. | 883 * Return an array containing information about all of the libraries that were
resolved. |
| 891 * @return an array containing the libraries that were resolved | 884 * @return an array containing the libraries that were resolved |
| 892 */ | 885 */ |
| 893 Set<Library> get resolvedLibraries => _resolvedLibraries; | 886 Set<Library> get resolvedLibraries => _resolvedLibraries; |
| 894 Object visitHtmlUnit(ht.HtmlUnit node) { | 887 Object visitHtmlUnit(ht.HtmlUnit node) { |
| 895 _parentNodes = new List<ht.XmlTagNode>(); | 888 _parentNodes = new List<ht.XmlTagNode>(); |
| 896 _scripts = new List<HtmlScriptElement>(); | 889 _scripts = new List<HtmlScriptElement>(); |
| 897 try { | 890 try { |
| 898 node.visitChildren(this); | 891 node.visitChildren(this); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 _scripts.add(script); | 965 _scripts.add(script); |
| 973 } | 966 } |
| 974 } else { | 967 } else { |
| 975 node.visitChildren(this); | 968 node.visitChildren(this); |
| 976 } | 969 } |
| 977 } finally { | 970 } finally { |
| 978 _parentNodes.remove(node); | 971 _parentNodes.remove(node); |
| 979 } | 972 } |
| 980 return null; | 973 return null; |
| 981 } | 974 } |
| 982 | 975 |
| 983 /** | 976 /** |
| 984 * Return the first source attribute for the given tag node, or {@code null} i
f it does not exist. | 977 * Return the first source attribute for the given tag node, or {@code null} i
f it does not exist. |
| 985 * @param node the node containing attributes | 978 * @param node the node containing attributes |
| 986 * @return the source attribute contained in the given tag | 979 * @return the source attribute contained in the given tag |
| 987 */ | 980 */ |
| 988 ht.XmlAttributeNode getScriptSourcePath(ht.XmlTagNode node) { | 981 ht.XmlAttributeNode getScriptSourcePath(ht.XmlTagNode node) { |
| 989 for (ht.XmlAttributeNode attribute in node.attributes) { | 982 for (ht.XmlAttributeNode attribute in node.attributes) { |
| 990 if (attribute.name.lexeme == _SRC) { | 983 if (attribute.name.lexeme == _SRC) { |
| 991 return attribute; | 984 return attribute; |
| 992 } | 985 } |
| 993 } | 986 } |
| 994 return null; | 987 return null; |
| 995 } | 988 } |
| 996 | 989 |
| 997 /** | 990 /** |
| 998 * Determine if the specified node is a Dart script. | 991 * Determine if the specified node is a Dart script. |
| 999 * @param node the node to be tested (not {@code null}) | 992 * @param node the node to be tested (not {@code null}) |
| 1000 * @return {@code true} if the node is a Dart script | 993 * @return {@code true} if the node is a Dart script |
| 1001 */ | 994 */ |
| 1002 bool isScriptNode(ht.XmlTagNode node) { | 995 bool isScriptNode(ht.XmlTagNode node) { |
| 1003 if (node.tagNodes.length != 0 || node.tag.lexeme != _SCRIPT) { | 996 if (node.tagNodes.length != 0 || node.tag.lexeme != _SCRIPT) { |
| 1004 return false; | 997 return false; |
| 1005 } | 998 } |
| 1006 for (ht.XmlAttributeNode attribute in node.attributes) { | 999 for (ht.XmlAttributeNode attribute in node.attributes) { |
| 1007 if (attribute.name.lexeme == _TYPE) { | 1000 if (attribute.name.lexeme == _TYPE) { |
| 1008 ht.Token valueToken = attribute.value; | 1001 ht.Token valueToken = attribute.value; |
| 1009 if (valueToken != null) { | 1002 if (valueToken != null) { |
| 1010 String value = valueToken.lexeme; | 1003 String value = valueToken.lexeme; |
| 1011 if (value == _APPLICATION_DART_IN_DOUBLE_QUOTES || value == _APPLICATI
ON_DART_IN_SINGLE_QUOTES) { | 1004 if (value == _APPLICATION_DART_IN_DOUBLE_QUOTES || value == _APPLICATI
ON_DART_IN_SINGLE_QUOTES) { |
| 1012 return true; | 1005 return true; |
| 1013 } | 1006 } |
| 1014 } | 1007 } |
| 1015 } | 1008 } |
| 1016 } | 1009 } |
| 1017 return false; | 1010 return false; |
| 1018 } | 1011 } |
| 1019 | 1012 |
| 1020 /** | 1013 /** |
| 1021 * Report an error with the given error code at the given location. Use the gi
ven arguments to | 1014 * Report an error with the given error code at the given location. Use the gi
ven arguments to |
| 1022 * compose the error message. | 1015 * compose the error message. |
| 1023 * @param errorCode the error code of the error to be reported | 1016 * @param errorCode the error code of the error to be reported |
| 1024 * @param offset the offset of the first character to be highlighted | 1017 * @param offset the offset of the first character to be highlighted |
| 1025 * @param length the number of characters to be highlighted | 1018 * @param length the number of characters to be highlighted |
| 1026 * @param arguments the arguments used to compose the error message | 1019 * @param arguments the arguments used to compose the error message |
| 1027 */ | 1020 */ |
| 1028 void reportError(ErrorCode errorCode, int offset, int length, List<Object> arg
uments) { | 1021 void reportError(ErrorCode errorCode, int offset, int length, List<Object> arg
uments) { |
| 1029 _errorListener.onError(new AnalysisError.con2(_htmlElement.source, offset, l
ength, errorCode, arguments)); | 1022 _errorListener.onError(new AnalysisError.con2(_htmlElement.source, offset, l
ength, errorCode, arguments)); |
| 1030 } | 1023 } |
| 1031 } | 1024 } |
| 1032 | |
| 1033 /** | 1025 /** |
| 1034 * Instances of the class {@code DeclarationResolver} are used to resolve declar
ations in an AST | 1026 * Instances of the class {@code DeclarationResolver} are used to resolve declar
ations in an AST |
| 1035 * structure to already built elements. | 1027 * structure to already built elements. |
| 1036 */ | 1028 */ |
| 1037 class DeclarationResolver extends RecursiveASTVisitor<Object> { | 1029 class DeclarationResolver extends RecursiveASTVisitor<Object> { |
| 1038 | 1030 |
| 1039 /** | 1031 /** |
| 1040 * The compilation unit containing the AST nodes being visited. | 1032 * The compilation unit containing the AST nodes being visited. |
| 1041 */ | 1033 */ |
| 1042 CompilationUnitElement _enclosingUnit; | 1034 CompilationUnitElement _enclosingUnit; |
| 1043 | 1035 |
| 1044 /** | 1036 /** |
| 1045 * The function type alias containing the AST nodes being visited, or {@code n
ull} if we are not | 1037 * The function type alias containing the AST nodes being visited, or {@code n
ull} if we are not |
| 1046 * in the scope of a function type alias. | 1038 * in the scope of a function type alias. |
| 1047 */ | 1039 */ |
| 1048 FunctionTypeAliasElement _enclosingAlias; | 1040 FunctionTypeAliasElement _enclosingAlias; |
| 1049 | 1041 |
| 1050 /** | 1042 /** |
| 1051 * The class containing the AST nodes being visited, or {@code null} if we are
not in the scope of | 1043 * The class containing the AST nodes being visited, or {@code null} if we are
not in the scope of |
| 1052 * a class. | 1044 * a class. |
| 1053 */ | 1045 */ |
| 1054 ClassElement _enclosingClass; | 1046 ClassElement _enclosingClass; |
| 1055 | 1047 |
| 1056 /** | 1048 /** |
| 1057 * The method or function containing the AST nodes being visited, or {@code nu
ll} if we are not in | 1049 * The method or function containing the AST nodes being visited, or {@code nu
ll} if we are not in |
| 1058 * the scope of a method or function. | 1050 * the scope of a method or function. |
| 1059 */ | 1051 */ |
| 1060 ExecutableElement _enclosingExecutable; | 1052 ExecutableElement _enclosingExecutable; |
| 1061 | 1053 |
| 1062 /** | 1054 /** |
| 1063 * The parameter containing the AST nodes being visited, or {@code null} if we
are not in the | 1055 * The parameter containing the AST nodes being visited, or {@code null} if we
are not in the |
| 1064 * scope of a parameter. | 1056 * scope of a parameter. |
| 1065 */ | 1057 */ |
| 1066 ParameterElement _enclosingParameter; | 1058 ParameterElement _enclosingParameter; |
| 1067 | 1059 |
| 1068 /** | 1060 /** |
| 1069 * Resolve the declarations within the given compilation unit to the elements
rooted at the given | 1061 * Resolve the declarations within the given compilation unit to the elements
rooted at the given |
| 1070 * element. | 1062 * element. |
| 1071 * @param unit the compilation unit to be resolved | 1063 * @param unit the compilation unit to be resolved |
| 1072 * @param element the root of the element model used to resolve the AST nodes | 1064 * @param element the root of the element model used to resolve the AST nodes |
| 1073 */ | 1065 */ |
| 1074 void resolve(CompilationUnit unit, CompilationUnitElement element2) { | 1066 void resolve(CompilationUnit unit, CompilationUnitElement element2) { |
| 1075 _enclosingUnit = element2; | 1067 _enclosingUnit = element2; |
| 1076 unit.element = element2; | 1068 unit.element = element2; |
| 1077 unit.accept(this); | 1069 unit.accept(this); |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1378 } else { | 1370 } else { |
| 1379 _enclosingExecutable = element.initializer; | 1371 _enclosingExecutable = element.initializer; |
| 1380 } | 1372 } |
| 1381 return super.visitVariableDeclaration(node); | 1373 return super.visitVariableDeclaration(node); |
| 1382 } finally { | 1374 } finally { |
| 1383 _enclosingExecutable = outerExecutable; | 1375 _enclosingExecutable = outerExecutable; |
| 1384 } | 1376 } |
| 1385 } | 1377 } |
| 1386 return super.visitVariableDeclaration(node); | 1378 return super.visitVariableDeclaration(node); |
| 1387 } | 1379 } |
| 1388 | 1380 |
| 1389 /** | 1381 /** |
| 1390 * Append the value of the given string literal to the given string builder. | 1382 * Append the value of the given string literal to the given string builder. |
| 1391 * @param builder the builder to which the string's value is to be appended | 1383 * @param builder the builder to which the string's value is to be appended |
| 1392 * @param literal the string literal whose value is to be appended to the buil
der | 1384 * @param literal the string literal whose value is to be appended to the buil
der |
| 1393 * @throws IllegalArgumentException if the string is not a constant string wit
hout any string | 1385 * @throws IllegalArgumentException if the string is not a constant string wit
hout any string |
| 1394 * interpolation | 1386 * interpolation |
| 1395 */ | 1387 */ |
| 1396 void appendStringValue(JavaStringBuilder builder, StringLiteral literal) { | 1388 void appendStringValue(JavaStringBuilder builder, StringLiteral literal) { |
| 1397 if (literal is SimpleStringLiteral) { | 1389 if (literal is SimpleStringLiteral) { |
| 1398 builder.append(((literal as SimpleStringLiteral)).value); | 1390 builder.append(((literal as SimpleStringLiteral)).value); |
| 1399 } else if (literal is AdjacentStrings) { | 1391 } else if (literal is AdjacentStrings) { |
| 1400 for (StringLiteral stringLiteral in ((literal as AdjacentStrings)).strings
) { | 1392 for (StringLiteral stringLiteral in ((literal as AdjacentStrings)).strings
) { |
| 1401 appendStringValue(builder, stringLiteral); | 1393 appendStringValue(builder, stringLiteral); |
| 1402 } | 1394 } |
| 1403 } else { | 1395 } else { |
| 1404 throw new IllegalArgumentException(); | 1396 throw new IllegalArgumentException(); |
| 1405 } | 1397 } |
| 1406 } | 1398 } |
| 1407 | 1399 |
| 1408 /** | 1400 /** |
| 1409 * Return the element for the part with the given source, or {@code null} if t
here is no element | 1401 * Return the element for the part with the given source, or {@code null} if t
here is no element |
| 1410 * for the given source. | 1402 * for the given source. |
| 1411 * @param parts the elements for the parts | 1403 * @param parts the elements for the parts |
| 1412 * @param partSource the source for the part whose element is to be returned | 1404 * @param partSource the source for the part whose element is to be returned |
| 1413 * @return the element for the part with the given source | 1405 * @return the element for the part with the given source |
| 1414 */ | 1406 */ |
| 1415 CompilationUnitElement find(List<CompilationUnitElement> parts, Source partSou
rce) { | 1407 CompilationUnitElement find(List<CompilationUnitElement> parts, Source partSou
rce) { |
| 1416 for (CompilationUnitElement part in parts) { | 1408 for (CompilationUnitElement part in parts) { |
| 1417 if (part.source == partSource) { | 1409 if (part.source == partSource) { |
| 1418 return part; | 1410 return part; |
| 1419 } | 1411 } |
| 1420 } | 1412 } |
| 1421 return null; | 1413 return null; |
| 1422 } | 1414 } |
| 1423 | 1415 |
| 1424 /** | 1416 /** |
| 1425 * Return the element in the given array of elements that was created for the
declaration at the | 1417 * Return the element in the given array of elements that was created for the
declaration at the |
| 1426 * given offset. This method should only be used when there is no name | 1418 * given offset. This method should only be used when there is no name |
| 1427 * @param elements the elements of the appropriate kind that exist in the curr
ent context | 1419 * @param elements the elements of the appropriate kind that exist in the curr
ent context |
| 1428 * @param offset the offset of the name of the element to be returned | 1420 * @param offset the offset of the name of the element to be returned |
| 1429 * @return the element at the given offset | 1421 * @return the element at the given offset |
| 1430 */ | 1422 */ |
| 1431 Element find2(List<Element> elements, int offset) => find4(elements, "", offse
t); | 1423 Element find2(List<Element> elements, int offset) => find4(elements, "", offse
t); |
| 1432 | 1424 |
| 1433 /** | 1425 /** |
| 1434 * Return the element in the given array of elements that was created for the
declaration with the | 1426 * Return the element in the given array of elements that was created for the
declaration with the |
| 1435 * given name. | 1427 * given name. |
| 1436 * @param elements the elements of the appropriate kind that exist in the curr
ent context | 1428 * @param elements the elements of the appropriate kind that exist in the curr
ent context |
| 1437 * @param identifier the name node in the declaration of the element to be ret
urned | 1429 * @param identifier the name node in the declaration of the element to be ret
urned |
| 1438 * @return the element created for the declaration with the given name | 1430 * @return the element created for the declaration with the given name |
| 1439 */ | 1431 */ |
| 1440 Element find3(List<Element> elements, SimpleIdentifier identifier) { | 1432 Element find3(List<Element> elements, SimpleIdentifier identifier) { |
| 1441 Element element = find4(elements, identifier.name, identifier.offset); | 1433 Element element = find4(elements, identifier.name, identifier.offset); |
| 1442 identifier.element = element; | 1434 identifier.element = element; |
| 1443 return element; | 1435 return element; |
| 1444 } | 1436 } |
| 1445 | 1437 |
| 1446 /** | 1438 /** |
| 1447 * Return the element in the given array of elements that was created for the
declaration with the | 1439 * Return the element in the given array of elements that was created for the
declaration with the |
| 1448 * given name at the given offset. | 1440 * given name at the given offset. |
| 1449 * @param elements the elements of the appropriate kind that exist in the curr
ent context | 1441 * @param elements the elements of the appropriate kind that exist in the curr
ent context |
| 1450 * @param name the name of the element to be returned | 1442 * @param name the name of the element to be returned |
| 1451 * @param offset the offset of the name of the element to be returned | 1443 * @param offset the offset of the name of the element to be returned |
| 1452 * @return the element with the given name and offset | 1444 * @return the element with the given name and offset |
| 1453 */ | 1445 */ |
| 1454 Element find4(List<Element> elements, String name, int offset) { | 1446 Element find4(List<Element> elements, String name, int offset) { |
| 1455 for (Element element in elements) { | 1447 for (Element element in elements) { |
| 1456 if (element.displayName == name && element.nameOffset == offset) { | 1448 if (element.displayName == name && element.nameOffset == offset) { |
| 1457 return element; | 1449 return element; |
| 1458 } | 1450 } |
| 1459 } | 1451 } |
| 1460 return null; | 1452 return null; |
| 1461 } | 1453 } |
| 1462 | 1454 |
| 1463 /** | 1455 /** |
| 1464 * Return the export element from the given array whose library has the given
source, or{@code null} if there is no such export. | 1456 * Return the export element from the given array whose library has the given
source, or{@code null} if there is no such export. |
| 1465 * @param exports the export elements being searched | 1457 * @param exports the export elements being searched |
| 1466 * @param source the source of the library associated with the export element
to being searched | 1458 * @param source the source of the library associated with the export element
to being searched |
| 1467 * for | 1459 * for |
| 1468 * @return the export element whose library has the given source | 1460 * @return the export element whose library has the given source |
| 1469 */ | 1461 */ |
| 1470 ExportElement find5(List<ExportElement> exports, Source source2) { | 1462 ExportElement find5(List<ExportElement> exports, Source source2) { |
| 1471 for (ExportElement export in exports) { | 1463 for (ExportElement export in exports) { |
| 1472 if (export.exportedLibrary.source == source2) { | 1464 if (export.exportedLibrary.source == source2) { |
| 1473 return export; | 1465 return export; |
| 1474 } | 1466 } |
| 1475 } | 1467 } |
| 1476 return null; | 1468 return null; |
| 1477 } | 1469 } |
| 1478 | 1470 |
| 1479 /** | 1471 /** |
| 1480 * Return the import element from the given array whose library has the given
source and that has | 1472 * Return the import element from the given array whose library has the given
source and that has |
| 1481 * the given prefix, or {@code null} if there is no such import. | 1473 * the given prefix, or {@code null} if there is no such import. |
| 1482 * @param imports the import elements being searched | 1474 * @param imports the import elements being searched |
| 1483 * @param source the source of the library associated with the import element
to being searched | 1475 * @param source the source of the library associated with the import element
to being searched |
| 1484 * for | 1476 * for |
| 1485 * @param prefix the prefix with which the library was imported | 1477 * @param prefix the prefix with which the library was imported |
| 1486 * @return the import element whose library has the given source and prefix | 1478 * @return the import element whose library has the given source and prefix |
| 1487 */ | 1479 */ |
| 1488 ImportElement find6(List<ImportElement> imports, Source source2, SimpleIdentif
ier prefix2) { | 1480 ImportElement find6(List<ImportElement> imports, Source source2, SimpleIdentif
ier prefix2) { |
| 1489 for (ImportElement element in imports) { | 1481 for (ImportElement element in imports) { |
| 1490 if (element.importedLibrary.source == source2) { | 1482 if (element.importedLibrary.source == source2) { |
| 1491 PrefixElement prefixElement = element.prefix; | 1483 PrefixElement prefixElement = element.prefix; |
| 1492 if (prefix2 == null) { | 1484 if (prefix2 == null) { |
| 1493 if (prefixElement == null) { | 1485 if (prefixElement == null) { |
| 1494 return element; | 1486 return element; |
| 1495 } | 1487 } |
| 1496 } else { | 1488 } else { |
| 1497 if (prefixElement != null && prefix2.name == prefixElement.displayName
) { | 1489 if (prefixElement != null && prefix2.name == prefixElement.displayName
) { |
| 1498 return element; | 1490 return element; |
| 1499 } | 1491 } |
| 1500 } | 1492 } |
| 1501 } | 1493 } |
| 1502 } | 1494 } |
| 1503 return null; | 1495 return null; |
| 1504 } | 1496 } |
| 1505 | 1497 |
| 1506 /** | 1498 /** |
| 1507 * Return the value of the given string literal, or {@code null} if the string
is not a constant | 1499 * Return the value of the given string literal, or {@code null} if the string
is not a constant |
| 1508 * string without any string interpolation. | 1500 * string without any string interpolation. |
| 1509 * @param literal the string literal whose value is to be returned | 1501 * @param literal the string literal whose value is to be returned |
| 1510 * @return the value of the given string literal | 1502 * @return the value of the given string literal |
| 1511 */ | 1503 */ |
| 1512 String getStringValue(StringLiteral literal) { | 1504 String getStringValue(StringLiteral literal) { |
| 1513 if (literal is StringInterpolation) { | 1505 if (literal is StringInterpolation) { |
| 1514 return null; | 1506 return null; |
| 1515 } | 1507 } |
| 1516 JavaStringBuilder builder = new JavaStringBuilder(); | 1508 JavaStringBuilder builder = new JavaStringBuilder(); |
| 1517 try { | 1509 try { |
| 1518 appendStringValue(builder, literal); | 1510 appendStringValue(builder, literal); |
| 1519 } on IllegalArgumentException catch (exception) { | 1511 } on IllegalArgumentException catch (exception) { |
| 1520 return null; | 1512 return null; |
| 1521 } | 1513 } |
| 1522 return builder.toString().trim(); | 1514 return builder.toString().trim(); |
| 1523 } | 1515 } |
| 1524 } | 1516 } |
| 1525 | |
| 1526 /** | 1517 /** |
| 1527 * Instances of the class {@code ElementResolver} are used by instances of {@lin
k ResolverVisitor}to resolve references within the AST structure to the elements
being referenced. The requirements | 1518 * Instances of the class {@code ElementResolver} are used by instances of {@lin
k ResolverVisitor}to resolve references within the AST structure to the elements
being referenced. The requirements |
| 1528 * for the element resolver are: | 1519 * for the element resolver are: |
| 1529 * <ol> | 1520 * <ol> |
| 1530 * <li>Every {@link SimpleIdentifier} should be resolved to the element to which
it refers. | 1521 * <li>Every {@link SimpleIdentifier} should be resolved to the element to which
it refers. |
| 1531 * Specifically: | 1522 * Specifically: |
| 1532 * <ul> | 1523 * <ul> |
| 1533 * <li>An identifier within the declaration of that name should resolve to the e
lement being | 1524 * <li>An identifier within the declaration of that name should resolve to the e
lement being |
| 1534 * declared.</li> | 1525 * declared.</li> |
| 1535 * <li>An identifier denoting a prefix should resolve to the element representin
g the import that | 1526 * <li>An identifier denoting a prefix should resolve to the element representin
g the import that |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1564 * <li>Every {@link PartDirective} should resolve to the element representing th
e compilation unit | 1555 * <li>Every {@link PartDirective} should resolve to the element representing th
e compilation unit |
| 1565 * being specified by the string unless the specified compilation unit does not
exist (a{@link CompilationUnitElement}).</li> | 1556 * being specified by the string unless the specified compilation unit does not
exist (a{@link CompilationUnitElement}).</li> |
| 1566 * </ol> | 1557 * </ol> |
| 1567 * Note that AST nodes that would represent elements that are not defined are no
t resolved to | 1558 * Note that AST nodes that would represent elements that are not defined are no
t resolved to |
| 1568 * anything. This includes such things as references to undeclared variables (wh
ich is an error) and | 1559 * anything. This includes such things as references to undeclared variables (wh
ich is an error) and |
| 1569 * names in hide and show combinators that are not defined in the imported libra
ry (which is not an | 1560 * names in hide and show combinators that are not defined in the imported libra
ry (which is not an |
| 1570 * error). | 1561 * error). |
| 1571 * @coverage dart.engine.resolver | 1562 * @coverage dart.engine.resolver |
| 1572 */ | 1563 */ |
| 1573 class ElementResolver extends SimpleASTVisitor<Object> { | 1564 class ElementResolver extends SimpleASTVisitor<Object> { |
| 1574 | 1565 |
| 1575 /** | 1566 /** |
| 1576 * @return {@code true} if the given identifier is the return type of a constr
uctor declaration. | 1567 * @return {@code true} if the given identifier is the return type of a constr
uctor declaration. |
| 1577 */ | 1568 */ |
| 1578 static bool isConstructorReturnType(SimpleIdentifier node) { | 1569 static bool isConstructorReturnType(SimpleIdentifier node) { |
| 1579 ASTNode parent2 = node.parent; | 1570 ASTNode parent2 = node.parent; |
| 1580 if (parent2 is ConstructorDeclaration) { | 1571 if (parent2 is ConstructorDeclaration) { |
| 1581 ConstructorDeclaration constructor = parent2 as ConstructorDeclaration; | 1572 ConstructorDeclaration constructor = parent2 as ConstructorDeclaration; |
| 1582 return identical(constructor.returnType, node); | 1573 return identical(constructor.returnType, node); |
| 1583 } | 1574 } |
| 1584 return false; | 1575 return false; |
| 1585 } | 1576 } |
| 1586 | 1577 |
| 1587 /** | 1578 /** |
| 1588 * @return {@code true} if the given identifier is the return type of a factor
y constructor | 1579 * @return {@code true} if the given identifier is the return type of a factor
y constructor |
| 1589 * declaration. | 1580 * declaration. |
| 1590 */ | 1581 */ |
| 1591 static bool isFactoryConstructorReturnType(SimpleIdentifier node) { | 1582 static bool isFactoryConstructorReturnType(SimpleIdentifier node) { |
| 1592 ASTNode parent2 = node.parent; | 1583 ASTNode parent2 = node.parent; |
| 1593 if (parent2 is ConstructorDeclaration) { | 1584 if (parent2 is ConstructorDeclaration) { |
| 1594 ConstructorDeclaration constructor = parent2 as ConstructorDeclaration; | 1585 ConstructorDeclaration constructor = parent2 as ConstructorDeclaration; |
| 1595 return identical(constructor.returnType, node) && constructor.factoryKeywo
rd != null; | 1586 return identical(constructor.returnType, node) && constructor.factoryKeywo
rd != null; |
| 1596 } | 1587 } |
| 1597 return false; | 1588 return false; |
| 1598 } | 1589 } |
| 1599 | 1590 |
| 1600 /** | 1591 /** |
| 1601 * Checks if the given 'super' expression is used in the valid context. | 1592 * Checks if the given 'super' expression is used in the valid context. |
| 1602 * @param node the 'super' expression to analyze | 1593 * @param node the 'super' expression to analyze |
| 1603 * @return {@code true} if the given 'super' expression is in the valid contex
t | 1594 * @return {@code true} if the given 'super' expression is in the valid contex
t |
| 1604 */ | 1595 */ |
| 1605 static bool isSuperInValidContext(SuperExpression node) { | 1596 static bool isSuperInValidContext(SuperExpression node) { |
| 1606 for (ASTNode n = node; n != null; n = n.parent) { | 1597 for (ASTNode n = node; n != null; n = n.parent) { |
| 1607 if (n is CompilationUnit) { | 1598 if (n is CompilationUnit) { |
| 1608 return false; | 1599 return false; |
| 1609 } | 1600 } |
| 1610 if (n is ConstructorDeclaration) { | 1601 if (n is ConstructorDeclaration) { |
| 1611 ConstructorDeclaration constructor = n as ConstructorDeclaration; | 1602 ConstructorDeclaration constructor = n as ConstructorDeclaration; |
| 1612 return constructor.factoryKeyword == null; | 1603 return constructor.factoryKeyword == null; |
| 1613 } | 1604 } |
| 1614 if (n is ConstructorFieldInitializer) { | 1605 if (n is ConstructorFieldInitializer) { |
| 1615 return false; | 1606 return false; |
| 1616 } | 1607 } |
| 1617 if (n is MethodDeclaration) { | 1608 if (n is MethodDeclaration) { |
| 1618 MethodDeclaration method = n as MethodDeclaration; | 1609 MethodDeclaration method = n as MethodDeclaration; |
| 1619 return !method.isStatic(); | 1610 return !method.isStatic(); |
| 1620 } | 1611 } |
| 1621 } | 1612 } |
| 1622 return false; | 1613 return false; |
| 1623 } | 1614 } |
| 1624 | 1615 |
| 1625 /** | 1616 /** |
| 1626 * The resolver driving this participant. | 1617 * The resolver driving this participant. |
| 1627 */ | 1618 */ |
| 1628 ResolverVisitor _resolver; | 1619 ResolverVisitor _resolver; |
| 1629 | 1620 |
| 1621 /** |
| 1622 * A flag indicating whether we are running in strict mode. In strict mode, er
ror reporting is |
| 1623 * based exclusively on the static type information. |
| 1624 */ |
| 1625 bool _strictMode = false; |
| 1626 |
| 1630 /** | 1627 /** |
| 1631 * The name of the method that can be implemented by a class to allow its inst
ances to be invoked | 1628 * The name of the method that can be implemented by a class to allow its inst
ances to be invoked |
| 1632 * as if they were a function. | 1629 * as if they were a function. |
| 1633 */ | 1630 */ |
| 1634 static String CALL_METHOD_NAME = "call"; | 1631 static String CALL_METHOD_NAME = "call"; |
| 1635 | 1632 |
| 1636 /** | 1633 /** |
| 1637 * The name of the method that will be invoked if an attempt is made to invoke
an undefined method | 1634 * The name of the method that will be invoked if an attempt is made to invoke
an undefined method |
| 1638 * on an object. | 1635 * on an object. |
| 1639 */ | 1636 */ |
| 1640 static String _NO_SUCH_METHOD_METHOD_NAME = "noSuchMethod"; | 1637 static String _NO_SUCH_METHOD_METHOD_NAME = "noSuchMethod"; |
| 1641 | 1638 |
| 1642 /** | 1639 /** |
| 1643 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 1640 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 1644 * @param resolver the resolver driving this participant | 1641 * @param resolver the resolver driving this participant |
| 1645 */ | 1642 */ |
| 1646 ElementResolver(ResolverVisitor resolver) { | 1643 ElementResolver(ResolverVisitor resolver) { |
| 1647 this._resolver = resolver; | 1644 this._resolver = resolver; |
| 1645 _strictMode = resolver.definingLibrary.context.analysisOptions.strictMode; |
| 1648 } | 1646 } |
| 1649 Object visitAssignmentExpression(AssignmentExpression node) { | 1647 Object visitAssignmentExpression(AssignmentExpression node) { |
| 1650 sc.Token operator2 = node.operator; | 1648 sc.Token operator2 = node.operator; |
| 1651 sc.TokenType operatorType = operator2.type; | 1649 sc.TokenType operatorType = operator2.type; |
| 1652 if (operatorType != sc.TokenType.EQ) { | 1650 if (operatorType != sc.TokenType.EQ) { |
| 1653 operatorType = operatorFromCompoundAssignment(operatorType); | 1651 operatorType = operatorFromCompoundAssignment(operatorType); |
| 1654 Expression leftHandSide2 = node.leftHandSide; | 1652 Expression leftHandSide2 = node.leftHandSide; |
| 1655 if (leftHandSide2 != null) { | 1653 if (leftHandSide2 != null) { |
| 1656 String methodName = operatorType.lexeme; | 1654 String methodName = operatorType.lexeme; |
| 1657 Type2 staticType = getStaticType(leftHandSide2); | 1655 Type2 staticType = getStaticType(leftHandSide2); |
| 1658 MethodElement staticMethod = lookUpMethod(leftHandSide2, staticType, met
hodName); | 1656 MethodElement staticMethod = lookUpMethod(leftHandSide2, staticType, met
hodName); |
| 1659 node.staticElement = staticMethod; | 1657 node.staticElement = staticMethod; |
| 1660 Type2 propagatedType = getPropagatedType(leftHandSide2); | 1658 Type2 propagatedType = getPropagatedType(leftHandSide2); |
| 1661 MethodElement propagatedMethod = lookUpMethod(leftHandSide2, propagatedT
ype, methodName); | 1659 MethodElement propagatedMethod = lookUpMethod(leftHandSide2, propagatedT
ype, methodName); |
| 1662 node.element = select3(staticMethod, propagatedMethod); | 1660 node.element = select3(staticMethod, propagatedMethod); |
| 1663 if (shouldReportMissingMember(staticType, staticMethod) && (propagatedTy
pe == null || shouldReportMissingMember(propagatedType, propagatedMethod))) { | 1661 if (shouldReportMissingMember(staticType, staticMethod) && (_strictMode
|| propagatedType == null || shouldReportMissingMember(propagatedType, propagate
dMethod))) { |
| 1664 _resolver.reportError6(StaticTypeWarningCode.UNDEFINED_METHOD, operato
r2, [methodName, staticType.displayName]); | 1662 _resolver.reportError6(StaticTypeWarningCode.UNDEFINED_METHOD, operato
r2, [methodName, staticType.displayName]); |
| 1665 } | 1663 } |
| 1666 } | 1664 } |
| 1667 } | 1665 } |
| 1668 return null; | 1666 return null; |
| 1669 } | 1667 } |
| 1670 Object visitBinaryExpression(BinaryExpression node) { | 1668 Object visitBinaryExpression(BinaryExpression node) { |
| 1671 sc.Token operator2 = node.operator; | 1669 sc.Token operator2 = node.operator; |
| 1672 if (operator2.isUserDefinableOperator()) { | 1670 if (operator2.isUserDefinableOperator()) { |
| 1673 Expression leftOperand2 = node.leftOperand; | 1671 Expression leftOperand2 = node.leftOperand; |
| 1674 if (leftOperand2 != null) { | 1672 if (leftOperand2 != null) { |
| 1675 String methodName = operator2.lexeme; | 1673 String methodName = operator2.lexeme; |
| 1676 Type2 staticType = getStaticType(leftOperand2); | 1674 Type2 staticType = getStaticType(leftOperand2); |
| 1677 MethodElement staticMethod = lookUpMethod(leftOperand2, staticType, meth
odName); | 1675 MethodElement staticMethod = lookUpMethod(leftOperand2, staticType, meth
odName); |
| 1678 node.staticElement = staticMethod; | 1676 node.staticElement = staticMethod; |
| 1679 Type2 propagatedType = getPropagatedType(leftOperand2); | 1677 Type2 propagatedType = getPropagatedType(leftOperand2); |
| 1680 MethodElement propagatedMethod = lookUpMethod(leftOperand2, propagatedTy
pe, methodName); | 1678 MethodElement propagatedMethod = lookUpMethod(leftOperand2, propagatedTy
pe, methodName); |
| 1681 node.element = select3(staticMethod, propagatedMethod); | 1679 node.element = select3(staticMethod, propagatedMethod); |
| 1682 if (shouldReportMissingMember(staticType, staticMethod) && (propagatedTy
pe == null || shouldReportMissingMember(propagatedType, propagatedMethod))) { | 1680 if (shouldReportMissingMember(staticType, staticMethod) && (_strictMode
|| propagatedType == null || shouldReportMissingMember(propagatedType, propagate
dMethod))) { |
| 1683 _resolver.reportError6(StaticTypeWarningCode.UNDEFINED_OPERATOR, opera
tor2, [methodName, staticType.displayName]); | 1681 _resolver.reportError6(StaticTypeWarningCode.UNDEFINED_OPERATOR, opera
tor2, [methodName, staticType.displayName]); |
| 1684 } | 1682 } |
| 1685 } | 1683 } |
| 1686 } | 1684 } |
| 1687 return null; | 1685 return null; |
| 1688 } | 1686 } |
| 1689 Object visitBreakStatement(BreakStatement node) { | 1687 Object visitBreakStatement(BreakStatement node) { |
| 1690 SimpleIdentifier labelNode = node.label; | 1688 SimpleIdentifier labelNode = node.label; |
| 1691 LabelElementImpl labelElement = lookupLabel(node, labelNode); | 1689 LabelElementImpl labelElement = lookupLabel(node, labelNode); |
| 1692 if (labelElement != null && labelElement.isOnSwitchMember()) { | 1690 if (labelElement != null && labelElement.isOnSwitchMember()) { |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2059 } | 2057 } |
| 2060 Object visitPostfixExpression(PostfixExpression node) { | 2058 Object visitPostfixExpression(PostfixExpression node) { |
| 2061 Expression operand2 = node.operand; | 2059 Expression operand2 = node.operand; |
| 2062 String methodName = getPostfixOperator(node); | 2060 String methodName = getPostfixOperator(node); |
| 2063 Type2 staticType = getStaticType(operand2); | 2061 Type2 staticType = getStaticType(operand2); |
| 2064 MethodElement staticMethod = lookUpMethod(operand2, staticType, methodName); | 2062 MethodElement staticMethod = lookUpMethod(operand2, staticType, methodName); |
| 2065 node.staticElement = staticMethod; | 2063 node.staticElement = staticMethod; |
| 2066 Type2 propagatedType = getPropagatedType(operand2); | 2064 Type2 propagatedType = getPropagatedType(operand2); |
| 2067 MethodElement propagatedMethod = lookUpMethod(operand2, propagatedType, meth
odName); | 2065 MethodElement propagatedMethod = lookUpMethod(operand2, propagatedType, meth
odName); |
| 2068 node.element = select3(staticMethod, propagatedMethod); | 2066 node.element = select3(staticMethod, propagatedMethod); |
| 2069 if (shouldReportMissingMember(staticType, staticMethod) && (propagatedType =
= null || shouldReportMissingMember(propagatedType, propagatedMethod))) { | 2067 if (shouldReportMissingMember(staticType, staticMethod) && (_strictMode || p
ropagatedType == null || shouldReportMissingMember(propagatedType, propagatedMet
hod))) { |
| 2070 _resolver.reportError6(StaticTypeWarningCode.UNDEFINED_OPERATOR, node.oper
ator, [methodName, staticType.displayName]); | 2068 _resolver.reportError6(StaticTypeWarningCode.UNDEFINED_OPERATOR, node.oper
ator, [methodName, staticType.displayName]); |
| 2071 } | 2069 } |
| 2072 return null; | 2070 return null; |
| 2073 } | 2071 } |
| 2074 Object visitPrefixedIdentifier(PrefixedIdentifier node) { | 2072 Object visitPrefixedIdentifier(PrefixedIdentifier node) { |
| 2075 SimpleIdentifier prefix2 = node.prefix; | 2073 SimpleIdentifier prefix2 = node.prefix; |
| 2076 SimpleIdentifier identifier2 = node.identifier; | 2074 SimpleIdentifier identifier2 = node.identifier; |
| 2077 Element prefixElement = prefix2.element; | 2075 Element prefixElement = prefix2.element; |
| 2078 if (prefixElement is PrefixElement) { | 2076 if (prefixElement is PrefixElement) { |
| 2079 Element element = _resolver.nameScope.lookup(node, _resolver.definingLibra
ry); | 2077 Element element = _resolver.nameScope.lookup(node, _resolver.definingLibra
ry); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2100 sc.TokenType operatorType = operator2.type; | 2098 sc.TokenType operatorType = operator2.type; |
| 2101 if (operatorType.isUserDefinableOperator() || identical(operatorType, sc.Tok
enType.PLUS_PLUS) || identical(operatorType, sc.TokenType.MINUS_MINUS)) { | 2099 if (operatorType.isUserDefinableOperator() || identical(operatorType, sc.Tok
enType.PLUS_PLUS) || identical(operatorType, sc.TokenType.MINUS_MINUS)) { |
| 2102 Expression operand2 = node.operand; | 2100 Expression operand2 = node.operand; |
| 2103 String methodName = getPrefixOperator(node); | 2101 String methodName = getPrefixOperator(node); |
| 2104 Type2 staticType = getStaticType(operand2); | 2102 Type2 staticType = getStaticType(operand2); |
| 2105 MethodElement staticMethod = lookUpMethod(operand2, staticType, methodName
); | 2103 MethodElement staticMethod = lookUpMethod(operand2, staticType, methodName
); |
| 2106 node.staticElement = staticMethod; | 2104 node.staticElement = staticMethod; |
| 2107 Type2 propagatedType = getPropagatedType(operand2); | 2105 Type2 propagatedType = getPropagatedType(operand2); |
| 2108 MethodElement propagatedMethod = lookUpMethod(operand2, propagatedType, me
thodName); | 2106 MethodElement propagatedMethod = lookUpMethod(operand2, propagatedType, me
thodName); |
| 2109 node.element = select3(staticMethod, propagatedMethod); | 2107 node.element = select3(staticMethod, propagatedMethod); |
| 2110 if (shouldReportMissingMember(staticType, staticMethod) && (propagatedType
== null || shouldReportMissingMember(propagatedType, propagatedMethod))) { | 2108 if (shouldReportMissingMember(staticType, staticMethod) && (_strictMode ||
propagatedType == null || shouldReportMissingMember(propagatedType, propagatedM
ethod))) { |
| 2111 _resolver.reportError6(StaticTypeWarningCode.UNDEFINED_OPERATOR, operato
r2, [methodName, staticType.displayName]); | 2109 _resolver.reportError6(StaticTypeWarningCode.UNDEFINED_OPERATOR, operato
r2, [methodName, staticType.displayName]); |
| 2112 } | 2110 } |
| 2113 } | 2111 } |
| 2114 return null; | 2112 return null; |
| 2115 } | 2113 } |
| 2116 Object visitPropertyAccess(PropertyAccess node) { | 2114 Object visitPropertyAccess(PropertyAccess node) { |
| 2117 Expression target = node.realTarget; | 2115 Expression target = node.realTarget; |
| 2118 if (target is SuperExpression && !isSuperInValidContext((target as SuperExpr
ession))) { | 2116 if (target is SuperExpression && !isSuperInValidContext((target as SuperExpr
ession))) { |
| 2119 return null; | 2117 return null; |
| 2120 } | 2118 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2212 variable.bound = bound2.type; | 2210 variable.bound = bound2.type; |
| 2213 } | 2211 } |
| 2214 } | 2212 } |
| 2215 setMetadata(node.element, node); | 2213 setMetadata(node.element, node); |
| 2216 return null; | 2214 return null; |
| 2217 } | 2215 } |
| 2218 Object visitVariableDeclaration(VariableDeclaration node) { | 2216 Object visitVariableDeclaration(VariableDeclaration node) { |
| 2219 setMetadata(node.element, node); | 2217 setMetadata(node.element, node); |
| 2220 return null; | 2218 return null; |
| 2221 } | 2219 } |
| 2222 | 2220 |
| 2223 /** | 2221 /** |
| 2224 * Generate annotation elements for each of the annotations in the given node
list and add them to | 2222 * Generate annotation elements for each of the annotations in the given node
list and add them to |
| 2225 * the given list of elements. | 2223 * the given list of elements. |
| 2226 * @param annotationList the list of elements to which new elements are to be
added | 2224 * @param annotationList the list of elements to which new elements are to be
added |
| 2227 * @param annotations the AST nodes used to generate new elements | 2225 * @param annotations the AST nodes used to generate new elements |
| 2228 */ | 2226 */ |
| 2229 void addAnnotations(List<AnnotationImpl> annotationList, NodeList<Annotation>
annotations) { | 2227 void addAnnotations(List<AnnotationImpl> annotationList, NodeList<Annotation>
annotations) { |
| 2230 for (Annotation annotationNode in annotations) { | 2228 for (Annotation annotationNode in annotations) { |
| 2231 Element resolvedElement = annotationNode.element; | 2229 Element resolvedElement = annotationNode.element; |
| 2232 if (resolvedElement != null) { | 2230 if (resolvedElement != null) { |
| 2233 annotationList.add(new AnnotationImpl(resolvedElement)); | 2231 annotationList.add(new AnnotationImpl(resolvedElement)); |
| 2234 } | 2232 } |
| 2235 } | 2233 } |
| 2236 } | 2234 } |
| 2237 | 2235 |
| 2238 /** | 2236 /** |
| 2239 * Given that we have found code to invoke the given element, return the error
code that should be | 2237 * Given that we have found code to invoke the given element, return the error
code that should be |
| 2240 * reported, or {@code null} if no error should be reported. | 2238 * reported, or {@code null} if no error should be reported. |
| 2241 * @param target the target of the invocation, or {@code null} if there was no
target | 2239 * @param target the target of the invocation, or {@code null} if there was no
target |
| 2242 * @param element the element to be invoked | 2240 * @param element the element to be invoked |
| 2243 * @return the error code that should be reported | 2241 * @return the error code that should be reported |
| 2244 */ | 2242 */ |
| 2245 ErrorCode checkForInvocationError(Expression target, Element element2) { | 2243 ErrorCode checkForInvocationError(Expression target, Element element2) { |
| 2246 if (element2 is PropertyAccessorElement) { | 2244 if (element2 is PropertyAccessorElement) { |
| 2247 FunctionType getterType = ((element2 as PropertyAccessorElement)).type; | 2245 FunctionType getterType = ((element2 as PropertyAccessorElement)).type; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2290 if (targetType == null) { | 2288 if (targetType == null) { |
| 2291 return StaticTypeWarningCode.UNDEFINED_FUNCTION; | 2289 return StaticTypeWarningCode.UNDEFINED_FUNCTION; |
| 2292 } else if (!targetType.isDynamic() && !classDeclaresNoSuchMethod2(targ
etType.element)) { | 2290 } else if (!targetType.isDynamic() && !classDeclaresNoSuchMethod2(targ
etType.element)) { |
| 2293 return StaticTypeWarningCode.UNDEFINED_METHOD; | 2291 return StaticTypeWarningCode.UNDEFINED_METHOD; |
| 2294 } | 2292 } |
| 2295 } | 2293 } |
| 2296 } | 2294 } |
| 2297 } | 2295 } |
| 2298 return null; | 2296 return null; |
| 2299 } | 2297 } |
| 2300 | 2298 |
| 2301 /** | 2299 /** |
| 2302 * Return {@code true} if the given class declares a method named "noSuchMetho
d" and is not the | 2300 * Return {@code true} if the given class declares a method named "noSuchMetho
d" and is not the |
| 2303 * class 'Object'. | 2301 * class 'Object'. |
| 2304 * @param element the class being tested | 2302 * @param element the class being tested |
| 2305 * @return {@code true} if the given class declares a method named "noSuchMeth
od" | 2303 * @return {@code true} if the given class declares a method named "noSuchMeth
od" |
| 2306 */ | 2304 */ |
| 2307 bool classDeclaresNoSuchMethod(ClassElement classElement) { | 2305 bool classDeclaresNoSuchMethod(ClassElement classElement) { |
| 2308 if (classElement == null) { | 2306 if (classElement == null) { |
| 2309 return false; | 2307 return false; |
| 2310 } | 2308 } |
| 2311 MethodElement methodElement = classElement.lookUpMethod(_NO_SUCH_METHOD_METH
OD_NAME, _resolver.definingLibrary); | 2309 MethodElement methodElement = classElement.lookUpMethod(_NO_SUCH_METHOD_METH
OD_NAME, _resolver.definingLibrary); |
| 2312 return methodElement != null && methodElement.enclosingElement.supertype !=
null; | 2310 return methodElement != null && methodElement.enclosingElement.supertype !=
null; |
| 2313 } | 2311 } |
| 2314 | 2312 |
| 2315 /** | 2313 /** |
| 2316 * Return {@code true} if the given element represents a class that declares a
method named | 2314 * Return {@code true} if the given element represents a class that declares a
method named |
| 2317 * "noSuchMethod" and is not the class 'Object'. | 2315 * "noSuchMethod" and is not the class 'Object'. |
| 2318 * @param element the element being tested | 2316 * @param element the element being tested |
| 2319 * @return {@code true} if the given element represents a class that declares
a method named | 2317 * @return {@code true} if the given element represents a class that declares
a method named |
| 2320 * "noSuchMethod" | 2318 * "noSuchMethod" |
| 2321 */ | 2319 */ |
| 2322 bool classDeclaresNoSuchMethod2(Element element) { | 2320 bool classDeclaresNoSuchMethod2(Element element) { |
| 2323 if (element is ClassElement) { | 2321 if (element is ClassElement) { |
| 2324 return classDeclaresNoSuchMethod((element as ClassElement)); | 2322 return classDeclaresNoSuchMethod((element as ClassElement)); |
| 2325 } | 2323 } |
| 2326 return false; | 2324 return false; |
| 2327 } | 2325 } |
| 2328 | 2326 |
| 2329 /** | 2327 /** |
| 2330 * If the given element is a setter, return the getter associated with it. Oth
erwise, return the | 2328 * If the given element is a setter, return the getter associated with it. Oth
erwise, return the |
| 2331 * element unchanged. | 2329 * element unchanged. |
| 2332 * @param element the element to be normalized | 2330 * @param element the element to be normalized |
| 2333 * @return a non-setter element derived from the given element | 2331 * @return a non-setter element derived from the given element |
| 2334 */ | 2332 */ |
| 2335 Element convertSetterToGetter(Element element) { | 2333 Element convertSetterToGetter(Element element) { |
| 2336 if (element is PropertyAccessorElement) { | 2334 if (element is PropertyAccessorElement) { |
| 2337 return ((element as PropertyAccessorElement)).variable.getter; | 2335 return ((element as PropertyAccessorElement)).variable.getter; |
| 2338 } | 2336 } |
| 2339 return element; | 2337 return element; |
| 2340 } | 2338 } |
| 2341 | 2339 |
| 2342 /** | 2340 /** |
| 2343 * Look for any declarations of the given identifier that are imported using a
prefix. Return the | 2341 * Look for any declarations of the given identifier that are imported using a
prefix. Return the |
| 2344 * element that was found, or {@code null} if the name is not imported using a
prefix. | 2342 * element that was found, or {@code null} if the name is not imported using a
prefix. |
| 2345 * @param identifier the identifier that might have been imported using a pref
ix | 2343 * @param identifier the identifier that might have been imported using a pref
ix |
| 2346 * @return the element that was found | 2344 * @return the element that was found |
| 2347 */ | 2345 */ |
| 2348 Element findImportWithoutPrefix(SimpleIdentifier identifier) { | 2346 Element findImportWithoutPrefix(SimpleIdentifier identifier) { |
| 2349 Element element = null; | 2347 Element element = null; |
| 2350 Scope nameScope2 = _resolver.nameScope; | 2348 Scope nameScope2 = _resolver.nameScope; |
| 2351 LibraryElement definingLibrary2 = _resolver.definingLibrary; | 2349 LibraryElement definingLibrary2 = _resolver.definingLibrary; |
| 2352 for (ImportElement importElement in definingLibrary2.imports) { | 2350 for (ImportElement importElement in definingLibrary2.imports) { |
| 2353 PrefixElement prefixElement = importElement.prefix; | 2351 PrefixElement prefixElement = importElement.prefix; |
| 2354 if (prefixElement != null) { | 2352 if (prefixElement != null) { |
| 2355 Identifier prefixedIdentifier = new ElementResolver_SyntheticIdentifier(
"${prefixElement.name}.${identifier.name}"); | 2353 Identifier prefixedIdentifier = new ElementResolver_SyntheticIdentifier(
"${prefixElement.name}.${identifier.name}"); |
| 2356 Element importedElement = nameScope2.lookup(prefixedIdentifier, defining
Library2); | 2354 Element importedElement = nameScope2.lookup(prefixedIdentifier, defining
Library2); |
| 2357 if (importedElement != null) { | 2355 if (importedElement != null) { |
| 2358 if (element == null) { | 2356 if (element == null) { |
| 2359 element = importedElement; | 2357 element = importedElement; |
| 2360 } else { | 2358 } else { |
| 2361 element = new MultiplyDefinedElementImpl(definingLibrary2.context, e
lement, importedElement); | 2359 element = new MultiplyDefinedElementImpl(definingLibrary2.context, e
lement, importedElement); |
| 2362 } | 2360 } |
| 2363 } | 2361 } |
| 2364 } | 2362 } |
| 2365 } | 2363 } |
| 2366 return element; | 2364 return element; |
| 2367 } | 2365 } |
| 2368 | 2366 |
| 2369 /** | 2367 /** |
| 2370 * Return the name of the method invoked by the given postfix expression. | 2368 * Return the name of the method invoked by the given postfix expression. |
| 2371 * @param node the postfix expression being invoked | 2369 * @param node the postfix expression being invoked |
| 2372 * @return the name of the method invoked by the expression | 2370 * @return the name of the method invoked by the expression |
| 2373 */ | 2371 */ |
| 2374 String getPostfixOperator(PostfixExpression node) => (identical(node.operator.
type, sc.TokenType.PLUS_PLUS)) ? sc.TokenType.PLUS.lexeme : sc.TokenType.MINUS.l
exeme; | 2372 String getPostfixOperator(PostfixExpression node) => (identical(node.operator.
type, sc.TokenType.PLUS_PLUS)) ? sc.TokenType.PLUS.lexeme : sc.TokenType.MINUS.l
exeme; |
| 2375 | 2373 |
| 2376 /** | 2374 /** |
| 2377 * Return the name of the method invoked by the given postfix expression. | 2375 * Return the name of the method invoked by the given postfix expression. |
| 2378 * @param node the postfix expression being invoked | 2376 * @param node the postfix expression being invoked |
| 2379 * @return the name of the method invoked by the expression | 2377 * @return the name of the method invoked by the expression |
| 2380 */ | 2378 */ |
| 2381 String getPrefixOperator(PrefixExpression node) { | 2379 String getPrefixOperator(PrefixExpression node) { |
| 2382 sc.Token operator2 = node.operator; | 2380 sc.Token operator2 = node.operator; |
| 2383 sc.TokenType operatorType = operator2.type; | 2381 sc.TokenType operatorType = operator2.type; |
| 2384 if (identical(operatorType, sc.TokenType.PLUS_PLUS)) { | 2382 if (identical(operatorType, sc.TokenType.PLUS_PLUS)) { |
| 2385 return sc.TokenType.PLUS.lexeme; | 2383 return sc.TokenType.PLUS.lexeme; |
| 2386 } else if (identical(operatorType, sc.TokenType.MINUS_MINUS)) { | 2384 } else if (identical(operatorType, sc.TokenType.MINUS_MINUS)) { |
| 2387 return sc.TokenType.MINUS.lexeme; | 2385 return sc.TokenType.MINUS.lexeme; |
| 2388 } else if (identical(operatorType, sc.TokenType.MINUS)) { | 2386 } else if (identical(operatorType, sc.TokenType.MINUS)) { |
| 2389 return "unary-"; | 2387 return "unary-"; |
| 2390 } else { | 2388 } else { |
| 2391 return operator2.lexeme; | 2389 return operator2.lexeme; |
| 2392 } | 2390 } |
| 2393 } | 2391 } |
| 2394 | 2392 |
| 2395 /** | 2393 /** |
| 2396 * Return the propagated type of the given expression that is to be used for t
ype analysis. | 2394 * Return the propagated type of the given expression that is to be used for t
ype analysis. |
| 2397 * @param expression the expression whose type is to be returned | 2395 * @param expression the expression whose type is to be returned |
| 2398 * @return the type of the given expression | 2396 * @return the type of the given expression |
| 2399 */ | 2397 */ |
| 2400 Type2 getPropagatedType(Expression expression) { | 2398 Type2 getPropagatedType(Expression expression) { |
| 2401 Type2 propagatedType2 = resolveTypeVariable(expression.propagatedType); | 2399 Type2 propagatedType2 = resolveTypeVariable(expression.propagatedType); |
| 2402 if (propagatedType2 is FunctionType) { | 2400 if (propagatedType2 is FunctionType) { |
| 2403 propagatedType2 = _resolver.typeProvider.functionType; | 2401 propagatedType2 = _resolver.typeProvider.functionType; |
| 2404 } | 2402 } |
| 2405 return propagatedType2; | 2403 return propagatedType2; |
| 2406 } | 2404 } |
| 2407 | 2405 |
| 2408 /** | 2406 /** |
| 2409 * Return the static type of the given expression that is to be used for type
analysis. | 2407 * Return the static type of the given expression that is to be used for type
analysis. |
| 2410 * @param expression the expression whose type is to be returned | 2408 * @param expression the expression whose type is to be returned |
| 2411 * @return the type of the given expression | 2409 * @return the type of the given expression |
| 2412 */ | 2410 */ |
| 2413 Type2 getStaticType(Expression expression) { | 2411 Type2 getStaticType(Expression expression) { |
| 2414 if (expression is NullLiteral) { | 2412 if (expression is NullLiteral) { |
| 2415 return _resolver.typeProvider.objectType; | 2413 return _resolver.typeProvider.objectType; |
| 2416 } | 2414 } |
| 2417 Type2 staticType2 = resolveTypeVariable(expression.staticType); | 2415 Type2 staticType2 = resolveTypeVariable(expression.staticType); |
| 2418 if (staticType2 is FunctionType) { | 2416 if (staticType2 is FunctionType) { |
| 2419 staticType2 = _resolver.typeProvider.functionType; | 2417 staticType2 = _resolver.typeProvider.functionType; |
| 2420 } | 2418 } |
| 2421 return staticType2; | 2419 return staticType2; |
| 2422 } | 2420 } |
| 2423 | 2421 |
| 2424 /** | 2422 /** |
| 2425 * Return the element representing the superclass of the given class. | 2423 * Return the element representing the superclass of the given class. |
| 2426 * @param targetClass the class whose superclass is to be returned | 2424 * @param targetClass the class whose superclass is to be returned |
| 2427 * @return the element representing the superclass of the given class | 2425 * @return the element representing the superclass of the given class |
| 2428 */ | 2426 */ |
| 2429 ClassElement getSuperclass(ClassElement targetClass) { | 2427 ClassElement getSuperclass(ClassElement targetClass) { |
| 2430 InterfaceType superType = targetClass.supertype; | 2428 InterfaceType superType = targetClass.supertype; |
| 2431 if (superType == null) { | 2429 if (superType == null) { |
| 2432 return null; | 2430 return null; |
| 2433 } | 2431 } |
| 2434 return superType.element; | 2432 return superType.element; |
| 2435 } | 2433 } |
| 2436 | 2434 |
| 2437 /** | 2435 /** |
| 2438 * Return {@code true} if the given type represents an object that could be in
voked using the call | 2436 * Return {@code true} if the given type represents an object that could be in
voked using the call |
| 2439 * operator '()'. | 2437 * operator '()'. |
| 2440 * @param type the type being tested | 2438 * @param type the type being tested |
| 2441 * @return {@code true} if the given type represents an object that could be i
nvoked | 2439 * @return {@code true} if the given type represents an object that could be i
nvoked |
| 2442 */ | 2440 */ |
| 2443 bool isExecutableType(Type2 type) { | 2441 bool isExecutableType(Type2 type) { |
| 2444 if (type.isDynamic() || (type is FunctionType) || type.isDartCoreFunction())
{ | 2442 if (type.isDynamic() || (type is FunctionType) || type.isDartCoreFunction())
{ |
| 2445 return true; | 2443 return true; |
| 2446 } else if (type is InterfaceType) { | 2444 } else if (type is InterfaceType) { |
| 2447 ClassElement classElement = ((type as InterfaceType)).element; | 2445 ClassElement classElement = ((type as InterfaceType)).element; |
| 2448 MethodElement methodElement = classElement.lookUpMethod(CALL_METHOD_NAME,
_resolver.definingLibrary); | 2446 MethodElement methodElement = classElement.lookUpMethod(CALL_METHOD_NAME,
_resolver.definingLibrary); |
| 2449 return methodElement != null; | 2447 return methodElement != null; |
| 2450 } | 2448 } |
| 2451 return false; | 2449 return false; |
| 2452 } | 2450 } |
| 2453 | 2451 |
| 2454 /** | 2452 /** |
| 2455 * Return {@code true} if the given element is a static element. | 2453 * Return {@code true} if the given element is a static element. |
| 2456 * @param element the element being tested | 2454 * @param element the element being tested |
| 2457 * @return {@code true} if the given element is a static element | 2455 * @return {@code true} if the given element is a static element |
| 2458 */ | 2456 */ |
| 2459 bool isStatic(Element element) { | 2457 bool isStatic(Element element) { |
| 2460 if (element is ExecutableElement) { | 2458 if (element is ExecutableElement) { |
| 2461 return ((element as ExecutableElement)).isStatic(); | 2459 return ((element as ExecutableElement)).isStatic(); |
| 2462 } else if (element is PropertyInducingElement) { | 2460 } else if (element is PropertyInducingElement) { |
| 2463 return ((element as PropertyInducingElement)).isStatic(); | 2461 return ((element as PropertyInducingElement)).isStatic(); |
| 2464 } | 2462 } |
| 2465 return false; | 2463 return false; |
| 2466 } | 2464 } |
| 2467 | 2465 |
| 2468 /** | 2466 /** |
| 2469 * Looks up the method element with the given name for index expression, repor
ts{@link StaticWarningCode#UNDEFINED_OPERATOR} if not found. | 2467 * Looks up the method element with the given name for index expression, repor
ts{@link StaticWarningCode#UNDEFINED_OPERATOR} if not found. |
| 2470 * @param node the index expression to resolve | 2468 * @param node the index expression to resolve |
| 2471 * @param target the target of the expression | 2469 * @param target the target of the expression |
| 2472 * @param methodName the name of the operator associated with the context of u
sing of the given | 2470 * @param methodName the name of the operator associated with the context of u
sing of the given |
| 2473 * index expression | 2471 * index expression |
| 2474 * @return {@code true} if and only if an error code is generated on the passe
d node | 2472 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 2475 */ | 2473 */ |
| 2476 bool lookUpCheckIndexOperator(IndexExpression node, Expression target, String
methodName, Type2 staticType, Type2 propagatedType) { | 2474 bool lookUpCheckIndexOperator(IndexExpression node, Expression target, String
methodName, Type2 staticType, Type2 propagatedType) { |
| 2477 MethodElement staticMethod = lookUpMethod(target, staticType, methodName); | 2475 MethodElement staticMethod = lookUpMethod(target, staticType, methodName); |
| 2478 MethodElement propagatedMethod = lookUpMethod(target, propagatedType, method
Name); | 2476 MethodElement propagatedMethod = lookUpMethod(target, propagatedType, method
Name); |
| 2479 node.staticElement = staticMethod; | 2477 node.staticElement = staticMethod; |
| 2480 node.element = select3(staticMethod, propagatedMethod); | 2478 node.element = select3(staticMethod, propagatedMethod); |
| 2481 if (shouldReportMissingMember(staticType, staticMethod) && (propagatedType =
= null || shouldReportMissingMember(propagatedType, propagatedMethod))) { | 2479 if (shouldReportMissingMember(staticType, staticMethod) && (_strictMode || p
ropagatedType == null || shouldReportMissingMember(propagatedType, propagatedMet
hod))) { |
| 2482 sc.Token leftBracket2 = node.leftBracket; | 2480 sc.Token leftBracket2 = node.leftBracket; |
| 2483 sc.Token rightBracket2 = node.rightBracket; | 2481 sc.Token rightBracket2 = node.rightBracket; |
| 2484 if (leftBracket2 == null || rightBracket2 == null) { | 2482 if (leftBracket2 == null || rightBracket2 == null) { |
| 2485 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_OPERATOR, node, [m
ethodName, staticType.displayName]); | 2483 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_OPERATOR, node, [m
ethodName, staticType.displayName]); |
| 2486 return true; | 2484 return true; |
| 2487 } else { | 2485 } else { |
| 2488 int offset2 = leftBracket2.offset; | 2486 int offset2 = leftBracket2.offset; |
| 2489 int length = rightBracket2.offset - offset2 + 1; | 2487 int length = rightBracket2.offset - offset2 + 1; |
| 2490 _resolver.reportError5(StaticTypeWarningCode.UNDEFINED_OPERATOR, offset2
, length, [methodName, staticType.displayName]); | 2488 _resolver.reportError5(StaticTypeWarningCode.UNDEFINED_OPERATOR, offset2
, length, [methodName, staticType.displayName]); |
| 2491 return true; | 2489 return true; |
| 2492 } | 2490 } |
| 2493 } | 2491 } |
| 2494 return false; | 2492 return false; |
| 2495 } | 2493 } |
| 2496 | 2494 |
| 2497 /** | 2495 /** |
| 2498 * Look up the getter with the given name in the given type. Return the elemen
t representing the | 2496 * Look up the getter with the given name in the given type. Return the elemen
t representing the |
| 2499 * getter that was found, or {@code null} if there is no getter with the given
name. | 2497 * getter that was found, or {@code null} if there is no getter with the given
name. |
| 2500 * @param target the target of the invocation, or {@code null} if there is no
target | 2498 * @param target the target of the invocation, or {@code null} if there is no
target |
| 2501 * @param type the type in which the getter is defined | 2499 * @param type the type in which the getter is defined |
| 2502 * @param getterName the name of the getter being looked up | 2500 * @param getterName the name of the getter being looked up |
| 2503 * @return the element representing the getter that was found | 2501 * @return the element representing the getter that was found |
| 2504 */ | 2502 */ |
| 2505 PropertyAccessorElement lookUpGetter(Expression target, Type2 type, String get
terName) { | 2503 PropertyAccessorElement lookUpGetter(Expression target, Type2 type, String get
terName) { |
| 2506 type = resolveTypeVariable(type); | 2504 type = resolveTypeVariable(type); |
| 2507 if (type is InterfaceType) { | 2505 if (type is InterfaceType) { |
| 2508 InterfaceType interfaceType = type as InterfaceType; | 2506 InterfaceType interfaceType = type as InterfaceType; |
| 2509 PropertyAccessorElement accessor; | 2507 PropertyAccessorElement accessor; |
| 2510 if (target is SuperExpression) { | 2508 if (target is SuperExpression) { |
| 2511 accessor = interfaceType.lookUpGetterInSuperclass(getterName, _resolver.
definingLibrary); | 2509 accessor = interfaceType.lookUpGetterInSuperclass(getterName, _resolver.
definingLibrary); |
| 2512 } else { | 2510 } else { |
| 2513 accessor = interfaceType.lookUpGetter(getterName, _resolver.definingLibr
ary); | 2511 accessor = interfaceType.lookUpGetter(getterName, _resolver.definingLibr
ary); |
| 2514 } | 2512 } |
| 2515 if (accessor != null) { | 2513 if (accessor != null) { |
| 2516 return accessor; | 2514 return accessor; |
| 2517 } | 2515 } |
| 2518 return lookUpGetterInInterfaces(interfaceType, false, getterName, new Set<
ClassElement>()); | 2516 return lookUpGetterInInterfaces(interfaceType, false, getterName, new Set<
ClassElement>()); |
| 2519 } | 2517 } |
| 2520 return null; | 2518 return null; |
| 2521 } | 2519 } |
| 2522 | 2520 |
| 2523 /** | 2521 /** |
| 2524 * Look up the getter with the given name in the interfaces implemented by the
given type, either | 2522 * Look up the getter with the given name in the interfaces implemented by the
given type, either |
| 2525 * directly or indirectly. Return the element representing the getter that was
found, or{@code null} if there is no getter with the given name. | 2523 * directly or indirectly. Return the element representing the getter that was
found, or{@code null} if there is no getter with the given name. |
| 2526 * @param targetType the type in which the getter might be defined | 2524 * @param targetType the type in which the getter might be defined |
| 2527 * @param includeTargetType {@code true} if the search should include the targ
et type | 2525 * @param includeTargetType {@code true} if the search should include the targ
et type |
| 2528 * @param getterName the name of the getter being looked up | 2526 * @param getterName the name of the getter being looked up |
| 2529 * @param visitedInterfaces a set containing all of the interfaces that have b
een examined, used | 2527 * @param visitedInterfaces a set containing all of the interfaces that have b
een examined, used |
| 2530 * to prevent infinite recursion and to optimize the search | 2528 * to prevent infinite recursion and to optimize the search |
| 2531 * @return the element representing the getter that was found | 2529 * @return the element representing the getter that was found |
| 2532 */ | 2530 */ |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2547 if (getter != null) { | 2545 if (getter != null) { |
| 2548 return getter; | 2546 return getter; |
| 2549 } | 2547 } |
| 2550 } | 2548 } |
| 2551 InterfaceType superclass2 = targetType.superclass; | 2549 InterfaceType superclass2 = targetType.superclass; |
| 2552 if (superclass2 == null) { | 2550 if (superclass2 == null) { |
| 2553 return null; | 2551 return null; |
| 2554 } | 2552 } |
| 2555 return lookUpGetterInInterfaces(superclass2, true, getterName, visitedInterf
aces); | 2553 return lookUpGetterInInterfaces(superclass2, true, getterName, visitedInterf
aces); |
| 2556 } | 2554 } |
| 2557 | 2555 |
| 2558 /** | 2556 /** |
| 2559 * Look up the method or getter with the given name in the given type. Return
the element | 2557 * Look up the method or getter with the given name in the given type. Return
the element |
| 2560 * representing the method or getter that was found, or {@code null} if there
is no method or | 2558 * representing the method or getter that was found, or {@code null} if there
is no method or |
| 2561 * getter with the given name. | 2559 * getter with the given name. |
| 2562 * @param type the type in which the method or getter is defined | 2560 * @param type the type in which the method or getter is defined |
| 2563 * @param memberName the name of the method or getter being looked up | 2561 * @param memberName the name of the method or getter being looked up |
| 2564 * @return the element representing the method or getter that was found | 2562 * @return the element representing the method or getter that was found |
| 2565 */ | 2563 */ |
| 2566 ExecutableElement lookupGetterOrMethod(Type2 type, String memberName) { | 2564 ExecutableElement lookupGetterOrMethod(Type2 type, String memberName) { |
| 2567 type = resolveTypeVariable(type); | 2565 type = resolveTypeVariable(type); |
| 2568 if (type is InterfaceType) { | 2566 if (type is InterfaceType) { |
| 2569 InterfaceType interfaceType = type as InterfaceType; | 2567 InterfaceType interfaceType = type as InterfaceType; |
| 2570 ExecutableElement member = interfaceType.lookUpMethod(memberName, _resolve
r.definingLibrary); | 2568 ExecutableElement member = interfaceType.lookUpMethod(memberName, _resolve
r.definingLibrary); |
| 2571 if (member != null) { | 2569 if (member != null) { |
| 2572 return member; | 2570 return member; |
| 2573 } | 2571 } |
| 2574 member = interfaceType.lookUpGetter(memberName, _resolver.definingLibrary)
; | 2572 member = interfaceType.lookUpGetter(memberName, _resolver.definingLibrary)
; |
| 2575 if (member != null) { | 2573 if (member != null) { |
| 2576 return member; | 2574 return member; |
| 2577 } | 2575 } |
| 2578 return lookUpGetterOrMethodInInterfaces(interfaceType, false, memberName,
new Set<ClassElement>()); | 2576 return lookUpGetterOrMethodInInterfaces(interfaceType, false, memberName,
new Set<ClassElement>()); |
| 2579 } | 2577 } |
| 2580 return null; | 2578 return null; |
| 2581 } | 2579 } |
| 2582 | 2580 |
| 2583 /** | 2581 /** |
| 2584 * Look up the method or getter with the given name in the interfaces implemen
ted by the given | 2582 * Look up the method or getter with the given name in the interfaces implemen
ted by the given |
| 2585 * type, either directly or indirectly. Return the element representing the me
thod or getter that | 2583 * type, either directly or indirectly. Return the element representing the me
thod or getter that |
| 2586 * was found, or {@code null} if there is no method or getter with the given n
ame. | 2584 * was found, or {@code null} if there is no method or getter with the given n
ame. |
| 2587 * @param targetType the type in which the method or getter might be defined | 2585 * @param targetType the type in which the method or getter might be defined |
| 2588 * @param includeTargetType {@code true} if the search should include the targ
et type | 2586 * @param includeTargetType {@code true} if the search should include the targ
et type |
| 2589 * @param memberName the name of the method or getter being looked up | 2587 * @param memberName the name of the method or getter being looked up |
| 2590 * @param visitedInterfaces a set containing all of the interfaces that have b
een examined, used | 2588 * @param visitedInterfaces a set containing all of the interfaces that have b
een examined, used |
| 2591 * to prevent infinite recursion and to optimize the search | 2589 * to prevent infinite recursion and to optimize the search |
| 2592 * @return the element representing the method or getter that was found | 2590 * @return the element representing the method or getter that was found |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2612 if (member != null) { | 2610 if (member != null) { |
| 2613 return member; | 2611 return member; |
| 2614 } | 2612 } |
| 2615 } | 2613 } |
| 2616 InterfaceType superclass2 = targetType.superclass; | 2614 InterfaceType superclass2 = targetType.superclass; |
| 2617 if (superclass2 == null) { | 2615 if (superclass2 == null) { |
| 2618 return null; | 2616 return null; |
| 2619 } | 2617 } |
| 2620 return lookUpGetterOrMethodInInterfaces(superclass2, true, memberName, visit
edInterfaces); | 2618 return lookUpGetterOrMethodInInterfaces(superclass2, true, memberName, visit
edInterfaces); |
| 2621 } | 2619 } |
| 2622 | 2620 |
| 2623 /** | 2621 /** |
| 2624 * Find the element corresponding to the given label node in the current label
scope. | 2622 * Find the element corresponding to the given label node in the current label
scope. |
| 2625 * @param parentNode the node containing the given label | 2623 * @param parentNode the node containing the given label |
| 2626 * @param labelNode the node representing the label being looked up | 2624 * @param labelNode the node representing the label being looked up |
| 2627 * @return the element corresponding to the given label node in the current sc
ope | 2625 * @return the element corresponding to the given label node in the current sc
ope |
| 2628 */ | 2626 */ |
| 2629 LabelElementImpl lookupLabel(ASTNode parentNode, SimpleIdentifier labelNode) { | 2627 LabelElementImpl lookupLabel(ASTNode parentNode, SimpleIdentifier labelNode) { |
| 2630 LabelScope labelScope2 = _resolver.labelScope; | 2628 LabelScope labelScope2 = _resolver.labelScope; |
| 2631 LabelElementImpl labelElement = null; | 2629 LabelElementImpl labelElement = null; |
| 2632 if (labelNode == null) { | 2630 if (labelNode == null) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2651 } | 2649 } |
| 2652 if (labelElement != null) { | 2650 if (labelElement != null) { |
| 2653 ExecutableElement labelContainer = labelElement.getAncestor(ExecutableElem
ent); | 2651 ExecutableElement labelContainer = labelElement.getAncestor(ExecutableElem
ent); |
| 2654 if (labelContainer != _resolver.enclosingFunction) { | 2652 if (labelContainer != _resolver.enclosingFunction) { |
| 2655 _resolver.reportError(CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE, labelNo
de, [labelNode.name]); | 2653 _resolver.reportError(CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE, labelNo
de, [labelNode.name]); |
| 2656 labelElement = null; | 2654 labelElement = null; |
| 2657 } | 2655 } |
| 2658 } | 2656 } |
| 2659 return labelElement; | 2657 return labelElement; |
| 2660 } | 2658 } |
| 2661 | 2659 |
| 2662 /** | 2660 /** |
| 2663 * Look up the method with the given name in the given type. Return the elemen
t representing the | 2661 * Look up the method with the given name in the given type. Return the elemen
t representing the |
| 2664 * method that was found, or {@code null} if there is no method with the given
name. | 2662 * method that was found, or {@code null} if there is no method with the given
name. |
| 2665 * @param target the target of the invocation, or {@code null} if there is no
target | 2663 * @param target the target of the invocation, or {@code null} if there is no
target |
| 2666 * @param type the type in which the method is defined | 2664 * @param type the type in which the method is defined |
| 2667 * @param methodName the name of the method being looked up | 2665 * @param methodName the name of the method being looked up |
| 2668 * @return the element representing the method that was found | 2666 * @return the element representing the method that was found |
| 2669 */ | 2667 */ |
| 2670 MethodElement lookUpMethod(Expression target, Type2 type, String methodName) { | 2668 MethodElement lookUpMethod(Expression target, Type2 type, String methodName) { |
| 2671 type = resolveTypeVariable(type); | 2669 type = resolveTypeVariable(type); |
| 2672 if (type is InterfaceType) { | 2670 if (type is InterfaceType) { |
| 2673 InterfaceType interfaceType = type as InterfaceType; | 2671 InterfaceType interfaceType = type as InterfaceType; |
| 2674 MethodElement method; | 2672 MethodElement method; |
| 2675 if (target is SuperExpression) { | 2673 if (target is SuperExpression) { |
| 2676 method = interfaceType.lookUpMethodInSuperclass(methodName, _resolver.de
finingLibrary); | 2674 method = interfaceType.lookUpMethodInSuperclass(methodName, _resolver.de
finingLibrary); |
| 2677 } else { | 2675 } else { |
| 2678 method = interfaceType.lookUpMethod(methodName, _resolver.definingLibrar
y); | 2676 method = interfaceType.lookUpMethod(methodName, _resolver.definingLibrar
y); |
| 2679 } | 2677 } |
| 2680 if (method != null) { | 2678 if (method != null) { |
| 2681 return method; | 2679 return method; |
| 2682 } | 2680 } |
| 2683 return lookUpMethodInInterfaces(interfaceType, false, methodName, new Set<
ClassElement>()); | 2681 return lookUpMethodInInterfaces(interfaceType, false, methodName, new Set<
ClassElement>()); |
| 2684 } | 2682 } |
| 2685 return null; | 2683 return null; |
| 2686 } | 2684 } |
| 2687 | 2685 |
| 2688 /** | 2686 /** |
| 2689 * Look up the method with the given name in the interfaces implemented by the
given type, either | 2687 * Look up the method with the given name in the interfaces implemented by the
given type, either |
| 2690 * directly or indirectly. Return the element representing the method that was
found, or{@code null} if there is no method with the given name. | 2688 * directly or indirectly. Return the element representing the method that was
found, or{@code null} if there is no method with the given name. |
| 2691 * @param targetType the type in which the member might be defined | 2689 * @param targetType the type in which the member might be defined |
| 2692 * @param includeTargetType {@code true} if the search should include the targ
et type | 2690 * @param includeTargetType {@code true} if the search should include the targ
et type |
| 2693 * @param methodName the name of the method being looked up | 2691 * @param methodName the name of the method being looked up |
| 2694 * @param visitedInterfaces a set containing all of the interfaces that have b
een examined, used | 2692 * @param visitedInterfaces a set containing all of the interfaces that have b
een examined, used |
| 2695 * to prevent infinite recursion and to optimize the search | 2693 * to prevent infinite recursion and to optimize the search |
| 2696 * @return the element representing the method that was found | 2694 * @return the element representing the method that was found |
| 2697 */ | 2695 */ |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2712 if (method != null) { | 2710 if (method != null) { |
| 2713 return method; | 2711 return method; |
| 2714 } | 2712 } |
| 2715 } | 2713 } |
| 2716 InterfaceType superclass2 = targetType.superclass; | 2714 InterfaceType superclass2 = targetType.superclass; |
| 2717 if (superclass2 == null) { | 2715 if (superclass2 == null) { |
| 2718 return null; | 2716 return null; |
| 2719 } | 2717 } |
| 2720 return lookUpMethodInInterfaces(superclass2, true, methodName, visitedInterf
aces); | 2718 return lookUpMethodInInterfaces(superclass2, true, methodName, visitedInterf
aces); |
| 2721 } | 2719 } |
| 2722 | 2720 |
| 2723 /** | 2721 /** |
| 2724 * Look up the setter with the given name in the given type. Return the elemen
t representing the | 2722 * Look up the setter with the given name in the given type. Return the elemen
t representing the |
| 2725 * setter that was found, or {@code null} if there is no setter with the given
name. | 2723 * setter that was found, or {@code null} if there is no setter with the given
name. |
| 2726 * @param target the target of the invocation, or {@code null} if there is no
target | 2724 * @param target the target of the invocation, or {@code null} if there is no
target |
| 2727 * @param type the type in which the setter is defined | 2725 * @param type the type in which the setter is defined |
| 2728 * @param setterName the name of the setter being looked up | 2726 * @param setterName the name of the setter being looked up |
| 2729 * @return the element representing the setter that was found | 2727 * @return the element representing the setter that was found |
| 2730 */ | 2728 */ |
| 2731 PropertyAccessorElement lookUpSetter(Expression target, Type2 type, String set
terName) { | 2729 PropertyAccessorElement lookUpSetter(Expression target, Type2 type, String set
terName) { |
| 2732 type = resolveTypeVariable(type); | 2730 type = resolveTypeVariable(type); |
| 2733 if (type is InterfaceType) { | 2731 if (type is InterfaceType) { |
| 2734 InterfaceType interfaceType = type as InterfaceType; | 2732 InterfaceType interfaceType = type as InterfaceType; |
| 2735 PropertyAccessorElement accessor; | 2733 PropertyAccessorElement accessor; |
| 2736 if (target is SuperExpression) { | 2734 if (target is SuperExpression) { |
| 2737 accessor = interfaceType.lookUpSetterInSuperclass(setterName, _resolver.
definingLibrary); | 2735 accessor = interfaceType.lookUpSetterInSuperclass(setterName, _resolver.
definingLibrary); |
| 2738 } else { | 2736 } else { |
| 2739 accessor = interfaceType.lookUpSetter(setterName, _resolver.definingLibr
ary); | 2737 accessor = interfaceType.lookUpSetter(setterName, _resolver.definingLibr
ary); |
| 2740 } | 2738 } |
| 2741 if (accessor != null) { | 2739 if (accessor != null) { |
| 2742 return accessor; | 2740 return accessor; |
| 2743 } | 2741 } |
| 2744 return lookUpSetterInInterfaces(interfaceType, false, setterName, new Set<
ClassElement>()); | 2742 return lookUpSetterInInterfaces(interfaceType, false, setterName, new Set<
ClassElement>()); |
| 2745 } | 2743 } |
| 2746 return null; | 2744 return null; |
| 2747 } | 2745 } |
| 2748 | 2746 |
| 2749 /** | 2747 /** |
| 2750 * Look up the setter with the given name in the interfaces implemented by the
given type, either | 2748 * Look up the setter with the given name in the interfaces implemented by the
given type, either |
| 2751 * directly or indirectly. Return the element representing the setter that was
found, or{@code null} if there is no setter with the given name. | 2749 * directly or indirectly. Return the element representing the setter that was
found, or{@code null} if there is no setter with the given name. |
| 2752 * @param targetType the type in which the setter might be defined | 2750 * @param targetType the type in which the setter might be defined |
| 2753 * @param includeTargetType {@code true} if the search should include the targ
et type | 2751 * @param includeTargetType {@code true} if the search should include the targ
et type |
| 2754 * @param setterName the name of the setter being looked up | 2752 * @param setterName the name of the setter being looked up |
| 2755 * @param visitedInterfaces a set containing all of the interfaces that have b
een examined, used | 2753 * @param visitedInterfaces a set containing all of the interfaces that have b
een examined, used |
| 2756 * to prevent infinite recursion and to optimize the search | 2754 * to prevent infinite recursion and to optimize the search |
| 2757 * @return the element representing the setter that was found | 2755 * @return the element representing the setter that was found |
| 2758 */ | 2756 */ |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2773 if (setter != null) { | 2771 if (setter != null) { |
| 2774 return setter; | 2772 return setter; |
| 2775 } | 2773 } |
| 2776 } | 2774 } |
| 2777 InterfaceType superclass2 = targetType.superclass; | 2775 InterfaceType superclass2 = targetType.superclass; |
| 2778 if (superclass2 == null) { | 2776 if (superclass2 == null) { |
| 2779 return null; | 2777 return null; |
| 2780 } | 2778 } |
| 2781 return lookUpSetterInInterfaces(superclass2, true, setterName, visitedInterf
aces); | 2779 return lookUpSetterInInterfaces(superclass2, true, setterName, visitedInterf
aces); |
| 2782 } | 2780 } |
| 2783 | 2781 |
| 2784 /** | 2782 /** |
| 2785 * Return the binary operator that is invoked by the given compound assignment
operator. | 2783 * Return the binary operator that is invoked by the given compound assignment
operator. |
| 2786 * @param operator the assignment operator being mapped | 2784 * @param operator the assignment operator being mapped |
| 2787 * @return the binary operator that invoked by the given assignment operator | 2785 * @return the binary operator that invoked by the given assignment operator |
| 2788 */ | 2786 */ |
| 2789 sc.TokenType operatorFromCompoundAssignment(sc.TokenType operator) { | 2787 sc.TokenType operatorFromCompoundAssignment(sc.TokenType operator) { |
| 2790 while (true) { | 2788 while (true) { |
| 2791 if (operator == sc.TokenType.AMPERSAND_EQ) { | 2789 if (operator == sc.TokenType.AMPERSAND_EQ) { |
| 2792 return sc.TokenType.AMPERSAND; | 2790 return sc.TokenType.AMPERSAND; |
| 2793 } else if (operator == sc.TokenType.BAR_EQ) { | 2791 } else if (operator == sc.TokenType.BAR_EQ) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2809 } else if (operator == sc.TokenType.STAR_EQ) { | 2807 } else if (operator == sc.TokenType.STAR_EQ) { |
| 2810 return sc.TokenType.STAR; | 2808 return sc.TokenType.STAR; |
| 2811 } else if (operator == sc.TokenType.TILDE_SLASH_EQ) { | 2809 } else if (operator == sc.TokenType.TILDE_SLASH_EQ) { |
| 2812 return sc.TokenType.TILDE_SLASH; | 2810 return sc.TokenType.TILDE_SLASH; |
| 2813 } | 2811 } |
| 2814 break; | 2812 break; |
| 2815 } | 2813 } |
| 2816 AnalysisEngine.instance.logger.logError("Failed to map ${operator.lexeme} to
it's corresponding operator"); | 2814 AnalysisEngine.instance.logger.logError("Failed to map ${operator.lexeme} to
it's corresponding operator"); |
| 2817 return operator; | 2815 return operator; |
| 2818 } | 2816 } |
| 2819 | 2817 |
| 2820 /** | 2818 /** |
| 2821 * Record the fact that the given AST node was resolved to the given element. | 2819 * Record the fact that the given AST node was resolved to the given element. |
| 2822 * @param node the AST node that was resolved | 2820 * @param node the AST node that was resolved |
| 2823 * @param element the element to which the AST node was resolved | 2821 * @param element the element to which the AST node was resolved |
| 2824 */ | 2822 */ |
| 2825 void recordResolution(SimpleIdentifier node, Element element2) { | 2823 void recordResolution(SimpleIdentifier node, Element element2) { |
| 2826 node.staticElement = element2; | 2824 node.staticElement = element2; |
| 2827 node.element = element2; | 2825 node.element = element2; |
| 2828 } | 2826 } |
| 2829 | 2827 |
| 2830 /** | 2828 /** |
| 2831 * Record the fact that the given AST node was resolved to the given elements. | 2829 * Record the fact that the given AST node was resolved to the given elements. |
| 2832 * @param node the AST node that was resolved | 2830 * @param node the AST node that was resolved |
| 2833 * @param staticElement the element to which the AST node was resolved using s
tatic type | 2831 * @param staticElement the element to which the AST node was resolved using s
tatic type |
| 2834 * information | 2832 * information |
| 2835 * @param propagatedElement the element to which the AST node was resolved usi
ng propagated type | 2833 * @param propagatedElement the element to which the AST node was resolved usi
ng propagated type |
| 2836 * information | 2834 * information |
| 2837 * @return the element that was associated with the node | 2835 * @return the element that was associated with the node |
| 2838 */ | 2836 */ |
| 2839 Element recordResolution2(SimpleIdentifier node, Element staticElement2, Eleme
nt propagatedElement) { | 2837 Element recordResolution2(SimpleIdentifier node, Element staticElement2, Eleme
nt propagatedElement) { |
| 2840 node.staticElement = staticElement2; | 2838 node.staticElement = staticElement2; |
| 2841 Element element = propagatedElement == null ? staticElement2 : propagatedEle
ment; | 2839 Element element = propagatedElement == null ? staticElement2 : propagatedEle
ment; |
| 2842 node.element = element; | 2840 node.element = element; |
| 2843 return element; | 2841 return element; |
| 2844 } | 2842 } |
| 2845 | 2843 |
| 2846 /** | 2844 /** |
| 2847 * Given a list of arguments and the element that will be invoked using those
argument, compute | 2845 * Given a list of arguments and the element that will be invoked using those
argument, compute |
| 2848 * the list of parameters that correspond to the list of arguments. | 2846 * the list of parameters that correspond to the list of arguments. |
| 2849 * @param reportError if {@code true} then compile-time error should be report
ed; if {@code false}then compile-time warning | 2847 * @param reportError if {@code true} then compile-time error should be report
ed; if {@code false}then compile-time warning |
| 2850 * @param argumentList the list of arguments being passed to the element | 2848 * @param argumentList the list of arguments being passed to the element |
| 2851 * @param executableElement the element that will be invoked with the argument
s | 2849 * @param executableElement the element that will be invoked with the argument
s |
| 2852 */ | 2850 */ |
| 2853 void resolveArgumentsToParameters(bool reportError, ArgumentList argumentList,
ExecutableElement executableElement) { | 2851 void resolveArgumentsToParameters(bool reportError, ArgumentList argumentList,
ExecutableElement executableElement) { |
| 2854 if (executableElement == null) { | 2852 if (executableElement == null) { |
| 2855 return; | 2853 return; |
| 2856 } | 2854 } |
| 2857 List<ParameterElement> parameters2 = executableElement.parameters; | 2855 List<ParameterElement> parameters2 = executableElement.parameters; |
| 2858 resolveArgumentsToParameters2(reportError, argumentList, parameters2); | 2856 resolveArgumentsToParameters2(reportError, argumentList, parameters2); |
| 2859 } | 2857 } |
| 2860 | 2858 |
| 2861 /** | 2859 /** |
| 2862 * Given a list of arguments and the element that will be invoked using those
argument, compute | 2860 * Given a list of arguments and the element that will be invoked using those
argument, compute |
| 2863 * the list of parameters that correspond to the list of arguments. | 2861 * the list of parameters that correspond to the list of arguments. |
| 2864 * @param reportError if {@code true} then compile-time error should be report
ed; if {@code false}then compile-time warning | 2862 * @param reportError if {@code true} then compile-time error should be report
ed; if {@code false}then compile-time warning |
| 2865 * @param argumentList the list of arguments being passed to the element | 2863 * @param argumentList the list of arguments being passed to the element |
| 2866 * @param parameters the of the function that will be invoked with the argumen
ts | 2864 * @param parameters the of the function that will be invoked with the argumen
ts |
| 2867 */ | 2865 */ |
| 2868 void resolveArgumentsToParameters2(bool reportError2, ArgumentList argumentLis
t, List<ParameterElement> parameters) { | 2866 void resolveArgumentsToParameters2(bool reportError2, ArgumentList argumentLis
t, List<ParameterElement> parameters) { |
| 2869 List<ParameterElement> requiredParameters = new List<ParameterElement>(); | 2867 List<ParameterElement> requiredParameters = new List<ParameterElement>(); |
| 2870 List<ParameterElement> positionalParameters = new List<ParameterElement>(); | 2868 List<ParameterElement> positionalParameters = new List<ParameterElement>(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2913 } | 2911 } |
| 2914 if (positionalArgumentCount < requiredParameters.length) { | 2912 if (positionalArgumentCount < requiredParameters.length) { |
| 2915 ErrorCode errorCode = reportError2 ? CompileTimeErrorCode.NOT_ENOUGH_REQUI
RED_ARGUMENTS : StaticWarningCode.NOT_ENOUGH_REQUIRED_ARGUMENTS; | 2913 ErrorCode errorCode = reportError2 ? CompileTimeErrorCode.NOT_ENOUGH_REQUI
RED_ARGUMENTS : StaticWarningCode.NOT_ENOUGH_REQUIRED_ARGUMENTS; |
| 2916 _resolver.reportError(errorCode, argumentList, [requiredParameters.length,
positionalArgumentCount]); | 2914 _resolver.reportError(errorCode, argumentList, [requiredParameters.length,
positionalArgumentCount]); |
| 2917 } else if (positionalArgumentCount > unnamedParameterCount) { | 2915 } else if (positionalArgumentCount > unnamedParameterCount) { |
| 2918 ErrorCode errorCode = reportError2 ? CompileTimeErrorCode.EXTRA_POSITIONAL
_ARGUMENTS : StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS; | 2916 ErrorCode errorCode = reportError2 ? CompileTimeErrorCode.EXTRA_POSITIONAL
_ARGUMENTS : StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS; |
| 2919 _resolver.reportError(errorCode, argumentList, [unnamedParameterCount, pos
itionalArgumentCount]); | 2917 _resolver.reportError(errorCode, argumentList, [unnamedParameterCount, pos
itionalArgumentCount]); |
| 2920 } | 2918 } |
| 2921 argumentList.correspondingParameters = resolvedParameters; | 2919 argumentList.correspondingParameters = resolvedParameters; |
| 2922 } | 2920 } |
| 2923 | 2921 |
| 2924 /** | 2922 /** |
| 2925 * Resolve the names in the given combinators in the scope of the given librar
y. | 2923 * Resolve the names in the given combinators in the scope of the given librar
y. |
| 2926 * @param library the library that defines the names | 2924 * @param library the library that defines the names |
| 2927 * @param combinators the combinators containing the names to be resolved | 2925 * @param combinators the combinators containing the names to be resolved |
| 2928 */ | 2926 */ |
| 2929 void resolveCombinators(LibraryElement library, NodeList<Combinator> combinato
rs) { | 2927 void resolveCombinators(LibraryElement library, NodeList<Combinator> combinato
rs) { |
| 2930 if (library == null) { | 2928 if (library == null) { |
| 2931 return; | 2929 return; |
| 2932 } | 2930 } |
| 2933 Namespace namespace = new NamespaceBuilder().createExportNamespace2(library)
; | 2931 Namespace namespace = new NamespaceBuilder().createExportNamespace2(library)
; |
| 2934 for (Combinator combinator in combinators) { | 2932 for (Combinator combinator in combinators) { |
| 2935 NodeList<SimpleIdentifier> names; | 2933 NodeList<SimpleIdentifier> names; |
| 2936 if (combinator is HideCombinator) { | 2934 if (combinator is HideCombinator) { |
| 2937 names = ((combinator as HideCombinator)).hiddenNames; | 2935 names = ((combinator as HideCombinator)).hiddenNames; |
| 2938 } else { | 2936 } else { |
| 2939 names = ((combinator as ShowCombinator)).shownNames; | 2937 names = ((combinator as ShowCombinator)).shownNames; |
| 2940 } | 2938 } |
| 2941 for (SimpleIdentifier name in names) { | 2939 for (SimpleIdentifier name in names) { |
| 2942 Element element = namespace.get(name.name); | 2940 Element element = namespace.get(name.name); |
| 2943 if (element != null) { | 2941 if (element != null) { |
| 2944 name.element = element; | 2942 name.element = element; |
| 2945 } | 2943 } |
| 2946 } | 2944 } |
| 2947 } | 2945 } |
| 2948 } | 2946 } |
| 2949 | 2947 |
| 2950 /** | 2948 /** |
| 2951 * Given an invocation of the form 'e.m(a1, ..., an)', resolve 'e.m' to the el
ement being invoked. | 2949 * Given an invocation of the form 'e.m(a1, ..., an)', resolve 'e.m' to the el
ement being invoked. |
| 2952 * If the returned element is a method, then the method will be invoked. If th
e returned element | 2950 * If the returned element is a method, then the method will be invoked. If th
e returned element |
| 2953 * is a getter, the getter will be invoked without arguments and the result of
that invocation | 2951 * is a getter, the getter will be invoked without arguments and the result of
that invocation |
| 2954 * will then be invoked with the arguments. | 2952 * will then be invoked with the arguments. |
| 2955 * @param target the target of the invocation ('e') | 2953 * @param target the target of the invocation ('e') |
| 2956 * @param targetType the type of the target | 2954 * @param targetType the type of the target |
| 2957 * @param methodName the name of the method being invoked ('m') | 2955 * @param methodName the name of the method being invoked ('m') |
| 2958 * @return the element being invoked | 2956 * @return the element being invoked |
| 2959 */ | 2957 */ |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2971 String name2 = "${((target as SimpleIdentifier)).name}.${methodName}"; | 2969 String name2 = "${((target as SimpleIdentifier)).name}.${methodName}"; |
| 2972 Identifier functionName = new ElementResolver_SyntheticIdentifier(name2)
; | 2970 Identifier functionName = new ElementResolver_SyntheticIdentifier(name2)
; |
| 2973 Element element = _resolver.nameScope.lookup(functionName, _resolver.def
iningLibrary); | 2971 Element element = _resolver.nameScope.lookup(functionName, _resolver.def
iningLibrary); |
| 2974 if (element != null) { | 2972 if (element != null) { |
| 2975 return element; | 2973 return element; |
| 2976 } | 2974 } |
| 2977 } | 2975 } |
| 2978 } | 2976 } |
| 2979 return null; | 2977 return null; |
| 2980 } | 2978 } |
| 2981 | 2979 |
| 2982 /** | 2980 /** |
| 2983 * Given an invocation of the form 'm(a1, ..., an)', resolve 'm' to the elemen
t being invoked. If | 2981 * Given an invocation of the form 'm(a1, ..., an)', resolve 'm' to the elemen
t being invoked. If |
| 2984 * the returned element is a method, then the method will be invoked. If the r
eturned element is a | 2982 * the returned element is a method, then the method will be invoked. If the r
eturned element is a |
| 2985 * getter, the getter will be invoked without arguments and the result of that
invocation will | 2983 * getter, the getter will be invoked without arguments and the result of that
invocation will |
| 2986 * then be invoked with the arguments. | 2984 * then be invoked with the arguments. |
| 2987 * @param methodName the name of the method being invoked ('m') | 2985 * @param methodName the name of the method being invoked ('m') |
| 2988 * @return the element being invoked | 2986 * @return the element being invoked |
| 2989 */ | 2987 */ |
| 2990 Element resolveInvokedElement2(SimpleIdentifier methodName) { | 2988 Element resolveInvokedElement2(SimpleIdentifier methodName) { |
| 2991 Element element = _resolver.nameScope.lookup(methodName, _resolver.definingL
ibrary); | 2989 Element element = _resolver.nameScope.lookup(methodName, _resolver.definingL
ibrary); |
| 2992 if (element == null) { | 2990 if (element == null) { |
| 2993 ClassElement enclosingClass2 = _resolver.enclosingClass; | 2991 ClassElement enclosingClass2 = _resolver.enclosingClass; |
| 2994 if (enclosingClass2 != null) { | 2992 if (enclosingClass2 != null) { |
| 2995 InterfaceType enclosingType = enclosingClass2.type; | 2993 InterfaceType enclosingType = enclosingClass2.type; |
| 2996 element = lookUpMethod(null, enclosingType, methodName.name); | 2994 element = lookUpMethod(null, enclosingType, methodName.name); |
| 2997 if (element == null) { | 2995 if (element == null) { |
| 2998 element = lookUpGetter(null, enclosingType, methodName.name); | 2996 element = lookUpGetter(null, enclosingType, methodName.name); |
| 2999 } | 2997 } |
| 3000 } | 2998 } |
| 3001 } | 2999 } |
| 3002 return element; | 3000 return element; |
| 3003 } | 3001 } |
| 3004 | 3002 |
| 3005 /** | 3003 /** |
| 3006 * Given that we are accessing a property of the given type with the given nam
e, return the | 3004 * Given that we are accessing a property of the given type with the given nam
e, return the |
| 3007 * element that represents the property. | 3005 * element that represents the property. |
| 3008 * @param target the target of the invocation ('e') | 3006 * @param target the target of the invocation ('e') |
| 3009 * @param targetType the type in which the search for the property should begi
n | 3007 * @param targetType the type in which the search for the property should begi
n |
| 3010 * @param propertyName the name of the property being accessed | 3008 * @param propertyName the name of the property being accessed |
| 3011 * @return the element that represents the property | 3009 * @return the element that represents the property |
| 3012 */ | 3010 */ |
| 3013 ExecutableElement resolveProperty(Expression target, Type2 targetType, SimpleI
dentifier propertyName) { | 3011 ExecutableElement resolveProperty(Expression target, Type2 targetType, SimpleI
dentifier propertyName) { |
| 3014 ExecutableElement memberElement = null; | 3012 ExecutableElement memberElement = null; |
| 3015 if (propertyName.inSetterContext()) { | 3013 if (propertyName.inSetterContext()) { |
| 3016 memberElement = lookUpSetter(target, targetType, propertyName.name); | 3014 memberElement = lookUpSetter(target, targetType, propertyName.name); |
| 3017 } | 3015 } |
| 3018 if (memberElement == null) { | 3016 if (memberElement == null) { |
| 3019 memberElement = lookUpGetter(target, targetType, propertyName.name); | 3017 memberElement = lookUpGetter(target, targetType, propertyName.name); |
| 3020 } | 3018 } |
| 3021 if (memberElement == null) { | 3019 if (memberElement == null) { |
| 3022 memberElement = lookUpMethod(target, targetType, propertyName.name); | 3020 memberElement = lookUpMethod(target, targetType, propertyName.name); |
| 3023 } | 3021 } |
| 3024 return memberElement; | 3022 return memberElement; |
| 3025 } | 3023 } |
| 3026 void resolvePropertyAccess(Expression target, SimpleIdentifier propertyName) { | 3024 void resolvePropertyAccess(Expression target, SimpleIdentifier propertyName) { |
| 3027 Type2 staticType = getStaticType(target); | 3025 Type2 staticType = getStaticType(target); |
| 3028 ExecutableElement staticElement = resolveProperty(target, staticType, proper
tyName); | 3026 ExecutableElement staticElement = resolveProperty(target, staticType, proper
tyName); |
| 3029 propertyName.staticElement = staticElement; | 3027 propertyName.staticElement = staticElement; |
| 3030 Type2 propagatedType = getPropagatedType(target); | 3028 Type2 propagatedType = getPropagatedType(target); |
| 3031 ExecutableElement propagatedElement = resolveProperty(target, propagatedType
, propertyName); | 3029 ExecutableElement propagatedElement = resolveProperty(target, propagatedType
, propertyName); |
| 3032 Element selectedElement = select2(staticElement, propagatedElement); | 3030 Element selectedElement = select2(staticElement, propagatedElement); |
| 3033 propertyName.element = selectedElement; | 3031 propertyName.element = selectedElement; |
| 3034 if (shouldReportMissingMember(staticType, staticElement) && (propagatedType
== null || shouldReportMissingMember(propagatedType, propagatedElement))) { | 3032 if (shouldReportMissingMember(staticType, staticElement) && (_strictMode ||
propagatedType == null || shouldReportMissingMember(propagatedType, propagatedEl
ement))) { |
| 3035 bool staticNoSuchMethod = staticType != null && classDeclaresNoSuchMethod2
(staticType.element); | 3033 bool staticNoSuchMethod = staticType != null && classDeclaresNoSuchMethod2
(staticType.element); |
| 3036 bool propagatedNoSuchMethod = propagatedType != null && classDeclaresNoSuc
hMethod2(propagatedType.element); | 3034 bool propagatedNoSuchMethod = propagatedType != null && classDeclaresNoSuc
hMethod2(propagatedType.element); |
| 3037 if (!staticNoSuchMethod && !propagatedNoSuchMethod) { | 3035 if (!staticNoSuchMethod && !propagatedNoSuchMethod) { |
| 3038 bool isStaticProperty = isStatic(selectedElement); | 3036 bool isStaticProperty = isStatic(selectedElement); |
| 3039 if (propertyName.inSetterContext()) { | 3037 if (propertyName.inSetterContext()) { |
| 3040 if (isStaticProperty) { | 3038 if (isStaticProperty) { |
| 3041 _resolver.reportError(StaticWarningCode.UNDEFINED_SETTER, propertyNa
me, [propertyName.name, staticType.displayName]); | 3039 _resolver.reportError(StaticWarningCode.UNDEFINED_SETTER, propertyNa
me, [propertyName.name, staticType.displayName]); |
| 3042 } else { | 3040 } else { |
| 3043 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_SETTER, proper
tyName, [propertyName.name, staticType.displayName]); | 3041 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_SETTER, proper
tyName, [propertyName.name, staticType.displayName]); |
| 3044 } | 3042 } |
| 3045 } else if (propertyName.inGetterContext()) { | 3043 } else if (propertyName.inGetterContext()) { |
| 3046 if (isStaticProperty) { | 3044 if (isStaticProperty) { |
| 3047 _resolver.reportError(StaticWarningCode.UNDEFINED_GETTER, propertyNa
me, [propertyName.name, staticType.displayName]); | 3045 _resolver.reportError(StaticWarningCode.UNDEFINED_GETTER, propertyNa
me, [propertyName.name, staticType.displayName]); |
| 3048 } else { | 3046 } else { |
| 3049 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_GETTER, proper
tyName, [propertyName.name, staticType.displayName]); | 3047 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_GETTER, proper
tyName, [propertyName.name, staticType.displayName]); |
| 3050 } | 3048 } |
| 3051 } else { | 3049 } else { |
| 3052 _resolver.reportError(StaticWarningCode.UNDEFINED_IDENTIFIER, property
Name, [propertyName.name]); | 3050 _resolver.reportError(StaticWarningCode.UNDEFINED_IDENTIFIER, property
Name, [propertyName.name]); |
| 3053 } | 3051 } |
| 3054 } | 3052 } |
| 3055 } | 3053 } |
| 3056 } | 3054 } |
| 3057 | 3055 |
| 3058 /** | 3056 /** |
| 3059 * Resolve the given simple identifier if possible. Return the element to whic
h it could be | 3057 * Resolve the given simple identifier if possible. Return the element to whic
h it could be |
| 3060 * resolved, or {@code null} if it could not be resolved. This does not record
the results of the | 3058 * resolved, or {@code null} if it could not be resolved. This does not record
the results of the |
| 3061 * resolution. | 3059 * resolution. |
| 3062 * @param node the identifier to be resolved | 3060 * @param node the identifier to be resolved |
| 3063 * @return the element to which the identifier could be resolved | 3061 * @return the element to which the identifier could be resolved |
| 3064 */ | 3062 */ |
| 3065 Element resolveSimpleIdentifier(SimpleIdentifier node) { | 3063 Element resolveSimpleIdentifier(SimpleIdentifier node) { |
| 3066 Element element = _resolver.nameScope.lookup(node, _resolver.definingLibrary
); | 3064 Element element = _resolver.nameScope.lookup(node, _resolver.definingLibrary
); |
| 3067 if (element is PropertyAccessorElement && node.inSetterContext()) { | 3065 if (element is PropertyAccessorElement && node.inSetterContext()) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 3089 } | 3087 } |
| 3090 if (element == null && node.inGetterContext()) { | 3088 if (element == null && node.inGetterContext()) { |
| 3091 element = lookUpGetter(null, enclosingType, node.name); | 3089 element = lookUpGetter(null, enclosingType, node.name); |
| 3092 } | 3090 } |
| 3093 if (element == null) { | 3091 if (element == null) { |
| 3094 element = lookUpMethod(null, enclosingType, node.name); | 3092 element = lookUpMethod(null, enclosingType, node.name); |
| 3095 } | 3093 } |
| 3096 } | 3094 } |
| 3097 return element; | 3095 return element; |
| 3098 } | 3096 } |
| 3099 | 3097 |
| 3100 /** | 3098 /** |
| 3101 * If the given type is a type variable, resolve it to the type that should be
used when looking | 3099 * If the given type is a type variable, resolve it to the type that should be
used when looking |
| 3102 * up members. Otherwise, return the original type. | 3100 * up members. Otherwise, return the original type. |
| 3103 * @param type the type that is to be resolved if it is a type variable | 3101 * @param type the type that is to be resolved if it is a type variable |
| 3104 * @return the type that should be used in place of the argument if it is a ty
pe variable, or the | 3102 * @return the type that should be used in place of the argument if it is a ty
pe variable, or the |
| 3105 * original argument if it isn't a type variable | 3103 * original argument if it isn't a type variable |
| 3106 */ | 3104 */ |
| 3107 Type2 resolveTypeVariable(Type2 type) { | 3105 Type2 resolveTypeVariable(Type2 type) { |
| 3108 if (type is TypeVariableType) { | 3106 if (type is TypeVariableType) { |
| 3109 Type2 bound2 = ((type as TypeVariableType)).element.bound; | 3107 Type2 bound2 = ((type as TypeVariableType)).element.bound; |
| 3110 if (bound2 == null) { | 3108 if (bound2 == null) { |
| 3111 return _resolver.typeProvider.objectType; | 3109 return _resolver.typeProvider.objectType; |
| 3112 } | 3110 } |
| 3113 return bound2; | 3111 return bound2; |
| 3114 } | 3112 } |
| 3115 return type; | 3113 return type; |
| 3116 } | 3114 } |
| 3117 | 3115 |
| 3118 /** | 3116 /** |
| 3119 * Given two possible error codes for the same piece of code, one computed usi
ng static type | 3117 * Given two possible error codes for the same piece of code, one computed usi
ng static type |
| 3120 * information and the other using propagated type information, return the err
or code that should | 3118 * information and the other using propagated type information, return the err
or code that should |
| 3121 * be reported, or {@code null} if no error should be reported. | 3119 * be reported, or {@code null} if no error should be reported. |
| 3122 * @param staticError the error code computed using static type information | 3120 * @param staticError the error code computed using static type information |
| 3123 * @param propagatedError the error code computed using propagated type inform
ation | 3121 * @param propagatedError the error code computed using propagated type inform
ation |
| 3124 * @return the error code that should be reported | 3122 * @return the error code that should be reported |
| 3125 */ | 3123 */ |
| 3126 ErrorCode select(ErrorCode staticError, ErrorCode propagatedError) { | 3124 ErrorCode select(ErrorCode staticError, ErrorCode propagatedError) { |
| 3127 if (staticError == null || propagatedError == null) { | 3125 if (staticError == null || propagatedError == null) { |
| 3128 return null; | 3126 return null; |
| 3129 } | 3127 } |
| 3130 return propagatedError; | 3128 return propagatedError; |
| 3131 } | 3129 } |
| 3132 | 3130 |
| 3133 /** | 3131 /** |
| 3134 * Return the propagated element if it is not {@code null}, or the static elem
ent if it is. | 3132 * Return the propagated element if it is not {@code null}, or the static elem
ent if it is. |
| 3135 * @param staticElement the element computed using static type information | 3133 * @param staticElement the element computed using static type information |
| 3136 * @param propagatedElement the element computed using propagated type informa
tion | 3134 * @param propagatedElement the element computed using propagated type informa
tion |
| 3137 * @return the more specific of the two elements | 3135 * @return the more specific of the two elements |
| 3138 */ | 3136 */ |
| 3139 ExecutableElement select2(ExecutableElement staticElement, ExecutableElement p
ropagatedElement) => propagatedElement != null ? propagatedElement : staticEleme
nt; | 3137 ExecutableElement select2(ExecutableElement staticElement, ExecutableElement p
ropagatedElement) => propagatedElement != null ? propagatedElement : staticEleme
nt; |
| 3140 | 3138 |
| 3141 /** | 3139 /** |
| 3142 * Return the propagated method if it is not {@code null}, or the static metho
d if it is. | 3140 * Return the propagated method if it is not {@code null}, or the static metho
d if it is. |
| 3143 * @param staticMethod the method computed using static type information | 3141 * @param staticMethod the method computed using static type information |
| 3144 * @param propagatedMethod the method computed using propagated type informati
on | 3142 * @param propagatedMethod the method computed using propagated type informati
on |
| 3145 * @return the more specific of the two methods | 3143 * @return the more specific of the two methods |
| 3146 */ | 3144 */ |
| 3147 MethodElement select3(MethodElement staticMethod, MethodElement propagatedMeth
od) => propagatedMethod != null ? propagatedMethod : staticMethod; | 3145 MethodElement select3(MethodElement staticMethod, MethodElement propagatedMeth
od) => propagatedMethod != null ? propagatedMethod : staticMethod; |
| 3148 | 3146 |
| 3149 /** | 3147 /** |
| 3150 * Given a node that can have annotations associated with it and the element t
o which that node | 3148 * Given a node that can have annotations associated with it and the element t
o which that node |
| 3151 * has been resolved, create the annotations in the element model representing
the annotations on | 3149 * has been resolved, create the annotations in the element model representing
the annotations on |
| 3152 * the node. | 3150 * the node. |
| 3153 * @param element the element to which the node has been resolved | 3151 * @param element the element to which the node has been resolved |
| 3154 * @param node the node that can have annotations associated with it | 3152 * @param node the node that can have annotations associated with it |
| 3155 */ | 3153 */ |
| 3156 void setMetadata(Element element, AnnotatedNode node) { | 3154 void setMetadata(Element element, AnnotatedNode node) { |
| 3157 if (element is! ElementImpl) { | 3155 if (element is! ElementImpl) { |
| 3158 return; | 3156 return; |
| 3159 } | 3157 } |
| 3160 List<AnnotationImpl> annotationList = new List<AnnotationImpl>(); | 3158 List<AnnotationImpl> annotationList = new List<AnnotationImpl>(); |
| 3161 addAnnotations(annotationList, node.metadata); | 3159 addAnnotations(annotationList, node.metadata); |
| 3162 if (node is VariableDeclaration && node.parent is VariableDeclarationList) { | 3160 if (node is VariableDeclaration && node.parent is VariableDeclarationList) { |
| 3163 VariableDeclarationList list = node.parent as VariableDeclarationList; | 3161 VariableDeclarationList list = node.parent as VariableDeclarationList; |
| 3164 addAnnotations(annotationList, list.metadata); | 3162 addAnnotations(annotationList, list.metadata); |
| 3165 if (list.parent is FieldDeclaration) { | 3163 if (list.parent is FieldDeclaration) { |
| 3166 FieldDeclaration fieldDeclaration = list.parent as FieldDeclaration; | 3164 FieldDeclaration fieldDeclaration = list.parent as FieldDeclaration; |
| 3167 addAnnotations(annotationList, fieldDeclaration.metadata); | 3165 addAnnotations(annotationList, fieldDeclaration.metadata); |
| 3168 } else if (list.parent is TopLevelVariableDeclaration) { | 3166 } else if (list.parent is TopLevelVariableDeclaration) { |
| 3169 TopLevelVariableDeclaration variableDeclaration = list.parent as TopLeve
lVariableDeclaration; | 3167 TopLevelVariableDeclaration variableDeclaration = list.parent as TopLeve
lVariableDeclaration; |
| 3170 addAnnotations(annotationList, variableDeclaration.metadata); | 3168 addAnnotations(annotationList, variableDeclaration.metadata); |
| 3171 } | 3169 } |
| 3172 } | 3170 } |
| 3173 if (!annotationList.isEmpty) { | 3171 if (!annotationList.isEmpty) { |
| 3174 ((element as ElementImpl)).metadata = new List.from(annotationList); | 3172 ((element as ElementImpl)).metadata = new List.from(annotationList); |
| 3175 } | 3173 } |
| 3176 } | 3174 } |
| 3177 | 3175 |
| 3178 /** | 3176 /** |
| 3179 * Return {@code true} if we should report an error as a result of looking up
a member in the | 3177 * Return {@code true} if we should report an error as a result of looking up
a member in the |
| 3180 * given type and not finding any member. | 3178 * given type and not finding any member. |
| 3181 * @param type the type in which we attempted to perform the look-up | 3179 * @param type the type in which we attempted to perform the look-up |
| 3182 * @param member the result of the look-up | 3180 * @param member the result of the look-up |
| 3183 * @return {@code true} if we should report an error | 3181 * @return {@code true} if we should report an error |
| 3184 */ | 3182 */ |
| 3185 bool shouldReportMissingMember(Type2 type, ExecutableElement member) { | 3183 bool shouldReportMissingMember(Type2 type, ExecutableElement member) { |
| 3186 if (member != null || type == null || type.isDynamic()) { | 3184 if (member != null || type == null || type.isDynamic()) { |
| 3187 return false; | 3185 return false; |
| 3188 } | 3186 } |
| 3189 if (type is InterfaceType) { | 3187 if (type is InterfaceType) { |
| 3190 return !classDeclaresNoSuchMethod(((type as InterfaceType)).element); | 3188 return !classDeclaresNoSuchMethod(((type as InterfaceType)).element); |
| 3191 } | 3189 } |
| 3192 return true; | 3190 return true; |
| 3193 } | 3191 } |
| 3194 } | 3192 } |
| 3195 | |
| 3196 /** | 3193 /** |
| 3197 * Instances of the class {@code SyntheticIdentifier} implement an identifier th
at can be used to | 3194 * Instances of the class {@code SyntheticIdentifier} implement an identifier th
at can be used to |
| 3198 * look up names in the lexical scope when there is no identifier in the AST str
ucture. There is | 3195 * look up names in the lexical scope when there is no identifier in the AST str
ucture. There is |
| 3199 * no identifier in the AST when the parser could not distinguish between a meth
od invocation and | 3196 * no identifier in the AST when the parser could not distinguish between a meth
od invocation and |
| 3200 * an invocation of a top-level function imported with a prefix. | 3197 * an invocation of a top-level function imported with a prefix. |
| 3201 */ | 3198 */ |
| 3202 class ElementResolver_SyntheticIdentifier extends Identifier { | 3199 class ElementResolver_SyntheticIdentifier extends Identifier { |
| 3203 | 3200 |
| 3204 /** | 3201 /** |
| 3205 * The name of the synthetic identifier. | 3202 * The name of the synthetic identifier. |
| 3206 */ | 3203 */ |
| 3207 String _name; | 3204 String _name; |
| 3208 | 3205 |
| 3209 /** | 3206 /** |
| 3210 * Initialize a newly created synthetic identifier to have the given name. | 3207 * Initialize a newly created synthetic identifier to have the given name. |
| 3211 * @param name the name of the synthetic identifier | 3208 * @param name the name of the synthetic identifier |
| 3212 */ | 3209 */ |
| 3213 ElementResolver_SyntheticIdentifier(String name) { | 3210 ElementResolver_SyntheticIdentifier(String name) { |
| 3214 this._name = name; | 3211 this._name = name; |
| 3215 } | 3212 } |
| 3216 accept(ASTVisitor visitor) => null; | 3213 accept(ASTVisitor visitor) => null; |
| 3217 sc.Token get beginToken => null; | 3214 sc.Token get beginToken => null; |
| 3218 Element get element => null; | 3215 Element get element => null; |
| 3219 sc.Token get endToken => null; | 3216 sc.Token get endToken => null; |
| 3220 String get name => _name; | 3217 String get name => _name; |
| 3221 Element get staticElement => null; | 3218 Element get staticElement => null; |
| 3222 void visitChildren(ASTVisitor<Object> visitor) { | 3219 void visitChildren(ASTVisitor<Object> visitor) { |
| 3223 } | 3220 } |
| 3224 } | 3221 } |
| 3225 | |
| 3226 /** | 3222 /** |
| 3227 * Instances of the class {@code InheritanceManager} manage the knowledge of whe
re class members | 3223 * Instances of the class {@code InheritanceManager} manage the knowledge of whe
re class members |
| 3228 * (methods, getters & setters) are inherited from. | 3224 * (methods, getters & setters) are inherited from. |
| 3229 * @coverage dart.engine.resolver | 3225 * @coverage dart.engine.resolver |
| 3230 */ | 3226 */ |
| 3231 class InheritanceManager { | 3227 class InheritanceManager { |
| 3232 | 3228 |
| 3233 /** | 3229 /** |
| 3234 * The {@link LibraryElement} that is managed by this manager. | 3230 * The {@link LibraryElement} that is managed by this manager. |
| 3235 */ | 3231 */ |
| 3236 LibraryElement _library; | 3232 LibraryElement _library; |
| 3237 | 3233 |
| 3238 /** | 3234 /** |
| 3239 * This is a mapping between each {@link ClassElement} and a map between the {
@link String} member | 3235 * This is a mapping between each {@link ClassElement} and a map between the {
@link String} member |
| 3240 * names and the associated {@link ExecutableElement} in the mixin and supercl
ass chain. | 3236 * names and the associated {@link ExecutableElement} in the mixin and supercl
ass chain. |
| 3241 */ | 3237 */ |
| 3242 Map<ClassElement, Map<String, ExecutableElement>> _classLookup; | 3238 Map<ClassElement, Map<String, ExecutableElement>> _classLookup; |
| 3243 | 3239 |
| 3244 /** | 3240 /** |
| 3245 * This is a mapping between each {@link ClassElement} and a map between the {
@link String} member | 3241 * This is a mapping between each {@link ClassElement} and a map between the {
@link String} member |
| 3246 * names and the associated {@link ExecutableElement} in the interface set. | 3242 * names and the associated {@link ExecutableElement} in the interface set. |
| 3247 */ | 3243 */ |
| 3248 Map<ClassElement, Map<String, ExecutableElement>> _interfaceLookup; | 3244 Map<ClassElement, Map<String, ExecutableElement>> _interfaceLookup; |
| 3249 | 3245 |
| 3250 /** | 3246 /** |
| 3251 * A map between each visited {@link ClassElement} and the set of {@link Analy
sisError}s found on | 3247 * A map between each visited {@link ClassElement} and the set of {@link Analy
sisError}s found on |
| 3252 * the class element. | 3248 * the class element. |
| 3253 */ | 3249 */ |
| 3254 Map<ClassElement, Set<AnalysisError>> _errorsInClassElement = new Map<ClassEle
ment, Set<AnalysisError>>(); | 3250 Map<ClassElement, Set<AnalysisError>> _errorsInClassElement = new Map<ClassEle
ment, Set<AnalysisError>>(); |
| 3255 | 3251 |
| 3256 /** | 3252 /** |
| 3257 * Initialize a newly created inheritance manager. | 3253 * Initialize a newly created inheritance manager. |
| 3258 * @param library the library element context that the inheritance mappings ar
e being generated | 3254 * @param library the library element context that the inheritance mappings ar
e being generated |
| 3259 */ | 3255 */ |
| 3260 InheritanceManager(LibraryElement library) { | 3256 InheritanceManager(LibraryElement library) { |
| 3261 this._library = library; | 3257 this._library = library; |
| 3262 _classLookup = new Map<ClassElement, Map<String, ExecutableElement>>(); | 3258 _classLookup = new Map<ClassElement, Map<String, ExecutableElement>>(); |
| 3263 _interfaceLookup = new Map<ClassElement, Map<String, ExecutableElement>>(); | 3259 _interfaceLookup = new Map<ClassElement, Map<String, ExecutableElement>>(); |
| 3264 } | 3260 } |
| 3265 | 3261 |
| 3266 /** | 3262 /** |
| 3267 * Return the set of {@link AnalysisError}s found on the passed {@link ClassEl
ement}, or{@code null} if there are none. | 3263 * Return the set of {@link AnalysisError}s found on the passed {@link ClassEl
ement}, or{@code null} if there are none. |
| 3268 * @param classElt the class element to query | 3264 * @param classElt the class element to query |
| 3269 * @return the set of {@link AnalysisError}s found on the passed {@link ClassE
lement}, or{@code null} if there are none | 3265 * @return the set of {@link AnalysisError}s found on the passed {@link ClassE
lement}, or{@code null} if there are none |
| 3270 */ | 3266 */ |
| 3271 Set<AnalysisError> getErrors(ClassElement classElt) => _errorsInClassElement[c
lassElt]; | 3267 Set<AnalysisError> getErrors(ClassElement classElt) => _errorsInClassElement[c
lassElt]; |
| 3272 | 3268 |
| 3273 /** | 3269 /** |
| 3274 * Get and return a mapping between the set of all string names of the members
inherited from the | 3270 * Get and return a mapping between the set of all string names of the members
inherited from the |
| 3275 * passed {@link ClassElement} superclass hierarchy, and the associated {@link
ExecutableElement}. | 3271 * passed {@link ClassElement} superclass hierarchy, and the associated {@link
ExecutableElement}. |
| 3276 * @param classElt the class element to query | 3272 * @param classElt the class element to query |
| 3277 * @return a mapping between the set of all members inherited from the passed
{@link ClassElement}superclass hierarchy, and the associated {@link ExecutableEl
ement} | 3273 * @return a mapping between the set of all members inherited from the passed
{@link ClassElement}superclass hierarchy, and the associated {@link ExecutableEl
ement} |
| 3278 */ | 3274 */ |
| 3279 Map<String, ExecutableElement> getMapOfMembersInheritedFromClasses(ClassElemen
t classElt) => computeClassChainLookupMap(classElt, new Set<ClassElement>()); | 3275 Map<String, ExecutableElement> getMapOfMembersInheritedFromClasses(ClassElemen
t classElt) => computeClassChainLookupMap(classElt, new Set<ClassElement>()); |
| 3280 | 3276 |
| 3281 /** | 3277 /** |
| 3282 * Get and return a mapping between the set of all string names of the members
inherited from the | 3278 * Get and return a mapping between the set of all string names of the members
inherited from the |
| 3283 * passed {@link ClassElement} interface hierarchy, and the associated {@link
ExecutableElement}. | 3279 * passed {@link ClassElement} interface hierarchy, and the associated {@link
ExecutableElement}. |
| 3284 * @param classElt the class element to query | 3280 * @param classElt the class element to query |
| 3285 * @return a mapping between the set of all string names of the members inheri
ted from the passed{@link ClassElement} interface hierarchy, and the associated
{@link ExecutableElement}. | 3281 * @return a mapping between the set of all string names of the members inheri
ted from the passed{@link ClassElement} interface hierarchy, and the associated
{@link ExecutableElement}. |
| 3286 */ | 3282 */ |
| 3287 Map<String, ExecutableElement> getMapOfMembersInheritedFromInterfaces(ClassEle
ment classElt) => computeInterfaceLookupMap(classElt, new Set<ClassElement>()); | 3283 Map<String, ExecutableElement> getMapOfMembersInheritedFromInterfaces(ClassEle
ment classElt) => computeInterfaceLookupMap(classElt, new Set<ClassElement>()); |
| 3288 | 3284 |
| 3289 /** | 3285 /** |
| 3290 * Given some {@link ClassElement class element} and some member name, this re
turns the{@link ExecutableElement executable element} that the class inherits fr
om the mixins, | 3286 * Given some {@link ClassElement class element} and some member name, this re
turns the{@link ExecutableElement executable element} that the class inherits fr
om the mixins, |
| 3291 * superclasses or interfaces, that has the member name, if no member is inher
ited {@code null} is | 3287 * superclasses or interfaces, that has the member name, if no member is inher
ited {@code null} is |
| 3292 * returned. | 3288 * returned. |
| 3293 * @param classElt the class element to query | 3289 * @param classElt the class element to query |
| 3294 * @param memberName the name of the executable element to find and return | 3290 * @param memberName the name of the executable element to find and return |
| 3295 * @return the inherited executable element with the member name, or {@code nu
ll} if no such | 3291 * @return the inherited executable element with the member name, or {@code nu
ll} if no such |
| 3296 * member exists | 3292 * member exists |
| 3297 */ | 3293 */ |
| 3298 ExecutableElement lookupInheritance(ClassElement classElt, String memberName)
{ | 3294 ExecutableElement lookupInheritance(ClassElement classElt, String memberName)
{ |
| 3299 if (memberName == null || memberName.isEmpty) { | 3295 if (memberName == null || memberName.isEmpty) { |
| 3300 return null; | 3296 return null; |
| 3301 } | 3297 } |
| 3302 ExecutableElement executable = computeClassChainLookupMap(classElt, new Set<
ClassElement>())[memberName]; | 3298 ExecutableElement executable = computeClassChainLookupMap(classElt, new Set<
ClassElement>())[memberName]; |
| 3303 if (executable == null) { | 3299 if (executable == null) { |
| 3304 return computeInterfaceLookupMap(classElt, new Set<ClassElement>())[member
Name]; | 3300 return computeInterfaceLookupMap(classElt, new Set<ClassElement>())[member
Name]; |
| 3305 } | 3301 } |
| 3306 return executable; | 3302 return executable; |
| 3307 } | 3303 } |
| 3308 | 3304 |
| 3309 /** | 3305 /** |
| 3310 * Given some {@link ClassElement class element} and some member name, this re
turns the{@link ExecutableElement executable element} that the class either decl
ares itself, or | 3306 * Given some {@link ClassElement class element} and some member name, this re
turns the{@link ExecutableElement executable element} that the class either decl
ares itself, or |
| 3311 * inherits, that has the member name, if no member is inherited {@code null}
is returned. | 3307 * inherits, that has the member name, if no member is inherited {@code null}
is returned. |
| 3312 * @param classElt the class element to query | 3308 * @param classElt the class element to query |
| 3313 * @param memberName the name of the executable element to find and return | 3309 * @param memberName the name of the executable element to find and return |
| 3314 * @return the inherited executable element with the member name, or {@code nu
ll} if no such | 3310 * @return the inherited executable element with the member name, or {@code nu
ll} if no such |
| 3315 * member exists | 3311 * member exists |
| 3316 */ | 3312 */ |
| 3317 ExecutableElement lookupMember(ClassElement classElt, String memberName) { | 3313 ExecutableElement lookupMember(ClassElement classElt, String memberName) { |
| 3318 ExecutableElement element = lookupMemberInClass(classElt, memberName); | 3314 ExecutableElement element = lookupMemberInClass(classElt, memberName); |
| 3319 if (element != null) { | 3315 if (element != null) { |
| 3320 return element; | 3316 return element; |
| 3321 } | 3317 } |
| 3322 return lookupInheritance(classElt, memberName); | 3318 return lookupInheritance(classElt, memberName); |
| 3323 } | 3319 } |
| 3324 | 3320 |
| 3325 /** | 3321 /** |
| 3326 * Set the new library element context. | 3322 * Set the new library element context. |
| 3327 * @param library the new library element | 3323 * @param library the new library element |
| 3328 */ | 3324 */ |
| 3329 void set libraryElement(LibraryElement library2) { | 3325 void set libraryElement(LibraryElement library2) { |
| 3330 this._library = library2; | 3326 this._library = library2; |
| 3331 } | 3327 } |
| 3332 | 3328 |
| 3333 /** | 3329 /** |
| 3334 * This method takes some inherited {@link FunctionType}, and resolves all the
parameterized types | 3330 * This method takes some inherited {@link FunctionType}, and resolves all the
parameterized types |
| 3335 * in the function type, dependent on the class in which it is being overridde
n. | 3331 * in the function type, dependent on the class in which it is being overridde
n. |
| 3336 * @param baseFunctionType the function type that is being overridden | 3332 * @param baseFunctionType the function type that is being overridden |
| 3337 * @param memberName the name of the member, this is used to lookup the inheri
tance path of the | 3333 * @param memberName the name of the member, this is used to lookup the inheri
tance path of the |
| 3338 * override | 3334 * override |
| 3339 * @param definingType the type that is overriding the member | 3335 * @param definingType the type that is overriding the member |
| 3340 * @return the passed function type with any parameterized types substituted | 3336 * @return the passed function type with any parameterized types substituted |
| 3341 */ | 3337 */ |
| 3342 FunctionType substituteTypeArgumentsInMemberFromInheritance(FunctionType baseF
unctionType, String memberName, InterfaceType definingType) { | 3338 FunctionType substituteTypeArgumentsInMemberFromInheritance(FunctionType baseF
unctionType, String memberName, InterfaceType definingType) { |
| 3343 if (baseFunctionType == null) { | 3339 if (baseFunctionType == null) { |
| 3344 return baseFunctionType; | 3340 return baseFunctionType; |
| 3345 } | 3341 } |
| 3346 Queue<InterfaceType> inheritancePath = new Queue<InterfaceType>(); | 3342 Queue<InterfaceType> inheritancePath = new Queue<InterfaceType>(); |
| 3347 computeInheritancePath(inheritancePath, definingType, memberName); | 3343 computeInheritancePath(inheritancePath, definingType, memberName); |
| 3348 if (inheritancePath == null || inheritancePath.length < 2) { | 3344 if (inheritancePath == null || inheritancePath.length < 2) { |
| 3349 return baseFunctionType; | 3345 return baseFunctionType; |
| 3350 } | 3346 } |
| 3351 FunctionType functionTypeToReturn = baseFunctionType; | 3347 FunctionType functionTypeToReturn = baseFunctionType; |
| 3352 InterfaceType lastType = inheritancePath.removeLast(); | 3348 InterfaceType lastType = inheritancePath.removeLast(); |
| 3353 while (inheritancePath.length > 0) { | 3349 while (inheritancePath.length > 0) { |
| 3354 List<Type2> paramTypes = TypeVariableTypeImpl.getTypes(lastType.element.ty
peVariables); | 3350 List<Type2> paramTypes = TypeVariableTypeImpl.getTypes(lastType.element.ty
peVariables); |
| 3355 List<Type2> argTypes = lastType.typeArguments; | 3351 List<Type2> argTypes = lastType.typeArguments; |
| 3356 functionTypeToReturn = functionTypeToReturn.substitute2(argTypes, paramTyp
es); | 3352 functionTypeToReturn = functionTypeToReturn.substitute2(argTypes, paramTyp
es); |
| 3357 lastType = inheritancePath.removeLast(); | 3353 lastType = inheritancePath.removeLast(); |
| 3358 } | 3354 } |
| 3359 return functionTypeToReturn; | 3355 return functionTypeToReturn; |
| 3360 } | 3356 } |
| 3361 | 3357 |
| 3362 /** | 3358 /** |
| 3363 * Compute and return a mapping between the set of all string names of the mem
bers inherited from | 3359 * Compute and return a mapping between the set of all string names of the mem
bers inherited from |
| 3364 * the passed {@link ClassElement} superclass hierarchy, and the associated{@l
ink ExecutableElement}. | 3360 * the passed {@link ClassElement} superclass hierarchy, and the associated{@l
ink ExecutableElement}. |
| 3365 * @param classElt the class element to query | 3361 * @param classElt the class element to query |
| 3366 * @param visitedClasses a set of visited classes passed back into this method
when it calls | 3362 * @param visitedClasses a set of visited classes passed back into this method
when it calls |
| 3367 * itself recursively | 3363 * itself recursively |
| 3368 * @return a mapping between the set of all string names of the members inheri
ted from the passed{@link ClassElement} superclass hierarchy, and the associated
{@link ExecutableElement} | 3364 * @return a mapping between the set of all string names of the members inheri
ted from the passed{@link ClassElement} superclass hierarchy, and the associated
{@link ExecutableElement} |
| 3369 */ | 3365 */ |
| 3370 Map<String, ExecutableElement> computeClassChainLookupMap(ClassElement classEl
t, Set<ClassElement> visitedClasses) { | 3366 Map<String, ExecutableElement> computeClassChainLookupMap(ClassElement classEl
t, Set<ClassElement> visitedClasses) { |
| 3371 Map<String, ExecutableElement> resultMap = _classLookup[classElt]; | 3367 Map<String, ExecutableElement> resultMap = _classLookup[classElt]; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3395 List<InterfaceType> mixins2 = classElt.mixins; | 3391 List<InterfaceType> mixins2 = classElt.mixins; |
| 3396 for (int i = mixins2.length - 1; i >= 0; i--) { | 3392 for (int i = mixins2.length - 1; i >= 0; i--) { |
| 3397 ClassElement mixinElement = mixins2[i].element; | 3393 ClassElement mixinElement = mixins2[i].element; |
| 3398 if (mixinElement != null) { | 3394 if (mixinElement != null) { |
| 3399 recordMapWithClassMembers(resultMap, mixinElement); | 3395 recordMapWithClassMembers(resultMap, mixinElement); |
| 3400 } | 3396 } |
| 3401 } | 3397 } |
| 3402 _classLookup[classElt] = resultMap; | 3398 _classLookup[classElt] = resultMap; |
| 3403 return resultMap; | 3399 return resultMap; |
| 3404 } | 3400 } |
| 3405 | 3401 |
| 3406 /** | 3402 /** |
| 3407 * Compute and return the inheritance path given the context of a type and a m
ember that is | 3403 * Compute and return the inheritance path given the context of a type and a m
ember that is |
| 3408 * overridden in the inheritance path (for which the type is in the path). | 3404 * overridden in the inheritance path (for which the type is in the path). |
| 3409 * @param chain the inheritance path that is built up as this method calls its
elf recursively, | 3405 * @param chain the inheritance path that is built up as this method calls its
elf recursively, |
| 3410 * when this method is called an empty {@link LinkedList} should be provided | 3406 * when this method is called an empty {@link LinkedList} should be provided |
| 3411 * @param currentType the current type in the inheritance path | 3407 * @param currentType the current type in the inheritance path |
| 3412 * @param memberName the name of the member that is being looked up the inheri
tance path | 3408 * @param memberName the name of the member that is being looked up the inheri
tance path |
| 3413 */ | 3409 */ |
| 3414 void computeInheritancePath(Queue<InterfaceType> chain, InterfaceType currentT
ype, String memberName) { | 3410 void computeInheritancePath(Queue<InterfaceType> chain, InterfaceType currentT
ype, String memberName) { |
| 3415 chain.add(currentType); | 3411 chain.add(currentType); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 3441 } | 3437 } |
| 3442 List<InterfaceType> interfaces2 = classElt.interfaces; | 3438 List<InterfaceType> interfaces2 = classElt.interfaces; |
| 3443 for (InterfaceType interfaceType in interfaces2) { | 3439 for (InterfaceType interfaceType in interfaces2) { |
| 3444 ClassElement interfaceElement = interfaceType.element; | 3440 ClassElement interfaceElement = interfaceType.element; |
| 3445 if (interfaceElement != null && lookupMember(interfaceElement, memberName)
!= null) { | 3441 if (interfaceElement != null && lookupMember(interfaceElement, memberName)
!= null) { |
| 3446 computeInheritancePath(chain, interfaceType, memberName); | 3442 computeInheritancePath(chain, interfaceType, memberName); |
| 3447 return; | 3443 return; |
| 3448 } | 3444 } |
| 3449 } | 3445 } |
| 3450 } | 3446 } |
| 3451 | 3447 |
| 3452 /** | 3448 /** |
| 3453 * Compute and return a mapping between the set of all string names of the mem
bers inherited from | 3449 * Compute and return a mapping between the set of all string names of the mem
bers inherited from |
| 3454 * the passed {@link ClassElement} interface hierarchy, and the associated{@li
nk ExecutableElement}. | 3450 * the passed {@link ClassElement} interface hierarchy, and the associated{@li
nk ExecutableElement}. |
| 3455 * @param classElt the class element to query | 3451 * @param classElt the class element to query |
| 3456 * @param visitedInterfaces a set of visited classes passed back into this met
hod when it calls | 3452 * @param visitedInterfaces a set of visited classes passed back into this met
hod when it calls |
| 3457 * itself recursively | 3453 * itself recursively |
| 3458 * @return a mapping between the set of all string names of the members inheri
ted from the passed{@link ClassElement} interface hierarchy, and the associated
{@link ExecutableElement} | 3454 * @return a mapping between the set of all string names of the members inheri
ted from the passed{@link ClassElement} interface hierarchy, and the associated
{@link ExecutableElement} |
| 3459 */ | 3455 */ |
| 3460 Map<String, ExecutableElement> computeInterfaceLookupMap(ClassElement classElt
, Set<ClassElement> visitedInterfaces) { | 3456 Map<String, ExecutableElement> computeInterfaceLookupMap(ClassElement classElt
, Set<ClassElement> visitedInterfaces) { |
| 3461 Map<String, ExecutableElement> resultMap = _interfaceLookup[classElt]; | 3457 Map<String, ExecutableElement> resultMap = _interfaceLookup[classElt]; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3592 if (!allMethods && !allGetters) { | 3588 if (!allMethods && !allGetters) { |
| 3593 reportError(classElt, classElt.nameOffset, classElt.displayName.leng
th, StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD, [key]); | 3589 reportError(classElt, classElt.nameOffset, classElt.displayName.leng
th, StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD, [key]); |
| 3594 } | 3590 } |
| 3595 resultMap.remove(entry.getKey()); | 3591 resultMap.remove(entry.getKey()); |
| 3596 } | 3592 } |
| 3597 } | 3593 } |
| 3598 } | 3594 } |
| 3599 _interfaceLookup[classElt] = resultMap; | 3595 _interfaceLookup[classElt] = resultMap; |
| 3600 return resultMap; | 3596 return resultMap; |
| 3601 } | 3597 } |
| 3602 | 3598 |
| 3603 /** | 3599 /** |
| 3604 * Given some {@link ClassElement}, this method finds and returns the {@link E
xecutableElement} of | 3600 * Given some {@link ClassElement}, this method finds and returns the {@link E
xecutableElement} of |
| 3605 * the passed name in the class element. Static members, members in super type
s and members not | 3601 * the passed name in the class element. Static members, members in super type
s and members not |
| 3606 * accessible from the current library are not considered. | 3602 * accessible from the current library are not considered. |
| 3607 * @param classElt the class element to query | 3603 * @param classElt the class element to query |
| 3608 * @param memberName the name of the member to lookup in the class | 3604 * @param memberName the name of the member to lookup in the class |
| 3609 * @return the found {@link ExecutableElement}, or {@code null} if no such mem
ber was found | 3605 * @return the found {@link ExecutableElement}, or {@code null} if no such mem
ber was found |
| 3610 */ | 3606 */ |
| 3611 ExecutableElement lookupMemberInClass(ClassElement classElt, String memberName
) { | 3607 ExecutableElement lookupMemberInClass(ClassElement classElt, String memberName
) { |
| 3612 List<MethodElement> methods2 = classElt.methods; | 3608 List<MethodElement> methods2 = classElt.methods; |
| 3613 for (MethodElement method in methods2) { | 3609 for (MethodElement method in methods2) { |
| 3614 if (memberName == method.name && method.isAccessibleIn(_library) && !metho
d.isStatic()) { | 3610 if (memberName == method.name && method.isAccessibleIn(_library) && !metho
d.isStatic()) { |
| 3615 return method; | 3611 return method; |
| 3616 } | 3612 } |
| 3617 } | 3613 } |
| 3618 List<PropertyAccessorElement> accessors2 = classElt.accessors; | 3614 List<PropertyAccessorElement> accessors2 = classElt.accessors; |
| 3619 for (PropertyAccessorElement accessor in accessors2) { | 3615 for (PropertyAccessorElement accessor in accessors2) { |
| 3620 if (memberName == accessor.name && accessor.isAccessibleIn(_library) && !a
ccessor.isStatic()) { | 3616 if (memberName == accessor.name && accessor.isAccessibleIn(_library) && !a
ccessor.isStatic()) { |
| 3621 return accessor; | 3617 return accessor; |
| 3622 } | 3618 } |
| 3623 } | 3619 } |
| 3624 return null; | 3620 return null; |
| 3625 } | 3621 } |
| 3626 | 3622 |
| 3627 /** | 3623 /** |
| 3628 * Record the passed map with the set of all members (methods, getters and set
ters) in the class | 3624 * Record the passed map with the set of all members (methods, getters and set
ters) in the class |
| 3629 * into the passed map. | 3625 * into the passed map. |
| 3630 * @param map some non-{@code null} | 3626 * @param map some non-{@code null} |
| 3631 * @param classElt the class element that will be recorded into the passed map | 3627 * @param classElt the class element that will be recorded into the passed map |
| 3632 */ | 3628 */ |
| 3633 void recordMapWithClassMembers(Map<String, ExecutableElement> map, ClassElemen
t classElt) { | 3629 void recordMapWithClassMembers(Map<String, ExecutableElement> map, ClassElemen
t classElt) { |
| 3634 List<MethodElement> methods2 = classElt.methods; | 3630 List<MethodElement> methods2 = classElt.methods; |
| 3635 for (MethodElement method in methods2) { | 3631 for (MethodElement method in methods2) { |
| 3636 if (method.isAccessibleIn(_library) && !method.isStatic()) { | 3632 if (method.isAccessibleIn(_library) && !method.isStatic()) { |
| 3637 map[method.name] = method; | 3633 map[method.name] = method; |
| 3638 } | 3634 } |
| 3639 } | 3635 } |
| 3640 List<PropertyAccessorElement> accessors2 = classElt.accessors; | 3636 List<PropertyAccessorElement> accessors2 = classElt.accessors; |
| 3641 for (PropertyAccessorElement accessor in accessors2) { | 3637 for (PropertyAccessorElement accessor in accessors2) { |
| 3642 if (accessor.isAccessibleIn(_library) && !accessor.isStatic()) { | 3638 if (accessor.isAccessibleIn(_library) && !accessor.isStatic()) { |
| 3643 map[accessor.name] = accessor; | 3639 map[accessor.name] = accessor; |
| 3644 } | 3640 } |
| 3645 } | 3641 } |
| 3646 } | 3642 } |
| 3647 | 3643 |
| 3648 /** | 3644 /** |
| 3649 * This method is used to report errors on when they are found computing inher
itance information. | 3645 * This method is used to report errors on when they are found computing inher
itance information. |
| 3650 * See {@link ErrorVerifier#checkForInconsistentMethodInheritance()} to see wh
ere these generated | 3646 * See {@link ErrorVerifier#checkForInconsistentMethodInheritance()} to see wh
ere these generated |
| 3651 * error codes are reported back into the analysis engine. | 3647 * error codes are reported back into the analysis engine. |
| 3652 * @param classElt the location of the source for which the exception occurred | 3648 * @param classElt the location of the source for which the exception occurred |
| 3653 * @param offset the offset of the location of the error | 3649 * @param offset the offset of the location of the error |
| 3654 * @param length the length of the location of the error | 3650 * @param length the length of the location of the error |
| 3655 * @param errorCode the error code to be associated with this error | 3651 * @param errorCode the error code to be associated with this error |
| 3656 * @param arguments the arguments used to build the error message | 3652 * @param arguments the arguments used to build the error message |
| 3657 */ | 3653 */ |
| 3658 void reportError(ClassElement classElt, int offset, int length, ErrorCode erro
rCode, List<Object> arguments) { | 3654 void reportError(ClassElement classElt, int offset, int length, ErrorCode erro
rCode, List<Object> arguments) { |
| 3659 Set<AnalysisError> errorSet = _errorsInClassElement[classElt]; | 3655 Set<AnalysisError> errorSet = _errorsInClassElement[classElt]; |
| 3660 if (errorSet == null) { | 3656 if (errorSet == null) { |
| 3661 errorSet = new Set<AnalysisError>(); | 3657 errorSet = new Set<AnalysisError>(); |
| 3662 _errorsInClassElement[classElt] = errorSet; | 3658 _errorsInClassElement[classElt] = errorSet; |
| 3663 } | 3659 } |
| 3664 javaSetAdd(errorSet, new AnalysisError.con2(classElt.source, offset, length,
errorCode, arguments)); | 3660 javaSetAdd(errorSet, new AnalysisError.con2(classElt.source, offset, length,
errorCode, arguments)); |
| 3665 } | 3661 } |
| 3666 } | 3662 } |
| 3667 | |
| 3668 /** | 3663 /** |
| 3669 * Instances of the class {@code Library} represent the data about a single libr
ary during the | 3664 * Instances of the class {@code Library} represent the data about a single libr
ary during the |
| 3670 * resolution of some (possibly different) library. They are not intended to be
used except during | 3665 * resolution of some (possibly different) library. They are not intended to be
used except during |
| 3671 * the resolution process. | 3666 * the resolution process. |
| 3672 * @coverage dart.engine.resolver | 3667 * @coverage dart.engine.resolver |
| 3673 */ | 3668 */ |
| 3674 class Library { | 3669 class Library { |
| 3675 | 3670 |
| 3676 /** | 3671 /** |
| 3677 * The analysis context in which this library is being analyzed. | 3672 * The analysis context in which this library is being analyzed. |
| 3678 */ | 3673 */ |
| 3679 InternalAnalysisContext _analysisContext; | 3674 InternalAnalysisContext _analysisContext; |
| 3680 | 3675 |
| 3681 /** | 3676 /** |
| 3682 * The inheritance manager which is used for this member lookups in this libra
ry. | 3677 * The inheritance manager which is used for this member lookups in this libra
ry. |
| 3683 */ | 3678 */ |
| 3684 InheritanceManager _inheritanceManager; | 3679 InheritanceManager _inheritanceManager; |
| 3685 | 3680 |
| 3686 /** | 3681 /** |
| 3687 * The listener to which analysis errors will be reported. | 3682 * The listener to which analysis errors will be reported. |
| 3688 */ | 3683 */ |
| 3689 AnalysisErrorListener _errorListener; | 3684 AnalysisErrorListener _errorListener; |
| 3690 | 3685 |
| 3691 /** | 3686 /** |
| 3692 * The source specifying the defining compilation unit of this library. | 3687 * The source specifying the defining compilation unit of this library. |
| 3693 */ | 3688 */ |
| 3694 Source _librarySource; | 3689 Source _librarySource; |
| 3695 | 3690 |
| 3696 /** | 3691 /** |
| 3697 * The library element representing this library. | 3692 * The library element representing this library. |
| 3698 */ | 3693 */ |
| 3699 LibraryElementImpl _libraryElement; | 3694 LibraryElementImpl _libraryElement; |
| 3700 | 3695 |
| 3701 /** | 3696 /** |
| 3702 * A list containing all of the libraries that are imported into this library. | 3697 * A list containing all of the libraries that are imported into this library. |
| 3703 */ | 3698 */ |
| 3704 Map<ImportDirective, Library> _importedLibraries = new Map<ImportDirective, Li
brary>(); | 3699 Map<ImportDirective, Library> _importedLibraries = new Map<ImportDirective, Li
brary>(); |
| 3705 | 3700 |
| 3706 /** | 3701 /** |
| 3707 * A table mapping URI-based directive to the actual URI value. | 3702 * A table mapping URI-based directive to the actual URI value. |
| 3708 */ | 3703 */ |
| 3709 Map<UriBasedDirective, String> _directiveUris = new Map<UriBasedDirective, Str
ing>(); | 3704 Map<UriBasedDirective, String> _directiveUris = new Map<UriBasedDirective, Str
ing>(); |
| 3710 | 3705 |
| 3711 /** | 3706 /** |
| 3712 * A flag indicating whether this library explicitly imports core. | 3707 * A flag indicating whether this library explicitly imports core. |
| 3713 */ | 3708 */ |
| 3714 bool _explicitlyImportsCore = false; | 3709 bool _explicitlyImportsCore = false; |
| 3715 | 3710 |
| 3716 /** | 3711 /** |
| 3717 * A list containing all of the libraries that are exported from this library. | 3712 * A list containing all of the libraries that are exported from this library. |
| 3718 */ | 3713 */ |
| 3719 Map<ExportDirective, Library> _exportedLibraries = new Map<ExportDirective, Li
brary>(); | 3714 Map<ExportDirective, Library> _exportedLibraries = new Map<ExportDirective, Li
brary>(); |
| 3720 | 3715 |
| 3721 /** | 3716 /** |
| 3722 * A table mapping the sources for the compilation units in this library to th
eir corresponding | 3717 * A table mapping the sources for the compilation units in this library to th
eir corresponding |
| 3723 * AST structures. | 3718 * AST structures. |
| 3724 */ | 3719 */ |
| 3725 Map<Source, CompilationUnit> _astMap = new Map<Source, CompilationUnit>(); | 3720 Map<Source, CompilationUnit> _astMap = new Map<Source, CompilationUnit>(); |
| 3726 | 3721 |
| 3727 /** | 3722 /** |
| 3728 * The library scope used when resolving elements within this library's compil
ation units. | 3723 * The library scope used when resolving elements within this library's compil
ation units. |
| 3729 */ | 3724 */ |
| 3730 LibraryScope _libraryScope; | 3725 LibraryScope _libraryScope; |
| 3731 | 3726 |
| 3732 /** | 3727 /** |
| 3733 * Initialize a newly created data holder that can maintain the data associate
d with a library. | 3728 * Initialize a newly created data holder that can maintain the data associate
d with a library. |
| 3734 * @param analysisContext the analysis context in which this library is being
analyzed | 3729 * @param analysisContext the analysis context in which this library is being
analyzed |
| 3735 * @param errorListener the listener to which analysis errors will be reported | 3730 * @param errorListener the listener to which analysis errors will be reported |
| 3736 * @param librarySource the source specifying the defining compilation unit of
this library | 3731 * @param librarySource the source specifying the defining compilation unit of
this library |
| 3737 */ | 3732 */ |
| 3738 Library(InternalAnalysisContext analysisContext, AnalysisErrorListener errorLi
stener, Source librarySource) { | 3733 Library(InternalAnalysisContext analysisContext, AnalysisErrorListener errorLi
stener, Source librarySource) { |
| 3739 this._analysisContext = analysisContext; | 3734 this._analysisContext = analysisContext; |
| 3740 this._errorListener = errorListener; | 3735 this._errorListener = errorListener; |
| 3741 this._librarySource = librarySource; | 3736 this._librarySource = librarySource; |
| 3742 this._libraryElement = analysisContext.getLibraryElement(librarySource) as L
ibraryElementImpl; | 3737 this._libraryElement = analysisContext.getLibraryElement(librarySource) as L
ibraryElementImpl; |
| 3743 } | 3738 } |
| 3744 | 3739 |
| 3745 /** | 3740 /** |
| 3746 * Record that the given library is exported from this library. | 3741 * Record that the given library is exported from this library. |
| 3747 * @param importLibrary the library that is exported from this library | 3742 * @param importLibrary the library that is exported from this library |
| 3748 */ | 3743 */ |
| 3749 void addExport(ExportDirective directive, Library exportLibrary) { | 3744 void addExport(ExportDirective directive, Library exportLibrary) { |
| 3750 _exportedLibraries[directive] = exportLibrary; | 3745 _exportedLibraries[directive] = exportLibrary; |
| 3751 } | 3746 } |
| 3752 | 3747 |
| 3753 /** | 3748 /** |
| 3754 * Record that the given library is imported into this library. | 3749 * Record that the given library is imported into this library. |
| 3755 * @param importLibrary the library that is imported into this library | 3750 * @param importLibrary the library that is imported into this library |
| 3756 */ | 3751 */ |
| 3757 void addImport(ImportDirective directive, Library importLibrary) { | 3752 void addImport(ImportDirective directive, Library importLibrary) { |
| 3758 _importedLibraries[directive] = importLibrary; | 3753 _importedLibraries[directive] = importLibrary; |
| 3759 } | 3754 } |
| 3760 | 3755 |
| 3761 /** | 3756 /** |
| 3762 * Return the AST structure associated with the given source. | 3757 * Return the AST structure associated with the given source. |
| 3763 * @param source the source representing the compilation unit whose AST is to
be returned | 3758 * @param source the source representing the compilation unit whose AST is to
be returned |
| 3764 * @return the AST structure associated with the given source | 3759 * @return the AST structure associated with the given source |
| 3765 * @throws AnalysisException if an AST structure could not be created for the
compilation unit | 3760 * @throws AnalysisException if an AST structure could not be created for the
compilation unit |
| 3766 */ | 3761 */ |
| 3767 CompilationUnit getAST(Source source) { | 3762 CompilationUnit getAST(Source source) { |
| 3768 CompilationUnit unit = _astMap[source]; | 3763 CompilationUnit unit = _astMap[source]; |
| 3769 if (unit == null) { | 3764 if (unit == null) { |
| 3770 unit = _analysisContext.computeResolvableCompilationUnit(source); | 3765 unit = _analysisContext.computeResolvableCompilationUnit(source); |
| 3771 _astMap[source] = unit; | 3766 _astMap[source] = unit; |
| 3772 } | 3767 } |
| 3773 return unit; | 3768 return unit; |
| 3774 } | 3769 } |
| 3775 | 3770 |
| 3776 /** | 3771 /** |
| 3777 * Return a collection containing the sources for the compilation units in thi
s library, including | 3772 * Return a collection containing the sources for the compilation units in thi
s library, including |
| 3778 * the defining compilation unit. | 3773 * the defining compilation unit. |
| 3779 * @return the sources for the compilation units in this library | 3774 * @return the sources for the compilation units in this library |
| 3780 */ | 3775 */ |
| 3781 Set<Source> get compilationUnitSources => _astMap.keys.toSet(); | 3776 Set<Source> get compilationUnitSources => _astMap.keys.toSet(); |
| 3782 | 3777 |
| 3783 /** | 3778 /** |
| 3784 * Return the AST structure associated with the defining compilation unit for
this library. | 3779 * Return the AST structure associated with the defining compilation unit for
this library. |
| 3785 * @return the AST structure associated with the defining compilation unit for
this library | 3780 * @return the AST structure associated with the defining compilation unit for
this library |
| 3786 * @throws AnalysisException if an AST structure could not be created for the
defining compilation | 3781 * @throws AnalysisException if an AST structure could not be created for the
defining compilation |
| 3787 * unit | 3782 * unit |
| 3788 */ | 3783 */ |
| 3789 CompilationUnit get definingCompilationUnit => getAST(librarySource); | 3784 CompilationUnit get definingCompilationUnit => getAST(librarySource); |
| 3790 | 3785 |
| 3791 /** | 3786 /** |
| 3792 * Return {@code true} if this library explicitly imports core. | 3787 * Return {@code true} if this library explicitly imports core. |
| 3793 * @return {@code true} if this library explicitly imports core | 3788 * @return {@code true} if this library explicitly imports core |
| 3794 */ | 3789 */ |
| 3795 bool get explicitlyImportsCore => _explicitlyImportsCore; | 3790 bool get explicitlyImportsCore => _explicitlyImportsCore; |
| 3796 | 3791 |
| 3797 /** | 3792 /** |
| 3798 * Return the library exported by the given directive. | 3793 * Return the library exported by the given directive. |
| 3799 * @param directive the directive that exports the library to be returned | 3794 * @param directive the directive that exports the library to be returned |
| 3800 * @return the library exported by the given directive | 3795 * @return the library exported by the given directive |
| 3801 */ | 3796 */ |
| 3802 Library getExport(ExportDirective directive) => _exportedLibraries[directive]; | 3797 Library getExport(ExportDirective directive) => _exportedLibraries[directive]; |
| 3803 | 3798 |
| 3804 /** | 3799 /** |
| 3805 * Return an array containing the libraries that are exported from this librar
y. | 3800 * Return an array containing the libraries that are exported from this librar
y. |
| 3806 * @return an array containing the libraries that are exported from this libra
ry | 3801 * @return an array containing the libraries that are exported from this libra
ry |
| 3807 */ | 3802 */ |
| 3808 List<Library> get exports { | 3803 List<Library> get exports { |
| 3809 Set<Library> libraries = new Set<Library>(); | 3804 Set<Library> libraries = new Set<Library>(); |
| 3810 libraries.addAll(_exportedLibraries.values); | 3805 libraries.addAll(_exportedLibraries.values); |
| 3811 return new List.from(libraries); | 3806 return new List.from(libraries); |
| 3812 } | 3807 } |
| 3813 | 3808 |
| 3814 /** | 3809 /** |
| 3815 * Return the library imported by the given directive. | 3810 * Return the library imported by the given directive. |
| 3816 * @param directive the directive that imports the library to be returned | 3811 * @param directive the directive that imports the library to be returned |
| 3817 * @return the library imported by the given directive | 3812 * @return the library imported by the given directive |
| 3818 */ | 3813 */ |
| 3819 Library getImport(ImportDirective directive) => _importedLibraries[directive]; | 3814 Library getImport(ImportDirective directive) => _importedLibraries[directive]; |
| 3820 | 3815 |
| 3821 /** | 3816 /** |
| 3822 * Return an array containing the libraries that are imported into this librar
y. | 3817 * Return an array containing the libraries that are imported into this librar
y. |
| 3823 * @return an array containing the libraries that are imported into this libra
ry | 3818 * @return an array containing the libraries that are imported into this libra
ry |
| 3824 */ | 3819 */ |
| 3825 List<Library> get imports { | 3820 List<Library> get imports { |
| 3826 Set<Library> libraries = new Set<Library>(); | 3821 Set<Library> libraries = new Set<Library>(); |
| 3827 libraries.addAll(_importedLibraries.values); | 3822 libraries.addAll(_importedLibraries.values); |
| 3828 return new List.from(libraries); | 3823 return new List.from(libraries); |
| 3829 } | 3824 } |
| 3830 | 3825 |
| 3831 /** | 3826 /** |
| 3832 * Return an array containing the libraries that are either imported or export
ed from this | 3827 * Return an array containing the libraries that are either imported or export
ed from this |
| 3833 * library. | 3828 * library. |
| 3834 * @return the libraries that are either imported or exported from this librar
y | 3829 * @return the libraries that are either imported or exported from this librar
y |
| 3835 */ | 3830 */ |
| 3836 List<Library> get importsAndExports { | 3831 List<Library> get importsAndExports { |
| 3837 Set<Library> libraries = new Set<Library>(); | 3832 Set<Library> libraries = new Set<Library>(); |
| 3838 libraries.addAll(_importedLibraries.values); | 3833 libraries.addAll(_importedLibraries.values); |
| 3839 libraries.addAll(_exportedLibraries.values); | 3834 libraries.addAll(_exportedLibraries.values); |
| 3840 return new List.from(libraries); | 3835 return new List.from(libraries); |
| 3841 } | 3836 } |
| 3842 | 3837 |
| 3843 /** | 3838 /** |
| 3844 * Return the inheritance manager for this library. | 3839 * Return the inheritance manager for this library. |
| 3845 * @return the inheritance manager for this library | 3840 * @return the inheritance manager for this library |
| 3846 */ | 3841 */ |
| 3847 InheritanceManager get inheritanceManager { | 3842 InheritanceManager get inheritanceManager { |
| 3848 if (_inheritanceManager == null) { | 3843 if (_inheritanceManager == null) { |
| 3849 return _inheritanceManager = new InheritanceManager(_libraryElement); | 3844 return _inheritanceManager = new InheritanceManager(_libraryElement); |
| 3850 } | 3845 } |
| 3851 return _inheritanceManager; | 3846 return _inheritanceManager; |
| 3852 } | 3847 } |
| 3853 | 3848 |
| 3854 /** | 3849 /** |
| 3855 * Return the library element representing this library, creating it if necess
ary. | 3850 * Return the library element representing this library, creating it if necess
ary. |
| 3856 * @return the library element representing this library | 3851 * @return the library element representing this library |
| 3857 */ | 3852 */ |
| 3858 LibraryElementImpl get libraryElement { | 3853 LibraryElementImpl get libraryElement { |
| 3859 if (_libraryElement == null) { | 3854 if (_libraryElement == null) { |
| 3860 try { | 3855 try { |
| 3861 _libraryElement = _analysisContext.computeLibraryElement(_librarySource)
as LibraryElementImpl; | 3856 _libraryElement = _analysisContext.computeLibraryElement(_librarySource)
as LibraryElementImpl; |
| 3862 } on AnalysisException catch (exception) { | 3857 } on AnalysisException catch (exception) { |
| 3863 AnalysisEngine.instance.logger.logError2("Could not compute ilbrary elem
ent for ${_librarySource.fullName}", exception); | 3858 AnalysisEngine.instance.logger.logError2("Could not compute ilbrary elem
ent for ${_librarySource.fullName}", exception); |
| 3864 } | 3859 } |
| 3865 } | 3860 } |
| 3866 return _libraryElement; | 3861 return _libraryElement; |
| 3867 } | 3862 } |
| 3868 | 3863 |
| 3869 /** | 3864 /** |
| 3870 * Return the library scope used when resolving elements within this library's
compilation units. | 3865 * Return the library scope used when resolving elements within this library's
compilation units. |
| 3871 * @return the library scope used when resolving elements within this library'
s compilation units | 3866 * @return the library scope used when resolving elements within this library'
s compilation units |
| 3872 */ | 3867 */ |
| 3873 LibraryScope get libraryScope { | 3868 LibraryScope get libraryScope { |
| 3874 if (_libraryScope == null) { | 3869 if (_libraryScope == null) { |
| 3875 _libraryScope = new LibraryScope(_libraryElement, _errorListener); | 3870 _libraryScope = new LibraryScope(_libraryElement, _errorListener); |
| 3876 } | 3871 } |
| 3877 return _libraryScope; | 3872 return _libraryScope; |
| 3878 } | 3873 } |
| 3879 | 3874 |
| 3880 /** | 3875 /** |
| 3881 * Return the source specifying the defining compilation unit of this library. | 3876 * Return the source specifying the defining compilation unit of this library. |
| 3882 * @return the source specifying the defining compilation unit of this library | 3877 * @return the source specifying the defining compilation unit of this library |
| 3883 */ | 3878 */ |
| 3884 Source get librarySource => _librarySource; | 3879 Source get librarySource => _librarySource; |
| 3885 | 3880 |
| 3886 /** | 3881 /** |
| 3887 * Return the result of resolving the URI of the given URI-based directive aga
inst the URI of the | 3882 * Return the result of resolving the URI of the given URI-based directive aga
inst the URI of the |
| 3888 * library, or {@code null} if the URI is not valid. If the URI is not valid,
report the error. | 3883 * library, or {@code null} if the URI is not valid. If the URI is not valid,
report the error. |
| 3889 * @param directive the directive which URI should be resolved | 3884 * @param directive the directive which URI should be resolved |
| 3890 * @return the result of resolving the URI against the URI of the library | 3885 * @return the result of resolving the URI against the URI of the library |
| 3891 */ | 3886 */ |
| 3892 Source getSource(UriBasedDirective directive) { | 3887 Source getSource(UriBasedDirective directive) { |
| 3893 StringLiteral uriLiteral = directive.uri; | 3888 StringLiteral uriLiteral = directive.uri; |
| 3894 if (uriLiteral is StringInterpolation) { | 3889 if (uriLiteral is StringInterpolation) { |
| 3895 _errorListener.onError(new AnalysisError.con2(_librarySource, uriLiteral.o
ffset, uriLiteral.length, CompileTimeErrorCode.URI_WITH_INTERPOLATION, [])); | 3890 _errorListener.onError(new AnalysisError.con2(_librarySource, uriLiteral.o
ffset, uriLiteral.length, CompileTimeErrorCode.URI_WITH_INTERPOLATION, [])); |
| 3896 return null; | 3891 return null; |
| 3897 } | 3892 } |
| 3898 String uriContent = uriLiteral.stringValue.trim(); | 3893 String uriContent = uriLiteral.stringValue.trim(); |
| 3899 _directiveUris[directive] = uriContent; | 3894 _directiveUris[directive] = uriContent; |
| 3900 try { | 3895 try { |
| 3901 parseUriWithException(uriContent); | 3896 parseUriWithException(uriContent); |
| 3902 Source source = getSource2(uriContent); | 3897 Source source = getSource2(uriContent); |
| 3903 if (source == null || !source.exists()) { | 3898 if (source == null || !source.exists()) { |
| 3904 _errorListener.onError(new AnalysisError.con2(_librarySource, uriLiteral
.offset, uriLiteral.length, CompileTimeErrorCode.URI_DOES_NOT_EXIST, [uriContent
])); | 3899 _errorListener.onError(new AnalysisError.con2(_librarySource, uriLiteral
.offset, uriLiteral.length, CompileTimeErrorCode.URI_DOES_NOT_EXIST, [uriContent
])); |
| 3905 } | 3900 } |
| 3906 return source; | 3901 return source; |
| 3907 } on URISyntaxException catch (exception) { | 3902 } on URISyntaxException catch (exception) { |
| 3908 _errorListener.onError(new AnalysisError.con2(_librarySource, uriLiteral.o
ffset, uriLiteral.length, CompileTimeErrorCode.INVALID_URI, [uriContent])); | 3903 _errorListener.onError(new AnalysisError.con2(_librarySource, uriLiteral.o
ffset, uriLiteral.length, CompileTimeErrorCode.INVALID_URI, [uriContent])); |
| 3909 } | 3904 } |
| 3910 return null; | 3905 return null; |
| 3911 } | 3906 } |
| 3912 | 3907 |
| 3913 /** | 3908 /** |
| 3914 * Returns the URI value of the given directive. | 3909 * Returns the URI value of the given directive. |
| 3915 */ | 3910 */ |
| 3916 String getUri(UriBasedDirective directive) => _directiveUris[directive]; | 3911 String getUri(UriBasedDirective directive) => _directiveUris[directive]; |
| 3917 | 3912 |
| 3918 /** | 3913 /** |
| 3919 * Set the AST structure associated with the defining compilation unit for thi
s library to the | 3914 * Set the AST structure associated with the defining compilation unit for thi
s library to the |
| 3920 * given AST structure. | 3915 * given AST structure. |
| 3921 * @param unit the AST structure associated with the defining compilation unit
for this library | 3916 * @param unit the AST structure associated with the defining compilation unit
for this library |
| 3922 */ | 3917 */ |
| 3923 void set definingCompilationUnit(CompilationUnit unit) { | 3918 void set definingCompilationUnit(CompilationUnit unit) { |
| 3924 _astMap[librarySource] = unit; | 3919 _astMap[librarySource] = unit; |
| 3925 } | 3920 } |
| 3926 | 3921 |
| 3927 /** | 3922 /** |
| 3928 * Set whether this library explicitly imports core to match the given value. | 3923 * Set whether this library explicitly imports core to match the given value. |
| 3929 * @param explicitlyImportsCore {@code true} if this library explicitly import
s core | 3924 * @param explicitlyImportsCore {@code true} if this library explicitly import
s core |
| 3930 */ | 3925 */ |
| 3931 void set explicitlyImportsCore(bool explicitlyImportsCore2) { | 3926 void set explicitlyImportsCore(bool explicitlyImportsCore2) { |
| 3932 this._explicitlyImportsCore = explicitlyImportsCore2; | 3927 this._explicitlyImportsCore = explicitlyImportsCore2; |
| 3933 } | 3928 } |
| 3934 | 3929 |
| 3935 /** | 3930 /** |
| 3936 * Set the library element representing this library to the given library elem
ent. | 3931 * Set the library element representing this library to the given library elem
ent. |
| 3937 * @param libraryElement the library element representing this library | 3932 * @param libraryElement the library element representing this library |
| 3938 */ | 3933 */ |
| 3939 void set libraryElement(LibraryElementImpl libraryElement2) { | 3934 void set libraryElement(LibraryElementImpl libraryElement2) { |
| 3940 this._libraryElement = libraryElement2; | 3935 this._libraryElement = libraryElement2; |
| 3941 if (_inheritanceManager != null) { | 3936 if (_inheritanceManager != null) { |
| 3942 _inheritanceManager.libraryElement = libraryElement2; | 3937 _inheritanceManager.libraryElement = libraryElement2; |
| 3943 } | 3938 } |
| 3944 } | 3939 } |
| 3945 String toString() => _librarySource.shortName; | 3940 String toString() => _librarySource.shortName; |
| 3946 | 3941 |
| 3947 /** | 3942 /** |
| 3948 * Return the result of resolving the given URI against the URI of the library
, or {@code null} if | 3943 * Return the result of resolving the given URI against the URI of the library
, or {@code null} if |
| 3949 * the URI is not valid. | 3944 * the URI is not valid. |
| 3950 * @param uri the URI to be resolved | 3945 * @param uri the URI to be resolved |
| 3951 * @return the result of resolving the given URI against the URI of the librar
y | 3946 * @return the result of resolving the given URI against the URI of the librar
y |
| 3952 */ | 3947 */ |
| 3953 Source getSource2(String uri) { | 3948 Source getSource2(String uri) { |
| 3954 if (uri == null) { | 3949 if (uri == null) { |
| 3955 return null; | 3950 return null; |
| 3956 } | 3951 } |
| 3957 return _analysisContext.sourceFactory.resolveUri(_librarySource, uri); | 3952 return _analysisContext.sourceFactory.resolveUri(_librarySource, uri); |
| 3958 } | 3953 } |
| 3959 } | 3954 } |
| 3960 | |
| 3961 /** | 3955 /** |
| 3962 * Instances of the class {@code LibraryElementBuilder} build an element model f
or a single library. | 3956 * Instances of the class {@code LibraryElementBuilder} build an element model f
or a single library. |
| 3963 * @coverage dart.engine.resolver | 3957 * @coverage dart.engine.resolver |
| 3964 */ | 3958 */ |
| 3965 class LibraryElementBuilder { | 3959 class LibraryElementBuilder { |
| 3966 | 3960 |
| 3967 /** | 3961 /** |
| 3968 * The analysis context in which the element model will be built. | 3962 * The analysis context in which the element model will be built. |
| 3969 */ | 3963 */ |
| 3970 InternalAnalysisContext _analysisContext; | 3964 InternalAnalysisContext _analysisContext; |
| 3971 | 3965 |
| 3972 /** | 3966 /** |
| 3973 * The listener to which errors will be reported. | 3967 * The listener to which errors will be reported. |
| 3974 */ | 3968 */ |
| 3975 AnalysisErrorListener _errorListener; | 3969 AnalysisErrorListener _errorListener; |
| 3976 | 3970 |
| 3977 /** | 3971 /** |
| 3978 * The name of the function used as an entry point. | 3972 * The name of the function used as an entry point. |
| 3979 */ | 3973 */ |
| 3980 static String _ENTRY_POINT_NAME = "main"; | 3974 static String _ENTRY_POINT_NAME = "main"; |
| 3981 | 3975 |
| 3982 /** | 3976 /** |
| 3983 * Initialize a newly created library element builder. | 3977 * Initialize a newly created library element builder. |
| 3984 * @param resolver the resolver for which the element model is being built | 3978 * @param resolver the resolver for which the element model is being built |
| 3985 */ | 3979 */ |
| 3986 LibraryElementBuilder(LibraryResolver resolver) { | 3980 LibraryElementBuilder(LibraryResolver resolver) { |
| 3987 this._analysisContext = resolver.analysisContext; | 3981 this._analysisContext = resolver.analysisContext; |
| 3988 this._errorListener = resolver.errorListener; | 3982 this._errorListener = resolver.errorListener; |
| 3989 } | 3983 } |
| 3990 | 3984 |
| 3991 /** | 3985 /** |
| 3992 * Build the library element for the given library. | 3986 * Build the library element for the given library. |
| 3993 * @param library the library for which an element model is to be built | 3987 * @param library the library for which an element model is to be built |
| 3994 * @return the library element that was built | 3988 * @return the library element that was built |
| 3995 * @throws AnalysisException if the analysis could not be performed | 3989 * @throws AnalysisException if the analysis could not be performed |
| 3996 */ | 3990 */ |
| 3997 LibraryElementImpl buildLibrary(Library library) { | 3991 LibraryElementImpl buildLibrary(Library library) { |
| 3998 CompilationUnitBuilder builder = new CompilationUnitBuilder(); | 3992 CompilationUnitBuilder builder = new CompilationUnitBuilder(); |
| 3999 Source librarySource2 = library.librarySource; | 3993 Source librarySource2 = library.librarySource; |
| 4000 CompilationUnit definingCompilationUnit2 = library.definingCompilationUnit; | 3994 CompilationUnit definingCompilationUnit2 = library.definingCompilationUnit; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4046 libraryElement.parts = new List.from(sourcedCompilationUnits); | 4040 libraryElement.parts = new List.from(sourcedCompilationUnits); |
| 4047 for (Directive directive in directivesToResolve) { | 4041 for (Directive directive in directivesToResolve) { |
| 4048 directive.element = libraryElement; | 4042 directive.element = libraryElement; |
| 4049 } | 4043 } |
| 4050 library.libraryElement = libraryElement; | 4044 library.libraryElement = libraryElement; |
| 4051 if (sourcedUnitCount > 0) { | 4045 if (sourcedUnitCount > 0) { |
| 4052 patchTopLevelAccessors(libraryElement); | 4046 patchTopLevelAccessors(libraryElement); |
| 4053 } | 4047 } |
| 4054 return libraryElement; | 4048 return libraryElement; |
| 4055 } | 4049 } |
| 4056 | 4050 |
| 4057 /** | 4051 /** |
| 4058 * Add all of the non-synthetic getters and setters defined in the given compi
lation unit that | 4052 * Add all of the non-synthetic getters and setters defined in the given compi
lation unit that |
| 4059 * have no corresponding accessor to one of the given collections. | 4053 * have no corresponding accessor to one of the given collections. |
| 4060 * @param getters the map to which getters are to be added | 4054 * @param getters the map to which getters are to be added |
| 4061 * @param setters the list to which setters are to be added | 4055 * @param setters the list to which setters are to be added |
| 4062 * @param unit the compilation unit defining the accessors that are potentiall
y being added | 4056 * @param unit the compilation unit defining the accessors that are potentiall
y being added |
| 4063 */ | 4057 */ |
| 4064 void collectAccessors(Map<String, PropertyAccessorElement> getters, List<Prope
rtyAccessorElement> setters, CompilationUnitElement unit) { | 4058 void collectAccessors(Map<String, PropertyAccessorElement> getters, List<Prope
rtyAccessorElement> setters, CompilationUnitElement unit) { |
| 4065 for (PropertyAccessorElement accessor in unit.accessors) { | 4059 for (PropertyAccessorElement accessor in unit.accessors) { |
| 4066 if (accessor.isGetter()) { | 4060 if (accessor.isGetter()) { |
| 4067 if (!accessor.isSynthetic() && accessor.correspondingSetter == null) { | 4061 if (!accessor.isSynthetic() && accessor.correspondingSetter == null) { |
| 4068 getters[accessor.displayName] = accessor; | 4062 getters[accessor.displayName] = accessor; |
| 4069 } | 4063 } |
| 4070 } else { | 4064 } else { |
| 4071 if (!accessor.isSynthetic() && accessor.correspondingGetter == null) { | 4065 if (!accessor.isSynthetic() && accessor.correspondingGetter == null) { |
| 4072 setters.add(accessor); | 4066 setters.add(accessor); |
| 4073 } | 4067 } |
| 4074 } | 4068 } |
| 4075 } | 4069 } |
| 4076 } | 4070 } |
| 4077 | 4071 |
| 4078 /** | 4072 /** |
| 4079 * Search the top-level functions defined in the given compilation unit for th
e entry point. | 4073 * Search the top-level functions defined in the given compilation unit for th
e entry point. |
| 4080 * @param element the compilation unit to be searched | 4074 * @param element the compilation unit to be searched |
| 4081 * @return the entry point that was found, or {@code null} if the compilation
unit does not define | 4075 * @return the entry point that was found, or {@code null} if the compilation
unit does not define |
| 4082 * an entry point | 4076 * an entry point |
| 4083 */ | 4077 */ |
| 4084 FunctionElement findEntryPoint(CompilationUnitElementImpl element) { | 4078 FunctionElement findEntryPoint(CompilationUnitElementImpl element) { |
| 4085 for (FunctionElement function in element.functions) { | 4079 for (FunctionElement function in element.functions) { |
| 4086 if (function.name == _ENTRY_POINT_NAME) { | 4080 if (function.name == _ENTRY_POINT_NAME) { |
| 4087 return function; | 4081 return function; |
| 4088 } | 4082 } |
| 4089 } | 4083 } |
| 4090 return null; | 4084 return null; |
| 4091 } | 4085 } |
| 4092 | 4086 |
| 4093 /** | 4087 /** |
| 4094 * Return the name of the library that the given part is declared to be a part
of, or {@code null}if the part does not contain a part-of directive. | 4088 * Return the name of the library that the given part is declared to be a part
of, or {@code null}if the part does not contain a part-of directive. |
| 4095 * @param library the library containing the part | 4089 * @param library the library containing the part |
| 4096 * @param partSource the source representing the part | 4090 * @param partSource the source representing the part |
| 4097 * @param directivesToResolve a list of directives that should be resolved to
the library being | 4091 * @param directivesToResolve a list of directives that should be resolved to
the library being |
| 4098 * built | 4092 * built |
| 4099 * @return the name of the library that the given part is declared to be a par
t of | 4093 * @return the name of the library that the given part is declared to be a par
t of |
| 4100 */ | 4094 */ |
| 4101 String getPartLibraryName(Library library, Source partSource, List<Directive>
directivesToResolve) { | 4095 String getPartLibraryName(Library library, Source partSource, List<Directive>
directivesToResolve) { |
| 4102 try { | 4096 try { |
| 4103 CompilationUnit partUnit = library.getAST(partSource); | 4097 CompilationUnit partUnit = library.getAST(partSource); |
| 4104 for (Directive directive in partUnit.directives) { | 4098 for (Directive directive in partUnit.directives) { |
| 4105 if (directive is PartOfDirective) { | 4099 if (directive is PartOfDirective) { |
| 4106 directivesToResolve.add(directive); | 4100 directivesToResolve.add(directive); |
| 4107 LibraryIdentifier libraryName2 = ((directive as PartOfDirective)).libr
aryName; | 4101 LibraryIdentifier libraryName2 = ((directive as PartOfDirective)).libr
aryName; |
| 4108 if (libraryName2 != null) { | 4102 if (libraryName2 != null) { |
| 4109 return libraryName2.name; | 4103 return libraryName2.name; |
| 4110 } | 4104 } |
| 4111 } | 4105 } |
| 4112 } | 4106 } |
| 4113 } on AnalysisException catch (exception) { | 4107 } on AnalysisException catch (exception) { |
| 4114 } | 4108 } |
| 4115 return null; | 4109 return null; |
| 4116 } | 4110 } |
| 4117 | 4111 |
| 4118 /** | 4112 /** |
| 4119 * Look through all of the compilation units defined for the given library, lo
oking for getters | 4113 * Look through all of the compilation units defined for the given library, lo
oking for getters |
| 4120 * and setters that are defined in different compilation units but that have t
he same names. If | 4114 * and setters that are defined in different compilation units but that have t
he same names. If |
| 4121 * any are found, make sure that they have the same variable element. | 4115 * any are found, make sure that they have the same variable element. |
| 4122 * @param libraryElement the library defining the compilation units to be proc
essed | 4116 * @param libraryElement the library defining the compilation units to be proc
essed |
| 4123 */ | 4117 */ |
| 4124 void patchTopLevelAccessors(LibraryElementImpl libraryElement) { | 4118 void patchTopLevelAccessors(LibraryElementImpl libraryElement) { |
| 4125 Map<String, PropertyAccessorElement> getters = new Map<String, PropertyAcces
sorElement>(); | 4119 Map<String, PropertyAccessorElement> getters = new Map<String, PropertyAcces
sorElement>(); |
| 4126 List<PropertyAccessorElement> setters = new List<PropertyAccessorElement>(); | 4120 List<PropertyAccessorElement> setters = new List<PropertyAccessorElement>(); |
| 4127 collectAccessors(getters, setters, libraryElement.definingCompilationUnit); | 4121 collectAccessors(getters, setters, libraryElement.definingCompilationUnit); |
| 4128 for (CompilationUnitElement unit in libraryElement.parts) { | 4122 for (CompilationUnitElement unit in libraryElement.parts) { |
| 4129 collectAccessors(getters, setters, unit); | 4123 collectAccessors(getters, setters, unit); |
| 4130 } | 4124 } |
| 4131 for (PropertyAccessorElement setter in setters) { | 4125 for (PropertyAccessorElement setter in setters) { |
| 4132 PropertyAccessorElement getter = getters[setter.displayName]; | 4126 PropertyAccessorElement getter = getters[setter.displayName]; |
| 4133 if (getter != null) { | 4127 if (getter != null) { |
| 4134 PropertyInducingElementImpl variable2 = getter.variable as PropertyInduc
ingElementImpl; | 4128 PropertyInducingElementImpl variable2 = getter.variable as PropertyInduc
ingElementImpl; |
| 4135 variable2.setter = setter; | 4129 variable2.setter = setter; |
| 4136 ((setter as PropertyAccessorElementImpl)).variable = variable2; | 4130 ((setter as PropertyAccessorElementImpl)).variable = variable2; |
| 4137 } | 4131 } |
| 4138 } | 4132 } |
| 4139 } | 4133 } |
| 4140 } | 4134 } |
| 4141 | |
| 4142 /** | 4135 /** |
| 4143 * Instances of the class {@code LibraryResolver} are used to resolve one or mor
e mutually dependent | 4136 * Instances of the class {@code LibraryResolver} are used to resolve one or mor
e mutually dependent |
| 4144 * libraries within a single context. | 4137 * libraries within a single context. |
| 4145 * @coverage dart.engine.resolver | 4138 * @coverage dart.engine.resolver |
| 4146 */ | 4139 */ |
| 4147 class LibraryResolver { | 4140 class LibraryResolver { |
| 4148 | 4141 |
| 4149 /** | 4142 /** |
| 4150 * The analysis context in which the libraries are being analyzed. | 4143 * The analysis context in which the libraries are being analyzed. |
| 4151 */ | 4144 */ |
| 4152 InternalAnalysisContext _analysisContext; | 4145 InternalAnalysisContext _analysisContext; |
| 4153 | 4146 |
| 4154 /** | 4147 /** |
| 4155 * The listener to which analysis errors will be reported, this error listener
is either | 4148 * The listener to which analysis errors will be reported, this error listener
is either |
| 4156 * references {@link #recordingErrorListener}, or it unions the passed{@link A
nalysisErrorListener} with the {@link #recordingErrorListener}. | 4149 * references {@link #recordingErrorListener}, or it unions the passed{@link A
nalysisErrorListener} with the {@link #recordingErrorListener}. |
| 4157 */ | 4150 */ |
| 4158 RecordingErrorListener _errorListener; | 4151 RecordingErrorListener _errorListener; |
| 4159 | 4152 |
| 4160 /** | 4153 /** |
| 4161 * A source object representing the core library (dart:core). | 4154 * A source object representing the core library (dart:core). |
| 4162 */ | 4155 */ |
| 4163 Source _coreLibrarySource; | 4156 Source _coreLibrarySource; |
| 4164 | 4157 |
| 4165 /** | 4158 /** |
| 4166 * The object representing the core library. | 4159 * The object representing the core library. |
| 4167 */ | 4160 */ |
| 4168 Library _coreLibrary; | 4161 Library _coreLibrary; |
| 4169 | 4162 |
| 4170 /** | 4163 /** |
| 4171 * The object used to access the types from the core library. | 4164 * The object used to access the types from the core library. |
| 4172 */ | 4165 */ |
| 4173 TypeProvider _typeProvider; | 4166 TypeProvider _typeProvider; |
| 4174 | 4167 |
| 4175 /** | 4168 /** |
| 4176 * A table mapping library sources to the information being maintained for tho
se libraries. | 4169 * A table mapping library sources to the information being maintained for tho
se libraries. |
| 4177 */ | 4170 */ |
| 4178 Map<Source, Library> _libraryMap = new Map<Source, Library>(); | 4171 Map<Source, Library> _libraryMap = new Map<Source, Library>(); |
| 4179 | 4172 |
| 4180 /** | 4173 /** |
| 4181 * A collection containing the libraries that are being resolved together. | 4174 * A collection containing the libraries that are being resolved together. |
| 4182 */ | 4175 */ |
| 4183 Set<Library> _librariesInCycles; | 4176 Set<Library> _librariesInCycles; |
| 4184 | 4177 |
| 4185 /** | 4178 /** |
| 4186 * Initialize a newly created library resolver to resolve libraries within the
given context. | 4179 * Initialize a newly created library resolver to resolve libraries within the
given context. |
| 4187 * @param analysisContext the analysis context in which the library is being a
nalyzed | 4180 * @param analysisContext the analysis context in which the library is being a
nalyzed |
| 4188 */ | 4181 */ |
| 4189 LibraryResolver(InternalAnalysisContext analysisContext) { | 4182 LibraryResolver(InternalAnalysisContext analysisContext) { |
| 4190 this._analysisContext = analysisContext; | 4183 this._analysisContext = analysisContext; |
| 4191 this._errorListener = new RecordingErrorListener(); | 4184 this._errorListener = new RecordingErrorListener(); |
| 4192 _coreLibrarySource = analysisContext.sourceFactory.forUri(DartSdk.DART_CORE)
; | 4185 _coreLibrarySource = analysisContext.sourceFactory.forUri(DartSdk.DART_CORE)
; |
| 4193 } | 4186 } |
| 4194 | 4187 |
| 4195 /** | 4188 /** |
| 4196 * Return the analysis context in which the libraries are being analyzed. | 4189 * Return the analysis context in which the libraries are being analyzed. |
| 4197 * @return the analysis context in which the libraries are being analyzed | 4190 * @return the analysis context in which the libraries are being analyzed |
| 4198 */ | 4191 */ |
| 4199 InternalAnalysisContext get analysisContext => _analysisContext; | 4192 InternalAnalysisContext get analysisContext => _analysisContext; |
| 4200 | 4193 |
| 4201 /** | 4194 /** |
| 4202 * Return the listener to which analysis errors will be reported. | 4195 * Return the listener to which analysis errors will be reported. |
| 4203 * @return the listener to which analysis errors will be reported | 4196 * @return the listener to which analysis errors will be reported |
| 4204 */ | 4197 */ |
| 4205 RecordingErrorListener get errorListener => _errorListener; | 4198 RecordingErrorListener get errorListener => _errorListener; |
| 4206 | 4199 |
| 4207 /** | 4200 /** |
| 4208 * Return an array containing information about all of the libraries that were
resolved. | 4201 * Return an array containing information about all of the libraries that were
resolved. |
| 4209 * @return an array containing the libraries that were resolved | 4202 * @return an array containing the libraries that were resolved |
| 4210 */ | 4203 */ |
| 4211 Set<Library> get resolvedLibraries => _librariesInCycles; | 4204 Set<Library> get resolvedLibraries => _librariesInCycles; |
| 4212 | 4205 |
| 4213 /** | 4206 /** |
| 4214 * Resolve the library specified by the given source in the given context. The
library is assumed | 4207 * Resolve the library specified by the given source in the given context. The
library is assumed |
| 4215 * to be embedded in the given source. | 4208 * to be embedded in the given source. |
| 4216 * @param librarySource the source specifying the defining compilation unit of
the library to be | 4209 * @param librarySource the source specifying the defining compilation unit of
the library to be |
| 4217 * resolved | 4210 * resolved |
| 4218 * @param unit the compilation unit representing the embedded library | 4211 * @param unit the compilation unit representing the embedded library |
| 4219 * @param fullAnalysis {@code true} if a full analysis should be performed | 4212 * @param fullAnalysis {@code true} if a full analysis should be performed |
| 4220 * @return the element representing the resolved library | 4213 * @return the element representing the resolved library |
| 4221 * @throws AnalysisException if the library could not be resolved for some rea
son | 4214 * @throws AnalysisException if the library could not be resolved for some rea
son |
| 4222 */ | 4215 */ |
| (...skipping 27 matching lines...) Expand all Loading... |
| 4250 instrumentation.metric3("performConstantEvaluation", "complete"); | 4243 instrumentation.metric3("performConstantEvaluation", "complete"); |
| 4251 if (fullAnalysis) { | 4244 if (fullAnalysis) { |
| 4252 runAdditionalAnalyses(); | 4245 runAdditionalAnalyses(); |
| 4253 instrumentation.metric3("runAdditionalAnalyses", "complete"); | 4246 instrumentation.metric3("runAdditionalAnalyses", "complete"); |
| 4254 } | 4247 } |
| 4255 return targetLibrary.libraryElement; | 4248 return targetLibrary.libraryElement; |
| 4256 } finally { | 4249 } finally { |
| 4257 instrumentation.log(); | 4250 instrumentation.log(); |
| 4258 } | 4251 } |
| 4259 } | 4252 } |
| 4260 | 4253 |
| 4261 /** | 4254 /** |
| 4262 * Resolve the library specified by the given source in the given context. | 4255 * Resolve the library specified by the given source in the given context. |
| 4263 * <p> | 4256 * <p> |
| 4264 * Note that because Dart allows circular imports between libraries, it is pos
sible that more than | 4257 * Note that because Dart allows circular imports between libraries, it is pos
sible that more than |
| 4265 * one library will need to be resolved. In such cases the error listener can
receive errors from | 4258 * one library will need to be resolved. In such cases the error listener can
receive errors from |
| 4266 * multiple libraries. | 4259 * multiple libraries. |
| 4267 * @param librarySource the source specifying the defining compilation unit of
the library to be | 4260 * @param librarySource the source specifying the defining compilation unit of
the library to be |
| 4268 * resolved | 4261 * resolved |
| 4269 * @param fullAnalysis {@code true} if a full analysis should be performed | 4262 * @param fullAnalysis {@code true} if a full analysis should be performed |
| 4270 * @return the element representing the resolved library | 4263 * @return the element representing the resolved library |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4304 } | 4297 } |
| 4305 instrumentation.metric2("librariesInCycles", _librariesInCycles.length); | 4298 instrumentation.metric2("librariesInCycles", _librariesInCycles.length); |
| 4306 for (Library lib in _librariesInCycles) { | 4299 for (Library lib in _librariesInCycles) { |
| 4307 instrumentation.metric2("librariesInCycles-CompilationUnitSources-Size",
lib.compilationUnitSources.length); | 4300 instrumentation.metric2("librariesInCycles-CompilationUnitSources-Size",
lib.compilationUnitSources.length); |
| 4308 } | 4301 } |
| 4309 return targetLibrary.libraryElement; | 4302 return targetLibrary.libraryElement; |
| 4310 } finally { | 4303 } finally { |
| 4311 instrumentation.log(); | 4304 instrumentation.log(); |
| 4312 } | 4305 } |
| 4313 } | 4306 } |
| 4314 | 4307 |
| 4315 /** | 4308 /** |
| 4316 * Add a dependency to the given map from the referencing library to the refer
enced library. | 4309 * Add a dependency to the given map from the referencing library to the refer
enced library. |
| 4317 * @param dependencyMap the map to which the dependency is to be added | 4310 * @param dependencyMap the map to which the dependency is to be added |
| 4318 * @param referencingLibrary the library that references the referenced librar
y | 4311 * @param referencingLibrary the library that references the referenced librar
y |
| 4319 * @param referencedLibrary the library referenced by the referencing library | 4312 * @param referencedLibrary the library referenced by the referencing library |
| 4320 */ | 4313 */ |
| 4321 void addDependencyToMap(Map<Library, List<Library>> dependencyMap, Library ref
erencingLibrary, Library referencedLibrary) { | 4314 void addDependencyToMap(Map<Library, List<Library>> dependencyMap, Library ref
erencingLibrary, Library referencedLibrary) { |
| 4322 List<Library> dependentLibraries = dependencyMap[referencedLibrary]; | 4315 List<Library> dependentLibraries = dependencyMap[referencedLibrary]; |
| 4323 if (dependentLibraries == null) { | 4316 if (dependentLibraries == null) { |
| 4324 dependentLibraries = new List<Library>(); | 4317 dependentLibraries = new List<Library>(); |
| 4325 dependencyMap[referencedLibrary] = dependentLibraries; | 4318 dependencyMap[referencedLibrary] = dependentLibraries; |
| 4326 } | 4319 } |
| 4327 dependentLibraries.add(referencingLibrary); | 4320 dependentLibraries.add(referencingLibrary); |
| 4328 } | 4321 } |
| 4329 | 4322 |
| 4330 /** | 4323 /** |
| 4331 * Given a library that is part of a cycle that includes the root library, add
to the given set of | 4324 * Given a library that is part of a cycle that includes the root library, add
to the given set of |
| 4332 * libraries all of the libraries reachable from the root library that are als
o included in the | 4325 * libraries all of the libraries reachable from the root library that are als
o included in the |
| 4333 * cycle. | 4326 * cycle. |
| 4334 * @param library the library to be added to the collection of libraries in cy
cles | 4327 * @param library the library to be added to the collection of libraries in cy
cles |
| 4335 * @param librariesInCycle a collection of the libraries that are in the cycle | 4328 * @param librariesInCycle a collection of the libraries that are in the cycle |
| 4336 * @param dependencyMap a table mapping libraries to the collection of librari
es from which those | 4329 * @param dependencyMap a table mapping libraries to the collection of librari
es from which those |
| 4337 * libraries are referenced | 4330 * libraries are referenced |
| 4338 */ | 4331 */ |
| 4339 void addLibrariesInCycle(Library library, Set<Library> librariesInCycle, Map<L
ibrary, List<Library>> dependencyMap) { | 4332 void addLibrariesInCycle(Library library, Set<Library> librariesInCycle, Map<L
ibrary, List<Library>> dependencyMap) { |
| 4340 if (javaSetAdd(librariesInCycle, library)) { | 4333 if (javaSetAdd(librariesInCycle, library)) { |
| 4341 List<Library> dependentLibraries = dependencyMap[library]; | 4334 List<Library> dependentLibraries = dependencyMap[library]; |
| 4342 if (dependentLibraries != null) { | 4335 if (dependentLibraries != null) { |
| 4343 for (Library dependentLibrary in dependentLibraries) { | 4336 for (Library dependentLibrary in dependentLibraries) { |
| 4344 addLibrariesInCycle(dependentLibrary, librariesInCycle, dependencyMap)
; | 4337 addLibrariesInCycle(dependentLibrary, librariesInCycle, dependencyMap)
; |
| 4345 } | 4338 } |
| 4346 } | 4339 } |
| 4347 } | 4340 } |
| 4348 } | 4341 } |
| 4349 | 4342 |
| 4350 /** | 4343 /** |
| 4351 * Add the given library, and all libraries reachable from it that have not al
ready been visited, | 4344 * Add the given library, and all libraries reachable from it that have not al
ready been visited, |
| 4352 * to the given dependency map. | 4345 * to the given dependency map. |
| 4353 * @param library the library currently being added to the dependency map | 4346 * @param library the library currently being added to the dependency map |
| 4354 * @param dependencyMap the dependency map being computed | 4347 * @param dependencyMap the dependency map being computed |
| 4355 * @param visitedLibraries the libraries that have already been visited, used
to prevent infinite | 4348 * @param visitedLibraries the libraries that have already been visited, used
to prevent infinite |
| 4356 * recursion | 4349 * recursion |
| 4357 */ | 4350 */ |
| 4358 void addToDependencyMap(Library library, Map<Library, List<Library>> dependenc
yMap, Set<Library> visitedLibraries) { | 4351 void addToDependencyMap(Library library, Map<Library, List<Library>> dependenc
yMap, Set<Library> visitedLibraries) { |
| 4359 if (javaSetAdd(visitedLibraries, library)) { | 4352 if (javaSetAdd(visitedLibraries, library)) { |
| 4360 for (Library referencedLibrary in library.importsAndExports) { | 4353 for (Library referencedLibrary in library.importsAndExports) { |
| 4361 addDependencyToMap(dependencyMap, library, referencedLibrary); | 4354 addDependencyToMap(dependencyMap, library, referencedLibrary); |
| 4362 addToDependencyMap(referencedLibrary, dependencyMap, visitedLibraries); | 4355 addToDependencyMap(referencedLibrary, dependencyMap, visitedLibraries); |
| 4363 } | 4356 } |
| 4364 if (!library.explicitlyImportsCore && library != _coreLibrary) { | 4357 if (!library.explicitlyImportsCore && library != _coreLibrary) { |
| 4365 addDependencyToMap(dependencyMap, library, _coreLibrary); | 4358 addDependencyToMap(dependencyMap, library, _coreLibrary); |
| 4366 } | 4359 } |
| 4367 } | 4360 } |
| 4368 } | 4361 } |
| 4369 | 4362 |
| 4370 /** | 4363 /** |
| 4371 * Build the element model representing the combinators declared by the given
directive. | 4364 * Build the element model representing the combinators declared by the given
directive. |
| 4372 * @param directive the directive that declares the combinators | 4365 * @param directive the directive that declares the combinators |
| 4373 * @return an array containing the import combinators that were built | 4366 * @return an array containing the import combinators that were built |
| 4374 */ | 4367 */ |
| 4375 List<NamespaceCombinator> buildCombinators(NamespaceDirective directive) { | 4368 List<NamespaceCombinator> buildCombinators(NamespaceDirective directive) { |
| 4376 List<NamespaceCombinator> combinators = new List<NamespaceCombinator>(); | 4369 List<NamespaceCombinator> combinators = new List<NamespaceCombinator>(); |
| 4377 for (Combinator combinator in directive.combinators) { | 4370 for (Combinator combinator in directive.combinators) { |
| 4378 if (combinator is HideCombinator) { | 4371 if (combinator is HideCombinator) { |
| 4379 HideCombinatorImpl hide = new HideCombinatorImpl(); | 4372 HideCombinatorImpl hide = new HideCombinatorImpl(); |
| 4380 hide.hiddenNames = getIdentifiers(((combinator as HideCombinator)).hidde
nNames); | 4373 hide.hiddenNames = getIdentifiers(((combinator as HideCombinator)).hidde
nNames); |
| 4381 combinators.add(hide); | 4374 combinators.add(hide); |
| 4382 } else { | 4375 } else { |
| 4383 ShowCombinatorImpl show = new ShowCombinatorImpl(); | 4376 ShowCombinatorImpl show = new ShowCombinatorImpl(); |
| 4384 show.shownNames = getIdentifiers(((combinator as ShowCombinator)).shownN
ames); | 4377 show.shownNames = getIdentifiers(((combinator as ShowCombinator)).shownN
ames); |
| 4385 combinators.add(show); | 4378 combinators.add(show); |
| 4386 } | 4379 } |
| 4387 } | 4380 } |
| 4388 return new List.from(combinators); | 4381 return new List.from(combinators); |
| 4389 } | 4382 } |
| 4390 | 4383 |
| 4391 /** | 4384 /** |
| 4392 * Every library now has a corresponding {@link LibraryElement}, so it is now
possible to resolve | 4385 * Every library now has a corresponding {@link LibraryElement}, so it is now
possible to resolve |
| 4393 * the import and export directives. | 4386 * the import and export directives. |
| 4394 * @throws AnalysisException if the defining compilation unit for any of the l
ibraries could not | 4387 * @throws AnalysisException if the defining compilation unit for any of the l
ibraries could not |
| 4395 * be accessed | 4388 * be accessed |
| 4396 */ | 4389 */ |
| 4397 void buildDirectiveModels() { | 4390 void buildDirectiveModels() { |
| 4398 for (Library library in _librariesInCycles) { | 4391 for (Library library in _librariesInCycles) { |
| 4399 Map<String, PrefixElementImpl> nameToPrefixMap = new Map<String, PrefixEle
mentImpl>(); | 4392 Map<String, PrefixElementImpl> nameToPrefixMap = new Map<String, PrefixEle
mentImpl>(); |
| 4400 List<ImportElement> imports = new List<ImportElement>(); | 4393 List<ImportElement> imports = new List<ImportElement>(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4445 ImportElementImpl importElement = new ImportElementImpl(); | 4438 ImportElementImpl importElement = new ImportElementImpl(); |
| 4446 importElement.importedLibrary = _coreLibrary.libraryElement; | 4439 importElement.importedLibrary = _coreLibrary.libraryElement; |
| 4447 importElement.synthetic = true; | 4440 importElement.synthetic = true; |
| 4448 imports.add(importElement); | 4441 imports.add(importElement); |
| 4449 } | 4442 } |
| 4450 LibraryElementImpl libraryElement2 = library.libraryElement; | 4443 LibraryElementImpl libraryElement2 = library.libraryElement; |
| 4451 libraryElement2.imports = new List.from(imports); | 4444 libraryElement2.imports = new List.from(imports); |
| 4452 libraryElement2.exports = new List.from(exports); | 4445 libraryElement2.exports = new List.from(exports); |
| 4453 } | 4446 } |
| 4454 } | 4447 } |
| 4455 | 4448 |
| 4456 /** | 4449 /** |
| 4457 * Build element models for all of the libraries in the current cycle. | 4450 * Build element models for all of the libraries in the current cycle. |
| 4458 * @throws AnalysisException if any of the element models cannot be built | 4451 * @throws AnalysisException if any of the element models cannot be built |
| 4459 */ | 4452 */ |
| 4460 void buildElementModels() { | 4453 void buildElementModels() { |
| 4461 for (Library library in _librariesInCycles) { | 4454 for (Library library in _librariesInCycles) { |
| 4462 LibraryElementBuilder builder = new LibraryElementBuilder(this); | 4455 LibraryElementBuilder builder = new LibraryElementBuilder(this); |
| 4463 LibraryElementImpl libraryElement = builder.buildLibrary(library); | 4456 LibraryElementImpl libraryElement = builder.buildLibrary(library); |
| 4464 library.libraryElement = libraryElement; | 4457 library.libraryElement = libraryElement; |
| 4465 } | 4458 } |
| 4466 } | 4459 } |
| 4467 | 4460 |
| 4468 /** | 4461 /** |
| 4469 * Resolve the type hierarchy across all of the types declared in the librarie
s in the current | 4462 * Resolve the type hierarchy across all of the types declared in the librarie
s in the current |
| 4470 * cycle. | 4463 * cycle. |
| 4471 * @throws AnalysisException if any of the type hierarchies could not be resol
ved | 4464 * @throws AnalysisException if any of the type hierarchies could not be resol
ved |
| 4472 */ | 4465 */ |
| 4473 void buildTypeHierarchies() { | 4466 void buildTypeHierarchies() { |
| 4474 for (Library library in _librariesInCycles) { | 4467 for (Library library in _librariesInCycles) { |
| 4475 for (Source source in library.compilationUnitSources) { | 4468 for (Source source in library.compilationUnitSources) { |
| 4476 TypeResolverVisitor visitor = new TypeResolverVisitor.con1(library, sour
ce, _typeProvider); | 4469 TypeResolverVisitor visitor = new TypeResolverVisitor.con1(library, sour
ce, _typeProvider); |
| 4477 library.getAST(source).accept(visitor); | 4470 library.getAST(source).accept(visitor); |
| 4478 } | 4471 } |
| 4479 } | 4472 } |
| 4480 } | 4473 } |
| 4481 | 4474 |
| 4482 /** | 4475 /** |
| 4483 * Compute a dependency map of libraries reachable from the given library. A d
ependency map is a | 4476 * Compute a dependency map of libraries reachable from the given library. A d
ependency map is a |
| 4484 * table that maps individual libraries to a list of the libraries that either
import or export | 4477 * table that maps individual libraries to a list of the libraries that either
import or export |
| 4485 * those libraries. | 4478 * those libraries. |
| 4486 * <p> | 4479 * <p> |
| 4487 * This map is used to compute all of the libraries involved in a cycle that i
nclude the root | 4480 * This map is used to compute all of the libraries involved in a cycle that i
nclude the root |
| 4488 * library. Given that we only add libraries that are reachable from the root
library, when we | 4481 * library. Given that we only add libraries that are reachable from the root
library, when we |
| 4489 * work backward we are guaranteed to only get libraries in the cycle. | 4482 * work backward we are guaranteed to only get libraries in the cycle. |
| 4490 * @param library the library currently being added to the dependency map | 4483 * @param library the library currently being added to the dependency map |
| 4491 */ | 4484 */ |
| 4492 Map<Library, List<Library>> computeDependencyMap(Library library) { | 4485 Map<Library, List<Library>> computeDependencyMap(Library library) { |
| 4493 Map<Library, List<Library>> dependencyMap = new Map<Library, List<Library>>(
); | 4486 Map<Library, List<Library>> dependencyMap = new Map<Library, List<Library>>(
); |
| 4494 addToDependencyMap(library, dependencyMap, new Set<Library>()); | 4487 addToDependencyMap(library, dependencyMap, new Set<Library>()); |
| 4495 return dependencyMap; | 4488 return dependencyMap; |
| 4496 } | 4489 } |
| 4497 | 4490 |
| 4498 /** | 4491 /** |
| 4499 * Return a collection containing all of the libraries reachable from the give
n library that are | 4492 * Return a collection containing all of the libraries reachable from the give
n library that are |
| 4500 * contained in a cycle that includes the given library. | 4493 * contained in a cycle that includes the given library. |
| 4501 * @param library the library that must be included in any cycles whose member
s are to be returned | 4494 * @param library the library that must be included in any cycles whose member
s are to be returned |
| 4502 * @return all of the libraries referenced by the given library that have a ci
rcular reference | 4495 * @return all of the libraries referenced by the given library that have a ci
rcular reference |
| 4503 * back to the given library | 4496 * back to the given library |
| 4504 */ | 4497 */ |
| 4505 Set<Library> computeLibrariesInCycles(Library library) { | 4498 Set<Library> computeLibrariesInCycles(Library library) { |
| 4506 Map<Library, List<Library>> dependencyMap = computeDependencyMap(library); | 4499 Map<Library, List<Library>> dependencyMap = computeDependencyMap(library); |
| 4507 Set<Library> librariesInCycle = new Set<Library>(); | 4500 Set<Library> librariesInCycle = new Set<Library>(); |
| 4508 addLibrariesInCycle(library, librariesInCycle, dependencyMap); | 4501 addLibrariesInCycle(library, librariesInCycle, dependencyMap); |
| 4509 return librariesInCycle; | 4502 return librariesInCycle; |
| 4510 } | 4503 } |
| 4511 | 4504 |
| 4512 /** | 4505 /** |
| 4513 * Recursively traverse the libraries reachable from the given library, creati
ng instances of the | 4506 * Recursively traverse the libraries reachable from the given library, creati
ng instances of the |
| 4514 * class {@link Library} to represent them, and record the references in the l
ibrary objects. | 4507 * class {@link Library} to represent them, and record the references in the l
ibrary objects. |
| 4515 * @param library the library to be processed to find libraries that have not
yet been traversed | 4508 * @param library the library to be processed to find libraries that have not
yet been traversed |
| 4516 * @throws AnalysisException if some portion of the library graph could not be
traversed | 4509 * @throws AnalysisException if some portion of the library graph could not be
traversed |
| 4517 */ | 4510 */ |
| 4518 void computeLibraryDependencies(Library library) { | 4511 void computeLibraryDependencies(Library library) { |
| 4519 bool explicitlyImportsCore = false; | 4512 bool explicitlyImportsCore = false; |
| 4520 CompilationUnit unit = library.definingCompilationUnit; | 4513 CompilationUnit unit = library.definingCompilationUnit; |
| 4521 for (Directive directive in unit.directives) { | 4514 for (Directive directive in unit.directives) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4566 if (!explicitlyImportsCore && _coreLibrarySource != library.librarySource) { | 4559 if (!explicitlyImportsCore && _coreLibrarySource != library.librarySource) { |
| 4567 Library importedLibrary = _libraryMap[_coreLibrarySource]; | 4560 Library importedLibrary = _libraryMap[_coreLibrarySource]; |
| 4568 if (importedLibrary == null) { | 4561 if (importedLibrary == null) { |
| 4569 importedLibrary = createLibraryOrNull(_coreLibrarySource); | 4562 importedLibrary = createLibraryOrNull(_coreLibrarySource); |
| 4570 if (importedLibrary != null) { | 4563 if (importedLibrary != null) { |
| 4571 computeLibraryDependencies(importedLibrary); | 4564 computeLibraryDependencies(importedLibrary); |
| 4572 } | 4565 } |
| 4573 } | 4566 } |
| 4574 } | 4567 } |
| 4575 } | 4568 } |
| 4576 | 4569 |
| 4577 /** | 4570 /** |
| 4578 * Create an object to represent the information about the library defined by
the compilation unit | 4571 * Create an object to represent the information about the library defined by
the compilation unit |
| 4579 * with the given source. | 4572 * with the given source. |
| 4580 * @param librarySource the source of the library's defining compilation unit | 4573 * @param librarySource the source of the library's defining compilation unit |
| 4581 * @return the library object that was created | 4574 * @return the library object that was created |
| 4582 * @throws AnalysisException if the library source is not valid | 4575 * @throws AnalysisException if the library source is not valid |
| 4583 */ | 4576 */ |
| 4584 Library createLibrary(Source librarySource) { | 4577 Library createLibrary(Source librarySource) { |
| 4585 Library library = new Library(_analysisContext, _errorListener, librarySourc
e); | 4578 Library library = new Library(_analysisContext, _errorListener, librarySourc
e); |
| 4586 library.definingCompilationUnit; | 4579 library.definingCompilationUnit; |
| 4587 _libraryMap[librarySource] = library; | 4580 _libraryMap[librarySource] = library; |
| 4588 return library; | 4581 return library; |
| 4589 } | 4582 } |
| 4590 | 4583 |
| 4591 /** | 4584 /** |
| 4592 * Create an object to represent the information about the library defined by
the compilation unit | 4585 * Create an object to represent the information about the library defined by
the compilation unit |
| 4593 * with the given source. | 4586 * with the given source. |
| 4594 * @param librarySource the source of the library's defining compilation unit | 4587 * @param librarySource the source of the library's defining compilation unit |
| 4595 * @return the library object that was created | 4588 * @return the library object that was created |
| 4596 * @throws AnalysisException if the library source is not valid | 4589 * @throws AnalysisException if the library source is not valid |
| 4597 */ | 4590 */ |
| 4598 Library createLibrary2(Source librarySource, CompilationUnit unit) { | 4591 Library createLibrary2(Source librarySource, CompilationUnit unit) { |
| 4599 Library library = new Library(_analysisContext, _errorListener, librarySourc
e); | 4592 Library library = new Library(_analysisContext, _errorListener, librarySourc
e); |
| 4600 library.definingCompilationUnit = unit; | 4593 library.definingCompilationUnit = unit; |
| 4601 _libraryMap[librarySource] = library; | 4594 _libraryMap[librarySource] = library; |
| 4602 return library; | 4595 return library; |
| 4603 } | 4596 } |
| 4604 | 4597 |
| 4605 /** | 4598 /** |
| 4606 * Create an object to represent the information about the library defined by
the compilation unit | 4599 * Create an object to represent the information about the library defined by
the compilation unit |
| 4607 * with the given source. Return the library object that was created, or {@cod
e null} if the | 4600 * with the given source. Return the library object that was created, or {@cod
e null} if the |
| 4608 * source is not valid. | 4601 * source is not valid. |
| 4609 * @param librarySource the source of the library's defining compilation unit | 4602 * @param librarySource the source of the library's defining compilation unit |
| 4610 * @return the library object that was created | 4603 * @return the library object that was created |
| 4611 */ | 4604 */ |
| 4612 Library createLibraryOrNull(Source librarySource) { | 4605 Library createLibraryOrNull(Source librarySource) { |
| 4613 if (!librarySource.exists()) { | 4606 if (!librarySource.exists()) { |
| 4614 return null; | 4607 return null; |
| 4615 } | 4608 } |
| 4616 Library library = new Library(_analysisContext, _errorListener, librarySourc
e); | 4609 Library library = new Library(_analysisContext, _errorListener, librarySourc
e); |
| 4617 try { | 4610 try { |
| 4618 library.definingCompilationUnit; | 4611 library.definingCompilationUnit; |
| 4619 } on AnalysisException catch (exception) { | 4612 } on AnalysisException catch (exception) { |
| 4620 return null; | 4613 return null; |
| 4621 } | 4614 } |
| 4622 _libraryMap[librarySource] = library; | 4615 _libraryMap[librarySource] = library; |
| 4623 return library; | 4616 return library; |
| 4624 } | 4617 } |
| 4625 | 4618 |
| 4626 /** | 4619 /** |
| 4627 * Return {@code true} if and only if the passed {@link CompilationUnit} has a
part-of directive. | 4620 * Return {@code true} if and only if the passed {@link CompilationUnit} has a
part-of directive. |
| 4628 * @param node the {@link CompilationUnit} to test | 4621 * @param node the {@link CompilationUnit} to test |
| 4629 * @return {@code true} if and only if the passed {@link CompilationUnit} has
a part-of directive | 4622 * @return {@code true} if and only if the passed {@link CompilationUnit} has
a part-of directive |
| 4630 */ | 4623 */ |
| 4631 bool doesCompilationUnitHavePartOfDirective(CompilationUnit node) { | 4624 bool doesCompilationUnitHavePartOfDirective(CompilationUnit node) { |
| 4632 NodeList<Directive> directives2 = node.directives; | 4625 NodeList<Directive> directives2 = node.directives; |
| 4633 for (Directive directive in directives2) { | 4626 for (Directive directive in directives2) { |
| 4634 if (directive is PartOfDirective) { | 4627 if (directive is PartOfDirective) { |
| 4635 return true; | 4628 return true; |
| 4636 } | 4629 } |
| 4637 } | 4630 } |
| 4638 return false; | 4631 return false; |
| 4639 } | 4632 } |
| 4640 | 4633 |
| 4641 /** | 4634 /** |
| 4642 * Return an array containing the lexical identifiers associated with the node
s in the given list. | 4635 * Return an array containing the lexical identifiers associated with the node
s in the given list. |
| 4643 * @param names the AST nodes representing the identifiers | 4636 * @param names the AST nodes representing the identifiers |
| 4644 * @return the lexical identifiers associated with the nodes in the list | 4637 * @return the lexical identifiers associated with the nodes in the list |
| 4645 */ | 4638 */ |
| 4646 List<String> getIdentifiers(NodeList<SimpleIdentifier> names) { | 4639 List<String> getIdentifiers(NodeList<SimpleIdentifier> names) { |
| 4647 int count = names.length; | 4640 int count = names.length; |
| 4648 List<String> identifiers = new List<String>(count); | 4641 List<String> identifiers = new List<String>(count); |
| 4649 for (int i = 0; i < count; i++) { | 4642 for (int i = 0; i < count; i++) { |
| 4650 identifiers[i] = names[i].name; | 4643 identifiers[i] = names[i].name; |
| 4651 } | 4644 } |
| 4652 return identifiers; | 4645 return identifiers; |
| 4653 } | 4646 } |
| 4654 | 4647 |
| 4655 /** | 4648 /** |
| 4656 * Compute a value for all of the constants in the libraries being analyzed. | 4649 * Compute a value for all of the constants in the libraries being analyzed. |
| 4657 */ | 4650 */ |
| 4658 void performConstantEvaluation() { | 4651 void performConstantEvaluation() { |
| 4659 ConstantValueComputer computer = new ConstantValueComputer(); | 4652 ConstantValueComputer computer = new ConstantValueComputer(); |
| 4660 for (Library library in _librariesInCycles) { | 4653 for (Library library in _librariesInCycles) { |
| 4661 for (Source source in library.compilationUnitSources) { | 4654 for (Source source in library.compilationUnitSources) { |
| 4662 try { | 4655 try { |
| 4663 CompilationUnit unit = library.getAST(source); | 4656 CompilationUnit unit = library.getAST(source); |
| 4664 if (unit != null) { | 4657 if (unit != null) { |
| 4665 computer.add(unit); | 4658 computer.add(unit); |
| 4666 } | 4659 } |
| 4667 } on AnalysisException catch (exception) { | 4660 } on AnalysisException catch (exception) { |
| 4668 AnalysisEngine.instance.logger.logError2("Internal Error: Could not ac
cess AST for ${source.fullName} during constant evaluation", exception); | 4661 AnalysisEngine.instance.logger.logError2("Internal Error: Could not ac
cess AST for ${source.fullName} during constant evaluation", exception); |
| 4669 } | 4662 } |
| 4670 } | 4663 } |
| 4671 } | 4664 } |
| 4672 computer.computeValues(); | 4665 computer.computeValues(); |
| 4673 } | 4666 } |
| 4674 | 4667 |
| 4675 /** | 4668 /** |
| 4676 * Resolve the identifiers and perform type analysis in the libraries in the c
urrent cycle. | 4669 * Resolve the identifiers and perform type analysis in the libraries in the c
urrent cycle. |
| 4677 * @throws AnalysisException if any of the identifiers could not be resolved o
r if any of the | 4670 * @throws AnalysisException if any of the identifiers could not be resolved o
r if any of the |
| 4678 * libraries could not have their types analyzed | 4671 * libraries could not have their types analyzed |
| 4679 */ | 4672 */ |
| 4680 void resolveReferencesAndTypes() { | 4673 void resolveReferencesAndTypes() { |
| 4681 for (Library library in _librariesInCycles) { | 4674 for (Library library in _librariesInCycles) { |
| 4682 resolveReferencesAndTypes2(library); | 4675 resolveReferencesAndTypes2(library); |
| 4683 } | 4676 } |
| 4684 } | 4677 } |
| 4685 | 4678 |
| 4686 /** | 4679 /** |
| 4687 * Resolve the identifiers and perform type analysis in the given library. | 4680 * Resolve the identifiers and perform type analysis in the given library. |
| 4688 * @param library the library to be resolved | 4681 * @param library the library to be resolved |
| 4689 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in | 4682 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in |
| 4690 * the library cannot be analyzed | 4683 * the library cannot be analyzed |
| 4691 */ | 4684 */ |
| 4692 void resolveReferencesAndTypes2(Library library) { | 4685 void resolveReferencesAndTypes2(Library library) { |
| 4693 for (Source source in library.compilationUnitSources) { | 4686 for (Source source in library.compilationUnitSources) { |
| 4694 ResolverVisitor visitor = new ResolverVisitor.con1(library, source, _typeP
rovider); | 4687 ResolverVisitor visitor = new ResolverVisitor.con1(library, source, _typeP
rovider); |
| 4695 library.getAST(source).accept(visitor); | 4688 library.getAST(source).accept(visitor); |
| 4696 } | 4689 } |
| 4697 } | 4690 } |
| 4698 | 4691 |
| 4699 /** | 4692 /** |
| 4700 * Run additional analyses, such as the {@link ConstantVerifier} and {@link Er
rorVerifier}analysis in the current cycle. | 4693 * Run additional analyses, such as the {@link ConstantVerifier} and {@link Er
rorVerifier}analysis in the current cycle. |
| 4701 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in | 4694 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in |
| 4702 * the library cannot be analyzed | 4695 * the library cannot be analyzed |
| 4703 */ | 4696 */ |
| 4704 void runAdditionalAnalyses() { | 4697 void runAdditionalAnalyses() { |
| 4705 for (Library library in _librariesInCycles) { | 4698 for (Library library in _librariesInCycles) { |
| 4706 runAdditionalAnalyses2(library); | 4699 runAdditionalAnalyses2(library); |
| 4707 } | 4700 } |
| 4708 } | 4701 } |
| 4709 | 4702 |
| 4710 /** | 4703 /** |
| 4711 * Run additional analyses, such as the {@link ConstantVerifier} and {@link Er
rorVerifier}analysis in the given library. | 4704 * Run additional analyses, such as the {@link ConstantVerifier} and {@link Er
rorVerifier}analysis in the given library. |
| 4712 * @param library the library to have the extra analyses processes run | 4705 * @param library the library to have the extra analyses processes run |
| 4713 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in | 4706 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in |
| 4714 * the library cannot be analyzed | 4707 * the library cannot be analyzed |
| 4715 */ | 4708 */ |
| 4716 void runAdditionalAnalyses2(Library library) { | 4709 void runAdditionalAnalyses2(Library library) { |
| 4717 for (Source source in library.compilationUnitSources) { | 4710 for (Source source in library.compilationUnitSources) { |
| 4718 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source); | 4711 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source); |
| 4719 CompilationUnit unit = library.getAST(source); | 4712 CompilationUnit unit = library.getAST(source); |
| 4720 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, library.lib
raryElement, _typeProvider, library.inheritanceManager); | 4713 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, library.lib
raryElement, _typeProvider, library.inheritanceManager); |
| 4721 unit.accept(errorVerifier); | 4714 unit.accept(errorVerifier); |
| 4715 unit.accept(new PubVerifier(errorReporter)); |
| 4722 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, _t
ypeProvider); | 4716 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, _t
ypeProvider); |
| 4723 unit.accept(constantVerifier); | 4717 unit.accept(constantVerifier); |
| 4724 } | 4718 } |
| 4725 } | 4719 } |
| 4726 } | 4720 } |
| 4727 | |
| 4728 /** | 4721 /** |
| 4729 * Instances of the class {@code ResolverVisitor} are used to resolve the nodes
within a single | 4722 * Instances of the class {@code ResolverVisitor} are used to resolve the nodes
within a single |
| 4730 * compilation unit. | 4723 * compilation unit. |
| 4731 * @coverage dart.engine.resolver | 4724 * @coverage dart.engine.resolver |
| 4732 */ | 4725 */ |
| 4733 class ResolverVisitor extends ScopedVisitor { | 4726 class ResolverVisitor extends ScopedVisitor { |
| 4734 | 4727 |
| 4735 /** | 4728 /** |
| 4736 * The object used to resolve the element associated with the current node. | 4729 * The object used to resolve the element associated with the current node. |
| 4737 */ | 4730 */ |
| 4738 ElementResolver _elementResolver; | 4731 ElementResolver _elementResolver; |
| 4739 | 4732 |
| 4740 /** | 4733 /** |
| 4741 * The object used to compute the type associated with the current node. | 4734 * The object used to compute the type associated with the current node. |
| 4742 */ | 4735 */ |
| 4743 StaticTypeAnalyzer _typeAnalyzer; | 4736 StaticTypeAnalyzer _typeAnalyzer; |
| 4744 | 4737 |
| 4745 /** | 4738 /** |
| 4746 * The class element representing the class containing the current node, or {@
code null} if the | 4739 * The class element representing the class containing the current node, or {@
code null} if the |
| 4747 * current node is not contained in a class. | 4740 * current node is not contained in a class. |
| 4748 */ | 4741 */ |
| 4749 ClassElement _enclosingClass = null; | 4742 ClassElement _enclosingClass = null; |
| 4750 | 4743 |
| 4751 /** | 4744 /** |
| 4752 * The element representing the function containing the current node, or {@cod
e null} if the | 4745 * The element representing the function containing the current node, or {@cod
e null} if the |
| 4753 * current node is not contained in a function. | 4746 * current node is not contained in a function. |
| 4754 */ | 4747 */ |
| 4755 ExecutableElement _enclosingFunction = null; | 4748 ExecutableElement _enclosingFunction = null; |
| 4756 | 4749 |
| 4757 /** | 4750 /** |
| 4758 * The object keeping track of which elements have had their types overridden. | 4751 * The object keeping track of which elements have had their types overridden. |
| 4759 */ | 4752 */ |
| 4760 TypeOverrideManager _overrideManager = new TypeOverrideManager(); | 4753 TypeOverrideManager _overrideManager = new TypeOverrideManager(); |
| 4761 | 4754 |
| 4762 /** | 4755 /** |
| 4763 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 4756 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 4764 * @param library the library containing the compilation unit being resolved | 4757 * @param library the library containing the compilation unit being resolved |
| 4765 * @param source the source representing the compilation unit being visited | 4758 * @param source the source representing the compilation unit being visited |
| 4766 * @param typeProvider the object used to access the types from the core libra
ry | 4759 * @param typeProvider the object used to access the types from the core libra
ry |
| 4767 */ | 4760 */ |
| 4768 ResolverVisitor.con1(Library library, Source source, TypeProvider typeProvider
) : super.con1(library, source, typeProvider) { | 4761 ResolverVisitor.con1(Library library, Source source, TypeProvider typeProvider
) : super.con1(library, source, typeProvider) { |
| 4769 _jtd_constructor_272_impl(library, source, typeProvider); | 4762 _jtd_constructor_273_impl(library, source, typeProvider); |
| 4770 } | 4763 } |
| 4771 _jtd_constructor_272_impl(Library library, Source source, TypeProvider typePro
vider) { | 4764 _jtd_constructor_273_impl(Library library, Source source, TypeProvider typePro
vider) { |
| 4772 this._elementResolver = new ElementResolver(this); | 4765 this._elementResolver = new ElementResolver(this); |
| 4773 this._typeAnalyzer = new StaticTypeAnalyzer(this); | 4766 this._typeAnalyzer = new StaticTypeAnalyzer(this); |
| 4774 } | 4767 } |
| 4775 | 4768 |
| 4776 /** | 4769 /** |
| 4777 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 4770 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 4778 * @param definingLibrary the element for the library containing the compilati
on unit being | 4771 * @param definingLibrary the element for the library containing the compilati
on unit being |
| 4779 * visited | 4772 * visited |
| 4780 * @param source the source representing the compilation unit being visited | 4773 * @param source the source representing the compilation unit being visited |
| 4781 * @param typeProvider the object used to access the types from the core libra
ry | 4774 * @param typeProvider the object used to access the types from the core libra
ry |
| 4782 * @param errorListener the error listener that will be informed of any errors
that are found | 4775 * @param errorListener the error listener that will be informed of any errors
that are found |
| 4783 * during resolution | 4776 * during resolution |
| 4784 */ | 4777 */ |
| 4785 ResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypeProvid
er typeProvider, AnalysisErrorListener errorListener) : super.con2(definingLibra
ry, source, typeProvider, errorListener) { | 4778 ResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypeProvid
er typeProvider, AnalysisErrorListener errorListener) : super.con2(definingLibra
ry, source, typeProvider, errorListener) { |
| 4786 _jtd_constructor_273_impl(definingLibrary, source, typeProvider, errorListen
er); | 4779 _jtd_constructor_274_impl(definingLibrary, source, typeProvider, errorListen
er); |
| 4787 } | 4780 } |
| 4788 _jtd_constructor_273_impl(LibraryElement definingLibrary, Source source, TypeP
rovider typeProvider, AnalysisErrorListener errorListener) { | 4781 _jtd_constructor_274_impl(LibraryElement definingLibrary, Source source, TypeP
rovider typeProvider, AnalysisErrorListener errorListener) { |
| 4789 this._elementResolver = new ElementResolver(this); | 4782 this._elementResolver = new ElementResolver(this); |
| 4790 this._typeAnalyzer = new StaticTypeAnalyzer(this); | 4783 this._typeAnalyzer = new StaticTypeAnalyzer(this); |
| 4791 } | 4784 } |
| 4792 | 4785 |
| 4793 /** | 4786 /** |
| 4794 * Return the object keeping track of which elements have had their types over
ridden. | 4787 * Return the object keeping track of which elements have had their types over
ridden. |
| 4795 * @return the object keeping track of which elements have had their types ove
rridden | 4788 * @return the object keeping track of which elements have had their types ove
rridden |
| 4796 */ | 4789 */ |
| 4797 TypeOverrideManager get overrideManager => _overrideManager; | 4790 TypeOverrideManager get overrideManager => _overrideManager; |
| 4798 Object visitAsExpression(AsExpression node) { | 4791 Object visitAsExpression(AsExpression node) { |
| 4799 super.visitAsExpression(node); | 4792 super.visitAsExpression(node); |
| 4800 VariableElement element = getOverridableElement(node.expression); | 4793 VariableElement element = getOverridableElement(node.expression); |
| 4801 if (element != null) { | 4794 if (element != null) { |
| 4802 override(element, node.type.type); | 4795 override(element, node.type.type); |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5155 propagateTrueState(condition2); | 5148 propagateTrueState(condition2); |
| 5156 body2.accept(this); | 5149 body2.accept(this); |
| 5157 } finally { | 5150 } finally { |
| 5158 _overrideManager.exitScope(); | 5151 _overrideManager.exitScope(); |
| 5159 } | 5152 } |
| 5160 } | 5153 } |
| 5161 node.accept(_elementResolver); | 5154 node.accept(_elementResolver); |
| 5162 node.accept(_typeAnalyzer); | 5155 node.accept(_typeAnalyzer); |
| 5163 return null; | 5156 return null; |
| 5164 } | 5157 } |
| 5165 | 5158 |
| 5166 /** | 5159 /** |
| 5167 * Return the class element representing the class containing the current node
, or {@code null} if | 5160 * Return the class element representing the class containing the current node
, or {@code null} if |
| 5168 * the current node is not contained in a class. | 5161 * the current node is not contained in a class. |
| 5169 * @return the class element representing the class containing the current nod
e | 5162 * @return the class element representing the class containing the current nod
e |
| 5170 */ | 5163 */ |
| 5171 ClassElement get enclosingClass => _enclosingClass; | 5164 ClassElement get enclosingClass => _enclosingClass; |
| 5172 | 5165 |
| 5173 /** | 5166 /** |
| 5174 * Return the element representing the function containing the current node, o
r {@code null} if | 5167 * Return the element representing the function containing the current node, o
r {@code null} if |
| 5175 * the current node is not contained in a function. | 5168 * the current node is not contained in a function. |
| 5176 * @return the element representing the function containing the current node | 5169 * @return the element representing the function containing the current node |
| 5177 */ | 5170 */ |
| 5178 ExecutableElement get enclosingFunction => _enclosingFunction; | 5171 ExecutableElement get enclosingFunction => _enclosingFunction; |
| 5179 | 5172 |
| 5180 /** | 5173 /** |
| 5181 * Return the element associated with the given expression whose type can be o
verridden, or{@code null} if there is no element whose type can be overridden. | 5174 * Return the element associated with the given expression whose type can be o
verridden, or{@code null} if there is no element whose type can be overridden. |
| 5182 * @param expression the expression with which the element is associated | 5175 * @param expression the expression with which the element is associated |
| 5183 * @return the element associated with the given expression | 5176 * @return the element associated with the given expression |
| 5184 */ | 5177 */ |
| 5185 VariableElement getOverridableElement(Expression expression) { | 5178 VariableElement getOverridableElement(Expression expression) { |
| 5186 Element element = null; | 5179 Element element = null; |
| 5187 if (expression is SimpleIdentifier) { | 5180 if (expression is SimpleIdentifier) { |
| 5188 element = ((expression as SimpleIdentifier)).element; | 5181 element = ((expression as SimpleIdentifier)).element; |
| 5189 } else if (expression is PrefixedIdentifier) { | 5182 } else if (expression is PrefixedIdentifier) { |
| 5190 element = ((expression as PrefixedIdentifier)).element; | 5183 element = ((expression as PrefixedIdentifier)).element; |
| 5191 } else if (expression is PropertyAccess) { | 5184 } else if (expression is PropertyAccess) { |
| 5192 element = ((expression as PropertyAccess)).propertyName.element; | 5185 element = ((expression as PropertyAccess)).propertyName.element; |
| 5193 } | 5186 } |
| 5194 if (element is VariableElement) { | 5187 if (element is VariableElement) { |
| 5195 return element as VariableElement; | 5188 return element as VariableElement; |
| 5196 } | 5189 } |
| 5197 return null; | 5190 return null; |
| 5198 } | 5191 } |
| 5199 | 5192 |
| 5200 /** | 5193 /** |
| 5201 * If it is appropriate to do so, override the current type of the given eleme
nt with the given | 5194 * If it is appropriate to do so, override the current type of the given eleme
nt with the given |
| 5202 * type. Generally speaking, it is appropriate if the given type is more speci
fic than the current | 5195 * type. Generally speaking, it is appropriate if the given type is more speci
fic than the current |
| 5203 * type. | 5196 * type. |
| 5204 * @param element the element whose type might be overridden | 5197 * @param element the element whose type might be overridden |
| 5205 * @param potentialType the potential type of the element | 5198 * @param potentialType the potential type of the element |
| 5206 */ | 5199 */ |
| 5207 void override(VariableElement element, Type2 potentialType) { | 5200 void override(VariableElement element, Type2 potentialType) { |
| 5208 if (potentialType == null || identical(potentialType, BottomTypeImpl.instanc
e)) { | 5201 if (potentialType == null || identical(potentialType, BottomTypeImpl.instanc
e)) { |
| 5209 return; | 5202 return; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5248 safelyVisit(node.condition); | 5241 safelyVisit(node.condition); |
| 5249 _overrideManager.enterScope(); | 5242 _overrideManager.enterScope(); |
| 5250 try { | 5243 try { |
| 5251 propagateTrueState(node.condition); | 5244 propagateTrueState(node.condition); |
| 5252 safelyVisit(node.body); | 5245 safelyVisit(node.body); |
| 5253 node.updaters.accept(this); | 5246 node.updaters.accept(this); |
| 5254 } finally { | 5247 } finally { |
| 5255 _overrideManager.exitScope(); | 5248 _overrideManager.exitScope(); |
| 5256 } | 5249 } |
| 5257 } | 5250 } |
| 5258 | 5251 |
| 5259 /** | 5252 /** |
| 5260 * Return the best type information available for the given element. If the ty
pe of the element | 5253 * Return the best type information available for the given element. If the ty
pe of the element |
| 5261 * has been overridden, then return the overriding type. Otherwise, return the
static type. | 5254 * has been overridden, then return the overriding type. Otherwise, return the
static type. |
| 5262 * @param element the element for which type information is to be returned | 5255 * @param element the element for which type information is to be returned |
| 5263 * @return the best type information available for the given element | 5256 * @return the best type information available for the given element |
| 5264 */ | 5257 */ |
| 5265 Type2 getBestType(Element element) { | 5258 Type2 getBestType(Element element) { |
| 5266 Type2 bestType = _overrideManager.getType(element); | 5259 Type2 bestType = _overrideManager.getType(element); |
| 5267 if (bestType == null) { | 5260 if (bestType == null) { |
| 5268 if (element is LocalVariableElement) { | 5261 if (element is LocalVariableElement) { |
| 5269 bestType = ((element as LocalVariableElement)).type; | 5262 bestType = ((element as LocalVariableElement)).type; |
| 5270 } else if (element is ParameterElement) { | 5263 } else if (element is ParameterElement) { |
| 5271 bestType = ((element as ParameterElement)).type; | 5264 bestType = ((element as ParameterElement)).type; |
| 5272 } | 5265 } |
| 5273 } | 5266 } |
| 5274 return bestType; | 5267 return bestType; |
| 5275 } | 5268 } |
| 5276 | 5269 |
| 5277 /** | 5270 /** |
| 5278 * The given expression is the expression used to compute the iterator for a f
or-each statement. | 5271 * The given expression is the expression used to compute the iterator for a f
or-each statement. |
| 5279 * Attempt to compute the type of objects that will be assigned to the loop va
riable and return | 5272 * Attempt to compute the type of objects that will be assigned to the loop va
riable and return |
| 5280 * that type. Return {@code null} if the type could not be determined. | 5273 * that type. Return {@code null} if the type could not be determined. |
| 5281 * @param iterator the iterator for a for-each statement | 5274 * @param iterator the iterator for a for-each statement |
| 5282 * @return the type of objects that will be assigned to the loop variable | 5275 * @return the type of objects that will be assigned to the loop variable |
| 5283 */ | 5276 */ |
| 5284 Type2 getIteratorElementType(Expression iteratorExpression) { | 5277 Type2 getIteratorElementType(Expression iteratorExpression) { |
| 5285 Type2 expressionType = iteratorExpression.staticType; | 5278 Type2 expressionType = iteratorExpression.staticType; |
| 5286 if (expressionType is InterfaceType) { | 5279 if (expressionType is InterfaceType) { |
| 5287 PropertyAccessorElement iterator = ((expressionType as InterfaceType)).loo
kUpGetter("iterator", definingLibrary); | 5280 PropertyAccessorElement iterator = ((expressionType as InterfaceType)).loo
kUpGetter("iterator", definingLibrary); |
| 5288 if (iterator == null) { | 5281 if (iterator == null) { |
| 5289 return null; | 5282 return null; |
| 5290 } | 5283 } |
| 5291 Type2 iteratorType = iterator.type.returnType; | 5284 Type2 iteratorType = iterator.type.returnType; |
| 5292 if (iteratorType is InterfaceType) { | 5285 if (iteratorType is InterfaceType) { |
| 5293 PropertyAccessorElement current = ((iteratorType as InterfaceType)).look
UpGetter("current", definingLibrary); | 5286 PropertyAccessorElement current = ((iteratorType as InterfaceType)).look
UpGetter("current", definingLibrary); |
| 5294 if (current == null) { | 5287 if (current == null) { |
| 5295 return null; | 5288 return null; |
| 5296 } | 5289 } |
| 5297 return current.type.returnType; | 5290 return current.type.returnType; |
| 5298 } | 5291 } |
| 5299 } | 5292 } |
| 5300 return null; | 5293 return null; |
| 5301 } | 5294 } |
| 5302 | 5295 |
| 5303 /** | 5296 /** |
| 5304 * Return {@code true} if the given expression terminates abruptly (that is, i
f any expression | 5297 * Return {@code true} if the given expression terminates abruptly (that is, i
f any expression |
| 5305 * following the given expression will not be reached). | 5298 * following the given expression will not be reached). |
| 5306 * @param expression the expression being tested | 5299 * @param expression the expression being tested |
| 5307 * @return {@code true} if the given expression terminates abruptly | 5300 * @return {@code true} if the given expression terminates abruptly |
| 5308 */ | 5301 */ |
| 5309 bool isAbruptTermination(Expression expression2) { | 5302 bool isAbruptTermination(Expression expression2) { |
| 5310 while (expression2 is ParenthesizedExpression) { | 5303 while (expression2 is ParenthesizedExpression) { |
| 5311 expression2 = ((expression2 as ParenthesizedExpression)).expression; | 5304 expression2 = ((expression2 as ParenthesizedExpression)).expression; |
| 5312 } | 5305 } |
| 5313 return expression2 is ThrowExpression || expression2 is RethrowExpression; | 5306 return expression2 is ThrowExpression || expression2 is RethrowExpression; |
| 5314 } | 5307 } |
| 5315 | 5308 |
| 5316 /** | 5309 /** |
| 5317 * Return {@code true} if the given statement terminates abruptly (that is, if
any statement | 5310 * Return {@code true} if the given statement terminates abruptly (that is, if
any statement |
| 5318 * following the given statement will not be reached). | 5311 * following the given statement will not be reached). |
| 5319 * @param statement the statement being tested | 5312 * @param statement the statement being tested |
| 5320 * @return {@code true} if the given statement terminates abruptly | 5313 * @return {@code true} if the given statement terminates abruptly |
| 5321 */ | 5314 */ |
| 5322 bool isAbruptTermination2(Statement statement) { | 5315 bool isAbruptTermination2(Statement statement) { |
| 5323 if (statement is ReturnStatement || statement is BreakStatement || statement
is ContinueStatement) { | 5316 if (statement is ReturnStatement || statement is BreakStatement || statement
is ContinueStatement) { |
| 5324 return true; | 5317 return true; |
| 5325 } else if (statement is ExpressionStatement) { | 5318 } else if (statement is ExpressionStatement) { |
| 5326 return isAbruptTermination(((statement as ExpressionStatement)).expression
); | 5319 return isAbruptTermination(((statement as ExpressionStatement)).expression
); |
| 5327 } else if (statement is Block) { | 5320 } else if (statement is Block) { |
| 5328 NodeList<Statement> statements2 = ((statement as Block)).statements; | 5321 NodeList<Statement> statements2 = ((statement as Block)).statements; |
| 5329 int size2 = statements2.length; | 5322 int size2 = statements2.length; |
| 5330 if (size2 == 0) { | 5323 if (size2 == 0) { |
| 5331 return false; | 5324 return false; |
| 5332 } | 5325 } |
| 5333 return isAbruptTermination2(statements2[size2 - 1]); | 5326 return isAbruptTermination2(statements2[size2 - 1]); |
| 5334 } | 5327 } |
| 5335 return false; | 5328 return false; |
| 5336 } | 5329 } |
| 5337 | 5330 |
| 5338 /** | 5331 /** |
| 5339 * Propagate any type information that results from knowing that the given con
dition will have | 5332 * Propagate any type information that results from knowing that the given con
dition will have |
| 5340 * been evaluated to 'false'. | 5333 * been evaluated to 'false'. |
| 5341 * @param condition the condition that will have evaluated to 'false' | 5334 * @param condition the condition that will have evaluated to 'false' |
| 5342 */ | 5335 */ |
| 5343 void propagateFalseState(Expression condition) { | 5336 void propagateFalseState(Expression condition) { |
| 5344 if (condition is BinaryExpression) { | 5337 if (condition is BinaryExpression) { |
| 5345 BinaryExpression binary = condition as BinaryExpression; | 5338 BinaryExpression binary = condition as BinaryExpression; |
| 5346 if (identical(binary.operator.type, sc.TokenType.BAR_BAR)) { | 5339 if (identical(binary.operator.type, sc.TokenType.BAR_BAR)) { |
| 5347 propagateFalseState(binary.leftOperand); | 5340 propagateFalseState(binary.leftOperand); |
| 5348 propagateFalseState(binary.rightOperand); | 5341 propagateFalseState(binary.rightOperand); |
| 5349 } | 5342 } |
| 5350 } else if (condition is IsExpression) { | 5343 } else if (condition is IsExpression) { |
| 5351 IsExpression is2 = condition as IsExpression; | 5344 IsExpression is2 = condition as IsExpression; |
| 5352 if (is2.notOperator != null) { | 5345 if (is2.notOperator != null) { |
| 5353 VariableElement element = getOverridableElement(is2.expression); | 5346 VariableElement element = getOverridableElement(is2.expression); |
| 5354 if (element != null) { | 5347 if (element != null) { |
| 5355 override(element, is2.type.type); | 5348 override(element, is2.type.type); |
| 5356 } | 5349 } |
| 5357 } | 5350 } |
| 5358 } else if (condition is PrefixExpression) { | 5351 } else if (condition is PrefixExpression) { |
| 5359 PrefixExpression prefix = condition as PrefixExpression; | 5352 PrefixExpression prefix = condition as PrefixExpression; |
| 5360 if (identical(prefix.operator.type, sc.TokenType.BANG)) { | 5353 if (identical(prefix.operator.type, sc.TokenType.BANG)) { |
| 5361 propagateTrueState(prefix.operand); | 5354 propagateTrueState(prefix.operand); |
| 5362 } | 5355 } |
| 5363 } else if (condition is ParenthesizedExpression) { | 5356 } else if (condition is ParenthesizedExpression) { |
| 5364 propagateFalseState(((condition as ParenthesizedExpression)).expression); | 5357 propagateFalseState(((condition as ParenthesizedExpression)).expression); |
| 5365 } | 5358 } |
| 5366 } | 5359 } |
| 5367 | 5360 |
| 5368 /** | 5361 /** |
| 5369 * Propagate any type information that results from knowing that the given exp
ression will have | 5362 * Propagate any type information that results from knowing that the given exp
ression will have |
| 5370 * been evaluated without altering the flow of execution. | 5363 * been evaluated without altering the flow of execution. |
| 5371 * @param expression the expression that will have been evaluated | 5364 * @param expression the expression that will have been evaluated |
| 5372 */ | 5365 */ |
| 5373 void propagateState(Expression expression) { | 5366 void propagateState(Expression expression) { |
| 5374 } | 5367 } |
| 5375 | 5368 |
| 5376 /** | 5369 /** |
| 5377 * Propagate any type information that results from knowing that the given con
dition will have | 5370 * Propagate any type information that results from knowing that the given con
dition will have |
| 5378 * been evaluated to 'true'. | 5371 * been evaluated to 'true'. |
| 5379 * @param condition the condition that will have evaluated to 'true' | 5372 * @param condition the condition that will have evaluated to 'true' |
| 5380 */ | 5373 */ |
| 5381 void propagateTrueState(Expression condition) { | 5374 void propagateTrueState(Expression condition) { |
| 5382 if (condition is BinaryExpression) { | 5375 if (condition is BinaryExpression) { |
| 5383 BinaryExpression binary = condition as BinaryExpression; | 5376 BinaryExpression binary = condition as BinaryExpression; |
| 5384 if (identical(binary.operator.type, sc.TokenType.AMPERSAND_AMPERSAND)) { | 5377 if (identical(binary.operator.type, sc.TokenType.AMPERSAND_AMPERSAND)) { |
| 5385 propagateTrueState(binary.leftOperand); | 5378 propagateTrueState(binary.leftOperand); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 5406 set elementResolver_J2DAccessor(__v) => _elementResolver = __v; | 5399 set elementResolver_J2DAccessor(__v) => _elementResolver = __v; |
| 5407 get labelScope_J2DAccessor => _labelScope; | 5400 get labelScope_J2DAccessor => _labelScope; |
| 5408 set labelScope_J2DAccessor(__v) => _labelScope = __v; | 5401 set labelScope_J2DAccessor(__v) => _labelScope = __v; |
| 5409 get nameScope_J2DAccessor => _nameScope; | 5402 get nameScope_J2DAccessor => _nameScope; |
| 5410 set nameScope_J2DAccessor(__v) => _nameScope = __v; | 5403 set nameScope_J2DAccessor(__v) => _nameScope = __v; |
| 5411 get typeAnalyzer_J2DAccessor => _typeAnalyzer; | 5404 get typeAnalyzer_J2DAccessor => _typeAnalyzer; |
| 5412 set typeAnalyzer_J2DAccessor(__v) => _typeAnalyzer = __v; | 5405 set typeAnalyzer_J2DAccessor(__v) => _typeAnalyzer = __v; |
| 5413 get enclosingClass_J2DAccessor => _enclosingClass; | 5406 get enclosingClass_J2DAccessor => _enclosingClass; |
| 5414 set enclosingClass_J2DAccessor(__v) => _enclosingClass = __v; | 5407 set enclosingClass_J2DAccessor(__v) => _enclosingClass = __v; |
| 5415 } | 5408 } |
| 5416 | |
| 5417 /** | 5409 /** |
| 5418 * The abstract class {@code ScopedVisitor} maintains name and label scopes as a
n AST structure is | 5410 * The abstract class {@code ScopedVisitor} maintains name and label scopes as a
n AST structure is |
| 5419 * being visited. | 5411 * being visited. |
| 5420 * @coverage dart.engine.resolver | 5412 * @coverage dart.engine.resolver |
| 5421 */ | 5413 */ |
| 5422 abstract class ScopedVisitor extends GeneralizingASTVisitor<Object> { | 5414 abstract class ScopedVisitor extends GeneralizingASTVisitor<Object> { |
| 5423 | 5415 |
| 5424 /** | 5416 /** |
| 5425 * The element for the library containing the compilation unit being visited. | 5417 * The element for the library containing the compilation unit being visited. |
| 5426 */ | 5418 */ |
| 5427 LibraryElement _definingLibrary; | 5419 LibraryElement _definingLibrary; |
| 5428 | 5420 |
| 5429 /** | 5421 /** |
| 5430 * The source representing the compilation unit being visited. | 5422 * The source representing the compilation unit being visited. |
| 5431 */ | 5423 */ |
| 5432 Source _source; | 5424 Source _source; |
| 5433 | 5425 |
| 5434 /** | 5426 /** |
| 5435 * The error listener that will be informed of any errors that are found durin
g resolution. | 5427 * The error listener that will be informed of any errors that are found durin
g resolution. |
| 5436 */ | 5428 */ |
| 5437 AnalysisErrorListener _errorListener; | 5429 AnalysisErrorListener _errorListener; |
| 5438 | 5430 |
| 5439 /** | 5431 /** |
| 5440 * The scope used to resolve identifiers. | 5432 * The scope used to resolve identifiers. |
| 5441 */ | 5433 */ |
| 5442 Scope _nameScope; | 5434 Scope _nameScope; |
| 5443 | 5435 |
| 5444 /** | 5436 /** |
| 5445 * The object used to access the types from the core library. | 5437 * The object used to access the types from the core library. |
| 5446 */ | 5438 */ |
| 5447 TypeProvider _typeProvider; | 5439 TypeProvider _typeProvider; |
| 5448 | 5440 |
| 5449 /** | 5441 /** |
| 5450 * The scope used to resolve labels for {@code break} and {@code continue} sta
tements, or{@code null} if no labels have been defined in the current context. | 5442 * The scope used to resolve labels for {@code break} and {@code continue} sta
tements, or{@code null} if no labels have been defined in the current context. |
| 5451 */ | 5443 */ |
| 5452 LabelScope _labelScope; | 5444 LabelScope _labelScope; |
| 5453 | 5445 |
| 5454 /** | 5446 /** |
| 5455 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 5447 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 5456 * @param library the library containing the compilation unit being resolved | 5448 * @param library the library containing the compilation unit being resolved |
| 5457 * @param source the source representing the compilation unit being visited | 5449 * @param source the source representing the compilation unit being visited |
| 5458 * @param typeProvider the object used to access the types from the core libra
ry | 5450 * @param typeProvider the object used to access the types from the core libra
ry |
| 5459 */ | 5451 */ |
| 5460 ScopedVisitor.con1(Library library, Source source2, TypeProvider typeProvider2
) { | 5452 ScopedVisitor.con1(Library library, Source source2, TypeProvider typeProvider2
) { |
| 5461 _jtd_constructor_274_impl(library, source2, typeProvider2); | 5453 _jtd_constructor_275_impl(library, source2, typeProvider2); |
| 5462 } | 5454 } |
| 5463 _jtd_constructor_274_impl(Library library, Source source2, TypeProvider typePr
ovider2) { | 5455 _jtd_constructor_275_impl(Library library, Source source2, TypeProvider typePr
ovider2) { |
| 5464 this._definingLibrary = library.libraryElement; | 5456 this._definingLibrary = library.libraryElement; |
| 5465 this._source = source2; | 5457 this._source = source2; |
| 5466 LibraryScope libraryScope2 = library.libraryScope; | 5458 LibraryScope libraryScope2 = library.libraryScope; |
| 5467 this._errorListener = libraryScope2.errorListener; | 5459 this._errorListener = libraryScope2.errorListener; |
| 5468 this._nameScope = libraryScope2; | 5460 this._nameScope = libraryScope2; |
| 5469 this._typeProvider = typeProvider2; | 5461 this._typeProvider = typeProvider2; |
| 5470 } | 5462 } |
| 5471 | 5463 |
| 5472 /** | 5464 /** |
| 5473 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 5465 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 5474 * @param definingLibrary the element for the library containing the compilati
on unit being | 5466 * @param definingLibrary the element for the library containing the compilati
on unit being |
| 5475 * visited | 5467 * visited |
| 5476 * @param source the source representing the compilation unit being visited | 5468 * @param source the source representing the compilation unit being visited |
| 5477 * @param typeProvider the object used to access the types from the core libra
ry | 5469 * @param typeProvider the object used to access the types from the core libra
ry |
| 5478 * @param errorListener the error listener that will be informed of any errors
that are found | 5470 * @param errorListener the error listener that will be informed of any errors
that are found |
| 5479 * during resolution | 5471 * during resolution |
| 5480 */ | 5472 */ |
| 5481 ScopedVisitor.con2(LibraryElement definingLibrary2, Source source2, TypeProvid
er typeProvider2, AnalysisErrorListener errorListener2) { | 5473 ScopedVisitor.con2(LibraryElement definingLibrary2, Source source2, TypeProvid
er typeProvider2, AnalysisErrorListener errorListener2) { |
| 5482 _jtd_constructor_275_impl(definingLibrary2, source2, typeProvider2, errorLis
tener2); | 5474 _jtd_constructor_276_impl(definingLibrary2, source2, typeProvider2, errorLis
tener2); |
| 5483 } | 5475 } |
| 5484 _jtd_constructor_275_impl(LibraryElement definingLibrary2, Source source2, Typ
eProvider typeProvider2, AnalysisErrorListener errorListener2) { | 5476 _jtd_constructor_276_impl(LibraryElement definingLibrary2, Source source2, Typ
eProvider typeProvider2, AnalysisErrorListener errorListener2) { |
| 5485 this._definingLibrary = definingLibrary2; | 5477 this._definingLibrary = definingLibrary2; |
| 5486 this._source = source2; | 5478 this._source = source2; |
| 5487 this._errorListener = errorListener2; | 5479 this._errorListener = errorListener2; |
| 5488 this._nameScope = new LibraryScope(definingLibrary2, errorListener2); | 5480 this._nameScope = new LibraryScope(definingLibrary2, errorListener2); |
| 5489 this._typeProvider = typeProvider2; | 5481 this._typeProvider = typeProvider2; |
| 5490 } | 5482 } |
| 5491 | 5483 |
| 5492 /** | 5484 /** |
| 5493 * Return the library element for the library containing the compilation unit
being resolved. | 5485 * Return the library element for the library containing the compilation unit
being resolved. |
| 5494 * @return the library element for the library containing the compilation unit
being resolved | 5486 * @return the library element for the library containing the compilation unit
being resolved |
| 5495 */ | 5487 */ |
| 5496 LibraryElement get definingLibrary => _definingLibrary; | 5488 LibraryElement get definingLibrary => _definingLibrary; |
| 5497 | 5489 |
| 5498 /** | 5490 /** |
| 5499 * Return the object used to access the types from the core library. | 5491 * Return the object used to access the types from the core library. |
| 5500 * @return the object used to access the types from the core library | 5492 * @return the object used to access the types from the core library |
| 5501 */ | 5493 */ |
| 5502 TypeProvider get typeProvider => _typeProvider; | 5494 TypeProvider get typeProvider => _typeProvider; |
| 5503 Object visitBlock(Block node) { | 5495 Object visitBlock(Block node) { |
| 5504 Scope outerScope = _nameScope; | 5496 Scope outerScope = _nameScope; |
| 5505 _nameScope = new EnclosedScope(_nameScope); | 5497 _nameScope = new EnclosedScope(_nameScope); |
| 5506 try { | 5498 try { |
| 5507 super.visitBlock(node); | 5499 super.visitBlock(node); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5714 Object visitWhileStatement(WhileStatement node) { | 5706 Object visitWhileStatement(WhileStatement node) { |
| 5715 LabelScope outerScope = _labelScope; | 5707 LabelScope outerScope = _labelScope; |
| 5716 _labelScope = new LabelScope.con1(outerScope, false, false); | 5708 _labelScope = new LabelScope.con1(outerScope, false, false); |
| 5717 try { | 5709 try { |
| 5718 super.visitWhileStatement(node); | 5710 super.visitWhileStatement(node); |
| 5719 } finally { | 5711 } finally { |
| 5720 _labelScope = outerScope; | 5712 _labelScope = outerScope; |
| 5721 } | 5713 } |
| 5722 return null; | 5714 return null; |
| 5723 } | 5715 } |
| 5724 | 5716 |
| 5725 /** | 5717 /** |
| 5726 * Return the label scope in which the current node is being resolved. | 5718 * Return the label scope in which the current node is being resolved. |
| 5727 * @return the label scope in which the current node is being resolved | 5719 * @return the label scope in which the current node is being resolved |
| 5728 */ | 5720 */ |
| 5729 LabelScope get labelScope => _labelScope; | 5721 LabelScope get labelScope => _labelScope; |
| 5730 | 5722 |
| 5731 /** | 5723 /** |
| 5732 * Return the name scope in which the current node is being resolved. | 5724 * Return the name scope in which the current node is being resolved. |
| 5733 * @return the name scope in which the current node is being resolved | 5725 * @return the name scope in which the current node is being resolved |
| 5734 */ | 5726 */ |
| 5735 Scope get nameScope => _nameScope; | 5727 Scope get nameScope => _nameScope; |
| 5736 | 5728 |
| 5737 /** | 5729 /** |
| 5738 * Report an error with the given error code and arguments. | 5730 * Report an error with the given error code and arguments. |
| 5739 * @param errorCode the error code of the error to be reported | 5731 * @param errorCode the error code of the error to be reported |
| 5740 * @param node the node specifying the location of the error | 5732 * @param node the node specifying the location of the error |
| 5741 * @param arguments the arguments to the error, used to compose the error mess
age | 5733 * @param arguments the arguments to the error, used to compose the error mess
age |
| 5742 */ | 5734 */ |
| 5743 void reportError(ErrorCode errorCode, ASTNode node, List<Object> arguments) { | 5735 void reportError(ErrorCode errorCode, ASTNode node, List<Object> arguments) { |
| 5744 _errorListener.onError(new AnalysisError.con2(_source, node.offset, node.len
gth, errorCode, arguments)); | 5736 _errorListener.onError(new AnalysisError.con2(_source, node.offset, node.len
gth, errorCode, arguments)); |
| 5745 } | 5737 } |
| 5746 | 5738 |
| 5747 /** | 5739 /** |
| 5748 * Report an error with the given error code and arguments. | 5740 * Report an error with the given error code and arguments. |
| 5749 * @param errorCode the error code of the error to be reported | 5741 * @param errorCode the error code of the error to be reported |
| 5750 * @param offset the offset of the location of the error | 5742 * @param offset the offset of the location of the error |
| 5751 * @param length the length of the location of the error | 5743 * @param length the length of the location of the error |
| 5752 * @param arguments the arguments to the error, used to compose the error mess
age | 5744 * @param arguments the arguments to the error, used to compose the error mess
age |
| 5753 */ | 5745 */ |
| 5754 void reportError5(ErrorCode errorCode, int offset, int length, List<Object> ar
guments) { | 5746 void reportError5(ErrorCode errorCode, int offset, int length, List<Object> ar
guments) { |
| 5755 _errorListener.onError(new AnalysisError.con2(_source, offset, length, error
Code, arguments)); | 5747 _errorListener.onError(new AnalysisError.con2(_source, offset, length, error
Code, arguments)); |
| 5756 } | 5748 } |
| 5757 | 5749 |
| 5758 /** | 5750 /** |
| 5759 * Report an error with the given error code and arguments. | 5751 * Report an error with the given error code and arguments. |
| 5760 * @param errorCode the error code of the error to be reported | 5752 * @param errorCode the error code of the error to be reported |
| 5761 * @param token the token specifying the location of the error | 5753 * @param token the token specifying the location of the error |
| 5762 * @param arguments the arguments to the error, used to compose the error mess
age | 5754 * @param arguments the arguments to the error, used to compose the error mess
age |
| 5763 */ | 5755 */ |
| 5764 void reportError6(ErrorCode errorCode, sc.Token token, List<Object> arguments)
{ | 5756 void reportError6(ErrorCode errorCode, sc.Token token, List<Object> arguments)
{ |
| 5765 _errorListener.onError(new AnalysisError.con2(_source, token.offset, token.l
ength, errorCode, arguments)); | 5757 _errorListener.onError(new AnalysisError.con2(_source, token.offset, token.l
ength, errorCode, arguments)); |
| 5766 } | 5758 } |
| 5767 | 5759 |
| 5768 /** | 5760 /** |
| 5769 * Visit the given AST node if it is not null. | 5761 * Visit the given AST node if it is not null. |
| 5770 * @param node the node to be visited | 5762 * @param node the node to be visited |
| 5771 */ | 5763 */ |
| 5772 void safelyVisit(ASTNode node) { | 5764 void safelyVisit(ASTNode node) { |
| 5773 if (node != null) { | 5765 if (node != null) { |
| 5774 node.accept(this); | 5766 node.accept(this); |
| 5775 } | 5767 } |
| 5776 } | 5768 } |
| 5777 | 5769 |
| 5778 /** | 5770 /** |
| 5779 * Visit the given statement after it's scope has been created. This replaces
the normal call to | 5771 * Visit the given statement after it's scope has been created. This replaces
the normal call to |
| 5780 * the inherited visit method so that ResolverVisitor can intervene when type
propagation is | 5772 * the inherited visit method so that ResolverVisitor can intervene when type
propagation is |
| 5781 * enabled. | 5773 * enabled. |
| 5782 * @param node the statement to be visited | 5774 * @param node the statement to be visited |
| 5783 */ | 5775 */ |
| 5784 void visitForEachStatementInScope(ForEachStatement node) { | 5776 void visitForEachStatementInScope(ForEachStatement node) { |
| 5785 safelyVisit(node.iterator); | 5777 safelyVisit(node.iterator); |
| 5786 safelyVisit(node.loopVariable); | 5778 safelyVisit(node.loopVariable); |
| 5787 safelyVisit(node.body); | 5779 safelyVisit(node.body); |
| 5788 } | 5780 } |
| 5789 | 5781 |
| 5790 /** | 5782 /** |
| 5791 * Visit the given statement after it's scope has been created. This replaces
the normal call to | 5783 * Visit the given statement after it's scope has been created. This replaces
the normal call to |
| 5792 * the inherited visit method so that ResolverVisitor can intervene when type
propagation is | 5784 * the inherited visit method so that ResolverVisitor can intervene when type
propagation is |
| 5793 * enabled. | 5785 * enabled. |
| 5794 * @param node the statement to be visited | 5786 * @param node the statement to be visited |
| 5795 */ | 5787 */ |
| 5796 void visitForStatementInScope(ForStatement node) { | 5788 void visitForStatementInScope(ForStatement node) { |
| 5797 super.visitForStatement(node); | 5789 super.visitForStatement(node); |
| 5798 } | 5790 } |
| 5799 | 5791 |
| 5800 /** | 5792 /** |
| 5801 * Add scopes for each of the given labels. | 5793 * Add scopes for each of the given labels. |
| 5802 * @param labels the labels for which new scopes are to be added | 5794 * @param labels the labels for which new scopes are to be added |
| 5803 * @return the scope that was in effect before the new scopes were added | 5795 * @return the scope that was in effect before the new scopes were added |
| 5804 */ | 5796 */ |
| 5805 LabelScope addScopesFor(NodeList<Label> labels) { | 5797 LabelScope addScopesFor(NodeList<Label> labels) { |
| 5806 LabelScope outerScope = _labelScope; | 5798 LabelScope outerScope = _labelScope; |
| 5807 for (Label label in labels) { | 5799 for (Label label in labels) { |
| 5808 SimpleIdentifier labelNameNode = label.label; | 5800 SimpleIdentifier labelNameNode = label.label; |
| 5809 String labelName = labelNameNode.name; | 5801 String labelName = labelNameNode.name; |
| 5810 LabelElement labelElement = labelNameNode.element as LabelElement; | 5802 LabelElement labelElement = labelNameNode.element as LabelElement; |
| 5811 _labelScope = new LabelScope.con2(_labelScope, labelName, labelElement); | 5803 _labelScope = new LabelScope.con2(_labelScope, labelName, labelElement); |
| 5812 } | 5804 } |
| 5813 return outerScope; | 5805 return outerScope; |
| 5814 } | 5806 } |
| 5815 } | 5807 } |
| 5816 | |
| 5817 /** | 5808 /** |
| 5818 * Instances of the class {@code StaticTypeAnalyzer} perform two type-related ta
sks. First, they | 5809 * Instances of the class {@code StaticTypeAnalyzer} perform two type-related ta
sks. First, they |
| 5819 * compute the static type of every expression. Second, they look for any static
type errors or | 5810 * compute the static type of every expression. Second, they look for any static
type errors or |
| 5820 * warnings that might need to be generated. The requirements for the type analy
zer are: | 5811 * warnings that might need to be generated. The requirements for the type analy
zer are: |
| 5821 * <ol> | 5812 * <ol> |
| 5822 * <li>Every element that refers to types should be fully populated. | 5813 * <li>Every element that refers to types should be fully populated. |
| 5823 * <li>Every node representing an expression should be resolved to the Type of t
he expression.</li> | 5814 * <li>Every node representing an expression should be resolved to the Type of t
he expression.</li> |
| 5824 * </ol> | 5815 * </ol> |
| 5825 * @coverage dart.engine.resolver | 5816 * @coverage dart.engine.resolver |
| 5826 */ | 5817 */ |
| 5827 class StaticTypeAnalyzer extends SimpleASTVisitor<Object> { | 5818 class StaticTypeAnalyzer extends SimpleASTVisitor<Object> { |
| 5828 | 5819 |
| 5829 /** | 5820 /** |
| 5830 * Create a table mapping HTML tag names to the names of the classes (in 'dart
:html') that | 5821 * Create a table mapping HTML tag names to the names of the classes (in 'dart
:html') that |
| 5831 * implement those tags. | 5822 * implement those tags. |
| 5832 * @return the table that was created | 5823 * @return the table that was created |
| 5833 */ | 5824 */ |
| 5834 static Map<String, String> createHtmlTagToClassMap() { | 5825 static Map<String, String> createHtmlTagToClassMap() { |
| 5835 Map<String, String> map = new Map<String, String>(); | 5826 Map<String, String> map = new Map<String, String>(); |
| 5836 map["a"] = "AnchorElement"; | 5827 map["a"] = "AnchorElement"; |
| 5837 map["area"] = "AreaElement"; | 5828 map["area"] = "AreaElement"; |
| 5838 map["br"] = "BRElement"; | 5829 map["br"] = "BRElement"; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5886 map["col"] = "TableColElement"; | 5877 map["col"] = "TableColElement"; |
| 5887 map["table"] = "TableElement"; | 5878 map["table"] = "TableElement"; |
| 5888 map["tr"] = "TableRowElement"; | 5879 map["tr"] = "TableRowElement"; |
| 5889 map["textarea"] = "TextAreaElement"; | 5880 map["textarea"] = "TextAreaElement"; |
| 5890 map["title"] = "TitleElement"; | 5881 map["title"] = "TitleElement"; |
| 5891 map["track"] = "TrackElement"; | 5882 map["track"] = "TrackElement"; |
| 5892 map["ul"] = "UListElement"; | 5883 map["ul"] = "UListElement"; |
| 5893 map["video"] = "VideoElement"; | 5884 map["video"] = "VideoElement"; |
| 5894 return map; | 5885 return map; |
| 5895 } | 5886 } |
| 5896 | 5887 |
| 5897 /** | 5888 /** |
| 5898 * The resolver driving the resolution and type analysis. | 5889 * The resolver driving the resolution and type analysis. |
| 5899 */ | 5890 */ |
| 5900 ResolverVisitor _resolver; | 5891 ResolverVisitor _resolver; |
| 5901 | 5892 |
| 5902 /** | 5893 /** |
| 5903 * The object providing access to the types defined by the language. | 5894 * The object providing access to the types defined by the language. |
| 5904 */ | 5895 */ |
| 5905 TypeProvider _typeProvider; | 5896 TypeProvider _typeProvider; |
| 5906 | 5897 |
| 5907 /** | 5898 /** |
| 5908 * The type representing the type 'dynamic'. | 5899 * The type representing the type 'dynamic'. |
| 5909 */ | 5900 */ |
| 5910 Type2 _dynamicType; | 5901 Type2 _dynamicType; |
| 5911 | 5902 |
| 5912 /** | 5903 /** |
| 5913 * The type representing the class containing the nodes being analyzed, or {@c
ode null} if the | 5904 * The type representing the class containing the nodes being analyzed, or {@c
ode null} if the |
| 5914 * nodes are not within a class. | 5905 * nodes are not within a class. |
| 5915 */ | 5906 */ |
| 5916 InterfaceType _thisType; | 5907 InterfaceType _thisType; |
| 5917 | 5908 |
| 5918 /** | 5909 /** |
| 5919 * The object keeping track of which elements have had their types overridden. | 5910 * The object keeping track of which elements have had their types overridden. |
| 5920 */ | 5911 */ |
| 5921 TypeOverrideManager _overrideManager; | 5912 TypeOverrideManager _overrideManager; |
| 5922 | 5913 |
| 5923 /** | 5914 /** |
| 5924 * A table mapping HTML tag names to the names of the classes (in 'dart:html')
that implement | 5915 * A table mapping HTML tag names to the names of the classes (in 'dart:html')
that implement |
| 5925 * those tags. | 5916 * those tags. |
| 5926 */ | 5917 */ |
| 5927 static Map<String, String> _HTML_ELEMENT_TO_CLASS_MAP = createHtmlTagToClassMa
p(); | 5918 static Map<String, String> _HTML_ELEMENT_TO_CLASS_MAP = createHtmlTagToClassMa
p(); |
| 5928 | 5919 |
| 5929 /** | 5920 /** |
| 5930 * Initialize a newly created type analyzer. | 5921 * Initialize a newly created type analyzer. |
| 5931 * @param resolver the resolver driving this participant | 5922 * @param resolver the resolver driving this participant |
| 5932 */ | 5923 */ |
| 5933 StaticTypeAnalyzer(ResolverVisitor resolver) { | 5924 StaticTypeAnalyzer(ResolverVisitor resolver) { |
| 5934 this._resolver = resolver; | 5925 this._resolver = resolver; |
| 5935 _typeProvider = resolver.typeProvider; | 5926 _typeProvider = resolver.typeProvider; |
| 5936 _dynamicType = _typeProvider.dynamicType; | 5927 _dynamicType = _typeProvider.dynamicType; |
| 5937 _overrideManager = resolver.overrideManager; | 5928 _overrideManager = resolver.overrideManager; |
| 5938 } | 5929 } |
| 5939 | 5930 |
| 5940 /** | 5931 /** |
| 5941 * Set the type of the class being analyzed to the given type. | 5932 * Set the type of the class being analyzed to the given type. |
| 5942 * @param thisType the type representing the class containing the nodes being
analyzed | 5933 * @param thisType the type representing the class containing the nodes being
analyzed |
| 5943 */ | 5934 */ |
| 5944 void set thisType(InterfaceType thisType2) { | 5935 void set thisType(InterfaceType thisType2) { |
| 5945 this._thisType = thisType2; | 5936 this._thisType = thisType2; |
| 5946 } | 5937 } |
| 5947 | 5938 |
| 5948 /** | 5939 /** |
| 5949 * The Dart Language Specification, 12.5: <blockquote>The static type of a str
ing literal is{@code String}.</blockquote> | 5940 * The Dart Language Specification, 12.5: <blockquote>The static type of a str
ing literal is{@code String}.</blockquote> |
| 5950 */ | 5941 */ |
| 5951 Object visitAdjacentStrings(AdjacentStrings node) { | 5942 Object visitAdjacentStrings(AdjacentStrings node) { |
| 5952 recordStaticType(node, _typeProvider.stringType); | 5943 recordStaticType(node, _typeProvider.stringType); |
| 5953 return null; | 5944 return null; |
| 5954 } | 5945 } |
| 5955 | 5946 |
| 5956 /** | 5947 /** |
| 5957 * The Dart Language Specification, 12.33: <blockquote>The static type of an a
rgument definition | 5948 * The Dart Language Specification, 12.33: <blockquote>The static type of an a
rgument definition |
| 5958 * test is {@code bool}.</blockquote> | 5949 * test is {@code bool}.</blockquote> |
| 5959 */ | 5950 */ |
| 5960 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) { | 5951 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) { |
| 5961 recordStaticType(node, _typeProvider.boolType); | 5952 recordStaticType(node, _typeProvider.boolType); |
| 5962 return null; | 5953 return null; |
| 5963 } | 5954 } |
| 5964 | 5955 |
| 5965 /** | 5956 /** |
| 5966 * The Dart Language Specification, 12.32: <blockquote>... the cast expression
<i>e as T</i> ... | 5957 * The Dart Language Specification, 12.32: <blockquote>... the cast expression
<i>e as T</i> ... |
| 5967 * <p> | 5958 * <p> |
| 5968 * It is a static warning if <i>T</i> does not denote a type available in the
current lexical | 5959 * It is a static warning if <i>T</i> does not denote a type available in the
current lexical |
| 5969 * scope. | 5960 * scope. |
| 5970 * <p> | 5961 * <p> |
| 5971 * The static type of a cast expression <i>e as T</i> is <i>T</i>.</blockquote
> | 5962 * The static type of a cast expression <i>e as T</i> is <i>T</i>.</blockquote
> |
| 5972 */ | 5963 */ |
| 5973 Object visitAsExpression(AsExpression node) { | 5964 Object visitAsExpression(AsExpression node) { |
| 5974 recordStaticType(node, getType2(node.type)); | 5965 recordStaticType(node, getType2(node.type)); |
| 5975 return null; | 5966 return null; |
| 5976 } | 5967 } |
| 5977 | 5968 |
| 5978 /** | 5969 /** |
| 5979 * The Dart Language Specification, 12.18: <blockquote>... an assignment <i>a<
/i> of the form <i>v | 5970 * The Dart Language Specification, 12.18: <blockquote>... an assignment <i>a<
/i> of the form <i>v |
| 5980 * = e</i> ... | 5971 * = e</i> ... |
| 5981 * <p> | 5972 * <p> |
| 5982 * It is a static type warning if the static type of <i>e</i> may not be assig
ned to the static | 5973 * It is a static type warning if the static type of <i>e</i> may not be assig
ned to the static |
| 5983 * type of <i>v</i>. | 5974 * type of <i>v</i>. |
| 5984 * <p> | 5975 * <p> |
| 5985 * The static type of the expression <i>v = e</i> is the static type of <i>e</
i>. | 5976 * The static type of the expression <i>v = e</i> is the static type of <i>e</
i>. |
| 5986 * <p> | 5977 * <p> |
| 5987 * ... an assignment of the form <i>C.v = e</i> ... | 5978 * ... an assignment of the form <i>C.v = e</i> ... |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6039 MethodElement propagatedMethodElement = node.element; | 6030 MethodElement propagatedMethodElement = node.element; |
| 6040 if (propagatedMethodElement != staticMethodElement) { | 6031 if (propagatedMethodElement != staticMethodElement) { |
| 6041 Type2 propagatedType = computeReturnType(propagatedMethodElement); | 6032 Type2 propagatedType = computeReturnType(propagatedMethodElement); |
| 6042 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy
pe)) { | 6033 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy
pe)) { |
| 6043 recordPropagatedType(node, propagatedType); | 6034 recordPropagatedType(node, propagatedType); |
| 6044 } | 6035 } |
| 6045 } | 6036 } |
| 6046 } | 6037 } |
| 6047 return null; | 6038 return null; |
| 6048 } | 6039 } |
| 6049 | 6040 |
| 6050 /** | 6041 /** |
| 6051 * The Dart Language Specification, 12.20: <blockquote>The static type of a lo
gical boolean | 6042 * The Dart Language Specification, 12.20: <blockquote>The static type of a lo
gical boolean |
| 6052 * expression is {@code bool}.</blockquote> | 6043 * expression is {@code bool}.</blockquote> |
| 6053 * <p> | 6044 * <p> |
| 6054 * The Dart Language Specification, 12.21:<blockquote>A bitwise expression of
the form | 6045 * The Dart Language Specification, 12.21:<blockquote>A bitwise expression of
the form |
| 6055 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio
n | 6046 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio
n |
| 6056 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. A bitwise expression of the form <i
>super op | 6047 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. A bitwise expression of the form <i
>super op |
| 6057 * e<sub>2</sub></i> is equivalent to the method invocation | 6048 * e<sub>2</sub></i> is equivalent to the method invocation |
| 6058 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> | 6049 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> |
| 6059 * <p> | 6050 * <p> |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6091 recordStaticType(node, staticType); | 6082 recordStaticType(node, staticType); |
| 6092 MethodElement propagatedMethodElement = node.element; | 6083 MethodElement propagatedMethodElement = node.element; |
| 6093 if (propagatedMethodElement != staticMethodElement) { | 6084 if (propagatedMethodElement != staticMethodElement) { |
| 6094 Type2 propagatedType = computeReturnType(propagatedMethodElement); | 6085 Type2 propagatedType = computeReturnType(propagatedMethodElement); |
| 6095 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType
)) { | 6086 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType
)) { |
| 6096 recordPropagatedType(node, propagatedType); | 6087 recordPropagatedType(node, propagatedType); |
| 6097 } | 6088 } |
| 6098 } | 6089 } |
| 6099 return null; | 6090 return null; |
| 6100 } | 6091 } |
| 6101 | 6092 |
| 6102 /** | 6093 /** |
| 6103 * The Dart Language Specification, 12.4: <blockquote>The static type of a boo
lean literal is | 6094 * The Dart Language Specification, 12.4: <blockquote>The static type of a boo
lean literal is |
| 6104 * bool.</blockquote> | 6095 * bool.</blockquote> |
| 6105 */ | 6096 */ |
| 6106 Object visitBooleanLiteral(BooleanLiteral node) { | 6097 Object visitBooleanLiteral(BooleanLiteral node) { |
| 6107 recordStaticType(node, _typeProvider.boolType); | 6098 recordStaticType(node, _typeProvider.boolType); |
| 6108 return null; | 6099 return null; |
| 6109 } | 6100 } |
| 6110 | 6101 |
| 6111 /** | 6102 /** |
| 6112 * The Dart Language Specification, 12.15.2: <blockquote>A cascaded method inv
ocation expression | 6103 * The Dart Language Specification, 12.15.2: <blockquote>A cascaded method inv
ocation expression |
| 6113 * of the form <i>e..suffix</i> is equivalent to the expression <i>(t) {t.suff
ix; return | 6104 * of the form <i>e..suffix</i> is equivalent to the expression <i>(t) {t.suff
ix; return |
| 6114 * t;}(e)</i>.</blockquote> | 6105 * t;}(e)</i>.</blockquote> |
| 6115 */ | 6106 */ |
| 6116 Object visitCascadeExpression(CascadeExpression node) { | 6107 Object visitCascadeExpression(CascadeExpression node) { |
| 6117 recordStaticType(node, getStaticType(node.target)); | 6108 recordStaticType(node, getStaticType(node.target)); |
| 6118 recordPropagatedType(node, getPropagatedType(node.target)); | 6109 recordPropagatedType(node, getPropagatedType(node.target)); |
| 6119 return null; | 6110 return null; |
| 6120 } | 6111 } |
| 6121 | 6112 |
| 6122 /** | 6113 /** |
| 6123 * The Dart Language Specification, 12.19: <blockquote> ... a conditional expr
ession <i>c</i> of | 6114 * The Dart Language Specification, 12.19: <blockquote> ... a conditional expr
ession <i>c</i> of |
| 6124 * the form <i>e<sub>1</sub> ? e<sub>2</sub> : e<sub>3</sub></i> ... | 6115 * the form <i>e<sub>1</sub> ? e<sub>2</sub> : e<sub>3</sub></i> ... |
| 6125 * <p> | 6116 * <p> |
| 6126 * It is a static type warning if the type of e<sub>1</sub> may not be assigne
d to {@code bool}. | 6117 * It is a static type warning if the type of e<sub>1</sub> may not be assigne
d to {@code bool}. |
| 6127 * <p> | 6118 * <p> |
| 6128 * The static type of <i>c</i> is the least upper bound of the static type of
<i>e<sub>2</sub></i> | 6119 * The static type of <i>c</i> is the least upper bound of the static type of
<i>e<sub>2</sub></i> |
| 6129 * and the static type of <i>e<sub>3</sub></i>.</blockquote> | 6120 * and the static type of <i>e<sub>3</sub></i>.</blockquote> |
| 6130 */ | 6121 */ |
| 6131 Object visitConditionalExpression(ConditionalExpression node) { | 6122 Object visitConditionalExpression(ConditionalExpression node) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 6151 if (propagatedElseType == null) { | 6142 if (propagatedElseType == null) { |
| 6152 propagatedElseType = staticElseType; | 6143 propagatedElseType = staticElseType; |
| 6153 } | 6144 } |
| 6154 Type2 propagatedType = propagatedThenType.getLeastUpperBound(propagatedEls
eType); | 6145 Type2 propagatedType = propagatedThenType.getLeastUpperBound(propagatedEls
eType); |
| 6155 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType
)) { | 6146 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType
)) { |
| 6156 recordPropagatedType(node, propagatedType); | 6147 recordPropagatedType(node, propagatedType); |
| 6157 } | 6148 } |
| 6158 } | 6149 } |
| 6159 return null; | 6150 return null; |
| 6160 } | 6151 } |
| 6161 | 6152 |
| 6162 /** | 6153 /** |
| 6163 * The Dart Language Specification, 12.3: <blockquote>The static type of a lit
eral double is | 6154 * The Dart Language Specification, 12.3: <blockquote>The static type of a lit
eral double is |
| 6164 * double.</blockquote> | 6155 * double.</blockquote> |
| 6165 */ | 6156 */ |
| 6166 Object visitDoubleLiteral(DoubleLiteral node) { | 6157 Object visitDoubleLiteral(DoubleLiteral node) { |
| 6167 recordStaticType(node, _typeProvider.doubleType); | 6158 recordStaticType(node, _typeProvider.doubleType); |
| 6168 return null; | 6159 return null; |
| 6169 } | 6160 } |
| 6170 Object visitFunctionDeclaration(FunctionDeclaration node) { | 6161 Object visitFunctionDeclaration(FunctionDeclaration node) { |
| 6171 FunctionExpression function = node.functionExpression; | 6162 FunctionExpression function = node.functionExpression; |
| 6172 FunctionTypeImpl functionType = node.element.type as FunctionTypeImpl; | 6163 FunctionTypeImpl functionType = node.element.type as FunctionTypeImpl; |
| 6173 setTypeInformation(functionType, computeReturnType2(node), function.paramete
rs); | 6164 setTypeInformation(functionType, computeReturnType2(node), function.paramete
rs); |
| 6174 recordStaticType(function, functionType); | 6165 recordStaticType(function, functionType); |
| 6175 return null; | 6166 return null; |
| 6176 } | 6167 } |
| 6177 | 6168 |
| 6178 /** | 6169 /** |
| 6179 * The Dart Language Specification, 12.9: <blockquote>The static type of a fun
ction literal of the | 6170 * The Dart Language Specification, 12.9: <blockquote>The static type of a fun
ction literal of the |
| 6180 * form <i>(T<sub>1</sub> a<sub>1</sub>, …, T<sub>n</sub> a<sub>n</sub>
, \[T<sub>n+1</sub> | 6171 * form <i>(T<sub>1</sub> a<sub>1</sub>, …, T<sub>n</sub> a<sub>n</sub>
, \[T<sub>n+1</sub> |
| 6181 * x<sub>n+1</sub> = d1, …, T<sub>n+k</sub> x<sub>n+k</sub> = dk\]) =>
e</i> is | 6172 * x<sub>n+1</sub> = d1, …, T<sub>n+k</sub> x<sub>n+k</sub> = dk\]) =>
e</i> is |
| 6182 * <i>(T<sub>1</sub>, …, Tn, \[T<sub>n+1</sub> x<sub>n+1</sub>, &hellip
;, T<sub>n+k</sub> | 6173 * <i>(T<sub>1</sub>, …, Tn, \[T<sub>n+1</sub> x<sub>n+1</sub>, &hellip
;, T<sub>n+k</sub> |
| 6183 * x<sub>n+k</sub>\]) → T<sub>0</sub></i>, where <i>T<sub>0</sub></i> is
the static type of | 6174 * x<sub>n+k</sub>\]) → T<sub>0</sub></i>, where <i>T<sub>0</sub></i> is
the static type of |
| 6184 * <i>e</i>. In any case where <i>T<sub>i</sub>, 1 <= i <= n</i>, is not
specified, it is | 6175 * <i>e</i>. In any case where <i>T<sub>i</sub>, 1 <= i <= n</i>, is not
specified, it is |
| 6185 * considered to have been specified as dynamic. | 6176 * considered to have been specified as dynamic. |
| 6186 * <p> | 6177 * <p> |
| 6187 * The static type of a function literal of the form <i>(T<sub>1</sub> a<sub>1
</sub>, …, | 6178 * The static type of a function literal of the form <i>(T<sub>1</sub> a<sub>1
</sub>, …, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 6207 */ | 6198 */ |
| 6208 Object visitFunctionExpression(FunctionExpression node) { | 6199 Object visitFunctionExpression(FunctionExpression node) { |
| 6209 if (node.parent is FunctionDeclaration) { | 6200 if (node.parent is FunctionDeclaration) { |
| 6210 return null; | 6201 return null; |
| 6211 } | 6202 } |
| 6212 FunctionTypeImpl functionType = node.element.type as FunctionTypeImpl; | 6203 FunctionTypeImpl functionType = node.element.type as FunctionTypeImpl; |
| 6213 setTypeInformation(functionType, computeReturnType3(node), node.parameters); | 6204 setTypeInformation(functionType, computeReturnType3(node), node.parameters); |
| 6214 recordStaticType(node, functionType); | 6205 recordStaticType(node, functionType); |
| 6215 return null; | 6206 return null; |
| 6216 } | 6207 } |
| 6217 | 6208 |
| 6218 /** | 6209 /** |
| 6219 * The Dart Language Specification, 12.14.4: <blockquote>A function expression
invocation <i>i</i> | 6210 * The Dart Language Specification, 12.14.4: <blockquote>A function expression
invocation <i>i</i> |
| 6220 * has the form <i>e<sub>f</sub>(a<sub>1</sub>, …, a<sub>n</sub>, x<sub
>n+1</sub>: | 6211 * has the form <i>e<sub>f</sub>(a<sub>1</sub>, …, a<sub>n</sub>, x<sub
>n+1</sub>: |
| 6221 * a<sub>n+1</sub>, …, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>, where <i>
e<sub>f</sub></i> is | 6212 * a<sub>n+1</sub>, …, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>, where <i>
e<sub>f</sub></i> is |
| 6222 * an expression. | 6213 * an expression. |
| 6223 * <p> | 6214 * <p> |
| 6224 * It is a static type warning if the static type <i>F</i> of <i>e<sub>f</sub>
</i> may not be | 6215 * It is a static type warning if the static type <i>F</i> of <i>e<sub>f</sub>
</i> may not be |
| 6225 * assigned to a function type. | 6216 * assigned to a function type. |
| 6226 * <p> | 6217 * <p> |
| 6227 * If <i>F</i> is not a function type, the static type of <i>i</i> is dynamic.
Otherwise the | 6218 * If <i>F</i> is not a function type, the static type of <i>i</i> is dynamic.
Otherwise the |
| 6228 * static type of <i>i</i> is the declared return type of <i>F</i>.</blockquot
e> | 6219 * static type of <i>i</i> is the declared return type of <i>F</i>.</blockquot
e> |
| 6229 */ | 6220 */ |
| 6230 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { | 6221 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { |
| 6231 ExecutableElement staticMethodElement = node.staticElement; | 6222 ExecutableElement staticMethodElement = node.staticElement; |
| 6232 Type2 staticType = computeReturnType(staticMethodElement); | 6223 Type2 staticType = computeReturnType(staticMethodElement); |
| 6233 recordStaticType(node, staticType); | 6224 recordStaticType(node, staticType); |
| 6234 ExecutableElement propagatedMethodElement = node.element; | 6225 ExecutableElement propagatedMethodElement = node.element; |
| 6235 Type2 propagatedType = computeReturnType(propagatedMethodElement); | 6226 Type2 propagatedType = computeReturnType(propagatedMethodElement); |
| 6236 if (staticType == null) { | 6227 if (staticType == null) { |
| 6237 recordStaticType(node, propagatedType); | 6228 recordStaticType(node, propagatedType); |
| 6238 } else if (propagatedType != null && propagatedType.isMoreSpecificThan(stati
cType)) { | 6229 } else if (propagatedType != null && propagatedType.isMoreSpecificThan(stati
cType)) { |
| 6239 recordPropagatedType(node, propagatedType); | 6230 recordPropagatedType(node, propagatedType); |
| 6240 } | 6231 } |
| 6241 return null; | 6232 return null; |
| 6242 } | 6233 } |
| 6243 | 6234 |
| 6244 /** | 6235 /** |
| 6245 * The Dart Language Specification, 12.29: <blockquote>An assignable expressio
n of the form | 6236 * The Dart Language Specification, 12.29: <blockquote>An assignable expressio
n of the form |
| 6246 * <i>e<sub>1</sub>\[e<sub>2</sub>\]</i> is evaluated as a method invocation o
f the operator method | 6237 * <i>e<sub>1</sub>\[e<sub>2</sub>\]</i> is evaluated as a method invocation o
f the operator method |
| 6247 * <i>\[\]</i> on <i>e<sub>1</sub></i> with argument <i>e<sub>2</sub></i>.</bl
ockquote> | 6238 * <i>\[\]</i> on <i>e<sub>1</sub></i> with argument <i>e<sub>2</sub></i>.</bl
ockquote> |
| 6248 */ | 6239 */ |
| 6249 Object visitIndexExpression(IndexExpression node) { | 6240 Object visitIndexExpression(IndexExpression node) { |
| 6250 if (node.inSetterContext()) { | 6241 if (node.inSetterContext()) { |
| 6251 ExecutableElement staticMethodElement = node.staticElement; | 6242 ExecutableElement staticMethodElement = node.staticElement; |
| 6252 Type2 staticType = computeArgumentType(staticMethodElement); | 6243 Type2 staticType = computeArgumentType(staticMethodElement); |
| 6253 recordStaticType(node, staticType); | 6244 recordStaticType(node, staticType); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 6265 MethodElement propagatedMethodElement = node.element; | 6256 MethodElement propagatedMethodElement = node.element; |
| 6266 if (propagatedMethodElement != staticMethodElement) { | 6257 if (propagatedMethodElement != staticMethodElement) { |
| 6267 Type2 propagatedType = computeReturnType(propagatedMethodElement); | 6258 Type2 propagatedType = computeReturnType(propagatedMethodElement); |
| 6268 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy
pe)) { | 6259 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy
pe)) { |
| 6269 recordPropagatedType(node, propagatedType); | 6260 recordPropagatedType(node, propagatedType); |
| 6270 } | 6261 } |
| 6271 } | 6262 } |
| 6272 } | 6263 } |
| 6273 return null; | 6264 return null; |
| 6274 } | 6265 } |
| 6275 | 6266 |
| 6276 /** | 6267 /** |
| 6277 * The Dart Language Specification, 12.11.1: <blockquote>The static type of a
new expression of | 6268 * The Dart Language Specification, 12.11.1: <blockquote>The static type of a
new expression of |
| 6278 * either the form <i>new T.id(a<sub>1</sub>, …, a<sub>n</sub>)</i> or
the form <i>new | 6269 * either the form <i>new T.id(a<sub>1</sub>, …, a<sub>n</sub>)</i> or
the form <i>new |
| 6279 * T(a<sub>1</sub>, …, a<sub>n</sub>)</i> is <i>T</i>.</blockquote> | 6270 * T(a<sub>1</sub>, …, a<sub>n</sub>)</i> is <i>T</i>.</blockquote> |
| 6280 * <p> | 6271 * <p> |
| 6281 * The Dart Language Specification, 12.11.2: <blockquote>The static type of a
constant object | 6272 * The Dart Language Specification, 12.11.2: <blockquote>The static type of a
constant object |
| 6282 * expression of either the form <i>const T.id(a<sub>1</sub>, …, a<sub>
n</sub>)</i> or the | 6273 * expression of either the form <i>const T.id(a<sub>1</sub>, …, a<sub>
n</sub>)</i> or the |
| 6283 * form <i>const T(a<sub>1</sub>, …, a<sub>n</sub>)</i> is <i>T</i>. </
blockquote> | 6274 * form <i>const T(a<sub>1</sub>, …, a<sub>n</sub>)</i> is <i>T</i>. </
blockquote> |
| 6284 */ | 6275 */ |
| 6285 Object visitInstanceCreationExpression(InstanceCreationExpression node) { | 6276 Object visitInstanceCreationExpression(InstanceCreationExpression node) { |
| 6286 recordStaticType(node, node.constructorName.type.type); | 6277 recordStaticType(node, node.constructorName.type.type); |
| 6287 ConstructorElement element2 = node.element; | 6278 ConstructorElement element2 = node.element; |
| 6288 if (element2 != null && "Element" == element2.enclosingElement.name && "tag"
== element2.name) { | 6279 if (element2 != null && "Element" == element2.enclosingElement.name && "tag"
== element2.name) { |
| 6289 LibraryElement library2 = element2.library; | 6280 LibraryElement library2 = element2.library; |
| 6290 if (isHtmlLibrary(library2)) { | 6281 if (isHtmlLibrary(library2)) { |
| 6291 Type2 returnType = getFirstArgumentAsType2(library2, node.argumentList,
_HTML_ELEMENT_TO_CLASS_MAP); | 6282 Type2 returnType = getFirstArgumentAsType2(library2, node.argumentList,
_HTML_ELEMENT_TO_CLASS_MAP); |
| 6292 if (returnType != null) { | 6283 if (returnType != null) { |
| 6293 recordPropagatedType(node, returnType); | 6284 recordPropagatedType(node, returnType); |
| 6294 } | 6285 } |
| 6295 } | 6286 } |
| 6296 } | 6287 } |
| 6297 return null; | 6288 return null; |
| 6298 } | 6289 } |
| 6299 | 6290 |
| 6300 /** | 6291 /** |
| 6301 * The Dart Language Specification, 12.3: <blockquote>The static type of an in
teger literal is{@code int}.</blockquote> | 6292 * The Dart Language Specification, 12.3: <blockquote>The static type of an in
teger literal is{@code int}.</blockquote> |
| 6302 */ | 6293 */ |
| 6303 Object visitIntegerLiteral(IntegerLiteral node) { | 6294 Object visitIntegerLiteral(IntegerLiteral node) { |
| 6304 recordStaticType(node, _typeProvider.intType); | 6295 recordStaticType(node, _typeProvider.intType); |
| 6305 return null; | 6296 return null; |
| 6306 } | 6297 } |
| 6307 | 6298 |
| 6308 /** | 6299 /** |
| 6309 * The Dart Language Specification, 12.31: <blockquote>It is a static warning
if <i>T</i> does not | 6300 * The Dart Language Specification, 12.31: <blockquote>It is a static warning
if <i>T</i> does not |
| 6310 * denote a type available in the current lexical scope. | 6301 * denote a type available in the current lexical scope. |
| 6311 * <p> | 6302 * <p> |
| 6312 * The static type of an is-expression is {@code bool}.</blockquote> | 6303 * The static type of an is-expression is {@code bool}.</blockquote> |
| 6313 */ | 6304 */ |
| 6314 Object visitIsExpression(IsExpression node) { | 6305 Object visitIsExpression(IsExpression node) { |
| 6315 recordStaticType(node, _typeProvider.boolType); | 6306 recordStaticType(node, _typeProvider.boolType); |
| 6316 return null; | 6307 return null; |
| 6317 } | 6308 } |
| 6318 | 6309 |
| 6319 /** | 6310 /** |
| 6320 * The Dart Language Specification, 12.6: <blockquote>The static type of a lis
t literal of the | 6311 * The Dart Language Specification, 12.6: <blockquote>The static type of a lis
t literal of the |
| 6321 * form <i><b>const</b> <E>\[e<sub>1</sub>, …, e<sub>n</sub>\]</i
> or the form | 6312 * form <i><b>const</b> <E>\[e<sub>1</sub>, …, e<sub>n</sub>\]</i
> or the form |
| 6322 * <i><E>\[e<sub>1</sub>, …, e<sub>n</sub>\]</i> is {@code List&l
t;E>}. The static | 6313 * <i><E>\[e<sub>1</sub>, …, e<sub>n</sub>\]</i> is {@code List&l
t;E>}. The static |
| 6323 * type a list literal of the form <i><b>const</b> \[e<sub>1</sub>, …,
e<sub>n</sub>\]</i> or | 6314 * type a list literal of the form <i><b>const</b> \[e<sub>1</sub>, …,
e<sub>n</sub>\]</i> or |
| 6324 * the form <i>\[e<sub>1</sub>, …, e<sub>n</sub>\]</i> is {@code List&l
t;dynamic>}.</blockquote> | 6315 * the form <i>\[e<sub>1</sub>, …, e<sub>n</sub>\]</i> is {@code List&l
t;dynamic>}.</blockquote> |
| 6325 */ | 6316 */ |
| 6326 Object visitListLiteral(ListLiteral node) { | 6317 Object visitListLiteral(ListLiteral node) { |
| 6327 Type2 staticType = _dynamicType; | 6318 Type2 staticType = _dynamicType; |
| 6328 TypeArgumentList typeArguments2 = node.typeArguments; | 6319 TypeArgumentList typeArguments2 = node.typeArguments; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 6351 propagatedType = _dynamicType; | 6342 propagatedType = _dynamicType; |
| 6352 } | 6343 } |
| 6353 } | 6344 } |
| 6354 } | 6345 } |
| 6355 if (propagatedType.isMoreSpecificThan(staticType)) { | 6346 if (propagatedType.isMoreSpecificThan(staticType)) { |
| 6356 recordPropagatedType(node, _typeProvider.listType.substitute5(<Type2> [p
ropagatedType])); | 6347 recordPropagatedType(node, _typeProvider.listType.substitute5(<Type2> [p
ropagatedType])); |
| 6357 } | 6348 } |
| 6358 } | 6349 } |
| 6359 return null; | 6350 return null; |
| 6360 } | 6351 } |
| 6361 | 6352 |
| 6362 /** | 6353 /** |
| 6363 * The Dart Language Specification, 12.7: <blockquote>The static type of a map
literal of the form | 6354 * The Dart Language Specification, 12.7: <blockquote>The static type of a map
literal of the form |
| 6364 * <i><b>const</b> <String, V> {k<sub>1</sub>:e<sub>1</sub>, …, | 6355 * <i><b>const</b> <String, V> {k<sub>1</sub>:e<sub>1</sub>, …, |
| 6365 * k<sub>n</sub>:e<sub>n</sub>}</i> or the form <i><String, V> {k<sub>1<
/sub>:e<sub>1</sub>, | 6356 * k<sub>n</sub>:e<sub>n</sub>}</i> or the form <i><String, V> {k<sub>1<
/sub>:e<sub>1</sub>, |
| 6366 * …, k<sub>n</sub>:e<sub>n</sub>}</i> is {@code Map<String, V>}.
The static type a | 6357 * …, k<sub>n</sub>:e<sub>n</sub>}</i> is {@code Map<String, V>}.
The static type a |
| 6367 * map literal of the form <i><b>const</b> {k<sub>1</sub>:e<sub>1</sub>, &hell
ip;, | 6358 * map literal of the form <i><b>const</b> {k<sub>1</sub>:e<sub>1</sub>, &hell
ip;, |
| 6368 * k<sub>n</sub>:e<sub>n</sub>}</i> or the form <i>{k<sub>1</sub>:e<sub>1</sub
>, …, | 6359 * k<sub>n</sub>:e<sub>n</sub>}</i> or the form <i>{k<sub>1</sub>:e<sub>1</sub
>, …, |
| 6369 * k<sub>n</sub>:e<sub>n</sub>}</i> is {@code Map<String, dynamic>}. | 6360 * k<sub>n</sub>:e<sub>n</sub>}</i> is {@code Map<String, dynamic>}. |
| 6370 * <p> | 6361 * <p> |
| 6371 * It is a compile-time error if the first type argument to a map literal is n
ot | 6362 * It is a compile-time error if the first type argument to a map literal is n
ot |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6425 propagatedKeyType = staticKeyType; | 6416 propagatedKeyType = staticKeyType; |
| 6426 } | 6417 } |
| 6427 if (!betterValue) { | 6418 if (!betterValue) { |
| 6428 propagatedValueType = staticValueType; | 6419 propagatedValueType = staticValueType; |
| 6429 } | 6420 } |
| 6430 recordPropagatedType(node, _typeProvider.mapType.substitute5(<Type2> [pr
opagatedKeyType, propagatedValueType])); | 6421 recordPropagatedType(node, _typeProvider.mapType.substitute5(<Type2> [pr
opagatedKeyType, propagatedValueType])); |
| 6431 } | 6422 } |
| 6432 } | 6423 } |
| 6433 return null; | 6424 return null; |
| 6434 } | 6425 } |
| 6435 | 6426 |
| 6436 /** | 6427 /** |
| 6437 * The Dart Language Specification, 12.15.1: <blockquote>An ordinary method in
vocation <i>i</i> | 6428 * The Dart Language Specification, 12.15.1: <blockquote>An ordinary method in
vocation <i>i</i> |
| 6438 * has the form <i>o.m(a<sub>1</sub>, …, a<sub>n</sub>, x<sub>n+1</sub>
: a<sub>n+1</sub>, | 6429 * has the form <i>o.m(a<sub>1</sub>, …, a<sub>n</sub>, x<sub>n+1</sub>
: a<sub>n+1</sub>, |
| 6439 * …, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>. | 6430 * …, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>. |
| 6440 * <p> | 6431 * <p> |
| 6441 * Let <i>T</i> be the static type of <i>o</i>. It is a static type warning if
<i>T</i> does not | 6432 * Let <i>T</i> be the static type of <i>o</i>. It is a static type warning if
<i>T</i> does not |
| 6442 * have an accessible instance member named <i>m</i>. If <i>T.m</i> exists, it
is a static warning | 6433 * have an accessible instance member named <i>m</i>. If <i>T.m</i> exists, it
is a static warning |
| 6443 * if the type <i>F</i> of <i>T.m</i> may not be assigned to a function type. | 6434 * if the type <i>F</i> of <i>T.m</i> may not be assigned to a function type. |
| 6444 * <p> | 6435 * <p> |
| 6445 * If <i>T.m</i> does not exist, or if <i>F</i> is not a function type, the st
atic type of | 6436 * If <i>T.m</i> does not exist, or if <i>F</i> is not a function type, the st
atic type of |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6544 } | 6535 } |
| 6545 } | 6536 } |
| 6546 return null; | 6537 return null; |
| 6547 } | 6538 } |
| 6548 Object visitNamedExpression(NamedExpression node) { | 6539 Object visitNamedExpression(NamedExpression node) { |
| 6549 Expression expression2 = node.expression; | 6540 Expression expression2 = node.expression; |
| 6550 recordStaticType(node, getStaticType(expression2)); | 6541 recordStaticType(node, getStaticType(expression2)); |
| 6551 recordPropagatedType(node, getPropagatedType(expression2)); | 6542 recordPropagatedType(node, getPropagatedType(expression2)); |
| 6552 return null; | 6543 return null; |
| 6553 } | 6544 } |
| 6554 | 6545 |
| 6555 /** | 6546 /** |
| 6556 * The Dart Language Specification, 12.2: <blockquote>The static type of {@cod
e null} is bottom. | 6547 * The Dart Language Specification, 12.2: <blockquote>The static type of {@cod
e null} is bottom. |
| 6557 * </blockquote> | 6548 * </blockquote> |
| 6558 */ | 6549 */ |
| 6559 Object visitNullLiteral(NullLiteral node) { | 6550 Object visitNullLiteral(NullLiteral node) { |
| 6560 recordStaticType(node, _typeProvider.bottomType); | 6551 recordStaticType(node, _typeProvider.bottomType); |
| 6561 return null; | 6552 return null; |
| 6562 } | 6553 } |
| 6563 Object visitParenthesizedExpression(ParenthesizedExpression node) { | 6554 Object visitParenthesizedExpression(ParenthesizedExpression node) { |
| 6564 Expression expression2 = node.expression; | 6555 Expression expression2 = node.expression; |
| 6565 recordStaticType(node, getStaticType(expression2)); | 6556 recordStaticType(node, getStaticType(expression2)); |
| 6566 recordPropagatedType(node, getPropagatedType(expression2)); | 6557 recordPropagatedType(node, getPropagatedType(expression2)); |
| 6567 return null; | 6558 return null; |
| 6568 } | 6559 } |
| 6569 | 6560 |
| 6570 /** | 6561 /** |
| 6571 * The Dart Language Specification, 12.28: <blockquote>A postfix expression of
the form | 6562 * The Dart Language Specification, 12.28: <blockquote>A postfix expression of
the form |
| 6572 * <i>v++</i>, where <i>v</i> is an identifier, is equivalent to <i>(){var r =
v; v = r + 1; | 6563 * <i>v++</i>, where <i>v</i> is an identifier, is equivalent to <i>(){var r =
v; v = r + 1; |
| 6573 * return r}()</i>. | 6564 * return r}()</i>. |
| 6574 * <p> | 6565 * <p> |
| 6575 * A postfix expression of the form <i>C.v++</i> is equivalent to <i>(){var r
= C.v; C.v = r + 1; | 6566 * A postfix expression of the form <i>C.v++</i> is equivalent to <i>(){var r
= C.v; C.v = r + 1; |
| 6576 * return r}()</i>. | 6567 * return r}()</i>. |
| 6577 * <p> | 6568 * <p> |
| 6578 * A postfix expression of the form <i>e1.v++</i> is equivalent to <i>(x){var
r = x.v; x.v = r + | 6569 * A postfix expression of the form <i>e1.v++</i> is equivalent to <i>(x){var
r = x.v; x.v = r + |
| 6579 * 1; return r}(e1)</i>. | 6570 * 1; return r}(e1)</i>. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 6600 if (identical(operator2, sc.TokenType.MINUS_MINUS) || identical(operator2, s
c.TokenType.PLUS_PLUS)) { | 6591 if (identical(operator2, sc.TokenType.MINUS_MINUS) || identical(operator2, s
c.TokenType.PLUS_PLUS)) { |
| 6601 Type2 intType2 = _typeProvider.intType; | 6592 Type2 intType2 = _typeProvider.intType; |
| 6602 if (identical(getStaticType(node.operand), intType2)) { | 6593 if (identical(getStaticType(node.operand), intType2)) { |
| 6603 staticType = intType2; | 6594 staticType = intType2; |
| 6604 } | 6595 } |
| 6605 } | 6596 } |
| 6606 recordStaticType(node, staticType); | 6597 recordStaticType(node, staticType); |
| 6607 recordPropagatedType(node, getPropagatedType(operand2)); | 6598 recordPropagatedType(node, getPropagatedType(operand2)); |
| 6608 return null; | 6599 return null; |
| 6609 } | 6600 } |
| 6610 | 6601 |
| 6611 /** | 6602 /** |
| 6612 * See {@link #visitSimpleIdentifier(SimpleIdentifier)}. | 6603 * See {@link #visitSimpleIdentifier(SimpleIdentifier)}. |
| 6613 */ | 6604 */ |
| 6614 Object visitPrefixedIdentifier(PrefixedIdentifier node) { | 6605 Object visitPrefixedIdentifier(PrefixedIdentifier node) { |
| 6615 SimpleIdentifier prefixedIdentifier = node.identifier; | 6606 SimpleIdentifier prefixedIdentifier = node.identifier; |
| 6616 Element element2 = prefixedIdentifier.element; | 6607 Element element2 = prefixedIdentifier.element; |
| 6617 Type2 staticType = _dynamicType; | 6608 Type2 staticType = _dynamicType; |
| 6618 if (element2 is ClassElement) { | 6609 if (element2 is ClassElement) { |
| 6619 if (isNotTypeLiteral(node)) { | 6610 if (isNotTypeLiteral(node)) { |
| 6620 staticType = ((element2 as ClassElement)).type; | 6611 staticType = ((element2 as ClassElement)).type; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 6636 } | 6627 } |
| 6637 recordStaticType(prefixedIdentifier, staticType); | 6628 recordStaticType(prefixedIdentifier, staticType); |
| 6638 recordStaticType(node, staticType); | 6629 recordStaticType(node, staticType); |
| 6639 Type2 propagatedType = _overrideManager.getType(element2); | 6630 Type2 propagatedType = _overrideManager.getType(element2); |
| 6640 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType))
{ | 6631 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType))
{ |
| 6641 recordPropagatedType(prefixedIdentifier, propagatedType); | 6632 recordPropagatedType(prefixedIdentifier, propagatedType); |
| 6642 recordPropagatedType(node, propagatedType); | 6633 recordPropagatedType(node, propagatedType); |
| 6643 } | 6634 } |
| 6644 return null; | 6635 return null; |
| 6645 } | 6636 } |
| 6646 | 6637 |
| 6647 /** | 6638 /** |
| 6648 * The Dart Language Specification, 12.27: <blockquote>A unary expression <i>u
</i> of the form | 6639 * The Dart Language Specification, 12.27: <blockquote>A unary expression <i>u
</i> of the form |
| 6649 * <i>op e</i> is equivalent to a method invocation <i>expression e.op()</i>.
An expression of the | 6640 * <i>op e</i> is equivalent to a method invocation <i>expression e.op()</i>.
An expression of the |
| 6650 * form <i>op super</i> is equivalent to the method invocation <i>super.op()<i
>.</blockquote> | 6641 * form <i>op super</i> is equivalent to the method invocation <i>super.op()<i
>.</blockquote> |
| 6651 */ | 6642 */ |
| 6652 Object visitPrefixExpression(PrefixExpression node) { | 6643 Object visitPrefixExpression(PrefixExpression node) { |
| 6653 sc.TokenType operator2 = node.operator.type; | 6644 sc.TokenType operator2 = node.operator.type; |
| 6654 if (identical(operator2, sc.TokenType.BANG)) { | 6645 if (identical(operator2, sc.TokenType.BANG)) { |
| 6655 recordStaticType(node, _typeProvider.boolType); | 6646 recordStaticType(node, _typeProvider.boolType); |
| 6656 } else { | 6647 } else { |
| 6657 ExecutableElement staticMethodElement = node.staticElement; | 6648 ExecutableElement staticMethodElement = node.staticElement; |
| 6658 Type2 staticType = computeReturnType(staticMethodElement); | 6649 Type2 staticType = computeReturnType(staticMethodElement); |
| 6659 if (identical(operator2, sc.TokenType.MINUS_MINUS) || identical(operator2,
sc.TokenType.PLUS_PLUS)) { | 6650 if (identical(operator2, sc.TokenType.MINUS_MINUS) || identical(operator2,
sc.TokenType.PLUS_PLUS)) { |
| 6660 Type2 intType2 = _typeProvider.intType; | 6651 Type2 intType2 = _typeProvider.intType; |
| 6661 if (identical(getStaticType(node.operand), intType2)) { | 6652 if (identical(getStaticType(node.operand), intType2)) { |
| 6662 staticType = intType2; | 6653 staticType = intType2; |
| 6663 } | 6654 } |
| 6664 } | 6655 } |
| 6665 recordStaticType(node, staticType); | 6656 recordStaticType(node, staticType); |
| 6666 MethodElement propagatedMethodElement = node.element; | 6657 MethodElement propagatedMethodElement = node.element; |
| 6667 if (propagatedMethodElement != staticMethodElement) { | 6658 if (propagatedMethodElement != staticMethodElement) { |
| 6668 Type2 propagatedType = computeReturnType(propagatedMethodElement); | 6659 Type2 propagatedType = computeReturnType(propagatedMethodElement); |
| 6669 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy
pe)) { | 6660 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy
pe)) { |
| 6670 recordPropagatedType(node, propagatedType); | 6661 recordPropagatedType(node, propagatedType); |
| 6671 } | 6662 } |
| 6672 } | 6663 } |
| 6673 } | 6664 } |
| 6674 return null; | 6665 return null; |
| 6675 } | 6666 } |
| 6676 | 6667 |
| 6677 /** | 6668 /** |
| 6678 * The Dart Language Specification, 12.13: <blockquote> Property extraction al
lows for a member of | 6669 * The Dart Language Specification, 12.13: <blockquote> Property extraction al
lows for a member of |
| 6679 * an object to be concisely extracted from the object. If <i>o</i> is an obje
ct, and if <i>m</i> | 6670 * an object to be concisely extracted from the object. If <i>o</i> is an obje
ct, and if <i>m</i> |
| 6680 * is the name of a method member of <i>o</i>, then | 6671 * is the name of a method member of <i>o</i>, then |
| 6681 * <ul> | 6672 * <ul> |
| 6682 * <li><i>o.m</i> is defined to be equivalent to: <i>(r<sub>1</sub>, …,
r<sub>n</sub>, | 6673 * <li><i>o.m</i> is defined to be equivalent to: <i>(r<sub>1</sub>, …,
r<sub>n</sub>, |
| 6683 * {p<sub>1</sub> : d<sub>1</sub>, …, p<sub>k</sub> : d<sub>k</sub>}){r
eturn | 6674 * {p<sub>1</sub> : d<sub>1</sub>, …, p<sub>k</sub> : d<sub>k</sub>}){r
eturn |
| 6684 * o.m(r<sub>1</sub>, …, r<sub>n</sub>, p<sub>1</sub>: p<sub>1</sub>, &
hellip;, | 6675 * o.m(r<sub>1</sub>, …, r<sub>n</sub>, p<sub>1</sub>: p<sub>1</sub>, &
hellip;, |
| 6685 * p<sub>k</sub>: p<sub>k</sub>);}</i> if <i>m</i> has required parameters <i>
r<sub>1</sub>, | 6676 * p<sub>k</sub>: p<sub>k</sub>);}</i> if <i>m</i> has required parameters <i>
r<sub>1</sub>, |
| 6686 * …, r<sub>n</sub></i>, and named parameters <i>p<sub>1</sub> …
p<sub>k</sub></i> | 6677 * …, r<sub>n</sub></i>, and named parameters <i>p<sub>1</sub> …
p<sub>k</sub></i> |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6728 } else { | 6719 } else { |
| 6729 } | 6720 } |
| 6730 recordStaticType(propertyName2, staticType); | 6721 recordStaticType(propertyName2, staticType); |
| 6731 recordStaticType(node, staticType); | 6722 recordStaticType(node, staticType); |
| 6732 Type2 propagatedType = _overrideManager.getType(element2); | 6723 Type2 propagatedType = _overrideManager.getType(element2); |
| 6733 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType))
{ | 6724 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType))
{ |
| 6734 recordPropagatedType(node, propagatedType); | 6725 recordPropagatedType(node, propagatedType); |
| 6735 } | 6726 } |
| 6736 return null; | 6727 return null; |
| 6737 } | 6728 } |
| 6738 | 6729 |
| 6739 /** | 6730 /** |
| 6740 * The Dart Language Specification, 12.9: <blockquote>The static type of a ret
hrow expression is | 6731 * The Dart Language Specification, 12.9: <blockquote>The static type of a ret
hrow expression is |
| 6741 * bottom.</blockquote> | 6732 * bottom.</blockquote> |
| 6742 */ | 6733 */ |
| 6743 Object visitRethrowExpression(RethrowExpression node) { | 6734 Object visitRethrowExpression(RethrowExpression node) { |
| 6744 recordStaticType(node, _typeProvider.bottomType); | 6735 recordStaticType(node, _typeProvider.bottomType); |
| 6745 return null; | 6736 return null; |
| 6746 } | 6737 } |
| 6747 | 6738 |
| 6748 /** | 6739 /** |
| 6749 * The Dart Language Specification, 12.30: <blockquote>Evaluation of an identi
fier expression | 6740 * The Dart Language Specification, 12.30: <blockquote>Evaluation of an identi
fier expression |
| 6750 * <i>e</i> of the form <i>id</i> proceeds as follows: | 6741 * <i>e</i> of the form <i>id</i> proceeds as follows: |
| 6751 * <p> | 6742 * <p> |
| 6752 * Let <i>d</i> be the innermost declaration in the enclosing lexical scope wh
ose name is | 6743 * Let <i>d</i> be the innermost declaration in the enclosing lexical scope wh
ose name is |
| 6753 * <i>id</i>. If no such declaration exists in the lexical scope, let <i>d</i>
be the declaration | 6744 * <i>id</i>. If no such declaration exists in the lexical scope, let <i>d</i>
be the declaration |
| 6754 * of the inherited member named <i>id</i> if it exists. | 6745 * of the inherited member named <i>id</i> if it exists. |
| 6755 * <ul> | 6746 * <ul> |
| 6756 * <li>If <i>d</i> is a class or type alias <i>T</i>, the value of <i>e</i> is
the unique instance | 6747 * <li>If <i>d</i> is a class or type alias <i>T</i>, the value of <i>e</i> is
the unique instance |
| 6757 * of class {@code Type} reifying <i>T</i>. | 6748 * of class {@code Type} reifying <i>T</i>. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6813 } else { | 6804 } else { |
| 6814 staticType = _dynamicType; | 6805 staticType = _dynamicType; |
| 6815 } | 6806 } |
| 6816 recordStaticType(node, staticType); | 6807 recordStaticType(node, staticType); |
| 6817 Type2 propagatedType = _overrideManager.getType(element2); | 6808 Type2 propagatedType = _overrideManager.getType(element2); |
| 6818 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType))
{ | 6809 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType))
{ |
| 6819 recordPropagatedType(node, propagatedType); | 6810 recordPropagatedType(node, propagatedType); |
| 6820 } | 6811 } |
| 6821 return null; | 6812 return null; |
| 6822 } | 6813 } |
| 6823 | 6814 |
| 6824 /** | 6815 /** |
| 6825 * The Dart Language Specification, 12.5: <blockquote>The static type of a str
ing literal is{@code String}.</blockquote> | 6816 * The Dart Language Specification, 12.5: <blockquote>The static type of a str
ing literal is{@code String}.</blockquote> |
| 6826 */ | 6817 */ |
| 6827 Object visitSimpleStringLiteral(SimpleStringLiteral node) { | 6818 Object visitSimpleStringLiteral(SimpleStringLiteral node) { |
| 6828 recordStaticType(node, _typeProvider.stringType); | 6819 recordStaticType(node, _typeProvider.stringType); |
| 6829 return null; | 6820 return null; |
| 6830 } | 6821 } |
| 6831 | 6822 |
| 6832 /** | 6823 /** |
| 6833 * The Dart Language Specification, 12.5: <blockquote>The static type of a str
ing literal is{@code String}.</blockquote> | 6824 * The Dart Language Specification, 12.5: <blockquote>The static type of a str
ing literal is{@code String}.</blockquote> |
| 6834 */ | 6825 */ |
| 6835 Object visitStringInterpolation(StringInterpolation node) { | 6826 Object visitStringInterpolation(StringInterpolation node) { |
| 6836 recordStaticType(node, _typeProvider.stringType); | 6827 recordStaticType(node, _typeProvider.stringType); |
| 6837 return null; | 6828 return null; |
| 6838 } | 6829 } |
| 6839 Object visitSuperExpression(SuperExpression node) { | 6830 Object visitSuperExpression(SuperExpression node) { |
| 6840 if (_thisType == null) { | 6831 if (_thisType == null) { |
| 6841 recordStaticType(node, _dynamicType); | 6832 recordStaticType(node, _dynamicType); |
| 6842 } else { | 6833 } else { |
| 6843 recordStaticType(node, _thisType); | 6834 recordStaticType(node, _thisType); |
| 6844 } | 6835 } |
| 6845 return null; | 6836 return null; |
| 6846 } | 6837 } |
| 6847 | 6838 |
| 6848 /** | 6839 /** |
| 6849 * The Dart Language Specification, 12.10: <blockquote>The static type of {@co
de this} is the | 6840 * The Dart Language Specification, 12.10: <blockquote>The static type of {@co
de this} is the |
| 6850 * interface of the immediately enclosing class.</blockquote> | 6841 * interface of the immediately enclosing class.</blockquote> |
| 6851 */ | 6842 */ |
| 6852 Object visitThisExpression(ThisExpression node) { | 6843 Object visitThisExpression(ThisExpression node) { |
| 6853 if (_thisType == null) { | 6844 if (_thisType == null) { |
| 6854 recordStaticType(node, _dynamicType); | 6845 recordStaticType(node, _dynamicType); |
| 6855 } else { | 6846 } else { |
| 6856 recordStaticType(node, _thisType); | 6847 recordStaticType(node, _thisType); |
| 6857 } | 6848 } |
| 6858 return null; | 6849 return null; |
| 6859 } | 6850 } |
| 6860 | 6851 |
| 6861 /** | 6852 /** |
| 6862 * The Dart Language Specification, 12.8: <blockquote>The static type of a thr
ow expression is | 6853 * The Dart Language Specification, 12.8: <blockquote>The static type of a thr
ow expression is |
| 6863 * bottom.</blockquote> | 6854 * bottom.</blockquote> |
| 6864 */ | 6855 */ |
| 6865 Object visitThrowExpression(ThrowExpression node) { | 6856 Object visitThrowExpression(ThrowExpression node) { |
| 6866 recordStaticType(node, _typeProvider.bottomType); | 6857 recordStaticType(node, _typeProvider.bottomType); |
| 6867 return null; | 6858 return null; |
| 6868 } | 6859 } |
| 6869 Object visitVariableDeclaration(VariableDeclaration node) { | 6860 Object visitVariableDeclaration(VariableDeclaration node) { |
| 6870 Expression initializer2 = node.initializer; | 6861 Expression initializer2 = node.initializer; |
| 6871 if (initializer2 != null) { | 6862 if (initializer2 != null) { |
| 6872 Type2 rightType = getBestType(initializer2); | 6863 Type2 rightType = getBestType(initializer2); |
| 6873 VariableElement element2 = node.name.element as VariableElement; | 6864 VariableElement element2 = node.name.element as VariableElement; |
| 6874 if (element2 != null) { | 6865 if (element2 != null) { |
| 6875 _resolver.override(element2, rightType); | 6866 _resolver.override(element2, rightType); |
| 6876 } | 6867 } |
| 6877 } | 6868 } |
| 6878 return null; | 6869 return null; |
| 6879 } | 6870 } |
| 6880 | 6871 |
| 6881 /** | 6872 /** |
| 6882 * Record that the static type of the given node is the type of the second arg
ument to the method | 6873 * Record that the static type of the given node is the type of the second arg
ument to the method |
| 6883 * represented by the given element. | 6874 * represented by the given element. |
| 6884 * @param element the element representing the method invoked by the given nod
e | 6875 * @param element the element representing the method invoked by the given nod
e |
| 6885 */ | 6876 */ |
| 6886 Type2 computeArgumentType(ExecutableElement element) { | 6877 Type2 computeArgumentType(ExecutableElement element) { |
| 6887 if (element != null) { | 6878 if (element != null) { |
| 6888 List<ParameterElement> parameters2 = element.parameters; | 6879 List<ParameterElement> parameters2 = element.parameters; |
| 6889 if (parameters2 != null && parameters2.length == 2) { | 6880 if (parameters2 != null && parameters2.length == 2) { |
| 6890 return parameters2[1].type; | 6881 return parameters2[1].type; |
| 6891 } | 6882 } |
| 6892 } | 6883 } |
| 6893 return _dynamicType; | 6884 return _dynamicType; |
| 6894 } | 6885 } |
| 6895 | 6886 |
| 6896 /** | 6887 /** |
| 6897 * Compute the return type of the method or function represented by the given
element. | 6888 * Compute the return type of the method or function represented by the given
element. |
| 6898 * @param element the element representing the method or function invoked by t
he given node | 6889 * @param element the element representing the method or function invoked by t
he given node |
| 6899 * @return the return type that was computed | 6890 * @return the return type that was computed |
| 6900 */ | 6891 */ |
| 6901 Type2 computeReturnType(Element element) { | 6892 Type2 computeReturnType(Element element) { |
| 6902 if (element is PropertyAccessorElement) { | 6893 if (element is PropertyAccessorElement) { |
| 6903 FunctionType propertyType = ((element as PropertyAccessorElement)).type; | 6894 FunctionType propertyType = ((element as PropertyAccessorElement)).type; |
| 6904 if (propertyType != null) { | 6895 if (propertyType != null) { |
| 6905 Type2 returnType2 = propertyType.returnType; | 6896 Type2 returnType2 = propertyType.returnType; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 6929 return type2.returnType; | 6920 return type2.returnType; |
| 6930 } | 6921 } |
| 6931 } else if (element is VariableElement) { | 6922 } else if (element is VariableElement) { |
| 6932 Type2 variableType = ((element as VariableElement)).type; | 6923 Type2 variableType = ((element as VariableElement)).type; |
| 6933 if (variableType is FunctionType) { | 6924 if (variableType is FunctionType) { |
| 6934 return ((variableType as FunctionType)).returnType; | 6925 return ((variableType as FunctionType)).returnType; |
| 6935 } | 6926 } |
| 6936 } | 6927 } |
| 6937 return _dynamicType; | 6928 return _dynamicType; |
| 6938 } | 6929 } |
| 6939 | 6930 |
| 6940 /** | 6931 /** |
| 6941 * Given a function declaration, compute the return type of the function. The
return type of | 6932 * Given a function declaration, compute the return type of the function. The
return type of |
| 6942 * functions with a block body is {@code dynamicType}, with an expression body
it is the type of | 6933 * functions with a block body is {@code dynamicType}, with an expression body
it is the type of |
| 6943 * the expression. | 6934 * the expression. |
| 6944 * @param node the function expression whose return type is to be computed | 6935 * @param node the function expression whose return type is to be computed |
| 6945 * @return the return type that was computed | 6936 * @return the return type that was computed |
| 6946 */ | 6937 */ |
| 6947 Type2 computeReturnType2(FunctionDeclaration node) { | 6938 Type2 computeReturnType2(FunctionDeclaration node) { |
| 6948 TypeName returnType2 = node.returnType; | 6939 TypeName returnType2 = node.returnType; |
| 6949 if (returnType2 == null) { | 6940 if (returnType2 == null) { |
| 6950 return _dynamicType; | 6941 return _dynamicType; |
| 6951 } | 6942 } |
| 6952 return returnType2.type; | 6943 return returnType2.type; |
| 6953 } | 6944 } |
| 6954 | 6945 |
| 6955 /** | 6946 /** |
| 6956 * Given a function expression, compute the return type of the function. The r
eturn type of | 6947 * Given a function expression, compute the return type of the function. The r
eturn type of |
| 6957 * functions with a block body is {@code dynamicType}, with an expression body
it is the type of | 6948 * functions with a block body is {@code dynamicType}, with an expression body
it is the type of |
| 6958 * the expression. | 6949 * the expression. |
| 6959 * @param node the function expression whose return type is to be computed | 6950 * @param node the function expression whose return type is to be computed |
| 6960 * @return the return type that was computed | 6951 * @return the return type that was computed |
| 6961 */ | 6952 */ |
| 6962 Type2 computeReturnType3(FunctionExpression node) { | 6953 Type2 computeReturnType3(FunctionExpression node) { |
| 6963 FunctionBody body2 = node.body; | 6954 FunctionBody body2 = node.body; |
| 6964 if (body2 is ExpressionFunctionBody) { | 6955 if (body2 is ExpressionFunctionBody) { |
| 6965 return getStaticType(((body2 as ExpressionFunctionBody)).expression); | 6956 return getStaticType(((body2 as ExpressionFunctionBody)).expression); |
| 6966 } | 6957 } |
| 6967 return _dynamicType; | 6958 return _dynamicType; |
| 6968 } | 6959 } |
| 6969 | 6960 |
| 6970 /** | 6961 /** |
| 6971 * Return the propagated type of the given expression if it is available, or t
he static type if | 6962 * Return the propagated type of the given expression if it is available, or t
he static type if |
| 6972 * there is no propagated type. | 6963 * there is no propagated type. |
| 6973 * @param expression the expression whose type is to be returned | 6964 * @param expression the expression whose type is to be returned |
| 6974 * @return the propagated or static type of the given expression | 6965 * @return the propagated or static type of the given expression |
| 6975 */ | 6966 */ |
| 6976 Type2 getBestType(Expression expression) { | 6967 Type2 getBestType(Expression expression) { |
| 6977 Type2 type = expression.propagatedType; | 6968 Type2 type = expression.propagatedType; |
| 6978 if (type == null) { | 6969 if (type == null) { |
| 6979 type = expression.staticType; | 6970 type = expression.staticType; |
| 6980 if (type == null) { | 6971 if (type == null) { |
| 6981 return _dynamicType; | 6972 return _dynamicType; |
| 6982 } | 6973 } |
| 6983 } | 6974 } |
| 6984 return type; | 6975 return type; |
| 6985 } | 6976 } |
| 6986 | 6977 |
| 6987 /** | 6978 /** |
| 6988 * If the given argument list contains at least one argument, and if the argum
ent is a simple | 6979 * If the given argument list contains at least one argument, and if the argum
ent is a simple |
| 6989 * string literal, then parse that argument as a query string and return the t
ype specified by the | 6980 * string literal, then parse that argument as a query string and return the t
ype specified by the |
| 6990 * argument. | 6981 * argument. |
| 6991 * @param library the library in which the specified type would be defined | 6982 * @param library the library in which the specified type would be defined |
| 6992 * @param argumentList the list of arguments from which a type is to be extrac
ted | 6983 * @param argumentList the list of arguments from which a type is to be extrac
ted |
| 6993 * @return the type specified by the first argument in the argument list | 6984 * @return the type specified by the first argument in the argument list |
| 6994 */ | 6985 */ |
| 6995 Type2 getFirstArgumentAsQuery(LibraryElement library, ArgumentList argumentLis
t) { | 6986 Type2 getFirstArgumentAsQuery(LibraryElement library, ArgumentList argumentLis
t) { |
| 6996 String argumentValue = getFirstArgumentAsString(argumentList); | 6987 String argumentValue = getFirstArgumentAsString(argumentList); |
| 6997 if (argumentValue != null) { | 6988 if (argumentValue != null) { |
| 6998 if (argumentValue.contains(" ")) { | 6989 if (argumentValue.contains(" ")) { |
| 6999 return null; | 6990 return null; |
| 7000 } | 6991 } |
| 7001 String tag = argumentValue; | 6992 String tag = argumentValue; |
| 7002 tag = StringUtilities.substringBefore(tag, ":"); | 6993 tag = StringUtilities.substringBefore(tag, ":"); |
| 7003 tag = StringUtilities.substringBefore(tag, "["); | 6994 tag = StringUtilities.substringBefore(tag, "["); |
| 7004 tag = StringUtilities.substringBefore(tag, "."); | 6995 tag = StringUtilities.substringBefore(tag, "."); |
| 7005 tag = StringUtilities.substringBefore(tag, "#"); | 6996 tag = StringUtilities.substringBefore(tag, "#"); |
| 7006 tag = _HTML_ELEMENT_TO_CLASS_MAP[tag.toLowerCase()]; | 6997 tag = _HTML_ELEMENT_TO_CLASS_MAP[tag.toLowerCase()]; |
| 7007 ClassElement returnType = library.getType(tag); | 6998 ClassElement returnType = library.getType(tag); |
| 7008 if (returnType != null) { | 6999 if (returnType != null) { |
| 7009 return returnType.type; | 7000 return returnType.type; |
| 7010 } | 7001 } |
| 7011 } | 7002 } |
| 7012 return null; | 7003 return null; |
| 7013 } | 7004 } |
| 7014 | 7005 |
| 7015 /** | 7006 /** |
| 7016 * If the given argument list contains at least one argument, and if the argum
ent is a simple | 7007 * If the given argument list contains at least one argument, and if the argum
ent is a simple |
| 7017 * string literal, return the String value of the argument. | 7008 * string literal, return the String value of the argument. |
| 7018 * @param argumentList the list of arguments from which a string value is to b
e extracted | 7009 * @param argumentList the list of arguments from which a string value is to b
e extracted |
| 7019 * @return the string specified by the first argument in the argument list | 7010 * @return the string specified by the first argument in the argument list |
| 7020 */ | 7011 */ |
| 7021 String getFirstArgumentAsString(ArgumentList argumentList) { | 7012 String getFirstArgumentAsString(ArgumentList argumentList) { |
| 7022 NodeList<Expression> arguments2 = argumentList.arguments; | 7013 NodeList<Expression> arguments2 = argumentList.arguments; |
| 7023 if (arguments2.length > 0) { | 7014 if (arguments2.length > 0) { |
| 7024 Expression argument = arguments2[0]; | 7015 Expression argument = arguments2[0]; |
| 7025 if (argument is SimpleStringLiteral) { | 7016 if (argument is SimpleStringLiteral) { |
| 7026 return ((argument as SimpleStringLiteral)).value; | 7017 return ((argument as SimpleStringLiteral)).value; |
| 7027 } | 7018 } |
| 7028 } | 7019 } |
| 7029 return null; | 7020 return null; |
| 7030 } | 7021 } |
| 7031 | 7022 |
| 7032 /** | 7023 /** |
| 7033 * If the given argument list contains at least one argument, and if the argum
ent is a simple | 7024 * If the given argument list contains at least one argument, and if the argum
ent is a simple |
| 7034 * string literal, and if the value of the argument is the name of a class def
ined within the | 7025 * string literal, and if the value of the argument is the name of a class def
ined within the |
| 7035 * given library, return the type specified by the argument. | 7026 * given library, return the type specified by the argument. |
| 7036 * @param library the library in which the specified type would be defined | 7027 * @param library the library in which the specified type would be defined |
| 7037 * @param argumentList the list of arguments from which a type is to be extrac
ted | 7028 * @param argumentList the list of arguments from which a type is to be extrac
ted |
| 7038 * @return the type specified by the first argument in the argument list | 7029 * @return the type specified by the first argument in the argument list |
| 7039 */ | 7030 */ |
| 7040 Type2 getFirstArgumentAsType(LibraryElement library, ArgumentList argumentList
) => getFirstArgumentAsType2(library, argumentList, null); | 7031 Type2 getFirstArgumentAsType(LibraryElement library, ArgumentList argumentList
) => getFirstArgumentAsType2(library, argumentList, null); |
| 7041 | 7032 |
| 7042 /** | 7033 /** |
| 7043 * If the given argument list contains at least one argument, and if the argum
ent is a simple | 7034 * If the given argument list contains at least one argument, and if the argum
ent is a simple |
| 7044 * string literal, and if the value of the argument is the name of a class def
ined within the | 7035 * string literal, and if the value of the argument is the name of a class def
ined within the |
| 7045 * given library, return the type specified by the argument. | 7036 * given library, return the type specified by the argument. |
| 7046 * @param library the library in which the specified type would be defined | 7037 * @param library the library in which the specified type would be defined |
| 7047 * @param argumentList the list of arguments from which a type is to be extrac
ted | 7038 * @param argumentList the list of arguments from which a type is to be extrac
ted |
| 7048 * @return the type specified by the first argument in the argument list | 7039 * @return the type specified by the first argument in the argument list |
| 7049 */ | 7040 */ |
| 7050 Type2 getFirstArgumentAsType2(LibraryElement library, ArgumentList argumentLis
t, Map<String, String> nameMap) { | 7041 Type2 getFirstArgumentAsType2(LibraryElement library, ArgumentList argumentLis
t, Map<String, String> nameMap) { |
| 7051 String argumentValue = getFirstArgumentAsString(argumentList); | 7042 String argumentValue = getFirstArgumentAsString(argumentList); |
| 7052 if (argumentValue != null) { | 7043 if (argumentValue != null) { |
| 7053 if (nameMap != null) { | 7044 if (nameMap != null) { |
| 7054 argumentValue = nameMap[argumentValue.toLowerCase()]; | 7045 argumentValue = nameMap[argumentValue.toLowerCase()]; |
| 7055 } | 7046 } |
| 7056 ClassElement returnType = library.getType(argumentValue); | 7047 ClassElement returnType = library.getType(argumentValue); |
| 7057 if (returnType != null) { | 7048 if (returnType != null) { |
| 7058 return returnType.type; | 7049 return returnType.type; |
| 7059 } | 7050 } |
| 7060 } | 7051 } |
| 7061 return null; | 7052 return null; |
| 7062 } | 7053 } |
| 7063 | 7054 |
| 7064 /** | 7055 /** |
| 7065 * Return the propagated type of the given expression. | 7056 * Return the propagated type of the given expression. |
| 7066 * @param expression the expression whose type is to be returned | 7057 * @param expression the expression whose type is to be returned |
| 7067 * @return the propagated type of the given expression | 7058 * @return the propagated type of the given expression |
| 7068 */ | 7059 */ |
| 7069 Type2 getPropagatedType(Expression expression) { | 7060 Type2 getPropagatedType(Expression expression) { |
| 7070 Type2 type = expression.propagatedType; | 7061 Type2 type = expression.propagatedType; |
| 7071 return type; | 7062 return type; |
| 7072 } | 7063 } |
| 7073 | 7064 |
| 7074 /** | 7065 /** |
| 7075 * Return the static type of the given expression. | 7066 * Return the static type of the given expression. |
| 7076 * @param expression the expression whose type is to be returned | 7067 * @param expression the expression whose type is to be returned |
| 7077 * @return the static type of the given expression | 7068 * @return the static type of the given expression |
| 7078 */ | 7069 */ |
| 7079 Type2 getStaticType(Expression expression) { | 7070 Type2 getStaticType(Expression expression) { |
| 7080 Type2 type = expression.staticType; | 7071 Type2 type = expression.staticType; |
| 7081 if (type == null) { | 7072 if (type == null) { |
| 7082 return _dynamicType; | 7073 return _dynamicType; |
| 7083 } | 7074 } |
| 7084 return type; | 7075 return type; |
| 7085 } | 7076 } |
| 7086 | 7077 |
| 7087 /** | 7078 /** |
| 7088 * Return the type that should be recorded for a node that resolved to the giv
en accessor. | 7079 * Return the type that should be recorded for a node that resolved to the giv
en accessor. |
| 7089 * @param accessor the accessor that the node resolved to | 7080 * @param accessor the accessor that the node resolved to |
| 7090 * @param context if the accessor element has context \[by being the RHS of a{
@link PrefixedIdentifier} or {@link PropertyAccess}\], and the return type of th
e | 7081 * @param context if the accessor element has context \[by being the RHS of a{
@link PrefixedIdentifier} or {@link PropertyAccess}\], and the return type of th
e |
| 7091 * accessor is a parameter type, then the type of the LHS can be used to get m
ore | 7082 * accessor is a parameter type, then the type of the LHS can be used to get m
ore |
| 7092 * specific type information | 7083 * specific type information |
| 7093 * @return the type that should be recorded for a node that resolved to the gi
ven accessor | 7084 * @return the type that should be recorded for a node that resolved to the gi
ven accessor |
| 7094 */ | 7085 */ |
| 7095 Type2 getType(PropertyAccessorElement accessor, Type2 context) { | 7086 Type2 getType(PropertyAccessorElement accessor, Type2 context) { |
| 7096 FunctionType functionType = accessor.type; | 7087 FunctionType functionType = accessor.type; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 7119 for (int i = 0; i < parameterElements.length; i++) { | 7110 for (int i = 0; i < parameterElements.length; i++) { |
| 7120 TypeVariableElement varElt = parameterElements[i]; | 7111 TypeVariableElement varElt = parameterElements[i]; |
| 7121 if (returnType2.name == varElt.name) { | 7112 if (returnType2.name == varElt.name) { |
| 7122 return interfaceTypeContext.typeArguments[i]; | 7113 return interfaceTypeContext.typeArguments[i]; |
| 7123 } | 7114 } |
| 7124 } | 7115 } |
| 7125 } | 7116 } |
| 7126 } | 7117 } |
| 7127 return returnType2; | 7118 return returnType2; |
| 7128 } | 7119 } |
| 7129 | 7120 |
| 7130 /** | 7121 /** |
| 7131 * Return the type represented by the given type name. | 7122 * Return the type represented by the given type name. |
| 7132 * @param typeName the type name representing the type to be returned | 7123 * @param typeName the type name representing the type to be returned |
| 7133 * @return the type represented by the type name | 7124 * @return the type represented by the type name |
| 7134 */ | 7125 */ |
| 7135 Type2 getType2(TypeName typeName) { | 7126 Type2 getType2(TypeName typeName) { |
| 7136 Type2 type2 = typeName.type; | 7127 Type2 type2 = typeName.type; |
| 7137 if (type2 == null) { | 7128 if (type2 == null) { |
| 7138 return _dynamicType; | 7129 return _dynamicType; |
| 7139 } | 7130 } |
| 7140 return type2; | 7131 return type2; |
| 7141 } | 7132 } |
| 7142 | 7133 |
| 7143 /** | 7134 /** |
| 7144 * Return {@code true} if the given library is the 'dart:html' library. | 7135 * Return {@code true} if the given library is the 'dart:html' library. |
| 7145 * @param library the library being tested | 7136 * @param library the library being tested |
| 7146 * @return {@code true} if the library is 'dart:html' | 7137 * @return {@code true} if the library is 'dart:html' |
| 7147 */ | 7138 */ |
| 7148 bool isHtmlLibrary(LibraryElement library) => library.name == "dart.dom.html"; | 7139 bool isHtmlLibrary(LibraryElement library) => library.name == "dart.dom.html"; |
| 7149 | 7140 |
| 7150 /** | 7141 /** |
| 7151 * Return {@code true} if the given node is not a type literal. | 7142 * Return {@code true} if the given node is not a type literal. |
| 7152 * @param node the node being tested | 7143 * @param node the node being tested |
| 7153 * @return {@code true} if the given node is not a type literal | 7144 * @return {@code true} if the given node is not a type literal |
| 7154 */ | 7145 */ |
| 7155 bool isNotTypeLiteral(Identifier node) { | 7146 bool isNotTypeLiteral(Identifier node) { |
| 7156 ASTNode parent2 = node.parent; | 7147 ASTNode parent2 = node.parent; |
| 7157 return parent2 is TypeName || (parent2 is PrefixedIdentifier && (parent2.par
ent is TypeName || identical(((parent2 as PrefixedIdentifier)).prefix, node))) |
| (parent2 is PropertyAccess && identical(((parent2 as PropertyAccess)).target,
node)) || (parent2 is MethodInvocation && identical(node, ((parent2 as MethodInv
ocation)).target)); | 7148 return parent2 is TypeName || (parent2 is PrefixedIdentifier && (parent2.par
ent is TypeName || identical(((parent2 as PrefixedIdentifier)).prefix, node))) |
| (parent2 is PropertyAccess && identical(((parent2 as PropertyAccess)).target,
node)) || (parent2 is MethodInvocation && identical(node, ((parent2 as MethodInv
ocation)).target)); |
| 7158 } | 7149 } |
| 7159 | 7150 |
| 7160 /** | 7151 /** |
| 7161 * Record that the propagated type of the given node is the given type. | 7152 * Record that the propagated type of the given node is the given type. |
| 7162 * @param expression the node whose type is to be recorded | 7153 * @param expression the node whose type is to be recorded |
| 7163 * @param type the propagated type of the node | 7154 * @param type the propagated type of the node |
| 7164 */ | 7155 */ |
| 7165 void recordPropagatedType(Expression expression, Type2 type) { | 7156 void recordPropagatedType(Expression expression, Type2 type) { |
| 7166 if (type != null && !type.isDynamic()) { | 7157 if (type != null && !type.isDynamic()) { |
| 7167 expression.propagatedType = type; | 7158 expression.propagatedType = type; |
| 7168 } | 7159 } |
| 7169 } | 7160 } |
| 7170 | 7161 |
| 7171 /** | 7162 /** |
| 7172 * Record that the static type of the given node is the given type. | 7163 * Record that the static type of the given node is the given type. |
| 7173 * @param expression the node whose type is to be recorded | 7164 * @param expression the node whose type is to be recorded |
| 7174 * @param type the static type of the node | 7165 * @param type the static type of the node |
| 7175 */ | 7166 */ |
| 7176 void recordStaticType(Expression expression, Type2 type) { | 7167 void recordStaticType(Expression expression, Type2 type) { |
| 7177 if (type == null) { | 7168 if (type == null) { |
| 7178 expression.staticType = _dynamicType; | 7169 expression.staticType = _dynamicType; |
| 7179 } else { | 7170 } else { |
| 7180 expression.staticType = type; | 7171 expression.staticType = type; |
| 7181 } | 7172 } |
| 7182 } | 7173 } |
| 7183 | 7174 |
| 7184 /** | 7175 /** |
| 7185 * Attempts to make a better guess for the static type of the given binary exp
ression. | 7176 * Attempts to make a better guess for the static type of the given binary exp
ression. |
| 7186 * @param node the binary expression to analyze | 7177 * @param node the binary expression to analyze |
| 7187 * @param staticType the static type of the expression as resolved | 7178 * @param staticType the static type of the expression as resolved |
| 7188 * @return the better type guess, or the same static type as given | 7179 * @return the better type guess, or the same static type as given |
| 7189 */ | 7180 */ |
| 7190 Type2 refineBinaryExpressionType(BinaryExpression node, Type2 staticType) { | 7181 Type2 refineBinaryExpressionType(BinaryExpression node, Type2 staticType) { |
| 7191 sc.TokenType operator2 = node.operator.type; | 7182 sc.TokenType operator2 = node.operator.type; |
| 7192 if (identical(operator2, sc.TokenType.AMPERSAND_AMPERSAND) || identical(oper
ator2, sc.TokenType.BAR_BAR) || identical(operator2, sc.TokenType.EQ_EQ) || iden
tical(operator2, sc.TokenType.BANG_EQ)) { | 7183 if (identical(operator2, sc.TokenType.AMPERSAND_AMPERSAND) || identical(oper
ator2, sc.TokenType.BAR_BAR) || identical(operator2, sc.TokenType.EQ_EQ) || iden
tical(operator2, sc.TokenType.BANG_EQ)) { |
| 7193 return _typeProvider.boolType; | 7184 return _typeProvider.boolType; |
| 7194 } | 7185 } |
| 7195 if (identical(operator2, sc.TokenType.MINUS) || identical(operator2, sc.Toke
nType.PERCENT) || identical(operator2, sc.TokenType.PLUS) || identical(operator2
, sc.TokenType.STAR)) { | 7186 if (identical(operator2, sc.TokenType.MINUS) || identical(operator2, sc.Toke
nType.PERCENT) || identical(operator2, sc.TokenType.PLUS) || identical(operator2
, sc.TokenType.STAR)) { |
| 7196 Type2 doubleType2 = _typeProvider.doubleType; | 7187 Type2 doubleType2 = _typeProvider.doubleType; |
| 7197 if (identical(getStaticType(node.leftOperand), doubleType2) || identical(g
etStaticType(node.rightOperand), doubleType2)) { | 7188 if (identical(getStaticType(node.leftOperand), doubleType2) || identical(g
etStaticType(node.rightOperand), doubleType2)) { |
| 7198 return doubleType2; | 7189 return doubleType2; |
| 7199 } | 7190 } |
| 7200 } | 7191 } |
| 7201 if (identical(operator2, sc.TokenType.MINUS) || identical(operator2, sc.Toke
nType.PERCENT) || identical(operator2, sc.TokenType.PLUS) || identical(operator2
, sc.TokenType.STAR) || identical(operator2, sc.TokenType.TILDE_SLASH)) { | 7192 if (identical(operator2, sc.TokenType.MINUS) || identical(operator2, sc.Toke
nType.PERCENT) || identical(operator2, sc.TokenType.PLUS) || identical(operator2
, sc.TokenType.STAR) || identical(operator2, sc.TokenType.TILDE_SLASH)) { |
| 7202 Type2 intType2 = _typeProvider.intType; | 7193 Type2 intType2 = _typeProvider.intType; |
| 7203 if (identical(getStaticType(node.leftOperand), intType2) && identical(getS
taticType(node.rightOperand), intType2)) { | 7194 if (identical(getStaticType(node.leftOperand), intType2) && identical(getS
taticType(node.rightOperand), intType2)) { |
| 7204 staticType = intType2; | 7195 staticType = intType2; |
| 7205 } | 7196 } |
| 7206 } | 7197 } |
| 7207 return staticType; | 7198 return staticType; |
| 7208 } | 7199 } |
| 7209 | 7200 |
| 7210 /** | 7201 /** |
| 7211 * Set the return type and parameter type information for the given function t
ype based on the | 7202 * Set the return type and parameter type information for the given function t
ype based on the |
| 7212 * given return type and parameter elements. | 7203 * given return type and parameter elements. |
| 7213 * @param functionType the function type to be filled in | 7204 * @param functionType the function type to be filled in |
| 7214 * @param returnType the return type of the function, or {@code null} if no ty
pe was declared | 7205 * @param returnType the return type of the function, or {@code null} if no ty
pe was declared |
| 7215 * @param parameters the elements representing the parameters to the function | 7206 * @param parameters the elements representing the parameters to the function |
| 7216 */ | 7207 */ |
| 7217 void setTypeInformation(FunctionTypeImpl functionType, Type2 returnType2, Form
alParameterList parameterList) { | 7208 void setTypeInformation(FunctionTypeImpl functionType, Type2 returnType2, Form
alParameterList parameterList) { |
| 7218 List<Type2> normalParameterTypes = new List<Type2>(); | 7209 List<Type2> normalParameterTypes = new List<Type2>(); |
| 7219 List<Type2> optionalParameterTypes = new List<Type2>(); | 7210 List<Type2> optionalParameterTypes = new List<Type2>(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 7233 } | 7224 } |
| 7234 } | 7225 } |
| 7235 functionType.normalParameterTypes = new List.from(normalParameterTypes); | 7226 functionType.normalParameterTypes = new List.from(normalParameterTypes); |
| 7236 functionType.optionalParameterTypes = new List.from(optionalParameterTypes); | 7227 functionType.optionalParameterTypes = new List.from(optionalParameterTypes); |
| 7237 functionType.namedParameterTypes = namedParameterTypes; | 7228 functionType.namedParameterTypes = namedParameterTypes; |
| 7238 functionType.returnType = returnType2; | 7229 functionType.returnType = returnType2; |
| 7239 } | 7230 } |
| 7240 get thisType_J2DAccessor => _thisType; | 7231 get thisType_J2DAccessor => _thisType; |
| 7241 set thisType_J2DAccessor(__v) => _thisType = __v; | 7232 set thisType_J2DAccessor(__v) => _thisType = __v; |
| 7242 } | 7233 } |
| 7243 | |
| 7244 /** | 7234 /** |
| 7245 * Instances of the class {@code TypeOverrideManager} manage the ability to over
ride the type of an | 7235 * Instances of the class {@code TypeOverrideManager} manage the ability to over
ride the type of an |
| 7246 * element within a given context. | 7236 * element within a given context. |
| 7247 */ | 7237 */ |
| 7248 class TypeOverrideManager { | 7238 class TypeOverrideManager { |
| 7249 | 7239 |
| 7250 /** | 7240 /** |
| 7251 * The current override scope, or {@code null} if no scope has been entered. | 7241 * The current override scope, or {@code null} if no scope has been entered. |
| 7252 */ | 7242 */ |
| 7253 TypeOverrideManager_TypeOverrideScope _currentScope; | 7243 TypeOverrideManager_TypeOverrideScope _currentScope; |
| 7254 | 7244 |
| 7255 /** | 7245 /** |
| 7256 * Apply a set of overrides that were previously captured. | 7246 * Apply a set of overrides that were previously captured. |
| 7257 * @param overrides the overrides to be applied | 7247 * @param overrides the overrides to be applied |
| 7258 */ | 7248 */ |
| 7259 void applyOverrides(Map<Element, Type2> overrides) { | 7249 void applyOverrides(Map<Element, Type2> overrides) { |
| 7260 if (_currentScope == null) { | 7250 if (_currentScope == null) { |
| 7261 throw new IllegalStateException("Cannot apply overrides without a scope"); | 7251 throw new IllegalStateException("Cannot apply overrides without a scope"); |
| 7262 } | 7252 } |
| 7263 _currentScope.applyOverrides(overrides); | 7253 _currentScope.applyOverrides(overrides); |
| 7264 } | 7254 } |
| 7265 | 7255 |
| 7266 /** | 7256 /** |
| 7267 * Return a table mapping the elements whose type is overridden in the current
scope to the | 7257 * Return a table mapping the elements whose type is overridden in the current
scope to the |
| 7268 * overriding type. | 7258 * overriding type. |
| 7269 * @return the overrides in the current scope | 7259 * @return the overrides in the current scope |
| 7270 */ | 7260 */ |
| 7271 Map<Element, Type2> captureLocalOverrides() { | 7261 Map<Element, Type2> captureLocalOverrides() { |
| 7272 if (_currentScope == null) { | 7262 if (_currentScope == null) { |
| 7273 throw new IllegalStateException("Cannot capture local overrides without a
scope"); | 7263 throw new IllegalStateException("Cannot capture local overrides without a
scope"); |
| 7274 } | 7264 } |
| 7275 return _currentScope.captureLocalOverrides(); | 7265 return _currentScope.captureLocalOverrides(); |
| 7276 } | 7266 } |
| 7277 | 7267 |
| 7278 /** | 7268 /** |
| 7279 * Return a map from the elements for the variables in the given list that hav
e their types | 7269 * Return a map from the elements for the variables in the given list that hav
e their types |
| 7280 * overridden to the overriding type. | 7270 * overridden to the overriding type. |
| 7281 * @param variableList the list of variables whose overriding types are to be
captured | 7271 * @param variableList the list of variables whose overriding types are to be
captured |
| 7282 * @return a table mapping elements to their overriding types | 7272 * @return a table mapping elements to their overriding types |
| 7283 */ | 7273 */ |
| 7284 Map<Element, Type2> captureOverrides(VariableDeclarationList variableList) { | 7274 Map<Element, Type2> captureOverrides(VariableDeclarationList variableList) { |
| 7285 if (_currentScope == null) { | 7275 if (_currentScope == null) { |
| 7286 throw new IllegalStateException("Cannot capture overrides without a scope"
); | 7276 throw new IllegalStateException("Cannot capture overrides without a scope"
); |
| 7287 } | 7277 } |
| 7288 return _currentScope.captureOverrides(variableList); | 7278 return _currentScope.captureOverrides(variableList); |
| 7289 } | 7279 } |
| 7290 | 7280 |
| 7291 /** | 7281 /** |
| 7292 * Enter a new override scope. | 7282 * Enter a new override scope. |
| 7293 */ | 7283 */ |
| 7294 void enterScope() { | 7284 void enterScope() { |
| 7295 _currentScope = new TypeOverrideManager_TypeOverrideScope(_currentScope); | 7285 _currentScope = new TypeOverrideManager_TypeOverrideScope(_currentScope); |
| 7296 } | 7286 } |
| 7297 | 7287 |
| 7298 /** | 7288 /** |
| 7299 * Exit the current override scope. | 7289 * Exit the current override scope. |
| 7300 */ | 7290 */ |
| 7301 void exitScope() { | 7291 void exitScope() { |
| 7302 if (_currentScope == null) { | 7292 if (_currentScope == null) { |
| 7303 throw new IllegalStateException("No scope to exit"); | 7293 throw new IllegalStateException("No scope to exit"); |
| 7304 } | 7294 } |
| 7305 _currentScope = _currentScope._outerScope; | 7295 _currentScope = _currentScope._outerScope; |
| 7306 } | 7296 } |
| 7307 | 7297 |
| 7308 /** | 7298 /** |
| 7309 * Return the overridden type of the given element, or {@code null} if the typ
e of the element has | 7299 * Return the overridden type of the given element, or {@code null} if the typ
e of the element has |
| 7310 * not been overridden. | 7300 * not been overridden. |
| 7311 * @param element the element whose type might have been overridden | 7301 * @param element the element whose type might have been overridden |
| 7312 * @return the overridden type of the given element | 7302 * @return the overridden type of the given element |
| 7313 */ | 7303 */ |
| 7314 Type2 getType(Element element) { | 7304 Type2 getType(Element element) { |
| 7315 if (_currentScope == null) { | 7305 if (_currentScope == null) { |
| 7316 return null; | 7306 return null; |
| 7317 } | 7307 } |
| 7318 return _currentScope.getType(element); | 7308 return _currentScope.getType(element); |
| 7319 } | 7309 } |
| 7320 | 7310 |
| 7321 /** | 7311 /** |
| 7322 * Set the overridden type of the given element to the given type | 7312 * Set the overridden type of the given element to the given type |
| 7323 * @param element the element whose type might have been overridden | 7313 * @param element the element whose type might have been overridden |
| 7324 * @param type the overridden type of the given element | 7314 * @param type the overridden type of the given element |
| 7325 */ | 7315 */ |
| 7326 void setType(Element element, Type2 type) { | 7316 void setType(Element element, Type2 type) { |
| 7327 if (_currentScope == null) { | 7317 if (_currentScope == null) { |
| 7328 throw new IllegalStateException("Cannot override without a scope"); | 7318 throw new IllegalStateException("Cannot override without a scope"); |
| 7329 } | 7319 } |
| 7330 _currentScope.setType(element, type); | 7320 _currentScope.setType(element, type); |
| 7331 } | 7321 } |
| 7332 } | 7322 } |
| 7333 | |
| 7334 /** | 7323 /** |
| 7335 * Instances of the class {@code TypeOverrideScope} represent a scope in which t
he types of | 7324 * Instances of the class {@code TypeOverrideScope} represent a scope in which t
he types of |
| 7336 * elements can be overridden. | 7325 * elements can be overridden. |
| 7337 */ | 7326 */ |
| 7338 class TypeOverrideManager_TypeOverrideScope { | 7327 class TypeOverrideManager_TypeOverrideScope { |
| 7339 | 7328 |
| 7340 /** | 7329 /** |
| 7341 * The outer scope in which types might be overridden. | 7330 * The outer scope in which types might be overridden. |
| 7342 */ | 7331 */ |
| 7343 TypeOverrideManager_TypeOverrideScope _outerScope; | 7332 TypeOverrideManager_TypeOverrideScope _outerScope; |
| 7344 | 7333 |
| 7345 /** | 7334 /** |
| 7346 * A table mapping elements to the overridden type of that element. | 7335 * A table mapping elements to the overridden type of that element. |
| 7347 */ | 7336 */ |
| 7348 Map<Element, Type2> _overridenTypes = new Map<Element, Type2>(); | 7337 Map<Element, Type2> _overridenTypes = new Map<Element, Type2>(); |
| 7349 | 7338 |
| 7350 /** | 7339 /** |
| 7351 * Initialize a newly created scope to be an empty child of the given scope. | 7340 * Initialize a newly created scope to be an empty child of the given scope. |
| 7352 * @param outerScope the outer scope in which types might be overridden | 7341 * @param outerScope the outer scope in which types might be overridden |
| 7353 */ | 7342 */ |
| 7354 TypeOverrideManager_TypeOverrideScope(TypeOverrideManager_TypeOverrideScope ou
terScope) { | 7343 TypeOverrideManager_TypeOverrideScope(TypeOverrideManager_TypeOverrideScope ou
terScope) { |
| 7355 this._outerScope = outerScope; | 7344 this._outerScope = outerScope; |
| 7356 } | 7345 } |
| 7357 | 7346 |
| 7358 /** | 7347 /** |
| 7359 * Apply a set of overrides that were previously captured. | 7348 * Apply a set of overrides that were previously captured. |
| 7360 * @param overrides the overrides to be applied | 7349 * @param overrides the overrides to be applied |
| 7361 */ | 7350 */ |
| 7362 void applyOverrides(Map<Element, Type2> overrides) { | 7351 void applyOverrides(Map<Element, Type2> overrides) { |
| 7363 for (MapEntry<Element, Type2> entry in getMapEntrySet(overrides)) { | 7352 for (MapEntry<Element, Type2> entry in getMapEntrySet(overrides)) { |
| 7364 _overridenTypes[entry.getKey()] = entry.getValue(); | 7353 _overridenTypes[entry.getKey()] = entry.getValue(); |
| 7365 } | 7354 } |
| 7366 } | 7355 } |
| 7367 | 7356 |
| 7368 /** | 7357 /** |
| 7369 * Return a table mapping the elements whose type is overridden in the current
scope to the | 7358 * Return a table mapping the elements whose type is overridden in the current
scope to the |
| 7370 * overriding type. | 7359 * overriding type. |
| 7371 * @return the overrides in the current scope | 7360 * @return the overrides in the current scope |
| 7372 */ | 7361 */ |
| 7373 Map<Element, Type2> captureLocalOverrides() => _overridenTypes; | 7362 Map<Element, Type2> captureLocalOverrides() => _overridenTypes; |
| 7374 | 7363 |
| 7375 /** | 7364 /** |
| 7376 * Return a map from the elements for the variables in the given list that hav
e their types | 7365 * Return a map from the elements for the variables in the given list that hav
e their types |
| 7377 * overridden to the overriding type. | 7366 * overridden to the overriding type. |
| 7378 * @param variableList the list of variables whose overriding types are to be
captured | 7367 * @param variableList the list of variables whose overriding types are to be
captured |
| 7379 * @return a table mapping elements to their overriding types | 7368 * @return a table mapping elements to their overriding types |
| 7380 */ | 7369 */ |
| 7381 Map<Element, Type2> captureOverrides(VariableDeclarationList variableList) { | 7370 Map<Element, Type2> captureOverrides(VariableDeclarationList variableList) { |
| 7382 Map<Element, Type2> overrides = new Map<Element, Type2>(); | 7371 Map<Element, Type2> overrides = new Map<Element, Type2>(); |
| 7383 if (variableList.isConst() || variableList.isFinal()) { | 7372 if (variableList.isConst() || variableList.isFinal()) { |
| 7384 for (VariableDeclaration variable in variableList.variables) { | 7373 for (VariableDeclaration variable in variableList.variables) { |
| 7385 Element element2 = variable.element; | 7374 Element element2 = variable.element; |
| 7386 if (element2 != null) { | 7375 if (element2 != null) { |
| 7387 Type2 type = _overridenTypes[element2]; | 7376 Type2 type = _overridenTypes[element2]; |
| 7388 if (type != null) { | 7377 if (type != null) { |
| 7389 overrides[element2] = type; | 7378 overrides[element2] = type; |
| 7390 } | 7379 } |
| 7391 } | 7380 } |
| 7392 } | 7381 } |
| 7393 } | 7382 } |
| 7394 return overrides; | 7383 return overrides; |
| 7395 } | 7384 } |
| 7396 | 7385 |
| 7397 /** | 7386 /** |
| 7398 * Return the overridden type of the given element, or {@code null} if the typ
e of the element | 7387 * Return the overridden type of the given element, or {@code null} if the typ
e of the element |
| 7399 * has not been overridden. | 7388 * has not been overridden. |
| 7400 * @param element the element whose type might have been overridden | 7389 * @param element the element whose type might have been overridden |
| 7401 * @return the overridden type of the given element | 7390 * @return the overridden type of the given element |
| 7402 */ | 7391 */ |
| 7403 Type2 getType(Element element) { | 7392 Type2 getType(Element element) { |
| 7404 Type2 type = _overridenTypes[element]; | 7393 Type2 type = _overridenTypes[element]; |
| 7405 if (type == null && element is PropertyAccessorElement) { | 7394 if (type == null && element is PropertyAccessorElement) { |
| 7406 type = _overridenTypes[((element as PropertyAccessorElement)).variable]; | 7395 type = _overridenTypes[((element as PropertyAccessorElement)).variable]; |
| 7407 } | 7396 } |
| 7408 if (type != null) { | 7397 if (type != null) { |
| 7409 return type; | 7398 return type; |
| 7410 } else if (_outerScope != null) { | 7399 } else if (_outerScope != null) { |
| 7411 return _outerScope.getType(element); | 7400 return _outerScope.getType(element); |
| 7412 } | 7401 } |
| 7413 return null; | 7402 return null; |
| 7414 } | 7403 } |
| 7415 | 7404 |
| 7416 /** | 7405 /** |
| 7417 * Set the overridden type of the given element to the given type | 7406 * Set the overridden type of the given element to the given type |
| 7418 * @param element the element whose type might have been overridden | 7407 * @param element the element whose type might have been overridden |
| 7419 * @param type the overridden type of the given element | 7408 * @param type the overridden type of the given element |
| 7420 */ | 7409 */ |
| 7421 void setType(Element element, Type2 type) { | 7410 void setType(Element element, Type2 type) { |
| 7422 _overridenTypes[element] = type; | 7411 _overridenTypes[element] = type; |
| 7423 } | 7412 } |
| 7424 } | 7413 } |
| 7425 | |
| 7426 /** | 7414 /** |
| 7427 * The interface {@code TypeProvider} defines the behavior of objects that provi
de access to types | 7415 * The interface {@code TypeProvider} defines the behavior of objects that provi
de access to types |
| 7428 * defined by the language. | 7416 * defined by the language. |
| 7429 * @coverage dart.engine.resolver | 7417 * @coverage dart.engine.resolver |
| 7430 */ | 7418 */ |
| 7431 abstract class TypeProvider { | 7419 abstract class TypeProvider { |
| 7432 | 7420 |
| 7433 /** | 7421 /** |
| 7434 * Return the type representing the built-in type 'bool'. | 7422 * Return the type representing the built-in type 'bool'. |
| 7435 * @return the type representing the built-in type 'bool' | 7423 * @return the type representing the built-in type 'bool' |
| 7436 */ | 7424 */ |
| 7437 InterfaceType get boolType; | 7425 InterfaceType get boolType; |
| 7438 | 7426 |
| 7439 /** | 7427 /** |
| 7440 * Return the type representing the type 'bottom'. | 7428 * Return the type representing the type 'bottom'. |
| 7441 * @return the type representing the type 'bottom' | 7429 * @return the type representing the type 'bottom' |
| 7442 */ | 7430 */ |
| 7443 Type2 get bottomType; | 7431 Type2 get bottomType; |
| 7444 | 7432 |
| 7445 /** | 7433 /** |
| 7446 * Return the type representing the built-in type 'double'. | 7434 * Return the type representing the built-in type 'double'. |
| 7447 * @return the type representing the built-in type 'double' | 7435 * @return the type representing the built-in type 'double' |
| 7448 */ | 7436 */ |
| 7449 InterfaceType get doubleType; | 7437 InterfaceType get doubleType; |
| 7450 | 7438 |
| 7451 /** | 7439 /** |
| 7452 * Return the type representing the built-in type 'dynamic'. | 7440 * Return the type representing the built-in type 'dynamic'. |
| 7453 * @return the type representing the built-in type 'dynamic' | 7441 * @return the type representing the built-in type 'dynamic' |
| 7454 */ | 7442 */ |
| 7455 Type2 get dynamicType; | 7443 Type2 get dynamicType; |
| 7456 | 7444 |
| 7457 /** | 7445 /** |
| 7458 * Return the type representing the built-in type 'Function'. | 7446 * Return the type representing the built-in type 'Function'. |
| 7459 * @return the type representing the built-in type 'Function' | 7447 * @return the type representing the built-in type 'Function' |
| 7460 */ | 7448 */ |
| 7461 InterfaceType get functionType; | 7449 InterfaceType get functionType; |
| 7462 | 7450 |
| 7463 /** | 7451 /** |
| 7464 * Return the type representing the built-in type 'int'. | 7452 * Return the type representing the built-in type 'int'. |
| 7465 * @return the type representing the built-in type 'int' | 7453 * @return the type representing the built-in type 'int' |
| 7466 */ | 7454 */ |
| 7467 InterfaceType get intType; | 7455 InterfaceType get intType; |
| 7468 | 7456 |
| 7469 /** | 7457 /** |
| 7470 * Return the type representing the built-in type 'List'. | 7458 * Return the type representing the built-in type 'List'. |
| 7471 * @return the type representing the built-in type 'List' | 7459 * @return the type representing the built-in type 'List' |
| 7472 */ | 7460 */ |
| 7473 InterfaceType get listType; | 7461 InterfaceType get listType; |
| 7474 | 7462 |
| 7475 /** | 7463 /** |
| 7476 * Return the type representing the built-in type 'Map'. | 7464 * Return the type representing the built-in type 'Map'. |
| 7477 * @return the type representing the built-in type 'Map' | 7465 * @return the type representing the built-in type 'Map' |
| 7478 */ | 7466 */ |
| 7479 InterfaceType get mapType; | 7467 InterfaceType get mapType; |
| 7480 | 7468 |
| 7481 /** | 7469 /** |
| 7482 * Return the type representing the built-in type 'num'. | 7470 * Return the type representing the built-in type 'num'. |
| 7483 * @return the type representing the built-in type 'num' | 7471 * @return the type representing the built-in type 'num' |
| 7484 */ | 7472 */ |
| 7485 InterfaceType get numType; | 7473 InterfaceType get numType; |
| 7486 | 7474 |
| 7487 /** | 7475 /** |
| 7488 * Return the type representing the built-in type 'Object'. | 7476 * Return the type representing the built-in type 'Object'. |
| 7489 * @return the type representing the built-in type 'Object' | 7477 * @return the type representing the built-in type 'Object' |
| 7490 */ | 7478 */ |
| 7491 InterfaceType get objectType; | 7479 InterfaceType get objectType; |
| 7492 | 7480 |
| 7493 /** | 7481 /** |
| 7494 * Return the type representing the built-in type 'StackTrace'. | 7482 * Return the type representing the built-in type 'StackTrace'. |
| 7495 * @return the type representing the built-in type 'StackTrace' | 7483 * @return the type representing the built-in type 'StackTrace' |
| 7496 */ | 7484 */ |
| 7497 InterfaceType get stackTraceType; | 7485 InterfaceType get stackTraceType; |
| 7498 | 7486 |
| 7499 /** | 7487 /** |
| 7500 * Return the type representing the built-in type 'String'. | 7488 * Return the type representing the built-in type 'String'. |
| 7501 * @return the type representing the built-in type 'String' | 7489 * @return the type representing the built-in type 'String' |
| 7502 */ | 7490 */ |
| 7503 InterfaceType get stringType; | 7491 InterfaceType get stringType; |
| 7504 | 7492 |
| 7505 /** | 7493 /** |
| 7506 * Return the type representing the built-in type 'Type'. | 7494 * Return the type representing the built-in type 'Type'. |
| 7507 * @return the type representing the built-in type 'Type' | 7495 * @return the type representing the built-in type 'Type' |
| 7508 */ | 7496 */ |
| 7509 InterfaceType get typeType; | 7497 InterfaceType get typeType; |
| 7510 } | 7498 } |
| 7511 | |
| 7512 /** | 7499 /** |
| 7513 * Instances of the class {@code TypeProviderImpl} provide access to types defin
ed by the language | 7500 * Instances of the class {@code TypeProviderImpl} provide access to types defin
ed by the language |
| 7514 * by looking for those types in the element model for the core library. | 7501 * by looking for those types in the element model for the core library. |
| 7515 * @coverage dart.engine.resolver | 7502 * @coverage dart.engine.resolver |
| 7516 */ | 7503 */ |
| 7517 class TypeProviderImpl implements TypeProvider { | 7504 class TypeProviderImpl implements TypeProvider { |
| 7518 | 7505 |
| 7519 /** | 7506 /** |
| 7520 * The type representing the built-in type 'bool'. | 7507 * The type representing the built-in type 'bool'. |
| 7521 */ | 7508 */ |
| 7522 InterfaceType _boolType; | 7509 InterfaceType _boolType; |
| 7523 | 7510 |
| 7524 /** | 7511 /** |
| 7525 * The type representing the type 'bottom'. | 7512 * The type representing the type 'bottom'. |
| 7526 */ | 7513 */ |
| 7527 Type2 _bottomType; | 7514 Type2 _bottomType; |
| 7528 | 7515 |
| 7529 /** | 7516 /** |
| 7530 * The type representing the built-in type 'double'. | 7517 * The type representing the built-in type 'double'. |
| 7531 */ | 7518 */ |
| 7532 InterfaceType _doubleType; | 7519 InterfaceType _doubleType; |
| 7533 | 7520 |
| 7534 /** | 7521 /** |
| 7535 * The type representing the built-in type 'dynamic'. | 7522 * The type representing the built-in type 'dynamic'. |
| 7536 */ | 7523 */ |
| 7537 Type2 _dynamicType; | 7524 Type2 _dynamicType; |
| 7538 | 7525 |
| 7539 /** | 7526 /** |
| 7540 * The type representing the built-in type 'Function'. | 7527 * The type representing the built-in type 'Function'. |
| 7541 */ | 7528 */ |
| 7542 InterfaceType _functionType; | 7529 InterfaceType _functionType; |
| 7543 | 7530 |
| 7544 /** | 7531 /** |
| 7545 * The type representing the built-in type 'int'. | 7532 * The type representing the built-in type 'int'. |
| 7546 */ | 7533 */ |
| 7547 InterfaceType _intType; | 7534 InterfaceType _intType; |
| 7548 | 7535 |
| 7549 /** | 7536 /** |
| 7550 * The type representing the built-in type 'List'. | 7537 * The type representing the built-in type 'List'. |
| 7551 */ | 7538 */ |
| 7552 InterfaceType _listType; | 7539 InterfaceType _listType; |
| 7553 | 7540 |
| 7554 /** | 7541 /** |
| 7555 * The type representing the built-in type 'Map'. | 7542 * The type representing the built-in type 'Map'. |
| 7556 */ | 7543 */ |
| 7557 InterfaceType _mapType; | 7544 InterfaceType _mapType; |
| 7558 | 7545 |
| 7559 /** | 7546 /** |
| 7560 * The type representing the built-in type 'num'. | 7547 * The type representing the built-in type 'num'. |
| 7561 */ | 7548 */ |
| 7562 InterfaceType _numType; | 7549 InterfaceType _numType; |
| 7563 | 7550 |
| 7564 /** | 7551 /** |
| 7565 * The type representing the built-in type 'Object'. | 7552 * The type representing the built-in type 'Object'. |
| 7566 */ | 7553 */ |
| 7567 InterfaceType _objectType; | 7554 InterfaceType _objectType; |
| 7568 | 7555 |
| 7569 /** | 7556 /** |
| 7570 * The type representing the built-in type 'StackTrace'. | 7557 * The type representing the built-in type 'StackTrace'. |
| 7571 */ | 7558 */ |
| 7572 InterfaceType _stackTraceType; | 7559 InterfaceType _stackTraceType; |
| 7573 | 7560 |
| 7574 /** | 7561 /** |
| 7575 * The type representing the built-in type 'String'. | 7562 * The type representing the built-in type 'String'. |
| 7576 */ | 7563 */ |
| 7577 InterfaceType _stringType; | 7564 InterfaceType _stringType; |
| 7578 | 7565 |
| 7579 /** | 7566 /** |
| 7580 * The type representing the built-in type 'Type'. | 7567 * The type representing the built-in type 'Type'. |
| 7581 */ | 7568 */ |
| 7582 InterfaceType _typeType; | 7569 InterfaceType _typeType; |
| 7583 | 7570 |
| 7584 /** | 7571 /** |
| 7585 * Initialize a newly created type provider to provide the types defined in th
e given library. | 7572 * Initialize a newly created type provider to provide the types defined in th
e given library. |
| 7586 * @param coreLibrary the element representing the core library (dart:core). | 7573 * @param coreLibrary the element representing the core library (dart:core). |
| 7587 */ | 7574 */ |
| 7588 TypeProviderImpl(LibraryElement coreLibrary) { | 7575 TypeProviderImpl(LibraryElement coreLibrary) { |
| 7589 initializeFrom(coreLibrary); | 7576 initializeFrom(coreLibrary); |
| 7590 } | 7577 } |
| 7591 InterfaceType get boolType => _boolType; | 7578 InterfaceType get boolType => _boolType; |
| 7592 Type2 get bottomType => _bottomType; | 7579 Type2 get bottomType => _bottomType; |
| 7593 InterfaceType get doubleType => _doubleType; | 7580 InterfaceType get doubleType => _doubleType; |
| 7594 Type2 get dynamicType => _dynamicType; | 7581 Type2 get dynamicType => _dynamicType; |
| 7595 InterfaceType get functionType => _functionType; | 7582 InterfaceType get functionType => _functionType; |
| 7596 InterfaceType get intType => _intType; | 7583 InterfaceType get intType => _intType; |
| 7597 InterfaceType get listType => _listType; | 7584 InterfaceType get listType => _listType; |
| 7598 InterfaceType get mapType => _mapType; | 7585 InterfaceType get mapType => _mapType; |
| 7599 InterfaceType get numType => _numType; | 7586 InterfaceType get numType => _numType; |
| 7600 InterfaceType get objectType => _objectType; | 7587 InterfaceType get objectType => _objectType; |
| 7601 InterfaceType get stackTraceType => _stackTraceType; | 7588 InterfaceType get stackTraceType => _stackTraceType; |
| 7602 InterfaceType get stringType => _stringType; | 7589 InterfaceType get stringType => _stringType; |
| 7603 InterfaceType get typeType => _typeType; | 7590 InterfaceType get typeType => _typeType; |
| 7604 | 7591 |
| 7605 /** | 7592 /** |
| 7606 * Return the type with the given name from the given namespace, or {@code nul
l} if there is no | 7593 * Return the type with the given name from the given namespace, or {@code nul
l} if there is no |
| 7607 * class with the given name. | 7594 * class with the given name. |
| 7608 * @param namespace the namespace in which to search for the given name | 7595 * @param namespace the namespace in which to search for the given name |
| 7609 * @param typeName the name of the type being searched for | 7596 * @param typeName the name of the type being searched for |
| 7610 * @return the type that was found | 7597 * @return the type that was found |
| 7611 */ | 7598 */ |
| 7612 InterfaceType getType(Namespace namespace, String typeName) { | 7599 InterfaceType getType(Namespace namespace, String typeName) { |
| 7613 Element element = namespace.get(typeName); | 7600 Element element = namespace.get(typeName); |
| 7614 if (element == null) { | 7601 if (element == null) { |
| 7615 AnalysisEngine.instance.logger.logInformation("No definition of type ${typ
eName}"); | 7602 AnalysisEngine.instance.logger.logInformation("No definition of type ${typ
eName}"); |
| 7616 return null; | 7603 return null; |
| 7617 } | 7604 } |
| 7618 return ((element as ClassElement)).type; | 7605 return ((element as ClassElement)).type; |
| 7619 } | 7606 } |
| 7620 | 7607 |
| 7621 /** | 7608 /** |
| 7622 * Initialize the types provided by this type provider from the given library. | 7609 * Initialize the types provided by this type provider from the given library. |
| 7623 * @param library the library containing the definitions of the core types | 7610 * @param library the library containing the definitions of the core types |
| 7624 */ | 7611 */ |
| 7625 void initializeFrom(LibraryElement library) { | 7612 void initializeFrom(LibraryElement library) { |
| 7626 Namespace namespace = new NamespaceBuilder().createPublicNamespace(library); | 7613 Namespace namespace = new NamespaceBuilder().createPublicNamespace(library); |
| 7627 _boolType = getType(namespace, "bool"); | 7614 _boolType = getType(namespace, "bool"); |
| 7628 _bottomType = BottomTypeImpl.instance; | 7615 _bottomType = BottomTypeImpl.instance; |
| 7629 _doubleType = getType(namespace, "double"); | 7616 _doubleType = getType(namespace, "double"); |
| 7630 _dynamicType = DynamicTypeImpl.instance; | 7617 _dynamicType = DynamicTypeImpl.instance; |
| 7631 _functionType = getType(namespace, "Function"); | 7618 _functionType = getType(namespace, "Function"); |
| 7632 _intType = getType(namespace, "int"); | 7619 _intType = getType(namespace, "int"); |
| 7633 _listType = getType(namespace, "List"); | 7620 _listType = getType(namespace, "List"); |
| 7634 _mapType = getType(namespace, "Map"); | 7621 _mapType = getType(namespace, "Map"); |
| 7635 _numType = getType(namespace, "num"); | 7622 _numType = getType(namespace, "num"); |
| 7636 _objectType = getType(namespace, "Object"); | 7623 _objectType = getType(namespace, "Object"); |
| 7637 _stackTraceType = getType(namespace, "StackTrace"); | 7624 _stackTraceType = getType(namespace, "StackTrace"); |
| 7638 _stringType = getType(namespace, "String"); | 7625 _stringType = getType(namespace, "String"); |
| 7639 _typeType = getType(namespace, "Type"); | 7626 _typeType = getType(namespace, "Type"); |
| 7640 } | 7627 } |
| 7641 } | 7628 } |
| 7642 | |
| 7643 /** | 7629 /** |
| 7644 * Instances of the class {@code TypeResolverVisitor} are used to resolve the ty
pes associated with | 7630 * Instances of the class {@code TypeResolverVisitor} are used to resolve the ty
pes associated with |
| 7645 * the elements in the element model. This includes the types of superclasses, m
ixins, interfaces, | 7631 * the elements in the element model. This includes the types of superclasses, m
ixins, interfaces, |
| 7646 * fields, methods, parameters, and local variables. As a side-effect, this also
finishes building | 7632 * fields, methods, parameters, and local variables. As a side-effect, this also
finishes building |
| 7647 * the type hierarchy. | 7633 * the type hierarchy. |
| 7648 * @coverage dart.engine.resolver | 7634 * @coverage dart.engine.resolver |
| 7649 */ | 7635 */ |
| 7650 class TypeResolverVisitor extends ScopedVisitor { | 7636 class TypeResolverVisitor extends ScopedVisitor { |
| 7651 | 7637 |
| 7652 /** | 7638 /** |
| 7653 * The type representing the type 'dynamic'. | 7639 * The type representing the type 'dynamic'. |
| 7654 */ | 7640 */ |
| 7655 Type2 _dynamicType; | 7641 Type2 _dynamicType; |
| 7656 | 7642 |
| 7657 /** | 7643 /** |
| 7658 * The flag specifying if currently visited class references 'super' expressio
n. | 7644 * The flag specifying if currently visited class references 'super' expressio
n. |
| 7659 */ | 7645 */ |
| 7660 bool _hasReferenceToSuper = false; | 7646 bool _hasReferenceToSuper = false; |
| 7661 | 7647 |
| 7662 /** | 7648 /** |
| 7663 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 7649 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 7664 * @param library the library containing the compilation unit being resolved | 7650 * @param library the library containing the compilation unit being resolved |
| 7665 * @param source the source representing the compilation unit being visited | 7651 * @param source the source representing the compilation unit being visited |
| 7666 * @param typeProvider the object used to access the types from the core libra
ry | 7652 * @param typeProvider the object used to access the types from the core libra
ry |
| 7667 */ | 7653 */ |
| 7668 TypeResolverVisitor.con1(Library library, Source source, TypeProvider typeProv
ider) : super.con1(library, source, typeProvider) { | 7654 TypeResolverVisitor.con1(Library library, Source source, TypeProvider typeProv
ider) : super.con1(library, source, typeProvider) { |
| 7669 _jtd_constructor_280_impl(library, source, typeProvider); | 7655 _jtd_constructor_281_impl(library, source, typeProvider); |
| 7670 } | 7656 } |
| 7671 _jtd_constructor_280_impl(Library library, Source source, TypeProvider typePro
vider) { | 7657 _jtd_constructor_281_impl(Library library, Source source, TypeProvider typePro
vider) { |
| 7672 _dynamicType = typeProvider.dynamicType; | 7658 _dynamicType = typeProvider.dynamicType; |
| 7673 } | 7659 } |
| 7674 | 7660 |
| 7675 /** | 7661 /** |
| 7676 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 7662 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 7677 * @param definingLibrary the element for the library containing the compilati
on unit being | 7663 * @param definingLibrary the element for the library containing the compilati
on unit being |
| 7678 * visited | 7664 * visited |
| 7679 * @param source the source representing the compilation unit being visited | 7665 * @param source the source representing the compilation unit being visited |
| 7680 * @param typeProvider the object used to access the types from the core libra
ry | 7666 * @param typeProvider the object used to access the types from the core libra
ry |
| 7681 * @param errorListener the error listener that will be informed of any errors
that are found | 7667 * @param errorListener the error listener that will be informed of any errors
that are found |
| 7682 * during resolution | 7668 * during resolution |
| 7683 */ | 7669 */ |
| 7684 TypeResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypePr
ovider typeProvider, AnalysisErrorListener errorListener) : super.con2(definingL
ibrary, source, typeProvider, errorListener) { | 7670 TypeResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypePr
ovider typeProvider, AnalysisErrorListener errorListener) : super.con2(definingL
ibrary, source, typeProvider, errorListener) { |
| 7685 _jtd_constructor_281_impl(definingLibrary, source, typeProvider, errorListen
er); | 7671 _jtd_constructor_282_impl(definingLibrary, source, typeProvider, errorListen
er); |
| 7686 } | 7672 } |
| 7687 _jtd_constructor_281_impl(LibraryElement definingLibrary, Source source, TypeP
rovider typeProvider, AnalysisErrorListener errorListener) { | 7673 _jtd_constructor_282_impl(LibraryElement definingLibrary, Source source, TypeP
rovider typeProvider, AnalysisErrorListener errorListener) { |
| 7688 _dynamicType = typeProvider.dynamicType; | 7674 _dynamicType = typeProvider.dynamicType; |
| 7689 } | 7675 } |
| 7690 Object visitCatchClause(CatchClause node) { | 7676 Object visitCatchClause(CatchClause node) { |
| 7691 super.visitCatchClause(node); | 7677 super.visitCatchClause(node); |
| 7692 SimpleIdentifier exception = node.exceptionParameter; | 7678 SimpleIdentifier exception = node.exceptionParameter; |
| 7693 if (exception != null) { | 7679 if (exception != null) { |
| 7694 TypeName exceptionTypeName = node.exceptionType; | 7680 TypeName exceptionTypeName = node.exceptionType; |
| 7695 Type2 exceptionType; | 7681 Type2 exceptionType; |
| 7696 if (exceptionTypeName == null) { | 7682 if (exceptionTypeName == null) { |
| 7697 exceptionType = typeProvider.objectType; | 7683 exceptionType = typeProvider.objectType; |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8028 FunctionTypeImpl setterType = new FunctionTypeImpl.con1(setter2); | 8014 FunctionTypeImpl setterType = new FunctionTypeImpl.con1(setter2); |
| 8029 setterType.returnType = VoidTypeImpl.instance; | 8015 setterType.returnType = VoidTypeImpl.instance; |
| 8030 setterType.normalParameterTypes = <Type2> [declaredType]; | 8016 setterType.normalParameterTypes = <Type2> [declaredType]; |
| 8031 setter2.type = setterType; | 8017 setter2.type = setterType; |
| 8032 } | 8018 } |
| 8033 } | 8019 } |
| 8034 } else { | 8020 } else { |
| 8035 } | 8021 } |
| 8036 return null; | 8022 return null; |
| 8037 } | 8023 } |
| 8038 | 8024 |
| 8039 /** | 8025 /** |
| 8040 * Return the class element that represents the class whose name was provided. | 8026 * Return the class element that represents the class whose name was provided. |
| 8041 * @param identifier the name from the declaration of a class | 8027 * @param identifier the name from the declaration of a class |
| 8042 * @return the class element that represents the class | 8028 * @return the class element that represents the class |
| 8043 */ | 8029 */ |
| 8044 ClassElementImpl getClassElement(SimpleIdentifier identifier) { | 8030 ClassElementImpl getClassElement(SimpleIdentifier identifier) { |
| 8045 if (identifier == null) { | 8031 if (identifier == null) { |
| 8046 return null; | 8032 return null; |
| 8047 } | 8033 } |
| 8048 Element element2 = identifier.element; | 8034 Element element2 = identifier.element; |
| 8049 if (element2 is! ClassElementImpl) { | 8035 if (element2 is! ClassElementImpl) { |
| 8050 return null; | 8036 return null; |
| 8051 } | 8037 } |
| 8052 return element2 as ClassElementImpl; | 8038 return element2 as ClassElementImpl; |
| 8053 } | 8039 } |
| 8054 | 8040 |
| 8055 /** | 8041 /** |
| 8056 * Return an array containing all of the elements associated with the paramete
rs in the given | 8042 * Return an array containing all of the elements associated with the paramete
rs in the given |
| 8057 * list. | 8043 * list. |
| 8058 * @param parameterList the list of parameters whose elements are to be return
ed | 8044 * @param parameterList the list of parameters whose elements are to be return
ed |
| 8059 * @return the elements associated with the parameters | 8045 * @return the elements associated with the parameters |
| 8060 */ | 8046 */ |
| 8061 List<ParameterElement> getElements(FormalParameterList parameterList) { | 8047 List<ParameterElement> getElements(FormalParameterList parameterList) { |
| 8062 List<ParameterElement> elements = new List<ParameterElement>(); | 8048 List<ParameterElement> elements = new List<ParameterElement>(); |
| 8063 for (FormalParameter parameter in parameterList.parameters) { | 8049 for (FormalParameter parameter in parameterList.parameters) { |
| 8064 ParameterElement element2 = parameter.identifier.element as ParameterEleme
nt; | 8050 ParameterElement element2 = parameter.identifier.element as ParameterEleme
nt; |
| 8065 if (element2 != null) { | 8051 if (element2 != null) { |
| 8066 elements.add(element2); | 8052 elements.add(element2); |
| 8067 } | 8053 } |
| 8068 } | 8054 } |
| 8069 return new List.from(elements); | 8055 return new List.from(elements); |
| 8070 } | 8056 } |
| 8071 | 8057 |
| 8072 /** | 8058 /** |
| 8073 * The number of type arguments in the given type name does not match the numb
er of parameters in | 8059 * The number of type arguments in the given type name does not match the numb
er of parameters in |
| 8074 * the corresponding class element. Return the error code that should be used
to report this | 8060 * the corresponding class element. Return the error code that should be used
to report this |
| 8075 * error. | 8061 * error. |
| 8076 * @param node the type name with the wrong number of type arguments | 8062 * @param node the type name with the wrong number of type arguments |
| 8077 * @return the error code that should be used to report that the wrong number
of type arguments | 8063 * @return the error code that should be used to report that the wrong number
of type arguments |
| 8078 * were provided | 8064 * were provided |
| 8079 */ | 8065 */ |
| 8080 ErrorCode getInvalidTypeParametersErrorCode(TypeName node) { | 8066 ErrorCode getInvalidTypeParametersErrorCode(TypeName node) { |
| 8081 ASTNode parent2 = node.parent; | 8067 ASTNode parent2 = node.parent; |
| 8082 if (parent2 is ConstructorName) { | 8068 if (parent2 is ConstructorName) { |
| 8083 parent2 = parent2.parent; | 8069 parent2 = parent2.parent; |
| 8084 if (parent2 is InstanceCreationExpression) { | 8070 if (parent2 is InstanceCreationExpression) { |
| 8085 if (((parent2 as InstanceCreationExpression)).isConst()) { | 8071 if (((parent2 as InstanceCreationExpression)).isConst()) { |
| 8086 return CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS; | 8072 return CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS; |
| 8087 } else { | 8073 } else { |
| 8088 return CompileTimeErrorCode.NEW_WITH_INVALID_TYPE_PARAMETERS; | 8074 return CompileTimeErrorCode.NEW_WITH_INVALID_TYPE_PARAMETERS; |
| 8089 } | 8075 } |
| 8090 } | 8076 } |
| 8091 } | 8077 } |
| 8092 return StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS; | 8078 return StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS; |
| 8093 } | 8079 } |
| 8094 | 8080 |
| 8095 /** | 8081 /** |
| 8096 * Given the multiple elements to which a single name could potentially be res
olved, return the | 8082 * Given the multiple elements to which a single name could potentially be res
olved, return the |
| 8097 * single interface type that should be used, or {@code null} if there is no c
lear choice. | 8083 * single interface type that should be used, or {@code null} if there is no c
lear choice. |
| 8098 * @param elements the elements to which a single name could potentially be re
solved | 8084 * @param elements the elements to which a single name could potentially be re
solved |
| 8099 * @return the single interface type that should be used for the type name | 8085 * @return the single interface type that should be used for the type name |
| 8100 */ | 8086 */ |
| 8101 InterfaceType getType(List<Element> elements) { | 8087 InterfaceType getType(List<Element> elements) { |
| 8102 InterfaceType type = null; | 8088 InterfaceType type = null; |
| 8103 for (Element element in elements) { | 8089 for (Element element in elements) { |
| 8104 if (element is ClassElement) { | 8090 if (element is ClassElement) { |
| 8105 if (type != null) { | 8091 if (type != null) { |
| 8106 return null; | 8092 return null; |
| 8107 } | 8093 } |
| 8108 type = ((element as ClassElement)).type; | 8094 type = ((element as ClassElement)).type; |
| 8109 } | 8095 } |
| 8110 } | 8096 } |
| 8111 return type; | 8097 return type; |
| 8112 } | 8098 } |
| 8113 | 8099 |
| 8114 /** | 8100 /** |
| 8115 * Return the type represented by the given type name. | 8101 * Return the type represented by the given type name. |
| 8116 * @param typeName the type name representing the type to be returned | 8102 * @param typeName the type name representing the type to be returned |
| 8117 * @return the type represented by the type name | 8103 * @return the type represented by the type name |
| 8118 */ | 8104 */ |
| 8119 Type2 getType3(TypeName typeName) { | 8105 Type2 getType3(TypeName typeName) { |
| 8120 Type2 type2 = typeName.type; | 8106 Type2 type2 = typeName.type; |
| 8121 if (type2 == null) { | 8107 if (type2 == null) { |
| 8122 return _dynamicType; | 8108 return _dynamicType; |
| 8123 } | 8109 } |
| 8124 return type2; | 8110 return type2; |
| 8125 } | 8111 } |
| 8126 | 8112 |
| 8127 /** | 8113 /** |
| 8128 * Return the type arguments associated with the given type. | 8114 * Return the type arguments associated with the given type. |
| 8129 * @param type the type whole type arguments are to be returned | 8115 * @param type the type whole type arguments are to be returned |
| 8130 * @return the type arguments associated with the given type | 8116 * @return the type arguments associated with the given type |
| 8131 */ | 8117 */ |
| 8132 List<Type2> getTypeArguments(Type2 type) { | 8118 List<Type2> getTypeArguments(Type2 type) { |
| 8133 if (type is InterfaceType) { | 8119 if (type is InterfaceType) { |
| 8134 return ((type as InterfaceType)).typeArguments; | 8120 return ((type as InterfaceType)).typeArguments; |
| 8135 } else if (type is FunctionType) { | 8121 } else if (type is FunctionType) { |
| 8136 return ((type as FunctionType)).typeArguments; | 8122 return ((type as FunctionType)).typeArguments; |
| 8137 } | 8123 } |
| 8138 return TypeImpl.EMPTY_ARRAY; | 8124 return TypeImpl.EMPTY_ARRAY; |
| 8139 } | 8125 } |
| 8140 | 8126 |
| 8141 /** | 8127 /** |
| 8142 * Returns the simple identifier of the given (may be qualified) type name. | 8128 * Returns the simple identifier of the given (may be qualified) type name. |
| 8143 * @param typeName the (may be qualified) qualified type name | 8129 * @param typeName the (may be qualified) qualified type name |
| 8144 * @return the simple identifier of the given (may be qualified) type name. | 8130 * @return the simple identifier of the given (may be qualified) type name. |
| 8145 */ | 8131 */ |
| 8146 SimpleIdentifier getTypeSimpleIdentifier(Identifier typeName) { | 8132 SimpleIdentifier getTypeSimpleIdentifier(Identifier typeName) { |
| 8147 if (typeName is SimpleIdentifier) { | 8133 if (typeName is SimpleIdentifier) { |
| 8148 return typeName as SimpleIdentifier; | 8134 return typeName as SimpleIdentifier; |
| 8149 } else { | 8135 } else { |
| 8150 return ((typeName as PrefixedIdentifier)).identifier; | 8136 return ((typeName as PrefixedIdentifier)).identifier; |
| 8151 } | 8137 } |
| 8152 } | 8138 } |
| 8153 | 8139 |
| 8154 /** | 8140 /** |
| 8155 * Checks if the given type name is used as the exception type in the catch cl
ause. | 8141 * Checks if the given type name is used as the exception type in the catch cl
ause. |
| 8156 * @param typeName the type name to analyzer | 8142 * @param typeName the type name to analyzer |
| 8157 * @return {@code true} if the given type name is used as the exception type i
n the catch clause. | 8143 * @return {@code true} if the given type name is used as the exception type i
n the catch clause. |
| 8158 */ | 8144 */ |
| 8159 bool isTypeNameInCatchClause(TypeName typeName) { | 8145 bool isTypeNameInCatchClause(TypeName typeName) { |
| 8160 ASTNode parent2 = typeName.parent; | 8146 ASTNode parent2 = typeName.parent; |
| 8161 if (parent2 is CatchClause) { | 8147 if (parent2 is CatchClause) { |
| 8162 CatchClause catchClause = parent2 as CatchClause; | 8148 CatchClause catchClause = parent2 as CatchClause; |
| 8163 return identical(catchClause.exceptionType, typeName); | 8149 return identical(catchClause.exceptionType, typeName); |
| 8164 } | 8150 } |
| 8165 return false; | 8151 return false; |
| 8166 } | 8152 } |
| 8167 | 8153 |
| 8168 /** | 8154 /** |
| 8169 * Checks if the given type name is used as the type in the instance creation
expression. | 8155 * Checks if the given type name is used as the type in the instance creation
expression. |
| 8170 * @param typeName the type name to analyzer | 8156 * @param typeName the type name to analyzer |
| 8171 * @return {@code true} if the given type name is used as the type in the inst
ance creation | 8157 * @return {@code true} if the given type name is used as the type in the inst
ance creation |
| 8172 * expression | 8158 * expression |
| 8173 */ | 8159 */ |
| 8174 bool isTypeNameInInstanceCreationExpression(TypeName typeName) { | 8160 bool isTypeNameInInstanceCreationExpression(TypeName typeName) { |
| 8175 ASTNode parent2 = typeName.parent; | 8161 ASTNode parent2 = typeName.parent; |
| 8176 if (parent2 is ConstructorName && parent2.parent is InstanceCreationExpressi
on) { | 8162 if (parent2 is ConstructorName && parent2.parent is InstanceCreationExpressi
on) { |
| 8177 ConstructorName constructorName = parent2 as ConstructorName; | 8163 ConstructorName constructorName = parent2 as ConstructorName; |
| 8178 return constructorName != null && identical(constructorName.type, typeName
); | 8164 return constructorName != null && identical(constructorName.type, typeName
); |
| 8179 } | 8165 } |
| 8180 return false; | 8166 return false; |
| 8181 } | 8167 } |
| 8182 | 8168 |
| 8183 /** | 8169 /** |
| 8184 * Record that the static type of the given node is the given type. | 8170 * Record that the static type of the given node is the given type. |
| 8185 * @param expression the node whose type is to be recorded | 8171 * @param expression the node whose type is to be recorded |
| 8186 * @param type the static type of the node | 8172 * @param type the static type of the node |
| 8187 */ | 8173 */ |
| 8188 Object recordType(Expression expression, Type2 type) { | 8174 Object recordType(Expression expression, Type2 type) { |
| 8189 if (type == null) { | 8175 if (type == null) { |
| 8190 expression.staticType = _dynamicType; | 8176 expression.staticType = _dynamicType; |
| 8191 } else { | 8177 } else { |
| 8192 expression.staticType = type; | 8178 expression.staticType = type; |
| 8193 } | 8179 } |
| 8194 return null; | 8180 return null; |
| 8195 } | 8181 } |
| 8196 | 8182 |
| 8197 /** | 8183 /** |
| 8198 * Resolve the types in the given with and implements clauses and associate th
ose types with the | 8184 * Resolve the types in the given with and implements clauses and associate th
ose types with the |
| 8199 * given class element. | 8185 * given class element. |
| 8200 * @param classElement the class element with which the mixin and interface ty
pes are to be | 8186 * @param classElement the class element with which the mixin and interface ty
pes are to be |
| 8201 * associated | 8187 * associated |
| 8202 * @param withClause the with clause to be resolved | 8188 * @param withClause the with clause to be resolved |
| 8203 * @param implementsClause the implements clause to be resolved | 8189 * @param implementsClause the implements clause to be resolved |
| 8204 */ | 8190 */ |
| 8205 void resolve(ClassElementImpl classElement, WithClause withClause, ImplementsC
lause implementsClause) { | 8191 void resolve(ClassElementImpl classElement, WithClause withClause, ImplementsC
lause implementsClause) { |
| 8206 if (withClause != null) { | 8192 if (withClause != null) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 8236 reportError(CompileTimeErrorCode.IMPLEMENTS_REPEATED, typeName2, [
name2]); | 8222 reportError(CompileTimeErrorCode.IMPLEMENTS_REPEATED, typeName2, [
name2]); |
| 8237 } | 8223 } |
| 8238 } | 8224 } |
| 8239 } | 8225 } |
| 8240 } | 8226 } |
| 8241 if (classElement != null) { | 8227 if (classElement != null) { |
| 8242 classElement.interfaces = interfaceTypes; | 8228 classElement.interfaces = interfaceTypes; |
| 8243 } | 8229 } |
| 8244 } | 8230 } |
| 8245 } | 8231 } |
| 8246 | 8232 |
| 8247 /** | 8233 /** |
| 8248 * Return the type specified by the given name. | 8234 * Return the type specified by the given name. |
| 8249 * @param typeName the type name specifying the type to be returned | 8235 * @param typeName the type name specifying the type to be returned |
| 8250 * @param nonTypeError the error to produce if the type name is defined to be
something other than | 8236 * @param nonTypeError the error to produce if the type name is defined to be
something other than |
| 8251 * a type | 8237 * a type |
| 8252 * @return the type specified by the type name | 8238 * @return the type specified by the type name |
| 8253 */ | 8239 */ |
| 8254 InterfaceType resolveType(TypeName typeName, ErrorCode nonTypeError) { | 8240 InterfaceType resolveType(TypeName typeName, ErrorCode nonTypeError) { |
| 8255 Type2 type2 = typeName.type; | 8241 Type2 type2 = typeName.type; |
| 8256 if (type2 is InterfaceType) { | 8242 if (type2 is InterfaceType) { |
| 8257 return type2 as InterfaceType; | 8243 return type2 as InterfaceType; |
| 8258 } | 8244 } |
| 8259 Identifier name2 = typeName.name; | 8245 Identifier name2 = typeName.name; |
| 8260 if (name2.name != sc.Keyword.DYNAMIC.syntax) { | 8246 if (name2.name != sc.Keyword.DYNAMIC.syntax) { |
| 8261 reportError(nonTypeError, name2, [name2.name]); | 8247 reportError(nonTypeError, name2, [name2.name]); |
| 8262 } | 8248 } |
| 8263 return null; | 8249 return null; |
| 8264 } | 8250 } |
| 8265 | 8251 |
| 8266 /** | 8252 /** |
| 8267 * Resolve the types in the given list of type names. | 8253 * Resolve the types in the given list of type names. |
| 8268 * @param typeNames the type names to be resolved | 8254 * @param typeNames the type names to be resolved |
| 8269 * @param nonTypeError the error to produce if the type name is defined to be
something other than | 8255 * @param nonTypeError the error to produce if the type name is defined to be
something other than |
| 8270 * a type | 8256 * a type |
| 8271 * @return an array containing all of the types that were resolved. | 8257 * @return an array containing all of the types that were resolved. |
| 8272 */ | 8258 */ |
| 8273 List<InterfaceType> resolveTypes(NodeList<TypeName> typeNames, ErrorCode nonTy
peError) { | 8259 List<InterfaceType> resolveTypes(NodeList<TypeName> typeNames, ErrorCode nonTy
peError) { |
| 8274 List<InterfaceType> types = new List<InterfaceType>(); | 8260 List<InterfaceType> types = new List<InterfaceType>(); |
| 8275 for (TypeName typeName in typeNames) { | 8261 for (TypeName typeName in typeNames) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 8288 PrefixedIdentifier identifier = typeName as PrefixedIdentifier; | 8274 PrefixedIdentifier identifier = typeName as PrefixedIdentifier; |
| 8289 identifier.identifier.element = element2; | 8275 identifier.identifier.element = element2; |
| 8290 SimpleIdentifier prefix2 = identifier.prefix; | 8276 SimpleIdentifier prefix2 = identifier.prefix; |
| 8291 Element prefixElement = nameScope.lookup(prefix2, definingLibrary); | 8277 Element prefixElement = nameScope.lookup(prefix2, definingLibrary); |
| 8292 if (prefixElement != null) { | 8278 if (prefixElement != null) { |
| 8293 prefix2.element = prefixElement; | 8279 prefix2.element = prefixElement; |
| 8294 } | 8280 } |
| 8295 } | 8281 } |
| 8296 } | 8282 } |
| 8297 } | 8283 } |
| 8298 | 8284 |
| 8299 /** | 8285 /** |
| 8300 * Set the return type and parameter type information for the given function t
ype based on the | 8286 * Set the return type and parameter type information for the given function t
ype based on the |
| 8301 * given return type and parameter elements. | 8287 * given return type and parameter elements. |
| 8302 * @param functionType the function type to be filled in | 8288 * @param functionType the function type to be filled in |
| 8303 * @param returnType the return type of the function, or {@code null} if no ty
pe was declared | 8289 * @param returnType the return type of the function, or {@code null} if no ty
pe was declared |
| 8304 * @param parameters the elements representing the parameters to the function | 8290 * @param parameters the elements representing the parameters to the function |
| 8305 */ | 8291 */ |
| 8306 void setTypeInformation(FunctionTypeImpl functionType, TypeName returnType2, L
ist<ParameterElement> parameters) { | 8292 void setTypeInformation(FunctionTypeImpl functionType, TypeName returnType2, L
ist<ParameterElement> parameters) { |
| 8307 List<Type2> normalParameterTypes = new List<Type2>(); | 8293 List<Type2> normalParameterTypes = new List<Type2>(); |
| 8308 List<Type2> optionalParameterTypes = new List<Type2>(); | 8294 List<Type2> optionalParameterTypes = new List<Type2>(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 8328 if (!namedParameterTypes.isEmpty) { | 8314 if (!namedParameterTypes.isEmpty) { |
| 8329 functionType.namedParameterTypes = namedParameterTypes; | 8315 functionType.namedParameterTypes = namedParameterTypes; |
| 8330 } | 8316 } |
| 8331 if (returnType2 == null) { | 8317 if (returnType2 == null) { |
| 8332 functionType.returnType = _dynamicType; | 8318 functionType.returnType = _dynamicType; |
| 8333 } else { | 8319 } else { |
| 8334 functionType.returnType = returnType2.type; | 8320 functionType.returnType = returnType2.type; |
| 8335 } | 8321 } |
| 8336 } | 8322 } |
| 8337 } | 8323 } |
| 8338 | |
| 8339 /** | 8324 /** |
| 8340 * Instances of the class {@code ClassScope} implement the scope defined by a cl
ass. | 8325 * Instances of the class {@code ClassScope} implement the scope defined by a cl
ass. |
| 8341 * @coverage dart.engine.resolver | 8326 * @coverage dart.engine.resolver |
| 8342 */ | 8327 */ |
| 8343 class ClassScope extends EnclosedScope { | 8328 class ClassScope extends EnclosedScope { |
| 8344 | 8329 |
| 8345 /** | 8330 /** |
| 8346 * Initialize a newly created scope enclosed within another scope. | 8331 * Initialize a newly created scope enclosed within another scope. |
| 8347 * @param enclosingScope the scope in which this scope is lexically enclosed | 8332 * @param enclosingScope the scope in which this scope is lexically enclosed |
| 8348 * @param typeElement the element representing the type represented by this sc
ope | 8333 * @param typeElement the element representing the type represented by this sc
ope |
| 8349 */ | 8334 */ |
| 8350 ClassScope(Scope enclosingScope, ClassElement typeElement) : super(new Enclose
dScope(enclosingScope)) { | 8335 ClassScope(Scope enclosingScope, ClassElement typeElement) : super(new Enclose
dScope(enclosingScope)) { |
| 8351 defineTypeParameters(typeElement); | 8336 defineTypeParameters(typeElement); |
| 8352 defineMembers(typeElement); | 8337 defineMembers(typeElement); |
| 8353 } | 8338 } |
| 8354 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { | 8339 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { |
| 8355 if (existing is PropertyAccessorElement && duplicate is MethodElement) { | 8340 if (existing is PropertyAccessorElement && duplicate is MethodElement) { |
| 8356 if (existing.nameOffset < duplicate.nameOffset) { | 8341 if (existing.nameOffset < duplicate.nameOffset) { |
| 8357 return new AnalysisError.con2(duplicate.source, duplicate.nameOffset, du
plicate.displayName.length, CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAM
E, [existing.displayName]); | 8342 return new AnalysisError.con2(duplicate.source, duplicate.nameOffset, du
plicate.displayName.length, CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAM
E, [existing.displayName]); |
| 8358 } else { | 8343 } else { |
| 8359 return new AnalysisError.con2(existing.source, existing.nameOffset, exis
ting.displayName.length, CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME,
[existing.displayName]); | 8344 return new AnalysisError.con2(existing.source, existing.nameOffset, exis
ting.displayName.length, CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME,
[existing.displayName]); |
| 8360 } | 8345 } |
| 8361 } | 8346 } |
| 8362 return super.getErrorForDuplicate(existing, duplicate); | 8347 return super.getErrorForDuplicate(existing, duplicate); |
| 8363 } | 8348 } |
| 8364 | 8349 |
| 8365 /** | 8350 /** |
| 8366 * Define the instance members defined by the class. | 8351 * Define the instance members defined by the class. |
| 8367 * @param typeElement the element representing the type represented by this sc
ope | 8352 * @param typeElement the element representing the type represented by this sc
ope |
| 8368 */ | 8353 */ |
| 8369 void defineMembers(ClassElement typeElement) { | 8354 void defineMembers(ClassElement typeElement) { |
| 8370 for (PropertyAccessorElement accessor in typeElement.accessors) { | 8355 for (PropertyAccessorElement accessor in typeElement.accessors) { |
| 8371 define(accessor); | 8356 define(accessor); |
| 8372 } | 8357 } |
| 8373 for (MethodElement method in typeElement.methods) { | 8358 for (MethodElement method in typeElement.methods) { |
| 8374 define(method); | 8359 define(method); |
| 8375 } | 8360 } |
| 8376 } | 8361 } |
| 8377 | 8362 |
| 8378 /** | 8363 /** |
| 8379 * Define the type parameters for the class. | 8364 * Define the type parameters for the class. |
| 8380 * @param typeElement the element representing the type represented by this sc
ope | 8365 * @param typeElement the element representing the type represented by this sc
ope |
| 8381 */ | 8366 */ |
| 8382 void defineTypeParameters(ClassElement typeElement) { | 8367 void defineTypeParameters(ClassElement typeElement) { |
| 8383 Scope parameterScope = enclosingScope; | 8368 Scope parameterScope = enclosingScope; |
| 8384 for (TypeVariableElement parameter in typeElement.typeVariables) { | 8369 for (TypeVariableElement parameter in typeElement.typeVariables) { |
| 8385 parameterScope.define(parameter); | 8370 parameterScope.define(parameter); |
| 8386 } | 8371 } |
| 8387 } | 8372 } |
| 8388 } | 8373 } |
| 8389 | |
| 8390 /** | 8374 /** |
| 8391 * Instances of the class {@code EnclosedScope} implement a scope that is lexica
lly enclosed in | 8375 * Instances of the class {@code EnclosedScope} implement a scope that is lexica
lly enclosed in |
| 8392 * another scope. | 8376 * another scope. |
| 8393 * @coverage dart.engine.resolver | 8377 * @coverage dart.engine.resolver |
| 8394 */ | 8378 */ |
| 8395 class EnclosedScope extends Scope { | 8379 class EnclosedScope extends Scope { |
| 8396 | 8380 |
| 8397 /** | 8381 /** |
| 8398 * The scope in which this scope is lexically enclosed. | 8382 * The scope in which this scope is lexically enclosed. |
| 8399 */ | 8383 */ |
| 8400 Scope _enclosingScope; | 8384 Scope _enclosingScope; |
| 8401 | 8385 |
| 8402 /** | 8386 /** |
| 8403 * Initialize a newly created scope enclosed within another scope. | 8387 * Initialize a newly created scope enclosed within another scope. |
| 8404 * @param enclosingScope the scope in which this scope is lexically enclosed | 8388 * @param enclosingScope the scope in which this scope is lexically enclosed |
| 8405 */ | 8389 */ |
| 8406 EnclosedScope(Scope enclosingScope) { | 8390 EnclosedScope(Scope enclosingScope) { |
| 8407 this._enclosingScope = enclosingScope; | 8391 this._enclosingScope = enclosingScope; |
| 8408 } | 8392 } |
| 8409 LibraryElement get definingLibrary => _enclosingScope.definingLibrary; | 8393 LibraryElement get definingLibrary => _enclosingScope.definingLibrary; |
| 8410 AnalysisErrorListener get errorListener => _enclosingScope.errorListener; | 8394 AnalysisErrorListener get errorListener => _enclosingScope.errorListener; |
| 8411 | 8395 |
| 8412 /** | 8396 /** |
| 8413 * Return the scope in which this scope is lexically enclosed. | 8397 * Return the scope in which this scope is lexically enclosed. |
| 8414 * @return the scope in which this scope is lexically enclosed | 8398 * @return the scope in which this scope is lexically enclosed |
| 8415 */ | 8399 */ |
| 8416 Scope get enclosingScope => _enclosingScope; | 8400 Scope get enclosingScope => _enclosingScope; |
| 8417 Element lookup3(Identifier identifier, String name, LibraryElement referencing
Library) { | 8401 Element lookup3(Identifier identifier, String name, LibraryElement referencing
Library) { |
| 8418 Element element = localLookup(name, referencingLibrary); | 8402 Element element = localLookup(name, referencingLibrary); |
| 8419 if (element != null) { | 8403 if (element != null) { |
| 8420 return element; | 8404 return element; |
| 8421 } | 8405 } |
| 8422 return _enclosingScope.lookup3(identifier, name, referencingLibrary); | 8406 return _enclosingScope.lookup3(identifier, name, referencingLibrary); |
| 8423 } | 8407 } |
| 8424 } | 8408 } |
| 8425 | |
| 8426 /** | 8409 /** |
| 8427 * Instances of the class {@code FunctionScope} implement the scope defined by a
function. | 8410 * Instances of the class {@code FunctionScope} implement the scope defined by a
function. |
| 8428 * @coverage dart.engine.resolver | 8411 * @coverage dart.engine.resolver |
| 8429 */ | 8412 */ |
| 8430 class FunctionScope extends EnclosedScope { | 8413 class FunctionScope extends EnclosedScope { |
| 8431 | 8414 |
| 8432 /** | 8415 /** |
| 8433 * Initialize a newly created scope enclosed within another scope. | 8416 * Initialize a newly created scope enclosed within another scope. |
| 8434 * @param enclosingScope the scope in which this scope is lexically enclosed | 8417 * @param enclosingScope the scope in which this scope is lexically enclosed |
| 8435 * @param functionElement the element representing the type represented by thi
s scope | 8418 * @param functionElement the element representing the type represented by thi
s scope |
| 8436 */ | 8419 */ |
| 8437 FunctionScope(Scope enclosingScope, ExecutableElement functionElement) : super
(new EnclosedScope(enclosingScope)) { | 8420 FunctionScope(Scope enclosingScope, ExecutableElement functionElement) : super
(new EnclosedScope(enclosingScope)) { |
| 8438 defineParameters(functionElement); | 8421 defineParameters(functionElement); |
| 8439 } | 8422 } |
| 8440 | 8423 |
| 8441 /** | 8424 /** |
| 8442 * Define the parameters for the given function in the scope that encloses thi
s function. | 8425 * Define the parameters for the given function in the scope that encloses thi
s function. |
| 8443 * @param functionElement the element representing the function represented by
this scope | 8426 * @param functionElement the element representing the function represented by
this scope |
| 8444 */ | 8427 */ |
| 8445 void defineParameters(ExecutableElement functionElement) { | 8428 void defineParameters(ExecutableElement functionElement) { |
| 8446 Scope parameterScope = enclosingScope; | 8429 Scope parameterScope = enclosingScope; |
| 8447 if (functionElement.enclosingElement is ExecutableElement) { | 8430 if (functionElement.enclosingElement is ExecutableElement) { |
| 8448 String name2 = functionElement.name; | 8431 String name2 = functionElement.name; |
| 8449 if (name2 != null && !name2.isEmpty) { | 8432 if (name2 != null && !name2.isEmpty) { |
| 8450 parameterScope.define(functionElement); | 8433 parameterScope.define(functionElement); |
| 8451 } | 8434 } |
| 8452 } | 8435 } |
| 8453 for (ParameterElement parameter in functionElement.parameters) { | 8436 for (ParameterElement parameter in functionElement.parameters) { |
| 8454 if (!parameter.isInitializingFormal()) { | 8437 if (!parameter.isInitializingFormal()) { |
| 8455 parameterScope.define(parameter); | 8438 parameterScope.define(parameter); |
| 8456 } | 8439 } |
| 8457 } | 8440 } |
| 8458 } | 8441 } |
| 8459 } | 8442 } |
| 8460 | |
| 8461 /** | 8443 /** |
| 8462 * Instances of the class {@code FunctionTypeScope} implement the scope defined
by a function type | 8444 * Instances of the class {@code FunctionTypeScope} implement the scope defined
by a function type |
| 8463 * alias. | 8445 * alias. |
| 8464 * @coverage dart.engine.resolver | 8446 * @coverage dart.engine.resolver |
| 8465 */ | 8447 */ |
| 8466 class FunctionTypeScope extends EnclosedScope { | 8448 class FunctionTypeScope extends EnclosedScope { |
| 8467 | 8449 |
| 8468 /** | 8450 /** |
| 8469 * Initialize a newly created scope enclosed within another scope. | 8451 * Initialize a newly created scope enclosed within another scope. |
| 8470 * @param enclosingScope the scope in which this scope is lexically enclosed | 8452 * @param enclosingScope the scope in which this scope is lexically enclosed |
| 8471 * @param typeElement the element representing the type alias represented by t
his scope | 8453 * @param typeElement the element representing the type alias represented by t
his scope |
| 8472 */ | 8454 */ |
| 8473 FunctionTypeScope(Scope enclosingScope, FunctionTypeAliasElement typeElement)
: super(new EnclosedScope(enclosingScope)) { | 8455 FunctionTypeScope(Scope enclosingScope, FunctionTypeAliasElement typeElement)
: super(new EnclosedScope(enclosingScope)) { |
| 8474 defineTypeVariables(typeElement); | 8456 defineTypeVariables(typeElement); |
| 8475 defineParameters(typeElement); | 8457 defineParameters(typeElement); |
| 8476 } | 8458 } |
| 8477 | 8459 |
| 8478 /** | 8460 /** |
| 8479 * Define the parameters for the function type alias. | 8461 * Define the parameters for the function type alias. |
| 8480 * @param typeElement the element representing the type represented by this sc
ope | 8462 * @param typeElement the element representing the type represented by this sc
ope |
| 8481 */ | 8463 */ |
| 8482 void defineParameters(FunctionTypeAliasElement typeElement) { | 8464 void defineParameters(FunctionTypeAliasElement typeElement) { |
| 8483 for (ParameterElement parameter in typeElement.parameters) { | 8465 for (ParameterElement parameter in typeElement.parameters) { |
| 8484 define(parameter); | 8466 define(parameter); |
| 8485 } | 8467 } |
| 8486 } | 8468 } |
| 8487 | 8469 |
| 8488 /** | 8470 /** |
| 8489 * Define the type variables for the function type alias. | 8471 * Define the type variables for the function type alias. |
| 8490 * @param typeElement the element representing the type represented by this sc
ope | 8472 * @param typeElement the element representing the type represented by this sc
ope |
| 8491 */ | 8473 */ |
| 8492 void defineTypeVariables(FunctionTypeAliasElement typeElement) { | 8474 void defineTypeVariables(FunctionTypeAliasElement typeElement) { |
| 8493 Scope typeVariableScope = enclosingScope; | 8475 Scope typeVariableScope = enclosingScope; |
| 8494 for (TypeVariableElement typeVariable in typeElement.typeVariables) { | 8476 for (TypeVariableElement typeVariable in typeElement.typeVariables) { |
| 8495 typeVariableScope.define(typeVariable); | 8477 typeVariableScope.define(typeVariable); |
| 8496 } | 8478 } |
| 8497 } | 8479 } |
| 8498 } | 8480 } |
| 8499 | |
| 8500 /** | 8481 /** |
| 8501 * Instances of the class {@code LabelScope} represent a scope in which a single
label is defined. | 8482 * Instances of the class {@code LabelScope} represent a scope in which a single
label is defined. |
| 8502 * @coverage dart.engine.resolver | 8483 * @coverage dart.engine.resolver |
| 8503 */ | 8484 */ |
| 8504 class LabelScope { | 8485 class LabelScope { |
| 8505 | 8486 |
| 8506 /** | 8487 /** |
| 8507 * The label scope enclosing this label scope. | 8488 * The label scope enclosing this label scope. |
| 8508 */ | 8489 */ |
| 8509 LabelScope _outerScope; | 8490 LabelScope _outerScope; |
| 8510 | 8491 |
| 8511 /** | 8492 /** |
| 8512 * The label defined in this scope. | 8493 * The label defined in this scope. |
| 8513 */ | 8494 */ |
| 8514 String _label; | 8495 String _label; |
| 8515 | 8496 |
| 8516 /** | 8497 /** |
| 8517 * The element to which the label resolves. | 8498 * The element to which the label resolves. |
| 8518 */ | 8499 */ |
| 8519 LabelElement _element; | 8500 LabelElement _element; |
| 8520 | 8501 |
| 8521 /** | 8502 /** |
| 8522 * The marker used to look up a label element for an unlabeled {@code break} o
r {@code continue}. | 8503 * The marker used to look up a label element for an unlabeled {@code break} o
r {@code continue}. |
| 8523 */ | 8504 */ |
| 8524 static String EMPTY_LABEL = ""; | 8505 static String EMPTY_LABEL = ""; |
| 8525 | 8506 |
| 8526 /** | 8507 /** |
| 8527 * The label element returned for scopes that can be the target of an unlabele
d {@code break} or{@code continue}. | 8508 * The label element returned for scopes that can be the target of an unlabele
d {@code break} or{@code continue}. |
| 8528 */ | 8509 */ |
| 8529 static SimpleIdentifier _EMPTY_LABEL_IDENTIFIER = new SimpleIdentifier.full(ne
w sc.StringToken(sc.TokenType.IDENTIFIER, "", 0)); | 8510 static SimpleIdentifier _EMPTY_LABEL_IDENTIFIER = new SimpleIdentifier.full(ne
w sc.StringToken(sc.TokenType.IDENTIFIER, "", 0)); |
| 8530 | 8511 |
| 8531 /** | 8512 /** |
| 8532 * Initialize a newly created scope to represent the potential target of an un
labeled{@code break} or {@code continue}. | 8513 * Initialize a newly created scope to represent the potential target of an un
labeled{@code break} or {@code continue}. |
| 8533 * @param outerScope the label scope enclosing the new label scope | 8514 * @param outerScope the label scope enclosing the new label scope |
| 8534 * @param onSwitchStatement {@code true} if this label is associated with a {@
code switch}statement | 8515 * @param onSwitchStatement {@code true} if this label is associated with a {@
code switch}statement |
| 8535 * @param onSwitchMember {@code true} if this label is associated with a {@cod
e switch} member | 8516 * @param onSwitchMember {@code true} if this label is associated with a {@cod
e switch} member |
| 8536 */ | 8517 */ |
| 8537 LabelScope.con1(LabelScope outerScope, bool onSwitchStatement, bool onSwitchMe
mber) { | 8518 LabelScope.con1(LabelScope outerScope, bool onSwitchStatement, bool onSwitchMe
mber) { |
| 8538 _jtd_constructor_286_impl(outerScope, onSwitchStatement, onSwitchMember); | 8519 _jtd_constructor_287_impl(outerScope, onSwitchStatement, onSwitchMember); |
| 8539 } | 8520 } |
| 8540 _jtd_constructor_286_impl(LabelScope outerScope, bool onSwitchStatement, bool
onSwitchMember) { | 8521 _jtd_constructor_287_impl(LabelScope outerScope, bool onSwitchStatement, bool
onSwitchMember) { |
| 8541 _jtd_constructor_287_impl(outerScope, EMPTY_LABEL, new LabelElementImpl(_EMP
TY_LABEL_IDENTIFIER, onSwitchStatement, onSwitchMember)); | 8522 _jtd_constructor_288_impl(outerScope, EMPTY_LABEL, new LabelElementImpl(_EMP
TY_LABEL_IDENTIFIER, onSwitchStatement, onSwitchMember)); |
| 8542 } | 8523 } |
| 8543 | 8524 |
| 8544 /** | 8525 /** |
| 8545 * Initialize a newly created scope to represent the given label. | 8526 * Initialize a newly created scope to represent the given label. |
| 8546 * @param outerScope the label scope enclosing the new label scope | 8527 * @param outerScope the label scope enclosing the new label scope |
| 8547 * @param label the label defined in this scope | 8528 * @param label the label defined in this scope |
| 8548 * @param element the element to which the label resolves | 8529 * @param element the element to which the label resolves |
| 8549 */ | 8530 */ |
| 8550 LabelScope.con2(LabelScope outerScope2, String label2, LabelElement element2)
{ | 8531 LabelScope.con2(LabelScope outerScope2, String label2, LabelElement element2)
{ |
| 8551 _jtd_constructor_287_impl(outerScope2, label2, element2); | 8532 _jtd_constructor_288_impl(outerScope2, label2, element2); |
| 8552 } | 8533 } |
| 8553 _jtd_constructor_287_impl(LabelScope outerScope2, String label2, LabelElement
element2) { | 8534 _jtd_constructor_288_impl(LabelScope outerScope2, String label2, LabelElement
element2) { |
| 8554 this._outerScope = outerScope2; | 8535 this._outerScope = outerScope2; |
| 8555 this._label = label2; | 8536 this._label = label2; |
| 8556 this._element = element2; | 8537 this._element = element2; |
| 8557 } | 8538 } |
| 8558 | 8539 |
| 8559 /** | 8540 /** |
| 8560 * Return the label element corresponding to the given label, or {@code null}
if the given label | 8541 * Return the label element corresponding to the given label, or {@code null}
if the given label |
| 8561 * is not defined in this scope. | 8542 * is not defined in this scope. |
| 8562 * @param targetLabel the label being looked up | 8543 * @param targetLabel the label being looked up |
| 8563 * @return the label element corresponding to the given label | 8544 * @return the label element corresponding to the given label |
| 8564 */ | 8545 */ |
| 8565 LabelElement lookup(SimpleIdentifier targetLabel) => lookup2(targetLabel.name)
; | 8546 LabelElement lookup(SimpleIdentifier targetLabel) => lookup2(targetLabel.name)
; |
| 8566 | 8547 |
| 8567 /** | 8548 /** |
| 8568 * Return the label element corresponding to the given label, or {@code null}
if the given label | 8549 * Return the label element corresponding to the given label, or {@code null}
if the given label |
| 8569 * is not defined in this scope. | 8550 * is not defined in this scope. |
| 8570 * @param targetLabel the label being looked up | 8551 * @param targetLabel the label being looked up |
| 8571 * @return the label element corresponding to the given label | 8552 * @return the label element corresponding to the given label |
| 8572 */ | 8553 */ |
| 8573 LabelElement lookup2(String targetLabel) { | 8554 LabelElement lookup2(String targetLabel) { |
| 8574 if (_label == targetLabel) { | 8555 if (_label == targetLabel) { |
| 8575 return _element; | 8556 return _element; |
| 8576 } else if (_outerScope != null) { | 8557 } else if (_outerScope != null) { |
| 8577 return _outerScope.lookup2(targetLabel); | 8558 return _outerScope.lookup2(targetLabel); |
| 8578 } else { | 8559 } else { |
| 8579 return null; | 8560 return null; |
| 8580 } | 8561 } |
| 8581 } | 8562 } |
| 8582 } | 8563 } |
| 8583 | |
| 8584 /** | 8564 /** |
| 8585 * Instances of the class {@code LibraryImportScope} represent the scope contain
ing all of the names | 8565 * Instances of the class {@code LibraryImportScope} represent the scope contain
ing all of the names |
| 8586 * available from imported libraries. | 8566 * available from imported libraries. |
| 8587 * @coverage dart.engine.resolver | 8567 * @coverage dart.engine.resolver |
| 8588 */ | 8568 */ |
| 8589 class LibraryImportScope extends Scope { | 8569 class LibraryImportScope extends Scope { |
| 8590 | 8570 |
| 8591 /** | 8571 /** |
| 8592 * @return {@code true} if the given {@link Identifier} is the part of type an
notation. | 8572 * @return {@code true} if the given {@link Identifier} is the part of type an
notation. |
| 8593 */ | 8573 */ |
| 8594 static bool isTypeAnnotation(Identifier identifier) { | 8574 static bool isTypeAnnotation(Identifier identifier) { |
| 8595 ASTNode parent4 = identifier.parent; | 8575 ASTNode parent4 = identifier.parent; |
| 8596 if (parent4 is TypeName) { | 8576 if (parent4 is TypeName) { |
| 8597 ASTNode parent2 = parent4.parent; | 8577 ASTNode parent2 = parent4.parent; |
| 8598 if (parent2 is FunctionDeclaration) { | 8578 if (parent2 is FunctionDeclaration) { |
| 8599 FunctionDeclaration decl = parent2 as FunctionDeclaration; | 8579 FunctionDeclaration decl = parent2 as FunctionDeclaration; |
| 8600 return identical(decl.returnType, parent4); | 8580 return identical(decl.returnType, parent4); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 8625 TypeName typeName = parent3 as TypeName; | 8605 TypeName typeName = parent3 as TypeName; |
| 8626 if (identical((typeName).typeArguments, parent2)) { | 8606 if (identical((typeName).typeArguments, parent2)) { |
| 8627 return isTypeAnnotation(typeName.name); | 8607 return isTypeAnnotation(typeName.name); |
| 8628 } | 8608 } |
| 8629 } | 8609 } |
| 8630 } | 8610 } |
| 8631 return false; | 8611 return false; |
| 8632 } | 8612 } |
| 8633 return false; | 8613 return false; |
| 8634 } | 8614 } |
| 8635 | 8615 |
| 8636 /** | 8616 /** |
| 8637 * The element representing the library in which this scope is enclosed. | 8617 * The element representing the library in which this scope is enclosed. |
| 8638 */ | 8618 */ |
| 8639 LibraryElement _definingLibrary; | 8619 LibraryElement _definingLibrary; |
| 8640 | 8620 |
| 8641 /** | 8621 /** |
| 8642 * The listener that is to be informed when an error is encountered. | 8622 * The listener that is to be informed when an error is encountered. |
| 8643 */ | 8623 */ |
| 8644 AnalysisErrorListener _errorListener; | 8624 AnalysisErrorListener _errorListener; |
| 8645 | 8625 |
| 8646 /** | 8626 /** |
| 8647 * A list of the namespaces representing the names that are available in this
scope from imported | 8627 * A list of the namespaces representing the names that are available in this
scope from imported |
| 8648 * libraries. | 8628 * libraries. |
| 8649 */ | 8629 */ |
| 8650 List<Namespace> _importedNamespaces = new List<Namespace>(); | 8630 List<Namespace> _importedNamespaces = new List<Namespace>(); |
| 8651 | 8631 |
| 8652 /** | 8632 /** |
| 8653 * Initialize a newly created scope representing the names imported into the g
iven library. | 8633 * Initialize a newly created scope representing the names imported into the g
iven library. |
| 8654 * @param definingLibrary the element representing the library that imports th
e names defined in | 8634 * @param definingLibrary the element representing the library that imports th
e names defined in |
| 8655 * this scope | 8635 * this scope |
| 8656 * @param errorListener the listener that is to be informed when an error is e
ncountered | 8636 * @param errorListener the listener that is to be informed when an error is e
ncountered |
| 8657 */ | 8637 */ |
| 8658 LibraryImportScope(LibraryElement definingLibrary, AnalysisErrorListener error
Listener) { | 8638 LibraryImportScope(LibraryElement definingLibrary, AnalysisErrorListener error
Listener) { |
| 8659 this._definingLibrary = definingLibrary; | 8639 this._definingLibrary = definingLibrary; |
| 8660 this._errorListener = errorListener; | 8640 this._errorListener = errorListener; |
| 8661 createImportedNamespaces(definingLibrary); | 8641 createImportedNamespaces(definingLibrary); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8696 } | 8676 } |
| 8697 ErrorCode errorCode = isTypeAnnotation(identifier) ? StaticWarningCode.AMB
IGUOUS_IMPORT : CompileTimeErrorCode.AMBIGUOUS_IMPORT; | 8677 ErrorCode errorCode = isTypeAnnotation(identifier) ? StaticWarningCode.AMB
IGUOUS_IMPORT : CompileTimeErrorCode.AMBIGUOUS_IMPORT; |
| 8698 _errorListener.onError(new AnalysisError.con2(source, identifier.offset, i
dentifier.length, errorCode, [foundEltName, libName1, libName2])); | 8678 _errorListener.onError(new AnalysisError.con2(source, identifier.offset, i
dentifier.length, errorCode, [foundEltName, libName1, libName2])); |
| 8699 return foundElement; | 8679 return foundElement; |
| 8700 } | 8680 } |
| 8701 if (foundElement != null) { | 8681 if (foundElement != null) { |
| 8702 defineWithoutChecking2(name, foundElement); | 8682 defineWithoutChecking2(name, foundElement); |
| 8703 } | 8683 } |
| 8704 return foundElement; | 8684 return foundElement; |
| 8705 } | 8685 } |
| 8706 | 8686 |
| 8707 /** | 8687 /** |
| 8708 * Create all of the namespaces associated with the libraries imported into th
is library. The | 8688 * Create all of the namespaces associated with the libraries imported into th
is library. The |
| 8709 * names are not added to this scope, but are stored for later reference. | 8689 * names are not added to this scope, but are stored for later reference. |
| 8710 * @param definingLibrary the element representing the library that imports th
e libraries for | 8690 * @param definingLibrary the element representing the library that imports th
e libraries for |
| 8711 * which namespaces will be created | 8691 * which namespaces will be created |
| 8712 */ | 8692 */ |
| 8713 void createImportedNamespaces(LibraryElement definingLibrary) { | 8693 void createImportedNamespaces(LibraryElement definingLibrary) { |
| 8714 NamespaceBuilder builder = new NamespaceBuilder(); | 8694 NamespaceBuilder builder = new NamespaceBuilder(); |
| 8715 for (ImportElement element in definingLibrary.imports) { | 8695 for (ImportElement element in definingLibrary.imports) { |
| 8716 _importedNamespaces.add(builder.createImportNamespace(element)); | 8696 _importedNamespaces.add(builder.createImportNamespace(element)); |
| 8717 } | 8697 } |
| 8718 } | 8698 } |
| 8719 } | 8699 } |
| 8720 | |
| 8721 /** | 8700 /** |
| 8722 * Instances of the class {@code LibraryScope} implement a scope containing all
of the names defined | 8701 * Instances of the class {@code LibraryScope} implement a scope containing all
of the names defined |
| 8723 * in a given library. | 8702 * in a given library. |
| 8724 * @coverage dart.engine.resolver | 8703 * @coverage dart.engine.resolver |
| 8725 */ | 8704 */ |
| 8726 class LibraryScope extends EnclosedScope { | 8705 class LibraryScope extends EnclosedScope { |
| 8727 | 8706 |
| 8728 /** | 8707 /** |
| 8729 * Initialize a newly created scope representing the names defined in the give
n library. | 8708 * Initialize a newly created scope representing the names defined in the give
n library. |
| 8730 * @param definingLibrary the element representing the library represented by
this scope | 8709 * @param definingLibrary the element representing the library represented by
this scope |
| 8731 * @param errorListener the listener that is to be informed when an error is e
ncountered | 8710 * @param errorListener the listener that is to be informed when an error is e
ncountered |
| 8732 */ | 8711 */ |
| 8733 LibraryScope(LibraryElement definingLibrary, AnalysisErrorListener errorListen
er) : super(new LibraryImportScope(definingLibrary, errorListener)) { | 8712 LibraryScope(LibraryElement definingLibrary, AnalysisErrorListener errorListen
er) : super(new LibraryImportScope(definingLibrary, errorListener)) { |
| 8734 defineTopLevelNames(definingLibrary); | 8713 defineTopLevelNames(definingLibrary); |
| 8735 } | 8714 } |
| 8736 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { | 8715 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { |
| 8737 if (existing is PrefixElement) { | 8716 if (existing is PrefixElement) { |
| 8738 int offset = duplicate.nameOffset; | 8717 int offset = duplicate.nameOffset; |
| 8739 if (duplicate is PropertyAccessorElement) { | 8718 if (duplicate is PropertyAccessorElement) { |
| 8740 PropertyAccessorElement accessor = duplicate as PropertyAccessorElement; | 8719 PropertyAccessorElement accessor = duplicate as PropertyAccessorElement; |
| 8741 if (accessor.isSynthetic()) { | 8720 if (accessor.isSynthetic()) { |
| 8742 offset = accessor.variable.nameOffset; | 8721 offset = accessor.variable.nameOffset; |
| 8743 } | 8722 } |
| 8744 } | 8723 } |
| 8745 return new AnalysisError.con2(source, offset, duplicate.displayName.length
, CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER, [existing.displayN
ame]); | 8724 return new AnalysisError.con2(source, offset, duplicate.displayName.length
, CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER, [existing.displayN
ame]); |
| 8746 } | 8725 } |
| 8747 return super.getErrorForDuplicate(existing, duplicate); | 8726 return super.getErrorForDuplicate(existing, duplicate); |
| 8748 } | 8727 } |
| 8749 | 8728 |
| 8750 /** | 8729 /** |
| 8751 * Add to this scope all of the public top-level names that are defined in the
given compilation | 8730 * Add to this scope all of the public top-level names that are defined in the
given compilation |
| 8752 * unit. | 8731 * unit. |
| 8753 * @param compilationUnit the compilation unit defining the top-level names to
be added to this | 8732 * @param compilationUnit the compilation unit defining the top-level names to
be added to this |
| 8754 * scope | 8733 * scope |
| 8755 */ | 8734 */ |
| 8756 void defineLocalNames(CompilationUnitElement compilationUnit) { | 8735 void defineLocalNames(CompilationUnitElement compilationUnit) { |
| 8757 for (PropertyAccessorElement element in compilationUnit.accessors) { | 8736 for (PropertyAccessorElement element in compilationUnit.accessors) { |
| 8758 define(element); | 8737 define(element); |
| 8759 } | 8738 } |
| 8760 for (FunctionElement element in compilationUnit.functions) { | 8739 for (FunctionElement element in compilationUnit.functions) { |
| 8761 define(element); | 8740 define(element); |
| 8762 } | 8741 } |
| 8763 for (FunctionTypeAliasElement element in compilationUnit.functionTypeAliases
) { | 8742 for (FunctionTypeAliasElement element in compilationUnit.functionTypeAliases
) { |
| 8764 define(element); | 8743 define(element); |
| 8765 } | 8744 } |
| 8766 for (ClassElement element in compilationUnit.types) { | 8745 for (ClassElement element in compilationUnit.types) { |
| 8767 define(element); | 8746 define(element); |
| 8768 } | 8747 } |
| 8769 } | 8748 } |
| 8770 | 8749 |
| 8771 /** | 8750 /** |
| 8772 * Add to this scope all of the names that are explicitly defined in the given
library. | 8751 * Add to this scope all of the names that are explicitly defined in the given
library. |
| 8773 * @param definingLibrary the element representing the library that defines th
e names in this | 8752 * @param definingLibrary the element representing the library that defines th
e names in this |
| 8774 * scope | 8753 * scope |
| 8775 */ | 8754 */ |
| 8776 void defineTopLevelNames(LibraryElement definingLibrary) { | 8755 void defineTopLevelNames(LibraryElement definingLibrary) { |
| 8777 for (PrefixElement prefix in definingLibrary.prefixes) { | 8756 for (PrefixElement prefix in definingLibrary.prefixes) { |
| 8778 define(prefix); | 8757 define(prefix); |
| 8779 } | 8758 } |
| 8780 defineLocalNames(definingLibrary.definingCompilationUnit); | 8759 defineLocalNames(definingLibrary.definingCompilationUnit); |
| 8781 for (CompilationUnitElement compilationUnit in definingLibrary.parts) { | 8760 for (CompilationUnitElement compilationUnit in definingLibrary.parts) { |
| 8782 defineLocalNames(compilationUnit); | 8761 defineLocalNames(compilationUnit); |
| 8783 } | 8762 } |
| 8784 } | 8763 } |
| 8785 } | 8764 } |
| 8786 | |
| 8787 /** | 8765 /** |
| 8788 * Instances of the class {@code Namespace} implement a mapping of identifiers t
o the elements | 8766 * Instances of the class {@code Namespace} implement a mapping of identifiers t
o the elements |
| 8789 * represented by those identifiers. Namespaces are the building blocks for scop
es. | 8767 * represented by those identifiers. Namespaces are the building blocks for scop
es. |
| 8790 * @coverage dart.engine.resolver | 8768 * @coverage dart.engine.resolver |
| 8791 */ | 8769 */ |
| 8792 class Namespace { | 8770 class Namespace { |
| 8793 | 8771 |
| 8794 /** | 8772 /** |
| 8795 * A table mapping names that are defined in this namespace to the element rep
resenting the thing | 8773 * A table mapping names that are defined in this namespace to the element rep
resenting the thing |
| 8796 * declared with that name. | 8774 * declared with that name. |
| 8797 */ | 8775 */ |
| 8798 Map<String, Element> _definedNames; | 8776 Map<String, Element> _definedNames; |
| 8799 | 8777 |
| 8800 /** | 8778 /** |
| 8801 * An empty namespace. | 8779 * An empty namespace. |
| 8802 */ | 8780 */ |
| 8803 static Namespace EMPTY = new Namespace(new Map<String, Element>()); | 8781 static Namespace EMPTY = new Namespace(new Map<String, Element>()); |
| 8804 | 8782 |
| 8805 /** | 8783 /** |
| 8806 * Initialize a newly created namespace to have the given defined names. | 8784 * Initialize a newly created namespace to have the given defined names. |
| 8807 * @param definedNames the mapping from names that are defined in this namespa
ce to the | 8785 * @param definedNames the mapping from names that are defined in this namespa
ce to the |
| 8808 * corresponding elements | 8786 * corresponding elements |
| 8809 */ | 8787 */ |
| 8810 Namespace(Map<String, Element> definedNames) { | 8788 Namespace(Map<String, Element> definedNames) { |
| 8811 this._definedNames = definedNames; | 8789 this._definedNames = definedNames; |
| 8812 } | 8790 } |
| 8813 | 8791 |
| 8814 /** | 8792 /** |
| 8815 * Return the element in this namespace that is available to the containing sc
ope using the given | 8793 * Return the element in this namespace that is available to the containing sc
ope using the given |
| 8816 * name. | 8794 * name. |
| 8817 * @param name the name used to reference the | 8795 * @param name the name used to reference the |
| 8818 * @return the element represented by the given identifier | 8796 * @return the element represented by the given identifier |
| 8819 */ | 8797 */ |
| 8820 Element get(String name) => _definedNames[name]; | 8798 Element get(String name) => _definedNames[name]; |
| 8821 | 8799 |
| 8822 /** | 8800 /** |
| 8823 * Return a table containing the same mappings as those defined by this namesp
ace. | 8801 * Return a table containing the same mappings as those defined by this namesp
ace. |
| 8824 * @return a table containing the same mappings as those defined by this names
pace | 8802 * @return a table containing the same mappings as those defined by this names
pace |
| 8825 */ | 8803 */ |
| 8826 Map<String, Element> get definedNames => new Map<String, Element>.from(_define
dNames); | 8804 Map<String, Element> get definedNames => new Map<String, Element>.from(_define
dNames); |
| 8827 } | 8805 } |
| 8828 | |
| 8829 /** | 8806 /** |
| 8830 * Instances of the class {@code NamespaceBuilder} are used to build a {@code Na
mespace}. Namespace | 8807 * Instances of the class {@code NamespaceBuilder} are used to build a {@code Na
mespace}. Namespace |
| 8831 * builders are thread-safe and re-usable. | 8808 * builders are thread-safe and re-usable. |
| 8832 * @coverage dart.engine.resolver | 8809 * @coverage dart.engine.resolver |
| 8833 */ | 8810 */ |
| 8834 class NamespaceBuilder { | 8811 class NamespaceBuilder { |
| 8835 | 8812 |
| 8836 /** | 8813 /** |
| 8837 * Create a namespace representing the export namespace of the given {@link Ex
portElement}. | 8814 * Create a namespace representing the export namespace of the given {@link Ex
portElement}. |
| 8838 * @param element the export element whose export namespace is to be created | 8815 * @param element the export element whose export namespace is to be created |
| 8839 * @return the export namespace that was created | 8816 * @return the export namespace that was created |
| 8840 */ | 8817 */ |
| 8841 Namespace createExportNamespace(ExportElement element) { | 8818 Namespace createExportNamespace(ExportElement element) { |
| 8842 LibraryElement exportedLibrary2 = element.exportedLibrary; | 8819 LibraryElement exportedLibrary2 = element.exportedLibrary; |
| 8843 if (exportedLibrary2 == null) { | 8820 if (exportedLibrary2 == null) { |
| 8844 return Namespace.EMPTY; | 8821 return Namespace.EMPTY; |
| 8845 } | 8822 } |
| 8846 Map<String, Element> definedNames = createExportMapping(exportedLibrary2, ne
w Set<LibraryElement>()); | 8823 Map<String, Element> definedNames = createExportMapping(exportedLibrary2, ne
w Set<LibraryElement>()); |
| 8847 definedNames = apply(definedNames, element.combinators); | 8824 definedNames = apply(definedNames, element.combinators); |
| 8848 return new Namespace(definedNames); | 8825 return new Namespace(definedNames); |
| 8849 } | 8826 } |
| 8850 | 8827 |
| 8851 /** | 8828 /** |
| 8852 * Create a namespace representing the export namespace of the given library. | 8829 * Create a namespace representing the export namespace of the given library. |
| 8853 * @param library the library whose export namespace is to be created | 8830 * @param library the library whose export namespace is to be created |
| 8854 * @return the export namespace that was created | 8831 * @return the export namespace that was created |
| 8855 */ | 8832 */ |
| 8856 Namespace createExportNamespace2(LibraryElement library) => new Namespace(crea
teExportMapping(library, new Set<LibraryElement>())); | 8833 Namespace createExportNamespace2(LibraryElement library) => new Namespace(crea
teExportMapping(library, new Set<LibraryElement>())); |
| 8857 | 8834 |
| 8858 /** | 8835 /** |
| 8859 * Create a namespace representing the import namespace of the given library. | 8836 * Create a namespace representing the import namespace of the given library. |
| 8860 * @param library the library whose import namespace is to be created | 8837 * @param library the library whose import namespace is to be created |
| 8861 * @return the import namespace that was created | 8838 * @return the import namespace that was created |
| 8862 */ | 8839 */ |
| 8863 Namespace createImportNamespace(ImportElement element) { | 8840 Namespace createImportNamespace(ImportElement element) { |
| 8864 LibraryElement importedLibrary2 = element.importedLibrary; | 8841 LibraryElement importedLibrary2 = element.importedLibrary; |
| 8865 if (importedLibrary2 == null) { | 8842 if (importedLibrary2 == null) { |
| 8866 return Namespace.EMPTY; | 8843 return Namespace.EMPTY; |
| 8867 } | 8844 } |
| 8868 Map<String, Element> definedNames = createExportMapping(importedLibrary2, ne
w Set<LibraryElement>()); | 8845 Map<String, Element> definedNames = createExportMapping(importedLibrary2, ne
w Set<LibraryElement>()); |
| 8869 definedNames = apply(definedNames, element.combinators); | 8846 definedNames = apply(definedNames, element.combinators); |
| 8870 definedNames = apply2(definedNames, element.prefix); | 8847 definedNames = apply2(definedNames, element.prefix); |
| 8871 return new Namespace(definedNames); | 8848 return new Namespace(definedNames); |
| 8872 } | 8849 } |
| 8873 | 8850 |
| 8874 /** | 8851 /** |
| 8875 * Create a namespace representing the public namespace of the given library. | 8852 * Create a namespace representing the public namespace of the given library. |
| 8876 * @param library the library whose public namespace is to be created | 8853 * @param library the library whose public namespace is to be created |
| 8877 * @return the public namespace that was created | 8854 * @return the public namespace that was created |
| 8878 */ | 8855 */ |
| 8879 Namespace createPublicNamespace(LibraryElement library) { | 8856 Namespace createPublicNamespace(LibraryElement library) { |
| 8880 Map<String, Element> definedNames = new Map<String, Element>(); | 8857 Map<String, Element> definedNames = new Map<String, Element>(); |
| 8881 addPublicNames(definedNames, library.definingCompilationUnit); | 8858 addPublicNames(definedNames, library.definingCompilationUnit); |
| 8882 for (CompilationUnitElement compilationUnit in library.parts) { | 8859 for (CompilationUnitElement compilationUnit in library.parts) { |
| 8883 addPublicNames(definedNames, compilationUnit); | 8860 addPublicNames(definedNames, compilationUnit); |
| 8884 } | 8861 } |
| 8885 return new Namespace(definedNames); | 8862 return new Namespace(definedNames); |
| 8886 } | 8863 } |
| 8887 | 8864 |
| 8888 /** | 8865 /** |
| 8889 * Add all of the names in the given namespace to the given mapping table. | 8866 * Add all of the names in the given namespace to the given mapping table. |
| 8890 * @param definedNames the mapping table to which the names in the given names
pace are to be added | 8867 * @param definedNames the mapping table to which the names in the given names
pace are to be added |
| 8891 * @param namespace the namespace containing the names to be added to this nam
espace | 8868 * @param namespace the namespace containing the names to be added to this nam
espace |
| 8892 */ | 8869 */ |
| 8893 void addAll(Map<String, Element> definedNames, Map<String, Element> newNames)
{ | 8870 void addAll(Map<String, Element> definedNames, Map<String, Element> newNames)
{ |
| 8894 for (MapEntry<String, Element> entry in getMapEntrySet(newNames)) { | 8871 for (MapEntry<String, Element> entry in getMapEntrySet(newNames)) { |
| 8895 definedNames[entry.getKey()] = entry.getValue(); | 8872 definedNames[entry.getKey()] = entry.getValue(); |
| 8896 } | 8873 } |
| 8897 } | 8874 } |
| 8898 | 8875 |
| 8899 /** | 8876 /** |
| 8900 * Add all of the names in the given namespace to the given mapping table. | 8877 * Add all of the names in the given namespace to the given mapping table. |
| 8901 * @param definedNames the mapping table to which the names in the given names
pace are to be added | 8878 * @param definedNames the mapping table to which the names in the given names
pace are to be added |
| 8902 * @param namespace the namespace containing the names to be added to this nam
espace | 8879 * @param namespace the namespace containing the names to be added to this nam
espace |
| 8903 */ | 8880 */ |
| 8904 void addAll2(Map<String, Element> definedNames2, Namespace namespace) { | 8881 void addAll2(Map<String, Element> definedNames2, Namespace namespace) { |
| 8905 if (namespace != null) { | 8882 if (namespace != null) { |
| 8906 addAll(definedNames2, namespace.definedNames); | 8883 addAll(definedNames2, namespace.definedNames); |
| 8907 } | 8884 } |
| 8908 } | 8885 } |
| 8909 | 8886 |
| 8910 /** | 8887 /** |
| 8911 * Add the given element to the given mapping table if it has a publicly visib
le name. | 8888 * Add the given element to the given mapping table if it has a publicly visib
le name. |
| 8912 * @param definedNames the mapping table to which the public name is to be add
ed | 8889 * @param definedNames the mapping table to which the public name is to be add
ed |
| 8913 * @param element the element to be added | 8890 * @param element the element to be added |
| 8914 */ | 8891 */ |
| 8915 void addIfPublic(Map<String, Element> definedNames, Element element) { | 8892 void addIfPublic(Map<String, Element> definedNames, Element element) { |
| 8916 String name2 = element.name; | 8893 String name2 = element.name; |
| 8917 if (name2 != null && !Scope.isPrivateName(name2)) { | 8894 if (name2 != null && !Scope.isPrivateName(name2)) { |
| 8918 definedNames[name2] = element; | 8895 definedNames[name2] = element; |
| 8919 } | 8896 } |
| 8920 } | 8897 } |
| 8921 | 8898 |
| 8922 /** | 8899 /** |
| 8923 * Add to the given mapping table all of the public top-level names that are d
efined in the given | 8900 * Add to the given mapping table all of the public top-level names that are d
efined in the given |
| 8924 * compilation unit. | 8901 * compilation unit. |
| 8925 * @param definedNames the mapping table to which the public names are to be a
dded | 8902 * @param definedNames the mapping table to which the public names are to be a
dded |
| 8926 * @param compilationUnit the compilation unit defining the top-level names to
be added to this | 8903 * @param compilationUnit the compilation unit defining the top-level names to
be added to this |
| 8927 * namespace | 8904 * namespace |
| 8928 */ | 8905 */ |
| 8929 void addPublicNames(Map<String, Element> definedNames, CompilationUnitElement
compilationUnit) { | 8906 void addPublicNames(Map<String, Element> definedNames, CompilationUnitElement
compilationUnit) { |
| 8930 for (PropertyAccessorElement element in compilationUnit.accessors) { | 8907 for (PropertyAccessorElement element in compilationUnit.accessors) { |
| 8931 addIfPublic(definedNames, element); | 8908 addIfPublic(definedNames, element); |
| 8932 } | 8909 } |
| 8933 for (FunctionElement element in compilationUnit.functions) { | 8910 for (FunctionElement element in compilationUnit.functions) { |
| 8934 addIfPublic(definedNames, element); | 8911 addIfPublic(definedNames, element); |
| 8935 } | 8912 } |
| 8936 for (FunctionTypeAliasElement element in compilationUnit.functionTypeAliases
) { | 8913 for (FunctionTypeAliasElement element in compilationUnit.functionTypeAliases
) { |
| 8937 addIfPublic(definedNames, element); | 8914 addIfPublic(definedNames, element); |
| 8938 } | 8915 } |
| 8939 for (ClassElement element in compilationUnit.types) { | 8916 for (ClassElement element in compilationUnit.types) { |
| 8940 addIfPublic(definedNames, element); | 8917 addIfPublic(definedNames, element); |
| 8941 } | 8918 } |
| 8942 } | 8919 } |
| 8943 | 8920 |
| 8944 /** | 8921 /** |
| 8945 * Apply the given combinators to all of the names in the given mapping table. | 8922 * Apply the given combinators to all of the names in the given mapping table. |
| 8946 * @param definedNames the mapping table to which the namespace operations are
to be applied | 8923 * @param definedNames the mapping table to which the namespace operations are
to be applied |
| 8947 * @param combinators the combinators to be applied | 8924 * @param combinators the combinators to be applied |
| 8948 */ | 8925 */ |
| 8949 Map<String, Element> apply(Map<String, Element> definedNames, List<NamespaceCo
mbinator> combinators) { | 8926 Map<String, Element> apply(Map<String, Element> definedNames, List<NamespaceCo
mbinator> combinators) { |
| 8950 for (NamespaceCombinator combinator in combinators) { | 8927 for (NamespaceCombinator combinator in combinators) { |
| 8951 if (combinator is __imp_combi.HideCombinator) { | 8928 if (combinator is __imp_combi.HideCombinator) { |
| 8952 hide(definedNames, ((combinator as __imp_combi.HideCombinator)).hiddenNa
mes); | 8929 hide(definedNames, ((combinator as __imp_combi.HideCombinator)).hiddenNa
mes); |
| 8953 } else if (combinator is __imp_combi.ShowCombinator) { | 8930 } else if (combinator is __imp_combi.ShowCombinator) { |
| 8954 definedNames = show(definedNames, ((combinator as __imp_combi.ShowCombin
ator)).shownNames); | 8931 definedNames = show(definedNames, ((combinator as __imp_combi.ShowCombin
ator)).shownNames); |
| 8955 } else { | 8932 } else { |
| 8956 AnalysisEngine.instance.logger.logError("Unknown type of combinator: ${c
ombinator.runtimeType.toString()}"); | 8933 AnalysisEngine.instance.logger.logError("Unknown type of combinator: ${c
ombinator.runtimeType.toString()}"); |
| 8957 } | 8934 } |
| 8958 } | 8935 } |
| 8959 return definedNames; | 8936 return definedNames; |
| 8960 } | 8937 } |
| 8961 | 8938 |
| 8962 /** | 8939 /** |
| 8963 * Apply the given prefix to all of the names in the table of defined names. | 8940 * Apply the given prefix to all of the names in the table of defined names. |
| 8964 * @param definedNames the names that were defined before this operation | 8941 * @param definedNames the names that were defined before this operation |
| 8965 * @param prefixElement the element defining the prefix to be added to the nam
es | 8942 * @param prefixElement the element defining the prefix to be added to the nam
es |
| 8966 */ | 8943 */ |
| 8967 Map<String, Element> apply2(Map<String, Element> definedNames, PrefixElement p
refixElement) { | 8944 Map<String, Element> apply2(Map<String, Element> definedNames, PrefixElement p
refixElement) { |
| 8968 if (prefixElement != null) { | 8945 if (prefixElement != null) { |
| 8969 String prefix = prefixElement.name; | 8946 String prefix = prefixElement.name; |
| 8970 Map<String, Element> newNames = new Map<String, Element>(); | 8947 Map<String, Element> newNames = new Map<String, Element>(); |
| 8971 for (MapEntry<String, Element> entry in getMapEntrySet(definedNames)) { | 8948 for (MapEntry<String, Element> entry in getMapEntrySet(definedNames)) { |
| 8972 newNames["${prefix}.${entry.getKey()}"] = entry.getValue(); | 8949 newNames["${prefix}.${entry.getKey()}"] = entry.getValue(); |
| 8973 } | 8950 } |
| 8974 return newNames; | 8951 return newNames; |
| 8975 } else { | 8952 } else { |
| 8976 return definedNames; | 8953 return definedNames; |
| 8977 } | 8954 } |
| 8978 } | 8955 } |
| 8979 | 8956 |
| 8980 /** | 8957 /** |
| 8981 * Create a mapping table representing the export namespace of the given libra
ry. | 8958 * Create a mapping table representing the export namespace of the given libra
ry. |
| 8982 * @param library the library whose public namespace is to be created | 8959 * @param library the library whose public namespace is to be created |
| 8983 * @param visitedElements a set of libraries that do not need to be visited wh
en processing the | 8960 * @param visitedElements a set of libraries that do not need to be visited wh
en processing the |
| 8984 * export directives of the given library because all of the names defined by
them will | 8961 * export directives of the given library because all of the names defined by
them will |
| 8985 * be added by another library | 8962 * be added by another library |
| 8986 * @return the mapping table that was created | 8963 * @return the mapping table that was created |
| 8987 */ | 8964 */ |
| 8988 Map<String, Element> createExportMapping(LibraryElement library, Set<LibraryEl
ement> visitedElements) { | 8965 Map<String, Element> createExportMapping(LibraryElement library, Set<LibraryEl
ement> visitedElements) { |
| 8989 javaSetAdd(visitedElements, library); | 8966 javaSetAdd(visitedElements, library); |
| 8990 try { | 8967 try { |
| 8991 Map<String, Element> definedNames = new Map<String, Element>(); | 8968 Map<String, Element> definedNames = new Map<String, Element>(); |
| 8992 for (ExportElement element in library.exports) { | 8969 for (ExportElement element in library.exports) { |
| 8993 LibraryElement exportedLibrary2 = element.exportedLibrary; | 8970 LibraryElement exportedLibrary2 = element.exportedLibrary; |
| 8994 if (exportedLibrary2 != null && !visitedElements.contains(exportedLibrar
y2)) { | 8971 if (exportedLibrary2 != null && !visitedElements.contains(exportedLibrar
y2)) { |
| 8995 Map<String, Element> exportedNames = createExportMapping(exportedLibra
ry2, visitedElements); | 8972 Map<String, Element> exportedNames = createExportMapping(exportedLibra
ry2, visitedElements); |
| 8996 exportedNames = apply(exportedNames, element.combinators); | 8973 exportedNames = apply(exportedNames, element.combinators); |
| 8997 addAll(definedNames, exportedNames); | 8974 addAll(definedNames, exportedNames); |
| 8998 } | 8975 } |
| 8999 } | 8976 } |
| 9000 addAll2(definedNames, ((library.context as InternalAnalysisContext)).getPu
blicNamespace(library)); | 8977 addAll2(definedNames, ((library.context as InternalAnalysisContext)).getPu
blicNamespace(library)); |
| 9001 return definedNames; | 8978 return definedNames; |
| 9002 } finally { | 8979 } finally { |
| 9003 visitedElements.remove(library); | 8980 visitedElements.remove(library); |
| 9004 } | 8981 } |
| 9005 } | 8982 } |
| 9006 | 8983 |
| 9007 /** | 8984 /** |
| 9008 * Hide all of the given names by removing them from the given collection of d
efined names. | 8985 * Hide all of the given names by removing them from the given collection of d
efined names. |
| 9009 * @param definedNames the names that were defined before this operation | 8986 * @param definedNames the names that were defined before this operation |
| 9010 * @param hiddenNames the names to be hidden | 8987 * @param hiddenNames the names to be hidden |
| 9011 */ | 8988 */ |
| 9012 void hide(Map<String, Element> definedNames, List<String> hiddenNames) { | 8989 void hide(Map<String, Element> definedNames, List<String> hiddenNames) { |
| 9013 for (String name in hiddenNames) { | 8990 for (String name in hiddenNames) { |
| 9014 definedNames.remove(name); | 8991 definedNames.remove(name); |
| 9015 } | 8992 } |
| 9016 } | 8993 } |
| 9017 | 8994 |
| 9018 /** | 8995 /** |
| 9019 * Show only the given names by removing all other names from the given collec
tion of defined | 8996 * Show only the given names by removing all other names from the given collec
tion of defined |
| 9020 * names. | 8997 * names. |
| 9021 * @param definedNames the names that were defined before this operation | 8998 * @param definedNames the names that were defined before this operation |
| 9022 * @param shownNames the names to be shown | 8999 * @param shownNames the names to be shown |
| 9023 */ | 9000 */ |
| 9024 Map<String, Element> show(Map<String, Element> definedNames, List<String> show
nNames) { | 9001 Map<String, Element> show(Map<String, Element> definedNames, List<String> show
nNames) { |
| 9025 Map<String, Element> newNames = new Map<String, Element>(); | 9002 Map<String, Element> newNames = new Map<String, Element>(); |
| 9026 for (String name in shownNames) { | 9003 for (String name in shownNames) { |
| 9027 Element element = definedNames[name]; | 9004 Element element = definedNames[name]; |
| 9028 if (element != null) { | 9005 if (element != null) { |
| 9029 newNames[name] = element; | 9006 newNames[name] = element; |
| 9030 } | 9007 } |
| 9031 } | 9008 } |
| 9032 return newNames; | 9009 return newNames; |
| 9033 } | 9010 } |
| 9034 } | 9011 } |
| 9035 | |
| 9036 /** | 9012 /** |
| 9037 * The abstract class {@code Scope} defines the behavior common to name scopes u
sed by the resolver | 9013 * The abstract class {@code Scope} defines the behavior common to name scopes u
sed by the resolver |
| 9038 * to determine which names are visible at any given point in the code. | 9014 * to determine which names are visible at any given point in the code. |
| 9039 * @coverage dart.engine.resolver | 9015 * @coverage dart.engine.resolver |
| 9040 */ | 9016 */ |
| 9041 abstract class Scope { | 9017 abstract class Scope { |
| 9042 | 9018 |
| 9043 /** | 9019 /** |
| 9044 * The prefix used to mark an identifier as being private to its library. | 9020 * The prefix used to mark an identifier as being private to its library. |
| 9045 */ | 9021 */ |
| 9046 static String PRIVATE_NAME_PREFIX = "_"; | 9022 static String PRIVATE_NAME_PREFIX = "_"; |
| 9047 | 9023 |
| 9048 /** | 9024 /** |
| 9049 * The suffix added to the declared name of a setter when looking up the sette
r. Used to | 9025 * The suffix added to the declared name of a setter when looking up the sette
r. Used to |
| 9050 * disambiguate between a getter and a setter that have the same name. | 9026 * disambiguate between a getter and a setter that have the same name. |
| 9051 */ | 9027 */ |
| 9052 static String SETTER_SUFFIX = "="; | 9028 static String SETTER_SUFFIX = "="; |
| 9053 | 9029 |
| 9054 /** | 9030 /** |
| 9055 * The name used to look up the method used to implement the unary minus opera
tor. Used to | 9031 * The name used to look up the method used to implement the unary minus opera
tor. Used to |
| 9056 * disambiguate between the unary and binary operators. | 9032 * disambiguate between the unary and binary operators. |
| 9057 */ | 9033 */ |
| 9058 static String UNARY_MINUS = "unary-"; | 9034 static String UNARY_MINUS = "unary-"; |
| 9059 | 9035 |
| 9060 /** | 9036 /** |
| 9061 * Return {@code true} if the given name is a library-private name. | 9037 * Return {@code true} if the given name is a library-private name. |
| 9062 * @param name the name being tested | 9038 * @param name the name being tested |
| 9063 * @return {@code true} if the given name is a library-private name | 9039 * @return {@code true} if the given name is a library-private name |
| 9064 */ | 9040 */ |
| 9065 static bool isPrivateName(String name) => name != null && name.startsWith(PRIV
ATE_NAME_PREFIX); | 9041 static bool isPrivateName(String name) => name != null && name.startsWith(PRIV
ATE_NAME_PREFIX); |
| 9066 | 9042 |
| 9067 /** | 9043 /** |
| 9068 * A table mapping names that are defined in this scope to the element represe
nting the thing | 9044 * A table mapping names that are defined in this scope to the element represe
nting the thing |
| 9069 * declared with that name. | 9045 * declared with that name. |
| 9070 */ | 9046 */ |
| 9071 Map<String, Element> _definedNames = new Map<String, Element>(); | 9047 Map<String, Element> _definedNames = new Map<String, Element>(); |
| 9072 | 9048 |
| 9073 /** | 9049 /** |
| 9074 * Add the given element to this scope. If there is already an element with th
e given name defined | 9050 * Add the given element to this scope. If there is already an element with th
e given name defined |
| 9075 * in this scope, then an error will be generated and the original element wil
l continue to be | 9051 * in this scope, then an error will be generated and the original element wil
l continue to be |
| 9076 * mapped to the name. If there is an element with the given name in an enclos
ing scope, then a | 9052 * mapped to the name. If there is an element with the given name in an enclos
ing scope, then a |
| 9077 * warning will be generated but the given element will hide the inherited ele
ment. | 9053 * warning will be generated but the given element will hide the inherited ele
ment. |
| 9078 * @param element the element to be added to this scope | 9054 * @param element the element to be added to this scope |
| 9079 */ | 9055 */ |
| 9080 void define(Element element) { | 9056 void define(Element element) { |
| 9081 String name = getName(element); | 9057 String name = getName(element); |
| 9082 if (name != null && !name.isEmpty) { | 9058 if (name != null && !name.isEmpty) { |
| 9083 if (_definedNames.containsKey(name)) { | 9059 if (_definedNames.containsKey(name)) { |
| 9084 errorListener.onError(getErrorForDuplicate(_definedNames[name], element)
); | 9060 errorListener.onError(getErrorForDuplicate(_definedNames[name], element)
); |
| 9085 } else { | 9061 } else { |
| 9086 _definedNames[name] = element; | 9062 _definedNames[name] = element; |
| 9087 } | 9063 } |
| 9088 } | 9064 } |
| 9089 } | 9065 } |
| 9090 | 9066 |
| 9091 /** | 9067 /** |
| 9092 * Return the element with which the given identifier is associated, or {@code
null} if the name | 9068 * Return the element with which the given identifier is associated, or {@code
null} if the name |
| 9093 * is not defined within this scope. | 9069 * is not defined within this scope. |
| 9094 * @param identifier the identifier associated with the element to be returned | 9070 * @param identifier the identifier associated with the element to be returned |
| 9095 * @param referencingLibrary the library that contains the reference to the na
me, used to | 9071 * @param referencingLibrary the library that contains the reference to the na
me, used to |
| 9096 * implement library-level privacy | 9072 * implement library-level privacy |
| 9097 * @return the element with which the given identifier is associated | 9073 * @return the element with which the given identifier is associated |
| 9098 */ | 9074 */ |
| 9099 Element lookup(Identifier identifier, LibraryElement referencingLibrary) => lo
okup3(identifier, identifier.name, referencingLibrary); | 9075 Element lookup(Identifier identifier, LibraryElement referencingLibrary) => lo
okup3(identifier, identifier.name, referencingLibrary); |
| 9100 | 9076 |
| 9101 /** | 9077 /** |
| 9102 * Add the given element to this scope without checking for duplication or hid
ing. | 9078 * Add the given element to this scope without checking for duplication or hid
ing. |
| 9103 * @param element the element to be added to this scope | 9079 * @param element the element to be added to this scope |
| 9104 */ | 9080 */ |
| 9105 void defineWithoutChecking(Element element) { | 9081 void defineWithoutChecking(Element element) { |
| 9106 _definedNames[getName(element)] = element; | 9082 _definedNames[getName(element)] = element; |
| 9107 } | 9083 } |
| 9108 | 9084 |
| 9109 /** | 9085 /** |
| 9110 * Add the given element to this scope without checking for duplication or hid
ing. | 9086 * Add the given element to this scope without checking for duplication or hid
ing. |
| 9111 * @param name the name of the element to be added | 9087 * @param name the name of the element to be added |
| 9112 * @param element the element to be added to this scope | 9088 * @param element the element to be added to this scope |
| 9113 */ | 9089 */ |
| 9114 void defineWithoutChecking2(String name, Element element) { | 9090 void defineWithoutChecking2(String name, Element element) { |
| 9115 _definedNames[name] = element; | 9091 _definedNames[name] = element; |
| 9116 } | 9092 } |
| 9117 | 9093 |
| 9118 /** | 9094 /** |
| 9119 * Return the element representing the library in which this scope is enclosed
. | 9095 * Return the element representing the library in which this scope is enclosed
. |
| 9120 * @return the element representing the library in which this scope is enclose
d | 9096 * @return the element representing the library in which this scope is enclose
d |
| 9121 */ | 9097 */ |
| 9122 LibraryElement get definingLibrary; | 9098 LibraryElement get definingLibrary; |
| 9123 | 9099 |
| 9124 /** | 9100 /** |
| 9125 * Return the error code to be used when reporting that a name being defined l
ocally conflicts | 9101 * Return the error code to be used when reporting that a name being defined l
ocally conflicts |
| 9126 * with another element of the same name in the local scope. | 9102 * with another element of the same name in the local scope. |
| 9127 * @param existing the first element to be declared with the conflicting name | 9103 * @param existing the first element to be declared with the conflicting name |
| 9128 * @param duplicate another element declared with the conflicting name | 9104 * @param duplicate another element declared with the conflicting name |
| 9129 * @return the error code used to report duplicate names within a scope | 9105 * @return the error code used to report duplicate names within a scope |
| 9130 */ | 9106 */ |
| 9131 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { | 9107 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { |
| 9132 Source source2 = duplicate.source; | 9108 Source source2 = duplicate.source; |
| 9133 if (source2 == null) { | 9109 if (source2 == null) { |
| 9134 source2 = source; | 9110 source2 = source; |
| 9135 } | 9111 } |
| 9136 return new AnalysisError.con2(source2, duplicate.nameOffset, duplicate.displ
ayName.length, CompileTimeErrorCode.DUPLICATE_DEFINITION, [existing.displayName]
); | 9112 return new AnalysisError.con2(source2, duplicate.nameOffset, duplicate.displ
ayName.length, CompileTimeErrorCode.DUPLICATE_DEFINITION, [existing.displayName]
); |
| 9137 } | 9113 } |
| 9138 | 9114 |
| 9139 /** | 9115 /** |
| 9140 * Return the listener that is to be informed when an error is encountered. | 9116 * Return the listener that is to be informed when an error is encountered. |
| 9141 * @return the listener that is to be informed when an error is encountered | 9117 * @return the listener that is to be informed when an error is encountered |
| 9142 */ | 9118 */ |
| 9143 AnalysisErrorListener get errorListener; | 9119 AnalysisErrorListener get errorListener; |
| 9144 | 9120 |
| 9145 /** | 9121 /** |
| 9146 * Return the source object representing the compilation unit with which error
s related to this | 9122 * Return the source object representing the compilation unit with which error
s related to this |
| 9147 * scope should be associated. | 9123 * scope should be associated. |
| 9148 * @return the source object with which errors should be associated | 9124 * @return the source object with which errors should be associated |
| 9149 */ | 9125 */ |
| 9150 Source get source => definingLibrary.definingCompilationUnit.source; | 9126 Source get source => definingLibrary.definingCompilationUnit.source; |
| 9151 | 9127 |
| 9152 /** | 9128 /** |
| 9153 * Return the element with which the given name is associated, or {@code null}
if the name is not | 9129 * Return the element with which the given name is associated, or {@code null}
if the name is not |
| 9154 * defined within this scope. This method only returns elements that are direc
tly defined within | 9130 * defined within this scope. This method only returns elements that are direc
tly defined within |
| 9155 * this scope, not elements that are defined in an enclosing scope. | 9131 * this scope, not elements that are defined in an enclosing scope. |
| 9156 * @param name the name associated with the element to be returned | 9132 * @param name the name associated with the element to be returned |
| 9157 * @param referencingLibrary the library that contains the reference to the na
me, used to | 9133 * @param referencingLibrary the library that contains the reference to the na
me, used to |
| 9158 * implement library-level privacy | 9134 * implement library-level privacy |
| 9159 * @return the element with which the given name is associated | 9135 * @return the element with which the given name is associated |
| 9160 */ | 9136 */ |
| 9161 Element localLookup(String name, LibraryElement referencingLibrary) => _define
dNames[name]; | 9137 Element localLookup(String name, LibraryElement referencingLibrary) => _define
dNames[name]; |
| 9162 | 9138 |
| 9163 /** | 9139 /** |
| 9164 * Return the element with which the given name is associated, or {@code null}
if the name is not | 9140 * Return the element with which the given name is associated, or {@code null}
if the name is not |
| 9165 * defined within this scope. | 9141 * defined within this scope. |
| 9166 * @param identifier the identifier node to lookup element for, used to report
correct kind of a | 9142 * @param identifier the identifier node to lookup element for, used to report
correct kind of a |
| 9167 * problem and associate problem with | 9143 * problem and associate problem with |
| 9168 * @param name the name associated with the element to be returned | 9144 * @param name the name associated with the element to be returned |
| 9169 * @param referencingLibrary the library that contains the reference to the na
me, used to | 9145 * @param referencingLibrary the library that contains the reference to the na
me, used to |
| 9170 * implement library-level privacy | 9146 * implement library-level privacy |
| 9171 * @return the element with which the given name is associated | 9147 * @return the element with which the given name is associated |
| 9172 */ | 9148 */ |
| 9173 Element lookup3(Identifier identifier, String name, LibraryElement referencing
Library); | 9149 Element lookup3(Identifier identifier, String name, LibraryElement referencing
Library); |
| 9174 | 9150 |
| 9175 /** | 9151 /** |
| 9176 * Return the name that will be used to look up the given element. | 9152 * Return the name that will be used to look up the given element. |
| 9177 * @param element the element whose look-up name is to be returned | 9153 * @param element the element whose look-up name is to be returned |
| 9178 * @return the name that will be used to look up the given element | 9154 * @return the name that will be used to look up the given element |
| 9179 */ | 9155 */ |
| 9180 String getName(Element element) { | 9156 String getName(Element element) { |
| 9181 if (element is MethodElement) { | 9157 if (element is MethodElement) { |
| 9182 MethodElement method = element as MethodElement; | 9158 MethodElement method = element as MethodElement; |
| 9183 if (method.name == "-" && method.parameters.length == 0) { | 9159 if (method.name == "-" && method.parameters.length == 0) { |
| 9184 return UNARY_MINUS; | 9160 return UNARY_MINUS; |
| 9185 } | 9161 } |
| 9186 } | 9162 } |
| 9187 return element.name; | 9163 return element.name; |
| 9188 } | 9164 } |
| 9189 } | 9165 } |
| 9190 | |
| 9191 /** | 9166 /** |
| 9192 * Instances of the class {@code ConstantVerifier} traverse an AST structure loo
king for additional | 9167 * Instances of the class {@code ConstantVerifier} traverse an AST structure loo
king for additional |
| 9193 * errors and warnings not covered by the parser and resolver. In particular, it
looks for errors | 9168 * errors and warnings not covered by the parser and resolver. In particular, it
looks for errors |
| 9194 * and warnings related to constant expressions. | 9169 * and warnings related to constant expressions. |
| 9195 * @coverage dart.engine.resolver | 9170 * @coverage dart.engine.resolver |
| 9196 */ | 9171 */ |
| 9197 class ConstantVerifier extends RecursiveASTVisitor<Object> { | 9172 class ConstantVerifier extends RecursiveASTVisitor<Object> { |
| 9198 | 9173 |
| 9199 /** | 9174 /** |
| 9200 * The error reporter by which errors will be reported. | 9175 * The error reporter by which errors will be reported. |
| 9201 */ | 9176 */ |
| 9202 ErrorReporter _errorReporter; | 9177 ErrorReporter _errorReporter; |
| 9203 | 9178 |
| 9204 /** | 9179 /** |
| 9205 * The type representing the type 'bool'. | 9180 * The type representing the type 'bool'. |
| 9206 */ | 9181 */ |
| 9207 InterfaceType _boolType; | 9182 InterfaceType _boolType; |
| 9208 | 9183 |
| 9209 /** | 9184 /** |
| 9210 * The type representing the type 'int'. | 9185 * The type representing the type 'int'. |
| 9211 */ | 9186 */ |
| 9212 InterfaceType _intType; | 9187 InterfaceType _intType; |
| 9213 | 9188 |
| 9214 /** | 9189 /** |
| 9215 * The type representing the type 'num'. | 9190 * The type representing the type 'num'. |
| 9216 */ | 9191 */ |
| 9217 InterfaceType _numType; | 9192 InterfaceType _numType; |
| 9218 | 9193 |
| 9219 /** | 9194 /** |
| 9220 * The type representing the type 'string'. | 9195 * The type representing the type 'string'. |
| 9221 */ | 9196 */ |
| 9222 InterfaceType _stringType; | 9197 InterfaceType _stringType; |
| 9223 | 9198 |
| 9224 /** | 9199 /** |
| 9225 * Initialize a newly created constant verifier. | 9200 * Initialize a newly created constant verifier. |
| 9226 * @param errorReporter the error reporter by which errors will be reported | 9201 * @param errorReporter the error reporter by which errors will be reported |
| 9227 */ | 9202 */ |
| 9228 ConstantVerifier(ErrorReporter errorReporter, TypeProvider typeProvider) { | 9203 ConstantVerifier(ErrorReporter errorReporter, TypeProvider typeProvider) { |
| 9229 this._errorReporter = errorReporter; | 9204 this._errorReporter = errorReporter; |
| 9230 this._boolType = typeProvider.boolType; | 9205 this._boolType = typeProvider.boolType; |
| 9231 this._intType = typeProvider.intType; | 9206 this._intType = typeProvider.intType; |
| 9232 this._numType = typeProvider.numType; | 9207 this._numType = typeProvider.numType; |
| 9233 this._stringType = typeProvider.stringType; | 9208 this._stringType = typeProvider.stringType; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9314 EvaluationResultImpl result = element2.evaluationResult; | 9289 EvaluationResultImpl result = element2.evaluationResult; |
| 9315 if (result == null) { | 9290 if (result == null) { |
| 9316 result = validate(initializer2, CompileTimeErrorCode.CONST_INITIALIZED_W
ITH_NON_CONSTANT_VALUE); | 9291 result = validate(initializer2, CompileTimeErrorCode.CONST_INITIALIZED_W
ITH_NON_CONSTANT_VALUE); |
| 9317 element2.evaluationResult = result; | 9292 element2.evaluationResult = result; |
| 9318 } else if (result is ErrorResult) { | 9293 } else if (result is ErrorResult) { |
| 9319 reportErrors(result, CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CON
STANT_VALUE); | 9294 reportErrors(result, CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CON
STANT_VALUE); |
| 9320 } | 9295 } |
| 9321 } | 9296 } |
| 9322 return null; | 9297 return null; |
| 9323 } | 9298 } |
| 9324 | 9299 |
| 9325 /** | 9300 /** |
| 9326 * Return {@code true} if the given value is the result of evaluating an expre
ssion whose value is | 9301 * Return {@code true} if the given value is the result of evaluating an expre
ssion whose value is |
| 9327 * a valid key in a const map literal. Keys in const map literals must be eith
er a string, number, | 9302 * a valid key in a const map literal. Keys in const map literals must be eith
er a string, number, |
| 9328 * boolean, list, map, or null. | 9303 * boolean, list, map, or null. |
| 9329 * @param value | 9304 * @param value |
| 9330 * @return {@code true} if the given value is a valid key in a const map liter
al | 9305 * @return {@code true} if the given value is a valid key in a const map liter
al |
| 9331 */ | 9306 */ |
| 9332 bool isValidConstMapKey(Object value) => true; | 9307 bool isValidConstMapKey(Object value) => true; |
| 9333 | 9308 |
| 9334 /** | 9309 /** |
| 9335 * If the given result represents one or more errors, report those errors. Exc
ept for special | 9310 * If the given result represents one or more errors, report those errors. Exc
ept for special |
| 9336 * cases, use the given error code rather than the one reported in the error. | 9311 * cases, use the given error code rather than the one reported in the error. |
| 9337 * @param result the result containing any errors that need to be reported | 9312 * @param result the result containing any errors that need to be reported |
| 9338 * @param errorCode the error code to be used if the result represents an erro
r | 9313 * @param errorCode the error code to be used if the result represents an erro
r |
| 9339 */ | 9314 */ |
| 9340 void reportErrors(EvaluationResultImpl result, ErrorCode errorCode2) { | 9315 void reportErrors(EvaluationResultImpl result, ErrorCode errorCode2) { |
| 9341 if (result is ErrorResult) { | 9316 if (result is ErrorResult) { |
| 9342 for (ErrorResult_ErrorData data in ((result as ErrorResult)).errorData) { | 9317 for (ErrorResult_ErrorData data in ((result as ErrorResult)).errorData) { |
| 9343 ErrorCode dataErrorCode = data.errorCode; | 9318 ErrorCode dataErrorCode = data.errorCode; |
| 9344 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)) { | 9319 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)) { |
| 9345 _errorReporter.reportError2(dataErrorCode, data.node, []); | 9320 _errorReporter.reportError2(dataErrorCode, data.node, []); |
| 9346 } else { | 9321 } else { |
| 9347 _errorReporter.reportError2(errorCode2, data.node, []); | 9322 _errorReporter.reportError2(errorCode2, data.node, []); |
| 9348 } | 9323 } |
| 9349 } | 9324 } |
| 9350 } | 9325 } |
| 9351 } | 9326 } |
| 9352 | 9327 |
| 9353 /** | 9328 /** |
| 9354 * Validate that the given expression is a compile time constant. Return the v
alue of the compile | 9329 * Validate that the given expression is a compile time constant. Return the v
alue of the compile |
| 9355 * time constant, or {@code null} if the expression is not a compile time cons
tant. | 9330 * time constant, or {@code null} if the expression is not a compile time cons
tant. |
| 9356 * @param expression the expression to be validated | 9331 * @param expression the expression to be validated |
| 9357 * @param errorCode the error code to be used if the expression is not a compi
le time constant | 9332 * @param errorCode the error code to be used if the expression is not a compi
le time constant |
| 9358 * @return the value of the compile time constant | 9333 * @return the value of the compile time constant |
| 9359 */ | 9334 */ |
| 9360 EvaluationResultImpl validate(Expression expression, ErrorCode errorCode) { | 9335 EvaluationResultImpl validate(Expression expression, ErrorCode errorCode) { |
| 9361 EvaluationResultImpl result = expression.accept(new ConstantVisitor()); | 9336 EvaluationResultImpl result = expression.accept(new ConstantVisitor()); |
| 9362 reportErrors(result, errorCode); | 9337 reportErrors(result, errorCode); |
| 9363 return result; | 9338 return result; |
| 9364 } | 9339 } |
| 9365 | 9340 |
| 9366 /** | 9341 /** |
| 9367 * Validate that if the passed instance creation is 'const' then all its argum
ents are constant | 9342 * Validate that if the passed instance creation is 'const' then all its argum
ents are constant |
| 9368 * expressions. | 9343 * expressions. |
| 9369 * @param node the instance creation evaluate | 9344 * @param node the instance creation evaluate |
| 9370 */ | 9345 */ |
| 9371 void validateConstantArguments(InstanceCreationExpression node) { | 9346 void validateConstantArguments(InstanceCreationExpression node) { |
| 9372 if (!node.isConst()) { | 9347 if (!node.isConst()) { |
| 9373 return; | 9348 return; |
| 9374 } | 9349 } |
| 9375 ArgumentList argumentList2 = node.argumentList; | 9350 ArgumentList argumentList2 = node.argumentList; |
| 9376 if (argumentList2 == null) { | 9351 if (argumentList2 == null) { |
| 9377 return; | 9352 return; |
| 9378 } | 9353 } |
| 9379 for (Expression argument in argumentList2.arguments) { | 9354 for (Expression argument in argumentList2.arguments) { |
| 9380 if (argument is NamedExpression) { | 9355 if (argument is NamedExpression) { |
| 9381 argument = ((argument as NamedExpression)).expression; | 9356 argument = ((argument as NamedExpression)).expression; |
| 9382 } | 9357 } |
| 9383 validate(argument, CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT); | 9358 validate(argument, CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT); |
| 9384 } | 9359 } |
| 9385 } | 9360 } |
| 9386 | 9361 |
| 9387 /** | 9362 /** |
| 9388 * Validate that the default value associated with each of the parameters in t
he given list is a | 9363 * Validate that the default value associated with each of the parameters in t
he given list is a |
| 9389 * compile time constant. | 9364 * compile time constant. |
| 9390 * @param parameters the list of parameters to be validated | 9365 * @param parameters the list of parameters to be validated |
| 9391 */ | 9366 */ |
| 9392 void validateDefaultValues(FormalParameterList parameters2) { | 9367 void validateDefaultValues(FormalParameterList parameters2) { |
| 9393 if (parameters2 == null) { | 9368 if (parameters2 == null) { |
| 9394 return; | 9369 return; |
| 9395 } | 9370 } |
| 9396 for (FormalParameter parameter in parameters2.parameters) { | 9371 for (FormalParameter parameter in parameters2.parameters) { |
| 9397 if (parameter is DefaultFormalParameter) { | 9372 if (parameter is DefaultFormalParameter) { |
| 9398 DefaultFormalParameter defaultParameter = parameter as DefaultFormalPara
meter; | 9373 DefaultFormalParameter defaultParameter = parameter as DefaultFormalPara
meter; |
| 9399 Expression defaultValue2 = defaultParameter.defaultValue; | 9374 Expression defaultValue2 = defaultParameter.defaultValue; |
| 9400 if (defaultValue2 != null) { | 9375 if (defaultValue2 != null) { |
| 9401 EvaluationResultImpl result = validate(defaultValue2, CompileTimeError
Code.NON_CONSTANT_DEFAULT_VALUE); | 9376 EvaluationResultImpl result = validate(defaultValue2, CompileTimeError
Code.NON_CONSTANT_DEFAULT_VALUE); |
| 9402 if (defaultParameter.isConst()) { | 9377 if (defaultParameter.isConst()) { |
| 9403 VariableElementImpl element2 = parameter.element as VariableElementI
mpl; | 9378 VariableElementImpl element2 = parameter.element as VariableElementI
mpl; |
| 9404 element2.evaluationResult = result; | 9379 element2.evaluationResult = result; |
| 9405 } | 9380 } |
| 9406 } | 9381 } |
| 9407 } | 9382 } |
| 9408 } | 9383 } |
| 9409 } | 9384 } |
| 9410 | 9385 |
| 9411 /** | 9386 /** |
| 9412 * Validates that the given expression is a compile time constant. | 9387 * Validates that the given expression is a compile time constant. |
| 9413 * @param parameterElements the elements of parameters of constant constructor
, they are | 9388 * @param parameterElements the elements of parameters of constant constructor
, they are |
| 9414 * considered as a valid potentially constant expressions | 9389 * considered as a valid potentially constant expressions |
| 9415 * @param expression the expression to validate | 9390 * @param expression the expression to validate |
| 9416 */ | 9391 */ |
| 9417 void validateInitializerExpression(List<ParameterElement> parameterElements, E
xpression expression) { | 9392 void validateInitializerExpression(List<ParameterElement> parameterElements, E
xpression expression) { |
| 9418 EvaluationResultImpl result = expression.accept(new ConstantVisitor_10(this,
parameterElements)); | 9393 EvaluationResultImpl result = expression.accept(new ConstantVisitor_10(this,
parameterElements)); |
| 9419 reportErrors(result, CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER)
; | 9394 reportErrors(result, CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER)
; |
| 9420 } | 9395 } |
| 9421 | 9396 |
| 9422 /** | 9397 /** |
| 9423 * Validates that all of the arguments of a constructor initializer are compil
e time constants. | 9398 * Validates that all of the arguments of a constructor initializer are compil
e time constants. |
| 9424 * @param parameterElements the elements of parameters of constant constructor
, they are | 9399 * @param parameterElements the elements of parameters of constant constructor
, they are |
| 9425 * considered as a valid potentially constant expressions | 9400 * considered as a valid potentially constant expressions |
| 9426 * @param argumentList the argument list to validate | 9401 * @param argumentList the argument list to validate |
| 9427 */ | 9402 */ |
| 9428 void validateInitializerInvocationArguments(List<ParameterElement> parameterEl
ements, ArgumentList argumentList) { | 9403 void validateInitializerInvocationArguments(List<ParameterElement> parameterEl
ements, ArgumentList argumentList) { |
| 9429 if (argumentList == null) { | 9404 if (argumentList == null) { |
| 9430 return; | 9405 return; |
| 9431 } | 9406 } |
| 9432 for (Expression argument in argumentList.arguments) { | 9407 for (Expression argument in argumentList.arguments) { |
| 9433 validateInitializerExpression(parameterElements, argument); | 9408 validateInitializerExpression(parameterElements, argument); |
| 9434 } | 9409 } |
| 9435 } | 9410 } |
| 9436 | 9411 |
| 9437 /** | 9412 /** |
| 9438 * Validates that the expressions of the given initializers (of a constant con
structor) are all | 9413 * Validates that the expressions of the given initializers (of a constant con
structor) are all |
| 9439 * compile time constants. | 9414 * compile time constants. |
| 9440 * @param constructor the constant constructor declaration to validate | 9415 * @param constructor the constant constructor declaration to validate |
| 9441 */ | 9416 */ |
| 9442 void validateInitializers(ConstructorDeclaration constructor) { | 9417 void validateInitializers(ConstructorDeclaration constructor) { |
| 9443 List<ParameterElement> parameterElements = constructor.parameters.elements; | 9418 List<ParameterElement> parameterElements = constructor.parameters.elements; |
| 9444 NodeList<ConstructorInitializer> initializers2 = constructor.initializers; | 9419 NodeList<ConstructorInitializer> initializers2 = constructor.initializers; |
| 9445 for (ConstructorInitializer initializer in initializers2) { | 9420 for (ConstructorInitializer initializer in initializers2) { |
| 9446 if (initializer is ConstructorFieldInitializer) { | 9421 if (initializer is ConstructorFieldInitializer) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9483 if (type2.isSubtypeOf(ConstantVerifier_this._stringType)) { | 9458 if (type2.isSubtypeOf(ConstantVerifier_this._stringType)) { |
| 9484 return ValidResult.RESULT_STRING; | 9459 return ValidResult.RESULT_STRING; |
| 9485 } | 9460 } |
| 9486 } | 9461 } |
| 9487 return ValidResult.RESULT_OBJECT; | 9462 return ValidResult.RESULT_OBJECT; |
| 9488 } | 9463 } |
| 9489 } | 9464 } |
| 9490 return super.visitSimpleIdentifier(node); | 9465 return super.visitSimpleIdentifier(node); |
| 9491 } | 9466 } |
| 9492 } | 9467 } |
| 9493 | |
| 9494 /** | 9468 /** |
| 9495 * Instances of the class {@code ErrorVerifier} traverse an AST structure lookin
g for additional | 9469 * Instances of the class {@code ErrorVerifier} traverse an AST structure lookin
g for additional |
| 9496 * errors and warnings not covered by the parser and resolver. | 9470 * errors and warnings not covered by the parser and resolver. |
| 9497 * @coverage dart.engine.resolver | 9471 * @coverage dart.engine.resolver |
| 9498 */ | 9472 */ |
| 9499 class ErrorVerifier extends RecursiveASTVisitor<Object> { | 9473 class ErrorVerifier extends RecursiveASTVisitor<Object> { |
| 9500 | 9474 |
| 9501 /** | 9475 /** |
| 9502 * Checks if the given expression is the reference to the type. | 9476 * Checks if the given expression is the reference to the type. |
| 9503 * @param expr the expression to evaluate | 9477 * @param expr the expression to evaluate |
| 9504 * @return {@code true} if the given expression is the reference to the type | 9478 * @return {@code true} if the given expression is the reference to the type |
| 9505 */ | 9479 */ |
| 9506 static bool isTypeReference(Expression expr) { | 9480 static bool isTypeReference(Expression expr) { |
| 9507 if (expr is Identifier) { | 9481 if (expr is Identifier) { |
| 9508 Identifier identifier = expr as Identifier; | 9482 Identifier identifier = expr as Identifier; |
| 9509 return identifier.element is ClassElement; | 9483 return identifier.element is ClassElement; |
| 9510 } | 9484 } |
| 9511 return false; | 9485 return false; |
| 9512 } | 9486 } |
| 9513 | 9487 |
| 9514 /** | 9488 /** |
| 9515 * The error reporter by which errors will be reported. | 9489 * The error reporter by which errors will be reported. |
| 9516 */ | 9490 */ |
| 9517 ErrorReporter _errorReporter; | 9491 ErrorReporter _errorReporter; |
| 9518 | 9492 |
| 9519 /** | 9493 /** |
| 9520 * The current library that is being analyzed. | 9494 * The current library that is being analyzed. |
| 9521 */ | 9495 */ |
| 9522 LibraryElement _currentLibrary; | 9496 LibraryElement _currentLibrary; |
| 9523 | 9497 |
| 9524 /** | 9498 /** |
| 9525 * The type representing the type 'dynamic'. | 9499 * The type representing the type 'dynamic'. |
| 9526 */ | 9500 */ |
| 9527 Type2 _dynamicType; | 9501 Type2 _dynamicType; |
| 9528 | 9502 |
| 9529 /** | 9503 /** |
| 9530 * The object providing access to the types defined by the language. | 9504 * The object providing access to the types defined by the language. |
| 9531 */ | 9505 */ |
| 9532 TypeProvider _typeProvider; | 9506 TypeProvider _typeProvider; |
| 9533 | 9507 |
| 9534 /** | 9508 /** |
| 9535 * The manager for the inheritance mappings. | 9509 * The manager for the inheritance mappings. |
| 9536 */ | 9510 */ |
| 9537 InheritanceManager _inheritanceManager; | 9511 InheritanceManager _inheritanceManager; |
| 9538 | 9512 |
| 9513 /** |
| 9514 * A flag indicating whether we are running in strict mode. In strict mode, er
ror reporting is |
| 9515 * based exclusively on the static type information. |
| 9516 */ |
| 9517 bool _strictMode = false; |
| 9518 |
| 9539 /** | 9519 /** |
| 9540 * This is set to {@code true} iff the visitor is currently visiting children
nodes of a{@link ConstructorDeclaration} and the constructor is 'const'. | 9520 * This is set to {@code true} iff the visitor is currently visiting children
nodes of a{@link ConstructorDeclaration} and the constructor is 'const'. |
| 9541 * @see #visitConstructorDeclaration(ConstructorDeclaration) | 9521 * @see #visitConstructorDeclaration(ConstructorDeclaration) |
| 9542 */ | 9522 */ |
| 9543 bool _isEnclosingConstructorConst = false; | 9523 bool _isEnclosingConstructorConst = false; |
| 9544 | 9524 |
| 9545 /** | 9525 /** |
| 9546 * This is set to {@code true} iff the visitor is currently visiting children
nodes of a{@link CatchClause}. | 9526 * This is set to {@code true} iff the visitor is currently visiting children
nodes of a{@link CatchClause}. |
| 9547 * @see #visitCatchClause(CatchClause) | 9527 * @see #visitCatchClause(CatchClause) |
| 9548 */ | 9528 */ |
| 9549 bool _isInCatchClause = false; | 9529 bool _isInCatchClause = false; |
| 9550 | 9530 |
| 9551 /** | 9531 /** |
| 9552 * This is set to {@code true} iff the visitor is currently visiting a{@link C
onstructorInitializer}. | 9532 * This is set to {@code true} iff the visitor is currently visiting a{@link C
onstructorInitializer}. |
| 9553 */ | 9533 */ |
| 9554 bool _isInConstructorInitializer = false; | 9534 bool _isInConstructorInitializer = false; |
| 9555 | 9535 |
| 9556 /** | 9536 /** |
| 9557 * This is set to {@code true} iff the visitor is currently visiting code in t
he SDK. | 9537 * This is set to {@code true} iff the visitor is currently visiting code in t
he SDK. |
| 9558 */ | 9538 */ |
| 9559 bool _isInSystemLibrary = false; | 9539 bool _isInSystemLibrary = false; |
| 9560 | 9540 |
| 9561 /** | 9541 /** |
| 9562 * The class containing the AST nodes being visited, or {@code null} if we are
not in the scope of | 9542 * The class containing the AST nodes being visited, or {@code null} if we are
not in the scope of |
| 9563 * a class. | 9543 * a class. |
| 9564 */ | 9544 */ |
| 9565 ClassElement _enclosingClass; | 9545 ClassElement _enclosingClass; |
| 9566 | 9546 |
| 9567 /** | 9547 /** |
| 9568 * The method or function that we are currently visiting, or {@code null} if w
e are not inside a | 9548 * The method or function that we are currently visiting, or {@code null} if w
e are not inside a |
| 9569 * method or function. | 9549 * method or function. |
| 9570 */ | 9550 */ |
| 9571 ExecutableElement _enclosingFunction; | 9551 ExecutableElement _enclosingFunction; |
| 9572 | 9552 |
| 9573 /** | 9553 /** |
| 9574 * This map is initialized when visiting the contents of a class declaration.
If the visitor is | 9554 * This map is initialized when visiting the contents of a class declaration.
If the visitor is |
| 9575 * not in an enclosing class declaration, then the map is set to {@code null}. | 9555 * not in an enclosing class declaration, then the map is set to {@code null}. |
| 9576 * <p> | 9556 * <p> |
| 9577 * When set the map maps the set of {@link FieldElement}s in the class to an{@
link INIT_STATE#NOT_INIT} or {@link INIT_STATE#INIT_IN_DECLARATION}. <code>check
For*</code> | 9557 * When set the map maps the set of {@link FieldElement}s in the class to an{@
link INIT_STATE#NOT_INIT} or {@link INIT_STATE#INIT_IN_DECLARATION}. <code>check
For*</code> |
| 9578 * methods, specifically {@link #checkForAllFinalInitializedErrorCodes(Constru
ctorDeclaration)}, | 9558 * methods, specifically {@link #checkForAllFinalInitializedErrorCodes(Constru
ctorDeclaration)}, |
| 9579 * can make a copy of the map to compute error code states. <code>checkFor*</c
ode> methods should | 9559 * can make a copy of the map to compute error code states. <code>checkFor*</c
ode> methods should |
| 9580 * only ever make a copy, or read from this map after it has been set in{@link
#visitClassDeclaration(ClassDeclaration)}. | 9560 * only ever make a copy, or read from this map after it has been set in{@link
#visitClassDeclaration(ClassDeclaration)}. |
| 9581 * @see #visitClassDeclaration(ClassDeclaration) | 9561 * @see #visitClassDeclaration(ClassDeclaration) |
| 9582 * @see #checkForAllFinalInitializedErrorCodes(ConstructorDeclaration) | 9562 * @see #checkForAllFinalInitializedErrorCodes(ConstructorDeclaration) |
| 9583 */ | 9563 */ |
| 9584 Map<FieldElement, INIT_STATE> _initialFieldElementsMap; | 9564 Map<FieldElement, INIT_STATE> _initialFieldElementsMap; |
| 9585 | 9565 |
| 9586 /** | 9566 /** |
| 9587 * A table mapping name of the library to the export directive which export th
is library. | 9567 * A table mapping name of the library to the export directive which export th
is library. |
| 9588 */ | 9568 */ |
| 9589 Map<String, LibraryElement> _nameToExportElement = new Map<String, LibraryElem
ent>(); | 9569 Map<String, LibraryElement> _nameToExportElement = new Map<String, LibraryElem
ent>(); |
| 9590 | 9570 |
| 9591 /** | 9571 /** |
| 9592 * A table mapping name of the library to the import directive which import th
is library. | 9572 * A table mapping name of the library to the import directive which import th
is library. |
| 9593 */ | 9573 */ |
| 9594 Map<String, LibraryElement> _nameToImportElement = new Map<String, LibraryElem
ent>(); | 9574 Map<String, LibraryElement> _nameToImportElement = new Map<String, LibraryElem
ent>(); |
| 9595 | 9575 |
| 9596 /** | 9576 /** |
| 9597 * A table mapping names to the export elements exported them. | 9577 * A table mapping names to the export elements exported them. |
| 9598 */ | 9578 */ |
| 9599 Map<String, ExportElement> _exportedNames = new Map<String, ExportElement>(); | 9579 Map<String, ExportElement> _exportedNames = new Map<String, ExportElement>(); |
| 9600 | 9580 |
| 9601 /** | 9581 /** |
| 9602 * A set of the names of the variable initializers we are visiting now. | 9582 * A set of the names of the variable initializers we are visiting now. |
| 9603 */ | 9583 */ |
| 9604 Set<String> _namesForReferenceToDeclaredVariableInInitializer = new Set<String
>(); | 9584 Set<String> _namesForReferenceToDeclaredVariableInInitializer = new Set<String
>(); |
| 9605 | 9585 |
| 9606 /** | 9586 /** |
| 9607 * A list of types used by the {@link CompileTimeErrorCode#EXTENDS_DISALLOWED_
CLASS} and{@link CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS} error codes. | 9587 * A list of types used by the {@link CompileTimeErrorCode#EXTENDS_DISALLOWED_
CLASS} and{@link CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS} error codes. |
| 9608 */ | 9588 */ |
| 9609 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT; | 9589 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT; |
| 9610 ErrorVerifier(ErrorReporter errorReporter, LibraryElement currentLibrary, Type
Provider typeProvider, InheritanceManager inheritanceManager) { | 9590 ErrorVerifier(ErrorReporter errorReporter, LibraryElement currentLibrary, Type
Provider typeProvider, InheritanceManager inheritanceManager) { |
| 9611 this._errorReporter = errorReporter; | 9591 this._errorReporter = errorReporter; |
| 9612 this._currentLibrary = currentLibrary; | 9592 this._currentLibrary = currentLibrary; |
| 9613 this._isInSystemLibrary = currentLibrary.source.isInSystemLibrary(); | 9593 this._isInSystemLibrary = currentLibrary.source.isInSystemLibrary(); |
| 9614 this._typeProvider = typeProvider; | 9594 this._typeProvider = typeProvider; |
| 9615 this._inheritanceManager = inheritanceManager; | 9595 this._inheritanceManager = inheritanceManager; |
| 9596 _strictMode = currentLibrary.context.analysisOptions.strictMode; |
| 9616 _isEnclosingConstructorConst = false; | 9597 _isEnclosingConstructorConst = false; |
| 9617 _isInCatchClause = false; | 9598 _isInCatchClause = false; |
| 9618 _dynamicType = typeProvider.dynamicType; | 9599 _dynamicType = typeProvider.dynamicType; |
| 9619 _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT = <InterfaceType> [typeProvider.num
Type, typeProvider.intType, typeProvider.doubleType, typeProvider.boolType, type
Provider.stringType]; | 9600 _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT = <InterfaceType> [typeProvider.num
Type, typeProvider.intType, typeProvider.doubleType, typeProvider.boolType, type
Provider.stringType]; |
| 9620 } | 9601 } |
| 9621 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) { | 9602 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) { |
| 9622 checkForArgumentDefinitionTestNonParameter(node); | 9603 checkForArgumentDefinitionTestNonParameter(node); |
| 9623 return super.visitArgumentDefinitionTest(node); | 9604 return super.visitArgumentDefinitionTest(node); |
| 9624 } | 9605 } |
| 9625 Object visitArgumentList(ArgumentList node) { | 9606 Object visitArgumentList(ArgumentList node) { |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9983 return super.visitVariableDeclarationList(node); | 9964 return super.visitVariableDeclarationList(node); |
| 9984 } | 9965 } |
| 9985 Object visitVariableDeclarationStatement(VariableDeclarationStatement node) { | 9966 Object visitVariableDeclarationStatement(VariableDeclarationStatement node) { |
| 9986 checkForFinalNotInitialized2(node.variables); | 9967 checkForFinalNotInitialized2(node.variables); |
| 9987 return super.visitVariableDeclarationStatement(node); | 9968 return super.visitVariableDeclarationStatement(node); |
| 9988 } | 9969 } |
| 9989 Object visitWhileStatement(WhileStatement node) { | 9970 Object visitWhileStatement(WhileStatement node) { |
| 9990 checkForNonBoolCondition(node.condition); | 9971 checkForNonBoolCondition(node.condition); |
| 9991 return super.visitWhileStatement(node); | 9972 return super.visitWhileStatement(node); |
| 9992 } | 9973 } |
| 9993 | 9974 |
| 9994 /** | 9975 /** |
| 9995 * This verifies that the passed constructor declaration does not violate any
of the error codes | 9976 * This verifies that the passed constructor declaration does not violate any
of the error codes |
| 9996 * relating to the initialization of fields in the enclosing class. | 9977 * relating to the initialization of fields in the enclosing class. |
| 9997 * @param node the {@link ConstructorDeclaration} to evaluate | 9978 * @param node the {@link ConstructorDeclaration} to evaluate |
| 9998 * @return {@code true} if and only if an error code is generated on the passe
d node | 9979 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 9999 * @see #initialFieldElementsMap | 9980 * @see #initialFieldElementsMap |
| 10000 * @see CompileTimeErrorCode#FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR | 9981 * @see CompileTimeErrorCode#FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR |
| 10001 * @see CompileTimeErrorCode#FINAL_INITIALIZED_MULTIPLE_TIMES | 9982 * @see CompileTimeErrorCode#FINAL_INITIALIZED_MULTIPLE_TIMES |
| 10002 */ | 9983 */ |
| 10003 bool checkForAllFinalInitializedErrorCodes(ConstructorDeclaration node) { | 9984 bool checkForAllFinalInitializedErrorCodes(ConstructorDeclaration node) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10051 foundError = true; | 10032 foundError = true; |
| 10052 } else if (identical(state, INIT_STATE.INIT_IN_INITIALIZERS)) { | 10033 } else if (identical(state, INIT_STATE.INIT_IN_INITIALIZERS)) { |
| 10053 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZED_B
Y_MULTIPLE_INITIALIZERS, fieldName2, [fieldElement.displayName]); | 10034 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZED_B
Y_MULTIPLE_INITIALIZERS, fieldName2, [fieldElement.displayName]); |
| 10054 foundError = true; | 10035 foundError = true; |
| 10055 } | 10036 } |
| 10056 } | 10037 } |
| 10057 } | 10038 } |
| 10058 } | 10039 } |
| 10059 return foundError; | 10040 return foundError; |
| 10060 } | 10041 } |
| 10061 | 10042 |
| 10062 /** | 10043 /** |
| 10063 * This checks the passed method declaration against override-error codes. | 10044 * This checks the passed method declaration against override-error codes. |
| 10064 * @param node the {@link MethodDeclaration} to evaluate | 10045 * @param node the {@link MethodDeclaration} to evaluate |
| 10065 * @return {@code true} if and only if an error code is generated on the passe
d node | 10046 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10066 * @see StaticWarningCode#INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC | 10047 * @see StaticWarningCode#INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC |
| 10067 * @see CompileTimeErrorCode#INVALID_OVERRIDE_REQUIRED | 10048 * @see CompileTimeErrorCode#INVALID_OVERRIDE_REQUIRED |
| 10068 * @see CompileTimeErrorCode#INVALID_OVERRIDE_POSITIONAL | 10049 * @see CompileTimeErrorCode#INVALID_OVERRIDE_POSITIONAL |
| 10069 * @see CompileTimeErrorCode#INVALID_OVERRIDE_NAMED | 10050 * @see CompileTimeErrorCode#INVALID_OVERRIDE_NAMED |
| 10070 * @see StaticWarningCode#INVALID_GETTER_OVERRIDE_RETURN_TYPE | 10051 * @see StaticWarningCode#INVALID_GETTER_OVERRIDE_RETURN_TYPE |
| 10071 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_RETURN_TYPE | 10052 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_RETURN_TYPE |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10198 } | 10179 } |
| 10199 } | 10180 } |
| 10200 if (parameterToSelect != null) { | 10181 if (parameterToSelect != null) { |
| 10201 _errorReporter.reportError2(StaticWarningCode.INVALID_METHOD_OVERRIDE_
NAMED_PARAM_TYPE, parameterToSelect, [overridingType.displayName, overriddenName
dPTEntry.getValue().displayName, overriddenExecutable.enclosingElement.displayNa
me]); | 10182 _errorReporter.reportError2(StaticWarningCode.INVALID_METHOD_OVERRIDE_
NAMED_PARAM_TYPE, parameterToSelect, [overridingType.displayName, overriddenName
dPTEntry.getValue().displayName, overriddenExecutable.enclosingElement.displayNa
me]); |
| 10202 return true; | 10183 return true; |
| 10203 } | 10184 } |
| 10204 } | 10185 } |
| 10205 } | 10186 } |
| 10206 return false; | 10187 return false; |
| 10207 } | 10188 } |
| 10208 | 10189 |
| 10209 /** | 10190 /** |
| 10210 * This verifies that all classes of the passed 'with' clause are valid. | 10191 * This verifies that all classes of the passed 'with' clause are valid. |
| 10211 * @param node the 'with' clause to evaluate | 10192 * @param node the 'with' clause to evaluate |
| 10212 * @return {@code true} if and only if an error code is generated on the passe
d node | 10193 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10213 * @see CompileTimeErrorCode#MIXIN_DECLARES_CONSTRUCTOR | 10194 * @see CompileTimeErrorCode#MIXIN_DECLARES_CONSTRUCTOR |
| 10214 * @see CompileTimeErrorCode#MIXIN_INHERITS_FROM_NOT_OBJECT | 10195 * @see CompileTimeErrorCode#MIXIN_INHERITS_FROM_NOT_OBJECT |
| 10215 * @see CompileTimeErrorCode#MIXIN_REFERENCES_SUPER | 10196 * @see CompileTimeErrorCode#MIXIN_REFERENCES_SUPER |
| 10216 */ | 10197 */ |
| 10217 bool checkForAllMixinErrorCodes(WithClause withClause) { | 10198 bool checkForAllMixinErrorCodes(WithClause withClause) { |
| 10218 if (withClause == null) { | 10199 if (withClause == null) { |
| 10219 return false; | 10200 return false; |
| 10220 } | 10201 } |
| 10221 bool problemReported = false; | 10202 bool problemReported = false; |
| 10222 for (TypeName mixinName in withClause.mixinTypes) { | 10203 for (TypeName mixinName in withClause.mixinTypes) { |
| 10223 Type2 mixinType = mixinName.type; | 10204 Type2 mixinType = mixinName.type; |
| 10224 if (mixinType is! InterfaceType) { | 10205 if (mixinType is! InterfaceType) { |
| 10225 continue; | 10206 continue; |
| 10226 } | 10207 } |
| 10227 ClassElement mixinElement = ((mixinType as InterfaceType)).element; | 10208 ClassElement mixinElement = ((mixinType as InterfaceType)).element; |
| 10228 problemReported = javaBooleanOr(problemReported, checkForMixinDeclaresCons
tructor(mixinName, mixinElement)); | 10209 problemReported = javaBooleanOr(problemReported, checkForMixinDeclaresCons
tructor(mixinName, mixinElement)); |
| 10229 problemReported = javaBooleanOr(problemReported, checkForMixinInheritsNotF
romObject(mixinName, mixinElement)); | 10210 problemReported = javaBooleanOr(problemReported, checkForMixinInheritsNotF
romObject(mixinName, mixinElement)); |
| 10230 problemReported = javaBooleanOr(problemReported, checkForMixinReferencesSu
per(mixinName, mixinElement)); | 10211 problemReported = javaBooleanOr(problemReported, checkForMixinReferencesSu
per(mixinName, mixinElement)); |
| 10231 } | 10212 } |
| 10232 return problemReported; | 10213 return problemReported; |
| 10233 } | 10214 } |
| 10234 | 10215 |
| 10235 /** | 10216 /** |
| 10236 * This checks that the return statement of the form <i>return e;</i> is not i
n a generative | 10217 * This checks that the return statement of the form <i>return e;</i> is not i
n a generative |
| 10237 * constructor. | 10218 * constructor. |
| 10238 * <p> | 10219 * <p> |
| 10239 * This checks that return statements without expressions are not in a generat
ive constructor and | 10220 * This checks that return statements without expressions are not in a generat
ive constructor and |
| 10240 * the return type is not assignable to {@code null}; that is, we don't have {
@code return;} if | 10221 * the return type is not assignable to {@code null}; that is, we don't have {
@code return;} if |
| 10241 * the enclosing method has a return type. | 10222 * the enclosing method has a return type. |
| 10242 * <p> | 10223 * <p> |
| 10243 * This checks that the return type matches the type of the declared return ty
pe in the enclosing | 10224 * This checks that the return type matches the type of the declared return ty
pe in the enclosing |
| 10244 * method or function. | 10225 * method or function. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 10270 Type2 staticReturnType = getStaticType(returnExpression); | 10251 Type2 staticReturnType = getStaticType(returnExpression); |
| 10271 if (expectedReturnType.isVoid()) { | 10252 if (expectedReturnType.isVoid()) { |
| 10272 if (staticReturnType.isVoid() || staticReturnType.isDynamic() || identical
(staticReturnType, BottomTypeImpl.instance)) { | 10253 if (staticReturnType.isVoid() || staticReturnType.isDynamic() || identical
(staticReturnType, BottomTypeImpl.instance)) { |
| 10273 return false; | 10254 return false; |
| 10274 } | 10255 } |
| 10275 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
returnExpression, [staticReturnType.displayName, expectedReturnType.displayName,
_enclosingFunction.displayName]); | 10256 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
returnExpression, [staticReturnType.displayName, expectedReturnType.displayName,
_enclosingFunction.displayName]); |
| 10276 return true; | 10257 return true; |
| 10277 } | 10258 } |
| 10278 bool isStaticAssignable = staticReturnType.isAssignableTo(expectedReturnType
); | 10259 bool isStaticAssignable = staticReturnType.isAssignableTo(expectedReturnType
); |
| 10279 Type2 propagatedReturnType = getPropagatedType(returnExpression); | 10260 Type2 propagatedReturnType = getPropagatedType(returnExpression); |
| 10280 if (propagatedReturnType == null) { | 10261 if (_strictMode || propagatedReturnType == null) { |
| 10281 if (isStaticAssignable) { | 10262 if (isStaticAssignable) { |
| 10282 return false; | 10263 return false; |
| 10283 } | 10264 } |
| 10284 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
returnExpression, [staticReturnType.displayName, expectedReturnType.displayName,
_enclosingFunction.displayName]); | 10265 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
returnExpression, [staticReturnType.displayName, expectedReturnType.displayName,
_enclosingFunction.displayName]); |
| 10285 return true; | 10266 return true; |
| 10286 } else { | 10267 } else { |
| 10287 bool isPropagatedAssignable = propagatedReturnType.isAssignableTo(expected
ReturnType); | 10268 bool isPropagatedAssignable = propagatedReturnType.isAssignableTo(expected
ReturnType); |
| 10288 if (isStaticAssignable || isPropagatedAssignable) { | 10269 if (isStaticAssignable || isPropagatedAssignable) { |
| 10289 return false; | 10270 return false; |
| 10290 } | 10271 } |
| 10291 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
returnExpression, [staticReturnType.displayName, expectedReturnType.displayName,
_enclosingFunction.displayName]); | 10272 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
returnExpression, [staticReturnType.displayName, expectedReturnType.displayName,
_enclosingFunction.displayName]); |
| 10292 return true; | 10273 return true; |
| 10293 } | 10274 } |
| 10294 } | 10275 } |
| 10295 | 10276 |
| 10296 /** | 10277 /** |
| 10297 * This verifies that the export namespace of the passed export directive does
not export any name | 10278 * This verifies that the export namespace of the passed export directive does
not export any name |
| 10298 * already exported by other export directive. | 10279 * already exported by other export directive. |
| 10299 * @param node the export directive node to report problem on | 10280 * @param node the export directive node to report problem on |
| 10300 * @return {@code true} if and only if an error code is generated on the passe
d node | 10281 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10301 * @see CompileTimeErrorCode#AMBIGUOUS_EXPORT | 10282 * @see CompileTimeErrorCode#AMBIGUOUS_EXPORT |
| 10302 */ | 10283 */ |
| 10303 bool checkForAmbiguousExport(ExportDirective node) { | 10284 bool checkForAmbiguousExport(ExportDirective node) { |
| 10304 if (node.element is! ExportElement) { | 10285 if (node.element is! ExportElement) { |
| 10305 return false; | 10286 return false; |
| 10306 } | 10287 } |
| 10307 ExportElement exportElement = node.element as ExportElement; | 10288 ExportElement exportElement = node.element as ExportElement; |
| 10308 LibraryElement exportedLibrary2 = exportElement.exportedLibrary; | 10289 LibraryElement exportedLibrary2 = exportElement.exportedLibrary; |
| 10309 if (exportedLibrary2 == null) { | 10290 if (exportedLibrary2 == null) { |
| 10310 return false; | 10291 return false; |
| 10311 } | 10292 } |
| 10312 Namespace namespace = new NamespaceBuilder().createExportNamespace(exportEle
ment); | 10293 Namespace namespace = new NamespaceBuilder().createExportNamespace(exportEle
ment); |
| 10313 Set<String> newNames = namespace.definedNames.keys.toSet(); | 10294 Set<String> newNames = namespace.definedNames.keys.toSet(); |
| 10314 for (String name in newNames) { | 10295 for (String name in newNames) { |
| 10315 ExportElement prevElement = _exportedNames[name]; | 10296 ExportElement prevElement = _exportedNames[name]; |
| 10316 if (prevElement != null && prevElement != exportElement) { | 10297 if (prevElement != null && prevElement != exportElement) { |
| 10317 _errorReporter.reportError2(CompileTimeErrorCode.AMBIGUOUS_EXPORT, node,
[name, prevElement.exportedLibrary.definingCompilationUnit.displayName, exporte
dLibrary2.definingCompilationUnit.displayName]); | 10298 _errorReporter.reportError2(CompileTimeErrorCode.AMBIGUOUS_EXPORT, node,
[name, prevElement.exportedLibrary.definingCompilationUnit.displayName, exporte
dLibrary2.definingCompilationUnit.displayName]); |
| 10318 return true; | 10299 return true; |
| 10319 } else { | 10300 } else { |
| 10320 _exportedNames[name] = exportElement; | 10301 _exportedNames[name] = exportElement; |
| 10321 } | 10302 } |
| 10322 } | 10303 } |
| 10323 return false; | 10304 return false; |
| 10324 } | 10305 } |
| 10325 | 10306 |
| 10326 /** | 10307 /** |
| 10327 * This verifies that the passed argument definition test identifier is a para
meter. | 10308 * This verifies that the passed argument definition test identifier is a para
meter. |
| 10328 * @param node the {@link ArgumentDefinitionTest} to evaluate | 10309 * @param node the {@link ArgumentDefinitionTest} to evaluate |
| 10329 * @return {@code true} if and only if an error code is generated on the passe
d node | 10310 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10330 * @see CompileTimeErrorCode#ARGUMENT_DEFINITION_TEST_NON_PARAMETER | 10311 * @see CompileTimeErrorCode#ARGUMENT_DEFINITION_TEST_NON_PARAMETER |
| 10331 */ | 10312 */ |
| 10332 bool checkForArgumentDefinitionTestNonParameter(ArgumentDefinitionTest node) { | 10313 bool checkForArgumentDefinitionTestNonParameter(ArgumentDefinitionTest node) { |
| 10333 SimpleIdentifier identifier2 = node.identifier; | 10314 SimpleIdentifier identifier2 = node.identifier; |
| 10334 Element element2 = identifier2.element; | 10315 Element element2 = identifier2.element; |
| 10335 if (element2 != null && element2 is! ParameterElement) { | 10316 if (element2 != null && element2 is! ParameterElement) { |
| 10336 _errorReporter.reportError2(CompileTimeErrorCode.ARGUMENT_DEFINITION_TEST_
NON_PARAMETER, identifier2, [identifier2.name]); | 10317 _errorReporter.reportError2(CompileTimeErrorCode.ARGUMENT_DEFINITION_TEST_
NON_PARAMETER, identifier2, [identifier2.name]); |
| 10337 return true; | 10318 return true; |
| 10338 } | 10319 } |
| 10339 return false; | 10320 return false; |
| 10340 } | 10321 } |
| 10341 | 10322 |
| 10342 /** | 10323 /** |
| 10343 * This verifies that the passed arguments can be assigned to their correspond
ing parameters. | 10324 * This verifies that the passed arguments can be assigned to their correspond
ing parameters. |
| 10344 * @param node the arguments to evaluate | 10325 * @param node the arguments to evaluate |
| 10345 * @return {@code true} if and only if an error code is generated on the passe
d node | 10326 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10346 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE | 10327 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE |
| 10347 */ | 10328 */ |
| 10348 bool checkForArgumentTypeNotAssignable(ArgumentList argumentList) { | 10329 bool checkForArgumentTypeNotAssignable(ArgumentList argumentList) { |
| 10349 if (argumentList == null) { | 10330 if (argumentList == null) { |
| 10350 return false; | 10331 return false; |
| 10351 } | 10332 } |
| 10352 bool problemReported = false; | 10333 bool problemReported = false; |
| 10353 for (Expression argument in argumentList.arguments) { | 10334 for (Expression argument in argumentList.arguments) { |
| 10354 problemReported = javaBooleanOr(problemReported, checkForArgumentTypeNotAs
signable2(argument)); | 10335 problemReported = javaBooleanOr(problemReported, checkForArgumentTypeNotAs
signable2(argument)); |
| 10355 } | 10336 } |
| 10356 return problemReported; | 10337 return problemReported; |
| 10357 } | 10338 } |
| 10358 | 10339 |
| 10359 /** | 10340 /** |
| 10360 * This verifies that the passed argument can be assigned to their correspondi
ng parameters. | 10341 * This verifies that the passed argument can be assigned to their correspondi
ng parameters. |
| 10361 * @param node the argument to evaluate | 10342 * @param node the argument to evaluate |
| 10362 * @return {@code true} if and only if an error code is generated on the passe
d node | 10343 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10363 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE | 10344 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE |
| 10364 */ | 10345 */ |
| 10365 bool checkForArgumentTypeNotAssignable2(Expression argument) { | 10346 bool checkForArgumentTypeNotAssignable2(Expression argument) { |
| 10366 if (argument == null) { | 10347 if (argument == null) { |
| 10367 return false; | 10348 return false; |
| 10368 } | 10349 } |
| 10369 ParameterElement parameterElement2 = argument.parameterElement; | 10350 ParameterElement parameterElement2 = argument.parameterElement; |
| 10370 if (parameterElement2 == null) { | 10351 if (parameterElement2 == null) { |
| 10371 return false; | 10352 return false; |
| 10372 } | 10353 } |
| 10373 Type2 parameterType = parameterElement2.type; | 10354 Type2 parameterType = parameterElement2.type; |
| 10374 if (parameterType == null) { | 10355 if (parameterType == null) { |
| 10375 return false; | 10356 return false; |
| 10376 } | 10357 } |
| 10377 Type2 staticType = getStaticType(argument); | 10358 Type2 staticType = getStaticType(argument); |
| 10378 if (staticType == null) { | 10359 if (staticType == null) { |
| 10379 return false; | 10360 return false; |
| 10380 } | 10361 } |
| 10381 if (staticType.isAssignableTo(parameterType)) { | 10362 if (staticType.isAssignableTo(parameterType)) { |
| 10382 return false; | 10363 return false; |
| 10383 } | 10364 } |
| 10365 if (_strictMode) { |
| 10366 _errorReporter.reportError2(StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE
, argument, [staticType.displayName, parameterType.displayName]); |
| 10367 return true; |
| 10368 } |
| 10384 Type2 propagatedType = getPropagatedType(argument); | 10369 Type2 propagatedType = getPropagatedType(argument); |
| 10385 if (propagatedType != null && propagatedType.isAssignableTo(parameterType))
{ | 10370 if (propagatedType != null && propagatedType.isAssignableTo(parameterType))
{ |
| 10386 return false; | 10371 return false; |
| 10387 } | 10372 } |
| 10388 _errorReporter.reportError2(StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE,
argument, [(propagatedType == null ? staticType : propagatedType).displayName, p
arameterType.displayName]); | 10373 _errorReporter.reportError2(StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE,
argument, [(propagatedType == null ? staticType : propagatedType).displayName, p
arameterType.displayName]); |
| 10389 return true; | 10374 return true; |
| 10390 } | 10375 } |
| 10391 | 10376 |
| 10392 /** | 10377 /** |
| 10393 * This verifies that left hand side of the passed assignment expression is no
t final. | 10378 * This verifies that left hand side of the passed assignment expression is no
t final. |
| 10394 * @param node the assignment expression to evaluate | 10379 * @param node the assignment expression to evaluate |
| 10395 * @return {@code true} if and only if an error code is generated on the passe
d node | 10380 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10396 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL | 10381 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL |
| 10397 */ | 10382 */ |
| 10398 bool checkForAssignmentToFinal(AssignmentExpression node) { | 10383 bool checkForAssignmentToFinal(AssignmentExpression node) { |
| 10399 Expression leftExpression = node.leftHandSide; | 10384 Expression leftExpression = node.leftHandSide; |
| 10400 return checkForAssignmentToFinal2(leftExpression); | 10385 return checkForAssignmentToFinal2(leftExpression); |
| 10401 } | 10386 } |
| 10402 | 10387 |
| 10403 /** | 10388 /** |
| 10404 * This verifies that the passed expression is not final. | 10389 * This verifies that the passed expression is not final. |
| 10405 * @param node the expression to evaluate | 10390 * @param node the expression to evaluate |
| 10406 * @return {@code true} if and only if an error code is generated on the passe
d node | 10391 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10407 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL | 10392 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL |
| 10408 */ | 10393 */ |
| 10409 bool checkForAssignmentToFinal2(Expression expression) { | 10394 bool checkForAssignmentToFinal2(Expression expression) { |
| 10410 Element element = null; | 10395 Element element = null; |
| 10411 if (expression is Identifier) { | 10396 if (expression is Identifier) { |
| 10412 element = ((expression as Identifier)).element; | 10397 element = ((expression as Identifier)).element; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 10425 if (element is PropertyAccessorElement) { | 10410 if (element is PropertyAccessorElement) { |
| 10426 PropertyAccessorElement leftAccessor = element as PropertyAccessorElement; | 10411 PropertyAccessorElement leftAccessor = element as PropertyAccessorElement; |
| 10427 if (!leftAccessor.isSetter()) { | 10412 if (!leftAccessor.isSetter()) { |
| 10428 _errorReporter.reportError2(StaticWarningCode.ASSIGNMENT_TO_FINAL, expre
ssion, []); | 10413 _errorReporter.reportError2(StaticWarningCode.ASSIGNMENT_TO_FINAL, expre
ssion, []); |
| 10429 return true; | 10414 return true; |
| 10430 } | 10415 } |
| 10431 return false; | 10416 return false; |
| 10432 } | 10417 } |
| 10433 return false; | 10418 return false; |
| 10434 } | 10419 } |
| 10435 | 10420 |
| 10436 /** | 10421 /** |
| 10437 * This verifies that the passed identifier is not a keyword, and generates th
e passed error code | 10422 * This verifies that the passed identifier is not a keyword, and generates th
e passed error code |
| 10438 * on the identifier if it is a keyword. | 10423 * on the identifier if it is a keyword. |
| 10439 * @param identifier the identifier to check to ensure that it is not a keywor
d | 10424 * @param identifier the identifier to check to ensure that it is not a keywor
d |
| 10440 * @param errorCode if the passed identifier is a keyword then this error code
is created on the | 10425 * @param errorCode if the passed identifier is a keyword then this error code
is created on the |
| 10441 * identifier, the error code will be one of{@link CompileTimeErrorCode#BUILT_
IN_IDENTIFIER_AS_TYPE_NAME},{@link CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_T
YPE_VARIABLE_NAME} or{@link CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_
NAME} | 10426 * identifier, the error code will be one of{@link CompileTimeErrorCode#BUILT_
IN_IDENTIFIER_AS_TYPE_NAME},{@link CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_T
YPE_VARIABLE_NAME} or{@link CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_
NAME} |
| 10442 * @return {@code true} if and only if an error code is generated on the passe
d node | 10427 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10443 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_NAME | 10428 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_NAME |
| 10444 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_VARIABLE_NAME | 10429 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_VARIABLE_NAME |
| 10445 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME | 10430 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME |
| 10446 */ | 10431 */ |
| 10447 bool checkForBuiltInIdentifierAsName(SimpleIdentifier identifier, ErrorCode er
rorCode) { | 10432 bool checkForBuiltInIdentifierAsName(SimpleIdentifier identifier, ErrorCode er
rorCode) { |
| 10448 sc.Token token2 = identifier.token; | 10433 sc.Token token2 = identifier.token; |
| 10449 if (identical(token2.type, sc.TokenType.KEYWORD)) { | 10434 if (identical(token2.type, sc.TokenType.KEYWORD)) { |
| 10450 _errorReporter.reportError2(errorCode, identifier, [identifier.name]); | 10435 _errorReporter.reportError2(errorCode, identifier, [identifier.name]); |
| 10451 return true; | 10436 return true; |
| 10452 } | 10437 } |
| 10453 return false; | 10438 return false; |
| 10454 } | 10439 } |
| 10455 | 10440 |
| 10456 /** | 10441 /** |
| 10457 * This verifies that the passed variable declaration list does not have a bui
lt-in identifier. | 10442 * This verifies that the passed variable declaration list does not have a bui
lt-in identifier. |
| 10458 * @param node the variable declaration list to check | 10443 * @param node the variable declaration list to check |
| 10459 * @return {@code true} if and only if an error code is generated on the passe
d node | 10444 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10460 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE | 10445 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE |
| 10461 */ | 10446 */ |
| 10462 bool checkForBuiltInIdentifierAsName2(VariableDeclarationList node) { | 10447 bool checkForBuiltInIdentifierAsName2(VariableDeclarationList node) { |
| 10463 TypeName typeName = node.type; | 10448 TypeName typeName = node.type; |
| 10464 if (typeName != null) { | 10449 if (typeName != null) { |
| 10465 Identifier identifier = typeName.name; | 10450 Identifier identifier = typeName.name; |
| 10466 if (identifier is SimpleIdentifier) { | 10451 if (identifier is SimpleIdentifier) { |
| 10467 SimpleIdentifier simpleIdentifier = identifier as SimpleIdentifier; | 10452 SimpleIdentifier simpleIdentifier = identifier as SimpleIdentifier; |
| 10468 sc.Token token2 = simpleIdentifier.token; | 10453 sc.Token token2 = simpleIdentifier.token; |
| 10469 if (identical(token2.type, sc.TokenType.KEYWORD)) { | 10454 if (identical(token2.type, sc.TokenType.KEYWORD)) { |
| 10470 if (((token2 as sc.KeywordToken)).keyword != sc.Keyword.DYNAMIC) { | 10455 if (((token2 as sc.KeywordToken)).keyword != sc.Keyword.DYNAMIC) { |
| 10471 _errorReporter.reportError2(CompileTimeErrorCode.BUILT_IN_IDENTIFIER
_AS_TYPE, identifier, [identifier.name]); | 10456 _errorReporter.reportError2(CompileTimeErrorCode.BUILT_IN_IDENTIFIER
_AS_TYPE, identifier, [identifier.name]); |
| 10472 return true; | 10457 return true; |
| 10473 } | 10458 } |
| 10474 } | 10459 } |
| 10475 } | 10460 } |
| 10476 } | 10461 } |
| 10477 return false; | 10462 return false; |
| 10478 } | 10463 } |
| 10479 | 10464 |
| 10480 /** | 10465 /** |
| 10481 * This verifies that the given switch case is terminated with 'break', 'conti
nue', 'return' or | 10466 * This verifies that the given switch case is terminated with 'break', 'conti
nue', 'return' or |
| 10482 * 'throw'. | 10467 * 'throw'. |
| 10483 * @param node the switch case to evaluate | 10468 * @param node the switch case to evaluate |
| 10484 * @return {@code true} if and only if an error code is generated on the passe
d node | 10469 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10485 * @see StaticWarningCode#CASE_BLOCK_NOT_TERMINATED | 10470 * @see StaticWarningCode#CASE_BLOCK_NOT_TERMINATED |
| 10486 */ | 10471 */ |
| 10487 bool checkForCaseBlockNotTerminated(SwitchCase node) { | 10472 bool checkForCaseBlockNotTerminated(SwitchCase node) { |
| 10488 NodeList<Statement> statements2 = node.statements; | 10473 NodeList<Statement> statements2 = node.statements; |
| 10489 if (statements2.isEmpty) { | 10474 if (statements2.isEmpty) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 10504 if (statement is ExpressionStatement) { | 10489 if (statement is ExpressionStatement) { |
| 10505 Expression expression2 = ((statement as ExpressionStatement)).expression
; | 10490 Expression expression2 = ((statement as ExpressionStatement)).expression
; |
| 10506 if (expression2 is ThrowExpression) { | 10491 if (expression2 is ThrowExpression) { |
| 10507 return false; | 10492 return false; |
| 10508 } | 10493 } |
| 10509 } | 10494 } |
| 10510 } | 10495 } |
| 10511 _errorReporter.reportError4(StaticWarningCode.CASE_BLOCK_NOT_TERMINATED, nod
e.keyword, []); | 10496 _errorReporter.reportError4(StaticWarningCode.CASE_BLOCK_NOT_TERMINATED, nod
e.keyword, []); |
| 10512 return true; | 10497 return true; |
| 10513 } | 10498 } |
| 10514 | 10499 |
| 10515 /** | 10500 /** |
| 10516 * This verifies that the switch cases in the given switch statement is termin
ated with 'break', | 10501 * This verifies that the switch cases in the given switch statement is termin
ated with 'break', |
| 10517 * 'continue', 'return' or 'throw'. | 10502 * 'continue', 'return' or 'throw'. |
| 10518 * @param node the switch statement containing the cases to be checked | 10503 * @param node the switch statement containing the cases to be checked |
| 10519 * @return {@code true} if and only if an error code is generated on the passe
d node | 10504 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10520 * @see StaticWarningCode#CASE_BLOCK_NOT_TERMINATED | 10505 * @see StaticWarningCode#CASE_BLOCK_NOT_TERMINATED |
| 10521 */ | 10506 */ |
| 10522 bool checkForCaseBlocksNotTerminated(SwitchStatement node) { | 10507 bool checkForCaseBlocksNotTerminated(SwitchStatement node) { |
| 10523 bool foundError = false; | 10508 bool foundError = false; |
| 10524 NodeList<SwitchMember> members2 = node.members; | 10509 NodeList<SwitchMember> members2 = node.members; |
| 10525 int lastMember = members2.length - 1; | 10510 int lastMember = members2.length - 1; |
| 10526 for (int i = 0; i < lastMember; i++) { | 10511 for (int i = 0; i < lastMember; i++) { |
| 10527 SwitchMember member = members2[i]; | 10512 SwitchMember member = members2[i]; |
| 10528 if (member is SwitchCase) { | 10513 if (member is SwitchCase) { |
| 10529 foundError = javaBooleanOr(foundError, checkForCaseBlockNotTerminated((m
ember as SwitchCase))); | 10514 foundError = javaBooleanOr(foundError, checkForCaseBlockNotTerminated((m
ember as SwitchCase))); |
| 10530 } | 10515 } |
| 10531 } | 10516 } |
| 10532 return foundError; | 10517 return foundError; |
| 10533 } | 10518 } |
| 10534 | 10519 |
| 10535 /** | 10520 /** |
| 10536 * This verifies that the passed switch statement does not have a case express
ion with the | 10521 * This verifies that the passed switch statement does not have a case express
ion with the |
| 10537 * operator '==' overridden. | 10522 * operator '==' overridden. |
| 10538 * @param node the switch statement to evaluate | 10523 * @param node the switch statement to evaluate |
| 10539 * @return {@code true} if and only if an error code is generated on the passe
d node | 10524 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10540 * @see CompileTimeErrorCode#CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS | 10525 * @see CompileTimeErrorCode#CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS |
| 10541 */ | 10526 */ |
| 10542 bool checkForCaseExpressionTypeImplementsEquals(SwitchStatement node) { | 10527 bool checkForCaseExpressionTypeImplementsEquals(SwitchStatement node) { |
| 10543 Expression expression2 = node.expression; | 10528 Expression expression2 = node.expression; |
| 10544 Type2 type = getStaticType(expression2); | 10529 Type2 type = getStaticType(expression2); |
| 10545 if (type != null && type != _typeProvider.intType && type != _typeProvider.s
tringType) { | 10530 if (type != null && type != _typeProvider.intType && type != _typeProvider.s
tringType) { |
| 10546 Element element2 = type.element; | 10531 Element element2 = type.element; |
| 10547 if (element2 is ClassElement) { | 10532 if (element2 is ClassElement) { |
| 10548 ClassElement classElement = element2 as ClassElement; | 10533 ClassElement classElement = element2 as ClassElement; |
| 10549 MethodElement method = classElement.lookUpMethod("==", _currentLibrary); | 10534 MethodElement method = classElement.lookUpMethod("==", _currentLibrary); |
| 10550 if (method != null && method.enclosingElement.type != _typeProvider.obje
ctType) { | 10535 if (method != null && method.enclosingElement.type != _typeProvider.obje
ctType) { |
| 10551 _errorReporter.reportError2(CompileTimeErrorCode.CASE_EXPRESSION_TYPE_
IMPLEMENTS_EQUALS, expression2, [element2.displayName]); | 10536 _errorReporter.reportError2(CompileTimeErrorCode.CASE_EXPRESSION_TYPE_
IMPLEMENTS_EQUALS, expression2, [element2.displayName]); |
| 10552 return true; | 10537 return true; |
| 10553 } | 10538 } |
| 10554 } | 10539 } |
| 10555 } | 10540 } |
| 10556 return false; | 10541 return false; |
| 10557 } | 10542 } |
| 10558 | 10543 |
| 10559 /** | 10544 /** |
| 10560 * This verifies that the passed method declaration is abstract only if the en
closing class is | 10545 * This verifies that the passed method declaration is abstract only if the en
closing class is |
| 10561 * also abstract. | 10546 * also abstract. |
| 10562 * @param node the method declaration to evaluate | 10547 * @param node the method declaration to evaluate |
| 10563 * @return {@code true} if and only if an error code is generated on the passe
d node | 10548 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10564 * @see StaticWarningCode#CONCRETE_CLASS_WITH_ABSTRACT_MEMBER | 10549 * @see StaticWarningCode#CONCRETE_CLASS_WITH_ABSTRACT_MEMBER |
| 10565 */ | 10550 */ |
| 10566 bool checkForConcreteClassWithAbstractMember(MethodDeclaration node) { | 10551 bool checkForConcreteClassWithAbstractMember(MethodDeclaration node) { |
| 10567 if (node.isAbstract() && _enclosingClass != null && !_enclosingClass.isAbstr
act()) { | 10552 if (node.isAbstract() && _enclosingClass != null && !_enclosingClass.isAbstr
act()) { |
| 10568 SimpleIdentifier methodName = node.name; | 10553 SimpleIdentifier methodName = node.name; |
| 10569 _errorReporter.reportError2(StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT
_MEMBER, methodName, [methodName.name, _enclosingClass.displayName]); | 10554 _errorReporter.reportError2(StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT
_MEMBER, methodName, [methodName.name, _enclosingClass.displayName]); |
| 10570 return true; | 10555 return true; |
| 10571 } | 10556 } |
| 10572 return false; | 10557 return false; |
| 10573 } | 10558 } |
| 10574 | 10559 |
| 10575 /** | 10560 /** |
| 10576 * This verifies all possible conflicts of the constructor name with other con
structors and | 10561 * This verifies all possible conflicts of the constructor name with other con
structors and |
| 10577 * members of the same class. | 10562 * members of the same class. |
| 10578 * @param node the constructor declaration to evaluate | 10563 * @param node the constructor declaration to evaluate |
| 10579 * @return {@code true} if and only if an error code is generated on the passe
d node | 10564 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10580 * @see CompileTimeErrorCode#DUPLICATE_CONSTRUCTOR_DEFAULT | 10565 * @see CompileTimeErrorCode#DUPLICATE_CONSTRUCTOR_DEFAULT |
| 10581 * @see CompileTimeErrorCode#DUPLICATE_CONSTRUCTOR_NAME | 10566 * @see CompileTimeErrorCode#DUPLICATE_CONSTRUCTOR_NAME |
| 10582 * @see CompileTimeErrorCode#CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD | 10567 * @see CompileTimeErrorCode#CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD |
| 10583 * @see CompileTimeErrorCode#CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD | 10568 * @see CompileTimeErrorCode#CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD |
| 10584 */ | 10569 */ |
| (...skipping 27 matching lines...) Expand all Loading... |
| 10612 List<MethodElement> methods2 = classElement.methods; | 10597 List<MethodElement> methods2 = classElement.methods; |
| 10613 for (MethodElement method in methods2) { | 10598 for (MethodElement method in methods2) { |
| 10614 if (method.name == name2) { | 10599 if (method.name == name2) { |
| 10615 _errorReporter.reportError2(CompileTimeErrorCode.CONFLICTING_CONSTRUCT
OR_NAME_AND_METHOD, node, [name2]); | 10600 _errorReporter.reportError2(CompileTimeErrorCode.CONFLICTING_CONSTRUCT
OR_NAME_AND_METHOD, node, [name2]); |
| 10616 return true; | 10601 return true; |
| 10617 } | 10602 } |
| 10618 } | 10603 } |
| 10619 } | 10604 } |
| 10620 return false; | 10605 return false; |
| 10621 } | 10606 } |
| 10622 | 10607 |
| 10623 /** | 10608 /** |
| 10624 * This verifies that the superclass of the enclosing class does not declare a
ccessible static | 10609 * This verifies that the superclass of the enclosing class does not declare a
ccessible static |
| 10625 * member with the same name as the passed instance getter/setter method decla
ration. | 10610 * member with the same name as the passed instance getter/setter method decla
ration. |
| 10626 * @param node the method declaration to evaluate | 10611 * @param node the method declaration to evaluate |
| 10627 * @return {@code true} if and only if an error code is generated on the passe
d node | 10612 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10628 * @see StaticWarningCode#CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER | 10613 * @see StaticWarningCode#CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER |
| 10629 * @see StaticWarningCode#CONFLICTING_INSTANCE_SETTER_AND_SUPERCLASS_MEMBER | 10614 * @see StaticWarningCode#CONFLICTING_INSTANCE_SETTER_AND_SUPERCLASS_MEMBER |
| 10630 */ | 10615 */ |
| 10631 bool checkForConflictingInstanceGetterAndSuperclassMember(MethodDeclaration no
de) { | 10616 bool checkForConflictingInstanceGetterAndSuperclassMember(MethodDeclaration no
de) { |
| 10632 if (node.isStatic()) { | 10617 if (node.isStatic()) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 10657 } | 10642 } |
| 10658 ClassElement superElementClass = superElement.enclosingElement as ClassEleme
nt; | 10643 ClassElement superElementClass = superElement.enclosingElement as ClassEleme
nt; |
| 10659 InterfaceType superElementType = superElementClass.type; | 10644 InterfaceType superElementType = superElementClass.type; |
| 10660 if (node.isGetter()) { | 10645 if (node.isGetter()) { |
| 10661 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_INSTANCE_GETTER_
AND_SUPERCLASS_MEMBER, nameNode, [superElementType.displayName]); | 10646 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_INSTANCE_GETTER_
AND_SUPERCLASS_MEMBER, nameNode, [superElementType.displayName]); |
| 10662 } else { | 10647 } else { |
| 10663 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_INSTANCE_SETTER_
AND_SUPERCLASS_MEMBER, nameNode, [superElementType.displayName]); | 10648 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_INSTANCE_SETTER_
AND_SUPERCLASS_MEMBER, nameNode, [superElementType.displayName]); |
| 10664 } | 10649 } |
| 10665 return true; | 10650 return true; |
| 10666 } | 10651 } |
| 10667 | 10652 |
| 10668 /** | 10653 /** |
| 10669 * This verifies that the enclosing class does not have an instance member wit
h the same name as | 10654 * This verifies that the enclosing class does not have an instance member wit
h the same name as |
| 10670 * the passed static getter method declaration. | 10655 * the passed static getter method declaration. |
| 10671 * @param node the method declaration to evaluate | 10656 * @param node the method declaration to evaluate |
| 10672 * @return {@code true} if and only if an error code is generated on the passe
d node | 10657 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10673 * @see StaticWarningCode#CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER | 10658 * @see StaticWarningCode#CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER |
| 10674 */ | 10659 */ |
| 10675 bool checkForConflictingStaticGetterAndInstanceSetter(MethodDeclaration node)
{ | 10660 bool checkForConflictingStaticGetterAndInstanceSetter(MethodDeclaration node)
{ |
| 10676 if (!node.isStatic()) { | 10661 if (!node.isStatic()) { |
| 10677 return false; | 10662 return false; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 10690 return false; | 10675 return false; |
| 10691 } | 10676 } |
| 10692 if (setter.isStatic()) { | 10677 if (setter.isStatic()) { |
| 10693 return false; | 10678 return false; |
| 10694 } | 10679 } |
| 10695 ClassElement setterClass = setter.enclosingElement as ClassElement; | 10680 ClassElement setterClass = setter.enclosingElement as ClassElement; |
| 10696 InterfaceType setterType = setterClass.type; | 10681 InterfaceType setterType = setterClass.type; |
| 10697 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_
INSTANCE_SETTER, nameNode, [setterType.displayName]); | 10682 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_
INSTANCE_SETTER, nameNode, [setterType.displayName]); |
| 10698 return true; | 10683 return true; |
| 10699 } | 10684 } |
| 10700 | 10685 |
| 10701 /** | 10686 /** |
| 10702 * This verifies that the enclosing class does not have an instance member wit
h the same name as | 10687 * This verifies that the enclosing class does not have an instance member wit
h the same name as |
| 10703 * the passed static getter method declaration. | 10688 * the passed static getter method declaration. |
| 10704 * @param node the method declaration to evaluate | 10689 * @param node the method declaration to evaluate |
| 10705 * @return {@code true} if and only if an error code is generated on the passe
d node | 10690 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10706 * @see StaticWarningCode#CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER | 10691 * @see StaticWarningCode#CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER |
| 10707 */ | 10692 */ |
| 10708 bool checkForConflictingStaticSetterAndInstanceMember(MethodDeclaration node)
{ | 10693 bool checkForConflictingStaticSetterAndInstanceMember(MethodDeclaration node)
{ |
| 10709 if (!node.isStatic()) { | 10694 if (!node.isStatic()) { |
| 10710 return false; | 10695 return false; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 10730 return false; | 10715 return false; |
| 10731 } | 10716 } |
| 10732 if (member.isStatic()) { | 10717 if (member.isStatic()) { |
| 10733 return false; | 10718 return false; |
| 10734 } | 10719 } |
| 10735 ClassElement memberClass = member.enclosingElement as ClassElement; | 10720 ClassElement memberClass = member.enclosingElement as ClassElement; |
| 10736 InterfaceType memberType = memberClass.type; | 10721 InterfaceType memberType = memberClass.type; |
| 10737 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_
INSTANCE_MEMBER, nameNode, [memberType.displayName]); | 10722 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_
INSTANCE_MEMBER, nameNode, [memberType.displayName]); |
| 10738 return true; | 10723 return true; |
| 10739 } | 10724 } |
| 10740 | 10725 |
| 10741 /** | 10726 /** |
| 10742 * This verifies that the passed constructor declaration is 'const' then there
are no non-final | 10727 * This verifies that the passed constructor declaration is 'const' then there
are no non-final |
| 10743 * instance variable. | 10728 * instance variable. |
| 10744 * @param node the constructor declaration to evaluate | 10729 * @param node the constructor declaration to evaluate |
| 10745 * @return {@code true} if and only if an error code is generated on the passe
d node | 10730 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10746 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD | 10731 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD |
| 10747 */ | 10732 */ |
| 10748 bool checkForConstConstructorWithNonFinalField(ConstructorDeclaration node) { | 10733 bool checkForConstConstructorWithNonFinalField(ConstructorDeclaration node) { |
| 10749 if (!_isEnclosingConstructorConst) { | 10734 if (!_isEnclosingConstructorConst) { |
| 10750 return false; | 10735 return false; |
| 10751 } | 10736 } |
| 10752 ConstructorElement constructorElement = node.element; | 10737 ConstructorElement constructorElement = node.element; |
| 10753 ClassElement classElement = constructorElement.enclosingElement; | 10738 ClassElement classElement = constructorElement.enclosingElement; |
| 10754 if (!classElement.hasNonFinalField()) { | 10739 if (!classElement.hasNonFinalField()) { |
| 10755 return false; | 10740 return false; |
| 10756 } | 10741 } |
| 10757 _errorReporter.reportError2(CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_
FINAL_FIELD, node, []); | 10742 _errorReporter.reportError2(CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_
FINAL_FIELD, node, []); |
| 10758 return true; | 10743 return true; |
| 10759 } | 10744 } |
| 10760 | 10745 |
| 10761 /** | 10746 /** |
| 10762 * This verifies that the passed throw expression is not enclosed in a 'const'
constructor | 10747 * This verifies that the passed throw expression is not enclosed in a 'const'
constructor |
| 10763 * declaration. | 10748 * declaration. |
| 10764 * @param node the throw expression expression to evaluate | 10749 * @param node the throw expression expression to evaluate |
| 10765 * @return {@code true} if and only if an error code is generated on the passe
d node | 10750 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10766 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_THROWS_EXCEPTION | 10751 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_THROWS_EXCEPTION |
| 10767 */ | 10752 */ |
| 10768 bool checkForConstEvalThrowsException(ThrowExpression node) { | 10753 bool checkForConstEvalThrowsException(ThrowExpression node) { |
| 10769 if (_isEnclosingConstructorConst) { | 10754 if (_isEnclosingConstructorConst) { |
| 10770 _errorReporter.reportError2(CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_
EXCEPTION, node, []); | 10755 _errorReporter.reportError2(CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_
EXCEPTION, node, []); |
| 10771 return true; | 10756 return true; |
| 10772 } | 10757 } |
| 10773 return false; | 10758 return false; |
| 10774 } | 10759 } |
| 10775 | 10760 |
| 10776 /** | 10761 /** |
| 10777 * This verifies that the passed normal formal parameter is not 'const'. | 10762 * This verifies that the passed normal formal parameter is not 'const'. |
| 10778 * @param node the normal formal parameter to evaluate | 10763 * @param node the normal formal parameter to evaluate |
| 10779 * @return {@code true} if and only if an error code is generated on the passe
d node | 10764 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10780 * @see CompileTimeErrorCode#CONST_FORMAL_PARAMETER | 10765 * @see CompileTimeErrorCode#CONST_FORMAL_PARAMETER |
| 10781 */ | 10766 */ |
| 10782 bool checkForConstFormalParameter(NormalFormalParameter node) { | 10767 bool checkForConstFormalParameter(NormalFormalParameter node) { |
| 10783 if (node.isConst()) { | 10768 if (node.isConst()) { |
| 10784 _errorReporter.reportError2(CompileTimeErrorCode.CONST_FORMAL_PARAMETER, n
ode, []); | 10769 _errorReporter.reportError2(CompileTimeErrorCode.CONST_FORMAL_PARAMETER, n
ode, []); |
| 10785 return true; | 10770 return true; |
| 10786 } | 10771 } |
| 10787 return false; | 10772 return false; |
| 10788 } | 10773 } |
| 10789 | 10774 |
| 10790 /** | 10775 /** |
| 10791 * This verifies that the passed instance creation expression is not being inv
oked on an abstract | 10776 * This verifies that the passed instance creation expression is not being inv
oked on an abstract |
| 10792 * class. | 10777 * class. |
| 10793 * @param node the instance creation expression to evaluate | 10778 * @param node the instance creation expression to evaluate |
| 10794 * @param typeName the {@link TypeName} of the {@link ConstructorName} from th
e{@link InstanceCreationExpression}, this is the AST node that the error is atta
ched to | 10779 * @param typeName the {@link TypeName} of the {@link ConstructorName} from th
e{@link InstanceCreationExpression}, this is the AST node that the error is atta
ched to |
| 10795 * @param type the type being constructed with this {@link InstanceCreationExp
ression} | 10780 * @param type the type being constructed with this {@link InstanceCreationExp
ression} |
| 10796 * @return {@code true} if and only if an error code is generated on the passe
d node | 10781 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10797 * @see StaticWarningCode#CONST_WITH_ABSTRACT_CLASS | 10782 * @see StaticWarningCode#CONST_WITH_ABSTRACT_CLASS |
| 10798 * @see StaticWarningCode#NEW_WITH_ABSTRACT_CLASS | 10783 * @see StaticWarningCode#NEW_WITH_ABSTRACT_CLASS |
| 10799 */ | 10784 */ |
| 10800 bool checkForConstOrNewWithAbstractClass(InstanceCreationExpression node, Type
Name typeName, InterfaceType type) { | 10785 bool checkForConstOrNewWithAbstractClass(InstanceCreationExpression node, Type
Name typeName, InterfaceType type) { |
| 10801 if (type.element.isAbstract()) { | 10786 if (type.element.isAbstract()) { |
| 10802 ConstructorElement element2 = node.element; | 10787 ConstructorElement element2 = node.element; |
| 10803 if (element2 != null && !element2.isFactory()) { | 10788 if (element2 != null && !element2.isFactory()) { |
| 10804 if (identical(((node.keyword as sc.KeywordToken)).keyword, sc.Keyword.CO
NST)) { | 10789 if (identical(((node.keyword as sc.KeywordToken)).keyword, sc.Keyword.CO
NST)) { |
| 10805 _errorReporter.reportError2(StaticWarningCode.CONST_WITH_ABSTRACT_CLAS
S, typeName, []); | 10790 _errorReporter.reportError2(StaticWarningCode.CONST_WITH_ABSTRACT_CLAS
S, typeName, []); |
| 10806 } else { | 10791 } else { |
| 10807 _errorReporter.reportError2(StaticWarningCode.NEW_WITH_ABSTRACT_CLASS,
typeName, []); | 10792 _errorReporter.reportError2(StaticWarningCode.NEW_WITH_ABSTRACT_CLASS,
typeName, []); |
| 10808 } | 10793 } |
| 10809 return true; | 10794 return true; |
| 10810 } | 10795 } |
| 10811 } | 10796 } |
| 10812 return false; | 10797 return false; |
| 10813 } | 10798 } |
| 10814 | 10799 |
| 10815 /** | 10800 /** |
| 10816 * This verifies that the passed 'const' instance creation expression is not b
eing invoked on a | 10801 * This verifies that the passed 'const' instance creation expression is not b
eing invoked on a |
| 10817 * constructor that is not 'const'. | 10802 * constructor that is not 'const'. |
| 10818 * <p> | 10803 * <p> |
| 10819 * This method assumes that the instance creation was tested to be 'const' bef
ore being called. | 10804 * This method assumes that the instance creation was tested to be 'const' bef
ore being called. |
| 10820 * @param node the instance creation expression to evaluate | 10805 * @param node the instance creation expression to evaluate |
| 10821 * @return {@code true} if and only if an error code is generated on the passe
d node | 10806 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10822 * @see CompileTimeErrorCode#CONST_WITH_NON_CONST | 10807 * @see CompileTimeErrorCode#CONST_WITH_NON_CONST |
| 10823 */ | 10808 */ |
| 10824 bool checkForConstWithNonConst(InstanceCreationExpression node) { | 10809 bool checkForConstWithNonConst(InstanceCreationExpression node) { |
| 10825 ConstructorElement constructorElement = node.element; | 10810 ConstructorElement constructorElement = node.element; |
| 10826 if (constructorElement != null && !constructorElement.isConst()) { | 10811 if (constructorElement != null && !constructorElement.isConst()) { |
| 10827 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_NON_CONST, nod
e, []); | 10812 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_NON_CONST, nod
e, []); |
| 10828 return true; | 10813 return true; |
| 10829 } | 10814 } |
| 10830 return false; | 10815 return false; |
| 10831 } | 10816 } |
| 10832 | 10817 |
| 10833 /** | 10818 /** |
| 10834 * This verifies that the passed 'const' instance creation expression does not
reference any type | 10819 * This verifies that the passed 'const' instance creation expression does not
reference any type |
| 10835 * parameters. | 10820 * parameters. |
| 10836 * <p> | 10821 * <p> |
| 10837 * This method assumes that the instance creation was tested to be 'const' bef
ore being called. | 10822 * This method assumes that the instance creation was tested to be 'const' bef
ore being called. |
| 10838 * @param node the instance creation expression to evaluate | 10823 * @param node the instance creation expression to evaluate |
| 10839 * @return {@code true} if and only if an error code is generated on the passe
d node | 10824 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10840 * @see CompileTimeErrorCode#CONST_WITH_TYPE_PARAMETERS | 10825 * @see CompileTimeErrorCode#CONST_WITH_TYPE_PARAMETERS |
| 10841 */ | 10826 */ |
| 10842 bool checkForConstWithTypeParameters(InstanceCreationExpression node) { | 10827 bool checkForConstWithTypeParameters(InstanceCreationExpression node) { |
| 10843 ConstructorName constructorName2 = node.constructorName; | 10828 ConstructorName constructorName2 = node.constructorName; |
| 10844 if (constructorName2 == null) { | 10829 if (constructorName2 == null) { |
| 10845 return false; | 10830 return false; |
| 10846 } | 10831 } |
| 10847 TypeName typeName = constructorName2.type; | 10832 TypeName typeName = constructorName2.type; |
| 10848 return checkForConstWithTypeParameters2(typeName); | 10833 return checkForConstWithTypeParameters2(typeName); |
| 10849 } | 10834 } |
| 10850 | 10835 |
| 10851 /** | 10836 /** |
| 10852 * This verifies that the passed type name does not reference any type paramet
ers. | 10837 * This verifies that the passed type name does not reference any type paramet
ers. |
| 10853 * @param typeName the type name to evaluate | 10838 * @param typeName the type name to evaluate |
| 10854 * @return {@code true} if and only if an error code is generated on the passe
d node | 10839 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10855 * @see CompileTimeErrorCode#CONST_WITH_TYPE_PARAMETERS | 10840 * @see CompileTimeErrorCode#CONST_WITH_TYPE_PARAMETERS |
| 10856 */ | 10841 */ |
| 10857 bool checkForConstWithTypeParameters2(TypeName typeName) { | 10842 bool checkForConstWithTypeParameters2(TypeName typeName) { |
| 10858 if (typeName == null) { | 10843 if (typeName == null) { |
| 10859 return false; | 10844 return false; |
| 10860 } | 10845 } |
| 10861 Identifier name2 = typeName.name; | 10846 Identifier name2 = typeName.name; |
| 10862 if (name2 == null) { | 10847 if (name2 == null) { |
| 10863 return false; | 10848 return false; |
| 10864 } | 10849 } |
| 10865 if (name2.element is TypeVariableElement) { | 10850 if (name2.element is TypeVariableElement) { |
| 10866 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETER
S, name2, []); | 10851 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETER
S, name2, []); |
| 10867 } | 10852 } |
| 10868 TypeArgumentList typeArguments2 = typeName.typeArguments; | 10853 TypeArgumentList typeArguments2 = typeName.typeArguments; |
| 10869 if (typeArguments2 != null) { | 10854 if (typeArguments2 != null) { |
| 10870 bool hasError = false; | 10855 bool hasError = false; |
| 10871 for (TypeName argument in typeArguments2.arguments) { | 10856 for (TypeName argument in typeArguments2.arguments) { |
| 10872 hasError = javaBooleanOr(hasError, checkForConstWithTypeParameters2(argu
ment)); | 10857 hasError = javaBooleanOr(hasError, checkForConstWithTypeParameters2(argu
ment)); |
| 10873 } | 10858 } |
| 10874 return hasError; | 10859 return hasError; |
| 10875 } | 10860 } |
| 10876 return false; | 10861 return false; |
| 10877 } | 10862 } |
| 10878 | 10863 |
| 10879 /** | 10864 /** |
| 10880 * This verifies that if the passed 'const' instance creation expression is be
ing invoked on the | 10865 * This verifies that if the passed 'const' instance creation expression is be
ing invoked on the |
| 10881 * resolved constructor. | 10866 * resolved constructor. |
| 10882 * <p> | 10867 * <p> |
| 10883 * This method assumes that the instance creation was tested to be 'const' bef
ore being called. | 10868 * This method assumes that the instance creation was tested to be 'const' bef
ore being called. |
| 10884 * @param node the instance creation expression to evaluate | 10869 * @param node the instance creation expression to evaluate |
| 10885 * @return {@code true} if and only if an error code is generated on the passe
d node | 10870 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10886 * @see CompileTimeErrorCode#CONST_WITH_UNDEFINED_CONSTRUCTOR | 10871 * @see CompileTimeErrorCode#CONST_WITH_UNDEFINED_CONSTRUCTOR |
| 10887 * @see CompileTimeErrorCode#CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT | 10872 * @see CompileTimeErrorCode#CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT |
| 10888 */ | 10873 */ |
| (...skipping 11 matching lines...) Expand all Loading... |
| 10900 } | 10885 } |
| 10901 Identifier className = type2.name; | 10886 Identifier className = type2.name; |
| 10902 SimpleIdentifier name2 = constructorName2.name; | 10887 SimpleIdentifier name2 = constructorName2.name; |
| 10903 if (name2 != null) { | 10888 if (name2 != null) { |
| 10904 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONS
TRUCTOR, name2, [className, name2]); | 10889 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONS
TRUCTOR, name2, [className, name2]); |
| 10905 } else { | 10890 } else { |
| 10906 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONS
TRUCTOR_DEFAULT, constructorName2, [className]); | 10891 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONS
TRUCTOR_DEFAULT, constructorName2, [className]); |
| 10907 } | 10892 } |
| 10908 return true; | 10893 return true; |
| 10909 } | 10894 } |
| 10910 | 10895 |
| 10911 /** | 10896 /** |
| 10912 * This verifies that there are no default parameters in the passed function t
ype alias. | 10897 * This verifies that there are no default parameters in the passed function t
ype alias. |
| 10913 * @param node the function type alias to evaluate | 10898 * @param node the function type alias to evaluate |
| 10914 * @return {@code true} if and only if an error code is generated on the passe
d node | 10899 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10915 * @see CompileTimeErrorCode#DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS | 10900 * @see CompileTimeErrorCode#DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS |
| 10916 */ | 10901 */ |
| 10917 bool checkForDefaultValueInFunctionTypeAlias(FunctionTypeAlias node) { | 10902 bool checkForDefaultValueInFunctionTypeAlias(FunctionTypeAlias node) { |
| 10918 bool result = false; | 10903 bool result = false; |
| 10919 FormalParameterList formalParameterList = node.parameters; | 10904 FormalParameterList formalParameterList = node.parameters; |
| 10920 NodeList<FormalParameter> parameters2 = formalParameterList.parameters; | 10905 NodeList<FormalParameter> parameters2 = formalParameterList.parameters; |
| 10921 for (FormalParameter formalParameter in parameters2) { | 10906 for (FormalParameter formalParameter in parameters2) { |
| 10922 if (formalParameter is DefaultFormalParameter) { | 10907 if (formalParameter is DefaultFormalParameter) { |
| 10923 DefaultFormalParameter defaultFormalParameter = formalParameter as Defau
ltFormalParameter; | 10908 DefaultFormalParameter defaultFormalParameter = formalParameter as Defau
ltFormalParameter; |
| 10924 if (defaultFormalParameter.defaultValue != null) { | 10909 if (defaultFormalParameter.defaultValue != null) { |
| 10925 _errorReporter.reportError2(CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNC
TION_TYPE_ALIAS, node, []); | 10910 _errorReporter.reportError2(CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNC
TION_TYPE_ALIAS, node, []); |
| 10926 result = true; | 10911 result = true; |
| 10927 } | 10912 } |
| 10928 } | 10913 } |
| 10929 } | 10914 } |
| 10930 return result; | 10915 return result; |
| 10931 } | 10916 } |
| 10932 | 10917 |
| 10933 /** | 10918 /** |
| 10934 * This verifies the passed import has unique name among other exported librar
ies. | 10919 * This verifies the passed import has unique name among other exported librar
ies. |
| 10935 * @param node the export directive to evaluate | 10920 * @param node the export directive to evaluate |
| 10936 * @return {@code true} if and only if an error code is generated on the passe
d node | 10921 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10937 * @see CompileTimeErrorCode#EXPORT_DUPLICATED_LIBRARY_NAME | 10922 * @see CompileTimeErrorCode#EXPORT_DUPLICATED_LIBRARY_NAME |
| 10938 */ | 10923 */ |
| 10939 bool checkForExportDuplicateLibraryName(ExportDirective node) { | 10924 bool checkForExportDuplicateLibraryName(ExportDirective node) { |
| 10940 Element nodeElement = node.element; | 10925 Element nodeElement = node.element; |
| 10941 if (nodeElement is! ExportElement) { | 10926 if (nodeElement is! ExportElement) { |
| 10942 return false; | 10927 return false; |
| 10943 } | 10928 } |
| 10944 ExportElement nodeExportElement = nodeElement as ExportElement; | 10929 ExportElement nodeExportElement = nodeElement as ExportElement; |
| 10945 LibraryElement nodeLibrary = nodeExportElement.exportedLibrary; | 10930 LibraryElement nodeLibrary = nodeExportElement.exportedLibrary; |
| 10946 if (nodeLibrary == null) { | 10931 if (nodeLibrary == null) { |
| 10947 return false; | 10932 return false; |
| 10948 } | 10933 } |
| 10949 String name2 = nodeLibrary.name; | 10934 String name2 = nodeLibrary.name; |
| 10950 LibraryElement prevLibrary = _nameToExportElement[name2]; | 10935 LibraryElement prevLibrary = _nameToExportElement[name2]; |
| 10951 if (prevLibrary != null) { | 10936 if (prevLibrary != null) { |
| 10952 if (prevLibrary != nodeLibrary) { | 10937 if (prevLibrary != nodeLibrary) { |
| 10953 _errorReporter.reportError2(StaticWarningCode.EXPORT_DUPLICATED_LIBRARY_
NAME, node, [prevLibrary.definingCompilationUnit.displayName, nodeLibrary.defini
ngCompilationUnit.displayName, name2]); | 10938 _errorReporter.reportError2(StaticWarningCode.EXPORT_DUPLICATED_LIBRARY_
NAME, node, [prevLibrary.definingCompilationUnit.displayName, nodeLibrary.defini
ngCompilationUnit.displayName, name2]); |
| 10954 return true; | 10939 return true; |
| 10955 } | 10940 } |
| 10956 } else { | 10941 } else { |
| 10957 _nameToExportElement[name2] = nodeLibrary; | 10942 _nameToExportElement[name2] = nodeLibrary; |
| 10958 } | 10943 } |
| 10959 return false; | 10944 return false; |
| 10960 } | 10945 } |
| 10961 | 10946 |
| 10962 /** | 10947 /** |
| 10963 * Check that if the visiting library is not system, then any passed library s
hould not be SDK | 10948 * Check that if the visiting library is not system, then any passed library s
hould not be SDK |
| 10964 * internal library. | 10949 * internal library. |
| 10965 * @param node the export directive to evaluate | 10950 * @param node the export directive to evaluate |
| 10966 * @return {@code true} if and only if an error code is generated on the passe
d node | 10951 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10967 * @see CompileTimeErrorCode#EXPORT_INTERNAL_LIBRARY | 10952 * @see CompileTimeErrorCode#EXPORT_INTERNAL_LIBRARY |
| 10968 */ | 10953 */ |
| 10969 bool checkForExportInternalLibrary(ExportDirective node) { | 10954 bool checkForExportInternalLibrary(ExportDirective node) { |
| 10970 if (_isInSystemLibrary) { | 10955 if (_isInSystemLibrary) { |
| 10971 return false; | 10956 return false; |
| 10972 } | 10957 } |
| 10973 Element element2 = node.element; | 10958 Element element2 = node.element; |
| 10974 if (element2 is! ExportElement) { | 10959 if (element2 is! ExportElement) { |
| 10975 return false; | 10960 return false; |
| 10976 } | 10961 } |
| 10977 ExportElement exportElement = element2 as ExportElement; | 10962 ExportElement exportElement = element2 as ExportElement; |
| 10978 DartSdk sdk = _currentLibrary.context.sourceFactory.dartSdk; | 10963 DartSdk sdk = _currentLibrary.context.sourceFactory.dartSdk; |
| 10979 String uri2 = exportElement.uri; | 10964 String uri2 = exportElement.uri; |
| 10980 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri2); | 10965 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri2); |
| 10981 if (sdkLibrary == null) { | 10966 if (sdkLibrary == null) { |
| 10982 return false; | 10967 return false; |
| 10983 } | 10968 } |
| 10984 if (!sdkLibrary.isInternal()) { | 10969 if (!sdkLibrary.isInternal()) { |
| 10985 return false; | 10970 return false; |
| 10986 } | 10971 } |
| 10987 _errorReporter.reportError2(CompileTimeErrorCode.EXPORT_INTERNAL_LIBRARY, no
de, [node.uri]); | 10972 _errorReporter.reportError2(CompileTimeErrorCode.EXPORT_INTERNAL_LIBRARY, no
de, [node.uri]); |
| 10988 return true; | 10973 return true; |
| 10989 } | 10974 } |
| 10990 | 10975 |
| 10991 /** | 10976 /** |
| 10992 * This verifies that the passed extends clause does not extend classes such a
s num or String. | 10977 * This verifies that the passed extends clause does not extend classes such a
s num or String. |
| 10993 * @param node the extends clause to test | 10978 * @param node the extends clause to test |
| 10994 * @return {@code true} if and only if an error code is generated on the passe
d node | 10979 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 10995 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS | 10980 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS |
| 10996 */ | 10981 */ |
| 10997 bool checkForExtendsDisallowedClass(ExtendsClause extendsClause) { | 10982 bool checkForExtendsDisallowedClass(ExtendsClause extendsClause) { |
| 10998 if (extendsClause == null) { | 10983 if (extendsClause == null) { |
| 10999 return false; | 10984 return false; |
| 11000 } | 10985 } |
| 11001 return checkForExtendsOrImplementsDisallowedClass(extendsClause.superclass,
CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS); | 10986 return checkForExtendsOrImplementsDisallowedClass(extendsClause.superclass,
CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS); |
| 11002 } | 10987 } |
| 11003 | 10988 |
| 11004 /** | 10989 /** |
| 11005 * This verifies that the passed type name does not extend or implement classe
s such as 'num' or | 10990 * This verifies that the passed type name does not extend or implement classe
s such as 'num' or |
| 11006 * 'String'. | 10991 * 'String'. |
| 11007 * @param node the type name to test | 10992 * @param node the type name to test |
| 11008 * @return {@code true} if and only if an error code is generated on the passe
d node | 10993 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11009 * @see #checkForExtendsDisallowedClass(ExtendsClause) | 10994 * @see #checkForExtendsDisallowedClass(ExtendsClause) |
| 11010 * @see #checkForImplementsDisallowedClass(ImplementsClause) | 10995 * @see #checkForImplementsDisallowedClass(ImplementsClause) |
| 11011 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS | 10996 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS |
| 11012 * @see CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS | 10997 * @see CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS |
| 11013 */ | 10998 */ |
| (...skipping 13 matching lines...) Expand all Loading... |
| 11027 return false; | 11012 return false; |
| 11028 } | 11013 } |
| 11029 } | 11014 } |
| 11030 } | 11015 } |
| 11031 _errorReporter.reportError2(errorCode, typeName, [disallowedType.display
Name]); | 11016 _errorReporter.reportError2(errorCode, typeName, [disallowedType.display
Name]); |
| 11032 return true; | 11017 return true; |
| 11033 } | 11018 } |
| 11034 } | 11019 } |
| 11035 return false; | 11020 return false; |
| 11036 } | 11021 } |
| 11037 | 11022 |
| 11038 /** | 11023 /** |
| 11039 * This verifies that the passed constructor field initializer has compatible
field and | 11024 * This verifies that the passed constructor field initializer has compatible
field and |
| 11040 * initializer expression types. | 11025 * initializer expression types. |
| 11041 * @param node the constructor field initializer to test | 11026 * @param node the constructor field initializer to test |
| 11042 * @return {@code true} if and only if an error code is generated on the passe
d node | 11027 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11043 * @see CompileTimeErrorCode#CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE | 11028 * @see CompileTimeErrorCode#CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE |
| 11044 * @see StaticWarningCode#FIELD_INITIALIZER_NOT_ASSIGNABLE | 11029 * @see StaticWarningCode#FIELD_INITIALIZER_NOT_ASSIGNABLE |
| 11045 */ | 11030 */ |
| 11046 bool checkForFieldInitializerNotAssignable(ConstructorFieldInitializer node) { | 11031 bool checkForFieldInitializerNotAssignable(ConstructorFieldInitializer node) { |
| 11047 Element fieldNameElement = node.fieldName.element; | 11032 Element fieldNameElement = node.fieldName.element; |
| 11048 if (fieldNameElement is! FieldElement) { | 11033 if (fieldNameElement is! FieldElement) { |
| 11049 return false; | 11034 return false; |
| 11050 } | 11035 } |
| 11051 FieldElement fieldElement = fieldNameElement as FieldElement; | 11036 FieldElement fieldElement = fieldNameElement as FieldElement; |
| 11052 Type2 fieldType = fieldElement.type; | 11037 Type2 fieldType = fieldElement.type; |
| 11053 Expression expression2 = node.expression; | 11038 Expression expression2 = node.expression; |
| 11054 if (expression2 == null) { | 11039 if (expression2 == null) { |
| 11055 return false; | 11040 return false; |
| 11056 } | 11041 } |
| 11057 Type2 staticType = getStaticType(expression2); | 11042 Type2 staticType = getStaticType(expression2); |
| 11058 if (staticType == null) { | 11043 if (staticType == null) { |
| 11059 return false; | 11044 return false; |
| 11060 } | 11045 } |
| 11061 if (staticType.isAssignableTo(fieldType)) { | 11046 if (staticType.isAssignableTo(fieldType)) { |
| 11062 return false; | 11047 return false; |
| 11048 } else if (_strictMode) { |
| 11049 if (_isEnclosingConstructorConst) { |
| 11050 _errorReporter.reportError2(CompileTimeErrorCode.CONST_FIELD_INITIALIZER
_NOT_ASSIGNABLE, expression2, [staticType.displayName, fieldType.displayName]); |
| 11051 } else { |
| 11052 _errorReporter.reportError2(StaticWarningCode.FIELD_INITIALIZER_NOT_ASSI
GNABLE, expression2, [staticType.displayName, fieldType.displayName]); |
| 11053 } |
| 11054 return true; |
| 11063 } | 11055 } |
| 11064 Type2 propagatedType = getPropagatedType(expression2); | 11056 Type2 propagatedType = getPropagatedType(expression2); |
| 11065 if (propagatedType != null && propagatedType.isAssignableTo(fieldType)) { | 11057 if (propagatedType != null && propagatedType.isAssignableTo(fieldType)) { |
| 11066 return false; | 11058 return false; |
| 11067 } | 11059 } |
| 11068 if (_isEnclosingConstructorConst) { | 11060 if (_isEnclosingConstructorConst) { |
| 11069 _errorReporter.reportError2(CompileTimeErrorCode.CONST_FIELD_INITIALIZER_N
OT_ASSIGNABLE, expression2, [(propagatedType == null ? staticType : propagatedTy
pe).displayName, fieldType.displayName]); | 11061 _errorReporter.reportError2(CompileTimeErrorCode.CONST_FIELD_INITIALIZER_N
OT_ASSIGNABLE, expression2, [(propagatedType == null ? staticType : propagatedTy
pe).displayName, fieldType.displayName]); |
| 11070 } else { | 11062 } else { |
| 11071 _errorReporter.reportError2(StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGN
ABLE, expression2, [(propagatedType == null ? staticType : propagatedType).displ
ayName, fieldType.displayName]); | 11063 _errorReporter.reportError2(StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGN
ABLE, expression2, [(propagatedType == null ? staticType : propagatedType).displ
ayName, fieldType.displayName]); |
| 11072 } | 11064 } |
| 11073 return true; | 11065 return true; |
| 11074 } | 11066 } |
| 11075 | 11067 |
| 11076 /** | 11068 /** |
| 11077 * This verifies that the passed field formal parameter is in a constructor de
claration. | 11069 * This verifies that the passed field formal parameter is in a constructor de
claration. |
| 11078 * @param node the field formal parameter to test | 11070 * @param node the field formal parameter to test |
| 11079 * @return {@code true} if and only if an error code is generated on the passe
d node | 11071 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11080 * @see CompileTimeErrorCode#FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR | 11072 * @see CompileTimeErrorCode#FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR |
| 11081 */ | 11073 */ |
| 11082 bool checkForFieldInitializingFormalRedirectingConstructor(FieldFormalParamete
r node) { | 11074 bool checkForFieldInitializingFormalRedirectingConstructor(FieldFormalParamete
r node) { |
| 11083 ConstructorDeclaration constructor = node.getAncestor(ConstructorDeclaration
); | 11075 ConstructorDeclaration constructor = node.getAncestor(ConstructorDeclaration
); |
| 11084 if (constructor == null) { | 11076 if (constructor == null) { |
| 11085 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE
_CONSTRUCTOR, node, []); | 11077 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE
_CONSTRUCTOR, node, []); |
| 11086 return true; | 11078 return true; |
| 11087 } | 11079 } |
| 11088 if (constructor.factoryKeyword != null) { | 11080 if (constructor.factoryKeyword != null) { |
| 11089 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY
_CONSTRUCTOR, node, []); | 11081 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY
_CONSTRUCTOR, node, []); |
| 11090 return true; | 11082 return true; |
| 11091 } | 11083 } |
| 11092 for (ConstructorInitializer initializer in constructor.initializers) { | 11084 for (ConstructorInitializer initializer in constructor.initializers) { |
| 11093 if (initializer is RedirectingConstructorInvocation) { | 11085 if (initializer is RedirectingConstructorInvocation) { |
| 11094 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_REDIR
ECTING_CONSTRUCTOR, node, []); | 11086 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_REDIR
ECTING_CONSTRUCTOR, node, []); |
| 11095 return true; | 11087 return true; |
| 11096 } | 11088 } |
| 11097 } | 11089 } |
| 11098 return false; | 11090 return false; |
| 11099 } | 11091 } |
| 11100 | 11092 |
| 11101 /** | 11093 /** |
| 11102 * This verifies that final fields that are declared, without any constructors
in the enclosing | 11094 * This verifies that final fields that are declared, without any constructors
in the enclosing |
| 11103 * class, are initialized. Cases in which there is at least one constructor ar
e handled at the end | 11095 * class, are initialized. Cases in which there is at least one constructor ar
e handled at the end |
| 11104 * of {@link #checkForAllFinalInitializedErrorCodes(ConstructorDeclaration)}. | 11096 * of {@link #checkForAllFinalInitializedErrorCodes(ConstructorDeclaration)}. |
| 11105 * @param node the class declaration to test | 11097 * @param node the class declaration to test |
| 11106 * @return {@code true} if and only if an error code is generated on the passe
d node | 11098 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11107 * @see CompileTimeErrorCode#FINAL_NOT_INITIALIZED | 11099 * @see CompileTimeErrorCode#FINAL_NOT_INITIALIZED |
| 11108 */ | 11100 */ |
| 11109 bool checkForFinalNotInitialized(ClassDeclaration node) { | 11101 bool checkForFinalNotInitialized(ClassDeclaration node) { |
| 11110 NodeList<ClassMember> classMembers = node.members; | 11102 NodeList<ClassMember> classMembers = node.members; |
| 11111 for (ClassMember classMember in classMembers) { | 11103 for (ClassMember classMember in classMembers) { |
| 11112 if (classMember is ConstructorDeclaration) { | 11104 if (classMember is ConstructorDeclaration) { |
| 11113 return false; | 11105 return false; |
| 11114 } | 11106 } |
| 11115 } | 11107 } |
| 11116 bool foundError = false; | 11108 bool foundError = false; |
| 11117 for (ClassMember classMember in classMembers) { | 11109 for (ClassMember classMember in classMembers) { |
| 11118 if (classMember is FieldDeclaration) { | 11110 if (classMember is FieldDeclaration) { |
| 11119 FieldDeclaration field = classMember as FieldDeclaration; | 11111 FieldDeclaration field = classMember as FieldDeclaration; |
| 11120 foundError = javaBooleanOr(foundError, checkForFinalNotInitialized2(fiel
d.fields)); | 11112 foundError = javaBooleanOr(foundError, checkForFinalNotInitialized2(fiel
d.fields)); |
| 11121 } | 11113 } |
| 11122 } | 11114 } |
| 11123 return foundError; | 11115 return foundError; |
| 11124 } | 11116 } |
| 11125 | 11117 |
| 11126 /** | 11118 /** |
| 11127 * This verifies that the passed variable declaration list has only initialize
d variables if the | 11119 * This verifies that the passed variable declaration list has only initialize
d variables if the |
| 11128 * list is final or const. This method is called by{@link #checkForFinalNotIni
tialized(ClassDeclaration)},{@link #visitTopLevelVariableDeclaration(TopLevelVar
iableDeclaration)} and{@link #visitVariableDeclarationStatement(VariableDeclarat
ionStatement)}. | 11120 * list is final or const. This method is called by{@link #checkForFinalNotIni
tialized(ClassDeclaration)},{@link #visitTopLevelVariableDeclaration(TopLevelVar
iableDeclaration)} and{@link #visitVariableDeclarationStatement(VariableDeclarat
ionStatement)}. |
| 11129 * @param node the class declaration to test | 11121 * @param node the class declaration to test |
| 11130 * @return {@code true} if and only if an error code is generated on the passe
d node | 11122 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11131 * @see CompileTimeErrorCode#FINAL_NOT_INITIALIZED | 11123 * @see CompileTimeErrorCode#FINAL_NOT_INITIALIZED |
| 11132 */ | 11124 */ |
| 11133 bool checkForFinalNotInitialized2(VariableDeclarationList node) { | 11125 bool checkForFinalNotInitialized2(VariableDeclarationList node) { |
| 11134 bool foundError = false; | 11126 bool foundError = false; |
| 11135 if (!node.isSynthetic() && (node.isConst() || node.isFinal())) { | 11127 if (!node.isSynthetic() && (node.isConst() || node.isFinal())) { |
| 11136 NodeList<VariableDeclaration> variables2 = node.variables; | 11128 NodeList<VariableDeclaration> variables2 = node.variables; |
| 11137 for (VariableDeclaration variable in variables2) { | 11129 for (VariableDeclaration variable in variables2) { |
| 11138 if (variable.initializer == null) { | 11130 if (variable.initializer == null) { |
| 11139 _errorReporter.reportError2(CompileTimeErrorCode.FINAL_NOT_INITIALIZED
, variable, [variable.name.name]); | 11131 _errorReporter.reportError2(CompileTimeErrorCode.FINAL_NOT_INITIALIZED
, variable, [variable.name.name]); |
| 11140 foundError = true; | 11132 foundError = true; |
| 11141 } | 11133 } |
| 11142 } | 11134 } |
| 11143 } | 11135 } |
| 11144 return foundError; | 11136 return foundError; |
| 11145 } | 11137 } |
| 11146 | 11138 |
| 11147 /** | 11139 /** |
| 11148 * This verifies that the passed implements clause does not implement classes
such as 'num' or | 11140 * This verifies that the passed implements clause does not implement classes
such as 'num' or |
| 11149 * 'String'. | 11141 * 'String'. |
| 11150 * @param node the implements clause to test | 11142 * @param node the implements clause to test |
| 11151 * @return {@code true} if and only if an error code is generated on the passe
d node | 11143 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11152 * @see CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS | 11144 * @see CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS |
| 11153 */ | 11145 */ |
| 11154 bool checkForImplementsDisallowedClass(ImplementsClause implementsClause) { | 11146 bool checkForImplementsDisallowedClass(ImplementsClause implementsClause) { |
| 11155 if (implementsClause == null) { | 11147 if (implementsClause == null) { |
| 11156 return false; | 11148 return false; |
| 11157 } | 11149 } |
| 11158 bool foundError = false; | 11150 bool foundError = false; |
| 11159 for (TypeName type in implementsClause.interfaces) { | 11151 for (TypeName type in implementsClause.interfaces) { |
| 11160 foundError = javaBooleanOr(foundError, checkForExtendsOrImplementsDisallow
edClass(type, CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS)); | 11152 foundError = javaBooleanOr(foundError, checkForExtendsOrImplementsDisallow
edClass(type, CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS)); |
| 11161 } | 11153 } |
| 11162 return foundError; | 11154 return foundError; |
| 11163 } | 11155 } |
| 11164 | 11156 |
| 11165 /** | 11157 /** |
| 11166 * This verifies that if the passed identifier is part of constructor initiali
zer, then it does | 11158 * This verifies that if the passed identifier is part of constructor initiali
zer, then it does |
| 11167 * not reference implicitly 'this' expression. | 11159 * not reference implicitly 'this' expression. |
| 11168 * @param node the simple identifier to test | 11160 * @param node the simple identifier to test |
| 11169 * @return {@code true} if and only if an error code is generated on the passe
d node | 11161 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11170 * @see CompileTimeErrorCode#IMPLICIT_THIS_REFERENCE_IN_INITIALIZER | 11162 * @see CompileTimeErrorCode#IMPLICIT_THIS_REFERENCE_IN_INITIALIZER |
| 11171 */ | 11163 */ |
| 11172 bool checkForImplicitThisReferenceInInitializer(SimpleIdentifier node) { | 11164 bool checkForImplicitThisReferenceInInitializer(SimpleIdentifier node) { |
| 11173 if (!_isInConstructorInitializer) { | 11165 if (!_isInConstructorInitializer) { |
| 11174 return false; | 11166 return false; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 11202 if (parent2 is PrefixedIdentifier) { | 11194 if (parent2 is PrefixedIdentifier) { |
| 11203 PrefixedIdentifier prefixed = parent2 as PrefixedIdentifier; | 11195 PrefixedIdentifier prefixed = parent2 as PrefixedIdentifier; |
| 11204 if (identical(prefixed.identifier, node)) { | 11196 if (identical(prefixed.identifier, node)) { |
| 11205 return false; | 11197 return false; |
| 11206 } | 11198 } |
| 11207 } | 11199 } |
| 11208 } | 11200 } |
| 11209 _errorReporter.reportError2(CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_
INITIALIZER, node, []); | 11201 _errorReporter.reportError2(CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_
INITIALIZER, node, []); |
| 11210 return true; | 11202 return true; |
| 11211 } | 11203 } |
| 11212 | 11204 |
| 11213 /** | 11205 /** |
| 11214 * This verifies the passed import has unique name among other imported librar
ies. | 11206 * This verifies the passed import has unique name among other imported librar
ies. |
| 11215 * @param node the import directive to evaluate | 11207 * @param node the import directive to evaluate |
| 11216 * @return {@code true} if and only if an error code is generated on the passe
d node | 11208 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11217 * @see CompileTimeErrorCode#IMPORT_DUPLICATED_LIBRARY_NAME | 11209 * @see CompileTimeErrorCode#IMPORT_DUPLICATED_LIBRARY_NAME |
| 11218 */ | 11210 */ |
| 11219 bool checkForImportDuplicateLibraryName(ImportDirective node) { | 11211 bool checkForImportDuplicateLibraryName(ImportDirective node) { |
| 11220 Element nodeElement = node.element; | 11212 Element nodeElement = node.element; |
| 11221 if (nodeElement is! ImportElement) { | 11213 if (nodeElement is! ImportElement) { |
| 11222 return false; | 11214 return false; |
| 11223 } | 11215 } |
| 11224 ImportElement nodeImportElement = nodeElement as ImportElement; | 11216 ImportElement nodeImportElement = nodeElement as ImportElement; |
| 11225 LibraryElement nodeLibrary = nodeImportElement.importedLibrary; | 11217 LibraryElement nodeLibrary = nodeImportElement.importedLibrary; |
| 11226 if (nodeLibrary == null) { | 11218 if (nodeLibrary == null) { |
| 11227 return false; | 11219 return false; |
| 11228 } | 11220 } |
| 11229 String name2 = nodeLibrary.name; | 11221 String name2 = nodeLibrary.name; |
| 11230 LibraryElement prevLibrary = _nameToImportElement[name2]; | 11222 LibraryElement prevLibrary = _nameToImportElement[name2]; |
| 11231 if (prevLibrary != null) { | 11223 if (prevLibrary != null) { |
| 11232 if (prevLibrary != nodeLibrary) { | 11224 if (prevLibrary != nodeLibrary) { |
| 11233 _errorReporter.reportError2(StaticWarningCode.IMPORT_DUPLICATED_LIBRARY_
NAME, node, [prevLibrary.definingCompilationUnit.displayName, nodeLibrary.defini
ngCompilationUnit.displayName, name2]); | 11225 _errorReporter.reportError2(StaticWarningCode.IMPORT_DUPLICATED_LIBRARY_
NAME, node, [prevLibrary.definingCompilationUnit.displayName, nodeLibrary.defini
ngCompilationUnit.displayName, name2]); |
| 11234 return true; | 11226 return true; |
| 11235 } | 11227 } |
| 11236 } else { | 11228 } else { |
| 11237 _nameToImportElement[name2] = nodeLibrary; | 11229 _nameToImportElement[name2] = nodeLibrary; |
| 11238 } | 11230 } |
| 11239 return false; | 11231 return false; |
| 11240 } | 11232 } |
| 11241 | 11233 |
| 11242 /** | 11234 /** |
| 11243 * Check that if the visiting library is not system, then any passed library s
hould not be SDK | 11235 * Check that if the visiting library is not system, then any passed library s
hould not be SDK |
| 11244 * internal library. | 11236 * internal library. |
| 11245 * @param node the import directive to evaluate | 11237 * @param node the import directive to evaluate |
| 11246 * @return {@code true} if and only if an error code is generated on the passe
d node | 11238 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11247 * @see CompileTimeErrorCode#IMPORT_INTERNAL_LIBRARY | 11239 * @see CompileTimeErrorCode#IMPORT_INTERNAL_LIBRARY |
| 11248 */ | 11240 */ |
| 11249 bool checkForImportInternalLibrary(ImportDirective node) { | 11241 bool checkForImportInternalLibrary(ImportDirective node) { |
| 11250 if (_isInSystemLibrary) { | 11242 if (_isInSystemLibrary) { |
| 11251 return false; | 11243 return false; |
| 11252 } | 11244 } |
| 11253 Element element2 = node.element; | 11245 Element element2 = node.element; |
| 11254 if (element2 is! ImportElement) { | 11246 if (element2 is! ImportElement) { |
| 11255 return false; | 11247 return false; |
| 11256 } | 11248 } |
| 11257 ImportElement importElement = element2 as ImportElement; | 11249 ImportElement importElement = element2 as ImportElement; |
| 11258 DartSdk sdk = _currentLibrary.context.sourceFactory.dartSdk; | 11250 DartSdk sdk = _currentLibrary.context.sourceFactory.dartSdk; |
| 11259 String uri2 = importElement.uri; | 11251 String uri2 = importElement.uri; |
| 11260 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri2); | 11252 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri2); |
| 11261 if (sdkLibrary == null) { | 11253 if (sdkLibrary == null) { |
| 11262 return false; | 11254 return false; |
| 11263 } | 11255 } |
| 11264 if (!sdkLibrary.isInternal()) { | 11256 if (!sdkLibrary.isInternal()) { |
| 11265 return false; | 11257 return false; |
| 11266 } | 11258 } |
| 11267 _errorReporter.reportError2(CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, no
de, [node.uri]); | 11259 _errorReporter.reportError2(CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, no
de, [node.uri]); |
| 11268 return true; | 11260 return true; |
| 11269 } | 11261 } |
| 11270 | 11262 |
| 11271 /** | 11263 /** |
| 11272 * This verifies that the passed switch statement case expressions all have th
e same type. | 11264 * This verifies that the passed switch statement case expressions all have th
e same type. |
| 11273 * @param node the switch statement to evaluate | 11265 * @param node the switch statement to evaluate |
| 11274 * @return {@code true} if and only if an error code is generated on the passe
d node | 11266 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11275 * @see CompileTimeErrorCode#INCONSISTENT_CASE_EXPRESSION_TYPES | 11267 * @see CompileTimeErrorCode#INCONSISTENT_CASE_EXPRESSION_TYPES |
| 11276 */ | 11268 */ |
| 11277 bool checkForInconsistentCaseExpressionTypes(SwitchStatement node) { | 11269 bool checkForInconsistentCaseExpressionTypes(SwitchStatement node) { |
| 11278 NodeList<SwitchMember> switchMembers = node.members; | 11270 NodeList<SwitchMember> switchMembers = node.members; |
| 11279 bool foundError = false; | 11271 bool foundError = false; |
| 11280 Type2 firstType = null; | 11272 Type2 firstType = null; |
| 11281 for (SwitchMember switchMember in switchMembers) { | 11273 for (SwitchMember switchMember in switchMembers) { |
| 11282 if (switchMember is SwitchCase) { | 11274 if (switchMember is SwitchCase) { |
| 11283 SwitchCase switchCase = switchMember as SwitchCase; | 11275 SwitchCase switchCase = switchMember as SwitchCase; |
| 11284 Expression expression2 = switchCase.expression; | 11276 Expression expression2 = switchCase.expression; |
| 11285 if (firstType == null) { | 11277 if (firstType == null) { |
| 11286 firstType = getBestType(expression2); | 11278 firstType = getBestType(expression2); |
| 11287 } else { | 11279 } else { |
| 11288 Type2 nType = getBestType(expression2); | 11280 Type2 nType = getBestType(expression2); |
| 11289 if (firstType != nType) { | 11281 if (firstType != nType) { |
| 11290 _errorReporter.reportError2(CompileTimeErrorCode.INCONSISTENT_CASE_E
XPRESSION_TYPES, expression2, [expression2.toSource(), firstType.displayName]); | 11282 _errorReporter.reportError2(CompileTimeErrorCode.INCONSISTENT_CASE_E
XPRESSION_TYPES, expression2, [expression2.toSource(), firstType.displayName]); |
| 11291 foundError = true; | 11283 foundError = true; |
| 11292 } | 11284 } |
| 11293 } | 11285 } |
| 11294 } | 11286 } |
| 11295 } | 11287 } |
| 11296 return foundError; | 11288 return foundError; |
| 11297 } | 11289 } |
| 11298 | 11290 |
| 11299 /** | 11291 /** |
| 11300 * For each class declaration, this method is called which verifies that all i
nherited members are | 11292 * For each class declaration, this method is called which verifies that all i
nherited members are |
| 11301 * inherited consistently. | 11293 * inherited consistently. |
| 11302 * @return {@code true} if and only if an error code is generated on the passe
d node | 11294 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11303 * @see StaticTypeWarningCode#INCONSISTENT_METHOD_INHERITANCE | 11295 * @see StaticTypeWarningCode#INCONSISTENT_METHOD_INHERITANCE |
| 11304 */ | 11296 */ |
| 11305 bool checkForInconsistentMethodInheritance() { | 11297 bool checkForInconsistentMethodInheritance() { |
| 11306 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(_enclosingClass); | 11298 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(_enclosingClass); |
| 11307 Set<AnalysisError> errors = _inheritanceManager.getErrors(_enclosingClass); | 11299 Set<AnalysisError> errors = _inheritanceManager.getErrors(_enclosingClass); |
| 11308 if (errors == null || errors.isEmpty) { | 11300 if (errors == null || errors.isEmpty) { |
| 11309 return false; | 11301 return false; |
| 11310 } | 11302 } |
| 11311 for (AnalysisError error in errors) { | 11303 for (AnalysisError error in errors) { |
| 11312 _errorReporter.reportError(error); | 11304 _errorReporter.reportError(error); |
| 11313 } | 11305 } |
| 11314 return true; | 11306 return true; |
| 11315 } | 11307 } |
| 11316 | 11308 |
| 11317 /** | 11309 /** |
| 11318 * Given an assignment using a compound assignment operator, this verifies tha
t the given | 11310 * Given an assignment using a compound assignment operator, this verifies tha
t the given |
| 11319 * assignment is valid. | 11311 * assignment is valid. |
| 11320 * @param node the assignment expression being tested | 11312 * @param node the assignment expression being tested |
| 11321 * @return {@code true} if and only if an error code is generated on the passe
d node | 11313 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11322 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT | 11314 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT |
| 11323 */ | 11315 */ |
| 11324 bool checkForInvalidAssignment(AssignmentExpression node) { | 11316 bool checkForInvalidAssignment(AssignmentExpression node) { |
| 11325 Expression lhs = node.leftHandSide; | 11317 Expression lhs = node.leftHandSide; |
| 11326 if (lhs == null) { | 11318 if (lhs == null) { |
| 11327 return false; | 11319 return false; |
| 11328 } | 11320 } |
| 11329 VariableElement leftElement = getVariableElement(lhs); | 11321 VariableElement leftElement = getVariableElement(lhs); |
| 11330 Type2 leftType = (leftElement == null) ? getStaticType(lhs) : leftElement.ty
pe; | 11322 Type2 leftType = (leftElement == null) ? getStaticType(lhs) : leftElement.ty
pe; |
| 11331 MethodElement invokedMethod = node.element; | 11323 MethodElement invokedMethod = node.element; |
| 11332 if (invokedMethod == null) { | 11324 if (invokedMethod == null) { |
| 11333 return false; | 11325 return false; |
| 11334 } | 11326 } |
| 11335 Type2 rightType = invokedMethod.type.returnType; | 11327 Type2 rightType = invokedMethod.type.returnType; |
| 11336 if (leftType == null || rightType == null) { | 11328 if (leftType == null || rightType == null) { |
| 11337 return false; | 11329 return false; |
| 11338 } | 11330 } |
| 11339 if (!rightType.isAssignableTo(leftType)) { | 11331 if (!rightType.isAssignableTo(leftType)) { |
| 11340 _errorReporter.reportError2(StaticTypeWarningCode.INVALID_ASSIGNMENT, node
.rightHandSide, [rightType.displayName, leftType.displayName]); | 11332 _errorReporter.reportError2(StaticTypeWarningCode.INVALID_ASSIGNMENT, node
.rightHandSide, [rightType.displayName, leftType.displayName]); |
| 11341 return true; | 11333 return true; |
| 11342 } | 11334 } |
| 11343 return false; | 11335 return false; |
| 11344 } | 11336 } |
| 11345 | 11337 |
| 11346 /** | 11338 /** |
| 11347 * This verifies that the passed left hand side and right hand side represent
a valid assignment. | 11339 * This verifies that the passed left hand side and right hand side represent
a valid assignment. |
| 11348 * @param lhs the left hand side expression | 11340 * @param lhs the left hand side expression |
| 11349 * @param rhs the right hand side expression | 11341 * @param rhs the right hand side expression |
| 11350 * @return {@code true} if and only if an error code is generated on the passe
d node | 11342 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11351 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT | 11343 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT |
| 11352 */ | 11344 */ |
| 11353 bool checkForInvalidAssignment2(Expression lhs, Expression rhs) { | 11345 bool checkForInvalidAssignment2(Expression lhs, Expression rhs) { |
| 11354 if (lhs == null || rhs == null) { | 11346 if (lhs == null || rhs == null) { |
| 11355 return false; | 11347 return false; |
| 11356 } | 11348 } |
| 11357 VariableElement leftElement = getVariableElement(lhs); | 11349 VariableElement leftElement = getVariableElement(lhs); |
| 11358 Type2 leftType = (leftElement == null) ? getStaticType(lhs) : leftElement.ty
pe; | 11350 Type2 leftType = (leftElement == null) ? getStaticType(lhs) : leftElement.ty
pe; |
| 11359 Type2 staticRightType = getStaticType(rhs); | 11351 Type2 staticRightType = getStaticType(rhs); |
| 11360 bool isStaticAssignable = staticRightType.isAssignableTo(leftType); | 11352 bool isStaticAssignable = staticRightType.isAssignableTo(leftType); |
| 11361 Type2 propagatedRightType = getPropagatedType(rhs); | 11353 Type2 propagatedRightType = getPropagatedType(rhs); |
| 11362 if (propagatedRightType == null) { | 11354 if (_strictMode || propagatedRightType == null) { |
| 11363 if (!isStaticAssignable) { | 11355 if (!isStaticAssignable) { |
| 11364 _errorReporter.reportError2(StaticTypeWarningCode.INVALID_ASSIGNMENT, rh
s, [staticRightType.displayName, leftType.displayName]); | 11356 _errorReporter.reportError2(StaticTypeWarningCode.INVALID_ASSIGNMENT, rh
s, [staticRightType.displayName, leftType.displayName]); |
| 11365 return true; | 11357 return true; |
| 11366 } | 11358 } |
| 11367 } else { | 11359 } else { |
| 11368 bool isPropagatedAssignable = propagatedRightType.isAssignableTo(leftType)
; | 11360 bool isPropagatedAssignable = propagatedRightType.isAssignableTo(leftType)
; |
| 11369 if (!isStaticAssignable && !isPropagatedAssignable) { | 11361 if (!isStaticAssignable && !isPropagatedAssignable) { |
| 11370 _errorReporter.reportError2(StaticTypeWarningCode.INVALID_ASSIGNMENT, rh
s, [staticRightType.displayName, leftType.displayName]); | 11362 _errorReporter.reportError2(StaticTypeWarningCode.INVALID_ASSIGNMENT, rh
s, [staticRightType.displayName, leftType.displayName]); |
| 11371 return true; | 11363 return true; |
| 11372 } | 11364 } |
| 11373 } | 11365 } |
| 11374 return false; | 11366 return false; |
| 11375 } | 11367 } |
| 11376 | 11368 |
| 11377 /** | 11369 /** |
| 11378 * This verifies that the usage of the passed 'this' is valid. | 11370 * This verifies that the usage of the passed 'this' is valid. |
| 11379 * @param node the 'this' expression to evaluate | 11371 * @param node the 'this' expression to evaluate |
| 11380 * @return {@code true} if and only if an error code is generated on the passe
d node | 11372 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11381 * @see CompileTimeErrorCode#INVALID_REFERENCE_TO_THIS | 11373 * @see CompileTimeErrorCode#INVALID_REFERENCE_TO_THIS |
| 11382 */ | 11374 */ |
| 11383 bool checkForInvalidReferenceToThis(ThisExpression node) { | 11375 bool checkForInvalidReferenceToThis(ThisExpression node) { |
| 11384 if (!isThisInValidContext(node)) { | 11376 if (!isThisInValidContext(node)) { |
| 11385 _errorReporter.reportError2(CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS
, node, []); | 11377 _errorReporter.reportError2(CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS
, node, []); |
| 11386 return true; | 11378 return true; |
| 11387 } | 11379 } |
| 11388 return false; | 11380 return false; |
| 11389 } | 11381 } |
| 11390 | 11382 |
| 11391 /** | 11383 /** |
| 11392 * Checks to ensure that first type argument to a map literal must be the 'Str
ing' type. | 11384 * Checks to ensure that first type argument to a map literal must be the 'Str
ing' type. |
| 11393 * @param arguments a non-{@code null}, non-empty {@link TypeName} node list f
rom the respective{@link MapLiteral} | 11385 * @param arguments a non-{@code null}, non-empty {@link TypeName} node list f
rom the respective{@link MapLiteral} |
| 11394 * @return {@code true} if and only if an error code is generated on the passe
d node | 11386 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11395 * @see CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_FOR_KEY | 11387 * @see CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_FOR_KEY |
| 11396 */ | 11388 */ |
| 11397 bool checkForInvalidTypeArgumentForKey(NodeList<TypeName> arguments) { | 11389 bool checkForInvalidTypeArgumentForKey(NodeList<TypeName> arguments) { |
| 11398 TypeName firstArgument = arguments[0]; | 11390 TypeName firstArgument = arguments[0]; |
| 11399 Type2 firstArgumentType = firstArgument.type; | 11391 Type2 firstArgumentType = firstArgument.type; |
| 11400 if (firstArgumentType != null && firstArgumentType != _typeProvider.stringTy
pe) { | 11392 if (firstArgumentType != null && firstArgumentType != _typeProvider.stringTy
pe) { |
| 11401 _errorReporter.reportError2(CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_FOR
_KEY, firstArgument, []); | 11393 _errorReporter.reportError2(CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_FOR
_KEY, firstArgument, []); |
| 11402 return true; | 11394 return true; |
| 11403 } | 11395 } |
| 11404 return false; | 11396 return false; |
| 11405 } | 11397 } |
| 11406 | 11398 |
| 11407 /** | 11399 /** |
| 11408 * Checks to ensure that the passed {@link ListLiteral} or {@link MapLiteral}
does not have a type | 11400 * Checks to ensure that the passed {@link ListLiteral} or {@link MapLiteral}
does not have a type |
| 11409 * parameter as a type argument. | 11401 * parameter as a type argument. |
| 11410 * @param arguments a non-{@code null}, non-empty {@link TypeName} node list f
rom the respective{@link ListLiteral} or {@link MapLiteral} | 11402 * @param arguments a non-{@code null}, non-empty {@link TypeName} node list f
rom the respective{@link ListLiteral} or {@link MapLiteral} |
| 11411 * @param errorCode either {@link CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_I
N_CONST_LIST} or{@link CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_IN_CONST_MAP} | 11403 * @param errorCode either {@link CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_I
N_CONST_LIST} or{@link CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_IN_CONST_MAP} |
| 11412 * @return {@code true} if and only if an error code is generated on the passe
d node | 11404 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11413 */ | 11405 */ |
| 11414 bool checkForInvalidTypeArgumentInConstTypedLiteral(NodeList<TypeName> argumen
ts, ErrorCode errorCode) { | 11406 bool checkForInvalidTypeArgumentInConstTypedLiteral(NodeList<TypeName> argumen
ts, ErrorCode errorCode) { |
| 11415 bool foundError = false; | 11407 bool foundError = false; |
| 11416 for (TypeName typeName in arguments) { | 11408 for (TypeName typeName in arguments) { |
| 11417 if (typeName.type is TypeVariableType) { | 11409 if (typeName.type is TypeVariableType) { |
| 11418 _errorReporter.reportError2(errorCode, typeName, [typeName.name]); | 11410 _errorReporter.reportError2(errorCode, typeName, [typeName.name]); |
| 11419 foundError = true; | 11411 foundError = true; |
| 11420 } | 11412 } |
| 11421 } | 11413 } |
| 11422 return foundError; | 11414 return foundError; |
| 11423 } | 11415 } |
| 11424 | 11416 |
| 11425 /** | 11417 /** |
| 11426 * This verifies that the {@link #enclosingClass} does not define members with
the same name as | 11418 * This verifies that the {@link #enclosingClass} does not define members with
the same name as |
| 11427 * the enclosing class. | 11419 * the enclosing class. |
| 11428 * @return {@code true} if and only if an error code is generated on the passe
d node | 11420 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11429 * @see CompileTimeErrorCode#MEMBER_WITH_CLASS_NAME | 11421 * @see CompileTimeErrorCode#MEMBER_WITH_CLASS_NAME |
| 11430 */ | 11422 */ |
| 11431 bool checkForMemberWithClassName() { | 11423 bool checkForMemberWithClassName() { |
| 11432 if (_enclosingClass == null) { | 11424 if (_enclosingClass == null) { |
| 11433 return false; | 11425 return false; |
| 11434 } | 11426 } |
| 11435 String className = _enclosingClass.name; | 11427 String className = _enclosingClass.name; |
| 11436 if (className == null) { | 11428 if (className == null) { |
| 11437 return false; | 11429 return false; |
| 11438 } | 11430 } |
| 11439 bool problemReported = false; | 11431 bool problemReported = false; |
| 11440 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { | 11432 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { |
| 11441 if (className == accessor.name) { | 11433 if (className == accessor.name) { |
| 11442 _errorReporter.reportError3(CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME,
accessor.nameOffset, className.length, []); | 11434 _errorReporter.reportError3(CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME,
accessor.nameOffset, className.length, []); |
| 11443 problemReported = true; | 11435 problemReported = true; |
| 11444 } | 11436 } |
| 11445 } | 11437 } |
| 11446 return problemReported; | 11438 return problemReported; |
| 11447 } | 11439 } |
| 11448 | 11440 |
| 11449 /** | 11441 /** |
| 11450 * Check to make sure that all similarly typed accessors are of the same type
(including inherited | 11442 * Check to make sure that all similarly typed accessors are of the same type
(including inherited |
| 11451 * accessors). | 11443 * accessors). |
| 11452 * @param node The accessor currently being visited. | 11444 * @param node The accessor currently being visited. |
| 11453 */ | 11445 */ |
| 11454 void checkForMismatchedAccessorTypes(Declaration accessorDeclaration, String a
ccessorTextName) { | 11446 void checkForMismatchedAccessorTypes(Declaration accessorDeclaration, String a
ccessorTextName) { |
| 11455 PropertyAccessorElement counterpartAccessor = null; | 11447 PropertyAccessorElement counterpartAccessor = null; |
| 11456 ExecutableElement accessorElement = accessorDeclaration.element as Executabl
eElement; | 11448 ExecutableElement accessorElement = accessorDeclaration.element as Executabl
eElement; |
| 11457 if (accessorElement is! PropertyAccessorElement) { | 11449 if (accessorElement is! PropertyAccessorElement) { |
| 11458 return; | 11450 return; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 11469 setterType = getSetterType(counterpartAccessor); | 11461 setterType = getSetterType(counterpartAccessor); |
| 11470 } else if (propertyAccessorElement.isSetter()) { | 11462 } else if (propertyAccessorElement.isSetter()) { |
| 11471 setterType = getSetterType(propertyAccessorElement); | 11463 setterType = getSetterType(propertyAccessorElement); |
| 11472 counterpartAccessor = propertyAccessorElement.correspondingGetter; | 11464 counterpartAccessor = propertyAccessorElement.correspondingGetter; |
| 11473 getterType = getGetterType(counterpartAccessor); | 11465 getterType = getGetterType(counterpartAccessor); |
| 11474 } | 11466 } |
| 11475 if (setterType != null && getterType != null && !getterType.isAssignableTo(s
etterType)) { | 11467 if (setterType != null && getterType != null && !getterType.isAssignableTo(s
etterType)) { |
| 11476 _errorReporter.reportError2(StaticWarningCode.MISMATCHED_GETTER_AND_SETTER
_TYPES, accessorDeclaration, [accessorTextName, setterType.displayName, getterTy
pe.displayName]); | 11468 _errorReporter.reportError2(StaticWarningCode.MISMATCHED_GETTER_AND_SETTER
_TYPES, accessorDeclaration, [accessorTextName, setterType.displayName, getterTy
pe.displayName]); |
| 11477 } | 11469 } |
| 11478 } | 11470 } |
| 11479 | 11471 |
| 11480 /** | 11472 /** |
| 11481 * This verifies that the passed mixin does not have an explicitly declared co
nstructor. | 11473 * This verifies that the passed mixin does not have an explicitly declared co
nstructor. |
| 11482 * @param mixinName the node to report problem on | 11474 * @param mixinName the node to report problem on |
| 11483 * @param mixinElement the mixing to evaluate | 11475 * @param mixinElement the mixing to evaluate |
| 11484 * @return {@code true} if and only if an error code is generated on the passe
d node | 11476 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11485 * @see CompileTimeErrorCode#MIXIN_DECLARES_CONSTRUCTOR | 11477 * @see CompileTimeErrorCode#MIXIN_DECLARES_CONSTRUCTOR |
| 11486 */ | 11478 */ |
| 11487 bool checkForMixinDeclaresConstructor(TypeName mixinName, ClassElement mixinEl
ement) { | 11479 bool checkForMixinDeclaresConstructor(TypeName mixinName, ClassElement mixinEl
ement) { |
| 11488 for (ConstructorElement constructor in mixinElement.constructors) { | 11480 for (ConstructorElement constructor in mixinElement.constructors) { |
| 11489 if (!constructor.isSynthetic() && !constructor.isFactory()) { | 11481 if (!constructor.isSynthetic() && !constructor.isFactory()) { |
| 11490 _errorReporter.reportError2(CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUC
TOR, mixinName, [mixinElement.name]); | 11482 _errorReporter.reportError2(CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUC
TOR, mixinName, [mixinElement.name]); |
| 11491 return true; | 11483 return true; |
| 11492 } | 11484 } |
| 11493 } | 11485 } |
| 11494 return false; | 11486 return false; |
| 11495 } | 11487 } |
| 11496 | 11488 |
| 11497 /** | 11489 /** |
| 11498 * This verifies that the passed mixin has the 'Object' superclass. | 11490 * This verifies that the passed mixin has the 'Object' superclass. |
| 11499 * @param mixinName the node to report problem on | 11491 * @param mixinName the node to report problem on |
| 11500 * @param mixinElement the mixing to evaluate | 11492 * @param mixinElement the mixing to evaluate |
| 11501 * @return {@code true} if and only if an error code is generated on the passe
d node | 11493 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11502 * @see CompileTimeErrorCode#MIXIN_INHERITS_FROM_NOT_OBJECT | 11494 * @see CompileTimeErrorCode#MIXIN_INHERITS_FROM_NOT_OBJECT |
| 11503 */ | 11495 */ |
| 11504 bool checkForMixinInheritsNotFromObject(TypeName mixinName, ClassElement mixin
Element) { | 11496 bool checkForMixinInheritsNotFromObject(TypeName mixinName, ClassElement mixin
Element) { |
| 11505 InterfaceType mixinSupertype = mixinElement.supertype; | 11497 InterfaceType mixinSupertype = mixinElement.supertype; |
| 11506 if (mixinSupertype != null) { | 11498 if (mixinSupertype != null) { |
| 11507 if (!mixinSupertype.isObject() || !mixinElement.isTypedef() && mixinElemen
t.mixins.length != 0) { | 11499 if (!mixinSupertype.isObject() || !mixinElement.isTypedef() && mixinElemen
t.mixins.length != 0) { |
| 11508 _errorReporter.reportError2(CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT
_OBJECT, mixinName, [mixinElement.name]); | 11500 _errorReporter.reportError2(CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT
_OBJECT, mixinName, [mixinElement.name]); |
| 11509 return true; | 11501 return true; |
| 11510 } | 11502 } |
| 11511 } | 11503 } |
| 11512 return false; | 11504 return false; |
| 11513 } | 11505 } |
| 11514 | 11506 |
| 11515 /** | 11507 /** |
| 11516 * This verifies that the passed mixin does not reference 'super'. | 11508 * This verifies that the passed mixin does not reference 'super'. |
| 11517 * @param mixinName the node to report problem on | 11509 * @param mixinName the node to report problem on |
| 11518 * @param mixinElement the mixing to evaluate | 11510 * @param mixinElement the mixing to evaluate |
| 11519 * @return {@code true} if and only if an error code is generated on the passe
d node | 11511 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11520 * @see CompileTimeErrorCode#MIXIN_REFERENCES_SUPER | 11512 * @see CompileTimeErrorCode#MIXIN_REFERENCES_SUPER |
| 11521 */ | 11513 */ |
| 11522 bool checkForMixinReferencesSuper(TypeName mixinName, ClassElement mixinElemen
t) { | 11514 bool checkForMixinReferencesSuper(TypeName mixinName, ClassElement mixinElemen
t) { |
| 11523 if (mixinElement.hasReferenceToSuper()) { | 11515 if (mixinElement.hasReferenceToSuper()) { |
| 11524 _errorReporter.reportError2(CompileTimeErrorCode.MIXIN_REFERENCES_SUPER, m
ixinName, [mixinElement.name]); | 11516 _errorReporter.reportError2(CompileTimeErrorCode.MIXIN_REFERENCES_SUPER, m
ixinName, [mixinElement.name]); |
| 11525 } | 11517 } |
| 11526 return false; | 11518 return false; |
| 11527 } | 11519 } |
| 11528 | 11520 |
| 11529 /** | 11521 /** |
| 11530 * This verifies that the passed constructor has at most one 'super' initializ
er. | 11522 * This verifies that the passed constructor has at most one 'super' initializ
er. |
| 11531 * @param node the constructor declaration to evaluate | 11523 * @param node the constructor declaration to evaluate |
| 11532 * @return {@code true} if and only if an error code is generated on the passe
d node | 11524 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11533 * @see CompileTimeErrorCode#MULTIPLE_SUPER_INITIALIZERS | 11525 * @see CompileTimeErrorCode#MULTIPLE_SUPER_INITIALIZERS |
| 11534 */ | 11526 */ |
| 11535 bool checkForMultipleSuperInitializers(ConstructorDeclaration node) { | 11527 bool checkForMultipleSuperInitializers(ConstructorDeclaration node) { |
| 11536 int numSuperInitializers = 0; | 11528 int numSuperInitializers = 0; |
| 11537 for (ConstructorInitializer initializer in node.initializers) { | 11529 for (ConstructorInitializer initializer in node.initializers) { |
| 11538 if (initializer is SuperConstructorInvocation) { | 11530 if (initializer is SuperConstructorInvocation) { |
| 11539 numSuperInitializers++; | 11531 numSuperInitializers++; |
| 11540 if (numSuperInitializers > 1) { | 11532 if (numSuperInitializers > 1) { |
| 11541 _errorReporter.reportError2(CompileTimeErrorCode.MULTIPLE_SUPER_INITIA
LIZERS, initializer, []); | 11533 _errorReporter.reportError2(CompileTimeErrorCode.MULTIPLE_SUPER_INITIA
LIZERS, initializer, []); |
| 11542 } | 11534 } |
| 11543 } | 11535 } |
| 11544 } | 11536 } |
| 11545 return numSuperInitializers > 0; | 11537 return numSuperInitializers > 0; |
| 11546 } | 11538 } |
| 11547 | 11539 |
| 11548 /** | 11540 /** |
| 11549 * Checks to ensure that native function bodies can only in SDK code. | 11541 * Checks to ensure that native function bodies can only in SDK code. |
| 11550 * @param node the native function body to test | 11542 * @param node the native function body to test |
| 11551 * @return {@code true} if and only if an error code is generated on the passe
d node | 11543 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11552 * @see ParserErrorCode#NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE | 11544 * @see ParserErrorCode#NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE |
| 11553 */ | 11545 */ |
| 11554 bool checkForNativeFunctionBodyInNonSDKCode(NativeFunctionBody node) { | 11546 bool checkForNativeFunctionBodyInNonSDKCode(NativeFunctionBody node) { |
| 11555 if (!_isInSystemLibrary) { | 11547 if (!_isInSystemLibrary) { |
| 11556 _errorReporter.reportError2(ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SD
K_CODE, node, []); | 11548 _errorReporter.reportError2(ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SD
K_CODE, node, []); |
| 11557 return true; | 11549 return true; |
| 11558 } | 11550 } |
| 11559 return false; | 11551 return false; |
| 11560 } | 11552 } |
| 11561 | 11553 |
| 11562 /** | 11554 /** |
| 11563 * This verifies that the passed 'new' instance creation expression invokes ex
isting constructor. | 11555 * This verifies that the passed 'new' instance creation expression invokes ex
isting constructor. |
| 11564 * <p> | 11556 * <p> |
| 11565 * This method assumes that the instance creation was tested to be 'new' befor
e being called. | 11557 * This method assumes that the instance creation was tested to be 'new' befor
e being called. |
| 11566 * @param node the instance creation expression to evaluate | 11558 * @param node the instance creation expression to evaluate |
| 11567 * @return {@code true} if and only if an error code is generated on the passe
d node | 11559 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11568 * @see StaticWarningCode#NEW_WITH_UNDEFINED_CONSTRUCTOR | 11560 * @see StaticWarningCode#NEW_WITH_UNDEFINED_CONSTRUCTOR |
| 11569 */ | 11561 */ |
| 11570 bool checkForNewWithUndefinedConstructor(InstanceCreationExpression node) { | 11562 bool checkForNewWithUndefinedConstructor(InstanceCreationExpression node) { |
| 11571 if (node.element != null) { | 11563 if (node.element != null) { |
| 11572 return false; | 11564 return false; |
| 11573 } | 11565 } |
| 11574 ConstructorName constructorName2 = node.constructorName; | 11566 ConstructorName constructorName2 = node.constructorName; |
| 11575 if (constructorName2 == null) { | 11567 if (constructorName2 == null) { |
| 11576 return false; | 11568 return false; |
| 11577 } | 11569 } |
| 11578 TypeName type2 = constructorName2.type; | 11570 TypeName type2 = constructorName2.type; |
| 11579 if (type2 == null) { | 11571 if (type2 == null) { |
| 11580 return false; | 11572 return false; |
| 11581 } | 11573 } |
| 11582 Identifier className = type2.name; | 11574 Identifier className = type2.name; |
| 11583 SimpleIdentifier name2 = constructorName2.name; | 11575 SimpleIdentifier name2 = constructorName2.name; |
| 11584 if (name2 != null) { | 11576 if (name2 != null) { |
| 11585 _errorReporter.reportError2(StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCT
OR, name2, [className, name2]); | 11577 _errorReporter.reportError2(StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCT
OR, name2, [className, name2]); |
| 11586 } else { | 11578 } else { |
| 11587 _errorReporter.reportError2(StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCT
OR_DEFAULT, constructorName2, [className]); | 11579 _errorReporter.reportError2(StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCT
OR_DEFAULT, constructorName2, [className]); |
| 11588 } | 11580 } |
| 11589 return true; | 11581 return true; |
| 11590 } | 11582 } |
| 11591 | 11583 |
| 11592 /** | 11584 /** |
| 11593 * This checks that passed class declaration overrides all members required by
its superclasses | 11585 * This checks that passed class declaration overrides all members required by
its superclasses |
| 11594 * and interfaces. | 11586 * and interfaces. |
| 11595 * @param node the {@link ClassDeclaration} to evaluate | 11587 * @param node the {@link ClassDeclaration} to evaluate |
| 11596 * @return {@code true} if and only if an error code is generated on the passe
d node | 11588 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11597 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE | 11589 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE |
| 11598 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO | 11590 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO |
| 11599 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE | 11591 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE |
| 11600 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR | 11592 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR |
| 11601 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLU
S | 11593 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLU
S |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11670 _errorReporter.reportError2(StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_
ABSTRACT_MEMBER_TWO, node.name, [missingOverridesArray[0].enclosingElement.displ
ayName, missingOverridesArray[0].displayName, missingOverridesArray[1].enclosing
Element.displayName, missingOverridesArray[1].displayName]); | 11662 _errorReporter.reportError2(StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_
ABSTRACT_MEMBER_TWO, node.name, [missingOverridesArray[0].enclosingElement.displ
ayName, missingOverridesArray[0].displayName, missingOverridesArray[1].enclosing
Element.displayName, missingOverridesArray[1].displayName]); |
| 11671 } else if (missingOverridesSize == 3) { | 11663 } else if (missingOverridesSize == 3) { |
| 11672 _errorReporter.reportError2(StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_
ABSTRACT_MEMBER_THREE, node.name, [missingOverridesArray[0].enclosingElement.dis
playName, missingOverridesArray[0].displayName, missingOverridesArray[1].enclosi
ngElement.displayName, missingOverridesArray[1].displayName, missingOverridesArr
ay[2].enclosingElement.displayName, missingOverridesArray[2].displayName]); | 11664 _errorReporter.reportError2(StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_
ABSTRACT_MEMBER_THREE, node.name, [missingOverridesArray[0].enclosingElement.dis
playName, missingOverridesArray[0].displayName, missingOverridesArray[1].enclosi
ngElement.displayName, missingOverridesArray[1].displayName, missingOverridesArr
ay[2].enclosingElement.displayName, missingOverridesArray[2].displayName]); |
| 11673 } else if (missingOverridesSize == 4) { | 11665 } else if (missingOverridesSize == 4) { |
| 11674 _errorReporter.reportError2(StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_
ABSTRACT_MEMBER_FOUR, node.name, [missingOverridesArray[0].enclosingElement.disp
layName, missingOverridesArray[0].displayName, missingOverridesArray[1].enclosin
gElement.displayName, missingOverridesArray[1].displayName, missingOverridesArra
y[2].enclosingElement.displayName, missingOverridesArray[2].displayName, missing
OverridesArray[3].enclosingElement.displayName, missingOverridesArray[3].display
Name]); | 11666 _errorReporter.reportError2(StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_
ABSTRACT_MEMBER_FOUR, node.name, [missingOverridesArray[0].enclosingElement.disp
layName, missingOverridesArray[0].displayName, missingOverridesArray[1].enclosin
gElement.displayName, missingOverridesArray[1].displayName, missingOverridesArra
y[2].enclosingElement.displayName, missingOverridesArray[2].displayName, missing
OverridesArray[3].enclosingElement.displayName, missingOverridesArray[3].display
Name]); |
| 11675 } else { | 11667 } else { |
| 11676 _errorReporter.reportError2(StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_
ABSTRACT_MEMBER_FIVE_PLUS, node.name, [missingOverridesArray[0].enclosingElement
.displayName, missingOverridesArray[0].displayName, missingOverridesArray[1].enc
losingElement.displayName, missingOverridesArray[1].displayName, missingOverride
sArray[2].enclosingElement.displayName, missingOverridesArray[2].displayName, mi
ssingOverridesArray[3].enclosingElement.displayName, missingOverridesArray[3].di
splayName, missingOverridesArray.length - 4]); | 11668 _errorReporter.reportError2(StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_
ABSTRACT_MEMBER_FIVE_PLUS, node.name, [missingOverridesArray[0].enclosingElement
.displayName, missingOverridesArray[0].displayName, missingOverridesArray[1].enc
losingElement.displayName, missingOverridesArray[1].displayName, missingOverride
sArray[2].enclosingElement.displayName, missingOverridesArray[2].displayName, mi
ssingOverridesArray[3].enclosingElement.displayName, missingOverridesArray[3].di
splayName, missingOverridesArray.length - 4]); |
| 11677 } | 11669 } |
| 11678 return true; | 11670 return true; |
| 11679 } | 11671 } |
| 11680 | 11672 |
| 11681 /** | 11673 /** |
| 11682 * Checks to ensure that the expressions that need to be of type bool, are. Ot
herwise an error is | 11674 * Checks to ensure that the expressions that need to be of type bool, are. Ot
herwise an error is |
| 11683 * reported on the expression. | 11675 * reported on the expression. |
| 11684 * @param condition the conditional expression to test | 11676 * @param condition the conditional expression to test |
| 11685 * @return {@code true} if and only if an error code is generated on the passe
d node | 11677 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11686 * @see StaticTypeWarningCode#NON_BOOL_CONDITION | 11678 * @see StaticTypeWarningCode#NON_BOOL_CONDITION |
| 11687 */ | 11679 */ |
| 11688 bool checkForNonBoolCondition(Expression condition) { | 11680 bool checkForNonBoolCondition(Expression condition) { |
| 11689 Type2 conditionType = getStaticType(condition); | 11681 Type2 conditionType = getStaticType(condition); |
| 11690 if (conditionType != null && !conditionType.isAssignableTo(_typeProvider.boo
lType)) { | 11682 if (conditionType != null && !conditionType.isAssignableTo(_typeProvider.boo
lType)) { |
| 11691 _errorReporter.reportError2(StaticTypeWarningCode.NON_BOOL_CONDITION, cond
ition, []); | 11683 _errorReporter.reportError2(StaticTypeWarningCode.NON_BOOL_CONDITION, cond
ition, []); |
| 11692 return true; | 11684 return true; |
| 11693 } | 11685 } |
| 11694 return false; | 11686 return false; |
| 11695 } | 11687 } |
| 11696 | 11688 |
| 11697 /** | 11689 /** |
| 11698 * This verifies that the passed assert statement has either a 'bool' or '() -
> bool' input. | 11690 * This verifies that the passed assert statement has either a 'bool' or '() -
> bool' input. |
| 11699 * @param node the assert statement to evaluate | 11691 * @param node the assert statement to evaluate |
| 11700 * @return {@code true} if and only if an error code is generated on the passe
d node | 11692 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11701 * @see StaticTypeWarningCode#NON_BOOL_EXPRESSION | 11693 * @see StaticTypeWarningCode#NON_BOOL_EXPRESSION |
| 11702 */ | 11694 */ |
| 11703 bool checkForNonBoolExpression(AssertStatement node) { | 11695 bool checkForNonBoolExpression(AssertStatement node) { |
| 11704 Expression expression = node.condition; | 11696 Expression expression = node.condition; |
| 11705 Type2 type = getStaticType(expression); | 11697 Type2 type = getStaticType(expression); |
| 11706 if (type is InterfaceType) { | 11698 if (type is InterfaceType) { |
| 11707 if (!type.isAssignableTo(_typeProvider.boolType)) { | 11699 if (!type.isAssignableTo(_typeProvider.boolType)) { |
| 11708 _errorReporter.reportError2(StaticTypeWarningCode.NON_BOOL_EXPRESSION, e
xpression, []); | 11700 _errorReporter.reportError2(StaticTypeWarningCode.NON_BOOL_EXPRESSION, e
xpression, []); |
| 11709 return true; | 11701 return true; |
| 11710 } | 11702 } |
| 11711 } else if (type is FunctionType) { | 11703 } else if (type is FunctionType) { |
| 11712 FunctionType functionType = type as FunctionType; | 11704 FunctionType functionType = type as FunctionType; |
| 11713 if (functionType.typeArguments.length == 0 && !functionType.returnType.isA
ssignableTo(_typeProvider.boolType)) { | 11705 if (functionType.typeArguments.length == 0 && !functionType.returnType.isA
ssignableTo(_typeProvider.boolType)) { |
| 11714 _errorReporter.reportError2(StaticTypeWarningCode.NON_BOOL_EXPRESSION, e
xpression, []); | 11706 _errorReporter.reportError2(StaticTypeWarningCode.NON_BOOL_EXPRESSION, e
xpression, []); |
| 11715 return true; | 11707 return true; |
| 11716 } | 11708 } |
| 11717 } | 11709 } |
| 11718 return false; | 11710 return false; |
| 11719 } | 11711 } |
| 11720 | 11712 |
| 11721 /** | 11713 /** |
| 11722 * This verifies the passed map literal either: | 11714 * This verifies the passed map literal either: |
| 11723 * <ul> | 11715 * <ul> |
| 11724 * <li>has {@code const modifier}</li> | 11716 * <li>has {@code const modifier}</li> |
| 11725 * <li>has explicit type arguments</li> | 11717 * <li>has explicit type arguments</li> |
| 11726 * <li>is not start of the statement</li> | 11718 * <li>is not start of the statement</li> |
| 11727 * <ul> | 11719 * <ul> |
| 11728 * @param node the map literal to evaluate | 11720 * @param node the map literal to evaluate |
| 11729 * @return {@code true} if and only if an error code is generated on the passe
d node | 11721 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11730 * @see CompileTimeErrorCode#NON_CONST_MAP_AS_EXPRESSION_STATEMENT | 11722 * @see CompileTimeErrorCode#NON_CONST_MAP_AS_EXPRESSION_STATEMENT |
| 11731 */ | 11723 */ |
| 11732 bool checkForNonConstMapAsExpressionStatement(MapLiteral node) { | 11724 bool checkForNonConstMapAsExpressionStatement(MapLiteral node) { |
| 11733 if (node.modifier != null) { | 11725 if (node.modifier != null) { |
| 11734 return false; | 11726 return false; |
| 11735 } | 11727 } |
| 11736 if (node.typeArguments != null) { | 11728 if (node.typeArguments != null) { |
| 11737 return false; | 11729 return false; |
| 11738 } | 11730 } |
| 11739 Statement statement = node.getAncestor(ExpressionStatement); | 11731 Statement statement = node.getAncestor(ExpressionStatement); |
| 11740 if (statement == null) { | 11732 if (statement == null) { |
| 11741 return false; | 11733 return false; |
| 11742 } | 11734 } |
| 11743 if (statement.beginToken != node.beginToken) { | 11735 if (statement.beginToken != node.beginToken) { |
| 11744 return false; | 11736 return false; |
| 11745 } | 11737 } |
| 11746 _errorReporter.reportError2(CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION
_STATEMENT, node, []); | 11738 _errorReporter.reportError2(CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION
_STATEMENT, node, []); |
| 11747 return true; | 11739 return true; |
| 11748 } | 11740 } |
| 11749 | 11741 |
| 11750 /** | 11742 /** |
| 11751 * This verifies the passed method declaration of operator {@code \[\]=}, has
{@code void} return | 11743 * This verifies the passed method declaration of operator {@code \[\]=}, has
{@code void} return |
| 11752 * type. | 11744 * type. |
| 11753 * @param node the method declaration to evaluate | 11745 * @param node the method declaration to evaluate |
| 11754 * @return {@code true} if and only if an error code is generated on the passe
d node | 11746 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11755 * @see StaticWarningCode#NON_VOID_RETURN_FOR_OPERATOR | 11747 * @see StaticWarningCode#NON_VOID_RETURN_FOR_OPERATOR |
| 11756 */ | 11748 */ |
| 11757 bool checkForNonVoidReturnTypeForOperator(MethodDeclaration node) { | 11749 bool checkForNonVoidReturnTypeForOperator(MethodDeclaration node) { |
| 11758 SimpleIdentifier name2 = node.name; | 11750 SimpleIdentifier name2 = node.name; |
| 11759 if (name2.name != "[]=") { | 11751 if (name2.name != "[]=") { |
| 11760 return false; | 11752 return false; |
| 11761 } | 11753 } |
| 11762 TypeName typeName = node.returnType; | 11754 TypeName typeName = node.returnType; |
| 11763 if (typeName != null) { | 11755 if (typeName != null) { |
| 11764 Type2 type2 = typeName.type; | 11756 Type2 type2 = typeName.type; |
| 11765 if (type2 != null && !type2.isVoid()) { | 11757 if (type2 != null && !type2.isVoid()) { |
| 11766 _errorReporter.reportError2(StaticWarningCode.NON_VOID_RETURN_FOR_OPERAT
OR, typeName, []); | 11758 _errorReporter.reportError2(StaticWarningCode.NON_VOID_RETURN_FOR_OPERAT
OR, typeName, []); |
| 11767 } | 11759 } |
| 11768 } | 11760 } |
| 11769 return false; | 11761 return false; |
| 11770 } | 11762 } |
| 11771 | 11763 |
| 11772 /** | 11764 /** |
| 11773 * This verifies the passed setter has no return type or the {@code void} retu
rn type. | 11765 * This verifies the passed setter has no return type or the {@code void} retu
rn type. |
| 11774 * @param typeName the type name to evaluate | 11766 * @param typeName the type name to evaluate |
| 11775 * @return {@code true} if and only if an error code is generated on the passe
d node | 11767 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11776 * @see StaticWarningCode#NON_VOID_RETURN_FOR_SETTER | 11768 * @see StaticWarningCode#NON_VOID_RETURN_FOR_SETTER |
| 11777 */ | 11769 */ |
| 11778 bool checkForNonVoidReturnTypeForSetter(TypeName typeName) { | 11770 bool checkForNonVoidReturnTypeForSetter(TypeName typeName) { |
| 11779 if (typeName != null) { | 11771 if (typeName != null) { |
| 11780 Type2 type2 = typeName.type; | 11772 Type2 type2 = typeName.type; |
| 11781 if (type2 != null && !type2.isVoid()) { | 11773 if (type2 != null && !type2.isVoid()) { |
| 11782 _errorReporter.reportError2(StaticWarningCode.NON_VOID_RETURN_FOR_SETTER
, typeName, []); | 11774 _errorReporter.reportError2(StaticWarningCode.NON_VOID_RETURN_FOR_SETTER
, typeName, []); |
| 11783 } | 11775 } |
| 11784 } | 11776 } |
| 11785 return false; | 11777 return false; |
| 11786 } | 11778 } |
| 11787 | 11779 |
| 11788 /** | 11780 /** |
| 11789 * This verifies the passed operator-method declaration, does not have an opti
onal parameter. | 11781 * This verifies the passed operator-method declaration, does not have an opti
onal parameter. |
| 11790 * <p> | 11782 * <p> |
| 11791 * This method assumes that the method declaration was tested to be an operato
r declaration before | 11783 * This method assumes that the method declaration was tested to be an operato
r declaration before |
| 11792 * being called. | 11784 * being called. |
| 11793 * @param node the method declaration to evaluate | 11785 * @param node the method declaration to evaluate |
| 11794 * @return {@code true} if and only if an error code is generated on the passe
d node | 11786 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11795 * @see CompileTimeErrorCode#OPTIONAL_PARAMETER_IN_OPERATOR | 11787 * @see CompileTimeErrorCode#OPTIONAL_PARAMETER_IN_OPERATOR |
| 11796 */ | 11788 */ |
| 11797 bool checkForOptionalParameterInOperator(MethodDeclaration node) { | 11789 bool checkForOptionalParameterInOperator(MethodDeclaration node) { |
| 11798 FormalParameterList parameterList = node.parameters; | 11790 FormalParameterList parameterList = node.parameters; |
| 11799 if (parameterList == null) { | 11791 if (parameterList == null) { |
| 11800 return false; | 11792 return false; |
| 11801 } | 11793 } |
| 11802 bool foundError = false; | 11794 bool foundError = false; |
| 11803 NodeList<FormalParameter> formalParameters = parameterList.parameters; | 11795 NodeList<FormalParameter> formalParameters = parameterList.parameters; |
| 11804 for (FormalParameter formalParameter in formalParameters) { | 11796 for (FormalParameter formalParameter in formalParameters) { |
| 11805 if (formalParameter.kind.isOptional()) { | 11797 if (formalParameter.kind.isOptional()) { |
| 11806 _errorReporter.reportError2(CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_O
PERATOR, formalParameter, []); | 11798 _errorReporter.reportError2(CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_O
PERATOR, formalParameter, []); |
| 11807 foundError = true; | 11799 foundError = true; |
| 11808 } | 11800 } |
| 11809 } | 11801 } |
| 11810 return foundError; | 11802 return foundError; |
| 11811 } | 11803 } |
| 11812 | 11804 |
| 11813 /** | 11805 /** |
| 11814 * This checks for named optional parameters that begin with '_'. | 11806 * This checks for named optional parameters that begin with '_'. |
| 11815 * @param node the default formal parameter to evaluate | 11807 * @param node the default formal parameter to evaluate |
| 11816 * @return {@code true} if and only if an error code is generated on the passe
d node | 11808 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11817 * @see CompileTimeErrorCode#PRIVATE_OPTIONAL_PARAMETER | 11809 * @see CompileTimeErrorCode#PRIVATE_OPTIONAL_PARAMETER |
| 11818 */ | 11810 */ |
| 11819 bool checkForPrivateOptionalParameter(DefaultFormalParameter node) { | 11811 bool checkForPrivateOptionalParameter(DefaultFormalParameter node) { |
| 11820 sc.Token separator2 = node.separator; | 11812 sc.Token separator2 = node.separator; |
| 11821 if (separator2 != null && separator2.lexeme == ":") { | 11813 if (separator2 != null && separator2.lexeme == ":") { |
| 11822 NormalFormalParameter parameter2 = node.parameter; | 11814 NormalFormalParameter parameter2 = node.parameter; |
| 11823 SimpleIdentifier name = parameter2.identifier; | 11815 SimpleIdentifier name = parameter2.identifier; |
| 11824 if (!name.isSynthetic() && name.name.startsWith("_")) { | 11816 if (!name.isSynthetic() && name.name.startsWith("_")) { |
| 11825 _errorReporter.reportError2(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAME
TER, node, []); | 11817 _errorReporter.reportError2(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAME
TER, node, []); |
| 11826 return true; | 11818 return true; |
| 11827 } | 11819 } |
| 11828 } | 11820 } |
| 11829 return false; | 11821 return false; |
| 11830 } | 11822 } |
| 11831 | 11823 |
| 11832 /** | 11824 /** |
| 11833 * This checks if the passed constructor declaration is the redirecting genera
tive constructor and | 11825 * This checks if the passed constructor declaration is the redirecting genera
tive constructor and |
| 11834 * references itself directly or indirectly. | 11826 * references itself directly or indirectly. |
| 11835 * @param node the constructor declaration to evaluate | 11827 * @param node the constructor declaration to evaluate |
| 11836 * @return {@code true} if and only if an error code is generated on the passe
d node | 11828 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11837 * @see CompileTimeErrorCode#RECURSIVE_CONSTRUCTOR_REDIRECT | 11829 * @see CompileTimeErrorCode#RECURSIVE_CONSTRUCTOR_REDIRECT |
| 11838 */ | 11830 */ |
| 11839 bool checkForRecursiveConstructorRedirect(ConstructorDeclaration node) { | 11831 bool checkForRecursiveConstructorRedirect(ConstructorDeclaration node) { |
| 11840 if (node.factoryKeyword != null) { | 11832 if (node.factoryKeyword != null) { |
| 11841 return false; | 11833 return false; |
| 11842 } | 11834 } |
| 11843 for (ConstructorInitializer initializer in node.initializers) { | 11835 for (ConstructorInitializer initializer in node.initializers) { |
| 11844 if (initializer is RedirectingConstructorInvocation) { | 11836 if (initializer is RedirectingConstructorInvocation) { |
| 11845 ConstructorElement element2 = node.element; | 11837 ConstructorElement element2 = node.element; |
| 11846 if (!hasRedirectingFactoryConstructorCycle(element2)) { | 11838 if (!hasRedirectingFactoryConstructorCycle(element2)) { |
| 11847 return false; | 11839 return false; |
| 11848 } | 11840 } |
| 11849 _errorReporter.reportError2(CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_R
EDIRECT, initializer, []); | 11841 _errorReporter.reportError2(CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_R
EDIRECT, initializer, []); |
| 11850 return true; | 11842 return true; |
| 11851 } | 11843 } |
| 11852 } | 11844 } |
| 11853 return false; | 11845 return false; |
| 11854 } | 11846 } |
| 11855 | 11847 |
| 11856 /** | 11848 /** |
| 11857 * This checks if the passed constructor declaration has redirected constructo
r and references | 11849 * This checks if the passed constructor declaration has redirected constructo
r and references |
| 11858 * itself directly or indirectly. | 11850 * itself directly or indirectly. |
| 11859 * @param node the constructor declaration to evaluate | 11851 * @param node the constructor declaration to evaluate |
| 11860 * @return {@code true} if and only if an error code is generated on the passe
d node | 11852 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11861 * @see CompileTimeErrorCode#RECURSIVE_FACTORY_REDIRECT | 11853 * @see CompileTimeErrorCode#RECURSIVE_FACTORY_REDIRECT |
| 11862 */ | 11854 */ |
| 11863 bool checkForRecursiveFactoryRedirect(ConstructorDeclaration node) { | 11855 bool checkForRecursiveFactoryRedirect(ConstructorDeclaration node) { |
| 11864 ConstructorName redirectedConstructorNode = node.redirectedConstructor; | 11856 ConstructorName redirectedConstructorNode = node.redirectedConstructor; |
| 11865 if (redirectedConstructorNode == null) { | 11857 if (redirectedConstructorNode == null) { |
| 11866 return false; | 11858 return false; |
| 11867 } | 11859 } |
| 11868 ConstructorElement element2 = node.element; | 11860 ConstructorElement element2 = node.element; |
| 11869 if (!hasRedirectingFactoryConstructorCycle(element2)) { | 11861 if (!hasRedirectingFactoryConstructorCycle(element2)) { |
| 11870 return false; | 11862 return false; |
| 11871 } | 11863 } |
| 11872 _errorReporter.reportError2(CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
redirectedConstructorNode, []); | 11864 _errorReporter.reportError2(CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT,
redirectedConstructorNode, []); |
| 11873 return true; | 11865 return true; |
| 11874 } | 11866 } |
| 11875 | 11867 |
| 11876 /** | 11868 /** |
| 11877 * This checks the class declaration is not a superinterface to itself. | 11869 * This checks the class declaration is not a superinterface to itself. |
| 11878 * @param classElt the class element to test | 11870 * @param classElt the class element to test |
| 11879 * @param list a list containing the potentially cyclic implements path | 11871 * @param list a list containing the potentially cyclic implements path |
| 11880 * @return {@code true} if and only if an error code is generated on the passe
d element | 11872 * @return {@code true} if and only if an error code is generated on the passe
d element |
| 11881 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE | 11873 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE |
| 11882 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS | 11874 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS |
| 11883 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEME
NTS | 11875 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEME
NTS |
| 11884 */ | 11876 */ |
| 11885 bool checkForRecursiveInterfaceInheritance(ClassElement classElt, List<ClassEl
ement> list) { | 11877 bool checkForRecursiveInterfaceInheritance(ClassElement classElt, List<ClassEl
ement> list) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11929 } | 11921 } |
| 11930 } | 11922 } |
| 11931 for (ClassElement classElt2 in interfaceElements) { | 11923 for (ClassElement classElt2 in interfaceElements) { |
| 11932 if (checkForRecursiveInterfaceInheritance(classElt2, list)) { | 11924 if (checkForRecursiveInterfaceInheritance(classElt2, list)) { |
| 11933 return true; | 11925 return true; |
| 11934 } | 11926 } |
| 11935 } | 11927 } |
| 11936 list.removeAt(list.length - 1); | 11928 list.removeAt(list.length - 1); |
| 11937 return false; | 11929 return false; |
| 11938 } | 11930 } |
| 11939 | 11931 |
| 11940 /** | 11932 /** |
| 11941 * This checks the passed constructor declaration has a valid combination of r
edirected | 11933 * This checks the passed constructor declaration has a valid combination of r
edirected |
| 11942 * constructor invocation(s), super constructor invocations and field initiali
zers. | 11934 * constructor invocation(s), super constructor invocations and field initiali
zers. |
| 11943 * @param node the constructor declaration to evaluate | 11935 * @param node the constructor declaration to evaluate |
| 11944 * @return {@code true} if and only if an error code is generated on the passe
d node | 11936 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11945 * @see CompileTimeErrorCode#MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS | 11937 * @see CompileTimeErrorCode#MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS |
| 11946 * @see CompileTimeErrorCode#SUPER_IN_REDIRECTING_CONSTRUCTOR | 11938 * @see CompileTimeErrorCode#SUPER_IN_REDIRECTING_CONSTRUCTOR |
| 11947 * @see CompileTimeErrorCode#FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR | 11939 * @see CompileTimeErrorCode#FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR |
| 11948 */ | 11940 */ |
| 11949 bool checkForRedirectingConstructorErrorCodes(ConstructorDeclaration node) { | 11941 bool checkForRedirectingConstructorErrorCodes(ConstructorDeclaration node) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 11965 numProblems++; | 11957 numProblems++; |
| 11966 } | 11958 } |
| 11967 if (initializer is ConstructorFieldInitializer) { | 11959 if (initializer is ConstructorFieldInitializer) { |
| 11968 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_RED
IRECTING_CONSTRUCTOR, initializer, []); | 11960 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_RED
IRECTING_CONSTRUCTOR, initializer, []); |
| 11969 numProblems++; | 11961 numProblems++; |
| 11970 } | 11962 } |
| 11971 } | 11963 } |
| 11972 } | 11964 } |
| 11973 return numProblems != 0; | 11965 return numProblems != 0; |
| 11974 } | 11966 } |
| 11975 | 11967 |
| 11976 /** | 11968 /** |
| 11977 * This checks if the passed constructor declaration has redirected constructo
r with compatible | 11969 * This checks if the passed constructor declaration has redirected constructo
r with compatible |
| 11978 * function type. | 11970 * function type. |
| 11979 * @param node the constructor declaration to evaluate | 11971 * @param node the constructor declaration to evaluate |
| 11980 * @return {@code true} if and only if an error code is generated on the passe
d node | 11972 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 11981 * @see StaticWarningCode#REDIRECT_TO_INVALID_RETURN_TYPE | 11973 * @see StaticWarningCode#REDIRECT_TO_INVALID_RETURN_TYPE |
| 11982 * @see StaticWarningCode#REDIRECT_TO_INVALID_FUNCTION_TYPE | 11974 * @see StaticWarningCode#REDIRECT_TO_INVALID_FUNCTION_TYPE |
| 11983 */ | 11975 */ |
| 11984 bool checkForRedirectToInvalidFunction(ConstructorDeclaration node) { | 11976 bool checkForRedirectToInvalidFunction(ConstructorDeclaration node) { |
| 11985 ConstructorName redirectedNode = node.redirectedConstructor; | 11977 ConstructorName redirectedNode = node.redirectedConstructor; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 11997 if (!redirectedReturnType.isSubtypeOf(constructorReturnType)) { | 11989 if (!redirectedReturnType.isSubtypeOf(constructorReturnType)) { |
| 11998 _errorReporter.reportError2(StaticWarningCode.REDIRECT_TO_INVALID_RETURN_T
YPE, redirectedNode, [redirectedReturnType, constructorReturnType]); | 11990 _errorReporter.reportError2(StaticWarningCode.REDIRECT_TO_INVALID_RETURN_T
YPE, redirectedNode, [redirectedReturnType, constructorReturnType]); |
| 11999 return true; | 11991 return true; |
| 12000 } | 11992 } |
| 12001 if (!redirectedType.isSubtypeOf(constructorType)) { | 11993 if (!redirectedType.isSubtypeOf(constructorType)) { |
| 12002 _errorReporter.reportError2(StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION
_TYPE, redirectedNode, [redirectedType, constructorType]); | 11994 _errorReporter.reportError2(StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION
_TYPE, redirectedNode, [redirectedType, constructorType]); |
| 12003 return true; | 11995 return true; |
| 12004 } | 11996 } |
| 12005 return false; | 11997 return false; |
| 12006 } | 11998 } |
| 12007 | 11999 |
| 12008 /** | 12000 /** |
| 12009 * This checks if the passed constructor declaration has redirected constructo
r and references | 12001 * This checks if the passed constructor declaration has redirected constructo
r and references |
| 12010 * itself directly or indirectly. TODO(scheglov) | 12002 * itself directly or indirectly. TODO(scheglov) |
| 12011 * @param node the constructor declaration to evaluate | 12003 * @param node the constructor declaration to evaluate |
| 12012 * @return {@code true} if and only if an error code is generated on the passe
d node | 12004 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 12013 * @see CompileTimeErrorCode#REDIRECT_TO_NON_CONST_CONSTRUCTOR | 12005 * @see CompileTimeErrorCode#REDIRECT_TO_NON_CONST_CONSTRUCTOR |
| 12014 */ | 12006 */ |
| 12015 bool checkForRedirectToNonConstConstructor(ConstructorDeclaration node) { | 12007 bool checkForRedirectToNonConstConstructor(ConstructorDeclaration node) { |
| 12016 ConstructorName redirectedConstructorNode = node.redirectedConstructor; | 12008 ConstructorName redirectedConstructorNode = node.redirectedConstructor; |
| 12017 if (redirectedConstructorNode == null) { | 12009 if (redirectedConstructorNode == null) { |
| 12018 return false; | 12010 return false; |
| 12019 } | 12011 } |
| 12020 ConstructorElement element2 = node.element; | 12012 ConstructorElement element2 = node.element; |
| 12021 if (element2 == null) { | 12013 if (element2 == null) { |
| 12022 return false; | 12014 return false; |
| 12023 } | 12015 } |
| 12024 if (!element2.isConst()) { | 12016 if (!element2.isConst()) { |
| 12025 return false; | 12017 return false; |
| 12026 } | 12018 } |
| 12027 ConstructorElement redirectedConstructor2 = element2.redirectedConstructor; | 12019 ConstructorElement redirectedConstructor2 = element2.redirectedConstructor; |
| 12028 if (redirectedConstructor2 == null) { | 12020 if (redirectedConstructor2 == null) { |
| 12029 return false; | 12021 return false; |
| 12030 } | 12022 } |
| 12031 if (redirectedConstructor2.isConst()) { | 12023 if (redirectedConstructor2.isConst()) { |
| 12032 return false; | 12024 return false; |
| 12033 } | 12025 } |
| 12034 _errorReporter.reportError2(CompileTimeErrorCode.REDIRECT_TO_NON_CONST_CONST
RUCTOR, redirectedConstructorNode, []); | 12026 _errorReporter.reportError2(CompileTimeErrorCode.REDIRECT_TO_NON_CONST_CONST
RUCTOR, redirectedConstructorNode, []); |
| 12035 return true; | 12027 return true; |
| 12036 } | 12028 } |
| 12037 | 12029 |
| 12038 /** | 12030 /** |
| 12039 * This checks if the passed identifier is banned because it is part of the va
riable declaration | 12031 * This checks if the passed identifier is banned because it is part of the va
riable declaration |
| 12040 * with the same name. | 12032 * with the same name. |
| 12041 * @param node the identifier to evaluate | 12033 * @param node the identifier to evaluate |
| 12042 * @return {@code true} if and only if an error code is generated on the passe
d node | 12034 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 12043 * @see CompileTimeErrorCode#REFERENCE_TO_DECLARED_VARIABLE_IN_INITIALIZER | 12035 * @see CompileTimeErrorCode#REFERENCE_TO_DECLARED_VARIABLE_IN_INITIALIZER |
| 12044 */ | 12036 */ |
| 12045 bool checkForReferenceToDeclaredVariableInInitializer(SimpleIdentifier node) { | 12037 bool checkForReferenceToDeclaredVariableInInitializer(SimpleIdentifier node) { |
| 12046 ASTNode parent2 = node.parent; | 12038 ASTNode parent2 = node.parent; |
| 12047 if (parent2 is PrefixedIdentifier) { | 12039 if (parent2 is PrefixedIdentifier) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 12074 return false; | 12066 return false; |
| 12075 } | 12067 } |
| 12076 } | 12068 } |
| 12077 String name2 = node.name; | 12069 String name2 = node.name; |
| 12078 if (!_namesForReferenceToDeclaredVariableInInitializer.contains(name2)) { | 12070 if (!_namesForReferenceToDeclaredVariableInInitializer.contains(name2)) { |
| 12079 return false; | 12071 return false; |
| 12080 } | 12072 } |
| 12081 _errorReporter.reportError2(CompileTimeErrorCode.REFERENCE_TO_DECLARED_VARIA
BLE_IN_INITIALIZER, node, [name2]); | 12073 _errorReporter.reportError2(CompileTimeErrorCode.REFERENCE_TO_DECLARED_VARIA
BLE_IN_INITIALIZER, node, [name2]); |
| 12082 return true; | 12074 return true; |
| 12083 } | 12075 } |
| 12084 | 12076 |
| 12085 /** | 12077 /** |
| 12086 * This checks that the rethrow is inside of a catch clause. | 12078 * This checks that the rethrow is inside of a catch clause. |
| 12087 * @param node the rethrow expression to evaluate | 12079 * @param node the rethrow expression to evaluate |
| 12088 * @return {@code true} if and only if an error code is generated on the passe
d node | 12080 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 12089 * @see CompileTimeErrorCode#RETHROW_OUTSIDE_CATCH | 12081 * @see CompileTimeErrorCode#RETHROW_OUTSIDE_CATCH |
| 12090 */ | 12082 */ |
| 12091 bool checkForRethrowOutsideCatch(RethrowExpression node) { | 12083 bool checkForRethrowOutsideCatch(RethrowExpression node) { |
| 12092 if (!_isInCatchClause) { | 12084 if (!_isInCatchClause) { |
| 12093 _errorReporter.reportError2(CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH, no
de, []); | 12085 _errorReporter.reportError2(CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH, no
de, []); |
| 12094 return true; | 12086 return true; |
| 12095 } | 12087 } |
| 12096 return false; | 12088 return false; |
| 12097 } | 12089 } |
| 12098 | 12090 |
| 12099 /** | 12091 /** |
| 12100 * This checks that if the given "target" is the type reference then the "name
" is not the | 12092 * This checks that if the given "target" is the type reference then the "name
" is not the |
| 12101 * reference to a instance member. | 12093 * reference to a instance member. |
| 12102 * @param target the target of the name access to evaluate | 12094 * @param target the target of the name access to evaluate |
| 12103 * @param name the accessed name to evaluate | 12095 * @param name the accessed name to evaluate |
| 12104 * @return {@code true} if and only if an error code is generated on the passe
d node | 12096 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 12105 * @see StaticWarningCode#STATIC_ACCESS_TO_INSTANCE_MEMBER | 12097 * @see StaticWarningCode#STATIC_ACCESS_TO_INSTANCE_MEMBER |
| 12106 */ | 12098 */ |
| 12107 bool checkForStaticAccessToInstanceMember(Expression target, SimpleIdentifier
name2) { | 12099 bool checkForStaticAccessToInstanceMember(Expression target, SimpleIdentifier
name2) { |
| 12108 Element element2 = name2.element; | 12100 Element element2 = name2.element; |
| 12109 if (element2 is! ExecutableElement) { | 12101 if (element2 is! ExecutableElement) { |
| 12110 return false; | 12102 return false; |
| 12111 } | 12103 } |
| 12112 ExecutableElement memberElement = element2 as ExecutableElement; | 12104 ExecutableElement memberElement = element2 as ExecutableElement; |
| 12113 if (memberElement.isStatic()) { | 12105 if (memberElement.isStatic()) { |
| 12114 return false; | 12106 return false; |
| 12115 } | 12107 } |
| 12116 if (!isTypeReference(target)) { | 12108 if (!isTypeReference(target)) { |
| 12117 return false; | 12109 return false; |
| 12118 } | 12110 } |
| 12119 _errorReporter.reportError2(StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMB
ER, name2, [name2.name]); | 12111 _errorReporter.reportError2(StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMB
ER, name2, [name2.name]); |
| 12120 return true; | 12112 return true; |
| 12121 } | 12113 } |
| 12122 | 12114 |
| 12123 /** | 12115 /** |
| 12124 * This checks that the type of the passed 'switch' expression is assignable t
o the type of the | 12116 * This checks that the type of the passed 'switch' expression is assignable t
o the type of the |
| 12125 * 'case' members. | 12117 * 'case' members. |
| 12126 * @param node the 'switch' statement to evaluate | 12118 * @param node the 'switch' statement to evaluate |
| 12127 * @return {@code true} if and only if an error code is generated on the passe
d node | 12119 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 12128 * @see StaticWarningCode#SWITCH_EXPRESSION_NOT_ASSIGNABLE | 12120 * @see StaticWarningCode#SWITCH_EXPRESSION_NOT_ASSIGNABLE |
| 12129 */ | 12121 */ |
| 12130 bool checkForSwitchExpressionNotAssignable(SwitchStatement node) { | 12122 bool checkForSwitchExpressionNotAssignable(SwitchStatement node) { |
| 12131 Expression expression2 = node.expression; | 12123 Expression expression2 = node.expression; |
| 12132 Type2 expressionType = getStaticType(expression2); | 12124 Type2 expressionType = getStaticType(expression2); |
| 12133 if (expressionType == null) { | 12125 if (expressionType == null) { |
| 12134 return false; | 12126 return false; |
| 12135 } | 12127 } |
| 12136 NodeList<SwitchMember> members2 = node.members; | 12128 NodeList<SwitchMember> members2 = node.members; |
| 12137 for (SwitchMember switchMember in members2) { | 12129 for (SwitchMember switchMember in members2) { |
| 12138 if (switchMember is! SwitchCase) { | 12130 if (switchMember is! SwitchCase) { |
| 12139 continue; | 12131 continue; |
| 12140 } | 12132 } |
| 12141 SwitchCase switchCase = switchMember as SwitchCase; | 12133 SwitchCase switchCase = switchMember as SwitchCase; |
| 12142 Expression caseExpression = switchCase.expression; | 12134 Expression caseExpression = switchCase.expression; |
| 12143 Type2 caseType = getStaticType(caseExpression); | 12135 Type2 caseType = getStaticType(caseExpression); |
| 12144 if (expressionType.isAssignableTo(caseType)) { | 12136 if (expressionType.isAssignableTo(caseType)) { |
| 12145 return false; | 12137 return false; |
| 12146 } | 12138 } |
| 12147 _errorReporter.reportError2(StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGN
ABLE, expression2, [expressionType, caseType]); | 12139 _errorReporter.reportError2(StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGN
ABLE, expression2, [expressionType, caseType]); |
| 12148 return true; | 12140 return true; |
| 12149 } | 12141 } |
| 12150 return false; | 12142 return false; |
| 12151 } | 12143 } |
| 12152 | 12144 |
| 12153 /** | 12145 /** |
| 12154 * This verifies that the type arguments in the passed instance creation expre
ssion are all within | 12146 * This verifies that the type arguments in the passed instance creation expre
ssion are all within |
| 12155 * their bounds as specified by the class element where the constructor \[that
is being invoked\] is | 12147 * their bounds as specified by the class element where the constructor \[that
is being invoked\] is |
| 12156 * declared. | 12148 * declared. |
| 12157 * @param node the instance creation expression to evaluate | 12149 * @param node the instance creation expression to evaluate |
| 12158 * @param typeName the {@link TypeName} of the {@link ConstructorName} from th
e{@link InstanceCreationExpression}, this is the AST node that the error is atta
ched to | 12150 * @param typeName the {@link TypeName} of the {@link ConstructorName} from th
e{@link InstanceCreationExpression}, this is the AST node that the error is atta
ched to |
| 12159 * @param constructorElement the {@link ConstructorElement} from the instance
creation expression | 12151 * @param constructorElement the {@link ConstructorElement} from the instance
creation expression |
| 12160 * @return {@code true} if and only if an error code is generated on the passe
d node | 12152 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 12161 * @see StaticTypeWarningCode#TYPE_ARGUMENT_NOT_MATCHING_BOUNDS | 12153 * @see StaticTypeWarningCode#TYPE_ARGUMENT_NOT_MATCHING_BOUNDS |
| 12162 */ | 12154 */ |
| 12163 bool checkForTypeArgumentNotMatchingBounds(InstanceCreationExpression node, Co
nstructorElement constructorElement, TypeName typeName) { | 12155 bool checkForTypeArgumentNotMatchingBounds(InstanceCreationExpression node, Co
nstructorElement constructorElement, TypeName typeName) { |
| 12164 if (typeName.typeArguments != null && constructorElement != null) { | 12156 if (typeName.typeArguments != null && constructorElement != null) { |
| 12165 NodeList<TypeName> typeNameArgList = typeName.typeArguments.arguments; | 12157 NodeList<TypeName> typeNameArgList = typeName.typeArguments.arguments; |
| 12166 List<TypeVariableElement> boundingElts = constructorElement.enclosingEleme
nt.typeVariables; | 12158 List<TypeVariableElement> boundingElts = constructorElement.enclosingEleme
nt.typeVariables; |
| 12167 int loopThroughIndex = Math.min(typeNameArgList.length, boundingElts.lengt
h); | 12159 int loopThroughIndex = Math.min(typeNameArgList.length, boundingElts.lengt
h); |
| 12168 for (int i = 0; i < loopThroughIndex; i++) { | 12160 for (int i = 0; i < loopThroughIndex; i++) { |
| 12169 TypeName argTypeName = typeNameArgList[i]; | 12161 TypeName argTypeName = typeNameArgList[i]; |
| 12170 Type2 argType = argTypeName.type; | 12162 Type2 argType = argTypeName.type; |
| 12171 Type2 boundType = boundingElts[i].bound; | 12163 Type2 boundType = boundingElts[i].bound; |
| 12172 if (argType != null && boundType != null) { | 12164 if (argType != null && boundType != null) { |
| 12173 if (!argType.isSubtypeOf(boundType)) { | 12165 if (!argType.isSubtypeOf(boundType)) { |
| 12174 _errorReporter.reportError2(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_
MATCHING_BOUNDS, argTypeName, [argTypeName.name, boundingElts[i].displayName]); | 12166 _errorReporter.reportError2(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_
MATCHING_BOUNDS, argTypeName, [argTypeName.name, boundingElts[i].displayName]); |
| 12175 return true; | 12167 return true; |
| 12176 } | 12168 } |
| 12177 } | 12169 } |
| 12178 } | 12170 } |
| 12179 } | 12171 } |
| 12180 return false; | 12172 return false; |
| 12181 } | 12173 } |
| 12182 | 12174 |
| 12183 /** | 12175 /** |
| 12184 * This checks that if the passed generative constructor has no explicit super
constructor | 12176 * This checks that if the passed generative constructor has no explicit super
constructor |
| 12185 * invocation, then super class has the default generative constructor. | 12177 * invocation, then super class has the default generative constructor. |
| 12186 * @param node the constructor declaration to evaluate | 12178 * @param node the constructor declaration to evaluate |
| 12187 * @return {@code true} if and only if an error code is generated on the passe
d node | 12179 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 12188 * @see CompileTimeErrorCode#UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT | 12180 * @see CompileTimeErrorCode#UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT |
| 12189 * @see CompileTimeErrorCode#NON_GENERATIVE_CONSTRUCTOR | 12181 * @see CompileTimeErrorCode#NON_GENERATIVE_CONSTRUCTOR |
| 12190 */ | 12182 */ |
| 12191 bool checkForUndefinedConstructorInInitializerImplicit(ConstructorDeclaration
node) { | 12183 bool checkForUndefinedConstructorInInitializerImplicit(ConstructorDeclaration
node) { |
| 12192 if (node.factoryKeyword != null) { | 12184 if (node.factoryKeyword != null) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 12209 if (superDefaultConstructor != null) { | 12201 if (superDefaultConstructor != null) { |
| 12210 if (superDefaultConstructor.isFactory()) { | 12202 if (superDefaultConstructor.isFactory()) { |
| 12211 _errorReporter.reportError2(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUC
TOR, node.returnType, [superDefaultConstructor]); | 12203 _errorReporter.reportError2(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUC
TOR, node.returnType, [superDefaultConstructor]); |
| 12212 return true; | 12204 return true; |
| 12213 } | 12205 } |
| 12214 return false; | 12206 return false; |
| 12215 } | 12207 } |
| 12216 _errorReporter.reportError2(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_IN
ITIALIZER_DEFAULT, node.returnType, [superElement.name]); | 12208 _errorReporter.reportError2(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_IN
ITIALIZER_DEFAULT, node.returnType, [superElement.name]); |
| 12217 return true; | 12209 return true; |
| 12218 } | 12210 } |
| 12219 | 12211 |
| 12220 /** | 12212 /** |
| 12221 * This verifies the passed operator-method declaration, has correct number of
parameters. | 12213 * This verifies the passed operator-method declaration, has correct number of
parameters. |
| 12222 * <p> | 12214 * <p> |
| 12223 * This method assumes that the method declaration was tested to be an operato
r declaration before | 12215 * This method assumes that the method declaration was tested to be an operato
r declaration before |
| 12224 * being called. | 12216 * being called. |
| 12225 * @param node the method declaration to evaluate | 12217 * @param node the method declaration to evaluate |
| 12226 * @return {@code true} if and only if an error code is generated on the passe
d node | 12218 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 12227 * @see CompileTimeErrorCode#WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR | 12219 * @see CompileTimeErrorCode#WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR |
| 12228 */ | 12220 */ |
| 12229 bool checkForWrongNumberOfParametersForOperator(MethodDeclaration node) { | 12221 bool checkForWrongNumberOfParametersForOperator(MethodDeclaration node) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 12248 if (expected != -1 && numParameters != expected) { | 12240 if (expected != -1 && numParameters != expected) { |
| 12249 _errorReporter.reportError2(CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETER
S_FOR_OPERATOR, nameNode, [name2, expected, numParameters]); | 12241 _errorReporter.reportError2(CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETER
S_FOR_OPERATOR, nameNode, [name2, expected, numParameters]); |
| 12250 return true; | 12242 return true; |
| 12251 } | 12243 } |
| 12252 if ("-" == name2 && numParameters > 1) { | 12244 if ("-" == name2 && numParameters > 1) { |
| 12253 _errorReporter.reportError2(CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETER
S_FOR_OPERATOR_MINUS, nameNode, [numParameters]); | 12245 _errorReporter.reportError2(CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETER
S_FOR_OPERATOR_MINUS, nameNode, [numParameters]); |
| 12254 return true; | 12246 return true; |
| 12255 } | 12247 } |
| 12256 return false; | 12248 return false; |
| 12257 } | 12249 } |
| 12258 | 12250 |
| 12259 /** | 12251 /** |
| 12260 * This verifies if the passed setter parameter list have only one parameter. | 12252 * This verifies if the passed setter parameter list have only one parameter. |
| 12261 * <p> | 12253 * <p> |
| 12262 * This method assumes that the method declaration was tested to be a setter b
efore being called. | 12254 * This method assumes that the method declaration was tested to be a setter b
efore being called. |
| 12263 * @param setterName the name of the setter to report problems on | 12255 * @param setterName the name of the setter to report problems on |
| 12264 * @param parameterList the parameter list to evaluate | 12256 * @param parameterList the parameter list to evaluate |
| 12265 * @return {@code true} if and only if an error code is generated on the passe
d node | 12257 * @return {@code true} if and only if an error code is generated on the passe
d node |
| 12266 * @see CompileTimeErrorCode#WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER | 12258 * @see CompileTimeErrorCode#WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER |
| 12267 */ | 12259 */ |
| 12268 bool checkForWrongNumberOfParametersForSetter(SimpleIdentifier setterName, For
malParameterList parameterList) { | 12260 bool checkForWrongNumberOfParametersForSetter(SimpleIdentifier setterName, For
malParameterList parameterList) { |
| 12269 if (setterName == null) { | 12261 if (setterName == null) { |
| 12270 return false; | 12262 return false; |
| 12271 } | 12263 } |
| 12272 if (parameterList == null) { | 12264 if (parameterList == null) { |
| 12273 return false; | 12265 return false; |
| 12274 } | 12266 } |
| 12275 int numberOfParameters = parameterList.parameters.length; | 12267 int numberOfParameters = parameterList.parameters.length; |
| 12276 if (numberOfParameters != 1) { | 12268 if (numberOfParameters != 1) { |
| 12277 _errorReporter.reportError2(CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETER
S_FOR_SETTER, setterName, [numberOfParameters]); | 12269 _errorReporter.reportError2(CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETER
S_FOR_SETTER, setterName, [numberOfParameters]); |
| 12278 return true; | 12270 return true; |
| 12279 } | 12271 } |
| 12280 return false; | 12272 return false; |
| 12281 } | 12273 } |
| 12282 | 12274 |
| 12283 /** | 12275 /** |
| 12284 * Return the propagated type of the given expression, or the static type if t
here is no | 12276 * Return the propagated type of the given expression, or the static type if t
here is no |
| 12285 * propagated type information. | 12277 * propagated type information. |
| 12286 * @param expression the expression whose type is to be returned | 12278 * @param expression the expression whose type is to be returned |
| 12287 * @return the propagated or static type of the given expression, whichever is
best | 12279 * @return the propagated or static type of the given expression, whichever is
best |
| 12288 */ | 12280 */ |
| 12289 Type2 getBestType(Expression expression) { | 12281 Type2 getBestType(Expression expression) { |
| 12290 Type2 type = getPropagatedType(expression); | 12282 Type2 type = getPropagatedType(expression); |
| 12291 if (type == null) { | 12283 if (type == null) { |
| 12292 type = getStaticType(expression); | 12284 type = getStaticType(expression); |
| 12293 } | 12285 } |
| 12294 return type; | 12286 return type; |
| 12295 } | 12287 } |
| 12296 | 12288 |
| 12297 /** | 12289 /** |
| 12298 * Returns the Type (return type) for a given getter. | 12290 * Returns the Type (return type) for a given getter. |
| 12299 * @param propertyAccessorElement | 12291 * @param propertyAccessorElement |
| 12300 * @return The type of the given getter. | 12292 * @return The type of the given getter. |
| 12301 */ | 12293 */ |
| 12302 Type2 getGetterType(PropertyAccessorElement propertyAccessorElement) { | 12294 Type2 getGetterType(PropertyAccessorElement propertyAccessorElement) { |
| 12303 FunctionType functionType = propertyAccessorElement.type; | 12295 FunctionType functionType = propertyAccessorElement.type; |
| 12304 if (functionType != null) { | 12296 if (functionType != null) { |
| 12305 return functionType.returnType; | 12297 return functionType.returnType; |
| 12306 } else { | 12298 } else { |
| 12307 return null; | 12299 return null; |
| 12308 } | 12300 } |
| 12309 } | 12301 } |
| 12310 | 12302 |
| 12311 /** | 12303 /** |
| 12312 * Return the propagated type of the given expression that is to be used for t
ype analysis. | 12304 * Return the propagated type of the given expression that is to be used for t
ype analysis. |
| 12313 * @param expression the expression whose type is to be returned | 12305 * @param expression the expression whose type is to be returned |
| 12314 * @return the propagated type of the given expression | 12306 * @return the propagated type of the given expression |
| 12315 */ | 12307 */ |
| 12316 Type2 getPropagatedType(Expression expression) => expression.propagatedType; | 12308 Type2 getPropagatedType(Expression expression) => expression.propagatedType; |
| 12317 | 12309 |
| 12318 /** | 12310 /** |
| 12319 * Returns the Type (first and only parameter) for a given setter. | 12311 * Returns the Type (first and only parameter) for a given setter. |
| 12320 * @param propertyAccessorElement | 12312 * @param propertyAccessorElement |
| 12321 * @return The type of the given setter. | 12313 * @return The type of the given setter. |
| 12322 */ | 12314 */ |
| 12323 Type2 getSetterType(PropertyAccessorElement propertyAccessorElement) { | 12315 Type2 getSetterType(PropertyAccessorElement propertyAccessorElement) { |
| 12324 List<ParameterElement> setterParameters = propertyAccessorElement.parameters
; | 12316 List<ParameterElement> setterParameters = propertyAccessorElement.parameters
; |
| 12325 if (setterParameters.length == 0) { | 12317 if (setterParameters.length == 0) { |
| 12326 return null; | 12318 return null; |
| 12327 } | 12319 } |
| 12328 return setterParameters[0].type; | 12320 return setterParameters[0].type; |
| 12329 } | 12321 } |
| 12330 | 12322 |
| 12331 /** | 12323 /** |
| 12332 * Return the static type of the given expression that is to be used for type
analysis. | 12324 * Return the static type of the given expression that is to be used for type
analysis. |
| 12333 * @param expression the expression whose type is to be returned | 12325 * @param expression the expression whose type is to be returned |
| 12334 * @return the static type of the given expression | 12326 * @return the static type of the given expression |
| 12335 */ | 12327 */ |
| 12336 Type2 getStaticType(Expression expression) { | 12328 Type2 getStaticType(Expression expression) { |
| 12337 Type2 type = expression.staticType; | 12329 Type2 type = expression.staticType; |
| 12338 if (type == null) { | 12330 if (type == null) { |
| 12339 return _dynamicType; | 12331 return _dynamicType; |
| 12340 } | 12332 } |
| 12341 return type; | 12333 return type; |
| 12342 } | 12334 } |
| 12343 | 12335 |
| 12344 /** | 12336 /** |
| 12345 * Return the variable element represented by the given expression, or {@code
null} if there is no | 12337 * Return the variable element represented by the given expression, or {@code
null} if there is no |
| 12346 * such element. | 12338 * such element. |
| 12347 * @param expression the expression whose element is to be returned | 12339 * @param expression the expression whose element is to be returned |
| 12348 * @return the variable element represented by the expression | 12340 * @return the variable element represented by the expression |
| 12349 */ | 12341 */ |
| 12350 VariableElement getVariableElement(Expression expression) { | 12342 VariableElement getVariableElement(Expression expression) { |
| 12351 if (expression is Identifier) { | 12343 if (expression is Identifier) { |
| 12352 Element element2 = ((expression as Identifier)).element; | 12344 Element element2 = ((expression as Identifier)).element; |
| 12353 if (element2 is VariableElement) { | 12345 if (element2 is VariableElement) { |
| 12354 return element2 as VariableElement; | 12346 return element2 as VariableElement; |
| 12355 } | 12347 } |
| 12356 } | 12348 } |
| 12357 return null; | 12349 return null; |
| 12358 } | 12350 } |
| 12359 | 12351 |
| 12360 /** | 12352 /** |
| 12361 * @return {@code true} if the given constructor redirects to itself, directly
or indirectly | 12353 * @return {@code true} if the given constructor redirects to itself, directly
or indirectly |
| 12362 */ | 12354 */ |
| 12363 bool hasRedirectingFactoryConstructorCycle(ConstructorElement element) { | 12355 bool hasRedirectingFactoryConstructorCycle(ConstructorElement element) { |
| 12364 Set<ConstructorElement> constructors = new Set<ConstructorElement>(); | 12356 Set<ConstructorElement> constructors = new Set<ConstructorElement>(); |
| 12365 ConstructorElement current = element; | 12357 ConstructorElement current = element; |
| 12366 while (current != null) { | 12358 while (current != null) { |
| 12367 if (constructors.contains(current)) { | 12359 if (constructors.contains(current)) { |
| 12368 return identical(current, element); | 12360 return identical(current, element); |
| 12369 } | 12361 } |
| 12370 javaSetAdd(constructors, current); | 12362 javaSetAdd(constructors, current); |
| 12371 current = current.redirectedConstructor; | 12363 current = current.redirectedConstructor; |
| 12372 if (current is ConstructorMember) { | 12364 if (current is ConstructorMember) { |
| 12373 current = ((current as ConstructorMember)).baseElement; | 12365 current = ((current as ConstructorMember)).baseElement; |
| 12374 } | 12366 } |
| 12375 } | 12367 } |
| 12376 return false; | 12368 return false; |
| 12377 } | 12369 } |
| 12378 | 12370 |
| 12379 /** | 12371 /** |
| 12380 * @param node the 'this' expression to analyze | 12372 * @param node the 'this' expression to analyze |
| 12381 * @return {@code true} if the given 'this' expression is in the valid context | 12373 * @return {@code true} if the given 'this' expression is in the valid context |
| 12382 */ | 12374 */ |
| 12383 bool isThisInValidContext(ThisExpression node) { | 12375 bool isThisInValidContext(ThisExpression node) { |
| 12384 for (ASTNode n = node; n != null; n = n.parent) { | 12376 for (ASTNode n = node; n != null; n = n.parent) { |
| 12385 if (n is CompilationUnit) { | 12377 if (n is CompilationUnit) { |
| 12386 return false; | 12378 return false; |
| 12387 } | 12379 } |
| 12388 if (n is ConstructorDeclaration) { | 12380 if (n is ConstructorDeclaration) { |
| 12389 ConstructorDeclaration constructor = n as ConstructorDeclaration; | 12381 ConstructorDeclaration constructor = n as ConstructorDeclaration; |
| 12390 return constructor.factoryKeyword == null; | 12382 return constructor.factoryKeyword == null; |
| 12391 } | 12383 } |
| 12392 if (n is ConstructorFieldInitializer) { | 12384 if (n is ConstructorFieldInitializer) { |
| 12393 return false; | 12385 return false; |
| 12394 } | 12386 } |
| 12395 if (n is MethodDeclaration) { | 12387 if (n is MethodDeclaration) { |
| 12396 MethodDeclaration method = n as MethodDeclaration; | 12388 MethodDeclaration method = n as MethodDeclaration; |
| 12397 return !method.isStatic(); | 12389 return !method.isStatic(); |
| 12398 } | 12390 } |
| 12399 } | 12391 } |
| 12400 return false; | 12392 return false; |
| 12401 } | 12393 } |
| 12402 } | 12394 } |
| 12403 | |
| 12404 /** | 12395 /** |
| 12405 * This enum holds one of four states of a field initialization state through a
constructor | 12396 * This enum holds one of four states of a field initialization state through a
constructor |
| 12406 * signature, not initialized, initialized in the field declaration, initialized
in the field | 12397 * signature, not initialized, initialized in the field declaration, initialized
in the field |
| 12407 * formal, and finally, initialized in the initializers list. | 12398 * formal, and finally, initialized in the initializers list. |
| 12408 */ | 12399 */ |
| 12409 class INIT_STATE implements Comparable<INIT_STATE> { | 12400 class INIT_STATE implements Comparable<INIT_STATE> { |
| 12410 static final INIT_STATE NOT_INIT = new INIT_STATE('NOT_INIT', 0); | 12401 static final INIT_STATE NOT_INIT = new INIT_STATE('NOT_INIT', 0); |
| 12411 static final INIT_STATE INIT_IN_DECLARATION = new INIT_STATE('INIT_IN_DECLARAT
ION', 1); | 12402 static final INIT_STATE INIT_IN_DECLARATION = new INIT_STATE('INIT_IN_DECLARAT
ION', 1); |
| 12412 static final INIT_STATE INIT_IN_FIELD_FORMAL = new INIT_STATE('INIT_IN_FIELD_F
ORMAL', 2); | 12403 static final INIT_STATE INIT_IN_FIELD_FORMAL = new INIT_STATE('INIT_IN_FIELD_F
ORMAL', 2); |
| 12413 static final INIT_STATE INIT_IN_DEFAULT_VALUE = new INIT_STATE('INIT_IN_DEFAUL
T_VALUE', 3); | 12404 static final INIT_STATE INIT_IN_DEFAULT_VALUE = new INIT_STATE('INIT_IN_DEFAUL
T_VALUE', 3); |
| 12414 static final INIT_STATE INIT_IN_INITIALIZERS = new INIT_STATE('INIT_IN_INITIAL
IZERS', 4); | 12405 static final INIT_STATE INIT_IN_INITIALIZERS = new INIT_STATE('INIT_IN_INITIAL
IZERS', 4); |
| 12415 static final List<INIT_STATE> values = [NOT_INIT, INIT_IN_DECLARATION, INIT_IN
_FIELD_FORMAL, INIT_IN_DEFAULT_VALUE, INIT_IN_INITIALIZERS]; | 12406 static final List<INIT_STATE> values = [NOT_INIT, INIT_IN_DECLARATION, INIT_IN
_FIELD_FORMAL, INIT_IN_DEFAULT_VALUE, INIT_IN_INITIALIZERS]; |
| 12416 | 12407 |
| 12417 /// The name of this enum constant, as declared in the enum declaration. | 12408 /// The name of this enum constant, as declared in the enum declaration. |
| 12418 final String name; | 12409 final String name; |
| 12419 | 12410 |
| 12420 /// The position in the enum declaration. | 12411 /// The position in the enum declaration. |
| 12421 final int ordinal; | 12412 final int ordinal; |
| 12422 INIT_STATE(this.name, this.ordinal) { | 12413 INIT_STATE(this.name, this.ordinal) { |
| 12423 } | 12414 } |
| 12424 int compareTo(INIT_STATE other) => ordinal - other.ordinal; | 12415 int compareTo(INIT_STATE other) => ordinal - other.ordinal; |
| 12425 String toString() => name; | 12416 String toString() => name; |
| 12426 } | 12417 } |
| 12418 /** |
| 12419 * Instances of the class {@code PubVerifier} traverse an AST structure looking
for deviations from |
| 12420 * pub best practices. |
| 12421 */ |
| 12422 class PubVerifier extends RecursiveASTVisitor<Object> { |
| 12427 | 12423 |
| 12424 /** |
| 12425 * The error reporter by which errors will be reported. |
| 12426 */ |
| 12427 ErrorReporter _errorReporter; |
| 12428 PubVerifier(ErrorReporter errorReporter) { |
| 12429 this._errorReporter = errorReporter; |
| 12430 } |
| 12431 Object visitImportDirective(ImportDirective directive) { |
| 12432 // StringLiteral uriLiteral = directive.uri; |
| 12433 // if (uriLiteral == null) { |
| 12434 // return null; |
| 12435 // } |
| 12436 // String uriContent = uriLiteral.stringValue; |
| 12437 // if (uriContent == null) { |
| 12438 // return null; |
| 12439 // } |
| 12440 // uriContent = uriContent.trim(); |
| 12441 // int index = uriContent.indexOf(':'); |
| 12442 // String scheme; |
| 12443 // String path; |
| 12444 // if (index > -1) { |
| 12445 // scheme = uriContent.substring(0, index); |
| 12446 // path = uriContent.substring(index + 1); |
| 12447 // } else { |
| 12448 // scheme = FileUriResolver.FILE_SCHEME; |
| 12449 // path = uriContent; |
| 12450 // } |
| 12451 // if (scheme == FileUriResolver.FILE_SCHEME) { |
| 12452 // if (checkForFileImportOutsideLibReferencesFileInside(directive, path)) { |
| 12453 // _errorReporter.reportError2(PubSuggestionCode.FILE_IMPORT_OUTSIDE_LIB_
REFERENCES_FILE_INSIDE, uriLiteral, []); |
| 12454 // } else if (checkForFileImportInsideLibReferencesFileOutside(directive, p
ath)) { |
| 12455 // _errorReporter.reportError2(PubSuggestionCode.FILE_IMPORT_INSIDE_LIB_R
EFERENCES_FILE_OUTSIDE, uriLiteral, []); |
| 12456 // } |
| 12457 // } else if (scheme == PackageUriResolver.PACKAGE_SCHEME) { |
| 12458 // if (checkForPackageImportContainsDotDot(path)) { |
| 12459 // _errorReporter.reportError2(PubSuggestionCode.PACKAGE_IMPORT_CONTAINS_
DOT_DOT, uriLiteral, []); |
| 12460 // } |
| 12461 // } |
| 12462 return null; |
| 12463 } |
| 12464 |
| 12465 /** |
| 12466 * Determine if the file file path lies inside the "lib" directory hierarchy b
ut references a file |
| 12467 * outside that directory hierarchy. |
| 12468 * @param directive the import directive (not {@code null}) |
| 12469 * @param path the file path being verified (not {@code null}) |
| 12470 * @return {@code true} if the file is inside but references a file outside |
| 12471 */ |
| 12472 bool checkForFileImportInsideLibReferencesFileOutside(ImportDirective directiv
e, String path) { |
| 12473 String fullName = getSourceFullName(directive); |
| 12474 if (fullName != null) { |
| 12475 int pathIndex = 0; |
| 12476 int fullNameIndex = fullName.length; |
| 12477 while (pathIndex < path.length && JavaString.startsWithBefore(path, "../",
pathIndex)) { |
| 12478 fullNameIndex = fullName.lastIndexOf('/', fullNameIndex); |
| 12479 if (fullNameIndex < 4) { |
| 12480 return false; |
| 12481 } |
| 12482 if (JavaString.startsWithBefore(fullName, "/lib", fullNameIndex - 4)) { |
| 12483 return true; |
| 12484 } |
| 12485 pathIndex += 3; |
| 12486 } |
| 12487 } |
| 12488 return false; |
| 12489 } |
| 12490 |
| 12491 /** |
| 12492 * Determine if the given file path lies outside the "lib" directory hierarchy
but references a |
| 12493 * file inside that directory hierarchy. |
| 12494 * @param directive the import directive (not {@code null}) |
| 12495 * @param path the file path being verified (not {@code null}) |
| 12496 * @return {@code true} if the file is outside but references a file inside |
| 12497 */ |
| 12498 bool checkForFileImportOutsideLibReferencesFileInside(ImportDirective directiv
e, String path) { |
| 12499 if (path.startsWith("lib/") || path.contains("/lib/")) { |
| 12500 String fullName = getSourceFullName(directive); |
| 12501 if (fullName != null) { |
| 12502 if (!fullName.contains("/lib/")) { |
| 12503 return true; |
| 12504 } |
| 12505 } |
| 12506 } |
| 12507 return false; |
| 12508 } |
| 12509 |
| 12510 /** |
| 12511 * Determine if the given package import path contains ".." |
| 12512 * @param path the path to be validated (not {@code null}) |
| 12513 * @return {@code true} if the import path contains ".." |
| 12514 */ |
| 12515 bool checkForPackageImportContainsDotDot(String path) => path.contains("/../")
; |
| 12516 |
| 12517 /** |
| 12518 * Answer the full name of the source associated with the compilation unit con
taining the given |
| 12519 * AST node. The returned value will have all {@link File#separatorChar} repla
ce by '/'. |
| 12520 * @param node the node (not {@code null}) |
| 12521 * @return the full name or {@code null} if it could not be determined |
| 12522 */ |
| 12523 String getSourceFullName(ASTNode node) { |
| 12524 // CompilationUnit unit = node.getAncestor(CompilationUnit); |
| 12525 // if (unit != null) { |
| 12526 // CompilationUnitElement element2 = unit.element; |
| 12527 // if (element2 != null) { |
| 12528 // Source librarySource = element2.source; |
| 12529 // if (librarySource != null) { |
| 12530 // String fullName2 = librarySource.fullName; |
| 12531 // if (fullName2 != null) { |
| 12532 // return fullName2.replaceAll(JavaFile.separatorChar, '/'); |
| 12533 // } |
| 12534 // } |
| 12535 // } |
| 12536 // } |
| 12537 return null; |
| 12538 } |
| 12539 } |
| 12428 /** | 12540 /** |
| 12429 * The enumeration {@code ResolverErrorCode} defines the error codes used for er
rors detected by the | 12541 * The enumeration {@code ResolverErrorCode} defines the error codes used for er
rors detected by the |
| 12430 * resolver. The convention for this class is for the name of the error code to
indicate the problem | 12542 * resolver. The convention for this class is for the name of the error code to
indicate the problem |
| 12431 * that caused the error to be generated and for the error message to explain wh
at is wrong and, | 12543 * that caused the error to be generated and for the error message to explain wh
at is wrong and, |
| 12432 * when appropriate, how the problem can be corrected. | 12544 * when appropriate, how the problem can be corrected. |
| 12433 * @coverage dart.engine.resolver | 12545 * @coverage dart.engine.resolver |
| 12434 */ | 12546 */ |
| 12435 class ResolverErrorCode implements Comparable<ResolverErrorCode>, ErrorCode { | 12547 class ResolverErrorCode implements Comparable<ResolverErrorCode>, ErrorCode { |
| 12436 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"); | 12548 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"); |
| 12437 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"); | 12549 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"); |
| 12438 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"); | 12550 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"); |
| 12439 static final List<ResolverErrorCode> values = [BREAK_LABEL_ON_SWITCH_MEMBER, C
ONTINUE_LABEL_ON_SWITCH, MISSING_LIBRARY_DIRECTIVE_WITH_PART]; | 12551 static final List<ResolverErrorCode> values = [BREAK_LABEL_ON_SWITCH_MEMBER, C
ONTINUE_LABEL_ON_SWITCH, MISSING_LIBRARY_DIRECTIVE_WITH_PART]; |
| 12440 | 12552 |
| 12441 /// The name of this enum constant, as declared in the enum declaration. | 12553 /// The name of this enum constant, as declared in the enum declaration. |
| 12442 final String name; | 12554 final String name; |
| 12443 | 12555 |
| 12444 /// The position in the enum declaration. | 12556 /// The position in the enum declaration. |
| 12445 final int ordinal; | 12557 final int ordinal; |
| 12446 | 12558 |
| 12447 /** | 12559 /** |
| 12448 * The type of this error. | 12560 * The type of this error. |
| 12449 */ | 12561 */ |
| 12450 ErrorType _type; | 12562 ErrorType _type; |
| 12451 | 12563 |
| 12452 /** | 12564 /** |
| 12453 * The message template used to create the message to be displayed for this er
ror. | 12565 * The message template used to create the message to be displayed for this er
ror. |
| 12454 */ | 12566 */ |
| 12455 String _message; | 12567 String _message; |
| 12456 | 12568 |
| 12457 /** | 12569 /** |
| 12458 * Initialize a newly created error code to have the given type and message. | 12570 * Initialize a newly created error code to have the given type and message. |
| 12459 * @param type the type of this error | 12571 * @param type the type of this error |
| 12460 * @param message the message template used to create the message to be displa
yed for the error | 12572 * @param message the message template used to create the message to be displa
yed for the error |
| 12461 */ | 12573 */ |
| 12462 ResolverErrorCode(this.name, this.ordinal, ErrorType type, String message) { | 12574 ResolverErrorCode(this.name, this.ordinal, ErrorType type, String message) { |
| 12463 this._type = type; | 12575 this._type = type; |
| 12464 this._message = message; | 12576 this._message = message; |
| 12465 } | 12577 } |
| 12466 ErrorSeverity get errorSeverity => _type.severity; | 12578 ErrorSeverity get errorSeverity => _type.severity; |
| 12467 String get message => _message; | 12579 String get message => _message; |
| 12468 ErrorType get type => _type; | 12580 ErrorType get type => _type; |
| 12469 int compareTo(ResolverErrorCode other) => ordinal - other.ordinal; | 12581 int compareTo(ResolverErrorCode other) => ordinal - other.ordinal; |
| 12470 String toString() => name; | 12582 String toString() => name; |
| 12471 } | 12583 } |
| OLD | NEW |