diff --git a/README.md b/README.md index c6ff7ba..ec6b1a2 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,8 @@ Usage: jst [-hV] [--in-format=] [--libraries-list=] --classpath= Additional classpath entries to use. Is combined with --libraries-list. -h, --help Show this help message and exit. + --hidden-prefix= + Do not process or emit paths that start with any of these prefixes. --ignore-prefix= Do not apply transformations to paths that start with any of these prefixes. diff --git a/cli/src/main/java/net/neoforged/jst/cli/Main.java b/cli/src/main/java/net/neoforged/jst/cli/Main.java index 613d2e1..2415666 100644 --- a/cli/src/main/java/net/neoforged/jst/cli/Main.java +++ b/cli/src/main/java/net/neoforged/jst/cli/Main.java @@ -35,6 +35,9 @@ public class Main implements Callable { @CommandLine.Option(names = "--ignore-prefix", description = "Do not apply transformations to paths that start with any of these prefixes.") List ignoredPrefixes = new ArrayList<>(); + @CommandLine.Option(names = "--hidden-prefix", description = "Do not process or emit paths that start with any of these prefixes.") + List hiddenPrefixes = new ArrayList<>(); + @CommandLine.Option(names = "--classpath", description = "Additional classpath entries to use. Is combined with --libraries-list.", converter = ClasspathConverter.class) List addToClasspath = new ArrayList<>(); @@ -79,6 +82,10 @@ public Integer call() throws Exception { for (String ignoredPrefix : ignoredPrefixes) { processor.addIgnoredPrefix(ignoredPrefix); } + for (String hiddenPrefix : hiddenPrefixes) { + processor.addIgnoredPrefix(hiddenPrefix); + processor.addHiddenPrefix(hiddenPrefix); + } processor.setMaxQueueDepth(maxQueueDepth); diff --git a/cli/src/main/java/net/neoforged/jst/cli/SourceFileProcessor.java b/cli/src/main/java/net/neoforged/jst/cli/SourceFileProcessor.java index 5e7dd06..a20fc92 100644 --- a/cli/src/main/java/net/neoforged/jst/cli/SourceFileProcessor.java +++ b/cli/src/main/java/net/neoforged/jst/cli/SourceFileProcessor.java @@ -34,6 +34,7 @@ class SourceFileProcessor implements AutoCloseable { private final Logger logger; private final List ignoredPrefixes = new ArrayList<>(); + private final List hiddenPrefixes = new ArrayList<>(); public SourceFileProcessor(Logger logger) throws IOException { this.logger = logger; @@ -114,13 +115,21 @@ private boolean processEntry(FileEntry entry, VirtualFile sourceRoot, List prefixes) { + for (String ignoredPrefix : prefixes) { if (relativePath.startsWith(ignoredPrefix)) { return true; } @@ -187,6 +196,12 @@ public void addIgnoredPrefix(String ignoredPrefix) { this.ignoredPrefixes.add(ignoredPrefix); } + public void addHiddenPrefix(String hiddenPrefix) { + System.out.println("Not reading entries starting with " + hiddenPrefix); + this.ignoredPrefixes.add(hiddenPrefix); + this.hiddenPrefixes.add(hiddenPrefix); + } + @Override public void close() throws IOException { ijEnv.close(); diff --git a/tests/data/accesstransformer/hidden_prefix/accesstransformer.cfg b/tests/data/accesstransformer/hidden_prefix/accesstransformer.cfg new file mode 100644 index 0000000..03fbbc4 --- /dev/null +++ b/tests/data/accesstransformer/hidden_prefix/accesstransformer.cfg @@ -0,0 +1 @@ +public C1 diff --git a/tests/data/accesstransformer/hidden_prefix/expected/C1.java b/tests/data/accesstransformer/hidden_prefix/expected/C1.java new file mode 100644 index 0000000..9784452 --- /dev/null +++ b/tests/data/accesstransformer/hidden_prefix/expected/C1.java @@ -0,0 +1,3 @@ +public class C1 { + C1() {} +} diff --git a/tests/data/accesstransformer/hidden_prefix/source/C1.java b/tests/data/accesstransformer/hidden_prefix/source/C1.java new file mode 100644 index 0000000..44f95f7 --- /dev/null +++ b/tests/data/accesstransformer/hidden_prefix/source/C1.java @@ -0,0 +1,2 @@ +class C1 { +} diff --git a/tests/data/accesstransformer/hidden_prefix/source/other/C2f.java b/tests/data/accesstransformer/hidden_prefix/source/other/C2f.java new file mode 100644 index 0000000..95e179b --- /dev/null +++ b/tests/data/accesstransformer/hidden_prefix/source/other/C2f.java @@ -0,0 +1,5 @@ +package other; + +final class C2f { + +} diff --git a/tests/src/test/java/net/neoforged/jst/tests/EmbeddedTest.java b/tests/src/test/java/net/neoforged/jst/tests/EmbeddedTest.java index 0beb39d..bc8e05f 100644 --- a/tests/src/test/java/net/neoforged/jst/tests/EmbeddedTest.java +++ b/tests/src/test/java/net/neoforged/jst/tests/EmbeddedTest.java @@ -297,6 +297,11 @@ void testMethodsNoInheritance() throws Exception { void testMethodsInheritance() throws Exception { runATTest("methods_inheritance", "--access-transformer-inherit-method"); } + + @Test + void testHiddenPrefixes() throws Exception { + runATTest("hidden_prefix", "--hidden-prefix=other"); + } } @Nested