use of org.eclipse.ceylon.model.typechecker.model.ClassOrInterface in project ceylon by eclipse.
the class ExpressionVisitor method visit.
@Override
public void visit(Tree.This that) {
ClassOrInterface ci = getContainingClassOrInterface(that.getScope());
if (inExtendsClause) {
if (ci != null) {
if (ci.isClassOrInterfaceMember()) {
ClassOrInterface cci = (ClassOrInterface) ci.getContainer();
that.setDeclarationModel(cci);
that.setTypeModel(cci.getType());
}
}
} else {
if (ci == null) {
that.addError("'this' occurs outside a class or interface definition");
} else {
that.setDeclarationModel(ci);
that.setTypeModel(ci.getType());
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.ClassOrInterface in project ceylon by eclipse.
the class GenerateJsVisitor method addToPrototype.
private void addToPrototype(ClassOrInterface d, final Tree.Statement s, List<Parameter> params, InitDeferrer initDeferrer) {
ClassOrInterface oldPrototypeOwner = prototypeOwner;
prototypeOwner = d;
if (s instanceof Tree.MethodDefinition) {
addMethodToPrototype(d, (Tree.MethodDefinition) s);
} else if (s instanceof Tree.MethodDeclaration) {
// Don't even bother with nodes that have errors
if (errVisitor.hasErrors(s))
return;
FunctionHelper.methodDeclaration(d, (Tree.MethodDeclaration) s, this, verboseStitcher);
} else if (s instanceof Tree.AttributeGetterDefinition) {
addGetterToPrototype(d, (Tree.AttributeGetterDefinition) s);
} else if (s instanceof Tree.AttributeDeclaration) {
AttributeGenerator.addGetterAndSetterToPrototype(d, (Tree.AttributeDeclaration) s, this, verboseStitcher);
} else if (s instanceof Tree.ClassDefinition) {
addClassToPrototype(d, (Tree.ClassDefinition) s, initDeferrer);
} else if (s instanceof Tree.InterfaceDefinition) {
addInterfaceToPrototype(d, (Tree.InterfaceDefinition) s, initDeferrer);
} else if (s instanceof Tree.ObjectDefinition) {
addObjectToPrototype(d, (Tree.ObjectDefinition) s, initDeferrer);
} else if (s instanceof Tree.ClassDeclaration) {
addClassDeclarationToPrototype(d, (Tree.ClassDeclaration) s);
} else if (s instanceof Tree.InterfaceDeclaration) {
addInterfaceDeclarationToPrototype(d, (Tree.InterfaceDeclaration) s);
} else if (s instanceof Tree.SpecifierStatement) {
addSpecifierToPrototype(d, (Tree.SpecifierStatement) s);
} else if (s instanceof Tree.TypeAliasDeclaration) {
addAliasDeclarationToPrototype(d, (Tree.TypeAliasDeclaration) s);
}
// This fixes #231 for prototype style
if (params != null && s instanceof Tree.Declaration) {
Declaration m = ((Tree.Declaration) s).getDeclarationModel();
for (Iterator<Parameter> iter = params.iterator(); iter.hasNext(); ) {
Parameter _p = iter.next();
if (m.getName() != null && m.getName().equals(_p.getName())) {
iter.remove();
break;
}
}
}
prototypeOwner = oldPrototypeOwner;
}
use of org.eclipse.ceylon.model.typechecker.model.ClassOrInterface in project ceylon by eclipse.
the class TypeGenerator method interfaceDefinition.
static void interfaceDefinition(final Tree.InterfaceDefinition that, final GenerateJsVisitor gen, InitDeferrer initDeferrer) {
// Don't even bother with nodes that have errors
if (errVisitor.hasErrors(that))
return;
final Interface d = that.getDeclarationModel();
// If it's inside a dynamic interface, don't generate anything
if (d.isClassOrInterfaceMember() && ((ClassOrInterface) d.getContainer()).isDynamic())
return;
final Interface natd = (Interface) ModelUtil.getNativeDeclaration(d, Backend.JavaScript);
final boolean headerWithoutBackend = NativeUtil.isHeaderWithoutBackend(that, Backend.JavaScript);
if (natd != null && (headerWithoutBackend || NativeUtil.isNativeHeader(that))) {
// It's a native header, remember it for later when we deal with its implementation
gen.saveNativeHeader(that);
return;
}
if (!(NativeUtil.isForBackend(that, Backend.JavaScript) || headerWithoutBackend)) {
return;
}
gen.comment(that);
gen.out(GenerateJsVisitor.function, gen.getNames().name(d));
final boolean withTargs = generateParameters(that.getTypeParameterList(), null, d, gen);
gen.beginBlock();
final List<Declaration> superDecs = new ArrayList<>(3);
if (!gen.opts.isOptimize()) {
new SuperVisitor(superDecs).visit(that.getInterfaceBody());
}
final Tree.SatisfiedTypes sats = that.getSatisfiedTypes();
if (withTargs) {
gen.out(gen.getClAlias(), "set_type_args(", gen.getNames().self(d), ",$$targs$$,", gen.getNames().name(d), ")");
gen.endLine(true);
}
callSupertypes(sats == null ? null : TypeUtils.getTypes(sats.getTypes()), null, d, that, superDecs, null, null, gen);
if (!d.isToplevel() && d.getContainer() instanceof Function && !((Function) d.getContainer()).getTypeParameters().isEmpty()) {
gen.out(gen.getClAlias(), "set_type_args(", gen.getNames().self(d), ",", gen.getNames().typeArgsParamName((Function) d.getContainer()), ",", gen.getNames().name(d), ")");
gen.endLine(true);
}
final List<Tree.Statement> stmts;
if (NativeUtil.isForBackend(d, Backend.JavaScript)) {
Tree.Declaration nh = gen.getNativeHeader(d);
if (nh == null && NativeUtil.hasNativeMembers(d)) {
nh = that;
}
stmts = NativeUtil.mergeStatements(that.getInterfaceBody(), nh, Backend.JavaScript);
} else {
stmts = that.getInterfaceBody().getStatements();
}
gen.visitStatements(stmts);
// returnSelf(d);
gen.endBlockNewLine();
if (d.isDynamic()) {
// Add the list of expected members here
final List<Declaration> members = d.getMembers();
gen.out(gen.getNames().name(d), ".dynmem$=[");
if (members.isEmpty()) {
gen.out("];");
} else {
gen.out("'");
boolean first = true;
for (Declaration m : members) {
if (first)
first = false;
else
gen.out("','");
gen.out(gen.getNames().name(m));
}
gen.out("'];");
}
}
// Add reference to metamodel
gen.out(gen.getNames().name(d), ".$crtmm$=");
TypeUtils.encodeForRuntime(that, d, that.getAnnotationList(), gen);
gen.endLine(true);
gen.share(d);
initializeType(that, gen, initDeferrer);
}
use of org.eclipse.ceylon.model.typechecker.model.ClassOrInterface in project ceylon by eclipse.
the class BmeGenerator method generateStaticReference.
static void generateStaticReference(Node n, Declaration d, GenerateJsVisitor gen) {
Declaration orig = d instanceof TypedDeclaration ? ((TypedDeclaration) d).getOriginalDeclaration() : d;
ClassOrInterface coi = (ClassOrInterface) (orig == null ? d : orig).getContainer();
gen.qualify(n, coi);
gen.out(gen.getNames().name(coi), ".$st$.", gen.getNames().name(d));
if (d instanceof Value && ((Value) d).getType().getDeclaration().isAnonymous()) {
gen.out("()");
}
}
use of org.eclipse.ceylon.model.typechecker.model.ClassOrInterface in project ceylon by eclipse.
the class TypeParameterCaptureVisitor method visit.
@Override
public void visit(Tree.ClassOrInterface that) {
ClassOrInterface model = that.getDeclarationModel();
if (model != null && !model.isAlias() && !model.isToplevel() && !model.isMember()) {
// it's a local type, capture!
captureTypeParameters(model);
}
super.visit(that);
}
Aggregations