/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { try { return new Compound( ClassConstant.of(fieldDescription.getDeclaringType()), new TextConstant(fieldDescription.getInternalName()), MethodInvocation.invoke(new MethodDescription.ForLoadedMethod(Class.class.getMethod("getDeclaredField", String.class))) ).apply(methodVisitor, implementationContext); } catch (NoSuchMethodException exception) { throw new IllegalStateException("Cannot locate Class::getDeclaredField", exception); } }
/** * Returns a method handle for a setter of the given field. * * @param fieldDescription The field to represent. * @return A method handle for a setter of the given field. */ public static MethodHandle ofGetter(FieldDescription.InDefinedShape fieldDescription) { return new MethodHandle(HandleType.ofGetter(fieldDescription), fieldDescription.getDeclaringType().asErasure(), fieldDescription.getInternalName(), fieldDescription.getType().asErasure(), Collections.<TypeDescription>emptyList()); }
/** * Returns a method handle for a getter of the given field. * * @param fieldDescription The field to represent. * @return A method handle for a getter of the given field. */ public static MethodHandle ofSetter(FieldDescription.InDefinedShape fieldDescription) { return new MethodHandle(HandleType.ofSetter(fieldDescription), fieldDescription.getDeclaringType().asErasure(), fieldDescription.getInternalName(), TypeDescription.VOID, Collections.singletonList(fieldDescription.getType().asErasure())); }
if ( persistentField.getDeclaringType().asErasure().equals( managedCtClass ) ) { methodVisitor.visitFieldInsn( Opcodes.GETFIELD, persistentField.getDeclaringType().asErasure().getInternalName(), persistentField.getName(), persistentField.getDescriptor() methodVisitor.visitMethodInsn( Opcodes.INVOKEVIRTUAL, persistentField.getDeclaringType().asErasure().getInternalName(), EnhancerConstants.PERSISTENT_FIELD_READER_PREFIX + persistentField.getName(), Type.getMethodDescriptor( Type.getType( persistentField.getDescriptor() ) ),
@Override protected void fieldWrite(MethodVisitor methodVisitor) { methodVisitor.visitFieldInsn( Opcodes.PUTFIELD, persistentFieldAsDefined.getDeclaringType().asErasure().getInternalName(), persistentFieldAsDefined.getInternalName(), persistentFieldAsDefined.getDescriptor() ); } }
@Override protected void fieldWrite(MethodVisitor methodVisitor) { methodVisitor.visitFieldInsn( Opcodes.PUTFIELD, persistentFieldAsDefined.getDeclaringType().asErasure().getInternalName(), persistentFieldAsDefined.getInternalName(), persistentFieldAsDefined.getDescriptor() ); } }
@Override protected void fieldRead(MethodVisitor methodVisitor) { methodVisitor.visitFieldInsn( Opcodes.GETFIELD, persistentFieldAsDefined.getDeclaringType().asErasure().getInternalName(), persistentFieldAsDefined.getInternalName(), persistentFieldAsDefined.getDescriptor() ); }
@Override protected void fieldRead(MethodVisitor methodVisitor) { methodVisitor.visitFieldInsn( Opcodes.GETFIELD, persistentFieldAsDefined.getDeclaringType().asErasure().getInternalName(), persistentFieldAsDefined.getInternalName(), persistentFieldAsDefined.getDescriptor() ); }
if ( persistentField.getDeclaringType().asErasure().equals( managedCtClass ) ) { methodVisitor.visitFieldInsn( Opcodes.GETFIELD, persistentField.getDeclaringType().asErasure().getInternalName(), persistentField.getName(), persistentField.getDescriptor() methodVisitor.visitMethodInsn( Opcodes.INVOKEVIRTUAL, persistentField.getDeclaringType().asErasure().getInternalName(), EnhancerConstants.PERSISTENT_FIELD_READER_PREFIX + persistentField.getName(), Type.getMethodDescriptor( Type.getType( persistentField.getDescriptor() ) ),
switch (opcode) { case Opcodes.PUTFIELD: parameters = new TypeList.Generic.Explicit(candidates.getOnly().getDeclaringType(), candidates.getOnly().getType()); result = TypeDescription.Generic.VOID; break; break; case Opcodes.GETFIELD: parameters = new TypeList.Generic.Explicit(candidates.getOnly().getDeclaringType()); result = candidates.getOnly().getType(); break;
/** * Returns a {@code static}, {@code final} field constant. * * @param fieldDescription The field to represent a value of. * @return A dynamically resolved field value constant. */ public static Dynamic ofField(FieldDescription.InDefinedShape fieldDescription) { if (!fieldDescription.isStatic() || !fieldDescription.isFinal()) { throw new IllegalArgumentException("Field must be static and final: " + fieldDescription); } boolean selfDeclared = fieldDescription.getType().isPrimitive() ? fieldDescription.getType().asErasure().asBoxed().equals(fieldDescription.getType().asErasure()) : fieldDescription.getDeclaringType().equals(fieldDescription.getType().asErasure()); return new Dynamic(new ConstantDynamic(fieldDescription.getInternalName(), fieldDescription.getDescriptor(), new Handle(Opcodes.H_INVOKESTATIC, CONSTANT_BOOTSTRAPS, "getStaticFinal", selfDeclared ? "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object;" : "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/Object;", false), selfDeclared ? new Object[0] : new Object[]{Type.getType(fieldDescription.getDeclaringType().getDescriptor())}), fieldDescription.getType().asErasure()); }
/** * Resolves a var handle constant for a field. * * @param fieldDescription The field to represent a var handle for. * @return A dynamic constant that represents the created var handle constant. */ public static JavaConstant ofVarHandle(FieldDescription.InDefinedShape fieldDescription) { return new Dynamic(new ConstantDynamic(fieldDescription.getInternalName(), JavaType.VAR_HANDLE.getTypeStub().getDescriptor(), new Handle(Opcodes.H_INVOKESTATIC, CONSTANT_BOOTSTRAPS, fieldDescription.isStatic() ? "staticFieldVarHandle" : "fieldVarHandle", "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/invoke/VarHandle;", false), Type.getType(fieldDescription.getDeclaringType().getDescriptor()), Type.getType(fieldDescription.getType().asErasure().getDescriptor())), JavaType.VAR_HANDLE.getTypeStub()); }
@Override protected void fieldWrite(MethodVisitor methodVisitor) { methodVisitor.visitFieldInsn( Opcodes.PUTFIELD, persistentFieldAsDefined.getDeclaringType().asErasure().getInternalName(), persistentFieldAsDefined.getInternalName(), persistentFieldAsDefined.getDescriptor() ); } }
@Override protected void fieldWrite(MethodVisitor methodVisitor) { methodVisitor.visitFieldInsn( Opcodes.PUTFIELD, persistentFieldAsDefined.getDeclaringType().asErasure().getInternalName(), persistentFieldAsDefined.getInternalName(), persistentFieldAsDefined.getDescriptor() ); } }
@Override protected void fieldRead(MethodVisitor methodVisitor) { methodVisitor.visitFieldInsn( Opcodes.GETFIELD, persistentFieldAsDefined.getDeclaringType().asErasure().getInternalName(), persistentFieldAsDefined.getInternalName(), persistentFieldAsDefined.getDescriptor() ); }
@Override protected void fieldRead(MethodVisitor methodVisitor) { methodVisitor.visitFieldInsn( Opcodes.GETFIELD, persistentFieldAsDefined.getDeclaringType().asErasure().getInternalName(), persistentFieldAsDefined.getInternalName(), persistentFieldAsDefined.getDescriptor() ); }
/** * {@inheritDoc} */ public Generic resolveFieldType(String fieldTypeDescriptor, TypePool typePool, Map<String, List<AnnotationToken>> annotationTokens, FieldDescription.InDefinedShape definingField) { return TokenizedGenericType.of(typePool, fieldTypeToken, fieldTypeDescriptor, annotationTokens, definingField.getDeclaringType()); } }
/** * {@inheritDoc} */ public Binding bind(FieldDescription.InDefinedShape fieldDescription, boolean writeAccess) { return (writeAccess ? matchFieldWrite : matchFieldRead) && fieldMatcher.matches(fieldDescription) ? new Binding.Resolved(fieldDescription.getDeclaringType(), fieldDescription, substitution) : Binding.Unresolved.INSTANCE; }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { methodVisitor.visitFieldInsn(getOpcode(), fieldDescription.getDeclaringType().getInternalName(), fieldDescription.getInternalName(), fieldDescription.getDescriptor()); return resolveSize(fieldDescription.getType().getStackSize()); }