Delete JvmClassName.byClass, refactor JvmAnnotationNames
Store constant class names as instances of FqName instead of JvmClassName. This is done to minimize usages of the method 'JvmClassName.getFqName()', since it's wrong and shouldn't be used
This commit is contained in:
@@ -32,11 +32,9 @@ import org.jetbrains.jet.codegen.state.JetTypeMapper;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaVisibilities;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
|
||||
import org.jetbrains.jet.lang.resolve.java.*;
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaCallableMemberDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
@@ -667,4 +665,8 @@ public class AsmUtil {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String asmDescByFqNameWithoutInnerClasses(@NotNull FqName fqName) {
|
||||
return JvmClassName.byFqNameWithoutInnerClasses(fqName).getDescriptor();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ import static org.jetbrains.jet.lang.resolve.BindingContextUtils.callableDescrip
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDeclaration;
|
||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isFunctionLiteral;
|
||||
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
|
||||
import static org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils.fqNameByClass;
|
||||
|
||||
public class FunctionCodegen extends GenerationStateAware {
|
||||
private final CodegenContext owner;
|
||||
@@ -190,7 +191,8 @@ public class FunctionCodegen extends GenerationStateAware {
|
||||
}
|
||||
}
|
||||
|
||||
AnnotationVisitor av = mv.visitParameterAnnotation(i, JvmClassName.byClass(JetValueParameter.class).getDescriptor(), true);
|
||||
AnnotationVisitor av =
|
||||
mv.visitParameterAnnotation(i, asmDescByFqNameWithoutInnerClasses(fqNameByClass(JetValueParameter.class)), true);
|
||||
av.visit("name", name);
|
||||
if (nullableType) {
|
||||
av.visit("type", "?");
|
||||
|
||||
@@ -227,7 +227,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
|
||||
ClassData data = new ClassData(createNameResolver(serializer.getNameTable()), classProto);
|
||||
|
||||
AnnotationVisitor av = v.getVisitor().visitAnnotation(JvmAnnotationNames.KOTLIN_CLASS.getDescriptor(), true);
|
||||
AnnotationVisitor av = v.getVisitor().visitAnnotation(asmDescByFqNameWithoutInnerClasses(JvmAnnotationNames.KOTLIN_CLASS), true);
|
||||
av.visit(JvmAnnotationNames.ABI_VERSION_FIELD_NAME, JvmAbi.VERSION);
|
||||
AnnotationVisitor array = av.visitArray(JvmAnnotationNames.DATA_FIELD_NAME);
|
||||
for (String string : BitEncoding.encodeBytes(data.toBytes())) {
|
||||
|
||||
@@ -54,6 +54,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.asm4.Opcodes.*;
|
||||
import static org.jetbrains.jet.codegen.AsmUtil.asmDescByFqNameWithoutInnerClasses;
|
||||
import static org.jetbrains.jet.descriptors.serialization.NameSerializationUtil.createNameResolver;
|
||||
|
||||
public class NamespaceCodegen extends MemberCodegen {
|
||||
@@ -152,7 +153,8 @@ public class NamespaceCodegen extends MemberCodegen {
|
||||
|
||||
PackageData data = new PackageData(createNameResolver(serializer.getNameTable()), packageProto);
|
||||
|
||||
AnnotationVisitor av = v.getClassBuilder().newAnnotation(JvmAnnotationNames.KOTLIN_PACKAGE.getDescriptor(), true);
|
||||
AnnotationVisitor av =
|
||||
v.getClassBuilder().newAnnotation(asmDescByFqNameWithoutInnerClasses(JvmAnnotationNames.KOTLIN_PACKAGE), true);
|
||||
av.visit(JvmAnnotationNames.ABI_VERSION_FIELD_NAME, JvmAbi.VERSION);
|
||||
AnnotationVisitor array = av.visitArray(JvmAnnotationNames.DATA_FIELD_NAME);
|
||||
for (String string : BitEncoding.encodeBytes(data.toBytes())) {
|
||||
@@ -215,7 +217,7 @@ public class NamespaceCodegen extends MemberCodegen {
|
||||
}
|
||||
|
||||
private static void writeKotlinPackageFragmentAnnotation(@NotNull ClassBuilder builder) {
|
||||
AnnotationVisitor av = builder.newAnnotation(JvmAnnotationNames.KOTLIN_PACKAGE_FRAGMENT.getDescriptor(), true);
|
||||
AnnotationVisitor av = builder.newAnnotation(JvmClassName.byFqNameWithoutInnerClasses(JvmAnnotationNames.KOTLIN_PACKAGE_FRAGMENT).getDescriptor(), true);
|
||||
av.visit(JvmAnnotationNames.ABI_VERSION_FIELD_NAME, JvmAbi.VERSION);
|
||||
av.visitEnd();
|
||||
}
|
||||
|
||||
+10
-3
@@ -17,25 +17,32 @@
|
||||
package org.jetbrains.jet.lang.resolve.java.kotlinSignature;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import jet.runtime.typeinfo.KotlinSignature;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.JavaAnnotationResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaAnnotation;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaAnnotationArgument;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaLiteralAnnotationArgument;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaMember;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils.fqNameByClass;
|
||||
|
||||
public class SignaturesUtil {
|
||||
public static final FqName KOTLIN_SIGNATURE = fqNameByClass(KotlinSignature.class);
|
||||
public static final Name KOTLIN_SIGNATURE_VALUE_FIELD_NAME = Name.identifier("value");
|
||||
|
||||
private SignaturesUtil() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getKotlinSignature(@NotNull JavaAnnotationResolver annotationResolver, @NotNull JavaMember member) {
|
||||
JavaAnnotation annotation = annotationResolver.findAnnotationWithExternal(member, JvmAnnotationNames.KOTLIN_SIGNATURE);
|
||||
JavaAnnotation annotation = annotationResolver.findAnnotationWithExternal(member, KOTLIN_SIGNATURE);
|
||||
|
||||
if (annotation != null) {
|
||||
JavaAnnotationArgument argument = annotation.findArgument(JvmAnnotationNames.KOTLIN_SIGNATURE_VALUE_FIELD_NAME);
|
||||
JavaAnnotationArgument argument = annotation.findArgument(KOTLIN_SIGNATURE_VALUE_FIELD_NAME);
|
||||
if (argument instanceof JavaLiteralAnnotationArgument) {
|
||||
Object value = ((JavaLiteralAnnotationArgument) argument).getValue();
|
||||
if (value instanceof String) {
|
||||
|
||||
-8
@@ -18,11 +18,9 @@ package org.jetbrains.jet.lang.resolve.java.resolver;
|
||||
|
||||
import com.intellij.codeInsight.ExternalAnnotationsManager;
|
||||
import com.intellij.psi.PsiAnnotation;
|
||||
import com.intellij.psi.PsiModifierList;
|
||||
import com.intellij.psi.PsiModifierListOwner;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaAnnotation;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaAnnotationOwner;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaAnnotationImpl;
|
||||
@@ -55,10 +53,4 @@ public class PsiBasedExternalAnnotationResolver implements ExternalAnnotationRes
|
||||
public static PsiAnnotation findExternalAnnotation(@NotNull PsiModifierListOwner owner, @NotNull FqName fqName) {
|
||||
return ExternalAnnotationsManager.getInstance(owner.getProject()).findExternalAnnotation(owner, fqName.asString());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiAnnotation findOwnAnnotation(@NotNull PsiModifierListOwner owner, @NotNull JvmClassName name) {
|
||||
PsiModifierList list = owner.getModifierList();
|
||||
return list == null ? null : list.findAnnotation(name.getFqName().asString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.TestJdkKind;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.CoreExternalAnnotationsManager;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames;
|
||||
import org.jetbrains.jet.lang.resolve.java.kotlinSignature.SignaturesUtil;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.KotlinTestWithEnvironment;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
@@ -158,9 +158,9 @@ public class IdeaJdkAnnotationsReflectedTest extends KotlinTestWithEnvironment {
|
||||
}
|
||||
|
||||
private enum AnnotationsKind {
|
||||
KOTLIN_SIGNATURE(JvmAnnotationNames.KOTLIN_SIGNATURE.getFqName().asString()),
|
||||
KOTLIN_SIGNATURE(SignaturesUtil.KOTLIN_SIGNATURE.asString()),
|
||||
NOT_NULL(AnnotationUtil.NOT_NULL),
|
||||
ANY(AnnotationUtil.NOT_NULL, JvmAnnotationNames.KOTLIN_SIGNATURE.getFqName().asString());
|
||||
ANY(AnnotationUtil.NOT_NULL, SignaturesUtil.KOTLIN_SIGNATURE.asString());
|
||||
|
||||
public final String[] annotationNames;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user