fix some code smells
All checks were successful
/ Build & Publish (push) Successful in 39s

This commit is contained in:
Daniella / Tove 2024-06-29 00:04:54 +02:00
parent 55b30e02c2
commit af2c043bab
2 changed files with 1 additions and 10 deletions

View file

@ -18,8 +18,6 @@ public class DarkField {
public static Field nameToField(Class<?> owner, String name) {
try {
// try the basic strategy first - it works often enough for this to be a speed advantage.
// this also prevents a StackOverflowError if we're using a ReflectionDataClass with a
// BasicOffsetGetter (like on some non-openjdk jvms)
return owner.getDeclaredField(name);
} catch (NoSuchFieldException e) {
return Arrays.stream(Strategy.classStrategy.instance(owner).getDeclaredFields()).filter(x -> x.getName().equals(name)).findAny().orElse(null);

View file

@ -14,7 +14,6 @@ import static de.tudbut.darkreflection.UnsafeProvider.offsetGetter;
// which strategy depends on which?
// FReflectionDataClass -> reflectionFieldStrategy
// FieldByName -> reflectedFieldStrategy
// FieldByName -> classStrategy
@ -116,13 +115,7 @@ public class Strategy {
return null;
}
}),
DarkReflection((owner, field, isStatic, type) -> {
try {
return reflectedFieldStrategy.instance(Arrays.stream(classStrategy.instance(owner).getDeclaredFields()).filter(x -> x.getName().equals(field)).findAny().orElseThrow(() -> new NoSuchFieldException(field)));
} catch (NoSuchFieldException e) {
return null;
}
}),
DarkReflection((owner, field, isStatic, type) -> reflectedFieldStrategy.instance(Arrays.stream(classStrategy.instance(owner).getDeclaredFields()).filter(x -> x.getName().equals(field)).findAny().orElse(null))),
Unsafe((owner, field, isStatic, type) -> new UnsafeField<>(
isStatic ? offsetGetter.staticFieldBase(owner, field) : null,
isStatic ? offsetGetter.staticFieldOffset(owner, field) : offsetGetter.objectFieldOffset(owner, field), type)),