use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.
the class TypeParserTests method testParamsVariance3.
@Test
public void testParamsVariance3() {
Type type = new TypeParser(MockLoader.instance).decodeType("t2<in b,c>", null, mockDefaultModule, mockPkgUnit);
assertTypeWithParameters(type);
Map<TypeParameter, SiteVariance> varianceOverrides = type.getVarianceOverrides();
Assert.assertNotNull(varianceOverrides);
Assert.assertEquals(1, varianceOverrides.size());
List<TypeParameter> tps = type.getDeclaration().getTypeParameters();
Assert.assertEquals(SiteVariance.IN, varianceOverrides.get(tps.get(0)));
Assert.assertEquals(null, varianceOverrides.get(tps.get(1)));
}
use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.
the class TypeParserTests method testParamsVariance1.
@Test
public void testParamsVariance1() {
Type type = new TypeParser(MockLoader.instance).decodeType("t2<in b,out c>", null, mockDefaultModule, mockPkgUnit);
assertTypeWithParameters(type);
Map<TypeParameter, SiteVariance> varianceOverrides = type.getVarianceOverrides();
Assert.assertNotNull(varianceOverrides);
Assert.assertEquals(2, varianceOverrides.size());
List<TypeParameter> tps = type.getDeclaration().getTypeParameters();
Assert.assertEquals(SiteVariance.IN, varianceOverrides.get(tps.get(0)));
Assert.assertEquals(SiteVariance.OUT, varianceOverrides.get(tps.get(1)));
}
use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.
the class TypeParserTests method testParamsVariance2.
@Test
public void testParamsVariance2() {
Type type = new TypeParser(MockLoader.instance).decodeType("t2<b,out c>", null, mockDefaultModule, mockPkgUnit);
assertTypeWithParameters(type);
Map<TypeParameter, SiteVariance> varianceOverrides = type.getVarianceOverrides();
Assert.assertNotNull(varianceOverrides);
Assert.assertEquals(1, varianceOverrides.size());
List<TypeParameter> tps = type.getDeclaration().getTypeParameters();
Assert.assertEquals(null, varianceOverrides.get(tps.get(0)));
Assert.assertEquals(SiteVariance.OUT, varianceOverrides.get(tps.get(1)));
}
use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.
the class GenerateJsVisitor method classDeclaration.
private void classDeclaration(final Tree.ClassDeclaration that) {
// Don't even bother with nodes that have errors
if (errVisitor.hasErrors(that))
return;
comment(that);
final Class d = that.getDeclarationModel();
final String aname = names.name(d);
final Tree.ClassSpecifier ext = that.getClassSpecifier();
out(function, aname, "(");
// Generate each parameter because we need to append one at the end
for (Tree.Parameter p : that.getParameterList().getParameters()) {
p.visit(this);
out(", ");
}
if (d.getTypeParameters() != null && !d.getTypeParameters().isEmpty()) {
out("$$targs$$,");
}
out(names.self(d), "){");
initSelf(that);
initParameters(that.getParameterList(), d, null);
out("return ");
TypeDeclaration aliased = ext.getType().getDeclarationModel();
final String aliasedName;
aliasedName = names.name(aliased);
qualify(that, aliased);
Scope superscope = getSuperMemberScope(ext.getType());
if (superscope != null) {
out("getT$all()['");
out(superscope.getQualifiedNameString());
out("'].$$.prototype.", aliasedName, ".call(", names.self(prototypeOwner), ",");
} else {
out(aliasedName, "(");
}
Tree.PositionalArgumentList posArgs = ext.getInvocationExpression().getPositionalArgumentList();
if (posArgs != null) {
posArgs.visit(this);
if (!posArgs.getPositionalArguments().isEmpty()) {
out(",");
}
} else {
out("/*PENDIENTE NAMED ARG CLASS DECL */");
}
Map<TypeParameter, Type> invargs = ext.getType().getTypeModel().getTypeArguments();
if (invargs != null && !invargs.isEmpty()) {
TypeUtils.printTypeArguments(that, invargs, this, true, ext.getType().getTypeModel().getVarianceOverrides());
out(",");
}
out(names.self(d), ");}");
endLine();
out(aname, ".$$=");
qualify(that, aliased);
out(aliasedName, ".$$");
endLine(true);
out(aname, ".$crtmm$=");
TypeUtils.encodeForRuntime(that, d, this);
endLine(true);
share(d);
if (aliased instanceof Class && ((Class) aliased).hasConstructors() || aliased instanceof Constructor) {
Class ac = aliased instanceof Constructor ? (Class) ((Constructor) aliased).getContainer() : (Class) aliased;
for (Declaration cm : ac.getMembers()) {
if (cm instanceof Constructor && cm != ac.getDefaultConstructor() && cm.isShared()) {
Constructor cons = (Constructor) cm;
final String constructorName = aname + names.constructorSeparator(cons) + names.name(cons);
out("function ", constructorName, "(");
List<Parameter> parameters = cons.getFirstParameterList().getParameters();
ArrayList<String> pnames = new ArrayList<>(parameters.size() + 1);
boolean first = true;
for (int i = 0; i < parameters.size(); i++) {
final String pname = names.createTempVariable();
pnames.add(pname);
if (first) {
first = false;
} else {
out(",");
}
out(pname);
}
out("){return ");
qualify(that, cons);
out(names.name(cons), "(");
first = true;
for (String pname : pnames) {
if (first) {
first = false;
} else {
out(",");
}
out(pname);
}
out(");}");
if (ac.isShared()) {
sharePrefix(ac, true);
out(constructorName, "=", constructorName, ";");
endLine();
}
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.
the class InvocationGenerator method getTypeArguments.
private Map<TypeParameter, Type> getTypeArguments(Tree.Primary p) {
if (p instanceof Tree.StaticMemberOrTypeExpression) {
Tree.StaticMemberOrTypeExpression smote = (Tree.StaticMemberOrTypeExpression) p;
final Declaration d = smote.getDeclaration();
final boolean hasTargs = d != null && d.getContainer() instanceof Generic && ((Generic) d.getContainer()).isParameterized();
final boolean hasParentTargs = TypeUtils.isStaticWithGenericContainer(d);
if (hasTargs && ModelUtil.isConstructor(d)) {
return smote.getTarget().getTypeArguments();
} else if (hasParentTargs) {
if (smote.getTypeArguments() != null && !smote.getTypeArguments().getTypeModels().isEmpty()) {
// If the type is static AND has type arguments of its own, we need to merge them
Map<TypeParameter, Type> targs = new HashMap<>();
targs.putAll(smote.getTarget().getTypeArguments());
targs.putAll(smote.getTarget().getQualifyingType().getTypeArguments());
return targs;
}
return smote.getTarget().getQualifyingType().getTypeArguments();
} else if (d instanceof Functional) {
Map<TypeParameter, Type> targs = TypeUtils.matchTypeParametersWithArguments(d.getTypeParameters(), smote.getTypeArguments() == null ? null : smote.getTypeArguments().getTypeModels());
if (targs == null) {
gen.out("/*TARGS != TPARAMS!!!!*/");
}
return targs;
}
} else if (p instanceof Tree.ExtendedTypeExpression) {
Tree.ExtendedTypeExpression ete = (Tree.ExtendedTypeExpression) p;
return ete.getTarget().getTypeArguments();
}
return null;
}
Aggregations