Skip to content

Commit da1ef6c

Browse files
committed
Annotate all the things
1 parent 980e8a8 commit da1ef6c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+623
-369
lines changed

src/main/java/com/falsepattern/lib/DeprecationDetails.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
@Retention(RetentionPolicy.RUNTIME)
1313
@StableAPI(since = "0.10.0")
1414
public @interface DeprecationDetails {
15-
@StableAPI(since = "0.10.0") String stableSince() default "";
16-
17-
@StableAPI(since = "0.10.0") String deprecatedSince();
15+
@StableAPI.Expose
16+
String deprecatedSince();
1817
}

src/main/java/com/falsepattern/lib/StableAPI.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
package com.falsepattern.lib;
2222

2323
import java.lang.annotation.Documented;
24+
import java.lang.annotation.ElementType;
2425
import java.lang.annotation.Retention;
2526
import java.lang.annotation.RetentionPolicy;
27+
import java.lang.annotation.Target;
2628

2729
/**
2830
* Anything annotated with this annotation will be considered stable, and the class/method/field will not get breaking
@@ -31,17 +33,55 @@
3133
* If a class or method is NOT annotated with this annotation, it will be considered unstable, and the package/method
3234
* arguments/etc. can freely change between patch releases without notice.
3335
* <p>
36+
* If you have a class implementing another class, you don't need to annotate the {@link Override}-annotated methods with
37+
* StableAPI, because the StableAPI system conforms to inheritance. You should still annotate the class itself, or any extra
38+
* fields or non-override methods you may have added if you want to expose those too.
39+
* <p>
3440
* NOTICE: You should no longer use this annotation exclusively on classes themselves, and instead, annotate every single
3541
* public or protected member you want to expose as a public API!
3642
* <p>
3743
* Private members will never be considered stable, and can be removed without notice.
44+
* <p>
45+
* You may set the {@link #since()} attribute to "__INTERNAL__", this will signal that even though the specific class/member
46+
* has been marked as stable, it is still for internal use only. This may be done for reference purposes in multi-developer
47+
* projects, where you need to communicate intent even in internal code.
3848
*/
3949
@Documented
4050
@Retention(RetentionPolicy.RUNTIME)
51+
@Target(value = {ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR})
4152
@StableAPI(since = "0.6.0")
4253
public @interface StableAPI {
4354
/**
4455
* The version this API was introduced/stabilized in. Used for library version tracking.
4556
*/
4657
@StableAPI(since = "0.6.0") String since();
58+
59+
/**
60+
* You may use this annotation if you want a member to have an equal effective {@link #since()} value as its owner
61+
* class.
62+
* <p>
63+
* Everything else from the {@link StableAPI} class still applies, this is only here for brevity's sake.
64+
* Note that if you add a new field in a version newer than the class, you must use {@link StableAPI} with the
65+
* correct version!
66+
* <p>
67+
* Also note that this only works for class members (methods and fields),
68+
* inner classes still need to use {@link StableAPI}.
69+
*/
70+
@Documented
71+
@Retention(RetentionPolicy.RUNTIME)
72+
@Target(value = {ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR})
73+
@StableAPI(since = "0.10.0")
74+
@interface Expose {}
75+
76+
/**
77+
* Use this if you want to explicitly mark specific members of a {@link StableAPI} class as internal-use only.
78+
* <p>
79+
* Library consumers should never use class members marked with this annotation, as said members can be freely
80+
* changed or removed in any version in the library without prior notice.
81+
*/
82+
@Documented
83+
@Retention(RetentionPolicy.RUNTIME)
84+
@Target(value = {ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR})
85+
@StableAPI(since = "0.10.0")
86+
@interface Internal {}
4787
}

src/main/java/com/falsepattern/lib/asm/ASMUtil.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121
package com.falsepattern.lib.asm;
2222

23+
import com.falsepattern.lib.StableAPI;
2324
import com.falsepattern.lib.asm.exceptions.AsmClassNotFoundException;
2425
import com.falsepattern.lib.asm.exceptions.AsmFieldNotFoundException;
2526
import com.falsepattern.lib.asm.exceptions.AsmMethodNotFoundException;
@@ -42,7 +43,9 @@
4243
import java.util.Arrays;
4344
import java.util.Objects;
4445

46+
@StableAPI(since = "0.10.0")
4547
public class ASMUtil {
48+
@StableAPI.Expose
4649
public static FieldNode findFieldStandard(ClassNode cn, String name, boolean optional) {
4750
for (final FieldNode ret : cn.fields) {
4851
if (name.equals(ret.name)) {
@@ -56,6 +59,7 @@ public static FieldNode findFieldStandard(ClassNode cn, String name, boolean opt
5659
}
5760

5861
@SneakyThrows
62+
@StableAPI.Expose
5963
public static FieldNode findFieldFromMCP(ClassNode cn, String fieldName, boolean optional) {
6064
val classMapping = discoverClassMappingType(cn);
6165
if (classMapping == null) {
@@ -67,6 +71,7 @@ public static FieldNode findFieldFromMCP(ClassNode cn, String fieldName, boolean
6771
.getName(classMapping), optional);
6872
}
6973

74+
@StableAPI.Expose
7075
public static FieldNode findFieldFromUniversal(ClassNode cn, UniversalField field, boolean optional) {
7176
String[] possibilities = CoreLoadingPlugin.isObfuscated() ? new String[]{field.getName(MappingType.SRG),
7277
field.getName(MappingType.Notch)}
@@ -83,6 +88,7 @@ public static FieldNode findFieldFromUniversal(ClassNode cn, UniversalField fiel
8388
possibilities.length == 1 ? possibilities[0] : Arrays.toString(possibilities));
8489
}
8590

91+
@StableAPI.Expose
8692
public static MethodNode findMethodStandard(ClassNode cn, String name, String descriptor, boolean optional) {
8793
for (final MethodNode ret : cn.methods) {
8894
if (name.equals(ret.name) && descriptor.equals(ret.desc)) {
@@ -96,6 +102,7 @@ public static MethodNode findMethodStandard(ClassNode cn, String name, String de
96102
}
97103

98104
@SneakyThrows
105+
@StableAPI.Expose
99106
public static MethodNode findMethodFromMCP(ClassNode cn, String mcpName, String mcpDescriptor, boolean optional) {
100107
val classMapping = discoverClassMappingType(cn);
101108
if (classMapping == null) {
@@ -107,6 +114,7 @@ public static MethodNode findMethodFromMCP(ClassNode cn, String mcpName, String
107114
return findMethodStandard(cn, method.getName(classMapping), method.getDescriptor(classMapping), optional);
108115
}
109116

117+
@StableAPI.Expose
110118
public static MethodNode findMethodFromUniversal(ClassNode cn, UniversalMethod method, boolean optional) {
111119
String[] possibleNames = CoreLoadingPlugin.isObfuscated() ? new String[]{method.getName(MappingType.SRG),
112120
method.getName(MappingType.Notch)}
@@ -127,6 +135,7 @@ public static MethodNode findMethodFromUniversal(ClassNode cn, UniversalMethod m
127135
possibleDescriptors.length == 1 ? possibleDescriptors[0] : Arrays.toString(possibleDescriptors));
128136
}
129137

138+
@StableAPI.Expose
130139
public static MappingType discoverClassMappingType(ClassNode cn) {
131140
if (CoreLoadingPlugin.isObfuscated()) {
132141
if (MappingManager.containsClass(NameType.Internal, MappingType.MCP, cn.name)) {
@@ -140,6 +149,7 @@ public static MappingType discoverClassMappingType(ClassNode cn) {
140149
return null;
141150
}
142151

152+
@StableAPI.Expose
143153
public static UniversalClass toUniversalClass(ClassNode cn) {
144154
if (CoreLoadingPlugin.isObfuscated()) {
145155
try {
@@ -160,18 +170,21 @@ public static UniversalClass toUniversalClass(ClassNode cn) {
160170
}
161171
}
162172

173+
@StableAPI.Expose
163174
public static ClassNode parseClass(byte[] bytes, int readerFlags) {
164175
val cn = new ClassNode(Opcodes.ASM5);
165176
val reader = new ClassReader(bytes);
166177
reader.accept(cn, readerFlags);
167178
return cn;
168179
}
169180

181+
@StableAPI.Expose
170182
public static byte[] serializeClass(ClassNode cn, int writerFlags) {
171183
val writer = new ClassWriter(writerFlags);
172184
return writer.toByteArray();
173185
}
174186

187+
@StableAPI.Expose
175188
public static boolean anyEquals(String str, String... options) {
176189
for (val option : options) {
177190
if (Objects.equals(str, option)) {

src/main/java/com/falsepattern/lib/asm/IClassNodeTransformer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,22 @@
2020
*/
2121
package com.falsepattern.lib.asm;
2222

23+
import com.falsepattern.lib.StableAPI;
2324
import org.objectweb.asm.tree.ClassNode;
2425

26+
@StableAPI(since = "0.10.0")
2527
public interface IClassNodeTransformer {
28+
@StableAPI.Expose
2629
String getName();
2730

31+
@StableAPI.Expose
2832
boolean shouldTransform(ClassNode cn, String transformedName, boolean obfuscated);
2933

34+
@StableAPI.Expose
3035
default int internalSortingOrder() {
3136
return 0;
3237
}
3338

39+
@StableAPI.Expose
3440
void transform(ClassNode cn, String transformedName, boolean obfuscated);
3541
}

src/main/java/com/falsepattern/lib/asm/SmartTransformer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121
package com.falsepattern.lib.asm;
2222

23+
import com.falsepattern.lib.StableAPI;
2324
import com.falsepattern.lib.internal.CoreLoadingPlugin;
2425
import lombok.val;
2526
import org.apache.logging.log4j.Logger;
@@ -35,9 +36,12 @@
3536
/**
3637
* An ASM transformation dispatcher utility, inspired by mixins.
3738
*/
39+
@StableAPI(since = "0.10.0")
3840
public interface SmartTransformer extends IClassTransformer {
41+
@StableAPI.Expose
3942
Logger logger();
4043

44+
@StableAPI.Expose
4145
List<IClassNodeTransformer> transformers();
4246

4347
@Override

src/main/java/com/falsepattern/lib/asm/exceptions/AsmClassNotFoundException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
*/
2121
package com.falsepattern.lib.asm.exceptions;
2222

23+
import com.falsepattern.lib.StableAPI;
24+
25+
@StableAPI(since = "0.10.0")
2326
public class AsmClassNotFoundException extends AsmTransformException {
27+
@StableAPI.Internal
2428
public AsmClassNotFoundException(final String clazz) {
2529
super("can't find class " + clazz);
2630
}

src/main/java/com/falsepattern/lib/asm/exceptions/AsmFieldNotFoundException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
*/
2121
package com.falsepattern.lib.asm.exceptions;
2222

23+
import com.falsepattern.lib.StableAPI;
24+
25+
@StableAPI(since = "0.10.0")
2326
public class AsmFieldNotFoundException extends AsmTransformException {
27+
@StableAPI.Internal
2428
public AsmFieldNotFoundException(final String field) {
2529
super("can't find field " + field);
2630
}

src/main/java/com/falsepattern/lib/asm/exceptions/AsmMethodNotFoundException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
*/
2121
package com.falsepattern.lib.asm.exceptions;
2222

23+
import com.falsepattern.lib.StableAPI;
24+
25+
@StableAPI(since = "0.10.0")
2326
public class AsmMethodNotFoundException extends AsmTransformException {
2427
public AsmMethodNotFoundException(final String method) {
2528
super("can't find method " + method);

src/main/java/com/falsepattern/lib/asm/exceptions/AsmTransformException.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,21 @@
2020
*/
2121
package com.falsepattern.lib.asm.exceptions;
2222

23+
import com.falsepattern.lib.StableAPI;
24+
25+
@StableAPI(since = "0.10.0")
2326
public class AsmTransformException extends RuntimeException {
27+
@StableAPI.Expose
2428
public AsmTransformException(final String message) {
2529
super(message);
2630
}
2731

32+
@StableAPI.Expose
2833
public AsmTransformException(final Throwable cause) {
2934
super(cause);
3035
}
3136

37+
@StableAPI.Expose
3238
public AsmTransformException(final String message, final Throwable cause) {
3339
super(message, cause);
3440
}

0 commit comments

Comments
 (0)