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

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

Issue 1232683003: Issue 23640. Implement 'analysis.getNavigation' request. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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
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; 5 library protocol;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 part 'generated_protocol.dart'; 10 part 'generated_protocol.dart';
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 /** 506 /**
507 * Initialize a newly created [Request] to have the given [id] and [method] 507 * Initialize a newly created [Request] to have the given [id] and [method]
508 * name. If [params] is supplied, it is used as the "params" map for the 508 * name. If [params] is supplied, it is used as the "params" map for the
509 * request. Otherwise an empty "params" map is allocated. 509 * request. Otherwise an empty "params" map is allocated.
510 */ 510 */
511 Request(this.id, this.method, 511 Request(this.id, this.method,
512 [Map<String, Object> params, this.clientRequestTime]) 512 [Map<String, Object> params, this.clientRequestTime])
513 : _params = params != null ? params : new HashMap<String, Object>(); 513 : _params = params != null ? params : new HashMap<String, Object>();
514 514
515 /** 515 /**
516 * Return a request parsed from the given [data], or `null` if the [data] is 516 * Return a request parsed from the given json, or `null` if the [data] is
517 * not a valid json representation of a request. The [data] is expected to 517 * not a valid json representation of a request. The [data] is expected to
518 * have the following format: 518 * have the following format:
519 * 519 *
520 * { 520 * {
521 * 'clientRequestTime': millisecondsSinceEpoch 521 * 'clientRequestTime': millisecondsSinceEpoch
522 * 'id': String, 522 * 'id': String,
523 * 'method': methodName, 523 * 'method': methodName,
524 * 'params': { 524 * 'params': {
525 * paramter_name: value 525 * paramter_name: value
526 * } 526 * }
527 * } 527 * }
528 * 528 *
529 * where both the parameters and clientRequestTime are optional. 529 * where both the parameters and clientRequestTime are optional.
530 * The parameters can contain any number of name/value pairs. 530 * The parameters can contain any number of name/value pairs.
531 * The clientRequestTime must be an int representing the time at which 531 * The clientRequestTime must be an int representing the time at which
532 * the client issued the request (milliseconds since epoch). 532 * the client issued the request (milliseconds since epoch).
533 */ 533 */
534 factory Request.fromString(String data) { 534 factory Request.fromJson(Map<String, dynamic> result) {
535 try { 535 var id = result[Request.ID];
536 var result = JSON.decode(data); 536 var method = result[Request.METHOD];
537 if (result is Map) { 537 if (id is! String || method is! String) {
538 return new Request.fromJson(result);
539 }
540 return null; 538 return null;
541 } catch (exception) { 539 }
540 var time = result[Request.CLIENT_REQUEST_TIME];
541 if (time != null && time is! int) {
542 return null;
543 }
544 var params = result[Request.PARAMS];
545 if (params is Map || params == null) {
546 return new Request(id, method, params, time);
547 } else {
542 return null; 548 return null;
543 } 549 }
544 } 550 }
545 551
546 /** 552 /**
547 * Return a request parsed from the given json, or `null` if the [data] is 553 * Return a request parsed from the given [data], or `null` if the [data] is
548 * not a valid json representation of a request. The [data] is expected to 554 * not a valid json representation of a request. The [data] is expected to
549 * have the following format: 555 * have the following format:
550 * 556 *
551 * { 557 * {
552 * 'clientRequestTime': millisecondsSinceEpoch 558 * 'clientRequestTime': millisecondsSinceEpoch
553 * 'id': String, 559 * 'id': String,
554 * 'method': methodName, 560 * 'method': methodName,
555 * 'params': { 561 * 'params': {
556 * paramter_name: value 562 * paramter_name: value
557 * } 563 * }
558 * } 564 * }
559 * 565 *
560 * where both the parameters and clientRequestTime are optional. 566 * where both the parameters and clientRequestTime are optional.
561 * The parameters can contain any number of name/value pairs. 567 * The parameters can contain any number of name/value pairs.
562 * The clientRequestTime must be an int representing the time at which 568 * The clientRequestTime must be an int representing the time at which
563 * the client issued the request (milliseconds since epoch). 569 * the client issued the request (milliseconds since epoch).
564 */ 570 */
565 factory Request.fromJson(Map<String, dynamic> result) { 571 factory Request.fromString(String data) {
566 var id = result[Request.ID]; 572 try {
567 var method = result[Request.METHOD]; 573 var result = JSON.decode(data);
568 if (id is! String || method is! String) { 574 if (result is Map) {
575 return new Request.fromJson(result);
576 }
569 return null; 577 return null;
570 } 578 } catch (exception) {
571 var time = result[Request.CLIENT_REQUEST_TIME];
572 if (time != null && time is! int) {
573 return null;
574 }
575 var params = result[Request.PARAMS];
576 if (params is Map || params == null) {
577 return new Request(id, method, params, time);
578 } else {
579 return null; 579 return null;
580 } 580 }
581 } 581 }
582 582
583 /** 583 /**
584 * Return a table representing the structure of the Json object that will be 584 * Return a table representing the structure of the Json object that will be
585 * sent to the client to represent this response. 585 * sent to the client to represent this response.
586 */ 586 */
587 Map<String, Object> toJson() { 587 Map<String, Object> toJson() {
588 Map<String, Object> jsonObject = new HashMap<String, Object>(); 588 Map<String, Object> jsonObject = new HashMap<String, Object>();
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 756
757 /** 757 /**
758 * Initialize a newly created instance to represent the 758 * Initialize a newly created instance to represent the
759 * GET_ERRORS_INVALID_FILE error condition. 759 * GET_ERRORS_INVALID_FILE error condition.
760 */ 760 */
761 Response.getErrorsInvalidFile(Request request) : this(request.id, 761 Response.getErrorsInvalidFile(Request request) : this(request.id,
762 error: new RequestError(RequestErrorCode.GET_ERRORS_INVALID_FILE, 762 error: new RequestError(RequestErrorCode.GET_ERRORS_INVALID_FILE,
763 'Error during `analysis.getErrors`: invalid file.')); 763 'Error during `analysis.getErrors`: invalid file.'));
764 764
765 /** 765 /**
766 * Initialize a newly created instance to represent the
767 * GET_NAVIGATION_INVALID_FILE error condition.
768 */
769 Response.getNavigationInvalidFile(Request request) : this(request.id,
770 error: new RequestError(RequestErrorCode.GET_NAVIGATION_INVALID_FILE,
771 'Error during `analysis.getNavigation`: invalid file.'));
772
773 /**
766 * Initialize a newly created instance to represent an error condition caused 774 * Initialize a newly created instance to represent an error condition caused
767 * by an analysis.reanalyze [request] that specifies an analysis root that is 775 * by an analysis.reanalyze [request] that specifies an analysis root that is
768 * not in the current list of analysis roots. 776 * not in the current list of analysis roots.
769 */ 777 */
770 Response.invalidAnalysisRoot(Request request, String rootPath) : this( 778 Response.invalidAnalysisRoot(Request request, String rootPath) : this(
771 request.id, 779 request.id,
772 error: new RequestError(RequestErrorCode.INVALID_ANALYSIS_ROOT, 780 error: new RequestError(RequestErrorCode.INVALID_ANALYSIS_ROOT,
773 "Invalid analysis root: $rootPath")); 781 "Invalid analysis root: $rootPath"));
774 782
775 /** 783 /**
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); 942 hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
935 hash = hash ^ (hash >> 11); 943 hash = hash ^ (hash >> 11);
936 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); 944 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
937 } 945 }
938 946
939 static int hash2(a, b) => finish(combine(combine(0, a), b)); 947 static int hash2(a, b) => finish(combine(combine(0, a), b));
940 948
941 static int hash4(a, b, c, d) => 949 static int hash4(a, b, c, d) =>
942 finish(combine(combine(combine(combine(0, a), b), c), d)); 950 finish(combine(combine(combine(combine(0, a), b), c), d));
943 } 951 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698