Skip to content

Commit 07de16f

Browse files
Add external annotations to Minecraft libraries (#2130)
* Add external annotations to Minecraft libraries * Don't remove previous annotation roots
1 parent 11e17b9 commit 07de16f

File tree

11 files changed

+407
-1
lines changed

11 files changed

+407
-1
lines changed

build.gradle.kts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import org.gradle.internal.jvm.Jvm
2424
import org.gradle.internal.os.OperatingSystem
2525
import org.jetbrains.gradle.ext.settings
2626
import org.jetbrains.gradle.ext.taskTriggers
27+
import org.jetbrains.intellij.tasks.PrepareSandboxTask
2728
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2829
import org.jlleitschuh.gradle.ktlint.tasks.BaseKtLintCheckTask
2930
import org.jlleitschuh.gradle.ktlint.tasks.KtLintFormatTask
@@ -72,6 +73,12 @@ val gradleToolingExtensionJar = tasks.register<Jar>(gradleToolingExtensionSource
7273
archiveClassifier.set("gradle-tooling-extension")
7374
}
7475

76+
val externalAnnotationsJar = tasks.register<Jar>("externalAnnotationsJar") {
77+
from("externalAnnotations")
78+
destinationDirectory.set(layout.buildDirectory.dir("externalAnnotations"))
79+
archiveFileName.set("externalAnnotations.jar")
80+
}
81+
7582
repositories {
7683
maven("https://repo.denwav.dev/repository/maven-public/")
7784
maven("https://maven.fabricmc.net/") {
@@ -298,6 +305,9 @@ license {
298305
register("grammars") {
299306
files.from(project.fileTree("src/main/grammars"))
300307
}
308+
register("externalAnnotations") {
309+
files.from(project.fileTree("externalAnnotations"))
310+
}
301311
}
302312
}
303313

@@ -356,6 +366,12 @@ tasks.register("cleanSandbox", Delete::class) {
356366
delete(layout.projectDirectory.dir(".sandbox"))
357367
}
358368

369+
tasks.withType<PrepareSandboxTask> {
370+
from(externalAnnotationsJar) {
371+
into("Minecraft Development/lib/resources")
372+
}
373+
}
374+
359375
tasks.runIde {
360376
maxHeapSize = "4G"
361377

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!--
2+
Minecraft Development for IntelliJ
3+
4+
https://mcdev.io/
5+
6+
Copyright (C) 2023 minecraft-dev
7+
8+
This program is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU Lesser General Public License as published
10+
by the Free Software Foundation, version 3.0 only.
11+
12+
This program is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public License
18+
along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
-->
20+
21+
<root>
22+
<item name="com.mojang.blaze3d.platform.InputConstants com.mojang.blaze3d.platform.InputConstants.Key getKey(java.lang.String) 0">
23+
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
24+
</item>
25+
</root>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<!--
2+
Minecraft Development for IntelliJ
3+
4+
https://mcdev.io/
5+
6+
Copyright (C) 2023 minecraft-dev
7+
8+
This program is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU Lesser General Public License as published
10+
by the Free Software Foundation, version 3.0 only.
11+
12+
This program is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public License
18+
along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
-->
20+
21+
<root>
22+
<item name="net.minecraft.client.KeyMapping KeyMapping(java.lang.String, int, java.lang.String) 0">
23+
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
24+
</item>
25+
<item name="net.minecraft.client.KeyMapping KeyMapping(java.lang.String, int, java.lang.String) 2">
26+
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
27+
</item>
28+
<item name="net.minecraft.client.KeyMapping KeyMapping(java.lang.String, com.mojang.blaze3d.platform.InputConstants.Type, int, java.lang.String) 0">
29+
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
30+
</item>
31+
<item name="net.minecraft.client.KeyMapping KeyMapping(java.lang.String, com.mojang.blaze3d.platform.InputConstants.Type, int, java.lang.String) 3">
32+
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
33+
</item>
34+
<item name="net.minecraft.client.KeyMapping KeyMapping(java.lang.String, net.minecraftforge.client.settings.IKeyConflictContext, com.mojang.blaze3d.platform.InputConstants.Type, int, java.lang.String) 0">
35+
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
36+
</item>
37+
<item name="net.minecraft.client.KeyMapping KeyMapping(java.lang.String, net.minecraftforge.client.settings.IKeyConflictContext, com.mojang.blaze3d.platform.InputConstants.Type, int, java.lang.String) 4">
38+
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
39+
</item>
40+
<item name="net.minecraft.client.KeyMapping KeyMapping(java.lang.String, net.minecraftforge.client.settings.IKeyConflictContext, com.mojang.blaze3d.platform.InputConstants.Key, java.lang.String) 0">
41+
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
42+
</item>
43+
<item name="net.minecraft.client.KeyMapping KeyMapping(java.lang.String, net.minecraftforge.client.settings.IKeyConflictContext, com.mojang.blaze3d.platform.InputConstants.Key, java.lang.String) 3">
44+
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
45+
</item>
46+
<item name="net.minecraft.client.KeyMapping KeyMapping(java.lang.String, net.minecraftforge.client.settings.IKeyConflictContext, net.minecraftforge.client.settings.KeyModifier, com.mojang.blaze3d.platform.InputConstants.Type, int, java.lang.String) 0">
47+
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
48+
</item>
49+
<item name="net.minecraft.client.KeyMapping KeyMapping(java.lang.String, net.minecraftforge.client.settings.IKeyConflictContext, net.minecraftforge.client.settings.KeyModifier, com.mojang.blaze3d.platform.InputConstants.Type, int, java.lang.String) 5">
50+
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
51+
</item>
52+
<item name="net.minecraft.client.KeyMapping KeyMapping(java.lang.String, net.minecraftforge.client.settings.IKeyConflictContext, net.minecraftforge.client.settings.KeyModifier, com.mojang.blaze3d.platform.InputConstants.Key, java.lang.String) 0">
53+
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
54+
</item>
55+
<item name="net.minecraft.client.KeyMapping KeyMapping(java.lang.String, net.minecraftforge.client.settings.IKeyConflictContext, net.minecraftforge.client.settings.KeyModifier, com.mojang.blaze3d.platform.InputConstants.Key, java.lang.String) 4">
56+
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
57+
</item>
58+
</root>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!--
2+
Minecraft Development for IntelliJ
3+
4+
https://mcdev.io/
5+
6+
Copyright (C) 2023 minecraft-dev
7+
8+
This program is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU Lesser General Public License as published
10+
by the Free Software Foundation, version 3.0 only.
11+
12+
This program is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public License
18+
along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
-->
20+
21+
<root>
22+
<item name="net.minecraft.client.resources.language.I18n java.lang.String get(java.lang.String, java.lang.Object...) 0">
23+
<annotation name="com.demonwav.mcdev.annotations.Translatable">
24+
<val name="foldMethod" val="true"/>
25+
</annotation>
26+
</item>
27+
<item name="net.minecraft.client.resources.language.I18n boolean exists(java.lang.String) 0">
28+
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
29+
</item>
30+
</root>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!--
2+
Minecraft Development for IntelliJ
3+
4+
https://mcdev.io/
5+
6+
Copyright (C) 2023 minecraft-dev
7+
8+
This program is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU Lesser General Public License as published
10+
by the Free Software Foundation, version 3.0 only.
11+
12+
This program is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public License
18+
along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
-->
20+
21+
<root>
22+
<item name="net.minecraft.command.CommandException CommandException(java.lang.String, java.lang.Object...) 0">
23+
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
24+
</item>
25+
</root>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!--
2+
Minecraft Development for IntelliJ
3+
4+
https://mcdev.io/
5+
6+
Copyright (C) 2023 minecraft-dev
7+
8+
This program is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU Lesser General Public License as published
10+
by the Free Software Foundation, version 3.0 only.
11+
12+
This program is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public License
18+
along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
-->
20+
21+
<root>
22+
<item name="net.minecraft.network.chat.TranslatableComponent TranslatableComponent(java.lang.String) 0">
23+
<annotation name="com.demonwav.mcdev.annotations.Translatable">
24+
<val name="foldMethod" val="true"/>
25+
</annotation>
26+
</item>
27+
<item name="net.minecraft.network.chat.TranslatableComponent TranslatableComponent(java.lang.String, java.lang.Object...) 0">
28+
<annotation name="com.demonwav.mcdev.annotations.Translatable">
29+
<val name="foldMethod" val="true"/>
30+
</annotation>
31+
</item>
32+
<item name="net.minecraft.network.chat.Component net.minecraft.network.chat.MutableComponent translatable(java.lang.String) 0">
33+
<annotation name="com.demonwav.mcdev.annotations.Translatable">
34+
<val name="foldMethod" val="true"/>
35+
</annotation>
36+
</item>
37+
<item name="net.minecraft.network.chat.Component net.minecraft.network.chat.MutableComponent translatable(java.lang.String, java.lang.Object...) 0">
38+
<annotation name="com.demonwav.mcdev.annotations.Translatable">
39+
<val name="foldMethod" val="true"/>
40+
</annotation>
41+
</item>
42+
<item name="net.minecraft.network.chat.Component net.minecraft.network.chat.MutableComponent translatableWithFallback(java.lang.String, java.lang.String) 0">
43+
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
44+
</item>
45+
<item name="net.minecraft.network.chat.Component net.minecraft.network.chat.MutableComponent translatableWithFallback(java.lang.String, java.lang.String, java.lang.Object...) 0">
46+
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
47+
</item>
48+
</root>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!--
2+
Minecraft Development for IntelliJ
3+
4+
https://mcdev.io/
5+
6+
Copyright (C) 2023 minecraft-dev
7+
8+
This program is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU Lesser General Public License as published
10+
by the Free Software Foundation, version 3.0 only.
11+
12+
This program is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public License
18+
along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
-->
20+
21+
<root>
22+
<item name="net.minecraftforge.server.command.TextComponentHelper net.minecraft.network.chat.BaseComponent createComponentTranslation(net.minecraft.commands.CommandSource, java.lang.String, java.lang.Object...) 1">
23+
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
24+
</item>
25+
</root>

src/main/kotlin/facet/ProjectReimporter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import com.intellij.openapi.project.Project
3333
object ProjectReimporter {
3434
private val log = logger<ProjectReimporter>()
3535

36-
const val CURRENT_REIMPORT_VERSION = 0
36+
const val CURRENT_REIMPORT_VERSION = 1
3737

3838
fun needsReimport(facet: MinecraftFacet) =
3939
facet.configuration.state.projectReimportVersion < CURRENT_REIMPORT_VERSION
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Minecraft Development for IntelliJ
3+
*
4+
* https://mcdev.io/
5+
*
6+
* Copyright (C) 2023 minecraft-dev
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published
10+
* by the Free Software Foundation, version 3.0 only.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
package com.demonwav.mcdev.translations.identification
22+
23+
import com.demonwav.mcdev.platform.mcp.framework.MCP_LIBRARY_KIND
24+
import com.intellij.codeInsight.externalAnnotation.location.AnnotationsLocation
25+
import com.intellij.codeInsight.externalAnnotation.location.AnnotationsLocationProvider
26+
import com.intellij.openapi.project.Project
27+
import com.intellij.openapi.roots.OrderRootType
28+
import com.intellij.openapi.roots.libraries.Library
29+
import com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager
30+
31+
class TranslationAnnotationsLocationProvider : AnnotationsLocationProvider {
32+
override fun getLocations(
33+
project: Project,
34+
library: Library,
35+
artifactId: String?,
36+
groupId: String?,
37+
version: String?
38+
): Collection<AnnotationsLocation> {
39+
val isMinecraftLibrary = LibraryPresentationManager.getInstance().isLibraryOfKind(
40+
library.getFiles(OrderRootType.CLASSES).toList(),
41+
MCP_LIBRARY_KIND
42+
)
43+
if (isMinecraftLibrary) {
44+
return listOf(TranslationExternalAnnotationsArtifactsResolver.Util.fakeMavenLocation)
45+
}
46+
return emptyList()
47+
}
48+
}

0 commit comments

Comments
 (0)