use of org.eclipse.ceylon.model.typechecker.model.Unit in project ceylon by eclipse.
the class TypePrinter method isTupleTypeWellformed.
private static boolean isTupleTypeWellformed(Type args) {
if (args == null || args.getTypeArgumentList().size() < 3) {
return false;
}
Unit unit = args.getDeclaration().getUnit();
List<Type> elemtypes = unit.getTupleElementTypes(args);
if (unit.isTupleLengthUnbounded(args)) {
int lastIndex = elemtypes.size() - 1;
elemtypes = new ArrayList<Type>(elemtypes);
Type last = elemtypes.get(lastIndex);
elemtypes.set(lastIndex, unit.getSequentialElementType(last));
}
if (elemtypes == null) {
return false;
}
int index = -1;
boolean optional = false;
while (true) {
index++;
if (args.isUnion()) {
// one of the two must be []
List<Type> cts = args.getCaseTypes();
if (cts.size() != 2) {
return false;
}
Type ct0 = cts.get(0);
Type ct1 = cts.get(1);
if (ct0.isEmpty()) {
args = ct1;
} else if (ct1.isEmpty()) {
args = ct0;
} else {
return false;
}
optional = true;
} else if (optional && !args.isSequential() && !args.isEmpty()) {
// the rest must be optional
return false;
}
if (args.isTuple()) {
List<Type> tal = args.getTypeArgumentList();
if (tal.size() < 3) {
return false;
}
Type t = union(elemtypes.subList(index, elemtypes.size()), unit);
Type typeArg = tal.get(0);
if (typeArg == null || !t.isExactly(typeArg)) {
return false;
}
// check Rest
args = tal.get(2);
if (args == null) {
return false;
}
} else if (args.isEmpty() || args.isSequential() || args.isSequence()) {
return true;
} else {
return false;
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Unit in project ceylon by eclipse.
the class TypePrinter method abbreviateOptional.
public static boolean abbreviateOptional(Type pt) {
if (pt.isUnion()) {
Unit unit = pt.getDeclaration().getUnit();
Class nd = unit.getNullDeclaration();
return pt.getCaseTypes().size() == 2 && isElementOfUnion(pt, nd);
/*&&
minus(unit.getNullDeclaration()).isPrimitiveAbbreviatedType();*/
} else {
return false;
}
}
Aggregations