OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 domains.analysis.navigation_dart; | 5 library domains.analysis.navigation_dart; |
6 | 6 |
7 import 'package:analysis_server/analysis/navigation_core.dart'; | 7 import 'package:analysis_server/analysis/navigation_core.dart'; |
8 import 'package:analysis_server/src/protocol_server.dart' as protocol; | 8 import 'package:analysis_server/src/protocol_server.dart' as protocol; |
9 import 'package:analyzer/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 collector.addRegion(offset, length, kind, location); | 67 collector.addRegion(offset, length, kind, location); |
68 } | 68 } |
69 | 69 |
70 void _addRegion_nodeStart_nodeEnd(AstNode a, AstNode b, Element element) { | 70 void _addRegion_nodeStart_nodeEnd(AstNode a, AstNode b, Element element) { |
71 int offset = a.offset; | 71 int offset = a.offset; |
72 int length = b.end - offset; | 72 int length = b.end - offset; |
73 _addRegion(offset, length, element); | 73 _addRegion(offset, length, element); |
74 } | 74 } |
75 | 75 |
76 void _addRegionForNode(AstNode node, Element element) { | 76 void _addRegionForNode(AstNode node, Element element) { |
| 77 if (node == null) { |
| 78 return; |
| 79 } |
77 int offset = node.offset; | 80 int offset = node.offset; |
78 int length = node.length; | 81 int length = node.length; |
79 _addRegion(offset, length, element); | 82 _addRegion(offset, length, element); |
80 } | 83 } |
81 | 84 |
82 void _addRegionForToken(Token token, Element element) { | 85 void _addRegionForToken(Token token, Element element) { |
83 int offset = token.offset; | 86 int offset = token.offset; |
84 int length = token.length; | 87 int length = token.length; |
85 _addRegion(offset, length, element); | 88 _addRegion(offset, length, element); |
86 } | 89 } |
87 } | 90 } |
88 | 91 |
89 class _DartNavigationComputerVisitor extends RecursiveAstVisitor { | 92 class _DartNavigationComputerVisitor extends RecursiveAstVisitor { |
90 final _DartNavigationCollector computer; | 93 final _DartNavigationCollector computer; |
91 | 94 |
92 _DartNavigationComputerVisitor(this.computer); | 95 _DartNavigationComputerVisitor(this.computer); |
93 | 96 |
94 @override | 97 @override |
| 98 visitAnnotation(Annotation node) { |
| 99 Element element = node.element; |
| 100 if (element is ConstructorElement && element.isSynthetic) { |
| 101 element = element.enclosingElement; |
| 102 } |
| 103 Identifier name = node.name; |
| 104 if (name is PrefixedIdentifier) { |
| 105 // use constructor in: @PrefixClass.constructorName |
| 106 Element prefixElement = name.prefix.staticElement; |
| 107 if (prefixElement is ClassElement) { |
| 108 prefixElement = element; |
| 109 } |
| 110 computer._addRegionForNode(name.prefix, prefixElement); |
| 111 // always constructor |
| 112 computer._addRegionForNode(name.identifier, element); |
| 113 } else { |
| 114 computer._addRegionForNode(name, element); |
| 115 } |
| 116 computer._addRegionForNode(node.constructorName, element); |
| 117 // arguments |
| 118 _safelyVisit(node.arguments); |
| 119 } |
| 120 |
| 121 @override |
95 visitAssignmentExpression(AssignmentExpression node) { | 122 visitAssignmentExpression(AssignmentExpression node) { |
96 _safelyVisit(node.leftHandSide); | 123 _safelyVisit(node.leftHandSide); |
97 computer._addRegionForToken(node.operator, node.bestElement); | 124 computer._addRegionForToken(node.operator, node.bestElement); |
98 _safelyVisit(node.rightHandSide); | 125 _safelyVisit(node.rightHandSide); |
99 } | 126 } |
100 | 127 |
101 @override | 128 @override |
102 visitBinaryExpression(BinaryExpression node) { | 129 visitBinaryExpression(BinaryExpression node) { |
103 _safelyVisit(node.leftOperand); | 130 _safelyVisit(node.leftOperand); |
104 computer._addRegionForToken(node.operator, node.bestElement); | 131 computer._addRegionForToken(node.operator, node.bestElement); |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 } | 327 } |
301 // The node starts or ends in the range. | 328 // The node starts or ends in the range. |
302 if (isInRange(node.offset) || isInRange(node.end)) { | 329 if (isInRange(node.offset) || isInRange(node.end)) { |
303 node.accept(visitor); | 330 node.accept(visitor); |
304 return; | 331 return; |
305 } | 332 } |
306 // Go deeper. | 333 // Go deeper. |
307 super.visitNode(node); | 334 super.visitNode(node); |
308 } | 335 } |
309 } | 336 } |
OLD | NEW |