Package com.redhat.ceylon.compiler.typechecker.model

Examples of com.redhat.ceylon.compiler.typechecker.model.TypeDeclaration


            if (pt == null) {
                gen.out("'", e.getKey().getName(), "'");
            } else if (!outputTypeList(node, pt, gen, skipSelfDecl)) {
                boolean hasParams = pt.getTypeArgumentList() != null && !pt.getTypeArgumentList().isEmpty();
                boolean closeBracket = false;
                final TypeDeclaration d = pt.getDeclaration();
                if (d instanceof TypeParameter) {
                    resolveTypeParameter(node, (TypeParameter)d, gen, skipSelfDecl);
                } else {
                    closeBracket = pt.getDeclaration() instanceof TypeAlias==false;
                    if (closeBracket)gen.out("{t:");
View Full Code Here


        gen.out("}");
    }

    static void outputQualifiedTypename(final Node node, final boolean imported, final ProducedType pt,
            final GenerateJsVisitor gen, final boolean skipSelfDecl) {
        TypeDeclaration t = pt.getDeclaration();
        final String qname = t.getQualifiedNameString();
        if (qname.equals("ceylon.language::Nothing")) {
            //Hack in the model means hack here as well
            gen.out(gen.getClAlias(), "Nothing");
        } else if (qname.equals("ceylon.language::null") || qname.equals("ceylon.language::Null")) {
            gen.out(gen.getClAlias(), "Null");
        } else if (pt.isUnknown()) {
            gen.out(gen.getClAlias(), "Anything");
        } else {
            final String modAlias = imported ? gen.getNames().moduleAlias(t.getUnit().getPackage().getModule()) : null;
            if (modAlias != null && !modAlias.isEmpty()) {
                gen.out(modAlias, ".");
            }
            if (t.getContainer() instanceof ClassOrInterface) {
                final Scope scope = node == null ? null : Util.getContainingClassOrInterface(node.getScope());
                List<ClassOrInterface> parents = new ArrayList<>();
                ClassOrInterface parent = (ClassOrInterface)t.getContainer();
                parents.add(0, parent);
                while (parent.getContainer() instanceof ClassOrInterface) {
                    parent = (ClassOrInterface)parent.getContainer();
                    parents.add(0, parent);
                }
View Full Code Here

    /** Prints out an object with a type constructor under the property "t" and its type arguments under
     * the property "a", or a union/intersection type with "u" or "i" under property "t" and the list
     * of types that compose it in an array under the property "l", or a type parameter as a reference to
     * already existing params. */
    static void typeNameOrList(final Node node, final ProducedType pt, final GenerateJsVisitor gen, final boolean skipSelfDecl) {
        TypeDeclaration type = pt.getDeclaration();
        if (!outputTypeList(node, pt, gen, skipSelfDecl)) {
            if (type instanceof TypeParameter) {
                resolveTypeParameter(node, (TypeParameter)type, gen, skipSelfDecl);
            } else if (type instanceof TypeAlias) {
                outputQualifiedTypename(node, node != null && gen.isImported(node.getUnit().getPackage(), type),
View Full Code Here

        }
    }

    /** Appends an object with the type's type and list of union/intersection types. */
    static boolean outputTypeList(final Node node, final ProducedType pt, final GenerateJsVisitor gen, final boolean skipSelfDecl) {
        TypeDeclaration d = pt.getDeclaration();
        final List<ProducedType> subs;
        if (d instanceof IntersectionType) {
            gen.out("{t:'i");
            subs = d.getSatisfiedTypes();
        } else if (d instanceof UnionType) {
            gen.out("{t:'u");
            subs = d.getCaseTypes();
        } else if ("ceylon.language::Tuple".equals(d.getQualifiedNameString())) {
            gen.out("{t:'T");
            subs = node.getUnit().getTupleElementTypes(pt);
            final ProducedType lastType = subs.get(subs.size()-1);
            if (node.getUnit().getSequenceDeclaration().equals(lastType.getDeclaration())
                    || node.getUnit().getSequentialDeclaration().equals(lastType.getDeclaration())) {
View Full Code Here

            }
        }
    }

    static ProducedType typeContainsTypeParameter(ProducedType td, TypeParameter tp) {
        TypeDeclaration d = td.getDeclaration();
        if (d == tp) {
            return td;
        } else if (d instanceof UnionType || d instanceof IntersectionType) {
            List<ProducedType> comps = td.getCaseTypes();
            if (comps == null) comps = td.getSupertypes();
View Full Code Here

    /** Turns a Tuple type into a parameter list. */
    List<Parameter> convertTupleToParameters(ProducedType _tuple) {
        ArrayList<Parameter> rval = new ArrayList<>();
        int pos = 0;
        TypeDeclaration tdecl = _tuple.getDeclaration();
        while (!(empty.equals(tdecl) || tdecl instanceof TypeParameter)) {
            Parameter _p = null;
            if (tuple.equals(tdecl) || (tdecl.getCaseTypeDeclarations() != null
                    && tdecl.getCaseTypeDeclarations().size()==2
                    && tdecl.getCaseTypeDeclarations().contains(tuple))) {
                _p = new Parameter();
                _p.setModel(new Value());
                if (tuple.equals(tdecl)) {
                    _p.getModel().setType(_tuple.getTypeArgumentList().get(1));
                    _tuple = _tuple.getTypeArgumentList().get(2);
                } else {
                    //Handle union types for defaulted parameters
                    for (ProducedType mt : _tuple.getCaseTypes()) {
                        if (tuple.equals(mt.getDeclaration())) {
                            _p.getModel().setType(mt.getTypeArgumentList().get(1));
                            _tuple = mt.getTypeArgumentList().get(2);
                            break;
                        }
                    }
                    _p.setDefaulted(true);
                }
            } else if (tdecl.inherits(sequential)) {
                //Handle Sequence, for nonempty variadic parameters
                _p = new Parameter();
                _p.setModel(new Value());
                _p.getModel().setType(_tuple.getTypeArgumentList().get(0));
                _p.setSequenced(true);
View Full Code Here

    /** This method encodes the type parameters of a Tuple in the same way
     * as a parameter list for runtime. */
    private static void encodeTupleAsParameterListForRuntime(ProducedType _tuple, boolean nameAndMetatype, GenerateJsVisitor gen) {
        gen.out("[");
        int pos = 1;
        TypeDeclaration tdecl = _tuple.getDeclaration();
        while (!(gen.getTypeUtils().empty.equals(tdecl) || tdecl instanceof TypeParameter)) {
            if (pos > 1) gen.out(",");
            gen.out("{");
            pos++;
            if (nameAndMetatype) {
                gen.out(MetamodelGenerator.KEY_NAME, ":'p", Integer.toString(pos), "',");
                gen.out(MetamodelGenerator.KEY_METATYPE, ":'", MetamodelGenerator.METATYPE_PARAMETER, "',");
            }
            gen.out(MetamodelGenerator.KEY_TYPE, ":");
            if (gen.getTypeUtils().tuple.equals(tdecl) || (tdecl.getCaseTypeDeclarations() != null
                    && tdecl.getCaseTypeDeclarations().size()==2
                    && tdecl.getCaseTypeDeclarations().contains(gen.getTypeUtils().tuple))) {
                if (gen.getTypeUtils().tuple.equals(tdecl)) {
                    metamodelTypeNameOrList(gen.getCurrentPackage(), _tuple.getTypeArgumentList().get(1), gen);
                    _tuple = _tuple.getTypeArgumentList().get(2);
                } else {
                    //Handle union types for defaulted parameters
                    for (ProducedType mt : _tuple.getCaseTypes()) {
                        if (gen.getTypeUtils().tuple.equals(mt.getDeclaration())) {
                            metamodelTypeNameOrList(gen.getCurrentPackage(), mt.getTypeArgumentList().get(1), gen);
                            _tuple = mt.getTypeArgumentList().get(2);
                            break;
                        }
                    }
                    gen.out(",", MetamodelGenerator.KEY_DEFAULT,":1");
                }
            } else if (tdecl.inherits(gen.getTypeUtils().sequential)) {
                ProducedType _t2 = _tuple.getSupertype(gen.getTypeUtils().sequential);
                //Handle Sequence, for nonempty variadic parameters
                metamodelTypeNameOrList(gen.getCurrentPackage(), _t2.getTypeArgumentList().get(0), gen);
                gen.out(",seq:1");
                _tuple = gen.getTypeUtils().empty.getType();
            } else if (tdecl instanceof UnionType) {
                metamodelTypeNameOrList(gen.getCurrentPackage(), _tuple, gen);
                tdecl = gen.getTypeUtils().empty; _tuple=null;
            } else {
                gen.out("\n/*WARNING3! Tuple is actually ", _tuple.getProducedTypeQualifiedName(), ", ", tdecl.getName(),"*/");
                if (pos > 100) {
                    break;
                }
            }
            gen.out("}");
View Full Code Here

                    } else if (p instanceof Method) {
                        sb.add(i, MetamodelGenerator.KEY_METHODS);
                    } else if (p instanceof TypeAlias || p instanceof Setter) {
                        sb.add(i, MetamodelGenerator.KEY_ATTRIBUTES);
                    } else { //It's a value
                        TypeDeclaration td=((TypedDeclaration)p).getTypeDeclaration();
                        sb.add(i, (td!=null&&td.isAnonymous())? MetamodelGenerator.KEY_OBJECTS
                                : MetamodelGenerator.KEY_ATTRIBUTES);
                    }
                }
                p = Util.getContainingDeclaration(p);
            }
View Full Code Here

            //In dynamic blocks we sometimes get a null producedType
            pt = ((TypeDeclaration)pkg.getModule().getLanguageModule().getDirectPackage(
                    Module.LANGUAGE_MODULE_NAME).getDirectMember("Anything", null, false)).getType();
        }
        if (!outputMetamodelTypeList(pkg, pt, gen)) {
            TypeDeclaration type = pt.getDeclaration();
            if (type instanceof TypeParameter) {
                gen.out("'", type.getNameAsString(), "$", ((TypeParameter)type).getDeclaration().getName(), "'");
            } else if (type instanceof TypeAlias) {
                outputQualifiedTypename(null, gen.isImported(pkg, type), pt, gen, false);
            } else {
                gen.out("{t:");
                outputQualifiedTypename(null, gen.isImported(pkg, type), pt, gen, false);
View Full Code Here

    /** Appends an object with the type's type and list of union/intersection types; works only with union,
     * intersection and tuple types.
     * @return true if output was generated, false otherwise (it was a regular type) */
    static boolean outputMetamodelTypeList(final com.redhat.ceylon.compiler.typechecker.model.Package pkg,
            ProducedType pt, GenerateJsVisitor gen) {
        TypeDeclaration type = pt.getDeclaration();
        final List<ProducedType> subs;
        if (type instanceof IntersectionType) {
            gen.out("{t:'i");
            subs = type.getSatisfiedTypes();
        } else if (type instanceof UnionType) {
            //It still could be a Tuple with first optional type
            List<TypeDeclaration> cts = type.getCaseTypeDeclarations();
            if (cts.size()==2 && cts.contains(gen.getTypeUtils().empty) && cts.contains(gen.getTypeUtils().tuple)) {
                //yup...
                gen.out("{t:'T',l:");
                encodeTupleAsParameterListForRuntime(pt,false,gen);
                gen.out("}");
                return true;
            }
            gen.out("{t:'u");
            subs = type.getCaseTypes();
        } else if (type.getQualifiedNameString().equals("ceylon.language::Tuple")) {
            gen.out("{t:'T',l:");
            encodeTupleAsParameterListForRuntime(pt,false, gen);
            gen.out("}");
            return true;
        } else {
View Full Code Here

TOP

Related Classes of com.redhat.ceylon.compiler.typechecker.model.TypeDeclaration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.