use of org.eclipse.ceylon.model.typechecker.model.Type in project ceylon by eclipse.
the class AnalyzerUtil method spreadType.
static Type spreadType(Type et, Unit unit, boolean requireSequential) {
if (et == null)
return null;
if (requireSequential) {
if (unit.isSequentialType(et)) {
// if (et.isTypeParameter()) {
return et;
/*}
else {
// if it's already a subtype of Sequential, erase
// out extraneous information, like that it is a
// String, just keeping information about what
// kind of tuple it is
List<Type> elementTypes = unit.getTupleElementTypes(et);
boolean variadic = unit.isTupleLengthUnbounded(et);
boolean atLeastOne = unit.isTupleVariantAtLeastOne(et);
int minimumLength = unit.getTupleMinimumLength(et);
if (variadic) {
Type spt = elementTypes.get(elementTypes.size()-1);
elementTypes.set(elementTypes.size()-1, unit.getIteratedType(spt));
}
return unit.getTupleType(elementTypes, variadic,
atLeastOne, minimumLength);
}*/
} else {
// transform any Iterable into a Sequence without
// losing the information that it is nonempty, in
// the case that we know that for sure
Type it = unit.getElementType(et);
Type st = unit.isNonemptyIterableType(et) ? unit.getSequenceType(it) : unit.getSequentialType(it);
// for now, just return the sequential type:
return st;
}
} else {
return et;
}
}
use of org.eclipse.ceylon.model.typechecker.model.Type in project ceylon by eclipse.
the class AnalyzerUtil method checkCasesDisjoint.
static boolean checkCasesDisjoint(Type later, Type earlier, Node node, String hint) {
if (!isTypeUnknown(later) && !isTypeUnknown(earlier)) {
Unit unit = node.getUnit();
Type it = intersectionType(later.resolveAliases(), earlier.resolveAliases(), unit);
if (!it.isNothing()) {
if (earlier.isExactly(later)) {
node.addError("case is not disjoint: there is another case of type '" + earlier.asString(unit) + "'" + hint);
} else if (earlier.isSubtypeOf(later)) {
node.addError("case is not disjoint: '" + later.asString(unit) + "' contains '" + earlier.asString(unit) + "'" + hint);
} else {
node.addError("case is not disjoint: '" + later.asString(unit) + "' and '" + earlier.asString(unit) + "' have intersection '" + it.asString(unit) + "'" + hint);
}
return false;
}
}
return true;
}
use of org.eclipse.ceylon.model.typechecker.model.Type in project ceylon by eclipse.
the class AnalyzerUtil method unwrapAliasedTypeConstructor.
static TypeDeclaration unwrapAliasedTypeConstructor(TypeDeclaration dec) {
TypeDeclaration d = dec;
while (!d.isParameterized() && d.isAlias()) {
Type et = d.getExtendedType();
if (et == null)
break;
et = et.resolveAliases();
d = et.getDeclaration();
if (et.isTypeConstructor() && d.isParameterized()) {
return d;
}
}
return dec;
}
use of org.eclipse.ceylon.model.typechecker.model.Type in project ceylon by eclipse.
the class AnalyzerUtil method isAlwaysSatisfied.
public static boolean isAlwaysSatisfied(Tree.ConditionList cl) {
if (cl == null)
return false;
for (Tree.Condition c : cl.getConditions()) {
if (c instanceof Tree.BooleanCondition) {
Tree.BooleanCondition bc = (Tree.BooleanCondition) c;
Tree.Expression ex = bc.getExpression();
if (ex != null) {
Type type = ex.getTypeModel();
if (type != null && type.getDeclaration().isTrueValue()) {
continue;
}
}
}
return false;
}
return true;
}
use of org.eclipse.ceylon.model.typechecker.model.Type in project ceylon by eclipse.
the class AnnotationVisitor method checkAnnotationType.
private void checkAnnotationType(Tree.AnyClass that, Class c) {
if (c.isParameterized()) {
that.addError("annotation class may not be a parameterized type");
}
/*if (c.isAbstract()) {
that.addError("annotation class may not be abstract");
}*/
if (!c.isFinal()) {
that.addError("annotation class must be final");
}
Type et = c.getExtendedType();
if (et != null) {
if (!et.isBasic()) {
that.addError("annotation class must directly extend 'Basic'");
}
}
for (Tree.Parameter pn : that.getParameterList().getParameters()) {
checkAnnotationParameter(c, pn);
}
if (that instanceof Tree.ClassDefinition) {
Tree.ClassDefinition cd = (Tree.ClassDefinition) that;
Tree.ClassBody body = cd.getClassBody();
if (body != null && !getExecutableStatements(body).isEmpty()) {
that.addError("annotation class body may not contain executable statements");
}
}
}
Aggregations