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

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

Issue 679103003: Support for enums semantic highlighting. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: small clean up for tests Created 6 years, 1 month 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/protocol.dart' hide Element; 7 import 'package:analysis_server/src/protocol.dart' hide Element;
8 import 'package:analyzer/src/generated/ast.dart'; 8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/element.dart'; 9 import 'package:analyzer/src/generated/element.dart';
10 import 'package:analyzer/src/generated/scanner.dart'; 10 import 'package:analyzer/src/generated/scanner.dart';
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 HighlightRegionType.ANNOTATION); 111 HighlightRegionType.ANNOTATION);
112 _addRegion_token(arguments.endToken, HighlightRegionType.ANNOTATION); 112 _addRegion_token(arguments.endToken, HighlightRegionType.ANNOTATION);
113 } 113 }
114 } 114 }
115 115
116 bool _addIdentifierRegion_class(SimpleIdentifier node) { 116 bool _addIdentifierRegion_class(SimpleIdentifier node) {
117 Element element = node.staticElement; 117 Element element = node.staticElement;
118 if (element is! ClassElement) { 118 if (element is! ClassElement) {
119 return false; 119 return false;
120 } 120 }
121 return _addRegion_node(node, HighlightRegionType.CLASS); 121 ClassElement classElement = element;
122 // prepare type
123 HighlightRegionType type;
124 if (classElement.isEnum) {
125 type = HighlightRegionType.ENUM;
126 } else {
127 type = HighlightRegionType.CLASS;
128 }
129 // add region
130 return _addRegion_node(node, type);
122 } 131 }
123 132
124 bool _addIdentifierRegion_constructor(SimpleIdentifier node) { 133 bool _addIdentifierRegion_constructor(SimpleIdentifier node) {
125 Element element = node.staticElement; 134 Element element = node.staticElement;
126 if (element is! ConstructorElement) { 135 if (element is! ConstructorElement) {
127 return false; 136 return false;
128 } 137 }
129 return _addRegion_node(node, HighlightRegionType.CONSTRUCTOR); 138 return _addRegion_node(node, HighlightRegionType.CONSTRUCTOR);
130 } 139 }
131 140
(...skipping 17 matching lines...) Expand all
149 } 158 }
150 159
151 bool _addIdentifierRegion_field(SimpleIdentifier node) { 160 bool _addIdentifierRegion_field(SimpleIdentifier node) {
152 Element element = node.bestElement; 161 Element element = node.bestElement;
153 if (element is FieldFormalParameterElement) { 162 if (element is FieldFormalParameterElement) {
154 element = (element as FieldFormalParameterElement).field; 163 element = (element as FieldFormalParameterElement).field;
155 } 164 }
156 if (element is PropertyAccessorElement) { 165 if (element is PropertyAccessorElement) {
157 element = (element as PropertyAccessorElement).variable; 166 element = (element as PropertyAccessorElement).variable;
158 } 167 }
168 // prepare type
169 HighlightRegionType type;
159 if (element is FieldElement) { 170 if (element is FieldElement) {
160 if ((element as FieldElement).isStatic) { 171 Element enclosingElement = element.enclosingElement;
161 return _addRegion_node(node, HighlightRegionType.FIELD_STATIC); 172 if (enclosingElement is ClassElement && enclosingElement.isEnum) {
173 type = HighlightRegionType.ENUM_CONSTANT;
174 } else if ((element as FieldElement).isStatic) {
175 type = HighlightRegionType.FIELD_STATIC;
162 } else { 176 } else {
163 return _addRegion_node(node, HighlightRegionType.FIELD); 177 type = HighlightRegionType.FIELD;
164 } 178 }
179 } else if (element is TopLevelVariableElement) {
180 type = HighlightRegionType.TOP_LEVEL_VARIABLE;
165 } 181 }
166 if (element is TopLevelVariableElement) { 182 // add region
167 return _addRegion_node(node, HighlightRegionType.TOP_LEVEL_VARIABLE); 183 if (type != null) {
184 return _addRegion_node(node, type);
168 } 185 }
169 return false; 186 return false;
170 } 187 }
171 188
172 bool _addIdentifierRegion_function(SimpleIdentifier node) { 189 bool _addIdentifierRegion_function(SimpleIdentifier node) {
173 Element element = node.staticElement; 190 Element element = node.staticElement;
174 if (element is! FunctionElement) { 191 if (element is! FunctionElement) {
175 return false; 192 return false;
176 } 193 }
177 HighlightRegionType type; 194 HighlightRegionType type;
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 return super.visitDoStatement(node); 431 return super.visitDoStatement(node);
415 } 432 }
416 433
417 @override 434 @override
418 Object visitDoubleLiteral(DoubleLiteral node) { 435 Object visitDoubleLiteral(DoubleLiteral node) {
419 computer._addRegion_node(node, HighlightRegionType.LITERAL_DOUBLE); 436 computer._addRegion_node(node, HighlightRegionType.LITERAL_DOUBLE);
420 return super.visitDoubleLiteral(node); 437 return super.visitDoubleLiteral(node);
421 } 438 }
422 439
423 @override 440 @override
441 Object visitEnumDeclaration(EnumDeclaration node) {
442 computer._addRegion_token(node.keyword, HighlightRegionType.KEYWORD);
443 return super.visitEnumDeclaration(node);
444 }
445
446 @override
424 Object visitExportDirective(ExportDirective node) { 447 Object visitExportDirective(ExportDirective node) {
425 computer._addRegion_node(node, HighlightRegionType.DIRECTIVE); 448 computer._addRegion_node(node, HighlightRegionType.DIRECTIVE);
426 computer._addRegion_token(node.keyword, HighlightRegionType.BUILT_IN); 449 computer._addRegion_token(node.keyword, HighlightRegionType.BUILT_IN);
427 return super.visitExportDirective(node); 450 return super.visitExportDirective(node);
428 } 451 }
429 452
430 @override 453 @override
431 Object visitFieldDeclaration(FieldDeclaration node) { 454 Object visitFieldDeclaration(FieldDeclaration node) {
432 computer._addRegion_token(node.staticKeyword, HighlightRegionType.BUILT_IN); 455 computer._addRegion_token(node.staticKeyword, HighlightRegionType.BUILT_IN);
433 return super.visitFieldDeclaration(node); 456 return super.visitFieldDeclaration(node);
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 computer._addRegion_token(node.keyword, HighlightRegionType.KEYWORD); 688 computer._addRegion_token(node.keyword, HighlightRegionType.KEYWORD);
666 return super.visitWhileStatement(node); 689 return super.visitWhileStatement(node);
667 } 690 }
668 691
669 @override 692 @override
670 Object visitWithClause(WithClause node) { 693 Object visitWithClause(WithClause node) {
671 computer._addRegion_token(node.withKeyword, HighlightRegionType.KEYWORD); 694 computer._addRegion_token(node.withKeyword, HighlightRegionType.KEYWORD);
672 return super.visitWithClause(node); 695 return super.visitWithClause(node);
673 } 696 }
674 } 697 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698