Search in sources :

Example 1 with AnnotationMirror

use of com.redhat.ceylon.model.loader.mirror.AnnotationMirror in project ceylon-compiler by ceylon.

the class AnnotationLoader method findLiteralAnnotationTerm.

/**
     * Searches the {@code @*Exprs} for one containing a {@code @*Value} 
     * whose {@code name} matches the given namePath returning the first 
     * match, or null.
     */
private LiteralAnnotationTerm findLiteralAnnotationTerm(Module moduleScope, List<AnnotationFieldName> namePath, Parameter parameter, AnnotatedMirror mm) {
    // FIXME: store info somewhere else
    boolean singeValue = !typeFactory.isIterableType(parameter.getType()) || parameter.getType().isString();
    final String name = Naming.getAnnotationFieldName(namePath);
    AnnotationMirror exprsAnnotation = mm.getAnnotation(AbstractModelLoader.CEYLON_STRING_EXPRS_ANNOTATION);
    if (exprsAnnotation != null) {
        for (AnnotationMirror valueAnnotation : getAnnotationAnnoValues(exprsAnnotation, "value")) {
            String path = (String) valueAnnotation.getValue("name");
            if (name.equals(path)) {
                return readStringValuesAnnotation(valueAnnotation, singeValue);
            }
        }
    }
    exprsAnnotation = mm.getAnnotation(AbstractModelLoader.CEYLON_INTEGER_EXPRS_ANNOTATION);
    if (exprsAnnotation != null) {
        for (AnnotationMirror valueAnnotation : getAnnotationAnnoValues(exprsAnnotation, "value")) {
            String path = (String) valueAnnotation.getValue("name");
            if (name.equals(path)) {
                return readIntegerValuesAnnotation(valueAnnotation, singeValue);
            }
        }
    }
    exprsAnnotation = mm.getAnnotation(AbstractModelLoader.CEYLON_BOOLEAN_EXPRS_ANNOTATION);
    if (exprsAnnotation != null) {
        for (AnnotationMirror valueAnnotation : getAnnotationAnnoValues(exprsAnnotation, "value")) {
            String path = (String) valueAnnotation.getValue("name");
            if (name.equals(path)) {
                return readBooleanValuesAnnotation(valueAnnotation, singeValue);
            }
        }
    }
    exprsAnnotation = mm.getAnnotation(AbstractModelLoader.CEYLON_DECLARATION_EXPRS_ANNOTATION);
    if (exprsAnnotation != null) {
        for (AnnotationMirror valueAnnotation : getAnnotationAnnoValues(exprsAnnotation, "value")) {
            String path = (String) valueAnnotation.getValue("name");
            if (name.equals(path)) {
                return readDeclarationValuesAnnotation(valueAnnotation, singeValue);
            }
        }
    }
    exprsAnnotation = mm.getAnnotation(AbstractModelLoader.CEYLON_OBJECT_EXPRS_ANNOTATION);
    if (exprsAnnotation != null) {
        for (AnnotationMirror valueAnnotation : getAnnotationAnnoValues(exprsAnnotation, "value")) {
            String path = (String) valueAnnotation.getValue("name");
            if (name.equals(path)) {
                return readObjectValuesAnnotation(moduleScope, valueAnnotation, singeValue);
            }
        }
    }
    exprsAnnotation = mm.getAnnotation(AbstractModelLoader.CEYLON_CHARACTER_EXPRS_ANNOTATION);
    if (exprsAnnotation != null) {
        for (AnnotationMirror valueAnnotation : getAnnotationAnnoValues(exprsAnnotation, "value")) {
            String path = (String) valueAnnotation.getValue("name");
            if (name.equals(path)) {
                return readCharacterValuesAnnotation(valueAnnotation, singeValue);
            }
        }
    }
    exprsAnnotation = mm.getAnnotation(AbstractModelLoader.CEYLON_FLOAT_EXPRS_ANNOTATION);
    if (exprsAnnotation != null) {
        for (AnnotationMirror valueAnnotation : getAnnotationAnnoValues(exprsAnnotation, "value")) {
            String path = (String) valueAnnotation.getValue("name");
            if (name.equals(path)) {
                return readFloatValuesAnnotation(valueAnnotation, singeValue);
            }
        }
    }
    return null;
}
Also used : AnnotationMirror(com.redhat.ceylon.model.loader.mirror.AnnotationMirror)

Example 2 with AnnotationMirror

use of com.redhat.ceylon.model.loader.mirror.AnnotationMirror in project ceylon-compiler by ceylon.

the class AnnotationLoader method loadAnnotationArgumentTerm.

private AnnotationTerm loadAnnotationArgumentTerm(List<AnnotationFieldName> path, LazyFunction method, AnnotationInvocation ai, Parameter parameter, List<AnnotationMirror> annotationTree, AnnotatedMirror dpm, short code) {
    if (code < 0 && code != Short.MIN_VALUE) {
        AnnotationMirror i = annotationTree.get(-code);
        AnnotationInvocation nested = new AnnotationInvocation();
        setPrimaryFromAnnotationInvocationAnnotation(i, nested);
        loadAnnotationInvocationArguments(path, method, nested, i, annotationTree, dpm);
        InvocationAnnotationTerm term = new InvocationAnnotationTerm();
        term.setInstantiation(nested);
        return term;
    } else {
        AnnotationTerm term = decode(Decl.getModuleContainer(method), method.getFirstParameterList().getParameters(), ai, parameter, dpm, path, code);
        return term;
    }
}
Also used : AnnotationMirror(com.redhat.ceylon.model.loader.mirror.AnnotationMirror) AnnotationInvocation(com.redhat.ceylon.compiler.java.codegen.AnnotationInvocation) InvocationAnnotationTerm(com.redhat.ceylon.compiler.java.codegen.InvocationAnnotationTerm) ObjectLiteralAnnotationTerm(com.redhat.ceylon.compiler.java.codegen.ObjectLiteralAnnotationTerm) CollectionLiteralAnnotationTerm(com.redhat.ceylon.compiler.java.codegen.CollectionLiteralAnnotationTerm) DeclarationLiteralAnnotationTerm(com.redhat.ceylon.compiler.java.codegen.DeclarationLiteralAnnotationTerm) StringLiteralAnnotationTerm(com.redhat.ceylon.compiler.java.codegen.StringLiteralAnnotationTerm) BooleanLiteralAnnotationTerm(com.redhat.ceylon.compiler.java.codegen.BooleanLiteralAnnotationTerm) CharacterLiteralAnnotationTerm(com.redhat.ceylon.compiler.java.codegen.CharacterLiteralAnnotationTerm) LiteralAnnotationTerm(com.redhat.ceylon.compiler.java.codegen.LiteralAnnotationTerm) ParameterAnnotationTerm(com.redhat.ceylon.compiler.java.codegen.ParameterAnnotationTerm) AnnotationTerm(com.redhat.ceylon.compiler.java.codegen.AnnotationTerm) InvocationAnnotationTerm(com.redhat.ceylon.compiler.java.codegen.InvocationAnnotationTerm) FloatLiteralAnnotationTerm(com.redhat.ceylon.compiler.java.codegen.FloatLiteralAnnotationTerm) IntegerLiteralAnnotationTerm(com.redhat.ceylon.compiler.java.codegen.IntegerLiteralAnnotationTerm)

Example 3 with AnnotationMirror

use of com.redhat.ceylon.model.loader.mirror.AnnotationMirror in project ceylon-compiler by ceylon.

the class AnnotationLoader method loadAnnotationInvocation.

private AnnotationInvocation loadAnnotationInvocation(LazyFunction method, AnnotatedMirror annoInstMirror, MethodMirror meth) {
    AnnotationInvocation ai = null;
    AnnotationMirror annotationInvocationAnnotation = null;
    List<AnnotationMirror> annotationTree = getAnnotationArrayValue(annoInstMirror, AbstractModelLoader.CEYLON_ANNOTATION_INSTANTIATION_TREE_ANNOTATION, "value");
    if (annotationTree != null && !annotationTree.isEmpty()) {
        annotationInvocationAnnotation = annotationTree.get(0);
    } else {
        annotationInvocationAnnotation = annoInstMirror.getAnnotation(AbstractModelLoader.CEYLON_ANNOTATION_INSTANTIATION_ANNOTATION);
    }
    //stringValueAnnotation = annoInstMirror.getAnnotation(CEYLON_STRING_VALUE_ANNOTATION);
    if (annotationInvocationAnnotation != null) {
        ai = new AnnotationInvocation();
        setPrimaryFromAnnotationInvocationAnnotation(annotationInvocationAnnotation, ai);
        loadAnnotationInvocationArguments(new ArrayList<AnnotationFieldName>(2), method, ai, annotationInvocationAnnotation, annotationTree, annoInstMirror);
    }
    return ai;
}
Also used : AnnotationMirror(com.redhat.ceylon.model.loader.mirror.AnnotationMirror) AnnotationInvocation(com.redhat.ceylon.compiler.java.codegen.AnnotationInvocation) AnnotationFieldName(com.redhat.ceylon.compiler.java.codegen.AnnotationFieldName)

Example 4 with AnnotationMirror

use of com.redhat.ceylon.model.loader.mirror.AnnotationMirror in project ceylon-compiler by ceylon.

the class AnnotationLoader method loadLiteralAnnotationTerm.

/** 
     * Loads a LiteralAnnotationTerm according to the presence of 
     * <ul>
     * <li>{@code @StringValue} <li>{@code @IntegerValue} <li>etc
     * </ul>
     * @param ctorParam 
     *  
     */
private LiteralAnnotationTerm loadLiteralAnnotationTerm(LazyFunction method, Parameter parameter, AnnotatedMirror mm) {
    // FIXME: store iterable info somewhere else
    boolean singleValue = !typeFactory.isIterableType(parameter.getType()) || parameter.getType().isString();
    AnnotationMirror valueAnnotation = mm.getAnnotation(AbstractModelLoader.CEYLON_STRING_VALUE_ANNOTATION);
    if (valueAnnotation != null) {
        return readStringValuesAnnotation(valueAnnotation, singleValue);
    }
    valueAnnotation = mm.getAnnotation(AbstractModelLoader.CEYLON_INTEGER_VALUE_ANNOTATION);
    if (valueAnnotation != null) {
        return readIntegerValuesAnnotation(valueAnnotation, singleValue);
    }
    valueAnnotation = mm.getAnnotation(AbstractModelLoader.CEYLON_BOOLEAN_VALUE_ANNOTATION);
    if (valueAnnotation != null) {
        return readBooleanValuesAnnotation(valueAnnotation, singleValue);
    }
    valueAnnotation = mm.getAnnotation(AbstractModelLoader.CEYLON_DECLARATION_VALUE_ANNOTATION);
    if (valueAnnotation != null) {
        return readDeclarationValuesAnnotation(valueAnnotation, singleValue);
    }
    valueAnnotation = mm.getAnnotation(AbstractModelLoader.CEYLON_OBJECT_VALUE_ANNOTATION);
    if (valueAnnotation != null) {
        return readObjectValuesAnnotation(Decl.getModuleContainer(method), valueAnnotation, singleValue);
    }
    valueAnnotation = mm.getAnnotation(AbstractModelLoader.CEYLON_CHARACTER_VALUE_ANNOTATION);
    if (valueAnnotation != null) {
        return readCharacterValuesAnnotation(valueAnnotation, singleValue);
    }
    valueAnnotation = mm.getAnnotation(AbstractModelLoader.CEYLON_FLOAT_VALUE_ANNOTATION);
    if (valueAnnotation != null) {
        return readFloatValuesAnnotation(valueAnnotation, singleValue);
    }
    return null;
}
Also used : AnnotationMirror(com.redhat.ceylon.model.loader.mirror.AnnotationMirror)

Aggregations

AnnotationMirror (com.redhat.ceylon.model.loader.mirror.AnnotationMirror)4 AnnotationInvocation (com.redhat.ceylon.compiler.java.codegen.AnnotationInvocation)2 AnnotationFieldName (com.redhat.ceylon.compiler.java.codegen.AnnotationFieldName)1 AnnotationTerm (com.redhat.ceylon.compiler.java.codegen.AnnotationTerm)1 BooleanLiteralAnnotationTerm (com.redhat.ceylon.compiler.java.codegen.BooleanLiteralAnnotationTerm)1 CharacterLiteralAnnotationTerm (com.redhat.ceylon.compiler.java.codegen.CharacterLiteralAnnotationTerm)1 CollectionLiteralAnnotationTerm (com.redhat.ceylon.compiler.java.codegen.CollectionLiteralAnnotationTerm)1 DeclarationLiteralAnnotationTerm (com.redhat.ceylon.compiler.java.codegen.DeclarationLiteralAnnotationTerm)1 FloatLiteralAnnotationTerm (com.redhat.ceylon.compiler.java.codegen.FloatLiteralAnnotationTerm)1 IntegerLiteralAnnotationTerm (com.redhat.ceylon.compiler.java.codegen.IntegerLiteralAnnotationTerm)1 InvocationAnnotationTerm (com.redhat.ceylon.compiler.java.codegen.InvocationAnnotationTerm)1 LiteralAnnotationTerm (com.redhat.ceylon.compiler.java.codegen.LiteralAnnotationTerm)1 ObjectLiteralAnnotationTerm (com.redhat.ceylon.compiler.java.codegen.ObjectLiteralAnnotationTerm)1 ParameterAnnotationTerm (com.redhat.ceylon.compiler.java.codegen.ParameterAnnotationTerm)1 StringLiteralAnnotationTerm (com.redhat.ceylon.compiler.java.codegen.StringLiteralAnnotationTerm)1