fix: finalize indexing API; remove api versions index

This commit is contained in:
Akash Yadav
2024-06-23 08:27:30 +05:30
parent 8e3b9efa30
commit b9389cec2b
20 changed files with 96 additions and 183 deletions
+1
View File
@@ -116,6 +116,7 @@
<module name="AndroidIDE.colorschemes" target="11" />
<module name="AndroidIDE.colorschemes.main" target="11" />
<module name="AndroidIDE.common" target="17" />
<module name="AndroidIDE.core.di" target="17" />
<module name="AndroidIDE.core.indexing" target="17" />
<module name="AndroidIDE.editor-api" target="17" />
<module name="AndroidIDE.editor-languages" target="11" />
+1
View File
@@ -87,6 +87,7 @@ dependencies {
implementation(libs.common.retrofit.gson)
implementation(libs.common.charts)
implementation(libs.common.hiddenApiBypass)
implementation(libs.aapt2.common)
implementation(libs.google.auto.service.annotations)
implementation(libs.google.gson)
@@ -15,12 +15,12 @@
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
*/
package com.itsaky.androidide.indexing.core.internal.platform
package com.itsaky.androidide.indexing.platform
import com.google.auto.service.AutoService
import com.itsaky.androidide.indexing.IIndexService
import com.itsaky.androidide.progress.IProgressIndicator
import com.itsaky.androidide.projects.api.Project
import org.slf4j.LoggerFactory
import java.io.File
/**
@@ -29,19 +29,26 @@ import java.io.File
@AutoService(IIndexService::class)
internal class PlatformIndexService : IIndexService {
companion object {
private val log = LoggerFactory.getLogger(PlatformIndexService::class.java)
}
override val displayName: String
get() = "Android Platform Indexing Service"
override fun scanFiles(project: Project): Collection<File> {
return mutableListOf<File>().apply {
project.findAndroidModules().forEach { androidModule ->
add(androidModule.getPlatformDir() ?: return@forEach)
add(androidModule.getPlatformDir()?.also {
log.debug("Adding {} to the list of indexable paths", it)
} ?: return@forEach)
}
}
}
override suspend fun indexFiles(
project: Project,
progress: IProgressIndicator,
files: Collection<File>
) {
TODO("Not yet implemented")
}
}
@@ -33,7 +33,6 @@ import com.itsaky.androidide.projects.api.AndroidModule
import com.itsaky.androidide.projects.api.ModuleProject
import com.itsaky.androidide.projects.api.Project
import com.itsaky.androidide.projects.builder.BuildService
import com.itsaky.androidide.projects.util.ProjectTransformer
import com.itsaky.androidide.tasks.executeAsync
import com.itsaky.androidide.tooling.api.IAndroidProject
import com.itsaky.androidide.tooling.api.IProject
@@ -15,7 +15,7 @@
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
*/
package com.itsaky.androidide.projects.util
package com.itsaky.androidide.projects
import com.itsaky.androidide.projects.api.AndroidModule
import com.itsaky.androidide.projects.api.GradleProject
@@ -25,9 +25,9 @@ import io.realm.Realm
* @property params The index parameters.
* @author Akash Yadav
*/
abstract class AbstractDBIndex<T : IIndexable, C : IIndexParams>(
abstract class AbstractDBIndex<T : IIndexable>(
protected val params: IIndexParams?
) : IIndex<T, C> {
) : IDatabaseIndex<T> {
protected abstract val realm: Realm
@@ -15,20 +15,19 @@
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
*/
package com.itsaky.androidide.indexing.core.platform
package com.itsaky.androidide.indexing
import com.itsaky.androidide.indexing.IIndexParams
import com.itsaky.androidide.indexing.core.platform.IApiVersionsIndex.Params
import io.realm.RealmQuery
/**
* Index which provides access to the API versions informations (`api-versions.xml`) from the
* Android SDK.
* An index which is stored in the database.
*
* @author Akash Yadav
*/
interface IApiVersionsIndex : IPlatformIndex<ClassOrMemberInfo, Params> {
interface IDatabaseIndex<IndexableT : IIndexable> : IIndex<IndexableT> {
class Params(
val platformId: String
) : IIndexParams
/**
* Perform a query on the Realm database.
*/
fun query(): RealmQuery<IndexableT>
}
@@ -24,7 +24,7 @@ import com.itsaky.androidide.db.IRealmProvider
*
* @author Akash Yadav
*/
interface IIndex<IndexableT : IIndexable, ConfigT : IIndexParams> {
interface IIndex<IndexableT : IIndexable> {
companion object {
@@ -36,7 +36,7 @@ interface IIndex<IndexableT : IIndexable, ConfigT : IIndexParams> {
/**
* Base path for indices.
*/
const val INDEX_BASE_PATH = "${IRealmProvider.PATH_SEPARATOR}index"
val INDEX_BASE_PATH = createIndexPath("", "index")
private const val DEF_IS_ASYNC = true
@@ -91,9 +91,9 @@ interface IIndex<IndexableT : IIndexable, ConfigT : IIndexParams> {
*
* @return The created sub-index.
*/
fun <I : IIndexable, C : IIndexParams> createSubIndex(
fun <I : IIndexable> createSubIndex(
params: IIndexParams? = null
): IIndex<I, C> {
): IIndex<I> {
throw UnsupportedOperationException()
}
@@ -49,7 +49,7 @@ interface IIndexFactory<I : IIndexable, P : IIndexParams> {
* @return The created [IIndex].
*/
@Throws(NotFoundException::class)
fun create(): IIndex<I, P>
fun create(): IIndex<I>
companion object {
@@ -99,10 +99,10 @@ interface IIndexFactory<I : IIndexable, P : IIndexParams> {
return factory
}
val impls = ServiceLoader.load(symTyp).iterator()
val impls = ServiceLoader.load(IIndexFactory::class.java).iterator()
while (impls.hasNext()) {
val impl = impls.next()
if (impl is IIndexFactory<*, *> && symTyp == impl.indexableType()) {
if (symTyp == impl.indexableType()) {
if (factory == null) {
factory = impl as IIndexFactory<T, P>
continue
@@ -18,7 +18,9 @@
package com.itsaky.androidide.indexing
/**
* Index configuration
* Index configuration parameters. All implementations of this interface must implement the
* [Object.equals] and [Object.hashCode] methods properly as the parameters may be used to cache
* the index implementations in [IIndexFactory]s.
*
* @author Akash Yadav
*/
@@ -17,7 +17,6 @@
package com.itsaky.androidide.indexing
import com.itsaky.androidide.progress.IProgressIndicator
import com.itsaky.androidide.projects.api.Project
import kotlinx.coroutines.Deferred
import java.io.File
@@ -29,6 +28,11 @@ import java.io.File
*/
interface IIndexService {
/**
* The display name of the service.
*/
val displayName: String
/**
* Called to scan files that need to be indexed by this index service.
*
@@ -41,8 +45,7 @@ interface IIndexService {
* Called to index the given files.
*
* @param project The root project model which can be used to query the project properties.
* @param progress An [IProgressIndicator] to report progress of the indexing process.
* @param files The files to index.
*/
suspend fun indexFiles(project: Project, progress: IProgressIndicator, files: Collection<File>)
suspend fun indexFiles(project: Project, files: Collection<File>)
}
@@ -24,5 +24,4 @@ import io.realm.RealmModel
*
* @author Akash Yadav
*/
interface IIndexable : RealmModel {
}
interface IIndexable : RealmModel
@@ -0,0 +1,26 @@
/*
* This file is part of AndroidIDE.
*
* AndroidIDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AndroidIDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
*/
package com.itsaky.androidide.indexing.core
import io.realm.annotations.RealmModule
/**
* @author Akash Yadav
*/
@RealmModule(classes = [])
class IndexingCoreRealmModule
@@ -1,44 +0,0 @@
/*
* This file is part of AndroidIDE.
*
* AndroidIDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AndroidIDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
*/
package com.itsaky.androidide.indexing.core.internal.platform
import com.google.auto.service.AutoService
import com.itsaky.androidide.indexing.IIndex
import com.itsaky.androidide.indexing.IIndexFactory
import com.itsaky.androidide.indexing.core.platform.AbstractIndexFactory
import com.itsaky.androidide.indexing.core.platform.ClassOrMemberInfo
import com.itsaky.androidide.indexing.core.platform.IApiVersionsIndex.Params
/**
* @author Akash Yadav
*/
@AutoService(IIndexFactory::class)
internal class ApiVersionsIndexFactory : AbstractIndexFactory<ClassOrMemberInfo, Params>() {
override fun indexableType(): Class<ClassOrMemberInfo> {
return ClassOrMemberInfo::class.java
}
override fun paramType(): Class<out Params> {
return Params::class.java
}
override fun create(): IIndex<ClassOrMemberInfo, Params> {
return ApiVersionsIndexImpl.newInstance(params)
}
}
@@ -1,51 +0,0 @@
/*
* This file is part of AndroidIDE.
*
* AndroidIDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AndroidIDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
*/
package com.itsaky.androidide.indexing.core.internal.platform
import com.itsaky.androidide.db.IRealmProvider
import com.itsaky.androidide.indexing.AbstractDBIndex
import com.itsaky.androidide.indexing.core.platform.ClassOrMemberInfo
import com.itsaky.androidide.indexing.core.platform.IApiVersionsIndex
import com.itsaky.androidide.indexing.core.platform.IPlatformIndex
import io.realm.Realm
/**
* Index to store [ClassOrMemberInfo].
*
* @author Akash Yadav
*/
internal class ApiVersionsIndexImpl private constructor(params: IApiVersionsIndex.Params?) :
AbstractDBIndex<ClassOrMemberInfo, IApiVersionsIndex.Params>(params),
IApiVersionsIndex {
companion object {
private const val NAME = "member-info"
private val PATH = IRealmProvider.createPath(IPlatformIndex.PLATFORM_INDEX_BASE_PATH, NAME)
@JvmStatic
fun newInstance(params: IApiVersionsIndex.Params?) = ApiVersionsIndexImpl(params)
}
override val name: String = NAME
override val path: String = PATH
override val realm: Realm by lazy {
val provider = IRealmProvider.instance()
provider.get(path)
}
}
@@ -70,8 +70,15 @@ open class ApiVersionsParser {
consumeEndElement(event.asEndElement())
}
}
onFinishParse()
}
/**
* Called when the parser is done parsing the `api-versions.xml` file.
*/
protected open fun onFinishParse() {}
private fun consumeStartElement(event: StartElement) {
when (event.name.localPart) {
"api" -> apiVersion = event.getAttributeByName(QName("version")).value.toInt()
@@ -110,6 +117,12 @@ open class ApiVersionsParser {
return false
}
/**
* Consume [ApiVersion] info of a class.
*
* @param name The fully qualified name of the class in its internal form.
* @param apiVersion The [ApiVersion] info of the class.
*/
protected open fun consumeClassVersionInfo(name: String, apiVersion: ApiVersion) {}
private fun consumeMember(event: StartElement, memberType: String) {
@@ -130,6 +143,14 @@ open class ApiVersionsParser {
return false
}
/**
* Consume [ApiVersion] info for a member of a class.
*
* @param className The name of the class which declares this member.
* @param member The identifier of the member. This is the name of the field and the method signature for methods.
* @param memberType The type of member. This may be "field" or "method".
* @param apiVersion The [ApiVersion] info.
*/
protected open fun consumeMemberVersionInfo(
className: String,
member: String,
@@ -1,49 +0,0 @@
/*
* This file is part of AndroidIDE.
*
* AndroidIDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AndroidIDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
*/
package com.itsaky.androidide.indexing.core.platform
import io.realm.annotations.RealmField
import io.realm.annotations.Required
/**
* [ApiVersion] of a class or class members.
*
* @property className The fully qualified name of the class.
* @property memberName The name of the member (optional). Must be set if the objects represents API
* information about a member of a class. Otherwise, it could be `null`.
* @property apiVersion The [ApiVersion] about the class or the member.
*
* @author Akash Yadav
*/
open class ClassOrMemberInfo : IPlatformIndexable {
@Required
@RealmField("className")
var className: String? = null
@Required
@RealmField("memberName")
var memberName: String? = null
@Required
@RealmField("apiVersion")
var apiVersion: ApiVersion? = null
fun isMember(): Boolean = !isClass()
fun isClass(): Boolean = this.memberName == null
}
@@ -17,22 +17,20 @@
package com.itsaky.androidide.indexing.core.platform
import com.itsaky.androidide.db.IRealmProvider
import com.itsaky.androidide.indexing.IIndex
import com.itsaky.androidide.indexing.IIndexParams
/**
* Index for data available in the Android Platform SDK.
*
* @author Akash Yadav
*/
interface IPlatformIndex<T : IPlatformIndexable, C : IIndexParams> : IIndex<T, C> {
interface IPlatformIndex<T : IPlatformIndexable> : IIndex<T> {
companion object {
/**
* Base path for the platform index.
*/
val PLATFORM_INDEX_BASE_PATH = IRealmProvider.createPath(IIndex.INDEX_BASE_PATH, "platform")
val PLATFORM_INDEX_BASE_PATH = IIndex.createIndexPath(IIndex.INDEX_BASE_PATH, "platform")
}
}
@@ -17,12 +17,12 @@
package com.itsaky.androidide.indexing.core.platform
import com.itsaky.androidide.indexing.core.internal.platform.ApiVersionsParser
import com.itsaky.androidide.indexing.platform.ApiVersionsParser
/**
* @author Akash Yadav
*/
class CollectingApiVersionsParser : ApiVersionsParser() {
class CollectingApiVersionsParser : com.itsaky.androidide.indexing.platform.ApiVersionsParser() {
private val apiInfo = mutableMapOf<String, Pair<ApiVersion, MutableMap<String, ApiVersion>>>()
@@ -19,7 +19,6 @@ package com.itsaky.androidide.lsp.java.indexing.internal
import com.google.auto.service.AutoService
import com.itsaky.androidide.indexing.IIndexService
import com.itsaky.androidide.progress.IProgressIndicator
import com.itsaky.androidide.projects.api.Project
import java.io.File
@@ -29,13 +28,15 @@ import java.io.File
@AutoService(IIndexService::class)
internal class JavaIndexServiceImpl : IIndexService {
override val displayName: String
get() = "Java LSP Indexing Service"
override fun scanFiles(project: Project): Collection<File> {
return emptySet()
}
override suspend fun indexFiles(
project: Project,
progress: IProgressIndicator,
files: Collection<File>
) {
}