Search in sources :

Example 1 with AnnotationMirror

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

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

Example 2 with AnnotationMirror

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

the class AbstractModelLoader method addInnerClassesFromAnnotation.

private void addInnerClassesFromAnnotation(ClassOrInterface klass, AnnotationMirror membersAnnotation) {
    @SuppressWarnings("unchecked") List<AnnotationMirror> members = (List<AnnotationMirror>) membersAnnotation.getValue();
    for (AnnotationMirror member : members) {
        TypeMirror javaClassMirror = (TypeMirror) member.getValue("klass");
        String javaClassName;
        // void.class is the default value, I guess it's a primitive?
        if (javaClassMirror != null && !javaClassMirror.isPrimitive()) {
            javaClassName = javaClassMirror.getQualifiedName();
        } else {
            // we get the class name as a string
            String name = (String) member.getValue("javaClassName");
            ClassMirror container = null;
            if (klass instanceof LazyClass) {
                container = ((LazyClass) klass).classMirror;
            } else if (klass instanceof LazyInterface) {
                if (((LazyInterface) klass).isCeylon())
                    container = ((LazyInterface) klass).companionClass;
                else
                    container = ((LazyInterface) klass).classMirror;
            }
            if (container == null)
                throw new ModelResolutionException("Unknown container type: " + klass + " when trying to load inner class " + name);
            javaClassName = container.getQualifiedName() + "$" + name;
        }
        Declaration innerDecl = convertToDeclaration(ModelUtil.getModuleContainer(klass), klass, javaClassName, DeclarationType.TYPE);
        if (innerDecl == null)
            throw new ModelResolutionException("Failed to load inner type " + javaClassName + " for outer type " + klass.getQualifiedNameString());
        if (shouldLinkNatives(innerDecl)) {
            initNativeHeaderMember(innerDecl);
        }
    }
}
Also used : AnnotationMirror(org.eclipse.ceylon.model.loader.mirror.AnnotationMirror) TypeMirror(org.eclipse.ceylon.model.loader.mirror.TypeMirror) LazyInterface(org.eclipse.ceylon.model.loader.model.LazyInterface) List(java.util.List) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) LazyClass(org.eclipse.ceylon.model.loader.model.LazyClass) ClassMirror(org.eclipse.ceylon.model.loader.mirror.ClassMirror)

Example 3 with AnnotationMirror

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

the class AbstractModelLoader method readModelAnnotation.

private Annotation readModelAnnotation(AnnotationMirror annotation) {
    Annotation modelAnnotation = new Annotation();
    modelAnnotation.setName((String) annotation.getValue());
    @SuppressWarnings("unchecked") List<String> arguments = (List<String>) annotation.getValue("arguments");
    if (arguments != null) {
        modelAnnotation.getPositionalArguments().addAll(arguments);
    } else {
        @SuppressWarnings("unchecked") List<AnnotationMirror> namedArguments = (List<AnnotationMirror>) annotation.getValue("namedArguments");
        if (namedArguments != null) {
            for (AnnotationMirror namedArgument : namedArguments) {
                String argName = (String) namedArgument.getValue("name");
                String argValue = (String) namedArgument.getValue("value");
                modelAnnotation.getNamedArguments().put(argName, argValue);
            }
        }
    }
    return modelAnnotation;
}
Also used : AnnotationMirror(org.eclipse.ceylon.model.loader.mirror.AnnotationMirror) List(java.util.List) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Annotation(org.eclipse.ceylon.model.typechecker.model.Annotation)

Example 4 with AnnotationMirror

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

the class AbstractModelLoader method addLocalDeclarations.

private void addLocalDeclarations(LocalDeclarationContainer container, ClassMirror classContainerMirror, AnnotatedMirror annotatedMirror) {
    if (!needsLocalDeclarations())
        return;
    AnnotationMirror annotation = annotatedMirror.getAnnotation(CEYLON_LOCAL_DECLARATIONS_ANNOTATION);
    if (annotation == null)
        return;
    List<String> values = getAnnotationStringValues(annotation, "value");
    String parentClassName = classContainerMirror.getQualifiedName();
    Package pkg = ModelUtil.getPackageContainer(container);
    Module module = pkg.getModule();
    for (String scope : values) {
        // assemble the name with the parent
        String name;
        if (scope.startsWith("::")) {
            // interface pulled to toplevel
            name = pkg.getNameAsString() + "." + scope.substring(2);
        } else {
            name = parentClassName;
            name += "$" + scope;
        }
        Declaration innerDecl = convertToDeclaration(module, (Declaration) container, name, DeclarationType.TYPE);
        if (innerDecl == null)
            throw new ModelResolutionException("Failed to load local type " + name + " for outer type " + container.getQualifiedNameString());
    }
}
Also used : AnnotationMirror(org.eclipse.ceylon.model.loader.mirror.AnnotationMirror) LazyPackage(org.eclipse.ceylon.model.loader.model.LazyPackage) Package(org.eclipse.ceylon.model.typechecker.model.Package) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Module(org.eclipse.ceylon.model.typechecker.model.Module) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule)

Example 5 with AnnotationMirror

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

the class AbstractModelLoader method makeLazyInterface.

protected LazyInterface makeLazyInterface(ClassMirror classMirror, boolean isNativeHeader) {
    LazyInterface iface = new LazyInterface(classMirror, this);
    iface.setSealed(classMirror.getAnnotation(CEYLON_LANGUAGE_SEALED_ANNOTATION) != null);
    iface.setDynamic(classMirror.getAnnotation(CEYLON_DYNAMIC_ANNOTATION) != null);
    if (iface.isCeylon()) {
        AnnotationMirror container = classMirror.getAnnotation(CEYLON_CONTAINER_ANNOTATION);
        if (container != null) {
            Object value = container.getValue("isStatic");
            if (value != null) {
                iface.setStatic(Boolean.TRUE.equals(value));
            }
        }
    } else {
        iface.setStatic(classMirror.getEnclosingClass() != null);
    }
    manageNativeBackend(iface, classMirror, isNativeHeader);
    return iface;
}
Also used : AnnotationMirror(org.eclipse.ceylon.model.loader.mirror.AnnotationMirror) LazyInterface(org.eclipse.ceylon.model.loader.model.LazyInterface)

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