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

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

Issue 389413002: Use HasToJson when set Reponse/Notification parameters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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.highlights; 5 library computer.highlights;
6 6
7 import 'package:analysis_server/src/collections.dart';
7 import 'package:analysis_server/src/constants.dart'; 8 import 'package:analysis_server/src/constants.dart';
8 import 'package:analyzer/src/generated/ast.dart'; 9 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
10 import 'package:analyzer/src/generated/scanner.dart'; 11 import 'package:analyzer/src/generated/scanner.dart';
11 12
12 13
13 /** 14 /**
14 * A computer for [HighlightRegion]s in a Dart [CompilationUnit]. 15 * A computer for [HighlightRegion]s in a Dart [CompilationUnit].
15 */ 16 */
16 class DartUnitHighlightsComputer { 17 class DartUnitHighlightsComputer {
17 final CompilationUnit _unit; 18 final CompilationUnit _unit;
18 19
19 final List<HighlightRegion> _regions = <HighlightRegion>[]; 20 final List<HighlightRegion> _regions = <HighlightRegion>[];
20 21
21 DartUnitHighlightsComputer(this._unit); 22 DartUnitHighlightsComputer(this._unit);
22 23
23 /** 24 /**
24 * Returns the computed highlight regions, not `null`. 25 * Returns the computed highlight regions, not `null`.
25 */ 26 */
26 List<Map<String, Object>> compute() { 27 List<HighlightRegion> compute() {
27 _unit.accept(new _DartUnitHighlightsComputerVisitor(this)); 28 _unit.accept(new _DartUnitHighlightsComputerVisitor(this));
28 _addCommentRanges(); 29 _addCommentRanges();
29 return _regions.map((region) => region.toJson()).toList(); 30 return _regions;
30 } 31 }
31 32
32 void _addCommentRanges() { 33 void _addCommentRanges() {
33 Token token = _unit.beginToken; 34 Token token = _unit.beginToken;
34 while (token != null && token.type != TokenType.EOF) { 35 while (token != null && token.type != TokenType.EOF) {
35 Token commentToken = token.precedingComments; 36 Token commentToken = token.precedingComments;
36 while (commentToken != null) { 37 while (commentToken != null) {
37 HighlightType highlightType = null; 38 HighlightType highlightType = null;
38 if (commentToken.type == TokenType.MULTI_LINE_COMMENT) { 39 if (commentToken.type == TokenType.MULTI_LINE_COMMENT) {
39 if (commentToken.lexeme.startsWith('/**')) { 40 if (commentToken.lexeme.startsWith('/**')) {
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 } 318 }
318 319
319 void _addRegion_tokenStart_tokenEnd(Token a, Token b, HighlightType type) { 320 void _addRegion_tokenStart_tokenEnd(Token a, Token b, HighlightType type) {
320 int offset = a.offset; 321 int offset = a.offset;
321 int end = b.end; 322 int end = b.end;
322 _addRegion(offset, end - offset, type); 323 _addRegion(offset, end - offset, type);
323 } 324 }
324 } 325 }
325 326
326 327
327 class HighlightRegion { 328 class HighlightRegion implements HasToJson {
328 final int offset; 329 final int offset;
329 final int length; 330 final int length;
330 final HighlightType type; 331 final HighlightType type;
331 332
332 HighlightRegion(this.offset, this.length, this.type); 333 HighlightRegion(this.offset, this.length, this.type);
333 334
334 factory HighlightRegion.fromJson(Map<String, Object> map) { 335 factory HighlightRegion.fromJson(Map<String, Object> map) {
335 HighlightType type = HighlightType.valueOf(map[TYPE]); 336 HighlightType type = HighlightType.valueOf(map[TYPE]);
336 return new HighlightRegion(map[OFFSET], map[LENGTH], type); 337 return new HighlightRegion(map[OFFSET], map[LENGTH], type);
337 } 338 }
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 DartType type = node.type; 626 DartType type = node.type;
626 if (type != null) { 627 if (type != null) {
627 if (type.isDynamic && node.name.name == "dynamic") { 628 if (type.isDynamic && node.name.name == "dynamic") {
628 computer._addRegion_node(node, HighlightType.TYPE_NAME_DYNAMIC); 629 computer._addRegion_node(node, HighlightType.TYPE_NAME_DYNAMIC);
629 return null; 630 return null;
630 } 631 }
631 } 632 }
632 return super.visitTypeName(node); 633 return super.visitTypeName(node);
633 } 634 }
634 } 635 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/collections.dart ('k') | pkg/analysis_server/lib/src/computer/computer_hover.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698