Fixed optional
This commit is contained in:
parent
3009921c16
commit
d0bb36c5af
|
@ -13,6 +13,7 @@ import java.util.HashSet;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
@ -235,8 +236,8 @@ public final class DefaultBȍőnLoader implements Bãß.𝔅𝔬𝔫𝔢𝔏𝔬
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Class<?> findInterfaceByAnnotation(Class<?> clazz, Class<? extends Annotation> annoType) {
|
public static Optional<Class<?>> findInterfaceByAnnotation(Class<?> clazz, Class<? extends Annotation> annoType) {
|
||||||
return walkInterfaces(clazz, new LinkedHashSet<>()).stream().filter(v -> v.isAnnotationPresent(annoType)).findFirst().get();
|
return walkInterfaces(clazz, new LinkedHashSet<>()).stream().filter(v -> v.isAnnotationPresent(annoType)).findFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<Class<?>> walkInterfaces(Class<?> clazz, Set<Class<?>> result) {
|
public static Set<Class<?>> walkInterfaces(Class<?> clazz, Set<Class<?>> result) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package love.distributedrebirth.bassboon.jpp.lang;
|
||||||
import java.lang.instrument.ClassFileTransformer;
|
import java.lang.instrument.ClassFileTransformer;
|
||||||
import java.lang.instrument.IllegalClassFormatException;
|
import java.lang.instrument.IllegalClassFormatException;
|
||||||
import java.security.ProtectionDomain;
|
import java.security.ProtectionDomain;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import love.distributedrebirth.bassboon.DefaultBȍőnLoader;
|
import love.distributedrebirth.bassboon.DefaultBȍőnLoader;
|
||||||
import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注;
|
import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注;
|
||||||
|
@ -21,20 +22,24 @@ public class ObjectScopeLimitΔ邪ᙾ implements ClassFileTransformer {
|
||||||
if (classBeingRedefined.getDeclaringClass() == null) {
|
if (classBeingRedefined.getDeclaringClass() == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Class<?> checkPrefixInterface = DefaultBȍőnLoader.findInterfaceByAnnotation(classBeingRedefined, ObjectScopeLimitΔ.Ꝑŕḯṿª₮ḕ.DeathMatchPrefix注.class);
|
Optional<Class<?>> checkPrefixInterface = DefaultBȍőnLoader.findInterfaceByAnnotation(classBeingRedefined, ObjectScopeLimitΔ.Ꝑŕḯṿª₮ḕ.DeathMatchPrefix注.class);
|
||||||
ObjectScopeLimitΔ.Ꝑŕḯṿª₮ḕ.DeathMatchPrefix注 checkPrefix = checkPrefixInterface.getAnnotation(ObjectScopeLimitΔ.Ꝑŕḯṿª₮ḕ.DeathMatchPrefix注.class);
|
if (checkPrefixInterface.isPresent()) {
|
||||||
|
ObjectScopeLimitΔ.Ꝑŕḯṿª₮ḕ.DeathMatchPrefix注 checkPrefix = checkPrefixInterface.get().getAnnotation(ObjectScopeLimitΔ.Ꝑŕḯṿª₮ḕ.DeathMatchPrefix注.class);
|
||||||
if (checkPrefix != null) {
|
if (checkPrefix != null) {
|
||||||
if (!classBeingRedefined.getName().startsWith(checkPrefix.match())) {
|
if (!classBeingRedefined.getName().startsWith(checkPrefix.match())) {
|
||||||
throw new IllegalClassFormatException(checkPrefix.lastBreath()+checkPrefix.match());
|
throw new IllegalClassFormatException(checkPrefix.lastBreath()+checkPrefix.match());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Class<?> checkNameInterface = DefaultBȍőnLoader.findInterfaceByAnnotation(classBeingRedefined, ObjectScopeLimitΔ.Ꝑŕḯṿª₮ḕ.DeathMatchName注.class);
|
}
|
||||||
ObjectScopeLimitΔ.Ꝑŕḯṿª₮ḕ.DeathMatchName注 checkName = checkNameInterface.getAnnotation(ObjectScopeLimitΔ.Ꝑŕḯṿª₮ḕ.DeathMatchName注.class);
|
Optional<Class<?>> checkNameInterface = DefaultBȍőnLoader.findInterfaceByAnnotation(classBeingRedefined, ObjectScopeLimitΔ.Ꝑŕḯṿª₮ḕ.DeathMatchName注.class);
|
||||||
|
if (checkNameInterface.isPresent()) {
|
||||||
|
ObjectScopeLimitΔ.Ꝑŕḯṿª₮ḕ.DeathMatchName注 checkName = checkNameInterface.get().getAnnotation(ObjectScopeLimitΔ.Ꝑŕḯṿª₮ḕ.DeathMatchName注.class);
|
||||||
if (checkName != null) {
|
if (checkName != null) {
|
||||||
if (!classBeingRedefined.getName().equals(checkName.match())) {
|
if (!classBeingRedefined.getName().equals(checkName.match())) {
|
||||||
throw new IllegalClassFormatException(checkName.lastBreath()+checkName.match());
|
throw new IllegalClassFormatException(checkName.lastBreath()+checkName.match());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import love.distributedrebirth.bassboon.DefaultBȍőnLoader;
|
import love.distributedrebirth.bassboon.DefaultBȍőnLoader;
|
||||||
import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注;
|
import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注;
|
||||||
|
@ -40,8 +41,11 @@ public interface /* childface */ BabelLocalizer { // JVM: only allow direct chil
|
||||||
}
|
}
|
||||||
|
|
||||||
default BabelLocalizerᴬᵖᶦ toBabelLocalizerᴬᵖᶦ() {
|
default BabelLocalizerᴬᵖᶦ toBabelLocalizerᴬᵖᶦ() {
|
||||||
Class<?> loc = DefaultBȍőnLoader.findInterfaceByAnnotation(getClass(), Ꝑŕḯṿª₮ḕ.BabelLocalizer注.class);
|
Optional<Class<?>> loc = DefaultBȍőnLoader.findInterfaceByAnnotation(getClass(), Ꝑŕḯṿª₮ḕ.BabelLocalizer注.class);
|
||||||
Ꝑŕḯṿª₮ḕ.BabelLocalizer注 anno = loc.getAnnotation(Ꝑŕḯṿª₮ḕ.BabelLocalizer注.class);
|
if (loc.isEmpty()) {
|
||||||
|
throw new RuntimeException("Missing required annotation BabelLocalizer注 on interface: "+this);
|
||||||
|
}
|
||||||
|
Ꝑŕḯṿª₮ḕ.BabelLocalizer注 anno = loc.get().getAnnotation(Ꝑŕḯṿª₮ḕ.BabelLocalizer注.class);
|
||||||
return BabelLocalizerᴬᵖᶦ.Ꝑŕᱜṫèƈ₮ࠄ₫.instanceᴺᵉʷ(anno.name(), new Locale(anno.locale()), anno.target());
|
return BabelLocalizerᴬᵖᶦ.Ꝑŕᱜṫèƈ₮ࠄ₫.instanceᴺᵉʷ(anno.name(), new Locale(anno.locale()), anno.target());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.lang.instrument.ClassFileTransformer;
|
||||||
import java.lang.instrument.IllegalClassFormatException;
|
import java.lang.instrument.IllegalClassFormatException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.security.ProtectionDomain;
|
import java.security.ProtectionDomain;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import love.distributedrebirth.bassboon.DefaultBȍőnLoader;
|
import love.distributedrebirth.bassboon.DefaultBȍőnLoader;
|
||||||
import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注;
|
import love.distributedrebirth.bassboon.clazz.BãßBȍőnAuthor注;
|
||||||
|
@ -33,10 +34,13 @@ public class BabelLocalizer邪ᙾ implements ClassFileTransformer {
|
||||||
}
|
}
|
||||||
|
|
||||||
// babel translated object interfaces
|
// babel translated object interfaces
|
||||||
Class<?> checkMethodNameInterface = DefaultBȍőnLoader.findInterfaceByAnnotation(classBeingRedefined, BabelLocalizer.Ꝑŕḯṿª₮ḕ.BabelMethodNameEnforcer注.class);
|
Optional<Class<?>> checkMethodNameInterface = DefaultBȍőnLoader.findInterfaceByAnnotation(classBeingRedefined, BabelLocalizer.Ꝑŕḯṿª₮ḕ.BabelMethodNameEnforcer注.class);
|
||||||
BabelLocalizer.Ꝑŕḯṿª₮ḕ.BabelMethodNameEnforcer注 checkMethodName = checkMethodNameInterface.getAnnotation(BabelLocalizer.Ꝑŕḯṿª₮ḕ.BabelMethodNameEnforcer注.class);
|
if (checkMethodNameInterface.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
BabelLocalizer.Ꝑŕḯṿª₮ḕ.BabelMethodNameEnforcer注 checkMethodName = checkMethodNameInterface.get().getAnnotation(BabelLocalizer.Ꝑŕḯṿª₮ḕ.BabelMethodNameEnforcer注.class);
|
||||||
if (checkMethodName == null) {
|
if (checkMethodName == null) {
|
||||||
return classfileBuffer;
|
return null;
|
||||||
}
|
}
|
||||||
for (Method m:classBeingRedefined.getMethods()) {
|
for (Method m:classBeingRedefined.getMethods()) {
|
||||||
if (m.getName().startsWith("toBabel")) {
|
if (m.getName().startsWith("toBabel")) {
|
||||||
|
|
Loading…
Reference in a new issue