Skip to content

Commit

Permalink
Merge pull request #1 from babbaj/master
Browse files Browse the repository at this point in the history
Give control to ITransformer to figure out what classes it targets
  • Loading branch information
ZeroMemes authored Oct 13, 2018
2 parents 2d696d3 + 70b5afd commit 9feb1b1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ public interface ITransformer {
void transform(ClassNode cn);

/**
* Returns the target class names. If none are returned,
* then it is assumed that the transformer is targetting
* all classes.
* Returns whether or not a class is targeted by this transformer.
* The given class may or may not be given in an obfuscated form.
*
* @return Target class names
* @return True if this transformer targets the given class
*/
default String[] getTargets() {
return new String[0];
default boolean isTarget(String className) {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class SimpleTransformer implements IClassTransformer {
*/
private final List<ITransformer> transformers = new ArrayList<>();

// This should only be used by the launchwrapper
public SimpleTransformer() {
// Set the instance
instance = this;
Expand All @@ -56,7 +57,7 @@ public final byte[] transform(String name, String transformedName, byte[] basicC
if (basicClass == null)
return null;

List<ITransformer> transformers = getTransformers(transformedName);
final List<ITransformer> transformers = getTransformers(transformedName);

if (!transformers.isEmpty()) {
try {
Expand Down Expand Up @@ -109,12 +110,12 @@ public final void registerAll(ITransformer... transformers) {
*/
private List<ITransformer> getTransformers(String name) {
return transformers.stream()
.filter(transformer -> transformer.getTargets().length == 0 || Arrays.asList(transformer.getTargets()).contains(name))
.filter(transformer -> transformer.isTarget(name))
.collect(Collectors.toList());
}

/**
* Instantiates a new transformer using reflections. Transformer must
* Instantiates a new transformer using reflection. Transformer must
* have a constructor that takes no parameters.
*
* @param clazz The transformer class name
Expand Down

0 comments on commit 9feb1b1

Please sign in to comment.