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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 98 |
99 /** | 99 /** |
100 * Construct based on a value from the analyzer engine. | 100 * Construct based on a value from the analyzer engine. |
101 */ | 101 */ |
102 Element newElement_fromEngine(engine.Element element) { | 102 Element newElement_fromEngine(engine.Element element) { |
103 String name = element.displayName; | 103 String name = element.displayName; |
104 String elementTypeParameters = _getTypeParametersString(element); | 104 String elementTypeParameters = _getTypeParametersString(element); |
105 String elementParameters = _getParametersString(element); | 105 String elementParameters = _getParametersString(element); |
106 String elementReturnType = getReturnTypeString(element); | 106 String elementReturnType = getReturnTypeString(element); |
107 ElementKind kind = newElementKind_fromEngineElement(element); | 107 ElementKind kind = newElementKind_fromEngineElement(element); |
108 return new Element(kind, name, Element.makeFlags( | 108 return new Element( |
| 109 kind, |
| 110 name, |
| 111 Element.makeFlags( |
109 isPrivate: element.isPrivate, | 112 isPrivate: element.isPrivate, |
110 isDeprecated: element.isDeprecated, | 113 isDeprecated: element.isDeprecated, |
111 isAbstract: _isAbstract(element), | 114 isAbstract: _isAbstract(element), |
112 isConst: _isConst(element), | 115 isConst: _isConst(element), |
113 isFinal: _isFinal(element), | 116 isFinal: _isFinal(element), |
114 isStatic: _isStatic(element)), | 117 isStatic: _isStatic(element)), |
115 location: newLocation_fromElement(element), | 118 location: newLocation_fromElement(element), |
116 typeParameters: elementTypeParameters, | 119 typeParameters: elementTypeParameters, |
117 parameters: elementParameters, | 120 parameters: elementParameters, |
118 returnType: elementReturnType); | 121 returnType: elementReturnType); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 return ElementKind.UNKNOWN; | 180 return ElementKind.UNKNOWN; |
178 } | 181 } |
179 | 182 |
180 /** | 183 /** |
181 * Construct based on a value from the analyzer engine. | 184 * Construct based on a value from the analyzer engine. |
182 */ | 185 */ |
183 ElementKind newElementKind_fromEngineElement(engine.Element element) { | 186 ElementKind newElementKind_fromEngineElement(engine.Element element) { |
184 if (element is engine.ClassElement && element.isEnum) { | 187 if (element is engine.ClassElement && element.isEnum) { |
185 return ElementKind.ENUM; | 188 return ElementKind.ENUM; |
186 } | 189 } |
187 if (element is engine.FieldElement && element.isEnumConstant && | 190 if (element is engine.FieldElement && |
| 191 element.isEnumConstant && |
188 // MyEnum.values and MyEnum.one.index return isEnumConstant = true | 192 // MyEnum.values and MyEnum.one.index return isEnumConstant = true |
189 // so these additional checks are necessary. | 193 // so these additional checks are necessary. |
190 // TODO(danrubel) MyEnum.values is constant, but is a list | 194 // TODO(danrubel) MyEnum.values is constant, but is a list |
191 // so should it return isEnumConstant = true? | 195 // so should it return isEnumConstant = true? |
192 // MyEnum.one.index is final but *not* constant | 196 // MyEnum.one.index is final but *not* constant |
193 // so should it return isEnumConstant = true? | 197 // so should it return isEnumConstant = true? |
194 // Or should we return ElementKind.ENUM_CONSTANT here | 198 // Or should we return ElementKind.ENUM_CONSTANT here |
195 // in either or both of these cases? | 199 // in either or both of these cases? |
196 element.type != null && | 200 element.type != null && |
197 element.type.element == element.enclosingElement) { | 201 element.type.element == element.enclosingElement) { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 } else { | 350 } else { |
347 return null; | 351 return null; |
348 } | 352 } |
349 StringBuffer sb = new StringBuffer(); | 353 StringBuffer sb = new StringBuffer(); |
350 String closeOptionalString = ''; | 354 String closeOptionalString = ''; |
351 for (engine.ParameterElement parameter in parameters) { | 355 for (engine.ParameterElement parameter in parameters) { |
352 if (sb.isNotEmpty) { | 356 if (sb.isNotEmpty) { |
353 sb.write(', '); | 357 sb.write(', '); |
354 } | 358 } |
355 if (closeOptionalString.isEmpty) { | 359 if (closeOptionalString.isEmpty) { |
356 if (parameter.kind == engine.ParameterKind.NAMED) { | 360 engine.ParameterKind kind = parameter.parameterKind; |
| 361 if (kind == engine.ParameterKind.NAMED) { |
357 sb.write('{'); | 362 sb.write('{'); |
358 closeOptionalString = '}'; | 363 closeOptionalString = '}'; |
359 } | 364 } |
360 if (parameter.kind == engine.ParameterKind.POSITIONAL) { | 365 if (kind == engine.ParameterKind.POSITIONAL) { |
361 sb.write('['); | 366 sb.write('['); |
362 closeOptionalString = ']'; | 367 closeOptionalString = ']'; |
363 } | 368 } |
364 } | 369 } |
365 sb.write(parameter.toString()); | 370 parameter.appendToWithoutDelimiters(sb); |
366 } | 371 } |
367 sb.write(closeOptionalString); | 372 sb.write(closeOptionalString); |
368 return '(' + sb.toString() + ')'; | 373 return '(' + sb.toString() + ')'; |
369 } | 374 } |
370 | 375 |
371 String _getTypeParametersString(engine.Element element) { | 376 String _getTypeParametersString(engine.Element element) { |
372 List<engine.TypeParameterElement> typeParameters; | 377 List<engine.TypeParameterElement> typeParameters; |
373 if (element is engine.ClassElement) { | 378 if (element is engine.ClassElement) { |
374 typeParameters = element.typeParameters; | 379 typeParameters = element.typeParameters; |
375 } else if (element is engine.FunctionTypeAliasElement) { | 380 } else if (element is engine.FunctionTypeAliasElement) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 if (lineInfo != null) { | 442 if (lineInfo != null) { |
438 engine.LineInfo_Location offsetLocation = | 443 engine.LineInfo_Location offsetLocation = |
439 lineInfo.getLocation(range.offset); | 444 lineInfo.getLocation(range.offset); |
440 startLine = offsetLocation.lineNumber; | 445 startLine = offsetLocation.lineNumber; |
441 startColumn = offsetLocation.columnNumber; | 446 startColumn = offsetLocation.columnNumber; |
442 } | 447 } |
443 } | 448 } |
444 return new Location( | 449 return new Location( |
445 source.fullName, range.offset, range.length, startLine, startColumn); | 450 source.fullName, range.offset, range.length, startLine, startColumn); |
446 } | 451 } |
OLD | NEW |