当前位置: 首页>>代码示例>>Java>>正文


Java DynamicType.Unloaded方法代码示例

本文整理汇总了Java中net.bytebuddy.dynamic.DynamicType.Unloaded方法的典型用法代码示例。如果您正苦于以下问题:Java DynamicType.Unloaded方法的具体用法?Java DynamicType.Unloaded怎么用?Java DynamicType.Unloaded使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.bytebuddy.dynamic.DynamicType的用法示例。


在下文中一共展示了DynamicType.Unloaded方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: check

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Override
public final void check() throws Exception {
    final TypeDescription typeDescription = new TypeDescription.ForLoadedType(clazz);
    final DynamicType.Builder<?> subclass = new ByteBuddy().redefine(clazz);
    final DynamicType.Unloaded<?> make = bt
            .transitionResult(subclass, typeDescription)
            .value()
            .get()
            .make();
    final Class<?> newClazz = make.load(new AnonymousClassLoader()).getLoaded();
    assertThat(
        List.of(newClazz.getDeclaredMethods()).map(Method::getName)
    ).containsOnlyElementsOf(
        methodNames
    );
}
 
开发者ID:project-avral,项目名称:oo-atom,代码行数:17,代码来源:AssertClassToHaveCertainMethodsAfterBuilderTransition.java

示例2: testRetrieveFromArray

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Test
public void testRetrieveFromArray() throws Exception {
    DynamicType.Unloaded<RetrieveFromArray> arr = new ByteBuddy().subclass(RetrieveFromArray.class)
                    .method(ElementMatchers.isDeclaredBy(RetrieveFromArray.class))
                    .intercept(new Implementation.Compound(new LoadReferenceParamImplementation(1),
                                    new RelativeRetrieveArrayImplementation(1),
                                    new ReturnAppenderImplementation(ReturnAppender.ReturnType.INT)))
                    .make();


    Class<?> dynamicType = arr.load(RetrieveFromArray.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
                    .getLoaded();

    RetrieveFromArray test = (RetrieveFromArray) dynamicType.newInstance();
    int result = test.returnVal(0, 1);
    assertEquals(1, result);

}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:19,代码来源:RelativeRetrieveTest.java

示例3: inPlaceSet

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Test
public void inPlaceSet() throws Exception {
    DynamicType.Unloaded<SetValueInPlace> val =
                    new ByteBuddy().subclass(SetValueInPlace.class)
                                    .method(ElementMatchers.isDeclaredBy(SetValueInPlace.class))
                                    .intercept(new StackManipulationImplementation(new StackManipulation.Compound(
                                                    MethodVariableAccess.REFERENCE.loadOffset(1),
                                                    MethodVariableAccess.INTEGER.loadOffset(2),
                                                    MethodVariableAccess.INTEGER.loadOffset(3),
                                                    ArrayStackManipulation.store(), MethodReturn.VOID)))
                                    .make();

    val.saveIn(new File("target"));
    SetValueInPlace dv = val.load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER).getLoaded()
                    .newInstance();
    int[] ret = {2, 4};
    int[] assertion = {1, 4};
    dv.update(ret, 0, 1);
    assertArrayEquals(assertion, ret);
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:21,代码来源:AssignImplementationTest.java

示例4: inPlaceDivide

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Test
public void inPlaceDivide() throws Exception {
    DynamicType.Unloaded<SetValueInPlace> val = new ByteBuddy().subclass(SetValueInPlace.class)
                    .method(ElementMatchers.isDeclaredBy(SetValueInPlace.class))
                    .intercept(new StackManipulationImplementation(new StackManipulation.Compound(
                                    MethodVariableAccess.REFERENCE.loadOffset(1),
                                    MethodVariableAccess.INTEGER.loadOffset(2), Duplication.DOUBLE,
                                    ArrayStackManipulation.load(), MethodVariableAccess.INTEGER.loadOffset(3),
                                    OpStackManipulation.div(), ArrayStackManipulation.store(), MethodReturn.VOID)))
                    .make();

    val.saveIn(new File("target"));
    SetValueInPlace dv = val.load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER).getLoaded()
                    .newInstance();
    int[] ret = {2, 4};
    int[] assertion = {1, 4};
    dv.update(ret, 0, 2);
    assertArrayEquals(assertion, ret);
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:20,代码来源:AssignImplementationTest.java

示例5: testCreateAndAssign

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Test
public void testCreateAndAssign() throws Exception {
    DynamicType.Unloaded<CreateAndAssignArray> arr = new ByteBuddy().subclass(CreateAndAssignArray.class)
                    .method(ElementMatchers.isDeclaredBy(CreateAndAssignArray.class))
                    .intercept(new Implementation.Compound(new IntArrayCreation(5), new DuplicateImplementation(),
                                    new RelativeArrayAssignWithValueImplementation(0, 5),
                                    new ReturnAppenderImplementation(ReturnAppender.ReturnType.REFERENCE)))
                    .make();


    Class<?> dynamicType =
                    arr.load(CreateAndAssignArray.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
                                    .getLoaded();

    CreateAndAssignArray test = (CreateAndAssignArray) dynamicType.newInstance();
    int[] result = test.create();
    assertEquals(5, result[0]);
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:19,代码来源:TestAggregateByteCodeAppender.java

示例6: testCreateInt

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Test
public void testCreateInt() throws Exception {
    DynamicType.Unloaded<CreateAndAssignIntArray> arr = new ByteBuddy().subclass(CreateAndAssignIntArray.class)
                    .method(ElementMatchers.isDeclaredBy(CreateAndAssignIntArray.class))
                    .intercept(new Implementation.Compound(new ConstantIntImplementation(1),
                                    new StoreIntImplementation(0), new LoadIntegerImplementation(0),
                                    new ReturnAppenderImplementation(ReturnAppender.ReturnType.INT)))
                    .make();


    Class<?> dynamicType =
                    arr.load(CreateAndAssignIntArray.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
                                    .getLoaded();

    CreateAndAssignIntArray test = (CreateAndAssignIntArray) dynamicType.newInstance();
    int result = test.returnVal();
    assertEquals(1, result);

}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:20,代码来源:CreateIntTests.java

示例7: make

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Override
public DynamicType.Unloaded<T> make(TypeResolutionStrategy typeResolutionStrategy, TypePool typePool) {
    MethodRegistry.Compiled methodRegistry = constructorStrategy
            .inject(instrumentedType, this.methodRegistry)
            .prepare(applyConstructorStrategy(instrumentedType), methodGraphCompiler, typeValidation, new InstrumentableMatcher(ignoredMethods))
            .compile(SubclassImplementationTarget.Factory.SUPER_CLASS, classFileVersion);
    return TypeWriter.Default.<T>forCreation(methodRegistry,
            fieldRegistry.compile(methodRegistry.getInstrumentedType()),
            typeAttributeAppender,
            asmVisitorWrapper,
            classFileVersion,
            annotationValueFilterFactory,
            annotationRetention,
            auxiliaryTypeNamingStrategy,
            implementationContextFactory,
            typeValidation,
            typePool).make(typeResolutionStrategy.resolve());
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:19,代码来源:SubclassDynamicTypeBuilder.java

示例8: make

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Override
public DynamicType.Unloaded<T> make(TypeResolutionStrategy typeResolutionStrategy, TypePool typePool) {
    MethodRegistry.Prepared methodRegistry = this.methodRegistry.prepare(instrumentedType,
            methodGraphCompiler,
            typeValidation,
            InliningImplementationMatcher.of(ignoredMethods, originalType));
    return TypeWriter.Default.<T>forRedefinition(methodRegistry,
            fieldRegistry.compile(methodRegistry.getInstrumentedType()),
            typeAttributeAppender,
            asmVisitorWrapper,
            classFileVersion,
            annotationValueFilterFactory,
            annotationRetention,
            auxiliaryTypeNamingStrategy,
            implementationContextFactory,
            typeValidation,
            typePool,
            originalType,
            classFileLocator).make(typeResolutionStrategy.resolve());
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:21,代码来源:RedefinitionDynamicTypeBuilder.java

示例9: check

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Override
public final void check() throws Exception {
    final TypeDescription typeDescription = new TypeDescription.ForLoadedType(type);
    final DynamicType.Builder<?> subclass = new ByteBuddy().redefine(type);
    final DynamicType.Unloaded<?> make = builderTransition
            .transitionResult(subclass, typeDescription)
            .value()
            .get()
            .make();
    final Class<?> clazz = make.load(new AnonymousClassLoader()).getLoaded();
    assertThat(clazz.getAnnotation(annotation))
            .withFailMessage("Expected annotation %s is missing on class %s", annotation.getName(), clazz.getName())
            .isNotNull();
}
 
开发者ID:project-avral,项目名称:oo-atom,代码行数:15,代码来源:AssertBuilderTransitionToAnnotateAClass.java

示例10: apply

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Override
public final void apply(final ClassPath classPath, final ClassNames classNames, final Path workingDirectory) {
    try {
        final ClassFileLocator cfl = new CflsCompound(
            new CflsFromClassPath(
                classPath
            ),
            new CflsExplicit(
                ClassFileLocator.ForClassLoader.ofClassPath()
            )
        ).classFileLocator();
        final TypePool tps = TypePool.Default.of(cfl);
        for (String className : classNames.classNames()) {
            final TypePool.Resolution resolution = tps.describe(className);
            if (resolution.isResolved()) {
                final TypeDescription td = resolution.resolve();
                final DynamicType.Builder<?> builder = new ByteBuddy().redefine(td, cfl);
                final DynamicType.Unloaded<?> unloaded = task.apply(builder, td).make();
                unloaded.saveIn(workingDirectory.toFile());
            } else {
                throw new RuntimeException("Class " + className + " cannot be resolved");
            }
        }
    } catch(Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
开发者ID:project-avral,项目名称:oo-atom,代码行数:28,代码来源:ByteBuddyStage.java

示例11: generateProxy

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
public ConventionBasedTest generateProxy(ConventionBasedTest conventionBasedTest)
{
    try {
        String className = generatedClassName(conventionBasedTest);
        String methodName = generatedMethodName(conventionBasedTest);
        TestAnnotationImpl testAnnotationImpl = new TestAnnotationImpl(conventionBasedTest);

        DynamicType.Unloaded<ConventionBasedTestProxy> dynamicType = new ByteBuddy()
                .subclass(ConventionBasedTestProxy.class)
                .name(className)
                .defineMethod(methodName, void.class, ImmutableList.of(), Visibility.PUBLIC)
                .intercept(MethodCall.invoke(ConventionBasedTestProxy.class.getMethod("test")))
                .annotateMethod(testAnnotationImpl)
                .make();

        LOGGER.debug("Generating proxy class: {}.{}, annotation: {}", className, methodName, testAnnotationImpl);

        return dynamicType
                .load(getSystemClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
                .getLoaded()
                .getConstructor(ConventionBasedTest.class)
                .newInstance(conventionBasedTest);
    }
    catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
        throw new IllegalStateException("Could not create proxy for convention test: " + conventionBasedTest, e);
    }
}
 
开发者ID:prestodb,项目名称:tempto,代码行数:28,代码来源:ConventionBasedTestProxyGenerator.java

示例12: getInd2SubInstance

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
/**
 * Get an ind2sub instance
 * based on the ordering and rank
 * @param ordering the ordering
 * @param rank the rank
 * @return the ind2sub instance
 */
public static IndexMapper getInd2SubInstance(char ordering, int rank) {
    Implementation impl = ShapeMapper.getInd2Sub(ordering, rank);
    DynamicType.Unloaded<IndexMapper> c = new ByteBuddy().subclass(IndexMapper.class)
                    .method(ElementMatchers.isDeclaredBy(IndexMapper.class)).intercept(impl).make();

    Class<IndexMapper> dynamicType = (Class<IndexMapper>) c
                    .load(IndexMapper.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER).getLoaded();
    try {
        return dynamicType.newInstance();
    } catch (Exception e) {
        throw new IllegalStateException("Unable to get index mapper for rank " + rank);
    }

}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:22,代码来源:ShapeMapper.java

示例13: getOffsetMapperInstance

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
/**
 * Get an ind2sub instance
 * based on the ordering and rank
 * @param rank the rank
 * @return the ind2sub instance
 */
public static OffsetMapper getOffsetMapperInstance(int rank) {
    Implementation impl = ShapeMapper.getOffsetMapper(rank);
    DynamicType.Unloaded<OffsetMapper> c = new ByteBuddy().subclass(OffsetMapper.class)
                    .method(ElementMatchers.isDeclaredBy(OffsetMapper.class)).intercept(impl).make();

    Class<OffsetMapper> dynamicType = (Class<OffsetMapper>) c
                    .load(OffsetMapper.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER).getLoaded();
    try {
        return dynamicType.newInstance();
    } catch (Exception e) {
        throw new IllegalStateException("Unable to get index mapper for rank " + rank);
    }

}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:21,代码来源:ShapeMapper.java

示例14: proxyOnlyDeclaredMethodOf

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
protected Class<?> proxyOnlyDeclaredMethodOf(Class<?> proxyTarget) throws Exception {
    MethodDescription.InDefinedShape proxyMethod = new TypeDescription.ForLoadedType(proxyTarget)
            .getDeclaredMethods().filter(not(isConstructor())).getOnly();
    when(methodAccessorFactory.registerAccessorFor(specialMethodInvocation, MethodAccessorFactory.AccessType.DEFAULT)).thenReturn(proxyMethod);
    String auxiliaryTypeName = getClass().getName() + "$" + proxyTarget.getSimpleName() + "$Proxy";
    DynamicType dynamicType = new MethodCallProxy(specialMethodInvocation, false).make(auxiliaryTypeName,
            ClassFileVersion.ofThisVm(),
            methodAccessorFactory);
    DynamicType.Unloaded<?> unloaded = (DynamicType.Unloaded<?>) dynamicType;
    Class<?> auxiliaryType = unloaded.load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER).getLoaded();
    assertThat(auxiliaryType.getName(), is(auxiliaryTypeName));
    verify(methodAccessorFactory).registerAccessorFor(specialMethodInvocation, MethodAccessorFactory.AccessType.DEFAULT);
    verifyNoMoreInteractions(methodAccessorFactory);
    verifyZeroInteractions(specialMethodInvocation);
    assertThat(auxiliaryType.getModifiers(), is(Opcodes.ACC_SYNTHETIC));
    assertThat(Callable.class.isAssignableFrom(auxiliaryType), is(true));
    assertThat(Runnable.class.isAssignableFrom(auxiliaryType), is(true));
    assertThat(auxiliaryType.getDeclaredConstructors().length, is(1));
    assertThat(auxiliaryType.getDeclaredMethods().length, is(2));
    assertThat(auxiliaryType.getDeclaredFields().length, is(proxyMethod.getParameters().size() + (proxyMethod.isStatic() ? 0 : 1)));
    int fieldIndex = 0;
    if (!proxyMethod.isStatic()) {
        assertThat(auxiliaryType.getDeclaredFields()[fieldIndex++].getType(), CoreMatchers.<Class<?>>is(proxyTarget));
    }
    for (Class<?> parameterType : proxyTarget.getDeclaredMethods()[0].getParameterTypes()) {
        assertThat(auxiliaryType.getDeclaredFields()[fieldIndex++].getType(), CoreMatchers.<Class<?>>is(parameterType));
    }
    return auxiliaryType;
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:30,代码来源:AbstractMethodCallProxyTest.java

示例15: make

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Override
public DynamicType.Unloaded<T> make(TypeResolutionStrategy typeResolutionStrategy, TypePool typePool) {
    MethodRegistry.Prepared methodRegistry = this.methodRegistry.prepare(instrumentedType,
            methodGraphCompiler,
            typeValidation,
            InliningImplementationMatcher.of(ignoredMethods, originalType));
    MethodRebaseResolver methodRebaseResolver = MethodRebaseResolver.Default.make(methodRegistry.getInstrumentedType(),
            new HashSet<MethodDescription.Token>(originalType.getDeclaredMethods()
                    .asTokenList(is(originalType))
                    .filter(RebaseableMatcher.of(methodRegistry.getInstrumentedType(), methodRegistry.getInstrumentedMethods()))),
            classFileVersion,
            auxiliaryTypeNamingStrategy,
            methodNameTransformer);
    return TypeWriter.Default.<T>forRebasing(methodRegistry,
            fieldRegistry.compile(methodRegistry.getInstrumentedType()),
            typeAttributeAppender,
            asmVisitorWrapper,
            classFileVersion,
            annotationValueFilterFactory,
            annotationRetention,
            auxiliaryTypeNamingStrategy,
            implementationContextFactory,
            typeValidation,
            typePool,
            originalType,
            classFileLocator,
            methodRebaseResolver).make(typeResolutionStrategy.resolve());
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:29,代码来源:RebaseDynamicTypeBuilder.java


注:本文中的net.bytebuddy.dynamic.DynamicType.Unloaded方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。