Simplify LinkageProcessor
This commit is contained in:
@@ -45,6 +45,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -114,6 +115,14 @@ public class LinkageProcessor extends AbstractProcessor {
|
||||
.forEach(disabledFeatures::add);
|
||||
}
|
||||
|
||||
private File getFile(File file, Predicate<File> predicate) {
|
||||
while (file != null) {
|
||||
if (predicate.test(file)) return file;
|
||||
file = file.getParentFile();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||
@@ -121,14 +130,9 @@ public class LinkageProcessor extends AbstractProcessor {
|
||||
processed = true;
|
||||
|
||||
URI uri = processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, "", ".ignore").toUri();
|
||||
File file = new File(uri.toString().substring(7)).getParentFile();
|
||||
do {
|
||||
if (!file.getName().contains("_") && new File(file, "build.gradle.kts").exists()) {
|
||||
break;
|
||||
}
|
||||
file = file.getParentFile();
|
||||
if (file == null) return false;
|
||||
} while (true);
|
||||
File file = getFile(new File(uri.toString().substring(7)), f -> {
|
||||
return !f.getName().contains("_") && new File(f, "build.gradle.kts").exists();
|
||||
});
|
||||
|
||||
name = file.getName().replaceAll("[^a-zA-Z]", "").toLowerCase();
|
||||
mainClass(file);
|
||||
|
||||
Reference in New Issue
Block a user