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

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

Issue 725163004: Report HintCode.UNUSED_ELEMENT for functions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
« 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:collection'; 7 import 'dart:collection';
8 import "dart:math" as math; 8 import "dart:math" as math;
9 9
10 import 'java_core.dart'; 10 import 'java_core.dart';
(...skipping 15565 matching lines...) Expand 10 before | Expand all | Expand 10 after
15576 ClassElement enclosingClassOld = _enclosingClass; 15576 ClassElement enclosingClassOld = _enclosingClass;
15577 try { 15577 try {
15578 _enclosingClass = node.element; 15578 _enclosingClass = node.element;
15579 super.visitClassDeclaration(node); 15579 super.visitClassDeclaration(node);
15580 } finally { 15580 } finally {
15581 _enclosingClass = enclosingClassOld; 15581 _enclosingClass = enclosingClassOld;
15582 } 15582 }
15583 } 15583 }
15584 15584
15585 @override 15585 @override
15586 visitFunctionDeclaration(FunctionDeclaration node) {
15587 ExecutableElement enclosingExecOld = _enclosingExec;
15588 try {
15589 _enclosingExec = node.element;
15590 super.visitFunctionDeclaration(node);
15591 } finally {
15592 _enclosingExec = enclosingExecOld;
15593 }
15594 }
15595
15596 @override
15597 visitFunctionExpression(FunctionExpression node) {
15598 if (node.parent is! FunctionDeclaration) {
15599 _useElement(node.element);
15600 }
15601 super.visitFunctionExpression(node);
15602 }
15603
15604 @override
15586 visitMethodDeclaration(MethodDeclaration node) { 15605 visitMethodDeclaration(MethodDeclaration node) {
15587 ExecutableElement enclosingExecOld = _enclosingExec; 15606 ExecutableElement enclosingExecOld = _enclosingExec;
15588 try { 15607 try {
15589 _enclosingExec = node.element; 15608 _enclosingExec = node.element;
15590 super.visitMethodDeclaration(node); 15609 super.visitMethodDeclaration(node);
15591 } finally { 15610 } finally {
15592 _enclosingExec = enclosingExecOld; 15611 _enclosingExec = enclosingExecOld;
15593 } 15612 }
15594 } 15613 }
15595 15614
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
15732 _reportErrorForElement( 15751 _reportErrorForElement(
15733 HintCode.UNUSED_ELEMENT, 15752 HintCode.UNUSED_ELEMENT,
15734 element, 15753 element,
15735 [element.kind.displayName, element.displayName]); 15754 [element.kind.displayName, element.displayName]);
15736 } 15755 }
15737 super.visitClassElement(element); 15756 super.visitClassElement(element);
15738 } 15757 }
15739 15758
15740 @override 15759 @override
15741 visitFieldElement(FieldElement element) { 15760 visitFieldElement(FieldElement element) {
15742 if (!element.isSynthetic && !_isReadMember(element)) { 15761 if (!_isReadMember(element)) {
15743 _reportErrorForElement( 15762 _reportErrorForElement(
15744 HintCode.UNUSED_FIELD, 15763 HintCode.UNUSED_FIELD,
15745 element, 15764 element,
15746 [element.displayName]); 15765 [element.displayName]);
15747 } 15766 }
15748 super.visitFieldElement(element); 15767 super.visitFieldElement(element);
15749 } 15768 }
15750 15769
15751 @override 15770 @override
15771 visitFunctionElement(FunctionElement element) {
15772 if (!_isUsedElement(element)) {
15773 _reportErrorForElement(
15774 HintCode.UNUSED_ELEMENT,
15775 element,
15776 [element.kind.displayName, element.displayName]);
15777 }
15778 super.visitFunctionElement(element);
15779 }
15780
15781 @override
15752 visitLocalVariableElement(LocalVariableElement element) { 15782 visitLocalVariableElement(LocalVariableElement element) {
15753 if (!_isUsedElement(element)) { 15783 if (!_isUsedElement(element)) {
15754 _reportErrorForElement( 15784 _reportErrorForElement(
15755 HintCode.UNUSED_LOCAL_VARIABLE, 15785 HintCode.UNUSED_LOCAL_VARIABLE,
15756 element, 15786 element,
15757 [element.displayName]); 15787 [element.displayName]);
15758 } 15788 }
15759 } 15789 }
15760 15790
15761 @override 15791 @override
15762 visitMethodElement(MethodElement element) { 15792 visitMethodElement(MethodElement element) {
15763 if (!_isUsedMember(element)) { 15793 if (!_isUsedMember(element)) {
15764 _reportErrorForElement( 15794 _reportErrorForElement(
15765 HintCode.UNUSED_ELEMENT, 15795 HintCode.UNUSED_ELEMENT,
15766 element, 15796 element,
15767 [element.kind.displayName, element.displayName]); 15797 [element.kind.displayName, element.displayName]);
15768 } 15798 }
15769 super.visitMethodElement(element); 15799 super.visitMethodElement(element);
15770 } 15800 }
15771 15801
15772 @override 15802 @override
15773 visitPropertyAccessorElement(PropertyAccessorElement element) { 15803 visitPropertyAccessorElement(PropertyAccessorElement element) {
15774 if (!element.isSynthetic && !_isUsedMember(element)) { 15804 if (!_isUsedMember(element)) {
15775 _reportErrorForElement( 15805 _reportErrorForElement(
15776 HintCode.UNUSED_ELEMENT, 15806 HintCode.UNUSED_ELEMENT,
15777 element, 15807 element,
15778 [element.kind.displayName, element.displayName]); 15808 [element.kind.displayName, element.displayName]);
15779 } 15809 }
15780 super.visitPropertyAccessorElement(element); 15810 super.visitPropertyAccessorElement(element);
15781 } 15811 }
15782 15812
15783 bool _isUsedElement(Element element) { 15813 bool _isUsedElement(Element element) {
15784 if (element is! LocalVariableElement) { 15814 if (element.isSynthetic) {
15815 return true;
15816 }
15817 if (element is LocalVariableElement ||
15818 element is FunctionElement && !element.isStatic) {
Brian Wilkerson 2014/11/14 18:52:57 It always looks weird to me to have an empty then
scheglov 2014/11/14 19:08:09 I agree in general, but in this case there are two
15819 } else {
15785 if (element.isPublic) { 15820 if (element.isPublic) {
15786 return true; 15821 return true;
15787 } 15822 }
15788 } 15823 }
15824 // if (element is! LocalVariableElement) {
15825 // if (element.isPublic) {
15826 // return true;
15827 // }
15828 // }
15789 return _usedElements.elements.contains(element); 15829 return _usedElements.elements.contains(element);
15790 } 15830 }
15791 15831
15792 bool _isReadMember(Element element) { 15832 bool _isReadMember(Element element) {
15793 if (element.isPublic) { 15833 if (element.isPublic) {
15794 return true; 15834 return true;
15795 } 15835 }
15836 if (element.isSynthetic) {
15837 return true;
15838 }
15796 return _usedElements.readMembers.contains(element.displayName); 15839 return _usedElements.readMembers.contains(element.displayName);
15797 } 15840 }
15798 15841
15799 bool _isUsedMember(Element element) { 15842 bool _isUsedMember(Element element) {
15800 if (element.isPublic) { 15843 if (element.isPublic) {
15801 return true; 15844 return true;
15802 } 15845 }
15846 if (element.isSynthetic) {
15847 return true;
15848 }
15803 if (_usedElements.members.contains(element.displayName)) { 15849 if (_usedElements.members.contains(element.displayName)) {
15804 return true; 15850 return true;
15805 } 15851 }
15806 return _usedElements.elements.contains(element); 15852 return _usedElements.elements.contains(element);
15807 } 15853 }
15808 15854
15809 void _reportErrorForElement(ErrorCode errorCode, Element element, List<Object> arguments) { 15855 void _reportErrorForElement(ErrorCode errorCode, Element element, List<Object> arguments) {
15810 if (element != null) { 15856 if (element != null) {
15811 _errorListener.onError( 15857 _errorListener.onError(
15812 new AnalysisError.con2( 15858 new AnalysisError.con2(
15813 element.source, 15859 element.source,
15814 element.nameOffset, 15860 element.nameOffset,
15815 element.displayName.length, 15861 element.displayName.length,
15816 errorCode, 15862 errorCode,
15817 arguments)); 15863 arguments));
15818 } 15864 }
15819 } 15865 }
15820 } 15866 }
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