diff --git a/jacodb-api-jvm/src/main/kotlin/org/jacodb/api/jvm/ext/JcCommons.kt b/jacodb-api-jvm/src/main/kotlin/org/jacodb/api/jvm/ext/JcCommons.kt index 43973a510..67b32f2c4 100644 --- a/jacodb-api-jvm/src/main/kotlin/org/jacodb/api/jvm/ext/JcCommons.kt +++ b/jacodb-api-jvm/src/main/kotlin/org/jacodb/api/jvm/ext/JcCommons.kt @@ -64,7 +64,7 @@ fun String.jcdbName(): String { substring(1, length - 1).replace('/', '.') } - else -> this.replace('/', '.') + else -> error("Incorrect JVM name: $this") } } diff --git a/jacodb-approximations/src/main/kotlin/org/jacodb/approximation/InstSubstitutorForApproximations.kt b/jacodb-approximations/src/main/kotlin/org/jacodb/approximation/InstSubstitutorForApproximations.kt index e0f35aeb8..e331551c2 100644 --- a/jacodb-approximations/src/main/kotlin/org/jacodb/approximation/InstSubstitutorForApproximations.kt +++ b/jacodb-approximations/src/main/kotlin/org/jacodb/approximation/InstSubstitutorForApproximations.kt @@ -398,7 +398,7 @@ object InstSubstitutorForApproximations : JcRawInstVisitor, JcRawExpr private fun 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)) } override fun visitJcRawLocalVar(value: JcRawLocalVar): JcRawExpr { diff --git a/jacodb-approximations/src/main/kotlin/org/jacodb/approximation/Util.kt b/jacodb-approximations/src/main/kotlin/org/jacodb/approximation/Util.kt index 570952b8d..4a0d53b9f 100644 --- a/jacodb-approximations/src/main/kotlin/org/jacodb/approximation/Util.kt +++ b/jacodb-approximations/src/main/kotlin/org/jacodb/approximation/Util.kt @@ -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) } diff --git a/jacodb-core/src/main/kotlin/org/jacodb/impl/bytecode/JcFieldImpl.kt b/jacodb-core/src/main/kotlin/org/jacodb/impl/bytecode/JcFieldImpl.kt index a3df16072..cca65ffd5 100644 --- a/jacodb-core/src/main/kotlin/org/jacodb/impl/bytecode/JcFieldImpl.kt +++ b/jacodb-core/src/main/kotlin/org/jacodb/impl/bytecode/JcFieldImpl.kt @@ -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 diff --git a/jacodb-core/src/main/kotlin/org/jacodb/impl/bytecode/JcMethodImpl.kt b/jacodb-core/src/main/kotlin/org/jacodb/impl/bytecode/JcMethodImpl.kt index e37ba3ce7..d3991c4f6 100644 --- a/jacodb-core/src/main/kotlin/org/jacodb/impl/bytecode/JcMethodImpl.kt +++ b/jacodb-core/src/main/kotlin/org/jacodb/impl/bytecode/JcMethodImpl.kt @@ -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 get() { - return methodInfo.exceptions.map { TypeNameImpl(it) } + return methodInfo.exceptions.map { TypeNameImpl.fromTypeName(it) } } override val declaration = JcDeclarationImpl.of(location = enclosingClass.declaration.location, this) diff --git a/jacodb-core/src/main/kotlin/org/jacodb/impl/bytecode/JcParameterImpl.kt b/jacodb-core/src/main/kotlin/org/jacodb/impl/bytecode/JcParameterImpl.kt index 5f8df1172..7d6365471 100644 --- a/jacodb-core/src/main/kotlin/org/jacodb/impl/bytecode/JcParameterImpl.kt +++ b/jacodb-core/src/main/kotlin/org/jacodb/impl/bytecode/JcParameterImpl.kt @@ -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" diff --git a/jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/RawInstListBuilder.kt b/jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/RawInstListBuilder.kt index b734381db..e06f6aabd 100644 --- a/jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/RawInstListBuilder.kt +++ b/jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/RawInstListBuilder.kt @@ -114,6 +114,8 @@ import org.jacodb.impl.cfg.util.isArray import org.jacodb.impl.cfg.util.isDWord import org.jacodb.impl.cfg.util.isPrimitive import org.jacodb.impl.cfg.util.typeName +import org.jacodb.impl.cfg.util.typeNameFromAsmInternalName +import org.jacodb.impl.cfg.util.typeNameFromJvmName import org.jacodb.impl.types.TypeNameImpl import org.objectweb.asm.* import org.objectweb.asm.tree.AbstractInsnNode @@ -179,7 +181,7 @@ private fun parseBsmHandleTag(tag: Int): BsmHandleTag = when (tag) { } private fun parseType(any: Any): TypeName = when (any) { - is String -> any.typeName() + is String -> any.typeNameFromAsmInternalName() is Int -> parsePrimitiveType(any) is LabelNode -> { val newNode: TypeInsnNode = any.run { @@ -191,7 +193,7 @@ private fun parseType(any: Any): TypeName = when (any) { } while (typeInsnNode == null) typeInsnNode } - newNode.desc.typeName() + newNode.desc.typeNameFromAsmInternalName() } else -> error("Unexpected local type $any") @@ -210,7 +212,7 @@ private infix fun TypeName.isCompatibleWith(type: TypeName): Boolean { return isDWord == type.isDWord } -private val OBJECT_TYPE_NAME = OBJECT_CLASS.typeName() +private val OBJECT_TYPE_NAME = OBJECT_CLASS.typeNameFromJvmName() private fun typeLub(first: TypeName, second: TypeName): TypeName { if (first == second) return first @@ -330,13 +332,15 @@ private val AbstractInsnNode.isBranchingInst private val AbstractInsnNode.isTerminateInst get() = this is InsnNode && (this.opcode == Opcodes.ATHROW || this.opcode in Opcodes.IRETURN..Opcodes.RETURN) -private val TryCatchBlockNode.typeOrDefault get() = this.type ?: THROWABLE_CLASS +private val TryCatchBlockNode.typeOrDefault: TypeName + get() = this.type?.typeNameFromAsmInternalName() + ?: THROWABLE_CLASS.typeNameFromJvmName() -private val Collection.commonTypeOrDefault - get() = map { it.type } +private val Collection.commonTypeOrDefault: TypeName + get() = map { it.type?.typeNameFromAsmInternalName() } .distinct() .singleOrNull() - ?: THROWABLE_CLASS + ?: THROWABLE_CLASS.typeNameFromJvmName() internal fun identityMap(): MutableMap = IdentityHashMap() @@ -806,9 +810,9 @@ class RawInstListBuilder( val typeOfNewAssigment = if (expr.typeName.typeName == PredefinedPrimitives.Null) { findLocalVariableWithInstruction(variable, insn) - ?.desc?.typeName() + ?.desc?.typeNameFromJvmName() ?: currentFrame.findLocal(variable)?.typeName - ?: "java.lang.Object".typeName() + ?: OBJECT_TYPE_NAME } else { expr.typeName } @@ -880,7 +884,7 @@ class RawInstListBuilder( nextVar = nextVar.copy(name = lvName) } - val declaredTypeName = lvNode?.desc?.typeName() + val declaredTypeName = lvNode?.desc?.typeNameFromJvmName() if (declaredTypeName != null && !declaredTypeName.isPrimitive && !typeName.isArray) { nextVar = nextVar.copy(typeName = declaredTypeName) } @@ -1003,7 +1007,7 @@ class RawInstListBuilder( return Frame(locals.copyOf(localsRealSize), persistentListOf()) } - private fun thisRef() = JcRawThis(method.enclosingClass.name.typeName()) + private fun thisRef() = JcRawThis(TypeNameImpl.fromTypeName(method.enclosingClass.name)) private fun buildInsnNode(insn: InsnNode, frame: FrameBuilder) = with(frame) { when (insn.opcode) { @@ -1211,8 +1215,8 @@ class RawInstListBuilder( val rightName = right.typeName val max = maxOfPrimitiveTypes(leftName, rightName) return when { - max.lessThen(PredefinedPrimitives.Int) -> TypeNameImpl(PredefinedPrimitives.Int) - else -> TypeNameImpl(max) + max.lessThen(PredefinedPrimitives.Int) -> TypeNameImpl.fromTypeName(PredefinedPrimitives.Int) + else -> TypeNameImpl.fromTypeName(max) } } return left @@ -1223,7 +1227,7 @@ class RawInstListBuilder( val expr = when (val opcode = insn.opcode) { in Opcodes.INEG..Opcodes.DNEG -> { val resolvedType = maxOfPrimitiveTypes(operand.typeName.typeName, PredefinedPrimitives.Int) - JcRawNegExpr(TypeNameImpl(resolvedType), operand) + JcRawNegExpr(TypeNameImpl.fromTypeName(resolvedType), operand) } Opcodes.ARRAYLENGTH -> JcRawLengthExpr(PredefinedPrimitives.Int.typeName(), operand) @@ -1296,8 +1300,8 @@ class RawInstListBuilder( private fun buildFieldInsnNode(insnNode: FieldInsnNode, frame: FrameBuilder) { val fieldName = insnNode.name - val fieldType = insnNode.desc.typeName() - val declaringClass = insnNode.owner.typeName() + val fieldType = insnNode.desc.typeNameFromJvmName() + val declaringClass = insnNode.owner.typeNameFromAsmInternalName() when (insnNode.opcode) { Opcodes.GETFIELD -> { val assignment = nextRegister(fieldType) @@ -1391,17 +1395,17 @@ class RawInstListBuilder( private val Handle.bsmHandleArg get() = BsmHandle( parseBsmHandleTag(tag), - owner.typeName(), + owner.typeNameFromAsmInternalName(), name, if (desc.contains("(")) { - Type.getArgumentTypes(desc).map { it.descriptor.typeName() } + Type.getArgumentTypes(desc).map { it.descriptor.typeNameFromJvmName() } } else { listOf() }, if (desc.contains("(")) { - Type.getReturnType(desc).descriptor.typeName() + Type.getReturnType(desc).descriptor.typeNameFromJvmName() } else { - Type.getReturnType("(;)$desc").descriptor.typeName() + Type.getReturnType("(;)$desc").descriptor.typeNameFromJvmName() }, isInterface ) @@ -1431,14 +1435,14 @@ class RawInstListBuilder( bsmMethod, bsmArgs, insnNode.name, - Type.getArgumentTypes(desc).map { it.descriptor.typeName() }, - Type.getReturnType(desc).descriptor.typeName(), + Type.getArgumentTypes(desc).map { it.descriptor.typeNameFromJvmName() }, + Type.getReturnType(desc).descriptor.typeNameFromJvmName(), args, ) if (Type.getReturnType(desc) == Type.VOID_TYPE) { addInstruction(insnNode, JcRawCallInst(method, expr)) } else { - val result = nextRegister(Type.getReturnType(desc).descriptor.typeName()) + val result = nextRegister(Type.getReturnType(desc).descriptor.typeNameFromJvmName()) addInstruction(insnNode, JcRawAssignInst(method, result, expr)) push(result) } @@ -1618,7 +1622,7 @@ class RawInstListBuilder( // If we have several variables types for one register we have to search right type in debug info otherwise we cannot guarantee anything val debugType = findLocalVariableWithInstruction(variable, curLabel) ?.let { Type.getType(it.desc) } - ?.descriptor?.typeName() + ?.descriptor?.typeNameFromJvmName() if (debugType != null) return debugType @@ -1658,7 +1662,7 @@ class RawInstListBuilder( val catchEntries = tryCatchHandlers[insnNode].orEmpty() if (catchEntries.isNotEmpty()) { - throwable = nextRegister(catchEntries.commonTypeOrDefault.typeName()) + throwable = nextRegister(catchEntries.commonTypeOrDefault) val entries = catchEntries.mapIndexed { index, node -> buildCatchEntry(node) @@ -1701,7 +1705,7 @@ class RawInstListBuilder( instructionList(node.end).add(endLabel) } - return JcRawCatchEntry(node.typeOrDefault.typeName(), startLabel.ref, endLabel.ref) + return JcRawCatchEntry(node.typeOrDefault, startLabel.ref, endLabel.ref) } private fun buildLineNumberNode(insnNode: LineNumberNode) = @@ -1713,15 +1717,15 @@ class RawInstListBuilder( is Float -> JcRawFloat(cst) is Double -> JcRawDouble(cst) is Long -> JcRawLong(cst) - is String -> JcRawStringConstant(cst, STRING_CLASS.typeName()) - is Type -> JcRawClassConstant(cst.descriptor.typeName(), CLASS_CLASS.typeName()) + is String -> JcRawStringConstant(cst, STRING_CLASS.typeNameFromJvmName()) + is Type -> JcRawClassConstant(cst.descriptor.typeNameFromJvmName(), CLASS_CLASS.typeNameFromJvmName()) is Handle -> { JcRawMethodConstant( - cst.owner.typeName(), + cst.owner.typeNameFromAsmInternalName(), cst.name, - Type.getArgumentTypes(cst.desc).map { it.descriptor.typeName() }, - Type.getReturnType(cst.desc).descriptor.typeName(), - METHOD_HANDLE_CLASS.typeName() + Type.getArgumentTypes(cst.desc).map { it.descriptor.typeNameFromJvmName() }, + Type.getReturnType(cst.desc).descriptor.typeNameFromJvmName(), + METHOD_HANDLE_CLASS.typeNameFromJvmName() ) } @@ -1735,18 +1739,18 @@ class RawInstListBuilder( is Float -> push(ldcValue(cst)) is Double -> push(ldcValue(cst)) is Long -> push(ldcValue(cst)) - is String -> push(JcRawStringConstant(cst, STRING_CLASS.typeName())) + is String -> push(JcRawStringConstant(cst, STRING_CLASS.typeNameFromJvmName())) is Type -> { - val assignment = nextRegister(CLASS_CLASS.typeName()) + val assignment = nextRegister(CLASS_CLASS.typeNameFromJvmName()) addInstruction( insnNode, JcRawAssignInst( method, assignment, when (cst.sort) { Type.METHOD -> JcRawMethodType( - cst.argumentTypes.map { it.descriptor.typeName() }, - cst.returnType.descriptor.typeName(), - METHOD_TYPE_CLASS.typeName() + cst.argumentTypes.map { it.descriptor.typeNameFromJvmName() }, + cst.returnType.descriptor.typeNameFromJvmName(), + METHOD_TYPE_CLASS.typeNameFromJvmName() ) else -> ldcValue(cst) @@ -1757,7 +1761,7 @@ class RawInstListBuilder( } is Handle -> { - val assignment = nextRegister(CLASS_CLASS.typeName()) + val assignment = nextRegister(CLASS_CLASS.typeNameFromJvmName()) addInstruction( insnNode, JcRawAssignInst( method, @@ -1770,7 +1774,7 @@ class RawInstListBuilder( is ConstantDynamic -> { val methodHande = cst.bootstrapMethod - val assignment = nextRegister(CLASS_CLASS.typeName()) + val assignment = nextRegister(CLASS_CLASS.typeNameFromJvmName()) val exprs = arrayListOf() repeat(cst.bootstrapMethodArgumentCount) { exprs.add( @@ -1779,38 +1783,38 @@ class RawInstListBuilder( } val methodCall: JcRawCallExpr = when (cst.bootstrapMethod.tag) { Opcodes.INVOKESPECIAL -> JcRawSpecialCallExpr( - methodHande.owner.typeName(), + methodHande.owner.typeNameFromAsmInternalName(), cst.name, - Type.getArgumentTypes(methodHande.desc).map { it.descriptor.typeName() }, - Type.getReturnType(methodHande.desc).descriptor.typeName(), + Type.getArgumentTypes(methodHande.desc).map { it.descriptor.typeNameFromJvmName() }, + Type.getReturnType(methodHande.desc).descriptor.typeNameFromJvmName(), thisRef(), exprs ) else -> { - val lookupAssignment = nextRegister(METHOD_HANDLES_LOOKUP_CLASS.typeName()) + val lookupAssignment = nextRegister(METHOD_HANDLES_LOOKUP_CLASS.typeNameFromJvmName()) addInstruction( insnNode, JcRawAssignInst( method, lookupAssignment, JcRawStaticCallExpr( - METHOD_HANDLES_CLASS.typeName(), + METHOD_HANDLES_CLASS.typeNameFromJvmName(), "lookup", emptyList(), - METHOD_HANDLES_LOOKUP_CLASS.typeName(), + METHOD_HANDLES_LOOKUP_CLASS.typeNameFromJvmName(), emptyList() ) ) ) JcRawStaticCallExpr( - methodHande.owner.typeName(), + methodHande.owner.typeNameFromAsmInternalName(), methodHande.name, - Type.getArgumentTypes(methodHande.desc).map { it.descriptor.typeName() }, - Type.getReturnType(methodHande.desc).descriptor.typeName(), + Type.getArgumentTypes(methodHande.desc).map { it.descriptor.typeNameFromJvmName() }, + Type.getReturnType(methodHande.desc).descriptor.typeNameFromJvmName(), listOf( lookupAssignment, - JcRawStringConstant(cst.name, STRING_CLASS.typeName()), - JcRawClassConstant(cst.descriptor.typeName(), CLASS_CLASS.typeName()) + JcRawStringConstant(cst.name, STRING_CLASS.typeNameFromJvmName()), + JcRawClassConstant(cst.descriptor.typeNameFromJvmName(), CLASS_CLASS.typeNameFromJvmName()) ) + exprs, methodHande.isInterface ) @@ -1834,13 +1838,14 @@ class RawInstListBuilder( } private fun buildMethodInsnNode(insnNode: MethodInsnNode, frame: FrameBuilder) = with(frame) { + val ownerTypeName = insnNode.owner.typeNameFromAsmInternalName() val owner = when { - insnNode.owner.typeName().isArray -> OBJECT_TYPE_NAME - else -> insnNode.owner.typeName() + ownerTypeName.isArray -> OBJECT_TYPE_NAME + else -> ownerTypeName } val methodName = insnNode.name - val argTypes = Type.getArgumentTypes(insnNode.desc).map { it.descriptor.typeName() } - val returnType = Type.getReturnType(insnNode.desc).descriptor.typeName() + val argTypes = Type.getArgumentTypes(insnNode.desc).map { it.descriptor.typeNameFromJvmName() } + val returnType = Type.getReturnType(insnNode.desc).descriptor.typeNameFromJvmName() val args = Type.getArgumentTypes(insnNode.desc).map { pop() }.reversed() @@ -1891,7 +1896,7 @@ class RawInstListBuilder( if (Type.getReturnType(insnNode.desc) == Type.VOID_TYPE) { addInstruction(insnNode, JcRawCallInst(method, expr)) } else { - val result = nextRegister(Type.getReturnType(insnNode.desc).descriptor.typeName()) + val result = nextRegister(Type.getReturnType(insnNode.desc).descriptor.typeNameFromJvmName()) addInstruction(insnNode, JcRawAssignInst(method, result, expr)) push(result) } @@ -1902,7 +1907,7 @@ class RawInstListBuilder( repeat(insnNode.dims) { dimensions += pop() } - val expr = JcRawNewArrayExpr(insnNode.desc.typeName(), dimensions.reversed()) + val expr = JcRawNewArrayExpr(insnNode.desc.typeNameFromJvmName(), dimensions.reversed()) val assignment = nextRegister(expr.typeName) addInstruction(insnNode, JcRawAssignInst(method, assignment, expr)) push(assignment) @@ -1918,7 +1923,7 @@ class RawInstListBuilder( } private fun buildTypeInsnNode(insnNode: TypeInsnNode, frame: FrameBuilder) = with(frame) { - val type = insnNode.desc.typeName() + val type = insnNode.desc.typeNameFromAsmInternalName() when (insnNode.opcode) { Opcodes.NEW -> { val assignment = nextRegister(type) diff --git a/jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/TypedMethodRefImpl.kt b/jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/TypedMethodRefImpl.kt index 9d9508040..8e0e1c572 100644 --- a/jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/TypedMethodRefImpl.kt +++ b/jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/TypedMethodRefImpl.kt @@ -20,7 +20,7 @@ import org.jacodb.api.jvm.* 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 @@ -64,7 +64,7 @@ abstract class MethodSignatureRef( protected val JcType.methodNotFoundMessage: String get() { - val argumentTypes = Type.getArgumentTypes(description).map { it.descriptor.typeName() } + val argumentTypes = Type.getArgumentTypes(description).map { it.descriptor.typeNameFromJvmName() } return buildString { append("Can't find method '") append(typeName) diff --git a/jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/ValueExt.kt b/jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/ValueExt.kt index c5b86d5c5..7bdb98ea1 100644 --- a/jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/ValueExt.kt +++ b/jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/ValueExt.kt @@ -48,6 +48,7 @@ import org.jacodb.api.jvm.ext.short 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) @@ -108,7 +109,7 @@ fun JcRawNumber(number: Number) = when (number) { @JvmName("rawString") fun JcRawString(value: String) = - JcRawStringConstant(value, STRING_CLASS.typeName()) + JcRawStringConstant(value, STRING_CLASS.typeNameFromJvmName()) fun JcClasspath.int(value: Int): JcInt = JcInt(value, int) fun JcClasspath.byte(value: Byte): JcByte = JcByte(value, byte) diff --git a/jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/util/types.kt b/jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/util/types.kt index 7bec1f1b3..b5124b48b 100644 --- a/jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/util/types.kt +++ b/jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/util/types.kt @@ -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(";") @@ -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 @@ -82,5 +83,8 @@ fun TypeName.baseElementType(): Pair { 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() diff --git a/jacodb-core/src/main/kotlin/org/jacodb/impl/features/classpaths/JcUnknownClass.kt b/jacodb-core/src/main/kotlin/org/jacodb/impl/features/classpaths/JcUnknownClass.kt index 829a7de9c..b8b0034f8 100644 --- a/jacodb-core/src/main/kotlin/org/jacodb/impl/features/classpaths/JcUnknownClass.kt +++ b/jacodb-core/src/main/kotlin/org/jacodb/impl/features/classpaths/JcUnknownClass.kt @@ -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 @@ -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) } diff --git a/jacodb-core/src/main/kotlin/org/jacodb/impl/features/classpaths/JcUnknownType.kt b/jacodb-core/src/main/kotlin/org/jacodb/impl/features/classpaths/JcUnknownType.kt index b8e3bec82..3dff283e1 100644 --- a/jacodb-core/src/main/kotlin/org/jacodb/impl/features/classpaths/JcUnknownType.kt +++ b/jacodb-core/src/main/kotlin/org/jacodb/impl/features/classpaths/JcUnknownType.kt @@ -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 @@ -79,7 +79,7 @@ open class JcUnknownClassLookup(val clazz: JcClassOrInterface) : JcLookup = emptyList() private set @@ -113,7 +113,7 @@ 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 { @@ -121,7 +121,7 @@ open class VirtualClassesBuilder { } fun returnType(name: String) = apply { - returnType = TypeNameImpl(name) + returnType = TypeNameImpl.fromTypeName(name) } open val description: String diff --git a/jacodb-core/src/main/kotlin/org/jacodb/impl/fs/ByteCodeConverter.kt b/jacodb-core/src/main/kotlin/org/jacodb/impl/fs/ByteCodeConverter.kt index b24b4fbf1..5d3460adb 100644 --- a/jacodb-core/src/main/kotlin/org/jacodb/impl/fs/ByteCodeConverter.kt +++ b/jacodb-core/src/main/kotlin/org/jacodb/impl/fs/ByteCodeConverter.kt @@ -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), diff --git a/jacodb-core/src/main/kotlin/org/jacodb/impl/types/Objects.kt b/jacodb-core/src/main/kotlin/org/jacodb/impl/types/Objects.kt index 030392042..8df6ca7bd 100644 --- a/jacodb-core/src/main/kotlin/org/jacodb/impl/types/Objects.kt +++ b/jacodb-core/src/main/kotlin/org/jacodb/impl/types/Objects.kt @@ -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 @@ -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()) + } } diff --git a/jacodb-taint-configuration/src/test/kotlin/org/jacodb/taint/configuration/ConfigurationTest.kt b/jacodb-taint-configuration/src/test/kotlin/org/jacodb/taint/configuration/ConfigurationTest.kt index c29ecd096..a12f6973b 100644 --- a/jacodb-taint-configuration/src/test/kotlin/org/jacodb/taint/configuration/ConfigurationTest.kt +++ b/jacodb-taint-configuration/src/test/kotlin/org/jacodb/taint/configuration/ConfigurationTest.kt @@ -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 = "" )