/** * Creates a new array creator for a reference type. * * @param referenceType The internal name of this array's non-primitive component type. */ protected ForReferenceType(TypeDescription referenceType) { this.internalTypeName = referenceType.getInternalName(); }
/** * {@inheritDoc} */ public String[] toInternalNames() { String[] internalName = new String[nestMembers.size() + 1]; internalName[0] = typeDescription.getInternalName(); int index = 1; for (String name : nestMembers) { internalName[index++] = name.replace('.', '/'); } return internalName; }
/** * {@inheritDoc} */ public void store(Map<TypeDescription, byte[]> binaryRepresentations) { for (Map.Entry<TypeDescription, byte[]> entry : binaryRepresentations.entrySet()) { storage.put(entry.getKey().getInternalName() + CLASS_FILE_EXTENSION, entry.getValue()); } }
/** * {@inheritDoc} */ public void store(Map<TypeDescription, byte[]> binaryRepresentations) throws IOException { for (Map.Entry<TypeDescription, byte[]> entry : binaryRepresentations.entrySet()) { outputStream.putNextEntry(new JarEntry(entry.getKey().getInternalName() + CLASS_FILE_EXTENSION)); outputStream.write(entry.getValue()); outputStream.closeEntry(); } }
/** * {@inheritDoc} */ public void onPrepare(MethodVisitor methodVisitor) { methodVisitor.visitTryCatchBlock(startOfMethod, endOfMethod, endOfMethod, suppressedType.getInternalName()); }
@Override protected void onUserPrepare() { methodVisitor.visitTryCatchBlock(userStart, returnHandler, exceptionHandler, throwable.getInternalName()); }
/** * Represents a map of type names to their binary representation as an in-memory source. * * @param binaryRepresentations A mapping of type names to their binary representation. * @return A source representing the supplied types. */ public static Source ofTypes(Map<TypeDescription, byte[]> binaryRepresentations) { Map<String, byte[]> storage = new HashMap<String, byte[]>(); for (Map.Entry<TypeDescription, byte[]> entry : binaryRepresentations.entrySet()) { storage.put(entry.getKey().getInternalName() + CLASS_FILE_EXTENSION, entry.getValue()); } return new InMemory(storage); }
/** * {@inheritDoc} */ public String[] toInternalNames() { String[] internalNames = new String[size()]; int i = 0; for (TypeDescription typeDescription : this) { internalNames[i++] = typeDescription.getInternalName(); } return internalNames.length == 0 ? NO_INTERFACES : internalNames; } }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { methodVisitor.visitTypeInsn(Opcodes.NEW, typeDescription.getInternalName()); return new Size(1, 1); } }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { methodVisitor.visitTypeInsn(Opcodes.INSTANCEOF, typeDescription.getInternalName()); return new Size(0, 0); } }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, wrapperType.asErasure().getInternalName(), unboxingMethodName, unboxingMethodDescriptor, false); return size; }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { methodVisitor.visitTypeInsn(Opcodes.CHECKCAST, typeDescription.getInternalName()); return StackSize.ZERO.toIncreasingSize(); } }
@Override public void visitInnerClass(String internalName, String outerName, String innerName, int modifiers) { if (instrumentedType.getInternalName().equals(internalName)) { for (Adjustment<TypeDescription> adjustment : typeAdjustments) { if (adjustment.matches(instrumentedType)) { modifiers = adjustment.resolve(modifiers); break; } } } super.visitInnerClass(internalName, outerName, innerName, modifiers); }
/** * {@inheritDoc} */ public String getCanonicalName() { if (isAnonymousType() || isLocalType()) { return NO_NAME; } String internalName = getInternalName(); TypeDescription enclosingType = getEnclosingType(); if (enclosingType != null && internalName.startsWith(enclosingType.getInternalName() + "$")) { return enclosingType.getCanonicalName() + "." + internalName.substring(enclosingType.getInternalName().length() + 1); } else { return getName(); } }
/** * {@inheritDoc} */ protected ClassVisitor writeTo(ClassVisitor classVisitor, TypeInitializer typeInitializer, ContextRegistry contextRegistry, int writerFlags, int readerFlags) { classVisitor = new RedefinitionClassVisitor(classVisitor, typeInitializer, contextRegistry, writerFlags, readerFlags); return originalType.getName().equals(instrumentedType.getName()) ? classVisitor : new OpenedClassRemapper(classVisitor, new SimpleRemapper(originalType.getInternalName(), instrumentedType.getInternalName())); }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, wrapperType.getInternalName(), boxingMethodName, boxingMethodDescriptor, false); return size.aggregate(stackManipulation.apply(methodVisitor, implementationContext)); } }
/** * {@inheritDoc} */ public Object asConstantPoolValue() { StringBuilder stringBuilder = new StringBuilder().append('('); for (TypeDescription parameterType : getParameterTypes()) { stringBuilder.append(parameterType.getDescriptor()); } String descriptor = stringBuilder.append(')').append(getReturnType().getDescriptor()).toString(); return new Handle(getHandleType().getIdentifier(), getOwnerType().getInternalName(), getName(), descriptor, getOwnerType().isInterface()); }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { methodVisitor.visitFieldInsn(getOpcode(), fieldDescription.getDeclaringType().getInternalName(), fieldDescription.getInternalName(), fieldDescription.getDescriptor()); return resolveSize(fieldDescription.getType().getStackSize()); }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { methodVisitor.visitMethodInsn(opcode == legacyOpcode || implementationContext.getClassFileVersion().isAtLeast(ClassFileVersion.JAVA_V11) ? opcode : legacyOpcode, typeDescription.getInternalName(), methodDescription.getInternalName(), methodDescription.getDescriptor(), typeDescription.isInterface()); int parameterSize = methodDescription.getStackSize(), returnValueSize = methodDescription.getReturnType().getStackSize().getSize(); return new Size(returnValueSize - parameterSize, Math.max(0, returnValueSize - parameterSize)); }
/** * {@inheritDoc} */ public SignatureVisitor onNonGenericType(Generic typeDescription) { if (typeDescription.isArray()) { typeDescription.getComponentType().accept(new ForSignatureVisitor(signatureVisitor.visitArrayType())); } else if (typeDescription.isPrimitive()) { signatureVisitor.visitBaseType(typeDescription.asErasure().getDescriptor().charAt(ONLY_CHARACTER)); } else { signatureVisitor.visitClassType(typeDescription.asErasure().getInternalName()); signatureVisitor.visitEnd(); } return signatureVisitor; }