| 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 'dart:collection'; |
| 8 |
| 7 import 'package:analysis_server/src/constants.dart'; | 9 import 'package:analysis_server/src/constants.dart'; |
| 8 import 'package:analyzer/src/generated/element.dart' as engine; | 10 import 'package:analyzer/src/generated/element.dart' as engine; |
| 9 import 'package:analyzer/src/generated/utilities_dart.dart' as engine; | 11 import 'package:analyzer/src/generated/utilities_dart.dart' as engine; |
| 10 | 12 |
| 11 | 13 |
| 12 /** | 14 /** |
| 13 * Information about an element. | 15 * Information about an element. |
| 14 */ | 16 */ |
| 15 class Element { | 17 class Element { |
| 16 static const List<Element> EMPTY_ARRAY = const <Element>[]; | 18 static const List<Element> EMPTY_ARRAY = const <Element>[]; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 int nameLength = name != null ? name.length : 0; | 74 int nameLength = name != null ? name.length : 0; |
| 73 String elementParameters = _getParametersString(element); | 75 String elementParameters = _getParametersString(element); |
| 74 String elementReturnType = _getReturnTypeString(element); | 76 String elementReturnType = _getReturnTypeString(element); |
| 75 return new Element(ElementKind.valueOfEngine(element.kind), name, | 77 return new Element(ElementKind.valueOfEngine(element.kind), name, |
| 76 element.nameOffset, nameLength, element.isPrivate, element.isDeprecated, | 78 element.nameOffset, nameLength, element.isPrivate, element.isDeprecated, |
| 77 parameters: elementParameters, returnType: elementReturnType, isAbstract
: | 79 parameters: elementParameters, returnType: elementReturnType, isAbstract
: |
| 78 _isAbstract(element), isConst: _isConst(element), isFinal: _isFinal(elem
ent), | 80 _isAbstract(element), isConst: _isConst(element), isFinal: _isFinal(elem
ent), |
| 79 isStatic: _isStatic(element)); | 81 isStatic: _isStatic(element)); |
| 80 } | 82 } |
| 81 | 83 |
| 82 factory Element.fromJson(Map<String, Object> map) { | 84 factory Element.fromJson(HashMap<String, Object> map) { |
| 83 ElementKind kind = ElementKind.valueOf(map[KIND]); | 85 ElementKind kind = ElementKind.valueOf(map[KIND]); |
| 84 int flags = map[FLAGS]; | 86 int flags = map[FLAGS]; |
| 85 return new Element(kind, map[NAME], map[OFFSET], map[LENGTH], _hasFlag( | 87 return new Element(kind, map[NAME], map[OFFSET], map[LENGTH], _hasFlag( |
| 86 flags, FLAG_PRIVATE), _hasFlag(flags, FLAG_DEPRECATED), parameters: | 88 flags, FLAG_PRIVATE), _hasFlag(flags, FLAG_DEPRECATED), parameters: |
| 87 map[PARAMETERS], returnType: map[RETURN_TYPE], isAbstract: _hasFlag(flag
s, | 89 map[PARAMETERS], returnType: map[RETURN_TYPE], isAbstract: _hasFlag(flag
s, |
| 88 FLAG_ABSTRACT), isConst: _hasFlag(flags, FLAG_CONST), isFinal: _hasFlag(
flags, | 90 FLAG_ABSTRACT), isConst: _hasFlag(flags, FLAG_CONST), isFinal: _hasFlag(
flags, |
| 89 FLAG_FINAL), isStatic: _hasFlag(flags, FLAG_STATIC)); | 91 FLAG_FINAL), isStatic: _hasFlag(flags, FLAG_STATIC)); |
| 90 } | 92 } |
| 91 | 93 |
| 92 int get flags { | 94 int get flags { |
| 93 int flags = 0; | 95 int flags = 0; |
| 94 if (isAbstract) flags |= FLAG_ABSTRACT; | 96 if (isAbstract) flags |= FLAG_ABSTRACT; |
| 95 if (isConst) flags |= FLAG_CONST; | 97 if (isConst) flags |= FLAG_CONST; |
| 96 if (isFinal) flags |= FLAG_FINAL; | 98 if (isFinal) flags |= FLAG_FINAL; |
| 97 if (isStatic) flags |= FLAG_STATIC; | 99 if (isStatic) flags |= FLAG_STATIC; |
| 98 if (isPrivate) flags |= FLAG_PRIVATE; | 100 if (isPrivate) flags |= FLAG_PRIVATE; |
| 99 if (isDeprecated) flags |= FLAG_DEPRECATED; | 101 if (isDeprecated) flags |= FLAG_DEPRECATED; |
| 100 return flags; | 102 return flags; |
| 101 } | 103 } |
| 102 | 104 |
| 103 Map<String, Object> toJson() { | 105 HashMap<String, Object> toJson() { |
| 104 Map<String, Object> json = { | 106 HashMap<String, Object> json = { |
| 105 KIND: kind.name, | 107 KIND: kind.name, |
| 106 NAME: name, | 108 NAME: name, |
| 107 OFFSET: offset, | 109 OFFSET: offset, |
| 108 LENGTH: length, | 110 LENGTH: length, |
| 109 FLAGS: flags | 111 FLAGS: flags |
| 110 }; | 112 }; |
| 111 if (parameters != null) { | 113 if (parameters != null) { |
| 112 json[PARAMETERS] = parameters; | 114 json[PARAMETERS] = parameters; |
| 113 } | 115 } |
| 114 if (returnType != null) { | 116 if (returnType != null) { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 } | 279 } |
| 278 if (kind == engine.ElementKind.SETTER) { | 280 if (kind == engine.ElementKind.SETTER) { |
| 279 return SETTER; | 281 return SETTER; |
| 280 } | 282 } |
| 281 if (kind == engine.ElementKind.TOP_LEVEL_VARIABLE) { | 283 if (kind == engine.ElementKind.TOP_LEVEL_VARIABLE) { |
| 282 return TOP_LEVEL_VARIABLE; | 284 return TOP_LEVEL_VARIABLE; |
| 283 } | 285 } |
| 284 return UNKNOWN; | 286 return UNKNOWN; |
| 285 } | 287 } |
| 286 } | 288 } |
| OLD | NEW |