Search in sources :

Example 36 with Constructor

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

the class ExpressionVisitor method visit.

@Override
public void visit(Tree.Constructor that) {
    Constructor c = that.getConstructor();
    checkDelegatedConstructor(that.getDelegatedConstructor(), c, that);
    TypeDeclaration occ = enterConstructorDelegation(c);
    Declaration od = beginReturnDeclaration(c);
    Tree.Type rt = beginReturnScope(fakeVoid(that));
    super.visit(that);
    endReturnScope(rt, null);
    endReturnDeclaration(od);
    endConstructorDelegation(occ);
}
Also used : Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) AnalyzerUtil.unwrapAliasedTypeConstructor(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.unwrapAliasedTypeConstructor) ModelUtil.isConstructor(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isConstructor) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) AnalyzerUtil.getPackageTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) ModelUtil.getNativeDeclaration(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getNativeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration) AnalyzerUtil.getPackageTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)

Example 37 with Constructor

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

the class DeprecationVisitor method visit.

@Override
public void visit(Tree.MemberOrTypeExpression that) {
    super.visit(that);
    Declaration d = that.getDeclaration();
    if (d != null && d.isDeprecated()) {
        that.addUsageWarning(Warning.deprecation, "declaration is deprecated: '" + d.getName() + "' is annotated 'deprecated' in " + module(d));
    }
    if (d instanceof Class && that.getDirectlyInvoked()) {
        Class c = (Class) d;
        Constructor dc = c.getDefaultConstructor();
        if (dc != null && dc.isDeprecated()) {
            that.addUsageWarning(Warning.deprecation, "declaration is deprecated: default constructor of '" + d.getName() + "' is annotated 'deprecated' in " + module(d));
        }
    }
}
Also used : Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Example 38 with Constructor

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

the class ClassDeclarationImpl method init.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void init() {
    super.init();
    // anonymous classes don't have parameter lists
    if (!declaration.isAnonymous()) {
        org.eclipse.ceylon.model.typechecker.model.Class classDeclaration = (org.eclipse.ceylon.model.typechecker.model.Class) declaration;
        if (classDeclaration.isAbstraction()) {
            List<Declaration> overloads = classDeclaration.getOverloads();
            if (overloads.size() == 1) {
                classDeclaration = (org.eclipse.ceylon.model.typechecker.model.Class) overloads.get(0);
            }
        // else{
        // throw Metamodel.newModelError("Class has more than one overloaded constructor: "+classDeclaration.getNameAsString());
        // }
        }
        ParameterList parameterList = classDeclaration.getParameterList();
        if (parameterList != null) {
            this.parameters = FunctionalUtil.getParameters(classDeclaration);
        } else {
            this.parameters = null;
        }
    } else {
        this.parameters = null;
    }
    if (((Class) declaration).hasConstructors() || ((Class) declaration).hasEnumerated()) {
        this.constructors = new LinkedList<ceylon.language.meta.declaration.Declaration>();
        for (Declaration d : declaration.getMembers()) {
            if (d instanceof Constructor) {
                this.constructors.add(Metamodel.<ceylon.language.meta.declaration.Declaration>getOrCreateMetamodel(d));
            }
        }
    } else {
        this.constructors = Collections.emptyList();
    }
}
Also used : Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) Class(org.eclipse.ceylon.model.typechecker.model.Class) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) Class(org.eclipse.ceylon.model.typechecker.model.Class) CallableConstructorDeclaration(ceylon.language.meta.declaration.CallableConstructorDeclaration) FunctionOrValueDeclaration(ceylon.language.meta.declaration.FunctionOrValueDeclaration) ValueDeclaration(ceylon.language.meta.declaration.ValueDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) ConstructorDeclaration(ceylon.language.meta.declaration.ConstructorDeclaration) ValueConstructorDeclaration(ceylon.language.meta.declaration.ValueConstructorDeclaration)

Example 39 with Constructor

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

the class GenerateJsVisitor method classDeclaration.

private void classDeclaration(final Tree.ClassDeclaration that) {
    // Don't even bother with nodes that have errors
    if (errVisitor.hasErrors(that))
        return;
    comment(that);
    final Class d = that.getDeclarationModel();
    final String aname = names.name(d);
    final Tree.ClassSpecifier ext = that.getClassSpecifier();
    out(function, aname, "(");
    // Generate each parameter because we need to append one at the end
    for (Tree.Parameter p : that.getParameterList().getParameters()) {
        p.visit(this);
        out(", ");
    }
    if (d.getTypeParameters() != null && !d.getTypeParameters().isEmpty()) {
        out("$$targs$$,");
    }
    out(names.self(d), "){");
    initSelf(that);
    initParameters(that.getParameterList(), d, null);
    out("return ");
    TypeDeclaration aliased = ext.getType().getDeclarationModel();
    final String aliasedName;
    aliasedName = names.name(aliased);
    qualify(that, aliased);
    Scope superscope = getSuperMemberScope(ext.getType());
    if (superscope != null) {
        out("getT$all()['");
        out(superscope.getQualifiedNameString());
        out("'].$$.prototype.", aliasedName, ".call(", names.self(prototypeOwner), ",");
    } else {
        out(aliasedName, "(");
    }
    Tree.PositionalArgumentList posArgs = ext.getInvocationExpression().getPositionalArgumentList();
    if (posArgs != null) {
        posArgs.visit(this);
        if (!posArgs.getPositionalArguments().isEmpty()) {
            out(",");
        }
    } else {
        out("/*PENDIENTE NAMED ARG CLASS DECL */");
    }
    Map<TypeParameter, Type> invargs = ext.getType().getTypeModel().getTypeArguments();
    if (invargs != null && !invargs.isEmpty()) {
        TypeUtils.printTypeArguments(that, invargs, this, true, ext.getType().getTypeModel().getVarianceOverrides());
        out(",");
    }
    out(names.self(d), ");}");
    endLine();
    out(aname, ".$$=");
    qualify(that, aliased);
    out(aliasedName, ".$$");
    endLine(true);
    out(aname, ".$crtmm$=");
    TypeUtils.encodeForRuntime(that, d, this);
    endLine(true);
    share(d);
    if (aliased instanceof Class && ((Class) aliased).hasConstructors() || aliased instanceof Constructor) {
        Class ac = aliased instanceof Constructor ? (Class) ((Constructor) aliased).getContainer() : (Class) aliased;
        for (Declaration cm : ac.getMembers()) {
            if (cm instanceof Constructor && cm != ac.getDefaultConstructor() && cm.isShared()) {
                Constructor cons = (Constructor) cm;
                final String constructorName = aname + names.constructorSeparator(cons) + names.name(cons);
                out("function ", constructorName, "(");
                List<Parameter> parameters = cons.getFirstParameterList().getParameters();
                ArrayList<String> pnames = new ArrayList<>(parameters.size() + 1);
                boolean first = true;
                for (int i = 0; i < parameters.size(); i++) {
                    final String pname = names.createTempVariable();
                    pnames.add(pname);
                    if (first) {
                        first = false;
                    } else {
                        out(",");
                    }
                    out(pname);
                }
                out("){return ");
                qualify(that, cons);
                out(names.name(cons), "(");
                first = true;
                for (String pname : pnames) {
                    if (first) {
                        first = false;
                    } else {
                        out(",");
                    }
                    out(pname);
                }
                out(");}");
                if (ac.isShared()) {
                    sharePrefix(ac, true);
                    out(constructorName, "=", constructorName, ";");
                    endLine();
                }
            }
        }
    }
}
Also used : TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) ArrayList(java.util.ArrayList) IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) Type(org.eclipse.ceylon.model.typechecker.model.Type) ExtendedType(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ExtendedType) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) AttributeDeclaration(org.eclipse.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 40 with Constructor

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

the class GenerateJsVisitor method comment.

void comment(Tree.Declaration that) {
    if (!opts.isComment() || opts.isMinify())
        return;
    endLine();
    String dname = that.getNodeType();
    if (dname.endsWith("Declaration") || dname.endsWith("Definition")) {
        dname = dname.substring(0, dname.length() - 7);
    }
    if (that instanceof Tree.Constructor) {
        Function dec = ((Tree.Constructor) that).getDeclarationModel();
        String cname = ((Class) dec.getContainer()).getName();
        out("//Constructor ", cname, ".", dec.getName() == null ? "<default>" : dec.getName());
    } else {
        out("//", dname, " ", that.getDeclarationModel().getName());
    }
    location(that);
    endLine();
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) Class(org.eclipse.ceylon.model.typechecker.model.Class)

Aggregations

Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)95 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)65 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)48 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)47 Type (org.eclipse.ceylon.model.typechecker.model.Type)45 Class (org.eclipse.ceylon.model.typechecker.model.Class)42 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)42 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)27 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)27 Value (org.eclipse.ceylon.model.typechecker.model.Value)27 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)26 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)25 Function (org.eclipse.ceylon.model.typechecker.model.Function)23 ModelUtil.isConstructor (org.eclipse.ceylon.model.typechecker.model.ModelUtil.isConstructor)21 ArrayList (java.util.ArrayList)20 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)19 Interface (org.eclipse.ceylon.model.typechecker.model.Interface)17 AnalyzerUtil.unwrapAliasedTypeConstructor (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.unwrapAliasedTypeConstructor)16 AnalyzerUtil.getPackageTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration)14 AnalyzerUtil.getTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)14