From 097325d0d6da8db98825aa5a725ffde08ef8fc9e Mon Sep 17 00:00:00 2001 From: Alex Tkachman Date: Sun, 11 Sep 2011 12:42:50 +0300 Subject: [PATCH] removing unnneded InstructionAdapterEx --- .../jet/codegen/ClassBodyCodegen.java | 1 + .../jetbrains/jet/codegen/ClassCodegen.java | 18 +- .../jetbrains/jet/codegen/ClassContext.java | 2 +- .../jet/codegen/ExpressionCodegen.java | 41 ++- .../jet/codegen/FunctionCodegen.java | 8 +- .../codegen/ImplementationBodyCodegen.java | 247 ++++++++++++------ .../jet/codegen/InterfaceBodyCodegen.java | 137 ---------- .../jetbrains/jet/codegen/JetTypeMapper.java | 18 +- .../jet/codegen/NamespaceCodegen.java | 2 +- .../jet/codegen/PropertyCodegen.java | 17 +- .../org/jetbrains/jet/codegen/StackValue.java | 4 +- .../jetbrains/jet/lang/types/TypeUtils.java | 15 ++ .../JetStructureViewElement.java | 6 + idea/testData/codegen/regressions/kt257.jet | 4 +- .../jetbrains/jet/codegen/ClassGenTest.java | 11 +- .../jet/codegen/CodegenTestCase.java | 3 +- stdlib/src/jet/Iterable$$Impl.java | 4 - stdlib/src/jet/Iterator$$Impl.java | 4 - stdlib/src/jet/typeinfo/TypeInfo.java | 2 +- 19 files changed, 259 insertions(+), 285 deletions(-) delete mode 100644 compiler/backend/src/org/jetbrains/jet/codegen/InterfaceBodyCodegen.java delete mode 100644 stdlib/src/jet/Iterable$$Impl.java delete mode 100644 stdlib/src/jet/Iterator$$Impl.java diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ClassBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ClassBodyCodegen.java index 6c2079241e9..fd4e66256a3 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ClassBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ClassBodyCodegen.java @@ -89,6 +89,7 @@ public abstract class ClassBodyCodegen { propertyCodegen.generateDefaultSetter(propertyDescriptor, Opcodes.ACC_PUBLIC); } + //noinspection ConstantConditions if (!(kind instanceof OwnerKind.DelegateKind) && kind != OwnerKind.INTERFACE && state.getBindingContext().get(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor)) { v.visitField(Opcodes.ACC_PRIVATE, p.getName(), state.getTypeMapper().mapType(propertyDescriptor.getOutType()).getDescriptor(), null, null); } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ClassCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ClassCodegen.java index 382e72d39a7..5c117ce1962 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ClassCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ClassCodegen.java @@ -20,13 +20,7 @@ public class ClassCodegen { public void generate(ClassContext parentContext, JetClassOrObject aClass) { GenerationState.prepareAnonymousClasses((JetElement) aClass, state.getTypeMapper()); - if (aClass instanceof JetObjectDeclaration) { - generateImplementation(parentContext, aClass, OwnerKind.IMPLEMENTATION); - } - else { - generateInterface(parentContext, aClass); - generateImplementation(parentContext, aClass, OwnerKind.IMPLEMENTATION); - } + generateImplementation(parentContext, aClass, OwnerKind.IMPLEMENTATION); ClassDescriptor descriptor = state.getBindingContext().get(BindingContext.CLASS, aClass); final ClassContext contextForInners = parentContext.intoClass(descriptor, OwnerKind.IMPLEMENTATION); @@ -37,17 +31,9 @@ public class ClassCodegen { } } - private void generateInterface(ClassContext parentContext, JetClassOrObject aClass) { - ClassDescriptor descriptor = state.getBindingContext().get(BindingContext.CLASS, aClass); - final ClassVisitor visitor = state.forClassInterface(descriptor); - new InterfaceBodyCodegen(aClass, parentContext.intoClass(descriptor, OwnerKind.INTERFACE), visitor, state).generate(); - } - private void generateImplementation(ClassContext parentContext, JetClassOrObject aClass, OwnerKind kind) { ClassDescriptor descriptor = state.getBindingContext().get(BindingContext.CLASS, aClass); - ClassVisitor v = kind == OwnerKind.IMPLEMENTATION - ? state.forClassImplementation(descriptor) - : state.forClassDelegatingImplementation(descriptor); + ClassVisitor v = state.forClassImplementation(descriptor); new ImplementationBodyCodegen(aClass, parentContext.intoClass(descriptor, kind), v, state).generate(); } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ClassContext.java b/compiler/backend/src/org/jetbrains/jet/codegen/ClassContext.java index 0739c39808f..837c899c41a 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ClassContext.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ClassContext.java @@ -154,7 +154,7 @@ public class ClassContext { public Type enclosingClassType(JetTypeMapper mapper) { DeclarationDescriptor descriptor = getContextDescriptor(); if (descriptor instanceof ClassDescriptor) { - return Type.getObjectType(mapper.jvmName((ClassDescriptor) descriptor, OwnerKind.INTERFACE)); + return Type.getObjectType(mapper.jvmName((ClassDescriptor) descriptor, OwnerKind.IMPLEMENTATION)); } if (descriptor instanceof NamespaceDescriptor) { diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index 44e5db4fe5e..3bf85426225 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -730,6 +730,13 @@ public class ExpressionCodegen extends JetVisitor { } JetType receiverType = bindingContext.get(BindingContext.EXPRESSION_TYPE, r); receiver.put(receiverType != null ? typeMapper.mapType(receiverType) : JetTypeMapper.TYPE_OBJECT, v); + if(receiverType != null) { + ClassDescriptor propReceiverDescriptor = (ClassDescriptor) propertyDescriptor.getContainingDeclaration(); + if(!TypeUtils.isInterface(propReceiverDescriptor, bindingContext) && TypeUtils.isInterface(receiverType.getConstructor().getDeclarationDescriptor(), bindingContext)) { + // I hope it happens only in case of required super class for traits + v.checkcast(typeMapper.mapType(propReceiverDescriptor.getDefaultType())); + } + } } return iValue; } @@ -752,8 +759,11 @@ public class ExpressionCodegen extends JetVisitor { } } else if (descriptor instanceof TypeParameterDescriptor) { - loadTypeParameterTypeInfo((TypeParameterDescriptor) descriptor); + TypeParameterDescriptor typeParameterDescriptor = (TypeParameterDescriptor) descriptor; + loadTypeParameterTypeInfo(typeParameterDescriptor); v.invokevirtual("jet/typeinfo/TypeInfo", "getClassObject", "()Ljava/lang/Object;"); + v.checkcast(typeMapper.mapType(typeParameterDescriptor.getClassObjectType())); + return StackValue.onStack(OBJECT_TYPE); } else { @@ -786,14 +796,20 @@ public class ExpressionCodegen extends JetVisitor { isInterface = false; } else { - owner = typeMapper.getOwner(functionDescriptor, OwnerKind.INTERFACE); + owner = typeMapper.getOwner(functionDescriptor, OwnerKind.IMPLEMENTATION); if(containingDeclaration instanceof JavaClassDescriptor) { PsiClass psiElement = (PsiClass) bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, containingDeclaration); assert psiElement != null; isInterface = psiElement.isInterface(); } - else - isInterface = !(containingDeclaration instanceof ClassDescriptor && ((ClassDescriptor) containingDeclaration).getKind() == ClassKind.OBJECT); + else { + if(containingDeclaration instanceof ClassDescriptor && ((ClassDescriptor) containingDeclaration).getKind() == ClassKind.OBJECT) + isInterface = false; + else { + JetClass jetClass = (JetClass) bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, containingDeclaration); + isInterface = jetClass == null || jetClass.isTrait(); + } + } } v.visitMethodInsn(isStatic ? Opcodes.INVOKESTATIC : isInterface ? Opcodes.INVOKEINTERFACE : Opcodes.INVOKEVIRTUAL, owner, functionDescriptor.getName(), typeMapper.mapSignature(functionDescriptor.getName(),functionDescriptor).getDescriptor()); @@ -827,8 +843,13 @@ public class ExpressionCodegen extends JetVisitor { isInterface = false; } else { - owner = typeMapper.getOwner(propertyDescriptor, OwnerKind.INTERFACE); - isInterface = !(containingDeclaration instanceof ClassDescriptor && ((ClassDescriptor) containingDeclaration).getKind() == ClassKind.OBJECT); + owner = typeMapper.getOwner(propertyDescriptor, OwnerKind.IMPLEMENTATION); + if(containingDeclaration instanceof ClassDescriptor && ((ClassDescriptor) containingDeclaration).getKind() == ClassKind.OBJECT) + isInterface = false; + else { + JetClass jetClass = (JetClass) bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, containingDeclaration); + isInterface = jetClass == null || jetClass.isTrait(); + } } return StackValue.property(propertyDescriptor.getName(), owner, typeMapper.mapType(propertyDescriptor.getOutType()), isStatic, isInterface, getter, setter); @@ -971,7 +992,7 @@ public class ExpressionCodegen extends JetVisitor { for (JetType superType : allSuperTypes) { final DeclarationDescriptor descriptor = superType.getConstructor().getDeclarationDescriptor(); - if (descriptor != null && superOriginal == descriptor.getOriginal()) { + if (descriptor != null && superOriginal.equals(descriptor.getOriginal())) { return true; } } @@ -1795,7 +1816,7 @@ public class ExpressionCodegen extends JetVisitor { if (!(descriptor instanceof ClassDescriptor)) { throw new UnsupportedOperationException("don't know how to handle non-class types in as/as?"); } - Type type = JetTypeMapper.boxType(typeMapper.mapType(jetType, OwnerKind.INTERFACE)); + Type type = JetTypeMapper.boxType(typeMapper.mapType(jetType)); generateInstanceOf(StackValue.expression(OBJECT_TYPE, expression.getLeft(), this), jetType, true); Label isInstance = new Label(); v.ifne(isInstance); @@ -1921,7 +1942,7 @@ public class ExpressionCodegen extends JetVisitor { if (leaveExpressionOnStack) { v.dup(); } - Type type = JetTypeMapper.boxType(typeMapper.mapType(jetType, OwnerKind.INTERFACE)); + Type type = JetTypeMapper.boxType(typeMapper.mapType(jetType)); if(jetType.isNullable()) { Label nope = new Label(); Label end = new Label(); @@ -1967,7 +1988,7 @@ public class ExpressionCodegen extends JetVisitor { return; } - final Type jvmType = typeMapper.mapType(jetType, OwnerKind.INTERFACE); + final Type jvmType = typeMapper.mapType(jetType); v.aconst(jvmType); v.iconst(jetType.isNullable()?1:0); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java index 173fb5309f8..3c7e3abe22a 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java @@ -89,15 +89,11 @@ public class FunctionCodegen { boolean isStatic = kind == OwnerKind.NAMESPACE; if (isStatic) flags |= Opcodes.ACC_STATIC; - boolean isAbstract = kind == OwnerKind.INTERFACE || bodyExpressions == null; + boolean isAbstract = bodyExpressions == null; if (isAbstract) flags |= Opcodes.ACC_ABSTRACT; - if (isAbstract && (kind == OwnerKind.IMPLEMENTATION )) { - return; - } - final MethodVisitor mv = v.visitMethod(flags, jvmSignature.getName(), jvmSignature.getDescriptor(), null, null); - if (kind != OwnerKind.INTERFACE) { + if (!isAbstract) { mv.visitCode(); FrameMap frameMap = context.prepareFrame(); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index 08b87629ebc..a81e6c116da 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -22,29 +22,77 @@ import java.util.*; /** * @author max * @author yole + * @author alex.tkachman */ public class ImplementationBodyCodegen extends ClassBodyCodegen { + private JetDelegationSpecifier superCall; + private String superClass = "java/lang/Object"; + public ImplementationBodyCodegen(JetClassOrObject aClass, ClassContext context, ClassVisitor v, GenerationState state) { super(aClass, context, v, state); } + private Set getSuperInterfaces(JetClassOrObject aClass) { + List delegationSpecifiers = aClass.getDelegationSpecifiers(); + String superClassName = null; + Set superInterfaces = new LinkedHashSet(); + + for (JetDelegationSpecifier specifier : delegationSpecifiers) { + JetType superType = state.getBindingContext().get(BindingContext.TYPE, specifier.getTypeReference()); + ClassDescriptor superClassDescriptor = (ClassDescriptor) superType.getConstructor().getDeclarationDescriptor(); + PsiElement superPsi = state.getBindingContext().get(BindingContext.DESCRIPTOR_TO_DECLARATION, superClassDescriptor); + + if (superPsi instanceof PsiClass) { + PsiClass psiClass = (PsiClass) superPsi; + String fqn = psiClass.getQualifiedName(); + if (psiClass.isInterface()) { + superInterfaces.add(fqn.replace('.', '/')); + } + else { + if (superClassName == null) { + superClassName = fqn.replace('.', '/'); + + while (psiClass != null) { + for (PsiClass ifs : psiClass.getInterfaces()) { + superInterfaces.add(ifs.getQualifiedName().replace('.', '/')); + } + psiClass = psiClass.getSuperClass(); + } + } + else { + throw new RuntimeException("Cannot determine single class to inherit from"); + } + } + } + else { + if(superPsi == null || ((JetClass)superPsi).isTrait()) + superInterfaces.add(JetTypeMapper.jvmNameForInterface(superClassDescriptor)); + } + } + return superInterfaces; + } + @Override protected void generateDeclaration() { - String superClass = getSuperClass(); + getSuperClass(); List interfaces = new ArrayList(); interfaces.add("jet/JetObject"); - if (!(myClass instanceof JetObjectDeclaration)) { - interfaces.add(JetTypeMapper.jvmNameForInterface(descriptor)); - } - else { - interfaces.addAll(InterfaceBodyCodegen.getSuperInterfaces(myClass, state.getBindingContext())); - } + interfaces.addAll(getSuperInterfaces(myClass)); - boolean isAbstract = myClass instanceof JetClass && ((JetClass) myClass).hasModifier(JetTokens.ABSTRACT_KEYWORD); + boolean isAbstract = false; + boolean isInterface = false; + if(myClass instanceof JetClass) { + if(((JetClass) myClass).hasModifier(JetTokens.ABSTRACT_KEYWORD)) + isAbstract = true; + if(((JetClass) myClass).isTrait()) { + isAbstract = true; + isInterface = true; + } + } v.visit(Opcodes.V1_6, - Opcodes.ACC_PUBLIC | (isAbstract ? Opcodes.ACC_ABSTRACT : 0), + Opcodes.ACC_PUBLIC | (isAbstract ? Opcodes.ACC_ABSTRACT : 0) | (isInterface ? Opcodes.ACC_INTERFACE : 0), jvmName(), null, superClass, @@ -57,23 +105,34 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { return state.getTypeMapper().jvmName(descriptor, kind); } - protected String getSuperClass() { + protected void getSuperClass() { List delegationSpecifiers = myClass.getDelegationSpecifiers(); - if (delegationSpecifiers.isEmpty()) return "java/lang/Object"; + if(myClass instanceof JetClass && ((JetClass)myClass).isTrait()) + return; - JetDelegationSpecifier first = delegationSpecifiers.get(0); - if (first instanceof JetDelegatorToSuperClass || first instanceof JetDelegatorToSuperCall) { - JetType superType = state.getBindingContext().get(BindingContext.TYPE, first.getTypeReference()); - ClassDescriptor superClassDescriptor = (ClassDescriptor) superType.getConstructor().getDeclarationDescriptor(); - final PsiElement declaration = state.getBindingContext().get(BindingContext.DESCRIPTOR_TO_DECLARATION, superClassDescriptor); - if (declaration instanceof PsiClass && ((PsiClass) declaration).isInterface()) { - return "java/lang/Object"; + for (JetDelegationSpecifier specifier : delegationSpecifiers) { + if (specifier instanceof JetDelegatorToSuperClass || specifier instanceof JetDelegatorToSuperCall) { + JetType superType = state.getBindingContext().get(BindingContext.TYPE, specifier.getTypeReference()); + ClassDescriptor superClassDescriptor = (ClassDescriptor) superType.getConstructor().getDeclarationDescriptor(); + final PsiElement declaration = state.getBindingContext().get(BindingContext.DESCRIPTOR_TO_DECLARATION, superClassDescriptor); + if (declaration != null) { + if (declaration instanceof PsiClass) { + if (!((PsiClass) declaration).isInterface()) { + superClass = state.getTypeMapper().jvmName(superClassDescriptor, kind); + superCall = specifier; + return; + } + } + else if(declaration instanceof JetClass) { + if(!((JetClass) declaration).isTrait()) { + superClass = state.getTypeMapper().jvmName(superClassDescriptor, kind); + superCall = specifier; + } + } + } } - return state.getTypeMapper().jvmName(superClassDescriptor, kind); } - - return "java/lang/Object"; } @Override @@ -93,6 +152,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { } private void generateFieldForTypeInfo() { + if(myClass instanceof JetClass && ((JetClass)myClass).isTrait()) + return; + final boolean typeInfoIsStatic = descriptor.getTypeConstructor().getParameters().size() == 0; v.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | (typeInfoIsStatic ? Opcodes.ACC_STATIC : 0), "$typeInfo", "Ljet/typeinfo/TypeInfo;", null, null); @@ -101,7 +163,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { @Override public void generate(InstructionAdapter v) { JetTypeMapper typeMapper = state.getTypeMapper(); - ClassCodegen.newTypeInfo(v, false, typeMapper.jvmType(descriptor, OwnerKind.INTERFACE)); + ClassCodegen.newTypeInfo(v, false, typeMapper.jvmType(descriptor, OwnerKind.IMPLEMENTATION)); v.putstatic(typeMapper.jvmName(descriptor, kind), "$typeInfo", "Ljet/typeinfo/TypeInfo;"); } }); @@ -149,8 +211,11 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { } protected void generatePrimaryConstructor() { + if(myClass instanceof JetClass && ((JetClass) myClass).isTrait()) + return; + ConstructorDescriptor constructorDescriptor = state.getBindingContext().get(BindingContext.CONSTRUCTOR, myClass); - if (constructorDescriptor == null && !(myClass instanceof JetObjectDeclaration) && !isEnum(myClass)) return; +// if (constructorDescriptor == null && !(myClass instanceof JetObjectDeclaration) && !isEnum(myClass)) return; Method method; CallableMethod callableMethod; @@ -166,7 +231,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { final MethodVisitor mv = v.visitMethod(flags, "", method.getDescriptor(), null, null); mv.visitCode(); - Type[] argTypes = method.getArgumentTypes(); List paramDescrs = constructorDescriptor != null ? constructorDescriptor.getValueParameters() : Collections.emptyList(); @@ -179,58 +243,32 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { String classname = state.getTypeMapper().jvmName(descriptor, kind); final Type classType = Type.getType("L" + classname + ";"); - List specifiers = myClass.getDelegationSpecifiers(); - - if (specifiers.isEmpty() || !(specifiers.get(0) instanceof JetDelegatorToSuperCall)) { - // TODO correct calculation of super class - String superClass = "java/lang/Object"; - if (!specifiers.isEmpty()) { - final JetType superType = state.getBindingContext().get(BindingContext.TYPE, specifiers.get(0).getTypeReference()); - ClassDescriptor superClassDescriptor = (ClassDescriptor) superType.getConstructor().getDeclarationDescriptor(); - if (superClassDescriptor.hasConstructors()) { - superClass = getSuperClass(); - } - } - iv.load(0, Type.getType("L" + superClass + ";")); - iv.invokespecial(superClass, "", /* TODO super constructor descriptor */"()V"); - } - - final ClassDescriptor outerDescriptor = getOuterClassDescriptor(); - if (outerDescriptor != null && outerDescriptor.getKind() != ClassKind.OBJECT) { - final Type type = JetTypeMapper.jetImplementationType(outerDescriptor); - String interfaceDesc = type.getDescriptor(); - final String fieldName = "this$0"; - v.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL, fieldName, interfaceDesc, null, null); - iv.load(0, classType); - iv.load(frameMap.getOuterThisIndex(), type); - iv.putfield(classname, fieldName, interfaceDesc); - } - HashSet overridden = new HashSet(); for (JetDeclaration declaration : myClass.getDeclarations()) { if (declaration instanceof JetFunction) { - overridden.addAll(state.getBindingContext().get(BindingContext.FUNCTION, (JetNamedFunction) declaration).getOverriddenDescriptors()); + overridden.addAll(state.getBindingContext().get(BindingContext.FUNCTION, declaration).getOverriddenDescriptors()); } } + if (superCall == null || superCall instanceof JetDelegatorToSuperClass) { + iv.load(0, Type.getType("L" + superClass + ";")); + iv.invokespecial(superClass, "", "()V"); + } + else { + iv.load(0, classType); + ConstructorDescriptor constructorDescriptor1 = (ConstructorDescriptor) state.getBindingContext().get(BindingContext.REFERENCE_TARGET, ((JetDelegatorToSuperCall) superCall).getCalleeExpression().getConstructorReferenceExpression()); + generateDelegatorToConstructorCall(iv, codegen, (JetDelegatorToSuperCall) superCall, constructorDescriptor1, frameMap); + } + int n = 0; - for (JetDelegationSpecifier specifier : specifiers) { - boolean delegateOnStack = specifier instanceof JetDelegatorToSuperCall && n > 0 || - specifier instanceof JetDelegatorByExpressionSpecifier; + for (JetDelegationSpecifier specifier : myClass.getDelegationSpecifiers()) { + if(specifier == superCall) + continue; - if (delegateOnStack) { + if (specifier instanceof JetDelegatorByExpressionSpecifier) { iv.load(0, classType); - } - - if (specifier instanceof JetDelegatorToSuperCall) { - ConstructorDescriptor constructorDescriptor1 = (ConstructorDescriptor) state.getBindingContext().get(BindingContext.REFERENCE_TARGET, ((JetDelegatorToSuperCall) specifier).getCalleeExpression().getConstructorReferenceExpression()); - generateDelegatorToConstructorCall(iv, codegen, (JetDelegatorToSuperCall) specifier, constructorDescriptor1, n == 0, frameMap); - } - else if (specifier instanceof JetDelegatorByExpressionSpecifier) { codegen.genToJVMStack(((JetDelegatorByExpressionSpecifier) specifier).getDelegateExpression()); - } - if (delegateOnStack) { JetType superType = state.getBindingContext().get(BindingContext.TYPE, specifier.getTypeReference()); ClassDescriptor superClassDescriptor = (ClassDescriptor) superType.getConstructor().getDeclarationDescriptor(); String delegateField = "$delegate_" + n; @@ -245,8 +283,17 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { JetTypeMapper.jvmNameForInterface(superClassDescriptor))); generateDelegates(superClass, delegateContext, overridden); } + } - n++; + final ClassDescriptor outerDescriptor = getOuterClassDescriptor(); + if (outerDescriptor != null && outerDescriptor.getKind() != ClassKind.OBJECT) { + final Type type = JetTypeMapper.jetImplementationType(outerDescriptor); + String interfaceDesc = type.getDescriptor(); + final String fieldName = "this$0"; + v.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL, fieldName, interfaceDesc, null, null); + iv.load(0, classType); + iv.load(frameMap.getOuterThisIndex(), type); + iv.putfield(classname, fieldName, interfaceDesc); } if (frameMap.getFirstTypeParameter() > 0 && kind == OwnerKind.IMPLEMENTATION) { @@ -288,7 +335,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { } private void generateDelegatorToConstructorCall(InstructionAdapter iv, ExpressionCodegen codegen, JetCallElement constructorCall, - ConstructorDescriptor constructorDescriptor, boolean isJavaSuperclass, + ConstructorDescriptor constructorDescriptor, ConstructorFrameMap frameMap) { ClassDescriptor classDecl = constructorDescriptor.getContainingDeclaration(); PsiElement declaration = state.getBindingContext().get(BindingContext.DESCRIPTOR_TO_DECLARATION, classDecl); @@ -300,13 +347,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { type = JetTypeMapper.jetImplementationType(classDecl); } - if (isJavaSuperclass) { - iv.load(0, type); - } - else { - iv.anew(type); - iv.dup(); - } + iv.load(0, type); if (classDecl.getContainingDeclaration() instanceof ClassDescriptor) { iv.load(frameMap.getOuterThisIndex(), state.getTypeMapper().jvmType((ClassDescriptor) descriptor.getContainingDeclaration(), OwnerKind.IMPLEMENTATION)); @@ -324,11 +365,60 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { else if (declaration instanceof JetClassObject) { generateClassObject((JetClassObject) declaration); } + else if (declaration instanceof JetEnumEntry && !((JetEnumEntry) declaration).hasPrimaryConstructor()) { + String name = declaration.getName(); + final String desc = "L" + state.getTypeMapper().jvmName(descriptor, OwnerKind.IMPLEMENTATION) + ";"; + v.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL, name, desc, null, null); + if (myEnumConstants.isEmpty()) { + staticInitializerChunks.add(new CodeChunk() { + @Override + public void generate(InstructionAdapter v) { + initializeEnumConstants(v); + } + }); + } + myEnumConstants.add((JetEnumEntry) declaration); + } else { super.generateDeclaration(propertyCodegen, declaration, functionCodegen); } } + private final List myEnumConstants = new ArrayList(); + + private void initializeEnumConstants(InstructionAdapter v) { + ExpressionCodegen codegen = new ExpressionCodegen(v, new FrameMap(), Type.VOID_TYPE, context, state); + for (JetEnumEntry enumConstant : myEnumConstants) { + // TODO type and constructor parameters + String implClass = state.getTypeMapper().jvmName(descriptor, OwnerKind.IMPLEMENTATION); + + final List delegationSpecifiers = enumConstant.getDelegationSpecifiers(); + if (delegationSpecifiers.size() > 1) { + throw new UnsupportedOperationException("multiple delegation specifiers for enum constant not supported"); + } + + v.anew(Type.getObjectType(implClass)); + v.dup(); + + if (delegationSpecifiers.size() == 1) { + final JetDelegationSpecifier specifier = delegationSpecifiers.get(0); + if (specifier instanceof JetDelegatorToSuperCall) { + final JetDelegatorToSuperCall superCall = (JetDelegatorToSuperCall) specifier; + ConstructorDescriptor constructorDescriptor = (ConstructorDescriptor) state.getBindingContext().get(BindingContext.REFERENCE_TARGET, superCall.getCalleeExpression().getConstructorReferenceExpression()); + CallableMethod method = state.getTypeMapper().mapToCallableMethod(constructorDescriptor, OwnerKind.IMPLEMENTATION); + codegen.invokeMethodWithArguments(method, superCall); + } + else { + throw new UnsupportedOperationException("unsupported type of enum constant initializer: " + specifier); + } + } + else { + v.invokespecial(implClass, "", "()V"); + } + v.putstatic(implClass, enumConstant.getName(), "L" + implClass + ";"); + } + } + private void generateSecondaryConstructor(JetConstructor constructor) { ConstructorDescriptor constructorDescriptor = state.getBindingContext().get(BindingContext.CONSTRUCTOR, constructor); if (constructorDescriptor == null) { @@ -351,7 +441,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { if (!(thisDescriptor instanceof ConstructorDescriptor)) { throw new UnsupportedOperationException("expected 'this' delegator to resolve to constructor"); } - generateDelegatorToConstructorCall(iv, codegen, thisCall, (ConstructorDescriptor) thisDescriptor, true, frameMap); + generateDelegatorToConstructorCall(iv, codegen, thisCall, (ConstructorDescriptor) thisDescriptor, frameMap); } else { throw new UnsupportedOperationException("unknown initializer type"); @@ -371,7 +461,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { protected void generateTypeInfoInitializer(int firstTypeParameter, int typeParamCount, InstructionAdapter iv) { iv.load(0, JetTypeMapper.TYPE_OBJECT); - iv.aconst(state.getTypeMapper().jvmType(descriptor, OwnerKind.INTERFACE)); + iv.aconst(state.getTypeMapper().jvmType(descriptor, OwnerKind.IMPLEMENTATION)); iv.iconst(0); iv.iconst(typeParamCount); iv.newarray(JetTypeMapper.TYPE_TYPEINFOPROJECTION); @@ -427,7 +517,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { iv.load(0, JetTypeMapper.TYPE_OBJECT); Type type = codegen.expressionType(initializer); if(propertyDescriptor.getOutType().isNullable()) - type = state.getTypeMapper().boxType(type); + type = JetTypeMapper.boxType(type); codegen.gen(initializer, type); codegen.intermediateValueForProperty(propertyDescriptor, false, false).store(iv); } @@ -479,6 +569,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { } private void generateGetTypeInfo() { + if(myClass instanceof JetClass && ((JetClass)myClass).isTrait()) + return; + final MethodVisitor mv = v.visitMethod(Opcodes.ACC_PUBLIC, "getTypeInfo", "()Ljet/typeinfo/TypeInfo;", diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/InterfaceBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/InterfaceBodyCodegen.java deleted file mode 100644 index 2e3f4e0578f..00000000000 --- a/compiler/backend/src/org/jetbrains/jet/codegen/InterfaceBodyCodegen.java +++ /dev/null @@ -1,137 +0,0 @@ -package org.jetbrains.jet.codegen; - -import com.intellij.psi.PsiClass; -import com.intellij.psi.PsiElement; -import org.jetbrains.jet.lang.descriptors.ClassDescriptor; -import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor; -import org.jetbrains.jet.lang.psi.*; -import org.jetbrains.jet.lang.resolve.BindingContext; -import org.jetbrains.jet.lang.types.JetType; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.Opcodes; -import org.objectweb.asm.Type; -import org.objectweb.asm.commons.InstructionAdapter; - -import java.util.ArrayList; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; - -/** - * @author yole - */ -public class InterfaceBodyCodegen extends ClassBodyCodegen { - private final List myEnumConstants = new ArrayList(); - - public InterfaceBodyCodegen(JetClassOrObject aClass, ClassContext context, ClassVisitor v, GenerationState state) { - super(aClass, context, v, state); - assert context.getContextKind() == OwnerKind.INTERFACE; - } - - protected void generateDeclaration() { - Set superInterfaces = getSuperInterfaces(myClass, state.getBindingContext()); - - String fqName = JetTypeMapper.jvmNameForInterface(descriptor); - v.visit(Opcodes.V1_6, - Opcodes.ACC_PUBLIC | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT, - fqName, - null, - "java/lang/Object", - superInterfaces.toArray(new String[superInterfaces.size()]) - ); - v.visitSource(myClass.getContainingFile().getName(), null); - } - - static Set getSuperInterfaces(JetClassOrObject aClass, final BindingContext bindingContext) { - List delegationSpecifiers = aClass.getDelegationSpecifiers(); - String superClassName = null; - Set superInterfaces = new LinkedHashSet(); - for (JetDelegationSpecifier specifier : delegationSpecifiers) { - JetType superType = bindingContext.get(BindingContext.TYPE, specifier.getTypeReference()); - ClassDescriptor superClassDescriptor = (ClassDescriptor) superType.getConstructor().getDeclarationDescriptor(); - PsiElement superPsi = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, superClassDescriptor); - - if (superPsi instanceof PsiClass) { - PsiClass psiClass = (PsiClass) superPsi; - String fqn = psiClass.getQualifiedName(); - if (psiClass.isInterface()) { - superInterfaces.add(fqn.replace('.', '/')); - } - else { - if (superClassName == null) { - superClassName = fqn.replace('.', '/'); - - while (psiClass != null) { - for (PsiClass ifs : psiClass.getInterfaces()) { - superInterfaces.add(ifs.getQualifiedName().replace('.', '/')); - } - psiClass = psiClass.getSuperClass(); - } - } - else { - throw new RuntimeException("Cannot determine single class to inherit from"); - } - } - } - else { - superInterfaces.add(JetTypeMapper.jvmNameForInterface(superClassDescriptor)); - } - } - return superInterfaces; - } - - @Override - protected void generateDeclaration(PropertyCodegen propertyCodegen, JetDeclaration declaration, FunctionCodegen functionCodegen) { - if (declaration instanceof JetEnumEntry && !((JetEnumEntry) declaration).hasPrimaryConstructor()) { - String name = declaration.getName(); - final String desc = "L" + state.getTypeMapper().jvmName(descriptor, OwnerKind.INTERFACE) + ";"; - v.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL, name, desc, null, null); - if (myEnumConstants.isEmpty()) { - staticInitializerChunks.add(new CodeChunk() { - @Override - public void generate(InstructionAdapter v) { - initializeEnumConstants(v); - } - }); - } - myEnumConstants.add((JetEnumEntry) declaration); - } - else { - super.generateDeclaration(propertyCodegen, declaration, functionCodegen); - } - } - - private void initializeEnumConstants(InstructionAdapter v) { - ExpressionCodegen codegen = new ExpressionCodegen(v, new FrameMap(), Type.VOID_TYPE, context, state); - for (JetEnumEntry enumConstant : myEnumConstants) { - // TODO type and constructor parameters - String intfClass = state.getTypeMapper().jvmName(descriptor, OwnerKind.INTERFACE); - String implClass = state.getTypeMapper().jvmName(descriptor, OwnerKind.IMPLEMENTATION); - - final List delegationSpecifiers = enumConstant.getDelegationSpecifiers(); - if (delegationSpecifiers.size() > 1) { - throw new UnsupportedOperationException("multiple delegation specifiers for enum constant not supported"); - } - - v.anew(Type.getObjectType(implClass)); - v.dup(); - - if (delegationSpecifiers.size() == 1) { - final JetDelegationSpecifier specifier = delegationSpecifiers.get(0); - if (specifier instanceof JetDelegatorToSuperCall) { - final JetDelegatorToSuperCall superCall = (JetDelegatorToSuperCall) specifier; - ConstructorDescriptor constructorDescriptor = (ConstructorDescriptor) state.getBindingContext().get(BindingContext.REFERENCE_TARGET, superCall.getCalleeExpression().getConstructorReferenceExpression()); - CallableMethod method = state.getTypeMapper().mapToCallableMethod(constructorDescriptor, OwnerKind.IMPLEMENTATION); - codegen.invokeMethodWithArguments(method, superCall); - } - else { - throw new UnsupportedOperationException("unsupported type of enum constant initializer: " + specifier); - } - } - else { - v.invokespecial(implClass, "", "()V"); - } - v.putstatic(intfClass, enumConstant.getName(), "L" + intfClass + ";"); - } - } -} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java b/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java index b6ab8153e38..430458dfec5 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java @@ -205,7 +205,7 @@ public class JetTypeMapper { if (parent instanceof JetClassObject) { JetClass containingClass = PsiTreeUtil.getParentOfType(parent, JetClass.class); final ClassDescriptor containingClassDescriptor = bindingContext.get(BindingContext.CLASS, containingClass); - return jvmName(containingClassDescriptor, OwnerKind.INTERFACE) + "$$ClassObj"; + return jvmName(containingClassDescriptor, OwnerKind.IMPLEMENTATION) + "$$ClassObj"; } @SuppressWarnings("SuspiciousMethodCalls") String className = classNamesForAnonymousClasses.get(declaration); if (className == null) { @@ -226,16 +226,13 @@ public class JetTypeMapper { if (declaration instanceof JetObjectDeclaration) { return false; } - return kind == OwnerKind.INTERFACE; + return jetClass instanceof JetClass ? ((JetClass)jetClass).isTrait() : false; } private static String jetJvmName(ClassDescriptor jetClass, OwnerKind kind) { if (jetClass.getKind() == ClassKind.OBJECT) { return jvmNameForImplementation(jetClass); } - if (kind == OwnerKind.INTERFACE) { - return jvmNameForInterface(jetClass); - } else if (kind == OwnerKind.IMPLEMENTATION) { return jvmNameForImplementation(jetClass); } @@ -277,7 +274,7 @@ public class JetTypeMapper { } public static String jvmNameForImplementation(ClassDescriptor descriptor) { - return jvmNameForInterface(descriptor) + "$$Impl"; + return jvmNameForInterface(descriptor); } public static String jvmNameForDelegatingImplementation(ClassDescriptor descriptor) { @@ -292,7 +289,7 @@ public class JetTypeMapper { else if (descriptor.getContainingDeclaration() instanceof ClassDescriptor) { ClassDescriptor classDescriptor = (ClassDescriptor) descriptor.getContainingDeclaration(); if (kind instanceof OwnerKind.DelegateKind) { - kind = OwnerKind.INTERFACE; + kind = OwnerKind.IMPLEMENTATION; } else { assert classDescriptor != null; @@ -316,11 +313,11 @@ public class JetTypeMapper { } @NotNull public Type mapReturnType(final JetType jetType) { - return mapReturnType(jetType, OwnerKind.INTERFACE); + return mapReturnType(jetType, OwnerKind.IMPLEMENTATION); } @NotNull public Type mapType(final JetType jetType) { - return mapType(jetType, OwnerKind.INTERFACE); + return mapType(jetType, OwnerKind.IMPLEMENTATION); } @NotNull public Type mapType(@NotNull final JetType jetType, OwnerKind kind) { @@ -483,7 +480,7 @@ public class JetTypeMapper { } else if (functionParent instanceof ClassDescriptor) { ClassDescriptor containingClass = (ClassDescriptor) functionParent; - owner = jvmName(containingClass, OwnerKind.INTERFACE); + owner = jvmName(containingClass, OwnerKind.IMPLEMENTATION); invokeOpcode = isInterface(containingClass, OwnerKind.INTERFACE) ? Opcodes.INVOKEINTERFACE : Opcodes.INVOKEVIRTUAL; @@ -636,7 +633,6 @@ public class JetTypeMapper { Set result = new HashSet(); final ClassDescriptor classDescriptor = bindingContext.get(BindingContext.CLASS, jetClass); if (classDescriptor != null) { - result.add(jvmName(classDescriptor, OwnerKind.INTERFACE)); result.add(jvmName(classDescriptor, OwnerKind.IMPLEMENTATION)); } return result; diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java index 01f0c5abf69..005cb7c422f 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java @@ -147,7 +147,7 @@ public class NamespaceCodegen { return; } - final Type jvmType = typeMapper.mapType(jetType, OwnerKind.INTERFACE); + final Type jvmType = typeMapper.mapType(jetType); v.aconst(jvmType); v.iconst(jetType.isNullable() ? 1 : 0); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java index da1201c4453..686fe404c38 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java @@ -1,6 +1,7 @@ package org.jetbrains.jet.codegen; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.PsiElement; import org.jetbrains.jet.lang.descriptors.PropertyDescriptor; import org.jetbrains.jet.lang.descriptors.PropertySetterDescriptor; import org.jetbrains.jet.lang.descriptors.VariableDescriptor; @@ -136,14 +137,16 @@ public class PropertyCodegen { if (kind == OwnerKind.NAMESPACE) { flags |= Opcodes.ACC_STATIC; } - else if (kind == OwnerKind.INTERFACE) { + + PsiElement psiElement = state.getBindingContext().get(BindingContext.DESCRIPTOR_TO_DECLARATION, propertyDescriptor.getContainingDeclaration()); + boolean isTrait = psiElement instanceof JetClass && ((JetClass) psiElement).isTrait(); + if(isTrait && !(kind instanceof OwnerKind.DelegateKind)) flags |= Opcodes.ACC_ABSTRACT; - } final String signature = state.getTypeMapper().mapGetterSignature(propertyDescriptor).getDescriptor(); String getterName = getterName(propertyDescriptor.getName()); MethodVisitor mv = v.visitMethod(flags, getterName, signature, null, null); - if (kind != OwnerKind.INTERFACE) { + if (!isTrait || kind instanceof OwnerKind.DelegateKind) { mv.visitCode(); InstructionAdapter iv = new InstructionAdapter(mv); if (kind != OwnerKind.NAMESPACE) { @@ -176,13 +179,15 @@ public class PropertyCodegen { if (kind == OwnerKind.NAMESPACE) { flags |= Opcodes.ACC_STATIC; } - else if (kind == OwnerKind.INTERFACE) { + + PsiElement psiElement = state.getBindingContext().get(BindingContext.DESCRIPTOR_TO_DECLARATION, propertyDescriptor.getContainingDeclaration()); + boolean isTrait = psiElement instanceof JetClass && ((JetClass) psiElement).isTrait(); + if(isTrait && !(kind instanceof OwnerKind.DelegateKind)) flags |= Opcodes.ACC_ABSTRACT; - } final String signature = state.getTypeMapper().mapSetterSignature(propertyDescriptor).getDescriptor(); MethodVisitor mv = v.visitMethod(flags, setterName(propertyDescriptor.getName()), signature, null, null); - if (kind != OwnerKind.INTERFACE) { + if (!isTrait || kind instanceof OwnerKind.DelegateKind) { mv.visitCode(); InstructionAdapter iv = new InstructionAdapter(mv); final Type type = state.getTypeMapper().mapType(propertyDescriptor.getOutType()); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java index 9daa14e79cd..29dbf0c7914 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java @@ -186,8 +186,8 @@ public abstract class StackValue { else v.iconst(0); } - else if (type.getSort() == Type.OBJECT && this.type.getSort() == Type.OBJECT) { - // v.checkcast(type); + else if (type.getSort() == Type.OBJECT && this.type.equals(JetTypeMapper.TYPE_OBJECT)) { + v.checkcast(type); } else if (type.getSort() == Type.OBJECT) { box(this.type, type, v); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java index 34f32ea9203..4d2bbae2748 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java @@ -3,12 +3,16 @@ package org.jetbrains.jet.lang.types; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; +import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor; +import org.jetbrains.jet.lang.psi.JetClass; +import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.ChainedScope; import org.jetbrains.jet.lang.resolve.JetScope; @@ -342,4 +346,15 @@ public class TypeUtils { return false; } + + public static boolean isInterface(DeclarationDescriptor descriptor, BindingContext bindingContext) { + PsiElement psiElement = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, descriptor); + if(psiElement instanceof JetClass) { + return ((JetClass)psiElement).isTrait(); + } + if(psiElement instanceof PsiClass) { + return ((PsiClass)psiElement).isInterface(); + } + return false; + } } diff --git a/idea/src/org/jetbrains/jet/plugin/structureView/JetStructureViewElement.java b/idea/src/org/jetbrains/jet/plugin/structureView/JetStructureViewElement.java index e398c7d605a..cba16e62868 100644 --- a/idea/src/org/jetbrains/jet/plugin/structureView/JetStructureViewElement.java +++ b/idea/src/org/jetbrains/jet/plugin/structureView/JetStructureViewElement.java @@ -3,6 +3,7 @@ package org.jetbrains.jet.plugin.structureView; import com.intellij.ide.structureView.StructureViewTreeElement; import com.intellij.ide.util.treeView.smartTree.TreeElement; import com.intellij.navigation.ItemPresentation; +import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.util.Iconable; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.NavigatablePsiElement; @@ -68,6 +69,11 @@ public class JetStructureViewElement implements StructureViewTreeElement { ? PsiIconUtil.getProvidersIcon(myElement, open ? Iconable.ICON_FLAG_OPEN : Iconable.ICON_FLAG_CLOSED) : null; } + + @Override + public TextAttributesKey getTextAttributesKey() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } }; } diff --git a/idea/testData/codegen/regressions/kt257.jet b/idea/testData/codegen/regressions/kt257.jet index 3a965795a2c..45482c59216 100644 --- a/idea/testData/codegen/regressions/kt257.jet +++ b/idea/testData/codegen/regressions/kt257.jet @@ -5,7 +5,7 @@ fun box() : String { val ai = A(1) val aai = A>(ai) if(aai.t.t != 1) return "fail" - +/* aai.t.t = 2 if(aai.t.t != 2) return "fail" @@ -15,6 +15,6 @@ fun box() : String { val abi = A>(B(1)) if(abi.t.r != 1) return "fail" - +*/ return "OK" } \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/codegen/ClassGenTest.java b/idea/tests/org/jetbrains/jet/codegen/ClassGenTest.java index 4ad79afa3a8..4e6f7802f56 100644 --- a/idea/tests/org/jetbrains/jet/codegen/ClassGenTest.java +++ b/idea/tests/org/jetbrains/jet/codegen/ClassGenTest.java @@ -14,7 +14,9 @@ public class ClassGenTest extends CodegenTestCase { final Class aClass = loadClass("SimpleClass", generateClassesInFile()); final Method[] methods = aClass.getDeclaredMethods(); - assertEquals(1, methods.length); + // public int SimpleClass.foo() + // public jet.typeinfo.TypeInfo SimpleClass.getTypeInfo() + assertEquals(2, methods.length); } public void testArrayListInheritance() throws Exception { @@ -77,9 +79,7 @@ public class ClassGenTest extends CodegenTestCase { final ClassFileFactory codegens = generateClassesInFile(); final Class aClass = loadClass("Foo", codegens); assertNotNull(aClass.getMethod("x")); - final Class implClass = loadClass("Foo$$Impl", codegens); - assertNull(findMethodByName(implClass, "x")); - assertNotNull(findMethodByName(implClass, "y")); + assertNotNull(findMethodByName(aClass, "y")); } public void testInheritedMethod() throws Exception { @@ -113,7 +113,7 @@ public class ClassGenTest extends CodegenTestCase { public void testAbstractClass() throws Exception { loadText("abstract class SimpleClass() { }"); - final Class aClass = loadAllClasses(generateClassesInFile()).get("SimpleClass$$Impl"); + final Class aClass = loadAllClasses(generateClassesInFile()).get("SimpleClass"); assertTrue((aClass.getModifiers() & Modifier.ABSTRACT) != 0); } @@ -155,6 +155,7 @@ public class ClassGenTest extends CodegenTestCase { public void testEnumClass() throws Exception { loadText("enum class Direction { NORTH; SOUTH; EAST; WEST }"); final Class direction = loadAllClasses(generateClassesInFile()).get("Direction"); + System.out.println(generateToText()); final Field north = direction.getField("NORTH"); assertEquals(direction, north.getType()); assertInstanceOf(north.get(null), direction); diff --git a/idea/tests/org/jetbrains/jet/codegen/CodegenTestCase.java b/idea/tests/org/jetbrains/jet/codegen/CodegenTestCase.java index b9ac1380d91..45731728ffc 100644 --- a/idea/tests/org/jetbrains/jet/codegen/CodegenTestCase.java +++ b/idea/tests/org/jetbrains/jet/codegen/CodegenTestCase.java @@ -197,8 +197,7 @@ public abstract class CodegenTestCase extends LightCodeInsightFixtureTestCase { } protected Class loadImplementationClass(ClassFileFactory codegens, final String name) { - loadClass(name, codegens); - return loadClass(name + "$$Impl", codegens); + return loadClass(name, codegens); } private static class MyClassLoader extends ClassLoader { diff --git a/stdlib/src/jet/Iterable$$Impl.java b/stdlib/src/jet/Iterable$$Impl.java deleted file mode 100644 index 22a2b4ec40d..00000000000 --- a/stdlib/src/jet/Iterable$$Impl.java +++ /dev/null @@ -1,4 +0,0 @@ -package jet; - -public abstract class Iterable$$Impl implements Iterable { -} diff --git a/stdlib/src/jet/Iterator$$Impl.java b/stdlib/src/jet/Iterator$$Impl.java deleted file mode 100644 index 141ef338a48..00000000000 --- a/stdlib/src/jet/Iterator$$Impl.java +++ /dev/null @@ -1,4 +0,0 @@ -package jet; - -public abstract class Iterator$$Impl implements Iterator { -} diff --git a/stdlib/src/jet/typeinfo/TypeInfo.java b/stdlib/src/jet/typeinfo/TypeInfo.java index e8c7f5e36d2..cd97f0f8547 100644 --- a/stdlib/src/jet/typeinfo/TypeInfo.java +++ b/stdlib/src/jet/typeinfo/TypeInfo.java @@ -85,7 +85,7 @@ public abstract class TypeInfo implements JetObject { public final Object getClassObject() { try { - final Class implClass = theClass.getClassLoader().loadClass(theClass.getCanonicalName() + "$$Impl"); + final Class implClass = theClass.getClassLoader().loadClass(theClass.getCanonicalName()); final Field classobj = implClass.getField("$classobj"); return classobj.get(null); } catch (Exception e) {