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

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

Issue 131233009: New analyzer snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // 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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.resolver; 8 library engine.resolver;
9 9
10 import 'dart:collection'; 10 import 'dart:collection';
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 static String _NG_ATTR = "NgAttr"; 52 static String _NG_ATTR = "NgAttr";
53 53
54 static String _NG_CALLBACK = "NgCallback"; 54 static String _NG_CALLBACK = "NgCallback";
55 55
56 static String _NG_ONE_WAY = "NgOneWay"; 56 static String _NG_ONE_WAY = "NgOneWay";
57 57
58 static String _NG_ONE_WAY_ONE_TIME = "NgOneWayOneTime"; 58 static String _NG_ONE_WAY_ONE_TIME = "NgOneWayOneTime";
59 59
60 static String _NG_TWO_WAY = "NgTwoWay"; 60 static String _NG_TWO_WAY = "NgTwoWay";
61 61
62 /**
63 * Returns the array of all top-level Angular elements that could be used in t his library.
64 *
65 * @param libraryElement the [LibraryElement] to analyze
66 * @return the array of all top-level Angular elements that could be used in t his library
67 */
68 static List<AngularElement> getAngularElements(LibraryElement libraryElement) {
69 List<AngularElement> angularElements = [];
70 // add Angular elements from current library
71 for (CompilationUnitElement unit in libraryElement.units) {
72 for (ClassElement type in unit.types) {
73 addAngularElements(angularElements, type);
74 }
75 }
76 // handle imports
77 for (ImportElement importElement in libraryElement.imports) {
78 Namespace namespace = new NamespaceBuilder().createImportNamespace(importE lement);
79 for (Element importedElement in namespace.definedNames.values) {
80 addAngularElements(angularElements, importedElement);
81 }
82 }
83 // done
84 return new List.from(angularElements);
85 }
86
87 static Element getElement(ASTNode node, int offset) { 62 static Element getElement(ASTNode node, int offset) {
88 // maybe node is not SimpleStringLiteral 63 // maybe node is not SimpleStringLiteral
89 if (node is! SimpleStringLiteral) { 64 if (node is! SimpleStringLiteral) {
90 return null; 65 return null;
91 } 66 }
92 // prepare enclosing ClassDeclaration 67 // prepare enclosing ClassDeclaration
93 ClassDeclaration classDeclaration = node.getAncestor(ClassDeclaration); 68 ClassDeclaration classDeclaration = node.getAncestor(ClassDeclaration);
94 if (classDeclaration == null) { 69 if (classDeclaration == null) {
95 return null; 70 return null;
96 } 71 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 } 146 }
172 } 147 }
173 // tag 148 // tag
174 if (StringUtilities.isTagName(text)) { 149 if (StringUtilities.isTagName(text)) {
175 return new IsTagSelectorElementImpl(text, offset); 150 return new IsTagSelectorElementImpl(text, offset);
176 } 151 }
177 return null; 152 return null;
178 } 153 }
179 154
180 /** 155 /**
181 * Adds [AngularElement] declared by the given top-level [Element].
182 *
183 * @param angularElements the list to fill with top-level [AngularElement]s
184 * @param unitMember the top-level member of unit, such as [ClassElement], to get
185 * [AngularElement]s from
186 */
187 static void addAngularElements(List<AngularElement> angularElements, Element u nitMember) {
188 if (unitMember is ClassElement) {
189 ClassElement type = unitMember;
190 for (ToolkitObjectElement toolkitObject in type.toolkitObjects) {
191 if (toolkitObject is AngularElement) {
192 angularElements.add(toolkitObject);
193 }
194 }
195 }
196 }
197
198 /**
199 * Returns the [FieldElement] of the first field in the given [FieldDeclaratio n]. 156 * Returns the [FieldElement] of the first field in the given [FieldDeclaratio n].
200 */ 157 */
201 static FieldElement getOnlyFieldElement(FieldDeclaration fieldDeclaration) { 158 static FieldElement getOnlyFieldElement(FieldDeclaration fieldDeclaration) {
202 NodeList<VariableDeclaration> fields = fieldDeclaration.fields.variables; 159 NodeList<VariableDeclaration> fields = fieldDeclaration.fields.variables;
203 return fields[0].element as FieldElement; 160 return fields[0].element as FieldElement;
204 } 161 }
205 162
206 /** 163 /**
207 * If given [Annotation] has one argument and it is [SimpleStringLiteral], ret urns it, 164 * If given [Annotation] has one argument and it is [SimpleStringLiteral], ret urns it,
208 * otherwise returns `null`. 165 * otherwise returns `null`.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 /** 198 /**
242 * Parses given [SimpleStringLiteral] using [parseSelector]. 199 * Parses given [SimpleStringLiteral] using [parseSelector].
243 */ 200 */
244 static AngularSelectorElement parseSelector2(SimpleStringLiteral literal) { 201 static AngularSelectorElement parseSelector2(SimpleStringLiteral literal) {
245 int offset = literal.valueOffset; 202 int offset = literal.valueOffset;
246 String text = literal.stringValue; 203 String text = literal.stringValue;
247 return parseSelector(offset, text); 204 return parseSelector(offset, text);
248 } 205 }
249 206
250 /** 207 /**
251 * The [AnalysisContext] that performs analysis.
252 */
253 AnalysisContext _context;
254
255 /**
256 * The listener to which errors will be reported. 208 * The listener to which errors will be reported.
257 */ 209 */
258 AnalysisErrorListener _errorListener; 210 AnalysisErrorListener _errorListener;
259 211
260 /** 212 /**
261 * The source containing the unit that will be analyzed. 213 * The source containing the unit that will be analyzed.
262 */ 214 */
263 Source _source; 215 Source _source;
264 216
265 /** 217 /**
(...skipping 15 matching lines...) Expand all
281 * The [Annotation] that is currently being analyzed. 233 * The [Annotation] that is currently being analyzed.
282 */ 234 */
283 Annotation _annotation; 235 Annotation _annotation;
284 236
285 /** 237 /**
286 * Initialize a newly created compilation unit element builder. 238 * Initialize a newly created compilation unit element builder.
287 * 239 *
288 * @param errorListener the listener to which errors will be reported. 240 * @param errorListener the listener to which errors will be reported.
289 * @param source the source containing the unit that will be analyzed 241 * @param source the source containing the unit that will be analyzed
290 */ 242 */
291 AngularCompilationUnitBuilder(AnalysisContext context, AnalysisErrorListener e rrorListener, Source source) { 243 AngularCompilationUnitBuilder(AnalysisErrorListener errorListener, Source sour ce) {
292 this._context = context;
293 this._errorListener = errorListener; 244 this._errorListener = errorListener;
294 this._source = source; 245 this._source = source;
295 } 246 }
296 247
297 /** 248 /**
298 * Builds Angular specific element models and adds them to the existing Dart e lements. 249 * Builds Angular specific element models and adds them to the existing Dart e lements.
299 * 250 *
300 * @param unit the compilation unit with built Dart element models 251 * @param unit the compilation unit with built Dart element models
301 */ 252 */
302 void build(CompilationUnit unit) { 253 void build(CompilationUnit unit) {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 } 390 }
440 // cssUrl 391 // cssUrl
441 String styleUri = null; 392 String styleUri = null;
442 int styleUriOffset = -1; 393 int styleUriOffset = -1;
443 if (hasStringArgument(_CSS_URL)) { 394 if (hasStringArgument(_CSS_URL)) {
444 styleUri = getStringArgument(_CSS_URL); 395 styleUri = getStringArgument(_CSS_URL);
445 styleUriOffset = getStringArgumentOffset(_CSS_URL); 396 styleUriOffset = getStringArgumentOffset(_CSS_URL);
446 } 397 }
447 // create 398 // create
448 if (isValid) { 399 if (isValid) {
449 AngularComponentElementImpl element = new AngularComponentElementImpl(name , nameOffset); 400 AngularComponentElementImpl element = new AngularComponentElementImpl(name , nameOffset, _annotation.offset);
450 element.selector = selector; 401 element.selector = selector;
451 element.templateUri = templateUri; 402 element.templateUri = templateUri;
452 element.templateUriOffset = templateUriOffset; 403 element.templateUriOffset = templateUriOffset;
453 // resolve template URI
454 // TODO(scheglov) resolve to HtmlElement to allow F3 ?
455 if (templateUri != null) {
456 try {
457 parseUriWithException(templateUri);
458 // TODO(scheglov) think if there is better solution
459 if (templateUri.startsWith("packages/")) {
460 templateUri = "package:${templateUri.substring("packages/".length)}" ;
461 }
462 Source templateSource = _context.sourceFactory.resolveUri(_source, tem plateUri);
463 if (templateSource == null || !templateSource.exists()) {
464 templateSource = _context.sourceFactory.resolveUri(_source, "package :${templateUri}");
465 }
466 if (templateSource == null || !templateSource.exists()) {
467 reportErrorForArgument(_TEMPLATE_URL, AngularCode.URI_DOES_NOT_EXIST , [templateUri]);
468 }
469 if (AnalysisEngine.isHtmlFileName(templateUri)) {
470 element.templateSource = templateSource;
471 }
472 } on URISyntaxException catch (exception) {
473 reportErrorForArgument(_TEMPLATE_URL, AngularCode.INVALID_URI, [templa teUri]);
474 }
475 }
476 element.styleUri = styleUri; 404 element.styleUri = styleUri;
477 element.styleUriOffset = styleUriOffset; 405 element.styleUriOffset = styleUriOffset;
478 element.properties = parseNgComponentProperties(true); 406 element.properties = parseNgComponentProperties(true);
479 _classToolkitObjects.add(element); 407 _classToolkitObjects.add(element);
480 } 408 }
481 } 409 }
482 410
483 /** 411 /**
484 * Parses [AngularPropertyElement]s from [annotation] and [classDeclaration]. 412 * Parses [AngularPropertyElement]s from [annotation] and [classDeclaration].
485 */ 413 */
(...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after
1884 * The error listener to which errors will be reported. 1812 * The error listener to which errors will be reported.
1885 */ 1813 */
1886 RecordingErrorListener _errorListener; 1814 RecordingErrorListener _errorListener;
1887 1815
1888 /** 1816 /**
1889 * The modification time of the source for which an element is being built. 1817 * The modification time of the source for which an element is being built.
1890 */ 1818 */
1891 int _modificationStamp = 0; 1819 int _modificationStamp = 0;
1892 1820
1893 /** 1821 /**
1894 * The line information associated with the source for which an element is bei ng built, or
1895 * `null` if we are not building an element.
1896 */
1897 LineInfo _lineInfo;
1898
1899 /**
1900 * The HTML element being built. 1822 * The HTML element being built.
1901 */ 1823 */
1902 HtmlElementImpl _htmlElement; 1824 HtmlElementImpl _htmlElement;
1903 1825
1904 /** 1826 /**
1905 * The elements in the path from the HTML unit to the current tag node. 1827 * The elements in the path from the HTML unit to the current tag node.
1906 */ 1828 */
1907 List<ht.XmlTagNode> _parentNodes; 1829 List<ht.XmlTagNode> _parentNodes;
1908 1830
1909 /** 1831 /**
(...skipping 29 matching lines...) Expand all
1939 * Build the HTML element for the given source. 1861 * Build the HTML element for the given source.
1940 * 1862 *
1941 * @param source the source describing the compilation unit 1863 * @param source the source describing the compilation unit
1942 * @param modificationStamp the modification time of the source for which an e lement is being 1864 * @param modificationStamp the modification time of the source for which an e lement is being
1943 * built 1865 * built
1944 * @param unit the AST structure representing the HTML 1866 * @param unit the AST structure representing the HTML
1945 * @throws AnalysisException if the analysis could not be performed 1867 * @throws AnalysisException if the analysis could not be performed
1946 */ 1868 */
1947 HtmlElementImpl buildHtmlElement2(Source source, int modificationStamp, ht.Htm lUnit unit) { 1869 HtmlElementImpl buildHtmlElement2(Source source, int modificationStamp, ht.Htm lUnit unit) {
1948 this._modificationStamp = modificationStamp; 1870 this._modificationStamp = modificationStamp;
1949 _lineInfo = _context.computeLineInfo(source);
1950 HtmlElementImpl result = new HtmlElementImpl(_context, source.shortName); 1871 HtmlElementImpl result = new HtmlElementImpl(_context, source.shortName);
1951 result.source = source; 1872 result.source = source;
1952 _htmlElement = result; 1873 _htmlElement = result;
1953 unit.accept(this); 1874 unit.accept(this);
1954 _htmlElement = null; 1875 _htmlElement = null;
1955 unit.element = result; 1876 unit.element = result;
1956 return result; 1877 return result;
1957 } 1878 }
1958 1879
1959 /** 1880 /**
(...skipping 22 matching lines...) Expand all
1982 if (identical(node.attributeEnd.type, ht.TokenType.GT) && scriptSourcePath == null) { 1903 if (identical(node.attributeEnd.type, ht.TokenType.GT) && scriptSourcePath == null) {
1983 EmbeddedHtmlScriptElementImpl script = new EmbeddedHtmlScriptElementImpl (node); 1904 EmbeddedHtmlScriptElementImpl script = new EmbeddedHtmlScriptElementImpl (node);
1984 try { 1905 try {
1985 LibraryResolver resolver = new LibraryResolver(_context); 1906 LibraryResolver resolver = new LibraryResolver(_context);
1986 LibraryElementImpl library = resolver.resolveEmbeddedLibrary(htmlSourc e, _modificationStamp, node.script, true) as LibraryElementImpl; 1907 LibraryElementImpl library = resolver.resolveEmbeddedLibrary(htmlSourc e, _modificationStamp, node.script, true) as LibraryElementImpl;
1987 script.scriptLibrary = library; 1908 script.scriptLibrary = library;
1988 _resolvedLibraries.addAll(resolver.resolvedLibraries); 1909 _resolvedLibraries.addAll(resolver.resolvedLibraries);
1989 _errorListener.addAll(resolver.errorListener); 1910 _errorListener.addAll(resolver.errorListener);
1990 } on AnalysisException catch (exception) { 1911 } on AnalysisException catch (exception) {
1991 //TODO (danrubel): Handle or forward the exception 1912 //TODO (danrubel): Handle or forward the exception
1992 AnalysisEngine.instance.logger.logError3(exception); 1913 AnalysisEngine.instance.logger.logError2("Could not resolve script tag ", exception);
1993 } 1914 }
1994 node.scriptElement = script; 1915 node.scriptElement = script;
1995 _scripts.add(script); 1916 _scripts.add(script);
1996 } else { 1917 } else {
1997 ExternalHtmlScriptElementImpl script = new ExternalHtmlScriptElementImpl (node); 1918 ExternalHtmlScriptElementImpl script = new ExternalHtmlScriptElementImpl (node);
1998 if (scriptSourcePath != null) { 1919 if (scriptSourcePath != null) {
1999 try { 1920 try {
2000 scriptSourcePath = Uri.encodeFull(scriptSourcePath); 1921 scriptSourcePath = Uri.encodeFull(scriptSourcePath);
2001 // Force an exception to be thrown if the URI is invalid so that we can report the 1922 // Force an exception to be thrown if the URI is invalid so that we can report the
2002 // problem. 1923 // problem.
(...skipping 22 matching lines...) Expand all
2025 try { 1946 try {
2026 node.visitChildren(this); 1947 node.visitChildren(this);
2027 _htmlElement.scripts = new List.from(_scripts); 1948 _htmlElement.scripts = new List.from(_scripts);
2028 } finally { 1949 } finally {
2029 _scripts = null; 1950 _scripts = null;
2030 _parentNodes = null; 1951 _parentNodes = null;
2031 } 1952 }
2032 return null; 1953 return null;
2033 } 1954 }
2034 1955
2035 Object visitXmlAttributeNode(ht.XmlAttributeNode node) { 1956 Object visitXmlAttributeNode(ht.XmlAttributeNode node) => null;
2036 for (ht.EmbeddedExpression expression in node.expressions) {
2037 resolveExpression(expression.expression);
2038 }
2039 return null;
2040 }
2041 1957
2042 Object visitXmlTagNode(ht.XmlTagNode node) { 1958 Object visitXmlTagNode(ht.XmlTagNode node) {
2043 if (_parentNodes.contains(node)) { 1959 if (_parentNodes.contains(node)) {
2044 return reportCircularity(node); 1960 return reportCircularity(node);
2045 } 1961 }
2046 _parentNodes.add(node); 1962 _parentNodes.add(node);
2047 try { 1963 try {
2048 for (ht.EmbeddedExpression expression in node.expressions) {
2049 resolveExpression(expression.expression);
2050 }
2051 node.visitChildren(this); 1964 node.visitChildren(this);
2052 } finally { 1965 } finally {
2053 _parentNodes.remove(node); 1966 _parentNodes.remove(node);
2054 } 1967 }
2055 return null; 1968 return null;
2056 } 1969 }
2057 1970
2058 /** 1971 /**
2059 * Return the first source attribute for the given tag node, or `null` if it d oes not exist. 1972 * Return the first source attribute for the given tag node, or `null` if it d oes not exist.
2060 * 1973 *
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2118 * @param errorCode the error code of the error to be reported 2031 * @param errorCode the error code of the error to be reported
2119 * @param offset the offset of the first character to be highlighted 2032 * @param offset the offset of the first character to be highlighted
2120 * @param length the number of characters to be highlighted 2033 * @param length the number of characters to be highlighted
2121 * @param arguments the arguments used to compose the error message 2034 * @param arguments the arguments used to compose the error message
2122 */ 2035 */
2123 void reportValueError(ErrorCode errorCode, ht.XmlAttributeNode attribute, List <Object> arguments) { 2036 void reportValueError(ErrorCode errorCode, ht.XmlAttributeNode attribute, List <Object> arguments) {
2124 int offset = attribute.valueToken.offset + 1; 2037 int offset = attribute.valueToken.offset + 1;
2125 int length = attribute.valueToken.length - 2; 2038 int length = attribute.valueToken.length - 2;
2126 reportError(errorCode, offset, length, arguments); 2039 reportError(errorCode, offset, length, arguments);
2127 } 2040 }
2128
2129 void resolveExpression(Expression expression) {
2130 }
2131 } 2041 }
2132 2042
2133 /** 2043 /**
2134 * Instances of the class `BestPracticesVerifier` traverse an AST structure look ing for 2044 * Instances of the class `BestPracticesVerifier` traverse an AST structure look ing for
2135 * violations of Dart best practices. 2045 * violations of Dart best practices.
2136 * 2046 *
2137 * @coverage dart.engine.resolver 2047 * @coverage dart.engine.resolver
2138 */ 2048 */
2139 class BestPracticesVerifier extends RecursiveASTVisitor<Object> { 2049 class BestPracticesVerifier extends RecursiveASTVisitor<Object> {
2140 static String _GETTER = "getter"; 2050 static String _GETTER = "getter";
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2189 2099
2190 Object visitAsExpression(AsExpression node) { 2100 Object visitAsExpression(AsExpression node) {
2191 checkForUnnecessaryCast(node); 2101 checkForUnnecessaryCast(node);
2192 return super.visitAsExpression(node); 2102 return super.visitAsExpression(node);
2193 } 2103 }
2194 2104
2195 Object visitAssignmentExpression(AssignmentExpression node) { 2105 Object visitAssignmentExpression(AssignmentExpression node) {
2196 sc.TokenType operatorType = node.operator.type; 2106 sc.TokenType operatorType = node.operator.type;
2197 if (operatorType != sc.TokenType.EQ) { 2107 if (operatorType != sc.TokenType.EQ) {
2198 checkForDeprecatedMemberUse(node.bestElement, node); 2108 checkForDeprecatedMemberUse(node.bestElement, node);
2109 } else {
2110 checkForUseOfVoidResult(node.rightHandSide);
2199 } 2111 }
2200 return super.visitAssignmentExpression(node); 2112 return super.visitAssignmentExpression(node);
2201 } 2113 }
2202 2114
2203 Object visitBinaryExpression(BinaryExpression node) { 2115 Object visitBinaryExpression(BinaryExpression node) {
2204 checkForDivisionOptimizationHint(node); 2116 checkForDivisionOptimizationHint(node);
2205 checkForDeprecatedMemberUse(node.bestElement, node); 2117 checkForDeprecatedMemberUse(node.bestElement, node);
2206 return super.visitBinaryExpression(node); 2118 return super.visitBinaryExpression(node);
2207 } 2119 }
2208 2120
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2273 Object visitSimpleIdentifier(SimpleIdentifier node) { 2185 Object visitSimpleIdentifier(SimpleIdentifier node) {
2274 checkForDeprecatedMemberUse2(node); 2186 checkForDeprecatedMemberUse2(node);
2275 return super.visitSimpleIdentifier(node); 2187 return super.visitSimpleIdentifier(node);
2276 } 2188 }
2277 2189
2278 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { 2190 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
2279 checkForDeprecatedMemberUse(node.staticElement, node); 2191 checkForDeprecatedMemberUse(node.staticElement, node);
2280 return super.visitSuperConstructorInvocation(node); 2192 return super.visitSuperConstructorInvocation(node);
2281 } 2193 }
2282 2194
2195 Object visitVariableDeclaration(VariableDeclaration node) {
2196 checkForUseOfVoidResult(node.initializer);
2197 return super.visitVariableDeclaration(node);
2198 }
2199
2283 /** 2200 /**
2284 * Check for the passed is expression for the unnecessary type check hint code s as well as null 2201 * Check for the passed is expression for the unnecessary type check hint code s as well as null
2285 * checks expressed using an is expression. 2202 * checks expressed using an is expression.
2286 * 2203 *
2287 * @param node the is expression to check 2204 * @param node the is expression to check
2288 * @return `true` if and only if a hint code is generated on the passed node 2205 * @return `true` if and only if a hint code is generated on the passed node
2289 * @see HintCode#TYPE_CHECK_IS_NOT_NULL 2206 * @see HintCode#TYPE_CHECK_IS_NOT_NULL
2290 * @see HintCode#TYPE_CHECK_IS_NULL 2207 * @see HintCode#TYPE_CHECK_IS_NULL
2291 * @see HintCode#UNNECESSARY_TYPE_CHECK_TRUE 2208 * @see HintCode#UNNECESSARY_TYPE_CHECK_TRUE
2292 * @see HintCode#UNNECESSARY_TYPE_CHECK_FALSE 2209 * @see HintCode#UNNECESSARY_TYPE_CHECK_FALSE
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2428 /** 2345 /**
2429 * Generate a hint for functions or methods that have a return type, but do no t have a return 2346 * Generate a hint for functions or methods that have a return type, but do no t have a return
2430 * statement on all branches. At the end of blocks with no return, Dart implic itly returns 2347 * statement on all branches. At the end of blocks with no return, Dart implic itly returns
2431 * `null`, avoiding these implicit returns is considered a best practice. 2348 * `null`, avoiding these implicit returns is considered a best practice.
2432 * 2349 *
2433 * @param node the binary expression to check 2350 * @param node the binary expression to check
2434 * @param body the function body 2351 * @param body the function body
2435 * @return `true` if and only if a hint code is generated on the passed node 2352 * @return `true` if and only if a hint code is generated on the passed node
2436 * @see HintCode#MISSING_RETURN 2353 * @see HintCode#MISSING_RETURN
2437 */ 2354 */
2438 bool checkForMissingReturn(TypeName returnType, FunctionBody body) => false; 2355 bool checkForMissingReturn(TypeName returnType, FunctionBody body) {
2356 // Check that the method or function has a return type, and a function body
2357 if (returnType == null || body == null) {
2358 return false;
2359 }
2360 // Check that the body is a BlockFunctionBody
2361 if (body is! BlockFunctionBody) {
2362 return false;
2363 }
2364 // Check that the type is resolvable, and is not "void"
2365 Type2 returnTypeType = returnType.type;
2366 if (returnTypeType == null || returnTypeType.isVoid) {
2367 return false;
2368 }
2369 // Check the block for a return statement, if not, create the hint
2370 BlockFunctionBody blockFunctionBody = body as BlockFunctionBody;
2371 if (!blockFunctionBody.accept(new ExitDetector())) {
2372 _errorReporter.reportError3(HintCode.MISSING_RETURN, returnType, [returnTy peType.displayName]);
2373 return true;
2374 }
2375 return false;
2376 }
2439 2377
2440 /** 2378 /**
2441 * Check for the passed class declaration for the 2379 * Check for the passed class declaration for the
2442 * [HintCode#OVERRIDE_EQUALS_BUT_NOT_HASH_CODE] hint code. 2380 * [HintCode#OVERRIDE_EQUALS_BUT_NOT_HASH_CODE] hint code.
2443 * 2381 *
2444 * @param node the class declaration to check 2382 * @param node the class declaration to check
2445 * @return `true` if and only if a hint code is generated on the passed node 2383 * @return `true` if and only if a hint code is generated on the passed node
2446 * @see HintCode#OVERRIDE_EQUALS_BUT_NOT_HASH_CODE 2384 * @see HintCode#OVERRIDE_EQUALS_BUT_NOT_HASH_CODE
2447 */ 2385 */
2448 bool checkForOverrideEqualsButNotHashCode(ClassDeclaration node) { 2386 bool checkForOverrideEqualsButNotHashCode(ClassDeclaration node) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
2543 Type2 lhsType = expression.staticType; 2481 Type2 lhsType = expression.staticType;
2544 Type2 rhsType = typeName.type; 2482 Type2 rhsType = typeName.type;
2545 // TODO(jwren) After dartbug.com/13732, revisit this, we should be able to r emove the 2483 // TODO(jwren) After dartbug.com/13732, revisit this, we should be able to r emove the
2546 // !(x instanceof TypeParameterType) checks. 2484 // !(x instanceof TypeParameterType) checks.
2547 if (lhsType != null && rhsType != null && !lhsType.isDynamic && !rhsType.isD ynamic && lhsType is! TypeParameterType && rhsType is! TypeParameterType && lhsT ype.isSubtypeOf(rhsType)) { 2485 if (lhsType != null && rhsType != null && !lhsType.isDynamic && !rhsType.isD ynamic && lhsType is! TypeParameterType && rhsType is! TypeParameterType && lhsT ype.isSubtypeOf(rhsType)) {
2548 _errorReporter.reportError3(HintCode.UNNECESSARY_CAST, node, []); 2486 _errorReporter.reportError3(HintCode.UNNECESSARY_CAST, node, []);
2549 return true; 2487 return true;
2550 } 2488 }
2551 return false; 2489 return false;
2552 } 2490 }
2491
2492 /**
2493 * Check for situations where the result of a method or function is used, when it returns 'void'.
2494 *
2495 * TODO(jwren) Many other situations of use could be covered. We currently cov er the cases var x =
2496 * m() and x = m(), but we could also cover cases such as m().x, m()[k], a + m (), f(m()), return
2497 * m().
2498 *
2499 * @param node expression on the RHS of some assignment
2500 * @return `true` if and only if a hint code is generated on the passed node
2501 * @see HintCode#USE_OF_VOID_RESULT
2502 */
2503 bool checkForUseOfVoidResult(Expression expression) {
2504 if (expression == null || expression is! MethodInvocation) {
2505 return false;
2506 }
2507 MethodInvocation methodInvocation = expression as MethodInvocation;
2508 if (identical(methodInvocation.staticType, VoidTypeImpl.instance)) {
2509 SimpleIdentifier methodName = methodInvocation.methodName;
2510 _errorReporter.reportError3(HintCode.USE_OF_VOID_RESULT, methodName, [meth odName.name]);
2511 return true;
2512 }
2513 return false;
2514 }
2553 } 2515 }
2554 2516
2555 /** 2517 /**
2556 * Instances of the class `Dart2JSVerifier` traverse an AST structure looking fo r hints for 2518 * Instances of the class `Dart2JSVerifier` traverse an AST structure looking fo r hints for
2557 * code that will be compiled to JS, such as [HintCode#IS_DOUBLE]. 2519 * code that will be compiled to JS, such as [HintCode#IS_DOUBLE].
2558 * 2520 *
2559 * @coverage dart.engine.resolver 2521 * @coverage dart.engine.resolver
2560 */ 2522 */
2561 class Dart2JSVerifier extends RecursiveASTVisitor<Object> { 2523 class Dart2JSVerifier extends RecursiveASTVisitor<Object> {
2562 /** 2524 /**
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
3012 } 2974 }
3013 return node.argumentList.accept(this); 2975 return node.argumentList.accept(this);
3014 } 2976 }
3015 2977
3016 bool visitIdentifier(Identifier node) => false; 2978 bool visitIdentifier(Identifier node) => false;
3017 2979
3018 bool visitIfStatement(IfStatement node) { 2980 bool visitIfStatement(IfStatement node) {
3019 Expression conditionExpression = node.condition; 2981 Expression conditionExpression = node.condition;
3020 Statement thenStatement = node.thenStatement; 2982 Statement thenStatement = node.thenStatement;
3021 Statement elseStatement = node.elseStatement; 2983 Statement elseStatement = node.elseStatement;
3022 // TODO(jwren) Do we want to take constant expressions into account, evaluat e if(false) {}
3023 // differently than if(<condition>), when <condition> evaluates to a constan t false value?
3024 if (conditionExpression.accept(this)) { 2984 if (conditionExpression.accept(this)) {
3025 return true; 2985 return true;
3026 } 2986 }
2987 // TODO(jwren) Do we want to take all constant expressions into account?
2988 if (conditionExpression is BooleanLiteral) {
2989 BooleanLiteral booleanLiteral = conditionExpression;
2990 if (booleanLiteral.value) {
2991 // if(true) ...
2992 return thenStatement.accept(this);
2993 } else if (elseStatement != null) {
2994 // if (false) ...
2995 return elseStatement.accept(this);
2996 }
2997 }
3027 if (thenStatement == null || elseStatement == null) { 2998 if (thenStatement == null || elseStatement == null) {
3028 return false; 2999 return false;
3029 } 3000 }
3030 return thenStatement.accept(this) && elseStatement.accept(this); 3001 return thenStatement.accept(this) && elseStatement.accept(this);
3031 } 3002 }
3032 3003
3033 bool visitIndexExpression(IndexExpression node) { 3004 bool visitIndexExpression(IndexExpression node) {
3034 Expression target = node.target; 3005 Expression target = node.realTarget;
3035 if (target != null && target.accept(this)) { 3006 if (target != null && target.accept(this)) {
3036 return true; 3007 return true;
3037 } 3008 }
3038 if (node.index.accept(this)) { 3009 if (node.index.accept(this)) {
3039 return true; 3010 return true;
3040 } 3011 }
3041 return false; 3012 return false;
3042 } 3013 }
3043 3014
3044 bool visitInstanceCreationExpression(InstanceCreationExpression node) => node. argumentList.accept(this); 3015 bool visitInstanceCreationExpression(InstanceCreationExpression node) => node. argumentList.accept(this);
3045 3016
3046 bool visitIsExpression(IsExpression node) => node.expression.accept(this); 3017 bool visitIsExpression(IsExpression node) => node.expression.accept(this);
3047 3018
3048 bool visitLabel(Label node) => false; 3019 bool visitLabel(Label node) => false;
3049 3020
3050 bool visitLabeledStatement(LabeledStatement node) => node.statement.accept(thi s); 3021 bool visitLabeledStatement(LabeledStatement node) => node.statement.accept(thi s);
3051 3022
3052 bool visitLiteral(Literal node) => false; 3023 bool visitLiteral(Literal node) => false;
3053 3024
3054 bool visitMethodInvocation(MethodInvocation node) { 3025 bool visitMethodInvocation(MethodInvocation node) {
3055 Expression target = node.target; 3026 Expression target = node.realTarget;
3056 if (target != null && target.accept(this)) { 3027 if (target != null && target.accept(this)) {
3057 return true; 3028 return true;
3058 } 3029 }
3059 return node.argumentList.accept(this); 3030 return node.argumentList.accept(this);
3060 } 3031 }
3061 3032
3062 bool visitNamedExpression(NamedExpression node) => node.expression.accept(this ); 3033 bool visitNamedExpression(NamedExpression node) => node.expression.accept(this );
3063 3034
3064 bool visitParenthesizedExpression(ParenthesizedExpression node) => node.expres sion.accept(this); 3035 bool visitParenthesizedExpression(ParenthesizedExpression node) => node.expres sion.accept(this);
3065 3036
3066 bool visitPostfixExpression(PostfixExpression node) => false; 3037 bool visitPostfixExpression(PostfixExpression node) => false;
3067 3038
3068 bool visitPrefixExpression(PrefixExpression node) => false; 3039 bool visitPrefixExpression(PrefixExpression node) => false;
3069 3040
3070 bool visitPropertyAccess(PropertyAccess node) => node.target.accept(this); 3041 bool visitPropertyAccess(PropertyAccess node) {
3042 Expression target = node.realTarget;
3043 if (target != null && target.accept(this)) {
3044 return true;
3045 }
3046 return false;
3047 }
3071 3048
3072 bool visitRethrowExpression(RethrowExpression node) => true; 3049 bool visitRethrowExpression(RethrowExpression node) => true;
3073 3050
3074 bool visitReturnStatement(ReturnStatement node) => true; 3051 bool visitReturnStatement(ReturnStatement node) => true;
3075 3052
3076 bool visitSuperExpression(SuperExpression node) => false; 3053 bool visitSuperExpression(SuperExpression node) => false;
3077 3054
3078 bool visitSwitchCase(SwitchCase node) => visitStatements(node.statements); 3055 bool visitSwitchCase(SwitchCase node) => visitStatements(node.statements);
3079 3056
3080 bool visitSwitchDefault(SwitchDefault node) => visitStatements(node.statements ); 3057 bool visitSwitchDefault(SwitchDefault node) => visitStatements(node.statements );
3081 3058
3082 bool visitSwitchStatement(SwitchStatement node) { 3059 bool visitSwitchStatement(SwitchStatement node) {
3083 bool hasDefault = false; 3060 bool hasDefault = false;
3084 for (SwitchMember member in node.members) { 3061 NodeList<SwitchMember> memberList = node.members;
3085 if (!member.accept(this)) { 3062 List<SwitchMember> members = new List.from(memberList);
3063 for (int i = 0; i < members.length; i++) {
3064 SwitchMember switchMember = members[i];
3065 if (switchMember is SwitchDefault) {
3066 hasDefault = true;
3067 // If this is the last member and there are no statements, return false
3068 if (switchMember.statements.isEmpty && i + 1 == members.length) {
3069 return false;
3070 }
3071 }
3072 // For switch members with no statements, don't visit the children, otherw ise, return false if
3073 // no return is found in the children statements
3074 if (!switchMember.statements.isEmpty && !switchMember.accept(this)) {
3086 return false; 3075 return false;
3087 } 3076 }
3088 if (member is SwitchDefault) {
3089 hasDefault = true;
3090 }
3091 } 3077 }
3092 return hasDefault; 3078 return hasDefault;
3093 } 3079 }
3094 3080
3095 bool visitThisExpression(ThisExpression node) => false; 3081 bool visitThisExpression(ThisExpression node) => false;
3096 3082
3097 bool visitThrowExpression(ThrowExpression node) => true; 3083 bool visitThrowExpression(ThrowExpression node) => true;
3098 3084
3099 bool visitTryStatement(TryStatement node) { 3085 bool visitTryStatement(TryStatement node) {
3100 if (node.body.accept(this)) { 3086 if (node.body.accept(this)) {
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
3428 visitMetadata(node.metadata); 3414 visitMetadata(node.metadata);
3429 return null; 3415 return null;
3430 } 3416 }
3431 3417
3432 Object visitLibraryDirective(LibraryDirective node) { 3418 Object visitLibraryDirective(LibraryDirective node) {
3433 visitMetadata(node.metadata); 3419 visitMetadata(node.metadata);
3434 return null; 3420 return null;
3435 } 3421 }
3436 3422
3437 Object visitPrefixedIdentifier(PrefixedIdentifier node) { 3423 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
3424 if (_unusedImports.isEmpty) {
3425 return null;
3426 }
3438 // If the prefixed identifier references some A.B, where A is a library pref ix, then we can 3427 // If the prefixed identifier references some A.B, where A is a library pref ix, then we can
3439 // lookup the associated ImportDirective in prefixElementMap and remove it f rom the 3428 // lookup the associated ImportDirective in prefixElementMap and remove it f rom the
3440 // unusedImports list. 3429 // unusedImports list.
3441 SimpleIdentifier prefixIdentifier = node.prefix; 3430 SimpleIdentifier prefixIdentifier = node.prefix;
3442 Element element = prefixIdentifier.staticElement; 3431 Element element = prefixIdentifier.staticElement;
3443 if (element is PrefixElement) { 3432 if (element is PrefixElement) {
3444 _unusedImports.remove(_prefixElementMap[element]); 3433 _unusedImports.remove(_prefixElementMap[element]);
3445 return null; 3434 return null;
3446 } 3435 }
3447 // Otherwise, pass the prefixed identifier element and name onto visitIdenti fier. 3436 // Otherwise, pass the prefixed identifier element and name onto visitIdenti fier.
3448 return visitIdentifier(element, prefixIdentifier.name); 3437 return visitIdentifier(element, prefixIdentifier.name);
3449 } 3438 }
3450 3439
3451 Object visitSimpleIdentifier(SimpleIdentifier node) => visitIdentifier(node.st aticElement, node.name); 3440 Object visitSimpleIdentifier(SimpleIdentifier node) {
3441 if (_unusedImports.isEmpty) {
3442 return null;
3443 }
3444 return visitIdentifier(node.staticElement, node.name);
3445 }
3452 3446
3453 void set inDefiningCompilationUnit(bool inDefiningCompilationUnit) { 3447 void set inDefiningCompilationUnit(bool inDefiningCompilationUnit) {
3454 this._inDefiningCompilationUnit = inDefiningCompilationUnit; 3448 this._inDefiningCompilationUnit = inDefiningCompilationUnit;
3455 } 3449 }
3456 3450
3457 /** 3451 /**
3458 * Recursively add any exported library elements into the [libraryMap]. 3452 * Recursively add any exported library elements into the [libraryMap].
3459 */ 3453 */
3460 void addAdditionalLibrariesForExports(LibraryElement library, ImportDirective importDirective, List<LibraryElement> exportPath) { 3454 void addAdditionalLibrariesForExports(LibraryElement library, ImportDirective importDirective, List<LibraryElement> exportPath) {
3461 if (exportPath.contains(library)) { 3455 if (exportPath.contains(library)) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
3512 // If the element is multiply defined then call this method recursively for each of the conflicting elements. 3506 // If the element is multiply defined then call this method recursively for each of the conflicting elements.
3513 if (element is MultiplyDefinedElement) { 3507 if (element is MultiplyDefinedElement) {
3514 MultiplyDefinedElement multiplyDefinedElement = element; 3508 MultiplyDefinedElement multiplyDefinedElement = element;
3515 for (Element elt in multiplyDefinedElement.conflictingElements) { 3509 for (Element elt in multiplyDefinedElement.conflictingElements) {
3516 visitIdentifier(elt, name); 3510 visitIdentifier(elt, name);
3517 } 3511 }
3518 return null; 3512 return null;
3519 } else if (element is PrefixElement) { 3513 } else if (element is PrefixElement) {
3520 _unusedImports.remove(_prefixElementMap[element]); 3514 _unusedImports.remove(_prefixElementMap[element]);
3521 return null; 3515 return null;
3516 } else if (element.enclosingElement is! CompilationUnitElement) {
3517 // Identifiers that aren't a prefix element and whose enclosing element is n't a
3518 // CompilationUnit are ignored- this covers the case the identifier is a r elative-reference,
3519 // a reference to an identifier not imported by this library.
3520 return null;
3522 } 3521 }
3523 LibraryElement containingLibrary = element.library; 3522 LibraryElement containingLibrary = element.library;
3524 if (containingLibrary == null) { 3523 if (containingLibrary == null) {
3525 return null; 3524 return null;
3526 } 3525 }
3527 // If the element is declared in the current library, return. 3526 // If the element is declared in the current library, return.
3528 if (_currentLibrary == containingLibrary) { 3527 if (_currentLibrary == containingLibrary) {
3529 return null; 3528 return null;
3530 } 3529 }
3531 List<ImportDirective> importsFromSameLibrary = _libraryMap[containingLibrary ]; 3530 List<ImportDirective> importsFromSameLibrary = _libraryMap[containingLibrary ];
(...skipping 1635 matching lines...) Expand 10 before | Expand all | Expand 10 after
5167 } 5166 }
5168 } 5167 }
5169 } 5168 }
5170 return null; 5169 return null;
5171 } 5170 }
5172 5171
5173 Object visitBreakStatement(BreakStatement node) { 5172 Object visitBreakStatement(BreakStatement node) {
5174 SimpleIdentifier labelNode = node.label; 5173 SimpleIdentifier labelNode = node.label;
5175 LabelElementImpl labelElement = lookupLabel(node, labelNode); 5174 LabelElementImpl labelElement = lookupLabel(node, labelNode);
5176 if (labelElement != null && labelElement.isOnSwitchMember) { 5175 if (labelElement != null && labelElement.isOnSwitchMember) {
5177 _resolver.reportError8(ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER, lab elNode, []); 5176 _resolver.reportError9(ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER, lab elNode, []);
5178 } 5177 }
5179 return null; 5178 return null;
5180 } 5179 }
5181 5180
5182 Object visitClassDeclaration(ClassDeclaration node) { 5181 Object visitClassDeclaration(ClassDeclaration node) {
5183 setMetadata(node.element, node); 5182 setMetadata(node.element, node);
5184 return null; 5183 return null;
5185 } 5184 }
5186 5185
5187 Object visitClassTypeAlias(ClassTypeAlias node) { 5186 Object visitClassTypeAlias(ClassTypeAlias node) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
5293 } 5292 }
5294 return null; 5293 return null;
5295 } 5294 }
5296 5295
5297 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) { 5296 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
5298 SimpleIdentifier fieldName = node.fieldName; 5297 SimpleIdentifier fieldName = node.fieldName;
5299 ClassElement enclosingClass = _resolver.enclosingClass; 5298 ClassElement enclosingClass = _resolver.enclosingClass;
5300 FieldElement fieldElement = enclosingClass.getField(fieldName.name); 5299 FieldElement fieldElement = enclosingClass.getField(fieldName.name);
5301 fieldName.staticElement = fieldElement; 5300 fieldName.staticElement = fieldElement;
5302 if (fieldElement == null || fieldElement.isSynthetic) { 5301 if (fieldElement == null || fieldElement.isSynthetic) {
5303 _resolver.reportError8(CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTANT_F IELD, node, [fieldName]); 5302 _resolver.reportError9(CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTANT_F IELD, node, [fieldName]);
5304 } else if (fieldElement.isStatic) { 5303 } else if (fieldElement.isStatic) {
5305 _resolver.reportError8(CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD, node, [fieldName]); 5304 _resolver.reportError9(CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD, node, [fieldName]);
5306 } 5305 }
5307 return null; 5306 return null;
5308 } 5307 }
5309 5308
5310 Object visitConstructorName(ConstructorName node) { 5309 Object visitConstructorName(ConstructorName node) {
5311 Type2 type = node.type.type; 5310 Type2 type = node.type.type;
5312 if (type != null && type.isDynamic) { 5311 if (type != null && type.isDynamic) {
5313 return null; 5312 return null;
5314 } else if (type is! InterfaceType) { 5313 } else if (type is! InterfaceType) {
5315 // TODO(brianwilkerson) Report these errors. 5314 // TODO(brianwilkerson) Report these errors.
(...skipping 17 matching lines...) Expand all
5333 name.staticElement = constructor; 5332 name.staticElement = constructor;
5334 } 5333 }
5335 node.staticElement = constructor; 5334 node.staticElement = constructor;
5336 return null; 5335 return null;
5337 } 5336 }
5338 5337
5339 Object visitContinueStatement(ContinueStatement node) { 5338 Object visitContinueStatement(ContinueStatement node) {
5340 SimpleIdentifier labelNode = node.label; 5339 SimpleIdentifier labelNode = node.label;
5341 LabelElementImpl labelElement = lookupLabel(node, labelNode); 5340 LabelElementImpl labelElement = lookupLabel(node, labelNode);
5342 if (labelElement != null && labelElement.isOnSwitchStatement) { 5341 if (labelElement != null && labelElement.isOnSwitchStatement) {
5343 _resolver.reportError8(ResolverErrorCode.CONTINUE_LABEL_ON_SWITCH, labelNo de, []); 5342 _resolver.reportError9(ResolverErrorCode.CONTINUE_LABEL_ON_SWITCH, labelNo de, []);
5344 } 5343 }
5345 return null; 5344 return null;
5346 } 5345 }
5347 5346
5348 Object visitDeclaredIdentifier(DeclaredIdentifier node) { 5347 Object visitDeclaredIdentifier(DeclaredIdentifier node) {
5349 setMetadata(node.element, node); 5348 setMetadata(node.element, node);
5350 return null; 5349 return null;
5351 } 5350 }
5352 5351
5353 Object visitExportDirective(ExportDirective node) { 5352 Object visitExportDirective(ExportDirective node) {
5354 Element element = node.element; 5353 Element element = node.element;
5355 if (element is ExportElement) { 5354 if (element is ExportElement) {
5356 // The element is null when the URI is invalid 5355 // The element is null when the URI is invalid
5357 // TODO(brianwilkerson) Figure out whether the element can ever be somethi ng other than an 5356 // TODO(brianwilkerson) Figure out whether the element can ever be somethi ng other than an
5358 // ExportElement 5357 // ExportElement
5359 resolveCombinators(element.exportedLibrary, node.combinators); 5358 resolveCombinators(element.exportedLibrary, node.combinators);
5360 setMetadata(element, node); 5359 setMetadata(element, node);
5361 } 5360 }
5362 return null; 5361 return null;
5363 } 5362 }
5364 5363
5365 Object visitFieldFormalParameter(FieldFormalParameter node) { 5364 Object visitFieldFormalParameter(FieldFormalParameter node) {
5366 String fieldName = node.identifier.name; 5365 String fieldName = node.identifier.name;
5367 ClassElement classElement = _resolver.enclosingClass; 5366 ClassElement classElement = _resolver.enclosingClass;
5368 if (classElement != null) { 5367 if (classElement != null) {
5369 FieldElement fieldElement = classElement.getField(fieldName); 5368 FieldElement fieldElement = classElement.getField(fieldName);
5370 if (fieldElement == null || fieldElement.isSynthetic) { 5369 if (fieldElement == null || fieldElement.isSynthetic) {
5371 _resolver.reportError8(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_ EXISTANT_FIELD, node, [fieldName]); 5370 _resolver.reportError9(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_ EXISTANT_FIELD, node, [fieldName]);
5372 } else { 5371 } else {
5373 ParameterElement parameterElement = node.element; 5372 ParameterElement parameterElement = node.element;
5374 if (parameterElement is FieldFormalParameterElementImpl) { 5373 if (parameterElement is FieldFormalParameterElementImpl) {
5375 FieldFormalParameterElementImpl fieldFormal = parameterElement; 5374 FieldFormalParameterElementImpl fieldFormal = parameterElement;
5376 Type2 declaredType = fieldFormal.type; 5375 Type2 declaredType = fieldFormal.type;
5377 Type2 fieldType = fieldElement.type; 5376 Type2 fieldType = fieldElement.type;
5378 if (fieldElement.isSynthetic) { 5377 if (fieldElement.isSynthetic) {
5379 _resolver.reportError8(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_ NON_EXISTANT_FIELD, node, [fieldName]); 5378 _resolver.reportError9(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_ NON_EXISTANT_FIELD, node, [fieldName]);
5380 } else if (fieldElement.isStatic) { 5379 } else if (fieldElement.isStatic) {
5381 _resolver.reportError8(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_ STATIC_FIELD, node, [fieldName]); 5380 _resolver.reportError9(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_ STATIC_FIELD, node, [fieldName]);
5382 } else if (declaredType != null && fieldType != null && !declaredType. isAssignableTo(fieldType)) { 5381 } else if (declaredType != null && fieldType != null && !declaredType. isAssignableTo(fieldType)) {
5383 _resolver.reportError8(StaticWarningCode.FIELD_INITIALIZING_FORMAL_N OT_ASSIGNABLE, node, [declaredType.displayName, fieldType.displayName]); 5382 _resolver.reportError9(StaticWarningCode.FIELD_INITIALIZING_FORMAL_N OT_ASSIGNABLE, node, [declaredType.displayName, fieldType.displayName]);
5384 } 5383 }
5385 } else { 5384 } else {
5386 if (fieldElement.isSynthetic) { 5385 if (fieldElement.isSynthetic) {
5387 _resolver.reportError8(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_ NON_EXISTANT_FIELD, node, [fieldName]); 5386 _resolver.reportError9(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_ NON_EXISTANT_FIELD, node, [fieldName]);
5388 } else if (fieldElement.isStatic) { 5387 } else if (fieldElement.isStatic) {
5389 _resolver.reportError8(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_ STATIC_FIELD, node, [fieldName]); 5388 _resolver.reportError9(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_ STATIC_FIELD, node, [fieldName]);
5390 } 5389 }
5391 } 5390 }
5392 } 5391 }
5393 } 5392 }
5394 // else { 5393 // else {
5395 // // TODO(jwren) Report error, constructor initializer variable is a top level element 5394 // // TODO(jwren) Report error, constructor initializer variable is a top level element
5396 // // (Either here or in ErrorVerifier#checkForAllFinalInitializedErrorCo des) 5395 // // (Either here or in ErrorVerifier#checkForAllFinalInitializedErrorCo des)
5397 // } 5396 // }
5398 setMetadata2(node.element, node); 5397 setMetadata2(node.element, node);
5399 return super.visitFieldFormalParameter(node); 5398 return super.visitFieldFormalParameter(node);
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
5605 } 5604 }
5606 } 5605 }
5607 } 5606 }
5608 } 5607 }
5609 generatedWithTypePropagation = true; 5608 generatedWithTypePropagation = true;
5610 } 5609 }
5611 if (errorCode == null) { 5610 if (errorCode == null) {
5612 return null; 5611 return null;
5613 } 5612 }
5614 if (identical(errorCode, StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION)) { 5613 if (identical(errorCode, StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION)) {
5615 _resolver.reportError8(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION, m ethodName, [methodName.name]); 5614 _resolver.reportError9(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION, m ethodName, [methodName.name]);
5616 } else if (identical(errorCode, CompileTimeErrorCode.UNDEFINED_FUNCTION)) { 5615 } else if (identical(errorCode, CompileTimeErrorCode.UNDEFINED_FUNCTION)) {
5617 _resolver.reportError8(CompileTimeErrorCode.UNDEFINED_FUNCTION, methodName , [methodName.name]); 5616 _resolver.reportError9(CompileTimeErrorCode.UNDEFINED_FUNCTION, methodName , [methodName.name]);
5618 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_METHOD)) { 5617 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_METHOD)) {
5619 String targetTypeName; 5618 String targetTypeName;
5620 if (target == null) { 5619 if (target == null) {
5621 ClassElement enclosingClass = _resolver.enclosingClass; 5620 ClassElement enclosingClass = _resolver.enclosingClass;
5622 targetTypeName = enclosingClass.displayName; 5621 targetTypeName = enclosingClass.displayName;
5623 ErrorCode proxyErrorCode = (generatedWithTypePropagation ? HintCode.UNDE FINED_METHOD : StaticTypeWarningCode.UNDEFINED_METHOD) as ErrorCode; 5622 ErrorCode proxyErrorCode = (generatedWithTypePropagation ? HintCode.UNDE FINED_METHOD : StaticTypeWarningCode.UNDEFINED_METHOD) as ErrorCode;
5624 _resolver.reportErrorProxyConditionalAnalysisError(_resolver.enclosingCl ass, proxyErrorCode, methodName, [methodName.name, targetTypeName]); 5623 _resolver.reportErrorProxyConditionalAnalysisError(_resolver.enclosingCl ass, proxyErrorCode, methodName, [methodName.name, targetTypeName]);
5625 } else { 5624 } else {
5626 // ignore Function "call" 5625 // ignore Function "call"
5627 // (if we are about to create a hint using type propagation, then we can use type 5626 // (if we are about to create a hint using type propagation, then we can use type
(...skipping 15 matching lines...) Expand all
5643 } 5642 }
5644 targetTypeName = targetType == null ? null : targetType.displayName; 5643 targetTypeName = targetType == null ? null : targetType.displayName;
5645 ErrorCode proxyErrorCode = (generatedWithTypePropagation ? HintCode.UNDE FINED_METHOD : StaticTypeWarningCode.UNDEFINED_METHOD) as ErrorCode; 5644 ErrorCode proxyErrorCode = (generatedWithTypePropagation ? HintCode.UNDE FINED_METHOD : StaticTypeWarningCode.UNDEFINED_METHOD) as ErrorCode;
5646 _resolver.reportErrorProxyConditionalAnalysisError(targetType.element, p roxyErrorCode, methodName, [methodName.name, targetTypeName]); 5645 _resolver.reportErrorProxyConditionalAnalysisError(targetType.element, p roxyErrorCode, methodName, [methodName.name, targetTypeName]);
5647 } 5646 }
5648 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_SUPER_METHOD )) { 5647 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_SUPER_METHOD )) {
5649 // Generate the type name. 5648 // Generate the type name.
5650 // The error code will never be generated via type propagation 5649 // The error code will never be generated via type propagation
5651 Type2 targetType = getStaticType(target); 5650 Type2 targetType = getStaticType(target);
5652 String targetTypeName = targetType == null ? null : targetType.name; 5651 String targetTypeName = targetType == null ? null : targetType.name;
5653 _resolver.reportError8(StaticTypeWarningCode.UNDEFINED_SUPER_METHOD, metho dName, [methodName.name, targetTypeName]); 5652 _resolver.reportError9(StaticTypeWarningCode.UNDEFINED_SUPER_METHOD, metho dName, [methodName.name, targetTypeName]);
5654 } 5653 }
5655 return null; 5654 return null;
5656 } 5655 }
5657 5656
5658 Object visitPartDirective(PartDirective node) { 5657 Object visitPartDirective(PartDirective node) {
5659 setMetadata(node.element, node); 5658 setMetadata(node.element, node);
5660 return null; 5659 return null;
5661 } 5660 }
5662 5661
5663 Object visitPartOfDirective(PartOfDirective node) { 5662 Object visitPartOfDirective(PartOfDirective node) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
5701 // First, check to see whether the prefix is really a prefix. 5700 // First, check to see whether the prefix is really a prefix.
5702 // 5701 //
5703 Element prefixElement = prefix.staticElement; 5702 Element prefixElement = prefix.staticElement;
5704 if (prefixElement is PrefixElement) { 5703 if (prefixElement is PrefixElement) {
5705 Element element = _resolver.nameScope.lookup(node, _definingLibrary); 5704 Element element = _resolver.nameScope.lookup(node, _definingLibrary);
5706 if (element == null && identifier.inSetterContext()) { 5705 if (element == null && identifier.inSetterContext()) {
5707 element = _resolver.nameScope.lookup(new ElementResolver_SyntheticIdenti fier("${node.name}="), _definingLibrary); 5706 element = _resolver.nameScope.lookup(new ElementResolver_SyntheticIdenti fier("${node.name}="), _definingLibrary);
5708 } 5707 }
5709 if (element == null) { 5708 if (element == null) {
5710 if (identifier.inSetterContext()) { 5709 if (identifier.inSetterContext()) {
5711 _resolver.reportError8(StaticWarningCode.UNDEFINED_SETTER, identifier, [identifier.name, prefixElement.name]); 5710 _resolver.reportError9(StaticWarningCode.UNDEFINED_SETTER, identifier, [identifier.name, prefixElement.name]);
5712 } else if (node.parent is Annotation) { 5711 } else if (node.parent is Annotation) {
5713 Annotation annotation = node.parent as Annotation; 5712 Annotation annotation = node.parent as Annotation;
5714 _resolver.reportError8(CompileTimeErrorCode.INVALID_ANNOTATION, annota tion, []); 5713 _resolver.reportError9(CompileTimeErrorCode.INVALID_ANNOTATION, annota tion, []);
5715 return null; 5714 return null;
5716 } else { 5715 } else {
5717 _resolver.reportError8(StaticWarningCode.UNDEFINED_GETTER, identifier, [identifier.name, prefixElement.name]); 5716 _resolver.reportError9(StaticWarningCode.UNDEFINED_GETTER, identifier, [identifier.name, prefixElement.name]);
5718 } 5717 }
5719 return null; 5718 return null;
5720 } 5719 }
5721 if (element is PropertyAccessorElement && identifier.inSetterContext()) { 5720 if (element is PropertyAccessorElement && identifier.inSetterContext()) {
5722 PropertyInducingElement variable = (element as PropertyAccessorElement). variable; 5721 PropertyInducingElement variable = (element as PropertyAccessorElement). variable;
5723 if (variable != null) { 5722 if (variable != null) {
5724 PropertyAccessorElement setter = variable.setter; 5723 PropertyAccessorElement setter = variable.setter;
5725 if (setter != null) { 5724 if (setter != null) {
5726 element = setter; 5725 element = setter;
5727 } 5726 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
5849 node.staticElement = _dynamicType.element; 5848 node.staticElement = _dynamicType.element;
5850 node.staticType = _typeType; 5849 node.staticType = _typeType;
5851 return null; 5850 return null;
5852 } 5851 }
5853 // 5852 //
5854 // Otherwise, the node should be resolved. 5853 // Otherwise, the node should be resolved.
5855 // 5854 //
5856 Element element = resolveSimpleIdentifier(node); 5855 Element element = resolveSimpleIdentifier(node);
5857 ClassElement enclosingClass = _resolver.enclosingClass; 5856 ClassElement enclosingClass = _resolver.enclosingClass;
5858 if (isFactoryConstructorReturnType(node) && element != enclosingClass) { 5857 if (isFactoryConstructorReturnType(node) && element != enclosingClass) {
5859 _resolver.reportError8(CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLA SS, node, []); 5858 _resolver.reportError9(CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLA SS, node, []);
5860 } else if (isConstructorReturnType(node) && element != enclosingClass) { 5859 } else if (isConstructorReturnType(node) && element != enclosingClass) {
5861 _resolver.reportError8(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, node , []); 5860 _resolver.reportError9(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, node , []);
5862 element = null; 5861 element = null;
5863 } else if (element == null || (element is PrefixElement && !isValidAsPrefix( node))) { 5862 } else if (element == null || (element is PrefixElement && !isValidAsPrefix( node))) {
5864 // TODO(brianwilkerson) Recover from this error. 5863 // TODO(brianwilkerson) Recover from this error.
5865 if (isConstructorReturnType(node)) { 5864 if (isConstructorReturnType(node)) {
5866 _resolver.reportError8(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, no de, []); 5865 _resolver.reportError9(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, no de, []);
5867 } else if (node.parent is Annotation) { 5866 } else if (node.parent is Annotation) {
5868 Annotation annotation = node.parent as Annotation; 5867 Annotation annotation = node.parent as Annotation;
5869 _resolver.reportError8(CompileTimeErrorCode.INVALID_ANNOTATION, annotati on, []); 5868 _resolver.reportError9(CompileTimeErrorCode.INVALID_ANNOTATION, annotati on, []);
5870 } else { 5869 } else {
5871 _resolver.reportErrorProxyConditionalAnalysisError(_resolver.enclosingCl ass, StaticWarningCode.UNDEFINED_IDENTIFIER, node, [node.name]); 5870 _resolver.reportErrorProxyConditionalAnalysisError(_resolver.enclosingCl ass, StaticWarningCode.UNDEFINED_IDENTIFIER, node, [node.name]);
5872 } 5871 }
5873 } 5872 }
5874 node.staticElement = element; 5873 node.staticElement = element;
5875 if (node.inSetterContext() && node.inGetterContext() && enclosingClass != nu ll) { 5874 if (node.inSetterContext() && node.inGetterContext() && enclosingClass != nu ll) {
5876 InterfaceType enclosingType = enclosingClass.type; 5875 InterfaceType enclosingType = enclosingClass.type;
5877 AuxiliaryElements auxiliaryElements = new AuxiliaryElements(lookUpGetter(n ull, enclosingType, node.name), null); 5876 AuxiliaryElements auxiliaryElements = new AuxiliaryElements(lookUpGetter(n ull, enclosingType, node.name), null);
5878 node.auxiliaryElements = auxiliaryElements; 5877 node.auxiliaryElements = auxiliaryElements;
5879 } 5878 }
(...skipping 16 matching lines...) Expand all
5896 InterfaceType superType = enclosingClass.supertype; 5895 InterfaceType superType = enclosingClass.supertype;
5897 if (superType == null) { 5896 if (superType == null) {
5898 // TODO(brianwilkerson) Report this error. 5897 // TODO(brianwilkerson) Report this error.
5899 return null; 5898 return null;
5900 } 5899 }
5901 SimpleIdentifier name = node.constructorName; 5900 SimpleIdentifier name = node.constructorName;
5902 String superName = name != null ? name.name : null; 5901 String superName = name != null ? name.name : null;
5903 ConstructorElement element = superType.lookUpConstructor(superName, _definin gLibrary); 5902 ConstructorElement element = superType.lookUpConstructor(superName, _definin gLibrary);
5904 if (element == null) { 5903 if (element == null) {
5905 if (name != null) { 5904 if (name != null) {
5906 _resolver.reportError8(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INI TIALIZER, node, [superType.displayName, name]); 5905 _resolver.reportError9(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INI TIALIZER, node, [superType.displayName, name]);
5907 } else { 5906 } else {
5908 _resolver.reportError8(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INI TIALIZER_DEFAULT, node, [superType.displayName]); 5907 _resolver.reportError9(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INI TIALIZER_DEFAULT, node, [superType.displayName]);
5909 } 5908 }
5910 return null; 5909 return null;
5911 } else { 5910 } else {
5912 if (element.isFactory) { 5911 if (element.isFactory) {
5913 _resolver.reportError8(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, node, [element]); 5912 _resolver.reportError9(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, node, [element]);
5914 } 5913 }
5915 } 5914 }
5916 if (name != null) { 5915 if (name != null) {
5917 name.staticElement = element; 5916 name.staticElement = element;
5918 } 5917 }
5919 node.staticElement = element; 5918 node.staticElement = element;
5920 ArgumentList argumentList = node.argumentList; 5919 ArgumentList argumentList = node.argumentList;
5921 List<ParameterElement> parameters = resolveArgumentsToParameters(isInConstCo nstructor, argumentList, element); 5920 List<ParameterElement> parameters = resolveArgumentsToParameters(isInConstCo nstructor, argumentList, element);
5922 if (parameters != null) { 5921 if (parameters != null) {
5923 argumentList.correspondingStaticParameters = parameters; 5922 argumentList.correspondingStaticParameters = parameters;
5924 } 5923 }
5925 return null; 5924 return null;
5926 } 5925 }
5927 5926
5928 Object visitSuperExpression(SuperExpression node) { 5927 Object visitSuperExpression(SuperExpression node) {
5929 if (!isSuperInValidContext(node)) { 5928 if (!isSuperInValidContext(node)) {
5930 _resolver.reportError8(CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT, node , []); 5929 _resolver.reportError9(CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT, node , []);
5931 } 5930 }
5932 return super.visitSuperExpression(node); 5931 return super.visitSuperExpression(node);
5933 } 5932 }
5934 5933
5935 Object visitTypeParameter(TypeParameter node) { 5934 Object visitTypeParameter(TypeParameter node) {
5936 setMetadata(node.element, node); 5935 setMetadata(node.element, node);
5937 return null; 5936 return null;
5938 } 5937 }
5939 5938
5940 Object visitVariableDeclaration(VariableDeclaration node) { 5939 Object visitVariableDeclaration(VariableDeclaration node) {
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
6476 if (labelElement == null) { 6475 if (labelElement == null) {
6477 } 6476 }
6478 // 6477 //
6479 // The label element that was returned was a marker for look-up and isn' t stored in the 6478 // The label element that was returned was a marker for look-up and isn' t stored in the
6480 // element model. 6479 // element model.
6481 // 6480 //
6482 labelElement = null; 6481 labelElement = null;
6483 } 6482 }
6484 } else { 6483 } else {
6485 if (labelScope == null) { 6484 if (labelScope == null) {
6486 _resolver.reportError8(CompileTimeErrorCode.LABEL_UNDEFINED, labelNode, [labelNode.name]); 6485 _resolver.reportError9(CompileTimeErrorCode.LABEL_UNDEFINED, labelNode, [labelNode.name]);
6487 } else { 6486 } else {
6488 labelElement = labelScope.lookup(labelNode) as LabelElementImpl; 6487 labelElement = labelScope.lookup(labelNode) as LabelElementImpl;
6489 if (labelElement == null) { 6488 if (labelElement == null) {
6490 _resolver.reportError8(CompileTimeErrorCode.LABEL_UNDEFINED, labelNode , [labelNode.name]); 6489 _resolver.reportError9(CompileTimeErrorCode.LABEL_UNDEFINED, labelNode , [labelNode.name]);
6491 } else { 6490 } else {
6492 labelNode.staticElement = labelElement; 6491 labelNode.staticElement = labelElement;
6493 } 6492 }
6494 } 6493 }
6495 } 6494 }
6496 if (labelElement != null) { 6495 if (labelElement != null) {
6497 ExecutableElement labelContainer = labelElement.getAncestor(ExecutableElem ent); 6496 ExecutableElement labelContainer = labelElement.getAncestor(ExecutableElem ent);
6498 if (labelContainer != _resolver.enclosingFunction) { 6497 if (labelContainer != _resolver.enclosingFunction) {
6499 _resolver.reportError8(CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE, labelN ode, [labelNode.name]); 6498 _resolver.reportError9(CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE, labelN ode, [labelNode.name]);
6500 labelElement = null; 6499 labelElement = null;
6501 } 6500 }
6502 } 6501 }
6503 return labelElement; 6502 return labelElement;
6504 } 6503 }
6505 6504
6506 /** 6505 /**
6507 * Look up the method with the given name in the given type. Return the elemen t representing the 6506 * Look up the method with the given name in the given type. Return the elemen t representing the
6508 * method that was found, or `null` if there is no method with the given name. 6507 * method that was found, or `null` if there is no method with the given name.
6509 * 6508 *
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
6814 resolveAnnotationElementGetter(annotation, getter); 6813 resolveAnnotationElementGetter(annotation, getter);
6815 return; 6814 return;
6816 } 6815 }
6817 // prefix.Class.constructor(args) 6816 // prefix.Class.constructor(args)
6818 constructor = new InterfaceTypeImpl.con1(classElement).lookUpConstructor (name3, _definingLibrary); 6817 constructor = new InterfaceTypeImpl.con1(classElement).lookUpConstructor (name3, _definingLibrary);
6819 nameNode3.staticElement = constructor; 6818 nameNode3.staticElement = constructor;
6820 } 6819 }
6821 } 6820 }
6822 // we need constructor 6821 // we need constructor
6823 if (constructor == null) { 6822 if (constructor == null) {
6824 _resolver.reportError8(CompileTimeErrorCode.INVALID_ANNOTATION, annotation , []); 6823 _resolver.reportError9(CompileTimeErrorCode.INVALID_ANNOTATION, annotation , []);
6825 return; 6824 return;
6826 } 6825 }
6827 // record element 6826 // record element
6828 annotation.element = constructor; 6827 annotation.element = constructor;
6829 // resolve arguments 6828 // resolve arguments
6830 resolveAnnotationConstructorInvocationArguments(annotation, constructor); 6829 resolveAnnotationConstructorInvocationArguments(annotation, constructor);
6831 } 6830 }
6832 6831
6833 void resolveAnnotationElementGetter(Annotation annotation, PropertyAccessorEle ment accessorElement) { 6832 void resolveAnnotationElementGetter(Annotation annotation, PropertyAccessorEle ment accessorElement) {
6834 // accessor should be synthetic 6833 // accessor should be synthetic
6835 if (!accessorElement.isSynthetic) { 6834 if (!accessorElement.isSynthetic) {
6836 _resolver.reportError8(CompileTimeErrorCode.INVALID_ANNOTATION, annotation , []); 6835 _resolver.reportError9(CompileTimeErrorCode.INVALID_ANNOTATION, annotation , []);
6837 return; 6836 return;
6838 } 6837 }
6839 // variable should be constant 6838 // variable should be constant
6840 VariableElement variableElement = accessorElement.variable; 6839 VariableElement variableElement = accessorElement.variable;
6841 if (!variableElement.isConst) { 6840 if (!variableElement.isConst) {
6842 _resolver.reportError8(CompileTimeErrorCode.INVALID_ANNOTATION, annotation , []); 6841 _resolver.reportError9(CompileTimeErrorCode.INVALID_ANNOTATION, annotation , []);
6843 } 6842 }
6844 // OK 6843 // OK
6845 return; 6844 return;
6846 } 6845 }
6847 6846
6848 /** 6847 /**
6849 * Given a list of arguments and the element that will be invoked using those argument, compute 6848 * Given a list of arguments and the element that will be invoked using those argument, compute
6850 * the list of parameters that correspond to the list of arguments. Return the parameters that 6849 * the list of parameters that correspond to the list of arguments. Return the parameters that
6851 * correspond to the arguments, or `null` if no correspondence could be comput ed. 6850 * correspond to the arguments, or `null` if no correspondence could be comput ed.
6852 * 6851 *
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
6899 int positionalArgumentCount = 0; 6898 int positionalArgumentCount = 0;
6900 Set<String> usedNames = new Set<String>(); 6899 Set<String> usedNames = new Set<String>();
6901 for (int i = 0; i < argumentCount; i++) { 6900 for (int i = 0; i < argumentCount; i++) {
6902 Expression argument = arguments[i]; 6901 Expression argument = arguments[i];
6903 if (argument is NamedExpression) { 6902 if (argument is NamedExpression) {
6904 SimpleIdentifier nameNode = argument.name.label; 6903 SimpleIdentifier nameNode = argument.name.label;
6905 String name = nameNode.name; 6904 String name = nameNode.name;
6906 ParameterElement element = namedParameters[name]; 6905 ParameterElement element = namedParameters[name];
6907 if (element == null) { 6906 if (element == null) {
6908 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.UNDEFINED_NA MED_PARAMETER : StaticWarningCode.UNDEFINED_NAMED_PARAMETER) as ErrorCode; 6907 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.UNDEFINED_NA MED_PARAMETER : StaticWarningCode.UNDEFINED_NAMED_PARAMETER) as ErrorCode;
6909 _resolver.reportError8(errorCode, nameNode, [name]); 6908 _resolver.reportError9(errorCode, nameNode, [name]);
6910 } else { 6909 } else {
6911 resolvedParameters[i] = element; 6910 resolvedParameters[i] = element;
6912 nameNode.staticElement = element; 6911 nameNode.staticElement = element;
6913 } 6912 }
6914 if (!usedNames.add(name)) { 6913 if (!usedNames.add(name)) {
6915 _resolver.reportError8(CompileTimeErrorCode.DUPLICATE_NAMED_ARGUMENT, nameNode, [name]); 6914 _resolver.reportError9(CompileTimeErrorCode.DUPLICATE_NAMED_ARGUMENT, nameNode, [name]);
6916 } 6915 }
6917 } else { 6916 } else {
6918 positionalArgumentCount++; 6917 positionalArgumentCount++;
6919 if (unnamedIndex < unnamedParameterCount) { 6918 if (unnamedIndex < unnamedParameterCount) {
6920 resolvedParameters[i] = unnamedParameters[unnamedIndex++]; 6919 resolvedParameters[i] = unnamedParameters[unnamedIndex++];
6921 } 6920 }
6922 } 6921 }
6923 } 6922 }
6924 if (positionalArgumentCount < requiredParameters.length) { 6923 if (positionalArgumentCount < requiredParameters.length) {
6925 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.NOT_ENOUGH_REQUI RED_ARGUMENTS : StaticWarningCode.NOT_ENOUGH_REQUIRED_ARGUMENTS) as ErrorCode; 6924 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.NOT_ENOUGH_REQUI RED_ARGUMENTS : StaticWarningCode.NOT_ENOUGH_REQUIRED_ARGUMENTS) as ErrorCode;
6926 _resolver.reportError8(errorCode, argumentList, [requiredParameters.length , positionalArgumentCount]); 6925 _resolver.reportError9(errorCode, argumentList, [requiredParameters.length , positionalArgumentCount]);
6927 } else if (positionalArgumentCount > unnamedParameterCount) { 6926 } else if (positionalArgumentCount > unnamedParameterCount) {
6928 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.EXTRA_POSITIONAL _ARGUMENTS : StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS) as ErrorCode; 6927 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.EXTRA_POSITIONAL _ARGUMENTS : StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS) as ErrorCode;
6929 _resolver.reportError8(errorCode, argumentList, [unnamedParameterCount, po sitionalArgumentCount]); 6928 _resolver.reportError9(errorCode, argumentList, [unnamedParameterCount, po sitionalArgumentCount]);
6930 } 6929 }
6931 return resolvedParameters; 6930 return resolvedParameters;
6932 } 6931 }
6933 6932
6934 /** 6933 /**
6935 * Resolve the names in the given combinators in the scope of the given librar y. 6934 * Resolve the names in the given combinators in the scope of the given librar y.
6936 * 6935 *
6937 * @param library the library that defines the names 6936 * @param library the library that defines the names
6938 * @param combinators the combinators containing the names to be resolved 6937 * @param combinators the combinators containing the names to be resolved
6939 */ 6938 */
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
7116 bool shouldReportMissingMember_static = shouldReportMissingMember(staticType , staticElement); 7115 bool shouldReportMissingMember_static = shouldReportMissingMember(staticType , staticElement);
7117 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_stati c && _enableHints ? shouldReportMissingMember(propagatedType, propagatedElement) : false; 7116 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_stati c && _enableHints ? shouldReportMissingMember(propagatedType, propagatedElement) : false;
7118 // If we are about to generate the hint (propagated version of this warning) , then check 7117 // If we are about to generate the hint (propagated version of this warning) , then check
7119 // that the member is not in a subtype of the propagated type. 7118 // that the member is not in a subtype of the propagated type.
7120 if (shouldReportMissingMember_propagated) { 7119 if (shouldReportMissingMember_propagated) {
7121 if (memberFoundInSubclass(propagatedType.element, propertyName.name, false , true)) { 7120 if (memberFoundInSubclass(propagatedType.element, propertyName.name, false , true)) {
7122 shouldReportMissingMember_propagated = false; 7121 shouldReportMissingMember_propagated = false;
7123 } 7122 }
7124 } 7123 }
7125 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) { 7124 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) {
7125 if (staticType.isVoid) {
7126 if (propertyName.inSetterContext()) {
7127 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_SETTER : HintCode.UNDEFINED_SETTER) as ErrorCode;
7128 _resolver.reportError9(errorCode, propertyName, [propertyName.name, st aticType.displayName]);
7129 } else if (propertyName.inGetterContext()) {
7130 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_GETTER : HintCode.UNDEFINED_GETTER) as ErrorCode;
7131 _resolver.reportError9(errorCode, propertyName, [propertyName.name, st aticType.displayName]);
7132 } else {
7133 _resolver.reportError9(StaticWarningCode.UNDEFINED_IDENTIFIER, propert yName, [propertyName.name]);
7134 }
7135 }
7126 Element staticOrPropagatedEnclosingElt = shouldReportMissingMember_static ? staticType.element : propagatedType.element; 7136 Element staticOrPropagatedEnclosingElt = shouldReportMissingMember_static ? staticType.element : propagatedType.element;
7127 if (staticOrPropagatedEnclosingElt != null) { 7137 if (staticOrPropagatedEnclosingElt != null) {
7128 bool isStaticProperty = isStatic(staticOrPropagatedEnclosingElt); 7138 bool isStaticProperty = isStatic(staticOrPropagatedEnclosingElt);
7129 if (propertyName.inSetterContext()) { 7139 if (propertyName.inSetterContext()) {
7130 if (isStaticProperty) { 7140 if (isStaticProperty) {
7131 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticWarn ingCode.UNDEFINED_SETTER : HintCode.UNDEFINED_SETTER) as ErrorCode; 7141 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticWarn ingCode.UNDEFINED_SETTER : HintCode.UNDEFINED_SETTER) as ErrorCode;
7132 _resolver.reportErrorProxyConditionalAnalysisError(staticOrPropagate dEnclosingElt, errorCode, propertyName, [ 7142 _resolver.reportErrorProxyConditionalAnalysisError(staticOrPropagate dEnclosingElt, errorCode, propertyName, [
7133 propertyName.name, 7143 propertyName.name,
7134 staticOrPropagatedEnclosingElt.displayName]); 7144 staticOrPropagatedEnclosingElt.displayName]);
7135 } else { 7145 } else {
(...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after
8091 * AST structures. 8101 * AST structures.
8092 */ 8102 */
8093 Map<Source, ResolvableCompilationUnit> _astMap = new Map<Source, ResolvableCom pilationUnit>(); 8103 Map<Source, ResolvableCompilationUnit> _astMap = new Map<Source, ResolvableCom pilationUnit>();
8094 8104
8095 /** 8105 /**
8096 * The library scope used when resolving elements within this library's compil ation units. 8106 * The library scope used when resolving elements within this library's compil ation units.
8097 */ 8107 */
8098 LibraryScope _libraryScope; 8108 LibraryScope _libraryScope;
8099 8109
8100 /** 8110 /**
8101 * An array of all top-level Angular elements that could be used in this libra ry.
8102 */
8103 List<AngularElement> angularElements;
8104
8105 /**
8106 * An empty array that can be used to initialize lists of libraries. 8111 * An empty array that can be used to initialize lists of libraries.
8107 */ 8112 */
8108 static List<Library> _EMPTY_ARRAY = new List<Library>(0); 8113 static List<Library> _EMPTY_ARRAY = new List<Library>(0);
8109 8114
8110 /** 8115 /**
8111 * The prefix of a URI using the dart-ext scheme to reference a native code li brary. 8116 * The prefix of a URI using the dart-ext scheme to reference a native code li brary.
8112 */ 8117 */
8113 static String _DART_EXT_SCHEME = "dart-ext:"; 8118 static String _DART_EXT_SCHEME = "dart-ext:";
8114 8119
8115 /** 8120 /**
(...skipping 1119 matching lines...) Expand 10 before | Expand all | Expand 10 after
9235 } 9240 }
9236 } 9241 }
9237 } finally { 9242 } finally {
9238 timeCounter.stop(); 9243 timeCounter.stop();
9239 } 9244 }
9240 // Angular 9245 // Angular
9241 timeCounter = PerformanceStatistics.angular.start(); 9246 timeCounter = PerformanceStatistics.angular.start();
9242 try { 9247 try {
9243 for (Source source in library.compilationUnitSources) { 9248 for (Source source in library.compilationUnitSources) {
9244 CompilationUnit ast = library.getAST(source); 9249 CompilationUnit ast = library.getAST(source);
9245 new AngularCompilationUnitBuilder(analysisContext, _errorListener, sourc e).build(ast); 9250 new AngularCompilationUnitBuilder(_errorListener, source).build(ast);
9246 } 9251 }
9247 // remember accessible Angular elements
9248 LibraryElementImpl libraryElement = library.libraryElement;
9249 library.angularElements = AngularCompilationUnitBuilder.getAngularElements (libraryElement);
9250 } finally { 9252 } finally {
9251 timeCounter.stop(); 9253 timeCounter.stop();
9252 } 9254 }
9253 } 9255 }
9254 9256
9255 /** 9257 /**
9256 * Return the result of resolving the URI of the given URI-based directive aga inst the URI of the 9258 * Return the result of resolving the URI of the given URI-based directive aga inst the URI of the
9257 * given library, or `null` if the URI is not valid. 9259 * given library, or `null` if the URI is not valid.
9258 * 9260 *
9259 * @param librarySource the source representing the library containing the dir ective 9261 * @param librarySource the source representing the library containing the dir ective
(...skipping 1890 matching lines...) Expand 10 before | Expand all | Expand 10 after
11150 */ 11152 */
11151 Scope get nameScope => _nameScope; 11153 Scope get nameScope => _nameScope;
11152 11154
11153 /** 11155 /**
11154 * Report an error with the given error code and arguments. 11156 * Report an error with the given error code and arguments.
11155 * 11157 *
11156 * @param errorCode the error code of the error to be reported 11158 * @param errorCode the error code of the error to be reported
11157 * @param node the node specifying the location of the error 11159 * @param node the node specifying the location of the error
11158 * @param arguments the arguments to the error, used to compose the error mess age 11160 * @param arguments the arguments to the error, used to compose the error mess age
11159 */ 11161 */
11160 void reportError8(ErrorCode errorCode, ASTNode node, List<Object> arguments) { 11162 void reportError9(ErrorCode errorCode, ASTNode node, List<Object> arguments) {
11161 _errorListener.onError(new AnalysisError.con2(source, node.offset, node.leng th, errorCode, arguments)); 11163 _errorListener.onError(new AnalysisError.con2(source, node.offset, node.leng th, errorCode, arguments));
11162 } 11164 }
11163 11165
11164 /** 11166 /**
11165 * Report an error with the given error code and arguments. 11167 * Report an error with the given error code and arguments.
11166 * 11168 *
11167 * @param errorCode the error code of the error to be reported 11169 * @param errorCode the error code of the error to be reported
11168 * @param offset the offset of the location of the error 11170 * @param offset the offset of the location of the error
11169 * @param length the length of the location of the error 11171 * @param length the length of the location of the error
11170 * @param arguments the arguments to the error, used to compose the error mess age 11172 * @param arguments the arguments to the error, used to compose the error mess age
11171 */ 11173 */
11172 void reportError9(ErrorCode errorCode, int offset, int length, List<Object> ar guments) { 11174 void reportError10(ErrorCode errorCode, int offset, int length, List<Object> a rguments) {
11173 _errorListener.onError(new AnalysisError.con2(source, offset, length, errorC ode, arguments)); 11175 _errorListener.onError(new AnalysisError.con2(source, offset, length, errorC ode, arguments));
11174 } 11176 }
11175 11177
11176 /** 11178 /**
11177 * Report an error with the given error code and arguments. 11179 * Report an error with the given error code and arguments.
11178 * 11180 *
11179 * @param errorCode the error code of the error to be reported 11181 * @param errorCode the error code of the error to be reported
11180 * @param token the token specifying the location of the error 11182 * @param token the token specifying the location of the error
11181 * @param arguments the arguments to the error, used to compose the error mess age 11183 * @param arguments the arguments to the error, used to compose the error mess age
11182 */ 11184 */
11183 void reportError10(ErrorCode errorCode, sc.Token token, List<Object> arguments ) { 11185 void reportError11(ErrorCode errorCode, sc.Token token, List<Object> arguments ) {
11184 _errorListener.onError(new AnalysisError.con2(source, token.offset, token.le ngth, errorCode, arguments)); 11186 _errorListener.onError(new AnalysisError.con2(source, token.offset, token.le ngth, errorCode, arguments));
11185 } 11187 }
11186 11188
11187 /** 11189 /**
11188 * Visit the given AST node if it is not null. 11190 * Visit the given AST node if it is not null.
11189 * 11191 *
11190 * @param node the node to be visited 11192 * @param node the node to be visited
11191 */ 11193 */
11192 void safelyVisit(ASTNode node) { 11194 void safelyVisit(ASTNode node) {
11193 if (node != null) { 11195 if (node != null) {
(...skipping 1121 matching lines...) Expand 10 before | Expand all | Expand 10 after
12315 * The static type of <i>i</i> is the declared return type of <i>C.m</i> if it exists or dynamic 12317 * The static type of <i>i</i> is the declared return type of <i>C.m</i> if it exists or dynamic
12316 * otherwise. 12318 * otherwise.
12317 * 12319 *
12318 * ... a top-level getter invocation <i>i</i> of the form <i>m</i>, where <i>m </i> is an 12320 * ... a top-level getter invocation <i>i</i> of the form <i>m</i>, where <i>m </i> is an
12319 * identifier ... 12321 * identifier ...
12320 * 12322 *
12321 * The static type of <i>i</i> is the declared return type of <i>m</i>.</block quote> 12323 * The static type of <i>i</i> is the declared return type of <i>m</i>.</block quote>
12322 */ 12324 */
12323 Object visitPropertyAccess(PropertyAccess node) { 12325 Object visitPropertyAccess(PropertyAccess node) {
12324 SimpleIdentifier propertyName = node.propertyName; 12326 SimpleIdentifier propertyName = node.propertyName;
12325 Element element = propertyName.staticElement; 12327 Element staticElement = propertyName.staticElement;
12326 Type2 staticType = _dynamicType; 12328 Type2 staticType = _dynamicType;
12327 if (element is MethodElement) { 12329 if (staticElement is MethodElement) {
12328 staticType = element.type; 12330 staticType = staticElement.type;
12329 } else if (element is PropertyAccessorElement) { 12331 } else if (staticElement is PropertyAccessorElement) {
12330 staticType = getType(element, node.target != null ? getStaticType(node.tar get) : null); 12332 Expression realTarget = node.realTarget;
12333 staticType = getType(staticElement, realTarget != null ? getStaticType(rea lTarget) : null);
12331 } else { 12334 } else {
12332 } 12335 }
12333 recordStaticType(propertyName, staticType); 12336 recordStaticType(propertyName, staticType);
12334 recordStaticType(node, staticType); 12337 recordStaticType(node, staticType);
12335 // TODO(brianwilkerson) I think we want to repeat the logic above using the propagated element 12338 Element propagatedElement = propertyName.propagatedElement;
12336 // to get another candidate for the propagated type. 12339 Type2 propagatedType = _overrideManager.getType(propagatedElement);
12337 Type2 propagatedType = _overrideManager.getType(element); 12340 if (propagatedElement is MethodElement) {
12341 propagatedType = propagatedElement.type;
12342 } else if (propagatedElement is PropertyAccessorElement) {
12343 Expression realTarget = node.realTarget;
12344 propagatedType = getType(propagatedElement, realTarget != null ? realTarge t.bestType : null);
12345 } else {
12346 }
12338 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType)) { 12347 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType)) {
12348 recordPropagatedType2(propertyName, propagatedType);
12339 recordPropagatedType2(node, propagatedType); 12349 recordPropagatedType2(node, propagatedType);
12340 } 12350 }
12341 return null; 12351 return null;
12342 } 12352 }
12343 12353
12344 /** 12354 /**
12345 * The Dart Language Specification, 12.9: <blockquote>The static type of a ret hrow expression is 12355 * The Dart Language Specification, 12.9: <blockquote>The static type of a ret hrow expression is
12346 * bottom.</blockquote> 12356 * bottom.</blockquote>
12347 */ 12357 */
12348 Object visitRethrowExpression(RethrowExpression node) { 12358 Object visitRethrowExpression(RethrowExpression node) {
(...skipping 1700 matching lines...) Expand 10 before | Expand all | Expand 10 after
14049 if (typeName is PrefixedIdentifier && parent is ConstructorName && argumen tList == null) { 14059 if (typeName is PrefixedIdentifier && parent is ConstructorName && argumen tList == null) {
14050 ConstructorName name = parent; 14060 ConstructorName name = parent;
14051 if (name.name == null) { 14061 if (name.name == null) {
14052 PrefixedIdentifier prefixedIdentifier = typeName as PrefixedIdentifier ; 14062 PrefixedIdentifier prefixedIdentifier = typeName as PrefixedIdentifier ;
14053 SimpleIdentifier prefix = prefixedIdentifier.prefix; 14063 SimpleIdentifier prefix = prefixedIdentifier.prefix;
14054 element = nameScope.lookup(prefix, definingLibrary); 14064 element = nameScope.lookup(prefix, definingLibrary);
14055 if (element is PrefixElement) { 14065 if (element is PrefixElement) {
14056 if (parent.parent is InstanceCreationExpression && (parent.parent as InstanceCreationExpression).isConst) { 14066 if (parent.parent is InstanceCreationExpression && (parent.parent as InstanceCreationExpression).isConst) {
14057 // If, if this is a const expression, then generate a 14067 // If, if this is a const expression, then generate a
14058 // CompileTimeErrorCode.CONST_WITH_NON_TYPE error. 14068 // CompileTimeErrorCode.CONST_WITH_NON_TYPE error.
14059 reportError8(CompileTimeErrorCode.CONST_WITH_NON_TYPE, prefixedIde ntifier.identifier, [prefixedIdentifier.identifier.name]); 14069 reportError9(CompileTimeErrorCode.CONST_WITH_NON_TYPE, prefixedIde ntifier.identifier, [prefixedIdentifier.identifier.name]);
14060 } else { 14070 } else {
14061 // Else, if this expression is a new expression, report a NEW_WITH _NON_TYPE warning. 14071 // Else, if this expression is a new expression, report a NEW_WITH _NON_TYPE warning.
14062 reportError8(StaticWarningCode.NEW_WITH_NON_TYPE, prefixedIdentifi er.identifier, [prefixedIdentifier.identifier.name]); 14072 reportError9(StaticWarningCode.NEW_WITH_NON_TYPE, prefixedIdentifi er.identifier, [prefixedIdentifier.identifier.name]);
14063 } 14073 }
14064 setElement(prefix, element); 14074 setElement(prefix, element);
14065 return null; 14075 return null;
14066 } else if (element != null) { 14076 } else if (element != null) {
14067 // 14077 //
14068 // Rewrite the constructor name. The parser, when it sees a construc tor named "a.b", 14078 // Rewrite the constructor name. The parser, when it sees a construc tor named "a.b",
14069 // cannot tell whether "a" is a prefix and "b" is a class name, or w hether "a" is a 14079 // cannot tell whether "a" is a prefix and "b" is a class name, or w hether "a" is a
14070 // class name and "b" is a constructor name. It arbitrarily chooses the former, but 14080 // class name and "b" is a constructor name. It arbitrarily chooses the former, but
14071 // in this case was wrong. 14081 // in this case was wrong.
14072 // 14082 //
14073 name.name = prefixedIdentifier.identifier; 14083 name.name = prefixedIdentifier.identifier;
14074 name.period = prefixedIdentifier.period; 14084 name.period = prefixedIdentifier.period;
14075 node.name = prefix; 14085 node.name = prefix;
14076 typeName = prefix; 14086 typeName = prefix;
14077 } 14087 }
14078 } 14088 }
14079 } 14089 }
14080 } 14090 }
14081 // check element 14091 // check element
14082 bool elementValid = element is! MultiplyDefinedElement; 14092 bool elementValid = element is! MultiplyDefinedElement;
14083 if (elementValid && element is! ClassElement && isTypeNameInInstanceCreation Expression(node)) { 14093 if (elementValid && element is! ClassElement && isTypeNameInInstanceCreation Expression(node)) {
14084 SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName); 14094 SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName);
14085 InstanceCreationExpression creation = node.parent.parent as InstanceCreati onExpression; 14095 InstanceCreationExpression creation = node.parent.parent as InstanceCreati onExpression;
14086 if (creation.isConst) { 14096 if (creation.isConst) {
14087 if (element == null) { 14097 if (element == null) {
14088 reportError8(CompileTimeErrorCode.UNDEFINED_CLASS, typeNameSimple, [ty peName]); 14098 reportError9(CompileTimeErrorCode.UNDEFINED_CLASS, typeNameSimple, [ty peName]);
14089 } else { 14099 } else {
14090 reportError8(CompileTimeErrorCode.CONST_WITH_NON_TYPE, typeNameSimple, [typeName]); 14100 reportError9(CompileTimeErrorCode.CONST_WITH_NON_TYPE, typeNameSimple, [typeName]);
14091 } 14101 }
14092 elementValid = false; 14102 elementValid = false;
14093 } else { 14103 } else {
14094 if (element != null) { 14104 if (element != null) {
14095 reportError8(StaticWarningCode.NEW_WITH_NON_TYPE, typeNameSimple, [typ eName]); 14105 reportError9(StaticWarningCode.NEW_WITH_NON_TYPE, typeNameSimple, [typ eName]);
14096 elementValid = false; 14106 elementValid = false;
14097 } 14107 }
14098 } 14108 }
14099 } 14109 }
14100 if (elementValid && element == null) { 14110 if (elementValid && element == null) {
14101 // We couldn't resolve the type name. 14111 // We couldn't resolve the type name.
14102 // TODO(jwren) Consider moving the check for CompileTimeErrorCode.BUILT_IN _IDENTIFIER_AS_TYPE 14112 // TODO(jwren) Consider moving the check for CompileTimeErrorCode.BUILT_IN _IDENTIFIER_AS_TYPE
14103 // from the ErrorVerifier, so that we don't have two errors on a built in identifier being 14113 // from the ErrorVerifier, so that we don't have two errors on a built in identifier being
14104 // used as a class name. See CompileTimeErrorCodeTest.test_builtInIdentifi erAsType(). 14114 // used as a class name. See CompileTimeErrorCodeTest.test_builtInIdentifi erAsType().
14105 SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName); 14115 SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName);
14106 RedirectingConstructorKind redirectingConstructorKind; 14116 RedirectingConstructorKind redirectingConstructorKind;
14107 if (isBuiltInIdentifier(node) && isTypeAnnotation(node)) { 14117 if (isBuiltInIdentifier(node) && isTypeAnnotation(node)) {
14108 reportError8(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, typeName, [typeName.name]); 14118 reportError9(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, typeName, [typeName.name]);
14109 } else if (typeNameSimple.name == "boolean") { 14119 } else if (typeNameSimple.name == "boolean") {
14110 reportError8(StaticWarningCode.UNDEFINED_CLASS_BOOLEAN, typeNameSimple, []); 14120 reportError9(StaticWarningCode.UNDEFINED_CLASS_BOOLEAN, typeNameSimple, []);
14111 } else if (isTypeNameInCatchClause(node)) { 14121 } else if (isTypeNameInCatchClause(node)) {
14112 reportError8(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [type Name.name]); 14122 reportError9(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [type Name.name]);
14113 } else if (isTypeNameInAsExpression(node)) { 14123 } else if (isTypeNameInAsExpression(node)) {
14114 reportError8(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.nam e]); 14124 reportError9(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.nam e]);
14115 } else if (isTypeNameInIsExpression(node)) { 14125 } else if (isTypeNameInIsExpression(node)) {
14116 reportError8(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [typeName.n ame]); 14126 reportError9(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [typeName.n ame]);
14117 } else if ((redirectingConstructorKind = getRedirectingConstructorKind(nod e)) != null) { 14127 } else if ((redirectingConstructorKind = getRedirectingConstructorKind(nod e)) != null) {
14118 ErrorCode errorCode = (identical(redirectingConstructorKind, Redirecting ConstructorKind.CONST) ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS : StaticWarn ingCode.REDIRECT_TO_NON_CLASS) as ErrorCode; 14128 ErrorCode errorCode = (identical(redirectingConstructorKind, Redirecting ConstructorKind.CONST) ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS : StaticWarn ingCode.REDIRECT_TO_NON_CLASS) as ErrorCode;
14119 reportError8(errorCode, typeName, [typeName.name]); 14129 reportError9(errorCode, typeName, [typeName.name]);
14120 } else if (isTypeNameInTypeArgumentList(node)) { 14130 } else if (isTypeNameInTypeArgumentList(node)) {
14121 reportError8(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, typeName, [typeName.name]); 14131 reportError9(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, typeName, [typeName.name]);
14122 } else { 14132 } else {
14123 reportError8(StaticWarningCode.UNDEFINED_CLASS, typeName, [typeName.name ]); 14133 reportError9(StaticWarningCode.UNDEFINED_CLASS, typeName, [typeName.name ]);
14124 } 14134 }
14125 elementValid = false; 14135 elementValid = false;
14126 } 14136 }
14127 if (!elementValid) { 14137 if (!elementValid) {
14128 if (element is MultiplyDefinedElement) { 14138 if (element is MultiplyDefinedElement) {
14129 setElement(typeName, element); 14139 setElement(typeName, element);
14130 } else { 14140 } else {
14131 setElement(typeName, this._dynamicType.element); 14141 setElement(typeName, this._dynamicType.element);
14132 } 14142 }
14133 typeName.staticType = this._dynamicType; 14143 typeName.staticType = this._dynamicType;
(...skipping 15 matching lines...) Expand all
14149 } else if (element is MultiplyDefinedElement) { 14159 } else if (element is MultiplyDefinedElement) {
14150 List<Element> elements = (element as MultiplyDefinedElement).conflictingEl ements; 14160 List<Element> elements = (element as MultiplyDefinedElement).conflictingEl ements;
14151 type = getType(elements); 14161 type = getType(elements);
14152 if (type != null) { 14162 if (type != null) {
14153 node.type = type; 14163 node.type = type;
14154 } 14164 }
14155 } else { 14165 } else {
14156 // The name does not represent a type. 14166 // The name does not represent a type.
14157 RedirectingConstructorKind redirectingConstructorKind; 14167 RedirectingConstructorKind redirectingConstructorKind;
14158 if (isTypeNameInCatchClause(node)) { 14168 if (isTypeNameInCatchClause(node)) {
14159 reportError8(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [type Name.name]); 14169 reportError9(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [type Name.name]);
14160 } else if (isTypeNameInAsExpression(node)) { 14170 } else if (isTypeNameInAsExpression(node)) {
14161 reportError8(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.nam e]); 14171 reportError9(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.nam e]);
14162 } else if (isTypeNameInIsExpression(node)) { 14172 } else if (isTypeNameInIsExpression(node)) {
14163 reportError8(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [typeName.n ame]); 14173 reportError9(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [typeName.n ame]);
14164 } else if ((redirectingConstructorKind = getRedirectingConstructorKind(nod e)) != null) { 14174 } else if ((redirectingConstructorKind = getRedirectingConstructorKind(nod e)) != null) {
14165 ErrorCode errorCode = (identical(redirectingConstructorKind, Redirecting ConstructorKind.CONST) ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS : StaticWarn ingCode.REDIRECT_TO_NON_CLASS) as ErrorCode; 14175 ErrorCode errorCode = (identical(redirectingConstructorKind, Redirecting ConstructorKind.CONST) ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS : StaticWarn ingCode.REDIRECT_TO_NON_CLASS) as ErrorCode;
14166 reportError8(errorCode, typeName, [typeName.name]); 14176 reportError9(errorCode, typeName, [typeName.name]);
14167 } else if (isTypeNameInTypeArgumentList(node)) { 14177 } else if (isTypeNameInTypeArgumentList(node)) {
14168 reportError8(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, typeName, [typeName.name]); 14178 reportError9(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, typeName, [typeName.name]);
14169 } else { 14179 } else {
14170 ASTNode parent = typeName.parent; 14180 ASTNode parent = typeName.parent;
14171 while (parent is TypeName) { 14181 while (parent is TypeName) {
14172 parent = parent.parent; 14182 parent = parent.parent;
14173 } 14183 }
14174 if (parent is ExtendsClause || parent is ImplementsClause || parent is W ithClause || parent is ClassTypeAlias) { 14184 if (parent is ExtendsClause || parent is ImplementsClause || parent is W ithClause || parent is ClassTypeAlias) {
14175 } else { 14185 } else {
14176 reportError8(StaticWarningCode.NOT_A_TYPE, typeName, [typeName.name]); 14186 reportError9(StaticWarningCode.NOT_A_TYPE, typeName, [typeName.name]);
14177 } 14187 }
14178 } 14188 }
14179 setElement(typeName, this._dynamicType.element); 14189 setElement(typeName, this._dynamicType.element);
14180 typeName.staticType = this._dynamicType; 14190 typeName.staticType = this._dynamicType;
14181 node.type = this._dynamicType; 14191 node.type = this._dynamicType;
14182 return null; 14192 return null;
14183 } 14193 }
14184 if (argumentList != null) { 14194 if (argumentList != null) {
14185 NodeList<TypeName> arguments = argumentList.arguments; 14195 NodeList<TypeName> arguments = argumentList.arguments;
14186 int argumentCount = arguments.length; 14196 int argumentCount = arguments.length;
14187 List<Type2> parameters = getTypeArguments(type); 14197 List<Type2> parameters = getTypeArguments(type);
14188 int parameterCount = parameters.length; 14198 int parameterCount = parameters.length;
14189 int count = Math.min(argumentCount, parameterCount); 14199 int count = Math.min(argumentCount, parameterCount);
14190 List<Type2> typeArguments = new List<Type2>(); 14200 List<Type2> typeArguments = new List<Type2>();
14191 for (int i = 0; i < count; i++) { 14201 for (int i = 0; i < count; i++) {
14192 Type2 argumentType = getType3(arguments[i]); 14202 Type2 argumentType = getType3(arguments[i]);
14193 if (argumentType != null) { 14203 if (argumentType != null) {
14194 typeArguments.add(argumentType); 14204 typeArguments.add(argumentType);
14195 } 14205 }
14196 } 14206 }
14197 if (argumentCount != parameterCount) { 14207 if (argumentCount != parameterCount) {
14198 reportError8(getInvalidTypeParametersErrorCode(node), node, [typeName.na me, parameterCount, argumentCount]); 14208 reportError9(getInvalidTypeParametersErrorCode(node), node, [typeName.na me, parameterCount, argumentCount]);
14199 } 14209 }
14200 argumentCount = typeArguments.length; 14210 argumentCount = typeArguments.length;
14201 if (argumentCount < parameterCount) { 14211 if (argumentCount < parameterCount) {
14202 // 14212 //
14203 // If there were too many arguments, we already handled it by not adding the values of the 14213 // If there were too many arguments, we already handled it by not adding the values of the
14204 // extra arguments to the list. If there are too few, we handle it by ad ding 'dynamic' 14214 // extra arguments to the list. If there are too few, we handle it by ad ding 'dynamic'
14205 // enough times to make the count equal. 14215 // enough times to make the count equal.
14206 // 14216 //
14207 for (int i = argumentCount; i < parameterCount; i++) { 14217 for (int i = argumentCount; i < parameterCount; i++) {
14208 typeArguments.add(this._dynamicType); 14218 typeArguments.add(this._dynamicType);
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
14586 TypeName typeName = typeNames[i]; 14596 TypeName typeName = typeNames[i];
14587 if (!detectedRepeatOnIndex[i]) { 14597 if (!detectedRepeatOnIndex[i]) {
14588 Element element = typeName.name.staticElement; 14598 Element element = typeName.name.staticElement;
14589 for (int j = i + 1; j < typeNames.length; j++) { 14599 for (int j = i + 1; j < typeNames.length; j++) {
14590 TypeName typeName2 = typeNames[j]; 14600 TypeName typeName2 = typeNames[j];
14591 Identifier identifier2 = typeName2.name; 14601 Identifier identifier2 = typeName2.name;
14592 String name2 = identifier2.name; 14602 String name2 = identifier2.name;
14593 Element element2 = identifier2.staticElement; 14603 Element element2 = identifier2.staticElement;
14594 if (element != null && element == element2) { 14604 if (element != null && element == element2) {
14595 detectedRepeatOnIndex[j] = true; 14605 detectedRepeatOnIndex[j] = true;
14596 reportError8(CompileTimeErrorCode.IMPLEMENTS_REPEATED, typeName2, [name2]); 14606 reportError9(CompileTimeErrorCode.IMPLEMENTS_REPEATED, typeName2, [name2]);
14597 } 14607 }
14598 } 14608 }
14599 } 14609 }
14600 } 14610 }
14601 } 14611 }
14602 } 14612 }
14603 14613
14604 /** 14614 /**
14605 * Return the type specified by the given name. 14615 * Return the type specified by the given name.
14606 * 14616 *
14607 * @param typeName the type name specifying the type to be returned 14617 * @param typeName the type name specifying the type to be returned
14608 * @param nonTypeError the error to produce if the type name is defined to be something other than 14618 * @param nonTypeError the error to produce if the type name is defined to be something other than
14609 * a type 14619 * a type
14610 * @param dynamicTypeError the error to produce if the type name is "dynamic" 14620 * @param dynamicTypeError the error to produce if the type name is "dynamic"
14611 * @return the type specified by the type name 14621 * @return the type specified by the type name
14612 */ 14622 */
14613 InterfaceType resolveType(TypeName typeName, ErrorCode nonTypeError, ErrorCode dynamicTypeError) { 14623 InterfaceType resolveType(TypeName typeName, ErrorCode nonTypeError, ErrorCode dynamicTypeError) {
14614 Type2 type = typeName.type; 14624 Type2 type = typeName.type;
14615 if (type is InterfaceType) { 14625 if (type is InterfaceType) {
14616 return type; 14626 return type;
14617 } 14627 }
14618 // If the type is not an InterfaceType, then visitTypeName() sets the type t o be a DynamicTypeImpl 14628 // If the type is not an InterfaceType, then visitTypeName() sets the type t o be a DynamicTypeImpl
14619 Identifier name = typeName.name; 14629 Identifier name = typeName.name;
14620 if (name.name == sc.Keyword.DYNAMIC.syntax) { 14630 if (name.name == sc.Keyword.DYNAMIC.syntax) {
14621 reportError8(dynamicTypeError, name, [name.name]); 14631 reportError9(dynamicTypeError, name, [name.name]);
14622 } else { 14632 } else {
14623 reportError8(nonTypeError, name, [name.name]); 14633 reportError9(nonTypeError, name, [name.name]);
14624 } 14634 }
14625 return null; 14635 return null;
14626 } 14636 }
14627 14637
14628 /** 14638 /**
14629 * Resolve the types in the given list of type names. 14639 * Resolve the types in the given list of type names.
14630 * 14640 *
14631 * @param typeNames the type names to be resolved 14641 * @param typeNames the type names to be resolved
14632 * @param nonTypeError the error to produce if the type name is defined to be something other than 14642 * @param nonTypeError the error to produce if the type name is defined to be something other than
14633 * a type 14643 * a type
(...skipping 6518 matching lines...) Expand 10 before | Expand all | Expand 10 after
21152 * @param correction the template used to create the correction to be displaye d for the error 21162 * @param correction the template used to create the correction to be displaye d for the error
21153 */ 21163 */
21154 ResolverErrorCode.con2(String name, int ordinal, this.type, this.message, Stri ng correction) : super(name, ordinal) { 21164 ResolverErrorCode.con2(String name, int ordinal, this.type, this.message, Stri ng correction) : super(name, ordinal) {
21155 this.correction9 = correction; 21165 this.correction9 = correction;
21156 } 21166 }
21157 21167
21158 String get correction => correction9; 21168 String get correction => correction9;
21159 21169
21160 ErrorSeverity get errorSeverity => type.severity; 21170 ErrorSeverity get errorSeverity => type.severity;
21161 } 21171 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698