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

com.fasterxml.classmate.AnnotationOverrides Maven / Gradle / Ivy

Go to download

Library for introspecting types with full generic information including resolving of field and method types.

There is a newer version: 1.7.0
Show newest version
package com.fasterxml.classmate;

import java.util.*;

import com.fasterxml.classmate.util.ClassKey;

/**
 * Interface for object that can provide mix-ins to override annotations.
 */
public abstract class AnnotationOverrides
{
    /*
    /**********************************************************************
    /* Public API
    /**********************************************************************
     */

    /**
     * Method called to find out which class(es) are to be used as source
     * for annotations to mix in for given type.
     * 
     * @return List of mix-in sources (starting with  highest priority); 
     *   can be null or empty list if no mix-ins are to be used.
     */
    public List> mixInsFor(Class beanClass) {
        return mixInsFor(new ClassKey(beanClass));
    }

    public abstract List> mixInsFor(ClassKey beanClass);

    /**
     * Method for constructing builder for creating simple overrides provider
     * that just uses direct assignments (target-to-override classes)
     */
    public static StdBuilder builder() {
        return new StdBuilder();
    }

    /*
    /**********************************************************************
    /* Helper types
    /**********************************************************************
     */
    
    /**
     * To make it easy to use simple override implementation (where overrides
     * are direct and explicit), here is a build that allow constructing
     * such override instance.
     */
    public static class StdBuilder
    {
        protected final HashMap>> _targetsToOverrides = new HashMap>>();

        public StdBuilder() { }

        public StdBuilder add(Class target, Class mixin) {
            return add(new ClassKey(target), mixin);
        }

        public StdBuilder add(ClassKey target, Class mixin)
        {
            List> mixins = _targetsToOverrides.get(target);
            if (mixins == null) {
                mixins = new ArrayList>();
                _targetsToOverrides.put(target, mixins);
            }
            mixins.add(mixin);
            return this;
        }
        
        /**
         * Method that will construct a {@link AnnotationOverrides} instance using
         * mappings that have been added using this builder
         */
        public AnnotationOverrides build() {
            return new StdImpl(_targetsToOverrides);
        }
    }
    
    /**
     * Simple implementation configured with explicit associations with
     * target class as key, and overrides as ordered list of classes
     * (with first entry having precedence over later ones).
     */
    public static class StdImpl extends AnnotationOverrides
    {
        protected final HashMap>> _targetsToOverrides;
        
        public StdImpl(HashMap>> overrides) {
            _targetsToOverrides = new HashMap>>(overrides);
        }

        @Override
        public List> mixInsFor(ClassKey target) {
            return _targetsToOverrides.get(target);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy