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

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

Issue 1345943006: Report UNRESOLVED_INSTANCE_MEMBER_REFERENCE for dynamicVar.member references. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: more fixes Created 5 years, 3 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/test/analysis/notification_highlights_test2.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 computer.highlights2; 5 library computer.highlights2;
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 } 89 }
90 if (_addIdentifierRegion_method(node)) { 90 if (_addIdentifierRegion_method(node)) {
91 return; 91 return;
92 } 92 }
93 if (_addIdentifierRegion_parameter(node)) { 93 if (_addIdentifierRegion_parameter(node)) {
94 return; 94 return;
95 } 95 }
96 if (_addIdentifierRegion_typeParameter(node)) { 96 if (_addIdentifierRegion_typeParameter(node)) {
97 return; 97 return;
98 } 98 }
99 if (_addIdentifierRegion_unresolvedInstanceMemberReference(node)) {
100 return;
101 }
99 _addRegion_node(node, HighlightRegionType.IDENTIFIER_DEFAULT); 102 _addRegion_node(node, HighlightRegionType.IDENTIFIER_DEFAULT);
100 } 103 }
101 104
102 void _addIdentifierRegion_annotation(Annotation node) { 105 void _addIdentifierRegion_annotation(Annotation node) {
103 ArgumentList arguments = node.arguments; 106 ArgumentList arguments = node.arguments;
104 if (arguments == null) { 107 if (arguments == null) {
105 _addRegion_node(node, HighlightRegionType.ANNOTATION); 108 _addRegion_node(node, HighlightRegionType.ANNOTATION);
106 } else { 109 } else {
107 _addRegion_nodeStart_tokenEnd( 110 _addRegion_nodeStart_tokenEnd(
108 node, arguments.beginToken, HighlightRegionType.ANNOTATION); 111 node, arguments.beginToken, HighlightRegionType.ANNOTATION);
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 } 348 }
346 349
347 bool _addIdentifierRegion_typeParameter(SimpleIdentifier node) { 350 bool _addIdentifierRegion_typeParameter(SimpleIdentifier node) {
348 Element element = node.staticElement; 351 Element element = node.staticElement;
349 if (element is! TypeParameterElement) { 352 if (element is! TypeParameterElement) {
350 return false; 353 return false;
351 } 354 }
352 return _addRegion_node(node, HighlightRegionType.TYPE_PARAMETER); 355 return _addRegion_node(node, HighlightRegionType.TYPE_PARAMETER);
353 } 356 }
354 357
358 bool _addIdentifierRegion_unresolvedInstanceMemberReference(
359 SimpleIdentifier node) {
360 // unresolved
361 Element element = node.bestElement;
362 if (element != null) {
363 return false;
364 }
365 // invoke / get / set
366 bool decorate = false;
367 AstNode parent = node.parent;
368 if (parent is MethodInvocation) {
369 Expression target = parent.realTarget;
370 if (parent.methodName == node &&
371 target != null &&
372 _isDynamicExpression(target)) {
373 decorate = true;
374 }
375 } else if (node.inGetterContext() || node.inSetterContext()) {
376 if (parent is PrefixedIdentifier) {
377 decorate = parent.identifier == node;
378 } else if (parent is PropertyAccess) {
379 decorate = parent.propertyName == node;
380 }
381 }
382 if (decorate) {
383 _addRegion_node(
384 node, HighlightRegionType.UNRESOLVED_INSTANCE_MEMBER_REFERENCE);
385 return true;
386 }
387 return false;
388 }
389
355 void _addRegion(int offset, int length, HighlightRegionType type) { 390 void _addRegion(int offset, int length, HighlightRegionType type) {
356 _regions.add(new HighlightRegion(type, offset, length)); 391 _regions.add(new HighlightRegion(type, offset, length));
357 } 392 }
358 393
359 bool _addRegion_node(AstNode node, HighlightRegionType type) { 394 bool _addRegion_node(AstNode node, HighlightRegionType type) {
360 int offset = node.offset; 395 int offset = node.offset;
361 int length = node.length; 396 int length = node.length;
362 _addRegion(offset, length, type); 397 _addRegion(offset, length, type);
363 return true; 398 return true;
364 } 399 }
(...skipping 12 matching lines...) Expand all
377 _addRegion(offset, length, type); 412 _addRegion(offset, length, type);
378 } 413 }
379 } 414 }
380 415
381 void _addRegion_tokenStart_tokenEnd( 416 void _addRegion_tokenStart_tokenEnd(
382 Token a, Token b, HighlightRegionType type) { 417 Token a, Token b, HighlightRegionType type) {
383 int offset = a.offset; 418 int offset = a.offset;
384 int end = b.end; 419 int end = b.end;
385 _addRegion(offset, end - offset, type); 420 _addRegion(offset, end - offset, type);
386 } 421 }
422
423 static bool _isDynamicExpression(Expression e) {
424 if (e is SimpleIdentifier && e.staticElement is PrefixElement) {
425 return false;
426 }
427 return e.bestType.isDynamic;
428 }
387 } 429 }
388 430
389 /** 431 /**
390 * An AST visitor for [DartUnitHighlightsComputer2]. 432 * An AST visitor for [DartUnitHighlightsComputer2].
391 */ 433 */
392 class _DartUnitHighlightsComputerVisitor2 extends RecursiveAstVisitor<Object> { 434 class _DartUnitHighlightsComputerVisitor2 extends RecursiveAstVisitor<Object> {
393 final DartUnitHighlightsComputer2 computer; 435 final DartUnitHighlightsComputer2 computer;
394 436
395 _DartUnitHighlightsComputerVisitor2(this.computer); 437 _DartUnitHighlightsComputerVisitor2(this.computer);
396 438
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 void _addRegions_functionBody(FunctionBody node) { 809 void _addRegions_functionBody(FunctionBody node) {
768 Token keyword = node.keyword; 810 Token keyword = node.keyword;
769 if (keyword != null) { 811 if (keyword != null) {
770 Token star = node.star; 812 Token star = node.star;
771 int offset = keyword.offset; 813 int offset = keyword.offset;
772 int end = star != null ? star.end : keyword.end; 814 int end = star != null ? star.end : keyword.end;
773 computer._addRegion(offset, end - offset, HighlightRegionType.BUILT_IN); 815 computer._addRegion(offset, end - offset, HighlightRegionType.BUILT_IN);
774 } 816 }
775 } 817 }
776 } 818 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/analysis/notification_highlights_test2.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698