Search in sources :

Example 71 with Scope

use of org.eclipse.ceylon.model.typechecker.model.Scope in project ceylon by eclipse.

the class GenerateJsVisitor method getSuperMemberScope.

/**
 * Checks if the given node is a MemberOrTypeExpression or QualifiedType which
 * represents an access to a supertype member and returns the scope of that
 * member or null.
 */
Scope getSuperMemberScope(Node node) {
    Scope scope = null;
    if (node instanceof Tree.QualifiedMemberOrTypeExpression) {
        // Check for "super.member"
        Tree.QualifiedMemberOrTypeExpression qmte = (Tree.QualifiedMemberOrTypeExpression) node;
        final Term primary = eliminateParensAndWidening(qmte.getPrimary());
        if (primary instanceof Tree.Super) {
            scope = qmte.getDeclaration().getContainer();
        }
    } else if (node instanceof Tree.QualifiedType) {
        // Check for super.Membertype
        Tree.QualifiedType qtype = (Tree.QualifiedType) node;
        if (qtype.getOuterType() instanceof Tree.SuperType) {
            scope = qtype.getDeclarationModel().getContainer();
        }
    }
    return scope;
}
Also used : Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Term(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Term)

Example 72 with Scope

use of org.eclipse.ceylon.model.typechecker.model.Scope in project ceylon by eclipse.

the class MethodOrValueReferenceVisitor method isSelfCaptured.

/**
 * Returns true if <code>that</code> is within the scope of the type of <code>d</code>,
 * which must be a value declaration for an object declaration.
 */
private boolean isSelfCaptured(Primary that, TypedDeclaration d) {
    TypeDeclaration type = d.getTypeDeclaration();
    Scope scope = that.getScope();
    while (scope != null && !(scope instanceof Package) && !Decl.equalScopeDecl(scope, type)) {
        scope = scope.getScope();
    }
    return Decl.equalScopeDecl(scope, type);
}
Also used : Scope(org.eclipse.ceylon.model.typechecker.model.Scope) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 73 with Scope

use of org.eclipse.ceylon.model.typechecker.model.Scope 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 74 with Scope

use of org.eclipse.ceylon.model.typechecker.model.Scope in project ceylon by eclipse.

the class AbstractModelLoader method isRaw.

private boolean isRaw(Module module, TypeMirror type) {
    // See https://github.com/ceylon/ceylon-compiler/issues/1085
    switch(type.getKind()) {
        // arrays are never raw
        case ARRAY:
        case BOOLEAN:
        case BYTE:
        case CHAR:
        case DOUBLE:
        case ERROR:
        case FLOAT:
        case INT:
        case LONG:
        case NULL:
        case SHORT:
        case TYPEVAR:
        case VOID:
        case WILDCARD:
            return false;
        case DECLARED:
            ClassMirror klass = type.getDeclaredClass();
            if (klass.isJavaSource()) {
                // I suppose this should work
                return type.isRaw();
            }
            List<String> path = new LinkedList<String>();
            String pkgName = klass.getPackage().getQualifiedName();
            String unquotedPkgName = unquotePackageName(klass.getPackage());
            String qualifiedName = klass.getQualifiedName();
            String relativeName = pkgName.isEmpty() ? qualifiedName : qualifiedName.substring(pkgName.length() + 1);
            for (String name : relativeName.split("[\\$\\.]")) {
                if (!name.isEmpty()) {
                    path.add(name);
                }
            }
            if (path.size() > 1) {
                // find the proper class mirror for the container
                klass = loadClass(module, pkgName, new StringBuilder(pkgName).append('.').append(path.get(0)).toString());
                if (klass == null)
                    return false;
            }
            if (!path.isEmpty() && klass.isLoadedFromSource()) {
                // we need to find its model
                Scope scope = packagesByName.get(cacheKeyByModule(module, unquotedPkgName));
                if (scope == null)
                    return false;
                for (String name : path) {
                    Declaration decl = scope.getDirectMember(name, null, false);
                    if (decl == null)
                        return false;
                    // if we get a value, we want its type
                    if (JvmBackendUtil.isValue(decl) && ((Value) decl).getTypeDeclaration().getName().equals(name))
                        decl = ((Value) decl).getTypeDeclaration();
                    if (decl instanceof TypeDeclaration == false)
                        return false;
                    scope = (TypeDeclaration) decl;
                }
                TypeDeclaration typeDecl = (TypeDeclaration) scope;
                return typeDecl.isParameterized() && type.getTypeArguments().isEmpty();
            }
            try {
                return type.isRaw();
            } catch (Exception x) {
                // it will be logged somewhere else
                return false;
            }
        default:
            return false;
    }
}
Also used : Scope(org.eclipse.ceylon.model.typechecker.model.Scope) 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) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) ClassMirror(org.eclipse.ceylon.model.loader.mirror.ClassMirror) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) LinkedList(java.util.LinkedList) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) IOException(java.io.IOException)

Example 75 with Scope

use of org.eclipse.ceylon.model.typechecker.model.Scope 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

Scope (org.eclipse.ceylon.model.typechecker.model.Scope)142 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)71 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)57 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)50 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)44 Type (org.eclipse.ceylon.model.typechecker.model.Type)44 ConditionScope (org.eclipse.ceylon.model.typechecker.model.ConditionScope)35 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)34 Class (org.eclipse.ceylon.model.typechecker.model.Class)33 ModelUtil.getRealScope (org.eclipse.ceylon.model.typechecker.model.ModelUtil.getRealScope)31 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)30 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)26 Value (org.eclipse.ceylon.model.typechecker.model.Value)26 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)25 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)24 Function (org.eclipse.ceylon.model.typechecker.model.Function)23 Package (org.eclipse.ceylon.model.typechecker.model.Package)22 ArrayList (java.util.ArrayList)21 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)20 NativeUtil.declarationScope (org.eclipse.ceylon.compiler.typechecker.util.NativeUtil.declarationScope)15