mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
refactor(lookup): use ServiceLoader to load DefaultLookup
This commit is contained in:
Generated
+2
-1
@@ -1,3 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ANTLRGenerationPreferences">
|
||||
<option name="perGrammarGenerationSettings">
|
||||
@@ -214,7 +215,7 @@
|
||||
</value>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
||||
Vendored
+2
@@ -28,6 +28,8 @@
|
||||
-keep class org.xml.** { *; }
|
||||
|
||||
# Services
|
||||
-keep @com.google.auto.service.AutoService class ** {
|
||||
}
|
||||
-keepclassmembers class ** {
|
||||
@com.google.auto.service.AutoService <methods>;
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -34,7 +34,7 @@ abstract class BaseBuildAction : EditorActivityAction() {
|
||||
|
||||
protected val log: ILogger = ILogger.newInstance(javaClass.simpleName)
|
||||
protected val buildService: BuildService?
|
||||
get() = Lookup.DEFAULT.lookup(BuildService.KEY_BUILD_SERVICE)
|
||||
get() = Lookup.getDefault().lookup(BuildService.KEY_BUILD_SERVICE)
|
||||
|
||||
override fun prepare(data: ActionData) {
|
||||
val context = data.getActivity()
|
||||
|
||||
@@ -48,7 +48,7 @@ class CancelBuildAction(context: Context) : EditorActivityAction() {
|
||||
}
|
||||
|
||||
val context = data.getActivity()
|
||||
val buildService = Lookup.DEFAULT.lookup(BuildService.KEY_BUILD_SERVICE)
|
||||
val buildService = Lookup.getDefault().lookup(BuildService.KEY_BUILD_SERVICE)
|
||||
if (context == null || buildService == null) {
|
||||
markInvisible()
|
||||
return
|
||||
@@ -60,7 +60,7 @@ class CancelBuildAction(context: Context) : EditorActivityAction() {
|
||||
|
||||
override fun execAction(data: ActionData): Boolean {
|
||||
log.info("Sending build cancellation request...")
|
||||
val builder = Lookup.DEFAULT.lookup(BuildService.KEY_BUILD_SERVICE)
|
||||
val builder = Lookup.getDefault().lookup(BuildService.KEY_BUILD_SERVICE)
|
||||
if (builder?.isToolingServerStarted() != true) {
|
||||
flashError(com.itsaky.androidide.projects.R.string.msg_tooling_server_unavailable)
|
||||
return false
|
||||
|
||||
@@ -178,7 +178,7 @@ abstract class BaseEditorActivity :
|
||||
|
||||
protected open fun postDestroy() {
|
||||
if (isDestroying) {
|
||||
Lookup.DEFAULT.unregisterAll()
|
||||
Lookup.getDefault().unregisterAll()
|
||||
ApiVersionsRegistry.getInstance().clear()
|
||||
ResourceTableRegistry.getInstance().clear()
|
||||
WidgetTableRegistry.getInstance().clear()
|
||||
@@ -392,7 +392,7 @@ abstract class BaseEditorActivity :
|
||||
}
|
||||
|
||||
fun notifySyncNeeded(onConfirm: () -> Unit) {
|
||||
val buildService = Lookup.DEFAULT.lookup(BuildService.KEY_BUILD_SERVICE)
|
||||
val buildService = Lookup.getDefault().lookup(BuildService.KEY_BUILD_SERVICE)
|
||||
if (buildService == null || buildService.isBuildInProgress) return
|
||||
|
||||
flashbarBuilder(
|
||||
|
||||
@@ -162,9 +162,9 @@ abstract class ProjectHandlerActivity : BaseEditorActivity(), IProjectHandler {
|
||||
} catch (err: Throwable) {
|
||||
log.error("Unable to unbind service")
|
||||
} finally {
|
||||
(Lookup.DEFAULT.lookup(BuildService.KEY_BUILD_SERVICE) as? GradleBuildService?)
|
||||
(Lookup.getDefault().lookup(BuildService.KEY_BUILD_SERVICE) as? GradleBuildService?)
|
||||
?.setEventListener(null)
|
||||
Lookup.DEFAULT.unregister(BuildService.KEY_BUILD_SERVICE)
|
||||
Lookup.getDefault().unregister(BuildService.KEY_BUILD_SERVICE)
|
||||
viewModel.isBoundToBuildSerice = false
|
||||
}
|
||||
}
|
||||
@@ -183,7 +183,7 @@ abstract class ProjectHandlerActivity : BaseEditorActivity(), IProjectHandler {
|
||||
}
|
||||
|
||||
override fun startServices() {
|
||||
val service = Lookup.DEFAULT.lookup(BuildService.KEY_BUILD_SERVICE) as GradleBuildService?
|
||||
val service = Lookup.getDefault().lookup(BuildService.KEY_BUILD_SERVICE) as GradleBuildService?
|
||||
if (viewModel.isBoundToBuildSerice && service != null) {
|
||||
log.info("Reusing already started Gradle build service")
|
||||
onGradleBuildServiceConnected(service)
|
||||
@@ -228,7 +228,7 @@ abstract class ProjectHandlerActivity : BaseEditorActivity(), IProjectHandler {
|
||||
//noinspection ConstantConditions
|
||||
ThreadUtils.runOnUiThread { preProjectInit() }
|
||||
|
||||
val buildService = Lookup.DEFAULT.lookup(BuildService.KEY_BUILD_SERVICE)
|
||||
val buildService = Lookup.getDefault().lookup(BuildService.KEY_BUILD_SERVICE)
|
||||
if (buildService == null) {
|
||||
log.error("No build service found. Cannot initialize project.")
|
||||
return
|
||||
@@ -268,7 +268,7 @@ abstract class ProjectHandlerActivity : BaseEditorActivity(), IProjectHandler {
|
||||
|
||||
private fun releaseServerListener() {
|
||||
// Release reference to server listener in order to prevent memory leak
|
||||
(Lookup.DEFAULT.lookup(BuildService.KEY_BUILD_SERVICE) as? GradleBuildService?)
|
||||
(Lookup.getDefault().lookup(BuildService.KEY_BUILD_SERVICE) as? GradleBuildService?)
|
||||
?.setServerListener(null)
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ abstract class ProjectHandlerActivity : BaseEditorActivity(), IProjectHandler {
|
||||
|
||||
buildServiceConnection.onConnected = null
|
||||
viewModel.isBoundToBuildSerice = true
|
||||
Lookup.DEFAULT.update(BuildService.KEY_BUILD_SERVICE, service)
|
||||
Lookup.getDefault().update(BuildService.KEY_BUILD_SERVICE, service)
|
||||
service.setEventListener(mBuildEventListener)
|
||||
|
||||
if (!service.isToolingServerStarted()) {
|
||||
|
||||
@@ -157,7 +157,7 @@ class RunTasksDialogFragment : BottomSheetDialogFragment() {
|
||||
|
||||
if (viewModel.displayedChild == CHILD_CONFIRMATION) {
|
||||
val buildService =
|
||||
Lookup.DEFAULT.lookup(BuildService.KEY_BUILD_SERVICE)
|
||||
Lookup.getDefault().lookup(BuildService.KEY_BUILD_SERVICE)
|
||||
?: run {
|
||||
log.error("Cannot find build service")
|
||||
return@setOnClickListener
|
||||
|
||||
@@ -15,11 +15,9 @@
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.androidide.lookup.internal;
|
||||
|
||||
import com.itsaky.androidide.lookup.Lookup;
|
||||
import com.itsaky.androidide.lookup.ServiceRegisteredException;
|
||||
package com.itsaky.androidide.lookup;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -31,15 +29,12 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
*
|
||||
* @author Akash Yadav
|
||||
*/
|
||||
@AutoService(Lookup.class)
|
||||
public final class DefaultLookup implements Lookup {
|
||||
|
||||
public static final Lookup INSTANCE = new DefaultLookup();
|
||||
|
||||
private final Map<Class<?>, Key<?>> keyTable = new ConcurrentHashMap<>();
|
||||
private final Map<Key<?>, Object> services = new ConcurrentHashMap<>();
|
||||
|
||||
private DefaultLookup() {}
|
||||
|
||||
@Override
|
||||
public <T> void register(final Class<T> klass, final T instance) {
|
||||
final Key<T> key = key(klass);
|
||||
|
||||
@@ -112,7 +112,7 @@ public class GradleBuildService extends Service implements BuildService, IToolin
|
||||
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
showNotification(getString(R.string.build_status_idle), false);
|
||||
|
||||
Lookup.DEFAULT.update(BuildService.KEY_BUILD_SERVICE, this);
|
||||
Lookup.getDefault().update(BuildService.KEY_BUILD_SERVICE, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -215,7 +215,7 @@ public class GradleBuildService extends Service implements BuildService, IToolin
|
||||
public void onListenerStarted(@NotNull final IToolingApiServer server, @NotNull IProject projectProxy, @NotNull final ProcessStreamsHolder streams) {
|
||||
startServerOutputReader(streams.err);
|
||||
this.server = server;
|
||||
Lookup.DEFAULT.update(BuildService.KEY_PROJECT_PROXY, projectProxy);
|
||||
Lookup.getDefault().update(BuildService.KEY_PROJECT_PROXY, projectProxy);
|
||||
this.isToolingServerStarted = true;
|
||||
ProjectManager.INSTANCE.setupProject(projectProxy);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class LogReceiverService : Service() {
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
Lookup.DEFAULT.update(LOOKUP_KEY, this)
|
||||
Lookup.getDefault().update(LOOKUP_KEY, this)
|
||||
}
|
||||
|
||||
override fun onBind(intent: Intent?): IBinder? {
|
||||
@@ -59,7 +59,7 @@ class LogReceiverService : Service() {
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
binder.close()
|
||||
Lookup.DEFAULT.unregister(LOOKUP_KEY)
|
||||
Lookup.getDefault().unregister(LOOKUP_KEY)
|
||||
}
|
||||
|
||||
fun setConsumer(consumer: ((LogLine) -> Unit)?) {
|
||||
@@ -68,5 +68,5 @@ class LogReceiverService : Service() {
|
||||
}
|
||||
|
||||
fun lookupLogService(): LogReceiverService? {
|
||||
return Lookup.DEFAULT.lookup(LogReceiverService.LOOKUP_KEY)
|
||||
return Lookup.getDefault().lookup(LogReceiverService.LOOKUP_KEY)
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ class CompletionListAdapter : EditorCompletionAdapter() {
|
||||
|
||||
val data = item.data
|
||||
val versions =
|
||||
Lookup.DEFAULT.lookup(ApiVersions.COMPLETION_LOOKUP_KEY) ?: return@executeAsync null
|
||||
Lookup.getDefault().lookup(ApiVersions.COMPLETION_LOOKUP_KEY) ?: return@executeAsync null
|
||||
val className =
|
||||
when (data) {
|
||||
is ClassCompletionData -> data.className
|
||||
|
||||
@@ -56,10 +56,10 @@ public abstract class IDELanguage implements Language {
|
||||
throws CompletionCancelledException {
|
||||
try {
|
||||
final var cancelChecker = new CompletionCancelChecker(publisher);
|
||||
Lookup.DEFAULT.register(ICompletionCancelChecker.class, cancelChecker);
|
||||
Lookup.getDefault().register(ICompletionCancelChecker.class, cancelChecker);
|
||||
doComplete(content, position, publisher, extraArguments);
|
||||
} finally {
|
||||
Lookup.DEFAULT.unregister(ICompletionCancelChecker.class);
|
||||
Lookup.getDefault().unregister(ICompletionCancelChecker.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-42
@@ -1,42 +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.logsender
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ExampleInstrumentedTest {
|
||||
|
||||
@Test
|
||||
fun useAppContext() {
|
||||
// Context of the app under test.
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
assertEquals("com.itsaky.androidide.logsender.test", appContext.packageName)
|
||||
}
|
||||
}
|
||||
@@ -19,14 +19,19 @@
|
||||
plugins {
|
||||
id("java-library")
|
||||
id("org.jetbrains.kotlin.jvm")
|
||||
id("kotlin-kapt")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
kapt(libs.google.auto.service)
|
||||
|
||||
implementation(projects.logger)
|
||||
|
||||
implementation(projects.shared)
|
||||
|
||||
implementation(libs.common.jkotlin)
|
||||
implementation(libs.google.auto.service.annotations)
|
||||
implementation(libs.google.guava)
|
||||
|
||||
|
||||
testImplementation(libs.tests.junit)
|
||||
testImplementation(libs.tests.google.truth)
|
||||
}
|
||||
@@ -17,8 +17,6 @@
|
||||
|
||||
package com.itsaky.androidide.lookup;
|
||||
|
||||
import com.itsaky.androidide.lookup.internal.DefaultLookup;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
@@ -28,23 +26,30 @@ import org.jetbrains.annotations.Nullable;
|
||||
*/
|
||||
public interface Lookup {
|
||||
|
||||
Lookup DEFAULT = DefaultLookup.INSTANCE;
|
||||
/**
|
||||
* Get the default implementation of {@link Lookup} service.
|
||||
*
|
||||
* @return The default implementation.
|
||||
*/
|
||||
static Lookup getDefault() {
|
||||
return LookupProvider.lookupService();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service for the given class.
|
||||
*
|
||||
* @param klass The class to register the service for.
|
||||
* @param klass The class to register the service for.
|
||||
* @param instance The implementation of the service.
|
||||
* @param <T> The type of service.
|
||||
* @param <T> The type of service.
|
||||
*/
|
||||
<T> void register(Class<T> klass, T instance);
|
||||
|
||||
/**
|
||||
* Updates the service for the given class. Registers if not already registered.
|
||||
*
|
||||
* @param klass The class to update the service for.
|
||||
* @param klass The class to update the service for.
|
||||
* @param instance The instance of the service.
|
||||
* @param <T> The type of the service.
|
||||
* @param <T> The type of the service.
|
||||
*/
|
||||
<T> void update(Class<T> klass, T instance);
|
||||
|
||||
@@ -52,7 +57,7 @@ public interface Lookup {
|
||||
* Unregister the service for given class.
|
||||
*
|
||||
* @param klass The class of service to unregister.
|
||||
* @param <T> The type of service.
|
||||
* @param <T> The type of service.
|
||||
*/
|
||||
<T> void unregister(Class<T> klass);
|
||||
|
||||
@@ -60,7 +65,7 @@ public interface Lookup {
|
||||
* Lookup the service for the given class.
|
||||
*
|
||||
* @param klass The Class of the service to look for.
|
||||
* @param <T> The type of service.
|
||||
* @param <T> The type of service.
|
||||
* @return The instance of the registered service or <code>null</code>.
|
||||
*/
|
||||
@Nullable
|
||||
@@ -69,9 +74,9 @@ public interface Lookup {
|
||||
/**
|
||||
* Register the service for the given key.
|
||||
*
|
||||
* @param key The class to register the service for.
|
||||
* @param key The class to register the service for.
|
||||
* @param instance The implementation of the service.
|
||||
* @param <T> The type of service.
|
||||
* @param <T> The type of service.
|
||||
*/
|
||||
<T> void register(Key<T> key, T instance);
|
||||
|
||||
@@ -96,13 +101,15 @@ public interface Lookup {
|
||||
/**
|
||||
* Updates the service for the given key. Registers if not already registered.
|
||||
*
|
||||
* @param key The key to update the service for.
|
||||
* @param key The key to update the service for.
|
||||
* @param instance The instance of the service.
|
||||
* @param <T> The type of the service.
|
||||
* @param <T> The type of the service.
|
||||
*/
|
||||
<T> void update(Key<T> key, T instance);
|
||||
|
||||
/** Unregister all registered services. */
|
||||
/**
|
||||
* Unregister all registered services.
|
||||
*/
|
||||
void unregisterAll();
|
||||
|
||||
/**
|
||||
|
||||
+16
-11
@@ -15,21 +15,26 @@
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.androidide.logsender
|
||||
package com.itsaky.androidide.lookup;
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.*
|
||||
import com.itsaky.androidide.utils.ServiceLoader;
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
* Provides instance of {@link Lookup}.
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
* @author Akash Yadav
|
||||
*/
|
||||
class ExampleUnitTest {
|
||||
class LookupProvider {
|
||||
|
||||
@Test
|
||||
fun addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2)
|
||||
private static Lookup sLookup;
|
||||
private static final Object lock = new Object();
|
||||
|
||||
static synchronized Lookup lookupService() {
|
||||
synchronized (lock) {
|
||||
if (sLookup != null) {
|
||||
return sLookup;
|
||||
}
|
||||
return sLookup = ServiceLoader.load(Lookup.class).findFirstOrThrow();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ class LookupTest {
|
||||
|
||||
@Test
|
||||
fun `test with class`() {
|
||||
val lookup = Lookup.DEFAULT
|
||||
val lookup = Lookup.getDefault()
|
||||
|
||||
// Test register
|
||||
var service = TestServiceImpl()
|
||||
@@ -53,7 +53,7 @@ class LookupTest {
|
||||
|
||||
@Test
|
||||
fun `test with key`() {
|
||||
val lookup = Lookup.DEFAULT
|
||||
val lookup = Lookup.getDefault()
|
||||
val key = Key<TestService>()
|
||||
|
||||
// Test register
|
||||
|
||||
@@ -59,7 +59,7 @@ public interface ICompletionProvider {
|
||||
|
||||
/** Abort the completion process if cancelled. */
|
||||
default void abortCompletionIfCancelled() {
|
||||
final var checker = Lookup.DEFAULT.lookup(ICompletionCancelChecker.class);
|
||||
final var checker = Lookup.getDefault().lookup(ICompletionCancelChecker.class);
|
||||
if (checker != null) {
|
||||
checker.abortIfCancelled();
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ fun setupLookupForCompletion(file: File) {
|
||||
|
||||
fun setupLookupForCompletion(file: Path) {
|
||||
val module = ProjectManager.findModuleForFile(file) ?: return
|
||||
val lookup = Lookup.DEFAULT
|
||||
val lookup = Lookup.getDefault()
|
||||
|
||||
lookup.update(ModuleProject.COMPLETION_MODULE_KEY, module)
|
||||
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ abstract class BaseJavaServiceProvider(
|
||||
|
||||
/** Abort the completion if cancelled. */
|
||||
fun abortCompletionIfCancelled() {
|
||||
val checker = Lookup.DEFAULT.lookup(ICompletionCancelChecker::class.java)
|
||||
val checker = Lookup.getDefault().lookup(ICompletionCancelChecker::class.java)
|
||||
checker?.abortIfCancelled()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ abstract class LSPTest {
|
||||
this.toolingProject = project
|
||||
this.toolingServer = server
|
||||
|
||||
Lookup.DEFAULT.update(BuildService.KEY_PROJECT_PROXY, project)
|
||||
Lookup.getDefault().update(BuildService.KEY_PROJECT_PROXY, project)
|
||||
|
||||
server
|
||||
.initialize(InitializeProjectMessage(FileProvider.testProjectRoot().toFile().absolutePath))
|
||||
|
||||
+1
-1
@@ -174,7 +174,7 @@ open class AttrCompletionProvider(provider: ICompletionProvider) :
|
||||
|
||||
protected open fun findNodeStyleables(node: DOMNode, styleables: ResourceGroup): Set<Styleable> {
|
||||
val nodeName = node.nodeName
|
||||
val widgets = Lookup.DEFAULT.lookup(WidgetTable.COMPLETION_LOOKUP_KEY) ?: return emptySet()
|
||||
val widgets = Lookup.getDefault().lookup(WidgetTable.COMPLETION_LOOKUP_KEY) ?: return emptySet()
|
||||
|
||||
// Find the widget
|
||||
val widget =
|
||||
|
||||
+2
-2
@@ -263,7 +263,7 @@ abstract class IXmlCompletionProvider(private val provider: ICompletionProvider)
|
||||
|
||||
if (pck == ResourceTableRegistry.PCK_ANDROID) {
|
||||
val platformResTable =
|
||||
Lookup.DEFAULT.lookup(ResourceTableRegistry.COMPLETION_FRAMEWORK_RES)
|
||||
Lookup.getDefault().lookup(ResourceTableRegistry.COMPLETION_FRAMEWORK_RES)
|
||||
?: run {
|
||||
log.debug("No platform resource table is set")
|
||||
return emptySet()
|
||||
@@ -283,7 +283,7 @@ abstract class IXmlCompletionProvider(private val provider: ICompletionProvider)
|
||||
}
|
||||
|
||||
protected open fun findAllModuleResourceTables(): Set<ResourceTable> {
|
||||
val lookup = Lookup.DEFAULT
|
||||
val lookup = Lookup.getDefault()
|
||||
val sourceResTables = lookup.lookup(ResourceTableRegistry.COMPLETION_MODULE_RES) ?: emptySet()
|
||||
val depResTables = lookup.lookup(ResourceTableRegistry.COMPLETION_DEP_RES) ?: emptySet()
|
||||
return mutableSetOf<ResourceTable>().also {
|
||||
|
||||
+2
-2
@@ -84,10 +84,10 @@ class QualifiedTagCompleter(provider: ICompletionProvider) : LayoutTagCompletion
|
||||
|
||||
private fun doLookup(): Pair<DefaultWidgetTable, ModuleProject> {
|
||||
val widgets =
|
||||
Lookup.DEFAULT.lookup(WidgetTable.COMPLETION_LOOKUP_KEY)
|
||||
Lookup.getDefault().lookup(WidgetTable.COMPLETION_LOOKUP_KEY)
|
||||
?: throw IllegalStateException("No widget table provided")
|
||||
val module =
|
||||
Lookup.DEFAULT.lookup(ModuleProject.COMPLETION_MODULE_KEY)
|
||||
Lookup.getDefault().lookup(ModuleProject.COMPLETION_MODULE_KEY)
|
||||
?: throw IllegalStateException("No module project provided")
|
||||
return widgets as DefaultWidgetTable to module
|
||||
}
|
||||
|
||||
+2
-2
@@ -44,7 +44,7 @@ class SimpleTagCompleter(provider: ICompletionProvider) : LayoutTagCompletionPro
|
||||
prefix: String
|
||||
): CompletionResult {
|
||||
val widgets =
|
||||
Lookup.DEFAULT.lookup(WidgetTable.COMPLETION_LOOKUP_KEY)?.getAllWidgets()
|
||||
Lookup.getDefault().lookup(WidgetTable.COMPLETION_LOOKUP_KEY)?.getAllWidgets()
|
||||
?: return CompletionResult.EMPTY
|
||||
val result = mutableListOf<CompletionItem>()
|
||||
|
||||
@@ -56,7 +56,7 @@ class SimpleTagCompleter(provider: ICompletionProvider) : LayoutTagCompletionPro
|
||||
|
||||
// Complete the root package names if possible
|
||||
val module =
|
||||
Lookup.DEFAULT.lookup(ModuleProject.COMPLETION_MODULE_KEY) ?: return CompletionResult(result)
|
||||
Lookup.getDefault().lookup(ModuleProject.COMPLETION_MODULE_KEY) ?: return CompletionResult(result)
|
||||
|
||||
// Add root packages from the compile classpath and source paths
|
||||
addFromTrie(module.compileClasspathClasses, prefix, result)
|
||||
|
||||
+1
-1
@@ -186,7 +186,7 @@ class ManifestAttrValueCompletionProvider(provider: ICompletionProvider) :
|
||||
}
|
||||
|
||||
private fun getModule(): ModuleProject {
|
||||
return Lookup.DEFAULT.lookup(ModuleProject.COMPLETION_MODULE_KEY)
|
||||
return Lookup.getDefault().lookup(ModuleProject.COMPLETION_MODULE_KEY)
|
||||
?: throw IllegalStateException("No module project provided")
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ class ManifestTagCompletionProvider(provider: ICompletionProvider) :
|
||||
}
|
||||
|
||||
val styleables =
|
||||
Lookup.DEFAULT.lookup(ResourceTableRegistry.COMPLETION_MANIFEST_ATTR_RES)
|
||||
Lookup.getDefault().lookup(ResourceTableRegistry.COMPLETION_MANIFEST_ATTR_RES)
|
||||
?.findPackage(ResourceTableRegistry.PCK_ANDROID)
|
||||
?.findGroup(STYLEABLE)
|
||||
?: run {
|
||||
|
||||
+1
-1
@@ -36,6 +36,6 @@ fun canCompleteManifest(pathData: ResourcePathData, type: NodeType): Boolean {
|
||||
|
||||
fun manifestResourceTable(): Set<ResourceTable> {
|
||||
return setOf(
|
||||
Lookup.DEFAULT.lookup(ResourceTableRegistry.COMPLETION_MANIFEST_ATTR_RES) ?: return emptySet()
|
||||
Lookup.getDefault().lookup(ResourceTableRegistry.COMPLETION_MANIFEST_ATTR_RES) ?: return emptySet()
|
||||
)
|
||||
}
|
||||
+1
-1
@@ -37,7 +37,7 @@ fun match(simpleName: String, qualifiedName: String, prefix: String): MatchLevel
|
||||
}
|
||||
|
||||
fun platformResourceTable(): ResourceTable? {
|
||||
return Lookup.DEFAULT.lookup(ResourceTableRegistry.COMPLETION_FRAMEWORK_RES)
|
||||
return Lookup.getDefault().lookup(ResourceTableRegistry.COMPLETION_FRAMEWORK_RES)
|
||||
}
|
||||
|
||||
fun findAllNamespaces(node: DOMNode): MutableSet<Pair<String, String>> {
|
||||
|
||||
@@ -39,7 +39,7 @@ object XMLLSPTest : LSPTest() {
|
||||
super.initProjectIfNeeded()
|
||||
try {
|
||||
val module = ProjectManager.app!!
|
||||
val lookup = Lookup.DEFAULT
|
||||
val lookup = Lookup.getDefault()
|
||||
|
||||
lookup.update(ModuleProject.COMPLETION_MODULE_KEY, module)
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@ include(
|
||||
":preferences",
|
||||
":resources",
|
||||
":shared",
|
||||
":templates-api",
|
||||
":treeview",
|
||||
":uidesigner",
|
||||
":xml-inflater",
|
||||
|
||||
@@ -62,7 +62,7 @@ object ProjectManager : EventReceiver {
|
||||
var cachedInitResult: InitializeResult? = null
|
||||
|
||||
@JvmOverloads
|
||||
fun setupProject(project: IProject = Lookup.DEFAULT.lookup(BuildService.KEY_PROJECT_PROXY)!!) {
|
||||
fun setupProject(project: IProject = Lookup.getDefault().lookup(BuildService.KEY_PROJECT_PROXY)!!) {
|
||||
val caching = CachingProject(project)
|
||||
this.rootProject = ProjectTransformer().transform(caching)
|
||||
if (this.rootProject != null) {
|
||||
@@ -94,7 +94,7 @@ object ProjectManager : EventReceiver {
|
||||
|
||||
@JvmOverloads
|
||||
fun generateSources(
|
||||
builder: BuildService? = Lookup.DEFAULT.lookup(BuildService.KEY_BUILD_SERVICE)
|
||||
builder: BuildService? = Lookup.getDefault().lookup(BuildService.KEY_BUILD_SERVICE)
|
||||
) {
|
||||
if (builder == null) {
|
||||
log.warn("Cannot generate sources. BuildService is null.")
|
||||
@@ -301,7 +301,7 @@ object ProjectManager : EventReceiver {
|
||||
}
|
||||
|
||||
private fun generateSourcesIfNecessary(event: FileEvent) {
|
||||
val builder = Lookup.DEFAULT.lookup(BuildService.KEY_BUILD_SERVICE) ?: return
|
||||
val builder = Lookup.getDefault().lookup(BuildService.KEY_BUILD_SERVICE) ?: return
|
||||
val file = event.file
|
||||
if (!isResource(file)) {
|
||||
return
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ class ModuleProjectTest {
|
||||
val (server, project) = ToolingApiTestLauncher().launchServer()
|
||||
server.initialize(InitializeProjectMessage(FileProvider.testProjectRoot().pathString)).get()
|
||||
|
||||
Lookup.DEFAULT.register(BuildService.KEY_PROJECT_PROXY, project)
|
||||
Lookup.getDefault().register(BuildService.KEY_PROJECT_PROXY, project)
|
||||
|
||||
verifyProjectManagerAPIs()
|
||||
|
||||
|
||||
@@ -30,6 +30,6 @@ class UiLayoutInflater : LayoutInflaterImpl() {
|
||||
|
||||
init {
|
||||
this.componentFactory = UiInflaterComponentFactory()
|
||||
Lookup.DEFAULT.update(com.itsaky.androidide.inflater.ILayoutInflater.LOOKUP_KEY, this)
|
||||
Lookup.getDefault().update(com.itsaky.androidide.inflater.ILayoutInflater.LOOKUP_KEY, this)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ private val activity by lazy { Robolectric.buildActivity(AppCompatActivity::clas
|
||||
|
||||
fun requiresActivity(initComponentFactory: Boolean = true, block: AppCompatActivity.() -> Unit) {
|
||||
if (initComponentFactory) {
|
||||
Lookup.DEFAULT.apply {
|
||||
Lookup.getDefault().apply {
|
||||
lookup(LAYOUT_INFLATER_COMPONENT_FACTORY_KEY)
|
||||
?: register(LAYOUT_INFLATER_COMPONENT_FACTORY_KEY, UiInflaterComponentFactory())
|
||||
}
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ open class LayoutInflaterImpl : ILayoutInflater {
|
||||
override var componentFactory: IComponentFactory = DefaultComponentFactory()
|
||||
set(value) {
|
||||
field = value
|
||||
Lookup.DEFAULT.update(LAYOUT_INFLATER_COMPONENT_FACTORY_KEY, value)
|
||||
Lookup.getDefault().update(LAYOUT_INFLATER_COMPONENT_FACTORY_KEY, value)
|
||||
}
|
||||
|
||||
protected val primaryInflatingFile: File
|
||||
|
||||
@@ -40,12 +40,12 @@ import java.io.File
|
||||
|
||||
/** Get the [ILayoutInflater] registered with [Lookup]. */
|
||||
fun lookupLayoutInflater(): ILayoutInflater? {
|
||||
return Lookup.DEFAULT.lookup(Companion.LOOKUP_KEY)
|
||||
return Lookup.getDefault().lookup(Companion.LOOKUP_KEY)
|
||||
}
|
||||
|
||||
/** Get the [IComponentFactory] registered with [Lookup]. */
|
||||
fun lookupComponentFactory(): IComponentFactory? {
|
||||
return Lookup.DEFAULT.lookup(IComponentFactory.LAYOUT_INFLATER_COMPONENT_FACTORY_KEY)
|
||||
return Lookup.getDefault().lookup(IComponentFactory.LAYOUT_INFLATER_COMPONENT_FACTORY_KEY)
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
|
||||
@@ -47,7 +47,7 @@ object XmlInflaterTest {
|
||||
ToolingApiTestLauncher().launchServer()
|
||||
server.initialize(InitializeProjectMessage(FileProvider.testProjectRoot().pathString)).get()
|
||||
|
||||
Lookup.DEFAULT.register(BuildService.KEY_PROJECT_PROXY, project)
|
||||
Lookup.getDefault().register(BuildService.KEY_PROJECT_PROXY, project)
|
||||
ProjectManager.setupProject()
|
||||
init = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user