diff --git a/build.gradle b/build.gradle index a9fe4b88..ad5b7452 100644 --- a/build.gradle +++ b/build.gradle @@ -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") diff --git a/gradle.properties b/gradle.properties index f3ccf2a6..2e81c858 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 +javaparser_version = 3.25.6 +javafx_version = 21.0.1 +checkstyle_version = 10.12.4 diff --git a/src/main/java/matcher/srcprocess/HtmlPrinter.java b/src/main/java/matcher/srcprocess/HtmlPrinter.java index 4598f4ce..fc176509 100644 --- a/src/main/java/matcher/srcprocess/HtmlPrinter.java +++ b/src/main/java/matcher/srcprocess/HtmlPrinter.java @@ -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. @@ -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; @@ -216,7 +215,7 @@ protected void printTypeArgs(final NodeWithTypeArguments nodeWithTypeArgument NodeList typeArguments = nodeWithTypeArguments.getTypeArguments().orElse(null); if (!isNullOrEmpty(typeArguments)) { - printer.print("<"); + printer.print("<"); // < for (final Iterator i = typeArguments.iterator(); i.hasNext(); ) { final Type t = i.next(); @@ -227,14 +226,14 @@ protected void printTypeArgs(final NodeWithTypeArguments nodeWithTypeArgument } } - printer.print(">"); + printer.print(">"); // > } } @Override protected void printTypeParameters(final NodeList args, final Void arg) { if (!isNullOrEmpty(args)) { - printer.print("<"); + printer.print("<"); // < for (final Iterator i = args.iterator(); i.hasNext(); ) { final TypeParameter t = i.next(); @@ -245,7 +244,7 @@ protected void printTypeParameters(final NodeList args, final Voi } } - printer.print(">"); + printer.print(">"); // > } } @@ -318,6 +317,19 @@ public void visit(final ClassOrInterfaceDeclaration n, final Void arg) { } } + if (!n.getPermittedTypes().isEmpty()) { + printer.print(" permits "); + + for (final Iterator i = n.getPermittedTypes().iterator(); i.hasNext(); ) { + final ClassOrInterfaceType c = i.next(); + c.accept(this, arg); + + if (i.hasNext()) { + printer.print(", "); + } + } + } + printer.println(" {"); printer.indent(); @@ -344,6 +356,8 @@ public void visit(RecordDeclaration n, Void arg) { n.getName().accept(this, arg); printer.print(""); + printTypeParameters(n.getTypeParameters(), arg); + printer.print("("); if (!isNullOrEmpty(n.getParameters())) { @@ -358,7 +372,6 @@ public void visit(RecordDeclaration n, Void arg) { } printer.print(")"); - printTypeParameters(n.getTypeParameters(), arg); if (!n.getImplementedTypes().isEmpty()) { printer.print(" implements "); @@ -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("/**"); + printer.print("") + 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 strippedLines = new ArrayList<>(); for (String line : lines) { final String trimmedLine = line.trim(); @@ -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; @@ -429,7 +448,9 @@ public void visit(final JavadocComment n, final Void arg) { } } - printer.println(" */"); + printer.print(" ") + .print(n.getFooter()) + .println(""); } } @@ -678,11 +699,11 @@ public void visit(final InstanceOfExpr n, final Void arg) { printComment(n.getComment(), arg); n.getExpression().accept(this, arg); printer.print(" instanceof "); - 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); } } @@ -983,6 +1004,13 @@ public void visit(final ConstructorDeclaration n, final Void arg) { printer.print(""); printer.print("("); + n.getReceiverParameter().ifPresent(rp -> { + rp.accept(this, arg); + + if (!isNullOrEmpty(n.getParameters())) { + printer.print(", "); + } + }); if (!n.getParameters().isEmpty()) { for (final Iterator i = n.getParameters().iterator(); i.hasNext(); ) { @@ -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()) { @@ -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()); @@ -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("}"); @@ -1748,8 +1774,9 @@ public void visit(final LineComment n, final Void arg) { } printer.print(""); - 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(""); } @@ -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("/*"); + printer.print(""); + 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("*/"); + printer.print(lines[lines.length - 1]) // last line is not followed by a newline, and simply terminated with `*/` + .print(n.getFooter()) + .println(""); } @Override @@ -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 everything = node.getChildNodes().stream().filter(n -> n.getRange().isPresent()).collect(Collectors.toList()); + List everything = new ArrayList<>(node.getChildNodes()); sortByBeginPosition(everything); if (everything.isEmpty()) { @@ -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 getOption(ConfigOption option) { + return configuration.get(new DefaultConfigurationOption(option)); + } + + // Matcher-introduced methods + private static boolean canAddNewLine(Node n) { Node prev = getPrev(n); @@ -1955,10 +1997,7 @@ private static Node getNext(Node n) { return parent.getChildNodes().get(idx + 1); } - private Optional 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;