/** * Returns a list of type constant load operations for the given list of parameters. * * @param parameterTypes A list of all type descriptions that should be represented as type constant * load operations. * @return A corresponding list of type constant load operations. */ protected static List<StackManipulation> typeConstantsFor(List<TypeDescription> parameterTypes) { List<StackManipulation> typeConstants = new ArrayList<StackManipulation>(parameterTypes.size()); for (TypeDescription parameterType : parameterTypes) { typeConstants.add(ClassConstant.of(parameterType)); } return typeConstants; }
/** * Creates a target for an offset mapping for a type constant. * * @param typeDescription The type constant to represent. * @return A mapping for a type constant. */ public static Target of(TypeDescription typeDescription) { return new ForStackManipulation(ClassConstant.of(typeDescription)); }
/** * {@inheritDoc} */ public Resolved resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, Assigner.Typing typing) { return new Resolved.Simple(ClassConstant.of(typeDescription), TypeDescription.CLASS); }
/** * Returns the given type in form of a loaded type. The value is loaded from the written class's constant pool. * * @param fixedValue The type to return from the method. * @return An implementation for the given {@code value}. */ public static AssignerConfigurable value(TypeDescription fixedValue) { return new ForPoolValue(ClassConstant.of(fixedValue), TypeDescription.CLASS); }
/** * Creates a new factory for binding a type description. * * @param annotationType The annotation type. * @param typeDescription The type to bind. */ public Factory(Class<T> annotationType, TypeDescription typeDescription) { this(annotationType, ClassConstant.of(typeDescription), TypeDescription.CLASS.asGenericType()); }
/** * {@inheritDoc} */ public Composable setsValue(TypeDescription typeDescription) { return setsValue(ClassConstant.of(typeDescription), Class.class); }
/** * Defines the given types to be provided as arguments to the invoked method where the represented types * are stored in the generated class's constant pool. * * @param typeDescription The type descriptions to provide as arguments. * @return A method call that hands the provided arguments to the invoked method. */ public MethodCall with(TypeDescription... typeDescription) { List<ArgumentLoader.Factory> argumentLoaders = new ArrayList<ArgumentLoader.Factory>(typeDescription.length); for (TypeDescription aTypeDescription : typeDescription) { argumentLoaders.add(new ArgumentLoader.ForStackManipulation(ClassConstant.of(aTypeDescription), Class.class)); } return with(argumentLoaders); }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Context implementationContext, MethodDescription instrumentedMethod) { return ForOriginType.this.apply(methodVisitor, implementationContext, instrumentedMethod, TypeDescription.CLASS.asGenericType(), ClassConstant.of(originType)); } }
/** * {@inheritDoc} */ public StackManipulation toStackManipulation(ParameterDescription target, Assigner assigner, Assigner.Typing typing) { StackManipulation stackManipulation = new StackManipulation.Compound( ClassConstant.of(instrumentedType), assigner.assign(TypeDescription.Generic.OfNonGenericType.ForLoadedType.CLASS, target.getType(), typing)); if (!stackManipulation.isValid()) { throw new IllegalStateException("Cannot assign Class value to " + target); } return stackManipulation; }
/** * {@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); } }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext, MethodDescription instrumentedMethod) { try { return new ByteCodeAppender.Simple(new StackManipulation.Compound( MethodInvocation.invoke(new MethodDescription.ForLoadedMethod(ClassLoader.class.getMethod("getSystemClassLoader"))), new TextConstant(Nexus.class.getName()), MethodInvocation.invoke(new MethodDescription.ForLoadedMethod(ClassLoader.class.getMethod("loadClass", String.class))), new TextConstant("initialize"), ArrayFactory.forType(TypeDescription.Generic.CLASS) .withValues(Arrays.asList( ClassConstant.of(TypeDescription.CLASS), ClassConstant.of(TypeDescription.ForLoadedType.of(int.class)))), MethodInvocation.invoke(new MethodDescription.ForLoadedMethod(Class.class.getMethod("getMethod", String.class, Class[].class))), NullConstant.INSTANCE, ArrayFactory.forType(TypeDescription.Generic.OBJECT) .withValues(Arrays.asList( ClassConstant.of(instrumentedMethod.getDeclaringType().asErasure()), new StackManipulation.Compound( IntegerConstant.forValue(identification), MethodInvocation.invoke(new MethodDescription.ForLoadedMethod(Integer.class.getMethod("valueOf", int.class)))))), MethodInvocation.invoke(new MethodDescription.ForLoadedMethod(Method.class.getMethod("invoke", Object.class, Object[].class))), Removal.SINGLE )).apply(methodVisitor, implementationContext, instrumentedMethod); } catch (NoSuchMethodException exception) { throw new IllegalStateException("Cannot locate method", exception); } } }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { return new Compound( ClassConstant.of(methodDescription.getDeclaringType()), methodName(), ArrayFactory.forType(TypeDescription.Generic.OfNonGenericType.CLASS) .withValues(typeConstantsFor(methodDescription.getParameters().asTypeList().asErasures())), MethodInvocation.invoke(accessorMethod()) ).apply(methodVisitor, implementationContext); }
TypeDescription parameterType = target.getType().asErasure(); if (parameterType.represents(Class.class)) { return new MethodDelegationBinder.ParameterBinding.Anonymous(ClassConstant.of(implementationTarget.getOriginType().asErasure())); } else if (parameterType.represents(Method.class)) { return source.isMethod()
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { TypeDescription auxiliaryType = implementationContext.register(PrivilegedMemberLookupAction.of(methodDescription)); return new Compound( TypeCreation.of(auxiliaryType), Duplication.SINGLE, ClassConstant.of(methodDescription.getDeclaringType()), methodName, ArrayFactory.forType(TypeDescription.Generic.OfNonGenericType.CLASS) .withValues(typeConstantsFor(methodDescription.getParameters().asTypeList().asErasures())), MethodInvocation.invoke(auxiliaryType.getDeclaredMethods().filter(isConstructor()).getOnly()), MethodInvocation.invoke(DO_PRIVILEGED), TypeCasting.to(TypeDescription.ForLoadedType.of(methodDescription.isConstructor() ? Constructor.class : Method.class)) ).apply(methodVisitor, implementationContext); }
TypeCreation.of(serializedLambda), Duplication.SINGLE, ClassConstant.of(targetType), new TextConstant(lambdaType.getInternalName()), new TextConstant(lambdaMethodName),
return setsValue(new TextConstant((String) value), String.class); } else if (type == Class.class) { return setsValue(ClassConstant.of(TypeDescription.ForLoadedType.of((Class<?>) value)), Class.class); } else if (type == Boolean.class) { return setsValue(IntegerConstant.forValue((Boolean) value), boolean.class);
suppliedType = TypeDescription.STRING; } else if (value instanceof Class) { stackManipulation = ClassConstant.of(TypeDescription.ForLoadedType.of((Class<?>) value)); suppliedType = TypeDescription.CLASS; } else if (value instanceof TypeDescription) { stackManipulation = ClassConstant.of((TypeDescription) value); suppliedType = TypeDescription.CLASS; } else if (JavaType.METHOD_HANDLE.getTypeStub().isInstance(value)) {
return new ForPoolValue(new TextConstant((String) fixedValue), TypeDescription.STRING); } else if (type == Class.class) { return new ForPoolValue(ClassConstant.of(TypeDescription.ForLoadedType.of((Class<?>) fixedValue)), TypeDescription.CLASS); } else if (type == Boolean.class) { return new ForPoolValue(IntegerConstant.forValue((Boolean) fixedValue), boolean.class);
return new ForStackManipulation(DoubleConstant.forValue((Double) value), double.class); } else if (value instanceof Class) { return new ForStackManipulation(ClassConstant.of(TypeDescription.ForLoadedType.of((Class<?>) value)), Class.class); } else if (JavaType.METHOD_HANDLE.getTypeStub().isInstance(value)) { return new ForStackManipulation(new JavaConstantValue(JavaConstant.MethodHandle.ofLoaded(value)), JavaType.METHOD_HANDLE.getTypeStub());
private List<StackManipulation> loadSignatureParametersClasess() { List<StackManipulation> constructorSignature = new ArrayList<StackManipulation>(); for (InDefinedShape targetParameter : targetParameters) { constructorSignature.add( ClassConstant.of(targetParameter.getType().asErasure()) ); } return constructorSignature; }