KT-1829 NoClassDefFoundError when using java inner classes
#KT-1829 Fixed
This commit is contained in:
@@ -64,7 +64,7 @@ public class ClassFileFactory {
|
||||
FqName fqName = JetPsiUtil.getFQName(file);
|
||||
NamespaceCodegen codegen = ns2codegen.get(fqName);
|
||||
if (codegen == null) {
|
||||
final ClassBuilder builder = newVisitor(NamespaceCodegen.getJVMClassName(fqName, true) + ".class");
|
||||
final ClassBuilder builder = newVisitor(NamespaceCodegen.getJVMClassNameForKotlinNs(fqName) + ".class");
|
||||
codegen = new NamespaceCodegen(builder, fqName, state, file.getContainingFile());
|
||||
ns2codegen.put(fqName, codegen);
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ public abstract class CodegenContext {
|
||||
while(!(descriptor instanceof NamespaceDescriptor)) {
|
||||
descriptor = descriptor.getContainingDeclaration();
|
||||
}
|
||||
return NamespaceCodegen.getJVMClassName(DescriptorUtils.getFQName(descriptor).toSafe(), true);
|
||||
return NamespaceCodegen.getJVMClassNameForKotlinNs(DescriptorUtils.getFQName(descriptor).toSafe());
|
||||
}
|
||||
|
||||
public OwnerKind getContextKind() {
|
||||
|
||||
@@ -333,7 +333,7 @@ public class FunctionCodegen {
|
||||
|
||||
String ownerInternalName;
|
||||
if (contextClass instanceof NamespaceDescriptor) {
|
||||
ownerInternalName = NamespaceCodegen.getJVMClassName(DescriptorUtils.getFQName(contextClass).toSafe(), true);
|
||||
ownerInternalName = NamespaceCodegen.getJVMClassNameForKotlinNs(DescriptorUtils.getFQName(contextClass).toSafe());
|
||||
}
|
||||
else {
|
||||
ownerInternalName = state.getInjector().getJetTypeMapper().mapType(((ClassDescriptor) contextClass).getDefaultType(), MapTypeMode.IMPL).getInternalName();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -184,28 +185,64 @@ public class JetTypeMapper {
|
||||
}
|
||||
}
|
||||
|
||||
private String jvmClassNameForNamespace(NamespaceDescriptor namespace) {
|
||||
FqName fqName = DescriptorUtils.getFQName(namespace).toSafe();
|
||||
JavaNamespaceKind javaNamespaceKind = bindingContext.get(JavaBindingContext.JAVA_NAMESPACE_KIND, namespace);
|
||||
Boolean src = bindingContext.get(BindingContext.NAMESPACE_IS_SRC, namespace);
|
||||
@NotNull
|
||||
private JavaNamespaceKind getNsKind(@NotNull NamespaceDescriptor ns) {
|
||||
JavaNamespaceKind javaNamespaceKind = bindingContext.get(JavaBindingContext.JAVA_NAMESPACE_KIND, ns);
|
||||
Boolean src = bindingContext.get(BindingContext.NAMESPACE_IS_SRC, ns);
|
||||
|
||||
if (javaNamespaceKind == null && src == null) {
|
||||
throw new IllegalStateException("unknown namespace origin: " + fqName);
|
||||
throw new IllegalStateException("unknown namespace origin: " + ns);
|
||||
}
|
||||
|
||||
boolean classStatics;
|
||||
if (javaNamespaceKind != null) {
|
||||
if (javaNamespaceKind == JavaNamespaceKind.CLASS_STATICS && src != null) {
|
||||
throw new IllegalStateException(
|
||||
"conflicting namespace " + fqName + ": it is both java statics and from src");
|
||||
"conflicting namespace " + ns + ": it is both java statics and from src");
|
||||
}
|
||||
classStatics = javaNamespaceKind == JavaNamespaceKind.CLASS_STATICS;
|
||||
return javaNamespaceKind;
|
||||
}
|
||||
else {
|
||||
classStatics = false;
|
||||
return JavaNamespaceKind.PROPER;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String jvmClassNameForNamespace(@NotNull NamespaceDescriptor namespace) {
|
||||
|
||||
StringBuilder r = new StringBuilder();
|
||||
|
||||
List<DeclarationDescriptor> path = DescriptorUtils.getPathWithoutRootNsAndModule(namespace);
|
||||
|
||||
for (DeclarationDescriptor pathElement : path) {
|
||||
NamespaceDescriptor ns = (NamespaceDescriptor) pathElement;
|
||||
if (r.length() > 0) {
|
||||
JavaNamespaceKind nsKind = getNsKind((NamespaceDescriptor) ns.getContainingDeclaration());
|
||||
if (nsKind == JavaNamespaceKind.PROPER) {
|
||||
r.append("/");
|
||||
}
|
||||
else if (nsKind == JavaNamespaceKind.CLASS_STATICS) {
|
||||
r.append("$");
|
||||
}
|
||||
}
|
||||
if (ns.getName().length() == 0) {
|
||||
throw new IllegalStateException(
|
||||
"name must not be empty at this point when generating for " + namespace);
|
||||
}
|
||||
r.append(ns.getName());
|
||||
}
|
||||
|
||||
return NamespaceCodegen.getJVMClassName(fqName, !classStatics);
|
||||
if (getNsKind(namespace) == JavaNamespaceKind.PROPER) {
|
||||
if (r.length() > 0) {
|
||||
r.append("/");
|
||||
}
|
||||
r.append("namespace");
|
||||
}
|
||||
|
||||
if (r.length() == 0) {
|
||||
throw new IllegalStateException("internal error: failed to generate classname for " + namespace);
|
||||
}
|
||||
|
||||
return r.toString();
|
||||
}
|
||||
|
||||
@NotNull public Type mapReturnType(@NotNull final JetType jetType) {
|
||||
|
||||
@@ -44,7 +44,7 @@ public class NamespaceCodegen {
|
||||
|
||||
v.defineClass(sourceFile, V1_6,
|
||||
ACC_PUBLIC/*|ACC_SUPER*/,
|
||||
getJVMClassName(fqName, true),
|
||||
getJVMClassNameForKotlinNs(fqName),
|
||||
null,
|
||||
//"jet/lang/Namespace",
|
||||
"java/lang/Object",
|
||||
@@ -137,10 +137,7 @@ public class NamespaceCodegen {
|
||||
v.done();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param namespace true for "namespace" suffix
|
||||
*/
|
||||
public static String getJVMClassName(@NotNull FqName fqName, boolean namespace) {
|
||||
public static String getJVMClassNameForKotlinNs(@NotNull FqName fqName) {
|
||||
if (fqName.isRoot()) {
|
||||
return JvmAbi.PACKAGE_CLASS;
|
||||
}
|
||||
@@ -149,9 +146,7 @@ public class NamespaceCodegen {
|
||||
if (name.startsWith(JavaDescriptorResolver.JAVA_ROOT)) {
|
||||
name = name.substring(JavaDescriptorResolver.JAVA_ROOT.length() + 1, name.length());
|
||||
}
|
||||
if (namespace) {
|
||||
name += "/" + JvmAbi.PACKAGE_CLASS;
|
||||
}
|
||||
name += "/" + JvmAbi.PACKAGE_CLASS;
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user