/** * Return the primary constructor of the provided class. For Kotlin classes, this * returns the Java constructor corresponding to the Kotlin primary constructor * (as defined in the Kotlin specification). Otherwise, in particular for non-Kotlin * classes, this simply returns {@code null}. * @param clazz the class to check * @since 5.0 * @see <a href="http://kotlinlang.org/docs/reference/classes.html#constructors">Kotlin docs</a> */ @SuppressWarnings("unchecked") @Nullable public static <T> Constructor<T> findPrimaryConstructor(Class<T> clazz) { Assert.notNull(clazz, "Class must not be null"); if (KotlinDetector.isKotlinReflectPresent() && KotlinDetector.isKotlinType(clazz)) { Constructor<T> kotlinPrimaryConstructor = KotlinDelegate.findPrimaryConstructor(clazz); if (kotlinPrimaryConstructor != null) { return kotlinPrimaryConstructor; } } return null; }
/** * Return whether this method indicates a parameter which is not required: * either in the form of Java 8's {@link java.util.Optional}, any variant * of a parameter-level {@code Nullable} annotation (such as from JSR-305 * or the FindBugs set of annotations), or a language-level nullable type * declaration in Kotlin. * @since 4.3 */ public boolean isOptional() { return (getParameterType() == Optional.class || hasNullableAnnotation() || (KotlinDetector.isKotlinReflectPresent() && KotlinDetector.isKotlinType(getContainingClass()) && KotlinDelegate.isOptional(this))); }
/** * Return whether this dependency is required. * <p>Optional semantics are derived from Java 8's {@link java.util.Optional}, * any variant of a parameter-level {@code Nullable} annotation (such as from * JSR-305 or the FindBugs set of annotations), or a language-level nullable * type declaration in Kotlin. */ public boolean isRequired() { if (!this.required) { return false; } if (this.field != null) { return !(this.field.getType() == Optional.class || hasNullableAnnotation() || (KotlinDetector.isKotlinReflectPresent() && KotlinDetector.isKotlinType(this.field.getDeclaringClass()) && KotlinDelegate.isNullable(this.field))); } else { return !obtainMethodParameter().isOptional(); } }
/** * Return the primary constructor of the provided class. For Kotlin classes, this * returns the Java constructor corresponding to the Kotlin primary constructor * (as defined in the Kotlin specification). Otherwise, in particular for non-Kotlin * classes, this simply returns {@code null}. * @param clazz the class to check * @since 5.0 * @see <a href="http://kotlinlang.org/docs/reference/classes.html#constructors">Kotlin docs</a> */ @SuppressWarnings("unchecked") @Nullable public static <T> Constructor<T> findPrimaryConstructor(Class<T> clazz) { Assert.notNull(clazz, "Class must not be null"); if (KotlinDetector.isKotlinReflectPresent() && KotlinDetector.isKotlinType(clazz)) { Constructor<T> kotlinPrimaryConstructor = KotlinDelegate.findPrimaryConstructor(clazz); if (kotlinPrimaryConstructor != null) { return kotlinPrimaryConstructor; } } return null; }
try { ReflectionUtils.makeAccessible(ctor); return (KotlinDetector.isKotlinReflectPresent() && KotlinDetector.isKotlinType(ctor.getDeclaringClass()) ? KotlinDelegate.instantiateClass(ctor, args) : ctor.newInstance(args));
/** * Return whether this method indicates a parameter which is not required: * either in the form of Java 8's {@link java.util.Optional}, any variant * of a parameter-level {@code Nullable} annotation (such as from JSR-305 * or the FindBugs set of annotations), or a language-level nullable type * declaration in Kotlin. * @since 4.3 */ public boolean isOptional() { return (getParameterType() == Optional.class || hasNullableAnnotation() || (KotlinDetector.isKotlinReflectPresent() && KotlinDetector.isKotlinType(getContainingClass()) && KotlinDelegate.isOptional(this))); }
try { ReflectionUtils.makeAccessible(ctor); return (KotlinDetector.isKotlinReflectPresent() && KotlinDetector.isKotlinType(ctor.getDeclaringClass()) ? KotlinDelegate.instantiateClass(ctor, args) : ctor.newInstance(args));
public DefaultParameterNameDiscoverer() { if (!GraalDetector.inImageCode()) { if (KotlinDetector.isKotlinReflectPresent()) { addDiscoverer(new KotlinReflectionParameterNameDiscoverer()); } addDiscoverer(new StandardReflectionParameterNameDiscoverer()); addDiscoverer(new LocalVariableTableParameterNameDiscoverer()); } }
/** * Return whether this dependency is required. * <p>Optional semantics are derived from Java 8's {@link java.util.Optional}, * any variant of a parameter-level {@code Nullable} annotation (such as from * JSR-305 or the FindBugs set of annotations), or a language-level nullable * type declaration in Kotlin. */ public boolean isRequired() { if (!this.required) { return false; } if (this.field != null) { return !(this.field.getType() == Optional.class || hasNullableAnnotation() || (KotlinDetector.isKotlinReflectPresent() && KotlinDetector.isKotlinType(this.field.getDeclaringClass()) && KotlinDelegate.isNullable(this.field))); } else { return !obtainMethodParameter().isOptional(); } }
public DefaultParameterNameDiscoverer() { if (!GraalDetector.inImageCode()) { if (KotlinDetector.isKotlinReflectPresent()) { addDiscoverer(new KotlinReflectionParameterNameDiscoverer()); } addDiscoverer(new StandardReflectionParameterNameDiscoverer()); addDiscoverer(new LocalVariableTableParameterNameDiscoverer()); } }
/** * Return whether this method indicates a parameter which is not required: * either in the form of Java 8's {@link java.util.Optional}, any variant * of a parameter-level {@code Nullable} annotation (such as from JSR-305 * or the FindBugs set of annotations), or a language-level nullable type * declaration in Kotlin. * @since 4.3 */ public boolean isOptional() { return (getParameterType() == Optional.class || hasNullableAnnotation() || (KotlinDetector.isKotlinReflectPresent() && KotlinDetector.isKotlinType(getContainingClass()) && KotlinDelegate.isOptional(this))); }
public DefaultParameterNameDiscoverer() { if (!GraalDetector.inImageCode()) { if (KotlinDetector.isKotlinReflectPresent()) { addDiscoverer(new KotlinReflectionParameterNameDiscoverer()); } addDiscoverer(new StandardReflectionParameterNameDiscoverer()); addDiscoverer(new LocalVariableTableParameterNameDiscoverer()); } }