Search in sources :

Example 1 with SetterWithLocalDeclarations

use of org.eclipse.ceylon.model.loader.model.SetterWithLocalDeclarations in project ceylon by eclipse.

the class AbstractModelLoader method findLocalContainerFromAnnotationAndSetCompanionClass.

private Scope findLocalContainerFromAnnotationAndSetCompanionClass(Package pkg, Interface declaration, AnnotationMirror localContainerAnnotation) {
    @SuppressWarnings("unchecked") List<String> path = (List<String>) localContainerAnnotation.getValue("path");
    // we start at the package
    Scope scope = pkg;
    for (String name : path) {
        scope = (Scope) getDirectMember(scope, name);
    }
    String companionClassName = (String) localContainerAnnotation.getValue("companionClassName");
    if (companionClassName == null || companionClassName.isEmpty()) {
        declaration.setCompanionClassNeeded(false);
        return scope;
    }
    ClassMirror container;
    Scope javaClassScope;
    if (scope instanceof TypedDeclaration && ((TypedDeclaration) scope).isMember())
        javaClassScope = scope.getContainer();
    else
        javaClassScope = scope;
    if (javaClassScope instanceof LazyInterface) {
        container = ((LazyInterface) javaClassScope).companionClass;
    } else if (javaClassScope instanceof LazyClass) {
        container = ((LazyClass) javaClassScope).classMirror;
    } else if (javaClassScope instanceof LazyValue) {
        container = ((LazyValue) javaClassScope).classMirror;
    } else if (javaClassScope instanceof LazyFunction) {
        container = ((LazyFunction) javaClassScope).classMirror;
    } else if (javaClassScope instanceof SetterWithLocalDeclarations) {
        container = ((SetterWithLocalDeclarations) javaClassScope).classMirror;
    } else {
        throw new ModelResolutionException("Unknown scope class: " + javaClassScope);
    }
    String qualifiedCompanionClassName = container.getQualifiedName() + "$" + companionClassName;
    ClassMirror companionClassMirror = lookupClassMirror(pkg.getModule(), qualifiedCompanionClassName);
    if (companionClassMirror == null)
        throw new ModelResolutionException("Could not find companion class mirror: " + qualifiedCompanionClassName);
    ((LazyInterface) declaration).companionClass = companionClassMirror;
    return scope;
}
Also used : TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) LazyValue(org.eclipse.ceylon.model.loader.model.LazyValue) LazyFunction(org.eclipse.ceylon.model.loader.model.LazyFunction) ClassMirror(org.eclipse.ceylon.model.loader.mirror.ClassMirror) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) LazyInterface(org.eclipse.ceylon.model.loader.model.LazyInterface) SetterWithLocalDeclarations(org.eclipse.ceylon.model.loader.model.SetterWithLocalDeclarations) List(java.util.List) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) LazyClass(org.eclipse.ceylon.model.loader.model.LazyClass)

Example 2 with SetterWithLocalDeclarations

use of org.eclipse.ceylon.model.loader.model.SetterWithLocalDeclarations in project ceylon by eclipse.

the class AbstractModelLoader method makeSetter.

private SetterWithLocalDeclarations makeSetter(Value value, ClassMirror classMirror) {
    SetterWithLocalDeclarations setter = new SetterWithLocalDeclarations(classMirror);
    Scope scope = value.getContainer();
    setter.setContainer(scope);
    setter.setScope(scope);
    setter.setType(value.getType());
    setter.setName(value.getName());
    Parameter p = new Parameter();
    p.setHidden(true);
    Value v = new Value();
    v.setType(value.getType());
    v.setUnboxed(value.getUnboxed());
    v.setInitializerParameter(p);
    v.setContainer(setter);
    v.setScope(setter);
    p.setModel(v);
    v.setName(setter.getName());
    p.setName(setter.getName());
    p.setDeclaration(setter);
    setter.setParameter(p);
    value.setSetter(setter);
    setter.setGetter(value);
    return setter;
}
Also used : Scope(org.eclipse.ceylon.model.typechecker.model.Scope) SetterWithLocalDeclarations(org.eclipse.ceylon.model.loader.model.SetterWithLocalDeclarations) JavaParameterValue(org.eclipse.ceylon.model.loader.model.JavaParameterValue) Value(org.eclipse.ceylon.model.typechecker.model.Value) FieldValue(org.eclipse.ceylon.model.loader.model.FieldValue) LazyValue(org.eclipse.ceylon.model.loader.model.LazyValue) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) JavaBeanValue(org.eclipse.ceylon.model.loader.model.JavaBeanValue) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter)

Aggregations

LazyValue (org.eclipse.ceylon.model.loader.model.LazyValue)2 SetterWithLocalDeclarations (org.eclipse.ceylon.model.loader.model.SetterWithLocalDeclarations)2 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ClassMirror (org.eclipse.ceylon.model.loader.mirror.ClassMirror)1 FieldValue (org.eclipse.ceylon.model.loader.model.FieldValue)1 JavaBeanValue (org.eclipse.ceylon.model.loader.model.JavaBeanValue)1 JavaParameterValue (org.eclipse.ceylon.model.loader.model.JavaParameterValue)1 LazyClass (org.eclipse.ceylon.model.loader.model.LazyClass)1 LazyFunction (org.eclipse.ceylon.model.loader.model.LazyFunction)1 LazyInterface (org.eclipse.ceylon.model.loader.model.LazyInterface)1 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)1 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)1 ParameterList (org.eclipse.ceylon.model.typechecker.model.ParameterList)1 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)1 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)1 Value (org.eclipse.ceylon.model.typechecker.model.Value)1