Search in sources :

Example 46 with Type

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

the class LinkRenderer method decorateWithLinkDropdownMenu.

private String decorateWithLinkDropdownMenu(String link, Type producedType) {
    if (!printLinkDropdownMenu || !printAbbreviated || !canLinkToCeylonLanguageModule()) {
        return link;
    }
    List<Type> producedTypes = new ArrayList<Type>();
    decompose(producedType, producedTypes);
    boolean containsOptional = false;
    boolean containsSequential = false;
    boolean containsSequence = false;
    boolean containsIterable = false;
    boolean containsEntry = false;
    boolean containsCallable = false;
    boolean containsTuple = false;
    for (Type pt : producedTypes) {
        if (abbreviateOptional(pt)) {
            containsOptional = true;
        } else if (abbreviateSequential(pt) && !link.contains("'Go to ceylon.language::Sequential'")) {
            containsSequential = true;
        } else if (abbreviateSequence(pt) && !link.contains("'Go to ceylon.language::Sequence'")) {
            containsSequence = true;
        } else if (abbreviateIterable(pt) && !link.contains("'Go to ceylon.language::Iterable'")) {
            containsIterable = true;
        } else if (abbreviateEntry(pt) && !link.contains("'Go to ceylon.language::Entry'")) {
            containsEntry = true;
        } else if (abbreviateCallable(pt) && !link.contains("'Go to ceylon.language::Callable'")) {
            containsCallable = true;
        } else if (abbreviateTuple(pt) && !link.contains("'Go to ceylon.language::Tuple'")) {
            containsTuple = true;
        }
    }
    Unit unit = producedType.getDeclaration().getUnit();
    if (containsOptional || containsSequential || containsSequence || containsIterable || containsEntry || containsCallable || containsTuple) {
        StringBuilder sb = new StringBuilder();
        sb.append("<span class='link-dropdown'>");
        sb.append(link.replaceAll("class='link'", "class='link type-identifier'"));
        sb.append("<span class='dropdown'>");
        sb.append("<a class='dropdown-toggle' data-toggle='dropdown' href='#'><b title='Show more links' class='caret'></b></a>");
        sb.append("<ul class='dropdown-menu'>");
        if (containsOptional) {
            sb.append(getLinkMenuItem(unit.getNullDeclaration(), "abbreviations X? means Null|X"));
        }
        if (containsSequential) {
            sb.append(getLinkMenuItem(unit.getSequentialDeclaration(), "abbreviation X[] or [X*] means Sequential&lt;X&gt;"));
        }
        if (containsSequence) {
            sb.append(getLinkMenuItem(unit.getSequenceDeclaration(), "abbreviation [X+] means Sequence&lt;X&gt;"));
        }
        if (containsIterable) {
            sb.append(getLinkMenuItem(unit.getIterableDeclaration(), "abbreviation {X+} or {X*} means Iterable&lt;X,Nothing&gt; or Iterable&lt;X,Null&gt;"));
        }
        if (containsEntry) {
            sb.append(getLinkMenuItem(unit.getEntryDeclaration(), "abbreviation X-&gt;Y means Entry&lt;X,Y&gt;"));
        }
        if (containsCallable) {
            sb.append(getLinkMenuItem(unit.getCallableDeclaration(), "abbreviation X(Y,Z) means Callable&lt;X,[Y,Z]&gt;"));
        }
        if (containsTuple) {
            sb.append(getLinkMenuItem(unit.getTupleDeclaration(), "abbreviation [X,Y] means Tuple&lt;X|Y,X,Tuple&lt;Y,Y,[]&gt;&gt;"));
        }
        // dropdown-menu
        sb.append("</ul>");
        // dropdown
        sb.append("</span>");
        // link-dropdown
        sb.append("</span>");
        return sb.toString();
    }
    return link;
}
Also used : Util.isAbbreviatedType(org.eclipse.ceylon.ceylondoc.Util.isAbbreviatedType) NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType) Type(org.eclipse.ceylon.model.typechecker.model.Type) ArrayList(java.util.ArrayList) Unit(org.eclipse.ceylon.model.typechecker.model.Unit)

Example 47 with Type

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

the class Util method getSuperInterfaces.

public static List<TypeDeclaration> getSuperInterfaces(TypeDeclaration decl) {
    Set<TypeDeclaration> superInterfaces = new HashSet<TypeDeclaration>();
    for (Type satisfiedType : decl.getSatisfiedTypes()) {
        superInterfaces.add(satisfiedType.getDeclaration());
        superInterfaces.addAll(getSuperInterfaces(satisfiedType.getDeclaration()));
    }
    List<TypeDeclaration> list = new ArrayList<TypeDeclaration>();
    list.addAll(superInterfaces);
    removeDuplicates(list);
    return list;
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) ArrayList(java.util.ArrayList) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) HashSet(java.util.HashSet)

Example 48 with Type

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

the class TypePrinter method abbreviateIterable.

public static boolean abbreviateIterable(Type pt) {
    if (pt.isIterable()) {
        Unit unit = pt.getDeclaration().getUnit();
        Type et = unit.getIteratedType(pt);
        List<Type> typeArgs = pt.getTypeArgumentList();
        if (et != null && typeArgs.size() == 2) {
            Type at = typeArgs.get(1);
            if (at != null) {
                return at.isNothing() || at.isNull();
            }
        }
    // && et.isPrimitiveAbbreviatedType();
    }
    return false;
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) Unit(org.eclipse.ceylon.model.typechecker.model.Unit)

Example 49 with Type

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

the class TypePrinter method getTupleElementTypeNames.

private String getTupleElementTypeNames(Type args, Unit unit) {
    if (args != null) {
        Unit u = args.getDeclaration().getUnit();
        boolean defaulted = false;
        if (args.isUnion()) {
            List<Type> cts = args.getCaseTypes();
            if (cts.size() == 2) {
                Type lc = cts.get(0);
                if (lc.isEmpty()) {
                    args = cts.get(1);
                    defaulted = true;
                }
                Type rc = cts.get(1);
                if (rc.isEmpty()) {
                    args = cts.get(0);
                    defaulted = true;
                }
            }
        }
        if (args.isClassOrInterface()) {
            if (args.isTuple()) {
                List<Type> tal = args.getTypeArgumentList();
                if (tal.size() >= 3) {
                    Type first = tal.get(1);
                    Type rest = tal.get(2);
                    if (first != null && rest != null) {
                        String argtype = print(first, unit);
                        if (rest.isEmpty()) {
                            return defaulted ? argtype + "=" : argtype;
                        }
                        String argtypes = getTupleElementTypeNames(rest, unit);
                        if (argtypes != null) {
                            return defaulted ? argtype + "=, " + argtypes : argtype + ", " + argtypes;
                        }
                    }
                }
            } else if (args.isEmpty()) {
                return defaulted ? "=" : "";
            } else if (!defaulted && args.isSequential()) {
                Type elementType = u.getIteratedType(args);
                if (elementType != null) {
                    String elemtype = print(elementType, unit);
                    if (isPrimitiveAbbreviatedType(elementType)) {
                        return elemtype + "*";
                    } else {
                        return lt() + elemtype + gt() + "*";
                    }
                }
            } else if (!defaulted && args.isSequence()) {
                Type elementType = u.getIteratedType(args);
                if (elementType != null) {
                    String elemtype = print(elementType, unit);
                    if (isPrimitiveAbbreviatedType(elementType)) {
                        return elemtype + "+";
                    } else {
                        return lt() + elemtype + gt() + "+";
                    }
                }
            }
        }
    }
    return null;
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) Unit(org.eclipse.ceylon.model.typechecker.model.Unit)

Example 50 with Type

use of org.eclipse.ceylon.model.typechecker.model.Type 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)

Aggregations

Type (org.eclipse.ceylon.model.typechecker.model.Type)692 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)270 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)263 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)244 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)225 ModelUtil.intersectionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType)207 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)182 AnalyzerUtil.getTupleType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType)176 AnalyzerUtil.spreadType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType)176 ModelUtil.unionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType)169 ModelUtil.genericFunctionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.genericFunctionType)153 UnionType (org.eclipse.ceylon.model.typechecker.model.UnionType)130 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)125 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)114 ArrayList (java.util.ArrayList)106 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)100 JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)96 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)95 IntersectionType (org.eclipse.ceylon.model.typechecker.model.IntersectionType)94 Class (org.eclipse.ceylon.model.typechecker.model.Class)87