diff --git a/.idea/artifacts/KotlinPlugin.xml b/.idea/artifacts/KotlinPlugin.xml new file mode 100644 index 00000000000..ee684d78127 --- /dev/null +++ b/.idea/artifacts/KotlinPlugin.xml @@ -0,0 +1,19 @@ + + + $PROJECT_DIR$/out/artifacts/KotlinPlugin + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 1397a2192d0..8d54c189540 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -15,6 +15,7 @@ + diff --git a/.idea/modules.xml b/.idea/modules.xml index 9c559c5bba1..911155cf2be 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -11,6 +11,7 @@ + diff --git a/build.xml b/build.xml index c6aa63a9a03..4084ccf2e94 100644 --- a/build.xml +++ b/build.xml @@ -73,7 +73,10 @@ + + + diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/BothSignatureWriter.java b/compiler/backend/src/org/jetbrains/jet/codegen/BothSignatureWriter.java index e8afc6a442d..66273168bdc 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/BothSignatureWriter.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/BothSignatureWriter.java @@ -3,11 +3,12 @@ package org.jetbrains.jet.codegen; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.resolve.java.JetSignatureUtils; +import org.jetbrains.jet.lang.types.Variance; import org.jetbrains.jet.rt.signature.JetSignatureAdapter; import org.jetbrains.jet.rt.signature.JetSignatureReader; import org.jetbrains.jet.rt.signature.JetSignatureWriter; -import org.jetbrains.jet.lang.types.Variance; import org.objectweb.asm.Type; +import org.objectweb.asm.commons.Method; import org.objectweb.asm.signature.SignatureVisitor; import org.objectweb.asm.signature.SignatureWriter; import org.objectweb.asm.util.CheckSignatureAdapter; @@ -40,6 +41,7 @@ public class BothSignatureWriter { TYPE_PARAMETERS, PARAMETERS, + PARAMETER, RETURN_TYPE, METHOD_END, @@ -55,16 +57,26 @@ public class BothSignatureWriter { private String kotlinClassParameters; private String kotlinClassSignature; - private List kotlinParameterTypes = new ArrayList(); + private List kotlinParameterTypes = new ArrayList(); private String kotlinReturnType; + + private int jvmCurrentTypeArrayLevel; + private Type jvmCurrentType; + private Type jvmReturnType; + + private JvmMethodParameterKind currentParameterKind; private final Mode mode; + private final boolean needGenerics; + private State state = State.START; private boolean generic = false; - public BothSignatureWriter(Mode mode) { + public BothSignatureWriter(Mode mode, boolean needGenerics) { this.mode = mode; + this.needGenerics = needGenerics; + if (DEBUG_SIGNATURE_WRITER) { signatureVisitor = new CheckSignatureAdapter(mode.asmType, signatureWriter); } else { @@ -152,11 +164,27 @@ public class BothSignatureWriter { } signatureVisitor().visitBaseType(c); jetSignatureWriter.visitBaseType(c, nullable); + writeAsmType0(Type.getType(String.valueOf(c))); + } + + private String makeArrayPrefix() { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < jvmCurrentTypeArrayLevel; ++i) { + sb.append('['); + } + return sb.toString(); + } + + private void writeAsmType0(Type type) { + if (jvmCurrentType == null) { + jvmCurrentType = Type.getType(makeArrayPrefix() + type.getDescriptor()); + } } public void writeClassBegin(String internalName, boolean nullable) { signatureVisitor().visitClassType(internalName); jetSignatureWriter.visitClassType(internalName, nullable); + writeAsmType0(Type.getObjectType(internalName)); } public void writeClassEnd() { @@ -167,6 +195,9 @@ public class BothSignatureWriter { public void writeArrayType(boolean nullable) { push(signatureVisitor().visitArrayType()); jetSignatureWriter.visitArrayType(nullable); + if (jvmCurrentType == null) { + ++jvmCurrentTypeArrayLevel; + } } public void writeArrayEnd() { @@ -183,10 +214,11 @@ public class BothSignatureWriter { pop(); } - public void writeTypeVariable(final String name, boolean nullable) { + public void writeTypeVariable(final String name, boolean nullable, Type asmType) { signatureVisitor().visitTypeVariable(name); jetSignatureWriter.visitTypeVariable(name, nullable); generic = true; + writeAsmType0(asmType); } public void writeFormalTypeParameter(final String name, Variance variance) { @@ -202,7 +234,7 @@ public class BothSignatureWriter { jetSignatureWriter.visitFormalTypeParameterEnd(); } - public void writerFormalTypeParametersStart() { + public void writeFormalTypeParametersStart() { checkTopLevel(); transitionState(State.START, State.TYPE_PARAMETERS); jetSignatureWriter = new JetSignatureWriter(); @@ -242,28 +274,59 @@ public class BothSignatureWriter { public void writeParametersStart() { transitionState(State.TYPE_PARAMETERS, State.PARAMETERS); + + // hacks + jvmCurrentType = null; + jvmCurrentTypeArrayLevel = 0; } public void writeParametersEnd() { checkState(State.PARAMETERS); } - public void writeParameterType() { + public void writeParameterType(JvmMethodParameterKind parameterKind) { + transitionState(State.PARAMETERS, State.PARAMETER); + push(signatureVisitor().visitParameterType()); jetSignatureWriter = new JetSignatureWriter(); + if (jvmCurrentType != null || jvmCurrentTypeArrayLevel != 0) { + throw new IllegalStateException(); + } + + if (currentParameterKind != null) { + throw new IllegalStateException(); + } + this.currentParameterKind = parameterKind; + //jetSignatureWriter.visitParameterType(); } public void writeParameterTypeEnd() { pop(); + + if (jvmCurrentType == null) { + throw new IllegalStateException(); + } + String signature = jetSignatureWriter.toString(); - kotlinParameterTypes.add(signature); + kotlinParameterTypes.add(new JvmMethodParameterSignature(jvmCurrentType, signature, currentParameterKind)); if (DEBUG_SIGNATURE_WRITER) { new JetSignatureReader(signature).acceptTypeOnly(new JetSignatureAdapter()); } + currentParameterKind = null; + jvmCurrentType = null; + jvmCurrentTypeArrayLevel = 0; + jetSignatureWriter = null; + transitionState(State.PARAMETER, State.PARAMETERS); + } + + public void writeTypeInfoParameter() { + writeParameterType(JvmMethodParameterKind.TYPE_INFO); + writeAsmType(JetTypeMapper.TYPE_TYPEINFO, false); + writeParameterTypeEnd(); } public void writeReturnType() { @@ -271,6 +334,10 @@ public class BothSignatureWriter { jetSignatureWriter = new JetSignatureWriter(); + if (jvmCurrentType != null) { + throw new IllegalStateException(); + } + push(signatureVisitor().visitReturnType()); //jetSignatureWriter.visitReturnType(); } @@ -280,6 +347,14 @@ public class BothSignatureWriter { kotlinReturnType = jetSignatureWriter.toString(); + if (jvmCurrentType == null) { + throw new IllegalStateException(); + } + + jvmReturnType = jvmCurrentType; + jvmCurrentType = null; + jvmCurrentTypeArrayLevel = 0; + if (DEBUG_SIGNATURE_WRITER) { new JetSignatureReader(kotlinReturnType).acceptTypeOnly(new JetSignatureAdapter()); } @@ -288,6 +363,12 @@ public class BothSignatureWriter { transitionState(State.RETURN_TYPE, State.METHOD_END); } + public void writeVoidReturn() { + writeReturnType(); + writeAsmType(Type.VOID_TYPE, false); + writeReturnTypeEnd(); + } + public void writeSupersStart() { transitionState(State.TYPE_PARAMETERS, State.SUPERS); jetSignatureWriter = new JetSignatureWriter(); @@ -333,6 +414,14 @@ public class BothSignatureWriter { + @NotNull + public Method makeAsmMethod(String name) { + List jvmParameterTypes = new ArrayList(kotlinParameterTypes.size()); + for (JvmMethodParameterSignature p : kotlinParameterTypes) { + jvmParameterTypes.add(p.getAsmType()); + } + return new Method(name, jvmReturnType, jvmParameterTypes.toArray(new Type[0])); + } @Nullable public String makeJavaString() { @@ -344,13 +433,13 @@ public class BothSignatureWriter { } @NotNull - public List makeKotlinParameterTypes() { + public List makeKotlinParameterTypes() { checkState(State.METHOD_END); // TODO: return nulls if equal to #makeJavaString return kotlinParameterTypes; } - @Nullable + @NotNull public String makeKotlinReturnTypeSignature() { checkState(State.METHOD_END); return kotlinReturnType; @@ -373,4 +462,19 @@ public class BothSignatureWriter { return kotlinClassParameters + kotlinClassSignature; } + @NotNull + public JvmMethodSignature makeJvmMethodSignature(String name) { + if (needGenerics) { + return new JvmMethodSignature( + makeAsmMethod(name), + makeJavaString(), + makeKotlinMethodTypeParameters(), + makeKotlinParameterTypes(), + makeKotlinReturnTypeSignature() + ); + } else { + return new JvmMethodSignature(makeAsmMethod(name), makeKotlinParameterTypes()); + } + } + } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/CallableMethod.java b/compiler/backend/src/org/jetbrains/jet/codegen/CallableMethod.java index f93b818b852..fe479826648 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/CallableMethod.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/CallableMethod.java @@ -19,17 +19,15 @@ public class CallableMethod implements Callable { private String owner; private final JvmMethodSignature signature; private int invokeOpcode; - private final List valueParameterTypes; private ClassDescriptor thisClass = null; private CallableDescriptor receiverFunction = null; private Type generateCalleeType = null; - public CallableMethod(String owner, JvmMethodSignature signature, int invokeOpcode, List valueParameterTypes) { + public CallableMethod(String owner, JvmMethodSignature signature, int invokeOpcode) { this.owner = owner; this.signature = signature; this.invokeOpcode = invokeOpcode; - this.valueParameterTypes = valueParameterTypes; } public String getOwner() { @@ -45,7 +43,7 @@ public class CallableMethod implements Callable { } public List getValueParameterTypes() { - return valueParameterTypes; + return signature.getValueParameterTypes(); } public void setNeedsReceiver(@Nullable CallableDescriptor receiverClass) { diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java index 138071c47b3..43f89484007 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java @@ -39,22 +39,40 @@ public class ClosureCodegen extends ObjectOrClosureCodegen { bindingContext = state.getBindingContext(); } - public static Method erasedInvokeSignature(FunctionDescriptor fd) { + public static JvmMethodSignature erasedInvokeSignature(FunctionDescriptor fd) { + + BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, false); + + signatureWriter.writeFormalTypeParametersStart(); + signatureWriter.writeFormalTypeParametersEnd(); + boolean isExtensionFunction = fd.getReceiverParameter().exists(); int paramCount = fd.getValueParameters().size(); if (isExtensionFunction) { paramCount++; } + + signatureWriter.writeParametersStart(); + + for (int i = 0; i < paramCount; ++i) { + signatureWriter.writeParameterType(JvmMethodParameterKind.VALUE); + signatureWriter.writeAsmType(JetTypeMapper.TYPE_OBJECT, true); + signatureWriter.writeParameterTypeEnd(); + } + + signatureWriter.writeParametersEnd(); - Type[] args = new Type[paramCount]; - Arrays.fill(args, JetTypeMapper.TYPE_OBJECT); - return new Method("invoke", JetTypeMapper.TYPE_OBJECT, args); + signatureWriter.writeReturnType(); + signatureWriter.writeAsmType(JetTypeMapper.TYPE_OBJECT, true); + signatureWriter.writeReturnTypeEnd(); + + return signatureWriter.makeJvmMethodSignature("invoke"); } public static CallableMethod asCallableMethod(FunctionDescriptor fd) { - Method descriptor = erasedInvokeSignature(fd); + JvmMethodSignature descriptor = erasedInvokeSignature(fd); String owner = getInternalClassName(fd); - final CallableMethod result = new CallableMethod(owner, new JvmMethodSignature(descriptor, null, null, null, null), INVOKEVIRTUAL, Arrays.asList(descriptor.getArgumentTypes())); + final CallableMethod result = new CallableMethod(owner, descriptor, INVOKEVIRTUAL); if (fd.getReceiverParameter().exists()) { result.setNeedsReceiver(fd); } @@ -62,8 +80,8 @@ public class ClosureCodegen extends ObjectOrClosureCodegen { return result; } - public Method invokeSignature(FunctionDescriptor fd) { - return state.getTypeMapper().mapSignature("invoke", fd).getAsmMethod(); + public JvmMethodSignature invokeSignature(FunctionDescriptor fd) { + return state.getTypeMapper().mapSignature("invoke", fd); } public GeneratedAnonymousClassDescriptor gen(JetFunctionLiteralExpression fun) { @@ -165,18 +183,19 @@ public class ClosureCodegen extends ObjectOrClosureCodegen { final CodegenContext.ClosureContext closureContext = context.intoClosure(funDescriptor, function, name, this, state.getTypeMapper()); FunctionCodegen fc = new FunctionCodegen(closureContext, cv, state); - fc.generateMethod(body, new JvmMethodSignature(invokeSignature(funDescriptor), null, null, null, null), funDescriptor); + JvmMethodSignature jvmMethodSignature = invokeSignature(funDescriptor); + fc.generateMethod(body, jvmMethodSignature, null, funDescriptor); return closureContext.outerWasUsed; } private void generateBridge(String className, FunctionDescriptor funDescriptor, JetExpression fun, ClassBuilder cv) { - final Method bridge = erasedInvokeSignature(funDescriptor); - final Method delegate = invokeSignature(funDescriptor); + final JvmMethodSignature bridge = erasedInvokeSignature(funDescriptor); + final Method delegate = invokeSignature(funDescriptor).getAsmMethod(); - if(bridge.getDescriptor().equals(delegate.getDescriptor())) + if(bridge.getAsmMethod().getDescriptor().equals(delegate.getDescriptor())) return; - final MethodVisitor mv = cv.newMethod(fun, ACC_PUBLIC, "invoke", bridge.getDescriptor(), null, new String[0]); + final MethodVisitor mv = cv.newMethod(fun, ACC_PUBLIC, "invoke", bridge.getAsmMethod().getDescriptor(), null, new String[0]); if (cv.generateCode()) { mv.visitCode(); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenContext.java b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenContext.java index c6e1d5a9a13..368b1915d9e 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenContext.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenContext.java @@ -207,11 +207,11 @@ public abstract class CodegenContext { if(accessor != null) return accessor; - if(descriptor instanceof FunctionDescriptor) { - FunctionDescriptorImpl myAccessor = new FunctionDescriptorImpl(contextType, + if(descriptor instanceof NamedFunctionDescriptor) { + NamedFunctionDescriptorImpl myAccessor = new NamedFunctionDescriptorImpl(contextType, Collections.emptyList(), descriptor.getName() + "$bridge$" + accessors.size()); - FunctionDescriptor fd = (FunctionDescriptor) descriptor; + FunctionDescriptor fd = (NamedFunctionDescriptor) descriptor; myAccessor.initialize(fd.getReceiverParameter().exists() ? fd.getReceiverParameter().getType() : null, fd.getExpectedThisObject(), fd.getTypeParameters(), @@ -241,11 +241,9 @@ public abstract class CodegenContext { pgd.initialize(myAccessor.getOutType()); PropertySetterDescriptor psd = new PropertySetterDescriptor( - myAccessor.getModality(), + myAccessor, Collections.emptyList(), myAccessor.getModality(), myAccessor.getVisibility(), - myAccessor, - Collections.emptyList(), - false, false); + false, false); myAccessor.initialize(pgd, psd); accessor = myAccessor; } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java index 2a2fcf34ea4..176502c3e82 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java @@ -85,9 +85,9 @@ public class CodegenUtil { return hasDerivedTypeInfoField(type); } - public static FunctionDescriptor createInvoke(ExpressionAsFunctionDescriptor fd) { + public static NamedFunctionDescriptor createInvoke(ExpressionAsFunctionDescriptor fd) { int arity = fd.getValueParameters().size(); - FunctionDescriptorImpl invokeDescriptor = new FunctionDescriptorImpl( + NamedFunctionDescriptorImpl invokeDescriptor = new NamedFunctionDescriptorImpl( fd.getExpectedThisObject().exists() ? JetStandardClasses.getReceiverFunction(arity) : JetStandardClasses.getFunction(arity), Collections.emptyList(), "invoke"); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index 75f29f34539..eacfd2e3308 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -1097,7 +1097,7 @@ public class ExpressionCodegen extends JetVisitor { } } if(!(containingDeclaration instanceof JavaNamespaceDescriptor) && !(containingDeclaration instanceof JavaClassDescriptor)) - getter = typeMapper.mapGetterSignature(propertyDescriptor, OwnerKind.IMPLEMENTATION).getAsmMethod(); + getter = typeMapper.mapGetterSignature(propertyDescriptor, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod(); else getter = null; } @@ -1107,8 +1107,8 @@ public class ExpressionCodegen extends JetVisitor { } else { if(!(containingDeclaration instanceof JavaNamespaceDescriptor) && !(containingDeclaration instanceof JavaClassDescriptor)) { - JvmMethodSignature jvmMethodSignature = typeMapper.mapSetterSignature(propertyDescriptor, OwnerKind.IMPLEMENTATION); - setter = jvmMethodSignature != null ? jvmMethodSignature.getAsmMethod() : null; + JvmPropertyAccessorSignature jvmMethodSignature = typeMapper.mapSetterSignature(propertyDescriptor, OwnerKind.IMPLEMENTATION); + setter = jvmMethodSignature != null ? jvmMethodSignature.getJvmMethodSignature().getAsmMethod() : null; } else { setter = null; } @@ -1218,7 +1218,7 @@ public class ExpressionCodegen extends JetVisitor { callableMethod = ClosureCodegen.asCallableMethod((FunctionDescriptor) fd); } else if (fd instanceof ExpressionAsFunctionDescriptor) { - FunctionDescriptor invoke = CodegenUtil.createInvoke((ExpressionAsFunctionDescriptor) fd); + NamedFunctionDescriptor invoke = CodegenUtil.createInvoke((ExpressionAsFunctionDescriptor) fd); callableMethod = ClosureCodegen.asCallableMethod(invoke); } else if (fd instanceof FunctionDescriptor) { diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java index da0a51a5e7e..d043a239822 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java @@ -1,6 +1,7 @@ package org.jetbrains.jet.codegen; import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.psi.*; @@ -40,21 +41,22 @@ public class FunctionCodegen { } public void gen(JetNamedFunction f) { - final FunctionDescriptor functionDescriptor = state.getBindingContext().get(BindingContext.FUNCTION, f); + final NamedFunctionDescriptor functionDescriptor = state.getBindingContext().get(BindingContext.FUNCTION, f); assert functionDescriptor != null; JvmMethodSignature method = typeMapper.mapToCallableMethod(functionDescriptor, false, owner.getContextKind()).getSignature(); - generateMethod(f, method, functionDescriptor); + generateMethod(f, method, null, functionDescriptor); } - public void generateMethod(JetDeclarationWithBody f, JvmMethodSignature jvmMethod, FunctionDescriptor functionDescriptor) { + public void generateMethod(JetDeclarationWithBody f, JvmMethodSignature jvmMethod, @Nullable String propertyTypeSignature, FunctionDescriptor functionDescriptor) { CodegenContext.MethodContext funContext = owner.intoFunction(functionDescriptor); final JetExpression bodyExpression = f.getBodyExpression(); - generatedMethod(bodyExpression, jvmMethod, funContext, functionDescriptor, f); + generatedMethod(bodyExpression, jvmMethod, propertyTypeSignature, funContext, functionDescriptor, f); } private void generatedMethod(JetExpression bodyExpressions, JvmMethodSignature jvmSignature, + @Nullable String propertyTypeSignature, CodegenContext.MethodContext context, FunctionDescriptor functionDescriptor, JetDeclarationWithBody fun) { @@ -91,17 +93,26 @@ public class FunctionCodegen { if(v.generateCode()) { int start = 0; if(kind != OwnerKind.TRAIT_IMPL) { - AnnotationVisitor av = mv.visitAnnotation(JvmStdlibNames.JET_METHOD.getDescriptor(), true); - if(functionDescriptor.getReturnType().isNullable()) { - av.visit(JvmStdlibNames.JET_METHOD_NULLABLE_RETURN_TYPE_FIELD, true); + if (functionDescriptor instanceof PropertyAccessorDescriptor) { + PropertyCodegen.generateJetPropertyAnnotation(mv, propertyTypeSignature, jvmSignature.getKotlinTypeParameter()); + } else if (functionDescriptor instanceof NamedFunctionDescriptor) { + if (propertyTypeSignature != null) { + throw new IllegalStateException(); + } + AnnotationVisitor av = mv.visitAnnotation(JvmStdlibNames.JET_METHOD.getDescriptor(), true); + if(functionDescriptor.getReturnType().isNullable()) { + av.visit(JvmStdlibNames.JET_METHOD_NULLABLE_RETURN_TYPE_FIELD, true); + } + if (jvmSignature.getKotlinReturnType() != null) { + av.visit(JvmStdlibNames.JET_METHOD_RETURN_TYPE_FIELD, jvmSignature.getKotlinReturnType()); + } + if (jvmSignature.getKotlinTypeParameter() != null) { + av.visit(JvmStdlibNames.JET_METHOD_TYPE_PARAMETERS_FIELD, jvmSignature.getKotlinTypeParameter()); + } + av.visitEnd(); + } else { + throw new IllegalStateException(); } - if (jvmSignature.getKotlinReturnType() != null) { - av.visit(JvmStdlibNames.JET_METHOD_RETURN_TYPE_FIELD, jvmSignature.getKotlinReturnType()); - } - if (jvmSignature.getKotlinTypeParameter() != null) { - av.visit(JvmStdlibNames.JET_METHOD_TYPE_PARAMETERS_FIELD, jvmSignature.getKotlinTypeParameter()); - } - av.visitEnd(); } if(kind == OwnerKind.TRAIT_IMPL) { @@ -134,7 +145,7 @@ public class FunctionCodegen { av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_NULLABLE_FIELD, true); } if (jvmSignature.getKotlinParameterTypes() != null && jvmSignature.getKotlinParameterTypes().get(i) != null) { - av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_TYPE_FIELD, jvmSignature.getKotlinParameterTypes().get(i + start)); + av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_TYPE_FIELD, jvmSignature.getKotlinParameterTypes().get(i + start).getKotlinSignature()); } av.visitEnd(); } @@ -241,7 +252,7 @@ public class FunctionCodegen { public static void endVisit(MethodVisitor mv, String description, PsiElement method) { try { - mv.visitMaxs(0, 0); + mv.visitMaxs(-1, -1); } catch (Throwable t) { throw new CompilationException("wrong code generated" + (description != null ? " for " + description : "") + t.getClass().getName() + " " + t.getMessage(), t, method); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index 7c98cd97d68..fbbb9cf5279 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -115,7 +115,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { LinkedHashSet superInterfacesLinkedHashSet = new LinkedHashSet(); - BothSignatureWriter signatureVisitor = new BothSignatureWriter(BothSignatureWriter.Mode.CLASS); + // TODO: generics signature is not always needed + BothSignatureWriter signatureVisitor = new BothSignatureWriter(BothSignatureWriter.Mode.CLASS, true); { // type parameters @@ -237,50 +238,58 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { PropertyDescriptor bridge = (PropertyDescriptor) entry.getValue(); PropertyDescriptor original = (PropertyDescriptor) entry.getKey(); - Method method = typeMapper.mapGetterSignature(bridge, OwnerKind.IMPLEMENTATION).getAsmMethod(); - Method originalMethod = typeMapper.mapGetterSignature(original, OwnerKind.IMPLEMENTATION).getAsmMethod(); - MethodVisitor mv = v.newMethod(null, Opcodes.ACC_PUBLIC|Opcodes.ACC_BRIDGE|Opcodes.ACC_FINAL, method.getName(), method.getDescriptor(), null, null); - mv.visitAnnotation(JvmStdlibNames.JET_PROPERTY.getDescriptor(), true).visitEnd(); - InstructionAdapter iv = null; - if (v.generateCode()) { - mv.visitCode(); + { + Method method = typeMapper.mapGetterSignature(bridge, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod(); + JvmPropertyAccessorSignature originalSignature = typeMapper.mapGetterSignature(original, OwnerKind.IMPLEMENTATION); + Method originalMethod = originalSignature.getJvmMethodSignature().getAsmMethod(); + MethodVisitor mv = v.newMethod(null, Opcodes.ACC_PUBLIC | Opcodes.ACC_BRIDGE | Opcodes.ACC_FINAL, method.getName(), method.getDescriptor(), null, null); + PropertyCodegen.generateJetPropertyAnnotation(mv, originalSignature.getPropertyTypeKotlinSignature(), originalSignature.getJvmMethodSignature().getKotlinTypeParameter()); + mv.visitAnnotation(JvmStdlibNames.JET_PROPERTY.getDescriptor(), true).visitEnd(); + if (v.generateCode()) { + mv.visitCode(); - iv = new InstructionAdapter(mv); + InstructionAdapter iv = new InstructionAdapter(mv); - iv.load(0, JetTypeMapper.TYPE_OBJECT); - if(original.getVisibility() == Visibility.PRIVATE) - iv.getfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), original.getName(), originalMethod.getReturnType().getDescriptor()); - else - iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), originalMethod.getName(), originalMethod.getDescriptor()); + iv.load(0, JetTypeMapper.TYPE_OBJECT); + if(original.getVisibility() == Visibility.PRIVATE) + iv.getfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), original.getName(), originalMethod.getReturnType().getDescriptor()); + else + iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), originalMethod.getName(), originalMethod.getDescriptor()); - iv.areturn(method.getReturnType()); - FunctionCodegen.endVisit(iv, "accessor", null); + iv.areturn(method.getReturnType()); + FunctionCodegen.endVisit(iv, "accessor", null); + } } - method = typeMapper.mapSetterSignature(bridge, OwnerKind.IMPLEMENTATION).getAsmMethod(); - originalMethod = typeMapper.mapSetterSignature(original, OwnerKind.IMPLEMENTATION).getAsmMethod(); - mv = v.newMethod(null, Opcodes.ACC_PUBLIC|Opcodes.ACC_BRIDGE|Opcodes.ACC_FINAL, method.getName(), method.getDescriptor(), null, null); - mv.visitAnnotation(JvmStdlibNames.JET_PROPERTY.getDescriptor(), true).visitEnd(); - if (v.generateCode()) { - mv.visitCode(); + { - iv = new InstructionAdapter(mv); + Method method = typeMapper.mapSetterSignature(bridge, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod(); + JvmPropertyAccessorSignature originalSignature2 = typeMapper.mapSetterSignature(original, OwnerKind.IMPLEMENTATION); + Method originalMethod = originalSignature2.getJvmMethodSignature().getAsmMethod(); + MethodVisitor mv = v.newMethod(null, Opcodes.ACC_PUBLIC | Opcodes.ACC_BRIDGE | Opcodes.ACC_FINAL, method.getName(), method.getDescriptor(), null, null); + PropertyCodegen.generateJetPropertyAnnotation(mv, originalSignature2.getPropertyTypeKotlinSignature(), originalSignature2.getJvmMethodSignature().getKotlinTypeParameter()); + mv.visitAnnotation(JvmStdlibNames.JET_PROPERTY.getDescriptor(), true).visitEnd(); + if (v.generateCode()) { + mv.visitCode(); - iv.load(0, JetTypeMapper.TYPE_OBJECT); - Type[] argTypes = method.getArgumentTypes(); - for (int i = 0, reg = 1; i < argTypes.length; i++) { - Type argType = argTypes[i]; - iv.load(reg, argType); - //noinspection AssignmentToForLoopParameter - reg += argType.getSize(); + InstructionAdapter iv = new InstructionAdapter(mv); + + iv.load(0, JetTypeMapper.TYPE_OBJECT); + Type[] argTypes = method.getArgumentTypes(); + for (int i = 0, reg = 1; i < argTypes.length; i++) { + Type argType = argTypes[i]; + iv.load(reg, argType); + //noinspection AssignmentToForLoopParameter + reg += argType.getSize(); + } + if(original.getVisibility() == Visibility.PRIVATE) + iv.putfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), original.getName(), originalMethod.getArgumentTypes()[0].getDescriptor()); + else + iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), originalMethod.getName(), originalMethod.getDescriptor()); + + iv.areturn(method.getReturnType()); + FunctionCodegen.endVisit(iv, "accessor", null); } - if(original.getVisibility() == Visibility.PRIVATE) - iv.putfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), original.getName(), originalMethod.getArgumentTypes()[0].getDescriptor()); - else - iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), originalMethod.getName(), originalMethod.getDescriptor()); - - iv.areturn(method.getReturnType()); - FunctionCodegen.endVisit(iv, "accessor", null); } } else { @@ -343,17 +352,31 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { Method constructorMethod; CallableMethod callableMethod; if (constructorDescriptor == null) { - List parameterTypes = new ArrayList(); + + BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, false); + + signatureWriter.writeFormalTypeParametersStart(); + signatureWriter.writeFormalTypeParametersEnd(); + + signatureWriter.writeParametersStart(); + if (CodegenUtil.hasThis0(descriptor)) { - parameterTypes.add(typeMapper.mapType(CodegenUtil.getOuterClassDescriptor(descriptor).getDefaultType(), OwnerKind.IMPLEMENTATION)); + signatureWriter.writeParameterType(JvmMethodParameterKind.THIS0); + typeMapper.mapType(CodegenUtil.getOuterClassDescriptor(descriptor).getDefaultType(), OwnerKind.IMPLEMENTATION, signatureWriter, false); + signatureWriter.writeParameterTypeEnd(); } if (CodegenUtil.requireTypeInfoConstructorArg(descriptor.getDefaultType())) { - parameterTypes.add(JetTypeMapper.TYPE_TYPEINFO); + signatureWriter.writeTypeInfoParameter(); } - constructorMethod = new Method("", Type.VOID_TYPE, parameterTypes.toArray(new Type[parameterTypes.size()])); - callableMethod = new CallableMethod("", new JvmMethodSignature(constructorMethod, null, null, null, null) /* TODO */, Opcodes.INVOKESPECIAL, Collections.emptyList()); + signatureWriter.writeParametersEnd(); + + signatureWriter.writeVoidReturn(); + + JvmMethodSignature jvmMethodSignature = signatureWriter.makeJvmMethodSignature(""); + constructorMethod = jvmMethodSignature.getAsmMethod(); + callableMethod = new CallableMethod("", jvmMethodSignature, Opcodes.INVOKESPECIAL); } else { callableMethod = typeMapper.mapToCallableMethod(constructorDescriptor, kind); @@ -445,8 +468,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { HashSet overridden = new HashSet(); for (JetDeclaration declaration : myClass.getDeclarations()) { - if (declaration instanceof JetFunction) { - FunctionDescriptor functionDescriptor = bindingContext.get(BindingContext.FUNCTION, declaration); + if (declaration instanceof JetNamedFunction) { + NamedFunctionDescriptor functionDescriptor = bindingContext.get(BindingContext.FUNCTION, declaration); assert functionDescriptor != null; overridden.addAll(functionDescriptor.getOverriddenDescriptors()); } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java b/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java index da511707882..0837a30cc0b 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java @@ -14,6 +14,7 @@ import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver; import org.jetbrains.jet.lang.resolve.java.JavaNamespaceDescriptor; import org.jetbrains.jet.lang.resolve.java.JvmAbi; +import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; import org.jetbrains.jet.lang.types.*; import org.jetbrains.jet.lexer.JetTokens; @@ -35,27 +36,11 @@ public class JetTypeMapper { public static final Type TYPE_TYPEINFOPROJECTION = Type.getType(TypeInfoProjection.class); public static final Type TYPE_JET_OBJECT = Type.getType(JetObject.class); public static final Type TYPE_NOTHING = Type.getObjectType("jet/Nothing"); - public static final Type JL_INTEGER_TYPE = Type.getObjectType("java/lang/Integer"); - public static final Type JL_LONG_TYPE = Type.getObjectType("java/lang/Long"); - public static final Type JL_SHORT_TYPE = Type.getObjectType("java/lang/Short"); - public static final Type JL_BYTE_TYPE = Type.getObjectType("java/lang/Byte"); - public static final Type JL_CHAR_TYPE = Type.getObjectType("java/lang/Character"); - public static final Type JL_FLOAT_TYPE = Type.getObjectType("java/lang/Float"); - public static final Type JL_DOUBLE_TYPE = Type.getObjectType("java/lang/Double"); - public static final Type JL_BOOLEAN_TYPE = Type.getObjectType("java/lang/Boolean"); public static final Type JL_NUMBER_TYPE = Type.getObjectType("java/lang/Number"); public static final Type JL_STRING_BUILDER = Type.getObjectType("java/lang/StringBuilder"); public static final Type JL_STRING_TYPE = Type.getObjectType("java/lang/String"); private static final Type JL_COMPARABLE_TYPE = Type.getObjectType("java/lang/Comparable"); - public static final Type ARRAY_INT_TYPE = Type.getType(int[].class); - public static final Type ARRAY_LONG_TYPE = Type.getType(long[].class); - public static final Type ARRAY_SHORT_TYPE = Type.getType(short[].class); - public static final Type ARRAY_BYTE_TYPE = Type.getType(byte[].class); - public static final Type ARRAY_CHAR_TYPE = Type.getType(char[].class); - public static final Type ARRAY_FLOAT_TYPE = Type.getType(float[].class); - public static final Type ARRAY_DOUBLE_TYPE = Type.getType(double[].class); - public static final Type ARRAY_BOOL_TYPE = Type.getType(boolean[].class); public static final Type ARRAY_GENERIC_TYPE = Type.getType(Object[].class); private final JetStandardLibrary standardLibrary; @@ -77,14 +62,6 @@ public class JetTypeMapper { public static final Type TYPE_SHARED_CHAR = Type.getObjectType("jet/runtime/SharedVar$Char"); public static final Type TYPE_SHARED_LONG = Type.getObjectType("jet/runtime/SharedVar$Long"); public static final Type TYPE_SHARED_BOOLEAN = Type.getObjectType("jet/runtime/SharedVar$Boolean"); - public static final Type TYPE_BOOLEAN_ITERATOR = Type.getObjectType("jet/BooleanIterator"); - public static final Type TYPE_CHAR_ITERATOR = Type.getObjectType("jet/CharIterator"); - public static final Type TYPE_BYTE_ITERATOR = Type.getObjectType("jet/ByteIterator"); - public static final Type TYPE_SHORT_ITERATOR = Type.getObjectType("jet/ShortIterator"); - public static final Type TYPE_INT_ITERATOR = Type.getObjectType("jet/IntIterator"); - public static final Type TYPE_LONG_ITERATOR = Type.getObjectType("jet/LongIterator"); - public static final Type TYPE_FLOAT_ITERATOR = Type.getObjectType("jet/FloatIterator"); - public static final Type TYPE_DOUBLE_ITERATOR = Type.getObjectType("jet/DoubleIterator"); public static final Type TYPE_FUNCTION0 = Type.getObjectType("jet/Function0"); public static final Type TYPE_FUNCTION1 = Type.getObjectType("jet/Function1"); @@ -107,28 +84,6 @@ public class JetTypeMapper { return type.getSort() != Type.OBJECT && type.getSort() != Type.ARRAY; } - public static Type getBoxedType(final Type type) { - switch (type.getSort()) { - case Type.BYTE: - return JL_BYTE_TYPE; - case Type.BOOLEAN: - return JL_BOOLEAN_TYPE; - case Type.SHORT: - return JL_SHORT_TYPE; - case Type.CHAR: - return JL_CHAR_TYPE; - case Type.INT: - return JL_INTEGER_TYPE; - case Type.FLOAT: - return JL_FLOAT_TYPE; - case Type.LONG: - return JL_LONG_TYPE; - case Type.DOUBLE: - return JL_DOUBLE_TYPE; - } - return type; - } - public static Type correctElementType(Type type) { String internalName = type.getInternalName(); assert internalName.charAt(0) == '['; @@ -351,12 +306,13 @@ public class JetTypeMapper { } if (descriptor instanceof TypeParameterDescriptor) { + + Type type = mapType(((TypeParameterDescriptor) descriptor).getUpperBoundsAsType(), kind); if (signatureVisitor != null) { TypeParameterDescriptor typeParameterDescriptor = (TypeParameterDescriptor) jetType.getConstructor().getDeclarationDescriptor(); - signatureVisitor.writeTypeVariable(typeParameterDescriptor.getName(), jetType.isNullable()); + signatureVisitor.writeTypeVariable(typeParameterDescriptor.getName(), jetType.isNullable(), type); } - - return mapType(((TypeParameterDescriptor) descriptor).getUpperBoundsAsType(), kind); + return type; } throw new UnsupportedOperationException("Unknown type " + jetType); @@ -378,56 +334,21 @@ public class JetTypeMapper { } public static Type unboxType(final Type type) { - if (type == JL_INTEGER_TYPE) { - return Type.INT_TYPE; + JvmPrimitiveType jvmPrimitiveType = JvmPrimitiveType.getByWrapperAsmType(type); + if (jvmPrimitiveType != null) { + return jvmPrimitiveType.getAsmType(); + } else { + throw new UnsupportedOperationException("Unboxing: " + type); } - else if (type == JL_BOOLEAN_TYPE) { - return Type.BOOLEAN_TYPE; - } - else if (type == JL_CHAR_TYPE) { - return Type.CHAR_TYPE; - } - else if (type == JL_SHORT_TYPE) { - return Type.SHORT_TYPE; - } - else if (type == JL_LONG_TYPE) { - return Type.LONG_TYPE; - } - else if (type == JL_BYTE_TYPE) { - return Type.BYTE_TYPE; - } - else if (type == JL_FLOAT_TYPE) { - return Type.FLOAT_TYPE; - } - else if (type == JL_DOUBLE_TYPE) { - return Type.DOUBLE_TYPE; - } - throw new UnsupportedOperationException("Unboxing: " + type); } public static Type boxType(Type asmType) { - switch (asmType.getSort()) { - case Type.VOID: - return Type.VOID_TYPE; - case Type.BYTE: - return JL_BYTE_TYPE; - case Type.BOOLEAN: - return JL_BOOLEAN_TYPE; - case Type.SHORT: - return JL_SHORT_TYPE; - case Type.CHAR: - return JL_CHAR_TYPE; - case Type.INT: - return JL_INTEGER_TYPE; - case Type.FLOAT: - return JL_FLOAT_TYPE; - case Type.LONG: - return JL_LONG_TYPE; - case Type.DOUBLE: - return JL_DOUBLE_TYPE; + JvmPrimitiveType jvmPrimitiveType = JvmPrimitiveType.getByAsmType(asmType); + if (jvmPrimitiveType != null) { + return jvmPrimitiveType.getWrapper().getAsmType(); + } else { + return asmType; } - - return asmType; } public CallableMethod mapToCallableMethod(FunctionDescriptor functionDescriptor, boolean superCall, OwnerKind kind) { @@ -435,8 +356,7 @@ public class JetTypeMapper { return null; final DeclarationDescriptor functionParent = functionDescriptor.getContainingDeclaration(); - final List valueParameterTypes = new ArrayList(); - JvmMethodSignature descriptor = mapSignature(functionDescriptor.getOriginal(), true, valueParameterTypes, kind); + JvmMethodSignature descriptor = mapSignature(functionDescriptor.getOriginal(), true, kind); String owner; int invokeOpcode; ClassDescriptor thisClass; @@ -463,7 +383,7 @@ public class JetTypeMapper { ? (superCall ? Opcodes.INVOKESTATIC : Opcodes.INVOKEINTERFACE) : (superCall ? Opcodes.INVOKESPECIAL : Opcodes.INVOKEVIRTUAL); if(isInterface && superCall) { - descriptor = mapSignature(functionDescriptor.getOriginal(), false, valueParameterTypes, OwnerKind.TRAIT_IMPL); + descriptor = mapSignature(functionDescriptor.getOriginal(), false, OwnerKind.TRAIT_IMPL); } thisClass = (ClassDescriptor) functionParent; } @@ -471,7 +391,7 @@ public class JetTypeMapper { throw new UnsupportedOperationException("unknown function parent"); } - final CallableMethod result = new CallableMethod(owner, descriptor, invokeOpcode, valueParameterTypes); + final CallableMethod result = new CallableMethod(owner, descriptor, invokeOpcode); result.setNeedsThis(thisClass); if(functionDescriptor.getReceiverParameter().exists()) { result.setNeedsReceiver(functionDescriptor); @@ -480,107 +400,63 @@ public class JetTypeMapper { return result; } - private JvmMethodSignature mapSignature(FunctionDescriptor f, boolean needGenericSignature, List valueParameterTypes, OwnerKind kind) { + private JvmMethodSignature mapSignature(FunctionDescriptor f, boolean needGenericSignature, OwnerKind kind) { - for (ValueParameterDescriptor valueParameterDescriptor : f.getValueParameters()) { - if (valueParameterDescriptor.hasDefaultValue()) { - // TODO - needGenericSignature = false; - } - } - if (kind == OwnerKind.TRAIT_IMPL) { needGenericSignature = false; } - BothSignatureWriter signatureVisitor = null; - if (needGenericSignature) { - signatureVisitor = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD); - } + BothSignatureWriter signatureVisitor = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, needGenericSignature); writeFormalTypeParameters(f.getTypeParameters(), signatureVisitor); final ReceiverDescriptor receiverTypeRef = f.getReceiverParameter(); final JetType receiverType = !receiverTypeRef.exists() ? null : receiverTypeRef.getType(); final List parameters = f.getValueParameters(); - List parameterTypes = new ArrayList(); + + signatureVisitor.writeParametersStart(); + if(kind == OwnerKind.TRAIT_IMPL) { ClassDescriptor containingDeclaration = (ClassDescriptor) f.getContainingDeclaration(); JetType jetType = TraitImplBodyCodegen.getSuperClass(containingDeclaration, bindingContext); - Type type = mapType(jetType, signatureVisitor); + Type type = mapType(jetType); if(type.getInternalName().equals("java/lang/Object")) { jetType = containingDeclaration.getDefaultType(); - type = mapType(jetType, signatureVisitor); + type = mapType(jetType); } - valueParameterTypes.add(type); - parameterTypes.add(type); + + signatureVisitor.writeParameterType(JvmMethodParameterKind.THIS); + signatureVisitor.writeAsmType(type, jetType.isNullable()); + signatureVisitor.writeParameterTypeEnd(); } + if (receiverType != null) { - if (signatureVisitor != null) { - signatureVisitor.writeParameterType(); - } - parameterTypes.add(mapType(receiverType, signatureVisitor)); - if (signatureVisitor != null) { - signatureVisitor.writeParameterTypeEnd(); - } - } - if (signatureVisitor != null) { - signatureVisitor.writeParametersStart(); + signatureVisitor.writeParameterType(JvmMethodParameterKind.RECEIVER); + mapType(receiverType, signatureVisitor); + signatureVisitor.writeParameterTypeEnd(); } for (TypeParameterDescriptor parameterDescriptor : f.getTypeParameters()) { if(parameterDescriptor.isReified()) { - parameterTypes.add(TYPE_TYPEINFO); - if (signatureVisitor != null) { - signatureVisitor.writeParameterType(); - visitAsmType(signatureVisitor, TYPE_TYPEINFO, false); - signatureVisitor.writeParameterTypeEnd(); - } + signatureVisitor.writeTypeInfoParameter(); } } for (ValueParameterDescriptor parameter : parameters) { - if (signatureVisitor != null) { - signatureVisitor.writeParameterType(); - } - Type type = mapType(parameter.getOutType(), signatureVisitor); - if (signatureVisitor != null) { - signatureVisitor.writeParameterTypeEnd(); - } - valueParameterTypes.add(type); - parameterTypes.add(type); + signatureVisitor.writeParameterType(JvmMethodParameterKind.VALUE); + mapType(parameter.getOutType(), signatureVisitor); + signatureVisitor.writeParameterTypeEnd(); } - - if (signatureVisitor != null) { - signatureVisitor.writeParametersEnd(); - } - - Type returnType; + + signatureVisitor.writeParametersEnd(); + if (f instanceof ConstructorDescriptor) { - returnType = Type.VOID_TYPE; - if (signatureVisitor != null) { - signatureVisitor.writeReturnType(); - visitAsmType(signatureVisitor, Type.VOID_TYPE, false); - signatureVisitor.writeReturnTypeEnd(); - } + signatureVisitor.writeVoidReturn(); } else { - if (signatureVisitor != null) { - signatureVisitor.writeReturnType(); - returnType = mapReturnType(f.getReturnType(), signatureVisitor); - signatureVisitor.writeReturnTypeEnd(); - } - else { - returnType = mapReturnType(f.getReturnType(), null); - } - } - Method method = new Method(f.getName(), returnType, parameterTypes.toArray(new Type[parameterTypes.size()])); - if (signatureVisitor == null) { - return new JvmMethodSignature(method, null, null, null, null); - } else { - return new JvmMethodSignature(method, signatureVisitor.makeJavaString(), - signatureVisitor.makeKotlinMethodTypeParameters(), - signatureVisitor.makeKotlinParameterTypes(), - signatureVisitor.makeKotlinReturnTypeSignature()); + signatureVisitor.writeReturnType(); + mapReturnType(f.getReturnType(), signatureVisitor); + signatureVisitor.writeReturnTypeEnd(); } + return signatureVisitor.makeJvmMethodSignature(f.getName()); } @@ -589,7 +465,7 @@ public class JetTypeMapper { return; } - signatureVisitor.writerFormalTypeParametersStart(); + signatureVisitor.writeFormalTypeParametersStart(); for (TypeParameterDescriptor typeParameterDescriptor : typeParameters) { writeFormalTypeParameter(typeParameterDescriptor, signatureVisitor); } @@ -640,103 +516,162 @@ public class JetTypeMapper { public JvmMethodSignature mapSignature(String name, FunctionDescriptor f) { final ReceiverDescriptor receiver = f.getReceiverParameter(); + + BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, false); + + writeFormalTypeParameters(f.getTypeParameters(), signatureWriter); + + signatureWriter.writeParametersStart(); + final List parameters = f.getValueParameters(); - List parameterTypes = new ArrayList(); if (receiver.exists()) { - parameterTypes.add(mapType(receiver.getType())); + signatureWriter.writeParameterType(JvmMethodParameterKind.RECEIVER); + mapType(receiver.getType(), signatureWriter); + signatureWriter.writeParameterTypeEnd(); } for (ValueParameterDescriptor parameter : parameters) { - parameterTypes.add(mapType(parameter.getOutType())); + signatureWriter.writeParameterType(JvmMethodParameterKind.VALUE); + mapType(parameter.getOutType(), signatureWriter); + signatureWriter.writeParameterTypeEnd(); } - Type returnType = mapReturnType(f.getReturnType()); - // TODO: proper generic signature - return new JvmMethodSignature(new Method(name, returnType, parameterTypes.toArray(new Type[parameterTypes.size()])), null, null, null, null); + + signatureWriter.writeParametersEnd(); + + signatureWriter.writeReturnType(); + mapReturnType(f.getReturnType(), signatureWriter); + signatureWriter.writeReturnTypeEnd(); + + return signatureWriter.makeJvmMethodSignature(name); } - - public JvmMethodSignature mapGetterSignature(PropertyDescriptor descriptor, OwnerKind kind) { - Type returnType = mapType(descriptor.getOutType()); + + public JvmPropertyAccessorSignature mapGetterSignature(PropertyDescriptor descriptor, OwnerKind kind) { String name = PropertyCodegen.getterName(descriptor.getName()); - ArrayList params = new ArrayList(); + + // TODO: do not generate generics if not needed + BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, true); + + writeFormalTypeParameters(descriptor.getTypeParameters(), signatureWriter); + + signatureWriter.writeParametersStart(); + if(kind == OwnerKind.TRAIT_IMPL) { ClassDescriptor containingDeclaration = (ClassDescriptor) descriptor.getContainingDeclaration(); assert containingDeclaration != null; - params.add(mapType(containingDeclaration.getDefaultType())); + signatureWriter.writeParameterType(JvmMethodParameterKind.THIS); + mapType(containingDeclaration.getDefaultType(), signatureWriter); + signatureWriter.writeParameterTypeEnd(); } if(descriptor.getReceiverParameter().exists()) { - params.add(mapType(descriptor.getReceiverParameter().getType())); + signatureWriter.writeParameterType(JvmMethodParameterKind.RECEIVER); + mapType(descriptor.getReceiverParameter().getType(), signatureWriter); + signatureWriter.writeParameterTypeEnd(); } for (TypeParameterDescriptor typeParameterDescriptor : descriptor.getTypeParameters()) { if(typeParameterDescriptor.isReified()) { - params.add(TYPE_TYPEINFO); + signatureWriter.writeTypeInfoParameter(); } } + + signatureWriter.writeParametersEnd(); - // TODO: proper generic signature - return new JvmMethodSignature(new Method(name, returnType, params.toArray(new Type[params.size()])), null, null, null, null); + signatureWriter.writeReturnType(); + mapType(descriptor.getOutType(), signatureWriter); + signatureWriter.writeReturnTypeEnd(); + + JvmMethodSignature jvmMethodSignature = signatureWriter.makeJvmMethodSignature(name); + + return new JvmPropertyAccessorSignature(jvmMethodSignature, jvmMethodSignature.getKotlinReturnType()); } @Nullable - public JvmMethodSignature mapSetterSignature(PropertyDescriptor descriptor, OwnerKind kind) { + public JvmPropertyAccessorSignature mapSetterSignature(PropertyDescriptor descriptor, OwnerKind kind) { if (!descriptor.isVar()) { return null; } + // TODO: generics signature is not always needed + BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, true); + + writeFormalTypeParameters(descriptor.getTypeParameters(), signatureWriter); + JetType outType = descriptor.getOutType(); + signatureWriter.writeParametersStart(); + String name = PropertyCodegen.setterName(descriptor.getName()); - ArrayList params = new ArrayList(); if(kind == OwnerKind.TRAIT_IMPL) { ClassDescriptor containingDeclaration = (ClassDescriptor) descriptor.getContainingDeclaration(); assert containingDeclaration != null; - params.add(mapType(containingDeclaration.getDefaultType())); + signatureWriter.writeParameterType(JvmMethodParameterKind.THIS); + mapType(containingDeclaration.getDefaultType(), signatureWriter); + signatureWriter.writeParameterTypeEnd(); } if(descriptor.getReceiverParameter().exists()) { - params.add(mapType(descriptor.getReceiverParameter().getType())); + signatureWriter.writeParameterType(JvmMethodParameterKind.RECEIVER); + mapType(descriptor.getReceiverParameter().getType(), signatureWriter); + signatureWriter.writeParameterTypeEnd(); } for (TypeParameterDescriptor typeParameterDescriptor : descriptor.getTypeParameters()) { if(typeParameterDescriptor.isReified()) { - params.add(TYPE_TYPEINFO); + signatureWriter.writeTypeInfoParameter(); } } - params.add(mapType(outType)); + signatureWriter.writeParameterType(JvmMethodParameterKind.VALUE); + mapType(outType, signatureWriter); + signatureWriter.writeParameterTypeEnd(); + + signatureWriter.writeParametersEnd(); + + signatureWriter.writeVoidReturn(); - // TODO: proper generic signature - return new JvmMethodSignature(new Method(name, Type.VOID_TYPE, params.toArray(new Type[params.size()])), null, null, null, null); + JvmMethodSignature jvmMethodSignature = signatureWriter.makeJvmMethodSignature(name); + return new JvmPropertyAccessorSignature(jvmMethodSignature, jvmMethodSignature.getKotlinParameterType(jvmMethodSignature.getParameterCount() - 1)); } - private JvmMethodSignature mapConstructorSignature(ConstructorDescriptor descriptor, List valueParameterTypes) { + private JvmMethodSignature mapConstructorSignature(ConstructorDescriptor descriptor) { + + BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, true); + List parameters = descriptor.getOriginal().getValueParameters(); - List parameterTypes = new ArrayList(); ClassDescriptor classDescriptor = descriptor.getContainingDeclaration(); + + writeFormalTypeParameters(descriptor.getTypeParameters(), signatureWriter); + + signatureWriter.writeParametersStart(); + if (CodegenUtil.hasThis0(classDescriptor)) { - parameterTypes.add(mapType(CodegenUtil.getOuterClassDescriptor(classDescriptor).getDefaultType(), OwnerKind.IMPLEMENTATION)); + signatureWriter.writeParameterType(JvmMethodParameterKind.THIS0); + mapType(CodegenUtil.getOuterClassDescriptor(classDescriptor).getDefaultType(), OwnerKind.IMPLEMENTATION, signatureWriter); + signatureWriter.writeParameterTypeEnd(); } if (CodegenUtil.requireTypeInfoConstructorArg(classDescriptor.getDefaultType())) { - parameterTypes.add(TYPE_TYPEINFO); + signatureWriter.writeTypeInfoParameter(); } for (ValueParameterDescriptor parameter : parameters) { - final Type type = mapType(parameter.getOutType()); - parameterTypes.add(type); - valueParameterTypes.add(type); + signatureWriter.writeParameterType(JvmMethodParameterKind.VALUE); + mapType(parameter.getOutType(), signatureWriter); + signatureWriter.writeParameterTypeEnd(); } + + signatureWriter.writeParametersEnd(); + + signatureWriter.writeVoidReturn(); - Method method = new Method("", Type.VOID_TYPE, parameterTypes.toArray(new Type[parameterTypes.size()])); - return new JvmMethodSignature(method, null, null, null, null); // TODO: generics signature + return signatureWriter.makeJvmMethodSignature(""); } public CallableMethod mapToCallableMethod(ConstructorDescriptor descriptor, OwnerKind kind) { - List valueParameterTypes = new ArrayList(); - final JvmMethodSignature method = mapConstructorSignature(descriptor, valueParameterTypes); + final JvmMethodSignature method = mapConstructorSignature(descriptor); String owner = mapType(descriptor.getContainingDeclaration().getDefaultType(), kind).getInternalName(); - return new CallableMethod(owner, method, INVOKESPECIAL, valueParameterTypes); + return new CallableMethod(owner, method, INVOKESPECIAL); } static int getAccessModifiers(JetDeclaration p, int defaultFlags) { @@ -802,85 +737,39 @@ public class JetTypeMapper { private void initKnownTypeNames() { knowTypeNames.put(JetStandardClasses.getAnyType(), "ANY_TYPE_INFO"); knowTypeNames.put(JetStandardClasses.getNullableAnyType(), "NULLABLE_ANY_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getIntType(), "INT_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getNullableIntType(), "NULLABLE_INT_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getLongType(), "LONG_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getNullableLongType(), "NULLABLE_LONG_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getShortType(),"SHORT_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getNullableShortType(),"NULLABLE_SHORT_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getByteType(),"BYTE_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getNullableByteType(),"NULLABLE_BYTE_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getCharType(),"CHAR_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getNullableCharType(),"NULLABLE_CHAR_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getFloatType(),"FLOAT_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getNullableFloatType(),"NULLABLE_FLOAT_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getDoubleType(),"DOUBLE_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getNullableDoubleType(),"NULLABLE_DOUBLE_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getBooleanType(),"BOOLEAN_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getNullableBooleanType(),"NULLABLE_BOOLEAN_TYPE_INFO"); + + for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) { + PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType(); + knowTypeNames.put(standardLibrary.getPrimitiveJetType(primitiveType), jvmPrimitiveType.name() + "_TYPE_INFO"); + knowTypeNames.put(standardLibrary.getNullablePrimitiveJetType(primitiveType), "NULLABLE_" + jvmPrimitiveType.name() + "_TYPE_INFO"); + knowTypeNames.put(standardLibrary.getPrimitiveArrayJetType(primitiveType), jvmPrimitiveType.name() + "_ARRAY_TYPE_INFO"); + knowTypeNames.put(standardLibrary.getNullablePrimitiveArrayJetType(primitiveType), jvmPrimitiveType.name() + "_ARRAY_TYPE_INFO"); + } + knowTypeNames.put(standardLibrary.getStringType(),"STRING_TYPE_INFO"); knowTypeNames.put(standardLibrary.getNullableStringType(),"NULLABLE_STRING_TYPE_INFO"); knowTypeNames.put(standardLibrary.getTuple0Type(),"TUPLE0_TYPE_INFO"); knowTypeNames.put(standardLibrary.getNullableTuple0Type(),"NULLABLE_TUPLE0_TYPE_INFO"); - - knowTypeNames.put(standardLibrary.getIntArrayType(), "INT_ARRAY_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getLongArrayType(), "LONG_ARRAY_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getShortArrayType(),"SHORT_ARRAY_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getByteArrayType(),"BYTE_ARRAY_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getCharArrayType(),"CHAR_ARRAY_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getFloatArrayType(),"FLOAT_ARRAY_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getDoubleArrayType(),"DOUBLE_ARRAY_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getBooleanArrayType(),"BOOLEAN_ARRAY_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getNullableIntArrayType(), "INT_ARRAY_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getNullableLongArrayType(), "LONG_ARRAY_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getNullableShortArrayType(),"SHORT_ARRAY_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getNullableByteArrayType(),"BYTE_ARRAY_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getNullableCharArrayType(),"CHAR_ARRAY_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getNullableFloatArrayType(),"FLOAT_ARRAY_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getNullableDoubleArrayType(),"DOUBLE_ARRAY_TYPE_INFO"); - knowTypeNames.put(standardLibrary.getNullableBooleanArrayType(),"BOOLEAN_ARRAY_TYPE_INFO"); } private void initKnownTypes() { knowTypes.put(JetStandardClasses.getNothingType(), TYPE_NOTHING); knowTypes.put(JetStandardClasses.getNullableNothingType(), TYPE_NOTHING); - - knowTypes.put(standardLibrary.getIntType(), Type.INT_TYPE); - knowTypes.put(standardLibrary.getNullableIntType(), JL_INTEGER_TYPE); - knowTypes.put(standardLibrary.getLongType(), Type.LONG_TYPE); - knowTypes.put(standardLibrary.getNullableLongType(), JL_LONG_TYPE); - knowTypes.put(standardLibrary.getShortType(),Type.SHORT_TYPE); - knowTypes.put(standardLibrary.getNullableShortType(),JL_SHORT_TYPE); - knowTypes.put(standardLibrary.getByteType(),Type.BYTE_TYPE); - knowTypes.put(standardLibrary.getNullableByteType(),JL_BYTE_TYPE); - knowTypes.put(standardLibrary.getCharType(),Type.CHAR_TYPE); - knowTypes.put(standardLibrary.getNullableCharType(),JL_CHAR_TYPE); - knowTypes.put(standardLibrary.getFloatType(),Type.FLOAT_TYPE); - knowTypes.put(standardLibrary.getNullableFloatType(),JL_FLOAT_TYPE); - knowTypes.put(standardLibrary.getDoubleType(),Type.DOUBLE_TYPE); - knowTypes.put(standardLibrary.getNullableDoubleType(),JL_DOUBLE_TYPE); - knowTypes.put(standardLibrary.getBooleanType(),Type.BOOLEAN_TYPE); - knowTypes.put(standardLibrary.getNullableBooleanType(),JL_BOOLEAN_TYPE); + + for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) { + PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType(); + knowTypes.put(standardLibrary.getPrimitiveJetType(primitiveType), jvmPrimitiveType.getAsmType()); + knowTypes.put(standardLibrary.getNullablePrimitiveJetType(primitiveType), jvmPrimitiveType.getWrapper().getAsmType()); + } knowTypes.put(standardLibrary.getStringType(),JL_STRING_TYPE); knowTypes.put(standardLibrary.getNullableStringType(),JL_STRING_TYPE); - knowTypes.put(standardLibrary.getIntArrayType(), ARRAY_INT_TYPE); - knowTypes.put(standardLibrary.getLongArrayType(), ARRAY_LONG_TYPE); - knowTypes.put(standardLibrary.getShortArrayType(),ARRAY_SHORT_TYPE); - knowTypes.put(standardLibrary.getByteArrayType(),ARRAY_BYTE_TYPE); - knowTypes.put(standardLibrary.getCharArrayType(),ARRAY_CHAR_TYPE); - knowTypes.put(standardLibrary.getFloatArrayType(),ARRAY_FLOAT_TYPE); - knowTypes.put(standardLibrary.getDoubleArrayType(),ARRAY_DOUBLE_TYPE); - knowTypes.put(standardLibrary.getBooleanArrayType(),ARRAY_BOOL_TYPE); - knowTypes.put(standardLibrary.getNullableIntArrayType(), ARRAY_INT_TYPE); - knowTypes.put(standardLibrary.getNullableLongArrayType(), ARRAY_LONG_TYPE); - knowTypes.put(standardLibrary.getNullableShortArrayType(),ARRAY_SHORT_TYPE); - knowTypes.put(standardLibrary.getNullableByteArrayType(),ARRAY_BYTE_TYPE); - knowTypes.put(standardLibrary.getNullableCharArrayType(),ARRAY_CHAR_TYPE); - knowTypes.put(standardLibrary.getNullableFloatArrayType(),ARRAY_FLOAT_TYPE); - knowTypes.put(standardLibrary.getNullableDoubleArrayType(),ARRAY_DOUBLE_TYPE); - knowTypes.put(standardLibrary.getNullableBooleanArrayType(),ARRAY_BOOL_TYPE); + for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) { + PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType(); + knowTypes.put(standardLibrary.getPrimitiveArrayJetType(primitiveType), jvmPrimitiveType.getAsmArrayType()); + knowTypes.put(standardLibrary.getNullablePrimitiveArrayJetType(primitiveType), jvmPrimitiveType.getAsmArrayType()); + } } public String isKnownTypeInfo(JetType jetType) { diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/JvmMethodParameterKind.java b/compiler/backend/src/org/jetbrains/jet/codegen/JvmMethodParameterKind.java new file mode 100644 index 00000000000..66cc3ef7376 --- /dev/null +++ b/compiler/backend/src/org/jetbrains/jet/codegen/JvmMethodParameterKind.java @@ -0,0 +1,15 @@ +package org.jetbrains.jet.codegen; + +import org.jetbrains.jet.lang.descriptors.ClassDescriptor; + +/** + * @author Stepan Koltsov + */ +public enum JvmMethodParameterKind { + VALUE, + THIS, + /** @see CodegenUtil#hasThis0(ClassDescriptor) */ + THIS0, + RECEIVER, + TYPE_INFO, +} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/JvmMethodParameterSignature.java b/compiler/backend/src/org/jetbrains/jet/codegen/JvmMethodParameterSignature.java new file mode 100644 index 00000000000..dc5991704d4 --- /dev/null +++ b/compiler/backend/src/org/jetbrains/jet/codegen/JvmMethodParameterSignature.java @@ -0,0 +1,38 @@ +package org.jetbrains.jet.codegen; + +import org.jetbrains.annotations.NotNull; +import org.objectweb.asm.Type; + +/** + * @author Stepan Koltsov + */ +public class JvmMethodParameterSignature { + @NotNull + private final Type asmType; + @NotNull + private final String kotlinSignature; + @NotNull + private final JvmMethodParameterKind kind; + + public JvmMethodParameterSignature( + @NotNull Type asmType, @NotNull String kotlinSignature, @NotNull JvmMethodParameterKind kind) { + this.asmType = asmType; + this.kotlinSignature = kotlinSignature; + this.kind = kind; + } + + @NotNull + public Type getAsmType() { + return asmType; + } + + @NotNull + public String getKotlinSignature() { + return kotlinSignature; + } + + @NotNull + public JvmMethodParameterKind getKind() { + return kind; + } +} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/JvmMethodSignature.java b/compiler/backend/src/org/jetbrains/jet/codegen/JvmMethodSignature.java index 2deac1ab39b..a3487e8a50d 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/JvmMethodSignature.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/JvmMethodSignature.java @@ -2,48 +2,112 @@ package org.jetbrains.jet.codegen; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.objectweb.asm.Type; import org.objectweb.asm.commons.Method; +import java.util.ArrayList; import java.util.List; /** * @author Stepan Koltsov */ public class JvmMethodSignature { - + + @NotNull private final Method asmMethod; /** Null when we don't care about type parameters */ private final String genericsSignature; private final String kotlinTypeParameter; - private final List kotlinParameterTypes; + @NotNull + private final List kotlinParameterTypes; + @NotNull private final String kotlinReturnType; + /** + * Generics info is generated. However it can be trivial (e.g. fields are null). + */ + private final boolean genericsAvailable; + public JvmMethodSignature(@NotNull Method asmMethod, @Nullable String genericsSignature, - @Nullable String kotlinTypeParameters, @Nullable List kotlinParameterTypes, @Nullable String kotlinReturnType) { + @Nullable String kotlinTypeParameters, @NotNull List kotlinParameterTypes, @NotNull String kotlinReturnType) { this.asmMethod = asmMethod; this.genericsSignature = genericsSignature; this.kotlinTypeParameter = kotlinTypeParameters; this.kotlinParameterTypes = kotlinParameterTypes; this.kotlinReturnType = kotlinReturnType; + this.genericsAvailable = true; + } + + public JvmMethodSignature(@NotNull Method asmMethod, @NotNull List kotlinParameterTypes) { + this.asmMethod = asmMethod; + this.genericsSignature = null; + this.kotlinTypeParameter = null; + this.kotlinParameterTypes = kotlinParameterTypes; + this.kotlinReturnType = ""; + this.genericsAvailable = false; } + private void checkGenericsAvailable() { + if (!genericsAvailable) { + // TODO: uncomment following line and fix all broken tests + //throw new IllegalStateException("incorrect call sequence"); + } + } + + @NotNull public Method getAsmMethod() { return asmMethod; } public String getGenericsSignature() { + checkGenericsAvailable(); return genericsSignature; } public String getKotlinTypeParameter() { + checkGenericsAvailable(); return kotlinTypeParameter; } - public List getKotlinParameterTypes() { + @Nullable + public List getKotlinParameterTypes() { + checkGenericsAvailable(); return kotlinParameterTypes; } + + public int getParameterCount() { + // TODO: slow + return asmMethod.getArgumentTypes().length; + } + + @NotNull + public String getKotlinParameterType(int i) { + checkGenericsAvailable(); + if (kotlinParameterTypes == null) { + return ""; + } else { + return kotlinParameterTypes.get(i).getKotlinSignature(); + } + } + @NotNull public String getKotlinReturnType() { + checkGenericsAvailable(); return kotlinReturnType; } + + public List getValueParameterTypes() { + List r = new ArrayList(kotlinParameterTypes.size()); + for (JvmMethodParameterSignature p : kotlinParameterTypes) { + if (p.getKind() == JvmMethodParameterKind.VALUE) { + r.add(p.getAsmType()); + } + } + return r; + } + + @NotNull + public String getName() { + return asmMethod.getName(); + } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/JvmPropertyAccessorSignature.java b/compiler/backend/src/org/jetbrains/jet/codegen/JvmPropertyAccessorSignature.java new file mode 100644 index 00000000000..77a5cde255c --- /dev/null +++ b/compiler/backend/src/org/jetbrains/jet/codegen/JvmPropertyAccessorSignature.java @@ -0,0 +1,28 @@ +package org.jetbrains.jet.codegen; + +import org.jetbrains.annotations.NotNull; + +/** + * @author Stepan Koltsov + */ +public class JvmPropertyAccessorSignature { + @NotNull + private final JvmMethodSignature jvmMethodSignature; + @NotNull + private final String propertyTypeKotlinSignature; + + public JvmPropertyAccessorSignature(@NotNull JvmMethodSignature jvmMethodSignature, @NotNull String propertyTypeKotlinSignature) { + this.jvmMethodSignature = jvmMethodSignature; + this.propertyTypeKotlinSignature = propertyTypeKotlinSignature; + } + + @NotNull + public JvmMethodSignature getJvmMethodSignature() { + return jvmMethodSignature; + } + + @NotNull + public String getPropertyTypeKotlinSignature() { + return propertyTypeKotlinSignature; + } +} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java index a4683e2c2ae..8ae216a3055 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java @@ -2,6 +2,7 @@ package org.jetbrains.jet.codegen; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.descriptors.PropertyDescriptor; import org.jetbrains.jet.lang.descriptors.PropertySetterDescriptor; @@ -12,6 +13,7 @@ import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; import org.jetbrains.jet.lang.resolve.java.JvmAbi; import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; import org.jetbrains.jet.lexer.JetTokens; +import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; @@ -86,7 +88,8 @@ public class PropertyCodegen { final JetPropertyAccessor getter = p.getGetter(); if (getter != null) { if (getter.getBodyExpression() != null) { - functionCodegen.generateMethod(getter, state.getTypeMapper().mapGetterSignature(propertyDescriptor, kind), propertyDescriptor.getGetter()); + JvmPropertyAccessorSignature signature = state.getTypeMapper().mapGetterSignature(propertyDescriptor, kind); + functionCodegen.generateMethod(getter, signature.getJvmMethodSignature(), signature.getPropertyTypeKotlinSignature(), propertyDescriptor.getGetter()); } else if (!getter.hasModifier(JetTokens.PRIVATE_KEYWORD)) { generateDefaultGetter(p, getter); @@ -107,7 +110,8 @@ public class PropertyCodegen { if (setter.getBodyExpression() != null) { final PropertySetterDescriptor setterDescriptor = propertyDescriptor.getSetter(); assert setterDescriptor != null; - functionCodegen.generateMethod(setter, state.getTypeMapper().mapSetterSignature(propertyDescriptor, kind), setterDescriptor); + JvmPropertyAccessorSignature signature = state.getTypeMapper().mapSetterSignature(propertyDescriptor, kind); + functionCodegen.generateMethod(setter, signature.getJvmMethodSignature(), signature.getPropertyTypeKotlinSignature(), setterDescriptor); } else if (!p.hasModifier(JetTokens.PRIVATE_KEYWORD)) { generateDefaultSetter(p, setter); @@ -138,10 +142,11 @@ public class PropertyCodegen { if(isTrait && !(kind instanceof OwnerKind.DelegateKind)) flags |= Opcodes.ACC_ABSTRACT; - final String signature = state.getTypeMapper().mapGetterSignature(propertyDescriptor, kind).getAsmMethod().getDescriptor(); + JvmPropertyAccessorSignature signature = state.getTypeMapper().mapGetterSignature(propertyDescriptor, kind); + final String descriptor = signature.getJvmMethodSignature().getAsmMethod().getDescriptor(); String getterName = getterName(propertyDescriptor.getName()); - MethodVisitor mv = v.newMethod(origin, flags, getterName, signature, null, null); - mv.visitAnnotation(JvmStdlibNames.JET_PROPERTY.getDescriptor(), true).visitEnd(); + MethodVisitor mv = v.newMethod(origin, flags, getterName, descriptor, null, null); + generateJetPropertyAnnotation(mv, signature.getPropertyTypeKotlinSignature(), signature.getJvmMethodSignature().getKotlinTypeParameter()); if (v.generateCode() && (!isTrait || kind instanceof OwnerKind.DelegateKind)) { mv.visitCode(); InstructionAdapter iv = new InstructionAdapter(mv); @@ -152,7 +157,7 @@ public class PropertyCodegen { if (kind instanceof OwnerKind.DelegateKind) { OwnerKind.DelegateKind dk = (OwnerKind.DelegateKind) kind; dk.getDelegate().put(JetTypeMapper.TYPE_OBJECT, iv); - iv.invokeinterface(dk.getOwnerClass(), getterName, signature); + iv.invokeinterface(dk.getOwnerClass(), getterName, descriptor); } else { iv.visitFieldInsn(kind == OwnerKind.NAMESPACE ? Opcodes.GETSTATIC : Opcodes.GETFIELD, @@ -164,6 +169,17 @@ public class PropertyCodegen { } } + public static void generateJetPropertyAnnotation(MethodVisitor mv, @NotNull String kotlinType, @NotNull String typeParameters) { + AnnotationVisitor annotationVisitor = mv.visitAnnotation(JvmStdlibNames.JET_PROPERTY.getDescriptor(), true); + if (kotlinType.length() > 0) { + annotationVisitor.visit(JvmStdlibNames.JET_PROPERTY_TYPE_FIELD, kotlinType); + } + if (typeParameters.length() > 0) { + annotationVisitor.visit(JvmStdlibNames.JET_PROPERTY_TYPE_PARAMETERS_FIELD, typeParameters); + } + annotationVisitor.visitEnd(); + } + private void generateDefaultSetter(JetProperty p, JetDeclaration declaration) { final PropertyDescriptor propertyDescriptor = (PropertyDescriptor) state.getBindingContext().get(BindingContext.VARIABLE, p); int flags = JetTypeMapper.getAccessModifiers(declaration, Opcodes.ACC_PUBLIC); @@ -184,9 +200,10 @@ public class PropertyCodegen { if(isTrait && !(kind instanceof OwnerKind.DelegateKind)) flags |= Opcodes.ACC_ABSTRACT; - final String signature = state.getTypeMapper().mapSetterSignature(propertyDescriptor, kind).getAsmMethod().getDescriptor(); - MethodVisitor mv = v.newMethod(origin, flags, setterName(propertyDescriptor.getName()), signature, null, null); - mv.visitAnnotation(JvmStdlibNames.JET_PROPERTY.getDescriptor(), true).visitEnd(); + JvmPropertyAccessorSignature signature = state.getTypeMapper().mapSetterSignature(propertyDescriptor, kind); + final String descriptor = signature.getJvmMethodSignature().getAsmMethod().getDescriptor(); + MethodVisitor mv = v.newMethod(origin, flags, setterName(propertyDescriptor.getName()), descriptor, null, null); + generateJetPropertyAnnotation(mv, signature.getPropertyTypeKotlinSignature(), signature.getJvmMethodSignature().getKotlinTypeParameter()); if (v.generateCode() && (!isTrait || kind instanceof OwnerKind.DelegateKind)) { mv.visitCode(); InstructionAdapter iv = new InstructionAdapter(mv); @@ -203,7 +220,7 @@ public class PropertyCodegen { dk.getDelegate().put(JetTypeMapper.TYPE_OBJECT, iv); iv.load(paramCode, type); - iv.invokeinterface(dk.getOwnerClass(), setterName(propertyDescriptor.getName()), signature); + iv.invokeinterface(dk.getOwnerClass(), setterName(propertyDescriptor.getName()), descriptor); } else { iv.load(paramCode, type); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java index b29522718c2..0cae7cbf43f 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java @@ -7,6 +7,7 @@ import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.psi.JetExpression; import org.jetbrains.jet.lang.resolve.calls.ResolvedCall; import org.jetbrains.jet.lang.resolve.java.JvmAbi; +import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lexer.JetTokens; @@ -36,7 +37,7 @@ public abstract class StackValue { if (type == Type.VOID_TYPE) { instructionAdapter.aconst(null); } else { - Type boxed = JetTypeMapper.getBoxedType(type); + Type boxed = JetTypeMapper.boxType(type); instructionAdapter.invokestatic(boxed.getInternalName(), "valueOf", "(" + type.getDescriptor() + ")" + boxed.getDescriptor()); } } @@ -209,10 +210,10 @@ public abstract class StackValue { else if (this.type.getSort() == Type.OBJECT && type.getSort() <= Type.DOUBLE) { if (this.type.equals(JetTypeMapper.TYPE_OBJECT)) { if (type.getSort() == Type.BOOLEAN) { - v.checkcast(JetTypeMapper.JL_BOOLEAN_TYPE); + v.checkcast(JvmPrimitiveType.BOOLEAN.getWrapper().getAsmType()); } else if (type.getSort() == Type.CHAR) { - v.checkcast(JetTypeMapper.JL_CHAR_TYPE); + v.checkcast(JvmPrimitiveType.CHAR.getWrapper().getAsmType()); } else { v.checkcast(JetTypeMapper.JL_NUMBER_TYPE); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArrayIterator.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArrayIterator.java index 60b7c7ec125..eec17fd486e 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArrayIterator.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArrayIterator.java @@ -10,7 +10,9 @@ import org.jetbrains.jet.lang.psi.JetCallExpression; import org.jetbrains.jet.lang.psi.JetExpression; import org.jetbrains.jet.lang.psi.JetSimpleNameExpression; import org.jetbrains.jet.lang.resolve.BindingContext; +import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType; import org.jetbrains.jet.lang.types.JetStandardLibrary; +import org.jetbrains.jet.lang.types.PrimitiveType; import org.objectweb.asm.Type; import org.objectweb.asm.commons.InstructionAdapter; @@ -31,40 +33,16 @@ public class ArrayIterator implements IntrinsicMethod { codegen.generateTypeInfo(funDescriptor.getReturnType().getArguments().get(0).getType(), null); v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([Ljava/lang/Object;Ljet/TypeInfo;)Ljet/Iterator;"); return StackValue.onStack(JetTypeMapper.TYPE_ITERATOR); - } - else if(containingDeclaration.equals(standardLibrary.getByteArrayClass())) { - v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([B)Ljet/ByteIterator;"); - return StackValue.onStack(JetTypeMapper.TYPE_BYTE_ITERATOR); - } - else if(containingDeclaration.equals(standardLibrary.getShortArrayClass())) { - v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([S)Ljet/ShortIterator;"); - return StackValue.onStack(JetTypeMapper.TYPE_SHORT_ITERATOR); - } - else if(containingDeclaration.equals(standardLibrary.getIntArrayClass())) { - v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([I)Ljet/IntIterator;"); - return StackValue.onStack(JetTypeMapper.TYPE_INT_ITERATOR); - } - else if(containingDeclaration.equals(standardLibrary.getLongArrayClass())) { - v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([J)Ljet/LongIterator;"); - return StackValue.onStack(JetTypeMapper.TYPE_LONG_ITERATOR); - } - else if(containingDeclaration.equals(standardLibrary.getFloatArrayClass())) { - v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([F)Ljet/FloatIterator;"); - return StackValue.onStack(JetTypeMapper.TYPE_FLOAT_ITERATOR); - } - else if(containingDeclaration.equals(standardLibrary.getDoubleArrayClass())) { - v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([D)Ljet/DoubleIterator;"); - return StackValue.onStack(JetTypeMapper.TYPE_DOUBLE_ITERATOR); - } - else if(containingDeclaration.equals(standardLibrary.getCharArrayClass())) { - v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([C)Ljet/CharIterator;"); - return StackValue.onStack(JetTypeMapper.TYPE_CHAR_ITERATOR); - } - else if(containingDeclaration.equals(standardLibrary.getBooleanArrayClass())) { - v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([Z)Ljet/BooleanIterator;"); - return StackValue.onStack(JetTypeMapper.TYPE_BOOLEAN_ITERATOR); - } - else { + } else { + for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) { + PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType(); + ClassDescriptor arrayClass = standardLibrary.getPrimitiveArrayClassDescriptor(primitiveType); + if (containingDeclaration.equals(arrayClass)) { + String methodSignature = "([" + jvmPrimitiveType.getJvmLetter() + ")" + jvmPrimitiveType.getIterator().getDescriptor(); + v.invokestatic("jet/runtime/ArrayIterator", "iterator", methodSignature); + return StackValue.onStack(jvmPrimitiveType.getIterator().getAsmType()); + } + } throw new UnsupportedOperationException(containingDeclaration.toString()); } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java index b57ecfe31cb..372e4a4f3c1 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java @@ -9,9 +9,11 @@ import com.intellij.psi.PsiMethod; import com.intellij.psi.search.DelegatingGlobalSearchScope; import com.intellij.psi.search.ProjectScope; import org.jetbrains.jet.lang.descriptors.*; +import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType; import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.types.JetStandardClasses; import org.jetbrains.jet.lang.types.JetStandardLibrary; +import org.jetbrains.jet.lang.types.PrimitiveType; import org.jetbrains.jet.lang.types.TypeProjection; import org.jetbrains.jet.plugin.JetFileType; import org.objectweb.asm.Opcodes; @@ -118,55 +120,25 @@ public class IntrinsicMethods { } private void declareArrayMethods() { + + for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) { + declareArrayMethodsForPrimitive(jvmPrimitiveType); + } + declareIntrinsicProperty("Array", "size", ARRAY_SIZE); - declareIntrinsicProperty("ByteArray", "size", ARRAY_SIZE); - declareIntrinsicProperty("ShortArray", "size", ARRAY_SIZE); - declareIntrinsicProperty("IntArray", "size", ARRAY_SIZE); - declareIntrinsicProperty("LongArray", "size", ARRAY_SIZE); - declareIntrinsicProperty("FloatArray", "size", ARRAY_SIZE); - declareIntrinsicProperty("DoubleArray", "size", ARRAY_SIZE); - declareIntrinsicProperty("CharArray", "size", ARRAY_SIZE); - declareIntrinsicProperty("BooleanArray", "size", ARRAY_SIZE); - declareIntrinsicProperty("Array", "indices", ARRAY_INDICES); - declareIntrinsicProperty("ByteArray", "indices", ARRAY_INDICES); - declareIntrinsicProperty("ShortArray", "indices", ARRAY_INDICES); - declareIntrinsicProperty("IntArray", "indices", ARRAY_INDICES); - declareIntrinsicProperty("LongArray", "indices", ARRAY_INDICES); - declareIntrinsicProperty("FloatArray", "indices", ARRAY_INDICES); - declareIntrinsicProperty("DoubleArray", "indices", ARRAY_INDICES); - declareIntrinsicProperty("CharArray", "indices", ARRAY_INDICES); - declareIntrinsicProperty("BooleanArray", "indices", ARRAY_INDICES); - declareIntrinsicFunction("Array", "set", 2, ARRAY_SET); - declareIntrinsicFunction("ByteArray", "set", 2, ARRAY_SET); - declareIntrinsicFunction("ShortArray", "set", 2, ARRAY_SET); - declareIntrinsicFunction("IntArray", "set", 2, ARRAY_SET); - declareIntrinsicFunction("LongArray", "set", 2, ARRAY_SET); - declareIntrinsicFunction("FloatArray", "set", 2, ARRAY_SET); - declareIntrinsicFunction("DoubleArray", "set", 2, ARRAY_SET); - declareIntrinsicFunction("CharArray", "set", 2, ARRAY_SET); - declareIntrinsicFunction("BooleanArray", "set", 2, ARRAY_SET); - declareIntrinsicFunction("Array", "get", 1, ARRAY_GET); - declareIntrinsicFunction("ByteArray", "get", 1, ARRAY_GET); - declareIntrinsicFunction("ShortArray", "get", 1, ARRAY_GET); - declareIntrinsicFunction("IntArray", "get", 1, ARRAY_GET); - declareIntrinsicFunction("LongArray", "get", 1, ARRAY_GET); - declareIntrinsicFunction("FloatArray", "get", 1, ARRAY_GET); - declareIntrinsicFunction("DoubleArray", "get", 1, ARRAY_GET); - declareIntrinsicFunction("CharArray", "get", 1, ARRAY_GET); - declareIntrinsicFunction("BooleanArray", "get", 1, ARRAY_GET); - declareIterator(myStdLib.getArray()); - declareIterator(myStdLib.getByteArrayClass()); - declareIterator(myStdLib.getShortArrayClass()); - declareIterator(myStdLib.getIntArrayClass()); - declareIterator(myStdLib.getLongArrayClass()); - declareIterator(myStdLib.getFloatArrayClass()); - declareIterator(myStdLib.getDoubleArrayClass()); - declareIterator(myStdLib.getCharArrayClass()); - declareIterator(myStdLib.getBooleanArrayClass()); + } + + private void declareArrayMethodsForPrimitive(JvmPrimitiveType jvmPrimitiveType) { + PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType(); + declareIntrinsicProperty(primitiveType.getArrayTypeName(), "size", ARRAY_SIZE); + declareIntrinsicProperty(primitiveType.getArrayTypeName(), "indices", ARRAY_INDICES); + declareIntrinsicFunction(primitiveType.getArrayTypeName(), "set", 2, ARRAY_SET); + declareIntrinsicFunction(primitiveType.getArrayTypeName(), "get", 1, ARRAY_GET); + declareIterator(myStdLib.getPrimitiveArrayClassDescriptor(primitiveType)); } private void declareIterator(ClassDescriptor classDescriptor) { @@ -186,8 +158,8 @@ public class IntrinsicMethods { } ); for (DeclarationDescriptor stringMember : stringMembers) { - if (stringMember instanceof FunctionDescriptor) { - final FunctionDescriptor stringMethod = (FunctionDescriptor) stringMember; + if (stringMember instanceof NamedFunctionDescriptor) { + final NamedFunctionDescriptor stringMethod = (NamedFunctionDescriptor) stringMember; final PsiMethod[] methods = stringPsiClass != null? stringPsiClass.findMethodsByName(stringMember.getName(), false) : new PsiMethod[]{}; for (PsiMethod method : methods) { diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/PsiMethodCall.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/PsiMethodCall.java index d7681a08590..b112f94615a 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/PsiMethodCall.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/PsiMethodCall.java @@ -5,7 +5,7 @@ import org.jetbrains.jet.codegen.CallableMethod; import org.jetbrains.jet.codegen.ExpressionCodegen; import org.jetbrains.jet.codegen.OwnerKind; import org.jetbrains.jet.codegen.StackValue; -import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; +import org.jetbrains.jet.lang.descriptors.NamedFunctionDescriptor; import org.jetbrains.jet.lang.psi.JetCallExpression; import org.jetbrains.jet.lang.psi.JetExpression; import org.objectweb.asm.Type; @@ -18,9 +18,9 @@ import java.util.List; * @author alex.tkachman */ public class PsiMethodCall implements IntrinsicMethod { - private final FunctionDescriptor myMethod; + private final NamedFunctionDescriptor myMethod; - public PsiMethodCall(FunctionDescriptor method) { + public PsiMethodCall(NamedFunctionDescriptor method) { myMethod = method; } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java index e3bdc3f6592..24820c7a34d 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java @@ -6,24 +6,66 @@ import com.google.common.collect.Sets; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.*; +import com.intellij.psi.HierarchicalMethodSignature; +import com.intellij.psi.JavaPsiFacade; +import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiClassType; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiEllipsisType; +import com.intellij.psi.PsiField; +import com.intellij.psi.PsiJavaFile; +import com.intellij.psi.PsiMethod; +import com.intellij.psi.PsiModifier; +import com.intellij.psi.PsiModifierListOwner; +import com.intellij.psi.PsiPackage; +import com.intellij.psi.PsiType; +import com.intellij.psi.PsiTypeParameter; +import com.intellij.psi.PsiTypeParameterListOwner; import com.intellij.psi.search.DelegatingGlobalSearchScope; import com.intellij.psi.search.GlobalSearchScope; import jet.typeinfo.TypeInfoVariance; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.descriptors.*; +import org.jetbrains.jet.lang.descriptors.ClassDescriptor; +import org.jetbrains.jet.lang.descriptors.ClassKind; +import org.jetbrains.jet.lang.descriptors.ConstructorDescriptorImpl; +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorImpl; +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorVisitor; +import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; +import org.jetbrains.jet.lang.descriptors.Modality; +import org.jetbrains.jet.lang.descriptors.NamedFunctionDescriptorImpl; +import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor; +import org.jetbrains.jet.lang.descriptors.PropertyDescriptor; +import org.jetbrains.jet.lang.descriptors.PropertyGetterDescriptor; +import org.jetbrains.jet.lang.descriptors.PropertySetterDescriptor; +import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor; +import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; +import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptorImpl; +import org.jetbrains.jet.lang.descriptors.VariableDescriptor; +import org.jetbrains.jet.lang.descriptors.Visibility; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.DescriptorUtils; -import org.jetbrains.jet.lang.types.*; +import org.jetbrains.jet.lang.resolve.java.kt.JetClassAnnotation; +import org.jetbrains.jet.lang.types.JetStandardClasses; +import org.jetbrains.jet.lang.types.JetType; +import org.jetbrains.jet.lang.types.TypeConstructorImpl; +import org.jetbrains.jet.lang.types.TypeSubstitutor; +import org.jetbrains.jet.lang.types.TypeUtils; +import org.jetbrains.jet.lang.types.Variance; import org.jetbrains.jet.plugin.JetFileType; import org.jetbrains.jet.rt.signature.JetSignatureAdapter; import org.jetbrains.jet.rt.signature.JetSignatureExceptionsAdapter; import org.jetbrains.jet.rt.signature.JetSignatureReader; import org.jetbrains.jet.rt.signature.JetSignatureVisitor; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * @author abreslav @@ -117,7 +159,7 @@ public class JavaDescriptorResolver { protected final Map namespaceDescriptorCacheByFqn = Maps.newHashMap(); protected final Map namespaceDescriptorCache = Maps.newHashMap(); - protected final Map typeParameterDescriptorCache = Maps.newHashMap(); + private final Map typeParameterDescriptorCache = Maps.newHashMap(); protected final Map methodDescriptorCache = Maps.newHashMap(); protected final Map fieldDescriptorCache = Maps.newHashMap(); protected final JavaPsiFacade javaFacade; @@ -259,17 +301,11 @@ public class JavaDescriptorResolver { } } else { - for (PsiMethod constructor : psiConstructors) { - PsiAnnotation jetConstructorAnnotation = - constructor.getModifierList().findAnnotation(JvmStdlibNames.JET_CONSTRUCTOR.getFqName()); - if (jetConstructorAnnotation != null) { - PsiLiteralExpression hiddenExpresson = (PsiLiteralExpression) jetConstructorAnnotation.findAttributeValue(JvmStdlibNames.JET_CONSTRUCTOR_HIDDEN_FIELD); - if (hiddenExpresson != null) { - boolean hidden = (Boolean) hiddenExpresson.getValue(); - if (hidden) { - continue; - } - } + for (PsiMethod psiConstructor : psiConstructors) { + PsiMethodWrapper constructor = new PsiMethodWrapper(psiConstructor); + + if (constructor.getJetConstructor().hidden()) { + continue; } ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl( @@ -277,17 +313,17 @@ public class JavaDescriptorResolver { Collections.emptyList(), // TODO false); ValueParameterDescriptors valueParameterDescriptors = resolveParameterDescriptors(constructorDescriptor, - constructor.getParameterList().getParameters(), + constructor.getParameters(), new TypeParameterListTypeVariableResolver(typeParameters) // TODO: outer too ); if (valueParameterDescriptors.receiverType != null) { throw new IllegalStateException(); } constructorDescriptor.initialize(typeParameters, valueParameterDescriptors.descriptors, Modality.FINAL, - resolveVisibilityFromPsiModifiers(constructor)); + resolveVisibilityFromPsiModifiers(psiConstructor)); constructorDescriptor.setReturnType(classData.classDescriptor.getDefaultType()); classData.classDescriptor.addConstructor(constructorDescriptor); - semanticServices.getTrace().record(BindingContext.CONSTRUCTOR, constructor, constructorDescriptor); + semanticServices.getTrace().record(BindingContext.CONSTRUCTOR, psiConstructor, constructorDescriptor); } } @@ -297,18 +333,14 @@ public class JavaDescriptorResolver { } private List resolveClassTypeParameters(PsiClass psiClass, ResolverClassData classData, TypeVariableResolver typeVariableResolver) { - for (PsiAnnotation annotation : psiClass.getModifierList().getAnnotations()) { - if (annotation.getQualifiedName().equals(JvmStdlibNames.JET_CLASS.getFqName())) { - classData.kotlin = true; - PsiLiteralExpression attributeValue = (PsiLiteralExpression) annotation.findAttributeValue(JvmStdlibNames.JET_CLASS_SIGNATURE); - if (attributeValue != null) { - String typeParametersString = (String) attributeValue.getValue(); - if (typeParametersString != null) { - return resolveClassTypeParametersFromJetSignature(typeParametersString, psiClass, classData.classDescriptor, typeVariableResolver); - } - } - } + JetClassAnnotation jetClassAnnotation = JetClassAnnotation.get(psiClass); + classData.kotlin = jetClassAnnotation.isDefined(); + + if (jetClassAnnotation.signature().length() > 0) { + return resolveClassTypeParametersFromJetSignature( + jetClassAnnotation.signature(), psiClass, classData.classDescriptor, typeVariableResolver); } + return makeUninitializedTypeParameters(classData.classDescriptor, psiClass.getTypeParameters()); } @@ -344,11 +376,12 @@ public class JavaDescriptorResolver { private final DeclarationDescriptor containingDeclaration; private final PsiTypeParameterListOwner psiOwner; private final String name; + private final int index; private final TypeInfoVariance variance; private final TypeVariableResolver typeVariableResolver; protected JetSignatureTypeParameterVisitor(DeclarationDescriptor containingDeclaration, PsiTypeParameterListOwner psiOwner, - String name, TypeInfoVariance variance, TypeVariableResolver typeVariableResolver) + String name, int index, TypeInfoVariance variance, TypeVariableResolver typeVariableResolver) { if (name.isEmpty()) { throw new IllegalStateException(); @@ -357,12 +390,11 @@ public class JavaDescriptorResolver { this.containingDeclaration = containingDeclaration; this.psiOwner = psiOwner; this.name = name; + this.index = index; this.variance = variance; this.typeVariableResolver = typeVariableResolver; } - int index = 0; - List upperBounds = new ArrayList(); List lowerBounds = new ArrayList(); @@ -397,7 +429,7 @@ public class JavaDescriptorResolver { true, // TODO: wrong JetSignatureUtils.translateVariance(variance), name, - ++index); + index); PsiTypeParameter psiTypeParameter = getPsiTypeParameterByName(psiOwner, name); typeParameterDescriptorCache.put(psiTypeParameter, new TypeParameterDescriptorInitialization(typeParameter, upperBounds, lowerBounds)); done(typeParameter); @@ -428,9 +460,11 @@ public class JavaDescriptorResolver { } new JetSignatureReader(jetSignature).accept(new JetSignatureExceptionsAdapter() { + private int formalTypeParameterIndex = 0; + @Override public JetSignatureVisitor visitFormalTypeParameter(final String name, final TypeInfoVariance variance) { - return new JetSignatureTypeParameterVisitor(classDescriptor, clazz, name, variance, new MyTypeVariableResolver()) { + return new JetSignatureTypeParameterVisitor(classDescriptor, clazz, name, formalTypeParameterIndex++, variance, new MyTypeVariableResolver()) { @Override protected void done(TypeParameterDescriptor typeParameterDescriptor) { r.add(typeParameterDescriptor); @@ -527,7 +561,10 @@ public class JavaDescriptorResolver { @NotNull private TypeParameterDescriptorInitialization resolveTypeParameter(@NotNull DeclarationDescriptor containingDeclaration, @NotNull PsiTypeParameter psiTypeParameter) { TypeParameterDescriptorInitialization typeParameterDescriptor = typeParameterDescriptorCache.get(psiTypeParameter); - assert typeParameterDescriptor != null : psiTypeParameter.getText(); + if (typeParameterDescriptor == null) { + // TODO: report properly without crashing compiler + throw new IllegalStateException("failed to resolve type parameter: " + psiTypeParameter.getName()); + } return typeParameterDescriptor; } @@ -633,21 +670,24 @@ public class JavaDescriptorResolver { } } - public ValueParameterDescriptors resolveParameterDescriptors(DeclarationDescriptor containingDeclaration, - PsiParameter[] parameters, TypeVariableResolver typeVariableResolver) { + private ValueParameterDescriptors resolveParameterDescriptors(DeclarationDescriptor containingDeclaration, + List parameters, TypeVariableResolver typeVariableResolver) { List result = new ArrayList(); JetType receiverType = null; - for (int i = 0, parametersLength = parameters.length; i < parametersLength; i++) { - PsiParameter parameter = parameters[i]; - JvmMethodParameterMeaning meaning = resolveParameterDescriptor(containingDeclaration, i, parameter, typeVariableResolver); + int indexDelta = 0; + for (int i = 0, parametersLength = parameters.size(); i < parametersLength; i++) { + PsiParameterWrapper parameter = parameters.get(i); + JvmMethodParameterMeaning meaning = resolveParameterDescriptor(containingDeclaration, i + indexDelta, parameter, typeVariableResolver); if (meaning.kind == JvmMethodParameterKind.TYPE_INFO) { // TODO + --indexDelta; } else if (meaning.kind == JvmMethodParameterKind.REGULAR) { result.add(meaning.valueParameterDescriptor); } else if (meaning.kind == JvmMethodParameterKind.RECEIVER) { if (receiverType != null) { throw new IllegalStateException("more then one receiver"); } + --indexDelta; receiverType = meaning.receiverType; } } @@ -688,8 +728,13 @@ public class JavaDescriptorResolver { @NotNull private JvmMethodParameterMeaning resolveParameterDescriptor(DeclarationDescriptor containingDeclaration, int i, - PsiParameter parameter, TypeVariableResolver typeVariableResolver) { - PsiType psiType = parameter.getType(); + PsiParameterWrapper parameter, TypeVariableResolver typeVariableResolver) { + + if (parameter.getJetTypeParameter().isDefined()) { + return JvmMethodParameterMeaning.typeInfo(new Object()); + } + + PsiType psiType = parameter.getPsiParameter().getType(); JetType varargElementType; if (psiType instanceof PsiEllipsisType) { @@ -700,56 +745,21 @@ public class JavaDescriptorResolver { varargElementType = null; } - boolean changeNullable = false; - boolean nullable = true; - String typeFromAnnotation = null; - - boolean receiver = false; - boolean hasDefaultValue = false; - + boolean nullable = parameter.getJetValueParameter().nullable(); + // TODO: must be very slow, make it lazy? - String name = parameter.getName() != null ? parameter.getName() : "p" + i; - for (PsiAnnotation annotation : parameter.getModifierList().getAnnotations()) { + String name = parameter.getPsiParameter().getName() != null ? parameter.getPsiParameter().getName() : "p" + i; - if (annotation.getQualifiedName().equals(JvmStdlibNames.JET_VALUE_PARAMETER.getFqName())) { - PsiLiteralExpression nameExpression = (PsiLiteralExpression) annotation.findAttributeValue(JvmStdlibNames.JET_VALUE_PARAMETER_NAME_FIELD); - if (nameExpression != null) { - name = (String) nameExpression.getValue(); - } - - PsiLiteralExpression nullableExpression = (PsiLiteralExpression) annotation.findAttributeValue(JvmStdlibNames.JET_VALUE_PARAMETER_NULLABLE_FIELD); - if (nullableExpression != null) { - nullable = (Boolean) nullableExpression.getValue(); - } else { - // default value of parameter - nullable = false; - changeNullable = true; - } - - PsiLiteralExpression signatureExpression = (PsiLiteralExpression) annotation.findAttributeValue(JvmStdlibNames.JET_VALUE_PARAMETER_TYPE_FIELD); - if (signatureExpression != null) { - typeFromAnnotation = (String) signatureExpression.getValue(); - } - - - PsiLiteralExpression receiverExpression = (PsiLiteralExpression) annotation.findAttributeValue(JvmStdlibNames.JET_VALUE_PARAMETER_RECEIVER_FIELD); - if (receiverExpression != null) { - receiver = (Boolean) receiverExpression.getValue(); - } - - PsiLiteralExpression hasDefaultValueExpression = (PsiLiteralExpression) annotation.findAttributeValue(JvmStdlibNames.JET_VALUE_PARAMETER_HAS_DEFAULT_VALUE_FIELD); - if (hasDefaultValueExpression != null) { - hasDefaultValue = (Boolean) hasDefaultValueExpression.getValue(); - } - - - } else if (annotation.getQualifiedName().equals(JvmStdlibNames.JET_TYPE_PARAMETER.getFqName())) { - return JvmMethodParameterMeaning.typeInfo(new Object()); - } + if (parameter.getJetValueParameter().name().length() > 0) { + name = parameter.getJetValueParameter().name(); } + String typeFromAnnotation = parameter.getJetValueParameter().type(); + boolean receiver = parameter.getJetValueParameter().receiver(); + boolean hasDefaultValue = parameter.getJetValueParameter().hasDefaultValue(); + JetType outType; - if (typeFromAnnotation != null && typeFromAnnotation.length() > 0) { + if (typeFromAnnotation.length() > 0) { outType = semanticServices.getTypeTransformer().transformToType(typeFromAnnotation, typeVariableResolver); } else { outType = semanticServices.getTypeTransformer().transformToType(psiType); @@ -763,7 +773,7 @@ public class JavaDescriptorResolver { Collections.emptyList(), // TODO name, false, - changeNullable ? TypeUtils.makeNullableAsSpecified(outType, nullable) : outType, + nullable ? TypeUtils.makeNullableAsSpecified(outType, nullable) : outType, hasDefaultValue, varargElementType )); @@ -797,24 +807,28 @@ public class JavaDescriptorResolver { private static class PropertyKey { @NotNull private final String name; - @NotNull - private final PsiType type; + //@NotNull + //private final PsiType type; + //@Nullable + //private final PsiType receiverType; - private PropertyKey(String name, PsiType type) { + private PropertyKey(@NotNull String name /*, @NotNull PsiType type, @Nullable PsiType receiverType */) { this.name = name; - this.type = type; + //this.type = type; + //this.receiverType = receiverType; } @Override public boolean equals(Object o) { - // generated by Idea if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PropertyKey that = (PropertyKey) o; if (!name.equals(that.name)) return false; - if (!type.equals(that.type)) return false; + //if (receiverType != null ? !receiverType.equals(that.receiverType) : that.receiverType != null) + // return false; + //if (!type.equals(that.type)) return false; return true; } @@ -822,15 +836,19 @@ public class JavaDescriptorResolver { @Override public int hashCode() { int result = name.hashCode(); - result = 31 * result + type.hashCode(); + //result = 31 * result + type.hashCode(); + //result = 31 * result + (receiverType != null ? receiverType.hashCode() : 0); return result; } } private static class MembersForProperty { - private PsiField field; - private PsiMethod setter; - private PsiMethod getter; + private PsiFieldWrapper field; + private PsiMethodWrapper setter; + private PsiMethodWrapper getter; + + private PsiType type; + private PsiType receiverType; } private Map getMembersForProperties(@NotNull PsiClass clazz, boolean staticMembers, boolean kotlin) { @@ -846,51 +864,106 @@ public class JavaDescriptorResolver { } MembersForProperty members = new MembersForProperty(); - members.field = field; - membersMap.put(new PropertyKey(field.getName(), field.getType()), members); + members.field = new PsiFieldWrapper(field); + members.type = field.getType(); + membersMap.put(new PropertyKey(field.getName() /*, field.getType(), null*/), members); } } - for (PsiMethod method : clazz.getMethods()) { - if (method.getModifierList().hasExplicitModifier(PsiModifier.STATIC) != staticMembers) { + for (PsiMethod psiMethod : clazz.getMethods()) { + PsiMethodWrapper method = new PsiMethodWrapper(psiMethod); + + if (method.isStatic() != staticMembers) { continue; } - if (method.hasModifierProperty(PsiModifier.PRIVATE)) { + if (method.isPrivate()) { continue; } // TODO: "is" prefix - if (method.getName().startsWith(JvmAbi.GETTER_PREFIX)) { - // TODO: some java properties too - if (method.getModifierList().findAnnotation(JvmStdlibNames.JET_PROPERTY.getFqName()) != null) { - if (method.getParameterList().getParametersCount() == 0) { - if (method.getName().equals(JvmStdlibNames.JET_OBJECT_GET_TYPEINFO_METHOD)) { - continue; - } + // TODO: remove getJavaClass + if (psiMethod.getName().startsWith(JvmAbi.GETTER_PREFIX)) { - String propertyName = StringUtil.decapitalize(method.getName().substring(JvmAbi.GETTER_PREFIX.length())); - PropertyKey key = new PropertyKey(propertyName, method.getReturnType()); - MembersForProperty members = membersMap.get(key); - if (members == null) { - members = new MembersForProperty(); - membersMap.put(key, members); - } - members.getter = method; + // TODO: some java properties too + if (method.getJetProperty().isDefined()) { + + if (psiMethod.getName().equals(JvmStdlibNames.JET_OBJECT_GET_TYPEINFO_METHOD)) { + continue; } + + int i = 0; + + PsiType receiverType; + if (i < method.getParameters().size() && method.getParameter(i).getJetValueParameter().receiver()) { + receiverType = method.getParameter(i).getPsiParameter().getType(); + ++i; + } else { + receiverType = null; + } + + while (i < method.getParameters().size() && method.getParameter(i).getJetTypeParameter().isDefined()) { + // TODO: store is reified + ++i; + } + + if (i != method.getParameters().size()) { + // TODO: report error properly + throw new IllegalStateException(); + } + + String propertyName = StringUtil.decapitalize(psiMethod.getName().substring(JvmAbi.GETTER_PREFIX.length())); + PropertyKey key = new PropertyKey(propertyName /*, psiMethod.getReturnType(), receiverType*/); + MembersForProperty members = membersMap.get(key); + if (members == null) { + members = new MembersForProperty(); + membersMap.put(key, members); + } + members.getter = new PsiMethodWrapper(psiMethod); + + // TODO: check conflicts with setter + members.type = psiMethod.getReturnType(); + members.receiverType = receiverType; } - } else if (method.getName().startsWith(JvmAbi.SETTER_PREFIX)) { - if (method.getModifierList().findAnnotation(JvmStdlibNames.JET_PROPERTY.getFqName()) != null) { - if (method.getParameterList().getParametersCount() == 1) { - String propertyName = StringUtil.decapitalize(method.getName().substring(JvmAbi.SETTER_PREFIX.length())); - PropertyKey key = new PropertyKey(propertyName, method.getParameterList().getParameters()[0].getType()); - MembersForProperty members = membersMap.get(key); - if (members == null) { - members = new MembersForProperty(); - membersMap.put(key, members); - } - members.setter = method; + } else if (psiMethod.getName().startsWith(JvmAbi.SETTER_PREFIX)) { + + if (method.getJetProperty().isDefined()) { + if (psiMethod.getParameterList().getParametersCount() == 0) { + // TODO: report error properly + throw new IllegalStateException(); } + + int i = 0; + + PsiType receiverType = null; + PsiParameterWrapper p1 = method.getParameter(0); + if (p1.getJetValueParameter().receiver()) { + receiverType = p1.getPsiParameter().getType(); + ++i; + } + + while (i < method.getParameters().size() && method.getParameter(i).getJetTypeParameter().isDefined()) { + ++i; + } + + if (i + 1 != psiMethod.getParameterList().getParametersCount()) { + throw new IllegalStateException(); + } + + PsiType propertyType = psiMethod.getParameterList().getParameters()[i].getType(); + + String propertyName = StringUtil.decapitalize(psiMethod.getName().substring(JvmAbi.SETTER_PREFIX.length())); + PropertyKey key = new PropertyKey(propertyName /*, propertyType, receiverType*/); + MembersForProperty members = membersMap.get(key); + if (members == null) { + members = new MembersForProperty(); + membersMap.put(key, members); + } + members.setter = new PsiMethodWrapper(psiMethod); + + // TODO: check conflicts with getter + members.type = propertyType; + members.receiverType = receiverType; } } } @@ -930,28 +1003,29 @@ public class JavaDescriptorResolver { } Set descriptors = Sets.newHashSet(); - for (Map.Entry entry : getMembersForProperties(psiClass, staticMembers, scopeData.kotlin).entrySet()) { + Map membersForProperties = getMembersForProperties(psiClass, staticMembers, scopeData.kotlin); + for (Map.Entry entry : membersForProperties.entrySet()) { //VariableDescriptor variableDescriptor = fieldDescriptorCache.get(field); //if (variableDescriptor != null) { // return variableDescriptor; //} String propertyName = entry.getKey().name; - PsiType propertyType = entry.getKey().type; + PsiType propertyType = entry.getValue().type; + PsiType receiverType = entry.getValue().receiverType; MembersForProperty members = entry.getValue(); - JetType type = semanticServices.getTypeTransformer().transformToType(propertyType); boolean isFinal; if (members.setter == null && members.getter == null) { - isFinal = members.field.hasModifierProperty(PsiModifier.FINAL); + isFinal = false; } else if (members.getter != null) { - isFinal = members.getter.hasModifierProperty(PsiModifier.FINAL); + isFinal = members.getter.isFinal(); } else if (members.setter != null) { - isFinal = members.setter.hasModifierProperty(PsiModifier.FINAL); + isFinal = members.setter.isFinal(); } else { isFinal = false; } - - PsiMember anyMember; + + PsiMemberWrapper anyMember; if (members.getter != null) { anyMember = members.getter; } else if (members.field != null) { @@ -973,14 +1047,64 @@ public class JavaDescriptorResolver { owner, Collections.emptyList(), isFinal && !staticMembers ? Modality.FINAL : Modality.OPEN, // TODO: abstract - resolveVisibilityFromPsiModifiers(anyMember), + resolveVisibilityFromPsiModifiers(anyMember.psiMember), isVar, false, - null, + propertyName); + + PropertyGetterDescriptor getterDescriptor = null; + PropertySetterDescriptor setterDescriptor = null; + if (members.getter != null) { + getterDescriptor = new PropertyGetterDescriptor(propertyDescriptor, Collections.emptyList(), Modality.OPEN, Visibility.PUBLIC, true, false); + } + if (members.setter != null) { + setterDescriptor = new PropertySetterDescriptor(propertyDescriptor, Collections.emptyList(), Modality.OPEN, Visibility.PUBLIC, true, false); + } + + propertyDescriptor.initialize(getterDescriptor, setterDescriptor); + + final List classTypeParameters; + if (anyMember instanceof PsiMethodWrapper && !anyMember.isStatic()) { + classTypeParameters = ((ClassDescriptor) owner).getTypeConstructor().getParameters(); + } else { + classTypeParameters = new ArrayList(0); + } + TypeParameterListTypeVariableResolver typeVariableResolver = new TypeParameterListTypeVariableResolver(classTypeParameters); + + List typeParameters = new ArrayList(0); + + if (members.setter != null) { + // call ugly code with side effects + typeParameters = resolveMethodTypeParameters(members.setter, propertyDescriptor.getSetter(), typeVariableResolver); + } + if (members.getter != null) { + // call ugly code with side effects + typeParameters = resolveMethodTypeParameters(members.getter, propertyDescriptor.getGetter(), typeVariableResolver); + } + + JetType receiverJetType; + if (receiverType == null) { + receiverJetType = null; + } else { + receiverJetType = semanticServices.getTypeTransformer().transformToType(receiverType); + } + + JetType type = semanticServices.getTypeTransformer().transformToType(propertyType); + + propertyDescriptor.setType( + type, + typeParameters, DescriptorUtils.getExpectedThisObjectIfNeeded(owner), - propertyName, - type); - semanticServices.getTrace().record(BindingContext.VARIABLE, anyMember, propertyDescriptor); + receiverJetType + ); + if (getterDescriptor != null) { + getterDescriptor.initialize(type); + } + if (setterDescriptor != null) { + // TODO: initialize + } + + semanticServices.getTrace().record(BindingContext.VARIABLE, anyMember.psiMember, propertyDescriptor); //fieldDescriptorCache.put(field, propertyDescriptor); descriptors.add(propertyDescriptor); } @@ -1053,14 +1177,16 @@ public class JavaDescriptorResolver { } @Nullable - public FunctionDescriptor resolveMethodToFunctionDescriptor(DeclarationDescriptor owner, PsiClass psiClass, TypeSubstitutor typeSubstitutorForGenericSuperclasses, PsiMethod method) { - PsiType returnType = method.getReturnType(); + public FunctionDescriptor resolveMethodToFunctionDescriptor(DeclarationDescriptor owner, PsiClass psiClass, TypeSubstitutor typeSubstitutorForGenericSuperclasses, PsiMethod psiMethod) { + PsiMethodWrapper method = new PsiMethodWrapper(psiMethod); + + PsiType returnType = psiMethod.getReturnType(); if (returnType == null) { return null; } - FunctionDescriptor functionDescriptor = methodDescriptorCache.get(method); + FunctionDescriptor functionDescriptor = methodDescriptorCache.get(psiMethod); if (functionDescriptor != null) { - if (method.getContainingClass() != psiClass) { + if (psiMethod.getContainingClass() != psiClass) { functionDescriptor = functionDescriptor.substitute(typeSubstitutorForGenericSuperclasses); } return functionDescriptor; @@ -1082,44 +1208,36 @@ public class JavaDescriptorResolver { kotlin = classData.kotlin; } - // TODO: hide getters and setters properly - if (kotlin) { - if (method.getName().startsWith(JvmAbi.GETTER_PREFIX) && method.getParameterList().getParametersCount() == 0) { - if (method.getModifierList().findAnnotation(JvmStdlibNames.JET_PROPERTY.getFqName()) != null) - return null; - } - if (method.getName().startsWith(JvmAbi.SETTER_PREFIX) && method.getParameterList().getParametersCount() == 1) { - if (method.getModifierList().findAnnotation(JvmStdlibNames.JET_PROPERTY.getFqName()) != null) - return null; - } + // TODO: ugly + if (method.getJetProperty().isDefined()) { + return null; } - + DeclarationDescriptor classDescriptor; final List classTypeParameters; - if (method.hasModifierProperty(PsiModifier.STATIC)) { - classDescriptor = resolveNamespace(method.getContainingClass()); + if (method.isStatic()) { + classDescriptor = resolveNamespace(psiMethod.getContainingClass()); classTypeParameters = Collections.emptyList(); } else { - ClassDescriptor classClassDescriptor = resolveClass(method.getContainingClass()); + ClassDescriptor classClassDescriptor = resolveClass(psiMethod.getContainingClass()); classDescriptor = classClassDescriptor; classTypeParameters = classClassDescriptor.getTypeConstructor().getParameters(); } if (classDescriptor == null) { return null; } - PsiParameter[] parameters = method.getParameterList().getParameters(); - FunctionDescriptorImpl functionDescriptorImpl = new FunctionDescriptorImpl( + NamedFunctionDescriptorImpl functionDescriptorImpl = new NamedFunctionDescriptorImpl( owner, Collections.emptyList(), // TODO - method.getName() + psiMethod.getName() ); - methodDescriptorCache.put(method, functionDescriptorImpl); + methodDescriptorCache.put(psiMethod, functionDescriptorImpl); // TODO: add outer classes TypeParameterListTypeVariableResolver typeVariableResolverForParameters = new TypeParameterListTypeVariableResolver(classTypeParameters); - final List methodTypeParameters = resolveMethodTypeParameters(method, functionDescriptorImpl, typeVariableResolverForParameters); + final List methodTypeParameters = resolveMethodTypeParameters(new PsiMethodWrapper(psiMethod), functionDescriptorImpl, typeVariableResolverForParameters); class MethodTypeVariableResolver implements TypeVariableResolver { @@ -1141,41 +1259,37 @@ public class JavaDescriptorResolver { } - ValueParameterDescriptors valueParameterDescriptors = resolveParameterDescriptors(functionDescriptorImpl, parameters, new MethodTypeVariableResolver()); + ValueParameterDescriptors valueParameterDescriptors = resolveParameterDescriptors(functionDescriptorImpl, method.getParameters(), new MethodTypeVariableResolver()); functionDescriptorImpl.initialize( valueParameterDescriptors.receiverType, DescriptorUtils.getExpectedThisObjectIfNeeded(classDescriptor), methodTypeParameters, valueParameterDescriptors.descriptors, makeReturnType(returnType, method, new MethodTypeVariableResolver()), - Modality.convertFromFlags(method.hasModifierProperty(PsiModifier.ABSTRACT), !method.hasModifierProperty(PsiModifier.FINAL)), - resolveVisibilityFromPsiModifiers(method) + Modality.convertFromFlags(psiMethod.hasModifierProperty(PsiModifier.ABSTRACT), !psiMethod.hasModifierProperty(PsiModifier.FINAL)), + resolveVisibilityFromPsiModifiers(psiMethod) ); - semanticServices.getTrace().record(BindingContext.FUNCTION, method, functionDescriptorImpl); + semanticServices.getTrace().record(BindingContext.FUNCTION, psiMethod, functionDescriptorImpl); FunctionDescriptor substitutedFunctionDescriptor = functionDescriptorImpl; - if (method.getContainingClass() != psiClass) { + if (psiMethod.getContainingClass() != psiClass) { substitutedFunctionDescriptor = functionDescriptorImpl.substitute(typeSubstitutorForGenericSuperclasses); } return substitutedFunctionDescriptor; } - private List resolveMethodTypeParameters(PsiMethod method, FunctionDescriptorImpl functionDescriptorImpl, TypeVariableResolver classTypeVariableResolver) { - for (PsiAnnotation annotation : method.getModifierList().getAnnotations()) { - if (annotation.getQualifiedName().equals(JvmStdlibNames.JET_METHOD.getFqName())) { - PsiLiteralExpression attributeValue = (PsiLiteralExpression) annotation.findAttributeValue(JvmStdlibNames.JET_METHOD_TYPE_PARAMETERS_FIELD); - if (attributeValue != null) { - String typeParametersString = (String) attributeValue.getValue(); - if (typeParametersString != null) { - List r = resolveMethodTypeParametersFromJetSignature(typeParametersString, method, functionDescriptorImpl, classTypeVariableResolver); - initializeTypeParameters(method); - return r; - } - } - } + private List resolveMethodTypeParameters( + @NotNull PsiMethodWrapper method, + @NotNull FunctionDescriptor functionDescriptor, + @NotNull TypeVariableResolver classTypeVariableResolver) { + if (method.getJetMethodOrProperty().typeParameters().length() > 0) { + List r = resolveMethodTypeParametersFromJetSignature( + method.getJetMethodOrProperty().typeParameters(), method.getPsiMethod(), functionDescriptor, classTypeVariableResolver); + initializeTypeParameters(method.getPsiMethod()); + return r; } - - List typeParameters = makeUninitializedTypeParameters(functionDescriptorImpl, method.getTypeParameters()); - initializeTypeParameters(method); + + List typeParameters = makeUninitializedTypeParameters(functionDescriptor, method.getPsiMethod().getTypeParameters()); + initializeTypeParameters(method.getPsiMethod()); return typeParameters; } @@ -1202,10 +1316,12 @@ public class JavaDescriptorResolver { } new JetSignatureReader(jetSignature).acceptFormalTypeParametersOnly(new JetSignatureExceptionsAdapter() { + private int formalTypeParameterIndex = 0; + @Override public JetSignatureVisitor visitFormalTypeParameter(final String name, final TypeInfoVariance variance) { - return new JetSignatureTypeParameterVisitor(functionDescriptor, method, name, variance, new MyTypeVariableResolver()) { + return new JetSignatureTypeParameterVisitor(functionDescriptor, method, name, formalTypeParameterIndex++, variance, new MyTypeVariableResolver()) { @Override protected void done(TypeParameterDescriptor typeParameterDescriptor) { r.add(typeParameterDescriptor); @@ -1217,37 +1333,18 @@ public class JavaDescriptorResolver { return r; } - private JetType makeReturnType(PsiType returnType, PsiMethod method, TypeVariableResolver typeVariableResolver) { - boolean changeNullable = false; - boolean nullable = true; - - String returnTypeFromAnnotation = null; + private JetType makeReturnType(PsiType returnType, PsiMethodWrapper method, TypeVariableResolver typeVariableResolver) { + + String returnTypeFromAnnotation = method.getJetMethod().returnType(); - for (PsiAnnotation annotation : method.getModifierList().getAnnotations()) { - if (annotation.getQualifiedName().equals(JvmStdlibNames.JET_METHOD.getFqName())) { - PsiLiteralExpression nullableExpression = (PsiLiteralExpression) annotation.findAttributeValue(JvmStdlibNames.JET_METHOD_NULLABLE_RETURN_TYPE_FIELD); - if (nullableExpression != null) { - nullable = (Boolean) nullableExpression.getValue(); - } else { - // default value of parameter - nullable = false; - changeNullable = true; - } - - PsiLiteralExpression returnTypeExpression = (PsiLiteralExpression) annotation.findAttributeValue(JvmStdlibNames.JET_METHOD_RETURN_TYPE_FIELD); - if (returnTypeExpression != null) { - returnTypeFromAnnotation = (String) returnTypeExpression.getValue(); - } - } - } JetType transformedType; - if (returnTypeFromAnnotation != null && returnTypeFromAnnotation.length() > 0) { + if (returnTypeFromAnnotation.length() > 0) { transformedType = semanticServices.getTypeTransformer().transformToType(returnTypeFromAnnotation, typeVariableResolver); } else { transformedType = semanticServices.getTypeTransformer().transformToType(returnType); } - if (changeNullable) { - return TypeUtils.makeNullableAsSpecified(transformedType, nullable); + if (method.getJetMethod().returnTypeNullable()) { + return TypeUtils.makeNullableAsSpecified(transformedType, true); } else { return transformedType; } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaPackageScope.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaPackageScope.java index 31bb50ad3db..cfd692ece93 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaPackageScope.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaPackageScope.java @@ -86,14 +86,6 @@ public class JavaPackageScope extends JetScopeImpl { return Collections.emptySet(); } - PsiField field = psiClassForPackage.findFieldByName(name, true); - if (field == null) { - return Collections.emptySet(); - } - if (!field.hasModifierProperty(PsiModifier.STATIC)) { - return Collections.emptySet(); - } - // TODO: cache return semanticServices.getDescriptorResolver().resolveFieldGroupByName(containingDescriptor, psiClassForPackage, name, true); } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java index 96e64c6f08c..dc5bbf755a2 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java @@ -88,6 +88,7 @@ public class JavaTypeTransformer { if (psiClass instanceof PsiTypeParameter) { PsiTypeParameter typeParameter = (PsiTypeParameter) psiClass; TypeParameterDescriptor typeParameterDescriptor = resolver.resolveTypeParameter(typeParameter); +// return TypeUtils.makeNullable(typeParameterDescriptor.getDefaultType()); return typeParameterDescriptor.getDefaultType(); } else { @@ -155,31 +156,13 @@ public class JavaTypeTransformer { public Map getPrimitiveTypesMap() { if (primitiveTypesMap == null) { primitiveTypesMap = new HashMap(); - primitiveTypesMap.put("byte", standardLibrary.getByteType()); - primitiveTypesMap.put("short", standardLibrary.getShortType()); - primitiveTypesMap.put("char", standardLibrary.getCharType()); - primitiveTypesMap.put("int", standardLibrary.getIntType()); - primitiveTypesMap.put("long", standardLibrary.getLongType()); - primitiveTypesMap.put("float", standardLibrary.getFloatType()); - primitiveTypesMap.put("double", standardLibrary.getDoubleType()); - primitiveTypesMap.put("boolean", standardLibrary.getBooleanType()); - primitiveTypesMap.put("[byte", standardLibrary.getByteArrayType()); - primitiveTypesMap.put("[short", standardLibrary.getShortArrayType()); - primitiveTypesMap.put("[char", standardLibrary.getCharArrayType()); - primitiveTypesMap.put("[int", standardLibrary.getIntArrayType()); - primitiveTypesMap.put("[long", standardLibrary.getLongArrayType()); - primitiveTypesMap.put("[float", standardLibrary.getFloatArrayType()); - primitiveTypesMap.put("[double", standardLibrary.getDoubleArrayType()); - primitiveTypesMap.put("[boolean", standardLibrary.getBooleanArrayType()); + for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) { + PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType(); + primitiveTypesMap.put(jvmPrimitiveType.getName(), standardLibrary.getPrimitiveJetType(primitiveType)); + primitiveTypesMap.put("[" + jvmPrimitiveType.getName(), standardLibrary.getPrimitiveArrayJetType(primitiveType)); + primitiveTypesMap.put(jvmPrimitiveType.getWrapper().getFqName(), standardLibrary.getNullablePrimitiveJetType(primitiveType)); + } primitiveTypesMap.put("void", JetStandardClasses.getUnitType()); - primitiveTypesMap.put("java.lang.Byte", TypeUtils.makeNullable(standardLibrary.getByteType())); - primitiveTypesMap.put("java.lang.Short", TypeUtils.makeNullable(standardLibrary.getShortType())); - primitiveTypesMap.put("java.lang.Character", TypeUtils.makeNullable(standardLibrary.getCharType())); - primitiveTypesMap.put("java.lang.Integer", TypeUtils.makeNullable(standardLibrary.getIntType())); - primitiveTypesMap.put("java.lang.Long", TypeUtils.makeNullable(standardLibrary.getLongType())); - primitiveTypesMap.put("java.lang.Float", TypeUtils.makeNullable(standardLibrary.getFloatType())); - primitiveTypesMap.put("java.lang.Double", TypeUtils.makeNullable(standardLibrary.getDoubleType())); - primitiveTypesMap.put("java.lang.Boolean", TypeUtils.makeNullable(standardLibrary.getBooleanType())); } return primitiveTypesMap; } @@ -187,14 +170,10 @@ public class JavaTypeTransformer { public Map getClassTypesMap() { if (classTypesMap == null) { classTypesMap = new HashMap(); - classTypesMap.put("java.lang.Byte", TypeUtils.makeNullable(standardLibrary.getByteType())); - classTypesMap.put("java.lang.Short", TypeUtils.makeNullable(standardLibrary.getShortType())); - classTypesMap.put("java.lang.Character", TypeUtils.makeNullable(standardLibrary.getCharType())); - classTypesMap.put("java.lang.Integer", TypeUtils.makeNullable(standardLibrary.getIntType())); - classTypesMap.put("java.lang.Long", TypeUtils.makeNullable(standardLibrary.getLongType())); - classTypesMap.put("java.lang.Float", TypeUtils.makeNullable(standardLibrary.getFloatType())); - classTypesMap.put("java.lang.Double", TypeUtils.makeNullable(standardLibrary.getDoubleType())); - classTypesMap.put("java.lang.Boolean", TypeUtils.makeNullable(standardLibrary.getBooleanType())); + for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) { + PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType(); + classTypesMap.put(jvmPrimitiveType.getWrapper().getFqName(), standardLibrary.getNullablePrimitiveJetType(primitiveType)); + } classTypesMap.put("java.lang.Object", JetStandardClasses.getNullableAnyType()); classTypesMap.put("java.lang.String", standardLibrary.getNullableStringType()); } @@ -204,14 +183,10 @@ public class JavaTypeTransformer { public Map getPrimitiveWrappersClassDescriptorMap() { if (classDescriptorMap == null) { classDescriptorMap = new HashMap(); - classDescriptorMap.put("java.lang.Byte", standardLibrary.getByte()); - classDescriptorMap.put("java.lang.Short", standardLibrary.getShort()); - classDescriptorMap.put("java.lang.Character", standardLibrary.getChar()); - classDescriptorMap.put("java.lang.Integer", standardLibrary.getInt()); - classDescriptorMap.put("java.lang.Long", standardLibrary.getLong()); - classDescriptorMap.put("java.lang.Float", standardLibrary.getFloat()); - classDescriptorMap.put("java.lang.Double", standardLibrary.getDouble()); - classDescriptorMap.put("java.lang.Boolean", standardLibrary.getBoolean()); + for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) { + PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType(); + classDescriptorMap.put(jvmPrimitiveType.getWrapper().getFqName(), standardLibrary.getPrimitiveClassDescriptor(primitiveType)); + } //classDescriptorMap.put("java.lang.Object", standardLibrary.get classDescriptorMap.put("java.lang.String", standardLibrary.getString()); } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JetTypeJetSignatureReader.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JetTypeJetSignatureReader.java index 0f51cf0df1e..dd8e8b6b3c8 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JetTypeJetSignatureReader.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JetTypeJetSignatureReader.java @@ -38,46 +38,22 @@ public abstract class JetTypeJetSignatureReader extends JetSignatureExceptionsAd private JetType getPrimitiveType(char descriptor, boolean nullable) { if (!nullable) { - switch (descriptor) { - case 'Z': - return jetStandardLibrary.getBooleanType(); - case 'C': - return jetStandardLibrary.getCharType(); - case 'B': - return jetStandardLibrary.getByteType(); - case 'S': - return jetStandardLibrary.getShortType(); - case 'I': - return jetStandardLibrary.getIntType(); - case 'F': - return jetStandardLibrary.getFloatType(); - case 'J': - return jetStandardLibrary.getLongType(); - case 'D': - return jetStandardLibrary.getDoubleType(); - case 'V': - return JetStandardClasses.getUnitType(); + for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) { + if (jvmPrimitiveType.getJvmLetter() == descriptor) { + return jetStandardLibrary.getPrimitiveJetType(jvmPrimitiveType.getPrimitiveType()); + } + } + if (descriptor == 'V') { + return JetStandardClasses.getUnitType(); } } else { - switch (descriptor) { - case 'Z': - return jetStandardLibrary.getNullableBooleanType(); - case 'C': - return jetStandardLibrary.getNullableCharType(); - case 'B': - return jetStandardLibrary.getNullableByteType(); - case 'S': - return jetStandardLibrary.getNullableShortType(); - case 'I': - return jetStandardLibrary.getNullableIntType(); - case 'F': - return jetStandardLibrary.getNullableFloatType(); - case 'J': - return jetStandardLibrary.getNullableLongType(); - case 'D': - return jetStandardLibrary.getNullableDoubleType(); - case 'V': - throw new IllegalStateException("incorrect signature: nullable void"); + for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) { + if (jvmPrimitiveType.getJvmLetter() == descriptor) { + return jetStandardLibrary.getNullablePrimitiveJetType(jvmPrimitiveType.getPrimitiveType()); + } + } + if (descriptor == 'V') { + throw new IllegalStateException("incorrect signature: nullable void"); } } throw new IllegalStateException("incorrect signature"); @@ -138,7 +114,7 @@ public abstract class JetTypeJetSignatureReader extends JetSignatureExceptionsAd JetType primitiveType = getPrimitiveType(descriptor, nullable); JetType arrayType; if (!nullable) { - arrayType = jetStandardLibrary.getPrimitiveArrayType(primitiveType); + arrayType = jetStandardLibrary.getPrimitiveArrayJetTypeByPrimitiveJetType(primitiveType); } else { arrayType = TypeUtils.makeNullableAsSpecified(jetStandardLibrary.getArrayType(primitiveType), nullable); } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmClassName.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmClassName.java index db1bcac52ff..165b0039324 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmClassName.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmClassName.java @@ -1,6 +1,7 @@ package org.jetbrains.jet.lang.resolve.java; import org.jetbrains.annotations.NotNull; +import org.objectweb.asm.Type; /** * @author Stepan Koltsov @@ -39,4 +40,13 @@ public class JvmClassName { } return descriptor; } + + private Type asmType; + + public Type getAsmType() { + if (asmType == null) { + asmType = Type.getType(getDescriptor()); + } + return asmType; + } } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmPrimitiveType.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmPrimitiveType.java new file mode 100644 index 00000000000..73daad8a0b8 --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmPrimitiveType.java @@ -0,0 +1,111 @@ +package org.jetbrains.jet.lang.resolve.java; + +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.lang.types.PrimitiveType; +import org.objectweb.asm.Type; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author Stepan Koltsov + */ +public enum JvmPrimitiveType { + BOOLEAN(PrimitiveType.BOOLEAN, "boolean", "java.lang.Boolean", Type.BOOLEAN_TYPE), + CHAR(PrimitiveType.CHAR, "char", "java.lang.Character", Type.CHAR_TYPE), + BYTE(PrimitiveType.BYTE, "byte", "java.lang.Byte", Type.BYTE_TYPE), + SHORT(PrimitiveType.SHORT, "short", "java.lang.Short", Type.SHORT_TYPE), + INT(PrimitiveType.INT, "int", "java.lang.Integer", Type.INT_TYPE), + FLOAT(PrimitiveType.FLOAT, "float", "java.lang.Float", Type.FLOAT_TYPE), + LONG(PrimitiveType.LONG, "long", "java.lang.Long", Type.LONG_TYPE), + DOUBLE(PrimitiveType.DOUBLE, "double", "java.lang.Double", Type.DOUBLE_TYPE), + ; + + private final PrimitiveType primitiveType; + private final String name; + private final JvmClassName wrapper; + private final Type asmType; + private final char jvmLetter; + private final Type asmArrayType; + private final JvmClassName iterator; + + private JvmPrimitiveType(PrimitiveType primitiveType, String name, String wrapperClassName, Type asmType) { + this.primitiveType = primitiveType; + this.name = name; + this.wrapper = new JvmClassName(wrapperClassName); + this.asmType = asmType; + this.jvmLetter = asmType.getDescriptor().charAt(0); + this.asmArrayType = makeArrayType(asmType); + this.iterator = new JvmClassName("jet." + primitiveType.getTypeName() + "Iterator"); + } + + private static Type makeArrayType(Type type) { + StringBuilder sb = new StringBuilder(2); + sb.append('['); + sb.append(type.getDescriptor()); + return Type.getType(sb.toString()); + } + + public PrimitiveType getPrimitiveType() { + return primitiveType; + } + + public String getName() { + return name; + } + + public JvmClassName getWrapper() { + return wrapper; + } + + public Type getAsmType() { + return asmType; + } + + public Type getAsmArrayType() { + return asmArrayType; + } + + public JvmClassName getIterator() { + return iterator; + } + + public char getJvmLetter() { + return jvmLetter; + } + + + + private static class MapByAsmTypeHolder { + private static final Map map; + + static { + map = new HashMap(); + for (JvmPrimitiveType jvmPrimitiveType : values()) { + map.put(jvmPrimitiveType.getAsmType().getSort(), jvmPrimitiveType); + } + } + } + + @Nullable + public static JvmPrimitiveType getByAsmType(Type type) { + return MapByAsmTypeHolder.map.get(type.getSort()); + } + + + private static class MapByWrapperAsmTypeHolder { + private static final Map map; + + static { + map = new HashMap(); + for (JvmPrimitiveType jvmPrimitiveType : values()) { + map.put(jvmPrimitiveType.getWrapper().getAsmType(), jvmPrimitiveType); + } + } + } + + @Nullable + public static JvmPrimitiveType getByWrapperAsmType(Type type) { + return MapByWrapperAsmTypeHolder.map.get(type); + } +} diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmStdlibNames.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmStdlibNames.java index c81e5b2dafd..48ac6e69141 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmStdlibNames.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmStdlibNames.java @@ -30,6 +30,9 @@ public class JvmStdlibNames { public static final JvmClassName JET_PROPERTY = new JvmClassName("jet.runtime.typeinfo.JetProperty"); + public static final String JET_PROPERTY_TYPE_FIELD = "type"; + public static final String JET_PROPERTY_TYPE_PARAMETERS_FIELD = "typeParameters"; + public static final JvmClassName JET_CONSTRUCTOR = new JvmClassName("jet.runtime.typeinfo.JetConstructor"); /** diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/PsiFieldWrapper.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/PsiFieldWrapper.java new file mode 100644 index 00000000000..75ad3e13860 --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/PsiFieldWrapper.java @@ -0,0 +1,13 @@ +package org.jetbrains.jet.lang.resolve.java; + +import com.intellij.psi.PsiMember; +import org.jetbrains.annotations.NotNull; + +/** + * @author Stepan Koltsov + */ +public class PsiFieldWrapper extends PsiMemberWrapper { + public PsiFieldWrapper(@NotNull PsiMember psiMember) { + super(psiMember); + } +} diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/PsiMemberWrapper.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/PsiMemberWrapper.java new file mode 100644 index 00000000000..9e382597382 --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/PsiMemberWrapper.java @@ -0,0 +1,27 @@ +package org.jetbrains.jet.lang.resolve.java; + +import com.intellij.psi.PsiMember; +import com.intellij.psi.PsiModifier; +import org.jetbrains.annotations.NotNull; + +/** + * @author Stepan Koltsov + */ +public class PsiMemberWrapper { + + @NotNull + protected final PsiMember psiMember; + + public PsiMemberWrapper(@NotNull PsiMember psiMember) { + this.psiMember = psiMember; + } + + public boolean isStatic() { + return psiMember.hasModifierProperty(PsiModifier.STATIC); + } + + public boolean isPrivate() { + return psiMember.hasModifierProperty(PsiModifier.PRIVATE); + } + +} diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/PsiMethodWrapper.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/PsiMethodWrapper.java new file mode 100644 index 00000000000..7fe74364e9b --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/PsiMethodWrapper.java @@ -0,0 +1,86 @@ +package org.jetbrains.jet.lang.resolve.java; + +import com.intellij.psi.PsiMember; +import com.intellij.psi.PsiMethod; +import com.intellij.psi.PsiModifier; +import com.intellij.psi.PsiParameter; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.resolve.java.kt.JetConstructorAnnotation; +import org.jetbrains.jet.lang.resolve.java.kt.JetMethodAnnotation; +import org.jetbrains.jet.lang.resolve.java.kt.JetMethodOrPropertyAnnotation; +import org.jetbrains.jet.lang.resolve.java.kt.JetPropertyAnnotation; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Stepan Koltsov + */ +public class PsiMethodWrapper extends PsiMemberWrapper { + + public PsiMethodWrapper(@NotNull PsiMethod psiMethod) { + super(psiMethod); + } + + private List parameters; + @NotNull + public List getParameters() { + if (parameters == null) { + PsiParameter[] psiParameters = getPsiMethod().getParameterList().getParameters(); + parameters = new ArrayList(psiParameters.length); + for (int i = 0; i < psiParameters.length; ++i) { + parameters.add(new PsiParameterWrapper(psiParameters[i])); + } + } + return parameters; + } + + @NotNull + public PsiParameterWrapper getParameter(int i) { + return getParameters().get(i); + } + + public boolean isFinal() { + return psiMember.hasModifierProperty(PsiModifier.FINAL); + } + + private JetMethodAnnotation jetMethod; + @NotNull + public JetMethodAnnotation getJetMethod() { + if (jetMethod == null) { + jetMethod = JetMethodAnnotation.get(getPsiMethod()); + } + return jetMethod; + } + + private JetConstructorAnnotation jetConstructor; + @NotNull + public JetConstructorAnnotation getJetConstructor() { + if (jetConstructor == null) { + jetConstructor = JetConstructorAnnotation.get(getPsiMethod()); + } + return jetConstructor; + } + + private JetPropertyAnnotation jetProperty; + @NotNull + public JetPropertyAnnotation getJetProperty() { + if (jetProperty == null) { + jetProperty = JetPropertyAnnotation.get(getPsiMethod()); + } + return jetProperty; + } + + public JetMethodOrPropertyAnnotation getJetMethodOrProperty() { + if (getJetMethod().isDefined()) { + return getJetMethod(); + } else { + return getJetProperty(); + } + } + + @NotNull + public PsiMethod getPsiMethod() { + return (PsiMethod) psiMember; + } +} diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/PsiParameterWrapper.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/PsiParameterWrapper.java new file mode 100644 index 00000000000..56f03009847 --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/PsiParameterWrapper.java @@ -0,0 +1,38 @@ +package org.jetbrains.jet.lang.resolve.java; + +import com.intellij.psi.PsiParameter; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.resolve.java.kt.JetTypeParameterAnnotation; +import org.jetbrains.jet.lang.resolve.java.kt.JetValueParameterAnnotation; + +/** + * @author Stepan Koltsov + */ +public class PsiParameterWrapper { + private final PsiParameter psiParameter; + + public PsiParameterWrapper(@NotNull PsiParameter psiParameter) { + this.psiParameter = psiParameter; + + this.jetValueParameter = JetValueParameterAnnotation.get(psiParameter); + this.jetTypeParameter = JetTypeParameterAnnotation.get(psiParameter); + } + + private JetValueParameterAnnotation jetValueParameter; + private JetTypeParameterAnnotation jetTypeParameter; + + @NotNull + public PsiParameter getPsiParameter() { + return psiParameter; + } + + @NotNull + public JetValueParameterAnnotation getJetValueParameter() { + return jetValueParameter; + } + + @NotNull + public JetTypeParameterAnnotation getJetTypeParameter() { + return jetTypeParameter; + } +} diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetClassAnnotation.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetClassAnnotation.java new file mode 100644 index 00000000000..65ed9874a6c --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetClassAnnotation.java @@ -0,0 +1,30 @@ +package org.jetbrains.jet.lang.resolve.java.kt; + +import com.intellij.psi.PsiAnnotation; +import com.intellij.psi.PsiClass; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; + +/** + * @author Stepan Koltsov + */ +public class JetClassAnnotation extends PsiAnnotationWrapper { + + public JetClassAnnotation(@Nullable PsiAnnotation psiAnnotation) { + super(psiAnnotation); + } + + private String signature; + public String signature() { + if (signature == null) { + signature = getStringAttribute(JvmStdlibNames.JET_CLASS_SIGNATURE, ""); + } + return signature; + } + + @NotNull + public static JetClassAnnotation get(PsiClass psiClass) { + return new JetClassAnnotation(psiClass.getModifierList().findAnnotation(JvmStdlibNames.JET_CLASS.getFqName())); + } +} diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetConstructorAnnotation.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetConstructorAnnotation.java new file mode 100644 index 00000000000..400c73e3f84 --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetConstructorAnnotation.java @@ -0,0 +1,31 @@ +package org.jetbrains.jet.lang.resolve.java.kt; + +import com.intellij.psi.PsiAnnotation; +import com.intellij.psi.PsiMethod; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; + +/** + * @author Stepan Koltsov + */ +public class JetConstructorAnnotation extends PsiAnnotationWrapper { + + public JetConstructorAnnotation(@Nullable PsiAnnotation psiAnnotation) { + super(psiAnnotation); + } + + private boolean hidden; + private boolean hiddenInitialized = false; + /** @deprecated */ + public boolean hidden() { + if (!hiddenInitialized) { + hidden = getBooleanAttribute(JvmStdlibNames.JET_CONSTRUCTOR_HIDDEN_FIELD, false); + hiddenInitialized = true; + } + return hidden; + } + + public static JetConstructorAnnotation get(PsiMethod constructor) { + return new JetConstructorAnnotation(constructor.getModifierList().findAnnotation(JvmStdlibNames.JET_CONSTRUCTOR.getFqName())); + } +} diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetMethodAnnotation.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetMethodAnnotation.java new file mode 100644 index 00000000000..2f4d954e21c --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetMethodAnnotation.java @@ -0,0 +1,41 @@ +package org.jetbrains.jet.lang.resolve.java.kt; + +import com.intellij.psi.PsiAnnotation; +import com.intellij.psi.PsiMethod; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; + +/** + * @author Stepan Koltsov + */ +public class JetMethodAnnotation extends JetMethodOrPropertyAnnotation { + + public JetMethodAnnotation(@Nullable PsiAnnotation psiAnnotation) { + super(psiAnnotation); + } + + private String returnType; + @NotNull + public String returnType() { + if (returnType == null) { + returnType = getStringAttribute(JvmStdlibNames.JET_METHOD_RETURN_TYPE_FIELD, ""); + } + return returnType; + } + + private boolean returnTypeNullable; + private boolean returnTypeNullableInitialized; + @NotNull + public boolean returnTypeNullable() { + if (!returnTypeNullableInitialized) { + returnTypeNullable = getBooleanAttribute(JvmStdlibNames.JET_METHOD_NULLABLE_RETURN_TYPE_FIELD, false); + returnTypeNullableInitialized = true; + } + return returnTypeNullable; + } + + public static JetMethodAnnotation get(PsiMethod psiMethod) { + return new JetMethodAnnotation(psiMethod.getModifierList().findAnnotation(JvmStdlibNames.JET_METHOD.getFqName())); + } +} diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetMethodOrPropertyAnnotation.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetMethodOrPropertyAnnotation.java new file mode 100644 index 00000000000..e21e5ab0680 --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetMethodOrPropertyAnnotation.java @@ -0,0 +1,25 @@ +package org.jetbrains.jet.lang.resolve.java.kt; + +import com.intellij.psi.PsiAnnotation; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; + +/** + * @author Stepan Koltsov + */ +public abstract class JetMethodOrPropertyAnnotation extends PsiAnnotationWrapper { + protected JetMethodOrPropertyAnnotation(@Nullable PsiAnnotation psiAnnotation) { + super(psiAnnotation); + } + + private String typeParameters; + @NotNull + public String typeParameters() { + if (typeParameters == null) { + typeParameters = getStringAttribute(JvmStdlibNames.JET_METHOD_TYPE_PARAMETERS_FIELD, ""); + } + return typeParameters; + } + +} diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetPropertyAnnotation.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetPropertyAnnotation.java new file mode 100644 index 00000000000..3ca9a0031f7 --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetPropertyAnnotation.java @@ -0,0 +1,21 @@ +package org.jetbrains.jet.lang.resolve.java.kt; + +import com.intellij.psi.PsiAnnotation; +import com.intellij.psi.PsiMethod; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; + +/** + * @author Stepan Koltsov + */ +public class JetPropertyAnnotation extends JetMethodOrPropertyAnnotation { + protected JetPropertyAnnotation(@Nullable PsiAnnotation psiAnnotation) { + super(psiAnnotation); + } + + @NotNull + public static JetPropertyAnnotation get(@NotNull PsiMethod psiMethod) { + return new JetPropertyAnnotation(psiMethod.getModifierList().findAnnotation(JvmStdlibNames.JET_PROPERTY.getFqName())); + } +} diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetTypeParameterAnnotation.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetTypeParameterAnnotation.java new file mode 100644 index 00000000000..e7ad45cc60b --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetTypeParameterAnnotation.java @@ -0,0 +1,22 @@ +package org.jetbrains.jet.lang.resolve.java.kt; + +import com.intellij.psi.PsiAnnotation; +import com.intellij.psi.PsiParameter; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; + +/** + * @author Stepan Koltsov + */ +public class JetTypeParameterAnnotation extends PsiAnnotationWrapper { + + protected JetTypeParameterAnnotation(@Nullable PsiAnnotation psiAnnotation) { + super(psiAnnotation); + } + + @NotNull + public static JetTypeParameterAnnotation get(@NotNull PsiParameter psiParameter) { + return new JetTypeParameterAnnotation(psiParameter.getModifierList().findAnnotation(JvmStdlibNames.JET_TYPE_PARAMETER.getFqName())); + } +} diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetValueParameterAnnotation.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetValueParameterAnnotation.java new file mode 100644 index 00000000000..174d047b9f1 --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetValueParameterAnnotation.java @@ -0,0 +1,70 @@ +package org.jetbrains.jet.lang.resolve.java.kt; + +import com.intellij.psi.PsiAnnotation; +import com.intellij.psi.PsiParameter; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; + +/** + * @author Stepan Koltsov + */ +public class JetValueParameterAnnotation extends PsiAnnotationWrapper { + + public JetValueParameterAnnotation(@Nullable PsiAnnotation psiAnnotation) { + super(psiAnnotation); + } + + private String name; + @NotNull + public String name() { + if (name == null) { + name = getStringAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_NAME_FIELD, ""); + } + return name; + } + + private String type; + @NotNull + public String type() { + if (type == null) { + type = getStringAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_TYPE_FIELD, ""); + } + return type; + } + + private boolean nullable; + private boolean nullableInitialized = false; + public boolean nullable() { + if (!nullableInitialized) { + nullable = getBooleanAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_NULLABLE_FIELD, false); + nullableInitialized = true; + } + return nullable; + } + + private boolean receiver; + private boolean receiverInitialized = false; + public boolean receiver() { + if (!receiverInitialized) { + receiver = getBooleanAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_RECEIVER_FIELD, false); + receiverInitialized = true; + } + return receiver; + } + + private boolean hasDefaultValue; + private boolean hasDefaultValueInitialized = false; + public boolean hasDefaultValue() { + if (!hasDefaultValueInitialized) { + hasDefaultValue = getBooleanAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_HAS_DEFAULT_VALUE_FIELD, false); + hasDefaultValueInitialized = true; + } + return hasDefaultValue; + } + + public static JetValueParameterAnnotation get(PsiParameter psiParameter) { + return new JetValueParameterAnnotation(psiParameter.getModifierList().findAnnotation(JvmStdlibNames.JET_VALUE_PARAMETER.getFqName())); + } + +} diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/PsiAnnotationUtils.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/PsiAnnotationUtils.java new file mode 100644 index 00000000000..ec611685b02 --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/PsiAnnotationUtils.java @@ -0,0 +1,35 @@ +package org.jetbrains.jet.lang.resolve.java.kt; + +import com.intellij.psi.PsiAnnotation; +import com.intellij.psi.PsiLiteralExpression; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Stepan Koltsov + */ +public class PsiAnnotationUtils { + + @NotNull + public static String getStringAttribute(@Nullable PsiAnnotation annotation, @NotNull String field, @NotNull String defaultValue) { + return getAttribute(annotation, field, defaultValue); + } + + public static boolean getBooleanAttribute(@Nullable PsiAnnotation annotation, @NotNull String field, boolean defaultValue) { + return getAttribute(annotation, field, defaultValue); + } + + private static T getAttribute(@Nullable PsiAnnotation annotation, @NotNull String field, @NotNull T defaultValue) { + if (annotation == null) { + return defaultValue; + } else { + PsiLiteralExpression attributeValue = (PsiLiteralExpression) annotation.findAttributeValue(field); + if (attributeValue != null) { + return (T) attributeValue.getValue(); + } else { + return defaultValue; + } + } + } + +} diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/PsiAnnotationWrapper.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/PsiAnnotationWrapper.java new file mode 100644 index 00000000000..005b49c587f --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/PsiAnnotationWrapper.java @@ -0,0 +1,36 @@ +package org.jetbrains.jet.lang.resolve.java.kt; + +import com.intellij.psi.PsiAnnotation; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Stepan Koltsov + */ +public abstract class PsiAnnotationWrapper { + + @Nullable + private PsiAnnotation psiAnnotation; + + protected PsiAnnotationWrapper(@Nullable PsiAnnotation psiAnnotation) { + this.psiAnnotation = psiAnnotation; + } + + @Nullable + public PsiAnnotation getPsiAnnotation() { + return psiAnnotation; + } + + public boolean isDefined() { + return psiAnnotation != null; + } + + @NotNull + protected String getStringAttribute(String name, String defaultValue) { + return PsiAnnotationUtils.getStringAttribute(psiAnnotation, name, defaultValue); + } + + protected boolean getBooleanAttribute(String name, boolean defaultValue) { + return PsiAnnotationUtils.getBooleanAttribute(psiAnnotation, name, defaultValue); + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorImpl.java index 490b9f889b1..83758f56700 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorImpl.java @@ -5,7 +5,6 @@ import com.google.common.collect.Sets; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; -import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; import org.jetbrains.jet.lang.resolve.scopes.receivers.TransientReceiver; @@ -22,20 +21,20 @@ import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor /** * @author abreslav */ -public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements FunctionDescriptor { +public abstract class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements FunctionDescriptor { - private List typeParameters; - private List unsubstitutedValueParameters; - private JetType unsubstitutedReturnType; + protected List typeParameters; + protected List unsubstitutedValueParameters; + protected JetType unsubstitutedReturnType; private ReceiverDescriptor receiver; - private ReceiverDescriptor expectedThisObject; + protected ReceiverDescriptor expectedThisObject; - private Modality modality; - private Visibility visibility; + protected Modality modality; + protected Visibility visibility; private final Set overriddenFunctions = Sets.newLinkedHashSet(); private final FunctionDescriptor original; - public FunctionDescriptorImpl( + protected FunctionDescriptorImpl( @NotNull DeclarationDescriptor containingDeclaration, @NotNull List annotations, @NotNull String name) { @@ -43,7 +42,7 @@ public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements this.original = this; } - public FunctionDescriptorImpl( + protected FunctionDescriptorImpl( @NotNull FunctionDescriptor original, @NotNull List annotations, @NotNull String name) { @@ -182,32 +181,10 @@ public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements return substitutedDescriptor; } - protected FunctionDescriptorImpl createSubstitutedCopy() { - return new FunctionDescriptorImpl( - this, - // TODO : safeSubstitute - getAnnotations(), - getName()); - } + protected abstract FunctionDescriptorImpl createSubstitutedCopy(); @Override public R accept(DeclarationDescriptorVisitor visitor, D data) { return visitor.visitFunctionDescriptor(this, data); } - - @NotNull - @Override - public FunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract) { - FunctionDescriptorImpl copy = new FunctionDescriptorImpl(newOwner, Lists.newArrayList(getAnnotations()), getName()); - copy.initialize( - getReceiverParameter().exists() ? getReceiverParameter().getType() : null, - expectedThisObject, - DescriptorUtils.copyTypeParameters(copy, typeParameters), - DescriptorUtils.copyValueParameters(copy, unsubstitutedValueParameters), - unsubstitutedReturnType, - DescriptorUtils.convertModality(modality, makeNonAbstract), - visibility - ); - return copy; - } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptor.java index c05c4a308a4..2368a139319 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptor.java @@ -27,7 +27,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme private final Set constructors = Sets.newLinkedHashSet(); private final Set callableMembers = Sets.newHashSet(); private final Set properties = Sets.newHashSet(); - private final Set functions = Sets.newHashSet(); + private final Set functions = Sets.newHashSet(); private List typeParameters = Lists.newArrayList(); private Collection supertypes = Lists.newArrayList(); private Map innerClassesAndObjects = Maps.newHashMap(); @@ -153,7 +153,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme } @Override - public void addFunctionDescriptor(@NotNull FunctionDescriptor functionDescriptor) { + public void addFunctionDescriptor(@NotNull NamedFunctionDescriptor functionDescriptor) { functions.add(functionDescriptor); callableMembers.add(functionDescriptor); scopeForMemberLookup.addFunctionDescriptor(functionDescriptor); @@ -161,7 +161,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme } @NotNull - public Set getFunctions() { + public Set getFunctions() { return functions; } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamedFunctionDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamedFunctionDescriptor.java new file mode 100644 index 00000000000..803b2d0ade8 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamedFunctionDescriptor.java @@ -0,0 +1,13 @@ +package org.jetbrains.jet.lang.descriptors; + +import org.jetbrains.annotations.NotNull; + +/** + * @author Stepan Koltsov + */ +public interface NamedFunctionDescriptor extends FunctionDescriptor { + + @NotNull + @Override + NamedFunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract); +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamedFunctionDescriptorImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamedFunctionDescriptorImpl.java new file mode 100644 index 00000000000..842fde848c7 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamedFunctionDescriptorImpl.java @@ -0,0 +1,47 @@ +package org.jetbrains.jet.lang.descriptors; + +import com.google.common.collect.Lists; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; +import org.jetbrains.jet.lang.resolve.DescriptorUtils; + +import java.util.List; + +/** + * @author Stepan Koltsov + */ +public class NamedFunctionDescriptorImpl extends FunctionDescriptorImpl implements NamedFunctionDescriptor { + + public NamedFunctionDescriptorImpl(@NotNull DeclarationDescriptor containingDeclaration, @NotNull List annotations, @NotNull String name) { + super(containingDeclaration, annotations, name); + } + + private NamedFunctionDescriptorImpl(@NotNull NamedFunctionDescriptor original, @NotNull List annotations, @NotNull String name) { + super(original, annotations, name); + } + + @Override + protected FunctionDescriptorImpl createSubstitutedCopy() { + return new NamedFunctionDescriptorImpl( + this, + // TODO : safeSubstitute + getAnnotations(), + getName()); + } + + @NotNull + @Override + public NamedFunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract) { + NamedFunctionDescriptorImpl copy = new NamedFunctionDescriptorImpl(newOwner, Lists.newArrayList(getAnnotations()), getName()); + copy.initialize( + getReceiverParameter().exists() ? getReceiverParameter().getType() : null, + expectedThisObject, + DescriptorUtils.copyTypeParameters(copy, typeParameters), + DescriptorUtils.copyValueParameters(copy, unsubstitutedValueParameters), + unsubstitutedReturnType, + DescriptorUtils.convertModality(modality, makeNonAbstract), + visibility + ); + return copy; + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamespaceDescriptorImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamespaceDescriptorImpl.java index 1ebe3a7e1b7..8c0252afe9e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamespaceDescriptorImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamespaceDescriptorImpl.java @@ -49,7 +49,7 @@ public class NamespaceDescriptorImpl extends AbstractNamespaceDescriptorImpl imp } @Override - public void addFunctionDescriptor(@NotNull FunctionDescriptor functionDescriptor) { + public void addFunctionDescriptor(@NotNull NamedFunctionDescriptor functionDescriptor) { memberScope.addFunctionDescriptor(functionDescriptor); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamespaceLike.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamespaceLike.java index 9ccf55baba4..6f74641d910 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamespaceLike.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamespaceLike.java @@ -67,7 +67,7 @@ public interface NamespaceLike extends DeclarationDescriptor { void addObjectDescriptor(@NotNull MutableClassDescriptor objectDescriptor); - void addFunctionDescriptor(@NotNull FunctionDescriptor functionDescriptor); + void addFunctionDescriptor(@NotNull NamedFunctionDescriptor functionDescriptor); void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyDescriptor.java index 7e8ffcf793a..6e7420483f1 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyDescriptor.java @@ -235,10 +235,8 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab newGetter.initialize(getter.getReturnType()); } PropertySetterDescriptor newSetter = setter == null ? null : new PropertySetterDescriptor( - DescriptorUtils.convertModality(setter.getModality(), makeNonAbstract), setter.getVisibility(), - propertyDescriptor, - Lists.newArrayList(setter.getAnnotations()), - setter.hasBody(), setter.isDefault()); + propertyDescriptor, Lists.newArrayList(setter.getAnnotations()), DescriptorUtils.convertModality(setter.getModality(), makeNonAbstract), setter.getVisibility(), + setter.hasBody(), setter.isDefault()); if (newSetter != null) { newSetter.initialize(setter.getValueParameters().get(0).copy(newSetter)); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertySetterDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertySetterDescriptor.java index d2fcd33ffc9..24930919768 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertySetterDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertySetterDescriptor.java @@ -16,12 +16,13 @@ public class PropertySetterDescriptor extends PropertyAccessorDescriptor { private ValueParameterDescriptor parameter; - public PropertySetterDescriptor(@NotNull Modality modality, - @NotNull Visibility visibility, - @NotNull PropertyDescriptor correspondingProperty, - @NotNull List annotations, - boolean hasBody, - boolean isDefault) { + public PropertySetterDescriptor( + @NotNull PropertyDescriptor correspondingProperty, + @NotNull List annotations, + @NotNull Modality modality, + @NotNull Visibility visibility, + boolean hasBody, + boolean isDefault) { super(modality, visibility, correspondingProperty, annotations, "set-" + correspondingProperty.getName(), hasBody, isDefault); if (isDefault) { initializeDefault(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptor.java index 96fec12666b..dd01df6d884 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptor.java @@ -42,6 +42,7 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement return new TypeParameterDescriptor(containingDeclaration, annotations, reified, variance, name, index); } + // 0-based private final int index; private final Variance variance; private final Set upperBounds; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/VariableAsFunctionDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/VariableAsFunctionDescriptor.java index 59670106531..744bb7729f0 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/VariableAsFunctionDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/VariableAsFunctionDescriptor.java @@ -34,4 +34,9 @@ public class VariableAsFunctionDescriptor extends FunctionDescriptorImpl { public VariableAsFunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract) { throw new UnsupportedOperationException("Should not be copied for overriding"); } + + @Override + protected FunctionDescriptorImpl createSubstitutedCopy() { + throw new IllegalStateException(); + } } \ No newline at end of file diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java index b1cc74fdea5..6faa4c683b7 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java @@ -129,11 +129,11 @@ public interface Errors { return super.on(elementToBlame, nodeToMark, s, classDescriptor, modifierListOwner).add(DiagnosticParameters.CLASS, modifierListOwner); } }; - PsiElementOnlyDiagnosticFactory1 ABSTRACT_FUNCTION_WITH_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "A function {0} with body cannot be abstract"); - PsiElementOnlyDiagnosticFactory1 NON_ABSTRACT_FUNCTION_WITH_NO_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Method {0} without a body must be abstract"); - PsiElementOnlyDiagnosticFactory1 NON_MEMBER_ABSTRACT_FUNCTION = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Function {0} is not a class or trait member and cannot be abstract"); + PsiElementOnlyDiagnosticFactory1 ABSTRACT_FUNCTION_WITH_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "A function {0} with body cannot be abstract"); + PsiElementOnlyDiagnosticFactory1 NON_ABSTRACT_FUNCTION_WITH_NO_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Method {0} without a body must be abstract"); + PsiElementOnlyDiagnosticFactory1 NON_MEMBER_ABSTRACT_FUNCTION = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Function {0} is not a class or trait member and cannot be abstract"); - PsiElementOnlyDiagnosticFactory1 NON_MEMBER_FUNCTION_NO_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Function {0} must have a body"); + PsiElementOnlyDiagnosticFactory1 NON_MEMBER_FUNCTION_NO_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Function {0} must have a body"); DiagnosticWithParameterFactory NON_FINAL_MEMBER_IN_FINAL_CLASS = DiagnosticWithParameterFactory.create(ERROR, "Non final member in a final class", DiagnosticParameters.CLASS); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java index 9f716f07039..2ccace9af81 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java @@ -32,7 +32,7 @@ public class JetExpressionParsing extends AbstractJetParsing { private static final TokenSet TYPE_ARGUMENT_LIST_STOPPERS = TokenSet.create( INTEGER_LITERAL, FLOAT_LITERAL, CHARACTER_LITERAL, OPEN_QUOTE, RAW_STRING_LITERAL, - NAMESPACE_KEYWORD, AS_KEYWORD, TYPE_KEYWORD, TRAIT_KEYWORD, CLASS_KEYWORD, THIS_KEYWORD, VAL_KEYWORD, VAR_KEYWORD, + PACKAGE_KEYWORD, AS_KEYWORD, TYPE_KEYWORD, TRAIT_KEYWORD, CLASS_KEYWORD, THIS_KEYWORD, VAL_KEYWORD, VAR_KEYWORD, FUN_KEYWORD, FOR_KEYWORD, NULL_KEYWORD, TRUE_KEYWORD, FALSE_KEYWORD, IS_KEYWORD, THROW_KEYWORD, RETURN_KEYWORD, BREAK_KEYWORD, CONTINUE_KEYWORD, OBJECT_KEYWORD, IF_KEYWORD, TRY_KEYWORD, ELSE_KEYWORD, WHILE_KEYWORD, DO_KEYWORD, @@ -83,7 +83,7 @@ public class JetExpressionParsing extends AbstractJetParsing { IDENTIFIER, // SimpleName FIELD_IDENTIFIER, // Field reference - NAMESPACE_KEYWORD // for absolute qualified names + PACKAGE_KEYWORD // for absolute qualified names ); private static final TokenSet STATEMENT_FIRST = TokenSet.orSet( @@ -509,7 +509,7 @@ public class JetExpressionParsing extends AbstractJetParsing { else if (at(HASH)) { parseTupleExpression(); } - else if (at(NAMESPACE_KEYWORD)) { + else if (at(PACKAGE_KEYWORD)) { parseOneTokenExpression(ROOT_NAMESPACE); } else if (at(THIS_KEYWORD)) { @@ -865,7 +865,7 @@ public class JetExpressionParsing extends AbstractJetParsing { myJetParsing.parseAnnotations(false); - if (at(NAMESPACE_KEYWORD) || at(IDENTIFIER) || at(FUN_KEYWORD) || at(THIS_KEYWORD)) { + if (at(PACKAGE_KEYWORD) || at(IDENTIFIER) || at(FUN_KEYWORD) || at(THIS_KEYWORD)) { PsiBuilder.Marker rollbackMarker = mark(); parseBinaryExpression(Precedence.ELVIS); if (at(HASH)) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java index e61adb089d5..fd72c80bf09 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java @@ -29,7 +29,7 @@ public class JetParsing extends AbstractJetParsing { } private static final TokenSet TOPLEVEL_OBJECT_FIRST = TokenSet.create(TYPE_KEYWORD, TRAIT_KEYWORD, CLASS_KEYWORD, - FUN_KEYWORD, VAL_KEYWORD, NAMESPACE_KEYWORD); + FUN_KEYWORD, VAL_KEYWORD, PACKAGE_KEYWORD); private static final TokenSet ENUM_MEMBER_FIRST = TokenSet.create(TYPE_KEYWORD, TRAIT_KEYWORD, CLASS_KEYWORD, FUN_KEYWORD, VAL_KEYWORD, IDENTIFIER); @@ -117,8 +117,8 @@ public class JetParsing extends AbstractJetParsing { PsiBuilder.Marker firstEntry = mark(); parseModifierList(MODIFIER_LIST, true); - if (at(NAMESPACE_KEYWORD)) { - advance(); // NAMESPACE_KEYWORD + if (at(PACKAGE_KEYWORD)) { + advance(); // PACKAGE_KEYWORD parseNamespaceName(); if (at(LBRACE)) { @@ -170,8 +170,8 @@ public class JetParsing extends AbstractJetParsing { advance(); // IMPORT_KEYWORD PsiBuilder.Marker qualifiedName = mark(); - if (at(NAMESPACE_KEYWORD)) { - advance(); // NAMESPACE_KEYWORD + if (at(PACKAGE_KEYWORD)) { + advance(); // PACKAGE_KEYWORD expect(DOT, "Expecting '.'", TokenSet.create(IDENTIFIER, MUL, SEMICOLON)); } @@ -233,7 +233,7 @@ public class JetParsing extends AbstractJetParsing { IElementType keywordToken = tt(); JetNodeType declType = null; -// if (keywordToken == NAMESPACE_KEYWORD) { +// if (keywordToken == PACKAGE_KEYWORD) { // declType = parseNamespaceBlock(); // } // else @@ -640,7 +640,7 @@ public class JetParsing extends AbstractJetParsing { parseClassBody(); } else { - expect(COLON, "Expecting ':'", TokenSet.create(IDENTIFIER, NAMESPACE_KEYWORD)); + expect(COLON, "Expecting ':'", TokenSet.create(IDENTIFIER, PACKAGE_KEYWORD)); parseDelegationSpecifierList(); parseClassBody(); } @@ -1253,7 +1253,7 @@ public class JetParsing extends AbstractJetParsing { PsiBuilder.Marker typeRefMarker = mark(); parseAnnotations(false); - if (at(IDENTIFIER) || at(NAMESPACE_KEYWORD)) { + if (at(IDENTIFIER) || at(PACKAGE_KEYWORD)) { parseUserType(); } else if (at(HASH)) { @@ -1340,8 +1340,8 @@ public class JetParsing extends AbstractJetParsing { private void parseUserType() { PsiBuilder.Marker userType = mark(); - if (at(NAMESPACE_KEYWORD)) { - advance(); // NAMESPACE_KEYWORD + if (at(PACKAGE_KEYWORD)) { + advance(); // PACKAGE_KEYWORD expect(DOT, "Expecting '.'", TokenSet.create(IDENTIFIER)); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetImportDirective.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetImportDirective.java index fbf5d660496..6251773488d 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetImportDirective.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetImportDirective.java @@ -25,7 +25,7 @@ public class JetImportDirective extends JetElement { } public boolean isAbsoluteInRootNamespace() { - return findChildByType(JetTokens.NAMESPACE_KEYWORD) != null; + return findChildByType(JetTokens.PACKAGE_KEYWORD) != null; } @Nullable @IfNotParsed diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetUserType.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetUserType.java index 5c754b83ed1..aa1b5880623 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetUserType.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetUserType.java @@ -19,7 +19,7 @@ public class JetUserType extends JetTypeElement { } public boolean isAbsoluteInRootNamespace() { - return findChildByType(JetTokens.NAMESPACE_KEYWORD) != null; + return findChildByType(JetTokens.PACKAGE_KEYWORD) != null; } @Override diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnalyzingUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnalyzingUtils.java index 6ed05150f5f..3edb5e6a0ae 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnalyzingUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnalyzingUtils.java @@ -122,7 +122,7 @@ public class AnalyzingUtils { } @Override - public void addFunctionDescriptor(@NotNull FunctionDescriptor functionDescriptor) { + public void addFunctionDescriptor(@NotNull NamedFunctionDescriptor functionDescriptor) { scope.addFunctionDescriptor(functionDescriptor); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContext.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContext.java index 4cc757284ef..a0fe615ff63 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContext.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContext.java @@ -117,7 +117,7 @@ public interface BindingContext { WritableSlice NAMESPACE = Slices.sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build(); WritableSlice CLASS = Slices.sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build(); WritableSlice TYPE_PARAMETER = Slices.sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build(); - WritableSlice FUNCTION = Slices.sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build(); + WritableSlice FUNCTION = Slices.sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build(); WritableSlice CONSTRUCTOR = Slices.sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build(); WritableSlice VARIABLE = Slices.sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build(); WritableSlice VALUE_PARAMETER = Slices.sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java index 171a69870b3..a0c94512896 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java @@ -467,9 +467,9 @@ public class BodyResolver { } private void resolveFunctionBodies() { - for (Map.Entry entry : this.context.getFunctions().entrySet()) { + for (Map.Entry entry : this.context.getFunctions().entrySet()) { JetNamedFunction declaration = entry.getKey(); - FunctionDescriptor descriptor = entry.getValue(); + NamedFunctionDescriptor descriptor = entry.getValue(); computeDeferredType(descriptor.getReturnType()); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ControlFlowAnalyzer.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ControlFlowAnalyzer.java index d56355f1331..47bbf55705d 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ControlFlowAnalyzer.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ControlFlowAnalyzer.java @@ -34,9 +34,9 @@ public class ControlFlowAnalyzer { if (!context.completeAnalysisNeeded(objectDeclaration)) continue; checkClassOrObject(objectDeclaration); } - for (Map.Entry entry : context.getFunctions().entrySet()) { + for (Map.Entry entry : context.getFunctions().entrySet()) { JetNamedFunction function = entry.getKey(); - FunctionDescriptorImpl functionDescriptor = entry.getValue(); + NamedFunctionDescriptor functionDescriptor = entry.getValue(); if (!context.completeAnalysisNeeded(function)) continue; final JetType expectedReturnType = !function.hasBlockBody() && !function.hasDeclaredReturnType() ? NO_EXPECTED_TYPE diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationResolver.java index 47071e7a1d9..9cb35b42de3 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationResolver.java @@ -103,7 +103,7 @@ public class DeclarationResolver { declaration.accept(new JetVisitorVoid() { @Override public void visitNamedFunction(JetNamedFunction function) { - FunctionDescriptorImpl functionDescriptor = context.getDescriptorResolver().resolveFunctionDescriptor(namespaceLike, scopeForFunctions, function); + NamedFunctionDescriptor functionDescriptor = context.getDescriptorResolver().resolveFunctionDescriptor(namespaceLike, scopeForFunctions, function); namespaceLike.addFunctionDescriptor(functionDescriptor); context.getFunctions().put(function, functionDescriptor); context.getDeclaringScopes().put(function, scopeForFunctions); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationsChecker.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationsChecker.java index 94ea67e824e..a96b6c41d82 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationsChecker.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationsChecker.java @@ -55,10 +55,10 @@ public class DeclarationsChecker { checkObject(objectDeclaration, objectDescriptor); } - Map functions = context.getFunctions(); - for (Map.Entry entry : functions.entrySet()) { + Map functions = context.getFunctions(); + for (Map.Entry entry : functions.entrySet()) { JetNamedFunction function = entry.getKey(); - FunctionDescriptorImpl functionDescriptor = entry.getValue(); + NamedFunctionDescriptor functionDescriptor = entry.getValue(); if (!context.completeAnalysisNeeded(function)) continue; checkFunction(function, functionDescriptor); @@ -254,7 +254,7 @@ public class DeclarationsChecker { } } - protected void checkFunction(JetNamedFunction function, FunctionDescriptor functionDescriptor) { + protected void checkFunction(JetNamedFunction function, NamedFunctionDescriptor functionDescriptor) { DeclarationDescriptor containingDescriptor = functionDescriptor.getContainingDeclaration(); PsiElement nameIdentifier = function.getNameIdentifier(); JetModifierList modifierList = function.getModifierList(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegationResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegationResolver.java index 9fb7350d280..1fae05541a9 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegationResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegationResolver.java @@ -3,6 +3,7 @@ package org.jetbrains.jet.lang.resolve; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; import org.jetbrains.jet.lang.descriptors.MutableClassDescriptor; +import org.jetbrains.jet.lang.descriptors.NamedFunctionDescriptor; import org.jetbrains.jet.lang.descriptors.PropertyDescriptor; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.types.JetType; @@ -49,10 +50,10 @@ public class DelegationResolver { context.getTrace().record(DELEGATED, copy); } } - else if (declarationDescriptor instanceof FunctionDescriptor) { - FunctionDescriptor functionDescriptor = (FunctionDescriptor) declarationDescriptor; + else if (declarationDescriptor instanceof NamedFunctionDescriptor) { + NamedFunctionDescriptor functionDescriptor = (NamedFunctionDescriptor) declarationDescriptor; if (functionDescriptor.getModality().isOverridable()) { - FunctionDescriptor copy = functionDescriptor.copy(classDescriptor, true); + NamedFunctionDescriptor copy = functionDescriptor.copy(classDescriptor, true); classDescriptor.addFunctionDescriptor(copy); context.getTrace().record(DELEGATED, copy); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java index dd86b8a9fea..d3b7266cfcf 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java @@ -139,8 +139,8 @@ public class DescriptorResolver { } @NotNull - public FunctionDescriptorImpl resolveFunctionDescriptor(DeclarationDescriptor containingDescriptor, final JetScope scope, final JetNamedFunction function) { - final FunctionDescriptorImpl functionDescriptor = new FunctionDescriptorImpl( + public NamedFunctionDescriptor resolveFunctionDescriptor(DeclarationDescriptor containingDescriptor, final JetScope scope, final JetNamedFunction function) { + final NamedFunctionDescriptorImpl functionDescriptor = new NamedFunctionDescriptorImpl( containingDescriptor, annotationResolver.resolveAnnotations(scope, function.getModifierList()), JetPsiUtil.safeName(function.getName()) @@ -276,31 +276,12 @@ public class DescriptorResolver { private JetType getVarargParameterType(JetType type) { JetStandardLibrary standardLibrary = semanticServices.getStandardLibrary(); - if (type.equals(standardLibrary.getByteType())) { - return standardLibrary.getByteArrayType(); + JetType arrayType = standardLibrary.getPrimitiveArrayJetTypeByPrimitiveJetType(type); + if (arrayType != null) { + return arrayType; + } else { + return standardLibrary.getArrayType(type); } - if (type.equals(standardLibrary.getCharType())) { - return standardLibrary.getCharArrayType(); - } - if (type.equals(standardLibrary.getShortType())) { - return standardLibrary.getShortArrayType(); - } - if (type.equals(standardLibrary.getIntType())) { - return standardLibrary.getIntArrayType(); - } - if (type.equals(standardLibrary.getLongType())) { - return standardLibrary.getLongArrayType(); - } - if (type.equals(standardLibrary.getFloatType())) { - return standardLibrary.getFloatArrayType(); - } - if (type.equals(standardLibrary.getDoubleType())) { - return standardLibrary.getDoubleArrayType(); - } - if (type.equals(standardLibrary.getBooleanType())) { - return standardLibrary.getBooleanArrayType(); - } - return standardLibrary.getArrayType(type); } public List resolveTypeParameters(DeclarationDescriptor containingDescriptor, WritableScope extensibleScope, List typeParameters) { @@ -668,9 +649,9 @@ public class DescriptorResolver { JetParameter parameter = setter.getParameter(); setterDescriptor = new PropertySetterDescriptor( - resolveModalityFromModifiers(setter.getModifierList(), propertyDescriptor.getModality()), + propertyDescriptor, annotations, resolveModalityFromModifiers(setter.getModifierList(), propertyDescriptor.getModality()), resolveVisibilityFromModifiers(setter.getModifierList(), propertyDescriptor.getVisibility()), - propertyDescriptor, annotations, setter.getBodyExpression() != null, false); + setter.getBodyExpression() != null, false); if (parameter != null) { if (parameter.isRef()) { // trace.getErrorHandler().genericError(parameter.getRefNode(), "Setter parameters can not be 'ref'"); @@ -728,9 +709,9 @@ public class DescriptorResolver { private PropertySetterDescriptor createDefaultSetter(PropertyDescriptor propertyDescriptor) { PropertySetterDescriptor setterDescriptor; setterDescriptor = new PropertySetterDescriptor( - propertyDescriptor.getModality(), + propertyDescriptor, Collections.emptyList(), propertyDescriptor.getModality(), propertyDescriptor.getVisibility(), - propertyDescriptor, Collections.emptyList(), false, true); + false, true); return setterDescriptor; } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverloadResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverloadResolver.java index 3fd237d3cac..c6143bc21e8 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverloadResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverloadResolver.java @@ -86,7 +86,7 @@ public class OverloadResolver { MultiMap functionsByName = MultiMap.create(); - for (FunctionDescriptorImpl function : context.getFunctions().values()) { + for (NamedFunctionDescriptor function : context.getFunctions().values()) { DeclarationDescriptor containingDeclaration = function.getContainingDeclaration(); if (containingDeclaration instanceof NamespaceDescriptor) { NamespaceDescriptor namespaceDescriptor = (NamespaceDescriptor) containingDeclaration; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalysisContext.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalysisContext.java index db01ad8461b..d0b691bb4ca 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalysisContext.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalysisContext.java @@ -34,7 +34,7 @@ import java.util.Set; protected final Map namespaceDescriptors = Maps.newHashMap(); private final Map declaringScopes = Maps.newHashMap(); - private final Map functions = Maps.newLinkedHashMap(); + private final Map functions = Maps.newLinkedHashMap(); private final Map constructors = Maps.newLinkedHashMap(); private final Map properties = Maps.newLinkedHashMap(); private final Set primaryConstructorParameterProperties = Sets.newHashSet(); @@ -138,7 +138,7 @@ import java.util.Set; return declaringScopes; } - public Map getFunctions() { + public Map getFunctions() { return functions; } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java index 6cf99701e37..30e3f7e9a35 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java @@ -139,7 +139,7 @@ public class TopDownAnalyzer { } @Override - public void addFunctionDescriptor(@NotNull FunctionDescriptor functionDescriptor) { + public void addFunctionDescriptor(@NotNull NamedFunctionDescriptor functionDescriptor) { throw new UnsupportedOperationException(); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ExpressionAsFunctionDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ExpressionAsFunctionDescriptor.java index ba4d91f3983..9b38282eb41 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ExpressionAsFunctionDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ExpressionAsFunctionDescriptor.java @@ -18,4 +18,15 @@ public class ExpressionAsFunctionDescriptor extends FunctionDescriptorImpl { public ExpressionAsFunctionDescriptor(DeclarationDescriptor containingDeclaration, String name) { super(containingDeclaration, Collections.emptyList(), name); } + + @Override + protected FunctionDescriptorImpl createSubstitutedCopy() { + throw new IllegalStateException(); + } + + @NotNull + @Override + public FunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract) { + throw new IllegalStateException(); + } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/ErrorUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/ErrorUtils.java index 3f0628f248a..87c02bed6d3 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/ErrorUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/ErrorUtils.java @@ -126,7 +126,7 @@ public class ErrorUtils { private static final Set ERROR_PROPERTY_GROUP = Collections.singleton(ERROR_PROPERTY); private static FunctionDescriptor createErrorFunction(List typeParameters, List positionedValueArgumentTypes) { - FunctionDescriptorImpl functionDescriptor = new FunctionDescriptorImpl(ERROR_CLASS, Collections.emptyList(), ""); + FunctionDescriptorImpl functionDescriptor = new NamedFunctionDescriptorImpl(ERROR_CLASS, Collections.emptyList(), ""); return functionDescriptor.initialize( null, ReceiverDescriptor.NO_RECEIVER, @@ -139,7 +139,7 @@ public class ErrorUtils { } public static FunctionDescriptor createErrorFunction(int typeParameterCount, List positionedValueParameterTypes) { - return new FunctionDescriptorImpl(ERROR_CLASS, Collections.emptyList(), "").initialize( + return new NamedFunctionDescriptorImpl(ERROR_CLASS, Collections.emptyList(), "").initialize( null, ReceiverDescriptor.NO_RECEIVER, Collections.emptyList(), // TODO diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java index 8ae62f01cee..c79b0c9fc3f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java @@ -4,6 +4,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.io.FileUtil; import com.intellij.psi.PsiFileFactory; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.JetSemanticServices; import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; @@ -50,14 +51,6 @@ public class JetStandardLibrary { private JetScope libraryScope; private ClassDescriptor numberClass; - private ClassDescriptor byteClass; - private ClassDescriptor charClass; - private ClassDescriptor shortClass; - private ClassDescriptor intClass; - private ClassDescriptor longClass; - private ClassDescriptor floatClass; - private ClassDescriptor doubleClass; - private ClassDescriptor booleanClass; private ClassDescriptor stringClass; private ClassDescriptor arrayClass; @@ -65,54 +58,10 @@ public class JetStandardLibrary { private ClassDescriptor typeInfoClass; private ClassDescriptor comparableClass; - private JetType byteType; - private JetType charType; - private JetType shortType; - private JetType intType; - private JetType longType; - private JetType floatType; - private JetType doubleType; - private JetType booleanType; - private JetType stringType; - private JetType nullableByteType; - private JetType nullableCharType; - private JetType nullableShortType; - private JetType nullableIntType; - private JetType nullableLongType; - private JetType nullableFloatType; - private JetType nullableDoubleType; - private JetType nullableBooleanType; private JetType nullableTuple0Type; - private ClassDescriptor byteArrayClass; - private ClassDescriptor charArrayClass; - private ClassDescriptor shortArrayClass; - private ClassDescriptor intArrayClass; - private ClassDescriptor longArrayClass; - private ClassDescriptor floatArrayClass; - private ClassDescriptor doubleArrayClass; - private ClassDescriptor booleanArrayClass; - - private JetType byteArrayType; - private JetType charArrayType; - private JetType shortArrayType; - private JetType intArrayType; - private JetType longArrayType; - private JetType floatArrayType; - private JetType doubleArrayType; - private JetType booleanArrayType; - - private JetType nullableByteArrayType; - private JetType nullableCharArrayType; - private JetType nullableShortArrayType; - private JetType nullableIntArrayType; - private JetType nullableLongArrayType; - private JetType nullableFloatArrayType; - private JetType nullableDoubleArrayType; - private JetType nullableBooleanArrayType; - public JetType getTuple0Type() { return tuple0Type; } @@ -122,6 +71,14 @@ public class JetStandardLibrary { private Set typeInfoFunction; + private EnumMap primitiveTypeToClass; + private EnumMap primitiveTypeToArrayClass; + private EnumMap primitiveTypeToJetType; + private EnumMap primitiveTypeToNullableJetType; + private EnumMap primitiveTypeToArrayJetType; + private EnumMap primitiveTypeToNullableArrayJetType; + private Map primitiveJetTypeToJetArrayType; + private JetStandardLibrary(@NotNull Project project) { // TODO : review List libraryFiles = Arrays.asList( @@ -168,14 +125,6 @@ public class JetStandardLibrary { if(libraryScope == null) { this.libraryScope = JetStandardClasses.STANDARD_CLASSES_NAMESPACE.getMemberScope(); this.numberClass = (ClassDescriptor) libraryScope.getClassifier("Number"); - this.byteClass = (ClassDescriptor) libraryScope.getClassifier("Byte"); - this.charClass = (ClassDescriptor) libraryScope.getClassifier("Char"); - this.shortClass = (ClassDescriptor) libraryScope.getClassifier("Short"); - this.intClass = (ClassDescriptor) libraryScope.getClassifier("Int"); - this.longClass = (ClassDescriptor) libraryScope.getClassifier("Long"); - this.floatClass = (ClassDescriptor) libraryScope.getClassifier("Float"); - this.doubleClass = (ClassDescriptor) libraryScope.getClassifier("Double"); - this.booleanClass = (ClassDescriptor) libraryScope.getClassifier("Boolean"); this.stringClass = (ClassDescriptor) libraryScope.getClassifier("String"); this.arrayClass = (ClassDescriptor) libraryScope.getClassifier("Array"); @@ -185,59 +134,41 @@ public class JetStandardLibrary { this.typeInfoClass = (ClassDescriptor) libraryScope.getClassifier("TypeInfo"); this.typeInfoFunction = libraryScope.getFunctions("typeinfo"); - this.byteType = new JetTypeImpl(getByte()); - this.charType = new JetTypeImpl(getChar()); - this.shortType = new JetTypeImpl(getShort()); - this.intType = new JetTypeImpl(getInt()); - this.longType = new JetTypeImpl(getLong()); - this.floatType = new JetTypeImpl(getFloat()); - this.doubleType = new JetTypeImpl(getDouble()); - this.booleanType = new JetTypeImpl(getBoolean()); - this.stringType = new JetTypeImpl(getString()); this.nullableStringType = TypeUtils.makeNullable(stringType); this.tuple0Type = new JetTypeImpl(JetStandardClasses.getTuple(0)); this.nullableTuple0Type = TypeUtils.makeNullable(tuple0Type); + + primitiveTypeToClass = new EnumMap(PrimitiveType.class); + primitiveTypeToJetType = new EnumMap(PrimitiveType.class); + primitiveTypeToNullableJetType = new EnumMap(PrimitiveType.class); + primitiveTypeToArrayClass = new EnumMap(PrimitiveType.class); + primitiveTypeToArrayJetType = new EnumMap(PrimitiveType.class); + primitiveTypeToNullableArrayJetType = new EnumMap(PrimitiveType.class); + primitiveJetTypeToJetArrayType = new HashMap(); - this.nullableByteType = TypeUtils.makeNullable(byteType); - this.nullableCharType = TypeUtils.makeNullable(charType); - this.nullableShortType = TypeUtils.makeNullable(shortType); - this.nullableIntType = TypeUtils.makeNullable(intType); - this.nullableLongType = TypeUtils.makeNullable(longType); - this.nullableFloatType = TypeUtils.makeNullable(floatType); - this.nullableDoubleType = TypeUtils.makeNullable(doubleType); - this.nullableBooleanType = TypeUtils.makeNullable(booleanType); - - this.byteArrayClass = (ClassDescriptor) libraryScope.getClassifier("ByteArray"); - this.charArrayClass = (ClassDescriptor) libraryScope.getClassifier("CharArray"); - this.shortArrayClass = (ClassDescriptor) libraryScope.getClassifier("ShortArray"); - this.intArrayClass = (ClassDescriptor) libraryScope.getClassifier("IntArray"); - this.longArrayClass = (ClassDescriptor) libraryScope.getClassifier("LongArray"); - this.floatArrayClass = (ClassDescriptor) libraryScope.getClassifier("FloatArray"); - this.doubleArrayClass = (ClassDescriptor) libraryScope.getClassifier("DoubleArray"); - this.booleanArrayClass = (ClassDescriptor) libraryScope.getClassifier("BooleanArray"); - - this.byteArrayType = new JetTypeImpl(byteArrayClass); - this.charArrayType = new JetTypeImpl(charArrayClass); - this.shortArrayType = new JetTypeImpl(shortArrayClass); - this.intArrayType = new JetTypeImpl(intArrayClass); - this.longArrayType = new JetTypeImpl(longArrayClass); - this.floatArrayType = new JetTypeImpl(floatArrayClass); - this.doubleArrayType = new JetTypeImpl(doubleArrayClass); - this.booleanArrayType = new JetTypeImpl(booleanArrayClass); - - this.nullableByteArrayType = TypeUtils.makeNullable(byteArrayType); - this.nullableCharArrayType = TypeUtils.makeNullable(charArrayType); - this.nullableShortArrayType = TypeUtils.makeNullable(shortArrayType); - this.nullableIntArrayType = TypeUtils.makeNullable(intArrayType); - this.nullableLongArrayType = TypeUtils.makeNullable(longArrayType); - this.nullableFloatArrayType = TypeUtils.makeNullable(floatArrayType); - this.nullableDoubleArrayType = TypeUtils.makeNullable(doubleArrayType); - this.nullableBooleanArrayType = TypeUtils.makeNullable(booleanArrayType); + for (PrimitiveType primitive : PrimitiveType.values()) { + makePrimitive(primitive); + } } } + private void makePrimitive(PrimitiveType primitiveType) { + ClassDescriptor clazz = (ClassDescriptor) libraryScope.getClassifier(primitiveType.getTypeName()); + ClassDescriptor arrayClazz = (ClassDescriptor) libraryScope.getClassifier(primitiveType.getTypeName() + "Array"); + JetTypeImpl type = new JetTypeImpl(clazz); + JetTypeImpl arrayType = new JetTypeImpl(arrayClazz); + + primitiveTypeToClass.put(primitiveType, clazz); + primitiveTypeToJetType.put(primitiveType, type); + primitiveTypeToNullableJetType.put(primitiveType, TypeUtils.makeNullable(type)); + primitiveTypeToArrayClass.put(primitiveType, arrayClazz); + primitiveTypeToArrayJetType.put(primitiveType, arrayType); + primitiveTypeToNullableArrayJetType.put(primitiveType, TypeUtils.makeNullable(arrayType)); + primitiveJetTypeToJetArrayType.put(type, arrayType); + } + @NotNull public ClassDescriptor getNumber() { initStdClasses(); @@ -245,51 +176,49 @@ public class JetStandardLibrary { } @NotNull - public ClassDescriptor getByte() { + public ClassDescriptor getPrimitiveClassDescriptor(PrimitiveType primitiveType) { initStdClasses(); - return byteClass; + return primitiveTypeToClass.get(primitiveType); + } + + @NotNull + public ClassDescriptor getByte() { + return getPrimitiveClassDescriptor(PrimitiveType.BYTE); } @NotNull public ClassDescriptor getChar() { - initStdClasses(); - return charClass; + return getPrimitiveClassDescriptor(PrimitiveType.CHAR); } @NotNull public ClassDescriptor getShort() { - initStdClasses(); - return shortClass; + return getPrimitiveClassDescriptor(PrimitiveType.SHORT); } @NotNull public ClassDescriptor getInt() { - initStdClasses(); - return intClass; + return getPrimitiveClassDescriptor(PrimitiveType.INT); } @NotNull public ClassDescriptor getLong() { - initStdClasses(); - return longClass; + return getPrimitiveClassDescriptor(PrimitiveType.LONG); } @NotNull public ClassDescriptor getFloat() { - initStdClasses(); - return floatClass; + return getPrimitiveClassDescriptor(PrimitiveType.FLOAT); } @NotNull public ClassDescriptor getDouble() { - initStdClasses(); - return doubleClass; + return getPrimitiveClassDescriptor(PrimitiveType.DOUBLE); } @NotNull public ClassDescriptor getBoolean() { - initStdClasses(); - return booleanClass; + return getPrimitiveClassDescriptor(PrimitiveType.BOOLEAN); } @NotNull @@ -338,40 +267,39 @@ public class JetStandardLibrary { return new JetTypeImpl(Collections.emptyList(), getTypeInfo().getTypeConstructor(), false, arguments, getTypeInfo().getMemberScope(arguments)); } + @NotNull + public JetType getPrimitiveJetType(PrimitiveType primitiveType) { + return primitiveTypeToJetType.get(primitiveType); + } + @NotNull public JetType getIntType() { - initStdClasses(); - return intType; + return getPrimitiveJetType(PrimitiveType.INT); } @NotNull public JetType getLongType() { - initStdClasses(); - return longType; + return getPrimitiveJetType(PrimitiveType.LONG); } @NotNull public JetType getDoubleType() { - initStdClasses(); - return doubleType; + return getPrimitiveJetType(PrimitiveType.DOUBLE); } @NotNull public JetType getFloatType() { - initStdClasses(); - return floatType; + return getPrimitiveJetType(PrimitiveType.FLOAT); } @NotNull public JetType getCharType() { - initStdClasses(); - return charType; + return getPrimitiveJetType(PrimitiveType.CHAR); } @NotNull public JetType getBooleanType() { - initStdClasses(); - return booleanType; + return getPrimitiveJetType(PrimitiveType.BOOLEAN); } @NotNull @@ -382,14 +310,12 @@ public class JetStandardLibrary { @NotNull public JetType getByteType() { - initStdClasses(); - return byteType; + return getPrimitiveJetType(PrimitiveType.BYTE); } @NotNull public JetType getShortType() { - initStdClasses(); - return shortType; + return getPrimitiveJetType(PrimitiveType.SHORT); } @NotNull @@ -431,168 +357,42 @@ public class JetStandardLibrary { return nullableStringType; } - public JetType getNullableByteType() { + @NotNull + public JetType getNullablePrimitiveJetType(PrimitiveType primitiveType) { initStdClasses(); - return nullableByteType; - } - - public JetType getNullableCharType() { - initStdClasses(); - return nullableCharType; - } - - public JetType getNullableShortType() { - initStdClasses(); - return nullableShortType; - } - - public JetType getNullableIntType() { - initStdClasses(); - return nullableIntType; - } - - public JetType getNullableLongType() { - initStdClasses(); - return nullableLongType; - } - - public JetType getNullableFloatType() { - initStdClasses(); - return nullableFloatType; - } - - public JetType getNullableDoubleType() { - initStdClasses(); - return nullableDoubleType; - } - - public JetType getNullableBooleanType() { - initStdClasses(); - return nullableBooleanType; + return primitiveTypeToNullableJetType.get(primitiveType); } public JetType getNullableTuple0Type() { initStdClasses(); return nullableTuple0Type; } - - public JetType getBooleanArrayType() { - initStdClasses(); - return booleanArrayType; - } - - public JetType getByteArrayType() { - initStdClasses(); - return byteArrayType; - } - - public JetType getCharArrayType() { - initStdClasses(); - return charArrayType; - } - - public JetType getShortArrayType() { - initStdClasses(); - return shortArrayType; - } - - public JetType getIntArrayType() { - initStdClasses(); - return intArrayType; - } - - public JetType getLongArrayType() { - initStdClasses(); - return longArrayType; - } - - public JetType getFloatArrayType() { - initStdClasses(); - return floatArrayType; - } - - public JetType getDoubleArrayType() { - initStdClasses(); - return doubleArrayType; - } - public JetType getPrimitiveArrayType(JetType jetType) { - if (jetType.equals(getIntType())) { - return getIntArrayType(); - } else { - throw new IllegalStateException("not implemented"); - } - } - - public ClassDescriptor getByteArrayClass() { + @NotNull + public JetType getPrimitiveArrayJetType(PrimitiveType primitiveType) { initStdClasses(); - return byteArrayClass; + return primitiveTypeToArrayJetType.get(primitiveType); } - public ClassDescriptor getCharArrayClass() { + /** + * @return null if not primitive + */ + @Nullable + public JetType getPrimitiveArrayJetTypeByPrimitiveJetType(JetType jetType) { + return primitiveJetTypeToJetArrayType.get(jetType); + } + + @NotNull + public ClassDescriptor getPrimitiveArrayClassDescriptor(PrimitiveType primitiveType) { initStdClasses(); - return charArrayClass; + return primitiveTypeToArrayClass.get(primitiveType); } - public ClassDescriptor getShortArrayClass() { + + @NotNull + public JetType getNullablePrimitiveArrayJetType(PrimitiveType primitiveType) { initStdClasses(); - return shortArrayClass; + return primitiveTypeToNullableArrayJetType.get(primitiveType); } - public ClassDescriptor getIntArrayClass() { - initStdClasses(); - return intArrayClass; - } - - public ClassDescriptor getLongArrayClass() { - initStdClasses(); - return longArrayClass; - } - - public ClassDescriptor getFloatArrayClass() { - initStdClasses(); - return floatArrayClass; - } - - public ClassDescriptor getDoubleArrayClass() { - initStdClasses(); - return doubleArrayClass; - } - - public ClassDescriptor getBooleanArrayClass() { - initStdClasses(); - return booleanArrayClass; - } - - public JetType getNullableByteArrayType() { - return nullableByteArrayType; - } - - public JetType getNullableCharArrayType() { - return nullableCharArrayType; - } - - public JetType getNullableShortArrayType() { - return nullableShortArrayType; - } - - public JetType getNullableIntArrayType() { - return nullableIntArrayType; - } - - public JetType getNullableLongArrayType() { - return nullableLongArrayType; - } - - public JetType getNullableFloatArrayType() { - return nullableFloatArrayType; - } - - public JetType getNullableDoubleArrayType() { - return nullableDoubleArrayType; - } - - public JetType getNullableBooleanArrayType() { - return nullableBooleanArrayType; - } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/PrimitiveType.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/PrimitiveType.java new file mode 100644 index 00000000000..1896489d5bc --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/PrimitiveType.java @@ -0,0 +1,33 @@ +package org.jetbrains.jet.lang.types; + +/** + * @author Stepan Koltsov + */ +public enum PrimitiveType { + + BOOLEAN("Boolean"), + CHAR("Char"), + BYTE("Byte"), + SHORT("Short"), + INT("Int"), + FLOAT("Float"), + LONG("Long"), + DOUBLE("Double"), + ; + + private final String typeName; + private final String arrayTypeName; + + private PrimitiveType(String typeName) { + this.typeName = typeName; + this.arrayTypeName = typeName + "Array"; + } + + public String getTypeName() { + return typeName; + } + + public String getArrayTypeName() { + return arrayTypeName; + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ClosureExpressionsTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ClosureExpressionsTypingVisitor.java index 52622522ba4..0df6d9c4af1 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ClosureExpressionsTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ClosureExpressionsTypingVisitor.java @@ -68,7 +68,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor { JetType expectedType = context.expectedType; boolean functionTypeExpected = expectedType != TypeUtils.NO_EXPECTED_TYPE && JetStandardClasses.isFunctionType(expectedType); - FunctionDescriptorImpl functionDescriptor = createFunctionDescriptor(expression, context, functionTypeExpected); + NamedFunctionDescriptorImpl functionDescriptor = createFunctionDescriptor(expression, context, functionTypeExpected); List parameterTypes = Lists.newArrayList(); List valueParameters = functionDescriptor.getValueParameters(); @@ -108,10 +108,10 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor { return DataFlowUtils.checkType(JetStandardClasses.getFunctionType(Collections.emptyList(), receiver, parameterTypes, safeReturnType), expression, context); } - private FunctionDescriptorImpl createFunctionDescriptor(JetFunctionLiteralExpression expression, ExpressionTypingContext context, boolean functionTypeExpected) { + private NamedFunctionDescriptorImpl createFunctionDescriptor(JetFunctionLiteralExpression expression, ExpressionTypingContext context, boolean functionTypeExpected) { JetFunctionLiteral functionLiteral = expression.getFunctionLiteral(); JetTypeReference receiverTypeRef = functionLiteral.getReceiverTypeRef(); - FunctionDescriptorImpl functionDescriptor = new FunctionDescriptorImpl( + NamedFunctionDescriptorImpl functionDescriptor = new NamedFunctionDescriptorImpl( context.scope.getContainingDeclaration(), Collections.emptyList(), ""); List valueParameterDescriptors = createValueParameterDescriptors(context, functionLiteral, functionDescriptor, functionTypeExpected); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingVisitorForStatements.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingVisitorForStatements.java index b4eabb934a0..d9684f96950 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingVisitorForStatements.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingVisitorForStatements.java @@ -105,7 +105,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito @Override public JetType visitNamedFunction(JetNamedFunction function, ExpressionTypingContext context) { - FunctionDescriptorImpl functionDescriptor = context.getDescriptorResolver().resolveFunctionDescriptor(scope.getContainingDeclaration(), scope, function); + NamedFunctionDescriptor functionDescriptor = context.getDescriptorResolver().resolveFunctionDescriptor(scope.getContainingDeclaration(), scope, function); scope.addFunctionDescriptor(functionDescriptor); JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(context.scope, functionDescriptor, context.trace); context.getServices().checkFunctionReturnType(functionInnerScope, function, functionDescriptor, context.dataFlowInfo); diff --git a/compiler/frontend/src/org/jetbrains/jet/lexer/Jet.flex b/compiler/frontend/src/org/jetbrains/jet/lexer/Jet.flex index c69a622e730..3e884bc914e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lexer/Jet.flex +++ b/compiler/frontend/src/org/jetbrains/jet/lexer/Jet.flex @@ -162,7 +162,7 @@ LONG_TEMPLATE_ENTRY_END=\} {RAW_STRING_LITERAL} { return JetTokens.RAW_STRING_LITERAL; } "continue" { return JetTokens.CONTINUE_KEYWORD ;} -"package" { return JetTokens.NAMESPACE_KEYWORD ;} +"package" { return JetTokens.PACKAGE_KEYWORD ;} "return" { return JetTokens.RETURN_KEYWORD ;} "object" { return JetTokens.OBJECT_KEYWORD ;} "while" { return JetTokens.WHILE_KEYWORD ;} diff --git a/compiler/frontend/src/org/jetbrains/jet/lexer/JetTokens.java b/compiler/frontend/src/org/jetbrains/jet/lexer/JetTokens.java index e2cd5e0282f..aa7e63da6c0 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lexer/JetTokens.java +++ b/compiler/frontend/src/org/jetbrains/jet/lexer/JetTokens.java @@ -31,7 +31,7 @@ public interface JetTokens { JetToken RAW_STRING_LITERAL = new JetToken("RAW_STRING_LITERAL"); - JetKeywordToken NAMESPACE_KEYWORD = JetKeywordToken.keyword("namespace"); + JetKeywordToken PACKAGE_KEYWORD = JetKeywordToken.keyword("package"); JetKeywordToken AS_KEYWORD = JetKeywordToken.keyword("as"); JetKeywordToken TYPE_KEYWORD = JetKeywordToken.keyword("type"); JetKeywordToken CLASS_KEYWORD = JetKeywordToken.keyword("class"); @@ -145,7 +145,7 @@ public interface JetTokens { // TODO: support this as an annotation on arguments. Then, they it probably can not be a soft keyword JetKeywordToken REF_KEYWORD = JetKeywordToken.softKeyword("ref"); - TokenSet KEYWORDS = TokenSet.create(NAMESPACE_KEYWORD, AS_KEYWORD, TYPE_KEYWORD, CLASS_KEYWORD, TRAIT_KEYWORD, + TokenSet KEYWORDS = TokenSet.create(PACKAGE_KEYWORD, AS_KEYWORD, TYPE_KEYWORD, CLASS_KEYWORD, TRAIT_KEYWORD, THIS_KEYWORD, SUPER_KEYWORD, VAL_KEYWORD, VAR_KEYWORD, FUN_KEYWORD, FOR_KEYWORD, NULL_KEYWORD, TRUE_KEYWORD, FALSE_KEYWORD, IS_KEYWORD, diff --git a/compiler/frontend/src/org/jetbrains/jet/lexer/_JetLexer.java b/compiler/frontend/src/org/jetbrains/jet/lexer/_JetLexer.java index cfc7b187828..60eea12256e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lexer/_JetLexer.java +++ b/compiler/frontend/src/org/jetbrains/jet/lexer/_JetLexer.java @@ -1,4 +1,4 @@ -/* The following code was generated by JFlex 1.4.3 on 12/25/11 2:36 PM */ +/* The following code was generated by JFlex 1.4.3 on 1/12/12 7:11 PM */ package org.jetbrains.jet.lexer; @@ -13,7 +13,7 @@ import org.jetbrains.jet.lexer.JetTokens; /** * This class is a scanner generated by * JFlex 1.4.3 - * on 12/25/11 2:36 PM from the specification file + * on 1/12/12 7:11 PM from the specification file * /Users/abreslav/work/jet/compiler/frontend/src/org/jetbrains/jet/lexer/Jet.flex */ class _JetLexer implements FlexLexer { @@ -1006,77 +1006,77 @@ class _JetLexer implements FlexLexer { { return JetTokens.MINUSEQ ; } case 138: break; + case 96: + { return JetTokens.PACKAGE_KEYWORD ; + } + case 139: break; case 87: { return JetTokens.THROW_KEYWORD ; } - case 139: break; + case 140: break; case 89: { return JetTokens.SUPER_KEYWORD ; } - case 140: break; + case 141: break; case 92: { return JetTokens.WHILE_KEYWORD ; } - case 141: break; + case 142: break; case 44: { return JetTokens.MINUSMINUS; } - case 142: break; + case 143: break; case 97: { return JetTokens.CONTINUE_KEYWORD ; } - case 143: break; + case 144: break; case 75: { return JetTokens.NOT_IN; } - case 144: break; + case 145: break; case 38: { return JetTokens.ATAT ; } - case 145: break; + case 146: break; case 6: { return JetTokens.DIV ; } - case 146: break; + case 147: break; case 37: { return JetTokens.LABEL_IDENTIFIER; } - case 147: break; + case 148: break; case 29: { return JetTokens.REGULAR_STRING_PART; } - case 148: break; + case 149: break; case 16: { return JetTokens.QUEST ; } - case 149: break; + case 150: break; case 60: { return JetTokens.OROR ; } - case 150: break; + case 151: break; case 20: { return JetTokens.PERC ; } - case 151: break; + case 152: break; case 76: { return JetTokens.EXCLEQEQEQ; } - case 152: break; + case 153: break; case 61: { return JetTokens.PERCEQ ; } - case 153: break; + case 154: break; case 43: { return JetTokens.RANGE ; } - case 154: break; + case 155: break; case 1: { return TokenType.BAD_CHARACTER; } - case 155: break; - case 96: - { return JetTokens.NAMESPACE_KEYWORD ; - } case 156: break; case 74: { return JetTokens.NOT_IS; diff --git a/compiler/frontend/src/org/jetbrains/jet/resolve/DescriptorRenderer.java b/compiler/frontend/src/org/jetbrains/jet/resolve/DescriptorRenderer.java index 1499f8669da..7db14516299 100644 --- a/compiler/frontend/src/org/jetbrains/jet/resolve/DescriptorRenderer.java +++ b/compiler/frontend/src/org/jetbrains/jet/resolve/DescriptorRenderer.java @@ -258,7 +258,7 @@ public class DescriptorRenderer implements Renderer { @Override public Void visitNamespaceDescriptor(NamespaceDescriptor namespaceDescriptor, StringBuilder builder) { - builder.append(renderKeyword(JetTokens.NAMESPACE_KEYWORD.getValue())).append(" "); + builder.append(renderKeyword(JetTokens.PACKAGE_KEYWORD.getValue())).append(" "); renderName(namespaceDescriptor, builder); return super.visitNamespaceDescriptor(namespaceDescriptor, builder); } diff --git a/compiler/jet.as.java.psi/jet.as.java.psi.iml b/compiler/jet.as.java.psi/jet.as.java.psi.iml new file mode 100644 index 00000000000..de82ce75e19 --- /dev/null +++ b/compiler/jet.as.java.psi/jet.as.java.psi.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/idea/src/org/jetbrains/jet/plugin/java/ClsWrapperStubPsiFactory.java b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/ClsWrapperStubPsiFactory.java similarity index 98% rename from idea/src/org/jetbrains/jet/plugin/java/ClsWrapperStubPsiFactory.java rename to compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/ClsWrapperStubPsiFactory.java index 9da8650a56e..56febf1699d 100644 --- a/idea/src/org/jetbrains/jet/plugin/java/ClsWrapperStubPsiFactory.java +++ b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/ClsWrapperStubPsiFactory.java @@ -1,7 +1,7 @@ /* * @author max */ -package org.jetbrains.jet.plugin.java; +package org.jetbrains.jet.asJava; import com.intellij.openapi.util.Key; import com.intellij.psi.*; diff --git a/idea/src/org/jetbrains/jet/plugin/java/JavaElementFinder.java b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JavaElementFinder.java similarity index 99% rename from idea/src/org/jetbrains/jet/plugin/java/JavaElementFinder.java rename to compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JavaElementFinder.java index 009ab41711d..ff190f2a1d6 100644 --- a/idea/src/org/jetbrains/jet/plugin/java/JavaElementFinder.java +++ b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JavaElementFinder.java @@ -1,7 +1,7 @@ /* * @author max */ -package org.jetbrains.jet.plugin.java; +package org.jetbrains.jet.asJava; import com.intellij.openapi.compiler.ex.CompilerPathsEx; import com.intellij.openapi.fileTypes.FileType; diff --git a/idea/src/org/jetbrains/jet/plugin/java/JetCodeBlockModificationListener.java b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetCodeBlockModificationListener.java similarity index 97% rename from idea/src/org/jetbrains/jet/plugin/java/JetCodeBlockModificationListener.java rename to compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetCodeBlockModificationListener.java index dd26ab448c4..132cdd32757 100644 --- a/idea/src/org/jetbrains/jet/plugin/java/JetCodeBlockModificationListener.java +++ b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetCodeBlockModificationListener.java @@ -1,7 +1,7 @@ /* * @author max */ -package org.jetbrains.jet.plugin.java; +package org.jetbrains.jet.asJava; import com.intellij.openapi.diagnostic.Logger; import com.intellij.psi.*; @@ -14,7 +14,7 @@ import org.jetbrains.jet.lang.psi.JetClass; import org.jetbrains.jet.lang.psi.JetFile; public class JetCodeBlockModificationListener implements PsiTreeChangePreprocessor { - private static final Logger LOG = Logger.getInstance("#org.jetbrains.jet.plugin.java.JetCodeBlockModificationListener"); + private static final Logger LOG = Logger.getInstance("#org.jetbrains.jet.asJava.JetCodeBlockModificationListener"); private final PsiModificationTrackerImpl myModificationTracker; diff --git a/idea/src/org/jetbrains/jet/plugin/java/JetLightClass.java b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetLightClass.java similarity index 98% rename from idea/src/org/jetbrains/jet/plugin/java/JetLightClass.java rename to compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetLightClass.java index d1c9036f035..5df0de584f9 100644 --- a/idea/src/org/jetbrains/jet/plugin/java/JetLightClass.java +++ b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetLightClass.java @@ -1,7 +1,7 @@ /* * @author max */ -package org.jetbrains.jet.plugin.java; +package org.jetbrains.jet.asJava; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; @@ -36,7 +36,7 @@ import java.util.Collections; import java.util.List; public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMarker { - private static final Logger LOG = Logger.getInstance("#org.jetbrains.jet.plugin.java.JetLightClass"); + private static final Logger LOG = Logger.getInstance("#org.jetbrains.jet.asJava.JetLightClass"); private final static Key> JAVA_API_STUB = Key.create("JAVA_API_STUB"); private final JetFile file; diff --git a/idea/src/org/jetbrains/jet/plugin/java/StubClassBuilder.java b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/StubClassBuilder.java similarity index 98% rename from idea/src/org/jetbrains/jet/plugin/java/StubClassBuilder.java rename to compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/StubClassBuilder.java index c5714910e67..20b300c6aad 100644 --- a/idea/src/org/jetbrains/jet/plugin/java/StubClassBuilder.java +++ b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/StubClassBuilder.java @@ -1,7 +1,7 @@ /* * @author max */ -package org.jetbrains.jet.plugin.java; +package org.jetbrains.jet.asJava; import com.intellij.psi.PsiElement; import com.intellij.psi.impl.compiled.InnerClassSourceStrategy; diff --git a/compiler/testData/psi/Attributes.txt b/compiler/testData/psi/Attributes.txt index d1dfe903a18..1402e8b4ad0 100644 --- a/compiler/testData/psi/Attributes.txt +++ b/compiler/testData/psi/Attributes.txt @@ -1,6 +1,6 @@ JetFile: Attributes.jet NAMESPACE_HEADER - PsiElement(namespace)('package') + PsiElement(package)('package') PsiWhiteSpace(' ') REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('foo') diff --git a/compiler/testData/psi/Attributes_ERR.txt b/compiler/testData/psi/Attributes_ERR.txt index 6c5ccaa76e3..7450c8379a6 100644 --- a/compiler/testData/psi/Attributes_ERR.txt +++ b/compiler/testData/psi/Attributes_ERR.txt @@ -1,6 +1,6 @@ JetFile: Attributes_ERR.jet NAMESPACE_HEADER - PsiElement(namespace)('package') + PsiElement(package)('package') PsiWhiteSpace(' ') REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('foo') diff --git a/compiler/testData/psi/BabySteps.txt b/compiler/testData/psi/BabySteps.txt index 4031aa393da..636cc72cb27 100644 --- a/compiler/testData/psi/BabySteps.txt +++ b/compiler/testData/psi/BabySteps.txt @@ -1,6 +1,6 @@ JetFile: BabySteps.jet NAMESPACE_HEADER - PsiElement(namespace)('package') + PsiElement(package)('package') PsiWhiteSpace(' ') PsiElement(IDENTIFIER)('foo') PsiWhiteSpace('\n\n') diff --git a/compiler/testData/psi/BabySteps_ERR.txt b/compiler/testData/psi/BabySteps_ERR.txt index c961672268c..2a72185da8b 100644 --- a/compiler/testData/psi/BabySteps_ERR.txt +++ b/compiler/testData/psi/BabySteps_ERR.txt @@ -1,6 +1,6 @@ JetFile: BabySteps_ERR.jet NAMESPACE_HEADER - PsiElement(namespace)('package') + PsiElement(package)('package') PsiWhiteSpace(' ') PsiElement(IDENTIFIER)('foo') PsiWhiteSpace('\n\n') diff --git a/compiler/testData/psi/FileStart_ERR.txt b/compiler/testData/psi/FileStart_ERR.txt index 03b700f38f5..5730db1fdf6 100644 --- a/compiler/testData/psi/FileStart_ERR.txt +++ b/compiler/testData/psi/FileStart_ERR.txt @@ -4,7 +4,7 @@ JetFile: FileStart_ERR.jet PsiErrorElement:Expecting namespace or top level declaration PsiElement(DIV)('/') PsiErrorElement:Expecting namespace or top level declaration - PsiElement(namespace)('package') + PsiElement(package)('package') PsiWhiteSpace(' ') MODIFIER_LIST ANNOTATION_ENTRY diff --git a/compiler/testData/psi/Imports.txt b/compiler/testData/psi/Imports.txt index 48e5b72e922..d044b7d9fa9 100644 --- a/compiler/testData/psi/Imports.txt +++ b/compiler/testData/psi/Imports.txt @@ -1,6 +1,6 @@ JetFile: Imports.jet NAMESPACE_HEADER - PsiElement(namespace)('package') + PsiElement(package)('package') PsiWhiteSpace(' ') REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('foo') @@ -13,7 +13,7 @@ JetFile: Imports.jet IMPORT_DIRECTIVE PsiElement(import)('import') PsiWhiteSpace(' ') - PsiElement(namespace)('package') + PsiElement(package)('package') PsiElement(DOT)('.') REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('foo') diff --git a/compiler/testData/psi/Imports_ERR.txt b/compiler/testData/psi/Imports_ERR.txt index d0e3d785f1f..392807d8234 100644 --- a/compiler/testData/psi/Imports_ERR.txt +++ b/compiler/testData/psi/Imports_ERR.txt @@ -1,6 +1,6 @@ JetFile: Imports_ERR.jet NAMESPACE_HEADER - PsiElement(namespace)('package') + PsiElement(package)('package') PsiWhiteSpace(' ') REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('foo') @@ -13,7 +13,7 @@ JetFile: Imports_ERR.jet IMPORT_DIRECTIVE PsiElement(import)('import') PsiWhiteSpace(' ') - PsiElement(namespace)('package') + PsiElement(package)('package') PsiErrorElement:Expecting '.' PsiWhiteSpace(' ') @@ -25,7 +25,7 @@ JetFile: Imports_ERR.jet IMPORT_DIRECTIVE PsiElement(import)('import') PsiWhiteSpace(' ') - PsiElement(namespace)('package') + PsiElement(package)('package') PsiElement(DOT)('.') REFERENCE_EXPRESSION PsiErrorElement:Expecting qualified name @@ -36,7 +36,7 @@ JetFile: Imports_ERR.jet IMPORT_DIRECTIVE PsiElement(import)('import') PsiWhiteSpace(' ') - PsiElement(namespace)('package') + PsiElement(package)('package') PsiElement(DOT)('.') PsiWhiteSpace(' ') REFERENCE_EXPRESSION diff --git a/compiler/testData/psi/NamespaceBlockFirst.txt b/compiler/testData/psi/NamespaceBlockFirst.txt index ac11709bc2f..c60803e634b 100644 --- a/compiler/testData/psi/NamespaceBlockFirst.txt +++ b/compiler/testData/psi/NamespaceBlockFirst.txt @@ -2,7 +2,7 @@ JetFile: NamespaceBlockFirst.jet NAMESPACE_HEADER PsiErrorElement:Expecting namespace or top level declaration - PsiElement(namespace)('package') + PsiElement(package)('package') PsiWhiteSpace(' ') MODIFIER_LIST ANNOTATION_ENTRY diff --git a/compiler/testData/psi/NamespaceModifiers.txt b/compiler/testData/psi/NamespaceModifiers.txt index 31e0fe0ef42..32ac9441456 100644 --- a/compiler/testData/psi/NamespaceModifiers.txt +++ b/compiler/testData/psi/NamespaceModifiers.txt @@ -13,6 +13,6 @@ JetFile: NamespaceModifiers.jet PsiElement(IDENTIFIER)('a') PsiElement(RBRACKET)(']') PsiWhiteSpace(' ') - PsiElement(namespace)('package') + PsiElement(package)('package') PsiWhiteSpace(' ') PsiElement(IDENTIFIER)('name') \ No newline at end of file diff --git a/compiler/testData/psi/RootNamespace.txt b/compiler/testData/psi/RootNamespace.txt index 677746d57d2..340eb7f8797 100644 --- a/compiler/testData/psi/RootNamespace.txt +++ b/compiler/testData/psi/RootNamespace.txt @@ -1,6 +1,6 @@ JetFile: RootNamespace.jet NAMESPACE_HEADER - PsiElement(namespace)('package') + PsiElement(package)('package') PsiWhiteSpace(' ') REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('foo') @@ -16,7 +16,7 @@ JetFile: RootNamespace.jet TYPE_PARAMETER_LIST PsiErrorElement:Expecting namespace or top level declaration - PsiElement(namespace)('package') + PsiElement(package)('package') PsiWhiteSpace(' ') MODIFIER_LIST ANNOTATION_ENTRY @@ -48,7 +48,7 @@ JetFile: RootNamespace.jet DOT_QUALIFIED_EXPRESSION DOT_QUALIFIED_EXPRESSION ROOT_NAMESPACE - PsiElement(namespace)('package') + PsiElement(package)('package') PsiElement(DOT)('.') REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('foo') @@ -63,7 +63,7 @@ JetFile: RootNamespace.jet DOT_QUALIFIED_EXPRESSION DOT_QUALIFIED_EXPRESSION ROOT_NAMESPACE - PsiElement(namespace)('package') + PsiElement(package)('package') PsiElement(DOT)('.') REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('foo') @@ -97,7 +97,7 @@ JetFile: RootNamespace.jet DOT_QUALIFIED_EXPRESSION DOT_QUALIFIED_EXPRESSION ROOT_NAMESPACE - PsiElement(namespace)('package') + PsiElement(package)('package') PsiElement(DOT)('.') REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('foo') diff --git a/compiler/testData/psi/ShortAnnotations.txt b/compiler/testData/psi/ShortAnnotations.txt index 39f693aa27b..41c0dec051f 100644 --- a/compiler/testData/psi/ShortAnnotations.txt +++ b/compiler/testData/psi/ShortAnnotations.txt @@ -49,7 +49,7 @@ JetFile: ShortAnnotations.jet REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('zoo') PsiWhiteSpace(' ') - PsiElement(namespace)('package') + PsiElement(package)('package') PsiWhiteSpace(' ') PsiElement(IDENTIFIER)('aa') PsiWhiteSpace('\n\n') diff --git a/compiler/testData/psi/SimpleModifiers.txt b/compiler/testData/psi/SimpleModifiers.txt index 20726bc4804..2be64903246 100644 --- a/compiler/testData/psi/SimpleModifiers.txt +++ b/compiler/testData/psi/SimpleModifiers.txt @@ -1,6 +1,6 @@ JetFile: SimpleModifiers.jet NAMESPACE_HEADER - PsiElement(namespace)('package') + PsiElement(package)('package') PsiWhiteSpace(' ') REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('foo') diff --git a/compiler/testData/psi/SoftKeywords.txt b/compiler/testData/psi/SoftKeywords.txt index 871079924de..1a88237090d 100644 --- a/compiler/testData/psi/SoftKeywords.txt +++ b/compiler/testData/psi/SoftKeywords.txt @@ -1,6 +1,6 @@ JetFile: SoftKeywords.jet NAMESPACE_HEADER - PsiElement(namespace)('package') + PsiElement(package)('package') PsiWhiteSpace(' ') REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('foo') diff --git a/compiler/testData/psi/TypeDef.txt b/compiler/testData/psi/TypeDef.txt index d2342ec1376..130cfbdbf25 100644 --- a/compiler/testData/psi/TypeDef.txt +++ b/compiler/testData/psi/TypeDef.txt @@ -1,6 +1,6 @@ JetFile: TypeDef.jet NAMESPACE_HEADER - PsiElement(namespace)('package') + PsiElement(package)('package') PsiWhiteSpace(' ') REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('foo') diff --git a/compiler/testData/psi/When.txt b/compiler/testData/psi/When.txt index 94a2b4d60a1..4fd91959ae0 100644 --- a/compiler/testData/psi/When.txt +++ b/compiler/testData/psi/When.txt @@ -598,7 +598,7 @@ JetFile: When.jet DOT_QUALIFIED_EXPRESSION DOT_QUALIFIED_EXPRESSION ROOT_NAMESPACE - PsiElement(namespace)('package') + PsiElement(package)('package') PsiElement(DOT)('.') REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('a') diff --git a/compiler/testData/readClass/prop/ExtValClass.kt b/compiler/testData/readClass/prop/ExtValClass.kt new file mode 100644 index 00000000000..02c6edf89ec --- /dev/null +++ b/compiler/testData/readClass/prop/ExtValClass.kt @@ -0,0 +1,4 @@ +package test + +val

P.anotherJavaClass: java.lang.Class

+ get() = throw Exception() diff --git a/compiler/testData/readClass/prop/ExtValInClass.kt b/compiler/testData/readClass/prop/ExtValInClass.kt new file mode 100644 index 00000000000..5bdd27596da --- /dev/null +++ b/compiler/testData/readClass/prop/ExtValInClass.kt @@ -0,0 +1,6 @@ +package test + +class ExtPropInClass { + val Int.itIs: Int + get() = this +} diff --git a/compiler/testData/readClass/prop/ExtValInt.kt b/compiler/testData/readClass/prop/ExtValInt.kt new file mode 100644 index 00000000000..7a66f817fa2 --- /dev/null +++ b/compiler/testData/readClass/prop/ExtValInt.kt @@ -0,0 +1,4 @@ +package test + +val Int.itIs: Int + get() = this diff --git a/compiler/testData/readClass/prop/ExtValIntCharSequence.kt b/compiler/testData/readClass/prop/ExtValIntCharSequence.kt new file mode 100644 index 00000000000..4d11a8c99f3 --- /dev/null +++ b/compiler/testData/readClass/prop/ExtValIntCharSequence.kt @@ -0,0 +1,6 @@ +package test + +import java.lang.CharSequence + +val Int.ggg: CharSequence + get() = throw Exception() diff --git a/compiler/testData/readClass/prop/ExtValIntCharSequenceQ.kt b/compiler/testData/readClass/prop/ExtValIntCharSequenceQ.kt new file mode 100644 index 00000000000..8c89b50f3df --- /dev/null +++ b/compiler/testData/readClass/prop/ExtValIntCharSequenceQ.kt @@ -0,0 +1,6 @@ +package test + +import java.lang.CharSequence + +val Int.ggg: CharSequence? + get() = throw Exception() diff --git a/compiler/testData/readClass/prop/ExtValIntListQOfIntInClass.kt b/compiler/testData/readClass/prop/ExtValIntListQOfIntInClass.kt new file mode 100644 index 00000000000..bced635853c --- /dev/null +++ b/compiler/testData/readClass/prop/ExtValIntListQOfIntInClass.kt @@ -0,0 +1,6 @@ +package test + +class ExtValInClass { + val Int.asas: java.util.List? + get() = throw Exception() +} diff --git a/compiler/testData/readClass/prop/ExtValIntTInClass.kt b/compiler/testData/readClass/prop/ExtValIntTInClass.kt new file mode 100644 index 00000000000..4b8146228a2 --- /dev/null +++ b/compiler/testData/readClass/prop/ExtValIntTInClass.kt @@ -0,0 +1,6 @@ +package test + +class ExtValInClass { + val Int.asas: T + get() = throw Exception() +} diff --git a/compiler/testData/readClass/prop/ExtValIntTQInClass.kt b/compiler/testData/readClass/prop/ExtValIntTQInClass.kt new file mode 100644 index 00000000000..665ef807303 --- /dev/null +++ b/compiler/testData/readClass/prop/ExtValIntTQInClass.kt @@ -0,0 +1,6 @@ +package test + +class ExtValInClass

{ + val Int.asas: P? + get() = throw Exception() +} diff --git a/compiler/testData/readClass/prop/ExtValTIntInClass.kt b/compiler/testData/readClass/prop/ExtValTIntInClass.kt new file mode 100644 index 00000000000..b1eb29567ed --- /dev/null +++ b/compiler/testData/readClass/prop/ExtValTIntInClass.kt @@ -0,0 +1,6 @@ +package test + +class ExtValPIntInClass

{ + val P.asas: Int + get() = throw Exception() +} diff --git a/compiler/testData/readClass/prop/ExtVarClass.kt b/compiler/testData/readClass/prop/ExtVarClass.kt new file mode 100644 index 00000000000..f32b9564961 --- /dev/null +++ b/compiler/testData/readClass/prop/ExtVarClass.kt @@ -0,0 +1,5 @@ +package test + +var

P.anotherJavaClass: java.lang.Class

+ get() = throw Exception() + set(p: java.lang.Class

) = throw Exception() diff --git a/compiler/testData/readClass/prop/ExtVarInClass.kt b/compiler/testData/readClass/prop/ExtVarInClass.kt new file mode 100644 index 00000000000..2e739bf5302 --- /dev/null +++ b/compiler/testData/readClass/prop/ExtVarInClass.kt @@ -0,0 +1,7 @@ +package test + +class ExtPropInClass { + var Int.itIs: Int + get() = throw Exception() + set(p: Int) = throw Exception() +} diff --git a/compiler/testData/readClass/prop/ExtVarInt.kt b/compiler/testData/readClass/prop/ExtVarInt.kt new file mode 100644 index 00000000000..229a26e8dc6 --- /dev/null +++ b/compiler/testData/readClass/prop/ExtVarInt.kt @@ -0,0 +1,5 @@ +package test + +var Int.ggg: Int + get() = throw Exception() + set(p) = throw Exception() diff --git a/compiler/testData/readClass/prop/ExtVarIntTInClass.kt b/compiler/testData/readClass/prop/ExtVarIntTInClass.kt new file mode 100644 index 00000000000..55ff0f66db4 --- /dev/null +++ b/compiler/testData/readClass/prop/ExtVarIntTInClass.kt @@ -0,0 +1,7 @@ +package test + +class ExtValInClass

{ + var Int.asas: P + get() = throw Exception() + set(p: P) = throw Exception() +} diff --git a/compiler/testData/readClass/prop/ExtVarIntTQInClass.kt b/compiler/testData/readClass/prop/ExtVarIntTQInClass.kt new file mode 100644 index 00000000000..ea0a6d7b512 --- /dev/null +++ b/compiler/testData/readClass/prop/ExtVarIntTQInClass.kt @@ -0,0 +1,7 @@ +package test + +class ExtValInClass

{ + var Int.asas: P? + get() = throw Exception() + set(p: P?) = throw Exception() +} diff --git a/compiler/testData/readClass/prop/ExtVarMapPQInt.kt b/compiler/testData/readClass/prop/ExtVarMapPQInt.kt new file mode 100644 index 00000000000..4abab48e497 --- /dev/null +++ b/compiler/testData/readClass/prop/ExtVarMapPQInt.kt @@ -0,0 +1,7 @@ +package test + +import java.util.Map + +var Map.asas: Int + get() = throw Exception() + set(i: Int) = throw Exception() diff --git a/compiler/testData/readClass/prop/ExtVarTIntInClass.kt b/compiler/testData/readClass/prop/ExtVarTIntInClass.kt new file mode 100644 index 00000000000..944b4167060 --- /dev/null +++ b/compiler/testData/readClass/prop/ExtVarTIntInClass.kt @@ -0,0 +1,7 @@ +package test + +class ExtValPIntInClass

{ + var P.asas: Int + get() = throw Exception() + set(p: Int) = throw Exception() +} diff --git a/compiler/testData/readClass/prop/ExtVarTQIntInClass.kt b/compiler/testData/readClass/prop/ExtVarTQIntInClass.kt new file mode 100644 index 00000000000..78b6b63aa93 --- /dev/null +++ b/compiler/testData/readClass/prop/ExtVarTQIntInClass.kt @@ -0,0 +1,7 @@ +package test + +class ExtValPIntInClass

{ + var P?.asas: Int + get() = throw Exception() + set(p: Int) = throw Exception() +} diff --git a/compiler/testData/readClass/type/ArrayOfCharSequence.kt b/compiler/testData/readClass/type/ArrayOfCharSequence.kt new file mode 100644 index 00000000000..8ba5d0f0661 --- /dev/null +++ b/compiler/testData/readClass/type/ArrayOfCharSequence.kt @@ -0,0 +1,3 @@ +package test + +fun nothing(): Array = throw Exception() diff --git a/compiler/testData/writeSignature/Int.kt b/compiler/testData/writeSignature/Int.kt new file mode 100644 index 00000000000..7b92774953a --- /dev/null +++ b/compiler/testData/writeSignature/Int.kt @@ -0,0 +1,6 @@ +fun key(): Int = throw Exception() + +// method: namespace::key +// jvm signature: ()I +// generic signature: null +// kotlin signature: ()I // TODO: make null diff --git a/compiler/testData/writeSignature/IntQ.kt b/compiler/testData/writeSignature/IntQ.kt new file mode 100644 index 00000000000..9f1c64ad65d --- /dev/null +++ b/compiler/testData/writeSignature/IntQ.kt @@ -0,0 +1,6 @@ +fun sometimes(): Int? = null + +// method: namespace::sometimes +// jvm signature: ()Ljava/lang/Integer; +// generic signature: null +// kotlin signature: ()?Ljava/lang/Integer; // TODO: need to skip kotlin signature diff --git a/compiler/testData/writeSignature/VarargCharSequence.kt b/compiler/testData/writeSignature/VarargCharSequence.kt new file mode 100644 index 00000000000..edbef9ab513 --- /dev/null +++ b/compiler/testData/writeSignature/VarargCharSequence.kt @@ -0,0 +1,6 @@ +fun foo(vararg tail: java.lang.CharSequence) = 1 + +// method: namespace::foo +// jvm signature: ([Ljava/lang/CharSequence;)I +// generic signature: null +// kotlin signature: ([Ljava/lang/CharSequence;)I // TODO: need to skip kotlin signature diff --git a/compiler/testData/writeSignature/VarargGeneric.kt b/compiler/testData/writeSignature/VarargGeneric.kt new file mode 100644 index 00000000000..9259216adb5 --- /dev/null +++ b/compiler/testData/writeSignature/VarargGeneric.kt @@ -0,0 +1,8 @@ +fun

foo(vararg tail: P) = 1 + +// method: namespace::foo +// jvm signature: (Ljet/TypeInfo;[Ljava/lang/Object;)I +// generic signature: (Ljet/TypeInfo;[TP;)I +// kotlin signature: (null[TP;)I +// TODO: skip kotlin signature +// TODO: properly serialize typeinfo diff --git a/compiler/tests/org/jetbrains/jet/ReadClassDataTest.java b/compiler/tests/org/jetbrains/jet/ReadClassDataTest.java index bc6ae1e349e..247c4a68796 100644 --- a/compiler/tests/org/jetbrains/jet/ReadClassDataTest.java +++ b/compiler/tests/org/jetbrains/jet/ReadClassDataTest.java @@ -7,6 +7,7 @@ import com.intellij.psi.PsiFileFactory; import com.intellij.psi.impl.PsiFileFactoryImpl; import com.intellij.testFramework.LightVirtualFile; import junit.framework.Test; +import org.codehaus.groovy.ast.expr.DeclarationExpression; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.codegen.ClassBuilderFactory; import org.jetbrains.jet.codegen.ClassFileFactory; @@ -33,7 +34,9 @@ import org.junit.Assert; import java.io.File; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -93,33 +96,73 @@ public class ReadClassDataTest extends TestCaseWithTmpdir { private void compareNamespaces(@NotNull NamespaceDescriptor nsa, @NotNull NamespaceDescriptor nsb) { Assert.assertEquals(nsa.getName(), nsb.getName()); System.out.println("namespace " + nsa.getName()); + + Assert.assertTrue(!nsa.getMemberScope().getAllDescriptors().isEmpty()); + + Set classifierNames = new HashSet(); + Set propertyNames = new HashSet(); + Set functionNames = new HashSet(); + for (DeclarationDescriptor ad : nsa.getMemberScope().getAllDescriptors()) { if (ad instanceof ClassifierDescriptor) { - ClassifierDescriptor bd = nsb.getMemberScope().getClassifier(ad.getName()); - Assert.assertTrue("classifier not found: " + ad.getName(), bd != null); - compareClassifiers((ClassifierDescriptor) ad, bd); - - Assert.assertNull(nsb.getMemberScope().getClassifier(ad.getName() + JvmAbi.TRAIT_IMPL_SUFFIX)); - } else if (ad instanceof FunctionDescriptor) { - Set functions = nsb.getMemberScope().getFunctions(ad.getName()); - Assert.assertTrue(functions.size() >= 1); - Assert.assertTrue("not implemented", functions.size() == 1); - FunctionDescriptor bd = functions.iterator().next(); - compareDescriptors(ad, bd); + classifierNames.add(ad.getName()); } else if (ad instanceof PropertyDescriptor) { - Set properties = nsb.getMemberScope().getProperties(ad.getName()); - Assert.assertTrue("property not found by name: " + ad.getName(), properties.size() >= 1); - Assert.assertTrue("not implemented", properties.size() == 1); - PropertyDescriptor bd = (PropertyDescriptor) properties.iterator().next(); - compareDescriptors(ad, bd); - - Assert.assertTrue(nsb.getMemberScope().getFunctions(PropertyCodegen.getterName(ad.getName())).isEmpty()); - Assert.assertTrue(nsb.getMemberScope().getFunctions(PropertyCodegen.setterName(ad.getName())).isEmpty()); + propertyNames.add(ad.getName()); + } else if (ad instanceof FunctionDescriptor) { + functionNames.add(ad.getName()); } else { - throw new AssertionError("Unknown member: " + ad); + throw new AssertionError("unknown member: " + ad); } } + + for (String name : classifierNames) { + ClassifierDescriptor ca = nsa.getMemberScope().getClassifier(name); + ClassifierDescriptor cb = nsb.getMemberScope().getClassifier(name); + Assert.assertTrue(ca != null); + Assert.assertTrue(cb != null); + compareClassifiers(ca, cb); + } + + for (String name : propertyNames) { + Set pa = nsa.getMemberScope().getProperties(name); + Set pb = nsb.getMemberScope().getProperties(name); + compareDeclarationSets(pa, pb); + + Assert.assertTrue(nsb.getMemberScope().getFunctions(PropertyCodegen.getterName(name)).isEmpty()); + Assert.assertTrue(nsb.getMemberScope().getFunctions(PropertyCodegen.setterName(name)).isEmpty()); + } + + for (String name : functionNames) { + Set fa = nsa.getMemberScope().getFunctions(name); + Set fb = nsb.getMemberScope().getFunctions(name); + compareDeclarationSets(fa, fb); + } } + + private void compareDeclarationSets(Set a, Set b) { + String at = serializedDeclarationSets(a); + String bt = serializedDeclarationSets(b); + Assert.assertEquals(at, bt); + System.out.print(at); + } + + private String serializedDeclarationSets(Collection ds) { + List strings = new ArrayList(); + for (DeclarationDescriptor d : ds) { + StringBuilder sb = new StringBuilder(); + new Serializer(sb).serialize(d); + strings.add(sb.toString()); + } + + Collections.sort(strings); + + StringBuilder r = new StringBuilder(); + for (String string : strings) { + r.append(string); + r.append("\n"); + } + return r.toString(); + } private void compareClassifiers(@NotNull ClassifierDescriptor a, @NotNull ClassifierDescriptor b) { StringBuilder sba = new StringBuilder(); @@ -282,12 +325,19 @@ public class ReadClassDataTest extends TestCaseWithTmpdir { } else { sb.append("val "); } + if (prop.getReceiverParameter().exists()) { + serialize(prop.getReceiverParameter().getType()); + sb.append("."); + } sb.append(prop.getName()); sb.append(": "); serialize(prop.getOutType()); } public void serialize(ValueParameterDescriptor valueParameter) { + sb.append("/*"); + sb.append(valueParameter.getIndex()); + sb.append("*/ "); if (valueParameter.getVarargElementType() != null) { sb.append("vararg "); } @@ -322,11 +372,11 @@ public class ReadClassDataTest extends TestCaseWithTmpdir { sb.append("<"); boolean first = true; for (TypeProjection proj : type.getArguments()) { - serialize(proj.getProjectionKind()); - serialize(proj.getType()); if (!first) { sb.append(", "); } + serialize(proj.getProjectionKind()); + serialize(proj.getType()); first = false; } sb.append(">"); @@ -347,7 +397,7 @@ public class ReadClassDataTest extends TestCaseWithTmpdir { first = false; } } - + private Method getMethodToSerialize(Object o) { // TODO: cache for (Method method : this.getClass().getMethods()) { @@ -396,6 +446,7 @@ public class ReadClassDataTest extends TestCaseWithTmpdir { } public void serialize(TypeParameterDescriptor param) { + sb.append("/*").append(param.getIndex()).append("*/ "); serialize(param.getVariance()); sb.append(param.getName()); if (!param.getUpperBounds().isEmpty()) { diff --git a/compiler/tests/org/jetbrains/jet/types/JetDefaultModalityModifiersTest.java b/compiler/tests/org/jetbrains/jet/types/JetDefaultModalityModifiersTest.java index 932cdda3086..9a0534638b6 100644 --- a/compiler/tests/org/jetbrains/jet/types/JetDefaultModalityModifiersTest.java +++ b/compiler/tests/org/jetbrains/jet/types/JetDefaultModalityModifiersTest.java @@ -74,7 +74,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture { List declarations = aClass.getDeclarations(); JetNamedFunction function = (JetNamedFunction) declarations.get(0); - FunctionDescriptorImpl functionDescriptor = descriptorResolver.resolveFunctionDescriptor(classDescriptor, scope, function); + NamedFunctionDescriptor functionDescriptor = descriptorResolver.resolveFunctionDescriptor(classDescriptor, scope, function); assertEquals(expectedFunctionModality, functionDescriptor.getModality()); } diff --git a/idea/idea.iml b/idea/idea.iml index 061858ad7f7..39519927146 100644 --- a/idea/idea.iml +++ b/idea/idea.iml @@ -13,6 +13,7 @@ + @@ -21,6 +22,7 @@ + diff --git a/idea/resources/fileTemplates/internal/Kotlin File.kt.ft b/idea/resources/fileTemplates/internal/Kotlin File.kt.ft new file mode 100644 index 00000000000..86620bf1121 --- /dev/null +++ b/idea/resources/fileTemplates/internal/Kotlin File.kt.ft @@ -0,0 +1,2 @@ +#parse("File Header.java") + diff --git a/idea/resources/fileTemplates/internal/Kotlin File.kt.html b/idea/resources/fileTemplates/internal/Kotlin File.kt.html new file mode 100644 index 00000000000..176477df927 --- /dev/null +++ b/idea/resources/fileTemplates/internal/Kotlin File.kt.html @@ -0,0 +1,14 @@ + + + + + + +
+ + This is a built-in template used by IDEA each time you create a + Kotlin file + +
+ + \ No newline at end of file diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 5d01613d996..94428276631 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -14,6 +14,10 @@ + + + + @@ -32,6 +36,9 @@ + + + @@ -59,8 +66,8 @@ - - + + overriddenFunctions = functionDescriptor.getOverriddenDescriptors(); Icon icon = isMember(functionDescriptor) ? (overriddenFunctions.isEmpty() ? PlatformIcons.METHOD_ICON : OVERRIDING_FUNCTION) : PlatformIcons.FUNCTION_ICON; @@ -182,7 +182,7 @@ public class JetLineMarkerProvider implements LineMarkerProvider { ); } - private boolean isMember(@NotNull FunctionDescriptor functionDescriptor) { + private boolean isMember(@NotNull NamedFunctionDescriptor functionDescriptor) { return functionDescriptor.getContainingDeclaration().getOriginal() instanceof ClassifierDescriptor; } diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/OverrideImplementMethodsHandler.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/OverrideImplementMethodsHandler.java index ddc4aa1dfe4..f3c8838cae5 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/OverrideImplementMethodsHandler.java +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/OverrideImplementMethodsHandler.java @@ -54,8 +54,8 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns } for (DescriptorClassMember selectedElement : selectedElements) { final DeclarationDescriptor descriptor = selectedElement.getDescriptor(); - if (descriptor instanceof FunctionDescriptor) { - JetElement target = overrideFunction(project, (FunctionDescriptor) descriptor); + if (descriptor instanceof NamedFunctionDescriptor) { + JetElement target = overrideFunction(project, (NamedFunctionDescriptor) descriptor); body.addBefore(target, body.getRBrace()); } else if (descriptor instanceof PropertyDescriptor) { @@ -84,7 +84,7 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns return JetPsiFactory.createProperty(project, bodyBuilder.toString()); } - private static JetElement overrideFunction(Project project, FunctionDescriptor descriptor) { + private static JetElement overrideFunction(Project project, NamedFunctionDescriptor descriptor) { StringBuilder bodyBuilder = new StringBuilder("override fun "); bodyBuilder.append(descriptor.getName()); bodyBuilder.append("("); diff --git a/idea/src/org/jetbrains/jet/plugin/references/JetPsiReference.java b/idea/src/org/jetbrains/jet/plugin/references/JetPsiReference.java index 5754049dd07..28bffebab46 100644 --- a/idea/src/org/jetbrains/jet/plugin/references/JetPsiReference.java +++ b/idea/src/org/jetbrains/jet/plugin/references/JetPsiReference.java @@ -11,9 +11,9 @@ import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.JetReferenceExpression; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContextUtils; -import org.jetbrains.jet.lang.resolve.calls.ResolvedCallImpl; import org.jetbrains.jet.plugin.compiler.WholeProjectAnalyzerFacade; +import java.util.ArrayList; import java.util.Collection; import static org.jetbrains.jet.lang.resolve.BindingContext.AMBIGUOUS_REFERENCE_TARGET; @@ -83,6 +83,8 @@ public abstract class JetPsiReference implements PsiPolyVariantReference { } Collection declarationDescriptors = bindingContext.get(AMBIGUOUS_REFERENCE_TARGET, myExpression); if (declarationDescriptors != null) return null; + + // TODO: Need a better resolution for intrinsic function (KT-975) return file; } @@ -91,15 +93,19 @@ public abstract class JetPsiReference implements PsiPolyVariantReference { BindingContext bindingContext = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(file); Collection declarationDescriptors = bindingContext.get(AMBIGUOUS_REFERENCE_TARGET, myExpression); if (declarationDescriptors == null) return ResolveResult.EMPTY_ARRAY; - ResolveResult[] results = new ResolveResult[declarationDescriptors.size()]; - int i = 0; + + ArrayList results = new ArrayList(declarationDescriptors.size()); + for (DeclarationDescriptor descriptor : declarationDescriptors) { PsiElement element = bindingContext.get(DESCRIPTOR_TO_DECLARATION, descriptor); - if (element != null) { - results[i] = new PsiElementResolveResult(element, true); - i++; + if (element == null) { + // TODO: Need a better resolution for intrinsic function (KT-975) + element = file; } + + results.add(new PsiElementResolveResult(element, true)); } - return results; + + return results.toArray(new ResolveResult[results.size()]); } } diff --git a/idea/src/org/jetbrains/jet/plugin/structureView/JetStructureViewElement.java b/idea/src/org/jetbrains/jet/plugin/structureView/JetStructureViewElement.java index 5d4ce0e93fe..de2ff848a3b 100644 --- a/idea/src/org/jetbrains/jet/plugin/structureView/JetStructureViewElement.java +++ b/idea/src/org/jetbrains/jet/plugin/structureView/JetStructureViewElement.java @@ -6,8 +6,16 @@ import com.intellij.navigation.ItemPresentation; import com.intellij.openapi.util.Iconable; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.NavigatablePsiElement; +import com.intellij.util.Function; import com.intellij.util.PsiIconUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.psi.*; +import org.jetbrains.jet.lang.resolve.BindingContext; +import org.jetbrains.jet.lang.resolve.DescriptorUtils; +import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; +import org.jetbrains.jet.lang.types.JetType; +import org.jetbrains.jet.resolve.DescriptorRenderer; import javax.swing.*; import java.util.ArrayList; @@ -19,8 +27,17 @@ import java.util.List; public class JetStructureViewElement implements StructureViewTreeElement { private final NavigatablePsiElement myElement; - public JetStructureViewElement(NavigatablePsiElement element) { + // For file context will be updated after each construction + // For other tree sub-elements it's immutable. + private BindingContext context; + + public JetStructureViewElement(NavigatablePsiElement element, BindingContext context) { myElement = element; + this.context = context; + } + + public JetStructureViewElement(JetFile fileElement) { + myElement = fileElement; } @Override @@ -48,13 +65,29 @@ public class JetStructureViewElement implements StructureViewTreeElement { return new ItemPresentation() { @Override public String getPresentableText() { - String name = myElement.getName(); - if (StringUtil.isEmpty(name)) { + String text = ""; + + // Try to find text in correspondent descriptor +// if (myElement instanceof JetDeclaration) { +// JetDeclaration declaration = (JetDeclaration) myElement; +// final DeclarationDescriptor descriptor = +// context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration); +// +// if (descriptor != null) { +// text = getDescriptorTreeText(descriptor); +// } +// } + + if (StringUtil.isEmpty(text)) { + text = myElement.getName(); + } + + if (StringUtil.isEmpty(text)) { if (myElement instanceof JetClassInitializer) { return ""; } } - return name; + return text; } @Override @@ -64,20 +97,26 @@ public class JetStructureViewElement implements StructureViewTreeElement { @Override public Icon getIcon(boolean open) { - return myElement.isValid() - ? PsiIconUtil.getProvidersIcon(myElement, open ? Iconable.ICON_FLAG_OPEN : Iconable.ICON_FLAG_CLOSED) - : null; + if (myElement.isValid()) { + return PsiIconUtil.getProvidersIcon( + myElement, + open ? Iconable.ICON_FLAG_OPEN : Iconable.ICON_FLAG_CLOSED); + } + + return null; } }; } - + @Override public TreeElement[] getChildren() { if (myElement instanceof JetFile) { - return new TreeElement[] { new JetStructureViewElement(myElement) }; - } - else if (myElement instanceof JetFile) { - return wrapDeclarations(((JetFile) myElement).getDeclarations()); + final JetFile jetFile = (JetFile) myElement; + + // TODO: Understand why it significantly reduce responsibility of IDEA during typing + // context = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(jetFile); + + return wrapDeclarations(jetFile.getDeclarations()); } else if (myElement instanceof JetClass) { JetClass jetClass = (JetClass) myElement; @@ -89,19 +128,68 @@ public class JetStructureViewElement implements StructureViewTreeElement { } declarations.addAll(jetClass.getDeclarations()); return wrapDeclarations(declarations); - } else if (myElement instanceof JetClassOrObject) { return wrapDeclarations(((JetClassOrObject) myElement).getDeclarations()); } return new TreeElement[0]; } - - private static TreeElement[] wrapDeclarations(List declarations) { + + private TreeElement[] wrapDeclarations(List declarations) { TreeElement[] result = new TreeElement[declarations.size()]; for (int i = 0; i < declarations.size(); i++) { - result[i] = new JetStructureViewElement(declarations.get(i)); + result[i] = new JetStructureViewElement(declarations.get(i), context); } return result; } + + public static String getDescriptorTreeText(@NotNull DeclarationDescriptor descriptor) { + StringBuilder textBuilder; + + if (descriptor instanceof FunctionDescriptor) { + textBuilder = new StringBuilder(); + + FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor; + ReceiverDescriptor receiver = functionDescriptor.getReceiverParameter(); + if (receiver.exists()) { + textBuilder.append(DescriptorRenderer.TEXT.renderType(receiver.getType())).append("."); + } + + textBuilder.append(functionDescriptor.getName()); + + String parametersString = StringUtil.join( + functionDescriptor.getValueParameters(), + new Function() { + @Override + public String fun(ValueParameterDescriptor valueParameterDescriptor) { + return valueParameterDescriptor.getName() + ":" + + DescriptorRenderer.TEXT.renderType(valueParameterDescriptor.getOutType()); + } + }, + ","); + + textBuilder.append("(").append(parametersString).append(")"); + + JetType returnType = functionDescriptor.getReturnType(); + textBuilder.append(":").append(DescriptorRenderer.TEXT.renderType(returnType)); + } + else if (descriptor instanceof VariableDescriptor) { + JetType outType = ((VariableDescriptor) descriptor).getOutType(); + + textBuilder = new StringBuilder(descriptor.getName()); + textBuilder.append(":").append(DescriptorRenderer.TEXT.renderType(outType)); + } + else if (descriptor instanceof ClassDescriptor) { + textBuilder = new StringBuilder(descriptor.getName()); + textBuilder + .append(" (") + .append(DescriptorUtils.getFQName(descriptor.getContainingDeclaration())) + .append(")"); + } + else { + return DescriptorRenderer.TEXT.render(descriptor); + } + + return textBuilder.toString(); + } } diff --git a/idea/src/org/jetbrains/jet/plugin/structureView/JetStructureViewFactory.java b/idea/src/org/jetbrains/jet/plugin/structureView/JetStructureViewFactory.java index 5e9d3fd2c63..a7fa2ca7162 100644 --- a/idea/src/org/jetbrains/jet/plugin/structureView/JetStructureViewFactory.java +++ b/idea/src/org/jetbrains/jet/plugin/structureView/JetStructureViewFactory.java @@ -6,6 +6,7 @@ import com.intellij.ide.structureView.TreeBasedStructureViewBuilder; import com.intellij.lang.PsiStructureViewFactory; import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.psi.JetFile; /** * @author yole @@ -13,12 +14,18 @@ import org.jetbrains.annotations.NotNull; public class JetStructureViewFactory implements PsiStructureViewFactory { @Override public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) { - return new TreeBasedStructureViewBuilder() { - @NotNull - @Override - public StructureViewModel createStructureViewModel() { - return new JetStructureViewModel(psiFile); - } - }; + if (psiFile instanceof JetFile) { + final JetFile file = (JetFile) psiFile; + + return new TreeBasedStructureViewBuilder() { + @NotNull + @Override + public StructureViewModel createStructureViewModel() { + return new JetStructureViewModel(file); + } + }; + } + + return null; } } diff --git a/idea/src/org/jetbrains/jet/plugin/structureView/JetStructureViewModel.java b/idea/src/org/jetbrains/jet/plugin/structureView/JetStructureViewModel.java index 6a1f5167d35..9a5954cd346 100644 --- a/idea/src/org/jetbrains/jet/plugin/structureView/JetStructureViewModel.java +++ b/idea/src/org/jetbrains/jet/plugin/structureView/JetStructureViewModel.java @@ -1,16 +1,16 @@ package org.jetbrains.jet.plugin.structureView; import com.intellij.ide.structureView.StructureViewModelBase; -import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.psi.JetDeclaration; +import org.jetbrains.jet.lang.psi.JetFile; /** * @author yole */ public class JetStructureViewModel extends StructureViewModelBase { - public JetStructureViewModel(@NotNull PsiFile psiFile) { - super(psiFile, new JetStructureViewElement(psiFile)); + public JetStructureViewModel(@NotNull JetFile jetFile) { + super(jetFile, new JetStructureViewElement(jetFile)); withSuitableClasses(JetDeclaration.class); } } diff --git a/idea/testData/resolve/multiResolve.kt b/idea/testData/resolve/multiResolve.kt new file mode 100644 index 00000000000..6d48eaa075f --- /dev/null +++ b/idea/testData/resolve/multiResolve.kt @@ -0,0 +1,8 @@ +package ctrl_click + +fun IntArray(vararg content : Int) : IntArray = content +fun array(vararg t : T) : Array = t + +fun main(args : ArrayList) { + var a = IntArray(array(1, 2, 3)) +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/resolve/ResolveBaseTest.java b/idea/tests/org/jetbrains/jet/resolve/ResolveBaseTest.java new file mode 100644 index 00000000000..fde92692bf3 --- /dev/null +++ b/idea/tests/org/jetbrains/jet/resolve/ResolveBaseTest.java @@ -0,0 +1,89 @@ +package org.jetbrains.jet.resolve; + +import com.intellij.openapi.projectRoots.Sdk; +import com.intellij.psi.PsiPolyVariantReference; +import com.intellij.psi.PsiReference; +import com.intellij.psi.ResolveResult; +import com.intellij.testFramework.LightCodeInsightTestCase; +import junit.framework.Test; +import junit.framework.TestSuite; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.JetTestCaseBuilder; +import org.jetbrains.jet.plugin.PluginTestCaseBase; + +import java.io.File; + +/** + * @author Nikolay Krasko + */ +public class ResolveBaseTest extends LightCodeInsightTestCase { + + private final String myPath; + private final String myName; + + protected ResolveBaseTest(@NotNull String path, @NotNull String name) { + myPath = path; + myName = name; + + // Set name explicitly because otherwise there will be "TestCase.fName cannot be null" + setName("testResolve"); + } + + @Override + protected Sdk getProjectJDK() { + return PluginTestCaseBase.jdkFromIdeaHome(); + } + + @Override + protected String getTestDataPath() { + return new File(PluginTestCaseBase.getTestDataPathBase(), myPath).getPath() + + File.separator; + } + + @NotNull + @Override + public String getName() { + return "test" + myName; + } + + public void testResolve() throws Exception { + doTest(); + } + + // TODO: Currently this test is only for KT-763 bug - it should be extended to framework for testing references + protected void doTest() throws Exception { + final String testName = getTestName(false); + configureByFile(testName + ".kt"); + + final PsiReference psiReference = + getFile().findReferenceAt(getEditor().getCaretModel().getOffset()); + + assertTrue(psiReference instanceof PsiPolyVariantReference); + + final PsiPolyVariantReference variantReference = (PsiPolyVariantReference) psiReference; + + final ResolveResult[] results = variantReference.multiResolve(true); + for (ResolveResult result : results) { + assertNotNull(result); + } + } + + @NotNull + public static TestSuite suite() { + TestSuite suite = new TestSuite(); + + JetTestCaseBuilder.appendTestsInDirectory( + PluginTestCaseBase.getTestDataPathBase(), "/resolve/", false, + JetTestCaseBuilder.emptyFilter, new JetTestCaseBuilder.NamedTestFactory() { + + + @NotNull + @Override + public Test createTest(@NotNull String dataPath, @NotNull String name, @NotNull File file) { + return new ResolveBaseTest(dataPath, name); + } + }, suite); + + return suite; + } +} diff --git a/license/LICENSE.txt b/license/LICENSE.txt new file mode 100644 index 00000000000..2fd60759901 --- /dev/null +++ b/license/LICENSE.txt @@ -0,0 +1,15 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ diff --git a/license/NOTICE.txt b/license/NOTICE.txt new file mode 100644 index 00000000000..fdc60488aba --- /dev/null +++ b/license/NOTICE.txt @@ -0,0 +1,8 @@ + ========================================================================= + == NOTICE file corresponding to the section 4 d of == + == the Apache License, Version 2.0, == + == in this case for the Kotlin Compiler distribution. == + ========================================================================= + + Kotlin Compiler + Copyright 2010-2012 JetBrains s.r.o and respective authors and developers diff --git a/stdlib/ktSrc/JavaUtilMap.kt b/stdlib/ktSrc/JavaUtilMap.kt index 3125f3b4d4c..42cc5b156b7 100644 --- a/stdlib/ktSrc/JavaUtilMap.kt +++ b/stdlib/ktSrc/JavaUtilMap.kt @@ -18,11 +18,11 @@ fun JMap.set(key : K, value : V) = this.put(key, value) /** Returns the key of the entry */ val JEntry.key : K - get() = getKey() + get() = getKey().sure() /** Returns the value of the entry */ val JEntry.value : V - get() = getValue() + get() = getValue().sure() /** Returns the value for the given key or returns the result of the defaultValue function if there was no entry for the given key */ inline fun java.util.Map.getOrElse(key: K, defaultValue: ()-> V) : V { diff --git a/stdlib/src/jet/runtime/typeinfo/JetProperty.java b/stdlib/src/jet/runtime/typeinfo/JetProperty.java index dbc996bf127..2344ebe1fc4 100644 --- a/stdlib/src/jet/runtime/typeinfo/JetProperty.java +++ b/stdlib/src/jet/runtime/typeinfo/JetProperty.java @@ -11,4 +11,7 @@ import java.lang.annotation.Target; @Target({ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) public @interface JetProperty { + String type() default ""; + + String typeParameters() default ""; } diff --git a/testlib/test/test/collections/TestAll.java b/testlib/test/test/collections/TestAll.java index f9c4176076d..89914772443 100644 --- a/testlib/test/test/collections/TestAll.java +++ b/testlib/test/test/collections/TestAll.java @@ -1,7 +1,5 @@ package test.collections; -import junit.framework.TestSuite; - /** */ public class TestAll {