本文整理汇总了Java中net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.ReceiverTypeDefinition类的典型用法代码示例。如果您正苦于以下问题:Java ReceiverTypeDefinition类的具体用法?Java ReceiverTypeDefinition怎么用?Java ReceiverTypeDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReceiverTypeDefinition类属于net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition包,在下文中一共展示了ReceiverTypeDefinition类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extendClass
import net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.ReceiverTypeDefinition; //导入依赖的package包/类
public static Class extendClass(Class<?> extend, final LuaTable delegations, Class<?>... inherit) {
long startTime = System.nanoTime();
ArrayDeque<Class> toCheck = new ArrayDeque<Class>();
toCheck.add(extend);
toCheck.addAll(Arrays.asList(inherit));
extendClassWhile(toCheck, delegations);
try {
ReceiverTypeDefinition<?> build = b.subclass(extend).implement(inherit)
.method(not(isConstructor()).and(isAbstract()))
.intercept(MethodDelegation.to(new AbstractInterceptor(delegations)));
if (!delegations.get("__new__").isnil()) {
build = build.constructor(isConstructor()).intercept(
SuperMethodCall.INSTANCE.andThen(MethodDelegation.to(new ConstructorInterceptor(delegations))));
}
Junction<MethodDescription> publicMethods = not(isConstructor().or(isAbstract())).and(isPublic())
.and(new ElementMatcher<MethodDescription>() {
@Override
public boolean matches(MethodDescription target) {
return !delegations.get(target.getName()).isnil();
}
});
build = build.method(publicMethods).intercept(MethodDelegation.to(new PublicInterceptor(delegations)));
Unloaded unloaded = build.make();
Loaded loaded = Compatibility.get().load(unloaded);
Class c = loaded.getLoaded();
Log.debug("Created dynamic class " + c.getName() + " in " + ((System.nanoTime() - startTime) / 1000000)
+ "ms");
return c;
} catch (Exception e) {
Log.error("Failed to create dynamic class " + extend.getName() + " " + Arrays.toString(inherit));
throw new CubesException("Failed to make dynamic class", e);
}
}
示例2: extendClass
import net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.ReceiverTypeDefinition; //导入依赖的package包/类
public static Class extendClass(Class<?> extend, final LuaTable delegations, Class<?>... inherit) {
long startTime = System.nanoTime();
ArrayDeque<Class> toCheck = new ArrayDeque<Class>();
toCheck.add(extend);
toCheck.addAll(Arrays.asList(inherit));
while (!toCheck.isEmpty()) {
Class check = toCheck.pop();
for (Method method : check.getDeclaredMethods()) {
if (Modifier.isAbstract(method.getModifiers())) {
if (delegations.get(method.getName()).isnil())
throw new DynamicDelegationError("No delegation for abstract method " + method);
}
}
check = check.getSuperclass();
if (check != null && check != Object.class) toCheck.add(check);
}
try {
ReceiverTypeDefinition<?> build = b.subclass(extend).implement(inherit)
.method(not(isConstructor()).and(isAbstract())).intercept(MethodDelegation.to(new AbstractInterceptor(delegations)));
if (!delegations.get("__new__").isnil()) {
build = build.constructor(isConstructor()).intercept(SuperMethodCall.INSTANCE.andThen(MethodDelegation.to(new ConstructorInterceptor(delegations))));
}
Junction<MethodDescription> publicMethods = not(isConstructor().or(isAbstract())).and(isPublic()).and(new ElementMatcher<MethodDescription>() {
@Override
public boolean matches(MethodDescription target) {
return !delegations.get(target.getName()).isnil();
}
});
build = build.method(publicMethods).intercept(MethodDelegation.to(new PublicInterceptor(delegations)));
Unloaded unloaded = build.make();
Loaded loaded = Compatibility.get().load(unloaded);
Class c = loaded.getLoaded();
Log.debug("Created dynamic class " + c.getName() + " in " + ((System.nanoTime() - startTime) / 1000000) + "ms");
return c;
} catch (Exception e) {
Log.error("Failed to create dynamic class " + extend.getName() + " " + Arrays.toString(inherit));
throw new CubesException("Failed to make dynamic class", e);
}
}