Move ClassLiteralId to 'descriptors', rename to ClassLiteralValue
This commit is contained in:
+6
-7
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.load.kotlin.header.ReadKotlinClassHeaderAnnotationVi
|
|||||||
import org.jetbrains.kotlin.name.ClassId;
|
import org.jetbrains.kotlin.name.ClassId;
|
||||||
import org.jetbrains.kotlin.name.FqName;
|
import org.jetbrains.kotlin.name.FqName;
|
||||||
import org.jetbrains.kotlin.name.Name;
|
import org.jetbrains.kotlin.name.Name;
|
||||||
|
import org.jetbrains.kotlin.resolve.constants.ClassLiteralValue;
|
||||||
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType;
|
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType;
|
||||||
import org.jetbrains.org.objectweb.asm.*;
|
import org.jetbrains.org.objectweb.asm.*;
|
||||||
|
|
||||||
@@ -173,8 +174,7 @@ public abstract class FileBasedKotlinClass implements KotlinJvmBinaryClass {
|
|||||||
@Override
|
@Override
|
||||||
public void visit(String name, @NotNull Object value) {
|
public void visit(String name, @NotNull Object value) {
|
||||||
if (value instanceof Type) {
|
if (value instanceof Type) {
|
||||||
ClassLiteralId classLiteralId = resolveKotlinNameByType((Type)value, innerClasses);
|
v.visitClassLiteral(Name.identifier(name), resolveKotlinNameByType((Type) value, innerClasses));
|
||||||
v.visitClassLiteral(Name.identifier(name), classLiteralId);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
v.visit(name == null ? null : Name.identifier(name), value);
|
v.visit(name == null ? null : Name.identifier(name), value);
|
||||||
@@ -188,8 +188,7 @@ public abstract class FileBasedKotlinClass implements KotlinJvmBinaryClass {
|
|||||||
@Override
|
@Override
|
||||||
public void visit(String name, @NotNull Object value) {
|
public void visit(String name, @NotNull Object value) {
|
||||||
if (value instanceof Type) {
|
if (value instanceof Type) {
|
||||||
ClassLiteralId classLiteralId = resolveKotlinNameByType((Type)value, innerClasses);
|
arv.visitClassLiteral(resolveKotlinNameByType((Type) value, innerClasses));
|
||||||
arv.visitClassLiteral(classLiteralId);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
arv.visit(value);
|
arv.visit(value);
|
||||||
@@ -282,17 +281,17 @@ public abstract class FileBasedKotlinClass implements KotlinJvmBinaryClass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static ClassLiteralId resolveKotlinNameByType(@NotNull Type type, @NotNull InnerClassesInfo innerClasses) {
|
private static ClassLiteralValue resolveKotlinNameByType(@NotNull Type type, @NotNull InnerClassesInfo innerClasses) {
|
||||||
String typeDesc = type.getDescriptor();
|
String typeDesc = type.getDescriptor();
|
||||||
int nestedness = typeDesc.charAt(0) == '[' ? type.getDimensions() : 0;
|
int nestedness = typeDesc.charAt(0) == '[' ? type.getDimensions() : 0;
|
||||||
String elementDesc = nestedness == 0 ? typeDesc : type.getElementType().getDescriptor();
|
String elementDesc = nestedness == 0 ? typeDesc : type.getElementType().getDescriptor();
|
||||||
JvmPrimitiveType primType = JvmPrimitiveType.getByDesc(elementDesc);
|
JvmPrimitiveType primType = JvmPrimitiveType.getByDesc(elementDesc);
|
||||||
if (primType != null) {
|
if (primType != null) {
|
||||||
return new ClassLiteralId(ClassId.topLevel(primType.getPrimitiveType().getTypeFqName()), nestedness);
|
return new ClassLiteralValue(ClassId.topLevel(primType.getPrimitiveType().getTypeFqName()), nestedness);
|
||||||
}
|
}
|
||||||
ClassId javaClassId = resolveNameByDesc(elementDesc, innerClasses);
|
ClassId javaClassId = resolveNameByDesc(elementDesc, innerClasses);
|
||||||
ClassId kotlinClassId = JavaToKotlinClassMap.INSTANCE.mapJavaToKotlin(javaClassId.asSingleFqName());
|
ClassId kotlinClassId = JavaToKotlinClassMap.INSTANCE.mapJavaToKotlin(javaClassId.asSingleFqName());
|
||||||
return new ClassLiteralId(kotlinClassId != null ? kotlinClassId : javaClassId, nestedness);
|
return new ClassLiteralValue(kotlinClassId != null ? kotlinClassId : javaClassId, nestedness);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
+10
-9
@@ -93,9 +93,9 @@ class BinaryClassAnnotationAndConstantLoaderImpl(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitClassLiteral(name: Name, classLiteralId: KotlinJvmBinaryClass.ClassLiteralId) {
|
override fun visitClassLiteral(name: Name, value: ClassLiteralValue) {
|
||||||
arguments[name] = classLiteralId.toClassValue() ?:
|
arguments[name] = value.toClassValue() ?:
|
||||||
ErrorValue.create("Error value of annotation argument: $name: class ${classLiteralId.classId.asSingleFqName()} not found")
|
ErrorValue.create("Error value of annotation argument: $name: class ${value.classId.asSingleFqName()} not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitEnum(name: Name, enumClassId: ClassId, enumEntryName: Name) {
|
override fun visitEnum(name: Name, enumClassId: ClassId, enumEntryName: Name) {
|
||||||
@@ -114,10 +114,11 @@ class BinaryClassAnnotationAndConstantLoaderImpl(
|
|||||||
elements.add(EnumValue(enumClassId, enumEntryName))
|
elements.add(EnumValue(enumClassId, enumEntryName))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitClassLiteral(classLiteralId: KotlinJvmBinaryClass.ClassLiteralId) {
|
override fun visitClassLiteral(value: ClassLiteralValue) {
|
||||||
elements.add(
|
elements.add(
|
||||||
classLiteralId.toClassValue()
|
value.toClassValue() ?: ErrorValue.create(
|
||||||
?: ErrorValue.create("Error array element value of annotation argument: $name: class ${classLiteralId.classId.asSingleFqName()} not found")
|
"Error array element value of annotation argument: $name: class ${value.classId.asSingleFqName()} not found"
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,10 +153,10 @@ class BinaryClassAnnotationAndConstantLoaderImpl(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KotlinJvmBinaryClass.ClassLiteralId.toClassValue(): KClassValue? =
|
private fun ClassLiteralValue.toClassValue(): KClassValue? =
|
||||||
module.findClassAcrossModuleDependencies(this.classId)?.let { classDescriptor ->
|
module.findClassAcrossModuleDependencies(classId)?.let { classDescriptor ->
|
||||||
var currentType = classDescriptor.defaultType
|
var currentType = classDescriptor.defaultType
|
||||||
for (i in 0 until this.arrayNestedness) {
|
for (i in 0 until arrayNestedness) {
|
||||||
val nextWrappedType =
|
val nextWrappedType =
|
||||||
(if (i == 0) module.builtIns.getPrimitiveArrayKotlinTypeByPrimitiveKotlinType(currentType) else null)
|
(if (i == 0) module.builtIns.getPrimitiveArrayKotlinTypeByPrimitiveKotlinType(currentType) else null)
|
||||||
?: module.builtIns.getArrayType(Variance.INVARIANT, currentType)
|
?: module.builtIns.getArrayType(Variance.INVARIANT, currentType)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.descriptors.SourceElement
|
|||||||
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
|
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
import org.jetbrains.kotlin.resolve.constants.ClassLiteralValue
|
||||||
|
|
||||||
interface KotlinJvmBinaryClass {
|
interface KotlinJvmBinaryClass {
|
||||||
val classId: ClassId
|
val classId: ClassId
|
||||||
@@ -53,12 +54,10 @@ interface KotlinJvmBinaryClass {
|
|||||||
fun visitParameterAnnotation(index: Int, classId: ClassId, source: SourceElement): AnnotationArgumentVisitor?
|
fun visitParameterAnnotation(index: Int, classId: ClassId, source: SourceElement): AnnotationArgumentVisitor?
|
||||||
}
|
}
|
||||||
|
|
||||||
class ClassLiteralId(val classId: ClassId, val arrayNestedness: Int)
|
|
||||||
|
|
||||||
interface AnnotationArgumentVisitor {
|
interface AnnotationArgumentVisitor {
|
||||||
fun visit(name: Name?, value: Any?)
|
fun visit(name: Name?, value: Any?)
|
||||||
|
|
||||||
fun visitClassLiteral(name: Name, classLiteralId: ClassLiteralId)
|
fun visitClassLiteral(name: Name, value: ClassLiteralValue)
|
||||||
|
|
||||||
fun visitEnum(name: Name, enumClassId: ClassId, enumEntryName: Name)
|
fun visitEnum(name: Name, enumClassId: ClassId, enumEntryName: Name)
|
||||||
|
|
||||||
@@ -74,7 +73,7 @@ interface KotlinJvmBinaryClass {
|
|||||||
|
|
||||||
fun visitEnum(enumClassId: ClassId, enumEntryName: Name)
|
fun visitEnum(enumClassId: ClassId, enumEntryName: Name)
|
||||||
|
|
||||||
fun visitClassLiteral(classLiteralId: ClassLiteralId)
|
fun visitClassLiteral(value: ClassLiteralValue)
|
||||||
|
|
||||||
fun visitEnd()
|
fun visitEnd()
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMetadataVersion;
|
|||||||
import org.jetbrains.kotlin.name.ClassId;
|
import org.jetbrains.kotlin.name.ClassId;
|
||||||
import org.jetbrains.kotlin.name.FqName;
|
import org.jetbrains.kotlin.name.FqName;
|
||||||
import org.jetbrains.kotlin.name.Name;
|
import org.jetbrains.kotlin.name.Name;
|
||||||
|
import org.jetbrains.kotlin.resolve.constants.ClassLiteralValue;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -164,7 +165,7 @@ public class ReadKotlinClassHeaderAnnotationVisitor implements AnnotationVisitor
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitClassLiteral(@NotNull Name name, @NotNull ClassLiteralId classLiteralId) {
|
public void visitClassLiteral(@NotNull Name name, @NotNull ClassLiteralValue classLiteralValue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -239,7 +240,7 @@ public class ReadKotlinClassHeaderAnnotationVisitor implements AnnotationVisitor
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitClassLiteral(@NotNull Name name, @NotNull ClassLiteralId classLiteralId) {
|
public void visitClassLiteral(@NotNull Name name, @NotNull ClassLiteralValue classLiteralValue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -311,7 +312,7 @@ public class ReadKotlinClassHeaderAnnotationVisitor implements AnnotationVisitor
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitClassLiteral(@NotNull ClassLiteralId classLiteralId) {
|
public void visitClassLiteral(@NotNull ClassLiteralValue classLiteralValue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+5
-4
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
|
|||||||
import org.jetbrains.kotlin.load.kotlin.header.ReadKotlinClassHeaderAnnotationVisitor
|
import org.jetbrains.kotlin.load.kotlin.header.ReadKotlinClassHeaderAnnotationVisitor
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
import org.jetbrains.kotlin.resolve.constants.ClassLiteralValue
|
||||||
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
|
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
|
||||||
import java.lang.reflect.Constructor
|
import java.lang.reflect.Constructor
|
||||||
import java.lang.reflect.Field
|
import java.lang.reflect.Field
|
||||||
@@ -184,7 +185,7 @@ private object ReflectClassStructure {
|
|||||||
visitor.visitEnd()
|
visitor.visitEnd()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Class<*>.classLiteralId(): KotlinJvmBinaryClass.ClassLiteralId {
|
private fun Class<*>.classLiteralValue(): ClassLiteralValue {
|
||||||
var currentClass = this
|
var currentClass = this
|
||||||
var nestedness = 0
|
var nestedness = 0
|
||||||
while (currentClass.isArray) {
|
while (currentClass.isArray) {
|
||||||
@@ -194,14 +195,14 @@ private object ReflectClassStructure {
|
|||||||
val classId =
|
val classId =
|
||||||
if (!currentClass.isPrimitive) currentClass.classId
|
if (!currentClass.isPrimitive) currentClass.classId
|
||||||
else ClassId.topLevel(JvmPrimitiveType.get(currentClass.name).primitiveType.typeFqName)
|
else ClassId.topLevel(JvmPrimitiveType.get(currentClass.name).primitiveType.typeFqName)
|
||||||
return KotlinJvmBinaryClass.ClassLiteralId(classId, nestedness)
|
return ClassLiteralValue(classId, nestedness)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processAnnotationArgumentValue(visitor: KotlinJvmBinaryClass.AnnotationArgumentVisitor, name: Name, value: Any) {
|
private fun processAnnotationArgumentValue(visitor: KotlinJvmBinaryClass.AnnotationArgumentVisitor, name: Name, value: Any) {
|
||||||
val clazz = value::class.java
|
val clazz = value::class.java
|
||||||
when {
|
when {
|
||||||
clazz == Class::class.java -> {
|
clazz == Class::class.java -> {
|
||||||
visitor.visitClassLiteral(name, (value as Class<*>).classLiteralId())
|
visitor.visitClassLiteral(name, (value as Class<*>).classLiteralValue())
|
||||||
}
|
}
|
||||||
clazz in TYPES_ELIGIBLE_FOR_SIMPLE_VISIT -> {
|
clazz in TYPES_ELIGIBLE_FOR_SIMPLE_VISIT -> {
|
||||||
visitor.visit(name, value)
|
visitor.visit(name, value)
|
||||||
@@ -227,7 +228,7 @@ private object ReflectClassStructure {
|
|||||||
}
|
}
|
||||||
else if (componentType == Class::class.java) {
|
else if (componentType == Class::class.java) {
|
||||||
for (element in value as Array<*>) {
|
for (element in value as Array<*>) {
|
||||||
v.visitClassLiteral((element as Class<*>).classLiteralId())
|
v.visitClassLiteral((element as Class<*>).classLiteralValue())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.resolve.constants
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
|
|
||||||
|
data class ClassLiteralValue(val classId: ClassId, val arrayNestedness: Int) {
|
||||||
|
override fun toString(): String = buildString {
|
||||||
|
repeat(arrayNestedness) { append("kotlin/Array<") }
|
||||||
|
append(classId)
|
||||||
|
repeat(arrayNestedness) { append(">") }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user