/** * {@inheritDoc} */ public boolean isPrimitive() { return delegate.isPrimitive(); }
/** * {@inheritDoc} */ public boolean isPrimitive() { return asErasure().isPrimitive(); }
/** * Creates a new instance check. * * @param typeDescription The type to apply the instance check against. * @return An appropriate stack manipulation. */ public static StackManipulation of(TypeDescription typeDescription) { if (typeDescription.isPrimitive()) { throw new IllegalArgumentException("Cannot check an instance against a primitive type: " + typeDescription); } return new InstanceCheck(typeDescription); }
/** * {@inheritDoc} */ public boolean isPrimitive() { return asErasure().isPrimitive(); }
/** * {@inheritDoc} */ public boolean isBridgeCompatible(TypeToken typeToken) { List<TypeDescription> types = getParameters().asTypeList().asErasures(), bridgeTypes = typeToken.getParameterTypes(); if (types.size() != bridgeTypes.size()) { return false; } for (int index = 0; index < types.size(); index++) { if (!types.get(index).equals(bridgeTypes.get(index)) && (types.get(index).isPrimitive() || bridgeTypes.get(index).isPrimitive())) { return false; } } TypeDescription returnType = getReturnType().asErasure(), bridgeReturnType = typeToken.getReturnType(); return returnType.equals(bridgeReturnType) || (!returnType.isPrimitive() && !bridgeReturnType.isPrimitive()); }
/** * Passes {@code null} values of the given types to the bootstrapped method. * * @param typeDescription The type that the {@code null} values should represent. * @return This invoke dynamic implementation where the bootstrapped method is passed the specified arguments. */ public InvokeDynamic withNullValue(TypeDescription... typeDescription) { List<InvocationProvider.ArgumentProvider> argumentProviders = new ArrayList<InvocationProvider.ArgumentProvider>(typeDescription.length); for (TypeDescription aTypeDescription : typeDescription) { if (aTypeDescription.isPrimitive()) { throw new IllegalArgumentException("Cannot assign null to primitive type: " + aTypeDescription); } argumentProviders.add(new InvocationProvider.ArgumentProvider.ForNullValue(aTypeDescription)); } return new InvokeDynamic(bootstrapMethod, handleArguments, invocationProvider.appendArguments(argumentProviders), terminationHandler, assigner, typing); }
/** * Creates a type creation for the given type. * * @param typeDescription The type to be create. * @return A stack manipulation that represents the creation of the given type. */ public static StackManipulation of(TypeDescription typeDescription) { if (typeDescription.isArray() || typeDescription.isPrimitive() || typeDescription.isAbstract()) { throw new IllegalArgumentException(typeDescription + " is not instantiable"); } return new TypeCreation(typeDescription); }
if (type.isArray() || type.isPrimitive()) { throw new IllegalArgumentException("Cannot decorate array or primitive type: " + type);
/** * Resolves a type locator based upon an annotation value. * * @param typeDescription The annotation's value. * @return The appropriate type locator. */ protected static TypeLocator of(TypeDescription typeDescription) { if (typeDescription.represents(void.class)) { return ForParameterType.INSTANCE; } else if (typeDescription.represents(TargetType.class)) { return ForInstrumentedType.INSTANCE; } else if (typeDescription.isPrimitive() || typeDescription.isArray()) { throw new IllegalStateException("Cannot assign proxy to " + typeDescription); } else { return new ForType(typeDescription); } }
/** * Rebases the given type where any intercepted method that is declared by the redefined type is preserved within the * rebased type's class such that the class's original can be invoked from the new method implementations. Rebasing a * type can be seen similarly to creating a subclass where the subclass is later merged with the original class file. * * @param type The type that is being rebased. * @param classFileLocator The class file locator that is queried for the rebased type's class file. * @param methodNameTransformer The method name transformer for renaming a method that is rebased. * @param <T> The loaded type of the rebased type. * @return A type builder for rebasing the provided type. */ public <T> DynamicType.Builder<T> rebase(TypeDescription type, ClassFileLocator classFileLocator, MethodNameTransformer methodNameTransformer) { if (type.isArray() || type.isPrimitive()) { throw new IllegalArgumentException("Cannot rebase array or primitive type: " + type); } return new RebaseDynamicTypeBuilder<T>(instrumentedTypeFactory.represent(type), classFileVersion, auxiliaryTypeNamingStrategy, annotationValueFilterFactory, annotationRetention, implementationContextFactory, methodGraphCompiler, typeValidation, classWriterStrategy, ignoredMethods, type, classFileLocator, methodNameTransformer); }
if (type.isArray() || type.isPrimitive()) { throw new IllegalArgumentException("Cannot redefine array or primitive type: " + type);
TypeDescription rightParameterType = right.getTarget().getParameters().get(rightParameterIndex).getType().asErasure(); if (!leftParameterType.equals(rightParameterType)) { if (leftParameterType.isPrimitive() && rightParameterType.isPrimitive()) { return PrimitiveTypePrecedence.forPrimitive(leftParameterType).resolve(PrimitiveTypePrecedence.forPrimitive(rightParameterType)); } else if (leftParameterType.isPrimitive() /* && !rightParameterType.isPrimitive() */) { return sourceParameterType.isPrimitive() ? Resolution.LEFT : Resolution.RIGHT; } else if (/* !leftParameterType.isPrimitive() && */ rightParameterType.isPrimitive()) { return sourceParameterType.isPrimitive() ? Resolution.RIGHT : Resolution.LEFT; } else {
/** * Delegates any intercepted method to invoke a {@code static} method that is declared by the supplied type. To be considered * a valid delegation target, the target method must be visible and accessible to the instrumented type. This is the case if * the target type is either public or in the same package as the instrumented type and if the target method is either public * or non-private and in the same package as the instrumented type. Private methods can only be used as a delegation target if * the delegation is targeting the instrumented type. * * @param typeDescription The target type for the delegation. * @return A method delegation that redirects method calls to a static method of the supplied type. */ public MethodDelegation to(TypeDescription typeDescription) { if (typeDescription.isArray()) { throw new IllegalArgumentException("Cannot delegate to array " + typeDescription); } else if (typeDescription.isPrimitive()) { throw new IllegalArgumentException("Cannot delegate to primitive " + typeDescription); } return new MethodDelegation(ImplementationDelegate.ForStaticMethod.of(typeDescription.getDeclaredMethods().filter(isStatic().and(matcher)), TargetMethodAnnotationDrivenBinder.of(parameterBinders)), parameterBinders, ambiguityResolver, bindingResolver); }
Object argument = argumentIterator.next(); finalParameterCheck = !((argument instanceof JavaConstant) && ((JavaConstant) argument).getType().isAssignableTo(parameterType)) && !(parameterType.represents(Class.class) && argument instanceof TypeDescription && !((TypeDescription) argument).isPrimitive()) && !(parameterType.represents(String.class) && argument.getClass() == String.class) && !(parameterType.represents(int.class) && argument.getClass() == Integer.class)
/** * Resolves a relocation handler that is triggered if the checked instance is of a given type. * * @param typeDescription The type that triggers a relocation. * @param checkedType The type that is carrying the checked value. * @return An appropriate relocation handler. */ protected static RelocationHandler of(TypeDescription typeDescription, TypeDefinition checkedType) { if (typeDescription.represents(void.class)) { return Disabled.INSTANCE; } else if (typeDescription.represents(OnDefaultValue.class)) { return ForValue.of(checkedType, false); } else if (typeDescription.represents(OnNonDefaultValue.class)) { return ForValue.of(checkedType, true); } else if (typeDescription.isPrimitive() || checkedType.isPrimitive()) { throw new IllegalStateException("Cannot skip method by instance type for primitive return type " + checkedType); } else { return new ForType(typeDescription); } }
/** * Returns a {@link Class} constant for a primitive type. * * @param typeDescription The primitive type to represent. * @return A dynamically resolved primitive type constant. */ public static JavaConstant ofPrimitiveType(TypeDescription typeDescription) { if (!typeDescription.isPrimitive()) { throw new IllegalArgumentException("Not a primitive type: " + typeDescription); } return new Dynamic(new ConstantDynamic(typeDescription.getDescriptor(), TypeDescription.CLASS.getDescriptor(), new Handle(Opcodes.H_INVOKESTATIC, CONSTANT_BOOTSTRAPS, "primitiveClass", "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Class;", false)), TypeDescription.CLASS); }
? JavaConstant.Dynamic.ofPrimitiveType((Class<?>) argument) : TypeDescription.ForLoadedType.of((Class<?>) argument); } else if (argument instanceof TypeDescription && ((TypeDescription) argument).isPrimitive()) { argument = JavaConstant.Dynamic.ofPrimitiveType((TypeDescription) argument); } else if (JavaType.METHOD_HANDLE.getTypeStub().isInstance(argument)) {
/** * Returns a stack manipulation that loads a {@link java.lang.Class} type onto the operand stack which * represents the given type. * * @param typeDescription The type to load onto the operand stack. * @return The corresponding stack manipulation. */ public static StackManipulation of(TypeDescription typeDescription) { if (!typeDescription.isPrimitive()) { return new ForReferenceType(typeDescription); } else if (typeDescription.represents(boolean.class)) { return BOOLEAN; } else if (typeDescription.represents(byte.class)) { return BYTE; } else if (typeDescription.represents(short.class)) { return SHORT; } else if (typeDescription.represents(char.class)) { return CHARACTER; } else if (typeDescription.represents(int.class)) { return INTEGER; } else if (typeDescription.represents(long.class)) { return LONG; } else if (typeDescription.represents(float.class)) { return FLOAT; } else if (typeDescription.represents(double.class)) { return DOUBLE; } else { return VOID; } }
return !targetType.isPrimitive();
/** * {@inheritDoc} */ public ParameterBinding<?> bind(AnnotationDescription.Loadable<S> annotation, MethodDescription source, ParameterDescription target, Implementation.Target implementationTarget, Assigner assigner, Assigner.Typing typing) { if (!declaringType(annotation).represents(void.class)) { if (declaringType(annotation).isPrimitive() || declaringType(annotation).isArray()) { throw new IllegalStateException("A primitive type or array type cannot declare a field: " + source); } else if (!implementationTarget.getInstrumentedType().isAssignableTo(declaringType(annotation))) { return MethodDelegationBinder.ParameterBinding.Illegal.INSTANCE; } } FieldLocator fieldLocator = declaringType(annotation).represents(void.class) ? new FieldLocator.ForClassHierarchy(implementationTarget.getInstrumentedType()) : new FieldLocator.ForExactType(declaringType(annotation), implementationTarget.getInstrumentedType()); FieldLocator.Resolution resolution = fieldName(annotation).equals(BEAN_PROPERTY) ? resolveAccessor(fieldLocator, source) : fieldLocator.locate(fieldName(annotation)); return resolution.isResolved() && !(source.isStatic() && !resolution.getField().isStatic()) ? bind(resolution.getField(), annotation, source, target, implementationTarget, assigner) : ParameterBinding.Illegal.INSTANCE; }