Class LambdaAndReferenceTck
java.lang.Object
io.micronaut.sourcegen.bytecode.tck.AbstractByteCodeWriterTck
io.micronaut.sourcegen.bytecode.tck.LambdaAndReferenceTck
Lambdas and method references: the functional interface method they implement, the receiver
they capture and the scope of the type variables they use.
A backend runs these tests by extending this class and implementing
AbstractByteCodeWriterTck.write(io.micronaut.sourcegen.model.ObjectDef).
- Since:
- 2.3
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA superclass with a method to refer to through `super`.static classGeneric superclass for a void-adapted reference. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidA bound reference checks its receiver where it is created, as `target::apply` does in source, not where the reference is invoked.voidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidreferencesCaptureTheirReceiverBeforeItChanges(String kind, int receiverReads) A bound method reference evaluates its receiver once, where it is created, so replacing the receiver later does not change what the reference calls.voidvoidA reference through `super` calls the method of the superclass, not the override of the class that creates it.voidA void functional target discards the result of a reference through super.voidA reference to a method of variable arity bound to a field -Function<String, String> f = this.format::formatted- reads the field once, where it is created: assigning the field afterwards does not change what the reference calls, and a null field fails where it is created.voidMethods inherited from class AbstractByteCodeWriterTck
assertCall, caller, callWithParameter, classShape, declaredFields, declaredMethods, define, defineInPackage, genericShape, invoke, list, load, outcome, run, run, run, selection, selection, shape, write
-
Constructor Details
-
LambdaAndReferenceTck
public LambdaAndReferenceTck()
-
-
Method Details
-
referencesCaptureTheirReceiverBeforeItChanges
@ParameterizedTest(name="a reference to a {0} receiver captures it before it changes, calling next() {1} time(s)") @CsvSource({"field, 0","local, 0","result, 1"}) public void referencesCaptureTheirReceiverBeforeItChanges(String kind, int receiverReads) throws Exception A bound method reference evaluates its receiver once, where it is created, so replacing the receiver later does not change what the reference calls. A receiver that is the result of a call is read exactly once.- Parameters:
kind- What the receiver is: a field, a local or the result of a callreceiverReads- How many times creating the reference calls the method that returns the receiver- Throws:
Exception- If the generated program cannot be loaded or invoked- Since:
- 2.3
-
varargsReferenceBoundToAFieldCapturesItsValue
A reference to a method of variable arity bound to a field -Function<String, String> f = this.format::formatted- reads the field once, where it is created: assigning the field afterwards does not change what the reference calls, and a null field fails where it is created.- Throws:
Exception- If the generated class cannot be used- Since:
- 2.3
-
boundReferenceRejectsANullReceiverWhereItIsCreated
-
superReferenceCallsTheMethodOfTheSuperclass
-
superReferenceCanDiscardTheReferencedResult
-
explicitGenericMethodReferenceKeepsErasedDescriptor
-
boundMethodReferenceUsesTheTargetsClassScope
-
staticMethodReferenceUsesTheTargetsMethodScope
-
lambdaCaptureRetainsTheEnclosingMethodsBound
-
genericConstructorReferenceUsesConstructorScope
-
genericMethodBoundReferenceAcceptsATypeVariableReceiver
-
genericVarargsMethodReferencePacksItsArguments
-
voidAdaptedGenericSuperReferenceDiscardsItsReturnValue
-
methodReferenceSamUsesTheEnclosingMethodBound
-
methodReferenceSamMethodBoundShadowsClassBound
-
lambdaSamUsesTheEnclosingMethodBound
-
methodReferenceByNameToAnObjectMethodOfAnInterfaceReceiver
-
methodReferenceByNameToAMethodWithABridge
-