Deprecate the StableAPI annotations, switch to JB annotations

This commit is contained in:
FalsePattern committed 2025-05-26 09:45:57 +02:00
1 parent 8645d20a16
commit df1f294776
96 files changed
+1079 -762

No files matched your search

@@ -21,7 +21,6 @@
*/
package com.falsepattern.lib.mapping;
import com.falsepattern.lib.StableAPI;
import com.falsepattern.lib.internal.FPLog;
import com.falsepattern.lib.internal.asm.CoreLoadingPlugin;
import com.falsepattern.lib.mapping.storage.Lookup;
@@ -39,7 +38,6 @@ import org.objectweb.asm.tree.MethodInsnNode;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicLong;
@StableAPI(since = "0.10.0")
public class MappingManager {
private static Lookup<UniversalClass> internalLookup;
private static Lookup<UniversalClass> regularLookup;
@@ -117,7 +115,6 @@ public class MappingManager {
}
}
@StableAPI.Expose
public static UniversalClass classForName(NameType nameType, MappingType mappingType, String className)
throws ClassNotFoundException {
initialize();
@@ -142,7 +139,6 @@ public class MappingManager {
}
}
@StableAPI.Expose
public static boolean containsClass(NameType nameType, MappingType mappingType, String className) {
initialize();
switch (nameType) {
@@ -155,7 +151,6 @@ public class MappingManager {
}
}
@StableAPI.Expose
public static UniversalField getField(FieldInsnNode instruction)
throws ClassNotFoundException, NoSuchFieldException {
initialize();
@@ -186,7 +181,6 @@ public class MappingManager {
}
}
@StableAPI.Expose
public static UniversalMethod getMethod(MethodInsnNode instruction)
throws ClassNotFoundException, NoSuchMethodException {
initialize();
@@ -0,0 +1,26 @@
/*
* This file is part of FalsePatternLib.
*
* Copyright (C) 2022-2025 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* FalsePatternLib 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, only version 3 of the License.
*
* FalsePatternLib 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FalsePatternLib. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* @since 0.10.0
*/
package com.falsepattern.lib.mapping;
@@ -21,12 +21,12 @@
*/
package com.falsepattern.lib.mapping.storage;
import com.falsepattern.lib.StableAPI;
import com.falsepattern.lib.mapping.types.MappingType;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import lombok.experimental.Accessors;
import lombok.val;
import org.jetbrains.annotations.ApiStatus;
import java.util.HashMap;
import java.util.HashSet;
@@ -36,7 +36,6 @@ import java.util.Set;
@Accessors(fluent = true)
@EqualsAndHashCode
@StableAPI(since = "0.10.0")
public class Lookup<T> {
private final Set<T> values = new HashSet<>();
private final Map<String, T> notch = new HashMap<>();
@@ -53,12 +52,10 @@ public class Lookup<T> {
}
}
@StableAPI.Expose
public boolean contains(T value) {
return values.contains(value);
}
@StableAPI.Expose
public boolean containsKey(MappingType mappingType, String key) {
switch (mappingType) {
case Notch:
@@ -72,7 +69,6 @@ public class Lookup<T> {
}
}
@StableAPI.Expose
public void unwrap(@NonNull MappedString mappedString, @NonNull T value) {
if (contains(value)) {
//Collision avoidance.
@@ -87,7 +83,6 @@ public class Lookup<T> {
mcp.put(mappedString.mcp, value);
}
@StableAPI.Expose
public T get(MappingType mappingType, String key) throws LookupException {
T result;
switch (mappingType) {
@@ -109,8 +104,8 @@ public class Lookup<T> {
return result;
}
@StableAPI(since = "0.10.0")
public static class LookupException extends Exception {
@ApiStatus.Internal
public LookupException(String message) {
super(message);
}
@@ -21,7 +21,6 @@
*/
package com.falsepattern.lib.mapping.storage;
import com.falsepattern.lib.StableAPI;
import com.falsepattern.lib.mapping.types.MappingType;
import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
@@ -38,32 +37,23 @@ import java.util.function.Function;
@EqualsAndHashCode
@Getter
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
@StableAPI(since = "0.10.0")
public class MappedString {
@StableAPI.Expose
public final String notch;
@StableAPI.Expose
public final String srg;
@StableAPI.Expose
public final String mcp;
@StableAPI.Expose
public MappedString(String[] source, int offset, int stride, Function<String, String> remapper, Map<String, String> stringPool) {
notch = stringPool.computeIfAbsent(remapper.apply(source[offset]), (str) -> str);
srg = stringPool.computeIfAbsent(remapper.apply(source[offset + stride]), (str) -> str);
mcp = stringPool.computeIfAbsent(remapper.apply(source[offset + stride * 2]), (str) -> str);
}
@StableAPI.Expose
public static MappedString fuse(MappedString a, MappedString b, String delimiter, Map<String, String> stringPool) {
return new MappedString(stringPool.computeIfAbsent(a.notch + delimiter + b.notch, (str) -> str),
stringPool.computeIfAbsent(a.srg + delimiter + b.srg, (str) -> str),
stringPool.computeIfAbsent(a.mcp + delimiter + b.mcp, (str) -> str));
}
@StableAPI.Expose
public String get(MappingType type) {
switch (type) {
case Notch:
@@ -21,11 +21,8 @@
*/
package com.falsepattern.lib.mapping.types;
import com.falsepattern.lib.StableAPI;
@StableAPI(since = "0.10.0")
public enum MappingType {
@StableAPI.Expose Notch,
@StableAPI.Expose SRG,
@StableAPI.Expose MCP
Notch,
SRG,
MCP
}
@@ -21,10 +21,7 @@
*/
package com.falsepattern.lib.mapping.types;
import com.falsepattern.lib.StableAPI;
@StableAPI(since = "0.10.0")
public enum NameType {
@StableAPI.Expose Internal,
@StableAPI.Expose Regular
Internal,
Regular
}
@@ -21,7 +21,6 @@
*/
package com.falsepattern.lib.mapping.types;
import com.falsepattern.lib.StableAPI;
import com.falsepattern.lib.internal.asm.CoreLoadingPlugin;
import com.falsepattern.lib.mapping.storage.Lookup;
import com.falsepattern.lib.mapping.storage.MappedString;
@@ -35,13 +34,12 @@ import java.util.Map;
@Accessors(fluent = true)
@ToString(onlyExplicitlyIncluded = true)
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
@StableAPI(since = "0.10.0")
public class UniversalClass {
@Getter(onMethod_ = @StableAPI.Expose)
@Getter
@ToString.Include
@EqualsAndHashCode.Include
public final MappedString internalName;
@Getter(onMethod_ = @StableAPI.Expose)
@Getter
@ToString.Include
@EqualsAndHashCode.Include
public final MappedString regularName;
@@ -53,7 +51,6 @@ public class UniversalClass {
@Getter
private MappingType realClassMapping = null;
@StableAPI.Expose
public UniversalClass(String[] names, Map<String, String> stringPool) {
internalName = new MappedString(names, 0, 1, (str) -> str, stringPool);
regularName = new MappedString(names, 0, 1, (str) -> str.replace('/', '.'), stringPool);
@@ -73,7 +70,6 @@ public class UniversalClass {
methods.unwrap(method.fusedNameDescriptor, method);
}
@StableAPI.Expose
public Class<?> asJavaClass() throws ClassNotFoundException {
if (javaClassCache != null) {
return javaClassCache;
@@ -98,7 +94,6 @@ public class UniversalClass {
return javaClassCache;
}
@StableAPI.Expose
public String getName(NameType nameType, MappingType mappingType) {
switch (nameType) {
case Internal:
@@ -110,12 +105,10 @@ public class UniversalClass {
}
}
@StableAPI.Expose
public String getNameAsDescriptor(MappingType mappingType) {
return "L" + getName(NameType.Internal, mappingType) + ";";
}
@StableAPI.Expose
public UniversalField getField(MappingType mappingType, String fieldName) throws NoSuchFieldException {
try {
return fields.get(mappingType, fieldName);
@@ -124,7 +117,6 @@ public class UniversalClass {
}
}
@StableAPI.Expose
public UniversalMethod getMethod(MappingType mappingType, String methodName, String methodDescriptor)
throws NoSuchMethodException {
try {
@@ -21,7 +21,6 @@
*/
package com.falsepattern.lib.mapping.types;
import com.falsepattern.lib.StableAPI;
import com.falsepattern.lib.internal.ReflectionUtil;
import com.falsepattern.lib.mapping.storage.MappedString;
import lombok.EqualsAndHashCode;
@@ -39,14 +38,13 @@ import java.util.Map;
@Accessors(fluent = true)
@ToString
@EqualsAndHashCode
@StableAPI(since = "0.10.0")
public class UniversalField {
@Getter(onMethod_ = @StableAPI.Expose)
@Getter
@ToString.Exclude
@EqualsAndHashCode.Exclude
public final UniversalClass parent;
@Getter(onMethod_ = @StableAPI.Expose)
@Getter
public final MappedString name;
private Field javaFieldCache = null;
@@ -57,17 +55,14 @@ public class UniversalField {
parent.addField(this);
}
@StableAPI.Expose
public static void createAndAddToParent(@NonNull UniversalClass parent, String[] names, Map<String, String> stringPool) {
new UniversalField(parent, names, stringPool);
}
@StableAPI.Expose
public String getName(MappingType mappingType) {
return name.get(mappingType);
}
@StableAPI.Expose
public Field asJavaField() throws ClassNotFoundException, NoSuchFieldException {
if (javaFieldCache != null) {
return javaFieldCache;
@@ -83,13 +78,11 @@ public class UniversalField {
* you don't need to manually handle exceptions.
*/
@SuppressWarnings("unchecked")
@StableAPI.Expose
public <T> T get(Object instance) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException {
val field = asJavaField();
return (T) field.get(instance);
}
@StableAPI.Expose
public FieldInsnNode asInstruction(int opcode, MappingType mapping, String descriptor) {
return new FieldInsnNode(opcode, parent.getName(NameType.Internal, mapping), getName(mapping), descriptor);
}
@@ -21,7 +21,6 @@
*/
package com.falsepattern.lib.mapping.types;
import com.falsepattern.lib.StableAPI;
import com.falsepattern.lib.internal.ReflectionUtil;
import com.falsepattern.lib.mapping.storage.MappedString;
import lombok.EqualsAndHashCode;
@@ -41,20 +40,19 @@ import java.util.Map;
@Accessors(fluent = true)
@ToString
@EqualsAndHashCode
@StableAPI(since = "0.10.0")
public class UniversalMethod {
@Getter(onMethod_ = @StableAPI.Expose)
@Getter
@ToString.Exclude
@EqualsAndHashCode.Exclude
public final UniversalClass parent;
@Getter(onMethod_ = @StableAPI.Expose)
@Getter
public final MappedString name;
@Getter(onMethod_ = @StableAPI.Expose)
@Getter
public final MappedString descriptor;
@Getter(onMethod_ = @StableAPI.Expose)
@Getter
public final MappedString fusedNameDescriptor;
private Method javaMethodCache = null;
@@ -67,7 +65,6 @@ public class UniversalMethod {
parent.addMethod(this);
}
@StableAPI.Expose
public static void createAndAddToParent(@NonNull UniversalClass parent, String[] names, Map<String, String> stringPool) {
new UniversalMethod(parent, names, stringPool);
}
@@ -135,17 +132,14 @@ public class UniversalMethod {
return result.toArray(new Class[0]);
}
@StableAPI.Expose
public String getName(MappingType mappingType) {
return name.get(mappingType);
}
@StableAPI.Expose
public String getDescriptor(MappingType mappingType) {
return descriptor.get(mappingType);
}
@StableAPI.Expose
public Method asJavaMethod() throws ClassNotFoundException, NoSuchMethodException {
if (javaMethodCache != null) {
return javaMethodCache;
@@ -163,18 +157,15 @@ public class UniversalMethod {
*/
@SuppressWarnings("unchecked")
@SneakyThrows
@StableAPI.Expose
public <T> T invoke(Object instance, Object... arguments) {
val m = asJavaMethod();
return (T) m.invoke(instance, arguments);
}
@StableAPI.Expose
public <T> T invokeStatic(Object... arguments) {
return invoke(null, arguments);
}
@StableAPI.Expose
public MethodInsnNode asInstruction(int opcode, MappingType mapping, boolean itf) {
return new MethodInsnNode(opcode,
parent.getName(NameType.Internal, mapping),
@@ -0,0 +1,26 @@
/*
* This file is part of FalsePatternLib.
*
* Copyright (C) 2022-2025 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* FalsePatternLib 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, only version 3 of the License.
*
* FalsePatternLib 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FalsePatternLib. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* @since 0.10.0
*/
package com.falsepattern.lib.mapping.types;