Skip to content

Commit

Permalink
Replace System.getProperty("path.separator") with File.pathSeparator
Browse files Browse the repository at this point in the history
Directly use constant asm version instead of `XXX.this.api` in inner classes
  • Loading branch information
XiaoPangxie732 committed Feb 6, 2024
1 parent a6b252a commit 8b5beaf
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/main/java/cn/maxpixel/mcdecompiler/Info.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public interface Info {
String METHOD_DESC_PATTERN = "^\\((\\[*([ZBCDFIJS]|L([A-Za-z_]+\\w*[/$]?)+;))*\\)\\[*([ZBCDFIJSV]|L([A-Za-z_]+\\w*[/$]?)+;)$";
boolean IS_DEV = System.console() == null && Boolean.getBoolean("mcd.isDevEnv");
int ASM_VERSION = Opcodes.ASM9;
String PATH_SEPARATOR = System.getProperty("path.separator"); // ;
Manifest MANIFEST = getManifest();

enum SideType {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/maxpixel/mcdecompiler/Properties.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public class Properties {
public static Path DOWNLOAD_DIR = Path.of("downloads");

public static Path getDownloadedDecompilerPath(@NotNull Info.DecompilerType type) {
if(type == Info.DecompilerType.USER_DEFINED) throw new UnsupportedOperationException();
if (type == Info.DecompilerType.USER_DEFINED) throw new UnsupportedOperationException();
return DOWNLOAD_DIR.resolve("decompiler").resolve(Objects.requireNonNull(type) + ".jar");
}

public static String getProperty(String name, String prop) {
if(Info.IS_DEV || Info.MANIFEST == null)
if (Info.IS_DEV || Info.MANIFEST == null)
return Objects.requireNonNull(System.getProperty(prop), "System property \"" + prop + "\" is not set");
return Objects.requireNonNull(Info.MANIFEST.getMainAttributes().getValue(name),
"Guess you forgot to add the " + name + " property to the manifest!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public MethodVisitor visitMethod(int access, String name, String descriptor, Str

public class Remapper extends MethodVisitor {
public Remapper(MethodVisitor methodVisitor) {
super(IndyRemapper.this.api, methodVisitor);
super(Info.ASM_VERSION, methodVisitor);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class MethodProcessor extends MethodVisitor {
private boolean skip;

public MethodProcessor(MethodVisitor methodVisitor, VariableNameProvider.RenameFunction renameFunction, Renamer renamer, String method, boolean notStatic) {
super(VariableNameProcessor.this.api, methodVisitor);
super(Info.ASM_VERSION, methodVisitor);
this.renameFunction = renameFunction;
this.renamer = renamer;
this.method = method;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import it.unimi.dsi.fastutil.objects.ObjectSets;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
Expand Down Expand Up @@ -61,7 +62,7 @@ public void decompile(@NotNull Path source, @NotNull Path target) throws IOExcep
try (ExternalJarClassLoader cl = new ExternalJarClassLoader(new URL[] {decompilerJarPath.toUri().toURL()})) {
Thread thread = (Thread) cl.loadClass("cn.maxpixel.mcdecompiler.decompiler.thread.CFRDecompileThread")
.getConstructor(String.class, String.class, String.class)
.newInstance(source.toString(), target.toString(), String.join(Info.PATH_SEPARATOR, libs));
.newInstance(source.toString(), target.toString(), String.join(File.pathSeparator, libs));
thread.start();
while(thread.isAlive()) Thread.onSpinWait();
} catch(ReflectiveOperationException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package cn.maxpixel.mcdecompiler.decompiler;

import cn.maxpixel.mcdecompiler.Info;
import cn.maxpixel.mcdecompiler.Properties;
import cn.maxpixel.mcdecompiler.util.FileUtil;
import cn.maxpixel.mcdecompiler.util.Utils;
Expand All @@ -28,6 +27,7 @@
import it.unimi.dsi.fastutil.objects.ObjectSet;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -83,7 +83,7 @@ private ObjectArrayList<String> resolveArgs(@NotNull Path source, @NotNull Path
String s = options.get(i);
if (s.contains("%source%")) s = s.replace("%source%", source.toString());
if (s.contains("%target%")) s = s.replace("%target%", target.toString());
if (s.contains("%lib_all%")) s = s.replace("%lib_all%", String.join(Info.PATH_SEPARATOR, libs));
if (s.contains("%lib_all%")) s = s.replace("%lib_all%", String.join(File.pathSeparator, libs));
if (s.contains("%abstract_params%")) {
Path p = Properties.TEMP_DIR.resolve(FERNFLOWER_ABSTRACT_PARAMETER_NAMES).toAbsolutePath().normalize();
s = s.replace("%abstract_params%", Files.exists(p) ? p.toString() : "");
Expand Down

0 comments on commit 8b5beaf

Please sign in to comment.