Chromium Code Reviews| 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 protocol.server; | 5 library protocol.server; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/protocol.dart'; | 7 import 'package:analysis_server/src/protocol.dart'; |
| 8 import 'package:analysis_server/src/services/search/search_engine.dart' | 8 import 'package:analysis_server/src/services/search/search_engine.dart' |
| 9 as engine; | 9 as engine; |
| 10 import 'package:analyzer/src/generated/ast.dart' as engine; | 10 import 'package:analyzer/src/generated/ast.dart' as engine; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 } | 80 } |
| 81 | 81 |
| 82 /** | 82 /** |
| 83 * Construct based on a value from the analyzer engine. | 83 * Construct based on a value from the analyzer engine. |
| 84 */ | 84 */ |
| 85 Element newElement_fromEngine(engine.Element element) { | 85 Element newElement_fromEngine(engine.Element element) { |
| 86 String name = element.displayName; | 86 String name = element.displayName; |
| 87 String elementTypeParameters = _getTypeParametersString(element); | 87 String elementTypeParameters = _getTypeParametersString(element); |
| 88 String elementParameters = _getParametersString(element); | 88 String elementParameters = _getParametersString(element); |
| 89 String elementReturnType = _getReturnTypeString(element); | 89 String elementReturnType = _getReturnTypeString(element); |
| 90 ElementKind kind = newElementKind_fromEngine(element.kind); | 90 ElementKind kind = newElementKind_fromEngineElement(element); |
| 91 // TODO(danrubel) this check should be in newElementKind_fromEngine | 91 return new Element(kind, name, Element.makeFlags( |
| 92 if (element is engine.ClassElement && element.isEnum) { | 92 isPrivate: element.isPrivate, |
| 93 kind = ElementKind.ENUM; | 93 isDeprecated: element.isDeprecated, |
| 94 } | 94 isAbstract: _isAbstract(element), |
| 95 return new Element(kind, name, Element | 95 isConst: _isConst(element), |
| 96 .makeFlags( | 96 isFinal: _isFinal(element), |
| 97 isPrivate: element.isPrivate, | 97 isStatic: _isStatic(element)), |
| 98 isDeprecated: element.isDeprecated, | |
| 99 isAbstract: _isAbstract(element), | |
| 100 isConst: _isConst(element), | |
| 101 isFinal: _isFinal(element), | |
| 102 isStatic: _isStatic(element)), | |
| 103 location: newLocation_fromElement(element), | 98 location: newLocation_fromElement(element), |
| 104 typeParameters: elementTypeParameters, | 99 typeParameters: elementTypeParameters, |
| 105 parameters: elementParameters, | 100 parameters: elementParameters, |
| 106 returnType: elementReturnType); | 101 returnType: elementReturnType); |
| 107 } | 102 } |
| 108 | 103 |
| 109 /** | 104 /** |
| 110 * Construct based on a value from the analyzer engine. | 105 * Construct based on a value from the analyzer engine. |
| 106 * This does not take into account that | |
| 107 * instances of ClassElement can be an enum and | |
| 108 * instances of FieldElement can be an enum constant. | |
| 109 * Use [newElementKind_fromEngineElement] where possible. | |
| 111 */ | 110 */ |
| 112 ElementKind newElementKind_fromEngine(engine.ElementKind kind) { | 111 ElementKind newElementKind_fromEngine(engine.ElementKind kind) { |
|
scheglov
2015/06/04 21:55:37
This function is always invoked for some "elementI
danrubel
2015/06/04 22:00:08
There are a number of tests for this method which
| |
| 113 if (kind == engine.ElementKind.CLASS) { | 112 if (kind == engine.ElementKind.CLASS) { |
| 114 // TODO(danrubel) check if element.isEnum and return ElementKind.ENUM | |
| 115 return ElementKind.CLASS; | 113 return ElementKind.CLASS; |
| 116 } | 114 } |
| 117 if (kind == engine.ElementKind.COMPILATION_UNIT) { | 115 if (kind == engine.ElementKind.COMPILATION_UNIT) { |
| 118 return ElementKind.COMPILATION_UNIT; | 116 return ElementKind.COMPILATION_UNIT; |
| 119 } | 117 } |
| 120 if (kind == engine.ElementKind.CONSTRUCTOR) { | 118 if (kind == engine.ElementKind.CONSTRUCTOR) { |
| 121 return ElementKind.CONSTRUCTOR; | 119 return ElementKind.CONSTRUCTOR; |
| 122 } | 120 } |
| 123 if (kind == engine.ElementKind.FIELD) { | 121 if (kind == engine.ElementKind.FIELD) { |
| 124 return ElementKind.FIELD; | 122 return ElementKind.FIELD; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 if (kind == engine.ElementKind.TOP_LEVEL_VARIABLE) { | 154 if (kind == engine.ElementKind.TOP_LEVEL_VARIABLE) { |
| 157 return ElementKind.TOP_LEVEL_VARIABLE; | 155 return ElementKind.TOP_LEVEL_VARIABLE; |
| 158 } | 156 } |
| 159 if (kind == engine.ElementKind.TYPE_PARAMETER) { | 157 if (kind == engine.ElementKind.TYPE_PARAMETER) { |
| 160 return ElementKind.TYPE_PARAMETER; | 158 return ElementKind.TYPE_PARAMETER; |
| 161 } | 159 } |
| 162 return ElementKind.UNKNOWN; | 160 return ElementKind.UNKNOWN; |
| 163 } | 161 } |
| 164 | 162 |
| 165 /** | 163 /** |
| 164 * Construct based on a value from the analyzer engine. | |
| 165 */ | |
| 166 ElementKind newElementKind_fromEngineElement(engine.Element element) { | |
| 167 if (element is engine.ClassElement && element.isEnum) { | |
| 168 return ElementKind.ENUM; | |
| 169 } | |
| 170 if (element is engine.FieldElement && element.isEnumConstant && | |
| 171 // MyEnum.values and MyEnum.one.index return isEnumConstant = true | |
| 172 // so these additional checks are necessary. | |
| 173 // TODO(danrubel) MyEnum.values is constant, but is a list | |
| 174 // so should it return isEnumConstant = true? | |
| 175 // MyEnum.one.index is final but *not* constant | |
| 176 // so should it return isEnumConstant = true? | |
| 177 // Or should we return ElementKind.ENUM_CONSTANT here | |
| 178 // in either or both of these cases? | |
| 179 element.type != null && | |
| 180 element.type.element == element.enclosingElement) { | |
| 181 return ElementKind.ENUM_CONSTANT; | |
| 182 } | |
| 183 return newElementKind_fromEngine(element.kind); | |
| 184 } | |
| 185 | |
| 186 /** | |
| 166 * Create a Location based on an [engine.Element]. | 187 * Create a Location based on an [engine.Element]. |
| 167 */ | 188 */ |
| 168 Location newLocation_fromElement(engine.Element element) { | 189 Location newLocation_fromElement(engine.Element element) { |
| 169 engine.AnalysisContext context = element.context; | 190 engine.AnalysisContext context = element.context; |
| 170 engine.Source source = element.source; | 191 engine.Source source = element.source; |
| 171 if (context == null || source == null) { | 192 if (context == null || source == null) { |
| 172 return null; | 193 return null; |
| 173 } | 194 } |
| 174 String name = element.displayName; | 195 String name = element.displayName; |
| 175 int offset = element.nameOffset; | 196 int offset = element.nameOffset; |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 if (lineInfo != null) { | 437 if (lineInfo != null) { |
| 417 engine.LineInfo_Location offsetLocation = | 438 engine.LineInfo_Location offsetLocation = |
| 418 lineInfo.getLocation(range.offset); | 439 lineInfo.getLocation(range.offset); |
| 419 startLine = offsetLocation.lineNumber; | 440 startLine = offsetLocation.lineNumber; |
| 420 startColumn = offsetLocation.columnNumber; | 441 startColumn = offsetLocation.columnNumber; |
| 421 } | 442 } |
| 422 } | 443 } |
| 423 return new Location( | 444 return new Location( |
| 424 source.fullName, range.offset, range.length, startLine, startColumn); | 445 source.fullName, range.offset, range.length, startLine, startColumn); |
| 425 } | 446 } |
| OLD | NEW |