Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package org.osgl.inject;
import org.osgl.$;
import org.osgl.inject.annotation.*;
import org.osgl.inject.util.AnnotationUtil;
import org.osgl.util.AnnotationAware;
import org.osgl.util.C;
import org.osgl.util.E;
import org.osgl.util.S;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import java.lang.annotation.Annotation;
import java.lang.reflect.*;
import java.util.*;
/**
* Specification of a bean to be injected
*/
public class BeanSpec implements AnnotationAware {
private final Injector injector;
private final int hc;
private final Type type;
private final boolean isArray;
private final Set elementLoaders = C.newSet();
private final Set filters = C.newSet();
private final Set transformers = C.newSet();
private final Set qualifiers = C.newSet();
private final Set postProcessors = C.newSet();
// only applied when bean spec constructed from Field
private final int modifiers;
/**
* The annotations will be used for calculating the hashCode and do
* equality test. The following annotations will added into
* the list:
* * {@link #elementLoaders}
* * {@link #filters}
* * {@link #qualifiers}
* * {@link #valueLoader}
* * {@link #postProcessors}
*/
private final Map, Annotation> annotations = new HashMap, Annotation>();
/**
* Stores all annotations including the ones that participating hashCode calculating and
* those who don't
* equality test
* @see #annotations
*/
private final Map, Annotation> allAnnotations = new HashMap, Annotation>();
private final Set annoData = new HashSet();
/**
* Store the name value of Named annotation if presented
*/
private String name;
private MapKey mapKey;
private Class extends Annotation> scope;
private Annotation valueLoader;
private List typeParams;
/**
* Construct the `BeanSpec` with bean type and field or parameter
* annotations
*
* @param type the type of the bean to be instantiated
* @param annotations the annotation tagged on field or parameter,
* or `null` if this is a direct API injection
* request
* @param name optional, the name coming from the Named qualifier
* @param injector the injector instance
* @param modifiers the modifiers
*/
private BeanSpec(Type type, Annotation[] annotations, String name, Injector injector, int modifiers) {
this.injector = injector;
this.type = type;
this.name = name;
this.isArray = rawType().isArray();
this.resolveTypeAnnotations();
this.resolveAnnotations(annotations);
this.hc = calcHashCode();
this.modifiers = modifiers;
}
private BeanSpec(BeanSpec source, Type convertTo) {
this.name = source.name;
this.injector = source.injector;
this.type = convertTo;
this.isArray = rawType().isArray();
this.qualifiers.addAll(source.qualifiers);
this.elementLoaders.addAll(source.elementLoaders);
this.filters.addAll(source.filters);
this.transformers.addAll(source.transformers);
this.valueLoader = source.valueLoader;
this.annotations.putAll(source.annotations);
this.annoData.addAll(source.annoData);
this.allAnnotations.putAll(source.allAnnotations);
this.hc = calcHashCode();
this.modifiers = source.modifiers;
}
private BeanSpec(BeanSpec source, String name) {
this.name = name;
this.injector = source.injector;
this.type = source.type;
this.isArray = rawType().isArray();
this.qualifiers.addAll(source.qualifiers);
this.elementLoaders.addAll(source.elementLoaders);
this.filters.addAll(source.filters);
this.transformers.addAll(source.transformers);
this.valueLoader = source.valueLoader;
this.annotations.putAll(source.annotations);
this.annoData.addAll(source.annoData);
this.allAnnotations.putAll(source.allAnnotations);
this.hc = calcHashCode();
this.modifiers = source.modifiers;
}
@Override
public int hashCode() {
return hc;
}
/**
* A bean spec equals to another bean spec if all of the following conditions are met:
* * the {@link #type} of the two bean spec equals to each other
* * the {@link #annotations} of the two bean spec equals to each other
*
* Specifically, {@link #scope} does not participate comparison because
* 1. Scope annotations shall be put onto {@link java.lang.annotation.ElementType#TYPE type},
* or the factory method with {@link Provides} annotation, which is equivalent to `Type`.
* So it is safe to ignore scope annotation because one type cannot be annotated with different
* scope
* 2. If we count scope annotation in equality test, we will never be able to get the correct
* provider stem from the factory methods.
*
* @param obj the object to compare with this object
* @return `true` if the two objects equals as per described above
*/
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof BeanSpec) {
BeanSpec that = (BeanSpec) obj;
return that.hc == hc
&& $.eq(type, that.type)
&& $.eq(name, that.name)
&& $.eq(annoData, that.annoData);
}
return false;
}
@Override
public String toString() {
StringBuilder sb = S.builder(type());
if (S.notBlank(name)) {
sb.append("(").append(name).append(")");
}
C.List