Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.src.generated.resolver; | 5 library analyzer.src.generated.resolver; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/visitor.dart'; | 10 import 'package:analyzer/dart/ast/visitor.dart'; |
| (...skipping 2079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2090 } | 2090 } |
| 2091 return super.visitCatchClause(node); | 2091 return super.visitCatchClause(node); |
| 2092 } | 2092 } |
| 2093 | 2093 |
| 2094 @override | 2094 @override |
| 2095 Object visitClassDeclaration(ClassDeclaration node) { | 2095 Object visitClassDeclaration(ClassDeclaration node) { |
| 2096 ClassElement outerClass = _enclosingClass; | 2096 ClassElement outerClass = _enclosingClass; |
| 2097 try { | 2097 try { |
| 2098 SimpleIdentifier className = node.name; | 2098 SimpleIdentifier className = node.name; |
| 2099 _enclosingClass = _findIdentifier(_enclosingUnit.types, className); | 2099 _enclosingClass = _findIdentifier(_enclosingUnit.types, className); |
| 2100 return super.visitClassDeclaration(node); | 2100 super.visitClassDeclaration(node); |
| 2101 _resolveMetadata(node.metadata, _enclosingClass.metadata); | |
| 2102 return null; | |
| 2101 } finally { | 2103 } finally { |
| 2102 _enclosingClass = outerClass; | 2104 _enclosingClass = outerClass; |
| 2103 } | 2105 } |
| 2104 } | 2106 } |
| 2105 | 2107 |
| 2106 @override | 2108 @override |
| 2107 Object visitClassTypeAlias(ClassTypeAlias node) { | 2109 Object visitClassTypeAlias(ClassTypeAlias node) { |
| 2108 ClassElement outerClass = _enclosingClass; | 2110 ClassElement outerClass = _enclosingClass; |
| 2109 try { | 2111 try { |
| 2110 SimpleIdentifier className = node.name; | 2112 SimpleIdentifier className = node.name; |
| 2111 _enclosingClass = _findIdentifier(_enclosingUnit.types, className); | 2113 _enclosingClass = _findIdentifier(_enclosingUnit.types, className); |
| 2112 return super.visitClassTypeAlias(node); | 2114 super.visitClassTypeAlias(node); |
| 2115 _resolveMetadata(node.metadata, _enclosingClass.metadata); | |
| 2116 return null; | |
| 2113 } finally { | 2117 } finally { |
| 2114 _enclosingClass = outerClass; | 2118 _enclosingClass = outerClass; |
| 2115 } | 2119 } |
| 2116 } | 2120 } |
| 2117 | 2121 |
| 2118 @override | 2122 @override |
| 2119 Object visitConstructorDeclaration(ConstructorDeclaration node) { | 2123 Object visitConstructorDeclaration(ConstructorDeclaration node) { |
| 2120 ExecutableElement outerExecutable = _enclosingExecutable; | 2124 ExecutableElement outerExecutable = _enclosingExecutable; |
| 2121 try { | 2125 try { |
| 2122 SimpleIdentifier constructorName = node.name; | 2126 SimpleIdentifier constructorName = node.name; |
| 2123 if (constructorName == null) { | 2127 if (constructorName == null) { |
| 2124 _enclosingExecutable = _enclosingClass.unnamedConstructor; | 2128 _enclosingExecutable = _enclosingClass.unnamedConstructor; |
| 2125 } else { | 2129 } else { |
| 2126 _enclosingExecutable = | 2130 _enclosingExecutable = |
| 2127 _enclosingClass.getNamedConstructor(constructorName.name); | 2131 _enclosingClass.getNamedConstructor(constructorName.name); |
| 2128 constructorName.staticElement = _enclosingExecutable; | 2132 constructorName.staticElement = _enclosingExecutable; |
| 2129 } | 2133 } |
| 2130 node.element = _enclosingExecutable as ConstructorElement; | 2134 node.element = _enclosingExecutable as ConstructorElement; |
| 2131 return super.visitConstructorDeclaration(node); | 2135 super.visitConstructorDeclaration(node); |
| 2136 _resolveMetadata(node.metadata, _enclosingExecutable.metadata); | |
| 2137 return null; | |
| 2132 } finally { | 2138 } finally { |
| 2133 _enclosingExecutable = outerExecutable; | 2139 _enclosingExecutable = outerExecutable; |
| 2134 } | 2140 } |
| 2135 } | 2141 } |
| 2136 | 2142 |
| 2137 @override | 2143 @override |
| 2138 Object visitDeclaredIdentifier(DeclaredIdentifier node) { | 2144 Object visitDeclaredIdentifier(DeclaredIdentifier node) { |
| 2139 SimpleIdentifier variableName = node.identifier; | 2145 SimpleIdentifier variableName = node.identifier; |
| 2140 _findIdentifier(_enclosingExecutable.localVariables, variableName); | 2146 Element element = |
| 2141 return super.visitDeclaredIdentifier(node); | 2147 _findIdentifier(_enclosingExecutable.localVariables, variableName); |
| 2148 super.visitDeclaredIdentifier(node); | |
| 2149 _resolveMetadata(node.metadata, element.metadata); | |
| 2150 return null; | |
| 2142 } | 2151 } |
| 2143 | 2152 |
| 2144 @override | 2153 @override |
| 2145 Object visitDefaultFormalParameter(DefaultFormalParameter node) { | 2154 Object visitDefaultFormalParameter(DefaultFormalParameter node) { |
| 2146 SimpleIdentifier parameterName = node.parameter.identifier; | 2155 SimpleIdentifier parameterName = node.parameter.identifier; |
| 2147 ParameterElement element = _getElementForParameter(node, parameterName); | 2156 ParameterElement element = _getElementForParameter(node, parameterName); |
| 2148 Expression defaultValue = node.defaultValue; | 2157 Expression defaultValue = node.defaultValue; |
| 2149 if (defaultValue != null) { | 2158 if (defaultValue != null) { |
| 2150 ExecutableElement outerExecutable = _enclosingExecutable; | 2159 ExecutableElement outerExecutable = _enclosingExecutable; |
| 2151 try { | 2160 try { |
| 2152 if (element == null) { | 2161 if (element == null) { |
| 2153 // TODO(brianwilkerson) Report this internal error. | 2162 // TODO(brianwilkerson) Report this internal error. |
| 2154 } else { | 2163 } else { |
| 2155 _enclosingExecutable = element.initializer; | 2164 _enclosingExecutable = element.initializer; |
| 2156 } | 2165 } |
| 2157 defaultValue.accept(this); | 2166 defaultValue.accept(this); |
| 2158 } finally { | 2167 } finally { |
| 2159 _enclosingExecutable = outerExecutable; | 2168 _enclosingExecutable = outerExecutable; |
| 2160 } | 2169 } |
| 2161 } | 2170 } |
| 2162 ParameterElement outerParameter = _enclosingParameter; | 2171 ParameterElement outerParameter = _enclosingParameter; |
| 2163 try { | 2172 try { |
| 2164 _enclosingParameter = element; | 2173 _enclosingParameter = element; |
| 2165 return super.visitDefaultFormalParameter(node); | 2174 super.visitDefaultFormalParameter(node); |
| 2175 _resolveMetadata(node.metadata, element.metadata); | |
| 2176 return null; | |
| 2166 } finally { | 2177 } finally { |
| 2167 _enclosingParameter = outerParameter; | 2178 _enclosingParameter = outerParameter; |
| 2168 } | 2179 } |
| 2169 } | 2180 } |
| 2170 | 2181 |
| 2171 @override | 2182 @override |
| 2172 Object visitEnumDeclaration(EnumDeclaration node) { | 2183 Object visitEnumDeclaration(EnumDeclaration node) { |
| 2173 ClassElement enclosingEnum = | 2184 ClassElement enclosingEnum = |
| 2174 _findIdentifier(_enclosingUnit.enums, node.name); | 2185 _findIdentifier(_enclosingUnit.enums, node.name); |
| 2175 List<FieldElement> constants = enclosingEnum.fields; | 2186 List<FieldElement> constants = enclosingEnum.fields; |
| 2176 for (EnumConstantDeclaration constant in node.constants) { | 2187 for (EnumConstantDeclaration constant in node.constants) { |
| 2177 _findIdentifier(constants, constant.name); | 2188 _findIdentifier(constants, constant.name); |
| 2178 } | 2189 } |
| 2179 return super.visitEnumDeclaration(node); | 2190 super.visitEnumDeclaration(node); |
| 2191 _resolveMetadata(node.metadata, enclosingEnum.metadata); | |
| 2192 return null; | |
| 2180 } | 2193 } |
| 2181 | 2194 |
| 2182 @override | 2195 @override |
| 2183 Object visitExportDirective(ExportDirective node) { | 2196 Object visitExportDirective(ExportDirective node) { |
| 2184 String uri = _getStringValue(node.uri); | 2197 String uri = _getStringValue(node.uri); |
| 2198 ExportElement exportElement; | |
| 2185 if (uri != null) { | 2199 if (uri != null) { |
| 2186 LibraryElement library = _enclosingUnit.library; | 2200 LibraryElement library = _enclosingUnit.library; |
| 2187 ExportElement exportElement = _findExport( | 2201 exportElement = _findExport( |
| 2188 library.exports, | 2202 library.exports, |
| 2189 _enclosingUnit.context.sourceFactory | 2203 _enclosingUnit.context.sourceFactory |
| 2190 .resolveUri(_enclosingUnit.source, uri)); | 2204 .resolveUri(_enclosingUnit.source, uri)); |
| 2191 node.element = exportElement; | 2205 node.element = exportElement; |
| 2192 } | 2206 } |
| 2193 return super.visitExportDirective(node); | 2207 super.visitExportDirective(node); |
| 2208 if (exportElement != null) { | |
| 2209 _resolveMetadata(node.metadata, exportElement.metadata); | |
| 2210 } | |
| 2211 return null; | |
| 2194 } | 2212 } |
| 2195 | 2213 |
| 2196 @override | 2214 @override |
| 2215 Object visitFieldDeclaration(FieldDeclaration node) { | |
| 2216 super.visitFieldDeclaration(node); | |
| 2217 _resolveMetadata(node.metadata, node.fields.variables[0].element.metadata); | |
| 2218 return null; | |
| 2219 } | |
| 2220 | |
| 2221 @override | |
| 2197 Object visitFieldFormalParameter(FieldFormalParameter node) { | 2222 Object visitFieldFormalParameter(FieldFormalParameter node) { |
| 2198 if (node.parent is! DefaultFormalParameter) { | 2223 if (node.parent is! DefaultFormalParameter) { |
| 2199 SimpleIdentifier parameterName = node.identifier; | 2224 SimpleIdentifier parameterName = node.identifier; |
| 2200 ParameterElement element = _getElementForParameter(node, parameterName); | 2225 ParameterElement element = _getElementForParameter(node, parameterName); |
| 2201 ParameterElement outerParameter = _enclosingParameter; | 2226 ParameterElement outerParameter = _enclosingParameter; |
| 2202 try { | 2227 try { |
| 2203 _enclosingParameter = element; | 2228 _enclosingParameter = element; |
| 2204 return super.visitFieldFormalParameter(node); | 2229 super.visitFieldFormalParameter(node); |
| 2230 _resolveMetadata(node.metadata, element.metadata); | |
| 2231 return null; | |
| 2205 } finally { | 2232 } finally { |
| 2206 _enclosingParameter = outerParameter; | 2233 _enclosingParameter = outerParameter; |
| 2207 } | 2234 } |
| 2208 } else { | 2235 } else { |
| 2209 return super.visitFieldFormalParameter(node); | 2236 return super.visitFieldFormalParameter(node); |
| 2210 } | 2237 } |
| 2211 } | 2238 } |
| 2212 | 2239 |
| 2213 @override | 2240 @override |
| 2214 Object visitFunctionDeclaration(FunctionDeclaration node) { | 2241 Object visitFunctionDeclaration(FunctionDeclaration node) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 2232 PropertyAccessorElement accessor = | 2259 PropertyAccessorElement accessor = |
| 2233 _findIdentifier(_enclosingUnit.accessors, functionName); | 2260 _findIdentifier(_enclosingUnit.accessors, functionName); |
| 2234 if ((property as KeywordToken).keyword == Keyword.SET) { | 2261 if ((property as KeywordToken).keyword == Keyword.SET) { |
| 2235 accessor = accessor.variable.setter; | 2262 accessor = accessor.variable.setter; |
| 2236 functionName.staticElement = accessor; | 2263 functionName.staticElement = accessor; |
| 2237 } | 2264 } |
| 2238 _enclosingExecutable = accessor; | 2265 _enclosingExecutable = accessor; |
| 2239 } | 2266 } |
| 2240 } | 2267 } |
| 2241 node.functionExpression.element = _enclosingExecutable; | 2268 node.functionExpression.element = _enclosingExecutable; |
| 2242 return super.visitFunctionDeclaration(node); | 2269 super.visitFunctionDeclaration(node); |
| 2270 _resolveMetadata(node.metadata, _enclosingExecutable.metadata); | |
| 2271 return null; | |
| 2243 } finally { | 2272 } finally { |
| 2244 _enclosingExecutable = outerExecutable; | 2273 _enclosingExecutable = outerExecutable; |
| 2245 } | 2274 } |
| 2246 } | 2275 } |
| 2247 | 2276 |
| 2248 @override | 2277 @override |
| 2249 Object visitFunctionExpression(FunctionExpression node) { | 2278 Object visitFunctionExpression(FunctionExpression node) { |
| 2250 if (node.parent is! FunctionDeclaration) { | 2279 if (node.parent is! FunctionDeclaration) { |
| 2251 FunctionElement element = | 2280 FunctionElement element = |
| 2252 _findAtOffset(_enclosingExecutable.functions, node.beginToken.offset); | 2281 _findAtOffset(_enclosingExecutable.functions, node.beginToken.offset); |
| 2253 node.element = element; | 2282 node.element = element; |
| 2254 } | 2283 } |
| 2255 ExecutableElement outerExecutable = _enclosingExecutable; | 2284 ExecutableElement outerExecutable = _enclosingExecutable; |
| 2256 try { | 2285 try { |
| 2257 _enclosingExecutable = node.element; | 2286 _enclosingExecutable = node.element; |
| 2258 return super.visitFunctionExpression(node); | 2287 return super.visitFunctionExpression(node); |
| 2259 } finally { | 2288 } finally { |
| 2260 _enclosingExecutable = outerExecutable; | 2289 _enclosingExecutable = outerExecutable; |
| 2261 } | 2290 } |
| 2262 } | 2291 } |
| 2263 | 2292 |
| 2264 @override | 2293 @override |
| 2265 Object visitFunctionTypeAlias(FunctionTypeAlias node) { | 2294 Object visitFunctionTypeAlias(FunctionTypeAlias node) { |
| 2266 FunctionTypeAliasElement outerAlias = _enclosingAlias; | 2295 FunctionTypeAliasElement outerAlias = _enclosingAlias; |
| 2267 try { | 2296 try { |
| 2268 SimpleIdentifier aliasName = node.name; | 2297 SimpleIdentifier aliasName = node.name; |
| 2269 _enclosingAlias = | 2298 _enclosingAlias = |
| 2270 _findIdentifier(_enclosingUnit.functionTypeAliases, aliasName); | 2299 _findIdentifier(_enclosingUnit.functionTypeAliases, aliasName); |
| 2271 return super.visitFunctionTypeAlias(node); | 2300 super.visitFunctionTypeAlias(node); |
| 2301 _resolveMetadata(node.metadata, _enclosingAlias.metadata); | |
| 2302 return null; | |
| 2272 } finally { | 2303 } finally { |
| 2273 _enclosingAlias = outerAlias; | 2304 _enclosingAlias = outerAlias; |
| 2274 } | 2305 } |
| 2275 } | 2306 } |
| 2276 | 2307 |
| 2277 @override | 2308 @override |
| 2278 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { | 2309 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { |
| 2279 if (node.parent is! DefaultFormalParameter) { | 2310 if (node.parent is! DefaultFormalParameter) { |
| 2280 SimpleIdentifier parameterName = node.identifier; | 2311 SimpleIdentifier parameterName = node.identifier; |
| 2281 ParameterElement element = _getElementForParameter(node, parameterName); | 2312 ParameterElement element = _getElementForParameter(node, parameterName); |
| 2282 ParameterElement outerParameter = _enclosingParameter; | 2313 ParameterElement outerParameter = _enclosingParameter; |
| 2283 try { | 2314 try { |
| 2284 _enclosingParameter = element; | 2315 _enclosingParameter = element; |
| 2285 return super.visitFunctionTypedFormalParameter(node); | 2316 super.visitFunctionTypedFormalParameter(node); |
| 2317 _resolveMetadata(node.metadata, _enclosingParameter.metadata); | |
| 2318 return null; | |
| 2286 } finally { | 2319 } finally { |
| 2287 _enclosingParameter = outerParameter; | 2320 _enclosingParameter = outerParameter; |
| 2288 } | 2321 } |
| 2289 } else { | 2322 } else { |
| 2290 return super.visitFunctionTypedFormalParameter(node); | 2323 return super.visitFunctionTypedFormalParameter(node); |
| 2291 } | 2324 } |
| 2292 } | 2325 } |
| 2293 | 2326 |
| 2294 @override | 2327 @override |
| 2295 Object visitImportDirective(ImportDirective node) { | 2328 Object visitImportDirective(ImportDirective node) { |
| 2296 String uri = _getStringValue(node.uri); | 2329 String uri = _getStringValue(node.uri); |
| 2330 ImportElement importElement; | |
| 2297 if (uri != null) { | 2331 if (uri != null) { |
| 2298 LibraryElement library = _enclosingUnit.library; | 2332 LibraryElement library = _enclosingUnit.library; |
| 2299 ImportElement importElement = _findImport( | 2333 importElement = _findImport( |
| 2300 library.imports, | 2334 library.imports, |
| 2301 _enclosingUnit.context.sourceFactory | 2335 _enclosingUnit.context.sourceFactory |
| 2302 .resolveUri(_enclosingUnit.source, uri), | 2336 .resolveUri(_enclosingUnit.source, uri), |
| 2303 node.prefix); | 2337 node.prefix); |
| 2304 node.element = importElement; | 2338 node.element = importElement; |
| 2305 } | 2339 } |
| 2306 return super.visitImportDirective(node); | 2340 super.visitImportDirective(node); |
| 2341 if (importElement != null) { | |
| 2342 _resolveMetadata(node.metadata, importElement.metadata); | |
| 2343 } | |
| 2344 return null; | |
| 2307 } | 2345 } |
| 2308 | 2346 |
| 2309 @override | 2347 @override |
| 2310 Object visitLabeledStatement(LabeledStatement node) { | 2348 Object visitLabeledStatement(LabeledStatement node) { |
| 2311 for (Label label in node.labels) { | 2349 for (Label label in node.labels) { |
| 2312 SimpleIdentifier labelName = label.label; | 2350 SimpleIdentifier labelName = label.label; |
| 2313 _findIdentifier(_enclosingExecutable.labels, labelName); | 2351 _findIdentifier(_enclosingExecutable.labels, labelName); |
| 2314 } | 2352 } |
| 2315 return super.visitLabeledStatement(node); | 2353 return super.visitLabeledStatement(node); |
| 2316 } | 2354 } |
| 2317 | 2355 |
| 2318 @override | 2356 @override |
| 2319 Object visitLibraryDirective(LibraryDirective node) { | 2357 Object visitLibraryDirective(LibraryDirective node) { |
| 2320 node.element = _enclosingUnit.library; | 2358 LibraryElement libraryElement = _enclosingUnit.library; |
| 2321 return super.visitLibraryDirective(node); | 2359 node.element = libraryElement; |
| 2360 super.visitLibraryDirective(node); | |
| 2361 _resolveMetadata(node.metadata, libraryElement.metadata); | |
| 2362 return null; | |
| 2322 } | 2363 } |
| 2323 | 2364 |
| 2324 @override | 2365 @override |
| 2325 Object visitMethodDeclaration(MethodDeclaration node) { | 2366 Object visitMethodDeclaration(MethodDeclaration node) { |
| 2326 ExecutableElement outerExecutable = _enclosingExecutable; | 2367 ExecutableElement outerExecutable = _enclosingExecutable; |
| 2327 try { | 2368 try { |
| 2328 Token property = node.propertyKeyword; | 2369 Token property = node.propertyKeyword; |
| 2329 SimpleIdentifier methodName = node.name; | 2370 SimpleIdentifier methodName = node.name; |
| 2330 String nameOfMethod = methodName.name; | 2371 String nameOfMethod = methodName.name; |
| 2331 if (property == null) { | 2372 if (property == null) { |
| 2332 _enclosingExecutable = _findWithNameAndOffset( | 2373 _enclosingExecutable = _findWithNameAndOffset( |
| 2333 _enclosingClass.methods, nameOfMethod, methodName.offset); | 2374 _enclosingClass.methods, nameOfMethod, methodName.offset); |
| 2334 methodName.staticElement = _enclosingExecutable; | 2375 methodName.staticElement = _enclosingExecutable; |
| 2335 } else { | 2376 } else { |
| 2336 PropertyAccessorElement accessor = | 2377 PropertyAccessorElement accessor = |
| 2337 _findIdentifier(_enclosingClass.accessors, methodName); | 2378 _findIdentifier(_enclosingClass.accessors, methodName); |
| 2338 if ((property as KeywordToken).keyword == Keyword.SET) { | 2379 if ((property as KeywordToken).keyword == Keyword.SET) { |
| 2339 accessor = accessor.variable.setter; | 2380 accessor = accessor.variable.setter; |
| 2340 methodName.staticElement = accessor; | 2381 methodName.staticElement = accessor; |
| 2341 } | 2382 } |
| 2342 _enclosingExecutable = accessor; | 2383 _enclosingExecutable = accessor; |
| 2343 } | 2384 } |
| 2344 return super.visitMethodDeclaration(node); | 2385 super.visitMethodDeclaration(node); |
| 2386 _resolveMetadata(node.metadata, _enclosingExecutable.metadata); | |
| 2387 return null; | |
| 2345 } finally { | 2388 } finally { |
| 2346 _enclosingExecutable = outerExecutable; | 2389 _enclosingExecutable = outerExecutable; |
| 2347 } | 2390 } |
| 2348 } | 2391 } |
| 2349 | 2392 |
| 2350 @override | 2393 @override |
| 2351 Object visitPartDirective(PartDirective node) { | 2394 Object visitPartDirective(PartDirective node) { |
| 2352 String uri = _getStringValue(node.uri); | 2395 String uri = _getStringValue(node.uri); |
| 2396 CompilationUnitElement compilationUnitElement; | |
| 2353 if (uri != null) { | 2397 if (uri != null) { |
| 2354 Source partSource = _enclosingUnit.context.sourceFactory | 2398 Source partSource = _enclosingUnit.context.sourceFactory |
| 2355 .resolveUri(_enclosingUnit.source, uri); | 2399 .resolveUri(_enclosingUnit.source, uri); |
| 2356 node.element = _findPart(_enclosingUnit.library.parts, partSource); | 2400 compilationUnitElement = |
| 2401 _findPart(_enclosingUnit.library.parts, partSource); | |
| 2402 node.element = compilationUnitElement; | |
| 2357 } | 2403 } |
| 2358 return super.visitPartDirective(node); | 2404 super.visitPartDirective(node); |
| 2405 if (compilationUnitElement != null) { | |
| 2406 _resolveMetadata(node.metadata, compilationUnitElement.metadata); | |
|
Brian Wilkerson
2016/02/04 19:44:52
Do we want to do this here? I think the compilatio
Paul Berry
2016/02/04 20:17:41
I don't think it will be a problem, because if a s
| |
| 2407 } | |
| 2408 return null; | |
| 2359 } | 2409 } |
| 2360 | 2410 |
| 2361 @override | 2411 @override |
| 2362 Object visitPartOfDirective(PartOfDirective node) { | 2412 Object visitPartOfDirective(PartOfDirective node) { |
| 2363 node.element = _enclosingUnit.library; | 2413 node.element = _enclosingUnit.library; |
| 2364 return super.visitPartOfDirective(node); | 2414 return super.visitPartOfDirective(node); |
| 2365 } | 2415 } |
| 2366 | 2416 |
| 2367 @override | 2417 @override |
| 2368 Object visitSimpleFormalParameter(SimpleFormalParameter node) { | 2418 Object visitSimpleFormalParameter(SimpleFormalParameter node) { |
| 2369 if (node.parent is! DefaultFormalParameter) { | 2419 if (node.parent is! DefaultFormalParameter) { |
| 2370 SimpleIdentifier parameterName = node.identifier; | 2420 SimpleIdentifier parameterName = node.identifier; |
| 2371 ParameterElement element = _getElementForParameter(node, parameterName); | 2421 ParameterElement element = _getElementForParameter(node, parameterName); |
| 2372 ParameterElement outerParameter = _enclosingParameter; | 2422 ParameterElement outerParameter = _enclosingParameter; |
| 2373 try { | 2423 try { |
| 2374 _enclosingParameter = element; | 2424 _enclosingParameter = element; |
| 2375 return super.visitSimpleFormalParameter(node); | 2425 super.visitSimpleFormalParameter(node); |
| 2426 _resolveMetadata(node.metadata, element.metadata); | |
| 2427 return null; | |
| 2376 } finally { | 2428 } finally { |
| 2377 _enclosingParameter = outerParameter; | 2429 _enclosingParameter = outerParameter; |
| 2378 } | 2430 } |
| 2379 } else {} | 2431 } else {} |
| 2380 return super.visitSimpleFormalParameter(node); | 2432 return super.visitSimpleFormalParameter(node); |
| 2381 } | 2433 } |
| 2382 | 2434 |
| 2383 @override | 2435 @override |
| 2384 Object visitSwitchCase(SwitchCase node) { | 2436 Object visitSwitchCase(SwitchCase node) { |
| 2385 for (Label label in node.labels) { | 2437 for (Label label in node.labels) { |
| 2386 SimpleIdentifier labelName = label.label; | 2438 SimpleIdentifier labelName = label.label; |
| 2387 _findIdentifier(_enclosingExecutable.labels, labelName); | 2439 _findIdentifier(_enclosingExecutable.labels, labelName); |
| 2388 } | 2440 } |
| 2389 return super.visitSwitchCase(node); | 2441 return super.visitSwitchCase(node); |
| 2390 } | 2442 } |
| 2391 | 2443 |
| 2392 @override | 2444 @override |
| 2393 Object visitSwitchDefault(SwitchDefault node) { | 2445 Object visitSwitchDefault(SwitchDefault node) { |
| 2394 for (Label label in node.labels) { | 2446 for (Label label in node.labels) { |
| 2395 SimpleIdentifier labelName = label.label; | 2447 SimpleIdentifier labelName = label.label; |
| 2396 _findIdentifier(_enclosingExecutable.labels, labelName); | 2448 _findIdentifier(_enclosingExecutable.labels, labelName); |
| 2397 } | 2449 } |
| 2398 return super.visitSwitchDefault(node); | 2450 return super.visitSwitchDefault(node); |
| 2399 } | 2451 } |
| 2400 | 2452 |
| 2401 @override | 2453 @override |
| 2454 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { | |
| 2455 super.visitTopLevelVariableDeclaration(node); | |
| 2456 _resolveMetadata( | |
| 2457 node.metadata, node.variables.variables[0].element.metadata); | |
| 2458 return null; | |
| 2459 } | |
| 2460 | |
| 2461 @override | |
| 2402 Object visitTypeParameter(TypeParameter node) { | 2462 Object visitTypeParameter(TypeParameter node) { |
| 2403 SimpleIdentifier parameterName = node.name; | 2463 SimpleIdentifier parameterName = node.name; |
| 2404 | 2464 |
| 2405 Element element; | 2465 Element element; |
| 2406 if (_enclosingExecutable != null) { | 2466 if (_enclosingExecutable != null) { |
| 2407 element = | 2467 element = |
| 2408 _findIdentifier(_enclosingExecutable.typeParameters, parameterName); | 2468 _findIdentifier(_enclosingExecutable.typeParameters, parameterName); |
| 2409 } | 2469 } |
| 2410 if (element == null) { | 2470 if (element == null) { |
| 2411 if (_enclosingClass != null) { | 2471 if (_enclosingClass != null) { |
| 2412 _findIdentifier(_enclosingClass.typeParameters, parameterName); | 2472 element = |
| 2473 _findIdentifier(_enclosingClass.typeParameters, parameterName); | |
| 2413 } else if (_enclosingAlias != null) { | 2474 } else if (_enclosingAlias != null) { |
| 2414 _findIdentifier(_enclosingAlias.typeParameters, parameterName); | 2475 element = |
| 2476 _findIdentifier(_enclosingAlias.typeParameters, parameterName); | |
| 2415 } | 2477 } |
| 2416 } | 2478 } |
| 2417 return super.visitTypeParameter(node); | 2479 super.visitTypeParameter(node); |
| 2480 _resolveMetadata(node.metadata, element.metadata); | |
| 2481 return null; | |
| 2418 } | 2482 } |
| 2419 | 2483 |
| 2420 @override | 2484 @override |
| 2421 Object visitVariableDeclaration(VariableDeclaration node) { | 2485 Object visitVariableDeclaration(VariableDeclaration node) { |
| 2422 VariableElement element = null; | 2486 VariableElement element = null; |
| 2423 SimpleIdentifier variableName = node.name; | 2487 SimpleIdentifier variableName = node.name; |
| 2424 if (_enclosingExecutable != null) { | 2488 if (_enclosingExecutable != null) { |
| 2425 element = | 2489 element = |
| 2426 _findIdentifier(_enclosingExecutable.localVariables, variableName); | 2490 _findIdentifier(_enclosingExecutable.localVariables, variableName); |
| 2427 } | 2491 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 2441 _enclosingExecutable = element.initializer; | 2505 _enclosingExecutable = element.initializer; |
| 2442 } | 2506 } |
| 2443 return super.visitVariableDeclaration(node); | 2507 return super.visitVariableDeclaration(node); |
| 2444 } finally { | 2508 } finally { |
| 2445 _enclosingExecutable = outerExecutable; | 2509 _enclosingExecutable = outerExecutable; |
| 2446 } | 2510 } |
| 2447 } | 2511 } |
| 2448 return super.visitVariableDeclaration(node); | 2512 return super.visitVariableDeclaration(node); |
| 2449 } | 2513 } |
| 2450 | 2514 |
| 2515 @override | |
| 2516 Object visitVariableDeclarationList(VariableDeclarationList node) { | |
| 2517 super.visitVariableDeclarationList(node); | |
| 2518 if (node.parent is! FieldDeclaration && | |
| 2519 node.parent is! TopLevelVariableDeclaration) { | |
| 2520 _resolveMetadata(node.metadata, node.variables[0].element.metadata); | |
| 2521 } | |
| 2522 return null; | |
| 2523 } | |
| 2524 | |
| 2451 /** | 2525 /** |
| 2452 * Return the element in the given array of elements that was created for the declaration at the | 2526 * Return the element in the given array of elements that was created for the declaration at the |
| 2453 * given offset. This method should only be used when there is no name | 2527 * given offset. This method should only be used when there is no name |
| 2454 * | 2528 * |
| 2455 * @param elements the elements of the appropriate kind that exist in the curr ent context | 2529 * @param elements the elements of the appropriate kind that exist in the curr ent context |
| 2456 * @param offset the offset of the name of the element to be returned | 2530 * @param offset the offset of the name of the element to be returned |
| 2457 * @return the element at the given offset | 2531 * @return the element at the given offset |
| 2458 */ | 2532 */ |
| 2459 Element _findAtOffset(List<Element> elements, int offset) => | 2533 Element _findAtOffset(List<Element> elements, int offset) => |
| 2460 _findWithNameAndOffset(elements, "", offset); | 2534 _findWithNameAndOffset(elements, "", offset); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2604 * | 2678 * |
| 2605 * @param literal the string literal whose value is to be returned | 2679 * @param literal the string literal whose value is to be returned |
| 2606 * @return the value of the given string literal | 2680 * @return the value of the given string literal |
| 2607 */ | 2681 */ |
| 2608 String _getStringValue(StringLiteral literal) { | 2682 String _getStringValue(StringLiteral literal) { |
| 2609 if (literal is StringInterpolation) { | 2683 if (literal is StringInterpolation) { |
| 2610 return null; | 2684 return null; |
| 2611 } | 2685 } |
| 2612 return literal.stringValue; | 2686 return literal.stringValue; |
| 2613 } | 2687 } |
| 2688 | |
| 2689 void _resolveMetadata(NodeList<Annotation> astMetadata, | |
| 2690 List<ElementAnnotation> elementMetadata) { | |
| 2691 assert(astMetadata.length == elementMetadata.length); | |
| 2692 for (int i = 0; i < astMetadata.length; i++) { | |
| 2693 astMetadata[i].elementAnnotation = elementMetadata[i]; | |
| 2694 } | |
| 2695 } | |
| 2614 } | 2696 } |
| 2615 | 2697 |
| 2616 /** | 2698 /** |
| 2617 * Instances of the class `ElementHolder` hold on to elements created while trav ersing an AST | 2699 * Instances of the class `ElementHolder` hold on to elements created while trav ersing an AST |
| 2618 * structure so that they can be accessed when creating their enclosing element. | 2700 * structure so that they can be accessed when creating their enclosing element. |
| 2619 */ | 2701 */ |
| 2620 class ElementHolder { | 2702 class ElementHolder { |
| 2621 List<PropertyAccessorElement> _accessors; | 2703 List<PropertyAccessorElement> _accessors; |
| 2622 | 2704 |
| 2623 List<ConstructorElement> _constructors; | 2705 List<ConstructorElement> _constructors; |
| (...skipping 9878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12502 nonFields.add(node); | 12584 nonFields.add(node); |
| 12503 return null; | 12585 return null; |
| 12504 } | 12586 } |
| 12505 | 12587 |
| 12506 @override | 12588 @override |
| 12507 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 12589 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
| 12508 | 12590 |
| 12509 @override | 12591 @override |
| 12510 Object visitWithClause(WithClause node) => null; | 12592 Object visitWithClause(WithClause node) => null; |
| 12511 } | 12593 } |
| OLD | NEW |