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

Side by Side Diff: pkg/analysis_server/lib/src/computer/element.dart

Issue 392693002: Initial implementation for 'search.findElementReferences'. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add comments Created 6 years, 5 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 | Annotate | Revision Log
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 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:analyzer/src/generated/element.dart' as engine; 8 import 'package:analyzer/src/generated/element.dart' as engine;
9 import 'package:analyzer/src/generated/source.dart'; 9 import 'package:analyzer/src/generated/source.dart';
10 import 'package:analyzer/src/generated/utilities_dart.dart' as engine; 10 import 'package:analyzer/src/generated/utilities_dart.dart' as engine;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 final bool isDeprecated; 60 final bool isDeprecated;
61 61
62 Element(this.kind, this.name, this.location, this.isPrivate, 62 Element(this.kind, this.name, this.location, this.isPrivate,
63 this.isDeprecated, {this.parameters, this.returnType, this.isAbstract: fal se, 63 this.isDeprecated, {this.parameters, this.returnType, this.isAbstract: fal se,
64 this.isConst: false, this.isFinal: false, this.isStatic: false}); 64 this.isConst: false, this.isFinal: false, this.isStatic: false});
65 65
66 factory Element.fromEngine(engine.Element element) { 66 factory Element.fromEngine(engine.Element element) {
67 String name = element.displayName; 67 String name = element.displayName;
68 String elementParameters = _getParametersString(element); 68 String elementParameters = _getParametersString(element);
69 String elementReturnType = _getReturnTypeString(element); 69 String elementReturnType = _getReturnTypeString(element);
70 return new Element(ElementKind.valueOfEngine(element.kind), name, 70 return new Element(
71 new Location.fromElement(element), element.isPrivate, element.isDeprecat ed, 71 ElementKind.valueOfEngine(element.kind),
72 parameters: elementParameters, returnType: elementReturnType, isAbstract : 72 name,
73 _isAbstract(element), isConst: _isConst(element), isFinal: _isFinal(elem ent), 73 new Location.fromElement(element),
74 element.isPrivate,
75 element.isDeprecated,
76 parameters: elementParameters,
77 returnType: elementReturnType,
78 isAbstract: _isAbstract(element),
79 isConst: _isConst(element),
80 isFinal: _isFinal(element),
74 isStatic: _isStatic(element)); 81 isStatic: _isStatic(element));
75 } 82 }
76 83
77 factory Element.fromJson(Map<String, Object> map) { 84 factory Element.fromJson(Map<String, Object> map) {
78 ElementKind kind = ElementKind.valueOf(map[KIND]); 85 ElementKind kind = ElementKind.valueOf(map[KIND]);
79 int flags = map[FLAGS]; 86 int flags = map[FLAGS];
80 return new Element(kind, map[NAME], new Location.fromJson(map[LOCATION]), 87 return new Element(
81 _hasFlag(flags, FLAG_PRIVATE), _hasFlag(flags, FLAG_DEPRECATED), paramet ers: 88 kind,
82 map[PARAMETERS], returnType: map[RETURN_TYPE], isAbstract: _hasFlag(flag s, 89 map[NAME],
83 FLAG_ABSTRACT), isConst: _hasFlag(flags, FLAG_CONST), isFinal: _hasFlag( flags, 90 new Location.fromJson(map[LOCATION]),
84 FLAG_FINAL), isStatic: _hasFlag(flags, FLAG_STATIC)); 91 _hasFlag(flags, FLAG_PRIVATE),
92 _hasFlag(flags, FLAG_DEPRECATED),
93 parameters: map[PARAMETERS],
94 returnType: map[RETURN_TYPE],
95 isAbstract: _hasFlag(flags, FLAG_ABSTRACT),
96 isConst: _hasFlag(flags, FLAG_CONST),
97 isFinal: _hasFlag(flags, FLAG_FINAL),
98 isStatic: _hasFlag(flags, FLAG_STATIC));
85 } 99 }
86 100
87 int get flags { 101 int get flags {
88 int flags = 0; 102 int flags = 0;
89 if (isAbstract) flags |= FLAG_ABSTRACT; 103 if (isAbstract) flags |= FLAG_ABSTRACT;
90 if (isConst) flags |= FLAG_CONST; 104 if (isConst) flags |= FLAG_CONST;
91 if (isFinal) flags |= FLAG_FINAL; 105 if (isFinal) flags |= FLAG_FINAL;
92 if (isStatic) flags |= FLAG_STATIC; 106 if (isStatic) flags |= FLAG_STATIC;
93 if (isPrivate) flags |= FLAG_PRIVATE; 107 if (isPrivate) flags |= FLAG_PRIVATE;
94 if (isDeprecated) flags |= FLAG_DEPRECATED; 108 if (isDeprecated) flags |= FLAG_DEPRECATED;
(...skipping 12 matching lines...) Expand all
107 } 121 }
108 if (returnType != null) { 122 if (returnType != null) {
109 json[RETURN_TYPE] = returnType; 123 json[RETURN_TYPE] = returnType;
110 } 124 }
111 return json; 125 return json;
112 } 126 }
113 127
114 @override 128 @override
115 String toString() => toJson().toString(); 129 String toString() => toJson().toString();
116 130
131 static Map<String, Object> asJson(Element element) {
132 return element.toJson();
133 }
134
117 static String _getParametersString(engine.Element element) { 135 static String _getParametersString(engine.Element element) {
118 // TODO(scheglov) expose the corresponding feature from ExecutableElement 136 // TODO(scheglov) expose the corresponding feature from ExecutableElement
119 if (element is engine.ExecutableElement) { 137 if (element is engine.ExecutableElement) {
120 var sb = new StringBuffer(); 138 var sb = new StringBuffer();
121 String closeOptionalString = ''; 139 String closeOptionalString = '';
122 for (var parameter in element.parameters) { 140 for (var parameter in element.parameters) {
123 if (sb.isNotEmpty) { 141 if (sb.isNotEmpty) {
124 sb.write(', '); 142 sb.write(', ');
125 } 143 }
126 if (closeOptionalString.isEmpty) { 144 if (closeOptionalString.isEmpty) {
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 LineInfo_Location lineLocation = lineInfo.getLocation(offset); 329 LineInfo_Location lineLocation = lineInfo.getLocation(offset);
312 int startLine = lineLocation.lineNumber; 330 int startLine = lineLocation.lineNumber;
313 int startColumn = lineLocation.columnNumber; 331 int startColumn = lineLocation.columnNumber;
314 if (element is engine.CompilationUnitElement) { 332 if (element is engine.CompilationUnitElement) {
315 offset = 0; 333 offset = 0;
316 length = 0; 334 length = 0;
317 startLine = 1; 335 startLine = 1;
318 startColumn = 1; 336 startColumn = 1;
319 } 337 }
320 // done 338 // done
321 return new Location(source.fullName, offset, length, startLine, 339 return new Location(
340 source.fullName,
341 offset,
342 length,
343 startLine,
344 startColumn);
345 }
346
347 factory Location.fromOffset(engine.Element element, int offset, int length) {
348 Source source = element.source;
349 LineInfo lineInfo = element.context.getLineInfo(source);
350 // prepare location
351 LineInfo_Location lineLocation = lineInfo.getLocation(offset);
352 int startLine = lineLocation.lineNumber;
353 int startColumn = lineLocation.columnNumber;
354 // done
355 return new Location(
356 source.fullName,
357 offset,
358 length,
359 startLine,
322 startColumn); 360 startColumn);
323 } 361 }
324 362
325 factory Location.fromJson(Map<String, Object> map) { 363 factory Location.fromJson(Map<String, Object> map) {
326 return new Location(map[FILE], map[OFFSET], map[LENGTH], map[START_LINE], 364 return new Location(
365 map[FILE],
366 map[OFFSET],
367 map[LENGTH],
368 map[START_LINE],
327 map[START_COLUMN]); 369 map[START_COLUMN]);
328 } 370 }
329 371
330 Map<String, Object> toJson() { 372 Map<String, Object> toJson() {
331 return { 373 return {
332 FILE: file, 374 FILE: file,
333 OFFSET: offset, 375 OFFSET: offset,
334 LENGTH: length, 376 LENGTH: length,
335 START_LINE: startLine, 377 START_LINE: startLine,
336 START_COLUMN: startColumn 378 START_COLUMN: startColumn
337 }; 379 };
338 } 380 }
339 381
340 @override 382 @override
341 String toString() { 383 String toString() {
342 return 'Location(file=$file; offset=$offset; length=$length; ' 384 return 'Location(file=$file; offset=$offset; length=$length; '
343 'startLine=$startLine; startColumn=$startColumn)'; 385 'startLine=$startLine; startColumn=$startColumn)';
344 } 386 }
345 } 387 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/analysis_server.dart ('k') | pkg/analysis_server/lib/src/constants.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698