Skip to content

Commit

Permalink
Update java formatter sbt plugin (#8543)
Browse files Browse the repository at this point in the history
Add a local clone of javaFormatter plugin. The upstream is not maintained anymore. And we need to update it to use the newest Google java formatter because the old one, that we use, cannot format sources with Java 8+ syntax.

# Important Notes
Update to Google java formatter 1.18.1 - https://github.com/google/google-java-format/releases/tag/v1.18.1
  • Loading branch information
Akirathan committed Dec 15, 2023
1 parent 56cc956 commit c109886
Show file tree
Hide file tree
Showing 297 changed files with 8,834 additions and 6,602 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ on:

env:
# Please ensure that this is in sync with graalVersion in build.sbt
javaVersion: 17.0.7
javaVersion: 21.0.1
# Please ensure that this is in sync with project/build.properties
sbtVersion: 1.9.0
sbtVersion: 1.9.7

jobs:
test_formatting:
Expand Down
6 changes: 6 additions & 0 deletions .jvmopts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-Xss16M
-Xmx4G
-XX:+UseCompressedOops
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
Original file line number Diff line number Diff line change
@@ -1,36 +1,48 @@
package org.enso.interpreter.dsl.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.DirectCallNode;
import com.oracle.truffle.api.nodes.RootNode;
import org.enso.interpreter.node.InlineableNode;
import org.enso.interpreter.runtime.callable.function.Function;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.enso.interpreter.node.InlineableNode;

public class InliningBuiltinsTest {

/** @see InliningBuiltinsInNode#execute(long, long) */
/**
* @see InliningBuiltinsInNode#execute(long, long)
*/
@Test
public void executeWithoutVirtualFrame() {
var fn = InliningBuiltinsInMethodGen.makeFunction(null);
if (fn.getCallTarget().getRootNode() instanceof InlineableNode.Root root) {
var call = root.createInlineableNode();
var clazz = call.getClass();
assertEquals("InlineableNode", clazz.getSuperclass().getSimpleName());
assertEquals("org.enso.interpreter.node.InlineableNode$Root", clazz.getEnclosingClass().getInterfaces()[0].getName());
assertEquals(
"org.enso.interpreter.node.InlineableNode$Root",
clazz.getEnclosingClass().getInterfaces()[0].getName());

var res = WithFrame.invoke((frame) -> {
return call.call(frame, Function.ArgumentsHelper.buildArguments(null, null, new Object[] { null, 5L, 7L }));
});
var res =
WithFrame.invoke(
(frame) -> {
return call.call(
frame,
Function.ArgumentsHelper.buildArguments(
null, null, new Object[] {null, 5L, 7L}));
});
assertEquals(12L, res);
} else {
fail("It is inlineable: " + fn.getCallTarget().getRootNode());
}
}

/** @see InliningBuiltinsOutNode#execute(com.oracle.truffle.api.frame.VirtualFrame, long, long) */
/**
* @see InliningBuiltinsOutNode#execute(com.oracle.truffle.api.frame.VirtualFrame, long, long)
*/
@Test
public void executeWithVirtualFrame() {
var fn = InliningBuiltinsOutMethodGen.makeFunction(null);
Expand All @@ -41,14 +53,20 @@ public void executeWithVirtualFrame() {
var clazz = call.getClass().getSuperclass();
assertEquals("com.oracle.truffle.api.nodes.DirectCallNode", clazz.getName());

var res = WithFrame.invoke((frame) -> {
return call.call(Function.ArgumentsHelper.buildArguments(null, null, new Object[] { null, 3L, 9L }));
});
var res =
WithFrame.invoke(
(frame) -> {
return call.call(
Function.ArgumentsHelper.buildArguments(
null, null, new Object[] {null, 3L, 9L}));
});
assertEquals(12L, res);
}
}

/** @see InliningBuiltinsNeedsNode#execute(long, long) */
/**
* @see InliningBuiltinsNeedsNode#execute(long, long)
*/
@Test
public void executeWhenNeedsVirtualFrame() {
var fn = InliningBuiltinsNeedsMethodGen.makeFunction(null);
Expand All @@ -59,26 +77,39 @@ public void executeWhenNeedsVirtualFrame() {
var clazz = call.getClass().getSuperclass();
assertEquals("com.oracle.truffle.api.nodes.DirectCallNode", clazz.getName());

var res = WithFrame.invoke((frame) -> {
return call.call(Function.ArgumentsHelper.buildArguments(null, null, new Object[] { null, 3L, 9L }));
});
var res =
WithFrame.invoke(
(frame) -> {
return call.call(
Function.ArgumentsHelper.buildArguments(
null, null, new Object[] {null, 3L, 9L}));
});
assertEquals(12L, res);
}
}

/** @see InliningBuiltinsNeedNotNode#execute(com.oracle.truffle.api.frame.VirtualFrame, long, long) */
/**
* @see InliningBuiltinsNeedNotNode#execute(com.oracle.truffle.api.frame.VirtualFrame, long, long)
*/
@Test
public void executeWhenNeedNotVirtualFrame() {
var fn = InliningBuiltinsNeedNotMethodGen.makeFunction(null);
if (fn.getCallTarget().getRootNode() instanceof InlineableNode.Root root) {
var call = root.createInlineableNode();
var clazz = call.getClass();
assertEquals("InlineableNode", clazz.getSuperclass().getSimpleName());
assertEquals("org.enso.interpreter.node.InlineableNode$Root", clazz.getEnclosingClass().getInterfaces()[0].getName());
assertEquals(
"org.enso.interpreter.node.InlineableNode$Root",
clazz.getEnclosingClass().getInterfaces()[0].getName());

var res = WithFrame.invoke((frame) -> {
return call.call(frame, Function.ArgumentsHelper.buildArguments(null, null, new Object[] { null, 5L, 7L }));
});
var res =
WithFrame.invoke(
(frame) -> {
return call.call(
frame,
Function.ArgumentsHelper.buildArguments(
null, null, new Object[] {null, 5L, 7L}));
});
assertEquals(12L, res);
} else {
fail("It is inlineable: " + fn.getCallTarget().getRootNode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ public class ThrowBuiltinNode extends Node {
public Object execute(Text type, long exceptionIdx) {
switch (type.toString()) {
case "exception" -> {
Supplier<RuntimeException> exceptionSupplier =
ThrowableCatchTest.exceptionSuppliers.get((int) exceptionIdx);
Supplier<RuntimeException> exceptionSupplier =
ThrowableCatchTest.exceptionSuppliers.get((int) exceptionIdx);
throw exceptionSupplier.get();
}
case "error" -> {
Supplier<Error> errorSupplier =
ThrowableCatchTest.errorSuppliers.get((int) exceptionIdx);
Supplier<Error> errorSupplier = ThrowableCatchTest.errorSuppliers.get((int) exceptionIdx);
throw errorSupplier.get();
}
default -> throw new AssertionError("Unknown type: " + type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
import static org.junit.Assert.fail;

import com.oracle.truffle.api.dsl.UnsupportedSpecializationException;
import java.io.ByteArrayOutputStream;
import com.oracle.truffle.api.nodes.Node;
import java.nio.file.Paths;
import java.util.List;
import java.util.function.Supplier;
import java.util.logging.Level;

import org.enso.interpreter.EnsoLanguage;
import org.enso.interpreter.runtime.EnsoContext;
import org.enso.interpreter.runtime.callable.function.Function;
Expand All @@ -24,7 +23,6 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.oracle.truffle.api.nodes.Node;

/**
* Most of the exceptions thrown by the builtin methods, generated by {@link
Expand Down Expand Up @@ -72,10 +70,7 @@ public void setup() {
.allowAllAccess(true)
.logHandler(System.err)
.option(RuntimeOptions.STRICT_ERRORS, "true")
.option(
RuntimeOptions.LOG_LEVEL,
Level.WARNING.getName()
)
.option(RuntimeOptions.LOG_LEVEL, Level.WARNING.getName())
.option(
RuntimeOptions.LANGUAGE_HOME_OVERRIDE,
Paths.get("../../distribution/component").toFile().getAbsolutePath())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
/** A component that should be initialized. */
public interface InitializationComponent {

/** @return `true` if the component is initialized */
/**
* @return `true` if the component is initialized
*/
boolean isInitialized();

/** Initialize the component. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ private CompletableFuture<Void> recoverClearDatabaseFile(Throwable error, int re
return CompletableFuture.completedFuture(null);
} else if (error instanceof FileSystemException) {
logger.error(
"Failed to delete the database file. Attempt #{}. The file will be removed during the shutdown.",
"Failed to delete the database file. Attempt #{}. The file will be removed during the"
+ " shutdown.",
retries + 1,
error);
Runtime.getRuntime()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.XMLFormatter;

import org.enso.languageserver.runtime.RuntimeConnector;
import org.enso.polyglot.runtime.Runtime;
import org.enso.polyglot.runtime.Runtime$Api$Request;
Expand Down Expand Up @@ -55,9 +54,7 @@ public RuntimeEventsMonitor(PrintStream out) {
this(out, Clock.systemUTC());
}

/**
* Direction of the message.
*/
/** Direction of the message. */
private enum Direction {
REQUEST,
RESPONSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ public interface IdExecutionService {

public abstract class Info {

/** @return UUID of the node, never {@code null}. */
/**
* @return UUID of the node, never {@code null}.
*/
public abstract UUID getId();

/** @return associated result or {@code null} if there is no associated result. */
/**
* @return associated result or {@code null} if there is no associated result.
*/
public abstract Object getResult();

/** @return {@code true} when the result is panic, {@code false} otherwise. */
/**
* @return {@code true} when the result is panic, {@code false} otherwise.
*/
public abstract boolean isPanic();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
/**
* A representation of a pointer into a stack frame at a given number of levels above the current.
*/
public record FramePointer(int parentLevel, int frameSlotIdx) {
}
public record FramePointer(int parentLevel, int frameSlotIdx) {}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,4 @@
* @param edit the editor change
* @param newIr the new literal
*/
public record SimpleUpdate(
Literal ir,
TextEdit edit,
Literal newIr
) {
}
public record SimpleUpdate(Literal ir, TextEdit edit, Literal newIr) {}
Loading

0 comments on commit c109886

Please sign in to comment.