diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java index e58ed8242a6..746f96e0aa1 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java @@ -40,6 +40,7 @@ import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.java.JvmAbi; import org.jetbrains.jet.lang.resolve.java.JvmClassName; import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; +import org.jetbrains.jet.lang.resolve.java.kt.DescriptorKindUtils; import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; @@ -164,6 +165,7 @@ public class FunctionCodegen extends GenerationStateAware { : JvmStdlibNames.FLAG_FORCE_OPEN_BIT); } aw.writeFlags(kotlinFlags); + aw.writeKind(DescriptorKindUtils.kindToInt(functionDescriptor.getKind())); aw.writeNullableReturnType(functionDescriptor.getReturnType().isNullable()); aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter()); aw.writeReturnType(jvmSignature.getKotlinReturnType()); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index 67159f5bd61..8b3ac87c030 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -46,6 +46,7 @@ import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; import org.jetbrains.jet.lang.resolve.java.JvmAbi; import org.jetbrains.jet.lang.resolve.java.JvmClassName; import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; +import org.jetbrains.jet.lang.resolve.java.kt.DescriptorKindUtils; import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; import org.jetbrains.jet.lexer.JetTokens; @@ -381,6 +382,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv); BitSet kotlinFlags = getFlagsForVisibility(function.getVisibility()); aw.writeFlags(kotlinFlags); + aw.writeKind(DescriptorKindUtils.kindToInt(function.getKind())); aw.writeNullableReturnType(returnType.isNullable()); JvmMethodSignature jvmMethodSignature = typeMapper.mapToCallableMethod(function, false, kind).getSignature(); aw.writeReturnType(jvmMethodSignature.getKotlinReturnType()); @@ -999,6 +1001,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { aw.writeReturnType(jvmSignature.getKotlinReturnType()); } aw.writeFlags(kotlinFlags); + aw.writeKind(DescriptorKindUtils.kindToInt(inheritedFun.getKind())); aw.visitEnd(); if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) { diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java index 1a57f984628..85d7c5db509 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java @@ -35,6 +35,7 @@ import org.jetbrains.jet.lang.resolve.DescriptorUtils; 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.lang.resolve.java.kt.DescriptorKindUtils; import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; @@ -258,6 +259,7 @@ public class PropertyCodegen extends GenerationStateAware { : JvmStdlibNames.FLAG_FORCE_OPEN_BIT); } aw.writeFlags(flags); + aw.writeKind(DescriptorKindUtils.kindToInt(propertyDescriptor.getKind())); aw.writeTypeParameters(typeParameters); aw.writePropertyType(kotlinType); aw.visitEnd(); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/signature/kotlin/JetMethodAnnotationWriter.java b/compiler/backend/src/org/jetbrains/jet/codegen/signature/kotlin/JetMethodAnnotationWriter.java index 3ceba45f16d..e8425a5c9f1 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/signature/kotlin/JetMethodAnnotationWriter.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/signature/kotlin/JetMethodAnnotationWriter.java @@ -20,6 +20,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.asm4.AnnotationVisitor; import org.jetbrains.asm4.MethodVisitor; import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; +import org.jetbrains.jet.lang.resolve.java.kt.DescriptorKindUtils; import org.jetbrains.jet.utils.BitSetUtils; import java.util.BitSet; @@ -41,6 +42,12 @@ public class JetMethodAnnotationWriter { } } + public void writeKind(int kind) { + if (kind != DescriptorKindUtils.getDefaultKindValue()) { + 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); 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 7c18fba3610..1a9b6a5b2c0 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 @@ -33,7 +33,9 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.resolve.*; import org.jetbrains.jet.lang.resolve.constants.*; import org.jetbrains.jet.lang.resolve.constants.StringValue; +import org.jetbrains.jet.lang.resolve.java.kt.DescriptorKindUtils; import org.jetbrains.jet.lang.resolve.java.kt.JetClassAnnotation; +import org.jetbrains.jet.lang.resolve.java.kt.JetMethodAnnotation; import org.jetbrains.jet.lang.resolve.java.kt.PsiAnnotationWithFlags; import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.name.FqNameBase; @@ -1170,9 +1172,12 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes } Visibility visibility = resolveVisibility(anyMember.getMember().psiMember, null); + CallableMemberDescriptor.Kind kind = CallableMemberDescriptor.Kind.DECLARATION; + if (members.getter != null && members.getter.getMember() instanceof PsiMethodWrapper) { - visibility = resolveVisibility(anyMember.getMember().psiMember, - ((PsiMethodWrapper) members.getter.getMember()).getJetMethod()); + JetMethodAnnotation jetMethod = ((PsiMethodWrapper) members.getter.getMember()).getJetMethod(); + visibility = resolveVisibility(anyMember.getMember().psiMember, jetMethod); + kind = DescriptorKindUtils.intToKind(jetMethod.kind()); } DeclarationDescriptor realOwner = getRealOwner(owner, scopeData, anyMember.getMember().isStatic()); @@ -1185,7 +1190,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes visibility, isVar, propertyName, - CallableMemberDescriptor.Kind.DECLARATION); + kind); //TODO: this is a hack to indicate that this enum entry is an object // class descriptor for enum entries is not used by backends so for now this should be safe to use @@ -1211,7 +1216,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes visibility, true, false, - CallableMemberDescriptor.Kind.DECLARATION); + kind); } if (members.setter != null) { Visibility setterVisibility = resolveVisibility(members.setter.getMember().psiMember, null); @@ -1226,7 +1231,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes setterVisibility, true, false, - CallableMemberDescriptor.Kind.DECLARATION); + kind); } propertyDescriptor.initialize(getterDescriptor, setterDescriptor); @@ -1289,7 +1294,9 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes setterDescriptor.initialize(new ValueParameterDescriptorImpl(setterDescriptor, 0, Collections.emptyList(), Name.identifier("p0") /*TODO*/, false, propertyDescriptor.getType(), false, null)); } - trace.record(BindingContext.VARIABLE, anyMember.getMember().psiMember, propertyDescriptor); + if (kind == CallableMemberDescriptor.Kind.DECLARATION) { + trace.record(BindingContext.VARIABLE, anyMember.getMember().psiMember, propertyDescriptor); + } propertiesFromCurrent.add(propertyDescriptor); } @@ -1505,7 +1512,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes scopeData.classOrNamespaceDescriptor, resolveAnnotations(method.getPsiMethod()), Name.identifier(method.getName()), - CallableMemberDescriptor.Kind.DECLARATION + DescriptorKindUtils.intToKind(method.getJetMethod().kind()) ); String context = "method " + method.getName() + " in class " + psiClass.getQualifiedName(); @@ -1538,7 +1545,9 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes /*isInline = */ false ); - BindingContextUtils.recordFunctionDeclarationToDescriptor(tempTrace, method.getPsiMethod(), functionDescriptorImpl); + if (functionDescriptorImpl.getKind() == CallableMemberDescriptor.Kind.DECLARATION) { + BindingContextUtils.recordFunctionDeclarationToDescriptor(tempTrace, method.getPsiMethod(), functionDescriptorImpl); + } if (method.getPsiMethod().getContainingClass() != psiClass && !method.isStatic()) { throw new IllegalStateException("non-static method in subclass"); 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 8dfe5a60116..7b0288f7c36 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 @@ -40,7 +40,6 @@ public class JvmStdlibNames { public static final JvmClassName JET_METHOD = JvmClassName.byFqNameWithoutInnerClasses("jet.runtime.typeinfo.JetMethod"); - @Deprecated public static final String JET_METHOD_KIND_FIELD = "kind"; public static final String JET_METHOD_FLAGS_FIELD = "flags"; public static final String JET_METHOD_NULLABLE_RETURN_TYPE_FIELD = "nullableReturnType"; @@ -49,7 +48,7 @@ public class JvmStdlibNames { public static final String JET_METHOD_PROPERTY_TYPE_FIELD = "propertyType"; public static final int FLAGS_DEFAULT_VALUE = 0; - public static final int FLAGS_BITS = 5; + public static final int FLAG_PROPERTY_BIT = 0; public static final int FLAG_FORCE_OPEN_BIT = 1; public static final int FLAG_FORCE_FINAL_BIT = 2; diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/DescriptorKindUtils.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/DescriptorKindUtils.java new file mode 100644 index 00000000000..ebbbea223c0 --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/DescriptorKindUtils.java @@ -0,0 +1,56 @@ +/* + * 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. + */ + +package org.jetbrains.jet.lang.resolve.java.kt; + +import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor; + +/** + * @author udalov + */ +public class DescriptorKindUtils { + private static final int KIND_DECLARATION = 0; + private static final int KIND_FAKE_OVERRIDE = 1; + private static final int KIND_DELEGATION = 2; + private static final int KIND_SYNTHESIZED = 3; + + private DescriptorKindUtils() { + } + + public static int getDefaultKindValue() { + return KIND_DECLARATION; + } + + public static int kindToInt(CallableMemberDescriptor.Kind kind) { + switch (kind) { + case DECLARATION: return KIND_DECLARATION; + case FAKE_OVERRIDE: return KIND_FAKE_OVERRIDE; + case DELEGATION: return KIND_DELEGATION; + case SYNTHESIZED: return KIND_SYNTHESIZED; + default: throw new IllegalArgumentException("Unknown kind: " + kind); + } + } + + public static CallableMemberDescriptor.Kind intToKind(int value) { + switch (value) { + case KIND_DECLARATION: return CallableMemberDescriptor.Kind.DECLARATION; + case KIND_FAKE_OVERRIDE: return CallableMemberDescriptor.Kind.FAKE_OVERRIDE; + case KIND_DELEGATION: return CallableMemberDescriptor.Kind.DELEGATION; + case KIND_SYNTHESIZED: return CallableMemberDescriptor.Kind.SYNTHESIZED; + default: throw new IllegalArgumentException("Unknown int value of kind: " + value); + } + } +} 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 5f6300ab75f..cc06fc498ba 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 @@ -40,16 +40,21 @@ public class JetMethodAnnotation extends PsiAnnotationWithFlags { public BitSet flags() { if (flags == null) { int flagsValue = getIntAttribute(JvmStdlibNames.JET_METHOD_FLAGS_FIELD, JvmStdlibNames.FLAGS_DEFAULT_VALUE); - if (flagsValue == JvmStdlibNames.FLAGS_DEFAULT_VALUE) { - // for compatibility - flagsValue = getIntAttribute(JvmStdlibNames.JET_METHOD_KIND_FIELD, JvmStdlibNames.FLAGS_DEFAULT_VALUE); - } - flags = BitSetUtils.toBitSet(flagsValue); } return flags; } + private int kind; + private boolean kindInitialized; + public int kind() { + if (!kindInitialized) { + kind = getIntAttribute(JvmStdlibNames.JET_METHOD_KIND_FIELD, DescriptorKindUtils.getDefaultKindValue()); + kindInitialized = true; + } + return kind; + } + private String typeParameters; @NotNull public String typeParameters() { diff --git a/runtime/src/jet/runtime/typeinfo/JetMethod.java b/runtime/src/jet/runtime/typeinfo/JetMethod.java index c53ca49de56..30ca2b7ea2f 100644 --- a/runtime/src/jet/runtime/typeinfo/JetMethod.java +++ b/runtime/src/jet/runtime/typeinfo/JetMethod.java @@ -34,9 +34,9 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) public @interface JetMethod { /** - * @deprecated use flags instead + * See CallableMemberDescriptor.Kind + * @return kind of this method */ - @Deprecated int kind() default 0; /**