Search in sources :

Example 26 with Scope

use of com.redhat.ceylon.model.typechecker.model.Scope in project ceylon-compiler by ceylon.

the class MethodDefinitionBuilder method isParamTypeLocalToMethod.

private boolean isParamTypeLocalToMethod(Parameter parameter, Type nonWideningType) {
    // error recovery
    if (nonWideningType == null)
        return false;
    if (parameter.getModel().getTypeErased()) {
        return false;
    }
    Declaration method = parameter.getDeclaration();
    TypeDeclaration paramTypeDecl = nonWideningType.getDeclaration();
    if (paramTypeDecl instanceof TypeParameter && Decl.equalScopeDecl(paramTypeDecl.getContainer(), method)) {
        return false;
    }
    Scope scope = paramTypeDecl.getContainer();
    while (scope != null && !(scope instanceof Package)) {
        if (Decl.equalScopeDecl(scope, method)) {
            return true;
        }
        scope = scope.getContainer();
    }
    return false;
}
Also used : TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) JCTypeParameter(com.sun.tools.javac.tree.JCTree.JCTypeParameter) Scope(com.redhat.ceylon.model.typechecker.model.Scope) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Package(com.redhat.ceylon.model.typechecker.model.Package) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Example 27 with Scope

use of com.redhat.ceylon.model.typechecker.model.Scope in project ceylon-compiler by ceylon.

the class NamedArgumentInvocation method getParameterTypeForValueType.

protected Type getParameterTypeForValueType(Reference producedReference, Parameter param) {
    // we need to find the interface for this method
    Type paramType = param.getModel().getReference().getFullType().getType();
    Scope paramContainer = param.getModel().getContainer();
    if (paramContainer instanceof TypedDeclaration) {
        TypedDeclaration method = (TypedDeclaration) paramContainer;
        if (method.getContainer() instanceof TypeDeclaration && !(method.getContainer() instanceof Constructor)) {
            TypeDeclaration container = (TypeDeclaration) method.getContainer();
            Type qualifyingType = producedReference.getQualifyingType();
            Type supertype = qualifyingType.getSupertype(container);
            return paramType.substitute(supertype);
        }
    }
    return paramType;
}
Also used : TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Type(com.redhat.ceylon.model.typechecker.model.Type) Scope(com.redhat.ceylon.model.typechecker.model.Scope) Constructor(com.redhat.ceylon.model.typechecker.model.Constructor) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Example 28 with Scope

use of com.redhat.ceylon.model.typechecker.model.Scope in project ceylon-compiler by ceylon.

the class ClassTransformer method makeLocalContainerPath.

private List<JCAnnotation> makeLocalContainerPath(Interface model) {
    List<String> path = List.nil();
    Scope container = model.getContainer();
    while (container != null && container instanceof Package == false) {
        if (container instanceof Declaration)
            path = path.prepend(((Declaration) container).getPrefixedName());
        container = container.getContainer();
    }
    return makeAtLocalContainer(path, model.isCompanionClassNeeded() ? model.getJavaCompanionClassName() : null);
}
Also used : Scope(com.redhat.ceylon.model.typechecker.model.Scope) Package(com.redhat.ceylon.model.typechecker.model.Package) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) MethodDeclaration(com.redhat.ceylon.compiler.typechecker.tree.Tree.MethodDeclaration) AttributeDeclaration(com.redhat.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration)

Example 29 with Scope

use of com.redhat.ceylon.model.typechecker.model.Scope in project ceylon-compiler by ceylon.

the class ExpressionTransformer method isReferenceInSameScope.

private boolean isReferenceInSameScope(Tree.StaticMemberOrTypeExpression expr) {
    if (isWithinSyntheticClassBody()) {
        return false;
    }
    Declaration decl = expr.getDeclaration();
    Scope s = expr.getScope();
    // are we in the same Declaration container?
    while (s != null && s instanceof Declaration == false) {
        s = s.getContainer();
    }
    return Decl.equalScopeDecl(s, decl);
}
Also used : Scope(com.redhat.ceylon.model.typechecker.model.Scope) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Example 30 with Scope

use of com.redhat.ceylon.model.typechecker.model.Scope in project ceylon-compiler by ceylon.

the class ExpressionTransformer method makeQualifiedDollarThis.

private JCExpression makeQualifiedDollarThis(Tree.BaseMemberExpression expr) {
    Declaration decl = expr.getDeclaration();
    Interface interf = (Interface) Decl.getClassOrInterfaceContainer(decl);
    // find the target container interface that is or satisfies the given interface
    Scope scope = expr.getScope();
    boolean needsQualified = false;
    while (scope != null) {
        if (scope instanceof Interface) {
            if (Decl.equalScopeDecl(scope, interf) || ((Interface) scope).inherits(interf)) {
                break;
            }
            // we only need to qualify it if we're aiming for a $this of an outer interface than the interface we are caught in
            needsQualified = true;
        }
        scope = scope.getContainer();
    }
    if (!needsQualified)
        return naming.makeQuotedThis();
    interf = (Interface) scope;
    return makeQualifiedDollarThis(interf.getType());
}
Also used : Scope(com.redhat.ceylon.model.typechecker.model.Scope) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Interface(com.redhat.ceylon.model.typechecker.model.Interface) ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface)

Aggregations

Scope (com.redhat.ceylon.model.typechecker.model.Scope)38 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)26 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)22 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)20 Package (com.redhat.ceylon.model.typechecker.model.Package)16 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)14 Interface (com.redhat.ceylon.model.typechecker.model.Interface)10 Class (com.redhat.ceylon.model.typechecker.model.Class)8 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)8 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)7 Type (com.redhat.ceylon.model.typechecker.model.Type)7 ArrayList (java.util.ArrayList)7 Function (com.redhat.ceylon.model.typechecker.model.Function)6 Constructor (com.redhat.ceylon.model.typechecker.model.Constructor)5 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)5 Value (com.redhat.ceylon.model.typechecker.model.Value)5 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)5 JCTree (com.sun.tools.javac.tree.JCTree)4 Generic (com.redhat.ceylon.model.typechecker.model.Generic)3 ParameterList (com.redhat.ceylon.model.typechecker.model.ParameterList)3