package net.ranides.assira.reflection.impl;

import net.ranides.assira.collection.query.CQuery;
import net.ranides.assira.generic.Ref;
import net.ranides.assira.reflection.*;

import java.lang.annotation.Annotation;

/**
 * Abstract base class for all IElement implementations.
 *
 * It declares mostly helper final methods.
 */
public abstract class AElement implements IElement {

    @Override
    public final boolean attribute(IAttribute attr) {
        return attributes().has(attr);
    }

    @Override
    public final <A extends Annotation> Ref<A> annotation(Class<A> type) {
        return annotations().first(type);
    }

    @Override
    public final <A extends Annotation> CQuery<A> annotations(Class<A> type) {
        return annotations().stream(type);
    }

    @Override
    public final boolean isPublic() {
        return attribute(IAttribute.PUBLIC);
    }

    @Override
    public final boolean isPackage() {
        return attribute(IAttribute.PACKAGE);
    }

    @Override
    public final boolean isPrivate() {
        return attribute(IAttribute.PRIVATE);
    }

    @Override
    public final boolean isProtected() {
        return attribute(IAttribute.PROTECTED);
    }

    @Override
    public final boolean isDeclared() {
        return attribute(IAttribute.DECLARED);
    }

    @Override
    public final boolean isParamaterized() {
        return attribute(IAttribute.PARAMETERIZED);
    }

    @Override
    public final boolean isFinal() {
        return attribute(IAttribute.FINAL);
    }

    @Override
    public final boolean isStatic() {
        return attribute(IAttribute.STATIC);
    }

    @Override
    public final boolean isSynthetic() {
        return attribute(IAttribute.SYNTHETIC);
    }
}
