package lombok.delombok; import com.discord.widgets.chat.input.autocomplete.AutocompleteViewModel; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; import java.util.Enumeration; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.jar.JarEntry; import java.util.jar.JarFile; import lombok.core.LombokApp; import lombok.permit.Permit; /* loaded from: com.discord-118107.apk:lombok/delombok/DelombokApp.SCL.lombok */ public class DelombokApp extends LombokApp { /* renamed from: lombok.delombok.DelombokApp$1 reason: invalid class name */ /* loaded from: com.discord-118107.apk:lombok/delombok/DelombokApp$1.SCL.lombok */ class AnonymousClass1 extends ClassLoader { private final /* synthetic */ JarFile val$toolsJarFile; private final /* synthetic */ File val$toolsJar; /* renamed from: lombok.delombok.DelombokApp$1$1 reason: invalid class name and collision with other inner class name */ /* loaded from: com.discord-118107.apk:lombok/delombok/DelombokApp$1$1.SCL.lombok */ class C04151 implements Enumeration { private boolean first = false; private final /* synthetic */ Enumeration val$parent; private final /* synthetic */ File val$toolsJar; private final /* synthetic */ String val$name; C04151(Enumeration enumeration, File file, String str) { this.val$parent = enumeration; this.val$toolsJar = file; this.val$name = str; } @Override // java.util.Enumeration public boolean hasMoreElements() { return !this.first || this.val$parent.hasMoreElements(); } /* JADX WARN: Can't rename method to resolve collision */ @Override // java.util.Enumeration public URL nextElement() { if (this.first) { return (URL) this.val$parent.nextElement(); } this.first = true; try { return new URL("jar:file:" + this.val$toolsJar.getAbsolutePath() + "!" + this.val$name); } catch (MalformedURLException unused) { return (URL) this.val$parent.nextElement(); } } } /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ AnonymousClass1(ClassLoader classLoader, JarFile jarFile, File file) { super(classLoader); this.val$toolsJarFile = jarFile; this.val$toolsJar = file; } private Class loadStreamAsClass(String str, boolean z2, InputStream inputStream) throws ClassNotFoundException { try { byte[] bArr = new byte[65536]; ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); while (true) { int read = inputStream.read(bArr); if (read == -1) { break; } byteArrayOutputStream.write(bArr, 0, read); } inputStream.close(); byte[] byteArray = byteArrayOutputStream.toByteArray(); Class defineClass = defineClass(str, byteArray, 0, byteArray.length); if (z2) { resolveClass(defineClass); } inputStream.close(); return defineClass; } catch (Exception e) { throw new ClassNotFoundException(str, e); } } @Override // java.lang.ClassLoader protected synchronized Class loadClass(String str, boolean z2) throws ClassNotFoundException { String replace = str.replace(".", AutocompleteViewModel.COMMAND_DISCOVER_TOKEN); String str2 = String.valueOf(replace) + ".class"; String str3 = String.valueOf(replace) + ".SCL.lombok"; JarEntry jarEntry = this.val$toolsJarFile.getJarEntry(str2); if (jarEntry != null) { try { return loadStreamAsClass(str, z2, this.val$toolsJarFile.getInputStream(jarEntry)); } catch (IOException e) { throw new ClassNotFoundException(str, e); } } else if (!str.startsWith("lombok.")) { return super.loadClass(str, z2); } else { InputStream resourceAsStream = getParent().getResourceAsStream(str2); if (resourceAsStream == null) { resourceAsStream = getParent().getResourceAsStream(str3); } return loadStreamAsClass(str, z2, resourceAsStream); } } @Override // java.lang.ClassLoader public URL getResource(String str) { if (this.val$toolsJarFile.getJarEntry(str) == null) { return super.getResource(str); } try { return new URL("jar:file:" + this.val$toolsJar.getAbsolutePath() + "!" + str); } catch (MalformedURLException unused) { return null; } } @Override // java.lang.ClassLoader public Enumeration getResources(String str) throws IOException { return this.val$toolsJarFile.getJarEntry(str) == null ? super.getResources(str) : new C04151(super.getResources(str), this.val$toolsJar, str); } } @Override // lombok.core.LombokApp public int runApp(List list) throws Exception { try { Class.forName("com.sun.tools.javac.main.JavaCompiler"); runDirectly(list); return 0; } catch (ClassNotFoundException unused) { if (loadDelombok(list) == null) { return 1; } try { Permit.getMethod(loadDelombok(list), "main", String[].class).invoke(null, list.toArray(new String[0])); return 0; } catch (InvocationTargetException e) { Throwable cause = e.getCause(); if (cause instanceof Error) { throw ((Error) cause); } else if (cause instanceof Exception) { throw ((Exception) cause); } else { throw e; } } } } public static Class loadDelombok(List list) throws Exception { File findToolsJar = findToolsJar(); if (findToolsJar != null) { return new AnonymousClass1(DelombokApp.class.getClassLoader(), new JarFile(findToolsJar), findToolsJar).loadClass("lombok.delombok.Delombok"); } String str = "/path/to/tools.jar"; if (File.separator.equals("\\")) { str = "C:\\path\\to\\tools.jar"; } StringBuilder sb = new StringBuilder(); Iterator it = list.iterator(); while (it.hasNext()) { String next = it.next(); if (sb.length() > 0) { sb.append(' '); } if (next.contains(" ")) { sb.append('\"').append(next).append('\"'); } else { sb.append(next); } } System.err.printf("Can't find tools.jar. Rerun delombok as: java -cp lombok.jar%1$s%2$s lombok.launch.Main delombok %3$s\n", File.pathSeparator, str, sb.toString()); return null; } private void runDirectly(List list) { Delombok.main((String[]) list.toArray(new String[0])); } private static File findToolsJar() { try { File findToolsJarViaRT = findToolsJarViaRT(); if (findToolsJarViaRT != null) { return findToolsJarViaRT; } } catch (Throwable unused) { } try { File findToolsJarViaProperties = findToolsJarViaProperties(); if (findToolsJarViaProperties != null) { return findToolsJarViaProperties; } } catch (Throwable unused2) { } try { return findToolsJarViaEnvironment(); } catch (Throwable unused3) { return null; } } private static File findToolsJarViaEnvironment() { Iterator> it = System.getenv().entrySet().iterator(); while (it.hasNext()) { Map.Entry next = it.next(); if ("JAVA_HOME".equalsIgnoreCase(next.getKey())) { return extensiveCheckToolsJar(new File(next.getValue())); } } return null; } private static File findToolsJarViaProperties() { return extensiveCheckToolsJar(new File(System.getProperty("java.home", "."))); } private static File extensiveCheckToolsJar(File file) { File checkToolsJar = checkToolsJar(file); if (checkToolsJar != null) { return checkToolsJar; } File checkToolsJar2 = checkToolsJar(new File(file, "lib")); if (checkToolsJar2 != null) { return checkToolsJar2; } File checkToolsJar3 = checkToolsJar(new File(file.getParentFile(), "lib")); if (checkToolsJar3 != null) { return checkToolsJar3; } File checkToolsJar4 = checkToolsJar(new File(new File(file, "jdk"), "lib")); if (checkToolsJar4 != null) { return checkToolsJar4; } return null; } private static File findToolsJarViaRT() { String substring; int indexOf; String url = ClassLoader.getSystemClassLoader().getResource("java/lang/String.class").toString(); if (!url.startsWith("jar:file:") || (indexOf = (substring = url.substring("jar:file:".length())).indexOf(33)) == -1) { return null; } String substring2 = substring.substring(0, indexOf); File checkToolsJar = checkToolsJar(new File(substring2).getParentFile()); if (checkToolsJar != null) { return checkToolsJar; } File checkToolsJar2 = checkToolsJar(new File(new File(substring2).getParentFile().getParentFile().getParentFile(), "lib")); if (checkToolsJar2 != null) { return checkToolsJar2; } return null; } private static File checkToolsJar(File file) { if (file.getName().equals("tools.jar") && file.isFile() && file.canRead()) { return file; } File file2 = new File(file, "tools.jar"); if (!file2.getName().equals("tools.jar") || !file2.isFile() || !file2.canRead()) { return null; } return file2; } @Override // lombok.core.LombokApp public String getAppName() { return "delombok"; } @Override // lombok.core.LombokApp public List getAppAliases() { return Arrays.asList("unlombok"); } @Override // lombok.core.LombokApp public String getAppDescription() { return "Applies lombok transformations without compiling your\njava code (so, 'unpacks' lombok annotations and such)."; } }