/** * {@inheritDoc} */ public Generic getComponentType() { Class<?> componentType = type.getComponentType(); return componentType == null ? Generic.UNDEFINED : new ForLoadedType(componentType, annotationReader.ofComponentType()); }
TypeDescription.Generic.OBJECT, Collections.<ParameterDescription.Token>emptyList(), Collections.singletonList(TypeDescription.Generic.OfNonGenericType.ForLoadedType.of(Exception.class)), Collections.<AnnotationDescription>emptyList(), AnnotationValue.UNDEFINED,
PrimitiveUnboxingDelegate.forReferenceType( TypeDescription.Generic.OBJECT ) .assignUnboxedTo( new TypeDescription.Generic.OfNonGenericType.ForLoadedType( setter.getParameterTypes()[0] ), ReferenceTypeAwareAssigner.INSTANCE, Assigner.Typing.DYNAMIC
PrimitiveUnboxingDelegate.forReferenceType( TypeDescription.Generic.OBJECT ) .assignUnboxedTo( new TypeDescription.Generic.OfNonGenericType.ForLoadedType( setter.getParameterTypes()[0] ), ReferenceTypeAwareAssigner.INSTANCE, Assigner.Typing.DYNAMIC
/** * Describes the generic type while using the supplied annotation reader for resolving type annotations if this * language feature is available on the current JVM. * * @param type The type to describe. * @param annotationReader The annotation reader for extracting type annotations. * @return A description of the provided generic annotated type. */ protected static TypeDescription.Generic describe(Type type, TypeDescription.Generic.AnnotationReader annotationReader) { if (type instanceof Class<?>) { return new TypeDescription.Generic.OfNonGenericType.ForLoadedType((Class<?>) type, annotationReader); } else if (type instanceof GenericArrayType) { return new TypeDescription.Generic.OfGenericArray.ForLoadedType((GenericArrayType) type, annotationReader); } else if (type instanceof ParameterizedType) { return new TypeDescription.Generic.OfParameterizedType.ForLoadedType((ParameterizedType) type, annotationReader); } else if (type instanceof TypeVariable) { return new TypeDescription.Generic.OfTypeVariable.ForLoadedType((TypeVariable<?>) type, annotationReader); } else if (type instanceof WildcardType) { return new TypeDescription.Generic.OfWildcardType.ForLoadedType((WildcardType) type, annotationReader); } else { throw new IllegalArgumentException("Unknown type: " + type); } }
/** * Creates a new java type representation. * * @param typeName The binary name of this type. * @param modifiers The modifiers of this type when creating a stub. * @param superClass The super class of this type when creating a stub. * @param interfaces The interfaces of this type when creating a stub. */ JavaType(String typeName, int modifiers, Class<?> superClass, Class<?>... interfaces) { TypeDescription typeDescription; try { typeDescription = TypeDescription.ForLoadedType.of(Class.forName(typeName)); } catch (Exception ignored) { typeDescription = new TypeDescription.Latent(typeName, modifiers, TypeDescription.Generic.OfNonGenericType.ForLoadedType.of(superClass), new TypeList.Generic.ForLoadedTypes(interfaces)); } this.typeDescription = typeDescription; }
/** * Invokes the specified method on the given instance. * * @param target The object on which the method is to be invoked upon. * @param type The object's type. * @param <T> The type of the object. * @return A method call that invokes the provided method on the given object. */ public <T> MethodCall on(T target, Class<? super T> type) { return new MethodCall(methodLocator, new TargetHandler.ForValue.Factory(target, TypeDescription.Generic.OfNonGenericType.ForLoadedType.of(type)), argumentLoaders, new MethodInvoker.ForVirtualInvocation.Factory(TypeDescription.ForLoadedType.of(type)), terminationHandler, assigner, typing); }
/** * Creates a new static field fixed value implementation. * * @param fieldName The name of the field for storing the fixed value. * @param value The fixed value to be returned. * @param assigner The assigner to use for assigning the fixed value to the return type of the * instrumented value. * @param typing Indicates if dynamic type castings should be attempted for incompatible assignments. */ private ForValue(Assigner assigner, Assigner.Typing typing, String fieldName, Object value) { super(assigner, typing); this.fieldName = fieldName; this.value = value; fieldType = TypeDescription.Generic.OfNonGenericType.ForLoadedType.of(value.getClass()); }
/** * {@inheritDoc} */ public Generic getSuperClass() { if (RAW_TYPES) { return type.getSuperclass() == null ? TypeDescription.Generic.UNDEFINED : Generic.OfNonGenericType.ForLoadedType.of(type.getSuperclass()); } return type.getSuperclass() == null ? TypeDescription.Generic.UNDEFINED : new Generic.LazyProjection.ForLoadedSuperClass(type); }
/** * {@inheritDoc} */ public Generic asGenericType() { return Generic.OfNonGenericType.ForLoadedType.of(type); }
@Override @CachedReturnPlugin.Enhance("resolved") protected Generic resolve() { java.lang.reflect.Type[] type = method.getGenericParameterTypes(); return erasure.length == type.length ? Sort.describe(type[index], getAnnotationReader()) : OfNonGenericType.ForLoadedType.of(erasure[index]); }
@Override @CachedReturnPlugin.Enhance("delegate") protected Generic resolve() { java.lang.reflect.Type[] type = constructor.getGenericParameterTypes(); return erasure.length == type.length ? Sort.describe(type[index], getAnnotationReader()) : OfNonGenericType.ForLoadedType.of(erasure[index]); }
/** * {@inheritDoc} */ public TypeDescription.Generic getType() { if (TypeDescription.AbstractBase.RAW_TYPES) { return TypeDescription.Generic.OfNonGenericType.ForLoadedType.of(parameterType[index]); } return new TypeDescription.Generic.LazyProjection.OfConstructorParameter(constructor, index, parameterType); }
/** * {@inheritDoc} */ public TypeDescription.Generic getType() { if (TypeDescription.AbstractBase.RAW_TYPES) { return TypeDescription.Generic.OfNonGenericType.ForLoadedType.of(parameterType[index]); } return new TypeDescription.Generic.LazyProjection.OfMethodParameter(method, index, parameterType); }
/** * {@inheritDoc} */ public InstrumentedType prepare(InstrumentedType instrumentedType) { return instrumentedType .withField(new FieldDescription.Token(name, Opcodes.ACC_SYNTHETIC | Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, TypeDescription.Generic.OfNonGenericType.ForLoadedType.of(value.getClass()))) .withInitializer(new LoadedTypeInitializer.ForStaticField(name, value)); }
/** * Returns a new immutable generic type description for a loaded type. * * @param type The type to be represented by this generic type description. * @return The generic type description representing the given type. */ public static Generic of(Class<?> type) { Generic typeDescription = TYPE_CACHE.get(type); return typeDescription == null ? new ForLoadedType(type) : typeDescription; }
/** * {@inheritDoc} */ public TypeDescription.Generic getType() { if (TypeDescription.AbstractBase.RAW_TYPES) { return TypeDescription.Generic.OfNonGenericType.ForLoadedType.of(field.getType()); } return new TypeDescription.Generic.LazyProjection.ForLoadedFieldType(field); }
/** * {@inheritDoc} */ public TypeDescription.Generic getReturnType() { if (TypeDescription.AbstractBase.RAW_TYPES) { return TypeDescription.Generic.OfNonGenericType.ForLoadedType.of(method.getReturnType()); } return new TypeDescription.Generic.LazyProjection.ForLoadedReturnType(method); }
/** * {@inheritDoc} */ @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "The implicit field type casting is not understood by Findbugs") public TypeDescription.Generic getType() { if (TypeDescription.AbstractBase.RAW_TYPES) { return TypeDescription.Generic.OfNonGenericType.ForLoadedType.of(executable.getParameterTypes()[index]); } return new TypeDescription.Generic.LazyProjection.OfMethodParameter(executable, index, executable.getParameterTypes()); }
/** * {@inheritDoc} */ @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "The implicit field type casting is not understood by Findbugs") public TypeDescription.Generic getType() { if (TypeDescription.AbstractBase.RAW_TYPES) { return TypeDescription.Generic.OfNonGenericType.ForLoadedType.of(executable.getParameterTypes()[index]); } return new TypeDescription.Generic.LazyProjection.OfConstructorParameter(executable, index, executable.getParameterTypes()); }