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

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: tweak 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 15633 matching lines...) Expand 10 before | Expand all | Expand 10 after
15644 ClassElement enclosingClassOld = _enclosingClass; 15644 ClassElement enclosingClassOld = _enclosingClass;
15645 try { 15645 try {
15646 _enclosingClass = node.element; 15646 _enclosingClass = node.element;
15647 super.visitClassDeclaration(node); 15647 super.visitClassDeclaration(node);
15648 } finally { 15648 } finally {
15649 _enclosingClass = enclosingClassOld; 15649 _enclosingClass = enclosingClassOld;
15650 } 15650 }
15651 } 15651 }
15652 15652
15653 @override 15653 @override
15654 visitFunctionDeclaration(FunctionDeclaration node) {
15655 ExecutableElement enclosingExecOld = _enclosingExec;
15656 try {
15657 _enclosingExec = node.element;
15658 super.visitFunctionDeclaration(node);
15659 } finally {
15660 _enclosingExec = enclosingExecOld;
15661 }
15662 }
15663
15664 @override
15665 visitFunctionExpression(FunctionExpression node) {
15666 if (node.parent is! FunctionDeclaration) {
15667 _useElement(node.element);
15668 }
15669 super.visitFunctionExpression(node);
15670 }
15671
15672 @override
15654 visitMethodDeclaration(MethodDeclaration node) { 15673 visitMethodDeclaration(MethodDeclaration node) {
15655 ExecutableElement enclosingExecOld = _enclosingExec; 15674 ExecutableElement enclosingExecOld = _enclosingExec;
15656 try { 15675 try {
15657 _enclosingExec = node.element; 15676 _enclosingExec = node.element;
15658 super.visitMethodDeclaration(node); 15677 super.visitMethodDeclaration(node);
15659 } finally { 15678 } finally {
15660 _enclosingExec = enclosingExecOld; 15679 _enclosingExec = enclosingExecOld;
15661 } 15680 }
15662 } 15681 }
15663 15682
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
15800 _reportErrorForElement( 15819 _reportErrorForElement(
15801 HintCode.UNUSED_ELEMENT, 15820 HintCode.UNUSED_ELEMENT,
15802 element, 15821 element,
15803 [element.kind.displayName, element.displayName]); 15822 [element.kind.displayName, element.displayName]);
15804 } 15823 }
15805 super.visitClassElement(element); 15824 super.visitClassElement(element);
15806 } 15825 }
15807 15826
15808 @override 15827 @override
15809 visitFieldElement(FieldElement element) { 15828 visitFieldElement(FieldElement element) {
15810 if (!element.isSynthetic && !_isReadMember(element)) { 15829 if (!_isReadMember(element)) {
15811 _reportErrorForElement( 15830 _reportErrorForElement(
15812 HintCode.UNUSED_FIELD, 15831 HintCode.UNUSED_FIELD,
15813 element, 15832 element,
15814 [element.displayName]); 15833 [element.displayName]);
15815 } 15834 }
15816 super.visitFieldElement(element); 15835 super.visitFieldElement(element);
15817 } 15836 }
15818 15837
15819 @override 15838 @override
15839 visitFunctionElement(FunctionElement element) {
15840 if (!_isUsedElement(element)) {
15841 _reportErrorForElement(
15842 HintCode.UNUSED_ELEMENT,
15843 element,
15844 [element.kind.displayName, element.displayName]);
15845 }
15846 super.visitFunctionElement(element);
15847 }
15848
15849 @override
15820 visitLocalVariableElement(LocalVariableElement element) { 15850 visitLocalVariableElement(LocalVariableElement element) {
15821 if (!_isUsedElement(element)) { 15851 if (!_isUsedElement(element)) {
15822 _reportErrorForElement( 15852 _reportErrorForElement(
15823 HintCode.UNUSED_LOCAL_VARIABLE, 15853 HintCode.UNUSED_LOCAL_VARIABLE,
15824 element, 15854 element,
15825 [element.displayName]); 15855 [element.displayName]);
15826 } 15856 }
15827 } 15857 }
15828 15858
15829 @override 15859 @override
15830 visitMethodElement(MethodElement element) { 15860 visitMethodElement(MethodElement element) {
15831 if (!_isUsedMember(element)) { 15861 if (!_isUsedMember(element)) {
15832 _reportErrorForElement( 15862 _reportErrorForElement(
15833 HintCode.UNUSED_ELEMENT, 15863 HintCode.UNUSED_ELEMENT,
15834 element, 15864 element,
15835 [element.kind.displayName, element.displayName]); 15865 [element.kind.displayName, element.displayName]);
15836 } 15866 }
15837 super.visitMethodElement(element); 15867 super.visitMethodElement(element);
15838 } 15868 }
15839 15869
15840 @override 15870 @override
15841 visitPropertyAccessorElement(PropertyAccessorElement element) { 15871 visitPropertyAccessorElement(PropertyAccessorElement element) {
15842 if (!element.isSynthetic && !_isUsedMember(element)) { 15872 if (!_isUsedMember(element)) {
15843 _reportErrorForElement( 15873 _reportErrorForElement(
15844 HintCode.UNUSED_ELEMENT, 15874 HintCode.UNUSED_ELEMENT,
15845 element, 15875 element,
15846 [element.kind.displayName, element.displayName]); 15876 [element.kind.displayName, element.displayName]);
15847 } 15877 }
15848 super.visitPropertyAccessorElement(element); 15878 super.visitPropertyAccessorElement(element);
15849 } 15879 }
15850 15880
15851 bool _isUsedElement(Element element) { 15881 bool _isUsedElement(Element element) {
15852 if (element is! LocalVariableElement) { 15882 if (element.isSynthetic) {
15883 return true;
15884 }
15885 if (element is LocalVariableElement ||
15886 element is FunctionElement && !element.isStatic) {
15887 // local variable or function
15888 } else {
15853 if (element.isPublic) { 15889 if (element.isPublic) {
15854 return true; 15890 return true;
15855 } 15891 }
15856 } 15892 }
15857 return _usedElements.elements.contains(element); 15893 return _usedElements.elements.contains(element);
15858 } 15894 }
15859 15895
15860 bool _isReadMember(Element element) { 15896 bool _isReadMember(Element element) {
15861 if (element.isPublic) { 15897 if (element.isPublic) {
15862 return true; 15898 return true;
15863 } 15899 }
15900 if (element.isSynthetic) {
15901 return true;
15902 }
15864 return _usedElements.readMembers.contains(element.displayName); 15903 return _usedElements.readMembers.contains(element.displayName);
15865 } 15904 }
15866 15905
15867 bool _isUsedMember(Element element) { 15906 bool _isUsedMember(Element element) {
15868 if (element.isPublic) { 15907 if (element.isPublic) {
15869 return true; 15908 return true;
15870 } 15909 }
15910 if (element.isSynthetic) {
15911 return true;
15912 }
15871 if (_usedElements.members.contains(element.displayName)) { 15913 if (_usedElements.members.contains(element.displayName)) {
15872 return true; 15914 return true;
15873 } 15915 }
15874 return _usedElements.elements.contains(element); 15916 return _usedElements.elements.contains(element);
15875 } 15917 }
15876 15918
15877 void _reportErrorForElement(ErrorCode errorCode, Element element, List<Object> arguments) { 15919 void _reportErrorForElement(ErrorCode errorCode, Element element, List<Object> arguments) {
15878 if (element != null) { 15920 if (element != null) {
15879 _errorListener.onError( 15921 _errorListener.onError(
15880 new AnalysisError.con2( 15922 new AnalysisError.con2(
15881 element.source, 15923 element.source,
15882 element.nameOffset, 15924 element.nameOffset,
15883 element.displayName.length, 15925 element.displayName.length,
15884 errorCode, 15926 errorCode,
15885 arguments)); 15927 arguments));
15886 } 15928 }
15887 } 15929 }
15888 } 15930 }
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