J2K KotlinJvmBinaryClass & AnnotationAndConstantLoader: convert
This commit is contained in:
@@ -42,7 +42,8 @@ class LocalFileKotlinClass private constructor(
|
||||
|
||||
val className: JvmClassName by lazy { JvmClassName.byClassId(classId) }
|
||||
|
||||
override fun getLocation(): String = file.absolutePath
|
||||
override val location: String
|
||||
get() = file.absolutePath
|
||||
|
||||
public override fun getFileContents(): ByteArray = fileContents
|
||||
|
||||
|
||||
+2
-1
@@ -33,7 +33,8 @@ class VirtualFileKotlinClass private constructor(
|
||||
innerClasses: FileBasedKotlinClass.InnerClassesInfo
|
||||
) : FileBasedKotlinClass(className, classHeader, innerClasses) {
|
||||
|
||||
override fun getLocation() = file.path
|
||||
override val location: String
|
||||
get() = file.path
|
||||
|
||||
override fun getFileContents(): ByteArray {
|
||||
try {
|
||||
|
||||
@@ -182,7 +182,8 @@ object InlineTestUtil {
|
||||
val klass = FileBasedKotlinClass.create(file.asByteArray()) {
|
||||
className, classHeader, innerClasses ->
|
||||
object : FileBasedKotlinClass(className, classHeader, innerClasses) {
|
||||
override fun getLocation(): String = throw UnsupportedOperationException()
|
||||
override val location: String
|
||||
get() = throw UnsupportedOperationException()
|
||||
override fun getFileContents(): ByteArray = throw UnsupportedOperationException()
|
||||
override fun hashCode(): Int = throw UnsupportedOperationException()
|
||||
override fun equals(other: Any?): Boolean = throw UnsupportedOperationException()
|
||||
|
||||
+9
-9
@@ -146,14 +146,14 @@ abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C : Any,
|
||||
|
||||
override fun loadValueParameterAnnotations(
|
||||
container: ProtoContainer,
|
||||
message: MessageLite,
|
||||
callableProto: MessageLite,
|
||||
kind: AnnotatedCallableKind,
|
||||
parameterIndex: Int,
|
||||
proto: ProtoBuf.ValueParameter
|
||||
): List<A> {
|
||||
val methodSignature = getCallableSignature(message, container.nameResolver, container.typeTable, kind)
|
||||
val methodSignature = getCallableSignature(callableProto, container.nameResolver, container.typeTable, kind)
|
||||
if (methodSignature != null) {
|
||||
val index = parameterIndex + computeJvmParameterIndexShift(container, message)
|
||||
val index = parameterIndex + computeJvmParameterIndexShift(container, callableProto)
|
||||
val paramSignature = MemberSignature.fromMethodSignatureAndParameterIndex(methodSignature, index)
|
||||
return findClassAndLoadMemberAnnotations(container, paramSignature)
|
||||
}
|
||||
@@ -176,10 +176,10 @@ abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C : Any,
|
||||
|
||||
override fun loadExtensionReceiverParameterAnnotations(
|
||||
container: ProtoContainer,
|
||||
message: MessageLite,
|
||||
proto: MessageLite,
|
||||
kind: AnnotatedCallableKind
|
||||
): List<A> {
|
||||
val methodSignature = getCallableSignature(message, container.nameResolver, container.typeTable, kind)
|
||||
val methodSignature = getCallableSignature(proto, container.nameResolver, container.typeTable, kind)
|
||||
if (methodSignature != null) {
|
||||
val paramSignature = MemberSignature.fromMethodSignatureAndParameterIndex(methodSignature, 0)
|
||||
return findClassAndLoadMemberAnnotations(container, paramSignature)
|
||||
@@ -188,12 +188,12 @@ abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C : Any,
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
override fun loadTypeAnnotations(type: ProtoBuf.Type, nameResolver: NameResolver): List<A> {
|
||||
return type.getExtension(JvmProtoBuf.typeAnnotation).map { loadTypeAnnotation(it, nameResolver) }
|
||||
override fun loadTypeAnnotations(proto: ProtoBuf.Type, nameResolver: NameResolver): List<A> {
|
||||
return proto.getExtension(JvmProtoBuf.typeAnnotation).map { loadTypeAnnotation(it, nameResolver) }
|
||||
}
|
||||
|
||||
override fun loadTypeParameterAnnotations(typeParameter: ProtoBuf.TypeParameter, nameResolver: NameResolver): List<A> {
|
||||
return typeParameter.getExtension(JvmProtoBuf.typeParameterAnnotation).map { loadTypeAnnotation(it, nameResolver) }
|
||||
override fun loadTypeParameterAnnotations(proto: ProtoBuf.TypeParameter, nameResolver: NameResolver): List<A> {
|
||||
return proto.getExtension(JvmProtoBuf.typeParameterAnnotation).map { loadTypeAnnotation(it, nameResolver) }
|
||||
}
|
||||
|
||||
override fun loadPropertyConstant(container: ProtoContainer, proto: ProtoBuf.Property, expectedType: KotlinType): C? {
|
||||
|
||||
+25
-36
@@ -14,74 +14,63 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.load.kotlin;
|
||||
package org.jetbrains.kotlin.load.kotlin
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement;
|
||||
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader;
|
||||
import org.jetbrains.kotlin.name.ClassId;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
public interface KotlinJvmBinaryClass {
|
||||
@NotNull
|
||||
ClassId getClassId();
|
||||
interface KotlinJvmBinaryClass {
|
||||
val classId: ClassId
|
||||
|
||||
/**
|
||||
* @return path to the class file (to be reported to the user upon error)
|
||||
*/
|
||||
@NotNull
|
||||
String getLocation();
|
||||
val location: String
|
||||
|
||||
void loadClassAnnotations(@NotNull AnnotationVisitor visitor);
|
||||
fun loadClassAnnotations(visitor: AnnotationVisitor)
|
||||
|
||||
void visitMembers(@NotNull MemberVisitor visitor);
|
||||
fun visitMembers(visitor: MemberVisitor)
|
||||
|
||||
@NotNull
|
||||
KotlinClassHeader getClassHeader();
|
||||
val classHeader: KotlinClassHeader
|
||||
|
||||
interface MemberVisitor {
|
||||
// TODO: abstract signatures for methods and fields instead of ASM 'desc' strings?
|
||||
|
||||
@Nullable
|
||||
MethodAnnotationVisitor visitMethod(@NotNull Name name, @NotNull String desc);
|
||||
fun visitMethod(name: Name, desc: String): MethodAnnotationVisitor?
|
||||
|
||||
@Nullable
|
||||
AnnotationVisitor visitField(@NotNull Name name, @NotNull String desc, @Nullable Object initializer);
|
||||
fun visitField(name: Name, desc: String, initializer: Any?): AnnotationVisitor?
|
||||
}
|
||||
|
||||
interface AnnotationVisitor {
|
||||
@Nullable
|
||||
AnnotationArgumentVisitor visitAnnotation(@NotNull ClassId classId, @NotNull SourceElement source);
|
||||
fun visitAnnotation(classId: ClassId, source: SourceElement): AnnotationArgumentVisitor?
|
||||
|
||||
void visitEnd();
|
||||
fun visitEnd()
|
||||
}
|
||||
|
||||
interface MethodAnnotationVisitor extends AnnotationVisitor {
|
||||
@Nullable
|
||||
AnnotationArgumentVisitor visitParameterAnnotation(int index, @NotNull ClassId classId, @NotNull SourceElement source);
|
||||
interface MethodAnnotationVisitor : AnnotationVisitor {
|
||||
fun visitParameterAnnotation(index: Int, classId: ClassId, source: SourceElement): AnnotationArgumentVisitor?
|
||||
}
|
||||
|
||||
interface AnnotationArgumentVisitor {
|
||||
// TODO: class literals
|
||||
void visit(@Nullable Name name, @Nullable Object value);
|
||||
fun visit(name: Name?, value: Any?)
|
||||
|
||||
void visitEnum(@NotNull Name name, @NotNull ClassId enumClassId, @NotNull Name enumEntryName);
|
||||
fun visitEnum(name: Name, enumClassId: ClassId, enumEntryName: Name)
|
||||
|
||||
@Nullable
|
||||
AnnotationArgumentVisitor visitAnnotation(@NotNull Name name, @NotNull ClassId classId);
|
||||
fun visitAnnotation(name: Name, classId: ClassId): AnnotationArgumentVisitor?
|
||||
|
||||
@Nullable
|
||||
AnnotationArrayArgumentVisitor visitArray(@NotNull Name name);
|
||||
fun visitArray(name: Name): AnnotationArrayArgumentVisitor?
|
||||
|
||||
void visitEnd();
|
||||
fun visitEnd()
|
||||
}
|
||||
|
||||
interface AnnotationArrayArgumentVisitor {
|
||||
void visit(@Nullable Object value);
|
||||
fun visit(value: Any?)
|
||||
|
||||
void visitEnum(@NotNull ClassId enumClassId, @NotNull Name enumEntryName);
|
||||
fun visitEnum(enumClassId: ClassId, enumEntryName: Name)
|
||||
|
||||
void visitEnd();
|
||||
fun visitEnd()
|
||||
}
|
||||
}
|
||||
|
||||
+6
-5
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.load.java.structure.reflect.isEnumClassOrSpecialized
|
||||
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass
|
||||
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
|
||||
import org.jetbrains.kotlin.load.kotlin.header.ReadKotlinClassHeaderAnnotationVisitor
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import java.lang.reflect.Constructor
|
||||
import java.lang.reflect.Field
|
||||
@@ -41,7 +42,7 @@ private val TYPES_ELIGIBLE_FOR_SIMPLE_VISIT = setOf<Class<*>>(
|
||||
|
||||
class ReflectKotlinClass private constructor(
|
||||
val klass: Class<*>,
|
||||
private val classHeader: KotlinClassHeader
|
||||
override val classHeader: KotlinClassHeader
|
||||
) : KotlinJvmBinaryClass {
|
||||
|
||||
companion object Factory {
|
||||
@@ -53,11 +54,11 @@ class ReflectKotlinClass private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getLocation() = klass.name.replace('.', '/') + ".class"
|
||||
override val location: String
|
||||
get() = klass.name.replace('.', '/') + ".class"
|
||||
|
||||
override fun getClassId() = klass.classId
|
||||
|
||||
override fun getClassHeader() = classHeader
|
||||
override val classId: ClassId
|
||||
get() = klass.classId
|
||||
|
||||
override fun loadClassAnnotations(visitor: KotlinJvmBinaryClass.AnnotationVisitor) {
|
||||
ReflectClassStructure.loadClassAnnotations(klass, visitor)
|
||||
|
||||
+43
-55
@@ -14,70 +14,58 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.serialization.deserialization;
|
||||
package org.jetbrains.kotlin.serialization.deserialization
|
||||
|
||||
import com.google.protobuf.MessageLite;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
import java.util.List;
|
||||
import com.google.protobuf.MessageLite
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
// The MessageLite instance everywhere should be Constructor, Function or Property
|
||||
// TODO: simplify this interface
|
||||
public interface AnnotationAndConstantLoader<A, C, T> {
|
||||
@NotNull
|
||||
List<A> loadClassAnnotations(
|
||||
@NotNull ProtoBuf.Class classProto,
|
||||
@NotNull NameResolver nameResolver
|
||||
);
|
||||
interface AnnotationAndConstantLoader<A : Any, C : Any, T : Any> {
|
||||
fun loadClassAnnotations(
|
||||
classProto: ProtoBuf.Class,
|
||||
nameResolver: NameResolver
|
||||
): List<A>
|
||||
|
||||
@NotNull
|
||||
List<T> loadCallableAnnotations(
|
||||
@NotNull ProtoContainer container,
|
||||
@NotNull MessageLite message,
|
||||
@NotNull AnnotatedCallableKind kind
|
||||
);
|
||||
fun loadCallableAnnotations(
|
||||
container: ProtoContainer,
|
||||
proto: MessageLite,
|
||||
kind: AnnotatedCallableKind
|
||||
): List<T>
|
||||
|
||||
@NotNull
|
||||
List<A> loadEnumEntryAnnotations(
|
||||
@NotNull ProtoContainer container,
|
||||
@NotNull ProtoBuf.EnumEntry proto
|
||||
);
|
||||
fun loadEnumEntryAnnotations(
|
||||
container: ProtoContainer,
|
||||
proto: ProtoBuf.EnumEntry
|
||||
): List<A>
|
||||
|
||||
@NotNull
|
||||
List<A> loadValueParameterAnnotations(
|
||||
@NotNull ProtoContainer container,
|
||||
@NotNull MessageLite message,
|
||||
@NotNull AnnotatedCallableKind kind,
|
||||
int parameterIndex,
|
||||
@NotNull ProtoBuf.ValueParameter proto
|
||||
);
|
||||
fun loadValueParameterAnnotations(
|
||||
container: ProtoContainer,
|
||||
callableProto: MessageLite,
|
||||
kind: AnnotatedCallableKind,
|
||||
parameterIndex: Int,
|
||||
proto: ProtoBuf.ValueParameter
|
||||
): List<A>
|
||||
|
||||
@NotNull
|
||||
List<A> loadExtensionReceiverParameterAnnotations(
|
||||
@NotNull ProtoContainer container,
|
||||
@NotNull MessageLite message,
|
||||
@NotNull AnnotatedCallableKind kind
|
||||
);
|
||||
fun loadExtensionReceiverParameterAnnotations(
|
||||
container: ProtoContainer,
|
||||
proto: MessageLite,
|
||||
kind: AnnotatedCallableKind
|
||||
): List<A>
|
||||
|
||||
@NotNull
|
||||
List<A> loadTypeAnnotations(
|
||||
@NotNull ProtoBuf.Type type,
|
||||
@NotNull NameResolver nameResolver
|
||||
);
|
||||
fun loadTypeAnnotations(
|
||||
proto: ProtoBuf.Type,
|
||||
nameResolver: NameResolver
|
||||
): List<A>
|
||||
|
||||
@NotNull
|
||||
List<A> loadTypeParameterAnnotations(
|
||||
@NotNull ProtoBuf.TypeParameter typeParameter,
|
||||
@NotNull NameResolver nameResolver
|
||||
);
|
||||
fun loadTypeParameterAnnotations(
|
||||
proto: ProtoBuf.TypeParameter,
|
||||
nameResolver: NameResolver
|
||||
): List<A>
|
||||
|
||||
@Nullable
|
||||
C loadPropertyConstant(
|
||||
@NotNull ProtoContainer container,
|
||||
@NotNull ProtoBuf.Property proto,
|
||||
@NotNull KotlinType expectedType
|
||||
);
|
||||
fun loadPropertyConstant(
|
||||
container: ProtoContainer,
|
||||
proto: ProtoBuf.Property,
|
||||
expectedType: KotlinType
|
||||
): C?
|
||||
}
|
||||
|
||||
+2
-2
@@ -64,7 +64,7 @@ class AnnotationAndConstantLoaderImpl(
|
||||
|
||||
override fun loadValueParameterAnnotations(
|
||||
container: ProtoContainer,
|
||||
message: MessageLite,
|
||||
callableProto: MessageLite,
|
||||
kind: AnnotatedCallableKind,
|
||||
parameterIndex: Int,
|
||||
proto: ProtoBuf.ValueParameter
|
||||
@@ -75,7 +75,7 @@ class AnnotationAndConstantLoaderImpl(
|
||||
|
||||
override fun loadExtensionReceiverParameterAnnotations(
|
||||
container: ProtoContainer,
|
||||
message: MessageLite,
|
||||
proto: MessageLite,
|
||||
kind: AnnotatedCallableKind
|
||||
): List<AnnotationDescriptor> = emptyList()
|
||||
|
||||
|
||||
+2
-2
@@ -57,7 +57,7 @@ class AnnotationLoaderForStubBuilderImpl(
|
||||
|
||||
override fun loadValueParameterAnnotations(
|
||||
container: ProtoContainer,
|
||||
message: MessageLite,
|
||||
callableProto: MessageLite,
|
||||
kind: AnnotatedCallableKind,
|
||||
parameterIndex: Int,
|
||||
proto: ProtoBuf.ValueParameter
|
||||
@@ -66,7 +66,7 @@ class AnnotationLoaderForStubBuilderImpl(
|
||||
|
||||
override fun loadExtensionReceiverParameterAnnotations(
|
||||
container: ProtoContainer,
|
||||
message: MessageLite,
|
||||
proto: MessageLite,
|
||||
kind: AnnotatedCallableKind
|
||||
): List<ClassId> = emptyList()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user