Latke Code View - IOC.annotated

本贴最后更新于 2922 天前,其中的信息可能已经时移俗易

这段代码看起来很少有逻辑上的内容,各种赋值,不是很懂,估计与其他地方有关系,暂做记录

org.b3log.latke.ioc.annotated.AbstractAnnotatedCallableImpl

import org.b3log.latke.util.CollectionUtils;
public abstract class AbstractAnnotatedCallableImpl<T> implements AnnotatedCallable<T> {
    private Member member;
    private List<AnnotatedParameter<T>> parameters;
    public AbstractAnnotatedCallableImpl(final Member member) {
        this.member = member;
        parameters = new ArrayList<AnnotatedParameter<T>>();
        Type[] parameterTypes = null;
        Annotation[][] parameterAnnotations = null;
        if (member instanceof Method) {
            parameterTypes = ((Method) member).getGenericParameterTypes();
            parameterAnnotations = ((Method) member).getParameterAnnotations();
        } else if (member instanceof Constructor) {
            parameterTypes = ((Constructor) member).getGenericParameterTypes();
            parameterAnnotations = ((Constructor) member).getParameterAnnotations();
        }
        for (int i = 0; i < parameterTypes.length; i++) {
            final Type parameter = parameterTypes[i];
            final Annotation[] annotations = parameterAnnotations[i];
            final Set<Annotation> annotationSet = CollectionUtils.arrayToSet(annotations);
            final AnnotatedParameter<T> annotatedParameter = new AnnotatedParameterImpl<T>(this, parameter, i, annotationSet);
            this.parameters.add(annotatedParameter);
        }
    }
    @Override
    public AnnotatedType<T> getDeclaringType() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    @Override
    public List<AnnotatedParameter<T>> getParameters() {
        return parameters;
    }
    @Override
    public boolean isStatic() {
        return Modifier.isStatic(member.getModifiers());
    }    
    //getJavaMember? see:> https://docs.oracle.com/javaee/7/api/toc.htm
    public Member getMember() { 
        return member;
    }
}

org.b3log.latke.ioc.annotated.AnnotatedConstructorImpl

import javax.enterprise.inject.spi.AnnotatedConstructor;
public class AnnotatedConstructorImpl<T> extends AbstractAnnotatedCallableImpl<T> implements
    AnnotatedConstructor<T> {
    public AnnotatedConstructorImpl(final Constructor<T> constructor) {
        super(constructor);
    }
    @Override
    public Constructor<T> getJavaMember() {
        return (Constructor) getMember();
    }
    @Override
    public <T extends Annotation> T getAnnotation(final Class<T> annotationType) {
        return getJavaMember().getAnnotation(annotationType);
    }
    @Override
    public Set<Annotation> getAnnotations() {
        return new HashSet<Annotation>(Arrays.asList(getJavaMember().getAnnotations()));
    }
    @Override
    public boolean isAnnotationPresent(final Class<? extends Annotation> annotationType) {
        return getJavaMember().isAnnotationPresent(annotationType);
    }
    @Override
    public Type getBaseType() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    @Override
    public Set<Type> getTypeClosure() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}

org.b3log.latke.ioc.annotated.AnnotatedFieldImpl

import javax.enterprise.inject.spi.AnnotatedField;
import javax.enterprise.inject.spi.AnnotatedType;
public class AnnotatedFieldImpl<T> implements AnnotatedField<T> {
    private Field field;
    public AnnotatedFieldImpl(final Field field) {
        this.field = field;
    }
    @Override
    public Field getJavaMember() {
        return field;
    }
    @Override
    public AnnotatedType<T> getDeclaringType() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    @Override
    public boolean isStatic() {
        return Modifier.isStatic(field.getModifiers());
    }
    @Override
    public Type getBaseType() {
        return field.getGenericType();
    }
    @Override
    public <T extends Annotation> T getAnnotation(final Class<T> annotationType) {
        return field.getAnnotation(annotationType);
    }
    @Override
    @SuppressWarnings("unchecked")
    public Set<Annotation> getAnnotations() {
        return new HashSet<Annotation>(Arrays.asList(field.getAnnotations()));
    }
    @Override
    public boolean isAnnotationPresent(
        final Class<? extends Annotation> annotationType) {
        return field.isAnnotationPresent(annotationType);
    }
    @Override
    public String toString() {
        return field.getName();
    }
    @Override
    public Set<Type> getTypeClosure() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}

org.b3log.latke.ioc.annotated.AnnotatedMethodImpl

import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.AnnotatedType;
public class AnnotatedMethodImpl<T> extends AbstractAnnotatedCallableImpl<T> implements AnnotatedMethod<T> {
    public AnnotatedMethodImpl(final Method method) {
        super(method);
    }
    @Override
    public Method getJavaMember() {
        return (Method) getMember();
    }
    @Override
    public AnnotatedType<T> getDeclaringType() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    @Override
    public <T extends Annotation> T getAnnotation(final Class<T> annotationType) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    @Override
    public Set<Annotation> getAnnotations() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    @Override
    public boolean isAnnotationPresent(final Class<? extends Annotation> annotationType) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    @Override
    public String toString() {
        return getJavaMember().getName();
    }
    @Override
    public Type getBaseType() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    @Override
    public Set<Type> getTypeClosure() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}

org.b3log.latke.ioc.annotated.AnnotatedParameterImpl

import javax.enterprise.inject.spi.AnnotatedCallable;
import javax.enterprise.inject.spi.AnnotatedParameter;
public class AnnotatedParameterImpl<T> implements AnnotatedParameter<T> {
    private AnnotatedCallable<T> annotatedCallable;
    private Type parameter;
    private int position;
    private Set<Annotation> annotations;
    public AnnotatedParameterImpl(final AnnotatedCallable<T> annotatedCallable,
        final Type parameter, final int position,
        final Set<Annotation> annotations) {
        this.parameter = parameter;
        this.position = position;
        this.annotations = annotations;
        this.annotatedCallable = annotatedCallable;
    }
    @Override
    public int getPosition() {
        return position;
    }
    @Override
    public AnnotatedCallable<T> getDeclaringCallable() {
        return annotatedCallable;
    }
    @Override
    public Type getBaseType() {
        return parameter;
    }
    @Override
    public <T extends Annotation> T getAnnotation(final Class<T> annotationType) {
        return ((Class<T>) parameter).getAnnotation(annotationType);
    }
    @Override
    public Set<Annotation> getAnnotations() {
        return annotations;
    }
    @Override
    public boolean isAnnotationPresent(final Class<? extends Annotation> annotationType) {
        return ((Class<T>) parameter).isAnnotationPresent(annotationType);
    }
    @Override
    public String toString() {
        return parameter.toString() + ", position=" + position;
    }
    @Override
    public Set<Type> getTypeClosure() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
  • B3log

    B3log 是一个开源组织,名字来源于“Bulletin Board Blog”缩写,目标是将独立博客与论坛结合,形成一种新的网络社区体验,详细请看 B3log 构思。目前 B3log 已经开源了多款产品:SymSoloVditor思源笔记

    1063 引用 • 3453 回帖 • 204 关注
  • CodeView
    5 引用 • 5 回帖
  • Latke

    Latke 是一款以 JSON 为主的 Java Web 框架。

    71 引用 • 535 回帖 • 788 关注

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...
  • ZephyrJung

    我转从 Latke-Demo 入手了,纯代码实在不好懂

    1 回复
  • 其他回帖
  • zk123

    应该是继承了 javax.enterprise.inject.spi 中的许多接口,但是百度后全是英文的,所以很棘手,不知从何下手

    1 回复
  • zk123

    是啊,瞬间感觉知识不够用