diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java index 64c1fc491b9..ddf47372e72 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java @@ -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.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; @@ -102,16 +105,14 @@ public class CodegenUtil { } - @NotNull - public static BitSet getFlagsForVisibility(@NotNull Visibility visibility) { - BitSet flags = new BitSet(); + public static int getFlagsForVisibility(@NotNull Visibility visibility) { if (visibility == Visibilities.INTERNAL) { - flags.set(JvmStdlibNames.FLAG_INTERNAL_BIT); + return JvmStdlibNames.FLAG_INTERNAL_BIT; } else if (visibility == Visibilities.PRIVATE) { - flags.set(JvmStdlibNames.FLAG_PRIVATE_BIT); + return JvmStdlibNames.FLAG_PRIVATE_BIT; } - return flags; + return 0; } @NotNull diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java index 9a653f4a9d0..b338074012d 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java @@ -348,16 +348,17 @@ public class FunctionCodegen extends GenerationStateAware { throw new IllegalStateException(); } JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv); - BitSet kotlinFlags = getFlagsForVisibility(functionDescriptor.getVisibility()); + int kotlinFlags = getFlagsForVisibility(functionDescriptor.getVisibility()); if (isInterface(functionDescriptor.getContainingDeclaration()) && modality != Modality.ABSTRACT) { - kotlinFlags.set(modality == Modality.FINAL + kotlinFlags |= modality == Modality.FINAL ? JvmStdlibNames.FLAG_FORCE_FINAL_BIT - : JvmStdlibNames.FLAG_FORCE_OPEN_BIT); + : JvmStdlibNames.FLAG_FORCE_OPEN_BIT; } - aw.writeFlags(kotlinFlags); - aw.writeKind(DescriptorKindUtils.kindToInt(functionDescriptor.getKind())); + kotlinFlags |= DescriptorKindUtils.kindToFlags(functionDescriptor.getKind()); //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.writeReturnType(jvmSignature.getKotlinReturnType()); aw.visitEnd(); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index 4c6812f8118..daaa2764d0f 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -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.lang.JetStandardLibrary; import org.jetbrains.jet.lexer.JetTokens; -import org.jetbrains.jet.utils.BitSetUtils; import java.util.*; @@ -248,10 +247,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { if (signature.getKotlinGenericSignature() != null || descriptor.getVisibility() != Visibilities.PUBLIC) { AnnotationVisitor annotationVisitor = v.newAnnotation(JvmStdlibNames.JET_CLASS.getDescriptor(), true); annotationVisitor.visit(JvmStdlibNames.JET_CLASS_SIGNATURE, signature.getKotlinGenericSignature()); - BitSet flags = getFlagsForVisibility(descriptor.getVisibility()); - int flagsValue = BitSetUtils.toInt(flags); - if (JvmStdlibNames.FLAGS_DEFAULT_VALUE != flagsValue) { - annotationVisitor.visit(JvmStdlibNames.JET_CLASS_FLAGS_FIELD, flagsValue); + int flags = getFlagsForVisibility(descriptor.getVisibility()); + if (JvmStdlibNames.FLAGS_DEFAULT_VALUE != flags) { + annotationVisitor.visit(JvmStdlibNames.JET_FLAGS_FIELD, flags); } annotationVisitor.visitEnd(); } @@ -827,9 +825,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { 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) { - jetConstructorVisitor.visit(JvmStdlibNames.JET_CLASS_FLAGS_FIELD, flagsValue); + jetConstructorVisitor.visit(JvmStdlibNames.JET_FLAGS_FIELD, flagsValue); } jetConstructorVisitor.visitEnd(); @@ -1218,21 +1216,22 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { JvmMethodSignature jvmSignature = typeMapper.mapToCallableMethod(inheritedFun, false, OwnerKind.IMPLEMENTATION).getSignature(); JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv); - BitSet kotlinFlags = getFlagsForVisibility(fun.getVisibility()); + int kotlinFlags = getFlagsForVisibility(fun.getVisibility()); if (fun instanceof PropertyAccessorDescriptor) { - kotlinFlags.set(JvmStdlibNames.FLAG_PROPERTY_BIT); + kotlinFlags |= JvmStdlibNames.FLAG_PROPERTY_BIT; aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter()); aw.writePropertyType(jvmSignature.getKotlinReturnType()); } else { JetType returnType = fun.getReturnType(); assert returnType != null; - aw.writeNullableReturnType(returnType.isNullable()); + if (returnType.isNullable()) + kotlinFlags |= JvmStdlibNames.FLAG_NULLABLE_RETURN_TYPE_BIT; aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter()); aw.writeReturnType(jvmSignature.getKotlinReturnType()); } + kotlinFlags |= DescriptorKindUtils.kindToFlags(inheritedFun.getKind()); 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 d58c281f40a..70ba8603ee0 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java @@ -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.types.lang.JetStandardLibrary; -import java.util.BitSet; - import static org.jetbrains.asm4.Opcodes.*; import static org.jetbrains.jet.codegen.AsmUtil.genStubThrow; import static org.jetbrains.jet.codegen.AsmUtil.getVisibilityAccessFlag; @@ -254,15 +252,13 @@ public class PropertyCodegen extends GenerationStateAware { ) { JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv); Modality modality = propertyDescriptor.getModality(); - BitSet flags = getFlagsForVisibility(visibility); - flags.set(JvmStdlibNames.FLAG_PROPERTY_BIT); + int flags = getFlagsForVisibility(visibility) | JvmStdlibNames.FLAG_PROPERTY_BIT; if (isInterface(propertyDescriptor.getContainingDeclaration()) && modality != Modality.ABSTRACT) { - flags.set(modality == Modality.FINAL + flags |= modality == Modality.FINAL ? JvmStdlibNames.FLAG_FORCE_FINAL_BIT - : JvmStdlibNames.FLAG_FORCE_OPEN_BIT); + : JvmStdlibNames.FLAG_FORCE_OPEN_BIT; } - aw.writeFlags(flags); - aw.writeKind(DescriptorKindUtils.kindToInt(propertyDescriptor.getKind())); + aw.writeFlags(flags | DescriptorKindUtils.kindToFlags(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 e8425a5c9f1..793a1a3b1c1 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,10 +20,6 @@ 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; /** * @author Stepan Koltsov @@ -35,16 +31,9 @@ public class JetMethodAnnotationWriter { this.av = av; } - public void writeFlags(BitSet flags) { - int flagsValue = BitSetUtils.toInt(flags); - if (flagsValue != JvmStdlibNames.FLAGS_DEFAULT_VALUE) { - 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); + public void writeFlags(int flags) { + if (flags != JvmStdlibNames.FLAGS_DEFAULT_VALUE) { + av.visit(JvmStdlibNames.JET_FLAGS_FIELD, flags); } } @@ -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() { av.visitEnd(); } 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 1aec6bec876..af204690e32 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 @@ -1214,7 +1214,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes if (members.getter != null && members.getter.getMember() instanceof PsiMethodWrapper) { JetMethodAnnotation jetMethod = ((PsiMethodWrapper) members.getter.getMember()).getJetMethod(); visibility = resolveVisibility(anyMember.getMember().psiMember, jetMethod); - kind = DescriptorKindUtils.intToKind(jetMethod.kind()); + kind = DescriptorKindUtils.flagsToKind(jetMethod.kind()); } DeclarationDescriptor realOwner = getRealOwner(owner, scopeData, anyMember.getMember().isStatic()); @@ -1533,7 +1533,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes } // TODO: ugly - if (method.getJetMethod().flags().get(JvmStdlibNames.FLAG_PROPERTY_BIT)) { + if (method.getJetMethod().hasPropertyFlag()) { return null; } @@ -1549,7 +1549,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes scopeData.classOrNamespaceDescriptor, resolveAnnotations(method.getPsiMethod()), Name.identifier(method.getName()), - DescriptorKindUtils.intToKind(method.getJetMethod().kind()) + DescriptorKindUtils.flagsToKind(method.getJetMethod().kind()) ); 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) { if (memberWrapper instanceof PsiMethodWrapper) { PsiMethodWrapper method = (PsiMethodWrapper) memberWrapper; - if (method.getJetMethod().flags().get(JvmStdlibNames.FLAG_FORCE_OPEN_BIT)) { + if (method.getJetMethod().hasForceOpenFlag()) { return Modality.OPEN; } - if (method.getJetMethod().flags().get(JvmStdlibNames.FLAG_FORCE_FINAL_BIT)) { + if (method.getJetMethod().hasForceFinalFlag()) { return Modality.FINAL; } } @@ -1907,11 +1907,10 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes private static Visibility resolveVisibility(PsiModifierListOwner modifierListOwner, @Nullable PsiAnnotationWithFlags annotation) { if (annotation != null) { - BitSet flags = annotation.flags(); - if (flags.get(JvmStdlibNames.FLAG_PRIVATE_BIT)) { + if (annotation.hasPrivateFlag()) { return Visibilities.PRIVATE; } - else if (flags.get(JvmStdlibNames.FLAG_INTERNAL_BIT)) { + else if (annotation.hasInternalFlag()) { return Visibilities.INTERNAL; } } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolverHelper.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolverHelper.java index 8587eeaa765..73706745fe7 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolverHelper.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolverHelper.java @@ -131,7 +131,7 @@ class JavaDescriptorResolverHelper { NamedMembers members = getNamedMembers(Name.identifier(propertyName)); // TODO: some java properties too - if (method.getJetMethod().flags().get(JvmStdlibNames.FLAG_PROPERTY_BIT)) { + if (method.getJetMethod().hasPropertyFlag()) { int i = 0; @@ -173,7 +173,7 @@ class JavaDescriptorResolverHelper { String propertyName = propertyParseResult.getPropertyName(); NamedMembers members = getNamedMembers(Name.identifier(propertyName)); - if (method.getJetMethod().flags().get(JvmStdlibNames.FLAG_PROPERTY_BIT)) { + if (method.getJetMethod().hasPropertyFlag()) { if (method.getParameters().size() == 0) { // TODO: report error properly 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.addMethod(method); } 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 7b0288f7c36..b65a40c930d 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 @@ -17,7 +17,6 @@ package org.jetbrains.jet.lang.resolve.java; import jet.runtime.typeinfo.JetConstructor; -import jet.runtime.typeinfo.KotlinSignature; /** * @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 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"; + public static final String JET_FLAGS_FIELD = "flags"; + 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 FLAGS_DEFAULT_VALUE = 0; - 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; - public static final int FLAG_PRIVATE_BIT = 3; - public static final int FLAG_INTERNAL_BIT = 4; + public static final int FLAG_PROPERTY_BIT = 1 << 0; + public static final int FLAG_FORCE_OPEN_BIT = 1 << 1; + public static final int FLAG_FORCE_FINAL_BIT = 1 << 2; + public static final int FLAG_PRIVATE_BIT = 1 << 3; + 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"); @@ -62,13 +68,11 @@ public class JvmStdlibNames { * @see JetConstructor#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 String JET_CLASS_SIGNATURE = "signature"; - public static final String JET_CLASS_FLAGS_FIELD = "flags"; public static final JvmClassName JET_OBJECT = JvmClassName.byFqNameWithoutInnerClasses("jet.JetObject"); 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 index ebbbea223c0..27484288350 100644 --- 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 @@ -17,39 +17,32 @@ package org.jetbrains.jet.lang.resolve.java.kt; import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor; +import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; /** * @author udalov + * @author alex.tkachman */ 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) { + public static int kindToFlags(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; + case DECLARATION: return JvmStdlibNames.FLAG_KIND_DECLARATION; + case FAKE_OVERRIDE: return JvmStdlibNames.FLAG_KIND_FAKE_OVERRIDE; + case DELEGATION: return JvmStdlibNames.FLAG_KIND_DELEGATION; + case SYNTHESIZED: return JvmStdlibNames.FLAG_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; + public static CallableMemberDescriptor.Kind flagsToKind(int value) { + switch (value & JvmStdlibNames.FLAG_KIND_MASK) { + case JvmStdlibNames.FLAG_KIND_DECLARATION: return CallableMemberDescriptor.Kind.DECLARATION; + case JvmStdlibNames.FLAG_KIND_FAKE_OVERRIDE: return CallableMemberDescriptor.Kind.FAKE_OVERRIDE; + case JvmStdlibNames.FLAG_KIND_DELEGATION: return CallableMemberDescriptor.Kind.DELEGATION; + case JvmStdlibNames.FLAG_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/JetClassAnnotation.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/JetClassAnnotation.java index c5a1c67345c..faa982387eb 100644 --- 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 @@ -22,37 +22,29 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver; import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; -import org.jetbrains.jet.utils.BitSetUtils; - -import java.util.BitSet; /** * @author Stepan Koltsov */ public class JetClassAnnotation extends PsiAnnotationWithFlags { + private String signature; + public JetClassAnnotation(@Nullable PsiAnnotation psiAnnotation) { super(psiAnnotation); } - - private String signature; + + @Override + protected void initialize() { + super.initialize(); + signature = getStringAttribute(JvmStdlibNames.JET_CLASS_SIGNATURE, ""); + } + public String signature() { - if (signature == null) { - signature = getStringAttribute(JvmStdlibNames.JET_CLASS_SIGNATURE, ""); - } + checkInitialized(); 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 public static JetClassAnnotation get(PsiClass psiClass) { return new JetClassAnnotation(JavaDescriptorResolver.findAnnotation(psiClass, JvmStdlibNames.JET_CLASS.getFqName().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 index 606b4c233b1..6d767c0c035 100644 --- 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 @@ -18,13 +18,9 @@ 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.JavaDescriptorResolver; import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; -import org.jetbrains.jet.utils.BitSetUtils; - -import java.util.BitSet; /** * @author Stepan Koltsov @@ -35,27 +31,20 @@ public class JetConstructorAnnotation extends PsiAnnotationWithFlags { super(psiAnnotation); } + @Override + protected void initialize() { + super.initialize(); + hidden = getBooleanAttribute(JvmStdlibNames.JET_CONSTRUCTOR_HIDDEN_FIELD, false); + } + private boolean hidden; - private boolean hiddenInitialized = false; + /** @deprecated */ public boolean hidden() { - if (!hiddenInitialized) { - hidden = getBooleanAttribute(JvmStdlibNames.JET_CONSTRUCTOR_HIDDEN_FIELD, false); - hiddenInitialized = true; - } + checkInitialized(); 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) { return new JetConstructorAnnotation(JavaDescriptorResolver.findAnnotation(constructor, JvmStdlibNames.JET_CONSTRUCTOR.getFqName().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 index cc06fc498ba..fb6f2236323 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 @@ -22,74 +22,52 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver; import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; -import org.jetbrains.jet.utils.BitSetUtils; - -import java.util.BitSet; /** * @author Stepan Koltsov + * @author alex.tkachman */ public class JetMethodAnnotation extends PsiAnnotationWithFlags { + private String typeParameters; + private String returnType; + private String propertyType; + public JetMethodAnnotation(@Nullable PsiAnnotation psiAnnotation) { super(psiAnnotation); } - - private BitSet flags = null; - @NotNull - public BitSet flags() { - if (flags == null) { - int flagsValue = getIntAttribute(JvmStdlibNames.JET_METHOD_FLAGS_FIELD, JvmStdlibNames.FLAGS_DEFAULT_VALUE); - flags = BitSetUtils.toBitSet(flagsValue); - } - return flags; + + @Override + protected void initialize() { + super.initialize(); + typeParameters = getStringAttribute(JvmStdlibNames.JET_METHOD_TYPE_PARAMETERS_FIELD, ""); + returnType = getStringAttribute(JvmStdlibNames.JET_METHOD_RETURN_TYPE_FIELD, ""); + propertyType = getStringAttribute(JvmStdlibNames.JET_METHOD_PROPERTY_TYPE_FIELD, ""); } - private int kind; - private boolean kindInitialized; public int kind() { - if (!kindInitialized) { - kind = getIntAttribute(JvmStdlibNames.JET_METHOD_KIND_FIELD, DescriptorKindUtils.getDefaultKindValue()); - kindInitialized = true; - } - return kind; + return flags() & JvmStdlibNames.FLAG_KIND_MASK; } - private String typeParameters; @NotNull public String typeParameters() { - if (typeParameters == null) { - typeParameters = getStringAttribute(JvmStdlibNames.JET_METHOD_TYPE_PARAMETERS_FIELD, ""); - } + checkInitialized(); return typeParameters; } - private String returnType; @NotNull public String returnType() { - if (returnType == null) { - returnType = getStringAttribute(JvmStdlibNames.JET_METHOD_RETURN_TYPE_FIELD, ""); - } + checkInitialized(); 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; + return (flags() & JvmStdlibNames.FLAG_NULLABLE_RETURN_TYPE_BIT) != 0; } - private String propertyType; @NotNull public String propertyType() { - if (propertyType == null) { - propertyType = getStringAttribute(JvmStdlibNames.JET_METHOD_PROPERTY_TYPE_FIELD, ""); - } + checkInitialized(); return propertyType; } 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 index 5fc31d8632c..df4239079e5 100644 --- 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 @@ -32,6 +32,10 @@ public class JetTypeParameterAnnotation extends PsiAnnotationWrapper { super(psiAnnotation); } + @Override + protected void initialize() { + } + @NotNull public static JetTypeParameterAnnotation get(@NotNull PsiParameter psiParameter) { return new JetTypeParameterAnnotation( 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 index 76cc424e502..7d9b8d424b7 100644 --- 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 @@ -25,6 +25,7 @@ import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; /** * @author Stepan Koltsov + * @author alex.tkachman */ public class JetValueParameterAnnotation extends PsiAnnotationWrapper { @@ -33,50 +34,44 @@ public class JetValueParameterAnnotation extends PsiAnnotationWrapper { } 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 public String name() { - if (name == null) { - name = getStringAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_NAME_FIELD, ""); - } + checkInitialized(); return name; } - - private String type; + @NotNull public String type() { - if (type == null) { - type = getStringAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_TYPE_FIELD, ""); - } + checkInitialized(); 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; - } + checkInitialized(); 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; - } + checkInitialized(); 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; - } + checkInitialized(); return hasDefaultValue; } @@ -84,5 +79,4 @@ public class JetValueParameterAnnotation extends PsiAnnotationWrapper { return new JetValueParameterAnnotation( JavaDescriptorResolver.findAnnotation(psiParameter, JvmStdlibNames.JET_VALUE_PARAMETER.getFqName().getFqName())); } - } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/KotlinSignatureAnnotation.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/KotlinSignatureAnnotation.java index 02e2a68fcbb..109e8f34d13 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/KotlinSignatureAnnotation.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/KotlinSignatureAnnotation.java @@ -29,21 +29,24 @@ import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; * @since 6/1/12 */ public class KotlinSignatureAnnotation extends PsiAnnotationWrapper { + private String signature; + public KotlinSignatureAnnotation(@Nullable PsiAnnotation psiAnnotation) { super(psiAnnotation); } - private String signature; + @Override + protected void initialize() { + signature = StringUtil.unescapeStringCharacters(getStringAttribute(JvmStdlibNames.KOTLIN_SIGNATURE_VALUE_METHOD, "")); + } public String signature() { - if (signature == null) { - signature = StringUtil.unescapeStringCharacters(getStringAttribute(JvmStdlibNames.KOTLIN_SIGNATURE_VALUE_METHOD, "")); - } + checkInitialized(); return signature; } @NotNull - public static KotlinSignatureAnnotation get(PsiMethod psiClass) { - return new KotlinSignatureAnnotation(JavaDescriptorResolver.findAnnotation(psiClass, JvmStdlibNames.KOTLIN_SIGNATURE.getFqName().getFqName())); + public static KotlinSignatureAnnotation get(PsiMethod psiMethod) { + return new KotlinSignatureAnnotation(JavaDescriptorResolver.findAnnotation(psiMethod, JvmStdlibNames.KOTLIN_SIGNATURE.getFqName().getFqName())); } } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/PsiAnnotationWithFlags.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/PsiAnnotationWithFlags.java index 0b28cdeaee4..6bbe670a936 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/PsiAnnotationWithFlags.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kt/PsiAnnotationWithFlags.java @@ -17,10 +17,8 @@ package org.jetbrains.jet.lang.resolve.java.kt; import com.intellij.psi.PsiAnnotation; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; - -import java.util.BitSet; +import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; /** * @author Evgeny Gerashchenko @@ -31,6 +29,33 @@ public abstract class PsiAnnotationWithFlags extends PsiAnnotationWrapper { super(psiAnnotation); } - @NotNull - public abstract BitSet flags(); + @Override + 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; + } } 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 176e0df2b3e..16239448842 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 @@ -26,26 +26,32 @@ import org.jetbrains.annotations.Nullable; public abstract class PsiAnnotationWrapper { @Nullable - private PsiAnnotation psiAnnotation; + private final PsiAnnotation psiAnnotation; + + protected int initialized = -1; protected PsiAnnotationWrapper(@Nullable PsiAnnotation psiAnnotation) { this.psiAnnotation = psiAnnotation; } - @Nullable - public PsiAnnotation getPsiAnnotation() { - return psiAnnotation; - } - public boolean isDefined() { return psiAnnotation != null; } - + + protected abstract void initialize(); + + protected void checkInitialized () { + if (initialized == -1) { + initialized = 0; + initialize(); + } + } + @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); } @@ -53,5 +59,4 @@ public abstract class PsiAnnotationWrapper { protected int getIntAttribute(String name, int defaultValue) { return PsiAnnotationUtils.getIntAttribute(psiAnnotation, name, defaultValue); } - } diff --git a/runtime/src/jet/runtime/typeinfo/JetMethod.java b/runtime/src/jet/runtime/typeinfo/JetMethod.java index 30ca2b7ea2f..30236caa51b 100644 --- a/runtime/src/jet/runtime/typeinfo/JetMethod.java +++ b/runtime/src/jet/runtime/typeinfo/JetMethod.java @@ -35,6 +35,7 @@ import java.lang.annotation.Target; public @interface JetMethod { /** * See CallableMemberDescriptor.Kind + * @deprecated See JvmStdlibNames - now kind is kept in flags * @return kind of this method */ int kind() default 0; @@ -46,6 +47,7 @@ public @interface JetMethod { int flags() default 0; /** + * @deprecated not used any more * @return type projections or empty */ JetTypeProjection[] returnTypeProjections() default {}; @@ -57,6 +59,7 @@ public @interface JetMethod { String typeParameters() default ""; /** + * @deprecated - now it kept in flags * @return is this type returnTypeNullable */ boolean nullableReturnType() default false;