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

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

Issue 1667963005: Make DeclarationResolver re-associate Annotations with ElementAnnotations. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fix a typo. Created 4 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
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/declaration_resolver_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.src.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
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);
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);
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);
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);
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);
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);
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 _resolveMetadata(node.metadata, exportElement);
2209 return null;
2194 } 2210 }
2195 2211
2196 @override 2212 @override
2213 Object visitFieldDeclaration(FieldDeclaration node) {
2214 super.visitFieldDeclaration(node);
2215 _resolveMetadata(node.metadata, node.fields.variables[0].element);
2216 return null;
2217 }
2218
2219 @override
2197 Object visitFieldFormalParameter(FieldFormalParameter node) { 2220 Object visitFieldFormalParameter(FieldFormalParameter node) {
2198 if (node.parent is! DefaultFormalParameter) { 2221 if (node.parent is! DefaultFormalParameter) {
2199 SimpleIdentifier parameterName = node.identifier; 2222 SimpleIdentifier parameterName = node.identifier;
2200 ParameterElement element = _getElementForParameter(node, parameterName); 2223 ParameterElement element = _getElementForParameter(node, parameterName);
2201 ParameterElement outerParameter = _enclosingParameter; 2224 ParameterElement outerParameter = _enclosingParameter;
2202 try { 2225 try {
2203 _enclosingParameter = element; 2226 _enclosingParameter = element;
2204 return super.visitFieldFormalParameter(node); 2227 super.visitFieldFormalParameter(node);
2228 _resolveMetadata(node.metadata, element);
2229 return null;
2205 } finally { 2230 } finally {
2206 _enclosingParameter = outerParameter; 2231 _enclosingParameter = outerParameter;
2207 } 2232 }
2208 } else { 2233 } else {
2209 return super.visitFieldFormalParameter(node); 2234 return super.visitFieldFormalParameter(node);
2210 } 2235 }
2211 } 2236 }
2212 2237
2213 @override 2238 @override
2214 Object visitFunctionDeclaration(FunctionDeclaration node) { 2239 Object visitFunctionDeclaration(FunctionDeclaration node) {
(...skipping 17 matching lines...) Expand all
2232 PropertyAccessorElement accessor = 2257 PropertyAccessorElement accessor =
2233 _findIdentifier(_enclosingUnit.accessors, functionName); 2258 _findIdentifier(_enclosingUnit.accessors, functionName);
2234 if ((property as KeywordToken).keyword == Keyword.SET) { 2259 if ((property as KeywordToken).keyword == Keyword.SET) {
2235 accessor = accessor.variable.setter; 2260 accessor = accessor.variable.setter;
2236 functionName.staticElement = accessor; 2261 functionName.staticElement = accessor;
2237 } 2262 }
2238 _enclosingExecutable = accessor; 2263 _enclosingExecutable = accessor;
2239 } 2264 }
2240 } 2265 }
2241 node.functionExpression.element = _enclosingExecutable; 2266 node.functionExpression.element = _enclosingExecutable;
2242 return super.visitFunctionDeclaration(node); 2267 super.visitFunctionDeclaration(node);
2268 _resolveMetadata(node.metadata, _enclosingExecutable);
2269 return null;
2243 } finally { 2270 } finally {
2244 _enclosingExecutable = outerExecutable; 2271 _enclosingExecutable = outerExecutable;
2245 } 2272 }
2246 } 2273 }
2247 2274
2248 @override 2275 @override
2249 Object visitFunctionExpression(FunctionExpression node) { 2276 Object visitFunctionExpression(FunctionExpression node) {
2250 if (node.parent is! FunctionDeclaration) { 2277 if (node.parent is! FunctionDeclaration) {
2251 FunctionElement element = 2278 FunctionElement element =
2252 _findAtOffset(_enclosingExecutable.functions, node.beginToken.offset); 2279 _findAtOffset(_enclosingExecutable.functions, node.beginToken.offset);
2253 node.element = element; 2280 node.element = element;
2254 } 2281 }
2255 ExecutableElement outerExecutable = _enclosingExecutable; 2282 ExecutableElement outerExecutable = _enclosingExecutable;
2256 try { 2283 try {
2257 _enclosingExecutable = node.element; 2284 _enclosingExecutable = node.element;
2258 return super.visitFunctionExpression(node); 2285 return super.visitFunctionExpression(node);
2259 } finally { 2286 } finally {
2260 _enclosingExecutable = outerExecutable; 2287 _enclosingExecutable = outerExecutable;
2261 } 2288 }
2262 } 2289 }
2263 2290
2264 @override 2291 @override
2265 Object visitFunctionTypeAlias(FunctionTypeAlias node) { 2292 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
2266 FunctionTypeAliasElement outerAlias = _enclosingAlias; 2293 FunctionTypeAliasElement outerAlias = _enclosingAlias;
2267 try { 2294 try {
2268 SimpleIdentifier aliasName = node.name; 2295 SimpleIdentifier aliasName = node.name;
2269 _enclosingAlias = 2296 _enclosingAlias =
2270 _findIdentifier(_enclosingUnit.functionTypeAliases, aliasName); 2297 _findIdentifier(_enclosingUnit.functionTypeAliases, aliasName);
2271 return super.visitFunctionTypeAlias(node); 2298 super.visitFunctionTypeAlias(node);
2299 _resolveMetadata(node.metadata, _enclosingAlias);
2300 return null;
2272 } finally { 2301 } finally {
2273 _enclosingAlias = outerAlias; 2302 _enclosingAlias = outerAlias;
2274 } 2303 }
2275 } 2304 }
2276 2305
2277 @override 2306 @override
2278 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { 2307 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
2279 if (node.parent is! DefaultFormalParameter) { 2308 if (node.parent is! DefaultFormalParameter) {
2280 SimpleIdentifier parameterName = node.identifier; 2309 SimpleIdentifier parameterName = node.identifier;
2281 ParameterElement element = _getElementForParameter(node, parameterName); 2310 ParameterElement element = _getElementForParameter(node, parameterName);
2282 ParameterElement outerParameter = _enclosingParameter; 2311 ParameterElement outerParameter = _enclosingParameter;
2283 try { 2312 try {
2284 _enclosingParameter = element; 2313 _enclosingParameter = element;
2285 return super.visitFunctionTypedFormalParameter(node); 2314 super.visitFunctionTypedFormalParameter(node);
2315 _resolveMetadata(node.metadata, _enclosingParameter);
2316 return null;
2286 } finally { 2317 } finally {
2287 _enclosingParameter = outerParameter; 2318 _enclosingParameter = outerParameter;
2288 } 2319 }
2289 } else { 2320 } else {
2290 return super.visitFunctionTypedFormalParameter(node); 2321 return super.visitFunctionTypedFormalParameter(node);
2291 } 2322 }
2292 } 2323 }
2293 2324
2294 @override 2325 @override
2295 Object visitImportDirective(ImportDirective node) { 2326 Object visitImportDirective(ImportDirective node) {
2296 String uri = _getStringValue(node.uri); 2327 String uri = _getStringValue(node.uri);
2328 ImportElement importElement;
2297 if (uri != null) { 2329 if (uri != null) {
2298 LibraryElement library = _enclosingUnit.library; 2330 LibraryElement library = _enclosingUnit.library;
2299 ImportElement importElement = _findImport( 2331 importElement = _findImport(
2300 library.imports, 2332 library.imports,
2301 _enclosingUnit.context.sourceFactory 2333 _enclosingUnit.context.sourceFactory
2302 .resolveUri(_enclosingUnit.source, uri), 2334 .resolveUri(_enclosingUnit.source, uri),
2303 node.prefix); 2335 node.prefix);
2304 node.element = importElement; 2336 node.element = importElement;
2305 } 2337 }
2306 return super.visitImportDirective(node); 2338 super.visitImportDirective(node);
2339 _resolveMetadata(node.metadata, importElement);
2340 return null;
2307 } 2341 }
2308 2342
2309 @override 2343 @override
2310 Object visitLabeledStatement(LabeledStatement node) { 2344 Object visitLabeledStatement(LabeledStatement node) {
2311 for (Label label in node.labels) { 2345 for (Label label in node.labels) {
2312 SimpleIdentifier labelName = label.label; 2346 SimpleIdentifier labelName = label.label;
2313 _findIdentifier(_enclosingExecutable.labels, labelName); 2347 _findIdentifier(_enclosingExecutable.labels, labelName);
2314 } 2348 }
2315 return super.visitLabeledStatement(node); 2349 return super.visitLabeledStatement(node);
2316 } 2350 }
2317 2351
2318 @override 2352 @override
2319 Object visitLibraryDirective(LibraryDirective node) { 2353 Object visitLibraryDirective(LibraryDirective node) {
2320 node.element = _enclosingUnit.library; 2354 LibraryElement libraryElement = _enclosingUnit.library;
2321 return super.visitLibraryDirective(node); 2355 node.element = libraryElement;
2356 super.visitLibraryDirective(node);
2357 _resolveMetadata(node.metadata, libraryElement);
2358 return null;
2322 } 2359 }
2323 2360
2324 @override 2361 @override
2325 Object visitMethodDeclaration(MethodDeclaration node) { 2362 Object visitMethodDeclaration(MethodDeclaration node) {
2326 ExecutableElement outerExecutable = _enclosingExecutable; 2363 ExecutableElement outerExecutable = _enclosingExecutable;
2327 try { 2364 try {
2328 Token property = node.propertyKeyword; 2365 Token property = node.propertyKeyword;
2329 SimpleIdentifier methodName = node.name; 2366 SimpleIdentifier methodName = node.name;
2330 String nameOfMethod = methodName.name; 2367 String nameOfMethod = methodName.name;
2331 if (property == null) { 2368 if (property == null) {
2332 _enclosingExecutable = _findWithNameAndOffset( 2369 _enclosingExecutable = _findWithNameAndOffset(
2333 _enclosingClass.methods, nameOfMethod, methodName.offset); 2370 _enclosingClass.methods, nameOfMethod, methodName.offset);
2334 methodName.staticElement = _enclosingExecutable; 2371 methodName.staticElement = _enclosingExecutable;
2335 } else { 2372 } else {
2336 PropertyAccessorElement accessor = 2373 PropertyAccessorElement accessor =
2337 _findIdentifier(_enclosingClass.accessors, methodName); 2374 _findIdentifier(_enclosingClass.accessors, methodName);
2338 if ((property as KeywordToken).keyword == Keyword.SET) { 2375 if ((property as KeywordToken).keyword == Keyword.SET) {
2339 accessor = accessor.variable.setter; 2376 accessor = accessor.variable.setter;
2340 methodName.staticElement = accessor; 2377 methodName.staticElement = accessor;
2341 } 2378 }
2342 _enclosingExecutable = accessor; 2379 _enclosingExecutable = accessor;
2343 } 2380 }
2344 return super.visitMethodDeclaration(node); 2381 super.visitMethodDeclaration(node);
2382 _resolveMetadata(node.metadata, _enclosingExecutable);
2383 return null;
2345 } finally { 2384 } finally {
2346 _enclosingExecutable = outerExecutable; 2385 _enclosingExecutable = outerExecutable;
2347 } 2386 }
2348 } 2387 }
2349 2388
2350 @override 2389 @override
2351 Object visitPartDirective(PartDirective node) { 2390 Object visitPartDirective(PartDirective node) {
2352 String uri = _getStringValue(node.uri); 2391 String uri = _getStringValue(node.uri);
2392 CompilationUnitElement compilationUnitElement;
2353 if (uri != null) { 2393 if (uri != null) {
2354 Source partSource = _enclosingUnit.context.sourceFactory 2394 Source partSource = _enclosingUnit.context.sourceFactory
2355 .resolveUri(_enclosingUnit.source, uri); 2395 .resolveUri(_enclosingUnit.source, uri);
2356 node.element = _findPart(_enclosingUnit.library.parts, partSource); 2396 compilationUnitElement =
2397 _findPart(_enclosingUnit.library.parts, partSource);
2398 node.element = compilationUnitElement;
2357 } 2399 }
2358 return super.visitPartDirective(node); 2400 super.visitPartDirective(node);
2401 _resolveMetadata(node.metadata, compilationUnitElement);
2402 return null;
2359 } 2403 }
2360 2404
2361 @override 2405 @override
2362 Object visitPartOfDirective(PartOfDirective node) { 2406 Object visitPartOfDirective(PartOfDirective node) {
2363 node.element = _enclosingUnit.library; 2407 node.element = _enclosingUnit.library;
2364 return super.visitPartOfDirective(node); 2408 return super.visitPartOfDirective(node);
2365 } 2409 }
2366 2410
2367 @override 2411 @override
2368 Object visitSimpleFormalParameter(SimpleFormalParameter node) { 2412 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
2369 if (node.parent is! DefaultFormalParameter) { 2413 if (node.parent is! DefaultFormalParameter) {
2370 SimpleIdentifier parameterName = node.identifier; 2414 SimpleIdentifier parameterName = node.identifier;
2371 ParameterElement element = _getElementForParameter(node, parameterName); 2415 ParameterElement element = _getElementForParameter(node, parameterName);
2372 ParameterElement outerParameter = _enclosingParameter; 2416 ParameterElement outerParameter = _enclosingParameter;
2373 try { 2417 try {
2374 _enclosingParameter = element; 2418 _enclosingParameter = element;
2375 return super.visitSimpleFormalParameter(node); 2419 super.visitSimpleFormalParameter(node);
2420 _resolveMetadata(node.metadata, element);
2421 return null;
2376 } finally { 2422 } finally {
2377 _enclosingParameter = outerParameter; 2423 _enclosingParameter = outerParameter;
2378 } 2424 }
2379 } else {} 2425 } else {}
2380 return super.visitSimpleFormalParameter(node); 2426 return super.visitSimpleFormalParameter(node);
2381 } 2427 }
2382 2428
2383 @override 2429 @override
2384 Object visitSwitchCase(SwitchCase node) { 2430 Object visitSwitchCase(SwitchCase node) {
2385 for (Label label in node.labels) { 2431 for (Label label in node.labels) {
2386 SimpleIdentifier labelName = label.label; 2432 SimpleIdentifier labelName = label.label;
2387 _findIdentifier(_enclosingExecutable.labels, labelName); 2433 _findIdentifier(_enclosingExecutable.labels, labelName);
2388 } 2434 }
2389 return super.visitSwitchCase(node); 2435 return super.visitSwitchCase(node);
2390 } 2436 }
2391 2437
2392 @override 2438 @override
2393 Object visitSwitchDefault(SwitchDefault node) { 2439 Object visitSwitchDefault(SwitchDefault node) {
2394 for (Label label in node.labels) { 2440 for (Label label in node.labels) {
2395 SimpleIdentifier labelName = label.label; 2441 SimpleIdentifier labelName = label.label;
2396 _findIdentifier(_enclosingExecutable.labels, labelName); 2442 _findIdentifier(_enclosingExecutable.labels, labelName);
2397 } 2443 }
2398 return super.visitSwitchDefault(node); 2444 return super.visitSwitchDefault(node);
2399 } 2445 }
2400 2446
2401 @override 2447 @override
2448 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
2449 super.visitTopLevelVariableDeclaration(node);
2450 _resolveMetadata(node.metadata, node.variables.variables[0].element);
2451 return null;
2452 }
2453
2454 @override
2402 Object visitTypeParameter(TypeParameter node) { 2455 Object visitTypeParameter(TypeParameter node) {
2403 SimpleIdentifier parameterName = node.name; 2456 SimpleIdentifier parameterName = node.name;
2404 2457
2405 Element element; 2458 Element element;
2406 if (_enclosingExecutable != null) { 2459 if (_enclosingExecutable != null) {
2407 element = 2460 element =
2408 _findIdentifier(_enclosingExecutable.typeParameters, parameterName); 2461 _findIdentifier(_enclosingExecutable.typeParameters, parameterName);
2409 } 2462 }
2410 if (element == null) { 2463 if (element == null) {
2411 if (_enclosingClass != null) { 2464 if (_enclosingClass != null) {
2412 _findIdentifier(_enclosingClass.typeParameters, parameterName); 2465 element =
2466 _findIdentifier(_enclosingClass.typeParameters, parameterName);
2413 } else if (_enclosingAlias != null) { 2467 } else if (_enclosingAlias != null) {
2414 _findIdentifier(_enclosingAlias.typeParameters, parameterName); 2468 element =
2469 _findIdentifier(_enclosingAlias.typeParameters, parameterName);
2415 } 2470 }
2416 } 2471 }
2417 return super.visitTypeParameter(node); 2472 super.visitTypeParameter(node);
2473 _resolveMetadata(node.metadata, element);
2474 return null;
2418 } 2475 }
2419 2476
2420 @override 2477 @override
2421 Object visitVariableDeclaration(VariableDeclaration node) { 2478 Object visitVariableDeclaration(VariableDeclaration node) {
2422 VariableElement element = null; 2479 VariableElement element = null;
2423 SimpleIdentifier variableName = node.name; 2480 SimpleIdentifier variableName = node.name;
2424 if (_enclosingExecutable != null) { 2481 if (_enclosingExecutable != null) {
2425 element = 2482 element =
2426 _findIdentifier(_enclosingExecutable.localVariables, variableName); 2483 _findIdentifier(_enclosingExecutable.localVariables, variableName);
2427 } 2484 }
(...skipping 13 matching lines...) Expand all
2441 _enclosingExecutable = element.initializer; 2498 _enclosingExecutable = element.initializer;
2442 } 2499 }
2443 return super.visitVariableDeclaration(node); 2500 return super.visitVariableDeclaration(node);
2444 } finally { 2501 } finally {
2445 _enclosingExecutable = outerExecutable; 2502 _enclosingExecutable = outerExecutable;
2446 } 2503 }
2447 } 2504 }
2448 return super.visitVariableDeclaration(node); 2505 return super.visitVariableDeclaration(node);
2449 } 2506 }
2450 2507
2508 @override
2509 Object visitVariableDeclarationList(VariableDeclarationList node) {
2510 super.visitVariableDeclarationList(node);
2511 if (node.parent is! FieldDeclaration &&
2512 node.parent is! TopLevelVariableDeclaration) {
2513 _resolveMetadata(node.metadata, node.variables[0].element);
2514 }
2515 return null;
2516 }
2517
2451 /** 2518 /**
2452 * Return the element in the given array of elements that was created for the declaration at the 2519 * 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 2520 * given offset. This method should only be used when there is no name
2454 * 2521 *
2455 * @param elements the elements of the appropriate kind that exist in the curr ent context 2522 * @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 2523 * @param offset the offset of the name of the element to be returned
2457 * @return the element at the given offset 2524 * @return the element at the given offset
2458 */ 2525 */
2459 Element _findAtOffset(List<Element> elements, int offset) => 2526 Element _findAtOffset(List<Element> elements, int offset) =>
2460 _findWithNameAndOffset(elements, "", offset); 2527 _findWithNameAndOffset(elements, "", offset);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
2604 * 2671 *
2605 * @param literal the string literal whose value is to be returned 2672 * @param literal the string literal whose value is to be returned
2606 * @return the value of the given string literal 2673 * @return the value of the given string literal
2607 */ 2674 */
2608 String _getStringValue(StringLiteral literal) { 2675 String _getStringValue(StringLiteral literal) {
2609 if (literal is StringInterpolation) { 2676 if (literal is StringInterpolation) {
2610 return null; 2677 return null;
2611 } 2678 }
2612 return literal.stringValue; 2679 return literal.stringValue;
2613 } 2680 }
2681
2682 /**
2683 * If [element] is not `null`, associate each [Annotation] in [astMetadata]
2684 * with the corresponding [ElementAnnotation] in [element.metadata].
2685 *
2686 * If [element] is `null`, do nothing--this allows us to be robust in the
2687 * case where we are operating on an element model that hasn't been fully
2688 * built.
2689 */
2690 void _resolveMetadata(NodeList<Annotation> astMetadata, Element element) {
2691 if (element != null) {
2692 List<ElementAnnotation> elementMetadata = element.metadata;
2693 assert(astMetadata.length == elementMetadata.length);
2694 for (int i = 0; i < astMetadata.length; i++) {
2695 astMetadata[i].elementAnnotation = elementMetadata[i];
2696 }
2697 }
2698 }
2614 } 2699 }
2615 2700
2616 /** 2701 /**
2617 * Instances of the class `ElementHolder` hold on to elements created while trav ersing an AST 2702 * 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. 2703 * structure so that they can be accessed when creating their enclosing element.
2619 */ 2704 */
2620 class ElementHolder { 2705 class ElementHolder {
2621 List<PropertyAccessorElement> _accessors; 2706 List<PropertyAccessorElement> _accessors;
2622 2707
2623 List<ConstructorElement> _constructors; 2708 List<ConstructorElement> _constructors;
(...skipping 9878 matching lines...) Expand 10 before | Expand all | Expand 10 after
12502 nonFields.add(node); 12587 nonFields.add(node);
12503 return null; 12588 return null;
12504 } 12589 }
12505 12590
12506 @override 12591 @override
12507 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); 12592 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this);
12508 12593
12509 @override 12594 @override
12510 Object visitWithClause(WithClause node) => null; 12595 Object visitWithClause(WithClause node) => null;
12511 } 12596 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/declaration_resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698