Skip to content

Commit

Permalink
Renames
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Sep 4, 2024
1 parent b6aa4c5 commit 590e6f5
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions cli/src/main/java/net/neoforged/jst/cli/SourceFileProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,16 @@ private boolean processEntry(FileEntry entry, VirtualFile sourceRoot, List<Sourc
return true;
}

boolean[] isOk = {true};
boolean[] success = {true};

try (var in = entry.openInputStream()) {
byte[] content = in.readAllBytes();
var lastModified = entry.lastModified();

if (!isIgnored(entry.relativePath()) && !transformers.isEmpty() && entry.hasExtension("java")) {
var orgContent = content;
content = transformSource(sourceRoot, entry, transformers, content, isOk);
if (!isOk[0]) {
content = transformSource(sourceRoot, entry, transformers, content, success);
if (!success[0]) {
return false;
}
if (orgContent != content) {
Expand All @@ -129,7 +129,7 @@ private boolean isIgnored(String relativePath) {
return false;
}

private byte[] transformSource(VirtualFile contentRoot, FileEntry entry, List<SourceTransformer> transformers, byte[] originalContentBytes, boolean[] status) {
private byte[] transformSource(VirtualFile contentRoot, FileEntry entry, List<SourceTransformer> transformers, byte[] originalContentBytes, boolean[] successOut) {
// Instead of parsing the content we actually read from the file, we read the virtual file that is
// visible to IntelliJ from adding the source jar. The reasoning is that IntelliJ will cache this internally
// and reuse it when cross-referencing type-references. If we parsed from a String instead, it would parse
Expand All @@ -155,15 +155,15 @@ private byte[] transformSource(VirtualFile contentRoot, FileEntry entry, List<So
}

var readOnlyReplacements = Collections.unmodifiableList(replacementsList);
boolean isOk = true;
boolean success = true;
for (var transformer : transformers) {
isOk = isOk && transformer.beforeReplacement(entry, readOnlyReplacements);
success = success && transformer.beforeReplacement(entry, readOnlyReplacements);
}

status[0] = isOk;
successOut[0] = success;

// If no replacements were made, just stream the original content into the destination file
if (!isOk || replacements.isEmpty()) {
if (!success || replacements.isEmpty()) {
return originalContentBytes;
}

Expand Down

0 comments on commit 590e6f5

Please sign in to comment.