/** * {@inheritDoc} */ public TypeDescription getNestHost() { return nestHost.represents(TargetType.class) ? this : nestHost; }
/** * {@inheritDoc} */ public <T extends Enum<T>> T load(Class<T> type) { if (!enumerationType.represents(type)) { throw new IllegalArgumentException(type + " does not represent " + enumerationType); } return Enum.valueOf(type, value); } }
/** * {@inheritDoc} */ public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) { for (AnnotationDescription annotation : this) { if (annotation.getAnnotationType().represents(annotationType)) { return true; } } return false; }
/** * {@inheritDoc} */ public <T extends Annotation> Loadable<T> prepare(Class<T> annotationType) { if (!this.annotationType.represents(annotationType)) { throw new IllegalArgumentException(annotationType + " does not represent " + this.annotationType); } return new Loadable<T>(typePool, annotationType, values); }
/** * {@inheritDoc} */ public <T extends Annotation> Loadable<T> prepare(Class<T> annotationType) { if (!this.annotationType.represents(annotationType)) { throw new IllegalArgumentException(annotationType + " does not represent " + this.annotationType); } return new Loadable<T>(annotationType); }
/** * Resolves an appropriate suppression handler. * * @param suppressedType The suppressed type or {@link NoExceptionHandler} if no type should be suppressed. * @return An appropriate suppression handler. */ protected static SuppressionHandler of(TypeDescription suppressedType) { return suppressedType.represents(NoExceptionHandler.class) ? NoOp.INSTANCE : new Suppressing(suppressedType); }
/** * {@inheritDoc} */ public boolean represents(java.lang.reflect.Type type) { return asErasure().represents(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); } }
/** * 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.isInterface()) { throw new IllegalStateException("Cannot assign proxy to " + typeDescription); } else { return new ForType(typeDescription); } }
/** * {@inheritDoc} */ @SuppressWarnings("unchecked") public <T extends Annotation> AnnotationDescription.Loadable<T> ofType(Class<T> annotationType) { for (AnnotationDescription annotation : this) { if (annotation.getAnnotationType().represents(annotationType)) { return annotation.prepare(annotationType); } } return (AnnotationDescription.Loadable<T>) AnnotationDescription.UNDEFINED; }
@Override protected Generic doBuild() { if (typeDescription.represents(void.class) && !annotations.isEmpty()) { throw new IllegalArgumentException("The void non-type cannot be annotated"); } return new Generic.OfNonGenericType.Latent(typeDescription, ownerType, new Explicit(annotations)); } }
@Override protected FieldLocator fieldLocator(TypeDescription instrumentedType) { if (!declaringType.represents(TargetType.class) && !instrumentedType.isAssignableTo(declaringType)) { throw new IllegalStateException(declaringType + " is no super type of " + instrumentedType); } return new FieldLocator.ForExactType(TargetType.resolve(declaringType, instrumentedType)); } }
/** * {@inheritDoc} */ public TypeList getNestMembers() { return nestHost.represents(TargetType.class) ? new TypeList.Explicit(CompoundList.of(this, nestMembers)) : nestHost.getNestMembers(); }
@Override public boolean isOverridden(Object instance, Method origin) { SoftReference<MethodGraph> reference = graphs.get(instance.getClass()); MethodGraph methodGraph = reference == null ? null : reference.get(); if (methodGraph == null) { methodGraph = compiler.compile(new TypeDescription.ForLoadedType(instance.getClass())); graphs.put(instance.getClass(), new SoftReference<MethodGraph>(methodGraph)); } MethodGraph.Node node = methodGraph.locate(new MethodDescription.ForLoadedMethod(origin).asSignatureToken()); return !node.getSort().isResolved() || !node.getRepresentative().asDefined().getDeclaringType().represents(origin.getDeclaringClass()); }
/** * Resolves the given type description to the supplied target type if it represents the {@link TargetType} placeholder. * Array types are resolved to their component type and rebuilt as an array of the actual target type, if necessary. * * @param typeDescription The type description that might represent the {@link TargetType} placeholder. * @param targetType The actual target type. * @return A description of the resolved type. */ public static TypeDescription resolve(TypeDescription typeDescription, TypeDescription targetType) { int arity = 0; TypeDescription componentType = typeDescription; while (componentType.isArray()) { componentType = componentType.getComponentType(); arity++; } return componentType.represents(TargetType.class) ? TypeDescription.ArrayProjection.of(targetType, arity) : typeDescription; }
/** * {@inheritDoc} */ public Boolean onParameterizedType(Generic parameterizedType) { if (typeDescription.equals(parameterizedType.asErasure())) { return true; } Generic superClass = parameterizedType.getSuperClass(); if (superClass != null && isAssignableFrom(superClass)) { return true; } for (Generic interfaceType : parameterizedType.getInterfaces()) { if (isAssignableFrom(interfaceType)) { return true; } } return typeDescription.represents(Object.class); }
/** * Resolves an appropriate offset mapping factory for the {@link Thrown} parameter annotation. * * @param adviceMethod The exit advice method, annotated with {@link OnMethodExit}. * @return An appropriate offset mapping factory. */ @SuppressWarnings("unchecked") // In absence of @SafeVarargs protected static OffsetMapping.Factory<?> of(MethodDescription.InDefinedShape adviceMethod) { return adviceMethod.getDeclaredAnnotations() .ofType(OnMethodExit.class) .getValue(ON_THROWABLE) .resolve(TypeDescription.class) .represents(NoExceptionHandler.class) ? new OffsetMapping.Factory.Illegal<Thrown>(Thrown.class) : Factory.INSTANCE; }
/** * {@inheritDoc} */ public Boolean onGenericArray(Generic genericArray) { return typeDescription.isArray() ? genericArray.getComponentType().accept(new ForNonGenericType(typeDescription.getComponentType())) : typeDescription.represents(Object.class) || TypeDescription.ARRAY_INTERFACES.contains(typeDescription.asGenericType()); }
/** * {@inheritDoc} */ public StackManipulation virtual(TypeDescription invocationTarget) { if (methodDescription.isConstructor() || methodDescription.isStatic()) { return Illegal.INSTANCE; } else if (methodDescription.isPrivate()) { return methodDescription.getDeclaringType().equals(invocationTarget) ? this : Illegal.INSTANCE; } else if (invocationTarget.isInterface()) { return methodDescription.getDeclaringType().represents(Object.class) ? this : INTERFACE.new Invocation(methodDescription, invocationTarget); } else { return VIRTUAL.new Invocation(methodDescription, invocationTarget); } }
/** * {@inheritDoc} */ public OffsetMapping make(ParameterDescription.InDefinedShape target, AnnotationDescription.Loadable<FieldValue> annotation, AdviceType adviceType) { if (adviceType.isDelegation() && !annotation.getValue(ForField.READ_ONLY).resolve(Boolean.class)) { throw new IllegalStateException("Cannot write to field for " + target + " in read-only context"); } else { TypeDescription declaringType = annotation.getValue(DECLARING_TYPE).resolve(TypeDescription.class); return declaringType.represents(void.class) ? new WithImplicitType(target.getType(), annotation) : new WithExplicitType(target.getType(), annotation, declaringType); } } }