net.bytebuddy.asm.AsmVisitorWrapper Java Examples

The following examples show how to use net.bytebuddy.asm.AsmVisitorWrapper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AllowancesByteBuddyTransformer.java    From BlockHound with Apache License 2.0 6 votes vote down vote up
@Override
public DynamicType.Builder<?> transform(
        DynamicType.Builder<?> builder,
        TypeDescription typeDescription,
        ClassLoader classLoader,
        JavaModule module
) {
    Map<String, Boolean> methods = allowances.get(typeDescription.getName());

    if (methods == null) {
        return builder;
    }

    AsmVisitorWrapper advice = Advice
            .withCustomMapping()
            .bind(new AllowedArgument.Factory(methods))
            .to(AllowAdvice.class)
            .on(method -> methods.containsKey(method.getInternalName()));

    return builder.visit(advice);
}
 
Example #2
Source File: BlockingCallsByteBuddyTransformer.java    From BlockHound with Apache License 2.0 6 votes vote down vote up
@Override
public DynamicType.Builder<?> transform(
        DynamicType.Builder<?> builder,
        TypeDescription typeDescription,
        ClassLoader classLoader,
        JavaModule module
) {
    Map<String, Set<String>> methods = blockingMethods.get(typeDescription.getInternalName());

    if (methods == null) {
        return builder;
    }

    AsmVisitorWrapper advice = Advice.withCustomMapping()
            .bind(ModifiersArgument.Factory.INSTANCE)
            .to(BlockingCallAdvice.class)
            .on(method -> {
                Set<String> descriptors = methods.get(method.getInternalName());
                return descriptors != null && descriptors.contains(method.getDescriptor());
            });

    return builder.visit(advice);
}
 
Example #3
Source File: AnnotationAppenderDefaultTest.java    From byte-buddy with Apache License 2.0 6 votes vote down vote up
private Class<?> makeTypeWithSuperClassAnnotation(Annotation annotation) throws Exception {
    when(valueFilter.isRelevant(any(AnnotationDescription.class), any(MethodDescription.InDefinedShape.class))).thenReturn(true);
    ClassWriter classWriter = new ClassWriter(AsmVisitorWrapper.NO_FLAGS);
    classWriter.visit(ClassFileVersion.ofThisVm().getMinorMajorVersion(),
            Opcodes.ACC_PUBLIC,
            BAR.replace('.', '/'),
            null,
            Type.getInternalName(Object.class),
            null);
    AnnotationVisitor annotationVisitor = classWriter.visitTypeAnnotation(TypeReference.newSuperTypeReference(-1).getValue(),
            null,
            Type.getDescriptor(annotation.annotationType()),
            true);
    when(target.visit(any(String.class), anyBoolean())).thenReturn(annotationVisitor);
    AnnotationDescription annotationDescription = AnnotationDescription.ForLoadedAnnotation.of(annotation);
    annotationAppender.append(annotationDescription, valueFilter);
    classWriter.visitEnd();
    Class<?> bar = new ByteArrayClassLoader(getClass().getClassLoader(), Collections.singletonMap(BAR, classWriter.toByteArray())).loadClass(BAR);
    assertThat(bar.getName(), is(BAR));
    assertThat(bar.getSuperclass(), CoreMatchers.<Class<?>>is(Object.class));
    return bar;
}
 
Example #4
Source File: AnnotationAppenderDefaultTest.java    From byte-buddy with Apache License 2.0 6 votes vote down vote up
private Class<?> makeTypeWithAnnotation(Annotation annotation) throws Exception {
    when(valueFilter.isRelevant(any(AnnotationDescription.class), any(MethodDescription.InDefinedShape.class))).thenReturn(true);
    ClassWriter classWriter = new ClassWriter(AsmVisitorWrapper.NO_FLAGS);
    classWriter.visit(ClassFileVersion.ofThisVm().getMinorMajorVersion(),
            Opcodes.ACC_PUBLIC,
            BAR.replace('.', '/'),
            null,
            Type.getInternalName(Object.class),
            null);
    AnnotationVisitor annotationVisitor = classWriter.visitAnnotation(Type.getDescriptor(annotation.annotationType()), true);
    when(target.visit(any(String.class), anyBoolean())).thenReturn(annotationVisitor);
    AnnotationDescription annotationDescription = AnnotationDescription.ForLoadedAnnotation.of(annotation);
    annotationAppender.append(annotationDescription, valueFilter);
    classWriter.visitEnd();
    Class<?> bar = new ByteArrayClassLoader(getClass().getClassLoader(), Collections.singletonMap(BAR, classWriter.toByteArray())).loadClass(BAR);
    assertThat(bar.getName(), is(BAR));
    assertThat(bar.getSuperclass(), CoreMatchers.<Class<?>>is(Object.class));
    return bar;
}
 
Example #5
Source File: DecoratingDynamicTypeBuilder.java    From byte-buddy with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public DynamicType.Builder<T> visit(AsmVisitorWrapper asmVisitorWrapper) {
    return new DecoratingDynamicTypeBuilder<T>(instrumentedType,
            typeAttributeAppender,
            new AsmVisitorWrapper.Compound(this.asmVisitorWrapper, asmVisitorWrapper),
            classFileVersion,
            auxiliaryTypeNamingStrategy,
            annotationValueFilterFactory,
            annotationRetention,
            implementationContextFactory,
            methodGraphCompiler,
            typeValidation,
            classWriterStrategy,
            ignoredMethods,
            auxiliaryTypes,
            classFileLocator);
}
 
Example #6
Source File: AbstractInliningDynamicTypeBuilder.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an inlining dynamic type builder.
 *
 * @param instrumentedType             An instrumented type representing the subclass.
 * @param fieldRegistry                The field pool to use.
 * @param methodRegistry               The method pool to use.
 * @param recordComponentRegistry      The record component pool to use.
 * @param typeAttributeAppender        The type attribute appender to apply onto the instrumented type.
 * @param asmVisitorWrapper            The ASM visitor wrapper to apply onto the class writer.
 * @param classFileVersion             The class file version to use for types that are not based on an existing class file.
 * @param auxiliaryTypeNamingStrategy  The naming strategy to use for naming auxiliary types.
 * @param annotationValueFilterFactory The annotation value filter factory to use.
 * @param annotationRetention          The annotation retention strategy to use.
 * @param implementationContextFactory The implementation context factory to use.
 * @param methodGraphCompiler          The method graph compiler to use.
 * @param typeValidation               Determines if a type should be explicitly validated.
 * @param visibilityBridgeStrategy     The visibility bridge strategy to apply.
 * @param classWriterStrategy          The class writer strategy to use.
 * @param ignoredMethods               A matcher for identifying methods that should be excluded from instrumentation.
 * @param auxiliaryTypes               A list of explicitly defined auxiliary types.
 * @param originalType                 The original type that is being redefined or rebased.
 * @param classFileLocator             The class file locator for locating the original type's class file.
 */
protected AbstractInliningDynamicTypeBuilder(InstrumentedType.WithFlexibleName instrumentedType,
                                             FieldRegistry fieldRegistry,
                                             MethodRegistry methodRegistry,
                                             RecordComponentRegistry recordComponentRegistry,
                                             TypeAttributeAppender typeAttributeAppender,
                                             AsmVisitorWrapper asmVisitorWrapper,
                                             ClassFileVersion classFileVersion,
                                             AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy,
                                             AnnotationValueFilter.Factory annotationValueFilterFactory,
                                             AnnotationRetention annotationRetention,
                                             Implementation.Context.Factory implementationContextFactory,
                                             MethodGraph.Compiler methodGraphCompiler,
                                             TypeValidation typeValidation,
                                             VisibilityBridgeStrategy visibilityBridgeStrategy,
                                             ClassWriterStrategy classWriterStrategy,
                                             LatentMatcher<? super MethodDescription> ignoredMethods,
                                             List<? extends DynamicType> auxiliaryTypes,
                                             TypeDescription originalType,
                                             ClassFileLocator classFileLocator) {
    super(instrumentedType,
            fieldRegistry,
            methodRegistry,
            recordComponentRegistry,
            typeAttributeAppender,
            asmVisitorWrapper,
            classFileVersion,
            auxiliaryTypeNamingStrategy,
            annotationValueFilterFactory,
            annotationRetention,
            implementationContextFactory,
            methodGraphCompiler,
            typeValidation,
            visibilityBridgeStrategy,
            classWriterStrategy,
            ignoredMethods,
            auxiliaryTypes);
    this.originalType = originalType;
    this.classFileLocator = classFileLocator;
}
 
Example #7
Source File: TypeWriterDefaultTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testTypeInitializerOnRebasedInterfaceWithFrameExpansion() throws Exception {
    assertThat(new ByteBuddy()
            .makeInterface()
            .visit(new AsmVisitorWrapper.ForDeclaredMethods().readerFlags(ClassReader.EXPAND_FRAMES))
            .invokable(isTypeInitializer())
            .intercept(StubMethod.INSTANCE)
            .make(), notNullValue(DynamicType.class));
}
 
Example #8
Source File: TypeWriterDefaultTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testTypeInitializerOnRebasedInterfaceWithFrameComputation() throws Exception {
    assertThat(new ByteBuddy()
            .makeInterface()
            .visit(new AsmVisitorWrapper.ForDeclaredMethods().writerFlags(ClassWriter.COMPUTE_FRAMES))
            .invokable(isTypeInitializer())
            .intercept(StubMethod.INSTANCE)
            .make(), notNullValue(DynamicType.class));
}
 
Example #9
Source File: DecoratingDynamicTypeBuilderTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testDecorationWithoutAnnotationRetention() throws Exception {
    Object instance = new ByteBuddy()
            .with(AnnotationRetention.DISABLED)
            .decorate(Foo.class)
            .annotateType(AnnotationDescription.Builder.ofType(Qux.class).build())
            .ignoreAlso(new LatentMatcher.Resolved<MethodDescription>(none()))
            .visit(new AsmVisitorWrapper.ForDeclaredMethods()
                    .method(named(FOO), new AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper() {
                        public MethodVisitor wrap(TypeDescription instrumentedType,
                                                  MethodDescription instrumentedMethod,
                                                  MethodVisitor methodVisitor,
                                                  Implementation.Context implementationContext,
                                                  TypePool typePool,
                                                  int writerFlags,
                                                  int readerFlags) {
                            return new MethodVisitor(OpenedClassReader.ASM_API, methodVisitor) {
                                @Override
                                public void visitLdcInsn(Object value) {
                                    if (FOO.equals(value)) {
                                        value = BAR;
                                    }
                                    super.visitLdcInsn(value);
                                }
                            };
                        }
                    }))
            .make()
            .load(getClass().getClassLoader(), ClassLoadingStrategy.Default.CHILD_FIRST)
            .getLoaded()
            .getConstructor()
            .newInstance();
    assertThat(instance.getClass().getMethod(FOO).invoke(instance), is((Object) BAR));
    assertThat(instance.getClass().isAnnotationPresent(Bar.class), is(true));
    assertThat(instance.getClass().isAnnotationPresent(Qux.class), is(true));
}
 
Example #10
Source File: DecoratingDynamicTypeBuilderTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testDecorationNonVirtualMember() throws Exception {
    Object instance = new ByteBuddy()
            .decorate(Foo.class)
            .annotateType(AnnotationDescription.Builder.ofType(Qux.class).build())
            .ignoreAlso(new LatentMatcher.Resolved<MethodDescription>(none()))
            .visit(new AsmVisitorWrapper.ForDeclaredMethods().method(named(BAR), new AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper() {
                public MethodVisitor wrap(TypeDescription instrumentedType,
                                          MethodDescription instrumentedMethod,
                                          MethodVisitor methodVisitor,
                                          Implementation.Context implementationContext,
                                          TypePool typePool,
                                          int writerFlags,
                                          int readerFlags) {
                    return new MethodVisitor(OpenedClassReader.ASM_API, methodVisitor) {
                        @Override
                        public void visitLdcInsn(Object value) {
                            if (FOO.equals(value)) {
                                value = BAR;
                            }
                            super.visitLdcInsn(value);
                        }
                    };
                }
            }))
            .make()
            .load(getClass().getClassLoader(), ClassLoadingStrategy.Default.CHILD_FIRST)
            .getLoaded()
            .getConstructor()
            .newInstance();
    assertThat(instance.getClass().getMethod(BAR).invoke(null), is((Object) BAR));
    assertThat(instance.getClass().isAnnotationPresent(Bar.class), is(true));
    assertThat(instance.getClass().isAnnotationPresent(Qux.class), is(true));
}
 
Example #11
Source File: DecoratingDynamicTypeBuilderTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testDecoration() throws Exception {
    Object instance = new ByteBuddy()
            .decorate(Foo.class)
            .annotateType(AnnotationDescription.Builder.ofType(Qux.class).build())
            .ignoreAlso(new LatentMatcher.Resolved<MethodDescription>(none()))
            .visit(new AsmVisitorWrapper.ForDeclaredMethods().method(named(FOO), new AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper() {
                public MethodVisitor wrap(TypeDescription instrumentedType,
                                          MethodDescription instrumentedMethod,
                                          MethodVisitor methodVisitor,
                                          Implementation.Context implementationContext,
                                          TypePool typePool,
                                          int writerFlags,
                                          int readerFlags) {
                    return new MethodVisitor(OpenedClassReader.ASM_API, methodVisitor) {
                        public void visitLdcInsn(Object value) {
                            if (FOO.equals(value)) {
                                value = BAR;
                            }
                            super.visitLdcInsn(value);
                        }
                    };
                }
            }))
            .make()
            .load(getClass().getClassLoader(), ClassLoadingStrategy.Default.CHILD_FIRST)
            .getLoaded()
            .getConstructor()
            .newInstance();
    assertThat(instance.getClass().getMethod(FOO).invoke(instance), is((Object) BAR));
    assertThat(instance.getClass().isAnnotationPresent(Bar.class), is(true));
    assertThat(instance.getClass().isAnnotationPresent(Qux.class), is(true));
}
 
Example #12
Source File: RedefinitionDynamicTypeBuilder.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Override
protected DynamicType.Builder<T> materialize(InstrumentedType.WithFlexibleName instrumentedType,
                                             FieldRegistry fieldRegistry,
                                             MethodRegistry methodRegistry,
                                             RecordComponentRegistry recordComponentRegistry,
                                             TypeAttributeAppender typeAttributeAppender,
                                             AsmVisitorWrapper asmVisitorWrapper,
                                             ClassFileVersion classFileVersion,
                                             AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy,
                                             AnnotationValueFilter.Factory annotationValueFilterFactory,
                                             AnnotationRetention annotationRetention,
                                             Implementation.Context.Factory implementationContextFactory,
                                             MethodGraph.Compiler methodGraphCompiler,
                                             TypeValidation typeValidation,
                                             VisibilityBridgeStrategy visibilityBridgeStrategy,
                                             ClassWriterStrategy classWriterStrategy,
                                             LatentMatcher<? super MethodDescription> ignoredMethods,
                                             List<? extends DynamicType> auxiliaryTypes) {
    return new RedefinitionDynamicTypeBuilder<T>(instrumentedType,
            fieldRegistry,
            methodRegistry,
            recordComponentRegistry,
            typeAttributeAppender,
            asmVisitorWrapper,
            classFileVersion,
            auxiliaryTypeNamingStrategy,
            annotationValueFilterFactory,
            annotationRetention,
            implementationContextFactory,
            methodGraphCompiler,
            typeValidation,
            visibilityBridgeStrategy,
            classWriterStrategy,
            ignoredMethods,
            auxiliaryTypes,
            originalType,
            classFileLocator);
}
 
Example #13
Source File: RedefinitionDynamicTypeBuilder.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a redefinition dynamic type builder.
 *
 * @param instrumentedType             An instrumented type representing the subclass.
 * @param fieldRegistry                The field pool to use.
 * @param methodRegistry               The method pool to use.
 * @param recordComponentRegistry      The record component pool to use.
 * @param typeAttributeAppender        The type attribute appender to apply onto the instrumented type.
 * @param asmVisitorWrapper            The ASM visitor wrapper to apply onto the class writer.
 * @param classFileVersion             The class file version to use for types that are not based on an existing class file.
 * @param auxiliaryTypeNamingStrategy  The naming strategy to use for naming auxiliary types.
 * @param annotationValueFilterFactory The annotation value filter factory to use.
 * @param annotationRetention          The annotation retention strategy to use.
 * @param implementationContextFactory The implementation context factory to use.
 * @param methodGraphCompiler          The method graph compiler to use.
 * @param typeValidation               Determines if a type should be explicitly validated.
 * @param visibilityBridgeStrategy     The visibility bridge strategy to apply.
 * @param classWriterStrategy          The class writer strategy to use.
 * @param ignoredMethods               A matcher for identifying methods that should be excluded from instrumentation.
 * @param auxiliaryTypes               A list of explicitly required auxiliary types.
 * @param originalType                 The original type that is being redefined or rebased.
 * @param classFileLocator             The class file locator for locating the original type's class file.
 */
protected RedefinitionDynamicTypeBuilder(InstrumentedType.WithFlexibleName instrumentedType,
                                         FieldRegistry fieldRegistry,
                                         MethodRegistry methodRegistry,
                                         RecordComponentRegistry recordComponentRegistry,
                                         TypeAttributeAppender typeAttributeAppender,
                                         AsmVisitorWrapper asmVisitorWrapper,
                                         ClassFileVersion classFileVersion,
                                         AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy,
                                         AnnotationValueFilter.Factory annotationValueFilterFactory,
                                         AnnotationRetention annotationRetention,
                                         Implementation.Context.Factory implementationContextFactory,
                                         MethodGraph.Compiler methodGraphCompiler,
                                         TypeValidation typeValidation,
                                         VisibilityBridgeStrategy visibilityBridgeStrategy,
                                         ClassWriterStrategy classWriterStrategy,
                                         LatentMatcher<? super MethodDescription> ignoredMethods,
                                         List<? extends DynamicType> auxiliaryTypes,
                                         TypeDescription originalType,
                                         ClassFileLocator classFileLocator) {
    super(instrumentedType,
            fieldRegistry,
            methodRegistry,
            recordComponentRegistry,
            typeAttributeAppender,
            asmVisitorWrapper,
            classFileVersion,
            auxiliaryTypeNamingStrategy,
            annotationValueFilterFactory,
            annotationRetention,
            implementationContextFactory,
            methodGraphCompiler,
            typeValidation,
            visibilityBridgeStrategy,
            classWriterStrategy,
            ignoredMethods,
            auxiliaryTypes,
            originalType,
            classFileLocator);
}
 
Example #14
Source File: RedefinitionDynamicTypeBuilder.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a redefinition dynamic type builder.
 *
 * @param instrumentedType             An instrumented type representing the subclass.
 * @param classFileVersion             The class file version to use for types that are not based on an existing class file.
 * @param auxiliaryTypeNamingStrategy  The naming strategy to use for naming auxiliary types.
 * @param annotationValueFilterFactory The annotation value filter factory to use.
 * @param annotationRetention          The annotation retention strategy to use.
 * @param implementationContextFactory The implementation context factory to use.
 * @param methodGraphCompiler          The method graph compiler to use.
 * @param typeValidation               Determines if a type should be explicitly validated.
 * @param visibilityBridgeStrategy     The visibility bridge strategy to apply.
 * @param classWriterStrategy          The class writer strategy to use.
 * @param ignoredMethods               A matcher for identifying methods that should be excluded from instrumentation.
 * @param originalType                 The original type that is being redefined or rebased.
 * @param classFileLocator             The class file locator for locating the original type's class file.
 */
public RedefinitionDynamicTypeBuilder(InstrumentedType.WithFlexibleName instrumentedType,
                                      ClassFileVersion classFileVersion,
                                      AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy,
                                      AnnotationValueFilter.Factory annotationValueFilterFactory,
                                      AnnotationRetention annotationRetention,
                                      Implementation.Context.Factory implementationContextFactory,
                                      MethodGraph.Compiler methodGraphCompiler,
                                      TypeValidation typeValidation,
                                      VisibilityBridgeStrategy visibilityBridgeStrategy,
                                      ClassWriterStrategy classWriterStrategy,
                                      LatentMatcher<? super MethodDescription> ignoredMethods,
                                      TypeDescription originalType,
                                      ClassFileLocator classFileLocator) {
    this(instrumentedType,
            new FieldRegistry.Default(),
            new MethodRegistry.Default(),
            new RecordComponentRegistry.Default(),
            annotationRetention.isEnabled()
                    ? new TypeAttributeAppender.ForInstrumentedType.Differentiating(originalType)
                    : TypeAttributeAppender.ForInstrumentedType.INSTANCE,
            AsmVisitorWrapper.NoOp.INSTANCE,
            classFileVersion,
            auxiliaryTypeNamingStrategy,
            annotationValueFilterFactory,
            annotationRetention,
            implementationContextFactory,
            methodGraphCompiler,
            typeValidation,
            visibilityBridgeStrategy,
            classWriterStrategy,
            ignoredMethods,
            Collections.<DynamicType>emptyList(),
            originalType,
            classFileLocator);
}
 
Example #15
Source File: ClassFileExtraction.java    From garmadon with Apache License 2.0 5 votes vote down vote up
public static byte[] extract(Class<?> type, AsmVisitorWrapper asmVisitorWrapper) throws IOException {
    ClassReader classReader = new ClassReader(type.getName());
    ClassWriter classWriter = new ClassWriter(classReader, AsmVisitorWrapper.NO_FLAGS);
    classReader.accept(asmVisitorWrapper.wrap(new TypeDescription.ForLoadedType(type),
            classWriter,
            new IllegalContext(),
            TypePool.Empty.INSTANCE,
            new FieldList.Empty<FieldDescription.InDefinedShape>(),
            new MethodList.Empty<MethodDescription>(),
            AsmVisitorWrapper.NO_FLAGS,
            AsmVisitorWrapper.NO_FLAGS), AsmVisitorWrapper.NO_FLAGS);
    return classWriter.toByteArray();
}
 
Example #16
Source File: RebaseDynamicTypeBuilder.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Override
protected DynamicType.Builder<T> materialize(InstrumentedType.WithFlexibleName instrumentedType,
                                             FieldRegistry fieldRegistry,
                                             MethodRegistry methodRegistry,
                                             RecordComponentRegistry recordComponentRegistry,
                                             TypeAttributeAppender typeAttributeAppender,
                                             AsmVisitorWrapper asmVisitorWrapper,
                                             ClassFileVersion classFileVersion,
                                             AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy,
                                             AnnotationValueFilter.Factory annotationValueFilterFactory,
                                             AnnotationRetention annotationRetention,
                                             Implementation.Context.Factory implementationContextFactory,
                                             MethodGraph.Compiler methodGraphCompiler,
                                             TypeValidation typeValidation,
                                             VisibilityBridgeStrategy visibilityBridgeStrategy,
                                             ClassWriterStrategy classWriterStrategy,
                                             LatentMatcher<? super MethodDescription> ignoredMethods,
                                             List<? extends DynamicType> auxiliaryTypes) {
    return new RebaseDynamicTypeBuilder<T>(instrumentedType,
            fieldRegistry,
            methodRegistry,
            recordComponentRegistry,
            typeAttributeAppender,
            asmVisitorWrapper,
            classFileVersion,
            auxiliaryTypeNamingStrategy,
            annotationValueFilterFactory,
            annotationRetention,
            implementationContextFactory,
            methodGraphCompiler,
            typeValidation,
            visibilityBridgeStrategy,
            classWriterStrategy,
            ignoredMethods,
            auxiliaryTypes,
            originalType,
            classFileLocator,
            methodNameTransformer);
}
 
Example #17
Source File: RebaseDynamicTypeBuilder.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a rebase dynamic type builder.
 *
 * @param instrumentedType             An instrumented type representing the subclass.
 * @param classFileVersion             The class file version to use for types that are not based on an existing class file.
 * @param auxiliaryTypeNamingStrategy  The naming strategy to use for naming auxiliary types.
 * @param annotationValueFilterFactory The annotation value filter factory to use.
 * @param annotationRetention          The annotation retention strategy to use.
 * @param implementationContextFactory The implementation context factory to use.
 * @param methodGraphCompiler          The method graph compiler to use.
 * @param typeValidation               Determines if a type should be explicitly validated.
 * @param visibilityBridgeStrategy     The visibility bridge strategy to apply.
 * @param classWriterStrategy          The class writer strategy to use.
 * @param ignoredMethods               A matcher for identifying methods that should be excluded from instrumentation.
 * @param originalType                 The original type that is being redefined or rebased.
 * @param classFileLocator             The class file locator for locating the original type's class file.
 * @param methodNameTransformer        The method rebase resolver to use for determining the name of a rebased method.
 */
public RebaseDynamicTypeBuilder(InstrumentedType.WithFlexibleName instrumentedType,
                                ClassFileVersion classFileVersion,
                                AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy,
                                AnnotationValueFilter.Factory annotationValueFilterFactory,
                                AnnotationRetention annotationRetention,
                                Implementation.Context.Factory implementationContextFactory,
                                MethodGraph.Compiler methodGraphCompiler,
                                TypeValidation typeValidation,
                                VisibilityBridgeStrategy visibilityBridgeStrategy,
                                ClassWriterStrategy classWriterStrategy,
                                LatentMatcher<? super MethodDescription> ignoredMethods,
                                TypeDescription originalType,
                                ClassFileLocator classFileLocator,
                                MethodNameTransformer methodNameTransformer) {
    this(instrumentedType,
            new FieldRegistry.Default(),
            new MethodRegistry.Default(),
            new RecordComponentRegistry.Default(),
            annotationRetention.isEnabled()
                    ? new TypeAttributeAppender.ForInstrumentedType.Differentiating(originalType)
                    : TypeAttributeAppender.ForInstrumentedType.INSTANCE,
            AsmVisitorWrapper.NoOp.INSTANCE,
            classFileVersion,
            auxiliaryTypeNamingStrategy,
            annotationValueFilterFactory,
            annotationRetention,
            implementationContextFactory,
            methodGraphCompiler,
            typeValidation,
            visibilityBridgeStrategy,
            classWriterStrategy,
            ignoredMethods,
            Collections.<DynamicType>emptyList(),
            originalType,
            classFileLocator,
            methodNameTransformer);
}
 
Example #18
Source File: DecoratingDynamicTypeBuilder.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new decorating dynamic type builder.
 *
 * @param instrumentedType             The instrumented type to decorate.
 * @param typeAttributeAppender        The type attribute appender to apply onto the instrumented type.
 * @param asmVisitorWrapper            The ASM visitor wrapper to apply onto the class writer.
 * @param classFileVersion             The class file version to define auxiliary types in.
 * @param auxiliaryTypeNamingStrategy  The naming strategy for auxiliary types to apply.
 * @param annotationValueFilterFactory The annotation value filter factory to apply.
 * @param annotationRetention          The annotation retention to apply.
 * @param implementationContextFactory The implementation context factory to apply.
 * @param methodGraphCompiler          The method graph compiler to use.
 * @param typeValidation               Determines if a type should be explicitly validated.
 * @param classWriterStrategy          The class writer strategy to use.
 * @param ignoredMethods               A matcher for identifying methods that should be excluded from instrumentation.
 * @param auxiliaryTypes               A list of explicitly required auxiliary types.
 * @param classFileLocator             The class file locator for locating the original type's class file.
 */
protected DecoratingDynamicTypeBuilder(TypeDescription instrumentedType,
                                       TypeAttributeAppender typeAttributeAppender,
                                       AsmVisitorWrapper asmVisitorWrapper,
                                       ClassFileVersion classFileVersion,
                                       AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy,
                                       AnnotationValueFilter.Factory annotationValueFilterFactory,
                                       AnnotationRetention annotationRetention,
                                       Implementation.Context.Factory implementationContextFactory,
                                       MethodGraph.Compiler methodGraphCompiler,
                                       TypeValidation typeValidation,
                                       ClassWriterStrategy classWriterStrategy,
                                       LatentMatcher<? super MethodDescription> ignoredMethods,
                                       List<DynamicType> auxiliaryTypes,
                                       ClassFileLocator classFileLocator) {
    this.instrumentedType = instrumentedType;
    this.typeAttributeAppender = typeAttributeAppender;
    this.asmVisitorWrapper = asmVisitorWrapper;
    this.classFileVersion = classFileVersion;
    this.auxiliaryTypeNamingStrategy = auxiliaryTypeNamingStrategy;
    this.annotationValueFilterFactory = annotationValueFilterFactory;
    this.annotationRetention = annotationRetention;
    this.implementationContextFactory = implementationContextFactory;
    this.methodGraphCompiler = methodGraphCompiler;
    this.typeValidation = typeValidation;
    this.classWriterStrategy = classWriterStrategy;
    this.ignoredMethods = ignoredMethods;
    this.auxiliaryTypes = auxiliaryTypes;
    this.classFileLocator = classFileLocator;
}
 
Example #19
Source File: DecoratingDynamicTypeBuilder.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new decorating dynamic type builder.
 *
 * @param instrumentedType             The instrumented type to decorate.
 * @param classFileVersion             The class file version to define auxiliary types in.
 * @param auxiliaryTypeNamingStrategy  The naming strategy for auxiliary types to apply.
 * @param annotationValueFilterFactory The annotation value filter factory to apply.
 * @param annotationRetention          The annotation retention to apply.
 * @param implementationContextFactory The implementation context factory to apply.
 * @param methodGraphCompiler          The method graph compiler to use.
 * @param typeValidation               Determines if a type should be explicitly validated.
 * @param classWriterStrategy          The class writer strategy to use.
 * @param ignoredMethods               A matcher for identifying methods that should be excluded from instrumentation.
 * @param classFileLocator             The class file locator for locating the original type's class file.
 */
public DecoratingDynamicTypeBuilder(TypeDescription instrumentedType,
                                    ClassFileVersion classFileVersion,
                                    AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy,
                                    AnnotationValueFilter.Factory annotationValueFilterFactory,
                                    AnnotationRetention annotationRetention,
                                    Implementation.Context.Factory implementationContextFactory,
                                    MethodGraph.Compiler methodGraphCompiler,
                                    TypeValidation typeValidation,
                                    ClassWriterStrategy classWriterStrategy,
                                    LatentMatcher<? super MethodDescription> ignoredMethods,
                                    ClassFileLocator classFileLocator) {
    this(instrumentedType,
            annotationRetention.isEnabled()
                    ? new TypeAttributeAppender.ForInstrumentedType.Differentiating(instrumentedType)
                    : TypeAttributeAppender.ForInstrumentedType.INSTANCE,
            AsmVisitorWrapper.NoOp.INSTANCE,
            classFileVersion,
            auxiliaryTypeNamingStrategy,
            annotationValueFilterFactory,
            annotationRetention,
            implementationContextFactory,
            methodGraphCompiler,
            typeValidation,
            classWriterStrategy,
            ignoredMethods,
            Collections.<DynamicType>emptyList(),
            classFileLocator);
}
 
Example #20
Source File: SubclassDynamicTypeBuilder.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Override
protected DynamicType.Builder<T> materialize(InstrumentedType.WithFlexibleName instrumentedType,
                                             FieldRegistry fieldRegistry,
                                             MethodRegistry methodRegistry,
                                             RecordComponentRegistry recordComponentRegistry,
                                             TypeAttributeAppender typeAttributeAppender,
                                             AsmVisitorWrapper asmVisitorWrapper,
                                             ClassFileVersion classFileVersion,
                                             AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy,
                                             AnnotationValueFilter.Factory annotationValueFilterFactory,
                                             AnnotationRetention annotationRetention,
                                             Implementation.Context.Factory implementationContextFactory,
                                             MethodGraph.Compiler methodGraphCompiler,
                                             TypeValidation typeValidation,
                                             VisibilityBridgeStrategy visibilityBridgeStrategy,
                                             ClassWriterStrategy classWriterStrategy,
                                             LatentMatcher<? super MethodDescription> ignoredMethods,
                                             List<? extends DynamicType> auxiliaryTypes) {
    return new SubclassDynamicTypeBuilder<T>(instrumentedType,
            fieldRegistry,
            methodRegistry,
            recordComponentRegistry,
            typeAttributeAppender,
            asmVisitorWrapper,
            classFileVersion,
            auxiliaryTypeNamingStrategy,
            annotationValueFilterFactory,
            annotationRetention,
            implementationContextFactory,
            methodGraphCompiler,
            typeValidation,
            visibilityBridgeStrategy,
            classWriterStrategy,
            ignoredMethods,
            auxiliaryTypes,
            constructorStrategy);
}
 
Example #21
Source File: SubclassDynamicTypeBuilder.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new type builder for creating a subclass.
 *
 * @param instrumentedType             An instrumented type representing the subclass.
 * @param fieldRegistry                The field registry to use.
 * @param methodRegistry               The method registry to use.
 * @param recordComponentRegistry      The record component registry to use.
 * @param typeAttributeAppender        The type attribute appender to apply onto the instrumented type.
 * @param asmVisitorWrapper            The ASM visitor wrapper to apply onto the class writer.
 * @param classFileVersion             The class file version to use for types that are not based on an existing class file.
 * @param auxiliaryTypeNamingStrategy  The naming strategy to use for naming auxiliary types.
 * @param annotationValueFilterFactory The annotation value filter factory to use.
 * @param annotationRetention          The annotation retention strategy to use.
 * @param implementationContextFactory The implementation context factory to use.
 * @param methodGraphCompiler          The method graph compiler to use.
 * @param typeValidation               Determines if a type should be explicitly validated.
 * @param visibilityBridgeStrategy     The visibility bridge strategy to apply.
 * @param classWriterStrategy          The class writer strategy to use.
 * @param ignoredMethods               A matcher for identifying methods that should be excluded from instrumentation.
 * @param constructorStrategy          The constructor strategy to apply onto the instrumented type.
 * @param auxiliaryTypes               A list of explicitly required auxiliary types.
 */
protected SubclassDynamicTypeBuilder(InstrumentedType.WithFlexibleName instrumentedType,
                                     FieldRegistry fieldRegistry,
                                     MethodRegistry methodRegistry,
                                     RecordComponentRegistry recordComponentRegistry,
                                     TypeAttributeAppender typeAttributeAppender,
                                     AsmVisitorWrapper asmVisitorWrapper,
                                     ClassFileVersion classFileVersion,
                                     AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy,
                                     AnnotationValueFilter.Factory annotationValueFilterFactory,
                                     AnnotationRetention annotationRetention,
                                     Implementation.Context.Factory implementationContextFactory,
                                     MethodGraph.Compiler methodGraphCompiler,
                                     TypeValidation typeValidation,
                                     VisibilityBridgeStrategy visibilityBridgeStrategy,
                                     ClassWriterStrategy classWriterStrategy,
                                     LatentMatcher<? super MethodDescription> ignoredMethods,
                                     List<? extends DynamicType> auxiliaryTypes,
                                     ConstructorStrategy constructorStrategy) {
    super(instrumentedType,
            fieldRegistry,
            methodRegistry,
            recordComponentRegistry,
            typeAttributeAppender,
            asmVisitorWrapper,
            classFileVersion,
            auxiliaryTypeNamingStrategy,
            annotationValueFilterFactory,
            annotationRetention,
            implementationContextFactory,
            methodGraphCompiler,
            typeValidation,
            visibilityBridgeStrategy,
            classWriterStrategy,
            ignoredMethods,
            auxiliaryTypes);
    this.constructorStrategy = constructorStrategy;
}
 
Example #22
Source File: SubclassDynamicTypeBuilder.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new type builder for creating a subclass.
 *
 * @param instrumentedType             An instrumented type representing the subclass.
 * @param classFileVersion             The class file version to use for types that are not based on an existing class file.
 * @param auxiliaryTypeNamingStrategy  The naming strategy to use for naming auxiliary types.
 * @param annotationValueFilterFactory The annotation value filter factory to use.
 * @param annotationRetention          The annotation retention strategy to use.
 * @param implementationContextFactory The implementation context factory to use.
 * @param methodGraphCompiler          The method graph compiler to use.
 * @param typeValidation               Determines if a type should be explicitly validated.
 * @param visibilityBridgeStrategy     The visibility bridge strategy to apply.
 * @param classWriterStrategy          The class writer strategy to use.
 * @param ignoredMethods               A matcher for identifying methods that should be excluded from instrumentation.
 * @param constructorStrategy          The constructor strategy to apply onto the instrumented type.
 */
public SubclassDynamicTypeBuilder(InstrumentedType.WithFlexibleName instrumentedType,
                                  ClassFileVersion classFileVersion,
                                  AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy,
                                  AnnotationValueFilter.Factory annotationValueFilterFactory,
                                  AnnotationRetention annotationRetention,
                                  Implementation.Context.Factory implementationContextFactory,
                                  MethodGraph.Compiler methodGraphCompiler,
                                  TypeValidation typeValidation,
                                  VisibilityBridgeStrategy visibilityBridgeStrategy,
                                  ClassWriterStrategy classWriterStrategy,
                                  LatentMatcher<? super MethodDescription> ignoredMethods,
                                  ConstructorStrategy constructorStrategy) {
    this(instrumentedType,
            new FieldRegistry.Default(),
            new MethodRegistry.Default(),
            new RecordComponentRegistry.Default(),
            TypeAttributeAppender.ForInstrumentedType.INSTANCE,
            AsmVisitorWrapper.NoOp.INSTANCE,
            classFileVersion,
            auxiliaryTypeNamingStrategy,
            annotationValueFilterFactory,
            annotationRetention,
            implementationContextFactory,
            methodGraphCompiler,
            typeValidation,
            visibilityBridgeStrategy,
            classWriterStrategy,
            ignoredMethods,
            Collections.<DynamicType>emptyList(),
            constructorStrategy);
}
 
Example #23
Source File: RebaseDynamicTypeBuilder.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a rebase dynamic type builder.
 *
 * @param instrumentedType             An instrumented type representing the subclass.
 * @param fieldRegistry                The field pool to use.
 * @param methodRegistry               The method pool to use.
 * @param recordComponentRegistry      The record component pool to use.
 * @param typeAttributeAppender        The type attribute appender to apply onto the instrumented type.
 * @param asmVisitorWrapper            The ASM visitor wrapper to apply onto the class writer.
 * @param classFileVersion             The class file version to use for types that are not based on an existing class file.
 * @param auxiliaryTypeNamingStrategy  The naming strategy to use for naming auxiliary types.
 * @param annotationValueFilterFactory The annotation value filter factory to use.
 * @param annotationRetention          The annotation retention strategy to use.
 * @param implementationContextFactory The implementation context factory to use.
 * @param methodGraphCompiler          The method graph compiler to use.
 * @param typeValidation               Determines if a type should be explicitly validated.
 * @param visibilityBridgeStrategy     The visibility bridge strategy to apply.
 * @param classWriterStrategy          The class writer strategy to use.
 * @param ignoredMethods               A matcher for identifying methods that should be excluded from instrumentation.
 * @param auxiliaryTypes               A list of explicitly required auxiliary types.
 * @param originalType                 The original type that is being redefined or rebased.
 * @param classFileLocator             The class file locator for locating the original type's class file.
 * @param methodNameTransformer        The method rebase resolver to use for determining the name of a rebased method.
 */
protected RebaseDynamicTypeBuilder(InstrumentedType.WithFlexibleName instrumentedType,
                                   FieldRegistry fieldRegistry,
                                   MethodRegistry methodRegistry,
                                   RecordComponentRegistry recordComponentRegistry,
                                   TypeAttributeAppender typeAttributeAppender,
                                   AsmVisitorWrapper asmVisitorWrapper,
                                   ClassFileVersion classFileVersion,
                                   AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy,
                                   AnnotationValueFilter.Factory annotationValueFilterFactory,
                                   AnnotationRetention annotationRetention,
                                   Implementation.Context.Factory implementationContextFactory,
                                   MethodGraph.Compiler methodGraphCompiler,
                                   TypeValidation typeValidation,
                                   VisibilityBridgeStrategy visibilityBridgeStrategy,
                                   ClassWriterStrategy classWriterStrategy,
                                   LatentMatcher<? super MethodDescription> ignoredMethods,
                                   List<? extends DynamicType> auxiliaryTypes,
                                   TypeDescription originalType,
                                   ClassFileLocator classFileLocator,
                                   MethodNameTransformer methodNameTransformer) {
    super(instrumentedType,
            fieldRegistry,
            methodRegistry,
            recordComponentRegistry,
            typeAttributeAppender,
            asmVisitorWrapper,
            classFileVersion,
            auxiliaryTypeNamingStrategy,
            annotationValueFilterFactory,
            annotationRetention,
            implementationContextFactory,
            methodGraphCompiler,
            typeValidation,
            visibilityBridgeStrategy,
            classWriterStrategy,
            ignoredMethods,
            auxiliaryTypes,
            originalType,
            classFileLocator);
    this.methodNameTransformer = methodNameTransformer;
}
 
Example #24
Source File: DebuggingWrapper.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
public static AsmVisitorWrapper makeDefault() {
    return makeDefault(true);
}
 
Example #25
Source File: DebuggingWrapper.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
public static AsmVisitorWrapper makeDefault(boolean check) {
    return new DebuggingWrapper(System.out, new Textifier(), check);
}
 
Example #26
Source File: AbstractDynamicTypeBuilderTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testWriterHint() throws Exception {
    AsmVisitorWrapper asmVisitorWrapper = mock(AsmVisitorWrapper.class);
    when(asmVisitorWrapper.wrap(any(TypeDescription.class),
            any(ClassVisitor.class),
            any(Implementation.Context.class),
            any(TypePool.class),
            any(FieldList.class),
            any(MethodList.class),
            anyInt(),
            anyInt())).then(new Answer<ClassVisitor>() {
        public ClassVisitor answer(InvocationOnMock invocationOnMock) throws Throwable {
            return new ClassVisitor(OpenedClassReader.ASM_API, (ClassVisitor) invocationOnMock.getArguments()[1]) {
                @Override
                public void visitEnd() {
                    MethodVisitor mv = visitMethod(Opcodes.ACC_PUBLIC, FOO, "()Ljava/lang/String;", null, null);
                    mv.visitCode();
                    mv.visitLdcInsn(FOO);
                    mv.visitInsn(Opcodes.ARETURN);
                    mv.visitMaxs(-1, -1);
                    mv.visitEnd();
                }
            };
        }
    });
    when(asmVisitorWrapper.mergeWriter(0)).thenReturn(ClassWriter.COMPUTE_MAXS);
    Class<?> type = createPlain()
            .visit(asmVisitorWrapper)
            .make()
            .load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER)
            .getLoaded();
    assertThat(type.getDeclaredMethod(FOO).invoke(type.getDeclaredConstructor().newInstance()), is((Object) FOO));
    verify(asmVisitorWrapper).mergeWriter(0);
    verify(asmVisitorWrapper, atMost(1)).mergeReader(0);
    verify(asmVisitorWrapper).wrap(any(TypeDescription.class),
            any(ClassVisitor.class),
            any(Implementation.Context.class),
            any(TypePool.class),
            any(FieldList.class),
            any(MethodList.class),
            anyInt(),
            anyInt());
    verifyNoMoreInteractions(asmVisitorWrapper);
}
 
Example #27
Source File: PersistentAttributeTransformer.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
DynamicType.Builder<?> applyExtended(DynamicType.Builder<?> builder) {
	AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper enhancer = new FieldAccessEnhancer( managedCtClass, enhancementContext, classPool );
	return builder.visit( new AsmVisitorWrapper.ForDeclaredMethods().method( not( nameStartsWith( "$$_hibernate_" ) ), enhancer ) );
}
 
Example #28
Source File: AbstractDynamicTypeBuilderForInliningTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testReaderHint() throws Exception {
    AsmVisitorWrapper asmVisitorWrapper = mock(AsmVisitorWrapper.class);
    when(asmVisitorWrapper.wrap(any(TypeDescription.class),
            any(ClassVisitor.class),
            any(Implementation.Context.class),
            any(TypePool.class),
            any(FieldList.class),
            any(MethodList.class),
            anyInt(),
            anyInt())).then(new Answer<ClassVisitor>() {
        public ClassVisitor answer(InvocationOnMock invocationOnMock) throws Throwable {
            return new ClassVisitor(OpenedClassReader.ASM_API, (ClassVisitor) invocationOnMock.getArguments()[1]) {
                @Override
                public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
                    return new LocalVariablesSorter(access, desc, super.visitMethod(access, name, desc, signature, exceptions));
                }
            };
        }
    });
    when(asmVisitorWrapper.mergeWriter(0)).thenReturn(ClassWriter.COMPUTE_MAXS);
    when(asmVisitorWrapper.mergeReader(0)).thenReturn(ClassReader.EXPAND_FRAMES);
    Class<?> type = create(StackMapFrames.class)
            .visit(asmVisitorWrapper)
            .make()
            .load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER)
            .getLoaded();
    assertThat(type.getDeclaredMethod(FOO).invoke(type.getDeclaredConstructor().newInstance()), is((Object) BAR));
    verify(asmVisitorWrapper).mergeWriter(0);
    verify(asmVisitorWrapper).mergeReader(0);
    verify(asmVisitorWrapper).wrap(any(TypeDescription.class),
            any(ClassVisitor.class),
            any(Implementation.Context.class),
            any(TypePool.class),
            any(FieldList.class),
            any(MethodList.class),
            anyInt(),
            anyInt());
    verifyNoMoreInteractions(asmVisitorWrapper);
}
 
Example #29
Source File: PersistentAttributeTransformer.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
DynamicType.Builder<?> applyTo(DynamicType.Builder<?> builder, boolean accessor) {
	boolean compositeOwner = false;

	builder = builder.visit( new AsmVisitorWrapper.ForDeclaredMethods().method( not( nameStartsWith( "$$_hibernate_" ) ), this ) );
	for ( FieldDescription enhancedField : enhancedFields ) {
		builder = builder
				.defineMethod(
						EnhancerConstants.PERSISTENT_FIELD_READER_PREFIX + enhancedField.getName(),
						enhancedField.getType().asErasure(),
						Visibility.PUBLIC
				)
				.intercept(
						accessor
								? FieldAccessor.ofField( enhancedField.getName() ).in( enhancedField.getDeclaringType().asErasure() )
								: fieldReader( enhancedField )
				)
				.defineMethod(
						EnhancerConstants.PERSISTENT_FIELD_WRITER_PREFIX + enhancedField.getName(),
						TypeDescription.VOID,
						Visibility.PUBLIC
				)
				.withParameters( enhancedField.getType().asErasure() )
				.intercept( accessor
									? FieldAccessor.ofField( enhancedField.getName() ).in( enhancedField.getDeclaringType().asErasure() )
									: fieldWriter( enhancedField ) );

		if ( !compositeOwner
				&& !accessor
				&& EnhancerImpl.isAnnotationPresent( enhancedField, Embedded.class )
				&& enhancementContext.isCompositeClass( enhancedField.getType().asErasure() )
				&& enhancementContext.doDirtyCheckingInline( managedCtClass ) ) {
			compositeOwner = true;
		}
	}

	if ( compositeOwner ) {
		builder = builder.implement( CompositeOwner.class );

		if ( enhancementContext.isCompositeClass( managedCtClass ) ) {
			builder = builder.defineMethod( EnhancerConstants.TRACKER_CHANGER_NAME, void.class, Visibility.PUBLIC )
					.withParameters( String.class )
					.intercept( Advice.to( CodeTemplates.CompositeOwnerDirtyCheckingHandler.class ).wrap( StubMethod.INSTANCE ) );
		}
	}

	if ( enhancementContext.doExtendedEnhancement( managedCtClass ) ) {
		builder = applyExtended( builder );
	}

	return builder;
}
 
Example #30
Source File: ClassFileExtraction.java    From garmadon with Apache License 2.0 4 votes vote down vote up
public static byte[] extract(Class<?> type) throws IOException {
    return extract(type, new AsmVisitorWrapper.Compound());
}