91 lines
4.1 KiB
Java
91 lines
4.1 KiB
Java
package lombok.core;
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.OutputStream;
|
|
import java.io.PrintWriter;
|
|
import java.io.StringWriter;
|
|
import java.io.Writer;
|
|
import java.util.Collections;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
/* loaded from: com.discord-119106.apk:lombok/core/PostCompiler.SCL.lombok */
|
|
public final class PostCompiler {
|
|
private static List<PostCompilerTransformation> transformations;
|
|
|
|
/* renamed from: lombok.core.PostCompiler$1 reason: invalid class name */
|
|
/* loaded from: com.discord-119106.apk:lombok/core/PostCompiler$1.SCL.lombok */
|
|
class AnonymousClass1 extends ByteArrayOutputStream {
|
|
private final /* synthetic */ String val$fileName;
|
|
private final /* synthetic */ DiagnosticsReceiver val$diagnostics;
|
|
private final /* synthetic */ OutputStream val$originalStream;
|
|
|
|
AnonymousClass1(String str, DiagnosticsReceiver diagnosticsReceiver, OutputStream outputStream) {
|
|
this.val$fileName = str;
|
|
this.val$diagnostics = diagnosticsReceiver;
|
|
this.val$originalStream = outputStream;
|
|
}
|
|
|
|
@Override // java.io.ByteArrayOutputStream, java.io.OutputStream, java.io.Closeable, java.lang.AutoCloseable
|
|
public void close() throws IOException {
|
|
byte[] byteArray = toByteArray();
|
|
byte[] bArr = null;
|
|
if (byteArray.length > 0) {
|
|
try {
|
|
bArr = PostCompiler.applyTransformations(byteArray, this.val$fileName, this.val$diagnostics);
|
|
} catch (Exception unused) {
|
|
this.val$diagnostics.addWarning(String.format("Error during the transformation of '%s'; no post-compilation has been applied", this.val$fileName));
|
|
}
|
|
}
|
|
if (bArr == null) {
|
|
bArr = byteArray;
|
|
}
|
|
this.val$originalStream.write(bArr);
|
|
this.val$originalStream.close();
|
|
}
|
|
}
|
|
|
|
private PostCompiler() {
|
|
}
|
|
|
|
public static byte[] applyTransformations(byte[] bArr, String str, DiagnosticsReceiver diagnosticsReceiver) {
|
|
if (System.getProperty("lombok.disablePostCompiler", null) != null) {
|
|
return bArr;
|
|
}
|
|
init(diagnosticsReceiver);
|
|
byte[] bArr2 = bArr;
|
|
Iterator<PostCompilerTransformation> it = transformations.iterator();
|
|
while (it.hasNext()) {
|
|
PostCompilerTransformation next = it.next();
|
|
try {
|
|
byte[] applyTransformations = next.applyTransformations(bArr2, str, diagnosticsReceiver);
|
|
if (applyTransformations != null) {
|
|
bArr2 = applyTransformations;
|
|
}
|
|
} catch (Exception e) {
|
|
StringWriter stringWriter = new StringWriter();
|
|
e.printStackTrace(new PrintWriter((Writer) stringWriter, true));
|
|
diagnosticsReceiver.addError(String.format("Error during the transformation of '%s'; post-compiler '%s' caused an exception: %s", str, next.getClass().getName(), stringWriter));
|
|
}
|
|
}
|
|
return bArr2;
|
|
}
|
|
|
|
private static synchronized void init(DiagnosticsReceiver diagnosticsReceiver) {
|
|
if (transformations == null) {
|
|
try {
|
|
transformations = SpiLoadUtil.readAllFromIterator(SpiLoadUtil.findServices(PostCompilerTransformation.class, PostCompilerTransformation.class.getClassLoader()));
|
|
} catch (IOException e) {
|
|
transformations = Collections.emptyList();
|
|
StringWriter stringWriter = new StringWriter();
|
|
e.printStackTrace(new PrintWriter((Writer) stringWriter, true));
|
|
diagnosticsReceiver.addError("Could not load post-compile transformers: " + e.getMessage() + "\n" + stringWriter.toString());
|
|
}
|
|
}
|
|
}
|
|
|
|
public static OutputStream wrapOutputStream(OutputStream outputStream, String str, DiagnosticsReceiver diagnosticsReceiver) throws IOException {
|
|
return System.getProperty("lombok.disablePostCompiler", null) != null ? outputStream : new AnonymousClass1(str, diagnosticsReceiver, outputStream);
|
|
}
|
|
}
|