Write callable member's kind to JetMethod annotation

Reuse deprecated kind() parameter in JetMethod annotation to store
CallableMemberDescriptor.Kind if it's not DECLARATION.

JavaDescriptorResolver doesn't always resolve members to DECLARATION
anymore, instead it deserializes member's kind from the annotation.

Create DescriptorKindUtils to convert Kind to int value and back.
This commit is contained in:
Alexander Udalov
2012-09-06 18:42:44 +04:00
parent 8a33d390a2
commit cb13995057
9 changed files with 100 additions and 17 deletions
@@ -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.<AnnotationDescriptor>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");
@@ -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;
@@ -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);
}
}
}
@@ -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() {