Skip to content

Commit 1c6a543

Browse files
committed
add access to JcDatabase#features
1 parent b01fdc7 commit 1c6a543

File tree

4 files changed

+11
-19
lines changed

4 files changed

+11
-19
lines changed

jacodb-api/src/main/kotlin/org/jacodb/api/Api.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ interface JcDatabase : Closeable {
132132
suspend fun awaitBackgroundJobs()
133133
fun asyncAwaitBackgroundJobs() = GlobalScope.future { awaitBackgroundJobs() }
134134

135-
fun isInstalled(feature: JcFeature<*, *>): Boolean
135+
fun isInstalled(feature: JcFeature<*, *>): Boolean = features.contains(feature)
136+
137+
val features: List<JcFeature<*, *>>
136138
}
137139

138140

jacodb-core/src/main/kotlin/org/jacodb/impl/FeaturesRegistry.kt

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,21 @@
1616

1717
package org.jacodb.impl
1818

19-
import org.jacodb.api.ByteCodeIndexer
20-
import org.jacodb.api.ClassSource
21-
import org.jacodb.api.JcDatabase
22-
import org.jacodb.api.JcFeature
23-
import org.jacodb.api.JcSignal
24-
import org.jacodb.api.RegisteredLocation
19+
import kotlinx.collections.immutable.toPersistentList
20+
import org.jacodb.api.*
2521
import org.jacodb.impl.fs.fullAsmNode
2622
import java.io.Closeable
2723

28-
class FeaturesRegistry(private val features: List<JcFeature<*, *>>) : Closeable {
24+
class FeaturesRegistry(features: List<JcFeature<*, *>>) : Closeable {
25+
26+
val features = features.toPersistentList()
2927

3028
private lateinit var jcdb: JcDatabase
3129

3230
fun bind(jcdb: JcDatabase) {
3331
this.jcdb = jcdb
3432
}
3533

36-
fun has(feature: JcFeature<*, *>): Boolean {
37-
return features.contains(feature)
38-
}
39-
4034
fun index(location: RegisteredLocation, classes: List<ClassSource>) {
4135
features.forEach { feature ->
4236
feature.index(location, classes)
@@ -58,10 +52,6 @@ class FeaturesRegistry(private val features: List<JcFeature<*, *>>) : Closeable
5852
features.forEach { it.onSignal(signal.asJcSignal(jcdb)) }
5953
}
6054

61-
fun forEach(action: (JcDatabase, JcFeature<*, *>) -> Unit) {
62-
features.forEach { action(jcdb, it) }
63-
}
64-
6555
override fun close() {
6656
}
6757

jacodb-core/src/main/kotlin/org/jacodb/impl/JcDatabaseImpl.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,8 @@ class JcDatabaseImpl(
197197
backgroundJobs.values.joinAll()
198198
}
199199

200-
override fun isInstalled(feature: JcFeature<*, *>): Boolean {
201-
return featureRegistry.has(feature)
202-
}
200+
override val features: List<JcFeature<*, *>>
201+
get() = featureRegistry.features
203202

204203
suspend fun afterStart() {
205204
hooks.forEach { it.afterStart() }

jacodb-core/src/test/java/org/jacodb/testing/JavaApiTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,6 @@ public void jcdbOperations() throws ExecutionException, InterruptedException, IO
7272
System.out.println("asyncRebuildFeatures finished");
7373
instance.asyncAwaitBackgroundJobs().get();
7474
System.out.println("asyncAwaitBackgroundJobs finished");
75+
instance.getFeatures();
7576
}
7677
}

0 commit comments

Comments
 (0)