<commit_before>package com.redhat.ceylon.model.typechecker.util;

import static com.redhat.ceylon.model.typechecker.model.ModelUtil.isElementOfUnion;
import static com.redhat.ceylon.model.typechecker.model.ModelUtil.union;

import java.util.List;

import com.redhat.ceylon.model.typechecker.model.Class;
import com.redhat.ceylon.model.typechecker.model.Declaration;
import com.redhat.ceylon.model.typechecker.model.Interface;
import com.redhat.ceylon.model.typechecker.model.Package;
import com.redhat.ceylon.model.typechecker.model.Scope;
import com.redhat.ceylon.model.typechecker.model.Type;
import com.redhat.ceylon.model.typechecker.model.TypeDeclaration;
import com.redhat.ceylon.model.typechecker.model.TypeParameter;
import com.redhat.ceylon.model.typechecker.model.Unit;

/**
 * Pretty-prints a type expression.
 * @see com.redhat.ceylon.model.loader.TypeParser
 */
public class TypePrinter {

    public static final TypePrinter DEFAULT = 
            new TypePrinter(true, true, false, true, false);

    public static final TypePrinter ESCAPED = 
            new TypePrinter(true, true, false, true, true);

    private final boolean printAbbreviated;
    private final boolean printTypeParameters;
    private final boolean printTypeParameterDetail;
    private final boolean printQualifyingType;
    private final boolean printQualifier;
    private final boolean printFullyQualified;
    private final boolean escapeLowercased;
    
    public TypePrinter() {
        this(false, false, false, false, false, false, false);
    }

    public TypePrinter(boolean printAbbreviated) {
        this(printAbbreviated, true, false, true, false);
    }

    public TypePrinter(boolean printAbbreviated, 
            boolean printTypeParameters, 
            boolean printTypeParameterDetail,
            boolean printQualifyingType,
            boolean escapeLowercased) {
        this(printAbbreviated, printTypeParameters, printTypeParameterDetail, printQualifyingType, escapeLowercased, false, false);
    }
    
    public TypePrinter(boolean printAbbreviated, 
            boolean printTypeParameters, 
            boolean printTypeParameterDetail,
            boolean printQualifyingType,
            boolean escapeLowercased,
            boolean printFullyQualified,
            boolean printQualifier) {
        this.printAbbreviated = printAbbreviated;
        this.printTypeParameters = printTypeParameters;
        this.printTypeParameterDetail = printTypeParameterDetail;
        this.printQualifyingType = printQualifyingType;
        this.escapeLowercased = escapeLowercased;
        this.printFullyQualified = printFullyQualified;
        this.printQualifier = printQualifier;
    }
    
    protected boolean printAbbreviated() {
        return printAbbreviated;
    }

    protected boolean printTypeParameters() {
        return printTypeParameters;
    }

    protected boolean printTypeParameterDetail() {
        return printTypeParameterDetail;
    }

    protected boolean printQualifyingType() {
        return printQualifyingType;
    }

    protected boolean printQualifier() {
        return printQualifier;
    }

    protected boolean printFullyQualified() {
        return printFullyQualified;
    }
    
    protected String lt() {
        return "<";
    }

    protected String gt() {
        return ">";
    }
    
    protected String amp() {
        return "&";
    }

    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();
                    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);
                    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);<commit_msg>that type abbreviation was removed<commit_after>package com.redhat.ceylon.model.typechecker.util;

import static com.redhat.ceylon.model.typechecker.model.ModelUtil.isElementOfUnion;
import static com.redhat.ceylon.model.typechecker.model.ModelUtil.union;

import java.util.List;

import com.redhat.ceylon.model.typechecker.model.Class;
import com.redhat.ceylon.model.typechecker.model.Declaration;
import com.redhat.ceylon.model.typechecker.model.Interface;
import com.redhat.ceylon.model.typechecker.model.Package;
import com.redhat.ceylon.model.typechecker.model.Scope;
import com.redhat.ceylon.model.typechecker.model.Type;
import com.redhat.ceylon.model.typechecker.model.TypeDeclaration;
import com.redhat.ceylon.model.typechecker.model.TypeParameter;
import com.redhat.ceylon.model.typechecker.model.Unit;

/**
 * Pretty-prints a type expression.
 * @see com.redhat.ceylon.model.loader.TypeParser
 */
public class TypePrinter {

    public static final TypePrinter DEFAULT = 
            new TypePrinter(true, true, false, true, false);

    public static final TypePrinter ESCAPED = 
            new TypePrinter(true, true, false, true, true);

    private final boolean printAbbreviated;
    private final boolean printTypeParameters;
    private final boolean printTypeParameterDetail;
    private final boolean printQualifyingType;
    private final boolean printQualifier;
    private final boolean printFullyQualified;
    private final boolean escapeLowercased;
    
    public TypePrinter() {
        this(false, false, false, false, false, false, false);
    }

    public TypePrinter(boolean printAbbreviated) {
        this(printAbbreviated, true, false, true, false);
    }

    public TypePrinter(boolean printAbbreviated, 
            boolean printTypeParameters, 
            boolean printTypeParameterDetail,
            boolean printQualifyingType,
            boolean escapeLowercased) {
        this(printAbbreviated, 
                printTypeParameters, 
                printTypeParameterDetail, 
                printQualifyingType, 
                escapeLowercased, false, false);
    }
    
    public TypePrinter(boolean printAbbreviated, 
            boolean printTypeParameters, 
            boolean printTypeParameterDetail,
            boolean printQualifyingType,
            boolean escapeLowercased,
            boolean printFullyQualified,
            boolean printQualifier) {
        this.printAbbreviated = printAbbreviated;
        this.printTypeParameters = printTypeParameters;
        this.printTypeParameterDetail = printTypeParameterDetail;
        this.printQualifyingType = printQualifyingType;
        this.escapeLowercased = escapeLowercased;
        this.printFullyQualified = printFullyQualified;
        this.printQualifier = printQualifier;
    }
    
    protected boolean printAbbreviated() {
        return printAbbreviated;
    }

    protected boolean printTypeParameters() {
        return printTypeParameters;
    }

    protected boolean printTypeParameterDetail() {
        return printTypeParameterDetail;
    }

    protected boolean printQualifyingType() {
        return printQualifyingType;
    }

    protected boolean printQualifier() {
        return printQualifier;
    }

    protected boolean printFullyQualified() {
        return printFullyQualified;
    }
    
    protected String lt() {
        return "<";
    }

    protected String gt() {
        return ">";
    }
    
    protected String amp() {
        return "&";
    }

    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();
                    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);
                    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);
{'fraction_non_alphanumeric': 0.09399186148567781, 'fraction_numerical': 0.00015957871219979256, 'mean_word_length': 1.631534747008188, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2013291', 'n_tokens_mistral': 3454, 'n_tokens_neox': 3199, 'n_words': 661}