Interface CtConsumableFunction<T>

Type Parameters:
T - the type of the input to the function
All Known Implementing Classes:
AllMethodsSameSignatureFunction, AllTypeMembersFunction, CatchVariableReferenceFunction, CatchVariableScopeFunction, CtScannerFunction, FieldReferenceFunction, FieldScopeFunction, LocalVariableReferenceFunction, LocalVariableScopeFunction, OverriddenMethodQuery, ParameterReferenceFunction, ParameterScopeFunction, ParentFunction, PotentialVariableDeclarationFunction, SiblingsFunction, SubInheritanceHierarchyFunction, SuperInheritanceHierarchyFunction, VariableReferenceFunction, VariableScopeFunction

public interface CtConsumableFunction<T>
Represents a function, as CtFunction. However, the main difference is that while a CtFunction returns something with a standard Java return keyword, a CtConsumableFunction returns something by passing the returned object as parameter to the given outpuConsumer#accept. This enables to write efficient and concise code in certain situations. It also enables one to emulate several returns, by simply calling several times accept, while not paying the code or performance price of creating a list or an iterable object. It is typically used as parameter of CtQueryable.map(CtConsumableFunction), can be written as one-liners with Java8 lambdas:.`cls.map((CtClass<?> c, CtConsumer<Object> out)->out.accept(c.getParent()))`
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    apply​(T input, CtConsumer<Object> outputConsumer)
    Evaluates the function on the given input.
  • Method Details

    • apply

      void apply(T input, CtConsumer<Object> outputConsumer)
      Evaluates the function on the given input.
      Parameters:
      input - the input of the function
      outputConsumer - the consumer which accepts the results of this function.