diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java index 43f89484007..ac955d16cac 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java @@ -24,7 +24,6 @@ import org.objectweb.asm.commons.Method; import org.objectweb.asm.signature.SignatureWriter; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -184,7 +183,7 @@ public class ClosureCodegen extends ObjectOrClosureCodegen { final CodegenContext.ClosureContext closureContext = context.intoClosure(funDescriptor, function, name, this, state.getTypeMapper()); FunctionCodegen fc = new FunctionCodegen(closureContext, cv, state); JvmMethodSignature jvmMethodSignature = invokeSignature(funDescriptor); - fc.generateMethod(body, jvmMethodSignature, null, funDescriptor); + fc.generateMethod(body, jvmMethodSignature, false, null, funDescriptor); return closureContext.outerWasUsed; } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java index d043a239822..77eff97f2d8 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java @@ -1,7 +1,6 @@ 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.*; @@ -44,21 +43,26 @@ public class FunctionCodegen { final NamedFunctionDescriptor functionDescriptor = state.getBindingContext().get(BindingContext.FUNCTION, f); assert functionDescriptor != null; JvmMethodSignature method = typeMapper.mapToCallableMethod(functionDescriptor, false, owner.getContextKind()).getSignature(); - generateMethod(f, method, null, functionDescriptor); + generateMethod(f, method, true, null, functionDescriptor); } - public void generateMethod(JetDeclarationWithBody f, JvmMethodSignature jvmMethod, @Nullable String propertyTypeSignature, FunctionDescriptor functionDescriptor) { + public void generateMethod(JetDeclarationWithBody f, + JvmMethodSignature jvmMethod, boolean needJetAnnotations, + @Nullable String propertyTypeSignature, FunctionDescriptor functionDescriptor) { + CodegenContext.MethodContext funContext = owner.intoFunction(functionDescriptor); final JetExpression bodyExpression = f.getBodyExpression(); - generatedMethod(bodyExpression, jvmMethod, propertyTypeSignature, funContext, functionDescriptor, f); + generatedMethod(bodyExpression, jvmMethod, needJetAnnotations, propertyTypeSignature, funContext, functionDescriptor, f); } private void generatedMethod(JetExpression bodyExpressions, - JvmMethodSignature jvmSignature, - @Nullable String propertyTypeSignature, - CodegenContext.MethodContext context, - FunctionDescriptor functionDescriptor, JetDeclarationWithBody fun) + JvmMethodSignature jvmSignature, + boolean needJetAnnotations, @Nullable String propertyTypeSignature, + CodegenContext.MethodContext context, + FunctionDescriptor functionDescriptor, + JetDeclarationWithBody fun + ) { List paramDescrs = functionDescriptor.getValueParameters(); List typeParameters = (functionDescriptor instanceof PropertyAccessorDescriptor ? ((PropertyAccessorDescriptor)functionDescriptor).getCorrespondingProperty(): functionDescriptor).getTypeParameters(); @@ -77,6 +81,10 @@ public class FunctionCodegen { } OwnerKind kind = context.getContextKind(); + + if (kind == OwnerKind.TRAIT_IMPL) { + needJetAnnotations = false; + } ReceiverDescriptor expectedThisObject = functionDescriptor.getExpectedThisObject(); ReceiverDescriptor receiverParameter = functionDescriptor.getReceiverParameter(); @@ -92,62 +100,52 @@ public class FunctionCodegen { final MethodVisitor mv = v.newMethod(fun, flags, jvmSignature.getAsmMethod().getName(), jvmSignature.getAsmMethod().getDescriptor(), jvmSignature.getGenericsSignature(), null); if(v.generateCode()) { int start = 0; - if(kind != OwnerKind.TRAIT_IMPL) { + if (needJetAnnotations) { 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(); + JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv); + aw.writeKind(JvmStdlibNames.JET_METHOD_KIND_REGULAR); + aw.writeNullableReturnType(functionDescriptor.getReturnType().isNullable()); + aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter()); + aw.writeReturnType(jvmSignature.getKotlinReturnType()); + aw.visitEnd(); } else { throw new IllegalStateException(); } - } - if(kind == OwnerKind.TRAIT_IMPL) { - AnnotationVisitor av = mv.visitParameterAnnotation(start++, JvmStdlibNames.JET_VALUE_PARAMETER.getDescriptor(), true); - av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_NAME_FIELD, "this$self"); - av.visitEnd(); - } - if(receiverParameter.exists()) { - AnnotationVisitor av = mv.visitParameterAnnotation(start++, JvmStdlibNames.JET_VALUE_PARAMETER.getDescriptor(), true); - av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_NAME_FIELD, "this$receiver"); - if(receiverParameter.getType().isNullable()) { - av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_NULLABLE_FIELD, true); + if(receiverParameter.exists()) { + AnnotationVisitor av = mv.visitParameterAnnotation(start++, JvmStdlibNames.JET_VALUE_PARAMETER.getDescriptor(), true); + av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_NAME_FIELD, "this$receiver"); + if(receiverParameter.getType().isNullable()) { + av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_NULLABLE_FIELD, true); + } + av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_RECEIVER_FIELD, true); + av.visitEnd(); } - av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_RECEIVER_FIELD, true); - av.visitEnd(); - } - for (final TypeParameterDescriptor typeParameterDescriptor : typeParameters) { - AnnotationVisitor av = mv.visitParameterAnnotation(start++, JvmStdlibNames.JET_TYPE_PARAMETER.getDescriptor(), true); - av.visit(JvmStdlibNames.JET_TYPE_PARAMETER_NAME_FIELD, typeParameterDescriptor.getName()); - av.visitEnd(); - } - for(int i = 0; i != paramDescrs.size(); ++i) { - AnnotationVisitor av = mv.visitParameterAnnotation(i + start, JvmStdlibNames.JET_VALUE_PARAMETER.getDescriptor(), true); - ValueParameterDescriptor parameterDescriptor = paramDescrs.get(i); - av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_NAME_FIELD, parameterDescriptor.getName()); - if(parameterDescriptor.hasDefaultValue()) { - av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_HAS_DEFAULT_VALUE_FIELD, true); + for (final TypeParameterDescriptor typeParameterDescriptor : typeParameters) { + AnnotationVisitor av = mv.visitParameterAnnotation(start++, JvmStdlibNames.JET_TYPE_PARAMETER.getDescriptor(), true); + av.visit(JvmStdlibNames.JET_TYPE_PARAMETER_NAME_FIELD, typeParameterDescriptor.getName()); + av.visitEnd(); } - if(parameterDescriptor.getOutType().isNullable()) { - av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_NULLABLE_FIELD, true); + for(int i = 0; i != paramDescrs.size(); ++i) { + AnnotationVisitor av = mv.visitParameterAnnotation(i + start, JvmStdlibNames.JET_VALUE_PARAMETER.getDescriptor(), true); + ValueParameterDescriptor parameterDescriptor = paramDescrs.get(i); + av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_NAME_FIELD, parameterDescriptor.getName()); + if(parameterDescriptor.hasDefaultValue()) { + av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_HAS_DEFAULT_VALUE_FIELD, true); + } + if(parameterDescriptor.getOutType().isNullable()) { + 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).getKotlinSignature()); + } + av.visitEnd(); } - if (jvmSignature.getKotlinParameterTypes() != null && jvmSignature.getKotlinParameterTypes().get(i) != null) { - av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_TYPE_FIELD, jvmSignature.getKotlinParameterTypes().get(i + start).getKotlinSignature()); - } - av.visitEnd(); } } if (!isAbstract && v.generateCode()) { diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index 401ff37777b..15f61fcaed3 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -245,7 +245,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { 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(); @@ -269,7 +268,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { 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(); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/JetMethodAnnotationWriter.java b/compiler/backend/src/org/jetbrains/jet/codegen/JetMethodAnnotationWriter.java new file mode 100644 index 00000000000..fe7ee73716b --- /dev/null +++ b/compiler/backend/src/org/jetbrains/jet/codegen/JetMethodAnnotationWriter.java @@ -0,0 +1,55 @@ +package org.jetbrains.jet.codegen; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; +import org.objectweb.asm.AnnotationVisitor; +import org.objectweb.asm.MethodVisitor; + +/** + * @author Stepan Koltsov + */ +public class JetMethodAnnotationWriter { + private final AnnotationVisitor av; + + private JetMethodAnnotationWriter(AnnotationVisitor av) { + this.av = av; + } + + public void writeKind(int kind) { + if (kind != JvmStdlibNames.JET_METHOD_KIND_DEFAULT) { + av.visit(JvmStdlibNames.JET_METHOD_KIND_FIELD, kind); + } + } + + public void writeTypeParameters(@NotNull String typeParameters) { + if (typeParameters.length() > 0) { + av.visit(JvmStdlibNames.JET_METHOD_TYPE_PARAMETERS_FIELD, typeParameters); + } + } + + public void writeReturnType(@NotNull String returnType) { + if (returnType.length() > 0) { + av.visit(JvmStdlibNames.JET_METHOD_RETURN_TYPE_FIELD, returnType); + } + } + + public void writePropertyType(@NotNull String propertyType) { + if (propertyType.length() > 0) { + av.visit(JvmStdlibNames.JET_METHOD_PROPERTY_TYPE_FIELD, propertyType); + } + } + + public void writeNullableReturnType(boolean nullableReturnType) { + if (nullableReturnType) { + av.visit(JvmStdlibNames.JET_METHOD_NULLABLE_RETURN_TYPE_FIELD, nullableReturnType); + } + } + + public void visitEnd() { + av.visitEnd(); + } + + public static JetMethodAnnotationWriter visitAnnotation(MethodVisitor mv) { + return new JetMethodAnnotationWriter(mv.visitAnnotation(JvmStdlibNames.JET_METHOD.getDescriptor(), true)); + } +} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java index 8ae216a3055..fefe4b7d5f5 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java @@ -13,7 +13,6 @@ 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; @@ -89,7 +88,7 @@ public class PropertyCodegen { if (getter != null) { if (getter.getBodyExpression() != null) { JvmPropertyAccessorSignature signature = state.getTypeMapper().mapGetterSignature(propertyDescriptor, kind); - functionCodegen.generateMethod(getter, signature.getJvmMethodSignature(), signature.getPropertyTypeKotlinSignature(), propertyDescriptor.getGetter()); + functionCodegen.generateMethod(getter, signature.getJvmMethodSignature(), true, signature.getPropertyTypeKotlinSignature(), propertyDescriptor.getGetter()); } else if (!getter.hasModifier(JetTokens.PRIVATE_KEYWORD)) { generateDefaultGetter(p, getter); @@ -111,7 +110,7 @@ public class PropertyCodegen { final PropertySetterDescriptor setterDescriptor = propertyDescriptor.getSetter(); assert setterDescriptor != null; JvmPropertyAccessorSignature signature = state.getTypeMapper().mapSetterSignature(propertyDescriptor, kind); - functionCodegen.generateMethod(setter, signature.getJvmMethodSignature(), signature.getPropertyTypeKotlinSignature(), setterDescriptor); + functionCodegen.generateMethod(setter, signature.getJvmMethodSignature(), true, signature.getPropertyTypeKotlinSignature(), setterDescriptor); } else if (!p.hasModifier(JetTokens.PRIVATE_KEYWORD)) { generateDefaultSetter(p, setter); @@ -170,14 +169,11 @@ 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(); + JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv); + aw.writeKind(JvmStdlibNames.JET_METHOD_KIND_PROPERTY); + aw.writeTypeParameters(typeParameters); + aw.writePropertyType(kotlinType); + aw.visitEnd(); } private void generateDefaultSetter(JetProperty p, JetDeclaration declaration) { 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 cd59eecbb31..6c11541235d 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 @@ -132,12 +132,11 @@ public class JavaDescriptorResolver { private static abstract class ResolverScopeData { @Nullable private Set properties; - private boolean kotlin; + protected boolean kotlin; } private static class ResolverClassData extends ResolverScopeData { private JavaClassDescriptor classDescriptor; - private boolean kotlin; @NotNull public ClassDescriptor getClassDescriptor() { @@ -147,7 +146,6 @@ public class JavaDescriptorResolver { private static class ResolverNamespaceData extends ResolverScopeData { private JavaNamespaceDescriptor namespaceDescriptor; - private boolean kotlin; @NotNull public NamespaceDescriptor getNamespaceDescriptor() { @@ -892,7 +890,7 @@ public class JavaDescriptorResolver { if (psiMethod.getName().startsWith(JvmAbi.GETTER_PREFIX)) { // TODO: some java properties too - if (method.getJetProperty().isDefined()) { + if (method.getJetMethod().kind() == JvmStdlibNames.JET_METHOD_KIND_PROPERTY) { if (psiMethod.getName().equals(JvmStdlibNames.JET_OBJECT_GET_TYPEINFO_METHOD)) { continue; @@ -933,7 +931,7 @@ public class JavaDescriptorResolver { } } else if (psiMethod.getName().startsWith(JvmAbi.SETTER_PREFIX)) { - if (method.getJetProperty().isDefined()) { + if (method.getJetMethod().kind() == JvmStdlibNames.JET_METHOD_KIND_PROPERTY) { if (psiMethod.getParameterList().getParametersCount() == 0) { // TODO: report error properly throw new IllegalStateException(); @@ -1215,7 +1213,7 @@ public class JavaDescriptorResolver { } // TODO: ugly - if (method.getJetProperty().isDefined()) { + if (method.getJetMethod().kind() == JvmStdlibNames.JET_METHOD_KIND_PROPERTY) { return null; } @@ -1308,9 +1306,9 @@ public class JavaDescriptorResolver { @NotNull PsiMethodWrapper method, @NotNull FunctionDescriptor functionDescriptor, @NotNull TypeVariableResolver classTypeVariableResolver) { - if (method.getJetMethodOrProperty().typeParameters().length() > 0) { + if (method.getJetMethod().typeParameters().length() > 0) { List r = resolveMethodTypeParametersFromJetSignature( - method.getJetMethodOrProperty().typeParameters(), method.getPsiMethod(), functionDescriptor, classTypeVariableResolver); + method.getJetMethod().typeParameters(), method.getPsiMethod(), functionDescriptor, classTypeVariableResolver); initializeTypeParameters(method.getPsiMethod()); return r; } 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 66d5ebf2677..8f2ceea64de 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 @@ -24,15 +24,16 @@ public class JvmStdlibNames { public static final JvmClassName JET_METHOD = new JvmClassName("jet.runtime.typeinfo.JetMethod"); + public static final String JET_METHOD_KIND_FIELD = "kind"; public static final String JET_METHOD_NULLABLE_RETURN_TYPE_FIELD = "nullableReturnType"; public static final String JET_METHOD_RETURN_TYPE_FIELD = "returnType"; public static final String JET_METHOD_TYPE_PARAMETERS_FIELD = "typeParameters"; + public static final String JET_METHOD_PROPERTY_TYPE_FIELD = "propertyType"; + + public static final int JET_METHOD_KIND_REGULAR = 0; + public static final int JET_METHOD_KIND_PROPERTY = 1; + public static final int JET_METHOD_KIND_DEFAULT = JET_METHOD_KIND_REGULAR; - 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/PsiMethodWrapper.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/PsiMethodWrapper.java index 7fe74364e9b..911b3d6119b 100644 --- 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 @@ -1,14 +1,11 @@ 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; @@ -62,23 +59,6 @@ public class PsiMethodWrapper extends PsiMemberWrapper { 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/kt/JetMethodAnnotation.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetMethodAnnotation.java index 2f4d954e21c..6a269b37932 100644 --- 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 @@ -9,11 +9,30 @@ import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; /** * @author Stepan Koltsov */ -public class JetMethodAnnotation extends JetMethodOrPropertyAnnotation { +public class JetMethodAnnotation extends PsiAnnotationWrapper { public JetMethodAnnotation(@Nullable PsiAnnotation psiAnnotation) { super(psiAnnotation); } + + private int kind; + private boolean kindInitialized; + public int kind() { + if (!kindInitialized) { + kind = getIntAttribute(JvmStdlibNames.JET_METHOD_KIND_FIELD, JvmStdlibNames.JET_METHOD_KIND_DEFAULT); + kindInitialized = true; + } + return kind; + } + + private String typeParameters; + @NotNull + public String typeParameters() { + if (typeParameters == null) { + typeParameters = getStringAttribute(JvmStdlibNames.JET_METHOD_TYPE_PARAMETERS_FIELD, ""); + } + return typeParameters; + } private String returnType; @NotNull @@ -34,7 +53,16 @@ public class JetMethodAnnotation extends JetMethodOrPropertyAnnotation { } return returnTypeNullable; } - + + private String propertyType; + @NotNull + public String propertyType() { + if (propertyType == null) { + propertyType = getStringAttribute(JvmStdlibNames.JET_METHOD_PROPERTY_TYPE_FIELD, ""); + } + return propertyType; + } + 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 deleted file mode 100644 index e21e5ab0680..00000000000 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetMethodOrPropertyAnnotation.java +++ /dev/null @@ -1,25 +0,0 @@ -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 deleted file mode 100644 index 3ca9a0031f7..00000000000 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetPropertyAnnotation.java +++ /dev/null @@ -1,21 +0,0 @@ -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/PsiAnnotationUtils.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/PsiAnnotationUtils.java index ec611685b02..cae68d2cf2d 100644 --- 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 @@ -19,6 +19,11 @@ public class PsiAnnotationUtils { return getAttribute(annotation, field, defaultValue); } + public static int getIntAttribute(@Nullable PsiAnnotation annotation, @NotNull String field, int defaultValue) { + return getAttribute(annotation, field, defaultValue); + } + + @NotNull private static T getAttribute(@Nullable PsiAnnotation annotation, @NotNull String field, @NotNull T defaultValue) { if (annotation == null) { 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 index 005b49c587f..4ebb9f756cb 100644 --- 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 @@ -33,4 +33,9 @@ public abstract class PsiAnnotationWrapper { protected boolean getBooleanAttribute(String name, boolean defaultValue) { return PsiAnnotationUtils.getBooleanAttribute(psiAnnotation, name, defaultValue); } + + protected int getIntAttribute(String name, int defaultValue) { + return PsiAnnotationUtils.getIntAttribute(psiAnnotation, name, defaultValue); + } + } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamedFunctionDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamedFunctionDescriptor.java index 803b2d0ade8..52668469719 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamedFunctionDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamedFunctionDescriptor.java @@ -3,6 +3,8 @@ package org.jetbrains.jet.lang.descriptors; import org.jetbrains.annotations.NotNull; /** + * ... and also a closure + * * @author Stepan Koltsov */ public interface NamedFunctionDescriptor extends FunctionDescriptor { diff --git a/stdlib/src/jet/runtime/typeinfo/JetMethod.java b/stdlib/src/jet/runtime/typeinfo/JetMethod.java index 47d4c9bf07a..29059a9caad 100644 --- a/stdlib/src/jet/runtime/typeinfo/JetMethod.java +++ b/stdlib/src/jet/runtime/typeinfo/JetMethod.java @@ -17,6 +17,11 @@ import java.lang.annotation.Target; @Target({ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) public @interface JetMethod { + int KIND_REGULAR = 0; + int KIND_PROPERTY = 1; + + int kind() default KIND_REGULAR; + /** * @return type projections or empty */ @@ -37,4 +42,10 @@ public @interface JetMethod { * Return type type unless java type is correct Kotlin type. */ String returnType () default ""; + + /** + * If this is property. + * @return + */ + String propertyType() default ""; } diff --git a/stdlib/src/jet/runtime/typeinfo/JetProperty.java b/stdlib/src/jet/runtime/typeinfo/JetProperty.java deleted file mode 100644 index 2344ebe1fc4..00000000000 --- a/stdlib/src/jet/runtime/typeinfo/JetProperty.java +++ /dev/null @@ -1,17 +0,0 @@ -package jet.runtime.typeinfo; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * @author Stepan Koltsov - */ -@Target({ElementType.METHOD}) -@Retention(RetentionPolicy.RUNTIME) -public @interface JetProperty { - String type() default ""; - - String typeParameters() default ""; -}