| 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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library service.computers; | 8 library service.computers; |
| 9 | 9 |
| 10 import 'package:analyzer/src/generated/java_core.dart' show JavaStringBuilder, S
tringUtils; | 10 import 'package:analyzer/src/generated/java_core.dart' show JavaStringBuilder, S
tringUtils; |
| 11 import 'package:analyzer/src/generated/java_engine.dart'; | 11 import 'package:analyzer/src/generated/java_engine.dart'; |
| 12 import 'package:analyzer/src/generated/source.dart' show Source; | 12 import 'package:analyzer/src/generated/source.dart' show Source; |
| 13 import 'package:analyzer/src/generated/scanner.dart' show Token; | 13 import 'package:analyzer/src/generated/scanner.dart' show Token; |
| 14 import 'package:analyzer/src/generated/ast.dart'; | 14 import 'package:analyzer/src/generated/ast.dart'; |
| 15 import 'package:analyzer/src/generated/element.dart'; | 15 import 'package:analyzer/src/generated/element.dart' as pae; |
| 16 import 'service_interfaces.dart'; | 16 import 'package:analyzer/src/generated/element.dart' show DartType; |
| 17 import 'package:analyzer/src/generated/source.dart'; |
| 18 import 'service_interfaces.dart' as psi; |
| 17 | 19 |
| 18 /** | 20 /** |
| 19 * A computer for [HighlightRegion]s in a Dart [CompilationUnit]. | 21 * A computer for [HighlightRegion]s in a Dart [CompilationUnit]. |
| 20 */ | 22 */ |
| 21 class DartUnitHighlightsComputer { | 23 class DartUnitHighlightsComputer { |
| 22 final CompilationUnit _unit; | 24 final CompilationUnit _unit; |
| 23 | 25 |
| 24 List<HighlightRegion> _regions = []; | 26 List<psi.HighlightRegion> _regions = []; |
| 25 | 27 |
| 26 DartUnitHighlightsComputer(this._unit); | 28 DartUnitHighlightsComputer(this._unit); |
| 27 | 29 |
| 28 /** | 30 /** |
| 29 * Returns the computed [HighlightRegion]s, not `null`. | 31 * Returns the computed [HighlightRegion]s, not `null`. |
| 30 */ | 32 */ |
| 31 List<HighlightRegion> compute() { | 33 List<psi.HighlightRegion> compute() { |
| 32 _unit.accept(new RecursiveAstVisitor_DartUnitHighlightsComputer_compute(this
)); | 34 _unit.accept(new RecursiveAstVisitor_DartUnitHighlightsComputer_compute(this
)); |
| 33 return new List.from(_regions); | 35 return new List.from(_regions); |
| 34 } | 36 } |
| 35 | 37 |
| 36 void _addIdentifierRegion(SimpleIdentifier node) { | 38 void _addIdentifierRegion(SimpleIdentifier node) { |
| 37 if (_addIdentifierRegion_keyword(node)) { | 39 if (_addIdentifierRegion_keyword(node)) { |
| 38 return; | 40 return; |
| 39 } | 41 } |
| 40 if (_addIdentifierRegion_class(node)) { | 42 if (_addIdentifierRegion_class(node)) { |
| 41 return; | 43 return; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 69 } | 71 } |
| 70 if (_addIdentifierRegion_parameter(node)) { | 72 if (_addIdentifierRegion_parameter(node)) { |
| 71 return; | 73 return; |
| 72 } | 74 } |
| 73 if (_addIdentifierRegion_topLevelVariable(node)) { | 75 if (_addIdentifierRegion_topLevelVariable(node)) { |
| 74 return; | 76 return; |
| 75 } | 77 } |
| 76 if (_addIdentifierRegion_typeParameter(node)) { | 78 if (_addIdentifierRegion_typeParameter(node)) { |
| 77 return; | 79 return; |
| 78 } | 80 } |
| 79 _addRegion_node(node, HighlightType.IDENTIFIER_DEFAULT); | 81 _addRegion_node(node, psi.HighlightType.IDENTIFIER_DEFAULT); |
| 80 } | 82 } |
| 81 | 83 |
| 82 void _addIdentifierRegion_annotation(Annotation node) { | 84 void _addIdentifierRegion_annotation(Annotation node) { |
| 83 ArgumentList arguments = node.arguments; | 85 ArgumentList arguments = node.arguments; |
| 84 if (arguments == null) { | 86 if (arguments == null) { |
| 85 _addRegion_node(node, HighlightType.ANNOTATION); | 87 _addRegion_node(node, psi.HighlightType.ANNOTATION); |
| 86 } else { | 88 } else { |
| 87 _addRegion_nodeStart_tokenEnd(node, arguments.beginToken, HighlightType.AN
NOTATION); | 89 _addRegion_nodeStart_tokenEnd(node, arguments.beginToken, psi.HighlightTyp
e.ANNOTATION); |
| 88 _addRegion_token(arguments.endToken, HighlightType.ANNOTATION); | 90 _addRegion_token(arguments.endToken, psi.HighlightType.ANNOTATION); |
| 89 } | 91 } |
| 90 } | 92 } |
| 91 | 93 |
| 92 bool _addIdentifierRegion_class(SimpleIdentifier node) { | 94 bool _addIdentifierRegion_class(SimpleIdentifier node) { |
| 93 Element element = node.staticElement; | 95 pae.Element element = node.staticElement; |
| 94 if (element is! ClassElement) { | 96 if (element is! pae.ClassElement) { |
| 95 return false; | 97 return false; |
| 96 } | 98 } |
| 97 return _addRegion_node(node, HighlightType.CLASS); | 99 return _addRegion_node(node, psi.HighlightType.CLASS); |
| 98 } | 100 } |
| 99 | 101 |
| 100 bool _addIdentifierRegion_constructor(SimpleIdentifier node) { | 102 bool _addIdentifierRegion_constructor(SimpleIdentifier node) { |
| 101 Element element = node.staticElement; | 103 pae.Element element = node.staticElement; |
| 102 if (element is! ConstructorElement) { | 104 if (element is! pae.ConstructorElement) { |
| 103 return false; | 105 return false; |
| 104 } | 106 } |
| 105 return _addRegion_node(node, HighlightType.CONSTRUCTOR); | 107 return _addRegion_node(node, psi.HighlightType.CONSTRUCTOR); |
| 106 } | 108 } |
| 107 | 109 |
| 108 bool _addIdentifierRegion_dynamicType(SimpleIdentifier node) { | 110 bool _addIdentifierRegion_dynamicType(SimpleIdentifier node) { |
| 109 // should be variable | 111 // should be variable |
| 110 Element element = node.staticElement; | 112 pae.Element element = node.staticElement; |
| 111 if (element is! VariableElement) { | 113 if (element is! pae.VariableElement) { |
| 112 return false; | 114 return false; |
| 113 } | 115 } |
| 114 // has propagated type | 116 // has propagated type |
| 115 if (node.propagatedType != null) { | 117 if (node.propagatedType != null) { |
| 116 return false; | 118 return false; |
| 117 } | 119 } |
| 118 // has dynamic static type | 120 // has dynamic static type |
| 119 DartType staticType = node.staticType; | 121 DartType staticType = node.staticType; |
| 120 if (staticType == null || !staticType.isDynamic) { | 122 if (staticType == null || !staticType.isDynamic) { |
| 121 return false; | 123 return false; |
| 122 } | 124 } |
| 123 // OK | 125 // OK |
| 124 return _addRegion_node(node, HighlightType.DYNAMIC_TYPE); | 126 return _addRegion_node(node, psi.HighlightType.DYNAMIC_TYPE); |
| 125 } | 127 } |
| 126 | 128 |
| 127 bool _addIdentifierRegion_field(SimpleIdentifier node) { | 129 bool _addIdentifierRegion_field(SimpleIdentifier node) { |
| 128 Element element = node.bestElement; | 130 pae.Element element = node.bestElement; |
| 129 if (element is FieldFormalParameterElement) { | 131 if (element is pae.FieldFormalParameterElement) { |
| 130 element = (element as FieldFormalParameterElement).field; | 132 element = (element as pae.FieldFormalParameterElement).field; |
| 131 } | 133 } |
| 132 if (element is FieldElement) { | 134 if (element is pae.FieldElement) { |
| 133 if ((element as FieldElement).isStatic) { | 135 if ((element as pae.FieldElement).isStatic) { |
| 134 return _addRegion_node(node, HighlightType.FIELD_STATIC); | 136 return _addRegion_node(node, psi.HighlightType.FIELD_STATIC); |
| 135 } else { | 137 } else { |
| 136 return _addRegion_node(node, HighlightType.FIELD); | 138 return _addRegion_node(node, psi.HighlightType.FIELD); |
| 137 } | 139 } |
| 138 } | 140 } |
| 139 if (element is PropertyAccessorElement) { | 141 if (element is pae.PropertyAccessorElement) { |
| 140 if ((element as PropertyAccessorElement).isStatic) { | 142 if ((element as pae.PropertyAccessorElement).isStatic) { |
| 141 return _addRegion_node(node, HighlightType.FIELD_STATIC); | 143 return _addRegion_node(node, psi.HighlightType.FIELD_STATIC); |
| 142 } else { | 144 } else { |
| 143 return _addRegion_node(node, HighlightType.FIELD); | 145 return _addRegion_node(node, psi.HighlightType.FIELD); |
| 144 } | 146 } |
| 145 } | 147 } |
| 146 return false; | 148 return false; |
| 147 } | 149 } |
| 148 | 150 |
| 149 bool _addIdentifierRegion_function(SimpleIdentifier node) { | 151 bool _addIdentifierRegion_function(SimpleIdentifier node) { |
| 150 Element element = node.staticElement; | 152 pae.Element element = node.staticElement; |
| 151 if (element is! FunctionElement) { | 153 if (element is! pae.FunctionElement) { |
| 152 return false; | 154 return false; |
| 153 } | 155 } |
| 154 HighlightType type; | 156 psi.HighlightType type; |
| 155 if (node.inDeclarationContext()) { | 157 if (node.inDeclarationContext()) { |
| 156 type = HighlightType.FUNCTION_DECLARATION; | 158 type = psi.HighlightType.FUNCTION_DECLARATION; |
| 157 } else { | 159 } else { |
| 158 type = HighlightType.FUNCTION; | 160 type = psi.HighlightType.FUNCTION; |
| 159 } | 161 } |
| 160 return _addRegion_node(node, type); | 162 return _addRegion_node(node, type); |
| 161 } | 163 } |
| 162 | 164 |
| 163 bool _addIdentifierRegion_functionTypeAlias(SimpleIdentifier node) { | 165 bool _addIdentifierRegion_functionTypeAlias(SimpleIdentifier node) { |
| 164 Element element = node.staticElement; | 166 pae.Element element = node.staticElement; |
| 165 if (element is! FunctionTypeAliasElement) { | 167 if (element is! pae.FunctionTypeAliasElement) { |
| 166 return false; | 168 return false; |
| 167 } | 169 } |
| 168 return _addRegion_node(node, HighlightType.FUNCTION_TYPE_ALIAS); | 170 return _addRegion_node(node, psi.HighlightType.FUNCTION_TYPE_ALIAS); |
| 169 } | 171 } |
| 170 | 172 |
| 171 bool _addIdentifierRegion_getterSetterDeclaration(SimpleIdentifier node) { | 173 bool _addIdentifierRegion_getterSetterDeclaration(SimpleIdentifier node) { |
| 172 // should be declaration | 174 // should be declaration |
| 173 AstNode parent = node.parent; | 175 AstNode parent = node.parent; |
| 174 if (!(parent is MethodDeclaration || parent is FunctionDeclaration)) { | 176 if (!(parent is MethodDeclaration || parent is FunctionDeclaration)) { |
| 175 return false; | 177 return false; |
| 176 } | 178 } |
| 177 // should be property accessor | 179 // should be property accessor |
| 178 Element element = node.staticElement; | 180 pae.Element element = node.staticElement; |
| 179 if (element is! PropertyAccessorElement) { | 181 if (element is! pae.PropertyAccessorElement) { |
| 180 return false; | 182 return false; |
| 181 } | 183 } |
| 182 // getter or setter | 184 // getter or setter |
| 183 PropertyAccessorElement propertyAccessorElement = element as PropertyAccesso
rElement; | 185 pae.PropertyAccessorElement propertyAccessorElement = element as pae.Propert
yAccessorElement; |
| 184 if (propertyAccessorElement.isGetter) { | 186 if (propertyAccessorElement.isGetter) { |
| 185 return _addRegion_node(node, HighlightType.GETTER_DECLARATION); | 187 return _addRegion_node(node, psi.HighlightType.GETTER_DECLARATION); |
| 186 } else { | 188 } else { |
| 187 return _addRegion_node(node, HighlightType.SETTER_DECLARATION); | 189 return _addRegion_node(node, psi.HighlightType.SETTER_DECLARATION); |
| 188 } | 190 } |
| 189 } | 191 } |
| 190 | 192 |
| 191 bool _addIdentifierRegion_importPrefix(SimpleIdentifier node) { | 193 bool _addIdentifierRegion_importPrefix(SimpleIdentifier node) { |
| 192 Element element = node.staticElement; | 194 pae.Element element = node.staticElement; |
| 193 if (element is! PrefixElement) { | 195 if (element is! pae.PrefixElement) { |
| 194 return false; | 196 return false; |
| 195 } | 197 } |
| 196 return _addRegion_node(node, HighlightType.IMPORT_PREFIX); | 198 return _addRegion_node(node, psi.HighlightType.IMPORT_PREFIX); |
| 197 } | 199 } |
| 198 | 200 |
| 199 bool _addIdentifierRegion_keyword(SimpleIdentifier node) { | 201 bool _addIdentifierRegion_keyword(SimpleIdentifier node) { |
| 200 String name = node.name; | 202 String name = node.name; |
| 201 if (name == "void") { | 203 if (name == "void") { |
| 202 return _addRegion_node(node, HighlightType.KEYWORD); | 204 return _addRegion_node(node, psi.HighlightType.KEYWORD); |
| 203 } | 205 } |
| 204 return false; | 206 return false; |
| 205 } | 207 } |
| 206 | 208 |
| 207 bool _addIdentifierRegion_localVariable(SimpleIdentifier node) { | 209 bool _addIdentifierRegion_localVariable(SimpleIdentifier node) { |
| 208 Element element = node.staticElement; | 210 pae.Element element = node.staticElement; |
| 209 if (element is! LocalVariableElement) { | 211 if (element is! pae.LocalVariableElement) { |
| 210 return false; | 212 return false; |
| 211 } | 213 } |
| 212 // OK | 214 // OK |
| 213 HighlightType type; | 215 psi.HighlightType type; |
| 214 if (node.inDeclarationContext()) { | 216 if (node.inDeclarationContext()) { |
| 215 type = HighlightType.LOCAL_VARIABLE_DECLARATION; | 217 type = psi.HighlightType.LOCAL_VARIABLE_DECLARATION; |
| 216 } else { | 218 } else { |
| 217 type = HighlightType.LOCAL_VARIABLE; | 219 type = psi.HighlightType.LOCAL_VARIABLE; |
| 218 } | 220 } |
| 219 return _addRegion_node(node, type); | 221 return _addRegion_node(node, type); |
| 220 } | 222 } |
| 221 | 223 |
| 222 bool _addIdentifierRegion_method(SimpleIdentifier node) { | 224 bool _addIdentifierRegion_method(SimpleIdentifier node) { |
| 223 Element element = node.bestElement; | 225 pae.Element element = node.bestElement; |
| 224 if (element is! MethodElement) { | 226 if (element is! pae.MethodElement) { |
| 225 return false; | 227 return false; |
| 226 } | 228 } |
| 227 MethodElement methodElement = element as MethodElement; | 229 pae.MethodElement methodElement = element as pae.MethodElement; |
| 228 bool isStatic = methodElement.isStatic; | 230 bool isStatic = methodElement.isStatic; |
| 229 // OK | 231 // OK |
| 230 HighlightType type; | 232 psi.HighlightType type; |
| 231 if (node.inDeclarationContext()) { | 233 if (node.inDeclarationContext()) { |
| 232 if (isStatic) { | 234 if (isStatic) { |
| 233 type = HighlightType.METHOD_DECLARATION_STATIC; | 235 type = psi.HighlightType.METHOD_DECLARATION_STATIC; |
| 234 } else { | 236 } else { |
| 235 type = HighlightType.METHOD_DECLARATION; | 237 type = psi.HighlightType.METHOD_DECLARATION; |
| 236 } | 238 } |
| 237 } else { | 239 } else { |
| 238 if (isStatic) { | 240 if (isStatic) { |
| 239 type = HighlightType.METHOD_STATIC; | 241 type = psi.HighlightType.METHOD_STATIC; |
| 240 } else { | 242 } else { |
| 241 type = HighlightType.METHOD; | 243 type = psi.HighlightType.METHOD; |
| 242 } | 244 } |
| 243 } | 245 } |
| 244 return _addRegion_node(node, type); | 246 return _addRegion_node(node, type); |
| 245 } | 247 } |
| 246 | 248 |
| 247 bool _addIdentifierRegion_parameter(SimpleIdentifier node) { | 249 bool _addIdentifierRegion_parameter(SimpleIdentifier node) { |
| 248 Element element = node.staticElement; | 250 pae.Element element = node.staticElement; |
| 249 if (element is! ParameterElement) { | 251 if (element is! pae.ParameterElement) { |
| 250 return false; | 252 return false; |
| 251 } | 253 } |
| 252 return _addRegion_node(node, HighlightType.PARAMETER); | 254 return _addRegion_node(node, psi.HighlightType.PARAMETER); |
| 253 } | 255 } |
| 254 | 256 |
| 255 bool _addIdentifierRegion_topLevelVariable(SimpleIdentifier node) { | 257 bool _addIdentifierRegion_topLevelVariable(SimpleIdentifier node) { |
| 256 Element element = node.staticElement; | 258 pae.Element element = node.staticElement; |
| 257 if (element is! TopLevelVariableElement) { | 259 if (element is! pae.TopLevelVariableElement) { |
| 258 return false; | 260 return false; |
| 259 } | 261 } |
| 260 return _addRegion_node(node, HighlightType.TOP_LEVEL_VARIABLE); | 262 return _addRegion_node(node, psi.HighlightType.TOP_LEVEL_VARIABLE); |
| 261 } | 263 } |
| 262 | 264 |
| 263 bool _addIdentifierRegion_typeParameter(SimpleIdentifier node) { | 265 bool _addIdentifierRegion_typeParameter(SimpleIdentifier node) { |
| 264 Element element = node.staticElement; | 266 pae.Element element = node.staticElement; |
| 265 if (element is! TypeParameterElement) { | 267 if (element is! pae.TypeParameterElement) { |
| 266 return false; | 268 return false; |
| 267 } | 269 } |
| 268 return _addRegion_node(node, HighlightType.TYPE_PARAMETER); | 270 return _addRegion_node(node, psi.HighlightType.TYPE_PARAMETER); |
| 269 } | 271 } |
| 270 | 272 |
| 271 void _addRegion(int offset, int length, HighlightType type) { | 273 void _addRegion(int offset, int length, psi.HighlightType type) { |
| 272 _regions.add(new HighlightRegionImpl(offset, length, type)); | 274 _regions.add(new HighlightRegionImpl(offset, length, type)); |
| 273 } | 275 } |
| 274 | 276 |
| 275 bool _addRegion_node(AstNode node, HighlightType type) { | 277 bool _addRegion_node(AstNode node, psi.HighlightType type) { |
| 276 int offset = node.offset; | 278 int offset = node.offset; |
| 277 int length = node.length; | 279 int length = node.length; |
| 278 _addRegion(offset, length, type); | 280 _addRegion(offset, length, type); |
| 279 return true; | 281 return true; |
| 280 } | 282 } |
| 281 | 283 |
| 282 void _addRegion_nodeStart_tokenEnd(AstNode a, Token b, HighlightType type) { | 284 void _addRegion_nodeStart_tokenEnd(AstNode a, Token b, psi.HighlightType type)
{ |
| 283 int offset = a.offset; | 285 int offset = a.offset; |
| 284 int end = b.end; | 286 int end = b.end; |
| 285 _addRegion(offset, end - offset, type); | 287 _addRegion(offset, end - offset, type); |
| 286 } | 288 } |
| 287 | 289 |
| 288 void _addRegion_token(Token token, HighlightType type) { | 290 void _addRegion_token(Token token, psi.HighlightType type) { |
| 289 if (token != null) { | 291 if (token != null) { |
| 290 int offset = token.offset; | 292 int offset = token.offset; |
| 291 int length = token.length; | 293 int length = token.length; |
| 292 _addRegion(offset, length, type); | 294 _addRegion(offset, length, type); |
| 293 } | 295 } |
| 294 } | 296 } |
| 295 | 297 |
| 296 void _addRegion_tokenStart_tokenEnd(Token a, Token b, HighlightType type) { | 298 void _addRegion_tokenStart_tokenEnd(Token a, Token b, psi.HighlightType type)
{ |
| 297 int offset = a.offset; | 299 int offset = a.offset; |
| 298 int end = b.end; | 300 int end = b.end; |
| 299 _addRegion(offset, end - offset, type); | 301 _addRegion(offset, end - offset, type); |
| 300 } | 302 } |
| 301 } | 303 } |
| 302 | 304 |
| 303 /** | 305 /** |
| 304 * A computer for [NavigationRegion]s in a Dart [CompilationUnit]. | 306 * A computer for [NavigationRegion]s in a Dart [CompilationUnit]. |
| 305 */ | 307 */ |
| 306 class DartUnitNavigationComputer { | 308 class DartUnitNavigationComputer { |
| 307 final CompilationUnit _unit; | 309 final CompilationUnit _unit; |
| 308 | 310 |
| 309 List<NavigationRegion> _regions = []; | 311 List<psi.NavigationRegion> _regions = []; |
| 310 | 312 |
| 311 DartUnitNavigationComputer(this._unit); | 313 DartUnitNavigationComputer(this._unit); |
| 312 | 314 |
| 313 /** | 315 /** |
| 314 * Returns the computed [NavigationRegion]s, not `null`. | 316 * Returns the computed [NavigationRegion]s, not `null`. |
| 315 */ | 317 */ |
| 316 List<NavigationRegion> compute() { | 318 List<psi.NavigationRegion> compute() { |
| 317 _unit.accept(new RecursiveAstVisitor_DartUnitNavigationComputer_compute(this
)); | 319 _unit.accept(new RecursiveAstVisitor_DartUnitNavigationComputer_compute(this
)); |
| 318 return new List.from(_regions); | 320 return new List.from(_regions); |
| 319 } | 321 } |
| 320 | 322 |
| 321 /** | 323 /** |
| 322 * If the given [Element] is not `null`, then creates a corresponding | 324 * If the given [Element] is not `null`, then creates a corresponding |
| 323 * [NavigationRegion]. | 325 * [NavigationRegion]. |
| 324 */ | 326 */ |
| 325 void _addRegion(int offset, int length, Element element) { | 327 void _addRegion(int offset, int length, pae.Element element) { |
| 326 NavigationTarget target = _createTarget(element); | 328 psi.Element target = _createTarget(element); |
| 327 if (target == null) { | 329 if (target == null) { |
| 328 return; | 330 return; |
| 329 } | 331 } |
| 330 _regions.add(new NavigationRegionImpl(offset, length, <NavigationTarget> [ta
rget])); | 332 _regions.add(new NavigationRegionImpl(offset, length, <psi.Element> [target]
)); |
| 331 } | 333 } |
| 332 | 334 |
| 333 void _addRegion_tokenStart_nodeEnd(Token a, AstNode b, Element element) { | 335 void _addRegion_tokenStart_nodeEnd(Token a, AstNode b, pae.Element element) { |
| 334 int offset = a.offset; | 336 int offset = a.offset; |
| 335 int length = b.end - offset; | 337 int length = b.end - offset; |
| 336 _addRegion(offset, length, element); | 338 _addRegion(offset, length, element); |
| 337 } | 339 } |
| 338 | 340 |
| 339 /** | 341 /** |
| 340 * If the given [Element] is not `null`, then creates a corresponding | 342 * If the given [Element] is not `null`, then creates a corresponding |
| 341 * [NavigationRegion]. | 343 * [NavigationRegion]. |
| 342 */ | 344 */ |
| 343 void _addRegionForNode(AstNode node, Element element) { | 345 void _addRegionForNode(AstNode node, pae.Element element) { |
| 344 int offset = node.offset; | 346 int offset = node.offset; |
| 345 int length = node.length; | 347 int length = node.length; |
| 346 _addRegion(offset, length, element); | 348 _addRegion(offset, length, element); |
| 347 } | 349 } |
| 348 | 350 |
| 349 /** | 351 /** |
| 350 * If the given [Element] is not `null`, then creates a corresponding | 352 * If the given [Element] is not `null`, then creates a corresponding |
| 351 * [NavigationRegion]. | 353 * [NavigationRegion]. |
| 352 */ | 354 */ |
| 353 void _addRegionForToken(Token token, Element element) { | 355 void _addRegionForToken(Token token, pae.Element element) { |
| 354 int offset = token.offset; | 356 int offset = token.offset; |
| 355 int length = token.length; | 357 int length = token.length; |
| 356 _addRegion(offset, length, element); | 358 _addRegion(offset, length, element); |
| 357 } | 359 } |
| 358 | 360 |
| 359 /** | 361 /** |
| 360 * Returns the [NavigationTarget] for the given [Element], maybe `null` if | 362 * Returns the [com.google.dart.server.Element] for the given [Element], maybe |
| 361 * `null` was given. | 363 * `null` if `null` was given. |
| 362 */ | 364 */ |
| 363 NavigationTarget _createTarget(Element element) { | 365 psi.Element _createTarget(pae.Element element) { |
| 364 if (element == null) { | 366 if (element == null) { |
| 365 return null; | 367 return null; |
| 366 } | 368 } |
| 367 if (element is FieldFormalParameterElement) { | 369 if (element is pae.FieldFormalParameterElement) { |
| 368 element = (element as FieldFormalParameterElement).field; | 370 element = (element as pae.FieldFormalParameterElement).field; |
| 369 } | 371 } |
| 370 int nameOffset = element.nameOffset; | 372 return ElementImpl.create(element); |
| 371 int nameLength = element.displayName.length; | |
| 372 if (nameOffset == -1) { | |
| 373 nameLength = 0; | |
| 374 } | |
| 375 return new NavigationTargetImpl(element.source, _getElementId(element), name
Offset, nameLength); | |
| 376 } | 373 } |
| 377 | |
| 378 String _getElementId(Element element) => element.location.encoding; | |
| 379 } | 374 } |
| 380 | 375 |
| 381 /** | 376 /** |
| 382 * A computer for [Outline]s in a Dart [CompilationUnit]. | 377 * A computer for [Outline]s in a Dart [CompilationUnit]. |
| 383 */ | 378 */ |
| 384 class DartUnitOutlineComputer { | 379 class DartUnitOutlineComputer { |
| 380 static String _UNITTEST_LIBRARY = "unittest"; |
| 381 |
| 382 final Source _source; |
| 383 |
| 385 final CompilationUnit _unit; | 384 final CompilationUnit _unit; |
| 386 | 385 |
| 387 DartUnitOutlineComputer(this._unit); | 386 DartUnitOutlineComputer(this._source, this._unit); |
| 388 | 387 |
| 389 /** | 388 /** |
| 390 * Returns the computed [Outline]s, not `null`. | 389 * Returns the computed [Outline]s, not `null`. |
| 391 */ | 390 */ |
| 392 Outline compute() { | 391 psi.Outline compute() { |
| 393 OutlineImpl unitOutline = _newUnitOutline(); | 392 OutlineImpl unitOutline = _newUnitOutline(); |
| 394 List<Outline> unitChildren = []; | 393 List<psi.Outline> unitChildren = []; |
| 395 for (CompilationUnitMember unitMember in _unit.declarations) { | 394 for (CompilationUnitMember unitMember in _unit.declarations) { |
| 396 if (unitMember is ClassDeclaration) { | 395 if (unitMember is ClassDeclaration) { |
| 397 ClassDeclaration classDeclartion = unitMember; | 396 ClassDeclaration classDeclartion = unitMember; |
| 398 OutlineImpl classOutline = _newClassOutline(unitOutline, unitChildren, c
lassDeclartion); | 397 OutlineImpl classOutline = _newClassOutline(unitOutline, unitChildren, c
lassDeclartion); |
| 399 List<Outline> classChildren = []; | 398 List<psi.Outline> classChildren = []; |
| 400 for (ClassMember classMember in classDeclartion.members) { | 399 for (ClassMember classMember in classDeclartion.members) { |
| 401 if (classMember is ConstructorDeclaration) { | 400 if (classMember is ConstructorDeclaration) { |
| 402 ConstructorDeclaration constructorDeclaration = classMember; | 401 ConstructorDeclaration constructorDeclaration = classMember; |
| 403 _newConstructorOutline(classOutline, classChildren, constructorDecla
ration); | 402 _newConstructorOutline(classOutline, classChildren, constructorDecla
ration); |
| 404 } | 403 } |
| 405 if (classMember is FieldDeclaration) { | 404 if (classMember is FieldDeclaration) { |
| 406 FieldDeclaration fieldDeclaration = classMember; | 405 FieldDeclaration fieldDeclaration = classMember; |
| 407 VariableDeclarationList fields = fieldDeclaration.fields; | 406 VariableDeclarationList fields = fieldDeclaration.fields; |
| 408 if (fields != null) { | 407 if (fields != null) { |
| 409 TypeName fieldType = fields.type; | 408 TypeName fieldType = fields.type; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 430 } | 429 } |
| 431 if (unitMember is FunctionTypeAlias) { | 430 if (unitMember is FunctionTypeAlias) { |
| 432 FunctionTypeAlias alias = unitMember; | 431 FunctionTypeAlias alias = unitMember; |
| 433 _newFunctionTypeAliasOutline(unitOutline, unitChildren, alias); | 432 _newFunctionTypeAliasOutline(unitOutline, unitChildren, alias); |
| 434 } | 433 } |
| 435 } | 434 } |
| 436 unitOutline.children = new List.from(unitChildren); | 435 unitOutline.children = new List.from(unitChildren); |
| 437 return unitOutline; | 436 return unitOutline; |
| 438 } | 437 } |
| 439 | 438 |
| 440 void _addLocalFunctionOutlines(OutlineImpl parenet, FunctionBody body) { | 439 void _addLocalFunctionOutlines(OutlineImpl parent, FunctionBody body) { |
| 441 List<Outline> localOutlines = []; | 440 List<psi.Outline> localOutlines = []; |
| 442 body.accept(new RecursiveAstVisitor_DartUnitOutlineComputer_addLocalFunction
Outlines(this, parenet, localOutlines)); | 441 body.accept(new RecursiveAstVisitor_DartUnitOutlineComputer_addLocalFunction
Outlines(this, parent, localOutlines)); |
| 443 parenet.children = new List.from(localOutlines); | 442 parent.children = new List.from(localOutlines); |
| 443 } |
| 444 |
| 445 bool _addUnitTestOutlines(OutlineImpl parent, List<psi.Outline> children, Meth
odInvocation node) { |
| 446 psi.ElementKind unitTestKind = null; |
| 447 if (_isUnitTestFunctionInvocation(node, "group")) { |
| 448 unitTestKind = psi.ElementKind.UNIT_TEST_GROUP; |
| 449 } else if (_isUnitTestFunctionInvocation(node, "test")) { |
| 450 unitTestKind = psi.ElementKind.UNIT_TEST_CASE; |
| 451 } else { |
| 452 return false; |
| 453 } |
| 454 ArgumentList argumentList = node.argumentList; |
| 455 if (argumentList != null) { |
| 456 List<Expression> arguments = argumentList.arguments; |
| 457 if (arguments.length == 2 && arguments[1] is FunctionExpression) { |
| 458 // prepare name |
| 459 String name; |
| 460 int nameOffset; |
| 461 int nameLength; |
| 462 { |
| 463 Expression nameNode = arguments[0]; |
| 464 if (nameNode is SimpleStringLiteral) { |
| 465 SimpleStringLiteral nameLiteral = arguments[0] as SimpleStringLitera
l; |
| 466 name = nameLiteral.value; |
| 467 nameOffset = nameLiteral.valueOffset; |
| 468 nameLength = name.length; |
| 469 } else { |
| 470 name = "??????????"; |
| 471 nameOffset = nameNode.offset; |
| 472 nameLength = nameNode.length; |
| 473 } |
| 474 } |
| 475 // add a new outline |
| 476 FunctionExpression functionExpression = arguments[1] as FunctionExpressi
on; |
| 477 SourceRegionImpl sourceRegion = new SourceRegionImpl(node.offset, node.l
ength); |
| 478 ElementImpl element = new ElementImpl(null, _source, unitTestKind, name,
nameOffset, nameLength, null, null, false, false, false); |
| 479 OutlineImpl outline = new OutlineImpl(parent, element, sourceRegion); |
| 480 children.add(outline); |
| 481 _addLocalFunctionOutlines(outline, functionExpression.body); |
| 482 return true; |
| 483 } |
| 484 } |
| 485 return false; |
| 444 } | 486 } |
| 445 | 487 |
| 446 /** | 488 /** |
| 447 * Returns the [AstNode]'s source region. | 489 * Returns the [AstNode]'s source region. |
| 448 */ | 490 */ |
| 449 SourceRegion _getSourceRegion(AstNode node) { | 491 psi.SourceRegion _getSourceRegion(AstNode node) { |
| 450 int endOffset = node.end; | 492 int endOffset = node.end; |
| 451 // prepare position of the node among its siblings | 493 // prepare position of the node among its siblings |
| 452 int firstOffset; | 494 int firstOffset; |
| 453 List<AstNode> siblings; | 495 List<AstNode> siblings; |
| 454 AstNode parent = node.parent; | 496 AstNode parent = node.parent; |
| 455 // field | 497 // field |
| 456 if (parent is VariableDeclarationList) { | 498 if (parent is VariableDeclarationList) { |
| 457 VariableDeclarationList variableList = parent as VariableDeclarationList; | 499 VariableDeclarationList variableList = parent as VariableDeclarationList; |
| 458 List<VariableDeclaration> variables = variableList.variables; | 500 List<VariableDeclaration> variables = variableList.variables; |
| 459 int variableIndex = variables.indexOf(node); | 501 int variableIndex = variables.indexOf(node); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 483 // first child: [endOfParent, endOfNode] | 525 // first child: [endOfParent, endOfNode] |
| 484 int index = siblings.indexOf(node); | 526 int index = siblings.indexOf(node); |
| 485 if (index == 0) { | 527 if (index == 0) { |
| 486 return new SourceRegionImpl(firstOffset, endOffset - firstOffset); | 528 return new SourceRegionImpl(firstOffset, endOffset - firstOffset); |
| 487 } | 529 } |
| 488 // not first child: [endOfPreviousSibling, endOfNode] | 530 // not first child: [endOfPreviousSibling, endOfNode] |
| 489 int prevSiblingEnd = siblings[index - 1].end; | 531 int prevSiblingEnd = siblings[index - 1].end; |
| 490 return new SourceRegionImpl(prevSiblingEnd, endOffset - prevSiblingEnd); | 532 return new SourceRegionImpl(prevSiblingEnd, endOffset - prevSiblingEnd); |
| 491 } | 533 } |
| 492 | 534 |
| 493 OutlineImpl _newClassOutline(Outline unitOutline, List<Outline> unitChildren,
ClassDeclaration classDeclaration) { | 535 /** |
| 536 * Returns `true` if the given [MethodInvocation] is invocation of the functio
n with |
| 537 * the given name from the "unittest" library. |
| 538 */ |
| 539 bool _isUnitTestFunctionInvocation(MethodInvocation node, String name) { |
| 540 SimpleIdentifier methodName = node.methodName; |
| 541 if (methodName != null) { |
| 542 pae.Element element = methodName.staticElement; |
| 543 if (element is pae.FunctionElement) { |
| 544 pae.FunctionElement functionElement = element; |
| 545 if (name == functionElement.name) { |
| 546 pae.LibraryElement libraryElement = functionElement.library; |
| 547 return libraryElement != null && _UNITTEST_LIBRARY == libraryElement.n
ame; |
| 548 } |
| 549 } |
| 550 } |
| 551 return false; |
| 552 } |
| 553 |
| 554 OutlineImpl _newClassOutline(psi.Outline unitOutline, List<psi.Outline> unitCh
ildren, ClassDeclaration classDeclaration) { |
| 494 SimpleIdentifier nameNode = classDeclaration.name; | 555 SimpleIdentifier nameNode = classDeclaration.name; |
| 495 String name = nameNode.name; | 556 String name = nameNode.name; |
| 496 OutlineImpl outline = new OutlineImpl(unitOutline, _getSourceRegion(classDec
laration), OutlineKind.CLASS, name, nameNode.offset, name.length, null, null, cl
assDeclaration.isAbstract, StringUtilities.startsWithChar(name, 0x5F), false); | 557 ElementImpl element = new ElementImpl(ElementImpl.createId(classDeclaration.
element), _source, psi.ElementKind.CLASS, name, nameNode.offset, name.length, nu
ll, null, classDeclaration.isAbstract, false, StringUtilities.startsWithChar(nam
e, 0x5F)); |
| 558 psi.SourceRegion sourceRegion = _getSourceRegion(classDeclaration); |
| 559 OutlineImpl outline = new OutlineImpl(unitOutline, element, sourceRegion); |
| 497 unitChildren.add(outline); | 560 unitChildren.add(outline); |
| 498 return outline; | 561 return outline; |
| 499 } | 562 } |
| 500 | 563 |
| 501 void _newClassTypeAlias(Outline unitOutline, List<Outline> unitChildren, Class
TypeAlias alias) { | 564 void _newClassTypeAlias(psi.Outline unitOutline, List<psi.Outline> unitChildre
n, ClassTypeAlias alias) { |
| 502 SimpleIdentifier nameNode = alias.name; | 565 SimpleIdentifier nameNode = alias.name; |
| 503 String name = nameNode.name; | 566 String name = nameNode.name; |
| 504 unitChildren.add(new OutlineImpl(unitOutline, _getSourceRegion(alias), Outli
neKind.CLASS_TYPE_ALIAS, name, nameNode.offset, nameNode.length, null, null, ali
as.isAbstract, StringUtilities.startsWithChar(name, 0x5F), false)); | 567 ElementImpl element = new ElementImpl(ElementImpl.createId(alias.element), _
source, psi.ElementKind.CLASS_TYPE_ALIAS, name, nameNode.offset, nameNode.length
, null, null, alias.isAbstract, false, StringUtilities.startsWithChar(name, 0x5F
)); |
| 568 psi.SourceRegion sourceRegion = _getSourceRegion(alias); |
| 569 OutlineImpl outline = new OutlineImpl(unitOutline, element, sourceRegion); |
| 570 unitChildren.add(outline); |
| 505 } | 571 } |
| 506 | 572 |
| 507 void _newConstructorOutline(OutlineImpl classOutline, List<Outline> children,
ConstructorDeclaration constructorDeclaration) { | 573 void _newConstructorOutline(OutlineImpl classOutline, List<psi.Outline> childr
en, ConstructorDeclaration constructorDeclaration) { |
| 508 Identifier returnType = constructorDeclaration.returnType; | 574 Identifier returnType = constructorDeclaration.returnType; |
| 509 String name = returnType.name; | 575 String name = returnType.name; |
| 510 int offset = returnType.offset; | 576 int offset = returnType.offset; |
| 511 int length = returnType.length; | 577 int length = returnType.length; |
| 512 bool isPrivate = false; | 578 bool isPrivate = false; |
| 513 SimpleIdentifier constructorNameNode = constructorDeclaration.name; | 579 SimpleIdentifier constructorNameNode = constructorDeclaration.name; |
| 514 if (constructorNameNode != null) { | 580 if (constructorNameNode != null) { |
| 515 String constructorName = constructorNameNode.name; | 581 String constructorName = constructorNameNode.name; |
| 516 isPrivate = StringUtilities.startsWithChar(constructorName, 0x5F); | 582 isPrivate = StringUtilities.startsWithChar(constructorName, 0x5F); |
| 517 name += ".${constructorName}"; | 583 name += ".${constructorName}"; |
| 518 offset = constructorNameNode.offset; | 584 offset = constructorNameNode.offset; |
| 519 length = constructorNameNode.length; | 585 length = constructorNameNode.length; |
| 520 } | 586 } |
| 521 FormalParameterList parameters = constructorDeclaration.parameters; | 587 FormalParameterList parameters = constructorDeclaration.parameters; |
| 522 OutlineImpl outline = new OutlineImpl(classOutline, _getSourceRegion(constru
ctorDeclaration), OutlineKind.CONSTRUCTOR, name, offset, length, parameters != n
ull ? parameters.toSource() : "", null, false, isPrivate, false); | 588 ElementImpl element = new ElementImpl(ElementImpl.createId(constructorDeclar
ation.element), _source, psi.ElementKind.CONSTRUCTOR, name, offset, length, para
meters != null ? parameters.toSource() : "", null, false, false, isPrivate); |
| 589 psi.SourceRegion sourceRegion = _getSourceRegion(constructorDeclaration); |
| 590 OutlineImpl outline = new OutlineImpl(classOutline, element, sourceRegion); |
| 523 children.add(outline); | 591 children.add(outline); |
| 524 _addLocalFunctionOutlines(outline, constructorDeclaration.body); | 592 _addLocalFunctionOutlines(outline, constructorDeclaration.body); |
| 525 } | 593 } |
| 526 | 594 |
| 527 void _newField(OutlineImpl classOutline, List<Outline> children, String fieldT
ypeName, VariableDeclaration field, bool isStatic) { | 595 void _newField(OutlineImpl classOutline, List<psi.Outline> children, String fi
eldTypeName, VariableDeclaration field, bool isStatic) { |
| 528 SimpleIdentifier nameNode = field.name; | 596 SimpleIdentifier nameNode = field.name; |
| 529 String name = nameNode.name; | 597 String name = nameNode.name; |
| 530 children.add(new OutlineImpl(classOutline, _getSourceRegion(field), OutlineK
ind.FIELD, name, nameNode.offset, nameNode.length, null, fieldTypeName, false, S
tringUtilities.startsWithChar(name, 0x5F), isStatic)); | 598 ElementImpl element = new ElementImpl(ElementImpl.createId(field.element), _
source, psi.ElementKind.FIELD, name, nameNode.offset, nameNode.length, null, fie
ldTypeName, false, isStatic, StringUtilities.startsWithChar(name, 0x5F)); |
| 531 } | 599 psi.SourceRegion sourceRegion = _getSourceRegion(field); |
| 532 | 600 OutlineImpl outline = new OutlineImpl(classOutline, element, sourceRegion); |
| 533 void _newFunctionOutline(Outline unitOutline, List<Outline> unitChildren, Func
tionDeclaration functionDeclaration) { | 601 children.add(outline); |
| 602 } |
| 603 |
| 604 void _newFunctionOutline(psi.Outline parent, List<psi.Outline> children, Funct
ionDeclaration functionDeclaration) { |
| 534 TypeName returnType = functionDeclaration.returnType; | 605 TypeName returnType = functionDeclaration.returnType; |
| 535 SimpleIdentifier nameNode = functionDeclaration.name; | 606 SimpleIdentifier nameNode = functionDeclaration.name; |
| 536 String name = nameNode.name; | 607 String name = nameNode.name; |
| 537 FunctionExpression functionExpression = functionDeclaration.functionExpressi
on; | 608 FunctionExpression functionExpression = functionDeclaration.functionExpressi
on; |
| 538 FormalParameterList parameters = functionExpression.parameters; | 609 FormalParameterList parameters = functionExpression.parameters; |
| 539 OutlineKind kind; | 610 psi.ElementKind kind; |
| 540 if (functionDeclaration.isGetter) { | 611 if (functionDeclaration.isGetter) { |
| 541 kind = OutlineKind.GETTER; | 612 kind = psi.ElementKind.GETTER; |
| 542 } else if (functionDeclaration.isSetter) { | 613 } else if (functionDeclaration.isSetter) { |
| 543 kind = OutlineKind.SETTER; | 614 kind = psi.ElementKind.SETTER; |
| 544 } else { | 615 } else { |
| 545 kind = OutlineKind.FUNCTION; | 616 kind = psi.ElementKind.FUNCTION; |
| 546 } | 617 } |
| 547 OutlineImpl outline = new OutlineImpl(unitOutline, _getSourceRegion(function
Declaration), kind, name, nameNode.offset, nameNode.length, parameters != null ?
parameters.toSource() : "", returnType != null ? returnType.toSource() : "", fa
lse, StringUtilities.startsWithChar(name, 0x5F), false); | 618 ElementImpl element = new ElementImpl(ElementImpl.createId(functionDeclarati
on.element), _source, kind, name, nameNode.offset, nameNode.length, parameters !
= null ? parameters.toSource() : "", returnType != null ? returnType.toSource()
: "", false, false, StringUtilities.startsWithChar(name, 0x5F)); |
| 548 unitChildren.add(outline); | 619 psi.SourceRegion sourceRegion = _getSourceRegion(functionDeclaration); |
| 620 OutlineImpl outline = new OutlineImpl(parent, element, sourceRegion); |
| 621 children.add(outline); |
| 549 _addLocalFunctionOutlines(outline, functionExpression.body); | 622 _addLocalFunctionOutlines(outline, functionExpression.body); |
| 550 } | 623 } |
| 551 | 624 |
| 552 void _newFunctionTypeAliasOutline(Outline unitOutline, List<Outline> unitChild
ren, FunctionTypeAlias alias) { | 625 void _newFunctionTypeAliasOutline(psi.Outline unitOutline, List<psi.Outline> u
nitChildren, FunctionTypeAlias alias) { |
| 553 TypeName returnType = alias.returnType; | 626 TypeName returnType = alias.returnType; |
| 554 SimpleIdentifier nameNode = alias.name; | 627 SimpleIdentifier nameNode = alias.name; |
| 555 String name = nameNode.name; | 628 String name = nameNode.name; |
| 556 FormalParameterList parameters = alias.parameters; | 629 FormalParameterList parameters = alias.parameters; |
| 557 unitChildren.add(new OutlineImpl(unitOutline, _getSourceRegion(alias), Outli
neKind.FUNCTION_TYPE_ALIAS, name, nameNode.offset, nameNode.length, parameters !
= null ? parameters.toSource() : "", returnType != null ? returnType.toSource()
: "", false, StringUtilities.startsWithChar(name, 0x5F), false)); | 630 ElementImpl element = new ElementImpl(ElementImpl.createId(alias.element), _
source, psi.ElementKind.FUNCTION_TYPE_ALIAS, name, nameNode.offset, nameNode.len
gth, parameters != null ? parameters.toSource() : "", returnType != null ? retur
nType.toSource() : "", false, false, StringUtilities.startsWithChar(name, 0x5F))
; |
| 558 } | 631 psi.SourceRegion sourceRegion = _getSourceRegion(alias); |
| 559 | 632 OutlineImpl outline = new OutlineImpl(unitOutline, element, sourceRegion); |
| 560 void _newMethodOutline(OutlineImpl classOutline, List<Outline> children, Metho
dDeclaration methodDeclaration) { | 633 unitChildren.add(outline); |
| 634 } |
| 635 |
| 636 void _newMethodOutline(OutlineImpl classOutline, List<psi.Outline> children, M
ethodDeclaration methodDeclaration) { |
| 561 TypeName returnType = methodDeclaration.returnType; | 637 TypeName returnType = methodDeclaration.returnType; |
| 562 SimpleIdentifier nameNode = methodDeclaration.name; | 638 SimpleIdentifier nameNode = methodDeclaration.name; |
| 563 String name = nameNode.name; | 639 String name = nameNode.name; |
| 564 FormalParameterList parameters = methodDeclaration.parameters; | 640 FormalParameterList parameters = methodDeclaration.parameters; |
| 565 OutlineKind kind; | 641 psi.ElementKind kind; |
| 566 if (methodDeclaration.isGetter) { | 642 if (methodDeclaration.isGetter) { |
| 567 kind = OutlineKind.GETTER; | 643 kind = psi.ElementKind.GETTER; |
| 568 } else if (methodDeclaration.isSetter) { | 644 } else if (methodDeclaration.isSetter) { |
| 569 kind = OutlineKind.SETTER; | 645 kind = psi.ElementKind.SETTER; |
| 570 } else { | 646 } else { |
| 571 kind = OutlineKind.METHOD; | 647 kind = psi.ElementKind.METHOD; |
| 572 } | 648 } |
| 573 OutlineImpl outline = new OutlineImpl(classOutline, _getSourceRegion(methodD
eclaration), kind, name, nameNode.offset, nameNode.length, parameters != null ?
parameters.toSource() : "", returnType != null ? returnType.toSource() : "", met
hodDeclaration.isAbstract, StringUtilities.startsWithChar(name, 0x5F), methodDec
laration.isStatic); | 649 ElementImpl element = new ElementImpl(ElementImpl.createId(methodDeclaration
.element), _source, kind, name, nameNode.offset, nameNode.length, parameters !=
null ? parameters.toSource() : "", returnType != null ? returnType.toSource() :
"", methodDeclaration.isAbstract, methodDeclaration.isStatic, StringUtilities.st
artsWithChar(name, 0x5F)); |
| 650 psi.SourceRegion sourceRegion = _getSourceRegion(methodDeclaration); |
| 651 OutlineImpl outline = new OutlineImpl(classOutline, element, sourceRegion); |
| 574 children.add(outline); | 652 children.add(outline); |
| 575 _addLocalFunctionOutlines(outline, methodDeclaration.body); | 653 _addLocalFunctionOutlines(outline, methodDeclaration.body); |
| 576 } | 654 } |
| 577 | 655 |
| 578 OutlineImpl _newUnitOutline() => new OutlineImpl(null, new SourceRegionImpl(_u
nit.offset, _unit.length), OutlineKind.COMPILATION_UNIT, null, 0, 0, null, null,
false, false, false); | 656 OutlineImpl _newUnitOutline() { |
| 657 ElementImpl element = new ElementImpl(ElementImpl.createId(_unit.element), _
source, psi.ElementKind.COMPILATION_UNIT, null, 0, 0, null, null, false, false,
false); |
| 658 return new OutlineImpl(null, element, new SourceRegionImpl(_unit.offset, _un
it.length)); |
| 659 } |
| 660 } |
| 661 |
| 662 /** |
| 663 * A concrete implementation of [Element]. |
| 664 */ |
| 665 class ElementImpl implements psi.Element { |
| 666 /** |
| 667 * Creates an [ElementImpl] instance for the given |
| 668 * [com.google.dart.engine.element.Element]. |
| 669 */ |
| 670 static ElementImpl create(pae.Element element) { |
| 671 // prepare name |
| 672 String name = element.displayName; |
| 673 int nameOffset = element.nameOffset; |
| 674 int nameLength = name != null ? name.length : 0; |
| 675 // prepare element kind specific information |
| 676 psi.ElementKind outlineKind; |
| 677 bool isAbstract = false; |
| 678 bool isStatic = false; |
| 679 bool isPrivate = element.isPrivate; |
| 680 while (true) { |
| 681 if (element.kind == pae.ElementKind.CLASS) { |
| 682 outlineKind = psi.ElementKind.CLASS; |
| 683 isAbstract = (element as pae.ClassElement).isAbstract; |
| 684 } else if (element.kind == pae.ElementKind.COMPILATION_UNIT) { |
| 685 outlineKind = psi.ElementKind.COMPILATION_UNIT; |
| 686 nameOffset = -1; |
| 687 nameLength = 0; |
| 688 } else if (element.kind == pae.ElementKind.CONSTRUCTOR) { |
| 689 outlineKind = psi.ElementKind.CONSTRUCTOR; |
| 690 String className = element.enclosingElement.name; |
| 691 if (name.length != 0) { |
| 692 name = "${className}.${name}"; |
| 693 } else { |
| 694 name = className; |
| 695 } |
| 696 } else if (element.kind == pae.ElementKind.FUNCTION) { |
| 697 outlineKind = psi.ElementKind.FUNCTION; |
| 698 } else if (element.kind == pae.ElementKind.FUNCTION_TYPE_ALIAS) { |
| 699 outlineKind = psi.ElementKind.FUNCTION_TYPE_ALIAS; |
| 700 } else if (element.kind == pae.ElementKind.LIBRARY) { |
| 701 outlineKind = psi.ElementKind.LIBRARY; |
| 702 } else if (element.kind == pae.ElementKind.METHOD) { |
| 703 outlineKind = psi.ElementKind.METHOD; |
| 704 isAbstract = (element as pae.MethodElement).isAbstract; |
| 705 } else { |
| 706 outlineKind = psi.ElementKind.UNKNOWN; |
| 707 } |
| 708 break; |
| 709 } |
| 710 // extract return type and parameters from toString() |
| 711 // TODO(scheglov) we need a way to get this information directly from an Ele
ment |
| 712 String parameters; |
| 713 String returnType; |
| 714 { |
| 715 String str = element.toString(); |
| 716 // return type |
| 717 String rightArrow = pae.Element.RIGHT_ARROW; |
| 718 int returnIndex = str.lastIndexOf(rightArrow); |
| 719 if (returnIndex != -1) { |
| 720 returnType = str.substring(returnIndex + rightArrow.length); |
| 721 str = str.substring(0, returnIndex); |
| 722 } else { |
| 723 returnType = null; |
| 724 } |
| 725 // parameters |
| 726 int parametersIndex = str.indexOf("("); |
| 727 if (parametersIndex != -1) { |
| 728 parameters = str.substring(parametersIndex); |
| 729 } else { |
| 730 parameters = null; |
| 731 } |
| 732 } |
| 733 // new element |
| 734 return new ElementImpl(createId(element), element.source, outlineKind, name,
nameOffset, nameLength, parameters, returnType, isAbstract, isStatic, isPrivate
); |
| 735 } |
| 736 |
| 737 /** |
| 738 * Returns an identifier of the given [Element], maybe `null` if `null` given. |
| 739 */ |
| 740 static String createId(pae.Element element) { |
| 741 if (element == null) { |
| 742 return null; |
| 743 } |
| 744 return element.location.encoding; |
| 745 } |
| 746 |
| 747 final String id; |
| 748 |
| 749 final Source source; |
| 750 |
| 751 final psi.ElementKind kind; |
| 752 |
| 753 final String name; |
| 754 |
| 755 final int offset; |
| 756 |
| 757 final int length; |
| 758 |
| 759 final String parameters; |
| 760 |
| 761 final String returnType; |
| 762 |
| 763 final bool isAbstract; |
| 764 |
| 765 final bool isPrivate; |
| 766 |
| 767 final bool isStatic; |
| 768 |
| 769 ElementImpl(this.id, this.source, this.kind, this.name, this.offset, this.leng
th, this.parameters, this.returnType, this.isAbstract, this.isStatic, this.isPri
vate); |
| 770 |
| 771 @override |
| 772 bool operator ==(Object obj) { |
| 773 if (identical(obj, this)) { |
| 774 return true; |
| 775 } |
| 776 if (obj is! ElementImpl) { |
| 777 return false; |
| 778 } |
| 779 ElementImpl other = obj as ElementImpl; |
| 780 return other.kind == kind && (other.source == source) && (name == other.name
); |
| 781 } |
| 782 |
| 783 @override |
| 784 int get hashCode { |
| 785 if (name == null) { |
| 786 return source.hashCode; |
| 787 } |
| 788 return ObjectUtilities.combineHashCodes(source.hashCode, name.hashCode); |
| 789 } |
| 790 |
| 791 @override |
| 792 String toString() { |
| 793 JavaStringBuilder builder = new JavaStringBuilder(); |
| 794 builder.append("[name="); |
| 795 builder.append(name); |
| 796 builder.append(", kind="); |
| 797 builder.append(kind); |
| 798 builder.append(", offset="); |
| 799 builder.append(offset); |
| 800 builder.append(", length="); |
| 801 builder.append(length); |
| 802 builder.append(", parameters="); |
| 803 builder.append(parameters); |
| 804 builder.append(", return="); |
| 805 builder.append(returnType); |
| 806 builder.append("]"); |
| 807 return builder.toString(); |
| 808 } |
| 579 } | 809 } |
| 580 | 810 |
| 581 /** | 811 /** |
| 582 * A concrete implementation of [HighlightRegion]. | 812 * A concrete implementation of [HighlightRegion]. |
| 583 */ | 813 */ |
| 584 class HighlightRegionImpl extends SourceRegionImpl implements HighlightRegion { | 814 class HighlightRegionImpl extends SourceRegionImpl implements psi.HighlightRegio
n { |
| 585 final HighlightType type; | 815 final psi.HighlightType type; |
| 586 | 816 |
| 587 HighlightRegionImpl(int offset, int length, this.type) : super(offset, length)
; | 817 HighlightRegionImpl(int offset, int length, this.type) : super(offset, length)
; |
| 588 | 818 |
| 589 @override | 819 @override |
| 590 String toString() { | 820 String toString() { |
| 591 JavaStringBuilder builder = new JavaStringBuilder(); | 821 JavaStringBuilder builder = new JavaStringBuilder(); |
| 592 builder.append("[offset="); | 822 builder.append("[offset="); |
| 593 builder.append(offset); | 823 builder.append(offset); |
| 594 builder.append(", length="); | 824 builder.append(", length="); |
| 595 builder.append(length); | 825 builder.append(length); |
| 596 builder.append(", type="); | 826 builder.append(", type="); |
| 597 builder.append(type); | 827 builder.append(type); |
| 598 builder.append("]"); | 828 builder.append("]"); |
| 599 return builder.toString(); | 829 return builder.toString(); |
| 600 } | 830 } |
| 601 } | 831 } |
| 602 | 832 |
| 603 /** | 833 /** |
| 604 * A concrete implementation of [NavigationRegion]. | 834 * A concrete implementation of [NavigationRegion]. |
| 605 */ | 835 */ |
| 606 class NavigationRegionImpl extends SourceRegionImpl implements NavigationRegion
{ | 836 class NavigationRegionImpl extends SourceRegionImpl implements psi.NavigationReg
ion { |
| 607 final List<NavigationTarget> targets; | 837 final List<psi.Element> targets; |
| 608 | 838 |
| 609 NavigationRegionImpl(int offset, int length, this.targets) : super(offset, len
gth); | 839 NavigationRegionImpl(int offset, int length, this.targets) : super(offset, len
gth); |
| 610 | 840 |
| 611 @override | 841 @override |
| 612 String toString() { | 842 String toString() { |
| 613 JavaStringBuilder builder = new JavaStringBuilder(); | 843 JavaStringBuilder builder = new JavaStringBuilder(); |
| 614 builder.append(super.toString()); | 844 builder.append(super.toString()); |
| 615 builder.append(" -> ["); | 845 builder.append(" -> ["); |
| 616 builder.append(StringUtils.join(targets, ", ")); | 846 builder.append(StringUtils.join(targets, ", ")); |
| 617 builder.append("]"); | 847 builder.append("]"); |
| 618 return builder.toString(); | 848 return builder.toString(); |
| 619 } | 849 } |
| 620 } | |
| 621 | |
| 622 /** | |
| 623 * A concrete implementation of [NavigationTarget]. | |
| 624 */ | |
| 625 class NavigationTargetImpl implements NavigationTarget { | |
| 626 final Source source; | |
| 627 | |
| 628 final String elementId; | |
| 629 | |
| 630 final int offset; | |
| 631 | |
| 632 final int length; | |
| 633 | |
| 634 NavigationTargetImpl(this.source, this.elementId, this.offset, this.length); | |
| 635 | |
| 636 @override | |
| 637 String toString() { | |
| 638 JavaStringBuilder builder = new JavaStringBuilder(); | |
| 639 builder.append("[offset="); | |
| 640 builder.append(offset); | |
| 641 builder.append(", length="); | |
| 642 builder.append(length); | |
| 643 builder.append(", source="); | |
| 644 builder.append(source); | |
| 645 builder.append(", element="); | |
| 646 builder.append(elementId); | |
| 647 builder.append("]"); | |
| 648 return builder.toString(); | |
| 649 } | |
| 650 } | 850 } |
| 651 | 851 |
| 652 /** | 852 /** |
| 653 * A concrete implementation of [Outline]. | 853 * A concrete implementation of [Outline]. |
| 654 */ | 854 */ |
| 655 class OutlineImpl implements Outline { | 855 class OutlineImpl implements psi.Outline { |
| 656 final Outline parent; | 856 final psi.Outline parent; |
| 657 | 857 |
| 658 final SourceRegion sourceRegion; | 858 final psi.Element element; |
| 659 | 859 |
| 660 final OutlineKind kind; | 860 final psi.SourceRegion sourceRegion; |
| 661 | 861 |
| 662 final String name; | 862 List<psi.Outline> children = psi.Outline.EMPTY_ARRAY; |
| 663 | 863 |
| 664 final int offset; | 864 OutlineImpl(this.parent, this.element, this.sourceRegion); |
| 665 | |
| 666 final int length; | |
| 667 | |
| 668 final String parameters; | |
| 669 | |
| 670 final String returnType; | |
| 671 | |
| 672 final bool isAbstract; | |
| 673 | |
| 674 final bool isPrivate; | |
| 675 | |
| 676 final bool isStatic; | |
| 677 | |
| 678 List<Outline> children = Outline.EMPTY_ARRAY; | |
| 679 | |
| 680 OutlineImpl(this.parent, this.sourceRegion, this.kind, this.name, this.offset,
this.length, this.parameters, this.returnType, this.isAbstract, this.isPrivate,
this.isStatic); | |
| 681 | 865 |
| 682 @override | 866 @override |
| 683 bool operator ==(Object obj) { | 867 bool operator ==(Object obj) { |
| 684 if (identical(obj, this)) { | 868 if (identical(obj, this)) { |
| 685 return true; | 869 return true; |
| 686 } | 870 } |
| 687 if (obj is! OutlineImpl) { | 871 if (obj is! OutlineImpl) { |
| 688 return false; | 872 return false; |
| 689 } | 873 } |
| 690 OutlineImpl other = obj as OutlineImpl; | 874 OutlineImpl other = obj as OutlineImpl; |
| 691 return (other.parent == parent) && other.offset == offset; | 875 return (other.element == element) && (other.parent == parent); |
| 692 } | 876 } |
| 693 | 877 |
| 694 @override | 878 @override |
| 695 int get hashCode => offset; | 879 int get hashCode { |
| 880 if (parent == null) { |
| 881 return element.hashCode; |
| 882 } |
| 883 return ObjectUtilities.combineHashCodes(parent.hashCode, element.hashCode); |
| 884 } |
| 696 | 885 |
| 697 @override | 886 @override |
| 698 String toString() { | 887 String toString() { |
| 699 JavaStringBuilder builder = new JavaStringBuilder(); | 888 JavaStringBuilder builder = new JavaStringBuilder(); |
| 700 builder.append("[name="); | 889 builder.append("[element="); |
| 701 builder.append(name); | 890 builder.append(element); |
| 702 builder.append(", kind="); | |
| 703 builder.append(kind); | |
| 704 builder.append(", offset="); | |
| 705 builder.append(offset); | |
| 706 builder.append(", length="); | |
| 707 builder.append(length); | |
| 708 builder.append(", parameters="); | |
| 709 builder.append(parameters); | |
| 710 builder.append(", return="); | |
| 711 builder.append(returnType); | |
| 712 builder.append(", children=["); | 891 builder.append(", children=["); |
| 713 builder.append(StringUtils.join(children, ", ")); | 892 builder.append(StringUtils.join(children, ", ")); |
| 714 builder.append("]]"); | 893 builder.append("]]"); |
| 715 return builder.toString(); | 894 return builder.toString(); |
| 716 } | 895 } |
| 717 } | 896 } |
| 718 | 897 |
| 719 class RecursiveAstVisitor_DartUnitHighlightsComputer_compute extends RecursiveAs
tVisitor<Object> { | 898 class RecursiveAstVisitor_DartUnitHighlightsComputer_compute extends RecursiveAs
tVisitor<Object> { |
| 720 final DartUnitHighlightsComputer DartUnitHighlightsComputer_this; | 899 final DartUnitHighlightsComputer DartUnitHighlightsComputer_this; |
| 721 | 900 |
| 722 RecursiveAstVisitor_DartUnitHighlightsComputer_compute(this.DartUnitHighlights
Computer_this) : super(); | 901 RecursiveAstVisitor_DartUnitHighlightsComputer_compute(this.DartUnitHighlights
Computer_this) : super(); |
| 723 | 902 |
| 724 @override | 903 @override |
| 725 Object visitAnnotation(Annotation node) { | 904 Object visitAnnotation(Annotation node) { |
| 726 DartUnitHighlightsComputer_this._addIdentifierRegion_annotation(node); | 905 DartUnitHighlightsComputer_this._addIdentifierRegion_annotation(node); |
| 727 return super.visitAnnotation(node); | 906 return super.visitAnnotation(node); |
| 728 } | 907 } |
| 729 | 908 |
| 730 @override | 909 @override |
| 731 Object visitAsExpression(AsExpression node) { | 910 Object visitAsExpression(AsExpression node) { |
| 732 DartUnitHighlightsComputer_this._addRegion_token(node.asOperator, HighlightT
ype.BUILT_IN); | 911 DartUnitHighlightsComputer_this._addRegion_token(node.asOperator, psi.Highli
ghtType.BUILT_IN); |
| 733 return super.visitAsExpression(node); | 912 return super.visitAsExpression(node); |
| 734 } | 913 } |
| 735 | 914 |
| 736 @override | 915 @override |
| 737 Object visitBooleanLiteral(BooleanLiteral node) { | 916 Object visitBooleanLiteral(BooleanLiteral node) { |
| 738 DartUnitHighlightsComputer_this._addRegion_node(node, HighlightType.LITERAL_
BOOLEAN); | 917 DartUnitHighlightsComputer_this._addRegion_node(node, psi.HighlightType.LITE
RAL_BOOLEAN); |
| 739 return super.visitBooleanLiteral(node); | 918 return super.visitBooleanLiteral(node); |
| 740 } | 919 } |
| 741 | 920 |
| 742 @override | 921 @override |
| 743 Object visitCatchClause(CatchClause node) { | 922 Object visitCatchClause(CatchClause node) { |
| 744 DartUnitHighlightsComputer_this._addRegion_token(node.onKeyword, HighlightTy
pe.BUILT_IN); | 923 DartUnitHighlightsComputer_this._addRegion_token(node.onKeyword, psi.Highlig
htType.BUILT_IN); |
| 745 return super.visitCatchClause(node); | 924 return super.visitCatchClause(node); |
| 746 } | 925 } |
| 747 | 926 |
| 748 @override | 927 @override |
| 749 Object visitClassDeclaration(ClassDeclaration node) { | 928 Object visitClassDeclaration(ClassDeclaration node) { |
| 750 DartUnitHighlightsComputer_this._addRegion_token(node.abstractKeyword, Highl
ightType.BUILT_IN); | 929 DartUnitHighlightsComputer_this._addRegion_token(node.abstractKeyword, psi.H
ighlightType.BUILT_IN); |
| 751 return super.visitClassDeclaration(node); | 930 return super.visitClassDeclaration(node); |
| 752 } | 931 } |
| 753 | 932 |
| 754 @override | 933 @override |
| 755 Object visitConstructorDeclaration(ConstructorDeclaration node) { | 934 Object visitConstructorDeclaration(ConstructorDeclaration node) { |
| 756 DartUnitHighlightsComputer_this._addRegion_token(node.externalKeyword, Highl
ightType.BUILT_IN); | 935 DartUnitHighlightsComputer_this._addRegion_token(node.externalKeyword, psi.H
ighlightType.BUILT_IN); |
| 757 DartUnitHighlightsComputer_this._addRegion_token(node.factoryKeyword, Highli
ghtType.BUILT_IN); | 936 DartUnitHighlightsComputer_this._addRegion_token(node.factoryKeyword, psi.Hi
ghlightType.BUILT_IN); |
| 758 return super.visitConstructorDeclaration(node); | 937 return super.visitConstructorDeclaration(node); |
| 759 } | 938 } |
| 760 | 939 |
| 761 @override | 940 @override |
| 762 Object visitDoubleLiteral(DoubleLiteral node) { | 941 Object visitDoubleLiteral(DoubleLiteral node) { |
| 763 DartUnitHighlightsComputer_this._addRegion_node(node, HighlightType.LITERAL_
DOUBLE); | 942 DartUnitHighlightsComputer_this._addRegion_node(node, psi.HighlightType.LITE
RAL_DOUBLE); |
| 764 return super.visitDoubleLiteral(node); | 943 return super.visitDoubleLiteral(node); |
| 765 } | 944 } |
| 766 | 945 |
| 767 @override | 946 @override |
| 768 Object visitExportDirective(ExportDirective node) { | 947 Object visitExportDirective(ExportDirective node) { |
| 769 DartUnitHighlightsComputer_this._addRegion_token(node.keyword, HighlightType
.BUILT_IN); | 948 DartUnitHighlightsComputer_this._addRegion_token(node.keyword, psi.Highlight
Type.BUILT_IN); |
| 770 return super.visitExportDirective(node); | 949 return super.visitExportDirective(node); |
| 771 } | 950 } |
| 772 | 951 |
| 773 @override | 952 @override |
| 774 Object visitFieldDeclaration(FieldDeclaration node) { | 953 Object visitFieldDeclaration(FieldDeclaration node) { |
| 775 DartUnitHighlightsComputer_this._addRegion_token(node.staticKeyword, Highlig
htType.BUILT_IN); | 954 DartUnitHighlightsComputer_this._addRegion_token(node.staticKeyword, psi.Hig
hlightType.BUILT_IN); |
| 776 return super.visitFieldDeclaration(node); | 955 return super.visitFieldDeclaration(node); |
| 777 } | 956 } |
| 778 | 957 |
| 779 @override | 958 @override |
| 780 Object visitFunctionDeclaration(FunctionDeclaration node) { | 959 Object visitFunctionDeclaration(FunctionDeclaration node) { |
| 781 DartUnitHighlightsComputer_this._addRegion_token(node.externalKeyword, Highl
ightType.BUILT_IN); | 960 DartUnitHighlightsComputer_this._addRegion_token(node.externalKeyword, psi.H
ighlightType.BUILT_IN); |
| 782 DartUnitHighlightsComputer_this._addRegion_token(node.propertyKeyword, Highl
ightType.BUILT_IN); | 961 DartUnitHighlightsComputer_this._addRegion_token(node.propertyKeyword, psi.H
ighlightType.BUILT_IN); |
| 783 return super.visitFunctionDeclaration(node); | 962 return super.visitFunctionDeclaration(node); |
| 784 } | 963 } |
| 785 | 964 |
| 786 @override | 965 @override |
| 787 Object visitFunctionTypeAlias(FunctionTypeAlias node) { | 966 Object visitFunctionTypeAlias(FunctionTypeAlias node) { |
| 788 DartUnitHighlightsComputer_this._addRegion_token(node.keyword, HighlightType
.BUILT_IN); | 967 DartUnitHighlightsComputer_this._addRegion_token(node.keyword, psi.Highlight
Type.BUILT_IN); |
| 789 return super.visitFunctionTypeAlias(node); | 968 return super.visitFunctionTypeAlias(node); |
| 790 } | 969 } |
| 791 | 970 |
| 792 @override | 971 @override |
| 793 Object visitHideCombinator(HideCombinator node) { | 972 Object visitHideCombinator(HideCombinator node) { |
| 794 DartUnitHighlightsComputer_this._addRegion_token(node.keyword, HighlightType
.BUILT_IN); | 973 DartUnitHighlightsComputer_this._addRegion_token(node.keyword, psi.Highlight
Type.BUILT_IN); |
| 795 return super.visitHideCombinator(node); | 974 return super.visitHideCombinator(node); |
| 796 } | 975 } |
| 797 | 976 |
| 798 @override | 977 @override |
| 799 Object visitImplementsClause(ImplementsClause node) { | 978 Object visitImplementsClause(ImplementsClause node) { |
| 800 DartUnitHighlightsComputer_this._addRegion_token(node.keyword, HighlightType
.BUILT_IN); | 979 DartUnitHighlightsComputer_this._addRegion_token(node.keyword, psi.Highlight
Type.BUILT_IN); |
| 801 return super.visitImplementsClause(node); | 980 return super.visitImplementsClause(node); |
| 802 } | 981 } |
| 803 | 982 |
| 804 @override | 983 @override |
| 805 Object visitImportDirective(ImportDirective node) { | 984 Object visitImportDirective(ImportDirective node) { |
| 806 DartUnitHighlightsComputer_this._addRegion_token(node.keyword, HighlightType
.BUILT_IN); | 985 DartUnitHighlightsComputer_this._addRegion_token(node.keyword, psi.Highlight
Type.BUILT_IN); |
| 807 DartUnitHighlightsComputer_this._addRegion_token(node.deferredToken, Highlig
htType.BUILT_IN); | 986 DartUnitHighlightsComputer_this._addRegion_token(node.deferredToken, psi.Hig
hlightType.BUILT_IN); |
| 808 DartUnitHighlightsComputer_this._addRegion_token(node.asToken, HighlightType
.BUILT_IN); | 987 DartUnitHighlightsComputer_this._addRegion_token(node.asToken, psi.Highlight
Type.BUILT_IN); |
| 809 return super.visitImportDirective(node); | 988 return super.visitImportDirective(node); |
| 810 } | 989 } |
| 811 | 990 |
| 812 @override | 991 @override |
| 813 Object visitIntegerLiteral(IntegerLiteral node) { | 992 Object visitIntegerLiteral(IntegerLiteral node) { |
| 814 DartUnitHighlightsComputer_this._addRegion_node(node, HighlightType.LITERAL_
INTEGER); | 993 DartUnitHighlightsComputer_this._addRegion_node(node, psi.HighlightType.LITE
RAL_INTEGER); |
| 815 return super.visitIntegerLiteral(node); | 994 return super.visitIntegerLiteral(node); |
| 816 } | 995 } |
| 817 | 996 |
| 818 @override | 997 @override |
| 819 Object visitLibraryDirective(LibraryDirective node) { | 998 Object visitLibraryDirective(LibraryDirective node) { |
| 820 DartUnitHighlightsComputer_this._addRegion_token(node.keyword, HighlightType
.BUILT_IN); | 999 DartUnitHighlightsComputer_this._addRegion_token(node.keyword, psi.Highlight
Type.BUILT_IN); |
| 821 return super.visitLibraryDirective(node); | 1000 return super.visitLibraryDirective(node); |
| 822 } | 1001 } |
| 823 | 1002 |
| 824 @override | 1003 @override |
| 825 Object visitMethodDeclaration(MethodDeclaration node) { | 1004 Object visitMethodDeclaration(MethodDeclaration node) { |
| 826 DartUnitHighlightsComputer_this._addRegion_token(node.externalKeyword, Highl
ightType.BUILT_IN); | 1005 DartUnitHighlightsComputer_this._addRegion_token(node.externalKeyword, psi.H
ighlightType.BUILT_IN); |
| 827 DartUnitHighlightsComputer_this._addRegion_token(node.modifierKeyword, Highl
ightType.BUILT_IN); | 1006 DartUnitHighlightsComputer_this._addRegion_token(node.modifierKeyword, psi.H
ighlightType.BUILT_IN); |
| 828 DartUnitHighlightsComputer_this._addRegion_token(node.operatorKeyword, Highl
ightType.BUILT_IN); | 1007 DartUnitHighlightsComputer_this._addRegion_token(node.operatorKeyword, psi.H
ighlightType.BUILT_IN); |
| 829 DartUnitHighlightsComputer_this._addRegion_token(node.propertyKeyword, Highl
ightType.BUILT_IN); | 1008 DartUnitHighlightsComputer_this._addRegion_token(node.propertyKeyword, psi.H
ighlightType.BUILT_IN); |
| 830 return super.visitMethodDeclaration(node); | 1009 return super.visitMethodDeclaration(node); |
| 831 } | 1010 } |
| 832 | 1011 |
| 833 @override | 1012 @override |
| 834 Object visitNativeClause(NativeClause node) { | 1013 Object visitNativeClause(NativeClause node) { |
| 835 DartUnitHighlightsComputer_this._addRegion_token(node.keyword, HighlightType
.BUILT_IN); | 1014 DartUnitHighlightsComputer_this._addRegion_token(node.keyword, psi.Highlight
Type.BUILT_IN); |
| 836 return super.visitNativeClause(node); | 1015 return super.visitNativeClause(node); |
| 837 } | 1016 } |
| 838 | 1017 |
| 839 @override | 1018 @override |
| 840 Object visitNativeFunctionBody(NativeFunctionBody node) { | 1019 Object visitNativeFunctionBody(NativeFunctionBody node) { |
| 841 DartUnitHighlightsComputer_this._addRegion_token(node.nativeToken, Highlight
Type.BUILT_IN); | 1020 DartUnitHighlightsComputer_this._addRegion_token(node.nativeToken, psi.Highl
ightType.BUILT_IN); |
| 842 return super.visitNativeFunctionBody(node); | 1021 return super.visitNativeFunctionBody(node); |
| 843 } | 1022 } |
| 844 | 1023 |
| 845 @override | 1024 @override |
| 846 Object visitPartDirective(PartDirective node) { | 1025 Object visitPartDirective(PartDirective node) { |
| 847 DartUnitHighlightsComputer_this._addRegion_token(node.keyword, HighlightType
.BUILT_IN); | 1026 DartUnitHighlightsComputer_this._addRegion_token(node.keyword, psi.Highlight
Type.BUILT_IN); |
| 848 return super.visitPartDirective(node); | 1027 return super.visitPartDirective(node); |
| 849 } | 1028 } |
| 850 | 1029 |
| 851 @override | 1030 @override |
| 852 Object visitPartOfDirective(PartOfDirective node) { | 1031 Object visitPartOfDirective(PartOfDirective node) { |
| 853 DartUnitHighlightsComputer_this._addRegion_tokenStart_tokenEnd(node.partToke
n, node.ofToken, HighlightType.BUILT_IN); | 1032 DartUnitHighlightsComputer_this._addRegion_tokenStart_tokenEnd(node.partToke
n, node.ofToken, psi.HighlightType.BUILT_IN); |
| 854 return super.visitPartOfDirective(node); | 1033 return super.visitPartOfDirective(node); |
| 855 } | 1034 } |
| 856 | 1035 |
| 857 @override | 1036 @override |
| 858 Object visitShowCombinator(ShowCombinator node) { | 1037 Object visitShowCombinator(ShowCombinator node) { |
| 859 DartUnitHighlightsComputer_this._addRegion_token(node.keyword, HighlightType
.BUILT_IN); | 1038 DartUnitHighlightsComputer_this._addRegion_token(node.keyword, psi.Highlight
Type.BUILT_IN); |
| 860 return super.visitShowCombinator(node); | 1039 return super.visitShowCombinator(node); |
| 861 } | 1040 } |
| 862 | 1041 |
| 863 @override | 1042 @override |
| 864 Object visitSimpleIdentifier(SimpleIdentifier node) { | 1043 Object visitSimpleIdentifier(SimpleIdentifier node) { |
| 865 DartUnitHighlightsComputer_this._addIdentifierRegion(node); | 1044 DartUnitHighlightsComputer_this._addIdentifierRegion(node); |
| 866 return super.visitSimpleIdentifier(node); | 1045 return super.visitSimpleIdentifier(node); |
| 867 } | 1046 } |
| 868 | 1047 |
| 869 @override | 1048 @override |
| 870 Object visitSimpleStringLiteral(SimpleStringLiteral node) { | 1049 Object visitSimpleStringLiteral(SimpleStringLiteral node) { |
| 871 DartUnitHighlightsComputer_this._addRegion_node(node, HighlightType.LITERAL_
STRING); | 1050 DartUnitHighlightsComputer_this._addRegion_node(node, psi.HighlightType.LITE
RAL_STRING); |
| 872 return super.visitSimpleStringLiteral(node); | 1051 return super.visitSimpleStringLiteral(node); |
| 873 } | 1052 } |
| 874 | 1053 |
| 875 @override | 1054 @override |
| 876 Object visitTypeName(TypeName node) { | 1055 Object visitTypeName(TypeName node) { |
| 877 DartType type = node.type; | 1056 DartType type = node.type; |
| 878 if (type != null) { | 1057 if (type != null) { |
| 879 if (type.isDynamic && node.name.name == "dynamic") { | 1058 if (type.isDynamic && node.name.name == "dynamic") { |
| 880 DartUnitHighlightsComputer_this._addRegion_node(node, HighlightType.TYPE
_NAME_DYNAMIC); | 1059 DartUnitHighlightsComputer_this._addRegion_node(node, psi.HighlightType.
TYPE_NAME_DYNAMIC); |
| 881 return null; | 1060 return null; |
| 882 } | 1061 } |
| 883 } | 1062 } |
| 884 return super.visitTypeName(node); | 1063 return super.visitTypeName(node); |
| 885 } | 1064 } |
| 886 } | 1065 } |
| 887 | 1066 |
| 888 class RecursiveAstVisitor_DartUnitNavigationComputer_compute extends RecursiveAs
tVisitor<Object> { | 1067 class RecursiveAstVisitor_DartUnitNavigationComputer_compute extends RecursiveAs
tVisitor<Object> { |
| 889 final DartUnitNavigationComputer DartUnitNavigationComputer_this; | 1068 final DartUnitNavigationComputer DartUnitNavigationComputer_this; |
| 890 | 1069 |
| 891 RecursiveAstVisitor_DartUnitNavigationComputer_compute(this.DartUnitNavigation
Computer_this) : super(); | 1070 RecursiveAstVisitor_DartUnitNavigationComputer_compute(this.DartUnitNavigation
Computer_this) : super(); |
| 892 | 1071 |
| 893 @override | 1072 @override |
| 894 Object visitAssignmentExpression(AssignmentExpression node) { | 1073 Object visitAssignmentExpression(AssignmentExpression node) { |
| 895 DartUnitNavigationComputer_this._addRegionForToken(node.operator, node.bestE
lement); | 1074 DartUnitNavigationComputer_this._addRegionForToken(node.operator, node.bestE
lement); |
| 896 return super.visitAssignmentExpression(node); | 1075 return super.visitAssignmentExpression(node); |
| 897 } | 1076 } |
| 898 | 1077 |
| 899 @override | 1078 @override |
| 900 Object visitBinaryExpression(BinaryExpression node) { | 1079 Object visitBinaryExpression(BinaryExpression node) { |
| 901 DartUnitNavigationComputer_this._addRegionForToken(node.operator, node.bestE
lement); | 1080 DartUnitNavigationComputer_this._addRegionForToken(node.operator, node.bestE
lement); |
| 902 return super.visitBinaryExpression(node); | 1081 return super.visitBinaryExpression(node); |
| 903 } | 1082 } |
| 904 | 1083 |
| 905 @override | 1084 @override |
| 906 Object visitExportDirective(ExportDirective node) { | 1085 Object visitExportDirective(ExportDirective node) { |
| 907 ExportElement exportElement = node.element; | 1086 pae.ExportElement exportElement = node.element; |
| 908 if (exportElement != null) { | 1087 if (exportElement != null) { |
| 909 Element element = exportElement.exportedLibrary; | 1088 pae.Element element = exportElement.exportedLibrary; |
| 910 DartUnitNavigationComputer_this._addRegion_tokenStart_nodeEnd(node.keyword
, node.uri, element); | 1089 DartUnitNavigationComputer_this._addRegion_tokenStart_nodeEnd(node.keyword
, node.uri, element); |
| 911 } | 1090 } |
| 912 return super.visitExportDirective(node); | 1091 return super.visitExportDirective(node); |
| 913 } | 1092 } |
| 914 | 1093 |
| 915 @override | 1094 @override |
| 916 Object visitImportDirective(ImportDirective node) { | 1095 Object visitImportDirective(ImportDirective node) { |
| 917 ImportElement importElement = node.element; | 1096 pae.ImportElement importElement = node.element; |
| 918 if (importElement != null) { | 1097 if (importElement != null) { |
| 919 Element element = importElement.importedLibrary; | 1098 pae.Element element = importElement.importedLibrary; |
| 920 DartUnitNavigationComputer_this._addRegion_tokenStart_nodeEnd(node.keyword
, node.uri, element); | 1099 DartUnitNavigationComputer_this._addRegion_tokenStart_nodeEnd(node.keyword
, node.uri, element); |
| 921 } | 1100 } |
| 922 return super.visitImportDirective(node); | 1101 return super.visitImportDirective(node); |
| 923 } | 1102 } |
| 924 | 1103 |
| 925 @override | 1104 @override |
| 926 Object visitIndexExpression(IndexExpression node) { | 1105 Object visitIndexExpression(IndexExpression node) { |
| 927 DartUnitNavigationComputer_this._addRegionForToken(node.rightBracket, node.b
estElement); | 1106 DartUnitNavigationComputer_this._addRegionForToken(node.rightBracket, node.b
estElement); |
| 928 return super.visitIndexExpression(node); | 1107 return super.visitIndexExpression(node); |
| 929 } | 1108 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 955 @override | 1134 @override |
| 956 Object visitSimpleIdentifier(SimpleIdentifier node) { | 1135 Object visitSimpleIdentifier(SimpleIdentifier node) { |
| 957 DartUnitNavigationComputer_this._addRegionForNode(node, node.bestElement); | 1136 DartUnitNavigationComputer_this._addRegionForNode(node, node.bestElement); |
| 958 return super.visitSimpleIdentifier(node); | 1137 return super.visitSimpleIdentifier(node); |
| 959 } | 1138 } |
| 960 } | 1139 } |
| 961 | 1140 |
| 962 class RecursiveAstVisitor_DartUnitOutlineComputer_addLocalFunctionOutlines exten
ds RecursiveAstVisitor<Object> { | 1141 class RecursiveAstVisitor_DartUnitOutlineComputer_addLocalFunctionOutlines exten
ds RecursiveAstVisitor<Object> { |
| 963 final DartUnitOutlineComputer DartUnitOutlineComputer_this; | 1142 final DartUnitOutlineComputer DartUnitOutlineComputer_this; |
| 964 | 1143 |
| 965 OutlineImpl parenet; | 1144 OutlineImpl parent; |
| 966 | 1145 |
| 967 List<Outline> localOutlines; | 1146 List<psi.Outline> localOutlines; |
| 968 | 1147 |
| 969 RecursiveAstVisitor_DartUnitOutlineComputer_addLocalFunctionOutlines(this.Dart
UnitOutlineComputer_this, this.parenet, this.localOutlines) : super(); | 1148 RecursiveAstVisitor_DartUnitOutlineComputer_addLocalFunctionOutlines(this.Dart
UnitOutlineComputer_this, this.parent, this.localOutlines) : super(); |
| 970 | 1149 |
| 971 @override | 1150 @override |
| 972 Object visitFunctionDeclaration(FunctionDeclaration node) { | 1151 Object visitFunctionDeclaration(FunctionDeclaration node) { |
| 973 DartUnitOutlineComputer_this._newFunctionOutline(parenet, localOutlines, nod
e); | 1152 DartUnitOutlineComputer_this._newFunctionOutline(parent, localOutlines, node
); |
| 974 return null; | 1153 return null; |
| 975 } | 1154 } |
| 1155 |
| 1156 @override |
| 1157 Object visitMethodInvocation(MethodInvocation node) { |
| 1158 bool handled = DartUnitOutlineComputer_this._addUnitTestOutlines(parent, loc
alOutlines, node); |
| 1159 if (handled) { |
| 1160 return null; |
| 1161 } |
| 1162 return super.visitMethodInvocation(node); |
| 1163 } |
| 1164 } |
| 1165 |
| 1166 /** |
| 1167 * A concrete implementation of [SearchResult]. |
| 1168 */ |
| 1169 class SearchResultImpl implements psi.SearchResult { |
| 1170 final List<psi.Element> path; |
| 1171 |
| 1172 final Source source; |
| 1173 |
| 1174 final psi.SearchResultKind kind; |
| 1175 |
| 1176 final int offset; |
| 1177 |
| 1178 final int length; |
| 1179 |
| 1180 SearchResultImpl(this.path, this.source, this.kind, this.offset, this.length); |
| 1181 |
| 1182 @override |
| 1183 String toString() { |
| 1184 JavaStringBuilder builder = new JavaStringBuilder(); |
| 1185 builder.append("[source="); |
| 1186 builder.append(source); |
| 1187 builder.append(", kind="); |
| 1188 builder.append(kind); |
| 1189 builder.append(", offset="); |
| 1190 builder.append(offset); |
| 1191 builder.append(", length="); |
| 1192 builder.append(length); |
| 1193 builder.append(", path="); |
| 1194 builder.append(path); |
| 1195 builder.append("]"); |
| 1196 return builder.toString(); |
| 1197 } |
| 976 } | 1198 } |
| 977 | 1199 |
| 978 /** | 1200 /** |
| 979 * A concrete implementation of [SourceRegion]. | 1201 * A concrete implementation of [SourceRegion]. |
| 980 */ | 1202 */ |
| 981 class SourceRegionImpl implements SourceRegion { | 1203 class SourceRegionImpl implements psi.SourceRegion { |
| 982 final int offset; | 1204 final int offset; |
| 983 | 1205 |
| 984 final int length; | 1206 final int length; |
| 985 | 1207 |
| 986 SourceRegionImpl(this.offset, this.length); | 1208 SourceRegionImpl(this.offset, this.length); |
| 987 | 1209 |
| 988 @override | 1210 @override |
| 989 bool containsInclusive(int x) => offset <= x && x <= offset + length; | 1211 bool containsInclusive(int x) => offset <= x && x <= offset + length; |
| 990 | 1212 |
| 991 @override | 1213 @override |
| 992 bool operator ==(Object obj) { | 1214 bool operator ==(Object obj) { |
| 993 if (identical(obj, this)) { | 1215 if (identical(obj, this)) { |
| 994 return true; | 1216 return true; |
| 995 } | 1217 } |
| 996 if (obj is! SourceRegion) { | 1218 if (obj is! psi.SourceRegion) { |
| 997 return false; | 1219 return false; |
| 998 } | 1220 } |
| 999 SourceRegion other = obj as SourceRegion; | 1221 psi.SourceRegion other = obj as psi.SourceRegion; |
| 1000 return other.offset == offset && other.length == length; | 1222 return other.offset == offset && other.length == length; |
| 1001 } | 1223 } |
| 1002 | 1224 |
| 1003 @override | 1225 @override |
| 1004 int get hashCode => ObjectUtilities.combineHashCodes(offset, length); | 1226 int get hashCode => ObjectUtilities.combineHashCodes(offset, length); |
| 1005 | 1227 |
| 1006 @override | 1228 @override |
| 1007 String toString() { | 1229 String toString() { |
| 1008 JavaStringBuilder builder = new JavaStringBuilder(); | 1230 JavaStringBuilder builder = new JavaStringBuilder(); |
| 1009 builder.append("[offset="); | 1231 builder.append("[offset="); |
| 1010 builder.append(offset); | 1232 builder.append(offset); |
| 1011 builder.append(", length="); | 1233 builder.append(", length="); |
| 1012 builder.append(length); | 1234 builder.append(length); |
| 1013 builder.append("]"); | 1235 builder.append("]"); |
| 1014 return builder.toString(); | 1236 return builder.toString(); |
| 1015 } | 1237 } |
| 1016 } | 1238 } |
| OLD | NEW |