| 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.dart.element.builder; | 5 library analyzer.src.dart.element.builder; |
| 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 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 element.typeParameters = holder.typeParameters; | 688 element.typeParameters = holder.typeParameters; |
| 689 if (body.isAsynchronous) { | 689 if (body.isAsynchronous) { |
| 690 element.asynchronous = true; | 690 element.asynchronous = true; |
| 691 } | 691 } |
| 692 if (body.isGenerator) { | 692 if (body.isGenerator) { |
| 693 element.generator = true; | 693 element.generator = true; |
| 694 } | 694 } |
| 695 if (_inFunction) { | 695 if (_inFunction) { |
| 696 Block enclosingBlock = node.getAncestor((node) => node is Block); | 696 Block enclosingBlock = node.getAncestor((node) => node is Block); |
| 697 if (enclosingBlock != null) { | 697 if (enclosingBlock != null) { |
| 698 element.setVisibleRange(enclosingBlock.offset, enclosingBlock.length
); | 698 element.setVisibleRange( |
| 699 enclosingBlock.offset, enclosingBlock.length); |
| 699 } | 700 } |
| 700 } | 701 } |
| 701 if (node.returnType == null) { | 702 if (node.returnType == null) { |
| 702 element.hasImplicitReturnType = true; | 703 element.hasImplicitReturnType = true; |
| 703 } | 704 } |
| 704 _currentHolder.addFunction(element); | 705 _currentHolder.addFunction(element); |
| 705 expression.element = element; | 706 expression.element = element; |
| 706 functionName.staticElement = element; | 707 functionName.staticElement = element; |
| 707 } else { | 708 } else { |
| 708 SimpleIdentifier propertyNameNode = node.name; | 709 SimpleIdentifier propertyNameNode = node.name; |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1311 typeParameters[i] as TypeParameterElementImpl; | 1312 typeParameters[i] as TypeParameterElementImpl; |
| 1312 TypeParameterTypeImpl typeParameterType = | 1313 TypeParameterTypeImpl typeParameterType = |
| 1313 new TypeParameterTypeImpl(typeParameter); | 1314 new TypeParameterTypeImpl(typeParameter); |
| 1314 typeParameter.type = typeParameterType; | 1315 typeParameter.type = typeParameterType; |
| 1315 typeArguments[i] = typeParameterType; | 1316 typeArguments[i] = typeParameterType; |
| 1316 } | 1317 } |
| 1317 return typeArguments; | 1318 return typeArguments; |
| 1318 } | 1319 } |
| 1319 | 1320 |
| 1320 /** | 1321 /** |
| 1321 * Return the body of the function that contains the given parameter, or `null
` if no | 1322 * Return the body of the function that contains the given [parameter], or |
| 1322 * function body could be found. | 1323 * `null` if no function body could be found. |
| 1323 * | |
| 1324 * @param node the parameter contained in the function whose body is to be ret
urned | |
| 1325 * @return the body of the function that contains the given parameter | |
| 1326 */ | 1324 */ |
| 1327 FunctionBody _getFunctionBody(FormalParameter node) { | 1325 FunctionBody _getFunctionBody(FormalParameter parameter) { |
| 1328 AstNode parent = node.parent; | 1326 AstNode parent = parameter?.parent?.parent; |
| 1329 while (parent != null) { | 1327 if (parent is ConstructorDeclaration) { |
| 1330 if (parent is ConstructorDeclaration) { | 1328 return parent.body; |
| 1331 return parent.body; | 1329 } else if (parent is FunctionExpression) { |
| 1332 } else if (parent is FunctionExpression) { | 1330 return parent.body; |
| 1333 return parent.body; | 1331 } else if (parent is MethodDeclaration) { |
| 1334 } else if (parent is MethodDeclaration) { | 1332 return parent.body; |
| 1335 return parent.body; | |
| 1336 } | |
| 1337 parent = parent.parent; | |
| 1338 } | 1333 } |
| 1339 return null; | 1334 return null; |
| 1340 } | 1335 } |
| 1341 | 1336 |
| 1342 /** | 1337 /** |
| 1343 * If the given [node] has a documentation comment, remember its content | 1338 * If the given [node] has a documentation comment, remember its content |
| 1344 * and range into the given [element]. | 1339 * and range into the given [element]. |
| 1345 */ | 1340 */ |
| 1346 void _setDoc(ElementImpl element, AnnotatedNode node) { | 1341 void _setDoc(ElementImpl element, AnnotatedNode node) { |
| 1347 Comment comment = node.documentationComment; | 1342 Comment comment = node.documentationComment; |
| 1348 if (comment != null && comment.isDocumentation) { | 1343 if (comment != null && comment.isDocumentation) { |
| 1349 element.documentationComment = | 1344 element.documentationComment = |
| 1350 comment.tokens.map((Token t) => t.lexeme).join('\n'); | 1345 comment.tokens.map((Token t) => t.lexeme).join('\n'); |
| 1351 element.setDocRange(comment.offset, comment.length); | 1346 element.setDocRange(comment.offset, comment.length); |
| 1352 } | 1347 } |
| 1353 } | 1348 } |
| 1354 | 1349 |
| 1355 /** | 1350 /** |
| 1356 * Sets the visible source range for formal parameter. | 1351 * Sets the visible source range for formal parameter. |
| 1357 */ | 1352 */ |
| 1358 void _setParameterVisibleRange( | 1353 void _setParameterVisibleRange( |
| 1359 FormalParameter node, ParameterElementImpl element) { | 1354 FormalParameter node, ParameterElementImpl element) { |
| 1360 FunctionBody body = _getFunctionBody(node); | 1355 FunctionBody body = _getFunctionBody(node); |
| 1361 if (body != null) { | 1356 if (body is BlockFunctionBody || body is ExpressionFunctionBody) { |
| 1362 element.setVisibleRange(body.offset, body.length); | 1357 element.setVisibleRange(body.offset, body.length); |
| 1363 } | 1358 } |
| 1364 } | 1359 } |
| 1365 | 1360 |
| 1366 /** | 1361 /** |
| 1367 * Make the given holder be the current holder while visiting the given node. | 1362 * Make the given holder be the current holder while visiting the given node. |
| 1368 * | 1363 * |
| 1369 * @param holder the holder that will gather elements that are built while vis
iting the children | 1364 * @param holder the holder that will gather elements that are built while vis
iting the children |
| 1370 * @param node the node to be visited | 1365 * @param node the node to be visited |
| 1371 */ | 1366 */ |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1451 return null; | 1446 return null; |
| 1452 } | 1447 } |
| 1453 | 1448 |
| 1454 /** | 1449 /** |
| 1455 * Return the lexical identifiers associated with the given [identifiers]. | 1450 * Return the lexical identifiers associated with the given [identifiers]. |
| 1456 */ | 1451 */ |
| 1457 static List<String> _getIdentifiers(NodeList<SimpleIdentifier> identifiers) { | 1452 static List<String> _getIdentifiers(NodeList<SimpleIdentifier> identifiers) { |
| 1458 return identifiers.map((identifier) => identifier.name).toList(); | 1453 return identifiers.map((identifier) => identifier.name).toList(); |
| 1459 } | 1454 } |
| 1460 } | 1455 } |
| OLD | NEW |