Skip to content

Commit

Permalink
Show dialog for choosing game path, cleanup (#1083)
Browse files Browse the repository at this point in the history
* show dialog for choosing game path

* cleanup code

* remove logs and refactor

* remove confusing mpq error, make some mpq loads readonly
  • Loading branch information
Frotty authored Nov 29, 2023
1 parent cafbdf8 commit 867bf9f
Show file tree
Hide file tree
Showing 215 changed files with 746 additions and 729 deletions.
2 changes: 1 addition & 1 deletion de.peeeq.wurstscript/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ dependencies {
implementation 'io.vavr:vavr:0.10.4'

// Support for the vscode language server protocol
implementation group: 'org.eclipse.lsp4j', name: 'org.eclipse.lsp4j', version: '0.12.0'
implementation group: 'org.eclipse.lsp4j', name: 'org.eclipse.lsp4j', version: '0.21.1'

// @Nullable annotations
implementation group: 'org.eclipse.jdt', name: 'org.eclipse.jdt.annotation', version: '2.1.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ public String generateDotFile(List<T> nodes) {
if (!visited.add(node)) {
continue;
}
sb.append(" \"").append(node.toString()).append("\";\n");
sb.append(" \"").append(node).append("\";\n");
for (T n : getIncidentNodes(node)) {
sb.append(" ");
sb.append("\"").append(node.toString()).append("\" -> ");
sb.append("\"").append(node).append("\" -> ");
sb.append("\"").append(n.toString()).append("\";\n\n");
todo.addFirst(n);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Iterator<ImmutableTree<T>> iterator() {
if (children2 != null) {
return children2.iterator();
} else {
return Collections.<ImmutableTree<T>>emptyList().iterator();
return Collections.emptyIterator();
}
}

Expand All @@ -70,7 +70,7 @@ private void addValues(Builder<@Nullable T> b) {
}

public static <T> ImmutableTree<T> empty() {
return node(ImmutableList.<ImmutableTree<T>>of());
return node(ImmutableList.of());
}

@Override
Expand Down Expand Up @@ -101,11 +101,8 @@ public boolean equals(@Nullable Object obj) {
return false;
@Nullable T e = elem;
if (e == null) {
if (other.elem != null)
return false;
} else if (!e.equals(other.elem))
return false;
return true;
return other.elem == null;
} else return e.equals(other.elem);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class Partitions<T> {

private class Partition {
private Partition rep;
private T item;
private final T item;

public Partition(T item) {
rep = this;
Expand All @@ -29,7 +29,7 @@ private Partition getRep() {
}
}

private Map<T, Partition> partitions = Maps.newLinkedHashMap();
private final Map<T, Partition> partitions = Maps.newLinkedHashMap();

public Partitions() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.google.common.collect.Multimap;

import java.util.*;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
* Implementation of https://en.wikipedia.org/wiki/Disjoint-set_data_structure
*/
public class UnionFind<T> {
private Map<T, T> parent = new LinkedHashMap<>();
private Map<T, Integer> rank = new LinkedHashMap<>();
private final Map<T, T> parent = new LinkedHashMap<>();
private final Map<T, Integer> rank = new LinkedHashMap<>();

public T find(T x) {
if (!parent.containsKey(x)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
* No element is added to the queue more than once.
*/
public class Worklist<T> {
private ArrayDeque<T> queue = new ArrayDeque<>();
private HashSet<T> set = new HashSet<>();
private final ArrayDeque<T> queue = new ArrayDeque<>();
private final HashSet<T> set = new HashSet<>();

public Worklist() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public boolean contains(T elem) {
* @return an empty list
*/
public static <T> ImmutableList<T> emptyList() {
return ImmutableListEmpty.<T>instance();
return ImmutableListEmpty.instance();
}

@SafeVarargs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.peeeq.wurstio;

import config.WurstProjectBuildMapData;
import config.WurstProjectConfigData;
import de.peeeq.wurstio.languageserver.requests.RunTests;
import de.peeeq.wurstio.mpq.MpqEditor;
Expand All @@ -20,7 +19,6 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Optional;
import java.util.function.Supplier;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ private void executeCompiletimeExpr(ImCompiletimeExpr cte) {
}


private GetAForB<ILconstObject, ImVar> globalForObject = new GetAForB<ILconstObject, ImVar>() {
private final GetAForB<ILconstObject, ImVar> globalForObject = new GetAForB<ILconstObject, ImVar>() {
@Override
public ImVar initFor(ILconstObject obj) {

Expand Down Expand Up @@ -308,7 +308,7 @@ public ImVar initFor(ILconstObject obj) {
}
};

private GetAForB<IlConstHandle, ImVar> globalForHandle = new GetAForB<IlConstHandle, ImVar>() {
private final GetAForB<IlConstHandle, ImVar> globalForHandle = new GetAForB<IlConstHandle, ImVar>() {
@Override
public ImVar initFor(IlConstHandle a) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.awt.*;
import java.io.*;
import java.net.*;
import java.nio.charset.StandardCharsets;

public class ErrorReportingIO extends ErrorReporting {

Expand Down Expand Up @@ -50,8 +51,8 @@ public void handleSevere(final Throwable t, final String sourcecode) {
options[1]); //default button titles

if (n == 1) {
final boolean results[] = new boolean[3];
Thread threads[] = new Thread[4];
final boolean[] results = new boolean[3];
Thread[] threads = new Thread[4];

threads[0] = new Thread(() -> results[0] = sendErrorReport(t, ""));

Expand Down Expand Up @@ -116,10 +117,10 @@ public boolean sendErrorReport(Throwable t, String sourcecode) {
try {

// Construct data
String data = URLEncoder.encode("errormessage", "UTF-8") + "=" + URLEncoder.encode(t.getMessage(), "UTF-8");
data += "&" + URLEncoder.encode("stacktrace", "UTF-8") + "=" + URLEncoder.encode(Utils.printExceptionWithStackTrace(t), "UTF-8");
data += "&" + URLEncoder.encode("version", "UTF-8") + "=" + URLEncoder.encode(AboutDialog.version, "UTF-8");
data += "&" + URLEncoder.encode("source", "UTF-8") + "=" + URLEncoder.encode(sourcecode, "UTF-8");
String data = URLEncoder.encode("errormessage", StandardCharsets.UTF_8) + "=" + URLEncoder.encode(t.getMessage(), StandardCharsets.UTF_8);
data += "&" + URLEncoder.encode("stacktrace", StandardCharsets.UTF_8) + "=" + URLEncoder.encode(Utils.printExceptionWithStackTrace(t), StandardCharsets.UTF_8);
data += "&" + URLEncoder.encode("version", StandardCharsets.UTF_8) + "=" + URLEncoder.encode(AboutDialog.version, StandardCharsets.UTF_8);
data += "&" + URLEncoder.encode("source", StandardCharsets.UTF_8) + "=" + URLEncoder.encode(sourcecode, StandardCharsets.UTF_8);

String request = "http://peeeq.de/wursterrors.php";
URL url = new URL(request);
Expand All @@ -130,7 +131,7 @@ public boolean sendErrorReport(Throwable t, String sourcecode) {
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("charset", "utf-8");
connection.setRequestProperty("Content-Length", "" + Integer.toString(data.getBytes().length));
connection.setRequestProperty("Content-Length", String.valueOf(data.getBytes().length));
connection.setUseCaches(false);
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.writeBytes(data);
Expand Down Expand Up @@ -185,7 +186,7 @@ private String showMultilineMessageDialog() {
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
JScrollPane areaScrollPane = new JScrollPane(textArea);
JComponent inputs[] = {
JComponent[] inputs = {
new JLabel("Please add some contact information here in case we have further questions regarding this problem."),
new JLabel("This can be your hive user-name or your mail address."),
new JLabel("You can also add more information on how to reproduce the problem."),
Expand Down
7 changes: 5 additions & 2 deletions de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
import de.peeeq.wurstio.mpq.MpqEditor;
import de.peeeq.wurstio.mpq.MpqEditorFactory;
import de.peeeq.wurstio.utils.W3InstallationData;
import de.peeeq.wurstscript.*;
import de.peeeq.wurstscript.CompileTimeInfo;
import de.peeeq.wurstscript.ErrorReporting;
import de.peeeq.wurstscript.RunArgs;
import de.peeeq.wurstscript.WLogger;
import de.peeeq.wurstscript.attributes.CompileError;
import de.peeeq.wurstscript.attributes.prettyPrint.PrettyUtils;
import de.peeeq.wurstscript.gui.WurstGui;
Expand Down Expand Up @@ -168,7 +171,7 @@ public static void main(String[] args) {

if (projectConfig != null && target.isPresent()) {
ProjectConfigBuilder.apply(projectConfig, target.get().toFile(), scriptFile, buildDir.toFile(),
runArgs, new W3InstallationData());
runArgs, new W3InstallationData(null, Paths.get(workspaceroot).toFile()));

WLogger.info("map build success");
System.out.println("Build succeeded. Output file: <" + target.get().toAbsolutePath() + ">");
Expand Down
10 changes: 5 additions & 5 deletions de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/Pjass.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public class Pjass {

public static class Result {

private boolean ok;
private String message;
private File jassFile;
private final boolean ok;
private final String message;
private final File jassFile;

public Result(File jassFile, boolean ok, String message) {
this.jassFile = jassFile;
Expand Down Expand Up @@ -125,7 +125,7 @@ public static Result runPjass(File outputFile, String commonJPath, String blizza
try {
p = Runtime.getRuntime().exec(args.toArray(new String[0]));
} catch (IOException e) {
return new Result(outputFile, false, "Pjass execution error: \n" + e.toString());
return new Result(outputFile, false, "Pjass execution error: \n" + e);
}

StringBuilder output = new StringBuilder();
Expand All @@ -141,7 +141,7 @@ public static Result runPjass(File outputFile, String commonJPath, String blizza

int exitValue = p.waitFor();
if (exitValue != 0) {
return new Result(outputFile, false, "pjass errors: \n" + output.toString());
return new Result(outputFile, false, "pjass errors: \n" + output);
} else {
return new Result(outputFile, true, output.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Recording implements TimeTaker {
private int nesting = 0;
private String currentPhaseDescription;
private long currentPhaseStart;
private Map<String, Long> accumulatedTimes = new LinkedHashMap<>();
private final Map<String, Long> accumulatedTimes = new LinkedHashMap<>();

private Long startTime = 0L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import com.google.common.base.Charsets;
import com.google.common.base.Preconditions;
import com.google.common.collect.*;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.common.io.Files;
import config.WurstProjectConfigData;
import de.peeeq.wurstio.languageserver.requests.RequestFailedException;
Expand All @@ -11,8 +14,8 @@
import de.peeeq.wurstio.utils.FileReading;
import de.peeeq.wurstio.utils.FileUtils;
import de.peeeq.wurstscript.*;
import de.peeeq.wurstscript.ast.*;
import de.peeeq.wurstscript.ast.Element;
import de.peeeq.wurstscript.ast.*;
import de.peeeq.wurstscript.attributes.CompilationUnitInfo;
import de.peeeq.wurstscript.attributes.CompileError;
import de.peeeq.wurstscript.attributes.ErrorHandler;
Expand All @@ -28,7 +31,10 @@
import de.peeeq.wurstscript.translation.imtranslation.*;
import de.peeeq.wurstscript.translation.lua.translation.LuaTranslator;
import de.peeeq.wurstscript.types.TypesHelper;
import de.peeeq.wurstscript.utils.*;
import de.peeeq.wurstscript.utils.LineOffsets;
import de.peeeq.wurstscript.utils.NotNullList;
import de.peeeq.wurstscript.utils.TempDir;
import de.peeeq.wurstscript.utils.Utils;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.lsp4j.MessageType;
import org.jetbrains.annotations.NotNull;
Expand All @@ -44,24 +50,24 @@

public class WurstCompilerJassImpl implements WurstCompiler {

private List<File> files = Lists.newArrayList();
private Map<String, Reader> otherInputs = Maps.newLinkedHashMap();
private final List<File> files = Lists.newArrayList();
private final Map<String, Reader> otherInputs = Maps.newLinkedHashMap();
private @Nullable JassProg prog;
private WurstGui gui;
private final WurstGui gui;
private boolean hasCommonJ;
private RunArgs runArgs;
private Optional<File> mapFile = Optional.empty();
private @Nullable File projectFolder;
private ErrorHandler errorHandler;
private final ErrorHandler errorHandler;
private @Nullable Map<String, File> libCache = null;
private @Nullable ImProg imProg;
private List<File> parsedFiles = Lists.newArrayList();
private final List<File> parsedFiles = Lists.newArrayList();
private final WurstParser parser;
private final WurstChecker checker;
private @Nullable ImTranslator imTranslator;
private List<File> dependencies = Lists.newArrayList();
private final List<File> dependencies = Lists.newArrayList();
private final @Nullable MpqEditor mapFileMpq;
private TimeTaker timeTaker;
private final TimeTaker timeTaker;

public WurstCompilerJassImpl(@Nullable File projectFolder, WurstGui gui, @Nullable MpqEditor mapFileMpq, RunArgs runArgs) {
this(new TimeTaker.Default(), projectFolder, gui, mapFileMpq, runArgs);
Expand Down Expand Up @@ -174,7 +180,7 @@ public static ImmutableList<File> checkDependencyFile(File depFile, WurstGui gui
if (!folder.exists()) {
gui.sendError(new CompileError(pos, "Folder " + line + " not found."));
} else if (!folder.isDirectory()) {
gui.sendError(new CompileError(pos, "" + line + " is not a folder."));
gui.sendError(new CompileError(pos, line + " is not a folder."));
} else {
dependencies.add(folder);
}
Expand Down Expand Up @@ -563,11 +569,16 @@ private void addJassHotCodeReloadCode() {
// add call to JHCR_Init_init in main
stmts.add(callExtern(trace, CallType.EXECUTE, "JHCR_Init_init"));

ImFunction statusFunc = findFunction("JHCR_API_GetLastStatus", trace.attrErrorPos());
ImFunctionCall jhcrStatusCall = JassIm.ImFunctionCall(trace, statusFunc, JassIm.ImTypeArguments(), JassIm.ImExprs(), false, CallType.NORMAL);
ImFunction I2S = findNative("I2S", trace.attrErrorPos());
ImFunctionCall statusCall = JassIm.ImFunctionCall(trace, I2S, JassIm.ImTypeArguments(), JassIm.ImExprs(jhcrStatusCall), false, CallType.NORMAL);


// add reload trigger for pressing escape
ImStmts reloadBody = JassIm.ImStmts(
callExtern(trace, CallType.EXECUTE, "JHCR_Init_parse"),
callExtern(trace, CallType.NORMAL, "BJDebugMsg", JassIm.ImStringVal("Code reloaded!"))
callExtern(trace, CallType.EXECUTE, "JHCR_Init_parse")
// callExtern(trace, CallType.NORMAL, "BJDebugMsg", JassIm.ImOperatorCall(PLUS, JassIm.ImExprs(JassIm.ImStringVal("Code reloaded, status: "), statusCall))
);
ImFunction jhcr_reload = JassIm.ImFunction(trace, "jhcr_reload_on_escape", JassIm.ImTypeVars(), JassIm.ImVars(), JassIm.ImVoid(), JassIm.ImVars(), reloadBody, Collections.emptyList());

Expand All @@ -584,6 +595,29 @@ private void addJassHotCodeReloadCode() {
mainFunc.getBody().addAll(0, stmts);
}

@NotNull
private ImFunction findNative(String funcName, WPos trace) {
return imProg.getFunctions()
.stream()
.filter(ImFunction::isNative)
.filter(func -> func.getName().equals(funcName))
.findFirst()
.orElseGet(() -> {
throw new CompileError(trace, "Could not find native " + funcName);
});
}

@NotNull
private ImFunction findFunction(String funcName, WPos trace) {
return imProg.getFunctions()
.stream()
.filter(func -> func.getName().equals(funcName))
.findFirst()
.orElseGet(() -> {
throw new CompileError(trace, "Could not find native " + funcName);
});
}

@NotNull
private ImFunctionCall callExtern(Element trace, CallType callType, String functionName, ImExpr... arguments) {
ImFunction jhcrinit = JassIm.ImFunction(trace, functionName, JassIm.ImTypeVars(), JassIm.ImVars(), JassIm.ImVoid(), JassIm.ImVars(), JassIm.ImStmts(), Collections.singletonList(FunctionFlagEnum.IS_EXTERN));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private void homepageButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FI
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
public static void main(String[] args) {
/* Create and display the dialog */
java.awt.EventQueue.invokeLater(() -> {
try {
Expand Down
Loading

0 comments on commit 867bf9f

Please sign in to comment.