mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 13:31:28 +07:00
IJPL-227045 (service overrides) update ServiceDescriptor's javadoc, fix misprints and improve logging messages
GitOrigin-RevId: baa3adf6709241e4af6bdf60a9b8c6332a2aa58b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
8c040d801d
commit
011d91dd1f
@@ -72,13 +72,24 @@ public final class ServiceDescriptor {
|
||||
public final String headlessImplementation;
|
||||
|
||||
/**
|
||||
* Allows overriding existing registered implementation for given {@link #serviceInterface}.
|
||||
* Declares that this service overrides an existing implementation of the same
|
||||
* {@link #serviceInterface}.
|
||||
* <p>
|
||||
* The overridden service must be marked as {@link #open}.
|
||||
* <p>
|
||||
* This attribute may be used together with {@link #open}, but such usage is
|
||||
* discouraged as it may lead to non-deterministic behavior.
|
||||
*/
|
||||
@Attribute
|
||||
public final boolean overrides;
|
||||
|
||||
/**
|
||||
* Allows this service to be overridden.
|
||||
* Declares that this service is eligible to be overridden by another service.
|
||||
* <p>
|
||||
* Only services marked as open may be overridden.
|
||||
* <p>
|
||||
* This attribute may be used together with {@link #overrides}, but such usage
|
||||
* is discouraged as it may lead to non-deterministic behavior.
|
||||
*/
|
||||
@Attribute
|
||||
public final boolean open;
|
||||
|
||||
@@ -4,5 +4,11 @@ package com.intellij.platform.instanceContainer
|
||||
import org.jetbrains.annotations.ApiStatus.Internal
|
||||
|
||||
class InstanceNotOverridableException @Internal internal constructor(
|
||||
message: String,
|
||||
) : IllegalStateException(message)
|
||||
serviceInterface: String,
|
||||
existingImpl: String,
|
||||
newImpl: String?,
|
||||
) : IllegalStateException("Override failed for $serviceInterface: " +
|
||||
if (newImpl != null)
|
||||
"$newImpl attempts to override $existingImpl, but the existing implementation is not overriddable (not declared as 'open=true')"
|
||||
else
|
||||
"Existing instance $existingImpl is attempted to be removed, but it is not overriddable (not declared as 'open=true')")
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.intellij.openapi.diagnostic.trace
|
||||
import com.intellij.platform.instanceContainer.InstanceContainer
|
||||
import com.intellij.platform.instanceContainer.InstanceNotRegisteredException
|
||||
import com.intellij.util.ArrayUtil
|
||||
import com.intellij.util.SystemProperties
|
||||
import kotlinx.collections.immutable.persistentHashMapOf
|
||||
import kotlinx.collections.immutable.persistentMapOf
|
||||
import kotlinx.coroutines.CoroutineName
|
||||
@@ -30,7 +31,7 @@ class InstanceContainerImpl @VisibleForTesting constructor(
|
||||
) : this(scopeHolder, containerName, dynamicInstanceSupport, ordered,
|
||||
// Use System.getProperty(), because the Registry is a service, and not available yet.
|
||||
// Default is `true` during the migration period, then will be changed to `false`
|
||||
shouldTolerateIncorrectOverrides = System.getProperty("instance.conteiner.tolerate.incorrect.overrides", "true").toBoolean())
|
||||
shouldTolerateIncorrectOverrides = SystemProperties.getBooleanProperty("intellij.platform.instance.container.tolerate.incorrect.overrides", true))
|
||||
|
||||
override fun toString(): String {
|
||||
val state = _state
|
||||
|
||||
@@ -64,7 +64,7 @@ internal class InstanceRegistrarImpl(
|
||||
}
|
||||
if (!existingInstanceHolder.overridable) {
|
||||
val exception =
|
||||
InstanceNotOverridableException("$keyClassName -> existing: ${existingInstanceHolder.instanceClassName()}, new: ${initializer?.instanceClassName ?: "<removed>"}")
|
||||
InstanceNotOverridableException(keyClassName, existingInstanceHolder.instanceClassName(), initializer?.instanceClassName)
|
||||
logIncorrectOverride(exception)
|
||||
}
|
||||
if (initializer == null) RegistrationAction.Remove else RegistrationAction.Override(initializer)
|
||||
@@ -73,7 +73,7 @@ internal class InstanceRegistrarImpl(
|
||||
check(keyClassName !in existingKeys) // sanity check
|
||||
if (!existingAction.initializer.overridable) {
|
||||
val exception =
|
||||
InstanceNotOverridableException("$keyClassName -> existing: ${existingAction.initializer.instanceClassName}, new: ${initializer?.instanceClassName ?: "<removed>"}")
|
||||
InstanceNotOverridableException(keyClassName, existingAction.initializer.instanceClassName, initializer?.instanceClassName)
|
||||
logIncorrectOverride(exception)
|
||||
}
|
||||
LOG.trace {
|
||||
@@ -92,7 +92,7 @@ internal class InstanceRegistrarImpl(
|
||||
check(keyClassName in existingKeys) // sanity check
|
||||
if (!existingAction.initializer.overridable) {
|
||||
val exception =
|
||||
InstanceNotOverridableException("$keyClassName -> existing: ${existingAction.initializer.instanceClassName}, new: ${initializer?.instanceClassName ?: "<removed>"}")
|
||||
InstanceNotOverridableException(keyClassName, existingAction.initializer.instanceClassName, initializer?.instanceClassName)
|
||||
logIncorrectOverride(exception)
|
||||
}
|
||||
LOG.trace {
|
||||
|
||||
Reference in New Issue
Block a user