final Attribute[] attributes = getAttributePrototypes(); firstField = null; lastField = null; attributes, (hasFrames ? ClassReader.EXPAND_FRAMES : 0) | ClassReader.EXPAND_ASM_INSNS); return toByteArray();
ClassLoader classLoader = getClassLoader(); Class<?> class1; try {
/** * Adds a handle to the constant pool of the class being build. Does nothing if the constant pool * already contains a similar item. <i>This method is intended for {@link Attribute} sub classes, * and is normally not needed by class generators or adapters.</i> * * @param tag the kind of this handle. Must be {@link Opcodes#H_GETFIELD}, {@link * Opcodes#H_GETSTATIC}, {@link Opcodes#H_PUTFIELD}, {@link Opcodes#H_PUTSTATIC}, {@link * Opcodes#H_INVOKEVIRTUAL}, {@link Opcodes#H_INVOKESTATIC}, {@link Opcodes#H_INVOKESPECIAL}, * {@link Opcodes#H_NEWINVOKESPECIAL} or {@link Opcodes#H_INVOKEINTERFACE}. * @param owner the internal name of the field or method owner class. * @param name the name of the field or method. * @param descriptor the descriptor of the field or method. * @return the index of a new or already existing method type reference item. * @deprecated this method is superseded by {@link #newHandle(int, String, String, String, * boolean)}. */ @Deprecated public int newHandle( final int tag, final String owner, final String name, final String descriptor) { return newHandle(tag, owner, name, descriptor, tag == Opcodes.H_INVOKEINTERFACE); }
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { if (loader == null || shouldIgnore(className)) { return null; } final ClassReader reader = new ClassReader(classfileBuffer); final ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); reader.accept(new PowerMockClassVisitor(writer), ClassReader.SKIP_FRAMES); return writer.toByteArray(); }
@Override protected UnresolvedType create(TypeInitializer typeInitializer) { try { int writerFlags = asmVisitorWrapper.mergeWriter(AsmVisitorWrapper.NO_FLAGS); int readerFlags = asmVisitorWrapper.mergeReader(AsmVisitorWrapper.NO_FLAGS); byte[] binaryRepresentation = classFileLocator.locate(originalType.getName()).resolve(); ClassDumpAction.dump(DUMP_FOLDER, instrumentedType, true, binaryRepresentation); ClassReader classReader = OpenedClassReader.of(binaryRepresentation); ClassWriter classWriter = classWriterStrategy.resolve(writerFlags, typePool, classReader); ContextRegistry contextRegistry = new ContextRegistry(); classReader.accept(writeTo(ValidatingClassVisitor.of(classWriter, typeValidation), typeInitializer, contextRegistry, writerFlags, readerFlags), readerFlags); return new UnresolvedType(classWriter.toByteArray(), contextRegistry.getAuxiliaryTypes()); } catch (IOException exception) { throw new RuntimeException("The class file could not be written", exception); } }
/** * Adds a merged type in the type table of this symbol table. Does nothing if the type table * already contains a similar type. * * @param typeTableIndex1 a {@link Symbol#TYPE_TAG} type, specified by its index in the type * table. * @param typeTableIndex2 another {@link Symbol#TYPE_TAG} type, specified by its index in the type * table. * @return the index of a new or already existing {@link Symbol#TYPE_TAG} type Symbol, * corresponding to the common super class of the given types. */ int addMergedType(final int typeTableIndex1, final int typeTableIndex2) { // TODO sort the arguments? The merge result should be independent of their order. long data = typeTableIndex1 | (((long) typeTableIndex2) << 32); int hashCode = hash(Symbol.MERGED_TYPE_TAG, typeTableIndex1 + typeTableIndex2); Entry entry = get(hashCode); while (entry != null) { if (entry.tag == Symbol.MERGED_TYPE_TAG && entry.hashCode == hashCode && entry.data == data) { return entry.info; } entry = entry.next; } String type1 = typeTable[typeTableIndex1].value; String type2 = typeTable[typeTableIndex2].value; int commonSuperTypeIndex = addType(classWriter.getCommonSuperClass(type1, type2)); put(new Entry(typeCount, Symbol.MERGED_TYPE_TAG, data, hashCode)).info = commonSuperTypeIndex; return commonSuperTypeIndex; }
return replaceAsmInstructions(result.data, hasFrames); } else { return result.data;
return new UnresolvedType(classWriter.toByteArray(), implementationContext.getAuxiliaryTypes());