| 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 computer.navigation; | 5 library computer.navigation; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/protocol.dart' as protocol; | 7 import 'package:analysis_server/src/protocol.dart' as protocol; |
| 8 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
| 9 import 'package:analyzer/src/generated/element.dart'; | 9 import 'package:analyzer/src/generated/element.dart'; |
| 10 import 'package:analyzer/src/generated/scanner.dart'; | 10 import 'package:analyzer/src/generated/scanner.dart'; |
| 11 | 11 |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * A computer for navigation regions in a Dart [CompilationUnit]. | 14 * A computer for navigation regions in a Dart [CompilationUnit]. |
| 15 */ | 15 */ |
| 16 class DartUnitNavigationComputer { | 16 class DartUnitNavigationComputer { |
| 17 final CompilationUnit _unit; | 17 final CompilationUnit _unit; |
| 18 | 18 |
| 19 final List<protocol.NavigationRegion> _regions = <protocol.NavigationRegion>[]
; | 19 final List<protocol.NavigationRegion> _regions = <protocol.NavigationRegion>[ |
| 20 ]; |
| 20 | 21 |
| 21 DartUnitNavigationComputer(this._unit); | 22 DartUnitNavigationComputer(this._unit); |
| 22 | 23 |
| 23 /** | 24 /** |
| 24 * Returns the computed navigation regions, not `null`. | 25 * Returns the computed navigation regions, not `null`. |
| 25 */ | 26 */ |
| 26 List<protocol.NavigationRegion> compute() { | 27 List<protocol.NavigationRegion> compute() { |
| 27 _unit.accept(new _DartUnitNavigationComputerVisitor(this)); | 28 _unit.accept(new _DartUnitNavigationComputerVisitor(this)); |
| 28 return new List.from(_regions); | 29 return new List.from(_regions); |
| 29 } | 30 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 130 |
| 130 @override | 131 @override |
| 131 visitIndexExpression(IndexExpression node) { | 132 visitIndexExpression(IndexExpression node) { |
| 132 computer._addRegionForToken(node.rightBracket, node.bestElement); | 133 computer._addRegionForToken(node.rightBracket, node.bestElement); |
| 133 return super.visitIndexExpression(node); | 134 return super.visitIndexExpression(node); |
| 134 } | 135 } |
| 135 | 136 |
| 136 @override | 137 @override |
| 137 visitInstanceCreationExpression(InstanceCreationExpression node) { | 138 visitInstanceCreationExpression(InstanceCreationExpression node) { |
| 138 Element element = node.staticElement; | 139 Element element = node.staticElement; |
| 139 if (element != null && element.isSynthetic) { | 140 ConstructorName constructorName = node.constructorName; |
| 140 element = element.enclosingElement; | 141 if (element != null && constructorName != null) { |
| 142 ClassElement classElement = element.enclosingElement; |
| 143 if (element.isSynthetic) { |
| 144 element = classElement; |
| 145 computer._addRegion_nodeStart_nodeStart( |
| 146 node, |
| 147 node.argumentList, |
| 148 element); |
| 149 } else { |
| 150 // add region for "type" first, so that it is found before "new " |
| 151 computer._addRegionForNode(constructorName.type, classElement); |
| 152 // "new " |
| 153 computer._addRegion_nodeStart_nodeStart( |
| 154 node, |
| 155 constructorName.type, |
| 156 element); |
| 157 // optional ".name" |
| 158 if (constructorName.period != null) { |
| 159 computer._addRegion_tokenStart_nodeEnd( |
| 160 constructorName.period, |
| 161 constructorName, |
| 162 element); |
| 163 } |
| 164 } |
| 141 } | 165 } |
| 142 computer._addRegion_nodeStart_nodeStart(node, node.argumentList, element); | |
| 143 return super.visitInstanceCreationExpression(node); | 166 return super.visitInstanceCreationExpression(node); |
| 144 } | 167 } |
| 145 | 168 |
| 146 @override | 169 @override |
| 147 visitPartDirective(PartDirective node) { | 170 visitPartDirective(PartDirective node) { |
| 148 computer._addRegion_tokenStart_nodeEnd( | 171 computer._addRegion_tokenStart_nodeEnd( |
| 149 node.keyword, | 172 node.keyword, |
| 150 node.uri, | 173 node.uri, |
| 151 node.element); | 174 node.element); |
| 152 return super.visitPartDirective(node); | 175 return super.visitPartDirective(node); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 175 | 198 |
| 176 @override | 199 @override |
| 177 visitSimpleIdentifier(SimpleIdentifier node) { | 200 visitSimpleIdentifier(SimpleIdentifier node) { |
| 178 if (node.parent is ConstructorDeclaration) { | 201 if (node.parent is ConstructorDeclaration) { |
| 179 } else { | 202 } else { |
| 180 computer._addRegionForNode(node, node.bestElement); | 203 computer._addRegionForNode(node, node.bestElement); |
| 181 } | 204 } |
| 182 return super.visitSimpleIdentifier(node); | 205 return super.visitSimpleIdentifier(node); |
| 183 } | 206 } |
| 184 } | 207 } |
| OLD | NEW |