Search in sources :

Example 36 with Class

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

the class LocalTypeVisitor method visit.

@Override
public void visit(Tree.BaseMemberOrTypeExpression that) {
    Declaration model = that.getDeclaration();
    if (model != null && (model instanceof Function || model instanceof Class) && !that.getAssigned() && // if it's a parameter we don't need to wrap it in a class
    !model.isParameter() && (model instanceof Class == false || !that.getStaticMethodReferencePrimary()) && !that.getDirectlyInvoked()) {
        String prefix = this.prefix;
        enterAnonymousClass();
        super.visit(that);
        exitAnonymousClass();
        this.prefix = prefix;
    } else {
        super.visit(that);
    }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Example 37 with Class

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

the class LocalTypeVisitor method visit.

@Override
public void visit(Tree.QualifiedMemberOrTypeExpression that) {
    Declaration model = that.getDeclaration();
    if (model != null && (model instanceof Function || model instanceof Class) && !that.getAssigned() && // if it's a parameter we don't need to wrap it in a class
    !model.isParameter() && (model instanceof Class == false || !that.getStaticMethodReferencePrimary()) && !that.getDirectlyInvoked()) {
        String prefix = this.prefix;
        enterAnonymousClass();
        super.visit(that);
        exitAnonymousClass();
        this.prefix = prefix;
    } else {
        super.visit(that);
    }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Example 38 with Class

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

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

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

the class Naming method makeTypeDeclaration.

private <R> R makeTypeDeclaration(TypeDeclarationBuilder<R> declarationBuilder, final TypeDeclaration decl, DeclNameFlag... options) {
    EnumSet<DeclNameFlag> flags = EnumSet.noneOf(DeclNameFlag.class);
    flags.addAll(Arrays.asList(options));
    if (flags.contains(DeclNameFlag.ANNOTATION) && !Decl.isAnnotationClass(decl)) {
        throw new BugException(decl.getName());
    }
    if (flags.contains(DeclNameFlag.ANNOTATIONS) && !(Decl.isAnnotationClass(decl) || decl instanceof Class || gen().isSequencedAnnotation((Class) decl))) {
        throw new BugException(decl.getName());
    }
    java.util.List<Scope> l = new java.util.ArrayList<Scope>();
    Scope s = decl;
    do {
        l.add(s);
        s = s.getContainer();
    } while (!(s instanceof Package));
    Collections.reverse(l);
    if (flags.contains(DeclNameFlag.QUALIFIED) && (!decl.isAnonymous() || decl.isNamed())) {
        final List<String> packageName = Decl.isJavaArray(decl) || AbstractTransformer.isJavaInterop(decl) ? ORG_ECLIPSE_CEYLON_LANGUAGE_PACKAGE : ((Package) s).getName();
        if (packageName.isEmpty() || !packageName.get(0).isEmpty()) {
            declarationBuilder.select("");
        }
        for (int ii = 0; ii < packageName.size(); ii++) {
            declarationBuilder.select(quoteIfJavaKeyword(packageName.get(ii)));
        }
    }
    for (int ii = 0; ii < l.size(); ii++) {
        Scope scope = l.get(ii);
        final boolean last = ii == l.size() - 1;
        appendTypeDeclaration(decl, flags, declarationBuilder, scope, last);
    }
    return declarationBuilder.result();
}
Also used : ArrayList(java.util.ArrayList) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) LazyClass(org.eclipse.ceylon.model.loader.model.LazyClass) Class(org.eclipse.ceylon.model.typechecker.model.Class) Package(org.eclipse.ceylon.model.typechecker.model.Package)

Aggregations

Class (org.eclipse.ceylon.model.typechecker.model.Class)184 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)110 Type (org.eclipse.ceylon.model.typechecker.model.Type)87 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)78 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)72 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)55 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)46 Value (org.eclipse.ceylon.model.typechecker.model.Value)46 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)42 UnionType (org.eclipse.ceylon.model.typechecker.model.UnionType)39 Function (org.eclipse.ceylon.model.typechecker.model.Function)38 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)36 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)35 Interface (org.eclipse.ceylon.model.typechecker.model.Interface)33 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)33 ArrayList (java.util.ArrayList)32 IntersectionType (org.eclipse.ceylon.model.typechecker.model.IntersectionType)32 JCNewClass (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCNewClass)31 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)27 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)23