net.bytebuddy.utility.OpenedClassReader Java Examples
The following examples show how to use
net.bytebuddy.utility.OpenedClassReader.
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: HibernateEntityEnhancer.java From quarkus with Apache License 2.0 | 6 votes |
public HibernateEnhancingClassVisitor(String className, ClassVisitor outputClassVisitor) { super(OpenedClassReader.ASM_API, new QuarkusClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS)); this.className = className; this.outputClassVisitor = outputClassVisitor; //note that as getLoadingClassLoader is resolved immediately this can't be created until transform time DefaultEnhancementContext enhancementContext = new DefaultEnhancementContext() { @Override public boolean doBiDirectionalAssociationManagement(final UnloadedField field) { //Don't enable automatic association management as it's often too surprising. //Also, there's several cases in which its semantics are of unspecified, //such as what should happen when dealing with ordered collections. return false; } @Override public ClassLoader getLoadingClassLoader() { return Thread.currentThread().getContextClassLoader(); } }; this.enhancer = PROVIDER.getEnhancer(enhancementContext); }
Example #2
Source File: AsmVisitorWrapper.java From byte-buddy with Apache License 2.0 | 6 votes |
/** * Creates a new dispatching visitor. * * @param classVisitor The underlying class visitor. * @param instrumentedType The instrumented type. * @param implementationContext The implementation context to use. * @param typePool The type pool to use. * @param methods The methods that are declared by the instrumented type or virtually inherited. * @param writerFlags The ASM {@link org.objectweb.asm.ClassWriter} flags to consider. * @param readerFlags The ASM {@link org.objectweb.asm.ClassReader} flags to consider. */ protected DispatchingVisitor(ClassVisitor classVisitor, TypeDescription instrumentedType, Implementation.Context implementationContext, TypePool typePool, Map<String, MethodDescription> methods, int writerFlags, int readerFlags) { super(OpenedClassReader.ASM_API, classVisitor); this.instrumentedType = instrumentedType; this.implementationContext = implementationContext; this.typePool = typePool; this.methods = methods; this.writerFlags = writerFlags; this.readerFlags = readerFlags; }
Example #3
Source File: ModifierAdjustment.java From byte-buddy with Apache License 2.0 | 6 votes |
/** * Creates a new modifier adjusting visitor. * * @param classVisitor The class visitor to delegate to. * @param typeAdjustments A list of type modifier adjustments to apply. * @param fieldAdjustments A list of field modifier adjustments to apply. * @param methodAdjustments A list of method modifier adjustments to apply. * @param instrumentedType The instrumented type. * @param fields A mapping of field names and descriptors to their description. * @param methods A mapping of method names and descriptors to their description. */ protected ModifierAdjustingClassVisitor(ClassVisitor classVisitor, List<Adjustment<TypeDescription>> typeAdjustments, List<Adjustment<FieldDescription.InDefinedShape>> fieldAdjustments, List<Adjustment<MethodDescription>> methodAdjustments, TypeDescription instrumentedType, Map<String, FieldDescription.InDefinedShape> fields, Map<String, MethodDescription> methods) { super(OpenedClassReader.ASM_API, classVisitor); this.typeAdjustments = typeAdjustments; this.fieldAdjustments = fieldAdjustments; this.methodAdjustments = methodAdjustments; this.instrumentedType = instrumentedType; this.fields = fields; this.methods = methods; }
Example #4
Source File: MemberRemoval.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * Creates a new member removing class visitor. * * @param classVisitor The class visitor to delegate to. * @param fieldMatcher The matcher that determines field removal. * @param methodMatcher The matcher that determines method removal. * @param fields A mapping of field names and descriptors to their description. * @param methods A mapping of method names and descriptors to their description. */ protected MemberRemovingClassVisitor(ClassVisitor classVisitor, ElementMatcher.Junction<FieldDescription.InDefinedShape> fieldMatcher, ElementMatcher.Junction<MethodDescription> methodMatcher, Map<String, FieldDescription.InDefinedShape> fields, Map<String, MethodDescription> methods) { super(OpenedClassReader.ASM_API, classVisitor); this.fieldMatcher = fieldMatcher; this.methodMatcher = methodMatcher; this.fields = fields; this.methods = methods; }
Example #5
Source File: TypeReferenceAdjustment.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * Creates a type reference class visitor. * * @param classVisitor {@code true} if the visitor should throw an exception if a type reference cannot be located. * @param strict {@code true} if the visitor should throw an exception if a type reference cannot be located. * @param filter A filter for excluding types from type reference analysis. * @param typePool The type pool to use for locating types. */ protected TypeReferenceClassVisitor(ClassVisitor classVisitor, boolean strict, ElementMatcher<? super TypeDescription> filter, TypePool typePool) { super(OpenedClassReader.ASM_API, classVisitor); this.typePool = typePool; this.strict = strict; this.filter = filter; observedTypes = new HashSet<String>(); visitedInnerTypes = new HashSet<String>(); }
Example #6
Source File: MemberAttributeExtension.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * @param methodVisitor The method visitor to apply changes to. * @param methodDescription The method to add annotations to. * @param methodAttributeAppender The annotation value filter to apply. * @param annotationValueFilter The annotation value filter to apply. */ private AttributeAppendingMethodVisitor(MethodVisitor methodVisitor, MethodDescription methodDescription, MethodAttributeAppender methodAttributeAppender, AnnotationValueFilter annotationValueFilter) { super(OpenedClassReader.ASM_API, methodVisitor); this.methodDescription = methodDescription; this.methodAttributeAppender = methodAttributeAppender; this.annotationValueFilter = annotationValueFilter; applicable = true; }
Example #7
Source File: MemberAttributeExtension.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * Creates a new field attribute visitor. * * @param fieldVisitor The field visitor to apply changes to. * @param fieldDescription The field to add annotations to. * @param fieldAttributeAppender The field attribute appender to apply. * @param annotationValueFilter The annotation value filter to apply. */ private FieldAttributeVisitor(FieldVisitor fieldVisitor, FieldDescription fieldDescription, FieldAttributeAppender fieldAttributeAppender, AnnotationValueFilter annotationValueFilter) { super(OpenedClassReader.ASM_API, fieldVisitor); this.fieldDescription = fieldDescription; this.fieldAttributeAppender = fieldAttributeAppender; this.annotationValueFilter = annotationValueFilter; }
Example #8
Source File: ByteArrayClassLoaderChildFirstTest.java From byte-buddy with Apache License 2.0 | 5 votes |
public ClassVisitor wrap(TypeDescription instrumentedType, ClassVisitor classVisitor, Implementation.Context implementationContext, TypePool typePool, FieldList<FieldDescription.InDefinedShape> fields, MethodList<?> methods, int writerFlags, int readerFlags) { return new ClassRemapper(OpenedClassReader.ASM_API, classVisitor, new SimpleRemapper(oldName, newName)) { /* only anonymous to define usage of Byte Buddy specific API version */ }; }
Example #9
Source File: TypeWriterDeclarationPreservationTest.java From byte-buddy with Apache License 2.0 | 5 votes |
@Test public void testRedefinition() throws Exception { TypeModifierExtractor typeModifierExtractor = new TypeModifierExtractor(); OpenedClassReader.of(ClassFileLocator.ForClassLoader.read(type)).accept(typeModifierExtractor, 0); new ByteBuddy() .redefine(type) .visit(new TypeValidator.Wrapper(typeModifierExtractor)) .make(); }
Example #10
Source File: StackAwareMethodVisitor.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * Creates a new stack aware method visitor. * * @param methodVisitor The method visitor to delegate operations to. * @param instrumentedMethod The method description for which this method visitor is applied. */ public StackAwareMethodVisitor(MethodVisitor methodVisitor, MethodDescription instrumentedMethod) { super(OpenedClassReader.ASM_API, methodVisitor); current = new ArrayList<StackSize>(); sizes = new HashMap<Label, List<StackSize>>(); freeIndex = instrumentedMethod.getStackSize(); }
Example #11
Source File: TypeWriterDeclarationPreservationTest.java From byte-buddy with Apache License 2.0 | 5 votes |
@Test public void testRebasing() throws Exception { TypeModifierExtractor typeModifierExtractor = new TypeModifierExtractor(); OpenedClassReader.of(ClassFileLocator.ForClassLoader.read(type)).accept(typeModifierExtractor, 0); new ByteBuddy() .rebase(type) .visit(new TypeValidator.Wrapper(typeModifierExtractor)) .make(); }
Example #12
Source File: TypeWriterDeclarationPreservationTest.java From byte-buddy with Apache License 2.0 | 5 votes |
@Test public void testDecoration() throws Exception { TypeModifierExtractor typeModifierExtractor = new TypeModifierExtractor(); OpenedClassReader.of(ClassFileLocator.ForClassLoader.read(type)).accept(typeModifierExtractor, 0); new ByteBuddy() .decorate(type) .visit(new TypeValidator.Wrapper(typeModifierExtractor)) .make(); }
Example #13
Source File: TypeWriterDeclarationPreservationTest.java From byte-buddy with Apache License 2.0 | 5 votes |
private TypeValidator(ClassVisitor classVisitor, int modifiers, Set<InnerClassAttribute> innerClassAttributes, OuterClassAttribute outerClassAttribute) { super(OpenedClassReader.ASM_API, classVisitor); this.modifiers = modifiers; this.innerClassAttributes = innerClassAttributes; this.outerClassAttribute = outerClassAttribute; }
Example #14
Source File: DecoratingDynamicTypeBuilderTest.java From byte-buddy with Apache License 2.0 | 5 votes |
@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 #15
Source File: DecoratingDynamicTypeBuilderTest.java From byte-buddy with Apache License 2.0 | 5 votes |
@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 #16
Source File: DecoratingDynamicTypeBuilderTest.java From byte-buddy with Apache License 2.0 | 5 votes |
@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 #17
Source File: AbstractDynamicTypeBuilderForInliningTest.java From byte-buddy with Apache License 2.0 | 4 votes |
@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 #18
Source File: TypeWriterDeclarationPreservationTest.java From byte-buddy with Apache License 2.0 | 4 votes |
private TypeModifierExtractor() { super(OpenedClassReader.ASM_API); }
Example #19
Source File: AbstractDynamicTypeBuilderTest.java From byte-buddy with Apache License 2.0 | 4 votes |
@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 #20
Source File: AbstractTypeDescriptionGenericTest.java From byte-buddy with Apache License 2.0 | 4 votes |
public GenericDisintegrator(ClassVisitor classVisitor) { super(OpenedClassReader.ASM_API, classVisitor); }
Example #21
Source File: AbstractTypeDescriptionTest.java From byte-buddy with Apache License 2.0 | 4 votes |
public SignatureMalformer(ClassVisitor classVisitor) { super(OpenedClassReader.ASM_API, classVisitor); }
Example #22
Source File: AbstractAnnotationDescriptionTest.java From byte-buddy with Apache License 2.0 | 4 votes |
private BreakingClassVisitor(ClassVisitor classVisitor) { super(OpenedClassReader.ASM_API, classVisitor); }
Example #23
Source File: TypeReferenceAdjustmentTest.java From byte-buddy with Apache License 2.0 | 4 votes |
private AssertionClassVisitor(ClassVisitor classVisitor) { super(OpenedClassReader.ASM_API, classVisitor); }
Example #24
Source File: AdviceTypeTest.java From byte-buddy with Apache License 2.0 | 4 votes |
public SerializationMethodVisitor(MethodVisitor methodVisitor) { super(OpenedClassReader.ASM_API, methodVisitor); }
Example #25
Source File: AdviceTypeTest.java From byte-buddy with Apache License 2.0 | 4 votes |
public SerializationClassVisitor(ClassVisitor classVisitor) { super(OpenedClassReader.ASM_API, classVisitor); }
Example #26
Source File: ClassFileVersion.java From byte-buddy with Apache License 2.0 | 4 votes |
/** * Returns the Java class file by its representation by a version string in accordance to the formats known to <i>javac</i>. * * @param javaVersionString The Java version string. * @return The appropriate class file version. */ public static ClassFileVersion ofJavaVersionString(String javaVersionString) { if (javaVersionString.equals("1.1")) { return JAVA_V1; } else if (javaVersionString.equals("1.2")) { return JAVA_V2; } else if (javaVersionString.equals("1.3")) { return JAVA_V3; } else if (javaVersionString.equals("1.4")) { return JAVA_V4; } else if (javaVersionString.equals("1.5") || javaVersionString.equals("5")) { return JAVA_V5; } else if (javaVersionString.equals("1.6") || javaVersionString.equals("6")) { return JAVA_V6; } else if (javaVersionString.equals("1.7") || javaVersionString.equals("7")) { return JAVA_V7; } else if (javaVersionString.equals("1.8") || javaVersionString.equals("8")) { return JAVA_V8; } else if (javaVersionString.equals("1.9") || javaVersionString.equals("9")) { return JAVA_V9; } else if (javaVersionString.equals("1.10") || javaVersionString.equals("10")) { return JAVA_V10; } else if (javaVersionString.equals("1.11") || javaVersionString.equals("11")) { return JAVA_V11; } else if (javaVersionString.equals("1.12") || javaVersionString.equals("12")) { return JAVA_V12; } else if (javaVersionString.equals("1.13") || javaVersionString.equals("13")) { return JAVA_V13; } else if (javaVersionString.equals("1.14") || javaVersionString.equals("14")) { return JAVA_V14; } else if (javaVersionString.equals("1.15") || javaVersionString.equals("15")) { return JAVA_V15; } else if (javaVersionString.equals("1.16") || javaVersionString.equals("16")) { return JAVA_V16; } else { if (OpenedClassReader.EXPERIMENTAL) { try { int version = Integer.parseInt(javaVersionString.startsWith("1.") ? javaVersionString.substring(2) : javaVersionString); if (version > 0) { return new ClassFileVersion(BASE_VERSION + version); } } catch (NumberFormatException ignored) { } } throw new IllegalArgumentException("Unknown Java version string: " + javaVersionString); } }
Example #27
Source File: BridgeClassVisitor.java From kanela with Apache License 2.0 | 4 votes |
private BridgeClassVisitor(BridgeDescription bridge, String className, ClassVisitor classVisitor) { super(OpenedClassReader.ASM_API, classVisitor); this.bridge = bridge; this.type = Type.getObjectType(className); }
Example #28
Source File: ClassFileVersionValidatorClassVisitor.java From kanela with Apache License 2.0 | 4 votes |
private ClassFileVersionValidatorClassVisitor(ClassVisitor classVisitor) { super(OpenedClassReader.ASM_API, classVisitor); }
Example #29
Source File: MixinInitializer.java From kanela with Apache License 2.0 | 4 votes |
MixinInitializer(MethodVisitor mv, int access, String name, String desc, Type typeClass, MixinDescription mixinDescription) { super(OpenedClassReader.ASM_API, mv, access, name, desc); this.typeClass = typeClass; this.mixinDescription = mixinDescription; }
Example #30
Source File: MixinClassVisitor.java From kanela with Apache License 2.0 | 4 votes |
private MixinClassVisitor(MixinDescription mixin, String className, ClassVisitor classVisitor) { super(OpenedClassReader.ASM_API, classVisitor); this.mixin = mixin; this.type = Type.getObjectType(className); }