Class LambdaFunctionalInterface

java.lang.Object
com.google.errorprone.bugpatterns.BugChecker
com.google.errorprone.bugpatterns.LambdaFunctionalInterface
All Implemented Interfaces:
BugChecker.MethodTreeMatcher, Suppressible, Serializable

public class LambdaFunctionalInterface
extends BugChecker
implements BugChecker.MethodTreeMatcher
Author:
amesbah@google.com (Ali Mesbah)
See Also:
Serialized Form
  • Constructor Details

    • LambdaFunctionalInterface

      public LambdaFunctionalInterface()
  • Method Details

    • matchMethod

      public Description matchMethod​(com.sun.source.tree.MethodTree tree, VisitorState state)
      Identifies methods with parameters that have a generic argument with Int, Long, or Double. If pre-conditions are met, it refactors them to the primitive specializations.
      PreConditions:
       (1): The method declaration has to be private (to do a safe refactoring)
       (2): Its parameters have to meet the following conditions:
          2.1 Contain type java.util.function.Function
          2.2 At least one argument type of the Function must be subtype of Number
       (3): All its invocations in the top-level enclosing class have to meet the following
       conditions as well:
          3.1: lambda argument of Kind.LAMBDA_EXPRESSION
          3.2: same as 2.1
          3.3: same as 2.2
       
       Refactoring Changes for matched methods:
       (1) Add the imports
       (2) Change the method signature to use utility function instead of Function
       (3) Find and change the 'apply' calls to the corresponding applyAsT
       
      Specified by:
      matchMethod in interface BugChecker.MethodTreeMatcher