From 1c6a543c46ca69057638bb410f4b141057be9df9 Mon Sep 17 00:00:00 2001 From: Alexey Volkov Date: Wed, 29 Nov 2023 16:49:35 +0300 Subject: [PATCH] add access to `JcDatabase#features` --- .../src/main/kotlin/org/jacodb/api/Api.kt | 4 +++- .../org/jacodb/impl/FeaturesRegistry.kt | 20 +++++-------------- .../kotlin/org/jacodb/impl/JcDatabaseImpl.kt | 5 ++--- .../java/org/jacodb/testing/JavaApiTest.java | 1 + 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/jacodb-api/src/main/kotlin/org/jacodb/api/Api.kt b/jacodb-api/src/main/kotlin/org/jacodb/api/Api.kt index 67c444080..bd3210a75 100644 --- a/jacodb-api/src/main/kotlin/org/jacodb/api/Api.kt +++ b/jacodb-api/src/main/kotlin/org/jacodb/api/Api.kt @@ -132,7 +132,9 @@ interface JcDatabase : Closeable { suspend fun awaitBackgroundJobs() fun asyncAwaitBackgroundJobs() = GlobalScope.future { awaitBackgroundJobs() } - fun isInstalled(feature: JcFeature<*, *>): Boolean + fun isInstalled(feature: JcFeature<*, *>): Boolean = features.contains(feature) + + val features: List> } diff --git a/jacodb-core/src/main/kotlin/org/jacodb/impl/FeaturesRegistry.kt b/jacodb-core/src/main/kotlin/org/jacodb/impl/FeaturesRegistry.kt index d068abceb..22db2b246 100644 --- a/jacodb-core/src/main/kotlin/org/jacodb/impl/FeaturesRegistry.kt +++ b/jacodb-core/src/main/kotlin/org/jacodb/impl/FeaturesRegistry.kt @@ -16,16 +16,14 @@ package org.jacodb.impl -import org.jacodb.api.ByteCodeIndexer -import org.jacodb.api.ClassSource -import org.jacodb.api.JcDatabase -import org.jacodb.api.JcFeature -import org.jacodb.api.JcSignal -import org.jacodb.api.RegisteredLocation +import kotlinx.collections.immutable.toPersistentList +import org.jacodb.api.* import org.jacodb.impl.fs.fullAsmNode import java.io.Closeable -class FeaturesRegistry(private val features: List>) : Closeable { +class FeaturesRegistry(features: List>) : Closeable { + + val features = features.toPersistentList() private lateinit var jcdb: JcDatabase @@ -33,10 +31,6 @@ class FeaturesRegistry(private val features: List>) : Closeable this.jcdb = jcdb } - fun has(feature: JcFeature<*, *>): Boolean { - return features.contains(feature) - } - fun index(location: RegisteredLocation, classes: List) { features.forEach { feature -> feature.index(location, classes) @@ -58,10 +52,6 @@ class FeaturesRegistry(private val features: List>) : Closeable features.forEach { it.onSignal(signal.asJcSignal(jcdb)) } } - fun forEach(action: (JcDatabase, JcFeature<*, *>) -> Unit) { - features.forEach { action(jcdb, it) } - } - override fun close() { } diff --git a/jacodb-core/src/main/kotlin/org/jacodb/impl/JcDatabaseImpl.kt b/jacodb-core/src/main/kotlin/org/jacodb/impl/JcDatabaseImpl.kt index 033d16ab7..75de75e21 100644 --- a/jacodb-core/src/main/kotlin/org/jacodb/impl/JcDatabaseImpl.kt +++ b/jacodb-core/src/main/kotlin/org/jacodb/impl/JcDatabaseImpl.kt @@ -197,9 +197,8 @@ class JcDatabaseImpl( backgroundJobs.values.joinAll() } - override fun isInstalled(feature: JcFeature<*, *>): Boolean { - return featureRegistry.has(feature) - } + override val features: List> + get() = featureRegistry.features suspend fun afterStart() { hooks.forEach { it.afterStart() } diff --git a/jacodb-core/src/test/java/org/jacodb/testing/JavaApiTest.java b/jacodb-core/src/test/java/org/jacodb/testing/JavaApiTest.java index 60b3d2fb2..335fbc3c3 100644 --- a/jacodb-core/src/test/java/org/jacodb/testing/JavaApiTest.java +++ b/jacodb-core/src/test/java/org/jacodb/testing/JavaApiTest.java @@ -72,5 +72,6 @@ public void jcdbOperations() throws ExecutionException, InterruptedException, IO System.out.println("asyncRebuildFeatures finished"); instance.asyncAwaitBackgroundJobs().get(); System.out.println("asyncAwaitBackgroundJobs finished"); + instance.getFeatures(); } }