當前位置: 首頁>>代碼示例>>Java>>正文


Java ReceiverTypeDefinition類代碼示例

本文整理匯總了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);
	}
}
 
開發者ID:RedTroop,項目名稱:Cubes_2,代碼行數:37,代碼來源:LuaGeneration.java

示例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);
  }
}
 
開發者ID:RedTroop,項目名稱:Cubes,代碼行數:43,代碼來源:LuaGeneration.java


注:本文中的net.bytebuddy.dynamic.DynamicType.Builder.MethodDefinition.ReceiverTypeDefinition類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。