use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.
the class TypeVisitor method visit.
@Override
public void visit(Tree.TypeParameterDeclaration that) {
TypeParameter p = that.getDeclarationModel();
p.setExtendedType(null);
p.getSatisfiedTypes().clear();
Class vd = unit.getAnythingDeclaration();
if (vd != null) {
p.setExtendedType(vd.getType());
}
super.visit(that);
Tree.TypeSpecifier ts = that.getTypeSpecifier();
if (ts != null) {
Tree.StaticType type = ts.getType();
if (type != null) {
Type dta = type.getTypeModel();
Declaration dec = p.getDeclaration();
if (dta != null && dta.involvesDeclaration(dec)) {
type.addError("default type argument involves parameterized type: '" + dta.asString(unit) + "' involves '" + dec.getName(unit) + "'");
dta = null;
}
/*else if (dta.containsTypeParameters()) {
type.addError("default type argument involves type parameters: " +
dta.asString(unit));
dta = null;
}*/
p.setDefaultTypeArgument(dta);
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.
the class ExpressionVisitor method getOrInferTypeArgumentsForTypeConstructor.
/**
* Get the explicitly specified or inferred type
* arguments of a generic function reference that occurs
* within the primary of an invocation expression.
*
* @param that the invocation
* @param receiverType the qualifying type
* @param type the type constructor
* @param tas the type argument list
* @return the type arguments
*/
private List<Type> getOrInferTypeArgumentsForTypeConstructor(Tree.InvocationExpression that, Type receiverType, Type type, Tree.TypeArguments tas) {
TypeDeclaration td = type.getDeclaration();
List<TypeParameter> typeParameters = td.getTypeParameters();
boolean explicit = tas instanceof Tree.TypeArgumentList;
if (explicit) {
return getTypeArguments(tas, receiverType, typeParameters);
} else {
return new TypeArgumentInference(unit).getInferredTypeArgsForTypeConstructor(that, receiverType, type, typeParameters);
}
}
use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.
the class UsageVisitor method visit.
@Override
public void visit(Tree.Declaration that) {
super.visit(that);
Declaration declaration = that.getDeclarationModel();
Backends bs = declaration.getNativeBackends();
if (declaration != null && declaration.getName() != null && !declaration.isShared() && !declaration.isToplevel() && !rc.isReferenced(declaration) && !declaration.isParameter() && !(that instanceof Tree.Variable) && !(declaration instanceof TypeParameter && ((TypeParameter) declaration).getDeclaration() instanceof TypeParameter)) {
if (bs.none() || isForBackend(bs, that.getUnit().getSupportedBackends())) {
that.addUsageWarning(Warning.unusedDeclaration, "declaration is never used: " + kind(declaration) + " '" + declaration.getName() + "' has no local references");
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.
the class Metamodel method checkTypeArguments.
public static void checkTypeArguments(Type qualifyingType, Declaration declaration, List<Type> typeArguments) {
if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.Generic) {
List<org.eclipse.ceylon.model.typechecker.model.TypeParameter> typeParameters = ((org.eclipse.ceylon.model.typechecker.model.Generic) declaration).getTypeParameters();
if (typeParameters.size() < typeArguments.size())
throw new TypeApplicationException("Too many type arguments provided: " + typeArguments.size() + ", but only accepts " + typeParameters.size());
int min = 0;
for (TypeParameter tp : typeParameters) {
if (!tp.isDefaulted())
min++;
}
if (typeArguments.size() < min) {
String requires = (min == typeParameters.size()) ? "exactly" : "at least";
throw new TypeApplicationException("Not enough type arguments provided: " + typeArguments.size() + ", but requires " + requires + " " + min);
}
for (int i = 0; i < typeArguments.size(); i++) {
Type typeArgument = typeArguments.get(i);
org.eclipse.ceylon.model.typechecker.model.TypeParameter typeParameter = typeParameters.get(i);
for (Type st : typeParameter.getSatisfiedTypes()) {
Type sts = st.appliedType(qualifyingType, declaration, typeArguments, null);
if (!typeArgument.isSubtypeOf(sts)) {
throw new TypeApplicationException("Type argument " + i + ": " + typeArgument.asQualifiedString() + " does not conform to upper bound constraint: " + sts.asQualifiedString() + " of type parameter " + typeParameter.getQualifiedNameString());
}
}
if (!ModelUtil.argumentSatisfiesEnumeratedConstraint(qualifyingType, declaration, typeArguments, typeArgument, typeParameter)) {
throw new TypeApplicationException("Type argument " + i + ": " + typeArgument.asQualifiedString() + " does not conform to enumerated constraints " + " of type parameter " + typeParameter.getQualifiedNameString());
}
}
} else {
if (!typeArguments.isEmpty())
throw new TypeApplicationException("Declaration does not accept type arguments");
}
}
use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.
the class OpenTypeVariableImpl method init.
private void init() {
// we need to find where it came from to look up the proper wrapper
Scope container = wrapped.getContainer();
if (container instanceof org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) {
ceylon.language.meta.declaration.GenericDeclaration containerMetamodel = (ceylon.language.meta.declaration.GenericDeclaration) Metamodel.getOrCreateMetamodel((org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) container);
ceylon.language.meta.declaration.TypeParameter typeParameter = containerMetamodel.getTypeParameterDeclaration(wrapped.getName());
if (typeParameter != null)
this.declaration = typeParameter;
else
throw Metamodel.newModelError("Failed to find type parameter: " + wrapped.getName() + " in container " + container);
} else if (container instanceof org.eclipse.ceylon.model.typechecker.model.Function) {
// try to find it in the method
ceylon.language.meta.declaration.FunctionDeclaration method = Metamodel.getMetamodel((org.eclipse.ceylon.model.typechecker.model.Function) container);
ceylon.language.meta.declaration.TypeParameter typeParameter = method.getTypeParameterDeclaration(wrapped.getName());
if (typeParameter != null)
this.declaration = typeParameter;
else
throw Metamodel.newModelError("Failed to find type parameter: " + wrapped.getName() + " in container " + container);
} else
throw Metamodel.newModelError("Declaration container type not supported yet: " + container);
}
Aggregations