use of org.eclipse.ceylon.model.typechecker.model.Constructor in project ceylon by eclipse.
the class ExpressionVisitor method visit.
@Override
public void visit(Tree.Constructor that) {
Constructor c = that.getConstructor();
checkDelegatedConstructor(that.getDelegatedConstructor(), c, that);
TypeDeclaration occ = enterConstructorDelegation(c);
Declaration od = beginReturnDeclaration(c);
Tree.Type rt = beginReturnScope(fakeVoid(that));
super.visit(that);
endReturnScope(rt, null);
endReturnDeclaration(od);
endConstructorDelegation(occ);
}
use of org.eclipse.ceylon.model.typechecker.model.Constructor in project ceylon by eclipse.
the class DeprecationVisitor method visit.
@Override
public void visit(Tree.MemberOrTypeExpression that) {
super.visit(that);
Declaration d = that.getDeclaration();
if (d != null && d.isDeprecated()) {
that.addUsageWarning(Warning.deprecation, "declaration is deprecated: '" + d.getName() + "' is annotated 'deprecated' in " + module(d));
}
if (d instanceof Class && that.getDirectlyInvoked()) {
Class c = (Class) d;
Constructor dc = c.getDefaultConstructor();
if (dc != null && dc.isDeprecated()) {
that.addUsageWarning(Warning.deprecation, "declaration is deprecated: default constructor of '" + d.getName() + "' is annotated 'deprecated' in " + module(d));
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Constructor in project ceylon by eclipse.
the class ClassDeclarationImpl method init.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void init() {
super.init();
// anonymous classes don't have parameter lists
if (!declaration.isAnonymous()) {
org.eclipse.ceylon.model.typechecker.model.Class classDeclaration = (org.eclipse.ceylon.model.typechecker.model.Class) declaration;
if (classDeclaration.isAbstraction()) {
List<Declaration> overloads = classDeclaration.getOverloads();
if (overloads.size() == 1) {
classDeclaration = (org.eclipse.ceylon.model.typechecker.model.Class) overloads.get(0);
}
// else{
// throw Metamodel.newModelError("Class has more than one overloaded constructor: "+classDeclaration.getNameAsString());
// }
}
ParameterList parameterList = classDeclaration.getParameterList();
if (parameterList != null) {
this.parameters = FunctionalUtil.getParameters(classDeclaration);
} else {
this.parameters = null;
}
} else {
this.parameters = null;
}
if (((Class) declaration).hasConstructors() || ((Class) declaration).hasEnumerated()) {
this.constructors = new LinkedList<ceylon.language.meta.declaration.Declaration>();
for (Declaration d : declaration.getMembers()) {
if (d instanceof Constructor) {
this.constructors.add(Metamodel.<ceylon.language.meta.declaration.Declaration>getOrCreateMetamodel(d));
}
}
} else {
this.constructors = Collections.emptyList();
}
}
use of org.eclipse.ceylon.model.typechecker.model.Constructor 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.Constructor in project ceylon by eclipse.
the class GenerateJsVisitor method comment.
void comment(Tree.Declaration that) {
if (!opts.isComment() || opts.isMinify())
return;
endLine();
String dname = that.getNodeType();
if (dname.endsWith("Declaration") || dname.endsWith("Definition")) {
dname = dname.substring(0, dname.length() - 7);
}
if (that instanceof Tree.Constructor) {
Function dec = ((Tree.Constructor) that).getDeclarationModel();
String cname = ((Class) dec.getContainer()).getName();
out("//Constructor ", cname, ".", dec.getName() == null ? "<default>" : dec.getName());
} else {
out("//", dname, " ", that.getDeclarationModel().getName());
}
location(that);
endLine();
}
Aggregations