Class AbstractByteCodeWriterTck
java.lang.Object
io.micronaut.sourcegen.bytecode.tck.AbstractByteCodeWriterTck
- Direct Known Subclasses:
BridgeTck, ByteCodeWriterTck, ControlFlowTck, ConversionTck, ExpressionTck, InferenceTck, LambdaAndReferenceTck, MemberTypeTck, OverloadSelectionTck, ReceiverTck, SignatureTck
The support shared by every topic of the bytecode writer TCK: writing definitions with the backend
under test, loading them, and calling them next to javac's own call of a compiled fixture.
A backend runs a topic by extending it and implementing write(ObjectDef).
- Since:
- 2.3
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidassertCall(Object expected, List<TypeDef> types, List<?> values, Function<List<ExpressionDef>, ExpressionDef> body) Generates a staticcallmethod taking parameters of the given types, invokes it with the given values and asserts its result.protected static ClassDefcaller(ExpressionDef expression) A class with a staticcallmethod that returns the expression.protected static ClassDefcallWithParameter(TypeDef parameter, Function<ExpressionDef, ExpressionDef> body) A class with a staticcallmethod that takes one parameter and returns the body.protected static StringclassShape(Class<?> type) The generic supertypes of a class, its own name read as SELF.protected static Field[]declaredFields(Class<?> type) The fields a class declares, without the fields a coverage agent adds to it ($jacocoData).protected static Method[]declaredMethods(Class<?> type) The methods a class declares, without the members a coverage agent adds to it ($jacocoInit), which a class compiled by javac has when the tests run with coverage and a written class does not.protected final Class<?> Writes and loads one definition in a class loader of its own.protected final Class<?> defineInPackage(ObjectDef definition) Defines a class in the package and the class loader of the fixtures, which reaches their package-private members.genericShape(Class<?> type) The generic declarations of the methods of a class, its own name read as SELF.protected static ObjectInvokes a method loaded byrun(String, TypeDef, List, BiFunction)on a new instance.protected static ClassTypeDefprotected final ClassLoaderWrites definitions into one class loader, so that they can refer to each other.protected static ObjectWhat a call returns, or the name of the exception it throws.protected final ObjectLoads a caller made bycaller(ExpressionDef)next to its dependencies and calls it.protected final Objectrun(ExpressionDef expression, ObjectDef... dependencies) Generates a staticcallmethod that returns the expression, loads it next to its dependencies and calls it.protected final Methodrun(String name, TypeDef returns, List<TypeDef> parameters, BiFunction<VariableDef.This, List<VariableDef.MethodParameter>, StatementDef> body) Writes and loads a class with one instance methodrun.protected static MethodDefA public static overload that identifies itself by the value it returns.protected static MethodDefA static overload that identifies itself by the value it returns.The declared methods of a class as javac writes them: name, erased descriptor, access, bridges and defaults.protected abstract byte[]Writes one definition to class file bytes with the backend under test.
-
Constructor Details
-
AbstractByteCodeWriterTck
public AbstractByteCodeWriterTck()
-
-
Method Details
-
write
Writes one definition to class file bytes with the backend under test.An implementation should assert whatever its backend guarantees about how the bytes were produced, such as verifying them or refusing a fallback path, so that a backend cannot pass the TCK by quietly declining to write the definition itself.
- Parameters:
definition- The definition to write- Returns:
- The class file bytes
-
define
Writes and loads one definition in a class loader of its own.- Parameters:
definition- The definition to write and load- Returns:
- The loaded class
- Throws:
ClassNotFoundException- If the class cannot be loaded
-
load
Writes definitions into one class loader, so that they can refer to each other.- Parameters:
definitions- The definitions to write- Returns:
- The class loader that defines them
-
defineInPackage
Defines a class in the package and the class loader of the fixtures, which reaches their package-private members. The definition must be named in this package.- Parameters:
definition- The definition to write and define- Returns:
- The defined class
- Throws:
IllegalAccessException- If the class cannot be defined in this package
-
assertCall
protected final void assertCall(Object expected, List<TypeDef> types, List<?> values, Function<List<ExpressionDef>, ExpressionDef> body) throws Exception Generates a staticcallmethod taking parameters of the given types, invokes it with the given values and asserts its result. The expected value is usually javac's own call of the same fixture, so that the generated call must choose what javac chooses.- Parameters:
expected- The expected resulttypes- The parameter types of the generated methodvalues- The arguments to call it withbody- The expression the method returns, given its parameters- Throws:
Exception- If the class cannot be written, loaded or called
-
run
Generates a staticcallmethod that returns the expression, loads it next to its dependencies and calls it.- Parameters:
expression- The expression to returndependencies- The definitions the expression refers to- Returns:
- The value of the expression
- Throws:
Exception- If the classes cannot be written, loaded or called
-
run
Loads a caller made bycaller(ExpressionDef)next to its dependencies and calls it.- Parameters:
caller- The callerdependencies- The definitions the caller refers to- Returns:
- The result of the call
- Throws:
Exception- If the classes cannot be written, loaded or called
-
run
protected final Method run(String name, TypeDef returns, List<TypeDef> parameters, BiFunction<VariableDef.This, List<VariableDef.MethodParameter>, StatementDef> body) throws Exception Writes and loads a class with one instance methodrun.- Parameters:
name- The class namereturns- The return type of the methodparameters- The parameter types of the methodbody- The body of the method- Returns:
- The loaded method
- Throws:
Exception- If the class cannot be written or loaded
-
invoke
-
caller
A class with a staticcallmethod that returns the expression.- Parameters:
expression- The expression- Returns:
- The class
-
callWithParameter
protected static ClassDef callWithParameter(TypeDef parameter, Function<ExpressionDef, ExpressionDef> body) A class with a staticcallmethod that takes one parameter and returns the body.- Parameters:
parameter- The parameter typebody- The returned expression, given the parameter- Returns:
- The class
-
selection
-
selection
A static overload that identifies itself by the value it returns.- Parameters:
name- The method nameparameter- The parameter typevalue- The value the overload returnsaccess- The access modifier of the overload- Returns:
- The method
-
list
- Parameters:
argument- The type argument- Returns:
List<argument>
-
shape
-
genericShape
-
classShape
-
outcome
-
declaredMethods
-
declaredFields
-