Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Side by Side Diff: pkg/analysis_server/lib/src/protocol_server.dart

Issue 1260593005: update suggestion element return type to have type param (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/completion/prefixed_element_contributor.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 29 matching lines...) Expand all
40 /** 40 /**
41 * Adds [edit] to the [FileEdit] for the given [source]. 41 * Adds [edit] to the [FileEdit] for the given [source].
42 */ 42 */
43 void doSourceChange_addSourceEdit(SourceChange change, 43 void doSourceChange_addSourceEdit(SourceChange change,
44 engine.AnalysisContext context, engine.Source source, SourceEdit edit) { 44 engine.AnalysisContext context, engine.Source source, SourceEdit edit) {
45 String file = source.fullName; 45 String file = source.fullName;
46 int fileStamp = context.getModificationStamp(source); 46 int fileStamp = context.getModificationStamp(source);
47 change.addEdit(file, fileStamp, edit); 47 change.addEdit(file, fileStamp, edit);
48 } 48 }
49 49
50 String getReturnTypeString(engine.Element element) {
51 if (element is engine.ExecutableElement) {
52 if (element.kind == engine.ElementKind.SETTER) {
53 return null;
54 } else {
55 return element.returnType.toString();
Brian Wilkerson 2015/08/04 04:40:13 Shouldn't this (and line 61) be 'displayName' rath
danrubel 2015/08/05 05:08:24 displayName does not include the type parameters,
Brian Wilkerson 2015/08/05 13:19:18 If not, then we need to add one. toString() is str
56 }
57 } else if (element is engine.VariableElement) {
58 engine.DartType type = element.type;
59 return type != null ? type.displayName : 'dynamic';
60 } else if (element is engine.FunctionTypeAliasElement) {
61 return element.returnType.toString();
62 } else {
63 return null;
64 }
65 }
66
50 /** 67 /**
51 * Construct based on error information from the analyzer engine. 68 * Construct based on error information from the analyzer engine.
52 */ 69 */
53 AnalysisError newAnalysisError_fromEngine( 70 AnalysisError newAnalysisError_fromEngine(
54 engine.LineInfo lineInfo, engine.AnalysisError error) { 71 engine.LineInfo lineInfo, engine.AnalysisError error) {
55 engine.ErrorCode errorCode = error.errorCode; 72 engine.ErrorCode errorCode = error.errorCode;
56 // prepare location 73 // prepare location
57 Location location; 74 Location location;
58 { 75 {
59 String file = error.source.fullName; 76 String file = error.source.fullName;
(...skipping 19 matching lines...) Expand all
79 correction: correction); 96 correction: correction);
80 } 97 }
81 98
82 /** 99 /**
83 * Construct based on a value from the analyzer engine. 100 * Construct based on a value from the analyzer engine.
84 */ 101 */
85 Element newElement_fromEngine(engine.Element element) { 102 Element newElement_fromEngine(engine.Element element) {
86 String name = element.displayName; 103 String name = element.displayName;
87 String elementTypeParameters = _getTypeParametersString(element); 104 String elementTypeParameters = _getTypeParametersString(element);
88 String elementParameters = _getParametersString(element); 105 String elementParameters = _getParametersString(element);
89 String elementReturnType = _getReturnTypeString(element); 106 String elementReturnType = getReturnTypeString(element);
90 ElementKind kind = newElementKind_fromEngineElement(element); 107 ElementKind kind = newElementKind_fromEngineElement(element);
91 return new Element(kind, name, Element.makeFlags( 108 return new Element(kind, name, Element.makeFlags(
92 isPrivate: element.isPrivate, 109 isPrivate: element.isPrivate,
93 isDeprecated: element.isDeprecated, 110 isDeprecated: element.isDeprecated,
94 isAbstract: _isAbstract(element), 111 isAbstract: _isAbstract(element),
95 isConst: _isConst(element), 112 isConst: _isConst(element),
96 isFinal: _isFinal(element), 113 isFinal: _isFinal(element),
97 isStatic: _isStatic(element)), 114 isStatic: _isStatic(element)),
98 location: newLocation_fromElement(element), 115 location: newLocation_fromElement(element),
99 typeParameters: elementTypeParameters, 116 typeParameters: elementTypeParameters,
100 parameters: elementParameters, 117 parameters: elementParameters,
101 returnType: elementReturnType); 118 returnType: elementReturnType);
102 } 119 }
103 120
104 /** 121 /**
105 * Construct based on a value from the analyzer engine. 122 * Construct based on a value from the analyzer engine.
106 * This does not take into account that 123 * This does not take into account that
107 * instances of ClassElement can be an enum and 124 * instances of ClassElement can be an enum and
108 * instances of FieldElement can be an enum constant. 125 * instances of FieldElement can be an enum constant.
109 * Use [newElementKind_fromEngineElement] where possible. 126 * Use [newElementKind_fromEngineElement] where possible.
110 */ 127 */
111 ElementKind newElementKind_fromEngine(engine.ElementKind kind) { 128 ElementKind newElementKind_fromEngine(engine.ElementKind kind) {
112 if (kind == engine.ElementKind.CLASS) { 129 if (kind == engine.ElementKind.CLASS) {
113 return ElementKind.CLASS; 130 return ElementKind.CLASS;
114 } 131 }
115 if (kind == engine.ElementKind.COMPILATION_UNIT) { 132 if (kind == engine.ElementKind.COMPILATION_UNIT) {
116 return ElementKind.COMPILATION_UNIT; 133 return ElementKind.COMPILATION_UNIT;
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 sb.write('['); 361 sb.write('[');
345 closeOptionalString = ']'; 362 closeOptionalString = ']';
346 } 363 }
347 } 364 }
348 sb.write(parameter.toString()); 365 sb.write(parameter.toString());
349 } 366 }
350 sb.write(closeOptionalString); 367 sb.write(closeOptionalString);
351 return '(' + sb.toString() + ')'; 368 return '(' + sb.toString() + ')';
352 } 369 }
353 370
354 String _getReturnTypeString(engine.Element element) {
355 if (element is engine.ExecutableElement) {
356 if (element.kind == engine.ElementKind.SETTER) {
357 return null;
358 } else {
359 return element.returnType.toString();
360 }
361 } else if (element is engine.VariableElement) {
362 engine.DartType type = element.type;
363 return type != null ? type.displayName : 'dynamic';
364 } else if (element is engine.FunctionTypeAliasElement) {
365 return element.returnType.toString();
366 } else {
367 return null;
368 }
369 }
370
371 String _getTypeParametersString(engine.Element element) { 371 String _getTypeParametersString(engine.Element element) {
372 List<engine.TypeParameterElement> typeParameters; 372 List<engine.TypeParameterElement> typeParameters;
373 if (element is engine.ClassElement) { 373 if (element is engine.ClassElement) {
374 typeParameters = element.typeParameters; 374 typeParameters = element.typeParameters;
375 } else if (element is engine.FunctionTypeAliasElement) { 375 } else if (element is engine.FunctionTypeAliasElement) {
376 typeParameters = element.typeParameters; 376 typeParameters = element.typeParameters;
377 } 377 }
378 if (typeParameters == null || typeParameters.isEmpty) { 378 if (typeParameters == null || typeParameters.isEmpty) {
379 return null; 379 return null;
380 } 380 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 if (lineInfo != null) { 437 if (lineInfo != null) {
438 engine.LineInfo_Location offsetLocation = 438 engine.LineInfo_Location offsetLocation =
439 lineInfo.getLocation(range.offset); 439 lineInfo.getLocation(range.offset);
440 startLine = offsetLocation.lineNumber; 440 startLine = offsetLocation.lineNumber;
441 startColumn = offsetLocation.columnNumber; 441 startColumn = offsetLocation.columnNumber;
442 } 442 }
443 } 443 }
444 return new Location( 444 return new Location(
445 source.fullName, range.offset, range.length, startLine, startColumn); 445 source.fullName, range.offset, range.length, startLine, startColumn);
446 } 446 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/completion/prefixed_element_contributor.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698