allow namespace-qualified references; generate nested namespaces

This commit is contained in:
Dmitry Jemerov
2011-06-16 19:04:35 +02:00
parent a05b65f1a6
commit 90c5a66362
4 changed files with 18 additions and 4 deletions
@@ -615,7 +615,7 @@ public class ExpressionCodegen extends JetVisitor {
myStack.push(iValue);
}
}
else {
else if (!(descriptor instanceof NamespaceDescriptor)) {
throw new UnsupportedOperationException("don't know how to generate reference " + descriptor);
}
}
@@ -38,9 +38,8 @@ public class NamespaceCodegen {
}
public void generate(JetNamespace namespace) {
BindingContext bindingContext1 = AnalyzingUtils.analyzeNamespace(namespace, JetControlFlowDataTraceFactory.EMPTY);
AnalyzingUtils.applyHandler(ErrorHandler.THROW_EXCEPTION, bindingContext1);
BindingContext bindingContext = bindingContext1;
BindingContext bindingContext = AnalyzingUtils.analyzeNamespace(namespace, JetControlFlowDataTraceFactory.EMPTY);
AnalyzingUtils.applyHandler(ErrorHandler.THROW_EXCEPTION, bindingContext);
final JetStandardLibrary standardLibrary = JetStandardLibrary.getJetStandardLibrary(project);
final FunctionCodegen functionCodegen = new FunctionCodegen(namespace, v, standardLibrary, bindingContext);
@@ -65,6 +64,10 @@ public class NamespaceCodegen {
else if (declaration instanceof JetClassOrObject) {
classCodegen.generate((JetClassOrObject) declaration);
}
else if (declaration instanceof JetNamespace) {
JetNamespace childNamespace = (JetNamespace) declaration;
codegens.forNamespace(childNamespace).generate(childNamespace);
}
}
}
@@ -0,0 +1,7 @@
namespace Foo {
fun bar() = 610
}
fun box(): String {
return if (Foo.bar() == 610) "OK" else "fail"
}
@@ -400,4 +400,8 @@ public class NamespaceGenTest extends CodegenTestCase {
final StringBuilder sb = new StringBuilder("x");
assertEquals('x', ((Character) main.invoke(null, sb)).charValue());
}
public void testNamespaceQualifiedMethod() throws Exception {
blackBoxFile("namespaceQualifiedMethod.jet");
}
}