- small optimizations of JavaDescriptorResolver

- kind of method encoded in flags
- nullable return type encoded in flags
This commit is contained in:
Alex Tkachman
2012-09-23 12:08:55 +02:00
parent 56232266fd
commit 1ec32810f4
18 changed files with 186 additions and 217 deletions
@@ -37,7 +37,10 @@ import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.lang.JetStandardClasses; import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
import java.util.*; import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE; import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
@@ -102,16 +105,14 @@ public class CodegenUtil {
} }
@NotNull public static int getFlagsForVisibility(@NotNull Visibility visibility) {
public static BitSet getFlagsForVisibility(@NotNull Visibility visibility) {
BitSet flags = new BitSet();
if (visibility == Visibilities.INTERNAL) { if (visibility == Visibilities.INTERNAL) {
flags.set(JvmStdlibNames.FLAG_INTERNAL_BIT); return JvmStdlibNames.FLAG_INTERNAL_BIT;
} }
else if (visibility == Visibilities.PRIVATE) { else if (visibility == Visibilities.PRIVATE) {
flags.set(JvmStdlibNames.FLAG_PRIVATE_BIT); return JvmStdlibNames.FLAG_PRIVATE_BIT;
} }
return flags; return 0;
} }
@NotNull @NotNull
@@ -348,16 +348,17 @@ public class FunctionCodegen extends GenerationStateAware {
throw new IllegalStateException(); throw new IllegalStateException();
} }
JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv); JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv);
BitSet kotlinFlags = getFlagsForVisibility(functionDescriptor.getVisibility()); int kotlinFlags = getFlagsForVisibility(functionDescriptor.getVisibility());
if (isInterface(functionDescriptor.getContainingDeclaration()) && modality != Modality.ABSTRACT) { if (isInterface(functionDescriptor.getContainingDeclaration()) && modality != Modality.ABSTRACT) {
kotlinFlags.set(modality == Modality.FINAL kotlinFlags |= modality == Modality.FINAL
? JvmStdlibNames.FLAG_FORCE_FINAL_BIT ? JvmStdlibNames.FLAG_FORCE_FINAL_BIT
: JvmStdlibNames.FLAG_FORCE_OPEN_BIT); : JvmStdlibNames.FLAG_FORCE_OPEN_BIT;
} }
aw.writeFlags(kotlinFlags); kotlinFlags |= DescriptorKindUtils.kindToFlags(functionDescriptor.getKind());
aw.writeKind(DescriptorKindUtils.kindToInt(functionDescriptor.getKind()));
//noinspection ConstantConditions //noinspection ConstantConditions
aw.writeNullableReturnType(functionDescriptor.getReturnType().isNullable()); if (functionDescriptor.getReturnType().isNullable())
kotlinFlags |= JvmStdlibNames.FLAG_NULLABLE_RETURN_TYPE_BIT;
aw.writeFlags(kotlinFlags);
aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter()); aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter());
aw.writeReturnType(jvmSignature.getKotlinReturnType()); aw.writeReturnType(jvmSignature.getKotlinReturnType());
aw.visitEnd(); aw.visitEnd();
@@ -53,7 +53,6 @@ import org.jetbrains.jet.lang.resolve.java.kt.DescriptorKindUtils;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.jet.lexer.JetTokens; import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.utils.BitSetUtils;
import java.util.*; import java.util.*;
@@ -248,10 +247,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
if (signature.getKotlinGenericSignature() != null || descriptor.getVisibility() != Visibilities.PUBLIC) { if (signature.getKotlinGenericSignature() != null || descriptor.getVisibility() != Visibilities.PUBLIC) {
AnnotationVisitor annotationVisitor = v.newAnnotation(JvmStdlibNames.JET_CLASS.getDescriptor(), true); AnnotationVisitor annotationVisitor = v.newAnnotation(JvmStdlibNames.JET_CLASS.getDescriptor(), true);
annotationVisitor.visit(JvmStdlibNames.JET_CLASS_SIGNATURE, signature.getKotlinGenericSignature()); annotationVisitor.visit(JvmStdlibNames.JET_CLASS_SIGNATURE, signature.getKotlinGenericSignature());
BitSet flags = getFlagsForVisibility(descriptor.getVisibility()); int flags = getFlagsForVisibility(descriptor.getVisibility());
int flagsValue = BitSetUtils.toInt(flags); if (JvmStdlibNames.FLAGS_DEFAULT_VALUE != flags) {
if (JvmStdlibNames.FLAGS_DEFAULT_VALUE != flagsValue) { annotationVisitor.visit(JvmStdlibNames.JET_FLAGS_FIELD, flags);
annotationVisitor.visit(JvmStdlibNames.JET_CLASS_FLAGS_FIELD, flagsValue);
} }
annotationVisitor.visitEnd(); annotationVisitor.visitEnd();
} }
@@ -827,9 +825,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
AnnotationVisitor jetConstructorVisitor = mv.visitAnnotation(JvmStdlibNames.JET_CONSTRUCTOR.getDescriptor(), true); AnnotationVisitor jetConstructorVisitor = mv.visitAnnotation(JvmStdlibNames.JET_CONSTRUCTOR.getDescriptor(), true);
int flagsValue = BitSetUtils.toInt(getFlagsForVisibility(constructorDescriptor.getVisibility())); int flagsValue = getFlagsForVisibility(constructorDescriptor.getVisibility());
if (JvmStdlibNames.FLAGS_DEFAULT_VALUE != flagsValue) { if (JvmStdlibNames.FLAGS_DEFAULT_VALUE != flagsValue) {
jetConstructorVisitor.visit(JvmStdlibNames.JET_CLASS_FLAGS_FIELD, flagsValue); jetConstructorVisitor.visit(JvmStdlibNames.JET_FLAGS_FIELD, flagsValue);
} }
jetConstructorVisitor.visitEnd(); jetConstructorVisitor.visitEnd();
@@ -1218,21 +1216,22 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
JvmMethodSignature jvmSignature = JvmMethodSignature jvmSignature =
typeMapper.mapToCallableMethod(inheritedFun, false, OwnerKind.IMPLEMENTATION).getSignature(); typeMapper.mapToCallableMethod(inheritedFun, false, OwnerKind.IMPLEMENTATION).getSignature();
JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv); JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv);
BitSet kotlinFlags = getFlagsForVisibility(fun.getVisibility()); int kotlinFlags = getFlagsForVisibility(fun.getVisibility());
if (fun instanceof PropertyAccessorDescriptor) { if (fun instanceof PropertyAccessorDescriptor) {
kotlinFlags.set(JvmStdlibNames.FLAG_PROPERTY_BIT); kotlinFlags |= JvmStdlibNames.FLAG_PROPERTY_BIT;
aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter()); aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter());
aw.writePropertyType(jvmSignature.getKotlinReturnType()); aw.writePropertyType(jvmSignature.getKotlinReturnType());
} }
else { else {
JetType returnType = fun.getReturnType(); JetType returnType = fun.getReturnType();
assert returnType != null; assert returnType != null;
aw.writeNullableReturnType(returnType.isNullable()); if (returnType.isNullable())
kotlinFlags |= JvmStdlibNames.FLAG_NULLABLE_RETURN_TYPE_BIT;
aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter()); aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter());
aw.writeReturnType(jvmSignature.getKotlinReturnType()); aw.writeReturnType(jvmSignature.getKotlinReturnType());
} }
kotlinFlags |= DescriptorKindUtils.kindToFlags(inheritedFun.getKind());
aw.writeFlags(kotlinFlags); aw.writeFlags(kotlinFlags);
aw.writeKind(DescriptorKindUtils.kindToInt(inheritedFun.getKind()));
aw.visitEnd(); aw.visitEnd();
if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) { if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) {
@@ -39,8 +39,6 @@ import org.jetbrains.jet.lang.resolve.java.kt.DescriptorKindUtils;
import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import java.util.BitSet;
import static org.jetbrains.asm4.Opcodes.*; import static org.jetbrains.asm4.Opcodes.*;
import static org.jetbrains.jet.codegen.AsmUtil.genStubThrow; import static org.jetbrains.jet.codegen.AsmUtil.genStubThrow;
import static org.jetbrains.jet.codegen.AsmUtil.getVisibilityAccessFlag; import static org.jetbrains.jet.codegen.AsmUtil.getVisibilityAccessFlag;
@@ -254,15 +252,13 @@ public class PropertyCodegen extends GenerationStateAware {
) { ) {
JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv); JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv);
Modality modality = propertyDescriptor.getModality(); Modality modality = propertyDescriptor.getModality();
BitSet flags = getFlagsForVisibility(visibility); int flags = getFlagsForVisibility(visibility) | JvmStdlibNames.FLAG_PROPERTY_BIT;
flags.set(JvmStdlibNames.FLAG_PROPERTY_BIT);
if (isInterface(propertyDescriptor.getContainingDeclaration()) && modality != Modality.ABSTRACT) { if (isInterface(propertyDescriptor.getContainingDeclaration()) && modality != Modality.ABSTRACT) {
flags.set(modality == Modality.FINAL flags |= modality == Modality.FINAL
? JvmStdlibNames.FLAG_FORCE_FINAL_BIT ? JvmStdlibNames.FLAG_FORCE_FINAL_BIT
: JvmStdlibNames.FLAG_FORCE_OPEN_BIT); : JvmStdlibNames.FLAG_FORCE_OPEN_BIT;
} }
aw.writeFlags(flags); aw.writeFlags(flags | DescriptorKindUtils.kindToFlags(propertyDescriptor.getKind()));
aw.writeKind(DescriptorKindUtils.kindToInt(propertyDescriptor.getKind()));
aw.writeTypeParameters(typeParameters); aw.writeTypeParameters(typeParameters);
aw.writePropertyType(kotlinType); aw.writePropertyType(kotlinType);
aw.visitEnd(); aw.visitEnd();
@@ -20,10 +20,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.asm4.AnnotationVisitor; import org.jetbrains.asm4.AnnotationVisitor;
import org.jetbrains.asm4.MethodVisitor; import org.jetbrains.asm4.MethodVisitor;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; 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;
/** /**
* @author Stepan Koltsov * @author Stepan Koltsov
@@ -35,16 +31,9 @@ public class JetMethodAnnotationWriter {
this.av = av; this.av = av;
} }
public void writeFlags(BitSet flags) { public void writeFlags(int flags) {
int flagsValue = BitSetUtils.toInt(flags); if (flags != JvmStdlibNames.FLAGS_DEFAULT_VALUE) {
if (flagsValue != JvmStdlibNames.FLAGS_DEFAULT_VALUE) { av.visit(JvmStdlibNames.JET_FLAGS_FIELD, flags);
av.visit(JvmStdlibNames.JET_METHOD_FLAGS_FIELD, flagsValue);
}
}
public void writeKind(int kind) {
if (kind != DescriptorKindUtils.getDefaultKindValue()) {
av.visit(JvmStdlibNames.JET_METHOD_KIND_FIELD, kind);
} }
} }
@@ -66,12 +55,6 @@ public class JetMethodAnnotationWriter {
} }
} }
public void writeNullableReturnType(boolean nullableReturnType) {
if (nullableReturnType) {
av.visit(JvmStdlibNames.JET_METHOD_NULLABLE_RETURN_TYPE_FIELD, nullableReturnType);
}
}
public void visitEnd() { public void visitEnd() {
av.visitEnd(); av.visitEnd();
} }
@@ -1214,7 +1214,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
if (members.getter != null && members.getter.getMember() instanceof PsiMethodWrapper) { if (members.getter != null && members.getter.getMember() instanceof PsiMethodWrapper) {
JetMethodAnnotation jetMethod = ((PsiMethodWrapper) members.getter.getMember()).getJetMethod(); JetMethodAnnotation jetMethod = ((PsiMethodWrapper) members.getter.getMember()).getJetMethod();
visibility = resolveVisibility(anyMember.getMember().psiMember, jetMethod); visibility = resolveVisibility(anyMember.getMember().psiMember, jetMethod);
kind = DescriptorKindUtils.intToKind(jetMethod.kind()); kind = DescriptorKindUtils.flagsToKind(jetMethod.kind());
} }
DeclarationDescriptor realOwner = getRealOwner(owner, scopeData, anyMember.getMember().isStatic()); DeclarationDescriptor realOwner = getRealOwner(owner, scopeData, anyMember.getMember().isStatic());
@@ -1533,7 +1533,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
} }
// TODO: ugly // TODO: ugly
if (method.getJetMethod().flags().get(JvmStdlibNames.FLAG_PROPERTY_BIT)) { if (method.getJetMethod().hasPropertyFlag()) {
return null; return null;
} }
@@ -1549,7 +1549,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
scopeData.classOrNamespaceDescriptor, scopeData.classOrNamespaceDescriptor,
resolveAnnotations(method.getPsiMethod()), resolveAnnotations(method.getPsiMethod()),
Name.identifier(method.getName()), Name.identifier(method.getName()),
DescriptorKindUtils.intToKind(method.getJetMethod().kind()) DescriptorKindUtils.flagsToKind(method.getJetMethod().kind())
); );
String context = "method " + method.getName() + " in class " + psiClass.getQualifiedName(); String context = "method " + method.getName() + " in class " + psiClass.getQualifiedName();
@@ -1893,10 +1893,10 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
private static Modality resolveModality(PsiMemberWrapper memberWrapper, boolean isFinal) { private static Modality resolveModality(PsiMemberWrapper memberWrapper, boolean isFinal) {
if (memberWrapper instanceof PsiMethodWrapper) { if (memberWrapper instanceof PsiMethodWrapper) {
PsiMethodWrapper method = (PsiMethodWrapper) memberWrapper; PsiMethodWrapper method = (PsiMethodWrapper) memberWrapper;
if (method.getJetMethod().flags().get(JvmStdlibNames.FLAG_FORCE_OPEN_BIT)) { if (method.getJetMethod().hasForceOpenFlag()) {
return Modality.OPEN; return Modality.OPEN;
} }
if (method.getJetMethod().flags().get(JvmStdlibNames.FLAG_FORCE_FINAL_BIT)) { if (method.getJetMethod().hasForceFinalFlag()) {
return Modality.FINAL; return Modality.FINAL;
} }
} }
@@ -1907,11 +1907,10 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
private static Visibility resolveVisibility(PsiModifierListOwner modifierListOwner, private static Visibility resolveVisibility(PsiModifierListOwner modifierListOwner,
@Nullable PsiAnnotationWithFlags annotation) { @Nullable PsiAnnotationWithFlags annotation) {
if (annotation != null) { if (annotation != null) {
BitSet flags = annotation.flags(); if (annotation.hasPrivateFlag()) {
if (flags.get(JvmStdlibNames.FLAG_PRIVATE_BIT)) {
return Visibilities.PRIVATE; return Visibilities.PRIVATE;
} }
else if (flags.get(JvmStdlibNames.FLAG_INTERNAL_BIT)) { else if (annotation.hasInternalFlag()) {
return Visibilities.INTERNAL; return Visibilities.INTERNAL;
} }
} }
@@ -131,7 +131,7 @@ class JavaDescriptorResolverHelper {
NamedMembers members = getNamedMembers(Name.identifier(propertyName)); NamedMembers members = getNamedMembers(Name.identifier(propertyName));
// TODO: some java properties too // TODO: some java properties too
if (method.getJetMethod().flags().get(JvmStdlibNames.FLAG_PROPERTY_BIT)) { if (method.getJetMethod().hasPropertyFlag()) {
int i = 0; int i = 0;
@@ -173,7 +173,7 @@ class JavaDescriptorResolverHelper {
String propertyName = propertyParseResult.getPropertyName(); String propertyName = propertyParseResult.getPropertyName();
NamedMembers members = getNamedMembers(Name.identifier(propertyName)); NamedMembers members = getNamedMembers(Name.identifier(propertyName));
if (method.getJetMethod().flags().get(JvmStdlibNames.FLAG_PROPERTY_BIT)) { if (method.getJetMethod().hasPropertyFlag()) {
if (method.getParameters().size() == 0) { if (method.getParameters().size() == 0) {
// TODO: report error properly // TODO: report error properly
throw new IllegalStateException(); throw new IllegalStateException();
@@ -210,7 +210,7 @@ class JavaDescriptorResolverHelper {
} }
} }
if (!method.getJetMethod().flags().get(JvmStdlibNames.FLAG_PROPERTY_BIT)) { if (!method.getJetMethod().hasPropertyFlag()) {
NamedMembers namedMembers = getNamedMembers(Name.identifier(method.getName())); NamedMembers namedMembers = getNamedMembers(Name.identifier(method.getName()));
namedMembers.addMethod(method); namedMembers.addMethod(method);
} }
@@ -17,7 +17,6 @@
package org.jetbrains.jet.lang.resolve.java; package org.jetbrains.jet.lang.resolve.java;
import jet.runtime.typeinfo.JetConstructor; import jet.runtime.typeinfo.JetConstructor;
import jet.runtime.typeinfo.KotlinSignature;
/** /**
* @author Stepan Koltsov * @author Stepan Koltsov
@@ -40,20 +39,27 @@ public class JvmStdlibNames {
public static final JvmClassName JET_METHOD = JvmClassName.byFqNameWithoutInnerClasses("jet.runtime.typeinfo.JetMethod"); public static final JvmClassName JET_METHOD = JvmClassName.byFqNameWithoutInnerClasses("jet.runtime.typeinfo.JetMethod");
public static final String JET_METHOD_KIND_FIELD = "kind"; public static final String JET_FLAGS_FIELD = "flags";
public static final String JET_METHOD_FLAGS_FIELD = "flags";
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_RETURN_TYPE_FIELD = "returnType";
public static final String JET_METHOD_TYPE_PARAMETERS_FIELD = "typeParameters"; public static final String JET_METHOD_TYPE_PARAMETERS_FIELD = "typeParameters";
public static final String JET_METHOD_PROPERTY_TYPE_FIELD = "propertyType"; public static final String JET_METHOD_PROPERTY_TYPE_FIELD = "propertyType";
public static final int FLAGS_DEFAULT_VALUE = 0; public static final int FLAGS_DEFAULT_VALUE = 0;
public static final int FLAG_PROPERTY_BIT = 0; public static final int FLAG_PROPERTY_BIT = 1 << 0;
public static final int FLAG_FORCE_OPEN_BIT = 1; public static final int FLAG_FORCE_OPEN_BIT = 1 << 1;
public static final int FLAG_FORCE_FINAL_BIT = 2; public static final int FLAG_FORCE_FINAL_BIT = 1 << 2;
public static final int FLAG_PRIVATE_BIT = 3; public static final int FLAG_PRIVATE_BIT = 1 << 3;
public static final int FLAG_INTERNAL_BIT = 4; public static final int FLAG_INTERNAL_BIT = 1 << 4;
public static final int FLAG_NULLABLE_RETURN_TYPE_BIT = 1 << 5;
// three bits (one reserved)
public static final int FLAG_KIND_MASK = 7 << 6;
public static final int FLAG_KIND_DECLARATION = 0 << 6;
public static final int FLAG_KIND_FAKE_OVERRIDE = 1 << 6;
public static final int FLAG_KIND_DELEGATION = 2 << 6;
public static final int FLAG_KIND_SYNTHESIZED = 3 << 6;
public static final JvmClassName JET_CONSTRUCTOR = JvmClassName.byFqNameWithoutInnerClasses("jet.runtime.typeinfo.JetConstructor"); public static final JvmClassName JET_CONSTRUCTOR = JvmClassName.byFqNameWithoutInnerClasses("jet.runtime.typeinfo.JetConstructor");
@@ -62,13 +68,11 @@ public class JvmStdlibNames {
* @see JetConstructor#hidden() * @see JetConstructor#hidden()
*/ */
public static final String JET_CONSTRUCTOR_HIDDEN_FIELD = "hidden"; public static final String JET_CONSTRUCTOR_HIDDEN_FIELD = "hidden";
public static final String JET_CONSTRUCTOR_FLAGS_FIELD = "flags";
public static final JvmClassName JET_CLASS = JvmClassName.byFqNameWithoutInnerClasses("jet.runtime.typeinfo.JetClass"); public static final JvmClassName JET_CLASS = JvmClassName.byFqNameWithoutInnerClasses("jet.runtime.typeinfo.JetClass");
public static final String JET_CLASS_SIGNATURE = "signature"; public static final String JET_CLASS_SIGNATURE = "signature";
public static final String JET_CLASS_FLAGS_FIELD = "flags";
public static final JvmClassName JET_OBJECT = JvmClassName.byFqNameWithoutInnerClasses("jet.JetObject"); public static final JvmClassName JET_OBJECT = JvmClassName.byFqNameWithoutInnerClasses("jet.JetObject");
@@ -17,39 +17,32 @@
package org.jetbrains.jet.lang.resolve.java.kt; package org.jetbrains.jet.lang.resolve.java.kt;
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor; import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
/** /**
* @author udalov * @author udalov
* @author alex.tkachman
*/ */
public class DescriptorKindUtils { 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() { private DescriptorKindUtils() {
} }
public static int getDefaultKindValue() { public static int kindToFlags(CallableMemberDescriptor.Kind kind) {
return KIND_DECLARATION;
}
public static int kindToInt(CallableMemberDescriptor.Kind kind) {
switch (kind) { switch (kind) {
case DECLARATION: return KIND_DECLARATION; case DECLARATION: return JvmStdlibNames.FLAG_KIND_DECLARATION;
case FAKE_OVERRIDE: return KIND_FAKE_OVERRIDE; case FAKE_OVERRIDE: return JvmStdlibNames.FLAG_KIND_FAKE_OVERRIDE;
case DELEGATION: return KIND_DELEGATION; case DELEGATION: return JvmStdlibNames.FLAG_KIND_DELEGATION;
case SYNTHESIZED: return KIND_SYNTHESIZED; case SYNTHESIZED: return JvmStdlibNames.FLAG_KIND_SYNTHESIZED;
default: throw new IllegalArgumentException("Unknown kind: " + kind); default: throw new IllegalArgumentException("Unknown kind: " + kind);
} }
} }
public static CallableMemberDescriptor.Kind intToKind(int value) { public static CallableMemberDescriptor.Kind flagsToKind(int value) {
switch (value) { switch (value & JvmStdlibNames.FLAG_KIND_MASK) {
case KIND_DECLARATION: return CallableMemberDescriptor.Kind.DECLARATION; case JvmStdlibNames.FLAG_KIND_DECLARATION: return CallableMemberDescriptor.Kind.DECLARATION;
case KIND_FAKE_OVERRIDE: return CallableMemberDescriptor.Kind.FAKE_OVERRIDE; case JvmStdlibNames.FLAG_KIND_FAKE_OVERRIDE: return CallableMemberDescriptor.Kind.FAKE_OVERRIDE;
case KIND_DELEGATION: return CallableMemberDescriptor.Kind.DELEGATION; case JvmStdlibNames.FLAG_KIND_DELEGATION: return CallableMemberDescriptor.Kind.DELEGATION;
case KIND_SYNTHESIZED: return CallableMemberDescriptor.Kind.SYNTHESIZED; case JvmStdlibNames.FLAG_KIND_SYNTHESIZED: return CallableMemberDescriptor.Kind.SYNTHESIZED;
default: throw new IllegalArgumentException("Unknown int value of kind: " + value); default: throw new IllegalArgumentException("Unknown int value of kind: " + value);
} }
} }
@@ -22,37 +22,29 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver; import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
import org.jetbrains.jet.utils.BitSetUtils;
import java.util.BitSet;
/** /**
* @author Stepan Koltsov * @author Stepan Koltsov
*/ */
public class JetClassAnnotation extends PsiAnnotationWithFlags { public class JetClassAnnotation extends PsiAnnotationWithFlags {
private String signature;
public JetClassAnnotation(@Nullable PsiAnnotation psiAnnotation) { public JetClassAnnotation(@Nullable PsiAnnotation psiAnnotation) {
super(psiAnnotation); super(psiAnnotation);
} }
private String signature; @Override
protected void initialize() {
super.initialize();
signature = getStringAttribute(JvmStdlibNames.JET_CLASS_SIGNATURE, "");
}
public String signature() { public String signature() {
if (signature == null) { checkInitialized();
signature = getStringAttribute(JvmStdlibNames.JET_CLASS_SIGNATURE, "");
}
return signature; return signature;
} }
private BitSet flags = null;
@NotNull
public BitSet flags() {
if (flags == null) {
flags = BitSetUtils.toBitSet(getIntAttribute(JvmStdlibNames.JET_CLASS_FLAGS_FIELD, JvmStdlibNames.FLAGS_DEFAULT_VALUE));
}
return flags;
}
@NotNull @NotNull
public static JetClassAnnotation get(PsiClass psiClass) { public static JetClassAnnotation get(PsiClass psiClass) {
return new JetClassAnnotation(JavaDescriptorResolver.findAnnotation(psiClass, JvmStdlibNames.JET_CLASS.getFqName().getFqName())); return new JetClassAnnotation(JavaDescriptorResolver.findAnnotation(psiClass, JvmStdlibNames.JET_CLASS.getFqName().getFqName()));
@@ -18,13 +18,9 @@ package org.jetbrains.jet.lang.resolve.java.kt;
import com.intellij.psi.PsiAnnotation; import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiMethod; import com.intellij.psi.PsiMethod;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver; import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
import org.jetbrains.jet.utils.BitSetUtils;
import java.util.BitSet;
/** /**
* @author Stepan Koltsov * @author Stepan Koltsov
@@ -35,27 +31,20 @@ public class JetConstructorAnnotation extends PsiAnnotationWithFlags {
super(psiAnnotation); super(psiAnnotation);
} }
@Override
protected void initialize() {
super.initialize();
hidden = getBooleanAttribute(JvmStdlibNames.JET_CONSTRUCTOR_HIDDEN_FIELD, false);
}
private boolean hidden; private boolean hidden;
private boolean hiddenInitialized = false;
/** @deprecated */ /** @deprecated */
public boolean hidden() { public boolean hidden() {
if (!hiddenInitialized) { checkInitialized();
hidden = getBooleanAttribute(JvmStdlibNames.JET_CONSTRUCTOR_HIDDEN_FIELD, false);
hiddenInitialized = true;
}
return hidden; return hidden;
} }
private BitSet flags;
@NotNull
@Override
public BitSet flags() {
if (flags == null) {
flags = BitSetUtils.toBitSet(getIntAttribute(JvmStdlibNames.JET_CONSTRUCTOR_FLAGS_FIELD, JvmStdlibNames.FLAGS_DEFAULT_VALUE));
}
return flags;
}
public static JetConstructorAnnotation get(PsiMethod constructor) { public static JetConstructorAnnotation get(PsiMethod constructor) {
return new JetConstructorAnnotation(JavaDescriptorResolver.findAnnotation(constructor, JvmStdlibNames.JET_CONSTRUCTOR.getFqName().getFqName())); return new JetConstructorAnnotation(JavaDescriptorResolver.findAnnotation(constructor, JvmStdlibNames.JET_CONSTRUCTOR.getFqName().getFqName()));
} }
@@ -22,74 +22,52 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver; import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
import org.jetbrains.jet.utils.BitSetUtils;
import java.util.BitSet;
/** /**
* @author Stepan Koltsov * @author Stepan Koltsov
* @author alex.tkachman
*/ */
public class JetMethodAnnotation extends PsiAnnotationWithFlags { public class JetMethodAnnotation extends PsiAnnotationWithFlags {
private String typeParameters;
private String returnType;
private String propertyType;
public JetMethodAnnotation(@Nullable PsiAnnotation psiAnnotation) { public JetMethodAnnotation(@Nullable PsiAnnotation psiAnnotation) {
super(psiAnnotation); super(psiAnnotation);
} }
private BitSet flags = null; @Override
@NotNull protected void initialize() {
public BitSet flags() { super.initialize();
if (flags == null) { typeParameters = getStringAttribute(JvmStdlibNames.JET_METHOD_TYPE_PARAMETERS_FIELD, "");
int flagsValue = getIntAttribute(JvmStdlibNames.JET_METHOD_FLAGS_FIELD, JvmStdlibNames.FLAGS_DEFAULT_VALUE); returnType = getStringAttribute(JvmStdlibNames.JET_METHOD_RETURN_TYPE_FIELD, "");
flags = BitSetUtils.toBitSet(flagsValue); propertyType = getStringAttribute(JvmStdlibNames.JET_METHOD_PROPERTY_TYPE_FIELD, "");
}
return flags;
} }
private int kind;
private boolean kindInitialized;
public int kind() { public int kind() {
if (!kindInitialized) { return flags() & JvmStdlibNames.FLAG_KIND_MASK;
kind = getIntAttribute(JvmStdlibNames.JET_METHOD_KIND_FIELD, DescriptorKindUtils.getDefaultKindValue());
kindInitialized = true;
}
return kind;
} }
private String typeParameters;
@NotNull @NotNull
public String typeParameters() { public String typeParameters() {
if (typeParameters == null) { checkInitialized();
typeParameters = getStringAttribute(JvmStdlibNames.JET_METHOD_TYPE_PARAMETERS_FIELD, "");
}
return typeParameters; return typeParameters;
} }
private String returnType;
@NotNull @NotNull
public String returnType() { public String returnType() {
if (returnType == null) { checkInitialized();
returnType = getStringAttribute(JvmStdlibNames.JET_METHOD_RETURN_TYPE_FIELD, "");
}
return returnType; return returnType;
} }
private boolean returnTypeNullable;
private boolean returnTypeNullableInitialized;
@NotNull
public boolean returnTypeNullable() { public boolean returnTypeNullable() {
if (!returnTypeNullableInitialized) { return (flags() & JvmStdlibNames.FLAG_NULLABLE_RETURN_TYPE_BIT) != 0;
returnTypeNullable = getBooleanAttribute(JvmStdlibNames.JET_METHOD_NULLABLE_RETURN_TYPE_FIELD, false);
returnTypeNullableInitialized = true;
}
return returnTypeNullable;
} }
private String propertyType;
@NotNull @NotNull
public String propertyType() { public String propertyType() {
if (propertyType == null) { checkInitialized();
propertyType = getStringAttribute(JvmStdlibNames.JET_METHOD_PROPERTY_TYPE_FIELD, "");
}
return propertyType; return propertyType;
} }
@@ -32,6 +32,10 @@ public class JetTypeParameterAnnotation extends PsiAnnotationWrapper {
super(psiAnnotation); super(psiAnnotation);
} }
@Override
protected void initialize() {
}
@NotNull @NotNull
public static JetTypeParameterAnnotation get(@NotNull PsiParameter psiParameter) { public static JetTypeParameterAnnotation get(@NotNull PsiParameter psiParameter) {
return new JetTypeParameterAnnotation( return new JetTypeParameterAnnotation(
@@ -25,6 +25,7 @@ import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
/** /**
* @author Stepan Koltsov * @author Stepan Koltsov
* @author alex.tkachman
*/ */
public class JetValueParameterAnnotation extends PsiAnnotationWrapper { public class JetValueParameterAnnotation extends PsiAnnotationWrapper {
@@ -33,50 +34,44 @@ public class JetValueParameterAnnotation extends PsiAnnotationWrapper {
} }
private String name; private String name;
private String type;
private boolean nullable;
private boolean receiver;
private boolean hasDefaultValue;
@Override
protected void initialize() {
name = getStringAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_NAME_FIELD, "");
type = getStringAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_TYPE_FIELD, "");
nullable = getBooleanAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_NULLABLE_FIELD, false);
receiver = getBooleanAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_RECEIVER_FIELD, false);
hasDefaultValue = getBooleanAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_HAS_DEFAULT_VALUE_FIELD, false);
}
@NotNull @NotNull
public String name() { public String name() {
if (name == null) { checkInitialized();
name = getStringAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_NAME_FIELD, "");
}
return name; return name;
} }
private String type;
@NotNull @NotNull
public String type() { public String type() {
if (type == null) { checkInitialized();
type = getStringAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_TYPE_FIELD, "");
}
return type; return type;
} }
private boolean nullable;
private boolean nullableInitialized = false;
public boolean nullable() { public boolean nullable() {
if (!nullableInitialized) { checkInitialized();
nullable = getBooleanAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_NULLABLE_FIELD, false);
nullableInitialized = true;
}
return nullable; return nullable;
} }
private boolean receiver;
private boolean receiverInitialized = false;
public boolean receiver() { public boolean receiver() {
if (!receiverInitialized) { checkInitialized();
receiver = getBooleanAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_RECEIVER_FIELD, false);
receiverInitialized = true;
}
return receiver; return receiver;
} }
private boolean hasDefaultValue;
private boolean hasDefaultValueInitialized = false;
public boolean hasDefaultValue() { public boolean hasDefaultValue() {
if (!hasDefaultValueInitialized) { checkInitialized();
hasDefaultValue = getBooleanAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_HAS_DEFAULT_VALUE_FIELD, false);
hasDefaultValueInitialized = true;
}
return hasDefaultValue; return hasDefaultValue;
} }
@@ -84,5 +79,4 @@ public class JetValueParameterAnnotation extends PsiAnnotationWrapper {
return new JetValueParameterAnnotation( return new JetValueParameterAnnotation(
JavaDescriptorResolver.findAnnotation(psiParameter, JvmStdlibNames.JET_VALUE_PARAMETER.getFqName().getFqName())); JavaDescriptorResolver.findAnnotation(psiParameter, JvmStdlibNames.JET_VALUE_PARAMETER.getFqName().getFqName()));
} }
} }
@@ -29,21 +29,24 @@ import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
* @since 6/1/12 * @since 6/1/12
*/ */
public class KotlinSignatureAnnotation extends PsiAnnotationWrapper { public class KotlinSignatureAnnotation extends PsiAnnotationWrapper {
private String signature;
public KotlinSignatureAnnotation(@Nullable PsiAnnotation psiAnnotation) { public KotlinSignatureAnnotation(@Nullable PsiAnnotation psiAnnotation) {
super(psiAnnotation); super(psiAnnotation);
} }
private String signature; @Override
protected void initialize() {
signature = StringUtil.unescapeStringCharacters(getStringAttribute(JvmStdlibNames.KOTLIN_SIGNATURE_VALUE_METHOD, ""));
}
public String signature() { public String signature() {
if (signature == null) { checkInitialized();
signature = StringUtil.unescapeStringCharacters(getStringAttribute(JvmStdlibNames.KOTLIN_SIGNATURE_VALUE_METHOD, ""));
}
return signature; return signature;
} }
@NotNull @NotNull
public static KotlinSignatureAnnotation get(PsiMethod psiClass) { public static KotlinSignatureAnnotation get(PsiMethod psiMethod) {
return new KotlinSignatureAnnotation(JavaDescriptorResolver.findAnnotation(psiClass, JvmStdlibNames.KOTLIN_SIGNATURE.getFqName().getFqName())); return new KotlinSignatureAnnotation(JavaDescriptorResolver.findAnnotation(psiMethod, JvmStdlibNames.KOTLIN_SIGNATURE.getFqName().getFqName()));
} }
} }
@@ -17,10 +17,8 @@
package org.jetbrains.jet.lang.resolve.java.kt; package org.jetbrains.jet.lang.resolve.java.kt;
import com.intellij.psi.PsiAnnotation; import com.intellij.psi.PsiAnnotation;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
import java.util.BitSet;
/** /**
* @author Evgeny Gerashchenko * @author Evgeny Gerashchenko
@@ -31,6 +29,33 @@ public abstract class PsiAnnotationWithFlags extends PsiAnnotationWrapper {
super(psiAnnotation); super(psiAnnotation);
} }
@NotNull @Override
public abstract BitSet flags(); protected void initialize() {
initialized = getIntAttribute(JvmStdlibNames.JET_FLAGS_FIELD, JvmStdlibNames.FLAGS_DEFAULT_VALUE);
}
public final int flags() {
checkInitialized();
return initialized;
}
public final boolean hasPropertyFlag() {
return (flags() & JvmStdlibNames.FLAG_PROPERTY_BIT) != 0;
}
public final boolean hasForceFinalFlag() {
return (flags() & JvmStdlibNames.FLAG_FORCE_FINAL_BIT) != 0;
}
public final boolean hasForceOpenFlag() {
return (flags() & JvmStdlibNames.FLAG_FORCE_OPEN_BIT) != 0;
}
public final boolean hasInternalFlag() {
return (flags() & JvmStdlibNames.FLAG_INTERNAL_BIT) != 0;
}
public final boolean hasPrivateFlag() {
return (flags() & JvmStdlibNames.FLAG_PRIVATE_BIT) != 0;
}
} }
@@ -26,26 +26,32 @@ import org.jetbrains.annotations.Nullable;
public abstract class PsiAnnotationWrapper { public abstract class PsiAnnotationWrapper {
@Nullable @Nullable
private PsiAnnotation psiAnnotation; private final PsiAnnotation psiAnnotation;
protected int initialized = -1;
protected PsiAnnotationWrapper(@Nullable PsiAnnotation psiAnnotation) { protected PsiAnnotationWrapper(@Nullable PsiAnnotation psiAnnotation) {
this.psiAnnotation = psiAnnotation; this.psiAnnotation = psiAnnotation;
} }
@Nullable
public PsiAnnotation getPsiAnnotation() {
return psiAnnotation;
}
public boolean isDefined() { public boolean isDefined() {
return psiAnnotation != null; return psiAnnotation != null;
} }
protected abstract void initialize();
protected void checkInitialized () {
if (initialized == -1) {
initialized = 0;
initialize();
}
}
@NotNull @NotNull
protected String getStringAttribute(String name, String defaultValue) { protected String getStringAttribute(String name, String defaultValue) {
return PsiAnnotationUtils.getStringAttribute(psiAnnotation, name, defaultValue); return PsiAnnotationUtils.getStringAttribute(psiAnnotation, name, defaultValue);
} }
protected boolean getBooleanAttribute(String name, boolean defaultValue) { protected boolean getBooleanAttribute(String name, boolean defaultValue) {
return PsiAnnotationUtils.getBooleanAttribute(psiAnnotation, name, defaultValue); return PsiAnnotationUtils.getBooleanAttribute(psiAnnotation, name, defaultValue);
} }
@@ -53,5 +59,4 @@ public abstract class PsiAnnotationWrapper {
protected int getIntAttribute(String name, int defaultValue) { protected int getIntAttribute(String name, int defaultValue) {
return PsiAnnotationUtils.getIntAttribute(psiAnnotation, name, defaultValue); return PsiAnnotationUtils.getIntAttribute(psiAnnotation, name, defaultValue);
} }
} }
@@ -35,6 +35,7 @@ import java.lang.annotation.Target;
public @interface JetMethod { public @interface JetMethod {
/** /**
* See CallableMemberDescriptor.Kind * See CallableMemberDescriptor.Kind
* @deprecated See JvmStdlibNames - now kind is kept in flags
* @return kind of this method * @return kind of this method
*/ */
int kind() default 0; int kind() default 0;
@@ -46,6 +47,7 @@ public @interface JetMethod {
int flags() default 0; int flags() default 0;
/** /**
* @deprecated not used any more
* @return type projections or empty * @return type projections or empty
*/ */
JetTypeProjection[] returnTypeProjections() default {}; JetTypeProjection[] returnTypeProjections() default {};
@@ -57,6 +59,7 @@ public @interface JetMethod {
String typeParameters() default ""; String typeParameters() default "";
/** /**
* @deprecated - now it kept in flags
* @return is this type returnTypeNullable * @return is this type returnTypeNullable
*/ */
boolean nullableReturnType() default false; boolean nullableReturnType() default false;