OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library analyzer.src.generated.resolver; | 5 library analyzer.src.generated.resolver; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 } | 773 } |
774 } | 774 } |
775 if (element.supertype != null) { | 775 if (element.supertype != null) { |
776 return isOrInheritsImmutable(element.supertype.element, visited); | 776 return isOrInheritsImmutable(element.supertype.element, visited); |
777 } | 777 } |
778 } | 778 } |
779 return false; | 779 return false; |
780 } | 780 } |
781 | 781 |
782 /** | 782 /** |
783 * Return `true` if the given class [element] defines a non-final field. | 783 * Return `true` if the given class [element] defines a non-final instance |
| 784 * field. |
784 */ | 785 */ |
785 bool hasNonFinalField(ClassElement element) { | 786 bool hasNonFinalInstanceField(ClassElement element) { |
786 for (FieldElement field in element.fields) { | 787 for (FieldElement field in element.fields) { |
787 if (!field.isSynthetic && !field.isFinal) { | 788 if (!field.isSynthetic && !field.isFinal && !field.isStatic) { |
788 return true; | 789 return true; |
789 } | 790 } |
790 } | 791 } |
791 return false; | 792 return false; |
792 } | 793 } |
793 | 794 |
794 /** | 795 /** |
795 * Return `true` if the given class [element] defines or inherits a | 796 * Return `true` if the given class [element] defines or inherits a |
796 * non-final field. | 797 * non-final field. |
797 */ | 798 */ |
798 bool hasOrInheritsNonFinalField( | 799 bool hasOrInheritsNonFinalInstanceField( |
799 ClassElement element, HashSet<ClassElement> visited) { | 800 ClassElement element, HashSet<ClassElement> visited) { |
800 if (visited.add(element)) { | 801 if (visited.add(element)) { |
801 if (hasNonFinalField(element)) { | 802 if (hasNonFinalInstanceField(element)) { |
802 return true; | 803 return true; |
803 } | 804 } |
804 for (InterfaceType mixin in element.mixins) { | 805 for (InterfaceType mixin in element.mixins) { |
805 if (hasNonFinalField(mixin.element)) { | 806 if (hasNonFinalInstanceField(mixin.element)) { |
806 return true; | 807 return true; |
807 } | 808 } |
808 } | 809 } |
809 if (element.supertype != null) { | 810 if (element.supertype != null) { |
810 return hasOrInheritsNonFinalField(element.supertype.element, visited); | 811 return hasOrInheritsNonFinalInstanceField(element.supertype.element, v
isited); |
811 } | 812 } |
812 } | 813 } |
813 return false; | 814 return false; |
814 } | 815 } |
815 | 816 |
816 ClassElement element = node.element; | 817 ClassElement element = node.element; |
817 if (isOrInheritsImmutable(element, new HashSet<ClassElement>()) && | 818 if (isOrInheritsImmutable(element, new HashSet<ClassElement>()) && |
818 hasOrInheritsNonFinalField(element, new HashSet<ClassElement>())) { | 819 hasOrInheritsNonFinalInstanceField(element, new HashSet<ClassElement>())
) { |
819 _errorReporter.reportErrorForNode(HintCode.MUST_BE_IMMUTABLE, node.name); | 820 _errorReporter.reportErrorForNode(HintCode.MUST_BE_IMMUTABLE, node.name); |
820 } | 821 } |
821 } | 822 } |
822 | 823 |
823 /** | 824 /** |
824 * This verifies that the passed left hand side and right hand side represent
a valid assignment. | 825 * This verifies that the passed left hand side and right hand side represent
a valid assignment. |
825 * | 826 * |
826 * This method corresponds to ErrorVerifier.checkForInvalidAssignment. | 827 * This method corresponds to ErrorVerifier.checkForInvalidAssignment. |
827 * | 828 * |
828 * @param lhs the left hand side expression | 829 * @param lhs the left hand side expression |
(...skipping 10095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10924 return null; | 10925 return null; |
10925 } | 10926 } |
10926 if (identical(node.staticElement, variable)) { | 10927 if (identical(node.staticElement, variable)) { |
10927 if (node.inSetterContext()) { | 10928 if (node.inSetterContext()) { |
10928 result = true; | 10929 result = true; |
10929 } | 10930 } |
10930 } | 10931 } |
10931 return null; | 10932 return null; |
10932 } | 10933 } |
10933 } | 10934 } |
OLD | NEW |