⁠
kyle wood: Merge branch '2024.1' into 2024.2
- /*
- * Minecraft Development for IntelliJ
- *
- * https://mcdev.io/
- *
- * Copyright (C) 2024 minecraft-dev
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation, version 3.0 only.
- *
- * This program 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 Lesser General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
- package com.demonwav.mcdev.framework
- import com.intellij.openapi.application.EDT
- import java.lang.reflect.Method
- import kotlinx.coroutines.Dispatchers
- import kotlinx.coroutines.runBlocking
- import org.junit.jupiter.api.extension.ExtensionContext
- import org.junit.jupiter.api.extension.InvocationInterceptor
- import org.junit.jupiter.api.extension.ReflectiveInvocationContext
- class EdtInterceptor : InvocationInterceptor {
- override fun interceptBeforeEachMethod(
- invocation: InvocationInterceptor.Invocation<Void>,
- invocationContext: ReflectiveInvocationContext<Method>,
- extensionContext: ExtensionContext,
- ) {
- exec(invocation, invocationContext)
- }
- override fun interceptAfterEachMethod(
- invocation: InvocationInterceptor.Invocation<Void>,
- invocationContext: ReflectiveInvocationContext<Method>,
- extensionContext: ExtensionContext,
- ) {
- exec(invocation, invocationContext)
- }
- override fun interceptTestMethod(
- invocation: InvocationInterceptor.Invocation<Void>,
- invocationContext: ReflectiveInvocationContext<Method>,
- extensionContext: ExtensionContext,
- ) {
- exec(invocation, invocationContext)
- }
- private fun exec(
- invocation: InvocationInterceptor.Invocation<Void>,
- invocationContext: ReflectiveInvocationContext<Method>,
- ) {
- if (invocationContext.executable.getAnnotation(NoEdt::class.java) != null) {
- invocation.proceed()
- return
- }
- val thrown = runBlocking(Dispatchers.EDT) {
- runCatching {
- invocation.proceed()
- }.exceptionOrNull()
- }
- if (thrown != null) {
- throw thrown
- }
- }
- }
- /*
- * Minecraft Development for IntelliJ
- *
- * https://mcdev.io/
- *
- * Copyright (C) 2025 minecraft-dev
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation, version 3.0 only.
- *
- * This program 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 Lesser General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
- package com.demonwav.mcdev.framework
- import com.intellij.openapi.application.EDT
- import java.lang.reflect.Method
- import kotlinx.coroutines.Dispatchers
- import kotlinx.coroutines.runBlocking
- import org.junit.jupiter.api.extension.ExtensionContext
- import org.junit.jupiter.api.extension.InvocationInterceptor
- import org.junit.jupiter.api.extension.ReflectiveInvocationContext
- class EdtInterceptor : InvocationInterceptor {
- override fun interceptBeforeEachMethod(
- invocation: InvocationInterceptor.Invocation<Void>,
- invocationContext: ReflectiveInvocationContext<Method>,
- extensionContext: ExtensionContext,
- ) {
- exec(invocation, invocationContext)
- }
- override fun interceptAfterEachMethod(
- invocation: InvocationInterceptor.Invocation<Void>,
- invocationContext: ReflectiveInvocationContext<Method>,
- extensionContext: ExtensionContext,
- ) {
- exec(invocation, invocationContext)
- }
- override fun interceptTestMethod(
- invocation: InvocationInterceptor.Invocation<Void>,
- invocationContext: ReflectiveInvocationContext<Method>,
- extensionContext: ExtensionContext,
- ) {
- exec(invocation, invocationContext)
- }
- private fun exec(
- invocation: InvocationInterceptor.Invocation<Void>,
- invocationContext: ReflectiveInvocationContext<Method>,
- ) {
- if (invocationContext.executable.getAnnotation(NoEdt::class.java) != null) {
- invocation.proceed()
- return
- }
- val thrown = runBlocking(Dispatchers.EDT) {
- runCatching {
- invocation.proceed()
- }.exceptionOrNull()
- }
- if (thrown != null) {
- throw thrown
- }
- }
- }