Search in sources :

Example 61 with TypeDeclaration

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

the class Naming method makeDefaultedParamMethod.

JCExpression makeDefaultedParamMethod(JCExpression qualifier, Parameter param) {
    // TODO Can we merge this into makeName(..., NA_DPM) ?
    if (!Strategy.hasDefaultParameterValueMethod(param)) {
        throw new BugException();
    }
    Declaration decl = param.getDeclaration();
    String methodName = getDefaultedParamMethodName(decl, param);
    switch(Strategy.defaultParameterMethodOwner(param.getModel())) {
        case SELF:
            {
                // method not within interface
                Declaration container = param.getDeclaration().getRefinedDeclaration();
                if (!container.isToplevel()) {
                    container = (Declaration) container.getContainer();
                }
                JCExpression className = makeTypeDeclarationExpression(qualifier, (TypeDeclaration) container, DeclNameFlag.COMPANION);
                return makeSelect(className, methodName);
            }
        case OUTER:
        case OUTER_COMPANION:
            return makeQuotedQualIdent(qualifier, methodName);
        case STATIC:
            {
                // top level method or class
                // return makeSelect(gen().makeStaticQualifier(param.getDeclaration().getRefinedDeclaration()), methodName);
                Declaration container = param.getDeclaration().getRefinedDeclaration();
                if (!container.isToplevel() && !container.isStatic()) {
                    container = (Declaration) container.getContainer();
                } else if (container.isStatic() && container instanceof TypedDeclaration) {
                    container = (Declaration) container.getContainer();
                }
                if (container instanceof TypedDeclaration) {
                    return makeSelect(makeName((TypedDeclaration) container, NA_FQ | NA_WRAPPER), methodName);
                } else {
                    return makeSelect(gen().makeJavaType(((TypeDeclaration) container).getType(), AbstractTransformer.JT_RAW | AbstractTransformer.JT_NO_PRIMITIVES), methodName);
                }
            }
        default:
            // inner or local class or method, or method in an interface
            return makeQuotedQualIdent(qualifier, methodName);
    }
}
Also used : TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 62 with TypeDeclaration

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

the class Naming method makeNamedConstructorName.

public JCExpression makeNamedConstructorName(Constructor constructor, boolean delegation) {
    DeclNameFlag[] flags = delegation ? new DeclNameFlag[] { DeclNameFlag.QUALIFIED, DeclNameFlag.DELEGATION } : new DeclNameFlag[] { DeclNameFlag.QUALIFIED };
    Class cls = (Class) constructor.getContainer();
    if (cls.isToplevel() || cls.isMember() && ((TypeDeclaration) cls.getContainer()).isToplevel()) {
        return makeTypeDeclarationExpression(null, constructor, flags);
    } else {
        return maker.TypeCast(makeTypeDeclarationExpression(null, constructor, flags), // makeTypeDeclarationExpression(makeTypeDeclarationExpression(null, cls, DeclNameFlag.QUALIFIED), constructor, DeclNameFlag.QUALIFIED),
        make().Literal(TypeTag.BOT, null));
    }
}
Also used : LazyClass(org.eclipse.ceylon.model.loader.model.LazyClass) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 63 with TypeDeclaration

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

the class Naming method appendTypeDeclaration.

private void appendTypeDeclaration(final TypeDeclaration decl, EnumSet<DeclNameFlag> flags, TypeDeclarationBuilder<?> typeDeclarationBuilder, Scope scope, final boolean last) {
    if (scope instanceof Class || scope instanceof TypeAlias || (scope instanceof Constructor && (scope.equals(decl) || !ModelUtil.isLocalNotInitializerScope(scope)))) {
        TypeDeclaration klass = (TypeDeclaration) scope;
        if (klass.isAnonymous() && !klass.isNamed())
            typeDeclarationBuilder.clear();
        String className = "";
        if (klass.getName() != null) {
            if (ModelUtil.isCeylonDeclaration(klass))
                className = escapeClassName(klass.getName());
            else
                className = getRealName(klass, NA_WRAPPER_UNQUOTED);
        }
        typeDeclarationBuilder.append(className);
        if (ModelUtil.isCeylonDeclaration(klass)) {
            if (flags.contains(DeclNameFlag.COMPANION) && ModelUtil.isLocalNotInitializer(klass) && last) {
                typeDeclarationBuilder.append(IMPL_POSTFIX);
            } else if (flags.contains(DeclNameFlag.ANNOTATION) && last) {
                typeDeclarationBuilder.append(ANNO_POSTFIX);
            } else if (flags.contains(DeclNameFlag.ANNOTATIONS) && last) {
                typeDeclarationBuilder.append(ANNOS_POSTFIX);
            } else if (flags.contains(DeclNameFlag.DELEGATION) && last) {
                typeDeclarationBuilder.append(DELEGATION_POSTFIX);
            }
        }
    } else if (scope instanceof Interface) {
        Interface iface = (Interface) scope;
        String className = "";
        if (iface.getName() != null) {
            if (ModelUtil.isCeylonDeclaration(iface))
                className = iface.getName();
            else
                className = getRealName(iface, NA_WRAPPER_UNQUOTED);
        }
        typeDeclarationBuilder.append(className);
        if (ModelUtil.isCeylonDeclaration(iface) && ((decl instanceof Class || decl instanceof Constructor || decl instanceof TypeAlias || scope instanceof Constructor) || flags.contains(DeclNameFlag.COMPANION))) {
            typeDeclarationBuilder.append(IMPL_POSTFIX);
        }
    } else if (ModelUtil.isLocalNotInitializerScope(scope)) {
        if (flags.contains(DeclNameFlag.COMPANION) || !(decl instanceof Interface)) {
            typeDeclarationBuilder.clear();
        } else if (flags.contains(DeclNameFlag.QUALIFIED) || (decl instanceof Interface)) {
            Scope nonLocal = scope;
            while (!(nonLocal instanceof Declaration)) {
                nonLocal = nonLocal.getContainer();
            }
            typeDeclarationBuilder.append(((Declaration) nonLocal).getPrefixedName());
            if (!Decl.equalScopes(scope, nonLocal)) {
                typeDeclarationBuilder.append('$');
                typeDeclarationBuilder.append(getLocalId(scope));
            }
            if (decl instanceof Interface) {
                typeDeclarationBuilder.append('$');
            } else {
                if (flags.contains(DeclNameFlag.QUALIFIED)) {
                    typeDeclarationBuilder.selectAppended();
                } else {
                    typeDeclarationBuilder.clear();
                }
            }
        }
        return;
    } else if (scope instanceof TypedDeclaration && ((Declaration) scope).isToplevel()) {
    // nothing? that's just weird
    }
    if (!last) {
        if (decl instanceof Interface && ModelUtil.isCeylonDeclaration((TypeDeclaration) decl) && !flags.contains(DeclNameFlag.COMPANION)) {
            typeDeclarationBuilder.append('$');
        } else if (decl instanceof Constructor && ((Class) decl.getContainer()).isMember() && decl.getContainer().equals(scope)) {
            typeDeclarationBuilder.append('$');
        } else {
            if (flags.contains(DeclNameFlag.QUALIFIED)) {
                typeDeclarationBuilder.selectAppended();
            } else {
                typeDeclarationBuilder.clear();
            }
        }
    } else {
        typeDeclarationBuilder.selectAppended();
    }
    return;
}
Also used : TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) LazyClass(org.eclipse.ceylon.model.loader.model.LazyClass) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypeAlias(org.eclipse.ceylon.model.typechecker.model.TypeAlias) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Interface(org.eclipse.ceylon.model.typechecker.model.Interface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) LazyInterface(org.eclipse.ceylon.model.loader.model.LazyInterface)

Example 64 with TypeDeclaration

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

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();
            if (qualifyingType != null) {
                Type supertype = qualifyingType.getSupertype(container);
                return paramType.substitute(supertype);
            }
        }
    }
    return paramType;
}
Also used : TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Type(org.eclipse.ceylon.model.typechecker.model.Type) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 65 with TypeDeclaration

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

the class Decl method getOuterScopeOfMemberInvocation.

public static TypeDeclaration getOuterScopeOfMemberInvocation(Tree.StaticMemberOrTypeExpression expr, Declaration decl) {
    // First check whether the expression is captured from an enclosing scope
    TypeDeclaration outer = null;
    // get the ClassOrInterface container of the declaration
    Scope stop = ModelUtil.getClassOrInterfaceContainer(decl, false);
    if (stop instanceof TypeDeclaration) {
        // reified scope
        Scope scope = expr.getScope();
        while (!(scope instanceof Package)) {
            if (scope.equals(stop)) {
                outer = (TypeDeclaration) stop;
                break;
            }
            scope = scope.getContainer();
        }
    }
    // If not it might be inherited...
    if (outer == null) {
        outer = expr.getScope().getInheritingDeclaration(decl);
    }
    return outer;
}
Also used : Scope(org.eclipse.ceylon.model.typechecker.model.Scope) ConditionScope(org.eclipse.ceylon.model.typechecker.model.ConditionScope) Package(org.eclipse.ceylon.model.typechecker.model.Package) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Aggregations

TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)303 Type (org.eclipse.ceylon.model.typechecker.model.Type)180 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)88 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)86 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)80 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)70 Class (org.eclipse.ceylon.model.typechecker.model.Class)68 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)65 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)57 UnionType (org.eclipse.ceylon.model.typechecker.model.UnionType)57 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)55 IntersectionType (org.eclipse.ceylon.model.typechecker.model.IntersectionType)51 Test (org.junit.Test)51 AnalyzerUtil.getPackageTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration)49 AnalyzerUtil.getTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)49 ArrayList (java.util.ArrayList)48 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)44 Interface (org.eclipse.ceylon.model.typechecker.model.Interface)43 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)39 ModelUtil.intersectionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType)34