| 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.element; | 5 library computer.element; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/constants.dart'; | 7 import 'package:analysis_server/src/constants.dart'; |
| 8 import 'package:analysis_server/src/protocol2.dart'; |
| 8 import 'package:analyzer/src/generated/element.dart' as engine; | 9 import 'package:analyzer/src/generated/element.dart' as engine; |
| 9 import 'package:analyzer/src/generated/source.dart'; | 10 import 'package:analyzer/src/generated/source.dart'; |
| 10 import 'package:analyzer/src/generated/utilities_dart.dart' as engine; | 11 import 'package:analyzer/src/generated/utilities_dart.dart' as engine; |
| 11 | 12 |
| 12 | 13 |
| 13 /** | 14 /** |
| 14 * Returns a JSON correponding to the given Engine element. | 15 * Returns a JSON correponding to the given Engine element. |
| 15 */ | 16 */ |
| 16 Map<String, Object> engineElementToJson(engine.Element element) { | 17 Map<String, Object> engineElementToJson(engine.Element element) { |
| 17 return new Element.fromEngine(element).toJson(); | 18 return new Element.fromEngine(element).toJson(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 70 |
| 70 Element(this.kind, this.name, this.location, this.isPrivate, | 71 Element(this.kind, this.name, this.location, this.isPrivate, |
| 71 this.isDeprecated, {this.parameters, this.returnType, this.isAbstract: fal
se, | 72 this.isDeprecated, {this.parameters, this.returnType, this.isAbstract: fal
se, |
| 72 this.isConst: false, this.isFinal: false, this.isStatic: false}); | 73 this.isConst: false, this.isFinal: false, this.isStatic: false}); |
| 73 | 74 |
| 74 factory Element.fromEngine(engine.Element element) { | 75 factory Element.fromEngine(engine.Element element) { |
| 75 String name = element.displayName; | 76 String name = element.displayName; |
| 76 String elementParameters = _getParametersString(element); | 77 String elementParameters = _getParametersString(element); |
| 77 String elementReturnType = _getReturnTypeString(element); | 78 String elementReturnType = _getReturnTypeString(element); |
| 78 return new Element( | 79 return new Element( |
| 79 ElementKind.valueOfEngine(element.kind), | 80 elementKindFromEngine(element.kind), |
| 80 name, | 81 name, |
| 81 new Location.fromElement(element), | 82 new Location.fromElement(element), |
| 82 element.isPrivate, | 83 element.isPrivate, |
| 83 element.isDeprecated, | 84 element.isDeprecated, |
| 84 parameters: elementParameters, | 85 parameters: elementParameters, |
| 85 returnType: elementReturnType, | 86 returnType: elementReturnType, |
| 86 isAbstract: _isAbstract(element), | 87 isAbstract: _isAbstract(element), |
| 87 isConst: _isConst(element), | 88 isConst: _isConst(element), |
| 88 isFinal: _isFinal(element), | 89 isFinal: _isFinal(element), |
| 89 isStatic: _isStatic(element)); | 90 isStatic: _isStatic(element)); |
| 90 } | 91 } |
| 91 | 92 |
| 92 factory Element.fromJson(Map<String, Object> map) { | 93 factory Element.fromJson(Map<String, Object> map) { |
| 93 ElementKind kind = ElementKind.valueOf(map[KIND]); | 94 ElementKind kind = new ElementKind(map[KIND]); |
| 94 int flags = map[FLAGS]; | 95 int flags = map[FLAGS]; |
| 95 return new Element( | 96 return new Element( |
| 96 kind, | 97 kind, |
| 97 map[NAME], | 98 map[NAME], |
| 98 new Location.fromJson(map[LOCATION]), | 99 new Location.fromJson(map[LOCATION]), |
| 99 _hasFlag(flags, FLAG_PRIVATE), | 100 _hasFlag(flags, FLAG_PRIVATE), |
| 100 _hasFlag(flags, FLAG_DEPRECATED), | 101 _hasFlag(flags, FLAG_DEPRECATED), |
| 101 parameters: map[PARAMETERS], | 102 parameters: map[PARAMETERS], |
| 102 returnType: map[RETURN_TYPE], | 103 returnType: map[RETURN_TYPE], |
| 103 isAbstract: _hasFlag(flags, FLAG_ABSTRACT), | 104 isAbstract: _hasFlag(flags, FLAG_ABSTRACT), |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 return element.isStatic; | 218 return element.isStatic; |
| 218 } | 219 } |
| 219 if (element is engine.PropertyInducingElement) { | 220 if (element is engine.PropertyInducingElement) { |
| 220 return element.isStatic; | 221 return element.isStatic; |
| 221 } | 222 } |
| 222 return false; | 223 return false; |
| 223 } | 224 } |
| 224 } | 225 } |
| 225 | 226 |
| 226 | 227 |
| 227 /** | 228 ElementKind elementKindFromEngine(engine.ElementKind kind) { |
| 228 * An enumeration of the kinds of elements. | 229 if (kind == engine.ElementKind.CLASS) { |
| 229 */ | 230 return ElementKind.CLASS; |
| 230 class ElementKind { | |
| 231 static const CLASS = const ElementKind('CLASS'); | |
| 232 static const CLASS_TYPE_ALIAS = const ElementKind('CLASS_TYPE_ALIAS'); | |
| 233 static const COMPILATION_UNIT = const ElementKind('COMPILATION_UNIT'); | |
| 234 static const CONSTRUCTOR = const ElementKind('CONSTRUCTOR'); | |
| 235 static const FIELD = const ElementKind('FIELD'); | |
| 236 static const FUNCTION = const ElementKind('FUNCTION'); | |
| 237 static const FUNCTION_TYPE_ALIAS = const ElementKind('FUNCTION_TYPE_ALIAS'); | |
| 238 static const GETTER = const ElementKind('GETTER'); | |
| 239 static const LIBRARY = const ElementKind('LIBRARY'); | |
| 240 static const LOCAL_VARIABLE = const ElementKind('LOCAL_VARIABLE'); | |
| 241 static const METHOD = const ElementKind('METHOD'); | |
| 242 static const PARAMETER = const ElementKind('PARAMETER'); | |
| 243 static const SETTER = const ElementKind('SETTER'); | |
| 244 static const TOP_LEVEL_VARIABLE = const ElementKind('TOP_LEVEL_VARIABLE'); | |
| 245 static const TYPE_PARAMETER = const ElementKind('TYPE_PARAMETER'); | |
| 246 static const UNIT_TEST_CASE = const ElementKind('UNIT_TEST_CASE'); | |
| 247 static const UNIT_TEST_GROUP = const ElementKind('UNIT_TEST_GROUP'); | |
| 248 static const UNKNOWN = const ElementKind('UNKNOWN'); | |
| 249 | |
| 250 final String name; | |
| 251 | |
| 252 const ElementKind(this.name); | |
| 253 | |
| 254 @override | |
| 255 String toString() => name; | |
| 256 | |
| 257 static ElementKind valueOf(String name) { | |
| 258 if (CLASS.name == name) return CLASS; | |
| 259 if (CLASS_TYPE_ALIAS.name == name) return CLASS_TYPE_ALIAS; | |
| 260 if (COMPILATION_UNIT.name == name) return COMPILATION_UNIT; | |
| 261 if (CONSTRUCTOR.name == name) return CONSTRUCTOR; | |
| 262 if (FIELD.name == name) return FIELD; | |
| 263 if (FUNCTION.name == name) return FUNCTION; | |
| 264 if (FUNCTION_TYPE_ALIAS.name == name) return FUNCTION_TYPE_ALIAS; | |
| 265 if (GETTER.name == name) return GETTER; | |
| 266 if (LIBRARY.name == name) return LIBRARY; | |
| 267 if (LOCAL_VARIABLE.name == name) return LOCAL_VARIABLE; | |
| 268 if (METHOD.name == name) return METHOD; | |
| 269 if (PARAMETER.name == name) return PARAMETER; | |
| 270 if (SETTER.name == name) return SETTER; | |
| 271 if (TOP_LEVEL_VARIABLE.name == name) return TOP_LEVEL_VARIABLE; | |
| 272 if (TYPE_PARAMETER.name == name) return TYPE_PARAMETER; | |
| 273 if (UNIT_TEST_CASE.name == name) return UNIT_TEST_CASE; | |
| 274 if (UNIT_TEST_GROUP.name == name) return UNIT_TEST_GROUP; | |
| 275 if (UNKNOWN.name == name) return UNKNOWN; | |
| 276 throw new ArgumentError('Unknown ElementKind: $name'); | |
| 277 } | 231 } |
| 278 | 232 if (kind == engine.ElementKind.COMPILATION_UNIT) { |
| 279 static ElementKind valueOfEngine(engine.ElementKind kind) { | 233 return ElementKind.COMPILATION_UNIT; |
| 280 if (kind == engine.ElementKind.CLASS) { | |
| 281 return CLASS; | |
| 282 } | |
| 283 if (kind == engine.ElementKind.COMPILATION_UNIT) { | |
| 284 return COMPILATION_UNIT; | |
| 285 } | |
| 286 if (kind == engine.ElementKind.CONSTRUCTOR) { | |
| 287 return CONSTRUCTOR; | |
| 288 } | |
| 289 if (kind == engine.ElementKind.FIELD) { | |
| 290 return FIELD; | |
| 291 } | |
| 292 if (kind == engine.ElementKind.FUNCTION) { | |
| 293 return FUNCTION; | |
| 294 } | |
| 295 if (kind == engine.ElementKind.FUNCTION_TYPE_ALIAS) { | |
| 296 return FUNCTION_TYPE_ALIAS; | |
| 297 } | |
| 298 if (kind == engine.ElementKind.GETTER) { | |
| 299 return GETTER; | |
| 300 } | |
| 301 if (kind == engine.ElementKind.LIBRARY) { | |
| 302 return LIBRARY; | |
| 303 } | |
| 304 if (kind == engine.ElementKind.LOCAL_VARIABLE) { | |
| 305 return LOCAL_VARIABLE; | |
| 306 } | |
| 307 if (kind == engine.ElementKind.METHOD) { | |
| 308 return METHOD; | |
| 309 } | |
| 310 if (kind == engine.ElementKind.PARAMETER) { | |
| 311 return PARAMETER; | |
| 312 } | |
| 313 if (kind == engine.ElementKind.SETTER) { | |
| 314 return SETTER; | |
| 315 } | |
| 316 if (kind == engine.ElementKind.TOP_LEVEL_VARIABLE) { | |
| 317 return TOP_LEVEL_VARIABLE; | |
| 318 } | |
| 319 if (kind == engine.ElementKind.TYPE_PARAMETER) { | |
| 320 return TYPE_PARAMETER; | |
| 321 } | |
| 322 return UNKNOWN; | |
| 323 } | 234 } |
| 235 if (kind == engine.ElementKind.CONSTRUCTOR) { |
| 236 return ElementKind.CONSTRUCTOR; |
| 237 } |
| 238 if (kind == engine.ElementKind.FIELD) { |
| 239 return ElementKind.FIELD; |
| 240 } |
| 241 if (kind == engine.ElementKind.FUNCTION) { |
| 242 return ElementKind.FUNCTION; |
| 243 } |
| 244 if (kind == engine.ElementKind.FUNCTION_TYPE_ALIAS) { |
| 245 return ElementKind.FUNCTION_TYPE_ALIAS; |
| 246 } |
| 247 if (kind == engine.ElementKind.GETTER) { |
| 248 return ElementKind.GETTER; |
| 249 } |
| 250 if (kind == engine.ElementKind.LIBRARY) { |
| 251 return ElementKind.LIBRARY; |
| 252 } |
| 253 if (kind == engine.ElementKind.LOCAL_VARIABLE) { |
| 254 return ElementKind.LOCAL_VARIABLE; |
| 255 } |
| 256 if (kind == engine.ElementKind.METHOD) { |
| 257 return ElementKind.METHOD; |
| 258 } |
| 259 if (kind == engine.ElementKind.PARAMETER) { |
| 260 return ElementKind.PARAMETER; |
| 261 } |
| 262 if (kind == engine.ElementKind.SETTER) { |
| 263 return ElementKind.SETTER; |
| 264 } |
| 265 if (kind == engine.ElementKind.TOP_LEVEL_VARIABLE) { |
| 266 return ElementKind.TOP_LEVEL_VARIABLE; |
| 267 } |
| 268 if (kind == engine.ElementKind.TYPE_PARAMETER) { |
| 269 return ElementKind.TYPE_PARAMETER; |
| 270 } |
| 271 return ElementKind.UNKNOWN; |
| 324 } | 272 } |
| 325 | 273 |
| 326 | 274 |
| 327 /** | 275 /** |
| 328 * Information about a location. | 276 * Information about a location. |
| 329 */ | 277 */ |
| 330 class Location { | 278 class Location { |
| 331 final String file; | 279 final String file; |
| 332 final int offset; | 280 final int offset; |
| 333 final int length; | 281 final int length; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 START_COLUMN: startColumn | 344 START_COLUMN: startColumn |
| 397 }; | 345 }; |
| 398 } | 346 } |
| 399 | 347 |
| 400 @override | 348 @override |
| 401 String toString() { | 349 String toString() { |
| 402 return 'Location(file=$file; offset=$offset; length=$length; ' | 350 return 'Location(file=$file; offset=$offset; length=$length; ' |
| 403 'startLine=$startLine; startColumn=$startColumn)'; | 351 'startLine=$startLine; startColumn=$startColumn)'; |
| 404 } | 352 } |
| 405 } | 353 } |
| OLD | NEW |