ElementMatchers.anyOf(Map.class, Collection.class, RObject.class)))); for (InDefinedShape field : fields) { throw new IllegalArgumentException("RIndex annotation couldn't be defined for field '" + field.getName() + "' with type '" + field.getType() + "'");
ElementMatchers.anyOf(Map.class, Collection.class, RObject.class)))); for (InDefinedShape field : fields) { throw new IllegalArgumentException("RIndex annotation couldn't be defined for field '" + field.getName() + "' with type '" + field.getType() + "'");
stackManipulations.add(MethodVariableAccess.loadThis()); stackManipulations.add(FieldAccess.forField(fieldDescription).read()); stackManipulations.add(ValueConsumer.of(fieldDescription.getType().asErasure()));
switch (opcode) { case Opcodes.PUTFIELD: parameters = new TypeList.Generic.Explicit(candidates.getOnly().getDeclaringType(), candidates.getOnly().getType()); result = TypeDescription.Generic.VOID; break; case Opcodes.PUTSTATIC: parameters = new TypeList.Generic.Explicit(candidates.getOnly().getType()); result = TypeDescription.Generic.VOID; break; case Opcodes.GETFIELD: parameters = new TypeList.Generic.Explicit(candidates.getOnly().getDeclaringType()); result = candidates.getOnly().getType(); break; case Opcodes.GETSTATIC: parameters = new TypeList.Generic.Empty(); result = candidates.getOnly().getType(); break; default:
stackManipulations.add(TypeCasting.to(instrumentedType)); stackManipulations.add(FieldAccess.forField(fieldDescription).read()); NullValueGuard nullValueGuard = fieldDescription.getType().isPrimitive() || fieldDescription.getType().isArray() || nonNullable.matches(fieldDescription) ? NullValueGuard.NoOp.INSTANCE : new NullValueGuard.UsingJump(instrumentedMethod); stackManipulations.add(nullValueGuard.before()); stackManipulations.add(ValueComparator.of(fieldDescription.getType())); stackManipulations.add(nullValueGuard.after()); padding = Math.max(padding, nullValueGuard.getRequiredVariablePadding());
lambdaArguments.add(new StackManipulation.Compound(MethodVariableAccess.loadThis(), FieldAccess.forField(fieldDescription).read(), Assigner.DEFAULT.assign(fieldDescription.getType(), TypeDescription.Generic.OBJECT, Assigner.Typing.STATIC)));
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Context implementationContext, MethodDescription instrumentedMethod) { if (instrumentedMethod.isStatic()) { throw new IllegalStateException("Hash code method must not be static: " + instrumentedMethod); } else if (!instrumentedMethod.getReturnType().represents(int.class)) { throw new IllegalStateException("Hash code method does not return primitive integer: " + instrumentedMethod); } List<StackManipulation> stackManipulations = new ArrayList<StackManipulation>(2 + fieldDescriptions.size() * 8); stackManipulations.add(initialValue); int padding = 0; for (FieldDescription.InDefinedShape fieldDescription : fieldDescriptions) { stackManipulations.add(IntegerConstant.forValue(multiplier)); stackManipulations.add(Multiplication.INTEGER); stackManipulations.add(MethodVariableAccess.loadThis()); stackManipulations.add(FieldAccess.forField(fieldDescription).read()); NullValueGuard nullValueGuard = fieldDescription.getType().isPrimitive() || fieldDescription.getType().isArray() || nonNullable.matches(fieldDescription) ? NullValueGuard.NoOp.INSTANCE : new NullValueGuard.UsingJump(instrumentedMethod); stackManipulations.add(nullValueGuard.before()); stackManipulations.add(ValueTransformer.of(fieldDescription.getType())); stackManipulations.add(Addition.INTEGER); stackManipulations.add(nullValueGuard.after()); padding = Math.max(padding, nullValueGuard.getRequiredVariablePadding()); } stackManipulations.add(MethodReturn.INTEGER); return new Size(new StackManipulation.Compound(stackManipulations).apply(methodVisitor, implementationContext).getMaximalSize(), instrumentedMethod.getStackSize() + padding); } }
/** * 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 fieldRead(MethodVisitor methodVisitor) { methodVisitor.visitMethodInsn( Opcodes.INVOKESPECIAL, managedCtClass.getSuperClass().asErasure().getInternalName(), EnhancerConstants.PERSISTENT_FIELD_READER_PREFIX + persistentFieldAsDefined.getName(), Type.getMethodDescriptor( Type.getType( persistentFieldAsDefined.getType().asErasure().getDescriptor() ) ), false ); }
@Override protected void fieldWrite(MethodVisitor methodVisitor) { methodVisitor.visitMethodInsn( Opcodes.INVOKESPECIAL, managedCtClass.getSuperClass().asErasure().getInternalName(), EnhancerConstants.PERSISTENT_FIELD_WRITER_PREFIX + persistentFieldAsDefined.getName(), Type.getMethodDescriptor( Type.getType( void.class ), Type.getType( persistentFieldAsDefined.getType().asErasure().getDescriptor() ) ), false ); } }
@Override protected void fieldWrite(MethodVisitor methodVisitor) { methodVisitor.visitMethodInsn( Opcodes.INVOKESPECIAL, managedCtClass.getSuperClass().asErasure().getInternalName(), EnhancerConstants.PERSISTENT_FIELD_WRITER_PREFIX + persistentFieldAsDefined.getName(), Type.getMethodDescriptor( Type.getType( void.class ), Type.getType( persistentFieldAsDefined.getType().asErasure().getDescriptor() ) ), false ); } }
@Override protected void fieldRead(MethodVisitor methodVisitor) { methodVisitor.visitMethodInsn( Opcodes.INVOKESPECIAL, managedCtClass.getSuperClass().asErasure().getInternalName(), EnhancerConstants.PERSISTENT_FIELD_READER_PREFIX + persistentFieldAsDefined.getName(), Type.getMethodDescriptor( Type.getType( persistentFieldAsDefined.getType().asErasure().getDescriptor() ) ), false ); }
/** * Creates a field access representation for a given field. If the field's return type derives from its declared shape, the value * is additionally casted to the generically resolved field. * * @param fieldDescription The field to be accessed. * @return A field access definition for the given field. */ public static Defined forField(FieldDescription fieldDescription) { FieldDescription.InDefinedShape declaredField = fieldDescription.asDefined(); return fieldDescription.getType().asErasure().equals(declaredField.getType().asErasure()) ? forField(declaredField) : OfGenericField.of(fieldDescription, forField(declaredField)); }
/** * 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())); }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { methodVisitor.visitFieldInsn(getOpcode(), fieldDescription.getDeclaringType().getInternalName(), fieldDescription.getInternalName(), fieldDescription.getDescriptor()); return resolveSize(fieldDescription.getType().getStackSize()); }
/** * 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()); }
/** * {@inheritDoc} */ public StackManipulation toStackManipulation(MethodDescription invokedMethod, Assigner assigner, Assigner.Typing typing) { StackManipulation stackManipulation = assigner.assign(fieldDescription.getType(), invokedMethod.getDeclaringType().asGenericType(), typing); if (!stackManipulation.isValid()) { throw new IllegalStateException("Cannot invoke " + invokedMethod + " on " + fieldDescription); } return new StackManipulation.Compound( FieldAccess.forField(fieldDescription).read(), stackManipulation ); }
/** * {@inheritDoc} */ public TypeDescription getTypeDescription() { return fieldDescription.getType().asErasure(); }