Skip to content

Commit b854fc5

Browse files
authored
Add hidden prefixes (#2)
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.
1 parent 7b55b32 commit b854fc5

File tree

8 files changed

+42
-2
lines changed

8 files changed

+42
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ Usage: jst [-hV] [--in-format=<inputFormat>] [--libraries-list=<librariesList>]
7272
--classpath=<addToClasspath>
7373
Additional classpath entries to use. Is combined with --libraries-list.
7474
-h, --help Show this help message and exit.
75+
--hidden-prefix=<hiddenPrefixes>
76+
Do not process or emit paths that start with any of these prefixes.
7577
--ignore-prefix=<ignoredPrefixes>
7678
Do not apply transformations to paths that start with any of these
7779
prefixes.

cli/src/main/java/net/neoforged/jst/cli/Main.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public class Main implements Callable<Integer> {
3535
@CommandLine.Option(names = "--ignore-prefix", description = "Do not apply transformations to paths that start with any of these prefixes.")
3636
List<String> ignoredPrefixes = new ArrayList<>();
3737

38+
@CommandLine.Option(names = "--hidden-prefix", description = "Do not process or emit paths that start with any of these prefixes.")
39+
List<String> hiddenPrefixes = new ArrayList<>();
40+
3841
@CommandLine.Option(names = "--classpath", description = "Additional classpath entries to use. Is combined with --libraries-list.", converter = ClasspathConverter.class)
3942
List<Path> addToClasspath = new ArrayList<>();
4043

@@ -79,6 +82,10 @@ public Integer call() throws Exception {
7982
for (String ignoredPrefix : ignoredPrefixes) {
8083
processor.addIgnoredPrefix(ignoredPrefix);
8184
}
85+
for (String hiddenPrefix : hiddenPrefixes) {
86+
processor.addIgnoredPrefix(hiddenPrefix);
87+
processor.addHiddenPrefix(hiddenPrefix);
88+
}
8289

8390
processor.setMaxQueueDepth(maxQueueDepth);
8491

cli/src/main/java/net/neoforged/jst/cli/SourceFileProcessor.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class SourceFileProcessor implements AutoCloseable {
3434
private final Logger logger;
3535

3636
private final List<String> ignoredPrefixes = new ArrayList<>();
37+
private final List<String> hiddenPrefixes = new ArrayList<>();
3738

3839
public SourceFileProcessor(Logger logger) throws IOException {
3940
this.logger = logger;
@@ -114,13 +115,21 @@ private boolean processEntry(FileEntry entry, VirtualFile sourceRoot, List<Sourc
114115
lastModified = FileTime.from(Instant.now());
115116
}
116117
}
117-
sink.putFile(entry.relativePath(), lastModified, content);
118+
if (!isHidden(entry.relativePath())) sink.putFile(entry.relativePath(), lastModified, content);
118119
}
119120
return true;
120121
}
121122

122123
private boolean isIgnored(String relativePath) {
123-
for (String ignoredPrefix : ignoredPrefixes) {
124+
return isRelativePathIn(relativePath, this.ignoredPrefixes);
125+
}
126+
127+
private boolean isHidden(String relativePath) {
128+
return isRelativePathIn(relativePath, this.hiddenPrefixes);
129+
}
130+
131+
private boolean isRelativePathIn(String relativePath, List<String> prefixes) {
132+
for (String ignoredPrefix : prefixes) {
124133
if (relativePath.startsWith(ignoredPrefix)) {
125134
return true;
126135
}
@@ -187,6 +196,12 @@ public void addIgnoredPrefix(String ignoredPrefix) {
187196
this.ignoredPrefixes.add(ignoredPrefix);
188197
}
189198

199+
public void addHiddenPrefix(String hiddenPrefix) {
200+
System.out.println("Not reading entries starting with " + hiddenPrefix);
201+
this.ignoredPrefixes.add(hiddenPrefix);
202+
this.hiddenPrefixes.add(hiddenPrefix);
203+
}
204+
190205
@Override
191206
public void close() throws IOException {
192207
ijEnv.close();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public C1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public class C1 {
2+
C1() {}
3+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class C1 {
2+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package other;
2+
3+
final class C2f {
4+
5+
}

tests/src/test/java/net/neoforged/jst/tests/EmbeddedTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@ void testMethodsNoInheritance() throws Exception {
297297
void testMethodsInheritance() throws Exception {
298298
runATTest("methods_inheritance", "--access-transformer-inherit-method");
299299
}
300+
301+
@Test
302+
void testHiddenPrefixes() throws Exception {
303+
runATTest("hidden_prefix", "--hidden-prefix=other");
304+
}
300305
}
301306

302307
@Nested

0 commit comments

Comments
 (0)