annotation refactor

This commit is contained in:
FalsePattern committed 2022-08-06 14:18:55 +02:00
1 parent a19adf283f
commit 28e8a93359
5 files changed
+23 -19

No files matched your search

@@ -38,7 +38,8 @@ import java.lang.annotation.Target;
* fields or non-override methods you may have added if you want to expose those too.
* <p>
* NOTICE: You should no longer use this annotation exclusively on classes themselves, and instead, annotate every single
* public or protected member you want to expose as a public API!
* public or protected member you want to expose as a public API! See the {@link Expose} and {@link Internal} annotations
* for extra info.
* <p>
* Private members will never be considered stable, and can be removed without notice.
* <p>
@@ -48,30 +49,33 @@ import java.lang.annotation.Target;
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(value = {ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR})
@Target(ElementType.TYPE)
@StableAPI(since = "0.6.0")
public @interface StableAPI {
/**
* The version this API was introduced/stabilized in. Used for library version tracking.
*/
@StableAPI(since = "0.6.0") String since();
@StableAPI.Expose
String since();
/**
* You may use this annotation if you want a member to have an equal effective {@link #since()} value as its owner
* class.
* <p>
* Everything else from the {@link StableAPI} class still applies, this is only here for brevity's sake.
* Note that if you add a new field in a version newer than the class, you must use {@link StableAPI} with the
* correct version!
* Note that if you add a method/field in a version newer than the class, you must also specify the correct version!
* <p>
* Also note that this only works for class members (methods and fields),
* inner classes still need to use {@link StableAPI}.
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(value = {ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR})
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR})
@StableAPI(since = "0.10.0")
@interface Expose {}
@interface Expose {
@StableAPI.Expose
String since() default "__PARENT__";
}
/**
* Use this if you want to explicitly mark specific members of a {@link StableAPI} class as internal-use only.
@@ -81,7 +85,7 @@ public @interface StableAPI {
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(value = {ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR})
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR})
@StableAPI(since = "0.10.0")
@interface Internal {}
}
@@ -43,12 +43,12 @@ import java.util.function.BiConsumer;
@StableAPI(since = "0.6.0")
public class ConfigurationManager {
@StableAPI(since = "0.10.0")
@StableAPI.Expose(since = "0.10.0")
public static void initialize(Class<?>... configClasses) throws ConfigException {
initialize((a, b) -> {}, configClasses);
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose(since = "0.10.0")
public static void initialize(BiConsumer<Class<?>, Field> validatorErrorCallback, Class<?>... configClasses)
throws ConfigException {
for (val clazz : configClasses) {
@@ -59,12 +59,12 @@ public class ConfigurationManager {
}
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose(since = "0.10.0")
public static boolean validate(boolean resetInvalid, Class<?>... configClasses) throws ConfigException {
return validate((x, y) -> {}, resetInvalid, configClasses);
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose(since = "0.10.0")
public static boolean validate(BiConsumer<Class<?>, Field> validatorErrorCallback, boolean resetInvalid, Class<?>... configClasses)
throws ConfigException {
boolean valid = true;
@@ -74,14 +74,14 @@ public class ConfigurationManager {
return valid;
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose(since = "0.10.0")
public static void loadFromFile(Class<?>... configClasses) throws ConfigException {
for (val clazz : configClasses) {
ConfigurationManagerImpl.load(clazz);
}
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose(since = "0.10.0")
public static void saveToFile(boolean validateAndResetInvalid, Class<?>... configClasses) throws ConfigException {
for (val clazz : configClasses) {
if (validateAndResetInvalid) {
@@ -127,7 +127,7 @@ public class ConfigurationManager {
* @return The configuration elements.
*/
@SuppressWarnings("rawtypes")
@StableAPI(since = "0.10.0")
@StableAPI.Expose(since = "0.10.0")
public static List<IConfigElement> getConfigElementsMulti(Class<?>... configClasses) throws ConfigException {
switch (configClasses.length) {
case 0:
@@ -37,7 +37,7 @@ public class SimpleGuiConfig extends GuiConfig {
this(parent, modID, modName, configClass);
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose(since = "0.10.0")
public SimpleGuiConfig(GuiScreen parent, String modID, String modName, Class<?>... configClasses)
throws ConfigException {
super(parent, ConfigurationManager.getConfigElementsMulti(configClasses), modID, false, false,
@@ -115,12 +115,12 @@ public class SimpleToast implements IToast {
return background.getIcon().getIconHeight();
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public void hide() {
visibility = IToast.Visibility.HIDE;
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public void setProgress(float progress) {
this.currentProgress = progress;
}
@@ -49,7 +49,7 @@ public final class RenderUtil {
return (Timer) timerField.get(getMinecraft());
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose(since = "0.10.0")
public static IIcon getFullTextureIcon(String iconName, int width, int height) {
return new IIcon() {
@Override