Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fun String.jcdbName(): String {
substring(1, length - 1).replace('/', '.')
}

else -> this.replace('/', '.')
else -> error("Incorrect JVM name: $this")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@
private fun <T : JcRawExpr> T.eliminateApproximations(typeName: TypeName, constructor: (TypeName) -> T): T {
val className = typeName.typeName.toApproximationName()
val originalClassName = findOriginalByApproximationOrNull(className) ?: return this
return constructor(TypeNameImpl(originalClassName))
return constructor(TypeNameImpl.fromTypeName(originalClassName))

Check warning on line 401 in jacodb-approximations/src/main/kotlin/org/jacodb/approximation/InstSubstitutorForApproximations.kt

View check run for this annotation

Codecov / codecov/patch

jacodb-approximations/src/main/kotlin/org/jacodb/approximation/InstSubstitutorForApproximations.kt#L401

Added line #L401 was not covered by tests
}

override fun visitJcRawLocalVar(value: JcRawLocalVar): JcRawExpr {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ fun TypeName.eliminateApproximation(): TypeName {
return resultElemType.asArray(dim)
}
val originalClassName = findOriginalByApproximationOrNull(typeName.toApproximationName()) ?: return this
return TypeNameImpl(originalClassName)
return TypeNameImpl.fromTypeName(originalClassName)
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class JcFieldImpl(
override val access: Int
get() = info.access

override val type: TypeName = TypeNameImpl(info.type)
override val type: TypeName = TypeNameImpl.fromTypeName(info.type)

override val signature: String?
get() = info.signature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ class JcMethodImpl(
override val name: String get() = methodInfo.name
override val access: Int get() = methodInfo.access
override val signature: String? get() = methodInfo.signature
override val returnType: TypeName = TypeNameImpl(methodInfo.returnClass)
override val returnType: TypeName = TypeNameImpl.fromTypeName(methodInfo.returnClass)

override val exceptions: List<TypeName>
get() {
return methodInfo.exceptions.map { TypeNameImpl(it) }
return methodInfo.exceptions.map { TypeNameImpl.fromTypeName(it) }
}

override val declaration = JcDeclarationImpl.of(location = enclosingClass.declaration.location, this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class JcParameterImpl(
get() = info.annotations.map { JcAnnotationImpl(it, method.enclosingClass.classpath) }

override val type: TypeName
get() = TypeNameImpl(info.type)
get() = TypeNameImpl.fromTypeName(info.type)

override fun toString(): String {
return "$method $name"
Expand Down
119 changes: 62 additions & 57 deletions jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/RawInstListBuilder.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.jacodb.api.jvm.cfg.*
import org.jacodb.api.jvm.ext.findType
import org.jacodb.api.jvm.ext.jvmName
import org.jacodb.impl.cfg.util.typeName
import org.jacodb.impl.cfg.util.typeNameFromJvmName
import org.jacodb.impl.softLazy
import org.jacodb.impl.weakLazy
import org.objectweb.asm.Type
Expand Down Expand Up @@ -64,7 +64,7 @@

protected val JcType.methodNotFoundMessage: String
get() {
val argumentTypes = Type.getArgumentTypes(description).map { it.descriptor.typeName() }
val argumentTypes = Type.getArgumentTypes(description).map { it.descriptor.typeNameFromJvmName() }

Check warning on line 67 in jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/TypedMethodRefImpl.kt

View check run for this annotation

Codecov / codecov/patch

jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/TypedMethodRefImpl.kt#L67

Added line #L67 was not covered by tests
return buildString {
append("Can't find method '")
append(typeName)
Expand Down
3 changes: 2 additions & 1 deletion jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/ValueExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.jacodb.impl.cfg.util.NULL
import org.jacodb.impl.cfg.util.STRING_CLASS
import org.jacodb.impl.cfg.util.typeName
import org.jacodb.impl.cfg.util.typeNameFromJvmName

@JvmName("rawNull")
fun JcRawNull() = JcRawNullConstant(NULL)
Expand Down Expand Up @@ -108,7 +109,7 @@

@JvmName("rawString")
fun JcRawString(value: String) =
JcRawStringConstant(value, STRING_CLASS.typeName())
JcRawStringConstant(value, STRING_CLASS.typeNameFromJvmName())

Check warning on line 112 in jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/ValueExt.kt

View check run for this annotation

Codecov / codecov/patch

jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/ValueExt.kt#L112

Added line #L112 was not covered by tests

fun JcClasspath.int(value: Int): JcInt = JcInt(value, int)
fun JcClasspath.byte(value: Byte): JcByte = JcByte(value, byte)
Expand Down
34 changes: 19 additions & 15 deletions jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/util/types.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ package org.jacodb.impl.cfg.util

import org.jacodb.api.jvm.PredefinedPrimitives
import org.jacodb.api.jvm.TypeName
import org.jacodb.api.jvm.ext.jcdbName
import org.jacodb.api.jvm.ext.jvmName
import org.jacodb.impl.types.TypeNameImpl
import org.objectweb.asm.Type

internal val NULL = "null".typeName()
internal const val OBJECT_CLASS = "Ljava.lang.Object;"
internal const val STRING_CLASS = "Ljava.lang.String;"
internal const val THROWABLE_CLASS = "Ljava.lang.Throwable;"
internal const val CLASS_CLASS = "Ljava.lang.Class;"
internal const val METHOD_HANDLE_CLASS = "Ljava.lang.invoke.MethodHandle;"
internal const val METHOD_HANDLES_CLASS = "Ljava.lang.invoke.MethodHandles;"
internal const val METHOD_HANDLES_LOOKUP_CLASS = "Ljava.lang.invoke.MethodHandles\$Lookup;"
internal const val METHOD_TYPE_CLASS = "Ljava.lang.invoke.MethodType;"
internal const val LAMBDA_METAFACTORY_CLASS = "Ljava.lang.invoke.LambdaMetafactory;"
internal val TOP = "TOP".typeName()
internal val UNINIT_THIS = "UNINIT_THIS".typeName()
internal val NULL = TypeNameImpl.fromTypeName("null")
internal const val OBJECT_CLASS = "Ljava/lang/Object;"
internal const val STRING_CLASS = "Ljava/lang/String;"
internal const val THROWABLE_CLASS = "Ljava/lang/Throwable;"
internal const val CLASS_CLASS = "Ljava/lang/Class;"
internal const val METHOD_HANDLE_CLASS = "Ljava/lang/invoke/MethodHandle;"
internal const val METHOD_HANDLES_CLASS = "Ljava/lang/invoke/MethodHandles;"
internal const val METHOD_HANDLES_LOOKUP_CLASS = "Ljava/lang/invoke/MethodHandles\$Lookup;"
internal const val METHOD_TYPE_CLASS = "Ljava/lang/invoke/MethodType;"
internal const val LAMBDA_METAFACTORY_CLASS = "Ljava/lang/invoke/LambdaMetafactory;"
internal val TOP = TypeNameImpl.fromTypeName("TOP")
internal val UNINIT_THIS = TypeNameImpl.fromTypeName("UNINIT_THIS")

internal val TypeName.jvmTypeName get() = typeName.jvmName()
internal val TypeName.jvmClassName get() = jvmTypeName.removePrefix("L").removeSuffix(";")
Expand All @@ -59,7 +59,8 @@ val TypeName.isClass get() = !isPrimitive && !isArray

internal val TypeName.isDWord get() = typeName == PredefinedPrimitives.Long || typeName == PredefinedPrimitives.Double

internal fun String.typeName(): TypeName = TypeNameImpl(this.jcdbName())
internal fun String.typeNameFromJvmName(): TypeName = TypeNameImpl.fromJvmName(this)
internal fun String.typeName(): TypeName = TypeNameImpl.fromTypeName(this)
fun TypeName.asArray(dimensions: Int = 1) = "$typeName${"[]".repeat(dimensions)}".typeName()
internal fun TypeName.elementType() = elementTypeOrNull() ?: this

Expand All @@ -82,5 +83,8 @@ fun TypeName.baseElementType(): Pair<TypeName, Int> {
return Pair(current!!, dim)
}

val lambdaMetaFactory: TypeName = LAMBDA_METAFACTORY_CLASS.typeName()
val lambdaMetaFactory: TypeName = LAMBDA_METAFACTORY_CLASS.typeNameFromJvmName()
val lambdaMetaFactoryMethodName: String = "metafactory"

internal fun String.typeNameFromAsmInternalName(): TypeName =
Type.getObjectType(this).descriptor.typeNameFromJvmName()
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import org.jacodb.api.jvm.JcMethod
import org.jacodb.api.jvm.JcTypedField
import org.jacodb.api.jvm.JcTypedMethod
import org.jacodb.api.jvm.TypeName
import org.jacodb.api.jvm.ext.jcdbName
import org.jacodb.impl.features.classpaths.AbstractJcResolvedResult.JcResolvedClassResultImpl
import org.jacodb.impl.features.classpaths.virtual.JcVirtualClassImpl
import org.jacodb.impl.features.classpaths.virtual.JcVirtualFieldImpl
Expand Down Expand Up @@ -75,8 +74,8 @@ class JcUnknownMethod(

fun method(type: JcClassOrInterface, name: String, access: Int, description: String): JcMethod {
val methodType = Type.getMethodType(description)
val returnType = TypeNameImpl(methodType.returnType.className.jcdbName())
val paramsType = methodType.argumentTypes.map { TypeNameImpl(it.className.jcdbName()) }
val returnType = TypeNameImpl.fromTypeName(methodType.returnType.className)
val paramsType = methodType.argumentTypes.map { TypeNameImpl.fromTypeName(it.className) }
return JcUnknownMethod(type, name, access, description, returnType, paramsType)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package org.jacodb.impl.features.classpaths
import org.jacodb.api.jvm.*
import org.jacodb.api.jvm.ext.objectType
import org.jacodb.impl.cfg.util.OBJECT_CLASS
import org.jacodb.impl.types.TypeNameImpl
import org.jacodb.impl.cfg.util.typeNameFromJvmName
import org.objectweb.asm.Opcodes


Expand Down Expand Up @@ -79,7 +79,7 @@ open class JcUnknownClassLookup(val clazz: JcClassOrInterface) : JcLookup<JcFiel

override fun field(name: String, typeName: TypeName?, fieldKind: JcLookup.FieldKind): JcField {
val staticModifier = if (fieldKind == JcLookup.FieldKind.STATIC) Opcodes.ACC_STATIC else 0
val fieldType = typeName ?: TypeNameImpl(OBJECT_CLASS)
val fieldType = typeName ?: OBJECT_CLASS.typeNameFromJvmName()
return JcUnknownField(clazz, name, access = Opcodes.ACC_PUBLIC or staticModifier, fieldType)
}

Expand All @@ -99,7 +99,7 @@ open class JcUnknownTypeLookup(val type: JcClassType) : JcLookup<JcTypedField, J

override fun field(name: String, typeName: TypeName?, fieldKind: JcLookup.FieldKind): JcTypedField {
val staticModifier = if (fieldKind == JcLookup.FieldKind.STATIC) Opcodes.ACC_STATIC else 0
val fieldType = typeName ?: TypeNameImpl(OBJECT_CLASS)
val fieldType = typeName ?: OBJECT_CLASS.typeNameFromJvmName()
return JcUnknownField.typedField(type, name, access = Opcodes.ACC_PUBLIC or staticModifier, fieldType)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ open class VirtualClassesBuilder {

open class VirtualFieldBuilder(private var _name: String = "_virtual_") {
companion object {
private val defType = TypeNameImpl("java.lang.Object")
private val defType = TypeNameImpl.fromTypeName("java.lang.Object")
}

val name: String get() = _name
Expand All @@ -85,7 +85,7 @@ open class VirtualClassesBuilder {
}

fun type(name: String) = apply {
type = TypeNameImpl(name)
type = TypeNameImpl.fromTypeName(name)
}

fun name(name: String) = apply {
Expand All @@ -103,7 +103,7 @@ open class VirtualClassesBuilder {

var access = Opcodes.ACC_PUBLIC
private set
var returnType: TypeName = TypeNameImpl(PredefinedPrimitives.Void)
var returnType: TypeName = TypeNameImpl.fromTypeName(PredefinedPrimitives.Void)
private set
var parameters: List<TypeName> = emptyList()
private set
Expand All @@ -113,15 +113,15 @@ open class VirtualClassesBuilder {
}

fun params(vararg p: String) = apply {
parameters = p.map { TypeNameImpl(it) }.toList()
parameters = p.map { TypeNameImpl.fromTypeName(it) }.toList()
}

fun name(name: String) = apply {
this._name = name
}

fun returnType(name: String) = apply {
returnType = TypeNameImpl(name)
returnType = TypeNameImpl.fromTypeName(name)
}

open val description: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private fun FieldNode.asFieldInfo() = FieldInfo(
name = name.interned,
signature = signature,
access = access,
type = Type.getObjectType(desc).className.interned,
type = Type.getType(desc).className.interned,
annotations = concatLists(
visibleAnnotations.asAnnotationInfos(true),
invisibleAnnotations.asAnnotationInfos(false),
Expand Down
8 changes: 7 additions & 1 deletion jacodb-core/src/main/kotlin/org/jacodb/impl/types/Objects.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package org.jacodb.impl.types
import kotlinx.serialization.Serializable
import org.jacodb.api.jvm.ext.jcdbName
import org.jacodb.api.jvm.TypeName
import org.jacodb.api.jvm.ext.jvmName
import org.jacodb.impl.storage.AnnotationValueKind
import org.jacodb.impl.util.adjustEmptyList
import org.jacodb.impl.util.interned
Expand Down Expand Up @@ -109,8 +110,13 @@ class ClassRef(val className: String) : AnnotationValue()
class EnumRef(val className: String, val enumName: String) : AnnotationValue()

@Serializable
data class TypeNameImpl(private val jvmName: String) : TypeName {
data class TypeNameImpl private constructor(private val jvmName: String) : TypeName {
override val typeName: String = jvmName.jcdbName().interned

override fun toString(): String = typeName

companion object {
fun fromJvmName(jvmName: String): TypeNameImpl = TypeNameImpl(jvmName)
fun fromTypeName(typeName: String): TypeNameImpl = fromJvmName(typeName.jvmName())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ open class ConfigurationTest : BaseTest() {

@Test
fun testVirtualMethod() {
val virtualParameter = JcVirtualParameter(0, TypeNameImpl(cp.objectType.typeName))
val virtualParameter = JcVirtualParameter(0, TypeNameImpl.fromTypeName(cp.objectType.typeName))

val method = JcVirtualMethodImpl(
name = "setValue",
returnType = TypeNameImpl(cp.objectType.typeName),
returnType = TypeNameImpl.fromTypeName(cp.objectType.typeName),
parameters = listOf(virtualParameter),
description = ""
)
Expand Down
Loading