Skip to content

Commit

Permalink
Add fully qualified method name API #198
Browse files Browse the repository at this point in the history
  • Loading branch information
lehvolk committed Nov 7, 2023
1 parent ab7e772 commit e107169
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 44 deletions.
2 changes: 1 addition & 1 deletion jacodb-api/src/main/kotlin/org/jacodb/api/ext/JcMethods.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ val JcMethod.jcdbSignature: String
val JcMethod.humanReadableSignature: String
get() {
val params = parameters.joinToString(",") { it.type.typeName }
return "${returnType.typeName} $name($params)"
return "${enclosingClass.name}#$name($params):${returnType.typeName}"
}

@get:JvmName("hasBody")
Expand Down
7 changes: 7 additions & 0 deletions jacodb-api/src/main/kotlin/org/jacodb/api/ext/JcTypes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,10 @@ fun JcClassType.findMethodOrNull(predicate: (JcTypedMethod) -> kotlin.Boolean):
return methods.firstOrNull(predicate)
}

val JcTypedMethod.humanReadableSignature: String get() {
val params = parameters.joinToString(",") { it.type.typeName }
val generics = typeParameters.takeIf { it.isNotEmpty() }?.let{
it.joinToString(prefix = "<", separator = ",", postfix = ">") { it.symbol }
} ?: ""
return "${enclosingType.typeName}#$generics$name($params):${returnType.typeName}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ data class AppVersion(val major: Int, val minor: Int) : Comparable<AppVersion> {

class PersistenceService(private val persistence: AbstractJcDatabasePersistenceImpl) {

companion object : KLogging()
companion object : KLogging() {

private val defaultVersion = AppVersion(1, 3)

}

private val refactorings = JcRefactoringChain(
listOf(
Expand All @@ -98,12 +102,18 @@ class PersistenceService(private val persistence: AbstractJcDatabasePersistenceI
persistence.read {
logger.info("Starting app version $currentAppVersion")
version = try {
val appVersion = it.selectFrom(APPLICATIONMETADATA).fetch().first()
logger.info("Restored app version is ${appVersion.version}")
AppVersion.parse(appVersion.version!!)
val appVersion = it.selectFrom(APPLICATIONMETADATA).fetch().firstOrNull()
if (appVersion != null) {
logger.info("Restored app version is ${appVersion.version}")
AppVersion.parse(appVersion.version!!)

Check warning on line 108 in jacodb-core/src/main/kotlin/org/jacodb/impl/storage/PersistenceService.kt

View check run for this annotation

Codecov / codecov/patch

jacodb-core/src/main/kotlin/org/jacodb/impl/storage/PersistenceService.kt#L107-L108

Added lines #L107 - L108 were not covered by tests
} else {
// this is startup on empty database
// there is no records in AppMetadata table
currentAppVersion
}
} catch (e: Exception) {
logger.info("fail to restore app version. Use [1.3] as fallback")
AppVersion(1, 3)
logger.info("fail to restore app version. Use [$defaultVersion] as fallback")

Check warning on line 115 in jacodb-core/src/main/kotlin/org/jacodb/impl/storage/PersistenceService.kt

View check run for this annotation

Codecov / codecov/patch

jacodb-core/src/main/kotlin/org/jacodb/impl/storage/PersistenceService.kt#L115

Added line #L115 was not covered by tests
defaultVersion
}
classIdGen.set(CLASSES.ID.maxId ?: 0)
symbolsIdGen.set(SYMBOLS.ID.maxId ?: 0)
Expand Down
10 changes: 10 additions & 0 deletions jacodb-core/src/test/kotlin/org/jacodb/testing/types/TypesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.jacodb.api.JcPrimitiveType
import org.jacodb.api.JcTypeVariable
import org.jacodb.api.ext.findClass
import org.jacodb.api.ext.findMethodOrNull
import org.jacodb.api.ext.humanReadableSignature
import org.jacodb.api.ext.toType
import org.jacodb.impl.types.JcClassTypeImpl
import org.jacodb.impl.types.signature.JvmClassRefType
Expand Down Expand Up @@ -137,6 +138,15 @@ class TypesTest : BaseTypesTest() {
assertNotEquals(objectList.iterator, stringList1.iterator)
}

@Test
fun `humanReadableSignature should work`() {
val type = listType<String>()
assertEquals(
"java.util.List<java.lang.String>#isEmpty():boolean",
type.declaredMethods.first { it.name == "isEmpty" }.humanReadableSignature
)
}

private inline fun <reified T> listType(raw: Boolean = false): JcClassType {
val elementName = T::class.java.name
return JcClassTypeImpl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,53 +21,22 @@ import org.jacodb.api.JcClassOrInterface
import org.jacodb.api.JcClassProcessingTask
import org.jacodb.api.JcClasspath
import org.jacodb.api.PredefinedPrimitives
import org.jacodb.api.ext.HierarchyExtension
import org.jacodb.api.ext.constructors
import org.jacodb.api.ext.enumValues
import org.jacodb.api.ext.fields
import org.jacodb.api.ext.findClass
import org.jacodb.api.ext.findClassOrNull
import org.jacodb.api.ext.findDeclaredFieldOrNull
import org.jacodb.api.ext.findDeclaredMethodOrNull
import org.jacodb.api.ext.findMethodOrNull
import org.jacodb.api.ext.hasBody
import org.jacodb.api.ext.humanReadableSignature
import org.jacodb.api.ext.isEnum
import org.jacodb.api.ext.isLocal
import org.jacodb.api.ext.isMemberClass
import org.jacodb.api.ext.isNullable
import org.jacodb.api.ext.jcdbSignature
import org.jacodb.api.ext.jvmSignature
import org.jacodb.api.ext.methods
import org.jacodb.api.ext.toType
import org.jacodb.api.ext.*
import org.jacodb.impl.features.classpaths.ClasspathCache
import org.jacodb.impl.features.classpaths.VirtualClassContent
import org.jacodb.impl.features.classpaths.VirtualClasses
import org.jacodb.impl.features.classpaths.virtual.JcVirtualClass
import org.jacodb.impl.features.classpaths.virtual.JcVirtualField
import org.jacodb.impl.features.classpaths.virtual.JcVirtualMethod
import org.jacodb.testing.A
import org.jacodb.testing.B
import org.jacodb.testing.Bar
import org.jacodb.testing.C
import org.jacodb.testing.D
import org.jacodb.testing.Enums
import org.jacodb.testing.Foo
import org.jacodb.testing.SuperDuper
import org.jacodb.testing.allClasspath
import org.jacodb.testing.*
import org.jacodb.testing.hierarchies.Creature
import org.jacodb.testing.skipAssertionsOn
import org.jacodb.testing.structure.FieldsAndMethods
import org.jacodb.testing.structure.HiddenFieldSuperClass.HiddenFieldSuccClass
import org.jacodb.testing.usages.Generics
import org.jacodb.testing.usages.HelloWorldAnonymousClasses
import org.jacodb.testing.usages.WithInner
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.JRE
Expand Down Expand Up @@ -224,7 +193,7 @@ abstract class DatabaseEnvTest {
assertEquals(DocumentType::class.java.name, returnType.typeName)
assertEquals("getDoctype()org.w3c.dom.DocumentType;", jcdbSignature)
assertEquals("getDoctype()Lorg/w3c/dom/DocumentType;", jvmSignature)
assertEquals("org.w3c.dom.DocumentType getDoctype()", humanReadableSignature)
assertEquals("org.w3c.dom.Document#getDoctype():org.w3c.dom.DocumentType", humanReadableSignature)
assertTrue(isPublic)
}

Expand All @@ -233,12 +202,12 @@ abstract class DatabaseEnvTest {
assertEquals(Element::class.java.name, returnType.typeName)
assertEquals("createElement(java.lang.String;)org.w3c.dom.Element;", jcdbSignature)
assertEquals("createElement(Ljava/lang/String;)Lorg/w3c/dom/Element;", jvmSignature)
assertEquals("org.w3c.dom.Element createElement(java.lang.String)", humanReadableSignature)
assertEquals("org.w3c.dom.Document#createElement(java.lang.String):org.w3c.dom.Element", humanReadableSignature)
}

with(methods.first { it.name == "importNode" }) {
assertEquals("importNode(org.w3c.dom.Node;boolean;)org.w3c.dom.Node;", jcdbSignature)
assertEquals("org.w3c.dom.Node importNode(org.w3c.dom.Node,boolean)", humanReadableSignature)
assertEquals("org.w3c.dom.Document#importNode(org.w3c.dom.Node,boolean):org.w3c.dom.Node", humanReadableSignature)
}
}

Expand Down

0 comments on commit e107169

Please sign in to comment.