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

Side by Side Diff: pkg/analyzer/lib/src/dart/element/element.dart

Issue 1863803002: Validation of `@required` params (#26182). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.src.dart.element.element; 5 library analyzer.src.dart.element.element;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:math' show min; 8 import 'dart:math' show min;
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 1631 matching lines...) Expand 10 before | Expand all | Expand 10 after
1642 */ 1642 */
1643 static String _PROTECTED_VARIABLE_NAME = "protected"; 1643 static String _PROTECTED_VARIABLE_NAME = "protected";
1644 1644
1645 /** 1645 /**
1646 * The name of the top-level variable used to mark a class as implementing a 1646 * The name of the top-level variable used to mark a class as implementing a
1647 * proxy object. 1647 * proxy object.
1648 */ 1648 */
1649 static String PROXY_VARIABLE_NAME = "proxy"; 1649 static String PROXY_VARIABLE_NAME = "proxy";
1650 1650
1651 /** 1651 /**
1652 * The name of the class used to mark a parameter as being required.
1653 */
1654 static String _REQUIRED_CLASS_NAME = "Required";
1655
1656 /**
1657 * The name of the top-level variable used to mark a parameter as being
1658 * required.
1659 */
1660 static String _REQUIRED_VARIABLE_NAME = "required";
1661
1662 /**
1652 * The element representing the field, variable, or constructor being used as 1663 * The element representing the field, variable, or constructor being used as
1653 * an annotation. 1664 * an annotation.
1654 */ 1665 */
1655 Element element; 1666 Element element;
1656 1667
1657 /** 1668 /**
1658 * The compilation unit in which this annotation appears. 1669 * The compilation unit in which this annotation appears.
1659 */ 1670 */
1660 final CompilationUnitElementImpl compilationUnit; 1671 final CompilationUnitElementImpl compilationUnit;
1661 1672
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1713 element is PropertyAccessorElement && 1724 element is PropertyAccessorElement &&
1714 element.name == _PROTECTED_VARIABLE_NAME && 1725 element.name == _PROTECTED_VARIABLE_NAME &&
1715 element.library?.name == _META_LIB_NAME; 1726 element.library?.name == _META_LIB_NAME;
1716 1727
1717 @override 1728 @override
1718 bool get isProxy => 1729 bool get isProxy =>
1719 element is PropertyAccessorElement && 1730 element is PropertyAccessorElement &&
1720 element.name == PROXY_VARIABLE_NAME && 1731 element.name == PROXY_VARIABLE_NAME &&
1721 element.library?.isDartCore == true; 1732 element.library?.isDartCore == true;
1722 1733
1734 @override
1735 bool get isRequired =>
1736 element is ConstructorElement &&
1737 element.enclosingElement.name == _REQUIRED_CLASS_NAME &&
1738 element.library?.name == _META_LIB_NAME ||
1739 element is PropertyAccessorElement &&
1740 element.name == _REQUIRED_VARIABLE_NAME &&
1741 element.library?.name == _META_LIB_NAME;
1742
1723 /** 1743 /**
1724 * Get the library containing this annotation. 1744 * Get the library containing this annotation.
1725 */ 1745 */
1726 Source get librarySource => compilationUnit.librarySource; 1746 Source get librarySource => compilationUnit.librarySource;
1727 1747
1728 @override 1748 @override
1729 Source get source => compilationUnit.source; 1749 Source get source => compilationUnit.source;
1730 1750
1731 @override 1751 @override
1732 String toString() => '@$element'; 1752 String toString() => '@$element';
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1928 return true; 1948 return true;
1929 } 1949 }
1930 } 1950 }
1931 return false; 1951 return false;
1932 } 1952 }
1933 1953
1934 @override 1954 @override
1935 bool get isPublic => !isPrivate; 1955 bool get isPublic => !isPrivate;
1936 1956
1937 @override 1957 @override
1958 bool get isRequired {
1959 for (ElementAnnotation annotation in metadata) {
1960 if (annotation.isRequired) {
1961 return true;
1962 }
1963 }
1964 return false;
1965 }
1966
1967 @override
1938 bool get isSynthetic => hasModifier(Modifier.SYNTHETIC); 1968 bool get isSynthetic => hasModifier(Modifier.SYNTHETIC);
1939 1969
1940 @override 1970 @override
1941 LibraryElement get library => 1971 LibraryElement get library =>
1942 getAncestor((element) => element is LibraryElement); 1972 getAncestor((element) => element is LibraryElement);
1943 1973
1944 @override 1974 @override
1945 ElementLocation get location { 1975 ElementLocation get location {
1946 if (_cachedLocation == null) { 1976 if (_cachedLocation == null) {
1947 if (library == null) { 1977 if (library == null) {
(...skipping 2138 matching lines...) Expand 10 before | Expand all | Expand 10 after
4086 return Identifier.isPrivateName(name); 4116 return Identifier.isPrivateName(name);
4087 } 4117 }
4088 4118
4089 @override 4119 @override
4090 bool get isProtected => false; 4120 bool get isProtected => false;
4091 4121
4092 @override 4122 @override
4093 bool get isPublic => !isPrivate; 4123 bool get isPublic => !isPrivate;
4094 4124
4095 @override 4125 @override
4126 bool get isRequired => false;
4127
4128 @override
4096 bool get isSynthetic => true; 4129 bool get isSynthetic => true;
4097 4130
4098 @override 4131 @override
4099 ElementKind get kind => ElementKind.ERROR; 4132 ElementKind get kind => ElementKind.ERROR;
4100 4133
4101 @override 4134 @override
4102 LibraryElement get library => null; 4135 LibraryElement get library => null;
4103 4136
4104 @override 4137 @override
4105 ElementLocation get location => null; 4138 ElementLocation get location => null;
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after
4965 4998
4966 @override 4999 @override
4967 void visitElement(Element element) { 5000 void visitElement(Element element) {
4968 int offset = element.nameOffset; 5001 int offset = element.nameOffset;
4969 if (offset != -1) { 5002 if (offset != -1) {
4970 map[offset] = element; 5003 map[offset] = element;
4971 } 5004 }
4972 super.visitElement(element); 5005 super.visitElement(element);
4973 } 5006 }
4974 } 5007 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698