Skip to content
Merged
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
27 changes: 21 additions & 6 deletions src/printers/expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
type TernaryExpressionNode
} from "../node-types.ts";
import {
createTypeCheckFunction,
hasChild,
hasDanglingComments,
hasType,
Expand Down Expand Up @@ -1364,6 +1365,19 @@ function printBinaryExpressions(

const logicalOperators = new Set(["||", "&&"]);

const isType = createTypeCheckFunction([
SyntaxType.VoidType,
SyntaxType.IntegralType,
SyntaxType.FloatingPointType,
SyntaxType.FloatingPointType,
SyntaxType.BooleanType,
SyntaxType.TypeIdentifier,
SyntaxType.ScopedTypeIdentifier,
SyntaxType.GenericType,
SyntaxType.ArrayType,
SyntaxType.AnnotatedType
]);

function isSimpleCallArgument(node: NamedNode, depth = 2): boolean {
if (depth <= 0) {
return false;
Expand Down Expand Up @@ -1417,7 +1431,8 @@ function isSimpleCallArgument(node: NamedNode, depth = 2): boolean {
node.type === SyntaxType.MethodReference ||
node.type === SyntaxType.UpdateExpression
) {
return isSimpleCallArgument(node.namedChildren[0], depth);
const [qualifierNode] = node.namedChildren;
return isType(qualifierNode) || isSimpleCallArgument(qualifierNode, depth);
}

return false;
Expand All @@ -1440,11 +1455,11 @@ function isLiteral(node: NamedNode) {
);
}

function isSingleWordType(node: NamedNode) {
return [SyntaxType.Identifier, SyntaxType.This, SyntaxType.Super].includes(
node.type
);
}
const isSingleWordType = createTypeCheckFunction([
SyntaxType.Identifier,
SyntaxType.This,
SyntaxType.Super
]);

function couldExpandArg(arg: NamedNode, lambdaChainRecursion = false) {
if (
Expand Down
16 changes: 16 additions & 0 deletions test/unit-test/member_chain/_input.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,22 @@ public void multipleInvocationsOnNewExpression() {

void methodReferences() {
dtoEntities.stream().map(UserDto::toString).forEach(LOGGER::info);

a.b()
.c()
.d(E[]::f);

a.b()
.c()
.d(e.E[]::f);

a.b()
.c()
.d(E<F>::f);

a.b()
.c()
.d(e.E<F>::f);
}

void classLiteralArgument() {
Expand Down
8 changes: 8 additions & 0 deletions test/unit-test/member_chain/_output.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ public void multipleInvocationsOnNewExpression() {

void methodReferences() {
dtoEntities.stream().map(UserDto::toString).forEach(LOGGER::info);

a.b().c().d(E[]::f);

a.b().c().d(e.E[]::f);

a.b().c().d(E<F>::f);

a.b().c().d(e.E<F>::f);
}

void classLiteralArgument() {
Expand Down
Loading