-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add chain builder and adjust visitor factory
- Loading branch information
Showing
7 changed files
with
148 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/main/java/io/papermc/asm/RewriteRuleVisitorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package io.papermc.asm; | ||
|
||
import io.papermc.asm.rules.RewriteRule; | ||
import java.util.function.Supplier; | ||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
import org.checkerframework.framework.qual.DefaultQualifier; | ||
import org.objectweb.asm.ClassVisitor; | ||
|
||
@DefaultQualifier(NonNull.class) | ||
public final class RewriteRuleVisitorFactory { | ||
|
||
private final int api; | ||
private final Supplier<RewriteRule> ruleFactory; | ||
private volatile @MonotonicNonNull RewriteRule rule; | ||
private final ClassInfoProvider classInfoProvider; | ||
|
||
public RewriteRuleVisitorFactory( | ||
final int api, | ||
final Supplier<RewriteRule> ruleFactory, | ||
final ClassInfoProvider classInfoProvider | ||
) { | ||
this.api = api; | ||
this.ruleFactory = ruleFactory; | ||
this.classInfoProvider = classInfoProvider; | ||
} | ||
|
||
public RewriteRuleVisitorFactory( | ||
final int api, | ||
final RewriteRule rule, | ||
final ClassInfoProvider classInfoProvider | ||
) { | ||
this(api, () -> rule, classInfoProvider); | ||
} | ||
|
||
public ClassVisitor createVisitor(final ClassVisitor parent) { | ||
final MutableProcessingContext context = new MutableProcessingContext(); | ||
final ClassVisitor ruleVisitor = this.rule().createVisitor(this.api, parent, context); | ||
return new ContextFillerVisitor(this.api, ruleVisitor, context); | ||
} | ||
|
||
private RewriteRule rule() { | ||
@Nullable RewriteRule rule = this.rule; | ||
if (rule != null) { | ||
return rule; | ||
} | ||
|
||
synchronized (this) { | ||
rule = this.rule; | ||
if (rule == null) { | ||
rule = this.ruleFactory.get(); | ||
this.rule = rule; | ||
} | ||
} | ||
|
||
return rule; | ||
} | ||
|
||
private final class MutableProcessingContext implements ClassProcessingContext { | ||
private @MonotonicNonNull String name; | ||
private @Nullable String superName; | ||
|
||
@Override | ||
public ClassInfoProvider classInfoProvider() { | ||
return RewriteRuleVisitorFactory.this.classInfoProvider; | ||
} | ||
|
||
@Override | ||
public String processingClassName() { | ||
return this.name; | ||
} | ||
|
||
@Override | ||
public @Nullable String processingClassSuperClassName() { | ||
return this.superName; | ||
} | ||
} | ||
|
||
private static final class ContextFillerVisitor extends ClassVisitor { | ||
|
||
private final MutableProcessingContext context; | ||
|
||
private ContextFillerVisitor(final int api, final ClassVisitor classVisitor, final MutableProcessingContext context) { | ||
super(api, classVisitor); | ||
this.context = context; | ||
} | ||
|
||
@Override | ||
public void visit(final int version, final int access, final String name, final @Nullable String signature, final @Nullable String superName, final String @Nullable [] interfaces) { | ||
super.visit(version, access, name, signature, superName, interfaces); | ||
this.context.name = name; | ||
this.context.superName = superName; | ||
} | ||
} | ||
} |
72 changes: 0 additions & 72 deletions
72
src/main/java/io/papermc/asm/RewriteRulesVisitorFactory.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters