discord-jadx/app/src/main/java/lombok/bytecode/SneakyThrowsRemover.java

196 lines
8.1 KiB
Java

package lombok.bytecode;
import java.util.concurrent.atomic.AtomicBoolean;
import lombok.core.DiagnosticsReceiver;
import lombok.core.PostCompilerTransformation;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
/* loaded from: com.discord-118107.apk:lombok/bytecode/SneakyThrowsRemover.SCL.lombok */
public class SneakyThrowsRemover implements PostCompilerTransformation {
/* renamed from: lombok.bytecode.SneakyThrowsRemover$1 reason: invalid class name */
/* loaded from: com.discord-118107.apk:lombok/bytecode/SneakyThrowsRemover$1.SCL.lombok */
class AnonymousClass1 extends ClassVisitor {
private final /* synthetic */ DiagnosticsReceiver val$diagnostics;
private final /* synthetic */ AtomicBoolean val$changesMade;
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
AnonymousClass1(int i, ClassVisitor classVisitor, DiagnosticsReceiver diagnosticsReceiver, AtomicBoolean atomicBoolean) {
super(i, classVisitor);
this.val$diagnostics = diagnosticsReceiver;
this.val$changesMade = atomicBoolean;
}
@Override // org.objectweb.asm.ClassVisitor
public MethodVisitor visitMethod(int i, String str, String str2, String str3, String[] strArr) {
return new C1SneakyThrowsRemoverVisitor(super.visitMethod(i, str, str2, str3, strArr), this.val$diagnostics, this.val$changesMade);
}
}
/* renamed from: lombok.bytecode.SneakyThrowsRemover$1SneakyThrowsRemoverVisitor reason: invalid class name */
/* loaded from: com.discord-118107.apk:lombok/bytecode/SneakyThrowsRemover$1SneakyThrowsRemoverVisitor.SCL.lombok */
class C1SneakyThrowsRemoverVisitor extends MethodVisitor {
private boolean methodInsnQueued = false;
private final /* synthetic */ DiagnosticsReceiver val$diagnostics;
private final /* synthetic */ AtomicBoolean val$changesMade;
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
C1SneakyThrowsRemoverVisitor(MethodVisitor methodVisitor, DiagnosticsReceiver diagnosticsReceiver, AtomicBoolean atomicBoolean) {
super(Opcodes.ASM7, methodVisitor);
this.val$diagnostics = diagnosticsReceiver;
this.val$changesMade = atomicBoolean;
}
@Override // org.objectweb.asm.MethodVisitor
public void visitMethodInsn(int i, String str, String str2, String str3, boolean z2) {
if (i != 184 || !"sneakyThrow".equals(str2) || !"lombok/Lombok".equals(str) || !"(Ljava/lang/Throwable;)Ljava/lang/RuntimeException;".equals(str3)) {
super.visitMethodInsn(i, str, str2, str3, z2);
} else if (System.getProperty("lombok.debugAsmOnly", null) != null) {
super.visitMethodInsn(i, str, str2, str3, z2);
} else {
this.methodInsnQueued = true;
}
}
private void handleQueue() {
if (this.methodInsnQueued) {
super.visitMethodInsn(Opcodes.INVOKESTATIC, "lombok/Lombok", "sneakyThrow", "(Ljava/lang/Throwable;)Ljava/lang/RuntimeException;", false);
this.methodInsnQueued = false;
this.val$diagnostics.addWarning("Proper usage is: throw lombok.Lombok.sneakyThrow(someException);. You did not 'throw' it. Because of this, the call to sneakyThrow remains in your classfile and you will need lombok.jar on the classpath at runtime.");
}
}
@Override // org.objectweb.asm.MethodVisitor
public void visitInsn(int i) {
if (this.methodInsnQueued && i == 191) {
this.val$changesMade.set(true);
this.methodInsnQueued = false;
}
handleQueue();
super.visitInsn(i);
}
@Override // org.objectweb.asm.MethodVisitor
public void visitFrame(int i, int i2, Object[] objArr, int i3, Object[] objArr2) {
handleQueue();
super.visitFrame(i, i2, objArr, i3, objArr2);
}
@Override // org.objectweb.asm.MethodVisitor
public void visitIincInsn(int i, int i2) {
handleQueue();
super.visitIincInsn(i, i2);
}
@Override // org.objectweb.asm.MethodVisitor
public void visitFieldInsn(int i, String str, String str2, String str3) {
handleQueue();
super.visitFieldInsn(i, str, str2, str3);
}
@Override // org.objectweb.asm.MethodVisitor
public void visitIntInsn(int i, int i2) {
handleQueue();
super.visitIntInsn(i, i2);
}
@Override // org.objectweb.asm.MethodVisitor
public void visitEnd() {
handleQueue();
super.visitEnd();
}
@Override // org.objectweb.asm.MethodVisitor
public void visitInvokeDynamicInsn(String str, String str2, Handle handle, Object... objArr) {
handleQueue();
super.visitInvokeDynamicInsn(str, str2, handle, objArr);
}
@Override // org.objectweb.asm.MethodVisitor
public void visitLabel(Label label) {
handleQueue();
super.visitLabel(label);
}
@Override // org.objectweb.asm.MethodVisitor
public void visitJumpInsn(int i, Label label) {
handleQueue();
super.visitJumpInsn(i, label);
}
@Override // org.objectweb.asm.MethodVisitor
public void visitLdcInsn(Object obj) {
handleQueue();
super.visitLdcInsn(obj);
}
@Override // org.objectweb.asm.MethodVisitor
public void visitLocalVariable(String str, String str2, String str3, Label label, Label label2, int i) {
handleQueue();
super.visitLocalVariable(str, str2, str3, label, label2, i);
}
@Override // org.objectweb.asm.MethodVisitor
public void visitMaxs(int i, int i2) {
handleQueue();
super.visitMaxs(i, i2);
}
@Override // org.objectweb.asm.MethodVisitor
public void visitLookupSwitchInsn(Label label, int[] iArr, Label[] labelArr) {
handleQueue();
super.visitLookupSwitchInsn(label, iArr, labelArr);
}
@Override // org.objectweb.asm.MethodVisitor
public void visitMultiANewArrayInsn(String str, int i) {
handleQueue();
super.visitMultiANewArrayInsn(str, i);
}
@Override // org.objectweb.asm.MethodVisitor
public void visitVarInsn(int i, int i2) {
handleQueue();
super.visitVarInsn(i, i2);
}
@Override // org.objectweb.asm.MethodVisitor
public void visitTryCatchBlock(Label label, Label label2, Label label3, String str) {
handleQueue();
super.visitTryCatchBlock(label, label2, label3, str);
}
@Override // org.objectweb.asm.MethodVisitor
public void visitTableSwitchInsn(int i, int i2, Label label, Label... labelArr) {
handleQueue();
super.visitTableSwitchInsn(i, i2, label, labelArr);
}
@Override // org.objectweb.asm.MethodVisitor
public void visitTypeInsn(int i, String str) {
handleQueue();
super.visitTypeInsn(i, str);
}
}
@Override // lombok.core.PostCompilerTransformation
public byte[] applyTransformations(byte[] bArr, String str, DiagnosticsReceiver diagnosticsReceiver) {
if (!new ClassFileMetaData(bArr).usesMethod("lombok/Lombok", "sneakyThrow")) {
return null;
}
ClassReader classReader = new ClassReader(AsmUtil.fixJSRInlining(bArr));
ClassWriter classWriter = new ClassWriter(classReader, 0);
AtomicBoolean atomicBoolean = new AtomicBoolean();
classReader.accept(new AnonymousClass1(Opcodes.ASM7, classWriter, diagnosticsReceiver, atomicBoolean), 0);
if (atomicBoolean.get()) {
return classWriter.toByteArray();
}
return null;
}
}