/** * Checks for a hidden implementation, first finding the class by name. * * @param className name of a class * @param fieldName name of a field (different from constructor) * @return this Builder for method chaining * @see java.lang.Class#forName(String) * @see java.lang.Class#getField(String) */ public Builder hiddenImpl(String className, String fieldName) { // don't do any work if an implementation has been found if (field != null) { return this; } try { Class<?> targetClass = Class.forName(className, true, loader); hiddenImpl(targetClass, fieldName); } catch (ClassNotFoundException e) { // not the right implementation candidates.add(className + "." + fieldName); } return this; }
/** * Checks for an implementation, first finding the class by name. * * @param className name of a class * @param fieldName name of the field * @return this Builder for method chaining * @see java.lang.Class#forName(String) * @see java.lang.Class#getField(String) */ public Builder impl(String className, String fieldName) { // don't do any work if an implementation has been found if (field != null) { return this; } try { Class<?> targetClass = Class.forName(className, true, loader); impl(targetClass, fieldName); } catch (ClassNotFoundException e) { // not the right implementation candidates.add(className + "." + fieldName); } return this; }
/** * Returns the first valid implementation as a BoundMethod or throws a * RuntimeException if there is none. * * @param target an Object on which to get and set the field * @param <T> Java class stored in the field * @return a {@link BoundField} with a valid implementation and target * @throws IllegalStateException if the method is static * @throws IllegalArgumentException if the receiver's class is incompatible * @throws RuntimeException if no implementation was found */ public <T> BoundField<T> build(Object target) { return this.<T>build().bind(target); }
public static Builder builder() { return new Builder(); }
/** * Returns the first valid implementation as a BoundMethod or throws a * NoSuchMethodException if there is none. * * @param target an Object on which to get and set the field * @param <T> Java class stored in the field * @return a {@link BoundField} with a valid implementation and target * @throws IllegalStateException if the method is static * @throws IllegalArgumentException if the receiver's class is incompatible * @throws NoSuchFieldException if no implementation was found */ public <T> BoundField<T> buildChecked(Object target) throws NoSuchFieldException { return this.<T>buildChecked().bind(target); }
/** * Returns the first valid implementation as a StaticField or throws a * RuntimeException if there is none. * * @param <T> Java class stored in the field * @return a {@link StaticField} with a valid implementation * @throws IllegalStateException if the method is not static * @throws RuntimeException if no implementation was found */ public <T> StaticField<T> buildStatic() { return this.<T>build().asStatic(); }
/** * Returns the first valid implementation as a StaticField or throws a * NoSuchFieldException if there is none. * * @param <T> Java class stored in the field * @return a {@link StaticField} with a valid implementation * @throws IllegalStateException if the method is not static * @throws NoSuchFieldException if no implementation was found */ public <T> StaticField<T> buildStaticChecked() throws NoSuchFieldException { return this.<T>buildChecked().asStatic(); }