/** * Returns the method {@link Type} corresponding to the given argument and return types. * * @param returnType the return type of the method. * @param argumentTypes the argument types of the method. * @return the method {@link Type} corresponding to the given argument and return types. */ public static Type getMethodType(final Type returnType, final Type... argumentTypes) { return getType(getMethodDescriptor(returnType, argumentTypes)); }
/** * {@inheritDoc} */ public String[] toInternalNames() { String[] internalName = new String[descriptors.size()]; int index = 0; for (String descriptor : descriptors) { internalName[index++] = Type.getType(descriptor).getInternalName(); } return internalName.length == 0 ? NO_INTERFACES : internalName; }
/** * Resolves all type references that are referenced by a {@link Type} value. * * @param type The type to resolve. */ protected void resolve(Type type) { if (type.getSort() == Type.METHOD) { resolve(type.getReturnType()); for (Type argumentType : type.getArgumentTypes()) { resolve(argumentType); } } else { while (type.getSort() == Type.ARRAY) { type = type.getElementType(); } if (type.getSort() == Type.OBJECT) { observedTypes.add(type.getInternalName()); } } }
/** * Returns the argument types of methods of this type. This method should only be used for method * types. * * @return the argument types of methods of this type. */ public Type[] getArgumentTypes() { return getArgumentTypes(getDescriptor()); }
managedCtClass.getInternalName(), EnhancerConstants.INTERCEPTOR_GETTER_NAME, Type.getMethodDescriptor( Type.getType( PersistentAttributeInterceptor.class ) ), false ); managedCtClass.getInternalName(), EnhancerConstants.INTERCEPTOR_GETTER_NAME, Type.getMethodDescriptor( Type.getType( PersistentAttributeInterceptor.class ) ), false ); methodVisitor.visitVarInsn( Opcodes.ALOAD, 0 ); fieldRead( methodVisitor ); methodVisitor.visitVarInsn( Type.getType( dispatcherType.getDescriptor() ).getOpcode( Opcodes.ILOAD ), 1 ); methodVisitor.visitMethodInsn( Opcodes.INVOKEINTERFACE, Type.getInternalName( PersistentAttributeInterceptor.class ), "write" + EnhancerImpl.capitalize( dispatcherType.getSimpleName() ), Type.getMethodDescriptor( Type.getType( dispatcherType.getDescriptor() ), Type.getType( Object.class ), Type.getType( String.class ), Type.getType( dispatcherType.getDescriptor() ), Type.getType( dispatcherType.getDescriptor() ) ), true methodVisitor.visitVarInsn( Type.getType( dispatcherType.getDescriptor() ).getOpcode( Opcodes.ILOAD ), 1 );
@Override public Size apply( MethodVisitor methodVisitor, Implementation.Context implementationContext, MethodDescription instrumentedMethod ) { methodVisitor.visitVarInsn( Opcodes.ALOAD, 0 ); methodVisitor.visitVarInsn( Type.getType( persistentField.getType().asErasure().getDescriptor() ).getOpcode( Opcodes.ILOAD ), 1 ); methodVisitor.visitMethodInsn( Opcodes.INVOKESPECIAL, managedCtClass.getSuperClass().asErasure().getInternalName(), EnhancerConstants.PERSISTENT_FIELD_WRITER_PREFIX + persistentField.getName(), Type.getMethodDescriptor( Type.getType( void.class ), Type.getType( persistentField.getType().asErasure().getDescriptor() ) ), false ); methodVisitor.visitInsn( Opcodes.RETURN ); return new Size( 1 + persistentField.getType().getStackSize().getSize(), instrumentedMethod.getStackSize() ); } }
/** * Returns the {@link Type} corresponding to the return type of the given method. * * @param method a method. * @return the {@link Type} corresponding to the return type of the given method. */ public static Type getReturnType(final Method method) { return getType(method.getReturnType()); }
@Override public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { if ( owner.startsWith( Type.getInternalName( CodeTemplates.class ) ) ) { if ( name.equals( "getter" ) ) { super.visitTypeInsn( Opcodes.CHECKCAST, targetEntity.getInternalName() ); targetEntity.getInternalName(), EnhancerConstants.PERSISTENT_FIELD_READER_PREFIX + mappedBy, Type.getMethodDescriptor( Type.getType( targetType.getDescriptor() ) ), false ); targetEntity.getInternalName(), EnhancerConstants.PERSISTENT_FIELD_WRITER_PREFIX + mappedBy, Type.getMethodDescriptor( Type.getType( void.class ), Type.getType( targetType.getDescriptor() ) ), false ); targetEntity.getInternalName(), EnhancerConstants.PERSISTENT_FIELD_WRITER_PREFIX + mappedBy, Type.getMethodDescriptor( Type.getType( void.class ), Type.getType( targetType.getDescriptor() ) ), false );
/** * Creates a type description from a descriptor by looking up the corresponding type. * * @param typePool The type pool to use for locating a type. * @param descriptor The descriptor to interpret. * @return A description of the type represented by the descriptor. */ protected static TypeDescription toErasure(TypePool typePool, String descriptor) { Type type = Type.getType(descriptor); return typePool.describe(type.getSort() == Type.ARRAY ? type.getInternalName().replace('/', '.') : type.getClassName()).resolve(); }
for ( Method setter : setters ) { methodVisitor.visitVarInsn( Opcodes.ALOAD, 1 ); methodVisitor.visitTypeInsn( Opcodes.CHECKCAST, Type.getInternalName( clazz ) ); methodVisitor.visitVarInsn( Opcodes.ALOAD, 2 ); methodVisitor.visitLdcInsn( index++ ); methodVisitor.visitTypeInsn( Opcodes.CHECKCAST, Type.getInternalName( setter.getParameterTypes()[0] ) ); Type.getInternalName( clazz ), setter.getName(), Type.getMethodDescriptor( setter ), false );
/** * Resolves all type references that are referenced by a {@link Handle} value. * * @param handle The handle to resolve. */ protected void resolve(Handle handle) { observedTypes.add(handle.getOwner()); Type methodType = Type.getType(handle.getDesc()); resolve(methodType.getReturnType()); for (Type type : methodType.getArgumentTypes()) { resolve(type); } }
/** * Represents a type value of an annotation. * * @param typePool The type pool to use for looking up types. * @param type A type representation of the type that is referenced by the annotation.. */ protected RawTypeValue(TypePool typePool, Type type) { this.typePool = typePool; name = type.getSort() == Type.ARRAY ? type.getInternalName().replace('/', '.') : type.getClassName(); }
/** * {@inheritDoc} */ public int prepare(MethodVisitor methodVisitor) { StackSize stackSize; if (!instrumentedMethod.isStatic()) { methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitVarInsn(Opcodes.ASTORE, instrumentedMethod.getStackSize() + exitType.getStackSize().getSize() + StackSize.of(namedTypes.values()) + enterType.getStackSize().getSize()); stackSize = StackSize.SINGLE; } else { stackSize = StackSize.ZERO; } for (ParameterDescription parameterDescription : instrumentedMethod.getParameters()) { Type type = Type.getType(parameterDescription.getType().asErasure().getDescriptor()); methodVisitor.visitVarInsn(type.getOpcode(Opcodes.ILOAD), parameterDescription.getOffset()); methodVisitor.visitVarInsn(type.getOpcode(Opcodes.ISTORE), instrumentedMethod.getStackSize() + exitType.getStackSize().getSize() + StackSize.of(namedTypes.values()) + enterType.getStackSize().getSize() + parameterDescription.getOffset()); stackSize = stackSize.maximum(parameterDescription.getType().getStackSize()); } return stackSize.getSize(); } }
/** * Returns the method {@link Type} corresponding to the given constructor. * * @param constructor a {@link Constructor} object. * @return the method {@link Type} corresponding to the given constructor. */ public static Type getType(final Constructor<?> constructor) { return getType(getConstructorDescriptor(constructor)); }
this.modifiers = modifiers; this.internalName = internalName; Type methodType = Type.getMethodType(descriptor); Type returnType = methodType.getReturnType(); Type[] parameterType = methodType.getArgumentTypes(); returnTypeDescriptor = returnType.getDescriptor(); parameterTypeDescriptors = new ArrayList<String>(parameterType.length); for (Type type : parameterType) { parameterTypeDescriptors.add(type.getDescriptor()); exceptionTypeDescriptors = new ArrayList<String>(exceptionTypeInternalName.length); for (String anExceptionTypeInternalName : exceptionTypeInternalName) { exceptionTypeDescriptors.add(Type.getObjectType(anExceptionTypeInternalName).getDescriptor());
return getType(getDescriptor(clazz));
/** * Creates a new class constant for a primitive type. * * @param type The primitive type to represent. */ ClassConstant(Class<?> type) { fieldOwnerInternalName = Type.getInternalName(type); }
private boolean typeEquals(String typeDescriptor, Class<?>... classes) { for (Class<?> clazz : classes) { if (clazz.getName().equals(Type.getType(typeDescriptor).getClassName())) { return true; } } return false; }
/** * Creates a new component type locator for an array type. * * @param methodDescriptor The method descriptor to resolve. */ public ForArrayType(String methodDescriptor) { String arrayType = Type.getMethodType(methodDescriptor).getReturnType().getClassName(); componentType = arrayType.substring(0, arrayType.length() - 2); }