KT-2566 fix - accessors naming

This commit is contained in:
Alex Tkachman
2012-08-02 19:07:55 +03:00
parent 6062e0e03d
commit d6e614a2d4
4 changed files with 54 additions and 35 deletions
@@ -27,10 +27,7 @@ import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.asm4.Type; import org.jetbrains.asm4.Type;
import org.jetbrains.asm4.commons.InstructionAdapter; import org.jetbrains.asm4.commons.InstructionAdapter;
import java.util.Collection; import java.util.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
/* /*
* @author max * @author max
@@ -45,7 +42,7 @@ public abstract class CodegenContext {
@Nullable @Nullable
private final CodegenContext parentContext; private final CodegenContext parentContext;
public final ObjectOrClosureCodegen closure; public final ObjectOrClosureCodegen closure;
HashMap<JetType,Integer> typeInfoConstants; HashMap<JetType,Integer> typeInfoConstants;
HashMap<Integer,JetType> reverseTypeInfoConstants; HashMap<Integer,JetType> reverseTypeInfoConstants;
int typeInfoConstantsCount; int typeInfoConstantsCount;
@@ -94,14 +91,6 @@ public abstract class CodegenContext {
return contextDescriptor; return contextDescriptor;
} }
public String getNamespaceClassName() {
DeclarationDescriptor descriptor = contextDescriptor;
while(!(descriptor instanceof NamespaceDescriptor)) {
descriptor = descriptor.getContainingDeclaration();
}
return NamespaceCodegen.getJVMClassNameForKotlinNs(DescriptorUtils.getFQName(descriptor).toSafe()).getInternalName();
}
public OwnerKind getContextKind() { public OwnerKind getContextKind() {
return contextKind; return contextKind;
} }
@@ -184,24 +173,7 @@ public abstract class CodegenContext {
return cur == null ? null : typeMapper.mapType(((ClassDescriptor) cur.getContextDescriptor()).getDefaultType(), MapTypeMode.IMPL); return cur == null ? null : typeMapper.mapType(((ClassDescriptor) cur.getContextDescriptor()).getDefaultType(), MapTypeMode.IMPL);
} }
public int getTypeInfoConstantIndex(JetType type) {
if (parentContext != CodegenContexts.STATIC) { return parentContext.getTypeInfoConstantIndex(type); }
if (typeInfoConstants == null) {
typeInfoConstants = new LinkedHashMap<JetType, Integer>();
reverseTypeInfoConstants = new LinkedHashMap<Integer, JetType>();
}
Integer index = typeInfoConstants.get(type);
if (index == null) {
index = typeInfoConstantsCount++;
typeInfoConstants.put(type, index);
reverseTypeInfoConstants.put(index, type);
}
return index;
}
DeclarationDescriptor getAccessor(DeclarationDescriptor descriptor) { DeclarationDescriptor getAccessor(DeclarationDescriptor descriptor) {
if (accessors == null) { if (accessors == null) {
accessors = new HashMap<DeclarationDescriptor,DeclarationDescriptor>(); accessors = new HashMap<DeclarationDescriptor,DeclarationDescriptor>();
@@ -234,7 +206,7 @@ public abstract class CodegenContext {
pd.getVisibility(), pd.getVisibility(),
pd.isVar(), pd.isVar(),
pd.isObjectDeclaration(), pd.isObjectDeclaration(),
Name.identifier(pd.getName() + "$bridge$" + accessors.size()), Name.identifier(pd.getName() + "$b$" + getHierarchyCount() + "$" + accessors.size()),
CallableMemberDescriptor.Kind.DECLARATION CallableMemberDescriptor.Kind.DECLARATION
); );
JetType receiverType = pd.getReceiverParameter().exists() ? pd.getReceiverParameter().getType() : null; JetType receiverType = pd.getReceiverParameter().exists() ? pd.getReceiverParameter().getType() : null;
@@ -245,7 +217,7 @@ public abstract class CodegenContext {
myAccessor.getVisibility(), myAccessor.getVisibility(),
false, false, CallableMemberDescriptor.Kind.DECLARATION); false, false, CallableMemberDescriptor.Kind.DECLARATION);
pgd.initialize(myAccessor.getType()); pgd.initialize(myAccessor.getType());
PropertySetterDescriptor psd = new PropertySetterDescriptor( PropertySetterDescriptor psd = new PropertySetterDescriptor(
myAccessor, Collections.<AnnotationDescriptor>emptyList(), myAccessor.getModality(), myAccessor, Collections.<AnnotationDescriptor>emptyList(), myAccessor.getModality(),
myAccessor.getVisibility(), myAccessor.getVisibility(),
@@ -261,14 +233,19 @@ public abstract class CodegenContext {
} }
private int getHierarchyCount() { private int getHierarchyCount() {
ClassifierDescriptor descriptor = getThisDescriptor(); ClassDescriptor descriptor = getThisDescriptor();
int c = 0; int c = 0;
while(true) { while(true) {
Collection<? extends JetType> supertypes = descriptor.getDefaultType().getConstructor().getSupertypes(); Collection<? extends JetType> supertypes = descriptor.getDefaultType().getConstructor().getSupertypes();
if(supertypes.isEmpty()) if (supertypes.isEmpty())
return c; return c;
c++; c++;
descriptor = supertypes.iterator().next().getConstructor().getDeclarationDescriptor(); for (JetType supertype : supertypes) {
descriptor = (ClassDescriptor) supertype.getConstructor().getDeclarationDescriptor();
if (descriptor.getKind() == ClassKind.CLASS) {
break;
}
}
} }
} }
@@ -0,0 +1,15 @@
open class A {
open fun foo() = "OK"
}
open class B : A() {
override fun foo() = super.foo()
}
trait I
class C : I, B() {
override fun foo() = super<B>.foo()
}
fun box() = C().foo()
@@ -0,0 +1,17 @@
open class A {
open val foo: String = "OK"
}
open class B : A() {
class E {
val foo: String = super<A>@B.foo
}
}
class C : B() {
class D {
val foo: String = super<B>@C.foo
}
}
fun box() = C().foo
@@ -471,4 +471,14 @@ public class ClassGenTest extends CodegenTestCase {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxMultiFile("regressions/kt2395.kt"); blackBoxMultiFile("regressions/kt2395.kt");
} }
public void testKt2566() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxMultiFile("regressions/kt2566.kt");
}
public void testKt2566_2() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxMultiFile("regressions/kt2566_2.kt");
}
} }