use of org.eclipse.ceylon.model.typechecker.model.Interface in project ceylon by eclipse.
the class TypeParserTests method testNonEmptyIterableAbbrev.
@Test
public void testNonEmptyIterableAbbrev() {
Type type = new TypeParser(MockLoader.instance).decodeType("{a+}", null, mockDefaultModule, mockPkgUnit);
Assert.assertNotNull(type);
TypeDeclaration declaration = type.getDeclaration();
Assert.assertNotNull(declaration);
Assert.assertTrue(declaration instanceof Interface);
Assert.assertEquals("ceylon.language::Iterable", declaration.getQualifiedNameString());
Assert.assertEquals("{a+}", type.asString());
Assert.assertNull(type.getQualifyingType());
}
use of org.eclipse.ceylon.model.typechecker.model.Interface in project ceylon by eclipse.
the class GenerateJsVisitor method interfaceDeclaration.
private void interfaceDeclaration(final Tree.InterfaceDeclaration that) {
// Don't even bother with nodes that have errors
if (errVisitor.hasErrors(that))
return;
comment(that);
final Interface d = that.getDeclarationModel();
final String aname = names.name(d);
Tree.StaticType ext = that.getTypeSpecifier().getType();
out(function, aname, "(");
if (d.getTypeParameters() != null && !d.getTypeParameters().isEmpty()) {
out("$$targs$$,");
}
out(names.self(d), "){");
final Type pt = ext.getTypeModel();
final TypeDeclaration aliased = pt.getDeclaration();
qualify(that, aliased);
out(names.name(aliased), "(");
if (!pt.getTypeArguments().isEmpty()) {
TypeUtils.printTypeArguments(that, pt.getTypeArguments(), this, true, pt.getVarianceOverrides());
out(",");
}
out(names.self(d), ");}");
endLine();
out(aname, ".$crtmm$=");
TypeUtils.encodeForRuntime(that, d, this);
endLine(true);
share(d);
}
use of org.eclipse.ceylon.model.typechecker.model.Interface 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.Interface in project ceylon by eclipse.
the class AbstractModelLoader method setInterfaceCompanionClass.
protected void setInterfaceCompanionClass(Declaration d, ClassOrInterface container, LazyPackage pkg) {
// find its companion class in its real container
ClassMirror containerMirror = null;
if (container instanceof LazyClass) {
containerMirror = ((LazyClass) container).classMirror;
} else if (container instanceof LazyInterface) {
// container must be a LazyInterface, as TypeAlias doesn't contain anything
containerMirror = ((LazyInterface) container).companionClass;
if (containerMirror == null) {
throw new ModelResolutionException("Interface companion class for " + container.getQualifiedNameString() + " not set up");
}
}
String companionName;
if (containerMirror != null)
companionName = containerMirror.getFlatName() + "$" + NamingBase.suffixName(NamingBase.Suffix.$impl, d.getName());
else {
// toplevel
String p = pkg.getNameAsString();
companionName = "";
if (!p.isEmpty())
companionName = p + ".";
companionName += NamingBase.suffixName(NamingBase.Suffix.$impl, d.getName());
}
ClassMirror companionClass = lookupClassMirror(pkg.getModule(), companionName);
if (companionClass == null) {
((Interface) d).setCompanionClassNeeded(false);
}
((LazyInterface) d).companionClass = companionClass;
}
use of org.eclipse.ceylon.model.typechecker.model.Interface in project ceylon by eclipse.
the class ExpressionVisitor method visitScaleOperator.
/*@Override public void visit(Tree.SumOp that) {
super.visit( (Tree.BinaryOperatorExpression) that );
Type lhst = leftType(that);
if (lhst!=null) {
//take into account overloading of + operator
if (lhst.isSubtypeOf(getStringDeclaration().getType())) {
visitBinaryOperator(that, getStringDeclaration());
}
else {
visitBinaryOperator(that, getNumericDeclaration());
}
}
}*/
private void visitScaleOperator(Tree.ScaleOp that) {
Type lhst = leftType(that);
Type rhst = rightType(that);
if (!isTypeUnknown(rhst) && !isTypeUnknown(lhst)) {
Interface sd = unit.getScalableDeclaration();
Type st = checkSupertype(rhst, sd, that, "right operand must be of scalable type");
if (st != null) {
Type ta = st.getTypeArgumentList().get(0);
Type rt = st.getTypeArgumentList().get(1);
// hardcoded implicit type conversion Integer->Float
TypeDeclaration fd = unit.getFloatDeclaration();
TypeDeclaration id = unit.getIntegerDeclaration();
if (lhst.getDeclaration().inherits(id) && ta.getDeclaration().inherits(fd)) {
lhst = fd.getType();
}
checkAssignable(lhst, ta, that, "scale factor must be assignable to scale type");
that.setTypeModel(rt);
}
}
}
Aggregations