Skip to content

Commit

Permalink
Add reference to module metamodel definition to declarations #196
Browse files Browse the repository at this point in the history
  • Loading branch information
chochos committed May 28, 2013
1 parent 31b9068 commit 86ec0c7
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions src/main/java/com/redhat/ceylon/compiler/js/TypeUtils.java
Expand Up @@ -371,12 +371,11 @@ void encodeTupleAsParameterListForRuntime(ProducedType _callable, GenerateJsVisi

/** Output a metamodel map for runtime use. */
static void encodeForRuntime(final Declaration d, final Tree.AnnotationList annotations, final GenerateJsVisitor gen) {
gen.out("{", MetamodelGenerator.KEY_NAME, ":'", d.getNameAsString(),
"',", MetamodelGenerator.KEY_METATYPE, ":'");
gen.out("{", MetamodelGenerator.KEY_METATYPE, ":'");
List<TypeParameter> tparms = null;
List<ProducedType> satisfies = null;
if (d instanceof com.redhat.ceylon.compiler.typechecker.model.Class) {
gen.out(MetamodelGenerator.METATYPE_CLASS, "'");
gen.out(d.isAnonymous() ? MetamodelGenerator.METATYPE_OBJECT : MetamodelGenerator.METATYPE_CLASS, "'");
tparms = ((com.redhat.ceylon.compiler.typechecker.model.Class) d).getTypeParameters();
if (((com.redhat.ceylon.compiler.typechecker.model.Class) d).getExtendedType() != null) {
gen.out(",'super':");
Expand Down Expand Up @@ -468,6 +467,39 @@ static void encodeForRuntime(final Declaration d, final Tree.AnnotationList anno
}
gen.out("];}");
}

gen.out(",mod:$$METAMODEL$$,pkg:'", d.getUnit().getPackage().getNameAsString(), "',d:$$METAMODEL$$['");
gen.out(d.getUnit().getPackage().getNameAsString(), "']");
if (d.isToplevel()) {
gen.out("['", d.getName(), "']");
} else {
ArrayList<String> path = new ArrayList<>();
Declaration p = d;
while (p instanceof Declaration) {
path.add(0, p.getName());
//Build the path in reverse
if (!p.isToplevel()) {
if (p instanceof com.redhat.ceylon.compiler.typechecker.model.Class) {
path.add(0, p.isAnonymous() ? "$o" : "$c");
} else if (p instanceof com.redhat.ceylon.compiler.typechecker.model.Interface) {
path.add(0, "$i");
} else if (p instanceof Method) {
path.add(0, "$m");
} else {
path.add(0, "$at");
}
}
Scope s = p.getContainer();
while (s != null && s instanceof Declaration == false) {
s = s.getContainer();
}
p = (Declaration)s;
}
//Output path
for (String part : path) {
gen.out("['", part, "']");
}
}
gen.out("}");
}

Expand Down

0 comments on commit 86ec0c7

Please sign in to comment.