Search in sources :

Example 6 with Unit

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

the class TypePrinter method print.

public String print(Type pt, Unit unit) {
    if (pt == null) {
        return "unknown";
    } else {
        if (printAbbreviated() && !pt.isTypeAlias()) {
            // TODO: we're going to have to fix this!
            Unit u = pt.getDeclaration().getUnit();
            if (abbreviateOptional(pt)) {
                Type dt = pt.eliminateNull();
                if (!dt.isNothing()) {
                    String dtn = print(dt, unit);
                    if (isPrimitiveAbbreviatedType(dt)) {
                        return dtn + "?";
                    } else {
                        return lt() + dtn + gt() + "?";
                    }
                }
            }
            if (abbreviateEmpty(pt)) {
                return "[]";
            }
            if (abbreviateHomoTuple(pt)) {
                Type et = u.getSequentialElementType(pt);
                String etn = print(et, unit);
                int len = u.getHomogeneousTupleLength(pt);
                if (isPrimitiveAbbreviatedType(et)) {
                    return etn + "[" + len + "]";
                } else {
                    return "<" + etn + ">[" + len + "]";
                }
            }
            if (abbreviateSequential(pt)) {
                Type it = u.getIteratedType(pt);
                String etn = print(it, unit);
                if (isPrimitiveAbbreviatedType(it)) {
                    return etn + "[]";
                } else {
                    return lt() + etn + gt() + "[]";
                }
            }
            if (abbreviateSequence(pt)) {
                Type it = u.getIteratedType(pt);
                String etn = print(it, unit);
                if (isPrimitiveAbbreviatedType(it) || it.isUnion() || it.isIntersection()) {
                    return "[" + etn + "+]";
                } else {
                    return "[" + lt() + etn + gt() + "+]";
                }
            }
            if (abbreviateIterable(pt)) {
                Type it = u.getIteratedType(pt);
                Type nt = pt.getTypeArgumentList().get(1);
                /*if (it.isNothing() && !nt.isNothing()) {
                    	return "{}";
                    }*/
                String itn = print(it, unit);
                String many = nt.isNothing() ? "+" : "*";
                if (isPrimitiveAbbreviatedType(it) || it.isUnion() || it.isIntersection()) {
                    return "{" + itn + many + "}";
                } else {
                    return "{" + lt() + itn + gt() + many + "}";
                }
            }
            if (abbreviateEntry(pt)) {
                Type kt = u.getKeyType(pt);
                Type vt = u.getValueType(pt);
                return print(kt, unit) + "-" + gt() + print(vt, unit);
            }
            if (abbreviateCallable(pt)) {
                List<Type> tal = pt.getTypeArgumentList();
                Type rt = tal.get(0);
                Type at = tal.get(1);
                if (abbreviateCallableArg(at)) {
                    String paramTypes = getTupleElementTypeNames(at, unit);
                    if (rt != null && paramTypes != null) {
                        String rtn = print(rt, unit);
                        if (!isPrimitiveAbbreviatedType(rt)) {
                            rtn = lt() + rtn + gt();
                        }
                        return rtn + "(" + paramTypes + ")";
                    }
                } else {
                    if (rt != null && at != null) {
                        String rtn = print(rt, unit);
                        String atn = print(at, unit);
                        if (!isPrimitiveAbbreviatedType(at)) {
                            atn = lt() + atn + gt();
                        }
                        if (!isPrimitiveAbbreviatedType(rt)) {
                            rtn = lt() + rtn + gt();
                        }
                        return rtn + "(*" + atn + ")";
                    }
                }
            }
            if (abbreviateTuple(pt)) {
                String elemTypes = getTupleElementTypeNames(pt, unit);
                if (elemTypes != null) {
                    return "[" + elemTypes + "]";
                }
            }
        }
        return printWithoutAbbreviation(pt, unit);
    }
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) Unit(org.eclipse.ceylon.model.typechecker.model.Unit)

Example 7 with Unit

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

the class TypePrinter method abbreviateEntry.

public static boolean abbreviateEntry(Type pt) {
    if (pt.isEntry() && pt.getTypeArgumentList().size() == 2) {
        Unit unit = pt.getDeclaration().getUnit();
        Type kt = unit.getKeyType(pt);
        Type vt = unit.getValueType(pt);
        return kt != null && vt != null && !kt.isEntry() && !vt.isEntry();
    /*&&
                    kt.isPrimitiveAbbreviatedType() && 
                    vt.isPrimitiveAbbreviatedType();*/
    } else {
        return false;
    }
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) Unit(org.eclipse.ceylon.model.typechecker.model.Unit)

Example 8 with Unit

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

the class TypePrinter method abbreviateCallable.

public static boolean abbreviateCallable(Type pt) {
    if (pt.isInterface()) {
        TypeDeclaration dec = pt.getDeclaration();
        Unit unit = dec.getUnit();
        Interface callableDeclaration = unit.getCallableDeclaration();
        return dec.equals(callableDeclaration) && pt.getTypeArgumentList().size() == 2 && pt.getTypeArgumentList().get(0) != null;
    } else {
        return false;
    }
}
Also used : Unit(org.eclipse.ceylon.model.typechecker.model.Unit) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Interface(org.eclipse.ceylon.model.typechecker.model.Interface)

Example 9 with Unit

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

the class AnalyzerUtil method getUnspecifiedParameter.

static Parameter getUnspecifiedParameter(Reference pr, ParameterList pl, Set<Parameter> foundParameters) {
    for (Parameter p : pl.getParameters()) {
        Type t = pr == null ? p.getType() : pr.getTypedParameter(p).getFullType();
        if (t != null) {
            t = t.resolveAliases();
            Unit unit = p.getDeclaration().getUnit();
            if (!foundParameters.contains(p) && unit.isIterableParameterType(t)) {
                return p;
            }
        }
    }
    return null;
}
Also used : ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType) ModelUtil.unionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType) Type(org.eclipse.ceylon.model.typechecker.model.Type) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Unit(org.eclipse.ceylon.model.typechecker.model.Unit)

Example 10 with Unit

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

the class AnalyzerUtil method getLastExecutableStatement.

public static Tree.Statement getLastExecutableStatement(Tree.ClassBody that) {
    List<Tree.Statement> statements = that.getStatements();
    Unit unit = that.getUnit();
    for (int i = statements.size() - 1; i >= 0; i--) {
        Tree.Statement s = statements.get(i);
        if (isExecutableStatement(unit, s) || s instanceof Tree.Constructor || s instanceof Tree.Enumerated) {
            return s;
        }
    }
    return null;
}
Also used : ModelUtil.isConstructor(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isConstructor) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Unit(org.eclipse.ceylon.model.typechecker.model.Unit)

Aggregations

Unit (org.eclipse.ceylon.model.typechecker.model.Unit)82 Type (org.eclipse.ceylon.model.typechecker.model.Type)41 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)31 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)25 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)23 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)16 AnalyzerUtil.getTypedDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration)11 ArrayList (java.util.ArrayList)10 Class (org.eclipse.ceylon.model.typechecker.model.Class)10 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)10 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)9 Function (org.eclipse.ceylon.model.typechecker.model.Function)9 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)9 ModelUtil.intersectionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType)9 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)9 Value (org.eclipse.ceylon.model.typechecker.model.Value)9 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)7 Module (org.eclipse.ceylon.model.typechecker.model.Module)7 IntersectionType (org.eclipse.ceylon.model.typechecker.model.IntersectionType)6 LazyType (org.eclipse.ceylon.model.typechecker.model.LazyType)6