use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.
the class ModuleManager method initCoreModules.
public void initCoreModules(Modules initialModules) {
modules = initialModules;
if (modules.getLanguageModule() == null) {
// build empty package
Package emptyPackage = createPackage("", null);
// build default module
// (module in which packages belong to when not explicitly under a module)
List<String> defaultModuleName = singletonList(DEFAULT_MODULE_NAME);
Module defaultModule = createModule(defaultModuleName, "unversioned");
// defaultModule.setDefault(true);
defaultModule.setAvailable(true);
bindPackageToModule(emptyPackage, defaultModule);
modules.getListOfModules().add(defaultModule);
modules.setDefaultModule(defaultModule);
// create language module and add it as a dependency of defaultModule
// since packages outside a module cannot declare dependencies
List<String> languageName = asList("ceylon", "language");
Module languageModule = createModule(languageName, CEYLON_VERSION_NUMBER);
languageModule.setLanguageModule(languageModule);
// not available yet
languageModule.setAvailable(false);
modules.setLanguageModule(languageModule);
modules.getListOfModules().add(languageModule);
defaultModule.addImport(new ModuleImport(null, languageModule, false, false));
defaultModule.setLanguageModule(languageModule);
}
}
use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.
the class TypePrinter method printDeclaration.
private void printDeclaration(StringBuilder ptn, Declaration declaration, boolean fullyQualified, Unit unit) {
// type parameters are not fully qualified
if (fullyQualified && !(declaration instanceof TypeParameter)) {
Scope container = declaration.getContainer();
while (container != null && !(container instanceof Package) && !(container instanceof Declaration)) {
container = container.getContainer();
}
if (container != null) {
if (container instanceof Package) {
String qname = container.getQualifiedNameString();
if (!qname.isEmpty()) {
ptn.append(qname).append("::");
}
} else {
printDeclaration(ptn, (Declaration) container, fullyQualified, unit);
ptn.append(".");
}
}
}
if (printQualifier()) {
String qualifier = declaration.getQualifier();
if (qualifier != null) {
ptn.append(qualifier);
}
}
ptn.append(getSimpleDeclarationName(declaration, unit));
}
use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.
the class GenerateJsVisitor method visit.
@Override
public void visit(final Tree.QualifiedMemberExpression that) {
if (errVisitor.hasErrors(that))
return;
// Big TODO: make sure the member is actually
// refined by the current class!
final Declaration d = that.getDeclaration();
if (that.getMemberOperator() instanceof Tree.SafeMemberOp) {
Operators.generateSafeOp(that, this);
} else if (that.getMemberOperator() instanceof Tree.SpreadOp) {
SequenceGenerator.generateSpread(that, this);
} else if (d instanceof Function && that.getSignature() == null) {
// TODO right now this causes that all method invocations are done this way
// we need to filter somehow to only use this pattern when the result is supposed to be a callable
// looks like checking for signature is a good way (not THE way though; named arg calls don't have signature)
FunctionHelper.generateCallable(that, null, this);
} else if (that.getStaticMethodReference() && d != null) {
if (d instanceof Value && ModelUtil.isConstructor(d)) {
Constructor cnst = (Constructor) ((Value) d).getTypeDeclaration();
if (cnst.getTypescriptEnum() != null && cnst.getTypescriptEnum().matches("[0-9.-]+")) {
out(cnst.getTypescriptEnum());
} else {
// TODO this won't work anymore I think
boolean wrap = false;
if (that.getPrimary() instanceof Tree.QualifiedMemberOrTypeExpression) {
Tree.QualifiedMemberOrTypeExpression prim = (Tree.QualifiedMemberOrTypeExpression) that.getPrimary();
if (prim.getStaticMethodReference()) {
wrap = true;
out("function(_$){return _$");
} else {
prim.getPrimary().visit(this);
}
out(".");
} else {
if (d.getContainer() instanceof Declaration) {
qualify(that.getPrimary(), (Declaration) d.getContainer());
} else if (d.getContainer() instanceof Package) {
out(names.moduleAlias(((Package) d.getContainer()).getModule()));
}
}
if (cnst.getTypescriptEnum() != null) {
out(names.name((TypeDeclaration) d.getContainer()), ".", cnst.getTypescriptEnum());
} else {
out(names.name((TypeDeclaration) d.getContainer()), names.constructorSeparator(d), names.name(d), "()");
}
if (wrap) {
out(";}");
}
}
} else if (d instanceof Function) {
Function fd = (Function) d;
if (fd.getTypeDeclaration() instanceof Constructor) {
that.getPrimary().visit(this);
out(names.constructorSeparator(fd), names.name(fd.getTypeDeclaration()));
} else if (fd.isStatic()) {
BmeGenerator.generateStaticReference(that, fd, this);
} else {
out("function($O$){return ");
if (BmeGenerator.hasTypeParameters(that)) {
BmeGenerator.printGenericMethodReference(this, that, "$O$", "$O$." + names.name(d));
} else {
out(getClAlias(), "jsc$3($O$,$O$.", names.name(d), ")");
}
out(";}");
}
} else {
if (d.isStatic()) {
BmeGenerator.generateStaticReference(that, d, this);
} else {
out("function($O$){return $O$.", names.name(d), ";}");
}
}
} else {
final boolean isDynamic = that.getPrimary() instanceof Tree.Dynamic;
String lhs = generateToString(new GenerateCallback() {
@Override
public void generateValue() {
if (isDynamic) {
out("(");
}
GenerateJsVisitor.super.visit(that);
if (isDynamic) {
out(")");
}
}
});
if (d != null && d.isStatic()) {
BmeGenerator.generateStaticReference(that, d, this);
} else {
out(memberAccess(that, lhs));
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.
the class BmeGenerator method generateBme.
static void generateBme(final Tree.BaseMemberExpression bme, final GenerateJsVisitor gen, boolean nonNull) {
final boolean forInvoke = bme.getDirectlyInvoked();
Declaration decl = bme.getDeclaration();
if (decl != null) {
String name = decl.getName();
Package pkg = decl.getUnit().getPackage();
// map Ceylon true/false/null directly to JS true/false/null
if (pkg.isLanguagePackage()) {
if ("true".equals(name) || "false".equals(name) || "null".equals(name)) {
gen.out(name);
return;
}
}
if (ModelUtil.isConstructor(decl)) {
Constructor cd = TypeUtils.getConstructor(decl);
Declaration cdc = (Declaration) cd.getContainer();
if (!gen.qualify(bme, cd)) {
gen.out(gen.getNames().name(cdc), gen.getNames().constructorSeparator(decl));
}
if (decl instanceof Value) {
gen.out(gen.getNames().name(decl));
} else {
gen.out(gen.getNames().name(cd));
}
if (!forInvoke && decl instanceof Value) {
gen.out("()");
}
return;
}
}
String exp = gen.memberAccess(bme, null);
if (decl == null && gen.isInDynamicBlock()) {
if ("undefined".equals(exp)) {
gen.out(exp);
} else if (nonNull) {
gen.out("(typeof ", exp, "==='undefined'||", exp, "===null?");
gen.generateThrow(null, "Undefined or null reference: " + exp, bme);
gen.out(":", exp, ")");
} else {
gen.out(exp);
}
} else {
final boolean isCallable = !forInvoke && (decl instanceof Functional || bme.getUnit().getCallableDeclaration().equals(bme.getTypeModel().getDeclaration()));
final boolean hasTparms = hasTypeParameters(bme);
if (isCallable && (decl.isParameter() || (decl.isToplevel() && !hasTparms))) {
// Callables passed as arguments are already wrapped in JsCallable
gen.out(exp);
return;
}
String who = isCallable && decl.isMember() ? gen.getMember(bme, null) : null;
if (who == null || who.isEmpty()) {
// We may not need to wrap this in certain cases
ClassOrInterface cont = ModelUtil.getContainingClassOrInterface(bme.getScope());
who = cont == null ? "0" : gen.getNames().self(cont);
}
if (isCallable && (who != null || hasTparms)) {
if (hasTparms) {
// Function refs with type arguments must be passed as a special function
printGenericMethodReference(gen, bme, who, exp);
} else {
// Member methods must be passed as JsCallables
gen.out(gen.getClAlias(), "jsc$3(", who, ",", exp, ")");
}
} else {
gen.out(exp);
}
}
}
Aggregations