Skip to content

Commit f328b53

Browse files
committed
misc
1 parent 5393346 commit f328b53

File tree

5 files changed

+56
-24
lines changed

5 files changed

+56
-24
lines changed

src/main/java/zzzank/probejs/lang/java/clazz/Clazz.java

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ public Clazz(Class<?> clazz) {
5252
))
5353
.collect(Collectors.toList());
5454
this.fields = Arrays.stream(ReflectUtils.fieldsSafe(original))
55-
.filter(f -> !names.contains(RemapperBridge.remapField(original, f)) && !f.isAnnotationPresent(HideFromJS.class))
55+
.filter(f -> !names.contains(RemapperBridge.remapField(original, f))
56+
&& !f.isAnnotationPresent(HideFromJS.class))
5657
.map(f -> new FieldInfo(original, f))
5758
.collect(Collectors.toList());
5859

@@ -106,29 +107,37 @@ private static boolean hasIdenticalParentMethod(Method method, Class<?> clazz) {
106107
/**
107108
* getGenericTypeReplacementForParentInterfaceMethodsJustBecauseJavaDoNotKnowToReplaceThemWithGenericArgumentsOfThisClass
108109
*/
109-
private static Map<TypeVariable<?>, Type> getGenericTypeReplacementForParentInterfaceMethods(Class<?> thisClass, Method thatMethod) {
110+
private static Map<TypeVariable<?>, Type> getGenericTypeReplacementForParentInterfaceMethods(
111+
Class<?> thisClass,
112+
Method thatMethod
113+
) {
110114
Class<?> targetClass = thatMethod.getDeclaringClass();
111115

112116
Map<TypeVariable<?>, Type> replacement = new HashMap<>();
113-
if (Arrays.stream(thisClass.getInterfaces()).noneMatch(c -> c.equals(targetClass))) {
114-
Class<?> superInterface = Arrays.stream(thisClass.getInterfaces()).filter(targetClass::isAssignableFrom).findFirst().orElse(null);
115-
if (superInterface == null) {
116-
return Collections.emptyMap();
117-
}
118-
Map<TypeVariable<?>, Type> parentType = getGenericTypeReplacementForParentInterfaceMethods(superInterface, thatMethod);
119-
Map<TypeVariable<?>, Type> parentReplacement = getInterfaceRemap(thisClass, superInterface);
120-
121-
for (Map.Entry<TypeVariable<?>, Type> entry : parentType.entrySet()) {
122-
TypeVariable<?> variable = entry.getKey();
123-
Type type = entry.getValue();
124-
125-
replacement.put(variable,
126-
type instanceof TypeVariable<?> typeVariable ? parentReplacement.getOrDefault(typeVariable, typeVariable) : type
127-
);
128-
}
129-
} else {
117+
if (Arrays.asList(thisClass.getInterfaces()).contains(targetClass)) {
130118
return getInterfaceRemap(thisClass, targetClass);
131119
}
120+
val superInterface = Arrays
121+
.stream(thisClass.getInterfaces())
122+
.filter(targetClass::isAssignableFrom)
123+
.findFirst()
124+
.orElse(null);
125+
if (superInterface == null) {
126+
return Collections.emptyMap();
127+
}
128+
val parentType = getGenericTypeReplacementForParentInterfaceMethods(superInterface, thatMethod);
129+
val parentReplacement = getInterfaceRemap(thisClass, superInterface);
130+
131+
for (val entry : parentType.entrySet()) {
132+
val variable = entry.getKey();
133+
val type = entry.getValue();
134+
135+
replacement.put(variable,
136+
type instanceof TypeVariable<?> typeVariable
137+
? parentReplacement.getOrDefault(typeVariable, typeVariable)
138+
: type
139+
);
140+
}
132141
return replacement;
133142
}
134143

src/main/java/zzzank/probejs/mixins/MixinConsole.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import dev.latvian.kubejs.script.ScriptType;
44
import dev.latvian.kubejs.util.ConsoleJS;
55
import dev.latvian.mods.rhino.RhinoException;
6+
import lombok.val;
67
import org.spongepowered.asm.mixin.Final;
78
import org.spongepowered.asm.mixin.Mixin;
89
import org.spongepowered.asm.mixin.Shadow;
@@ -14,7 +15,6 @@
1415
import zzzank.probejs.utils.FileUtils;
1516
import zzzank.probejs.utils.JsonUtils;
1617

17-
import java.nio.file.Path;
1818
import java.util.regex.Pattern;
1919

2020
@Mixin(value = ConsoleJS.class, remap = false)
@@ -34,11 +34,11 @@ public void reportError(String message, Throwable error, Pattern exitPattern, Ca
3434
return;
3535
}
3636
if (error instanceof RhinoException rhinoException) {
37-
Path path = FileUtils.parseSourcePath(rhinoException.sourceName());
37+
val path = FileUtils.parseSourcePath(rhinoException.sourceName());
3838
if (path == null) {
3939
return;
4040
}
41-
LintingWarning warning = new LintingWarning(
41+
val warning = new LintingWarning(
4242
path,
4343
LintingWarning.Level.ERROR,
4444
rhinoException.lineNumber(),

src/main/java/zzzank/probejs/utils/CollectUtils.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,22 @@ static <T> T anyIn(Iterable<T> iterable) {
8686
static <T> T anyIn(Stream<T> stream) {
8787
return stream.findAny().orElse(null);
8888
}
89+
90+
static <T> Iterator<T> enumToItr(Enumeration<T> enumeration) {
91+
return new Iterator<T>() {
92+
@Override
93+
public boolean hasNext() {
94+
return enumeration.hasMoreElements();
95+
}
96+
97+
@Override
98+
public T next() {
99+
return enumeration.nextElement();
100+
}
101+
};
102+
}
103+
104+
static <T> Iterable<T> enumToIterable(Enumeration<T> enumeration) {
105+
return () -> enumToItr(enumeration);
106+
}
89107
}

src/main/java/zzzank/probejs/utils/NameUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public class NameUtils {
1414
public static final Pattern MATCH_CONST_REQUIRE = Pattern.compile("^const \\{(.+)} = require\\((.+)\\)");
1515
public static final Pattern MATCH_ANY_REQUIRE = Pattern.compile("^.+ \\{(.+)} = require\\((.+)\\)");
1616

17-
1817
public static String[] extractAlphabets(String input) {
1918
return input.split("[^a-zA-Z]+");
2019
}

src/main/java/zzzank/probejs/utils/registry/RegistryInfo.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
import net.minecraft.tags.StaticTags;
88
import net.minecraftforge.registries.ForgeRegistry;
99
import net.minecraftforge.registries.IForgeRegistryEntry;
10+
import org.jetbrains.annotations.NotNull;
1011
import org.jetbrains.annotations.Nullable;
1112

1213
import java.util.Set;
1314

14-
public class RegistryInfo {
15+
public class RegistryInfo implements Comparable<RegistryInfo> {
1516

1617
public final Registry<?> raw;
1718
public final ForgeRegistry<? extends IForgeRegistryEntry<?>> forgeRaw;
@@ -42,4 +43,9 @@ public RegistryInfo(Registry<?> registry) {
4243
this.names = raw.keySet();
4344
this.tagHelper = StaticTags.get(this.id);
4445
}
46+
47+
@Override
48+
public int compareTo(@NotNull RegistryInfo o) {
49+
return resKey.compareTo(o.resKey);
50+
}
4551
}

0 commit comments

Comments
 (0)