Don't rely on enums being present
This commit is contained in:
parent
47b614e0ef
commit
6f769066c5
|
|
@ -17,7 +17,6 @@ dependencies {
|
||||||
implementation "net.fabricmc:sponge-mixin:0.12.5+"
|
implementation "net.fabricmc:sponge-mixin:0.12.5+"
|
||||||
// Platform classes
|
// Platform classes
|
||||||
implementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
|
implementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
|
||||||
implementation "net.minecraftforge:mergetool:1.1.0"
|
|
||||||
implementation project(":annotations")
|
implementation project(":annotations")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,10 @@
|
||||||
package org.fury_phoenix.mixinAp.annotation;
|
package org.fury_phoenix.mixinAp.annotation;
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.invoke.*;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
|
@ -41,15 +37,13 @@ public class ClientMixinValidator {
|
||||||
|
|
||||||
private final boolean debug;
|
private final boolean debug;
|
||||||
|
|
||||||
private static final Map<String, String> markers = Map.of(
|
private static final Iterable<String> markers = Set.of(
|
||||||
"net.fabricmc.api.Environment", "net.fabricmc.api.EnvType",
|
"net.fabricmc.api.Environment",
|
||||||
"net.minecraftforge.api.distmarker.OnlyIn", "net.minecraftforge.api.distmarker.Dist",
|
"net.minecraftforge.api.distmarker.OnlyIn",
|
||||||
"net.neoforged.api.distmarker.OnlyIn", "net.neoforged.api.distmarker.Dist");
|
"net.neoforged.api.distmarker.OnlyIn");
|
||||||
|
|
||||||
private static final Collection<String> unannotatedClasses = new HashSet<>();
|
private static final Collection<String> unannotatedClasses = new HashSet<>();
|
||||||
|
|
||||||
private static final MethodHandles.Lookup lookup = MethodHandles.publicLookup();
|
|
||||||
|
|
||||||
public ClientMixinValidator(ProcessingEnvironment env)
|
public ClientMixinValidator(ProcessingEnvironment env)
|
||||||
throws ReflectiveOperationException {
|
throws ReflectiveOperationException {
|
||||||
typeHandleProvider = AnnotatedMixinsAccessor.getMixinAP(env);
|
typeHandleProvider = AnnotatedMixinsAccessor.getMixinAP(env);
|
||||||
|
|
@ -97,11 +91,12 @@ public class ClientMixinValidator {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isClientMarked(TypeElement te) {
|
private boolean isClientMarked(TypeElement te) {
|
||||||
for (var entry : getPlatformClasses(markers).entrySet()) {
|
for (var marker : getPlatformMarkers(markers)) {
|
||||||
IAnnotationHandle marker = getAnnotationHandle(te, entry.getKey());
|
messager.printMessage(Diagnostic.Kind.WARNING, marker.toString());
|
||||||
if(!marker.exists()) continue;
|
IAnnotationHandle handle = getAnnotationHandle(te, marker);
|
||||||
|
if(!handle.exists()) continue;
|
||||||
|
|
||||||
String[] enumValue = marker.getValue("value");
|
String[] enumValue = handle.getValue("value");
|
||||||
if(enumValue==null) continue;
|
if(enumValue==null) continue;
|
||||||
|
|
||||||
return enumValue[1].equals("CLIENT");
|
return enumValue[1].equals("CLIENT");
|
||||||
|
|
@ -119,15 +114,6 @@ public class ClientMixinValidator {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Optional<MethodHandle> getAccessor(Class<? extends Annotation> markerClass,
|
|
||||||
Class<? extends Enum<?>> enumClass) {
|
|
||||||
MethodType enumValueAccessorType = MethodType.methodType(enumClass);
|
|
||||||
try {
|
|
||||||
return Optional.of(lookup.findVirtual(markerClass, "value", enumValueAccessorType));
|
|
||||||
} catch (ReflectiveOperationException e) {}
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public SimpleImmutableEntry<? extends CharSequence, ? extends CharSequence>
|
public SimpleImmutableEntry<? extends CharSequence, ? extends CharSequence>
|
||||||
getEntry(TypeElement annotatedMixinClass) {
|
getEntry(TypeElement annotatedMixinClass) {
|
||||||
return new SimpleImmutableEntry<>(
|
return new SimpleImmutableEntry<>(
|
||||||
|
|
@ -159,14 +145,11 @@ public class ClientMixinValidator {
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<Class<? extends Annotation>, Class<? extends Enum<?>>>
|
private static Iterable<Class<? extends Annotation>>
|
||||||
getPlatformClasses(Map<String, String> map) {
|
getPlatformMarkers(Iterable<String> markers) {
|
||||||
Map<Class<? extends Annotation>, Class<? extends Enum<?>>> platformClasses = new HashMap<>();
|
Set<Class<? extends Annotation>> platformClasses = new HashSet<>();
|
||||||
for(var entry : map.entrySet()) {
|
for(var marker : markers) {
|
||||||
Optional<Class<? extends Annotation>> annotation = getMarkerClass(entry.getKey());
|
getMarkerClass(marker).ifPresent(platformClasses::add);
|
||||||
Optional<Class<? extends Enum<?>>> enumClz = getMarkerEnumClass(entry.getValue());
|
|
||||||
if(!annotation.isEmpty() && !enumClz.isEmpty())
|
|
||||||
platformClasses.put(annotation.orElseThrow(), enumClz.orElseThrow());
|
|
||||||
}
|
}
|
||||||
return platformClasses;
|
return platformClasses;
|
||||||
}
|
}
|
||||||
|
|
@ -179,24 +162,7 @@ public class ClientMixinValidator {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private static Optional<Class<? extends Enum<?>>> getMarkerEnumClass(String enumClz) {
|
|
||||||
try {
|
|
||||||
Optional.of((Class<? extends Enum<?>>)Class.forName(enumClz));
|
|
||||||
} catch (ClassNotFoundException e) {}
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String toSourceString(String bytecodeName) {
|
public static String toSourceString(String bytecodeName) {
|
||||||
return bytecodeName.replaceAll("\\/", ".");
|
return bytecodeName.replaceAll("\\/", ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object invoke(MethodHandle mh, Annotation marker) {
|
|
||||||
try { return mh.invoke(marker); }
|
|
||||||
catch (Throwable e) {
|
|
||||||
messager.printMessage(Diagnostic.Kind.ERROR, "Fatal error:" +
|
|
||||||
Throwables.getStackTraceAsString(e));
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user