Skip to content

Commit

Permalink
fix access widener transformer not providing the widened ClassNode
Browse files Browse the repository at this point in the history
  • Loading branch information
vectrixdevelops committed Mar 16, 2024
1 parent b800163 commit 573ca02
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ public void addResourceExclusion(final @NotNull Predicate<String> predicate) {
return input;
}

ClassNode node = new ClassNode(IgniteConstants.ASM_VERSION);

final Type type = Type.getObjectType(internalName);
final ClassNode node = new ClassNode(IgniteConstants.ASM_VERSION);
if(input.length > 0) {
final ClassReader reader = new ClassReader(input);
reader.accept(node, 0);
Expand All @@ -123,7 +124,11 @@ public void addResourceExclusion(final @NotNull Predicate<String> predicate) {
// If the transformer should not transform the class, skip it.
if(!service.shouldTransform(type, node)) continue;
// Attempt to transform the class.
transformed |= service.transform(type, node, phase);
final ClassNode transformedNode = service.transform(type, node, phase);
if(transformedNode != null) {
node = transformedNode;
transformed = true;
}
} catch(final Throwable throwable) {
Logger.error(throwable, "Failed to transform {} with {}", type.getClassName(), service.getClass().getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package space.vectrix.ignite.launch.ember;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.ClassNode;

Expand Down Expand Up @@ -71,14 +72,14 @@ public interface TransformerService {

/**
* Attempts to transform a class, with the given {@link Type}, {@link ClassNode}
* and {@link TransformPhase} and returns {@code true} if modifications were
* made, otherwise returns {@code false}.
* and {@link TransformPhase} and returns the {@link ClassNode} if modifications were
* made, otherwise returns {@code null}.
*
* @param type the type
* @param node the class node
* @param phase the transform phase
* @return whether the class was transformed
* @since 1.0.0
* @return whether the class node if the class was transformed
* @since 1.0.2
*/
boolean transform(final @NotNull Type type, final @NotNull ClassNode node, final @NotNull TransformPhase phase) throws Throwable;
@Nullable ClassNode transform(final @NotNull Type type, final @NotNull ClassNode node, final @NotNull TransformPhase phase) throws Throwable;
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public boolean shouldTransform(final @NotNull Type type, final @NotNull ClassNod
}

@Override
public boolean transform(final @NotNull Type type, final @NotNull ClassNode node, final @NotNull TransformPhase phase) throws Throwable {
public @NotNull ClassNode transform(final @NotNull Type type, final @NotNull ClassNode node, final @NotNull TransformPhase phase) throws Throwable {
final ClassNode widened = new ClassNode(IgniteConstants.ASM_VERSION);
widened.accept(node);

Expand All @@ -103,6 +103,6 @@ public boolean transform(final @NotNull Type type, final @NotNull ClassNode node
node.interfaces.clear();

widened.accept(visitor);
return true;
return widened;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package space.vectrix.ignite.launch.transformer;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.ClassNode;
Expand Down Expand Up @@ -82,14 +83,14 @@ public boolean shouldTransform(final @NotNull Type type, final @NotNull ClassNod
}

@Override
public boolean transform(final @NotNull Type type, final @NotNull ClassNode node, final @NotNull TransformPhase phase) throws Throwable {
public @Nullable ClassNode transform(final @NotNull Type type, final @NotNull ClassNode node, final @NotNull TransformPhase phase) throws Throwable {
// Generate the class if it is synthetic through mixin.
if(this.shouldGenerateClass(type)) {
return this.generateClass(type, node);
return this.generateClass(type, node) ? node : null;
}

// Transform the class through mixin.
return this.transformer.transformClass(MixinEnvironment.getCurrentEnvironment(), type.getClassName(), node);
return this.transformer.transformClass(MixinEnvironment.getCurrentEnvironment(), type.getClassName(), node) ? node : null;
}

/**
Expand Down

0 comments on commit 573ca02

Please sign in to comment.