Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies #42

Merged
merged 4 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ dependencies {
extraJavaModuleInfo {
failOnMissingModuleInfo.set(false) // because of transitive dependencies

// Mapping-IO
automaticModule("net.fabricmc:mapping-io", "net.fabricmc.mappingio")

// CFR
automaticModule("net.fabricmc:cfr", "cfr")

Expand Down
16 changes: 8 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
org.gradle.jvmargs=-Xmx2G

# Gradle Plugins
javafx_plugin_version = 0.0.13
javafx_plugin_version = 0.1.0
shadow_version = 7.1.2
extra_java_module_info_version = 1.3
extra_java_module_info_version = 1.5

# Poject Properties
version = 0.1.0

# Project Dependencies
asm_version = 9.4
fabric_cfr_version = 0.2.0
asm_version = 9.6
fabric_cfr_version = 0.2.1
fabric_fernflower_version = 2.0.0
procyon_version = 0.6.0
mappingio_version = 0.3.0
javaparser_version = 3.24.2
javafx_version = 17.0.2
checkstyle_version = 10.3.4
mappingio_version = 0.4.2
NebelNidas marked this conversation as resolved.
Show resolved Hide resolved
javaparser_version = 3.25.6
javafx_version = 21.0.1
checkstyle_version = 10.12.4
103 changes: 71 additions & 32 deletions src/main/java/matcher/srcprocess/HtmlPrinter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Most of this file is copied from DefaultPrettyPrinterVisitor,
* Most of this file is copied from DefaultPrettyPrinterVisitor (commit 19e0559),
* tweaked to output HTML instead of plain text. Original license:
*
* Copyright (C) 2011, 2013-2021 The JavaParser Team.
Expand Down Expand Up @@ -27,13 +27,12 @@
import static com.github.javaparser.utils.Utils.isNullOrEmpty;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import java.util.regex.Pattern;

import com.github.javaparser.ast.ArrayCreationLevel;
import com.github.javaparser.ast.ImportDeclaration;
Expand Down Expand Up @@ -216,7 +215,7 @@ protected void printTypeArgs(final NodeWithTypeArguments<?> nodeWithTypeArgument
NodeList<Type> typeArguments = nodeWithTypeArguments.getTypeArguments().orElse(null);

if (!isNullOrEmpty(typeArguments)) {
printer.print("&lt;");
printer.print("&lt;"); // <

for (final Iterator<Type> i = typeArguments.iterator(); i.hasNext(); ) {
final Type t = i.next();
Expand All @@ -227,14 +226,14 @@ protected void printTypeArgs(final NodeWithTypeArguments<?> nodeWithTypeArgument
}
}

printer.print("&gt;");
printer.print("&gt;"); // >
}
}

@Override
protected void printTypeParameters(final NodeList<TypeParameter> args, final Void arg) {
if (!isNullOrEmpty(args)) {
printer.print("&lt;");
printer.print("&lt;"); // <

for (final Iterator<TypeParameter> i = args.iterator(); i.hasNext(); ) {
final TypeParameter t = i.next();
Expand All @@ -245,7 +244,7 @@ protected void printTypeParameters(final NodeList<TypeParameter> args, final Voi
}
}

printer.print("&gt;");
printer.print("&gt;"); // >
}
}

Expand Down Expand Up @@ -318,6 +317,19 @@ public void visit(final ClassOrInterfaceDeclaration n, final Void arg) {
}
}

if (!n.getPermittedTypes().isEmpty()) {
printer.print(" <span class=\"keyword\">permits</span> ");

for (final Iterator<ClassOrInterfaceType> i = n.getPermittedTypes().iterator(); i.hasNext(); ) {
final ClassOrInterfaceType c = i.next();
c.accept(this, arg);

if (i.hasNext()) {
printer.print(", ");
}
}
}

printer.println(" {");
printer.indent();

Expand All @@ -344,6 +356,8 @@ public void visit(RecordDeclaration n, Void arg) {
n.getName().accept(this, arg);
printer.print("</span>");

printTypeParameters(n.getTypeParameters(), arg);

printer.print("(");

if (!isNullOrEmpty(n.getParameters())) {
Expand All @@ -358,7 +372,6 @@ public void visit(RecordDeclaration n, Void arg) {
}

printer.print(")");
printTypeParameters(n.getTypeParameters(), arg);

if (!n.getImplementedTypes().isEmpty()) {
printer.print(" <span class=\"keyword\">implements</span> ");
Expand Down Expand Up @@ -391,12 +404,11 @@ public void visit(final JavadocComment n, final Void arg) {
printOrphanCommentsBeforeThisChildNode(n);

if (getOption(ConfigOption.PRINT_COMMENTS).isPresent() && getOption(ConfigOption.PRINT_JAVADOC).isPresent()) {
printer.println("<span class=\"comment\">/**");
printer.print("<span class=\"comment\">");
printer.println(n.getHeader());
final String commentContent = Utils.normalizeEolInTextBlock(HtmlUtil.escape(n.getContent()), getOption(ConfigOption.END_OF_LINE_CHARACTER).get().asString());
String[] lines = commentContent.split("\\R");
boolean skippingLeadingEmptyLines = true;
boolean prependEmptyLine = false;
boolean prependSpace = Arrays.stream(lines).anyMatch(line -> !line.isEmpty() && !line.startsWith(" "));
List<String> strippedLines = new ArrayList<>();

for (String line : lines) {
final String trimmedLine = line.trim();
Expand All @@ -406,7 +418,14 @@ public void visit(final JavadocComment n, final Void arg) {
}

line = Utils.trimTrailingSpaces(line);
strippedLines.add(line);
}

boolean skippingLeadingEmptyLines = true;
boolean prependEmptyLine = false;
boolean prependSpace = strippedLines.stream().anyMatch(line -> !line.isEmpty() && !line.startsWith(" "));

for (String line : strippedLines) {
if (line.isEmpty()) {
if (!skippingLeadingEmptyLines) {
prependEmptyLine = true;
Expand All @@ -429,7 +448,9 @@ public void visit(final JavadocComment n, final Void arg) {
}
}

printer.println(" */</span>");
printer.print(" ")
.print(n.getFooter())
.println("</span>");
}
}

Expand Down Expand Up @@ -678,11 +699,11 @@ public void visit(final InstanceOfExpr n, final Void arg) {
printComment(n.getComment(), arg);
n.getExpression().accept(this, arg);
printer.print(" <span class=\"keyword\">instanceof</span> ");
n.getType().accept(this, arg);

if (n.getName().isPresent()) {
printer.print(" ");
n.getName().get().accept(this, arg);
if (n.getPattern().isPresent()) {
n.getPattern().get().accept(this, arg);
} else {
n.getType().accept(this, arg);
}
}

Expand Down Expand Up @@ -983,6 +1004,13 @@ public void visit(final ConstructorDeclaration n, final Void arg) {
printer.print("</span>");

printer.print("(");
n.getReceiverParameter().ifPresent(rp -> {
rp.accept(this, arg);

if (!isNullOrEmpty(n.getParameters())) {
printer.print(", ");
}
});

if (!n.getParameters().isEmpty()) {
for (final Iterator<Parameter> i = n.getParameters().iterator(); i.hasNext(); ) {
Expand Down Expand Up @@ -1024,7 +1052,6 @@ public void visit(final CompactConstructorDeclaration n, final Void arg) {
printComment(n.getComment(), arg);
printMemberAnnotations(n.getAnnotations(), arg);
printModifiers(n.getModifiers());

printTypeParameters(n.getTypeParameters(), arg);

if (n.isGeneric()) {
Expand Down Expand Up @@ -1065,7 +1092,6 @@ public void visit(final MethodDeclaration n, final Void arg) {
}

printOrphanCommentsBeforeThisChildNode(n);

printComment(n.getComment(), arg);
printMemberAnnotations(n.getAnnotations(), arg);
printModifiers(n.getModifiers());
Expand Down Expand Up @@ -1209,13 +1235,13 @@ private void printSwitchNode(SwitchNode n, Void arg) {
printer.println(") {");

if (n.getEntries() != null) {
if (getOption(ConfigOption.INDENT_CASE_IN_SWITCH).isPresent()) printer.indent();
indentIf(getOption(ConfigOption.INDENT_CASE_IN_SWITCH).isPresent());

for (final SwitchEntry e : n.getEntries()) {
e.accept(this, arg);
}

if (getOption(ConfigOption.INDENT_CASE_IN_SWITCH).isPresent()) printer.indent();
unindentIf(getOption(ConfigOption.INDENT_CASE_IN_SWITCH).isPresent());
}

printer.print("}");
Expand Down Expand Up @@ -1748,8 +1774,9 @@ public void visit(final LineComment n, final Void arg) {
}

printer.print("<span class=\"comment\">");
printer.print("// ")
.println(Utils.normalizeEolInTextBlock(HtmlUtil.escape(n.getContent()), "").trim());
printer.print(n.getHeader())
.print(" ")
.println(Utils.normalizeEolInTextBlock(HtmlUtil.escape(RTRIM.matcher(n.getContent()).replaceAll("")), ""));
printer.println("</span>");
}

Expand All @@ -1761,15 +1788,17 @@ public void visit(final BlockComment n, final Void arg) {

final String commentContent = Utils.normalizeEolInTextBlock(n.getContent(), getOption(ConfigOption.END_OF_LINE_CHARACTER).get().asString());
String[] lines = commentContent.split("\\R", -1); // as BlockComment should not be formatted, -1 to preserve any trailing empty line if present
printer.print("<span class=\"comment\">/*");
printer.print("<span class=\"comment\">");
printer.print(n.getHeader());

for (int i = 0; i < (lines.length - 1); i++) {
printer.print(lines[i]);
printer.print(getOption(ConfigOption.END_OF_LINE_CHARACTER).get().asString()); // Avoids introducing indentation in blockcomments. ie: do not use println() as it would trigger indentation at the next print call.
}

printer.print(lines[lines.length - 1]); // last line is not followed by a newline, and simply terminated with `*/`
printer.println("*/</span>");
printer.print(lines[lines.length - 1]) // last line is not followed by a newline, and simply terminated with `*/`
.print(n.getFooter())
.println("</span>");
}

@Override
Expand Down Expand Up @@ -1893,8 +1922,7 @@ private void printOrphanCommentsBeforeThisChildNode(final Node node) {
private void printOrphanCommentsEnding(final Node node) {
if (!getOption(ConfigOption.PRINT_COMMENTS).isPresent()) return;

// extract all nodes for which the position/range is indicated to avoid to skip orphan comments
List<Node> everything = node.getChildNodes().stream().filter(n -> n.getRange().isPresent()).collect(Collectors.toList());
List<Node> everything = new ArrayList<>(node.getChildNodes());
sortByBeginPosition(everything);

if (everything.isEmpty()) {
Expand All @@ -1918,6 +1946,20 @@ private void printOrphanCommentsEnding(final Node node) {
}
}

private void indentIf(boolean expr) {
if (expr) printer.indent();
}

private void unindentIf(boolean expr) {
if (expr) printer.unindent();
}

private Optional<ConfigurationOption> getOption(ConfigOption option) {
return configuration.get(new DefaultConfigurationOption(option));
}

// Matcher-introduced methods

private static boolean canAddNewLine(Node n) {
Node prev = getPrev(n);

Expand Down Expand Up @@ -1955,10 +1997,7 @@ private static Node getNext(Node n) {
return parent.getChildNodes().get(idx + 1);
}

private Optional<ConfigurationOption> getOption(ConfigOption option) {
return configuration.get(new DefaultConfigurationOption(option));
}

private static Pattern RTRIM = Pattern.compile("\\s+$");
protected final TypeResolver typeResolver;
protected boolean instantiationAhead;
protected int recursionCounter;
Expand Down