Skip to content

Commit 453ec7c

Browse files
authored
Fix TypeName (#308)
1 parent b70957d commit 453ec7c

File tree

16 files changed

+112
-97
lines changed

16 files changed

+112
-97
lines changed

jacodb-api-jvm/src/main/kotlin/org/jacodb/api/jvm/ext/JcCommons.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fun String.jcdbName(): String {
6464
substring(1, length - 1).replace('/', '.')
6565
}
6666

67-
else -> this.replace('/', '.')
67+
else -> error("Incorrect JVM name: $this")
6868
}
6969
}
7070

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ object InstSubstitutorForApproximations : JcRawInstVisitor<JcRawInst>, JcRawExpr
398398
private fun <T : JcRawExpr> T.eliminateApproximations(typeName: TypeName, constructor: (TypeName) -> T): T {
399399
val className = typeName.typeName.toApproximationName()
400400
val originalClassName = findOriginalByApproximationOrNull(className) ?: return this
401-
return constructor(TypeNameImpl(originalClassName))
401+
return constructor(TypeNameImpl.fromTypeName(originalClassName))
402402
}
403403

404404
override fun visitJcRawLocalVar(value: JcRawLocalVar): JcRawExpr {

jacodb-approximations/src/main/kotlin/org/jacodb/approximation/Util.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ fun TypeName.eliminateApproximation(): TypeName {
3333
return resultElemType.asArray(dim)
3434
}
3535
val originalClassName = findOriginalByApproximationOrNull(typeName.toApproximationName()) ?: return this
36-
return TypeNameImpl(originalClassName)
36+
return TypeNameImpl.fromTypeName(originalClassName)
3737
}

jacodb-core/src/main/kotlin/org/jacodb/impl/bytecode/JcFieldImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class JcFieldImpl(
4040
override val access: Int
4141
get() = info.access
4242

43-
override val type: TypeName = TypeNameImpl(info.type)
43+
override val type: TypeName = TypeNameImpl.fromTypeName(info.type)
4444

4545
override val signature: String?
4646
get() = info.signature

jacodb-core/src/main/kotlin/org/jacodb/impl/bytecode/JcMethodImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ class JcMethodImpl(
4545
override val name: String get() = methodInfo.name
4646
override val access: Int get() = methodInfo.access
4747
override val signature: String? get() = methodInfo.signature
48-
override val returnType: TypeName = TypeNameImpl(methodInfo.returnClass)
48+
override val returnType: TypeName = TypeNameImpl.fromTypeName(methodInfo.returnClass)
4949

5050
override val exceptions: List<TypeName>
5151
get() {
52-
return methodInfo.exceptions.map { TypeNameImpl(it) }
52+
return methodInfo.exceptions.map { TypeNameImpl.fromTypeName(it) }
5353
}
5454

5555
override val declaration = JcDeclarationImpl.of(location = enclosingClass.declaration.location, this)

jacodb-core/src/main/kotlin/org/jacodb/impl/bytecode/JcParameterImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class JcParameterImpl(
4646
get() = info.annotations.map { JcAnnotationImpl(it, method.enclosingClass.classpath) }
4747

4848
override val type: TypeName
49-
get() = TypeNameImpl(info.type)
49+
get() = TypeNameImpl.fromTypeName(info.type)
5050

5151
override fun toString(): String {
5252
return "$method $name"

jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/RawInstListBuilder.kt

Lines changed: 62 additions & 57 deletions
Large diffs are not rendered by default.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import org.jacodb.api.jvm.*
2020
import org.jacodb.api.jvm.cfg.*
2121
import org.jacodb.api.jvm.ext.findType
2222
import org.jacodb.api.jvm.ext.jvmName
23-
import org.jacodb.impl.cfg.util.typeName
23+
import org.jacodb.impl.cfg.util.typeNameFromJvmName
2424
import org.jacodb.impl.softLazy
2525
import org.jacodb.impl.weakLazy
2626
import org.objectweb.asm.Type
@@ -64,7 +64,7 @@ abstract class MethodSignatureRef(
6464

6565
protected val JcType.methodNotFoundMessage: String
6666
get() {
67-
val argumentTypes = Type.getArgumentTypes(description).map { it.descriptor.typeName() }
67+
val argumentTypes = Type.getArgumentTypes(description).map { it.descriptor.typeNameFromJvmName() }
6868
return buildString {
6969
append("Can't find method '")
7070
append(typeName)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import org.jacodb.api.jvm.ext.short
4848
import org.jacodb.impl.cfg.util.NULL
4949
import org.jacodb.impl.cfg.util.STRING_CLASS
5050
import org.jacodb.impl.cfg.util.typeName
51+
import org.jacodb.impl.cfg.util.typeNameFromJvmName
5152

5253
@JvmName("rawNull")
5354
fun JcRawNull() = JcRawNullConstant(NULL)
@@ -108,7 +109,7 @@ fun JcRawNumber(number: Number) = when (number) {
108109

109110
@JvmName("rawString")
110111
fun JcRawString(value: String) =
111-
JcRawStringConstant(value, STRING_CLASS.typeName())
112+
JcRawStringConstant(value, STRING_CLASS.typeNameFromJvmName())
112113

113114
fun JcClasspath.int(value: Int): JcInt = JcInt(value, int)
114115
fun JcClasspath.byte(value: Byte): JcByte = JcByte(value, byte)

jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/util/types.kt

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ package org.jacodb.impl.cfg.util
1818

1919
import org.jacodb.api.jvm.PredefinedPrimitives
2020
import org.jacodb.api.jvm.TypeName
21-
import org.jacodb.api.jvm.ext.jcdbName
2221
import org.jacodb.api.jvm.ext.jvmName
2322
import org.jacodb.impl.types.TypeNameImpl
23+
import org.objectweb.asm.Type
2424

25-
internal val NULL = "null".typeName()
26-
internal const val OBJECT_CLASS = "Ljava.lang.Object;"
27-
internal const val STRING_CLASS = "Ljava.lang.String;"
28-
internal const val THROWABLE_CLASS = "Ljava.lang.Throwable;"
29-
internal const val CLASS_CLASS = "Ljava.lang.Class;"
30-
internal const val METHOD_HANDLE_CLASS = "Ljava.lang.invoke.MethodHandle;"
31-
internal const val METHOD_HANDLES_CLASS = "Ljava.lang.invoke.MethodHandles;"
32-
internal const val METHOD_HANDLES_LOOKUP_CLASS = "Ljava.lang.invoke.MethodHandles\$Lookup;"
33-
internal const val METHOD_TYPE_CLASS = "Ljava.lang.invoke.MethodType;"
34-
internal const val LAMBDA_METAFACTORY_CLASS = "Ljava.lang.invoke.LambdaMetafactory;"
35-
internal val TOP = "TOP".typeName()
36-
internal val UNINIT_THIS = "UNINIT_THIS".typeName()
25+
internal val NULL = TypeNameImpl.fromTypeName("null")
26+
internal const val OBJECT_CLASS = "Ljava/lang/Object;"
27+
internal const val STRING_CLASS = "Ljava/lang/String;"
28+
internal const val THROWABLE_CLASS = "Ljava/lang/Throwable;"
29+
internal const val CLASS_CLASS = "Ljava/lang/Class;"
30+
internal const val METHOD_HANDLE_CLASS = "Ljava/lang/invoke/MethodHandle;"
31+
internal const val METHOD_HANDLES_CLASS = "Ljava/lang/invoke/MethodHandles;"
32+
internal const val METHOD_HANDLES_LOOKUP_CLASS = "Ljava/lang/invoke/MethodHandles\$Lookup;"
33+
internal const val METHOD_TYPE_CLASS = "Ljava/lang/invoke/MethodType;"
34+
internal const val LAMBDA_METAFACTORY_CLASS = "Ljava/lang/invoke/LambdaMetafactory;"
35+
internal val TOP = TypeNameImpl.fromTypeName("TOP")
36+
internal val UNINIT_THIS = TypeNameImpl.fromTypeName("UNINIT_THIS")
3737

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

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

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

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

85-
val lambdaMetaFactory: TypeName = LAMBDA_METAFACTORY_CLASS.typeName()
86+
val lambdaMetaFactory: TypeName = LAMBDA_METAFACTORY_CLASS.typeNameFromJvmName()
8687
val lambdaMetaFactoryMethodName: String = "metafactory"
88+
89+
internal fun String.typeNameFromAsmInternalName(): TypeName =
90+
Type.getObjectType(this).descriptor.typeNameFromJvmName()

0 commit comments

Comments
 (0)