All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.elopteryx.reflect.BeanMirror Maven / Gradle / Ivy

package com.github.elopteryx.reflect;

import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
import java.util.Objects;

/**
 * The entry point for creating mirror instances.
 * They can be created from a plain object or from a class type.
 * The class instances are immutable.
 */
public final class BeanMirror {

    private BeanMirror() {
        // No need to instantiate.
        throw new UnsupportedOperationException();
    }

    /**
     * Creates a new mirror instance, wrapping the given object.
     * @param object The object to be wrapped
     * @param  The generic type
     * @return A new mirror instance
     */
    public static  ObjectMirror of(T object) {
        return of(object, MethodHandles.lookup());
    }

    /**
     * Creates a new mirror instance, wrapping the given object.
     * @param object The object to be wrapped
     * @param lookup User-supplied lookup for access check
     * @param  The generic type
     * @return A new mirror instance
     */
    public static  ObjectMirror of(T object, Lookup lookup) {
        Objects.requireNonNull(object);
        Objects.requireNonNull(lookup);
        return new ObjectMirror<>(object, null, lookup);
    }

    /**
     * Creates a new mirror instance, wrapping the given class object.
     * @param clazz The class to be wrapped
     * @param  The generic type
     * @return A new mirror instance
     */
    public static  ClassMirror of(Class clazz) {
        return of(clazz, MethodHandles.lookup());
    }

    /**
     * Creates a new mirror instance, wrapping the given class object.
     * @param clazz The class to be wrapped
     * @param lookup User-supplied lookup for access check
     * @param  The generic type
     * @return A new mirror instance
     */
    public static  ClassMirror of(Class clazz, Lookup lookup) {
        Objects.requireNonNull(clazz);
        Objects.requireNonNull(lookup);
        return new ClassMirror<>(clazz, lookup);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy