KT-414 Hello world does not run if defined in an anonymous namesapce
+ getFQName moved out of a PSI class
This commit is contained in:
@@ -31,7 +31,7 @@ public class ClassFileFactory {
|
||||
|
||||
NamespaceCodegen forNamespace(JetNamespace namespace) {
|
||||
assert !isDone : "Already done!";
|
||||
String fqName = namespace.getFQName();
|
||||
String fqName = CodegenUtil.getFQName(namespace);
|
||||
NamespaceCodegen codegen = ns2codegen.get(fqName);
|
||||
if (codegen == null) {
|
||||
final ClassBuilder builder = newVisitor(NamespaceCodegen.getJVMClassName(fqName) + ".class");
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import java.util.List;
|
||||
@@ -98,4 +102,26 @@ public class CodegenUtil {
|
||||
|
||||
return hasTypeInfoField(outerClassDescriptor.getDefaultType());
|
||||
}
|
||||
|
||||
public static String getFQName(JetNamespace jetNamespace) {
|
||||
JetNamespace parent = PsiTreeUtil.getParentOfType(jetNamespace, JetNamespace.class);
|
||||
if (parent != null) {
|
||||
String parentFQName = getFQName(parent);
|
||||
if (parentFQName.length() > 0) {
|
||||
return parentFQName + "." + jetNamespace.getName();
|
||||
}
|
||||
}
|
||||
return jetNamespace.getName(); // TODO: Must include module root namespace
|
||||
}
|
||||
|
||||
public static String getFQName(JetClass jetClass) {
|
||||
JetNamedDeclaration parent = PsiTreeUtil.getParentOfType(jetClass, JetNamespace.class, JetClass.class);
|
||||
if (parent instanceof JetNamespace) {
|
||||
return getFQName(((JetNamespace) parent)) + "." + jetClass.getName();
|
||||
}
|
||||
if (parent instanceof JetClass) {
|
||||
return getFQName(((JetClass) parent)) + "." + jetClass.getName();
|
||||
}
|
||||
return jetClass.getName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import jet.JetObject;
|
||||
import jet.typeinfo.TypeInfo;
|
||||
import jet.typeinfo.TypeInfoProjection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
@@ -172,7 +171,7 @@ public class JetTypeMapper {
|
||||
}
|
||||
|
||||
public static String jvmName(JetNamespace namespace) {
|
||||
return NamespaceCodegen.getJVMClassName(namespace.getFQName());
|
||||
return NamespaceCodegen.getJVMClassName(CodegenUtil.getFQName(namespace));
|
||||
}
|
||||
|
||||
static String jvmName(NamespaceDescriptor namespace) {
|
||||
@@ -516,7 +515,7 @@ public class JetTypeMapper {
|
||||
|
||||
String baseName;
|
||||
if (container instanceof JetNamespace) {
|
||||
baseName = NamespaceCodegen.getJVMClassName(((JetNamespace) container).getFQName());
|
||||
baseName = NamespaceCodegen.getJVMClassName(CodegenUtil.getFQName(((JetNamespace) container)));
|
||||
}
|
||||
else {
|
||||
ClassDescriptor aClass = bindingContext.get(BindingContext.CLASS, container);
|
||||
|
||||
@@ -13,6 +13,7 @@ import jet.modules.IModuleSetBuilder;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||
import org.jetbrains.jet.codegen.CodegenUtil;
|
||||
import org.jetbrains.jet.codegen.GeneratedClassLoader;
|
||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||
import org.jetbrains.jet.plugin.JetMainDetector;
|
||||
@@ -322,7 +323,7 @@ public class CompileEnvironment {
|
||||
String mainClass = null;
|
||||
for (JetNamespace namespace : session.getSourceFileNamespaces()) {
|
||||
if (JetMainDetector.hasMain(namespace.getDeclarations())) {
|
||||
mainClass = namespace.getFQName() + ".namespace";
|
||||
mainClass = CodegenUtil.getFQName(namespace) + ".namespace";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,14 +53,4 @@ public class JetNamespace extends JetNamedDeclaration {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
public String getFQName() {
|
||||
JetNamespace parent = PsiTreeUtil.getParentOfType(this, JetNamespace.class);
|
||||
if (parent != null) {
|
||||
String parentFQName = parent.getFQName();
|
||||
if (parentFQName.length() > 0) {
|
||||
return parentFQName + "." + getName();
|
||||
}
|
||||
}
|
||||
return getName(); // TODO: Must include module root namespace
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public abstract class CodegenTestCase extends JetLiteFixture {
|
||||
GeneratedClassLoader loader = new GeneratedClassLoader(codegens);
|
||||
|
||||
final JetNamespace namespace = myFile.getRootNamespace();
|
||||
String fqName = NamespaceCodegen.getJVMClassName(namespace.getFQName()).replace("/", ".");
|
||||
String fqName = NamespaceCodegen.getJVMClassName(CodegenUtil.getFQName(namespace)).replace("/", ".");
|
||||
Class<?> namespaceClass = loader.loadClass(fqName);
|
||||
Method method = namespaceClass.getMethod("box");
|
||||
return (String) method.invoke(null);
|
||||
@@ -121,7 +121,7 @@ public abstract class CodegenTestCase extends JetLiteFixture {
|
||||
|
||||
protected Class loadRootNamespaceClass(ClassFileFactory state) {
|
||||
final JetNamespace namespace = myFile.getRootNamespace();
|
||||
String fqName = NamespaceCodegen.getJVMClassName(namespace.getFQName()).replace("/", ".");
|
||||
String fqName = NamespaceCodegen.getJVMClassName(CodegenUtil.getFQName(namespace)).replace("/", ".");
|
||||
Map<String, Class> classMap = loadAllClasses(state);
|
||||
return classMap.get(fqName);
|
||||
}
|
||||
|
||||
@@ -8,10 +8,9 @@ import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.jet.codegen.CodegenUtil;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||
import org.jetbrains.jet.plugin.JetMainDetector;
|
||||
|
||||
@@ -25,17 +24,6 @@ public class JetRunConfigurationProducer extends RuntimeConfigurationProducer im
|
||||
super(JetRunConfigurationType.getInstance());
|
||||
}
|
||||
|
||||
private static String getFQName(JetClass jetClass) {
|
||||
JetNamedDeclaration parent = PsiTreeUtil.getParentOfType(jetClass, JetNamespace.class, JetClass.class);
|
||||
if (parent instanceof JetNamespace) {
|
||||
return ((JetNamespace) parent).getFQName() + "." + jetClass.getName();
|
||||
}
|
||||
if (parent instanceof JetClass) {
|
||||
return getFQName(((JetClass) parent)) + "." + jetClass.getName();
|
||||
}
|
||||
return jetClass.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement getSourceElement() {
|
||||
return mySourceElement;
|
||||
@@ -46,14 +34,16 @@ public class JetRunConfigurationProducer extends RuntimeConfigurationProducer im
|
||||
JetClass containingClass = (JetClass) location.getParentElement(JetClass.class);
|
||||
if (containingClass != null && JetMainDetector.hasMain(containingClass.getDeclarations())) {
|
||||
mySourceElement = containingClass;
|
||||
return createConfigurationByQName(location.getModule(), configurationContext, getFQName(containingClass));
|
||||
return createConfigurationByQName(location.getModule(), configurationContext, CodegenUtil.getFQName(containingClass));
|
||||
}
|
||||
PsiFile psiFile = location.getPsiElement().getContainingFile();
|
||||
if (psiFile instanceof JetFile) {
|
||||
JetNamespace namespace = ((JetFile) psiFile).getRootNamespace();
|
||||
if (JetMainDetector.hasMain(namespace.getDeclarations())) {
|
||||
mySourceElement = namespace;
|
||||
return createConfigurationByQName(location.getModule(), configurationContext, namespace.getFQName() + ".namespace");
|
||||
String fqName = CodegenUtil.getFQName(namespace);
|
||||
String className = fqName.length() == 0 ? "namespace" : fqName + ".namespace";
|
||||
return createConfigurationByQName(location.getModule(), configurationContext, className);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user