use of org.eclipse.ceylon.compiler.typechecker.tree.Tree.TypeVariance in project ceylon by eclipse.
the class AnalyzerUtil method getVariances.
static List<SiteVariance> getVariances(Tree.TypeArguments tas, List<TypeParameter> typeParameters) {
if (tas instanceof Tree.TypeArgumentList) {
Tree.TypeArgumentList tal = (Tree.TypeArgumentList) tas;
int size = typeParameters.size();
List<SiteVariance> variances = new ArrayList<SiteVariance>(size);
List<Tree.Type> types = tal.getTypes();
int count = types.size();
for (int i = 0; i < count; i++) {
Tree.Type type = types.get(i);
if (type instanceof Tree.StaticType) {
Tree.StaticType st = (Tree.StaticType) type;
TypeVariance tv = st.getTypeVariance();
if (tv != null) {
boolean contra = tv.getText().equals("in");
variances.add(contra ? IN : OUT);
} else {
variances.add(null);
}
} else {
variances.add(null);
}
}
return variances;
} else {
return emptyList();
}
}
use of org.eclipse.ceylon.compiler.typechecker.tree.Tree.TypeVariance in project ceylon by eclipse.
the class AnalyzerUtil method getTypeArguments.
/**
* Get the type arguments specified explicitly in the
* code, or an empty list if no type arguments were
* explicitly specified. For missing arguments, use
* default type arguments.
*
* @param tas the type argument list
* @param qualifyingType the qualifying type
* @param typeParameters the list of type parameters
*
* @return a list of type arguments to the given type
* parameters
*/
static List<Type> getTypeArguments(Tree.TypeArguments tas, Type qualifyingType, List<TypeParameter> typeParameters) {
if (tas instanceof Tree.TypeArgumentList) {
// accumulate substitutions in case we need
// them below for calculating default args
Map<TypeParameter, Type> typeArgs = new HashMap<TypeParameter, Type>();
Map<TypeParameter, SiteVariance> vars = new HashMap<TypeParameter, SiteVariance>();
if (qualifyingType != null) {
typeArgs.putAll(qualifyingType.getTypeArguments());
vars.putAll(qualifyingType.getVarianceOverrides());
}
Tree.TypeArgumentList tal = (Tree.TypeArgumentList) tas;
int size = typeParameters.size();
List<Type> typeArguments = new ArrayList<Type>(size);
List<Tree.Type> types = tal.getTypes();
int count = types.size();
for (int i = 0; i < count; i++) {
Tree.Type type = types.get(i);
Type t = type.getTypeModel();
if (t == null) {
typeArguments.add(null);
} else {
typeArguments.add(t);
if (i < size) {
TypeParameter tp = typeParameters.get(i);
if (tp.isTypeConstructor()) {
setTypeConstructor(type, tp);
}
typeArgs.put(tp, t);
if (type instanceof Tree.StaticType) {
Tree.StaticType st = (Tree.StaticType) type;
TypeVariance tv = st.getTypeVariance();
if (tv != null) {
boolean contra = tv.getText().equals("in");
vars.put(tp, contra ? IN : OUT);
}
}
}
}
}
// for missing arguments, use the default args
for (int i = typeArguments.size(); i < size; i++) {
TypeParameter tp = typeParameters.get(i);
Type dta = tp.getDefaultTypeArgument();
if (dta == null) {
break;
} else {
Type da = dta.substitute(typeArgs, vars);
typeArguments.add(da);
typeArgs.put(tp, da);
}
}
return typeArguments;
} else if (tas instanceof Tree.InferredTypeArguments && tas.getTypeModels() != null) {
return tas.getTypeModels();
} else {
return emptyList();
}
}
Aggregations