|
| 1 | +/* |
| 2 | + * Minecraft Dev for IntelliJ Annotations |
| 3 | + * |
| 4 | + * https://minecraftdev.org |
| 5 | + * |
| 6 | + * Copyright (c) 2023 minecraft-dev |
| 7 | + * |
| 8 | + * MIT License |
| 9 | + */ |
| 10 | + |
| 11 | +package com.demonwav.mcdev.annotations; |
| 12 | + |
| 13 | +import java.lang.annotation.Documented; |
| 14 | +import java.lang.annotation.ElementType; |
| 15 | +import java.lang.annotation.Retention; |
| 16 | +import java.lang.annotation.RetentionPolicy; |
| 17 | +import java.lang.annotation.Target; |
| 18 | + |
| 19 | +/** |
| 20 | + * Used to tell MinecraftDev that a {@code String} parameter to a method should point to an entry in the mod's |
| 21 | + * translation files. If there is an {@code Object} varargs parameter to that method, it is assumed that those are the |
| 22 | + * arguments to this translation. |
| 23 | + * |
| 24 | + * <p>Example: |
| 25 | + * <pre> |
| 26 | + * {@code |
| 27 | + * public static Component errorMessage(@Translatable String translationKey, Object... args) { |
| 28 | + * return Component.translatable(translationKey, args).styled(style -> style.withColor(Formatting.RED)); |
| 29 | + * } |
| 30 | + * } |
| 31 | + * </pre> |
| 32 | + */ |
| 33 | +@Retention(RetentionPolicy.CLASS) |
| 34 | +@Target(ElementType.PARAMETER) |
| 35 | +@Documented |
| 36 | +public @interface Translatable { |
| 37 | + /** |
| 38 | + * Defaults to {@code true}. If this value is {@code false}, MinecraftDev will not create a warning if the |
| 39 | + * translation key doesn't point to a valid translation. This is intended for use when a {@code String} <i>maybe</i> |
| 40 | + * points to a translation, but not necessarily. |
| 41 | + */ |
| 42 | + boolean required() default true; |
| 43 | + |
| 44 | + /** |
| 45 | + * Whether to fold the entire method call. Defaults to {@code false}. |
| 46 | + */ |
| 47 | + boolean foldMethod() default false; |
| 48 | + |
| 49 | + /** |
| 50 | + * The prefix that will be added to this argument. |
| 51 | + * |
| 52 | + * <p>Example: |
| 53 | + * <pre> |
| 54 | + * {@code |
| 55 | + * public static Component itemTranslatable(@Translatable(prefix = "item.") String translationKey) { |
| 56 | + * return Component.translatable("item." + translationKey); |
| 57 | + * } |
| 58 | + * } |
| 59 | + * </pre> |
| 60 | + */ |
| 61 | + String prefix() default ""; |
| 62 | + |
| 63 | + /** |
| 64 | + * The suffix that will be added to this argument. |
| 65 | + * |
| 66 | + * <p>Example: |
| 67 | + * <pre> |
| 68 | + * {@code |
| 69 | + * public static Component translatableWithSuffix(@Translatable(prefix = ".suffix") String translationKey) { |
| 70 | + * return Component.translatable(translationKey + ".suffix"); |
| 71 | + * } |
| 72 | + * } |
| 73 | + * </pre> |
| 74 | + */ |
| 75 | + String suffix() default ""; |
| 76 | +} |
0 commit comments