Skip to content

Commit

Permalink
Add hidden prefixes (#2)
Browse files Browse the repository at this point in the history
JSTs ignored prefixes are still pushed into the output file sink, which
is not needed when the input and output sources are the same.
The commit adds a stronger version of ignored prefixes, "hidden"
prefixes, which are not processed or pushed to the output sink.
  • Loading branch information
lynxplay authored Dec 18, 2024
1 parent 7b55b32 commit b854fc5
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ Usage: jst [-hV] [--in-format=<inputFormat>] [--libraries-list=<librariesList>]
--classpath=<addToClasspath>
Additional classpath entries to use. Is combined with --libraries-list.
-h, --help Show this help message and exit.
--hidden-prefix=<hiddenPrefixes>
Do not process or emit paths that start with any of these prefixes.
--ignore-prefix=<ignoredPrefixes>
Do not apply transformations to paths that start with any of these
prefixes.
Expand Down
7 changes: 7 additions & 0 deletions cli/src/main/java/net/neoforged/jst/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public class Main implements Callable<Integer> {
@CommandLine.Option(names = "--ignore-prefix", description = "Do not apply transformations to paths that start with any of these prefixes.")
List<String> ignoredPrefixes = new ArrayList<>();

@CommandLine.Option(names = "--hidden-prefix", description = "Do not process or emit paths that start with any of these prefixes.")
List<String> hiddenPrefixes = new ArrayList<>();

@CommandLine.Option(names = "--classpath", description = "Additional classpath entries to use. Is combined with --libraries-list.", converter = ClasspathConverter.class)
List<Path> addToClasspath = new ArrayList<>();

Expand Down Expand Up @@ -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);

Expand Down
19 changes: 17 additions & 2 deletions cli/src/main/java/net/neoforged/jst/cli/SourceFileProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class SourceFileProcessor implements AutoCloseable {
private final Logger logger;

private final List<String> ignoredPrefixes = new ArrayList<>();
private final List<String> hiddenPrefixes = new ArrayList<>();

public SourceFileProcessor(Logger logger) throws IOException {
this.logger = logger;
Expand Down Expand Up @@ -114,13 +115,21 @@ private boolean processEntry(FileEntry entry, VirtualFile sourceRoot, List<Sourc
lastModified = FileTime.from(Instant.now());
}
}
sink.putFile(entry.relativePath(), lastModified, content);
if (!isHidden(entry.relativePath())) sink.putFile(entry.relativePath(), lastModified, content);
}
return true;
}

private boolean isIgnored(String relativePath) {
for (String ignoredPrefix : ignoredPrefixes) {
return isRelativePathIn(relativePath, this.ignoredPrefixes);
}

private boolean isHidden(String relativePath) {
return isRelativePathIn(relativePath, this.hiddenPrefixes);
}

private boolean isRelativePathIn(String relativePath, List<String> prefixes) {
for (String ignoredPrefix : prefixes) {
if (relativePath.startsWith(ignoredPrefix)) {
return true;
}
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public C1
3 changes: 3 additions & 0 deletions tests/data/accesstransformer/hidden_prefix/expected/C1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public class C1 {
C1() {}
}
2 changes: 2 additions & 0 deletions tests/data/accesstransformer/hidden_prefix/source/C1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class C1 {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package other;

final class C2f {

}
5 changes: 5 additions & 0 deletions tests/src/test/java/net/neoforged/jst/tests/EmbeddedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b854fc5

Please sign in to comment.