dev.lukebemish.opensesame.compile.OpenProcessor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opensesame-compile Show documentation
Show all versions of opensesame-compile Show documentation
Compile-time abstractions for OpenSesame, a tool for typesafe access to normally inaccessible members
package dev.lukebemish.opensesame.compile;
import dev.lukebemish.opensesame.annotations.Coerce;
import dev.lukebemish.opensesame.annotations.Open;
import org.jetbrains.annotations.Nullable;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.ArrayList;
import java.util.List;
public interface OpenProcessor {
TypeProvider types();
ConDynUtils conDynUtils();
Object typeProviderFromAnnotation(A annotation, M method, Class> annotationType);
record Opening(T factoryType, Object targetProvider, Object methodTypeProvider, Open.Type type, String name, boolean unsafe) {}
record MethodParameter(T type, @Nullable A annotation) {}
@Nullable A annotation(M method, Class> type);
List> parameters(M method, @Nullable Class> type);
Open.Type type(A annotation);
@Nullable String name(A annotation);
boolean unsafe(A annotation);
T returnType(M method);
boolean isStatic(M method);
String methodName(M method);
T declaringClass(M method);
default Opening opening(M method) {
A annotation = annotation(method, Open.class);
Object targetClassHandle = typeProviderFromAnnotation(annotation, method, Open.class);
String name = name(annotation);
if (name == null || name.isEmpty()) {
name = "$dev$lukebemish$opensesame$$unspecified";
}
final Open.Type type = type(annotation);
var parameters = parameters(method, Coerce.class);
String[] parameterDescs = new String[parameters.size()];
for (int i = 0; i < parameters.size(); i++) {
parameterDescs[i] = types().descriptor(parameters.get(i).type());
}
T asmDescType = types().methodType(types().descriptor(returnType(method)), parameterDescs);
Object returnType = conDynUtils().conDynFromClass(types().returnType(asmDescType));
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy