Skip to content

refactor: Format Java code #216

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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: 2 additions & 1 deletion src/main/java/com/caoccao/javet/interop/JavetBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
import java.util.Map;

public final class JavetBridge {
private JavetBridge() {}
private JavetBridge() {
}

public static Map<Long, IV8ValueReference> getReferenceMapSnapshot(V8Runtime runtime) {
return new HashMap<>(runtime.referenceMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public class AddLicenseHeader extends Recipe {
* See {@link MethodMatcher} for details on the expression's syntax.
*/
@Option(displayName = "License text",
description = "The license header text without the block comment. May contain ${CURRENT_YEAR} property.",
example = "Copyright ${CURRENT_YEAR} the original author or authors...")
description = "The license header text without the block comment. May contain ${CURRENT_YEAR} property.",
example = "Copyright ${CURRENT_YEAR} the original author or authors...")
String licenseText;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ public J visitJsImport(JS.JsImport jsImport, P p) {
}
return i;
}

public J visitJsOperator(JS.JsOperator operator, P p) {
JS.JsOperator o = operator;
o = o.withPrefix(visitSpace(o.getPrefix(), JsSpace.Location.OPERATOR_PREFIX, p));
Expand Down Expand Up @@ -458,7 +459,8 @@ private <J2 extends J> JContainer<J2> visitTypeNames(@Nullable JContainer<J2> na
if (nameTrees == null) {
return null;
}
@SuppressWarnings("unchecked") List<JRightPadded<J2>> js = ListUtils.map(nameTrees.getPadding().getElements(),
@SuppressWarnings("unchecked")
List<JRightPadded<J2>> js = ListUtils.map(nameTrees.getPadding().getElements(),
t -> t.getElement() instanceof NameTree ? (JRightPadded<J2>) visitTypeName((JRightPadded<NameTree>) t, p) : t);
return js == nameTrees.getPadding().getElements() ? nameTrees : JContainer.build(nameTrees.getBefore(), js, Markers.EMPTY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private static void actuallyInit() {
try (
InputStream inputStream = JavetLibLoader.class.getResourceAsStream(nativeLibPath);
FileOutputStream outputStream = new FileOutputStream(tempFile)
) {
) {
if (inputStream == null) {
throw new IllegalStateException("Could not find bundled resource for " + nativeLibPath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import org.openrewrite.internal.lang.Nullable;

public class JavetUtils {
private JavetUtils() {}
private JavetUtils() {
}

public static void close(@Nullable IV8Value valueV8) {
if (valueV8 != null && !valueV8.isClosed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private void printTSCNode(TSCNode node, int depth, TSCSourceFileContext context,
outputLines.add(line);
List<TSCNode> tscNodes = node.getAllChildNodes();

for ( int i = 0; i < tscNodes.size(); i++) {
for (int i = 0; i < tscNodes.size(); i++) {
TSCNode childNode = tscNodes.get(i);
TSCNode nextChildNode = i < tscNodes.size() - 1 ? tscNodes.get(i + 1) : null;
boolean hasGap = nextChildNode != null && nextChildNode.getStart() > childNode.getEnd();
Expand Down Expand Up @@ -161,7 +161,7 @@ private void printTSCNode(TSCNode node, int depth, TSCSourceFileContext context,
}

private static String toString(TSCNode node) {
return "[" + node.getStart() + "," + node.getEnd() + ")" + " | " + node.syntaxKind().name() + " | Text : \"" +
return "[" + node.getStart() + "," + node.getEnd() + ")" + " | " + node.syntaxKind().name() + " | Text : \"" +
truncate(node.getText()).replace("\n", "\\n").replace("\r", "\\r") + "\"";
}

Expand Down Expand Up @@ -401,7 +401,7 @@ public static String printIndexedSourceCode(String sourceCode) {
}

if (!digits.isEmpty()) {
spacesSb.append(digits.poll()) ;
spacesSb.append(digits.poll());
} else {
spacesSb.append(" ");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public JS.CompilationUnit visitSourceFile() {
List<JRightPadded<Statement>> statements = new ArrayList<>(statementList.size());
Space prefix = whitespace();
for (TSCNode child : statementList) {
@Nullable J visited;
@Nullable
J visited;
int saveCursor = getCursor();
try {
visited = visitNode(child);
Expand Down Expand Up @@ -1728,7 +1729,7 @@ private J.Literal visitNumericLiteral(TSCNode node) {

private J visitObjectLiteralExpression(TSCNode node) {
Space prefix = whitespace();
return mapPropertyNodesToNewClass( node.getOptionalNodeListProperty("properties"), prefix);
return mapPropertyNodesToNewClass(node.getOptionalNodeListProperty("properties"), prefix);
}

private JS.ObjectBindingDeclarations mapObjectBindingDeclaration(TSCNode node) {
Expand Down Expand Up @@ -2334,7 +2335,7 @@ private JS.JsOperator visitTsOperator(TSCNode node) {

private J visitTypeLiteral(TSCNode node) {
Space prefix = whitespace();
return mapPropertyNodesToNewClass( node.getOptionalNodeListProperty("members"), prefix);
return mapPropertyNodesToNewClass(node.getOptionalNodeListProperty("members"), prefix);
}

private JS.TypeOperator visitTypeOperator(TSCNode node) {
Expand Down Expand Up @@ -3606,4 +3607,4 @@ private void implementMe(TSCNode node, String propertyName) {
throw new UnsupportedOperationException(node.syntaxKind() + "#" + propertyName + " not implemented");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public interface TSCConversion<T> {
}

default T convertNonNull(TSCProgramContext context, V8Value value) {
@Nullable T converted = convertNullable(context, value);
@Nullable
T converted = convertNullable(context, value);
if (converted == null) {
throw new IllegalArgumentException("value converted to null, but was required to be non-null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@

@Value
public class TSCIndexInfo {
@NonNull TSCType keyType;
@NonNull TSCType type;
@NonNull
TSCType keyType;
@NonNull
TSCType type;
boolean isReadonly;
TSCNode declaration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static TSCInstanceOfChecks fromJS(V8ValueObject tsGlobalsV8) {
V8ValueObject allocators = tsGlobalsV8.get("objectAllocator");
V8ValueArray constructors = runtimeV8.createV8ValueArray();
V8ValueObject outerVars = runtimeV8.createV8ValueObject()
) {
) {

for (ConstructorKind constructorKind : ConstructorKind.values()) {
try (V8ValueFunction constructor = allocators.invoke(constructorKind.allocatorAccessorName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static TSCProgramContext fromJS(V8ValueObject contextV8) {
V8ValueFunction createScanner = contextV8.get("createScanner");
V8ValueFunction getOpenRewriteId = contextV8.get("getOpenRewriteId");
V8ValueObject pathPrefixes = contextV8.get("pathPrefixes");
) {
) {
return new TSCProgramContext(
program,
tsGlobals,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void parseSourceTexts(Map<Path, String> sourceTexts, BiConsumer<TSCNode,
V8ValueObject parseResultV8 = tsParseV8.call(null, sourceTextsV8, this.parseOptionsV8);
TSCProgramContext programContext = TSCProgramContext.fromJS(parseResultV8);
V8ValueMap sourceFilesByPathV8 = parseResultV8.get("sourceFiles")
) {
) {
sourceFilesByPathV8.forEach((V8ValueString filePathV8, V8Value maybeSourceFileV8) -> {
if (maybeSourceFileV8.isNullOrUndefined()) {
// TODO figure out how to handle this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public String toString() {
if (enclosing != null) {
interfaceName = enclosing.getSimpleName();
}
return "Type[as " + interfaceName + "]#" + getTypeId() + "(" + typeToString() + ")";
return "Type[as " + interfaceName + "]#" + getTypeId() + "(" + typeToString() + ")";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ default List<String> getOwnPropertyNames() {
}

default List<String> getAllPropertyNames() {
try(IV8ValueArray propertyNames = this.getBackingV8Object().getPropertyNames()) {
try (IV8ValueArray propertyNames = this.getBackingV8Object().getPropertyNames()) {
List<String> result = new ArrayList<>(propertyNames.getLength());
for (int i = 0; i < propertyNames.getLength(); i++) {
result.add(propertyNames.getString(i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static V8ValueFunction makeFunction(
try (
V8ValueFunction outerFn = runtime.createV8ValueFunction(outerCode);
V8Value innerFnObject = outerFn.call(null, variables)
) {
) {
if (!(innerFnObject instanceof V8ValueFunction)) {
throw new IllegalStateException("expected a function; found: " + innerFnObject.getClass().getSimpleName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public void defaults(RecipeSpec spec) {
@Test
void noChange() {
rewriteRun(
javaScript(
"""
javaScript(
"""
function foo(x) {
switch (x) {
case "a":
Expand All @@ -52,15 +52,15 @@ function foo(x) {
}
}
"""
)
)
);
}

@Test
void booleanLiteral() {
rewriteRun(
javaScript(
"""
javaScript(
"""
function method(x: number) {
switch (true) {
case foo(), bar():
Expand All @@ -75,15 +75,15 @@ function foo(): boolean {
function bar(): boolean {
}
"""
)
)
);
}

@Test
void logicalAndWithOr() {
rewriteRun(
javaScript(
"""
javaScript(
"""
function foo(x) {
switch (x) {
case "a" && "b" || "c":
Expand All @@ -94,16 +94,16 @@ function foo(x) {
}
}
"""
)
)
);
}

@DocumentExample
@Test
void logicalOrs() {
rewriteRun(
javaScript(
"""
javaScript(
"""
function foo(x) {
switch (x) {
case "a" || "b" || "c":
Expand All @@ -114,7 +114,7 @@ function foo(x) {
}
}
""",
"""
"""
function foo(x) {
switch (x) {
case "a":
Expand All @@ -127,15 +127,15 @@ function foo(x) {
}
}
"""
)
)
);
}

@Test
void logicalComma() {
rewriteRun(
javaScript(
"""
javaScript(
"""
function foo(x) {
switch (x) {
case "a" , "b" , "c":
Expand All @@ -146,7 +146,7 @@ function foo(x) {
}
}
""",
"""
"""
function foo(x) {
switch (x) {
case "a":
Expand All @@ -159,15 +159,15 @@ function foo(x) {
}
}
"""
)
)
);
}

@Test
void withBraces() {
rewriteRun(
javaScript(
"""
javaScript(
"""
function foo(x) {
switch (x) {
case "a" , "b" , "c": {
Expand All @@ -179,7 +179,7 @@ function foo(x) {
}
}
""",
"""
"""
function foo(x) {
switch (x) {
case "a":
Expand All @@ -193,7 +193,7 @@ function foo(x) {
}
}
"""
)
)
);
}
}
Loading