Search in sources :

Example 11 with AnnotationMirror

use of org.eclipse.ceylon.model.loader.mirror.AnnotationMirror in project ceylon by eclipse.

the class AbstractModelLoader method getClassConstructors.

private List<MethodMirror> getClassConstructors(ClassMirror instantiatedType, ClassMirror methodContainer, MethodMirrorFilter p) {
    LinkedList<MethodMirror> constructors = new LinkedList<MethodMirror>();
    boolean isFromJDK = isFromJDK(methodContainer);
    for (MethodMirror methodMirror : methodContainer.getDirectMethods()) {
        // We skip members marked with @Ignore, unless they value constructor getters
        if (methodMirror.getAnnotation(CEYLON_IGNORE_ANNOTATION) != null && methodMirror.getAnnotation(CEYLON_ENUMERATED_ANNOTATION) == null)
            continue;
        if (!p.accept(methodMirror))
            continue;
        // FIXME: tmp hack to skip constructors that have type params as we don't handle them yet
        if (!methodMirror.getTypeParameters().isEmpty())
            continue;
        // referenced in private methods but not available
        if (isFromJDK && !methodMirror.isPublic() && // classes in the jdk packages
        !methodMirror.isProtected())
            continue;
        // if we are expecting Ceylon code, check that we have enough reified type parameters
        if (methodContainer.getAnnotation(CEYLON_CEYLON_ANNOTATION) != null) {
            List<AnnotationMirror> tpAnnotations = getTypeParametersFromAnnotations(instantiatedType);
            int tpCount = tpAnnotations != null ? tpAnnotations.size() : instantiatedType.getTypeParameters().size();
            if (!checkReifiedTypeDescriptors(tpCount, instantiatedType.getQualifiedName(), methodMirror, true))
                continue;
        }
        constructors.add(methodMirror);
    }
    return constructors;
}
Also used : MethodMirror(org.eclipse.ceylon.model.loader.mirror.MethodMirror) AnnotationMirror(org.eclipse.ceylon.model.loader.mirror.AnnotationMirror) LinkedList(java.util.LinkedList)

Example 12 with AnnotationMirror

use of org.eclipse.ceylon.model.loader.mirror.AnnotationMirror in project ceylon by eclipse.

the class JvmBackendUtil method getMirrorName.

public static String getMirrorName(AnnotatedMirror mirror) {
    String name;
    AnnotationMirror annot = mirror.getAnnotation(CEYLON_NAME_ANNOTATION);
    if (annot != null) {
        name = (String) annot.getValue();
    } else {
        name = mirror.getName();
        name = name.isEmpty() ? name : stripLeadingDollar(name);
        if (mirror instanceof ClassMirror && isInitialLowerCase(name) && name.endsWith("_") && mirror.getAnnotation(CEYLON_CEYLON_ANNOTATION) != null) {
            name = name.substring(0, name.length() - 1);
        }
    }
    return name;
}
Also used : AnnotationMirror(org.eclipse.ceylon.model.loader.mirror.AnnotationMirror) ClassMirror(org.eclipse.ceylon.model.loader.mirror.ClassMirror)

Example 13 with AnnotationMirror

use of org.eclipse.ceylon.model.loader.mirror.AnnotationMirror in project ceylon by eclipse.

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(ModelUtil.getModuleContainer(method), method.getFirstParameterList().getParameters(), ai, parameter, dpm, path, code);
        return term;
    }
}
Also used : AnnotationMirror(org.eclipse.ceylon.model.loader.mirror.AnnotationMirror) AnnotationInvocation(org.eclipse.ceylon.compiler.java.codegen.AnnotationInvocation) InvocationAnnotationTerm(org.eclipse.ceylon.compiler.java.codegen.InvocationAnnotationTerm) CollectionLiteralAnnotationTerm(org.eclipse.ceylon.compiler.java.codegen.CollectionLiteralAnnotationTerm) FloatLiteralAnnotationTerm(org.eclipse.ceylon.compiler.java.codegen.FloatLiteralAnnotationTerm) ObjectLiteralAnnotationTerm(org.eclipse.ceylon.compiler.java.codegen.ObjectLiteralAnnotationTerm) LiteralAnnotationTerm(org.eclipse.ceylon.compiler.java.codegen.LiteralAnnotationTerm) DeclarationLiteralAnnotationTerm(org.eclipse.ceylon.compiler.java.codegen.DeclarationLiteralAnnotationTerm) BooleanLiteralAnnotationTerm(org.eclipse.ceylon.compiler.java.codegen.BooleanLiteralAnnotationTerm) InvocationAnnotationTerm(org.eclipse.ceylon.compiler.java.codegen.InvocationAnnotationTerm) AnnotationTerm(org.eclipse.ceylon.compiler.java.codegen.AnnotationTerm) CharacterLiteralAnnotationTerm(org.eclipse.ceylon.compiler.java.codegen.CharacterLiteralAnnotationTerm) ParameterAnnotationTerm(org.eclipse.ceylon.compiler.java.codegen.ParameterAnnotationTerm) IntegerLiteralAnnotationTerm(org.eclipse.ceylon.compiler.java.codegen.IntegerLiteralAnnotationTerm) StringLiteralAnnotationTerm(org.eclipse.ceylon.compiler.java.codegen.StringLiteralAnnotationTerm)

Example 14 with AnnotationMirror

use of org.eclipse.ceylon.model.loader.mirror.AnnotationMirror in project ceylon by eclipse.

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(org.eclipse.ceylon.model.loader.mirror.AnnotationMirror)

Example 15 with AnnotationMirror

use of org.eclipse.ceylon.model.loader.mirror.AnnotationMirror in project ceylon by eclipse.

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(org.eclipse.ceylon.model.loader.mirror.AnnotationMirror) AnnotationInvocation(org.eclipse.ceylon.compiler.java.codegen.AnnotationInvocation) AnnotationFieldName(org.eclipse.ceylon.compiler.java.codegen.AnnotationFieldName)

Aggregations

AnnotationMirror (org.eclipse.ceylon.model.loader.mirror.AnnotationMirror)25 LinkedList (java.util.LinkedList)6 LazyModule (org.eclipse.ceylon.model.loader.model.LazyModule)6 Module (org.eclipse.ceylon.model.typechecker.model.Module)6 ParameterList (org.eclipse.ceylon.model.typechecker.model.ParameterList)6 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 TypeMirror (org.eclipse.ceylon.model.loader.mirror.TypeMirror)5 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)5 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)5 FunctionalInterfaceType (org.eclipse.ceylon.model.loader.mirror.FunctionalInterfaceType)4 LazyClass (org.eclipse.ceylon.model.loader.model.LazyClass)4 Type (org.eclipse.ceylon.model.typechecker.model.Type)4 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)4 ClassMirror (org.eclipse.ceylon.model.loader.mirror.ClassMirror)3 AnnotationProxyClass (org.eclipse.ceylon.model.loader.model.AnnotationProxyClass)3 LazyInterface (org.eclipse.ceylon.model.loader.model.LazyInterface)3 LazyValue (org.eclipse.ceylon.model.loader.model.LazyValue)3 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)3