Skip to content

Commit

Permalink
@deprecated should work on 'called' objects
Browse files Browse the repository at this point in the history
BUG=#9470

Example output:

$ cat -n a.dart
     1  class Foo {
     2    Foo foo;
     3
     4    @deprecated
     5    call(String name) {
     6      print("hello $name");
     7    }
     8  }
     9
    10  void main() {
    11    Foo f = new Foo();
    12    f("Thomas");
    13    f.foo = new Foo();
    14    f.foo("Timmy");
    15  }
$ xcodebuild/ReleaseX64/dart-sdk/bin/dartanalyzer a.dart
Analyzing [a.dart]...
[hint] 'Foo.call' is deprecated (/Users/srawlins/code/dart-repo3/sdk/a.dart, line 12, col 3)
[hint] 'Foo.call' is deprecated (/Users/srawlins/code/dart-repo3/sdk/a.dart, line 14, col 3)
2 hints found.

R=brianwilkerson@google.com, scheglov@google.com

Review URL: https://codereview.chromium.org/1922563003 .
  • Loading branch information
srawlins committed Apr 27, 2016
1 parent 4ea8b39 commit 2cfa9c4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
21 changes: 19 additions & 2 deletions pkg/analyzer/lib/src/generated/resolver.dart
Expand Up @@ -76,12 +76,18 @@ class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
*/
TypeSystem _typeSystem;

/**
* The current library
*/
LibraryElement _currentLibrary;

/**
* Create a new instance of the [BestPracticesVerifier].
*
* @param errorReporter the error reporter
*/
BestPracticesVerifier(this._errorReporter, TypeProvider typeProvider,
BestPracticesVerifier(
this._errorReporter, TypeProvider typeProvider, this._currentLibrary,
{TypeSystem typeSystem})
: _futureNullType = typeProvider.futureNullType,
_typeSystem = (typeSystem != null) ? typeSystem : new TypeSystemImpl();
Expand Down Expand Up @@ -253,6 +259,12 @@ class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
Object visitMethodInvocation(MethodInvocation node) {
_checkForCanBeNullAfterNullAware(node.realTarget, node.operator);
_checkForInvalidProtectedMethodCalls(node);
DartType staticInvokeType = node.staticInvokeType;
if (staticInvokeType is InterfaceType) {
MethodElement methodElement = staticInvokeType.lookUpMethod(
FunctionElement.CALL_METHOD_NAME, _currentLibrary);
_checkForDeprecatedMemberUse(methodElement, node);
}
return super.visitMethodInvocation(node);
}

Expand Down Expand Up @@ -554,6 +566,10 @@ class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
if (!element.displayName.isEmpty) {
displayName = "$displayName.${element.displayName}";
}
} else if (displayName == FunctionElement.CALL_METHOD_NAME &&
node is MethodInvocation &&
node.staticInvokeType is InterfaceType) {
displayName = "${node.staticInvokeType.displayName}.${element.displayName}";
}
_errorReporter.reportErrorForNode(
HintCode.DEPRECATED_MEMBER_USE, node, [displayName]);
Expand Down Expand Up @@ -4236,7 +4252,8 @@ class HintGenerator {
unit.accept(new Dart2JSVerifier(errorReporter));
}
// Dart best practices
unit.accept(new BestPracticesVerifier(errorReporter, _context.typeProvider,
unit.accept(new BestPracticesVerifier(
errorReporter, _context.typeProvider, _library,
typeSystem: _context.typeSystem));
unit.accept(new OverrideVerifier(errorReporter, _manager));
// Find to-do comments
Expand Down
4 changes: 2 additions & 2 deletions pkg/analyzer/lib/src/task/dart.dart
Expand Up @@ -2805,8 +2805,8 @@ class GenerateHintsTask extends SourceBasedAnalysisTask {
new InheritanceManager(libraryElement);
TypeProvider typeProvider = getRequiredInput(TYPE_PROVIDER_INPUT);

unit.accept(new BestPracticesVerifier(errorReporter, typeProvider,
typeSystem: typeSystem));
unit.accept(new BestPracticesVerifier(
errorReporter, typeProvider, libraryElement, typeSystem: typeSystem));
unit.accept(new OverrideVerifier(errorReporter, inheritanceManager));
// Find to-do comments.
new ToDoFinder(errorReporter).findIn(unit);
Expand Down
15 changes: 15 additions & 0 deletions pkg/analyzer/test/generated/hint_code_test.dart
Expand Up @@ -813,6 +813,21 @@ class B extends A {
verify([source]);
}

void test_deprecatedAnnotationUse_call() {
Source source = addSource(r'''
class A {
@deprecated
call() {}
m() {
A a = new A();
a();
}
}''');
computeLibrarySourceErrors(source);
assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]);
verify([source]);
}

void test_divisionOptimization_double() {
Source source = addSource(r'''
f(double x, double y) {
Expand Down

0 comments on commit 2cfa9c4

Please sign in to comment.