@@ -1569,6 +1616,10 @@
+
+
+
Index: src/main/resources/assets/icons/general/tiny_potato.LICENSE.txt
===================================================================
--- src/main/resources/assets/icons/general/tiny_potato.LICENSE.txt (revision 19b7b6f903071157b5202adf613d68c13cf0417f)
+++ src/main/resources/assets/icons/general/tiny_potato.LICENSE.txt (revision 19b7b6f903071157b5202adf613d68c13cf0417f)
@@ -0,0 +1,3 @@
+tiny_potato.png, tiny_potato@2x.png, tiny_potato_large.png and tiny_potato_large@2x.png are downscaled from
+https://github.com/FabricMC/community/blob/main/media/tater-wall/png/potato.png by FabricMC, licensed under the
+Creative Commons Attribution 4.0 International license (https://creativecommons.org/licenses/by/4.0/).
Index: src/main/resources/inspectionDescriptions/AnnotaterJavadocComment.html
===================================================================
--- src/main/resources/inspectionDescriptions/AnnotaterJavadocComment.html (revision 19b7b6f903071157b5202adf613d68c13cf0417f)
+++ src/main/resources/inspectionDescriptions/AnnotaterJavadocComment.html (revision 19b7b6f903071157b5202adf613d68c13cf0417f)
@@ -0,0 +1,37 @@
+
+
+
+
+
+ Reports comments in the annotater Javadoc editor that are not Markdown documentation comments (///)
+
+
+
+ Annotater stores its Javadocs as Markdown, so only Markdown documentation comments can be saved to the annotater checkout.
+ Traditional Javadoc comments (/** */), line comments and block comments are not supported.
+
+
+/** Returns the maximum stack size. */ // bad
+/// Returns the maximum stack size. // good
+public int getMaxStackSize() {
+
+
+
Index: src/main/resources/inspectionDescriptions/AnnotaterJavadocUnqualifiedReference.html
===================================================================
--- src/main/resources/inspectionDescriptions/AnnotaterJavadocUnqualifiedReference.html (revision 19b7b6f903071157b5202adf613d68c13cf0417f)
+++ src/main/resources/inspectionDescriptions/AnnotaterJavadocUnqualifiedReference.html (revision 19b7b6f903071157b5202adf613d68c13cf0417f)
@@ -0,0 +1,38 @@
+
+
+
+
+
+ Reports classes referenced in annotater Javadocs without their fully qualified name
+
+
+
+ Annotater Javadocs are applied to Minecraft sources that may have different imports to the file they were written in, so
+ annotater requires every class referenced from a Javadoc to be written with its fully qualified name. Fully qualified
+ names can still be shown shortened in the inlay hints, depending on the annotater settings.
+
+
+/// Returns the [ItemStack] in the given slot. // bad
+/// Returns the [net.minecraft.world.item.ItemStack] in the given slot. // good
+public ItemStack getItem(int slot) {
+
+
+
Index: src/main/resources/intentionDescriptions/EditAnnotaterJavadocIntention/after.java.template
===================================================================
--- src/main/resources/intentionDescriptions/EditAnnotaterJavadocIntention/after.java.template (revision 19b7b6f903071157b5202adf613d68c13cf0417f)
+++ src/main/resources/intentionDescriptions/EditAnnotaterJavadocIntention/after.java.template (revision 19b7b6f903071157b5202adf613d68c13cf0417f)
@@ -0,0 +1,6 @@
+/// Clamps a value between a minimum and a maximum.
+///
+/// @return the clamped value
+public static int clamp(int value, int min, int max) {
+ return Math.min(Math.max(value, min), max);
+}
Index: src/main/resources/intentionDescriptions/EditAnnotaterJavadocIntention/before.java.template
===================================================================
--- src/main/resources/intentionDescriptions/EditAnnotaterJavadocIntention/before.java.template (revision 19b7b6f903071157b5202adf613d68c13cf0417f)
+++ src/main/resources/intentionDescriptions/EditAnnotaterJavadocIntention/before.java.template (revision 19b7b6f903071157b5202adf613d68c13cf0417f)
@@ -0,0 +1,3 @@
+public static int clamp(int value, int min, int max) {
+ return Math.min(Math.max(value, min), max);
+}
Index: src/main/resources/intentionDescriptions/EditAnnotaterJavadocIntention/description.html
===================================================================
--- src/main/resources/intentionDescriptions/EditAnnotaterJavadocIntention/description.html (revision 19b7b6f903071157b5202adf613d68c13cf0417f)
+++ src/main/resources/intentionDescriptions/EditAnnotaterJavadocIntention/description.html (revision 19b7b6f903071157b5202adf613d68c13cf0417f)
@@ -0,0 +1,25 @@
+
+
+
+
+Opens an editor for the annotater Javadoc of a Minecraft class, field or method. Annotater Javadocs are written as Markdown documentation comments (///) and saved to your annotater checkout.
+
+
Index: src/main/resources/messages/MinecraftDevelopmentBundle.properties
===================================================================
--- src/main/resources/messages/MinecraftDevelopmentBundle.properties (revision 8d3f31db2322c5a8d13cb01e180bac8ce26fa419)
+++ src/main/resources/messages/MinecraftDevelopmentBundle.properties (revision 19b7b6f903071157b5202adf613d68c13cf0417f)
@@ -28,6 +28,8 @@
action.CopyMixinTargetReferenceAction.text=Mixin Target Reference
action.CreateMinecraftClass.description=Create skeleton classes used in Minecraft Mods
action.CreateMinecraftClass.text=Minecraft Class
+action.EditAnnotaterJavadoc.description=Edit the annotater Javadoc of this Minecraft class, field or method
+action.EditAnnotaterJavadoc.text=Edit Annotater Javadoc
action.FindMixinsAction.description=Find classes which mix into this class
action.FindMixinsAction.text=Find Mixins
action.FindSrgMappingAction.description=Find the associated SRG mapping for this element
@@ -227,6 +229,8 @@
inspection.added_enum_constants_name_pattern.name=Name does not match the pattern for added enum constants
inspection.added_mixin_members_name_pattern.name=Name does not match the pattern for added mixin members
inspection.ambiguous_mixin_reference.name=Ambiguous reference
+inspection.annotater_javadoc_comment.name=Unsupported comment in annotater Javadoc
+inspection.annotater_javadoc_unqualified_reference.name=Unqualified class reference in annotater Javadoc
inspection.annotation_outside_of_mixin.name=Mixin annotation outside of @Mixin class
inspection.at_usage.name=Unused access transformer
inspection.bukkit_listener_implemented.name=Bukkit @EventHandler in class not implementing Listener
@@ -396,6 +400,7 @@
nbt.file.save_notify.parse_exception.title=Error saving NBT file
nbt.file.save_notify.parse_exception.content=An unexpected exception happened, {0} could not be saved\: {1}
+notification.group.minecraft_annotater=Minecraft annotater
notification.group.minecraft_development_updates=Minecraft Development updates
notification.group.minecraft_facet=Minecraft facet
notification.group.minecraft_project_creator=Minecraft project creator
@@ -515,3 +520,116 @@
update.outdated_ide.title=IDE version no longer supported
update.outdated_ide.content=Minecraft Development has dropped support for {0}. To receive further updates to Minecraft Development, please update your IDE.
+
+fabric.annotater.settings.display_name=Annotater
+fabric.annotater.settings.title=Annotater
+fabric.annotater.settings.enabled=Enable annotater
+fabric.annotater.settings.enabled.comment=Contribute to annotater, Fabric's Minecraft documentation, from within the IDE.
+fabric.annotater.settings.guidelines=Please follow annotater''s {0} when writing Javadocs and opening pull requests.
+fabric.annotater.settings.guidelines.link=contribution guidelines
+fabric.annotater.settings.guidelines.link.version=contribution guidelines for {0}
+fabric.annotater.settings.show_javadocs=Show annotater Javadocs in code
+fabric.annotater.settings.shorten_class_names=Shorten fully qualified class names in inlay hints
+fabric.annotater.settings.shorten_class_names.comment=The names are still saved fully qualified, as required by annotater.
+fabric.annotater.settings.managed=Clone annotater automatically
+fabric.annotater.settings.managed_root=Clone into\:
+fabric.annotater.settings.clone_now=Clone or Update Annotater
+fabric.annotater.settings.clone_now.version=Minecraft version to clone annotater for\:
+fabric.annotater.settings.clone_now.no_versions=No Minecraft versions could be found in the open projects. Refresh the Gradle project, or set the Minecraft version in the Minecraft module settings.
+fabric.annotater.settings.no_git=The Git plugin is required to clone annotater.
+fabric.annotater.settings.custom=Use an existing annotater directory\:
+fabric.annotater.settings.custom.comment=Commit, push and open pull requests yourself. MinecraftDev will not run git in this directory.
+fabric.annotater.settings.custom.version_mismatch=This annotater directory is for Minecraft {0}, but the open projects use Minecraft {1}.
+
+fabric.annotater.unavailable=Annotater unavailable
+fabric.annotater.configure=Configure Annotater
+fabric.annotater.clone=Clone annotater for {0}
+fabric.annotater.cloned=Annotater for {0} is ready
+fabric.annotater.cloned.content=Annotater is checked out in {0}.
+fabric.annotater.clone_failed=Failed to clone annotater
+fabric.annotater.cloning=Cloning annotater for {0}
+fabric.annotater.cloning.clone=Cloning annotater...
+fabric.annotater.cloning.fetch=Fetching annotater...
+fabric.annotater.cloning.worktree=Checking out annotater...
+fabric.annotater.no_branch=Annotater has no branch for Minecraft {0}.
+fabric.annotater.invalid_after_clone=The annotater checkout at {0} is not valid.
+fabric.annotater.uncommitted_changes=The annotater checkout has uncommitted changes.
+fabric.annotater.preparing=Preparing annotater checkout
+fabric.annotater.preparing.failed=Failed to prepare the annotater checkout
+fabric.annotater.create_pull_request=Create Pull Request...
+fabric.annotater.update_pull_request=Update Pull Request...
+fabric.annotater.dropdown={0} \u25BE
+fabric.annotater.menu=Annotater
+fabric.annotater.contribution.tooltip=Switch to another contribution
+fabric.annotater.contribution.switch=Switch Contribution
+fabric.annotater.contribution.new=New contribution
+fabric.annotater.contribution.switching=Switching annotater contribution
+fabric.annotater.contribution.failed=Failed to switch annotater contribution
+fabric.annotater.contribution.save_failed=Fix the errors in the open annotater editors before switching contribution.
+fabric.annotater.contribution.commit=The changes to "{0}" will be committed before switching. Commit message\:
+fabric.annotater.contribution.delete=Delete Contribution
+fabric.annotater.contribution.delete.title=Delete Contribution
+fabric.annotater.contribution.delete.ok=Delete
+fabric.annotater.contribution.delete.confirm=Delete the contribution "{0}"? It is only deleted locally. Any branch pushed to GitHub and any pull request for it are kept.
+fabric.annotater.contribution.delete.confirm.current=This contribution is checked out, so its uncommitted changes will be lost.
+fabric.annotater.contribution.deleting=Deleting annotater contribution
+fabric.annotater.contribution.deleted=Annotater contribution deleted
+fabric.annotater.contribution.deleted.content=Deleted the contribution "{0}".
+fabric.annotater.contribution.delete.failed=Failed to delete annotater contribution
+fabric.annotater.status.disabled=Annotater is disabled in the MinecraftDev settings.
+fabric.annotater.status.unknown_version=The Minecraft version of this project is unknown.
+fabric.annotater.status.not_cloned=Annotater has not been cloned for Minecraft {0} yet.
+fabric.annotater.status.not_cloned_no_git=Annotater has not been cloned for Minecraft {0}. Install the Git plugin, or select an existing annotater directory.
+fabric.annotater.status.version_mismatch=The selected annotater directory is for Minecraft {0}, but this project uses Minecraft {1}.
+fabric.annotater.status.invalid=Invalid annotater directory\: {0}
+
+fabric.annotater.javadoc.edit=Edit Annotater Javadoc
+fabric.annotater.javadoc.open_failed=Failed to open annotater Javadoc
+fabric.annotater.banner=Annotater Javadocs for Minecraft {0} from {1}. Changes are saved automatically.
+fabric.annotater.banner.pull_request=Changes are saved to the contribution for pull request #{0}, for Minecraft {1}. Start a new contribution for unrelated changes.
+fabric.annotater.banner.closed=Pull request #{0} for this contribution was closed. It''s recommended to start a new contribution for new changes.
+fabric.annotater.banner.merged=Pull request #{0} for this contribution was already merged. It''s recommended to start a new contribution for new changes.
+fabric.annotater.banner.open_pull_request=Open #{0}
+fabric.annotater.javadoc.finish=Finish editing
+fabric.annotater.javadoc.save_failed=Failed to save annotater Javadoc
+fabric.annotater.javadoc.error.not_markdown=Annotater only supports Markdown Javadoc comments (///). Changes were not saved.
+fabric.annotater.javadoc.error.plain_comment=Only Markdown Javadoc comments (///) can be saved to annotater. Changes were not saved.
+fabric.annotater.javadoc.error.structure_changed=The declarations in the copy of the source file changed. Changes were not saved.
+fabric.annotater.javadoc.error.io=Failed to save annotater Javadocs\: {0}
+
+fabric.annotater.inspection.unqualified.problem=Annotater requires fully qualified class names, use ''{0}''
+fabric.annotater.inspection.unqualified.fix=Replace with ''{0}''
+fabric.annotater.inspection.unqualified.fix.family=Use fully qualified class name
+
+fabric.annotater.pr.checking=Checking annotater changes
+fabric.annotater.pr.nothing=Nothing to submit
+fabric.annotater.pr.nothing.content=There are no annotater Javadoc changes for Minecraft {0} to submit.
+fabric.annotater.pr.no_account=Log in to a GitHub.com account in the GitHub settings to create pull requests.
+fabric.annotater.pr.failed=Failed to create annotater pull request
+fabric.annotater.pr.no_base_branch={0} has no {1} branch to open a pull request against.
+fabric.annotater.pr.creating=Creating annotater pull request
+fabric.annotater.pr.updating=Updating annotater pull request
+fabric.annotater.pr.committing=Committing changes...
+fabric.annotater.pr.forking=Forking annotater...
+fabric.annotater.pr.pushing=Pushing changes...
+fabric.annotater.pr.opening=Opening pull request...
+fabric.annotater.pr.created=Annotater pull request created
+fabric.annotater.pr.updated=Annotater pull request updated
+fabric.annotater.pr.open=Open in Browser
+fabric.annotater.pr.start_new=Start New Contribution
+fabric.annotater.pr.dialog.ok=Create Pull Request
+fabric.annotater.pr.dialog.update=Update Pull Request
+fabric.annotater.pr.dialog.existing=The changes will be added to this contribution''s pull request, {0}.
+fabric.annotater.pr.dialog.closed=This contribution''s pull request, {0}, was closed, so a new pull request will be opened.
+fabric.annotater.pr.dialog.merged=This contribution''s pull request, {0}, was already merged, so a new pull request will be opened. If it was squash merged, the new pull request will repeat its changes, so consider starting a new contribution instead.
+fabric.annotater.pr.dialog.account=GitHub account\:
+fabric.annotater.pr.dialog.title=Title\:
+fabric.annotater.pr.dialog.description=Description\:
+fabric.annotater.pr.dialog.commit_message=Commit message\:
+fabric.annotater.pr.dialog.changes=Changed files\:
{0}
+fabric.annotater.pr.dialog.check_build=Check the build first
+fabric.annotater.pr.dialog.check_build.comment=Runs gradlew check in the annotater checkout. May take a minute or two.
+fabric.annotater.pr.check_build.progress=Checking the annotater build
+fabric.annotater.pr.check_build.failed=Annotater Build Check Failed
+fabric.annotater.pr.check_build.failed.message=The annotater build check failed with the following error log.
+fabric.annotater.pr.check_build.submit_anyway=Submit Anyway
Index: src/test/kotlin/platform/fabric/annotater/AnnotaterJavadocEditorTest.kt
===================================================================
--- src/test/kotlin/platform/fabric/annotater/AnnotaterJavadocEditorTest.kt (revision 19b7b6f903071157b5202adf613d68c13cf0417f)
+++ src/test/kotlin/platform/fabric/annotater/AnnotaterJavadocEditorTest.kt (revision 19b7b6f903071157b5202adf613d68c13cf0417f)
@@ -0,0 +1,601 @@
+/*
+ * Minecraft Development for IntelliJ
+ *
+ * https://mcdev.io/
+ *
+ * Copyright (C) 2026 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 .
+ */
+
+package com.demonwav.mcdev.platform.fabric.annotater
+
+import com.demonwav.mcdev.framework.BaseMinecraftTest
+import com.demonwav.mcdev.framework.EdtInterceptor
+import com.demonwav.mcdev.platform.fabric.annotater.javadoc.AnnotaterJavadocCodeStyleSettingsModifier
+import com.demonwav.mcdev.platform.fabric.annotater.javadoc.AnnotaterJavadocInlineEditor
+import com.demonwav.mcdev.platform.fabric.annotater.javadoc.AnnotaterJavadocIntentionActionFilter
+import com.demonwav.mcdev.platform.fabric.annotater.javadoc.AnnotaterJavadocRendering
+import com.demonwav.mcdev.platform.fabric.annotater.javadoc.AnnotaterJavadocSourceCopy
+import com.demonwav.mcdev.platform.fabric.annotater.javadoc.AnnotaterJavadocTarget
+import com.demonwav.mcdev.platform.fabric.annotater.javadoc.AnnotaterJavadocUnqualifiedReferenceInspection
+import com.demonwav.mcdev.platform.fabric.annotater.javadoc.AnnotaterJavadocVirtualFile
+import com.intellij.application.options.CodeStyle
+import com.intellij.codeInsight.intention.IntentionAction
+import com.intellij.codeInsight.intention.IntentionManager
+import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction
+import com.intellij.codeInsight.lookup.Lookup
+import com.intellij.codeInsight.template.impl.TemplateManagerImpl
+import com.intellij.ide.DataManager
+import com.intellij.ide.impl.HeadlessDataManager
+import com.intellij.lang.annotation.HighlightSeverity
+import com.intellij.openapi.actionSystem.PlatformCoreDataKeys
+import com.intellij.openapi.command.WriteCommandAction
+import com.intellij.openapi.command.undo.UndoManager
+import com.intellij.openapi.editor.Editor
+import com.intellij.openapi.editor.colors.EditorColorsManager
+import com.intellij.openapi.editor.ex.EditorEx
+import com.intellij.openapi.fileEditor.FileDocumentManager
+import com.intellij.openapi.fileEditor.TextEditor
+import com.intellij.openapi.project.Project
+import com.intellij.openapi.util.Disposer
+import com.intellij.openapi.util.TextRange
+import com.intellij.psi.JavaPsiFacade
+import com.intellij.psi.PsiClass
+import com.intellij.psi.PsiDocumentManager
+import com.intellij.psi.PsiElement
+import com.intellij.psi.PsiFile
+import com.intellij.psi.PsiMember
+import com.intellij.psi.PsiMethod
+import com.intellij.psi.codeStyle.CodeStyleManager
+import com.intellij.psi.codeStyle.modifier.TransientCodeStyleSettings
+import com.intellij.psi.javadoc.PsiDocComment
+import com.intellij.psi.search.GlobalSearchScope
+import com.intellij.psi.util.PsiTreeUtil
+import java.nio.file.Path
+import java.util.concurrent.TimeUnit
+import kotlin.io.path.readText
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Assertions.assertFalse
+import org.junit.jupiter.api.Assertions.assertInstanceOf
+import org.junit.jupiter.api.Assertions.assertNotNull
+import org.junit.jupiter.api.Assertions.assertNull
+import org.junit.jupiter.api.Assertions.assertSame
+import org.junit.jupiter.api.Assertions.assertTrue
+import org.junit.jupiter.api.BeforeEach
+import org.junit.jupiter.api.DisplayName
+import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.extension.ExtendWith
+import org.junit.jupiter.api.io.TempDir
+
+@ExtendWith(EdtInterceptor::class)
+@DisplayName("Annotater Javadoc Editor Tests")
+class AnnotaterJavadocEditorTest : BaseMinecraftTest() {
+ @TempDir
+ lateinit var root: Path
+
+ private lateinit var checkout: AnnotaterCheckout
+
+ private val clamp = AnnotaterJavadocTarget.MethodTarget("net/minecraft/util/Mth", "clamp", "(III)I")
+
+ @BeforeEach
+ fun setUpProject() {
+ checkout = AnnotaterCheckout(root, AnnotaterConfig("26.3", "mappings", null), managed = false)
+ buildProject {
+ java(
+ "net/minecraft/util/Mth.java",
+ """
+ package net.minecraft.util;
+
+ /** Existing class docs. */
+ public class Mth {
+ /** Existing method docs. */
+ public static int clamp(int value, int min, int max) {
+ // Not clamped yet
+ return value;
+ }
+
+ public static final float PI = 3.14F;
+ }
+ """.trimIndent(),
+ )
+ java(
+ "net/minecraft/util/Ticker.java",
+ """
+ package net.minecraft.util;
+
+ public class Ticker {
+ public void tick() {
+ class Step {
+ int count;
+ }
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ }
+ };
+ }
+ }
+ """.trimIndent(),
+ )
+ java(
+ "net/minecraft/world/level/Level.java",
+ """
+ package net.minecraft.world.level;
+
+ public class Level {
+ public boolean addEntity(net.minecraft.util.Ticker> ticker, String[] names, int count) {
+ return true ;
+ }
+ }
+ """.trimIndent(),
+ )
+ }
+ }
+
+ private fun findMember(className: String, name: String? = null): PsiMember {
+ val clazz = JavaPsiFacade.getInstance(project).findClass(className, GlobalSearchScope.allScope(project))!!
+ return when (name) {
+ null -> clazz
+ else -> clazz.findMethodsByName(name, false).firstOrNull() ?: clazz.findFieldByName(name, false)!!
+ }
+ }
+
+ /**
+ * Tests use temporary code style settings, which code style settings modifiers aren't applied to.
+ */
+ private fun withAnnotaterCodeStyle(action: () -> Unit) {
+ val settings = TransientCodeStyleSettings(fixture.file.virtualFile, project, CodeStyle.getSettings(project))
+ AnnotaterJavadocCodeStyleSettingsModifier().modifySettings(settings, fixture.file)
+ CodeStyle.doWithTemporarySettings(project, settings, Runnable(action))
+ }
+
+ private val pi = AnnotaterJavadocTarget.FieldTarget("net/minecraft/util/Mth", "PI", "F")
+
+ private fun clampCopy(javadoc: String?, placeholderFor: AnnotaterJavadocTarget? = null) =
+ AnnotaterJavadocSourceCopy.create(findMember("net.minecraft.util.Mth", "clamp"), placeholderFor) {
+ if (it == clamp) javadoc else null
+ }!!
+
+ @Test
+ @DisplayName("Source copy replaces the existing Javadocs with Markdown annotater Javadocs")
+ fun sourceCopyText() {
+ val copy = clampCopy("Clamps a value.\n\n@param value the value")
+ assertEquals(
+ """
+ package net.minecraft.util;
+
+ public class Mth {
+ /// Clamps a value.
+ ///
+ /// @param value the value
+ public static int clamp(int value, int min, int max) {
+ // Not clamped yet
+ return value;
+ }
+
+ public static final float PI = 3.14F;
+ }
+ """.trimIndent(),
+ copy.text,
+ )
+ assertEquals("Mth.java", copy.fileName)
+ assertEquals(listOf(AnnotaterJavadocTarget.ClassTarget("net/minecraft/util/Mth"), clamp, pi), copy.targets)
+ }
+
+ @Test
+ @DisplayName("Local classes and members of local and anonymous classes can be documented")
+ fun localAndAnonymousClasses() {
+ val copy = AnnotaterJavadocSourceCopy.create(findMember("net.minecraft.util.Ticker")) { null }!!
+ assertEquals(
+ listOf(
+ AnnotaterJavadocTarget.ClassTarget("net/minecraft/util/Ticker"),
+ AnnotaterJavadocTarget.MethodTarget("net/minecraft/util/Ticker", "tick", "()V"),
+ AnnotaterJavadocTarget.ClassTarget("net/minecraft/util/Ticker\$1Step"),
+ AnnotaterJavadocTarget.FieldTarget("net/minecraft/util/Ticker\$1Step", "count", "I"),
+ AnnotaterJavadocTarget.MethodTarget("net/minecraft/util/Ticker\$1", "run", "()V"),
+ ),
+ // Type parameters and anonymous classes are also PsiClasses, but aren't declarations that can be documented
+ copy.targets,
+ )
+ assertEquals("net/minecraft/util/Ticker", copy.outerClass)
+ }
+
+ @Test
+ @DisplayName("Source copy adds a placeholder Javadoc to the edited member")
+ fun sourceCopyPlaceholder() {
+ val copy = clampCopy(null, placeholderFor = clamp)
+ assertTrue(copy.text.contains("public class Mth {\n /// \n public static int clamp("), copy.text)
+ }
+
+ @Test
+ @DisplayName("Javadocs are extracted from Markdown doc comments")
+ fun extract() {
+ val copy = clampCopy("Clamps a value.\n\n@param value the value")
+ val file = copy.createPsiFile(project)!!
+ val method = copy.memberOf(file, clamp) as PsiMethod
+ assertTrue(method.docComment!!.isMarkdownComment)
+ assertEquals(clamp, copy.targetOf(file, method))
+ assertEquals(
+ AnnotaterJavadocSourceCopy.ExtractResult.Success(
+ mapOf(
+ AnnotaterJavadocTarget.ClassTarget("net/minecraft/util/Mth") to null,
+ pi to null,
+ clamp to "Clamps a value.\n\n@param value the value",
+ ),
+ ),
+ // The comment in the method body is part of the original source
+ copy.extractJavadocs(file) { it.substring(file.text) == "// Not clamped yet" },
+ )
+ }
+
+ @Test
+ @DisplayName("Traditional Javadoc comments are rejected")
+ fun rejectTraditionalJavadoc() {
+ val copy = clampCopy("Clamps a value.")
+ val changed = AnnotaterJavadocSourceCopy(
+ copy.fileName,
+ copy.text.replace("/// Clamps a value.", "/** Clamps a value. */"),
+ copy.targets,
+ copy.languageLevel,
+ )
+ val result = changed.extractJavadocs(changed.createPsiFile(project)!!)
+ assertInstanceOf(AnnotaterJavadocSourceCopy.ExtractResult.Error::class.java, result)
+ }
+
+ private fun startEditing(copy: AnnotaterJavadocSourceCopy, target: AnnotaterJavadocTarget) =
+ AnnotaterJavadocInlineEditor.start(
+ project,
+ AnnotaterJavadocVirtualFile(checkout, copy, target),
+ )!!
+
+ @Test
+ @DisplayName("Editing the Javadoc saves it to the annotater checkout")
+ fun save() {
+ val inlineEditor = startEditing(clampCopy(null, placeholderFor = clamp), clamp)
+ val document = FileDocumentManager.getInstance().getDocument(inlineEditor.file)!!
+ try {
+ WriteCommandAction.runWriteCommandAction(project) {
+ val offset = document.text.indexOf("/// ") + 4
+ document.insertString(offset, "Clamps a value.")
+ }
+ assertTrue(inlineEditor.save().get(10, TimeUnit.SECONDS))
+ assertEquals(
+ "CLASS net/minecraft/util/Mth\n\tMETHOD clamp (III)I\n\t\tCOMMENT Clamps a value.\n",
+ root.resolve("mappings/net/minecraft/util/Mth.mapping").readText(),
+ )
+ } finally {
+ Disposer.dispose(inlineEditor)
+ }
+ }
+
+ @Test
+ @DisplayName("Only the edited Javadoc is editable")
+ fun guards() {
+ val inlineEditor = startEditing(clampCopy("Clamps a value."), clamp)
+ val document = FileDocumentManager.getInstance().getDocument(inlineEditor.file)!!
+ try {
+ val text = document.text
+ fun guarded(start: Int, end: Int) = document.getRangeGuard(start, end) != null
+ val comment = text.indexOf("/// Clamps a value.")
+ val commentEnd = comment + "/// Clamps a value.".length
+ assertFalse(guarded(comment, commentEnd))
+ assertTrue(guarded(commentEnd, commentEnd + 1), "The line break after the comment is read-only")
+ assertTrue(guarded(text.indexOf("return value"), text.indexOf("return value") + 1))
+ assertTrue(guarded(text.indexOf("PI"), text.indexOf("PI") + 1))
+ } finally {
+ Disposer.dispose(inlineEditor)
+ }
+ }
+
+ @Test
+ @DisplayName("Saving doesn't overwrite Javadocs of other members that changed on disk")
+ fun saveOnlyEdited() {
+ checkout.javadocStore.setAll(mapOf(pi to "Pi."))
+ val copy = AnnotaterJavadocSourceCopy.create(findMember("net.minecraft.util.Mth", "clamp"), clamp) {
+ checkout.javadocStore.get(it)
+ }!!
+ val inlineEditor = startEditing(copy, clamp)
+ val document = FileDocumentManager.getInstance().getDocument(inlineEditor.file)!!
+ try {
+ checkout.javadocStore.setAll(mapOf(pi to "Changed on disk."))
+ WriteCommandAction.runWriteCommandAction(project) {
+ document.insertString(document.text.indexOf("/// \n public static int") + 4, "Clamps a value.")
+ }
+ assertTrue(inlineEditor.save().get(10, TimeUnit.SECONDS))
+ checkout.javadocStore.invalidate(clamp.outerClass)
+ assertEquals("Clamps a value.", checkout.javadocStore.get(clamp))
+ assertEquals("Changed on disk.", checkout.javadocStore.get(pi))
+ } finally {
+ Disposer.dispose(inlineEditor)
+ }
+ }
+
+ @Test
+ @DisplayName("The Javadoc is edited in an editor embedded in the class, which only shows the Javadoc")
+ fun inlineEditor() {
+ val method = findMember("net.minecraft.util.Mth", "clamp")
+ fixture.openFileInEditor(method.containingFile.virtualFile)
+ val host = fixture.editor as EditorEx
+ val inlineEditor = startEditing(clampCopy("Clamps a value.\n\n@param value the value"), clamp)
+ try {
+ inlineEditor.show(host, AnnotaterJavadocRendering.displayOffset(method))
+ val editor = inlineEditor.editor!!
+ val document = editor.document
+ // Only the 3 comment lines are visible
+ assertEquals(2, editor.offsetToVisualLine(document.textLength, false))
+ assertEquals(0, editor.offsetToVisualLine(0, false))
+ assertEquals(
+ document.text.indexOf("/// Clamps a value.") + "/// Clamps a value.".length,
+ editor.caretModel.offset,
+ )
+ assertEquals(1, host.inlayModel.getBlockElementsInRange(0, host.document.textLength).size)
+
+ // The end of the document is displayed at the end of the last comment line
+ editor.caretModel.moveToOffset(document.textLength)
+ val lastLine = document.text.indexOf("/// @param value the value") + "/// @param value the value".length
+ assertEquals(lastLine, editor.caretModel.offset)
+ editor.caretModel.moveToOffset(0)
+ val firstLine = document.getLineStartOffset(document.getLineNumber(document.text.indexOf("/// Clamps")))
+ assertEquals(firstLine, editor.caretModel.offset)
+
+ WriteCommandAction.runWriteCommandAction(project) {
+ document.insertString(lastLine, " Or not.")
+ }
+ val edited = document.text
+ // Undo uses the embedded editor, not the host editor it's embedded in
+ val dataManager = DataManager.getInstance() as HeadlessDataManager
+ HeadlessDataManager.fallbackToProductionDataManager(inlineEditor)
+ dataManager.setTestDataProvider(null, inlineEditor)
+ val fileEditor = DataManager.getInstance().getDataContext(editor.contentComponent)
+ .getData(PlatformCoreDataKeys.FILE_EDITOR) as TextEditor
+ assertSame(editor, fileEditor.editor)
+ val undoManager = UndoManager.getInstance(project)
+ assertTrue(undoManager.isUndoAvailable(fileEditor))
+ undoManager.undo(fileEditor)
+ assertFalse(document.text.contains("Or not."))
+ undoManager.redo(fileEditor)
+ assertEquals(edited, document.text)
+
+ assertTrue(inlineEditor.finish())
+ assertNull(AnnotaterJavadocInlineEditor.current(project))
+ assertTrue(host.inlayModel.getBlockElementsInRange(0, host.document.textLength).isEmpty())
+ } finally {
+ Disposer.dispose(inlineEditor)
+ }
+ }
+
+ @Test
+ @DisplayName("Editing can't be finished while the Javadoc can't be saved")
+ fun finishInvalid() {
+ val inlineEditor = startEditing(clampCopy("Clamps a value."), clamp)
+ val document = FileDocumentManager.getInstance().getDocument(inlineEditor.file)!!
+ try {
+ WriteCommandAction.runWriteCommandAction(project) {
+ val start = document.text.indexOf("/// Clamps a value.")
+ document.replaceString(start, start + "/// Clamps a value.".length, "/** Clamps a value. */")
+ }
+ assertFalse(inlineEditor.finish())
+ assertSame(inlineEditor, AnnotaterJavadocInlineEditor.current(project))
+ assertTrue(inlineEditor.finish(force = true))
+ assertNull(AnnotaterJavadocInlineEditor.current(project))
+ } finally {
+ Disposer.dispose(inlineEditor)
+ }
+ }
+
+ @Test
+ @DisplayName("Intentions are only offered in the editable Javadocs")
+ fun intentionFilter() {
+ fixture.openFileInEditor(AnnotaterJavadocVirtualFile(checkout, clampCopy("Clamps a value."), clamp))
+ val file = fixture.file
+ val text = fixture.editor.document.text
+ val intention = object : IntentionAction {
+ override fun getText() = "Test"
+ override fun getFamilyName() = text
+ override fun isAvailable(project: Project, editor: Editor?, file: PsiFile?) = true
+ override fun invoke(project: Project, editor: Editor?, file: PsiFile?) {}
+ override fun startInWriteAction() = true
+ }
+ val filter = AnnotaterJavadocIntentionActionFilter()
+ assertTrue(filter.accept(intention, file, text.indexOf("Clamps")))
+ assertFalse(filter.accept(intention, file, text.indexOf("return value")))
+ assertFalse(filter.accept(intention, file, text.indexOf("// Not clamped")))
+ assertFalse(filter.accept(intention, file, -1))
+ }
+
+ @Test
+ @DisplayName("The documented declaration's intentions aren't offered in its Javadoc, unlike the Javadoc's own")
+ fun declarationIntentions() {
+ val javadocIntention = object : PsiElementBaseIntentionAction() {
+ override fun getText() = "Javadoc intention"
+ override fun getFamilyName() = text
+ override fun isAvailable(project: Project, editor: Editor, element: PsiElement) =
+ PsiTreeUtil.getParentOfType(element, PsiDocComment::class.java) != null
+ override fun invoke(project: Project, editor: Editor, element: PsiElement) {}
+ }
+ IntentionManager.getInstance().addAction(javadocIntention)
+ Disposer.register(fixture.testRootDisposable) {
+ IntentionManager.getInstance().unregisterIntention(javadocIntention)
+ }
+ fixture.enableInspections(AnnotaterJavadocUnqualifiedReferenceInspection::class)
+ fixture.openFileInEditor(AnnotaterJavadocVirtualFile(checkout, clampCopy("Clamps a [String] value."), clamp))
+ val text = fixture.editor.document.text
+ fixture.editor.caretModel.moveToOffset(text.indexOf("Clamps"))
+ var intentions = fixture.availableIntentions.map { it.text }
+ assertTrue("Javadoc intention" in intentions, intentions.toString())
+ assertFalse("Change access modifier" in intentions, intentions.toString())
+ assertFalse("Generate overloaded method with default parameter values" in intentions, intentions.toString())
+ fixture.editor.caretModel.moveToOffset(text.indexOf("String]"))
+ intentions = fixture.availableIntentions.map { it.text }
+ assertTrue("Replace with 'java.lang.String'" in intentions, intentions.toString())
+ assertFalse("Change access modifier" in intentions, intentions.toString())
+ }
+
+ @Test
+ @DisplayName("Unqualified class references are reported and fixed")
+ fun unqualifiedReferences() {
+ val copy = clampCopy(
+ "See [Mth], [net.minecraft.util.Mth#clamp], [#clamp] and [String].\n\n@see net.minecraft.world.level.Level",
+ )
+ fixture.enableInspections(AnnotaterJavadocUnqualifiedReferenceInspection::class)
+ fixture.openFileInEditor(AnnotaterJavadocVirtualFile(checkout, copy, clamp))
+
+ val warnings = fixture.doHighlighting(HighlightSeverity.WARNING)
+ .filter { it.description?.contains("fully qualified") == true }
+ .map { fixture.editor.document.getText(TextRange(it.startOffset, it.endOffset)) }
+ assertEquals(listOf("Mth", "String"), warnings)
+
+ fixture.editor.caretModel.moveToOffset(fixture.editor.document.text.indexOf("[Mth]") + 2)
+ // launchAction can't be used, since it tries to make the light file read only on disk
+ val fix = fixture.findSingleIntention("Replace with 'net.minecraft.util.Mth'")
+ WriteCommandAction.runWriteCommandAction(project) { fix.invoke(project, fixture.editor, fixture.file) }
+ assertTrue(fixture.editor.document.text.contains("See [net.minecraft.util.Mth], "))
+ }
+
+ @Test
+ @DisplayName("Class name completion inserts fully qualified names")
+ fun completion() {
+ val copy = clampCopy("See [Lev].")
+ fixture.openFileInEditor(AnnotaterJavadocVirtualFile(checkout, copy, clamp))
+ fixture.editor.caretModel.moveToOffset(fixture.editor.document.text.indexOf("Lev]") + 3)
+ val lookup = fixture.completeBasic()
+ // java.util.logging.Level is also offered
+ val level = lookup.single { (it.psiElement as? PsiClass)?.qualifiedName == "net.minecraft.world.level.Level" }
+ fixture.lookup.currentItem = level
+ fixture.finishLookup(Lookup.NORMAL_SELECT_CHAR)
+ assertTrue(
+ fixture.editor.document.text.contains("/// See [net.minecraft.world.level.Level]."),
+ fixture.editor.document.text,
+ )
+ }
+
+ @Test
+ @DisplayName("Method completion inserts fully qualified parameter types")
+ fun methodParameterCompletion() {
+ val copy = clampCopy("See [net.minecraft.world.level.Level#addEn].")
+ fixture.openFileInEditor(AnnotaterJavadocVirtualFile(checkout, copy, clamp))
+ fixture.editor.caretModel.moveToOffset(fixture.editor.document.text.indexOf("#addEn]") + 6)
+ TemplateManagerImpl.setTemplateTesting(fixture.testRootDisposable)
+ withAnnotaterCodeStyle { fixture.completeBasic() }
+ // The parameters can still be edited with the template Java starts for them
+ val templateState = TemplateManagerImpl.getTemplateState(fixture.editor)
+ assertNotNull(templateState)
+ val parameters = fixture.editor.document.getText(templateState!!.getVariableRange("PARAMETERS")!!)
+ assertTrue(parameters.contains("net.minecraft.util.Ticker, java.lang.String\\[\\], int"), parameters)
+ templateState.gotoEnd(false)
+ val text = fixture.editor.document.text
+ assertTrue(
+ text.contains(
+ "See [net.minecraft.world.level.Level#addEntity(net.minecraft.util.Ticker, java.lang.String\\[\\], int)].",
+ ),
+ text,
+ )
+ }
+
+ @Test
+ @DisplayName("Quick documentation shows the annotater Javadoc instead of the existing one")
+ fun quickDocumentation() {
+ val clampMethod = findMember("net.minecraft.util.Mth", "clamp")
+ val doc = AnnotaterJavadocRendering.generateDoc(clampMethod, "Clamps a **value**.")!!
+ assertTrue("Clamps a value." in doc || "Clamps a value." in doc, doc)
+ assertFalse("Existing method docs" in doc, doc)
+
+ val hidden = AnnotaterJavadocRendering.generateDoc(clampMethod, null)!!
+ assertFalse("Existing method docs" in hidden, hidden)
+ }
+
+ @Test
+ @DisplayName("Displayed Javadocs are highlighted like doc comments in the editor")
+ fun editorHighlights() {
+ val javadoc = "Clamps a value.\n\nSee [#clamp(int, int, int)]."
+ val highlights = decorateJavadoc(javadoc, shortenClassNames = true)?.highlights.orEmpty()
+ val lines = javadoc.lines().map { if (it.isEmpty()) "///" else "/// $it" }
+ assertEquals(
+ listOf(2 to "clamp"),
+ highlights.map { it.range }.map { it.line to lines[it.line].substring(it.startColumn, it.endColumn) },
+ )
+ }
+
+ @Test
+ @DisplayName("Displayed Javadocs can hide the packages of class names")
+ fun shortenedClassNames() {
+ val javadoc = "See [net.minecraft.util.Mth#clamp(int, int, int)] and [net.minecraft.util.Ticker], " +
+ "not [net.minecraft.util]."
+ fun hidden(shortenClassNames: Boolean) = decorateJavadoc(javadoc, shortenClassNames)?.hiddenRanges.orEmpty()
+ .map { "/// $javadoc".substring(it.startColumn, it.endColumn) }
+ assertEquals(listOf("net.minecraft.util.", "net.minecraft.util."), hidden(shortenClassNames = true))
+ assertEquals(emptyList(), hidden(shortenClassNames = false))
+ }
+
+ private fun decorateJavadoc(javadoc: String, shortenClassNames: Boolean) =
+ AnnotaterJavadocRendering.decorateJavadocs(
+ findMember("net.minecraft.util.Mth", "clamp"),
+ { if (it == clamp) javadoc else null },
+ EditorColorsManager.getInstance().globalScheme,
+ shortenClassNames,
+ )[clamp]
+
+ // TODO: uncomment in 2026.3
+ // @Test
+ // @DisplayName("Inserting a Javadoc stub formats it")
+ // fun javadocStub() {
+ // val inlineEditor = startEditing(clampCopy(null, placeholderFor = clamp), clamp)
+ // try {
+ // fixture.openFileInEditor(inlineEditor.file)
+ // fixture.editor.caretModel.moveToOffset(fixture.editor.document.text.indexOf("/// ") + 4)
+ // withAnnotaterCodeStyle { fixture.completeBasic() }
+ // fixture.lookup.currentItem = fixture.lookupElements!!.single { it.lookupString == "Insert Javadoc Stub" }
+ // withAnnotaterCodeStyle { fixture.finishLookup(Lookup.NORMAL_SELECT_CHAR) }
+ // val text = fixture.editor.document.text
+ // assertTrue(
+ // text.contains(
+ // " /// \n /// @param value\n /// @param min\n /// @param max\n /// @return\n" +
+ // " public static int clamp(",
+ // ),
+ // text,
+ // )
+ // } finally {
+ // Disposer.dispose(inlineEditor)
+ // }
+ // }
+
+ @Test
+ @DisplayName("Formatting only changes the edited Javadoc")
+ fun formatting() {
+ val addEntity = AnnotaterJavadocTarget.MethodTarget(
+ "net/minecraft/world/level/Level",
+ "addEntity",
+ "(Lnet/minecraft/util/Ticker;[Ljava/lang/String;I)Z",
+ )
+ val copy = AnnotaterJavadocSourceCopy.create(findMember("net.minecraft.world.level.Level", "addEntity"), null) {
+ if (it == addEntity) "Adds an entity." else null
+ }!!
+ val inlineEditor = startEditing(copy, addEntity)
+ val document = FileDocumentManager.getInstance().getDocument(inlineEditor.file)!!
+ try {
+ WriteCommandAction.runWriteCommandAction(project) {
+ val offset = document.text.indexOf("/// Adds an entity.") + "/// Adds an entity.".length
+ document.insertString(offset, "\n /// More.")
+ val documentManager = PsiDocumentManager.getInstance(project)
+ documentManager.commitDocument(document)
+ CodeStyleManager.getInstance(project).reformat(documentManager.getPsiFile(document)!!)
+ }
+ val text = document.text
+ assertTrue(text.contains(" /// Adds an entity.\n /// More.\n"), text)
+ assertTrue(text.contains("return true ;"), text)
+ } finally {
+ Disposer.dispose(inlineEditor)
+ }
+ }
+}
Index: src/test/kotlin/platform/fabric/annotater/AnnotaterJavadocStoreTest.kt
===================================================================
--- src/test/kotlin/platform/fabric/annotater/AnnotaterJavadocStoreTest.kt (revision 19b7b6f903071157b5202adf613d68c13cf0417f)
+++ src/test/kotlin/platform/fabric/annotater/AnnotaterJavadocStoreTest.kt (revision 19b7b6f903071157b5202adf613d68c13cf0417f)
@@ -0,0 +1,141 @@
+/*
+ * Minecraft Development for IntelliJ
+ *
+ * https://mcdev.io/
+ *
+ * Copyright (C) 2026 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 .
+ */
+
+package com.demonwav.mcdev.platform.fabric.annotater
+
+import com.demonwav.mcdev.platform.fabric.annotater.javadoc.AnnotaterJavadocStore
+import com.demonwav.mcdev.platform.fabric.annotater.javadoc.AnnotaterJavadocTarget.ClassTarget
+import com.demonwav.mcdev.platform.fabric.annotater.javadoc.AnnotaterJavadocTarget.FieldTarget
+import com.demonwav.mcdev.platform.fabric.annotater.javadoc.AnnotaterJavadocTarget.MethodTarget
+import java.nio.file.Path
+import kotlin.io.path.createDirectories
+import kotlin.io.path.exists
+import kotlin.io.path.readText
+import kotlin.io.path.writeText
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Assertions.assertFalse
+import org.junit.jupiter.api.Assertions.assertNull
+import org.junit.jupiter.api.DisplayName
+import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.io.TempDir
+
+@DisplayName("Annotater Javadoc Store Tests")
+class AnnotaterJavadocStoreTest {
+ @TempDir
+ lateinit var mappings: Path
+
+ private val mth = "net/minecraft/util/Mth"
+
+ // The only file on annotater's 26.3 branch at the time of writing
+ private val mthMapping = """
+ |CLASS net/minecraft/util/Mth
+ | COMMENT Math utilities.
+ | METHOD clamp (III)I
+ | COMMENT Clamps `value` between `min` and `max` (inclusive).
+ | COMMENT
+ | COMMENT @param value the value to clamp
+ | COMMENT @param min the minimum value
+ | COMMENT @param max the maximum value
+ | COMMENT @return the clamped value
+ |
+ """.trimMargin()
+
+ private fun writeMth(): Path {
+ val file = mappings.resolve("$mth.mapping")
+ file.parent.createDirectories()
+ file.writeText(mthMapping)
+ return file
+ }
+
+ @Test
+ @DisplayName("Reads class and method comments")
+ fun read() {
+ writeMth()
+ val store = AnnotaterJavadocStore(mappings)
+ assertEquals("Math utilities.", store.get(ClassTarget(mth)))
+ assertEquals(
+ """
+ Clamps `value` between `min` and `max` (inclusive).
+
+ @param value the value to clamp
+ @param min the minimum value
+ @param max the maximum value
+ @return the clamped value
+ """.trimIndent(),
+ store.get(MethodTarget(mth, "clamp", "(III)I")),
+ )
+ assertNull(store.get(MethodTarget(mth, "clamp", "(FFF)F")))
+ }
+
+ @Test
+ @DisplayName("Rewriting unchanged comments produces an identical file")
+ fun roundTrip() {
+ val file = writeMth()
+ val store = AnnotaterJavadocStore(mappings)
+ store.set(ClassTarget(mth), store.get(ClassTarget(mth)))
+ assertEquals(mthMapping, file.readText())
+ }
+
+ @Test
+ @DisplayName("Adding a comment keeps the rest of the file")
+ fun addComment() {
+ val file = writeMth()
+ val store = AnnotaterJavadocStore(mappings)
+ store.set(FieldTarget(mth, "PI", "F"), "Pi as a float.")
+ assertEquals(
+ mthMapping.replace("\tMETHOD clamp", "\tFIELD PI F\n\t\tCOMMENT Pi as a float.\n\tMETHOD clamp"),
+ file.readText(),
+ )
+ assertEquals("Pi as a float.", AnnotaterJavadocStore(mappings).get(FieldTarget(mth, "PI", "F")))
+ }
+
+ @Test
+ @DisplayName("Removing the last comment deletes the file")
+ fun removeComments() {
+ val file = writeMth()
+ val store = AnnotaterJavadocStore(mappings)
+ store.set(MethodTarget(mth, "clamp", "(III)I"), null)
+ assertEquals("CLASS net/minecraft/util/Mth\n\tCOMMENT Math utilities.\n", file.readText())
+ store.set(ClassTarget(mth), "")
+ assertFalse(file.exists())
+ }
+
+ @Test
+ @DisplayName("Inner classes are stored in their outer class's file")
+ fun innerClass() {
+ val store = AnnotaterJavadocStore(mappings)
+ val outer = "net/minecraft/world/level/Level"
+ store.set(ClassTarget("$outer\$Inner"), "An inner class.")
+ store.set(ClassTarget(outer), "The level.")
+ // Enigma nests inner classes inside their outer class
+ assertEquals(
+ "CLASS $outer\n\tCOMMENT The level.\n\tCLASS Inner\n\t\tCOMMENT An inner class.\n",
+ mappings.resolve("$outer.mapping").readText(),
+ )
+ assertEquals("An inner class.", AnnotaterJavadocStore(mappings).get(ClassTarget("$outer\$Inner")))
+ }
+
+ @Test
+ @DisplayName("Outer class names")
+ fun outerClassName() {
+ assertEquals("a/B", ClassTarget("a/B\$C\$D").outerClass)
+ assertEquals("a/\$B", ClassTarget("a/\$B").outerClass)
+ }
+}