- 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.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
@@ -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();
@@ -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) {
@@ -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();
@@ -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();
}
@@ -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;
}
}
@@ -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);
}
@@ -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");
@@ -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);
}
}
@@ -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()));
@@ -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()));
}
@@ -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;
}
@@ -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(
@@ -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()));
}
}
@@ -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()));
}
}
@@ -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;
}
}
@@ -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);
}
}
@@ -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;