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

Side by Side Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 1040083007: do not report _ as unused variable (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 5 years, 8 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
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/resolver_test.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 engine.resolver; 5 library engine.resolver;
6 6
7 import "dart:math" as math; 7 import "dart:math" as math;
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/src/generated/utilities_collection.dart'; 10 import 'package:analyzer/src/generated/utilities_collection.dart';
(...skipping 15302 matching lines...) Expand 10 before | Expand all | Expand 10 after
15313 _reportErrorForElement(HintCode.UNUSED_ELEMENT, element, [ 15313 _reportErrorForElement(HintCode.UNUSED_ELEMENT, element, [
15314 element.kind.displayName, 15314 element.kind.displayName,
15315 element.displayName 15315 element.displayName
15316 ]); 15316 ]);
15317 } 15317 }
15318 super.visitFunctionElement(element); 15318 super.visitFunctionElement(element);
15319 } 15319 }
15320 15320
15321 @override 15321 @override
15322 visitLocalVariableElement(LocalVariableElement element) { 15322 visitLocalVariableElement(LocalVariableElement element) {
15323 if (!_isUsedElement(element)) { 15323 if (!_isUsedElement(element) && !_isNamedUnderscore(element)) {
15324 HintCode errorCode; 15324 HintCode errorCode;
15325 if (_usedElements.isCatchException(element)) { 15325 if (_usedElements.isCatchException(element)) {
15326 errorCode = HintCode.UNUSED_CATCH_CLAUSE; 15326 errorCode = HintCode.UNUSED_CATCH_CLAUSE;
15327 } else if (_usedElements.isCatchStackTrace(element)) { 15327 } else if (_usedElements.isCatchStackTrace(element)) {
15328 errorCode = HintCode.UNUSED_CATCH_STACK; 15328 errorCode = HintCode.UNUSED_CATCH_STACK;
15329 } else { 15329 } else {
15330 errorCode = HintCode.UNUSED_LOCAL_VARIABLE; 15330 errorCode = HintCode.UNUSED_LOCAL_VARIABLE;
15331 } 15331 }
15332 _reportErrorForElement(errorCode, element, [element.displayName]); 15332 _reportErrorForElement(errorCode, element, [element.displayName]);
15333 } 15333 }
(...skipping 14 matching lines...) Expand all
15348 visitPropertyAccessorElement(PropertyAccessorElement element) { 15348 visitPropertyAccessorElement(PropertyAccessorElement element) {
15349 if (!_isUsedMember(element)) { 15349 if (!_isUsedMember(element)) {
15350 _reportErrorForElement(HintCode.UNUSED_ELEMENT, element, [ 15350 _reportErrorForElement(HintCode.UNUSED_ELEMENT, element, [
15351 element.kind.displayName, 15351 element.kind.displayName,
15352 element.displayName 15352 element.displayName
15353 ]); 15353 ]);
15354 } 15354 }
15355 super.visitPropertyAccessorElement(element); 15355 super.visitPropertyAccessorElement(element);
15356 } 15356 }
15357 15357
15358 bool _isNamedUnderscore(LocalVariableElement element) {
15359 String name = element.name;
15360 if (name != null) {
15361 for (int index = name.length - 1; index >= 0; --index) {
15362 if (name.codeUnitAt(index) != 0x5F) { // 0x5F => '_'
15363 return false;
15364 }
15365 }
15366 return true;
15367 }
15368 return false;
15369 }
15370
15358 bool _isReadMember(Element element) { 15371 bool _isReadMember(Element element) {
15359 if (element.isPublic) { 15372 if (element.isPublic) {
15360 return true; 15373 return true;
15361 } 15374 }
15362 if (element.isSynthetic) { 15375 if (element.isSynthetic) {
15363 return true; 15376 return true;
15364 } 15377 }
15365 return _usedElements.readMembers.contains(element.displayName); 15378 return _usedElements.readMembers.contains(element.displayName);
15366 } 15379 }
15367 15380
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
15447 } 15460 }
15448 15461
15449 bool isCatchException(LocalVariableElement element) { 15462 bool isCatchException(LocalVariableElement element) {
15450 return catchExceptionElements.contains(element); 15463 return catchExceptionElements.contains(element);
15451 } 15464 }
15452 15465
15453 bool isCatchStackTrace(LocalVariableElement element) { 15466 bool isCatchStackTrace(LocalVariableElement element) {
15454 return catchStackTraceElements.contains(element); 15467 return catchStackTraceElements.contains(element);
15455 } 15468 }
15456 } 15469 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698