From 7777b3753b437b543b38529f20fe597666ad485b Mon Sep 17 00:00:00 2001 From: Andrii Rodionov Date: Mon, 25 Nov 2024 09:56:07 +0100 Subject: [PATCH 1/4] fix parsing errors --- openrewrite/src/javascript/parser.ts | 42 ++++++++++++------- .../test/javascript/parser/arrow.test.ts | 18 ++++++++ .../test/javascript/parser/call.test.ts | 34 +++++++++++++++ .../test/javascript/parser/function.test.ts | 7 ++++ 4 files changed, 87 insertions(+), 14 deletions(-) diff --git a/openrewrite/src/javascript/parser.ts b/openrewrite/src/javascript/parser.ts index ca22c0cc..05a5f80e 100644 --- a/openrewrite/src/javascript/parser.ts +++ b/openrewrite/src/javascript/parser.ts @@ -1581,16 +1581,30 @@ export class JavaScriptParserVisitor { name = this.convert(node.expression); } - return new J.MethodInvocation( - randomId(), - prefix, - Markers.EMPTY, - select, - typeArguments, - name, - this.mapCommaSeparatedList(node.getChildren(this.sourceFile).slice(-3)), - this.mapMethodType(node) - ) + if (name instanceof J.Identifier) { + return new J.MethodInvocation( + randomId(), + prefix, + Markers.EMPTY, + select, + typeArguments, + name, + this.mapCommaSeparatedList(node.getChildren(this.sourceFile).slice(-3)), + this.mapMethodType(node) + ) + } else { + return new JS.JSMethodInvocation( + randomId(), + prefix, + Markers.EMPTY, + select, + typeArguments, + name, + this.mapCommaSeparatedList(node.getChildren(this.sourceFile).slice(-3)), + this.mapMethodType(node) + ) + } + } visitNewExpression(node: ts.NewExpression) { @@ -1666,12 +1680,12 @@ export class JavaScriptParserVisitor { node.typeParameters ? this.mapTypeParametersAsObject(node) : null, new Lambda.Parameters( randomId(), - this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken)!), + this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken) ?? node), Markers.EMPTY, - true, + this.findChildNode(node, ts.SyntaxKind.OpenParenToken) ? true : false, node.parameters.length > 0 ? node.parameters.map(p => this.rightPadded(this.convert(p), this.suffix(p))) - .concat(node.parameters.hasTrailingComma ? this.rightPadded(this.newJEmpty(), this.prefix(this.findChildNode(node, ts.SyntaxKind.CloseParenToken)!)) : []) : + .concat(node.parameters.hasTrailingComma ? this.rightPadded(this.newJEmpty(), this.prefix(this.findChildNode(node, ts.SyntaxKind.CloseParenToken) ?? node.equalsGreaterThanToken)) : []) : [this.rightPadded(this.newJEmpty(), this.prefix(this.findChildNode(node, ts.SyntaxKind.CloseParenToken)!))] // to handle the case: (/*no*/) => ... ), this.mapTypeInfo(node), @@ -2428,7 +2442,7 @@ export class JavaScriptParserVisitor { this.prefix(node), Markers.EMPTY, this.mapModifiers(node), - this.visit(node.name!), + node.name ? this.visit(node.name) : null, this.mapTypeParametersAsObject(node), this.mapCommaSeparatedList(this.getParameterListNodes(node)), this.mapTypeInfo(node), diff --git a/openrewrite/test/javascript/parser/arrow.test.ts b/openrewrite/test/javascript/parser/arrow.test.ts index 4038b759..5aaff4e2 100644 --- a/openrewrite/test/javascript/parser/arrow.test.ts +++ b/openrewrite/test/javascript/parser/arrow.test.ts @@ -152,4 +152,22 @@ describe('arrow mapping', () => { ); }); + test('no paren', () => { + rewriteRun( + //language=typescript + typeScript(` + const echo = input => input; + `) + ); + }); + + test('no paren with comments', () => { + rewriteRun( + //language=typescript + typeScript(` + const echo = /*a*/input/*b*/ => input; + `) + ); + }); + }); diff --git a/openrewrite/test/javascript/parser/call.test.ts b/openrewrite/test/javascript/parser/call.test.ts index 7b157562..328138f9 100644 --- a/openrewrite/test/javascript/parser/call.test.ts +++ b/openrewrite/test/javascript/parser/call.test.ts @@ -103,4 +103,38 @@ describe('call mapping', () => { ); }); + test('call expression with mapping', () => { + rewriteRun( + //language=typescript + typeScript(` + type Operation = (a: number, b: number) => number; + + // Define an object with methods accessed by string keys + const operations: { [key: string]: Operation } = { + add: (a, b) => a + b, + multiply: (a, b) => a * b, + }; + + // Access and call the "add" method using bracket notation + const result1 = operations["add"](3, 4); // 3 + 4 = 7 + `) + ); + }); + + + test('call expression with mapping adv', () => { + rewriteRun( + //language=typescript + typeScript(` + const arr: { [key: string]: (x: number, y: number) => number }[] = [ + { + abc: (x, y) => x - y, + }, + ]; + + const result = arr[0]["abc"](10, 5); // Calls the function and subtracts 10 - 5 = 5 + `) + ); + }); + }); diff --git a/openrewrite/test/javascript/parser/function.test.ts b/openrewrite/test/javascript/parser/function.test.ts index cf8767d3..45743715 100644 --- a/openrewrite/test/javascript/parser/function.test.ts +++ b/openrewrite/test/javascript/parser/function.test.ts @@ -66,6 +66,13 @@ describe('function mapping', () => { ); }); + test('function with modifiers and without name', () => { + rewriteRun( + //language=typescript + typeScript('export default function(hljs) {}') + ); + }); + test('function with modifiers and comments', () => { rewriteRun( //language=typescript From a761a70cef12939a5707aee4582d088d25b0c509 Mon Sep 17 00:00:00 2001 From: Andrii Rodionov Date: Mon, 25 Nov 2024 12:00:28 +0100 Subject: [PATCH 2/4] arrow func upd --- openrewrite/src/javascript/parser.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/openrewrite/src/javascript/parser.ts b/openrewrite/src/javascript/parser.ts index 05a5f80e..26d6b338 100644 --- a/openrewrite/src/javascript/parser.ts +++ b/openrewrite/src/javascript/parser.ts @@ -1671,6 +1671,8 @@ export class JavaScriptParserVisitor { } visitArrowFunction(node: ts.ArrowFunction) { + const openParenToken = this.findChildNode(node, ts.SyntaxKind.OpenParenToken); + const isParenthesized = openParenToken != undefined; return new JS.ArrowFunction( randomId(), this.prefix(node), @@ -1680,13 +1682,13 @@ export class JavaScriptParserVisitor { node.typeParameters ? this.mapTypeParametersAsObject(node) : null, new Lambda.Parameters( randomId(), - this.prefix(this.findChildNode(node, ts.SyntaxKind.OpenParenToken) ?? node), + isParenthesized ? this.prefix(openParenToken) : Space.EMPTY, Markers.EMPTY, - this.findChildNode(node, ts.SyntaxKind.OpenParenToken) ? true : false, + isParenthesized, node.parameters.length > 0 ? node.parameters.map(p => this.rightPadded(this.convert(p), this.suffix(p))) - .concat(node.parameters.hasTrailingComma ? this.rightPadded(this.newJEmpty(), this.prefix(this.findChildNode(node, ts.SyntaxKind.CloseParenToken) ?? node.equalsGreaterThanToken)) : []) : - [this.rightPadded(this.newJEmpty(), this.prefix(this.findChildNode(node, ts.SyntaxKind.CloseParenToken)!))] // to handle the case: (/*no*/) => ... + .concat(node.parameters.hasTrailingComma ? this.rightPadded(this.newJEmpty(), this.prefix(this.findChildNode(node, ts.SyntaxKind.CloseParenToken)!)) : []) : + isParenthesized ? [this.rightPadded(this.newJEmpty(), this.prefix(this.findChildNode(node, ts.SyntaxKind.CloseParenToken)!))] : [] // to handle the case: (/*no*/) => ... ), this.mapTypeInfo(node), this.prefix(node.equalsGreaterThanToken), From 6d37c55826cdc8370056b467fa23ae0f003d2807 Mon Sep 17 00:00:00 2001 From: Andrii Rodionov Date: Mon, 25 Nov 2024 14:07:32 +0100 Subject: [PATCH 3/4] call expression refactored for select usage --- openrewrite/src/javascript/parser.ts | 91 ++++++------------- .../test/javascript/parser/call.test.ts | 19 ++++ .../test/javascript/parser/function.test.ts | 13 ++- .../internal/JavaScriptPrinter.java | 8 +- 4 files changed, 67 insertions(+), 64 deletions(-) diff --git a/openrewrite/src/javascript/parser.ts b/openrewrite/src/javascript/parser.ts index 26d6b338..c2e962b8 100644 --- a/openrewrite/src/javascript/parser.ts +++ b/openrewrite/src/javascript/parser.ts @@ -1526,42 +1526,13 @@ export class JavaScriptParserVisitor { const prefix = this.prefix(node); const typeArguments = node.typeArguments ? this.mapTypeArguments(this.prefix(this.findChildNode(node, ts.SyntaxKind.LessThanToken)!), node.typeArguments) : null; - if (ts.isParenthesizedExpression(node.expression)) { - return new JS.JSMethodInvocation( - randomId(), - prefix, - Markers.EMPTY, - null, - typeArguments, - this.convert(node.expression), - this.mapCommaSeparatedList(node.getChildren(this.sourceFile).slice(-3)), - this.mapMethodType(node) - ); - } - - if (node.questionDotToken) { - return new JS.JSMethodInvocation( - randomId(), - prefix, - Markers.EMPTY, - null, - typeArguments, - new JS.Unary( - randomId(), - Space.EMPTY, - Markers.EMPTY, - this.leftPadded(this.suffix(node.expression), JS.Unary.Type.QuestionDotWithDot), - this.visit(node.expression), - this.mapType(node) - ), - this.mapCommaSeparatedList(node.getChildren(this.sourceFile).slice(-3)), - this.mapMethodType(node) - ); - } - let select: JRightPadded | null; - let name: J.Identifier; - if (ts.isPropertyAccessExpression(node.expression)) { + let name: J.Identifier = new J.Identifier( randomId(), Space.EMPTY, Markers.EMPTY, [], "", null, null); + + if (ts.isIdentifier(node.expression) && !node.questionDotToken) { + select = null; + name = this.convert(node.expression); + } else if (ts.isPropertyAccessExpression(node.expression)) { select = this.rightPadded( node.expression.questionDotToken ? new JS.Unary( @@ -1577,34 +1548,32 @@ export class JavaScriptParserVisitor { ); name = this.convert(node.expression.name); } else { - select = null; - name = this.convert(node.expression); - } - - if (name instanceof J.Identifier) { - return new J.MethodInvocation( - randomId(), - prefix, - Markers.EMPTY, - select, - typeArguments, - name, - this.mapCommaSeparatedList(node.getChildren(this.sourceFile).slice(-3)), - this.mapMethodType(node) - ) - } else { - return new JS.JSMethodInvocation( - randomId(), - prefix, - Markers.EMPTY, - select, - typeArguments, - name, - this.mapCommaSeparatedList(node.getChildren(this.sourceFile).slice(-3)), - this.mapMethodType(node) - ) + if (node.questionDotToken) { + select = this.rightPadded(new JS.Unary( + randomId(), + Space.EMPTY, + Markers.EMPTY, + this.leftPadded(this.suffix(node.expression), JS.Unary.Type.QuestionDotWithDot), + this.visit(node.expression), + this.mapType(node) + ), + Space.EMPTY + ) + } else { + select = this.rightPadded(this.visit(node.expression), this.suffix(node.expression)) + } } + return new J.MethodInvocation( + randomId(), + prefix, + Markers.EMPTY, + select, + typeArguments, + name, + this.mapCommaSeparatedList(node.getChildren(this.sourceFile).slice(-3)), + this.mapMethodType(node) + ) } visitNewExpression(node: ts.NewExpression) { diff --git a/openrewrite/test/javascript/parser/call.test.ts b/openrewrite/test/javascript/parser/call.test.ts index 328138f9..daf1cae7 100644 --- a/openrewrite/test/javascript/parser/call.test.ts +++ b/openrewrite/test/javascript/parser/call.test.ts @@ -45,6 +45,8 @@ describe('call mapping', () => { typeScript(` const func = (message: string) => message; const result1 = func/*a*/?./*b*/("TS"); // Invokes the function + const result2 = func/*a*/?./*b*/call("TS"); // Invokes the function + `) ); }); @@ -121,6 +123,23 @@ describe('call mapping', () => { ); }); + test('call expression with mapping and ?.', () => { + rewriteRun( + //language=typescript + typeScript(` + type Operation = (a: number, b: number) => number; + + // Define an object with methods accessed by string keys + const operations: { [key: string]: Operation } = { + add: (a, b) => a + b, + multiply: (a, b) => a * b, + }; + + // Access and call the "add" method using bracket notation + const result1 = operations["add"]?.(3, 4); // 3 + 4 = 7 + `) + ); + }); test('call expression with mapping adv', () => { rewriteRun( diff --git a/openrewrite/test/javascript/parser/function.test.ts b/openrewrite/test/javascript/parser/function.test.ts index 45743715..4735ed1a 100644 --- a/openrewrite/test/javascript/parser/function.test.ts +++ b/openrewrite/test/javascript/parser/function.test.ts @@ -176,7 +176,18 @@ describe('function mapping', () => { typeScript(` (function() { console.log('IIFE'); - })(); + })/*a*/(); + `) + ); + }); + + test('immediately invoked anonymous function with ?.', () => { + rewriteRun( + //language=typescript + typeScript(` + (function() { + console.log('IIFE'); + })/*a*/?./*b*/(); `) ); }); diff --git a/rewrite-javascript/src/main/java/org/openrewrite/javascript/internal/JavaScriptPrinter.java b/rewrite-javascript/src/main/java/org/openrewrite/javascript/internal/JavaScriptPrinter.java index 4113eca5..9750e82c 100644 --- a/rewrite-javascript/src/main/java/org/openrewrite/javascript/internal/JavaScriptPrinter.java +++ b/rewrite-javascript/src/main/java/org/openrewrite/javascript/internal/JavaScriptPrinter.java @@ -918,8 +918,12 @@ public J visitMethodDeclaration(J.MethodDeclaration method, PrintOutputCapture

p) { beforeSyntax(method, Space.Location.METHOD_INVOCATION_PREFIX, p); - visitRightPadded(method.getPadding().getSelect(), JRightPadded.Location.METHOD_SELECT, ".", p); - visit(method.getName(), p); + if (method.getName().toString().isEmpty()) { + visitRightPadded(method.getPadding().getSelect(), JRightPadded.Location.METHOD_SELECT, p); + } else { + visitRightPadded(method.getPadding().getSelect(), JRightPadded.Location.METHOD_SELECT, ".", p); + visit(method.getName(), p); + } visitContainer("<", method.getPadding().getTypeParameters(), JContainer.Location.TYPE_PARAMETERS, ",", ">", p); visitContainer("(", method.getPadding().getArguments(), JContainer.Location.METHOD_INVOCATION_ARGUMENTS, ",", ")", p); afterSyntax(method, p); From ff9183e9f4a3cc1a8a9bff4b7420e34a56f95d83 Mon Sep 17 00:00:00 2001 From: Andrii Rodionov Date: Mon, 25 Nov 2024 14:46:51 +0100 Subject: [PATCH 4/4] removed JS.JSMethodInvocation --- openrewrite/src/javascript/remote/receiver.ts | 27 +--- openrewrite/src/javascript/remote/sender.ts | 14 +- .../src/javascript/tree/support_types.ts | 4 - openrewrite/src/javascript/tree/tree.ts | 132 --------------- openrewrite/src/javascript/visitor.ts | 24 +-- .../javascript/remote/JavaScriptReceiver.java | 26 --- .../javascript/remote/JavaScriptSender.java | 13 -- .../remote/JavaScriptValidator.java | 9 -- .../javascript/JavaScriptVisitor.java | 36 ----- .../internal/JavaScriptPrinter.java | 11 -- .../org/openrewrite/javascript/tree/JS.java | 152 ------------------ .../javascript/tree/JsContainer.java | 2 - .../javascript/tree/JsRightPadded.java | 2 - .../openrewrite/javascript/tree/JsSpace.java | 3 - 14 files changed, 3 insertions(+), 452 deletions(-) diff --git a/openrewrite/src/javascript/remote/receiver.ts b/openrewrite/src/javascript/remote/receiver.ts index 867a07d7..05a0351b 100644 --- a/openrewrite/src/javascript/remote/receiver.ts +++ b/openrewrite/src/javascript/remote/receiver.ts @@ -2,7 +2,7 @@ import * as extensions from "./remote_extensions"; import {Checksum, Cursor, FileAttributes, ListUtils, Tree} from '../../core'; import {DetailsReceiver, Receiver, ReceiverContext, ReceiverFactory, ValueType} from '@openrewrite/rewrite-remote'; import {JavaScriptVisitor} from '..'; -import {JS, JsLeftPadded, JsRightPadded, JsContainer, JsSpace, CompilationUnit, Alias, ArrowFunction, Await, DefaultType, Delete, Export, ExpressionStatement, FunctionType, JsImport, JsImportSpecifier, JsBinary, ObjectBindingDeclarations, PropertyAssignment, ScopedVariableDeclarations, StatementExpression, TemplateExpression, Tuple, TypeDeclaration, TypeOf, TypeQuery, TypeOperator, Unary, Union, Intersection, Void, Yield, TypeInfo, JSVariableDeclarations, JSMethodDeclaration, JSMethodInvocation, JSForOfLoop, JSForInLoop, JSForInOfLoopControl, NamespaceDeclaration, FunctionDeclaration, TypeLiteral, IndexSignatureDeclaration, ArrayBindingPattern, BindingElement} from '../tree'; +import {JS, JsLeftPadded, JsRightPadded, JsContainer, JsSpace, CompilationUnit, Alias, ArrowFunction, Await, DefaultType, Delete, Export, ExpressionStatement, FunctionType, JsImport, JsImportSpecifier, JsBinary, ObjectBindingDeclarations, PropertyAssignment, ScopedVariableDeclarations, StatementExpression, TemplateExpression, Tuple, TypeDeclaration, TypeOf, TypeQuery, TypeOperator, Unary, Union, Intersection, Void, Yield, TypeInfo, JSVariableDeclarations, JSMethodDeclaration, JSForOfLoop, JSForInLoop, JSForInOfLoopControl, NamespaceDeclaration, FunctionDeclaration, TypeLiteral, IndexSignatureDeclaration, ArrayBindingPattern, BindingElement} from '../tree'; import {Expression, J, JContainer, JLeftPadded, JRightPadded, NameTree, Space, Statement, TypeTree, TypedTree} from "../../java"; import * as Java from "../../java/tree"; @@ -358,18 +358,6 @@ class Visitor extends JavaScriptVisitor { return jSMethodDeclaration; } - public visitJSMethodInvocation(jSMethodInvocation: JSMethodInvocation, ctx: ReceiverContext): J { - jSMethodInvocation = jSMethodInvocation.withId(ctx.receiveValue(jSMethodInvocation.id, ValueType.UUID)!); - jSMethodInvocation = jSMethodInvocation.withPrefix(ctx.receiveNode(jSMethodInvocation.prefix, receiveSpace)!); - jSMethodInvocation = jSMethodInvocation.withMarkers(ctx.receiveNode(jSMethodInvocation.markers, ctx.receiveMarkers)!); - jSMethodInvocation = jSMethodInvocation.padding.withSelect(ctx.receiveNode(jSMethodInvocation.padding.select, receiveRightPaddedTree)); - jSMethodInvocation = jSMethodInvocation.padding.withTypeParameters(ctx.receiveNode(jSMethodInvocation.padding.typeParameters, receiveContainer)); - jSMethodInvocation = jSMethodInvocation.withName(ctx.receiveNode(jSMethodInvocation.name, ctx.receiveTree)!); - jSMethodInvocation = jSMethodInvocation.padding.withArguments(ctx.receiveNode(jSMethodInvocation.padding.arguments, receiveContainer)!); - jSMethodInvocation = jSMethodInvocation.withMethodType(ctx.receiveValue(jSMethodInvocation.methodType, ValueType.Object)); - return jSMethodInvocation; - } - public visitJSForOfLoop(jSForOfLoop: JSForOfLoop, ctx: ReceiverContext): J { jSForOfLoop = jSForOfLoop.withId(ctx.receiveValue(jSForOfLoop.id, ValueType.UUID)!); jSForOfLoop = jSForOfLoop.withPrefix(ctx.receiveNode(jSForOfLoop.prefix, receiveSpace)!); @@ -1496,19 +1484,6 @@ class Factory implements ReceiverFactory { ); } - if (type === "org.openrewrite.javascript.tree.JS$JSMethodInvocation") { - return new JSMethodInvocation( - ctx.receiveValue(null, ValueType.UUID)!, - ctx.receiveNode(null, receiveSpace)!, - ctx.receiveNode(null, ctx.receiveMarkers)!, - ctx.receiveNode>(null, receiveRightPaddedTree), - ctx.receiveNode>(null, receiveContainer), - ctx.receiveNode(null, ctx.receiveTree)!, - ctx.receiveNode>(null, receiveContainer)!, - ctx.receiveValue(null, ValueType.Object) - ); - } - if (type === "org.openrewrite.javascript.tree.JS$JSForOfLoop") { return new JSForOfLoop( ctx.receiveValue(null, ValueType.UUID)!, diff --git a/openrewrite/src/javascript/remote/sender.ts b/openrewrite/src/javascript/remote/sender.ts index 51221b73..02c73602 100644 --- a/openrewrite/src/javascript/remote/sender.ts +++ b/openrewrite/src/javascript/remote/sender.ts @@ -2,7 +2,7 @@ import * as extensions from "./remote_extensions"; import {Cursor, ListUtils, Tree} from '../../core'; import {Sender, SenderContext, ValueType} from '@openrewrite/rewrite-remote'; import {JavaScriptVisitor} from '..'; -import {JS, JsLeftPadded, JsRightPadded, JsContainer, JsSpace, CompilationUnit, Alias, ArrowFunction, Await, DefaultType, Delete, Export, ExpressionStatement, FunctionType, JsImport, JsImportSpecifier, JsBinary, ObjectBindingDeclarations, PropertyAssignment, ScopedVariableDeclarations, StatementExpression, TemplateExpression, Tuple, TypeDeclaration, TypeOf, TypeQuery, TypeOperator, Unary, Union, Intersection, Void, Yield, TypeInfo, JSVariableDeclarations, JSMethodDeclaration, JSMethodInvocation, JSForOfLoop, JSForInLoop, JSForInOfLoopControl, NamespaceDeclaration, FunctionDeclaration, TypeLiteral, IndexSignatureDeclaration, ArrayBindingPattern, BindingElement} from '../tree'; +import {JS, JsLeftPadded, JsRightPadded, JsContainer, JsSpace, CompilationUnit, Alias, ArrowFunction, Await, DefaultType, Delete, Export, ExpressionStatement, FunctionType, JsImport, JsImportSpecifier, JsBinary, ObjectBindingDeclarations, PropertyAssignment, ScopedVariableDeclarations, StatementExpression, TemplateExpression, Tuple, TypeDeclaration, TypeOf, TypeQuery, TypeOperator, Unary, Union, Intersection, Void, Yield, TypeInfo, JSVariableDeclarations, JSMethodDeclaration, JSForOfLoop, JSForInLoop, JSForInOfLoopControl, NamespaceDeclaration, FunctionDeclaration, TypeLiteral, IndexSignatureDeclaration, ArrayBindingPattern, BindingElement} from '../tree'; import {Expression, J, JContainer, JLeftPadded, JRightPadded, Space, Statement} from "../../java"; import * as Java from "../../java/tree"; @@ -353,18 +353,6 @@ class Visitor extends JavaScriptVisitor { return jSMethodDeclaration; } - public visitJSMethodInvocation(jSMethodInvocation: JSMethodInvocation, ctx: SenderContext): J { - ctx.sendValue(jSMethodInvocation, v => v.id, ValueType.UUID); - ctx.sendNode(jSMethodInvocation, v => v.prefix, Visitor.sendSpace); - ctx.sendNode(jSMethodInvocation, v => v.markers, ctx.sendMarkers); - ctx.sendNode(jSMethodInvocation, v => v.padding.select, Visitor.sendRightPadded(ValueType.Tree)); - ctx.sendNode(jSMethodInvocation, v => v.padding.typeParameters, Visitor.sendContainer(ValueType.Tree)); - ctx.sendNode(jSMethodInvocation, v => v.name, ctx.sendTree); - ctx.sendNode(jSMethodInvocation, v => v.padding.arguments, Visitor.sendContainer(ValueType.Tree)); - ctx.sendTypedValue(jSMethodInvocation, v => v.methodType, ValueType.Object); - return jSMethodInvocation; - } - public visitJSForOfLoop(jSForOfLoop: JSForOfLoop, ctx: SenderContext): J { ctx.sendValue(jSForOfLoop, v => v.id, ValueType.UUID); ctx.sendNode(jSForOfLoop, v => v.prefix, Visitor.sendSpace); diff --git a/openrewrite/src/javascript/tree/support_types.ts b/openrewrite/src/javascript/tree/support_types.ts index fe0854a7..2c6fd4ed 100644 --- a/openrewrite/src/javascript/tree/support_types.ts +++ b/openrewrite/src/javascript/tree/support_types.ts @@ -223,7 +223,6 @@ export namespace JsSpace { NAMESPACE_DECLARATION_PREFIX, JSMETHOD_DECLARATION_PREFIX, FUNCTION_DECLARATION_PREFIX, - JSMETHOD_INVOCATION_PREFIX, INTERSECTION_PREFIX, TYPE_LITERAL_PREFIX, TYPE_LITERAL_MEMBERS_PREFIX, @@ -276,7 +275,6 @@ export namespace JsRightPadded { JSVARIABLE_DECLARATIONS_VARIABLES, NAMESPACE_DECLARATION_NAME, INTERSECTION_TYPES, - JSMETHOD_INVOCATION_SELECT, TYPE_LITERAL_MEMBERS, INDEX_SIGNATURE_DECLARATION_PARAMETERS, JSFOR_IN_OF_LOOP_CONTROL_VARIABLE, @@ -296,8 +294,6 @@ export namespace JsContainer { JSMETHOD_DECLARATION_PARAMETERS, JSMETHOD_DECLARATION_THROWZ, FUNCTION_DECLARATION_PARAMETERS, - JSMETHOD_INVOCATION_TYPE_PARAMETERS, - JSMETHOD_INVOCATION_ARGUMENTS, TYPE_LITERAL_MEMBERS, INDEX_SIGNATURE_DECLARATION_PARAMETERS, ARRAY_BINDING_PATTERN_ELEMENTS, diff --git a/openrewrite/src/javascript/tree/tree.ts b/openrewrite/src/javascript/tree/tree.ts index 977f9f2c..d067b46d 100644 --- a/openrewrite/src/javascript/tree/tree.ts +++ b/openrewrite/src/javascript/tree/tree.ts @@ -2987,138 +2987,6 @@ export class JSMethodDeclaration extends JSMixin(Object) implements Statement, T } -@LstType("org.openrewrite.javascript.tree.JS$JSMethodInvocation") -export class JSMethodInvocation extends JSMixin(Object) implements Statement, TypedTree, MethodCall { - public constructor(id: UUID, prefix: Space, markers: Markers, select: JRightPadded | null, typeParameters: JContainer | null, name: Expression, _arguments: JContainer, methodType: JavaType.Method | null) { - super(); - this._id = id; - this._prefix = prefix; - this._markers = markers; - this._select = select; - this._typeParameters = typeParameters; - this._name = name; - this._arguments = _arguments; - this._methodType = methodType; - } - - private readonly _id: UUID; - - public get id(): UUID { - return this._id; - } - - public withId(id: UUID): JSMethodInvocation { - return id === this._id ? this : new JSMethodInvocation(id, this._prefix, this._markers, this._select, this._typeParameters, this._name, this._arguments, this._methodType); - } - - private readonly _prefix: Space; - - public get prefix(): Space { - return this._prefix; - } - - public withPrefix(prefix: Space): JSMethodInvocation { - return prefix === this._prefix ? this : new JSMethodInvocation(this._id, prefix, this._markers, this._select, this._typeParameters, this._name, this._arguments, this._methodType); - } - - private readonly _markers: Markers; - - public get markers(): Markers { - return this._markers; - } - - public withMarkers(markers: Markers): JSMethodInvocation { - return markers === this._markers ? this : new JSMethodInvocation(this._id, this._prefix, markers, this._select, this._typeParameters, this._name, this._arguments, this._methodType); - } - - private readonly _select: JRightPadded | null; - - public get select(): Expression | null { - return this._select === null ? null : this._select.element; - } - - public withSelect(select: Expression | null): JSMethodInvocation { - return this.padding.withSelect(JRightPadded.withElement(this._select, select)); - } - - private readonly _typeParameters: JContainer | null; - - public get typeParameters(): Expression[] | null { - return this._typeParameters === null ? null : this._typeParameters.elements; - } - - public withTypeParameters(typeParameters: Expression[] | null): JSMethodInvocation { - return this.padding.withTypeParameters(JContainer.withElementsNullable(this._typeParameters, typeParameters)); - } - - private readonly _name: Expression; - - public get name(): Expression { - return this._name; - } - - public withName(name: Expression): JSMethodInvocation { - return name === this._name ? this : new JSMethodInvocation(this._id, this._prefix, this._markers, this._select, this._typeParameters, name, this._arguments, this._methodType); - } - - private readonly _arguments: JContainer; - - public get arguments(): Expression[] { - return this._arguments.elements; - } - - public withArguments(_arguments: Expression[]): JSMethodInvocation { - return this.padding.withArguments(JContainer.withElements(this._arguments, _arguments)); - } - - private readonly _methodType: JavaType.Method | null; - - public get methodType(): JavaType.Method | null { - return this._methodType; - } - - public withMethodType(methodType: JavaType.Method | null): JSMethodInvocation { - return methodType === this._methodType ? this : new JSMethodInvocation(this._id, this._prefix, this._markers, this._select, this._typeParameters, this._name, this._arguments, methodType); - } - - public acceptJavaScript

(v: JavaScriptVisitor

, p: P): J | null { - return v.visitJSMethodInvocation(this, p); - } - - public get type(): JavaType | null { - return extensions.getJavaType(this); - } - - public withType(type: JavaType): JSMethodInvocation { - return extensions.withJavaType(this, type); - } - - get padding() { - const t = this; - return new class { - public get select(): JRightPadded | null { - return t._select; - } - public withSelect(select: JRightPadded | null): JSMethodInvocation { - return t._select === select ? t : new JSMethodInvocation(t._id, t._prefix, t._markers, select, t._typeParameters, t._name, t._arguments, t._methodType); - } - public get typeParameters(): JContainer | null { - return t._typeParameters; - } - public withTypeParameters(typeParameters: JContainer | null): JSMethodInvocation { - return t._typeParameters === typeParameters ? t : new JSMethodInvocation(t._id, t._prefix, t._markers, t._select, typeParameters, t._name, t._arguments, t._methodType); - } - public get arguments(): JContainer { - return t._arguments; - } - public withArguments(_arguments: JContainer): JSMethodInvocation { - return t._arguments === _arguments ? t : new JSMethodInvocation(t._id, t._prefix, t._markers, t._select, t._typeParameters, t._name, _arguments, t._methodType); - } - } - } - -} - @LstType("org.openrewrite.javascript.tree.JS$JSForOfLoop") export class JSForOfLoop extends JSMixin(Object) implements Loop { public constructor(id: UUID, prefix: Space, markers: Markers, await: JLeftPadded, control: JSForInOfLoopControl, body: JRightPadded) { diff --git a/openrewrite/src/javascript/visitor.ts b/openrewrite/src/javascript/visitor.ts index 179a1af2..d67c4bb0 100644 --- a/openrewrite/src/javascript/visitor.ts +++ b/openrewrite/src/javascript/visitor.ts @@ -1,7 +1,7 @@ import * as extensions from "./extensions"; import {ListUtils, SourceFile, Tree, TreeVisitor} from "../core"; import {JS, isJavaScript, JsLeftPadded, JsRightPadded, JsContainer, JsSpace} from "./tree"; -import {CompilationUnit, Alias, ArrowFunction, Await, DefaultType, Delete, Export, ExpressionStatement, FunctionType, JsImport, JsImportSpecifier, JsBinary, ObjectBindingDeclarations, PropertyAssignment, ScopedVariableDeclarations, StatementExpression, TemplateExpression, Tuple, TypeDeclaration, TypeOf, TypeQuery, TypeOperator, Unary, Union, Intersection, Void, Yield, TypeInfo, JSVariableDeclarations, JSMethodDeclaration, JSMethodInvocation, JSForOfLoop, JSForInLoop, JSForInOfLoopControl, NamespaceDeclaration, FunctionDeclaration, TypeLiteral, IndexSignatureDeclaration, ArrayBindingPattern, BindingElement} from "./tree"; +import {CompilationUnit, Alias, ArrowFunction, Await, DefaultType, Delete, Export, ExpressionStatement, FunctionType, JsImport, JsImportSpecifier, JsBinary, ObjectBindingDeclarations, PropertyAssignment, ScopedVariableDeclarations, StatementExpression, TemplateExpression, Tuple, TypeDeclaration, TypeOf, TypeQuery, TypeOperator, Unary, Union, Intersection, Void, Yield, TypeInfo, JSVariableDeclarations, JSMethodDeclaration, JSForOfLoop, JSForInLoop, JSForInOfLoopControl, NamespaceDeclaration, FunctionDeclaration, TypeLiteral, IndexSignatureDeclaration, ArrayBindingPattern, BindingElement} from "./tree"; import {Expression, J, JContainer, JLeftPadded, JRightPadded, Space, Statement} from "../java/tree"; import {JavaVisitor} from "../java"; import * as Java from "../java/tree"; @@ -475,28 +475,6 @@ export class JavaScriptVisitor

extends JavaVisitor

{ return jSMethodDeclaration; } - public visitJSMethodInvocation(jSMethodInvocation: JSMethodInvocation, p: P): J | null { - jSMethodInvocation = jSMethodInvocation.withPrefix(this.visitJsSpace(jSMethodInvocation.prefix, JsSpace.Location.JSMETHOD_INVOCATION_PREFIX, p)!); - let tempStatement = this.visitStatement(jSMethodInvocation, p) as Statement; - if (!(tempStatement instanceof JSMethodInvocation)) - { - return tempStatement; - } - jSMethodInvocation = tempStatement as JSMethodInvocation; - let tempExpression = this.visitExpression(jSMethodInvocation, p) as Expression; - if (!(tempExpression instanceof JSMethodInvocation)) - { - return tempExpression; - } - jSMethodInvocation = tempExpression as JSMethodInvocation; - jSMethodInvocation = jSMethodInvocation.withMarkers(this.visitMarkers(jSMethodInvocation.markers, p)); - jSMethodInvocation = jSMethodInvocation.padding.withSelect(this.visitJsRightPadded(jSMethodInvocation.padding.select, JsRightPadded.Location.JSMETHOD_INVOCATION_SELECT, p)); - jSMethodInvocation = jSMethodInvocation.padding.withTypeParameters(this.visitJsContainer(jSMethodInvocation.padding.typeParameters, JsContainer.Location.JSMETHOD_INVOCATION_TYPE_PARAMETERS, p)); - jSMethodInvocation = jSMethodInvocation.withName(this.visitAndCast(jSMethodInvocation.name, p)!); - jSMethodInvocation = jSMethodInvocation.padding.withArguments(this.visitJsContainer(jSMethodInvocation.padding.arguments, JsContainer.Location.JSMETHOD_INVOCATION_ARGUMENTS, p)!); - return jSMethodInvocation; - } - public visitJSForOfLoop(jSForOfLoop: JSForOfLoop, p: P): J | null { jSForOfLoop = jSForOfLoop.withPrefix(this.visitJsSpace(jSForOfLoop.prefix, JsSpace.Location.JSFOR_OF_LOOP_PREFIX, p)!); let tempStatement = this.visitStatement(jSForOfLoop, p) as Statement; diff --git a/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptReceiver.java b/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptReceiver.java index f4d92c46..6b4299b5 100644 --- a/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptReceiver.java +++ b/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptReceiver.java @@ -436,19 +436,6 @@ public JS.JSMethodDeclaration visitJSMethodDeclaration(JS.JSMethodDeclaration jS return jSMethodDeclaration; } - @Override - public JS.JSMethodInvocation visitJSMethodInvocation(JS.JSMethodInvocation jSMethodInvocation, ReceiverContext ctx) { - jSMethodInvocation = jSMethodInvocation.withId(ctx.receiveNonNullValue(jSMethodInvocation.getId(), UUID.class)); - jSMethodInvocation = jSMethodInvocation.withPrefix(ctx.receiveNonNullNode(jSMethodInvocation.getPrefix(), JavaScriptReceiver::receiveSpace)); - jSMethodInvocation = jSMethodInvocation.withMarkers(ctx.receiveNonNullNode(jSMethodInvocation.getMarkers(), ctx::receiveMarkers)); - jSMethodInvocation = jSMethodInvocation.getPadding().withSelect(ctx.receiveNode(jSMethodInvocation.getPadding().getSelect(), JavaScriptReceiver::receiveRightPaddedTree)); - jSMethodInvocation = jSMethodInvocation.getPadding().withTypeParameters(ctx.receiveNode(jSMethodInvocation.getPadding().getTypeParameters(), JavaScriptReceiver::receiveContainer)); - jSMethodInvocation = jSMethodInvocation.withName(ctx.receiveNonNullNode(jSMethodInvocation.getName(), ctx::receiveTree)); - jSMethodInvocation = jSMethodInvocation.getPadding().withArguments(ctx.receiveNonNullNode(jSMethodInvocation.getPadding().getArguments(), JavaScriptReceiver::receiveContainer)); - jSMethodInvocation = jSMethodInvocation.withMethodType(ctx.receiveValue(jSMethodInvocation.getMethodType(), JavaType.Method.class)); - return jSMethodInvocation; - } - @Override public JS.JSForOfLoop visitJSForOfLoop(JS.JSForOfLoop jSForOfLoop, ReceiverContext ctx) { jSForOfLoop = jSForOfLoop.withId(ctx.receiveNonNullValue(jSForOfLoop.getId(), UUID.class)); @@ -1614,19 +1601,6 @@ public T create(Class type, ReceiverContext ctx) { ); } - if (type == JS.JSMethodInvocation.class) { - return (T) new JS.JSMethodInvocation( - ctx.receiveNonNullValue(null, UUID.class), - ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), - ctx.receiveNonNullNode(null, ctx::receiveMarkers), - ctx.receiveNode(null, JavaScriptReceiver::receiveRightPaddedTree), - ctx.receiveNode(null, JavaScriptReceiver::receiveContainer), - ctx.receiveNonNullNode(null, ctx::receiveTree), - ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveContainer), - ctx.receiveValue(null, JavaType.Method.class) - ); - } - if (type == JS.JSForOfLoop.class) { return (T) new JS.JSForOfLoop( ctx.receiveNonNullValue(null, UUID.class), diff --git a/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptSender.java b/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptSender.java index 32d88967..25fd7a8f 100644 --- a/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptSender.java +++ b/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptSender.java @@ -419,19 +419,6 @@ public JS.JSMethodDeclaration visitJSMethodDeclaration(JS.JSMethodDeclaration jS return jSMethodDeclaration; } - @Override - public JS.JSMethodInvocation visitJSMethodInvocation(JS.JSMethodInvocation jSMethodInvocation, SenderContext ctx) { - ctx.sendValue(jSMethodInvocation, JS.JSMethodInvocation::getId); - ctx.sendNode(jSMethodInvocation, JS.JSMethodInvocation::getPrefix, JavaScriptSender::sendSpace); - ctx.sendNode(jSMethodInvocation, JS.JSMethodInvocation::getMarkers, ctx::sendMarkers); - ctx.sendNode(jSMethodInvocation, e -> e.getPadding().getSelect(), JavaScriptSender::sendRightPadded); - ctx.sendNode(jSMethodInvocation, e -> e.getPadding().getTypeParameters(), JavaScriptSender::sendContainer); - ctx.sendNode(jSMethodInvocation, JS.JSMethodInvocation::getName, ctx::sendTree); - ctx.sendNode(jSMethodInvocation, e -> e.getPadding().getArguments(), JavaScriptSender::sendContainer); - ctx.sendTypedValue(jSMethodInvocation, JS.JSMethodInvocation::getMethodType); - return jSMethodInvocation; - } - @Override public JS.JSForOfLoop visitJSForOfLoop(JS.JSForOfLoop jSForOfLoop, SenderContext ctx) { ctx.sendValue(jSForOfLoop, JS.JSForOfLoop::getId); diff --git a/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptValidator.java b/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptValidator.java index b0ab228c..feefcb15 100644 --- a/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptValidator.java +++ b/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptValidator.java @@ -277,15 +277,6 @@ public JS.JSMethodDeclaration visitJSMethodDeclaration(JS.JSMethodDeclaration jS return jSMethodDeclaration; } - @Override - public JS.JSMethodInvocation visitJSMethodInvocation(JS.JSMethodInvocation jSMethodInvocation, P p) { - visitAndValidate(jSMethodInvocation.getSelect(), Expression.class, p); - visitAndValidate(jSMethodInvocation.getTypeParameters(), Expression.class, p); - visitAndValidate(jSMethodInvocation.getName(), Expression.class, p); - visitAndValidate(jSMethodInvocation.getArguments(), Expression.class, p); - return jSMethodInvocation; - } - @Override public JS.JSForOfLoop visitJSForOfLoop(JS.JSForOfLoop jSForOfLoop, P p) { visitAndValidate(jSForOfLoop.getControl(), JS.JSForInOfLoopControl.class, p); diff --git a/rewrite-javascript/src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java b/rewrite-javascript/src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java index 220e942b..21010e71 100644 --- a/rewrite-javascript/src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java +++ b/rewrite-javascript/src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java @@ -701,42 +701,6 @@ public J visitJSMethodDeclaration(JS.JSMethodDeclaration method, P p) { return m; } - public J visitJSMethodInvocation(JS.JSMethodInvocation method, P p) { - JS.JSMethodInvocation m = method; - m = m.withPrefix(visitSpace(m.getPrefix(), Space.Location.METHOD_INVOCATION_PREFIX, p)); - m = m.withMarkers(visitMarkers(m.getMarkers(), p)); - Statement temp = (Statement) visitStatement(m, p); - if (!(temp instanceof J.MethodInvocation)) { - return temp; - } else { - m = (JS.JSMethodInvocation) temp; - } - Expression temp2 = (Expression) visitExpression(m, p); - if (!(temp2 instanceof JS.MethodInvocation)) { - return temp2; - } else { - m = (JS.JSMethodInvocation) temp2; - } - if (m.getPadding().getSelect() != null && m.getPadding().getSelect().getElement() instanceof NameTree && - method.getMethodType() != null && method.getMethodType().hasFlags(Flag.Static)) { - //noinspection unchecked - m = m.getPadding().withSelect( - (JRightPadded) (JRightPadded) - visitTypeName((JRightPadded) (JRightPadded) m.getPadding().getSelect(), p)); - } - if (m.getPadding().getSelect() != null) { - m = m.getPadding().withSelect(visitRightPadded(m.getPadding().getSelect(), JsRightPadded.Location.JSMETHOD_SELECT, p)); - } - if (m.getPadding().getTypeParameters() != null) { - m = m.getPadding().withTypeParameters(visitContainer(m.getPadding().getTypeParameters(), JsContainer.Location.JSTYPE_PARAMETERS, p)); - } - m = m.getPadding().withTypeParameters(visitTypeNames(m.getPadding().getTypeParameters(), p)); - m = m.withName(this.visitAndCast(m.getName(), p)); - m = m.getPadding().withArguments(visitContainer(m.getPadding().getArguments(), JsContainer.Location.JSMETHOD_INVOCATION_ARGUMENTS, p)); - m = m.withMethodType((JavaType.Method) visitType(m.getMethodType(), p)); - return m; - } - public J visitNamespaceDeclaration(JS.NamespaceDeclaration namespaceDeclaration, P p) { JS.NamespaceDeclaration ns = namespaceDeclaration; ns = ns.withPrefix(visitSpace(ns.getPrefix(), JsSpace.Location.NAMESPACE_DECLARATION_PREFIX, p)); diff --git a/rewrite-javascript/src/main/java/org/openrewrite/javascript/internal/JavaScriptPrinter.java b/rewrite-javascript/src/main/java/org/openrewrite/javascript/internal/JavaScriptPrinter.java index 9750e82c..1bf94615 100644 --- a/rewrite-javascript/src/main/java/org/openrewrite/javascript/internal/JavaScriptPrinter.java +++ b/rewrite-javascript/src/main/java/org/openrewrite/javascript/internal/JavaScriptPrinter.java @@ -611,17 +611,6 @@ public J visitJSMethodDeclaration(JS.JSMethodDeclaration method, PrintOutputCapt return method; } - @Override - public J visitJSMethodInvocation(JS.JSMethodInvocation method, PrintOutputCapture

p) { - beforeSyntax(method, Space.Location.METHOD_INVOCATION_PREFIX, p); - visitRightPadded(method.getPadding().getSelect(), JsRightPadded.Location.JSMETHOD_SELECT, p); - visit(method.getName(), p); - visitContainer("<", method.getPadding().getTypeParameters(), JsContainer.Location.JSMETHOD_DECLARATION_PARAMETERS, ",", ">", p); - visitContainer("(", method.getPadding().getArguments(), JsContainer.Location.JSMETHOD_INVOCATION_ARGUMENTS, ",", ")", p); - afterSyntax(method, p); - return method; - } - @Override public J visitFunctionDeclaration(JS.FunctionDeclaration functionDeclaration, PrintOutputCapture

p) { beforeSyntax(functionDeclaration, JsSpace.Location.FUNCTION_DECLARATION_PREFIX, p); diff --git a/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JS.java b/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JS.java index 0635409d..b0a92481 100644 --- a/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JS.java +++ b/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JS.java @@ -2683,158 +2683,6 @@ public JSMethodDeclaration withDefaultValue(@Nullable JLeftPadded de } } - @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) - @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) - @RequiredArgsConstructor - @AllArgsConstructor(access = AccessLevel.PRIVATE) - final class JSMethodInvocation implements JS, Statement, TypedTree, MethodCall { - - @Nullable - @NonFinal - transient WeakReference padding; - - @With - @EqualsAndHashCode.Include - @Getter - UUID id; - - @With - @Getter - Space prefix; - - @With - @Getter - Markers markers; - - /** - * Right padded before the '.' - */ - @Nullable - JRightPadded select; - - public @Nullable Expression getSelect() { - return select == null ? null : select.getElement(); - } - - public JSMethodInvocation withSelect(@Nullable Expression select) { - return getPadding().withSelect(JRightPadded.withElement(this.select, select)); - } - - @Nullable - @With - JContainer typeParameters; - - public @Nullable List getTypeParameters() { - return typeParameters == null ? null : typeParameters.getElements(); - } - - @With - @Getter - Expression name; - - JContainer arguments; - - @Override - public List getArguments() { - return arguments.getElements(); - } - - @Override - public JSMethodInvocation withArguments(List arguments) { - return getPadding().withArguments(JContainer.withElements(this.arguments, arguments)); - } - - @Getter - JavaType.@Nullable Method methodType; - - @Override - public JSMethodInvocation withMethodType(JavaType.@Nullable Method type) { - if (type == this.methodType) { - return this; - } - return new JSMethodInvocation(id, prefix, markers, select, typeParameters, name, arguments, type); - } - - @SuppressWarnings("unchecked") - @Override - public JSMethodInvocation withType(@Nullable JavaType type) { - throw new UnsupportedOperationException("To change the return type of this method invocation, use withMethodType(..)"); - } - - public JSMethodInvocation withDeclaringType(JavaType.FullyQualified type) { - if (this.methodType == null) { - return this; - } else { - return withMethodType(this.methodType.withDeclaringType(type)); - } - } - - @Override - public

J acceptJavaScript(JavaScriptVisitor

v, P p) { - return v.visitJSMethodInvocation(this, p); - } - - @Override - @Transient - public CoordinateBuilder.Statement getCoordinates() { - return new CoordinateBuilder.Statement(this); - } - - @Override - public JavaType getType() { - return methodType == null ? null : methodType.getReturnType(); - } - - public Padding getPadding() { - Padding p; - if (this.padding == null) { - p = new Padding(this); - this.padding = new WeakReference<>(p); - } else { - p = this.padding.get(); - if (p == null || p.t != this) { - p = new Padding(this); - this.padding = new WeakReference<>(p); - } - } - return p; - } - - @Override - public String toString() { - return withPrefix(Space.EMPTY).printTrimmed(new JavaPrinter<>()); - } - - @RequiredArgsConstructor - public static class Padding { - private final JSMethodInvocation t; - - public @Nullable JRightPadded getSelect() { - return t.select; - } - - public JSMethodInvocation withSelect(@Nullable JRightPadded select) { - return t.select == select ? t : new JSMethodInvocation(t.id, t.prefix, t.markers, select, t.typeParameters, t.name, t.arguments, t.methodType); - } - - public @Nullable JContainer getTypeParameters() { - return t.typeParameters; - } - - public JSMethodInvocation withTypeParameters(@Nullable JContainer typeParameters) { - return t.typeParameters == typeParameters ? t : new JSMethodInvocation(t.id, t.prefix, t.markers, t.select, typeParameters, t.name, t.arguments, t.methodType); - } - - public JContainer getArguments() { - return t.arguments; - } - - public JSMethodInvocation withArguments(JContainer arguments) { - return t.arguments == arguments ? t : new JSMethodInvocation(t.id, t.prefix, t.markers, t.select, t.typeParameters, t.name, arguments, t.methodType); - } - } - } - @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) @RequiredArgsConstructor diff --git a/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsContainer.java b/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsContainer.java index 77963099..97747607 100644 --- a/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsContainer.java +++ b/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsContainer.java @@ -27,8 +27,6 @@ public enum Location { IMPORT_ELEMENT(JsSpace.Location.IMPORT_ELEMENTS, JsRightPadded.Location.IMPORT_ELEMENT_SUFFIX), TUPLE_ELEMENT(JsSpace.Location.TUPLE_ELEMENT, JsRightPadded.Location.TUPLE_ELEMENT_SUFFIX), JSMETHOD_DECLARATION_PARAMETERS(JsSpace.Location.JSMETHOD_DECLARATION_PARAMETERS, JsRightPadded.Location.JSMETHOD_DECLARATION_PARAMETER), - JSTYPE_PARAMETERS(JsSpace.Location.JSTYPE_PARAMETERS, JsRightPadded.Location.JSTYPE_PARAMETER), - JSMETHOD_INVOCATION_ARGUMENTS(JsSpace.Location.JSTYPE_PARAMETERS, JsRightPadded.Location.JSTYPE_PARAMETER), TYPE_LITERAL_MEMBERS(JsSpace.Location.TYPE_LITERAL_MEMBERS_PREFIX, JsRightPadded.Location.TYPE_LITERAL_MEMBERS), INDEXED_SIGNATURE_DECLARATION_PARAMETERS(JsSpace.Location.INDEXED_SIGNATURE_DECLARATION_PARAMETERS_PREFIX, JsRightPadded.Location.INDEXED_SIGNATURE_DECLARATION_PARAMETERS), ARRAY_BINDING_PATTERN_ELEMENTS(JsSpace.Location.ARRAY_BINDING_PATTERN_ELEMENTS_PREFIX, JsRightPadded.Location.ARRAY_BINDING_PATTERN_ELEMENTS), diff --git a/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsRightPadded.java b/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsRightPadded.java index c78c622a..9c461ec9 100644 --- a/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsRightPadded.java +++ b/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsRightPadded.java @@ -37,8 +37,6 @@ public enum Location { JSNAMED_VARIABLE(JsSpace.Location.JSNAMED_VARIABLE_SUFFIX), NAMESPACE_DECLARATION_NAME(JsSpace.Location.NAMESPACE_DECLARATION_PREFIX), JSMETHOD_DECLARATION_PARAMETER(JsSpace.Location.JSMETHOD_DECLARATION_PARAMETERS), - JSMETHOD_SELECT(JsSpace.Location.JSMETHOD_SELECT_SUFFIX), - JSTYPE_PARAMETER(JsSpace.Location.JSTYPE_PARAMETER_SUFFIX), TYPE_LITERAL_MEMBERS(JsSpace.Location.TYPE_LITERAL_MEMBERS_SUFFIX), INDEXED_SIGNATURE_DECLARATION_PARAMETERS(JsSpace.Location.INDEXED_SIGNATURE_DECLARATION_PARAMETERS_SUFFIX), FOR_CONTROL_VAR(JsSpace.Location.FOR_INIT_SUFFIX), diff --git a/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsSpace.java b/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsSpace.java index f17868db..d421ee55 100644 --- a/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsSpace.java +++ b/rewrite-javascript/src/main/java/org/openrewrite/javascript/tree/JsSpace.java @@ -88,9 +88,6 @@ public enum Location { FUNCTION_DECLARATION_PREFIX, JS_IMPORT_SPECIFIER_PREFIX, JS_IMPORT_SPECIFIER_IMPORT_TYPE_PREFIX, - JSMETHOD_SELECT_SUFFIX, - JSTYPE_PARAMETERS, - JSTYPE_PARAMETER_SUFFIX, TYPE_LITERAL_PREFIX, TYPE_LITERAL_MEMBERS_PREFIX, TYPE_LITERAL_MEMBERS_SUFFIX,