Skip to content
This repository was archived by the owner on May 12, 2024. It is now read-only.

Commit 61f71e7

Browse files
committed
Return the result
1 parent 37c53c2 commit 61f71e7

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

src/main/java/net/raphimc/javadowngrader/JavaDowngrader.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package net.raphimc.javadowngrader;
1919

20+
import net.raphimc.javadowngrader.transformer.DowngradeResult;
2021
import net.raphimc.javadowngrader.transformer.DowngradingTransformer;
2122
import net.raphimc.javadowngrader.transformer.j10.Java11ToJava10;
2223
import net.raphimc.javadowngrader.transformer.j11.Java12ToJava11;
@@ -61,10 +62,11 @@ public class JavaDowngrader {
6162
*
6263
* @param classNode The class to downgrade
6364
* @param targetVersion The target Java version
65+
* @return The downgrade result
6466
* @see ClassNode
6567
*/
66-
public static void downgrade(final ClassNode classNode, final int targetVersion) {
67-
downgrade(classNode, targetVersion, RuntimeDepCollector.NULL);
68+
public static DowngradeResult downgrade(final ClassNode classNode, final int targetVersion) {
69+
return downgrade(classNode, targetVersion, RuntimeDepCollector.NULL);
6870
}
6971

7072
/**
@@ -74,15 +76,19 @@ public static void downgrade(final ClassNode classNode, final int targetVersion)
7476
* @param targetVersion The target Java version
7577
* @param depCollector The {@link RuntimeDepCollector} to use to collect runtime dependencies. Check the javadoc
7678
* of {@link RuntimeDepCollector} for more info.
79+
* @return The downgrade result
7780
* @see ClassNode
7881
* @see RuntimeDepCollector
7982
*/
80-
public static void downgrade(final ClassNode classNode, final int targetVersion, final RuntimeDepCollector depCollector) {
83+
public static DowngradeResult downgrade(final ClassNode classNode, final int targetVersion, final RuntimeDepCollector depCollector) {
84+
DowngradeResult result = new DowngradeResult();
8185
for (DowngradingTransformer transformer : TRANSFORMER) {
8286
if (transformer.getTargetVersion() >= targetVersion && (classNode.version & 0xFF) > transformer.getTargetVersion()) {
83-
transformer.transform(classNode, depCollector);
87+
DowngradeResult transformerResult = transformer.transform(classNode, depCollector);
88+
result.add(transformerResult);
8489
}
8590
}
91+
return result;
8692
}
8793

8894
}

src/main/java/net/raphimc/javadowngrader/transformer/DowngradeResult.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,42 @@ public class DowngradeResult {
2222
private int transformerCount;
2323
private boolean requiresStackMapFrames;
2424

25+
/**
26+
* @return The amount of transformers that were applied
27+
*/
2528
public int getTransformerCount() {
2629
return this.transformerCount;
2730
}
2831

32+
/**
33+
* Increments the transformer count by 1.
34+
*/
2935
public void incrementTransformerCount() {
3036
this.transformerCount++;
3137
}
3238

39+
/**
40+
* @return If the class requires stack map frame recalculation
41+
*/
3342
public boolean requiresStackMapFrames() {
3443
return this.requiresStackMapFrames;
3544
}
3645

46+
/**
47+
* Sets the class to require stack map frame recalculation.
48+
*/
3749
public void setRequiresStackMapFrames() {
3850
this.requiresStackMapFrames = true;
3951
}
4052

53+
/**
54+
* Adds the values of the given result to this result.
55+
*
56+
* @param result The result to add
57+
*/
58+
public void add(final DowngradeResult result) {
59+
this.transformerCount += result.transformerCount;
60+
this.requiresStackMapFrames |= result.requiresStackMapFrames;
61+
}
62+
4163
}

0 commit comments

Comments
 (0)