use of org.eclipse.ceylon.model.typechecker.model.TypeAlias in project ceylon by eclipse.
the class MetamodelHelper method generateOpenType.
static void generateOpenType(final Tree.MetaLiteral that, final Declaration d, final GenerateJsVisitor gen, boolean compilingLanguageModule) {
final Module m = d.getUnit().getPackage().getModule();
final boolean isConstructor = ModelUtil.isConstructor(d) || that instanceof Tree.NewLiteral;
if (d instanceof TypeParameter == false) {
if (compilingLanguageModule) {
gen.out("$init$");
} else {
gen.out(gen.getClAlias());
}
}
if (d instanceof org.eclipse.ceylon.model.typechecker.model.Interface) {
gen.out("OpenInterface$jsint");
} else if (isConstructor) {
if (TypeUtils.getConstructor(d).isValueConstructor()) {
gen.out("OpenValueConstructor$jsint");
} else {
gen.out("OpenCallableConstructor$jsint");
}
} else if (d instanceof Class) {
gen.out("openClass$jsint");
} else if (d instanceof Function) {
gen.out("OpenFunction$jsint");
} else if (d instanceof Value) {
gen.out("OpenValue$jsint");
} else if (d instanceof org.eclipse.ceylon.model.typechecker.model.IntersectionType) {
gen.out("OpenIntersection");
} else if (d instanceof org.eclipse.ceylon.model.typechecker.model.UnionType) {
gen.out("OpenUnion");
} else if (d instanceof TypeParameter) {
generateOpenType(that, ((TypeParameter) d).getDeclaration(), gen, compilingLanguageModule);
gen.out(".getTypeParameterDeclaration('", d.getName(), "')");
return;
} else if (d instanceof org.eclipse.ceylon.model.typechecker.model.NothingType) {
gen.out("NothingType");
} else if (d instanceof TypeAlias) {
gen.out("OpenAlias$jsint(");
if (compilingLanguageModule) {
gen.out(")(");
}
if (d.isMember()) {
// Make the chain to the top-level container
ArrayList<Declaration> parents = new ArrayList<>(2);
Declaration pd = (Declaration) d.getContainer();
while (pd != null) {
parents.add(0, pd);
pd = pd.isMember() ? (Declaration) pd.getContainer() : null;
}
for (Declaration _d : parents) {
gen.out(gen.getNames().name(_d), ".$$.prototype.");
}
}
gen.out(gen.getNames().name(d), ")");
return;
}
// TODO optimize for local declarations
if (compilingLanguageModule) {
gen.out("()");
}
gen.out("(", gen.getClAlias());
final String pkgname = d.getUnit().getPackage().getNameAsString();
if (Objects.equals(that.getUnit().getPackage().getModule(), d.getUnit().getPackage().getModule())) {
gen.out("lmp$(ex$,'");
} else {
// TODO use $ for language module as well
gen.out("fmp$('", m.getNameAsString(), "','", m.getVersion(), "','");
}
gen.out("ceylon.language".equals(pkgname) ? "$" : pkgname, "'),");
if (d.isMember() || isConstructor) {
if (isConstructor) {
final Class actualClass;
final String constrName;
if (d instanceof Class) {
actualClass = (Class) d;
constrName = "$c$";
} else {
actualClass = (Class) d.getContainer();
if (d instanceof Constructor && ((Constructor) d).isValueConstructor()) {
constrName = gen.getNames().name(actualClass.getDirectMember(d.getName(), null, false));
} else {
constrName = gen.getNames().name(d);
}
}
if (gen.isImported(that.getUnit().getPackage(), actualClass)) {
gen.out(gen.getNames().moduleAlias(actualClass.getUnit().getPackage().getModule()), ".");
}
if (actualClass.isMember()) {
outputPathToDeclaration(that, actualClass, gen);
}
gen.out(gen.getNames().name(actualClass), gen.getNames().constructorSeparator(d), constrName, ")");
return;
} else {
outputPathToDeclaration(that, d, gen);
}
}
if (d instanceof Value || d.isParameter()) {
if (!d.isMember())
gen.qualify(that, d);
if (d.isStatic() && d instanceof Value && ((Value) d).getType().getDeclaration().isAnonymous()) {
gen.out(gen.getNames().name(d), ")");
} else {
gen.out(gen.getNames().getter(d, true), ")");
}
} else {
if (d.isAnonymous()) {
final String oname = gen.getNames().objectName(d);
if (d.isToplevel()) {
gen.qualify(that, d);
}
gen.out("$init$", oname);
if (!d.isToplevel()) {
gen.out("()");
}
} else {
if (!d.isMember())
gen.qualify(that, d);
gen.out(gen.getNames().name(d));
}
gen.out(")");
}
}
use of org.eclipse.ceylon.model.typechecker.model.TypeAlias in project ceylon by eclipse.
the class DeclarationVisitor method visit.
@Override
public void visit(Tree.TypeAliasDeclaration that) {
TypeAlias a = new TypeAlias();
that.setDeclarationModel(a);
visitDeclaration(that, a);
Scope o = enterScope(a);
super.visit(that);
exitScope(o);
}
use of org.eclipse.ceylon.model.typechecker.model.TypeAlias in project ceylon by eclipse.
the class DeclarationVisitor method visit.
public void visit(Tree.TypeConstructor that) {
TypeAlias ta = new TypeAlias();
ta.setShared(true);
ta.setName("Anonymous#" + fid++);
ta.setAnonymous(true);
visitElement(that, ta);
ModelUtil.setVisibleScope(ta);
Scope o = enterScope(ta);
Declaration od = beginDeclaration(ta);
super.visit(that);
endDeclaration(od);
exitScope(o);
ta.setExtendedType(that.getType().getTypeModel());
that.setDeclarationModel(ta);
Type pt = ta.getType();
pt.setTypeConstructor(true);
that.setTypeModel(pt);
}
use of org.eclipse.ceylon.model.typechecker.model.TypeAlias in project ceylon by eclipse.
the class TypeVisitor method visit.
@Override
public void visit(Tree.ExtendedType that) {
inExtendsOrClassAlias = that.getInvocationExpression() != null;
super.visit(that);
inExtendsOrClassAlias = false;
inheritedType(that.getType());
checkExtendedTypeExpression(that.getType());
TypeDeclaration td = (TypeDeclaration) that.getScope();
if (!td.isAlias()) {
Tree.SimpleType et = that.getType();
if (et != null) {
Type type = et.getTypeModel();
if (type != null) {
TypeDeclaration etd = et.getDeclarationModel();
if (etd != null && !(etd instanceof UnknownType)) {
if (etd instanceof Constructor) {
type = type.getExtendedType();
etd = etd.getExtendedType().getDeclaration();
}
if (etd == td) {
// unnecessary, handled by SupertypeVisitor
// et.addError("directly extends itself: '" +
// td.getName() + "'");
} else if (etd instanceof TypeParameter) {
et.addError("directly extends a type parameter: '" + type.getDeclaration().getName(unit) + "'");
} else if (etd instanceof Interface) {
et.addError("extends an interface: '" + type.getDeclaration().getName(unit) + "'");
} else if (etd instanceof TypeAlias) {
et.addError("extends a type alias: '" + type.getDeclaration().getName(unit) + "'");
} else if (etd instanceof NothingType) {
et.addError("extends the bottom type 'Nothing'");
} else {
td.setExtendedType(type);
}
}
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.TypeAlias in project ceylon by eclipse.
the class TypeVisitor method visit.
@Override
public void visit(Tree.TypeAliasDeclaration that) {
TypeAlias ta = that.getDeclarationModel();
ta.setExtendedType(null);
super.visit(that);
Tree.TypeSpecifier typeSpecifier = that.getTypeSpecifier();
if (typeSpecifier == null) {
that.addError("missing aliased type");
} else {
Tree.StaticType et = typeSpecifier.getType();
if (et == null) {
that.addError("malformed aliased type");
} else {
Type type = et.getTypeModel();
if (type != null) {
setTypeConstructor(et, null);
ta.setExtendedType(type);
}
}
}
}
Aggregations