From f5f51b310d6e4908fb0f507f6f205b859b358cb4 Mon Sep 17 00:00:00 2001 From: Oleh Dokuka Date: Tue, 10 Dec 2024 10:51:24 +0200 Subject: [PATCH] fix ParenthesizedTypeTree usage and replace it with TypeTreeExpression where needed --- openrewrite/jest.config.js | 2 +- openrewrite/src/javascript/parser.ts | 19 +- openrewrite/src/javascript/remote/receiver.ts | 19 +- openrewrite/src/javascript/remote/sender.ts | 10 +- .../src/javascript/tree/support_types.ts | 1 + openrewrite/src/javascript/tree/tree.ts | 64 + openrewrite/src/javascript/visitor.ts | 15 +- .../e2e/electron-server.files.test.ts | 724 +++++++++++ .../test/javascript/e2e/twenty.files.test.ts | 2 +- .../test/javascript/parser/binary.test.ts | 28 + .../test/javascript/parser/class.test.ts | 3 + .../javascript/remote/JavaScriptReceiver.java | 1148 ++++++++++------- .../javascript/remote/JavaScriptSender.java | 9 + .../remote/JavaScriptValidator.java | 358 ++--- .../javascript/JavaScriptVisitor.java | 24 +- .../internal/JavaScriptPrinter.java | 41 +- .../org/openrewrite/javascript/tree/JS.java | 41 + .../openrewrite/javascript/tree/JsSpace.java | 1 + 18 files changed, 1786 insertions(+), 723 deletions(-) create mode 100644 openrewrite/test/javascript/e2e/electron-server.files.test.ts diff --git a/openrewrite/jest.config.js b/openrewrite/jest.config.js index 1d4e73ba..bd12b948 100644 --- a/openrewrite/jest.config.js +++ b/openrewrite/jest.config.js @@ -15,4 +15,4 @@ module.exports = { }, testMatch: ['**/__tests__/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'], collectCoverageFrom: ['src/**/*.{ts,tsx}', '!src/**/*.d.ts'], -}; \ No newline at end of file +}; diff --git a/openrewrite/src/javascript/parser.ts b/openrewrite/src/javascript/parser.ts index 999c3948..3b2841f1 100644 --- a/openrewrite/src/javascript/parser.ts +++ b/openrewrite/src/javascript/parser.ts @@ -26,7 +26,7 @@ import { import {binarySearch, compareTextSpans, getNextSibling, getPreviousSibling, TextSpan} from "./parserUtils"; import {JavaScriptTypeMapping} from "./typeMapping"; import path from "node:path"; -import {ExpressionStatement} from "."; +import {ExpressionStatement, TypeTreeExpression} from "."; export class JavaScriptParser extends Parser { @@ -440,7 +440,8 @@ export class JavaScriptParserVisitor { } for (let heritageClause of node.heritageClauses) { if (heritageClause.token == ts.SyntaxKind.ExtendsKeyword) { - return this.leftPadded(this.prefix(heritageClause.getFirstToken()!), this.visit(heritageClause.types[0])); + const typeTreeExpression = this.visit(heritageClause.types[0]); + return this.leftPadded(this.prefix(heritageClause.getFirstToken()!), new TypeTreeExpression(randomId(), Space.EMPTY, Markers.EMPTY, typeTreeExpression)); } } return null; @@ -1810,18 +1811,12 @@ export class JavaScriptParserVisitor { } visitParenthesizedExpression(node: ts.ParenthesizedExpression) { - return new J.ParenthesizedTypeTree( + return new J.Parentheses( randomId(), - Space.EMPTY, + this.prefix(node), Markers.EMPTY, - [], - new J.Parentheses( - randomId(), - this.prefix(node), - Markers.EMPTY, - this.rightPadded(this.convert(node.expression), this.prefix(node.getLastToken()!)) - ) - ); + this.rightPadded(this.convert(node.expression), this.prefix(node.getLastToken()!)) + ) } visitFunctionExpression(node: ts.FunctionExpression) { diff --git a/openrewrite/src/javascript/remote/receiver.ts b/openrewrite/src/javascript/remote/receiver.ts index 1df16aa2..f2f0cd54 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, ConditionalType, DefaultType, Delete, Export, ExpressionStatement, ExpressionWithTypeArguments, FunctionType, InferType, ImportType, JsImport, JsImportSpecifier, JsBinary, LiteralType, ObjectBindingDeclarations, PropertyAssignment, SatisfiesExpression, ScopedVariableDeclarations, StatementExpression, TaggedTemplateExpression, TemplateExpression, Tuple, TypeDeclaration, TypeOf, TypeQuery, TypeOperator, TypePredicate, Unary, Union, Intersection, Void, Yield, TypeInfo, JSVariableDeclarations, JSMethodDeclaration, JSForOfLoop, JSForInLoop, JSForInOfLoopControl, NamespaceDeclaration, FunctionDeclaration, TypeLiteral, IndexSignatureDeclaration, ArrayBindingPattern, BindingElement, ExportDeclaration, ExportAssignment, NamedExports, ExportSpecifier, IndexedAccessType, JsAssignmentOperation} from '../tree'; +import {JS, JsLeftPadded, JsRightPadded, JsContainer, JsSpace, CompilationUnit, Alias, ArrowFunction, Await, ConditionalType, DefaultType, Delete, Export, ExpressionStatement, ExpressionWithTypeArguments, FunctionType, InferType, ImportType, JsImport, JsImportSpecifier, JsBinary, LiteralType, ObjectBindingDeclarations, PropertyAssignment, SatisfiesExpression, ScopedVariableDeclarations, StatementExpression, TaggedTemplateExpression, TemplateExpression, Tuple, TypeDeclaration, TypeOf, TypeQuery, TypeOperator, TypePredicate, Unary, Union, Intersection, Void, Yield, TypeInfo, JSVariableDeclarations, JSMethodDeclaration, JSForOfLoop, JSForInLoop, JSForInOfLoopControl, NamespaceDeclaration, FunctionDeclaration, TypeLiteral, IndexSignatureDeclaration, ArrayBindingPattern, BindingElement, ExportDeclaration, ExportAssignment, NamedExports, ExportSpecifier, IndexedAccessType, JsAssignmentOperation, TypeTreeExpression} from '../tree'; import {Expression, J, JContainer, JLeftPadded, JRightPadded, NameTree, Space, Statement, TypeTree, TypedTree} from "../../java"; import * as Java from "../../java/tree"; @@ -603,6 +603,14 @@ class Visitor extends JavaScriptVisitor { return jsAssignmentOperation; } + public visitTypeTreeExpression(typeTreeExpression: TypeTreeExpression, ctx: ReceiverContext): J { + typeTreeExpression = typeTreeExpression.withId(ctx.receiveValue(typeTreeExpression.id, ValueType.UUID)!); + typeTreeExpression = typeTreeExpression.withPrefix(ctx.receiveNode(typeTreeExpression.prefix, receiveSpace)!); + typeTreeExpression = typeTreeExpression.withMarkers(ctx.receiveNode(typeTreeExpression.markers, ctx.receiveMarkers)!); + typeTreeExpression = typeTreeExpression.withExpression(ctx.receiveNode(typeTreeExpression.expression, ctx.receiveTree)!); + return typeTreeExpression; + } + public visitAnnotatedType(annotatedType: Java.AnnotatedType, ctx: ReceiverContext): J { annotatedType = annotatedType.withId(ctx.receiveValue(annotatedType.id, ValueType.UUID)!); annotatedType = annotatedType.withPrefix(ctx.receiveNode(annotatedType.prefix, receiveSpace)!); @@ -1905,6 +1913,15 @@ class Factory implements ReceiverFactory { ); } + if (type === "org.openrewrite.javascript.tree.JS$TypeTreeExpression") { + return new TypeTreeExpression( + ctx.receiveValue(null, ValueType.UUID)!, + ctx.receiveNode(null, receiveSpace)!, + ctx.receiveNode(null, ctx.receiveMarkers)!, + ctx.receiveNode(null, ctx.receiveTree)! + ); + } + if (type === "org.openrewrite.java.tree.J$AnnotatedType") { return new Java.AnnotatedType( ctx.receiveValue(null, ValueType.UUID)!, diff --git a/openrewrite/src/javascript/remote/sender.ts b/openrewrite/src/javascript/remote/sender.ts index 504d4a47..7503117c 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, ConditionalType, DefaultType, Delete, Export, ExpressionStatement, ExpressionWithTypeArguments, FunctionType, InferType, ImportType, JsImport, JsImportSpecifier, JsBinary, LiteralType, ObjectBindingDeclarations, PropertyAssignment, SatisfiesExpression, ScopedVariableDeclarations, StatementExpression, TaggedTemplateExpression, TemplateExpression, Tuple, TypeDeclaration, TypeOf, TypeQuery, TypeOperator, TypePredicate, Unary, Union, Intersection, Void, Yield, TypeInfo, JSVariableDeclarations, JSMethodDeclaration, JSForOfLoop, JSForInLoop, JSForInOfLoopControl, NamespaceDeclaration, FunctionDeclaration, TypeLiteral, IndexSignatureDeclaration, ArrayBindingPattern, BindingElement, ExportDeclaration, ExportAssignment, NamedExports, ExportSpecifier, IndexedAccessType, JsAssignmentOperation} from '../tree'; +import {JS, JsLeftPadded, JsRightPadded, JsContainer, JsSpace, CompilationUnit, Alias, ArrowFunction, Await, ConditionalType, DefaultType, Delete, Export, ExpressionStatement, ExpressionWithTypeArguments, FunctionType, InferType, ImportType, JsImport, JsImportSpecifier, JsBinary, LiteralType, ObjectBindingDeclarations, PropertyAssignment, SatisfiesExpression, ScopedVariableDeclarations, StatementExpression, TaggedTemplateExpression, TemplateExpression, Tuple, TypeDeclaration, TypeOf, TypeQuery, TypeOperator, TypePredicate, Unary, Union, Intersection, Void, Yield, TypeInfo, JSVariableDeclarations, JSMethodDeclaration, JSForOfLoop, JSForInLoop, JSForInOfLoopControl, NamespaceDeclaration, FunctionDeclaration, TypeLiteral, IndexSignatureDeclaration, ArrayBindingPattern, BindingElement, ExportDeclaration, ExportAssignment, NamedExports, ExportSpecifier, IndexedAccessType, JsAssignmentOperation, TypeTreeExpression} from '../tree'; import {Expression, J, JContainer, JLeftPadded, JRightPadded, Space, Statement} from "../../java"; import * as Java from "../../java/tree"; @@ -598,6 +598,14 @@ class Visitor extends JavaScriptVisitor { return jsAssignmentOperation; } + public visitTypeTreeExpression(typeTreeExpression: TypeTreeExpression, ctx: SenderContext): J { + ctx.sendValue(typeTreeExpression, v => v.id, ValueType.UUID); + ctx.sendNode(typeTreeExpression, v => v.prefix, Visitor.sendSpace); + ctx.sendNode(typeTreeExpression, v => v.markers, ctx.sendMarkers); + ctx.sendNode(typeTreeExpression, v => v.expression, ctx.sendTree); + return typeTreeExpression; + } + public visitAnnotatedType(annotatedType: Java.AnnotatedType, ctx: SenderContext): J { ctx.sendValue(annotatedType, v => v.id, ValueType.UUID); ctx.sendNode(annotatedType, v => v.prefix, Visitor.sendSpace); diff --git a/openrewrite/src/javascript/tree/support_types.ts b/openrewrite/src/javascript/tree/support_types.ts index 741cc6e7..b3043356 100644 --- a/openrewrite/src/javascript/tree/support_types.ts +++ b/openrewrite/src/javascript/tree/support_types.ts @@ -256,6 +256,7 @@ export namespace JsSpace { INDEXED_ACCESS_TYPE_INDEX_TYPE_SUFFIX, INDEXED_ACCESS_TYPE_INDEX_TYPE_ELEMENT_SUFFIX, JS_ASSIGNMENT_OPERATION_PREFIX, + TYPE_TREE_EXPRESSION_PREFIX, } } export namespace JsLeftPadded { diff --git a/openrewrite/src/javascript/tree/tree.ts b/openrewrite/src/javascript/tree/tree.ts index 5e0fa33a..d2945a71 100644 --- a/openrewrite/src/javascript/tree/tree.ts +++ b/openrewrite/src/javascript/tree/tree.ts @@ -5286,3 +5286,67 @@ export namespace JsAssignmentOperation { } } + +@LstType("org.openrewrite.javascript.tree.JS$TypeTreeExpression") +export class TypeTreeExpression extends JSMixin(Object) implements Expression, TypeTree { + public constructor(id: UUID, prefix: Space, markers: Markers, expression: Expression) { + super(); + this._id = id; + this._prefix = prefix; + this._markers = markers; + this._expression = expression; + } + + private readonly _id: UUID; + + public get id(): UUID { + return this._id; + } + + public withId(id: UUID): TypeTreeExpression { + return id === this._id ? this : new TypeTreeExpression(id, this._prefix, this._markers, this._expression); + } + + private readonly _prefix: Space; + + public get prefix(): Space { + return this._prefix; + } + + public withPrefix(prefix: Space): TypeTreeExpression { + return prefix === this._prefix ? this : new TypeTreeExpression(this._id, prefix, this._markers, this._expression); + } + + private readonly _markers: Markers; + + public get markers(): Markers { + return this._markers; + } + + public withMarkers(markers: Markers): TypeTreeExpression { + return markers === this._markers ? this : new TypeTreeExpression(this._id, this._prefix, markers, this._expression); + } + + private readonly _expression: Expression; + + public get expression(): Expression { + return this._expression; + } + + public withExpression(expression: Expression): TypeTreeExpression { + return expression === this._expression ? this : new TypeTreeExpression(this._id, this._prefix, this._markers, expression); + } + + public acceptJavaScript

(v: JavaScriptVisitor

, p: P): J | null { + return v.visitTypeTreeExpression(this, p); + } + + public get type(): JavaType | null { + return extensions.getJavaType(this); + } + + public withType(type: JavaType): TypeTreeExpression { + return extensions.withJavaType(this, type); + } + +} diff --git a/openrewrite/src/javascript/visitor.ts b/openrewrite/src/javascript/visitor.ts index afc0cf31..1459bad7 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, ConditionalType, DefaultType, Delete, Export, ExpressionStatement, ExpressionWithTypeArguments, FunctionType, InferType, ImportType, JsImport, JsImportSpecifier, JsBinary, LiteralType, ObjectBindingDeclarations, PropertyAssignment, SatisfiesExpression, ScopedVariableDeclarations, StatementExpression, TaggedTemplateExpression, TemplateExpression, Tuple, TypeDeclaration, TypeOf, TypeQuery, TypeOperator, TypePredicate, Unary, Union, Intersection, Void, Yield, TypeInfo, JSVariableDeclarations, JSMethodDeclaration, JSForOfLoop, JSForInLoop, JSForInOfLoopControl, NamespaceDeclaration, FunctionDeclaration, TypeLiteral, IndexSignatureDeclaration, ArrayBindingPattern, BindingElement, ExportDeclaration, ExportAssignment, NamedExports, ExportSpecifier, IndexedAccessType, JsAssignmentOperation} from "./tree"; +import {CompilationUnit, Alias, ArrowFunction, Await, ConditionalType, DefaultType, Delete, Export, ExpressionStatement, ExpressionWithTypeArguments, FunctionType, InferType, ImportType, JsImport, JsImportSpecifier, JsBinary, LiteralType, ObjectBindingDeclarations, PropertyAssignment, SatisfiesExpression, ScopedVariableDeclarations, StatementExpression, TaggedTemplateExpression, TemplateExpression, Tuple, TypeDeclaration, TypeOf, TypeQuery, TypeOperator, TypePredicate, Unary, Union, Intersection, Void, Yield, TypeInfo, JSVariableDeclarations, JSMethodDeclaration, JSForOfLoop, JSForInLoop, JSForInOfLoopControl, NamespaceDeclaration, FunctionDeclaration, TypeLiteral, IndexSignatureDeclaration, ArrayBindingPattern, BindingElement, ExportDeclaration, ExportAssignment, NamedExports, ExportSpecifier, IndexedAccessType, JsAssignmentOperation, TypeTreeExpression} from "./tree"; import {Expression, J, JContainer, JLeftPadded, JRightPadded, Space, Statement} from "../java/tree"; import {JavaVisitor} from "../java"; import * as Java from "../java/tree"; @@ -842,6 +842,19 @@ export class JavaScriptVisitor

extends JavaVisitor

{ return jsAssignmentOperation; } + public visitTypeTreeExpression(typeTreeExpression: TypeTreeExpression, p: P): J | null { + typeTreeExpression = typeTreeExpression.withPrefix(this.visitJsSpace(typeTreeExpression.prefix, JsSpace.Location.TYPE_TREE_EXPRESSION_PREFIX, p)!); + let tempExpression = this.visitExpression(typeTreeExpression, p) as Expression; + if (!(tempExpression instanceof TypeTreeExpression)) + { + return tempExpression; + } + typeTreeExpression = tempExpression as TypeTreeExpression; + typeTreeExpression = typeTreeExpression.withMarkers(this.visitMarkers(typeTreeExpression.markers, p)); + typeTreeExpression = typeTreeExpression.withExpression(this.visitAndCast(typeTreeExpression.expression, p)!); + return typeTreeExpression; + } + public visitJsLeftPadded(left: JLeftPadded | null, loc: JsLeftPadded.Location, p: P): JLeftPadded { return extensions.visitJsLeftPadded(this, left, loc, p); } diff --git a/openrewrite/test/javascript/e2e/electron-server.files.test.ts b/openrewrite/test/javascript/e2e/electron-server.files.test.ts new file mode 100644 index 00000000..d1a12fb9 --- /dev/null +++ b/openrewrite/test/javascript/e2e/electron-server.files.test.ts @@ -0,0 +1,724 @@ +import {connect, disconnect, rewriteRun, rewriteRunWithOptions, typeScript} from '../testHarness'; +import url from "url"; + +describe('electron-release-server files tests', () => { + beforeAll(() => connect()); + afterAll(() => disconnect()); + + test('api/controllers/VersionController.js', () => { + rewriteRun( + //language=typescript + typeScript(` + /** + * VersionController + * + * @description :: Server-side logic for handling version requests + * @help :: See http://sailsjs.org/#!/documentation/concepts/Controllers + */ + + var actionUtil = require('sails/lib/hooks/blueprints/actionUtil'); + var url = require('url'); + var Promise = require('bluebird'); + var semver = require('semver'); + var compareVersions = require('compare-versions'); + + const availabilityFilter = () => ({'<=': (new Date()).toISOString()}); + + module.exports = { + + /** + * Set availability date of specified version + * + * (PUT /version/availability/:version/:timestamp) + */ + availability: (req, res) => { + const {version, timestamp} = req.params; + + if (!version) return res.badRequest('Requires \`version\` parameter'); + if (!timestamp) return res.badRequest('Requires \`timestamp\` parameter'); + + const availability = new Date(parseInt(timestamp, 10)); + + if (isNaN(availability) || availability.getTime().toString() !== timestamp) { + return res.badRequest('Parameter \`timestamp\` must be a valid unix timestamp in milliseconds'); + } + + Version + .findOne(version) + .then(foundVersion => { + if (!foundVersion) return res.notFound('The specified \`version\` does not exist'); + + if (availability < new Date(foundVersion.createdAt)) { + return res.badRequest( + 'Parameter \`timestamp\` must be greater than or equal to the version creation date' + ); + } + + return Version + .update(version, {availability}) + .then(([updatedVersion]) => { + Version.publish([version.id], { + verb: 'updated', + id: version.id, + data: updatedVersion, + previous: version + }, req); + + res.send(updatedVersion); + }); + }) + .catch(res.negotiate); + }, + + /** + * Redirect the update request to the appropriate endpoint + * (GET /update) + */ + redirect: function (req, res) { + var platform = req.param('platform'); + var version = req.param('version'); + + if (!version) { + return res.badRequest('Requires "version" parameter'); + } + if (!platform) { + return res.badRequest('Requires "platform" parameter'); + } + + return res.redirect('/update/' + platform + '/' + version); + }, + + /** + * Sorts versions and returns pages of them sorted by sermver + * + * ( GET /versions/sorted ) + */ + list: function (req, res) { + Version + .find() + .then(versions => { + var count = versions.length; + var page = req.param('page') || req.query.page || 0; + var start = page * sails.config.views.pageSize; + var end = start + sails.config.views.pageSize; + var items = versions + .sort(function (a, b) { + return -compareVersions(a.name, b.name); + }) + .slice(start, end); + + const response = { + total: count, + offset: start, + page: page, + items: items + } + + return Promise.all([ + // load channels + new Promise(function (resolve, reject) { + Promise.all(items.map(function (version) { + return Channel.findOne({ + name: version.channel + }) + })) + .then(resolve) + .catch(reject) + }), + // load assets + new Promise(function (resolve, reject) { + Promise.all(items.map(function (version) { + return Asset.find({ + version: version.id + }) + })) + .then(resolve) + .catch(reject) + }), + // load flavors + new Promise((resolve, reject) => Promise + .map(items, version => Flavor.findOne(version.flavor)) + .then(resolve) + .catch(reject) + ) + ]) + .then(function (results) { + response.items = response.items.map(function (item, index) { + return { + id: item.id, + channel: results[0][index], + assets: results[1][index].map(function (asset) { + return { + id: asset.id, + name: asset.name, + platform: asset.platform, + filetype: asset.filetype, + hash: asset.hash, + size: asset.size, + download_count: asset.download_count, + fd: asset.fd, + createdAt: asset.createdAt, + updatedAt: asset.updatedAt + } + }), + flavor: results[2][index], + name: item.name, + notes: item.notes, + createdAt: item.createdAt, + updatedAt: item.updatedAt, + availability: item.availability + } + }) + + return response + }) + }) + .then(response => { + res.send(response); + }) + .catch(res.negotiate); + }, + + /** + * Serves auto-updates: Status and Squirrel.Mac + * + * Assumes stable channel & default flavor unless specified + * + * (GET /update/:platform/:version/:channel) + * (GET /update/flavor/:flavor/:platform/:version/:channel?) + */ + general: function (req, res) { + var platform = req.param('platform'); + var version = req.param('version'); + var channel = req.param('channel') || 'stable'; + const flavor = req.params.flavor || 'default'; + + if (!version) { + return res.badRequest('Requires \`version\` parameter'); + } + + if (!platform) { + return res.badRequest('Requires \`platform\` parameter'); + } + + var platforms = PlatformService.detect(platform, true); + + sails.log.debug('Update Search Query', { + platform: platforms, + version: version, + channel: channel, + flavor + }); + + // Get specified version object, it's time will be used for the general + // cutoff. + Version + .findOne({ + name: version, + flavor + }) + .then(function (currentVersion) { + + var applicableChannels, createdAtFilter; + + applicableChannels = ChannelService.getApplicableChannels(channel); + sails.log.debug('Applicable Channels', applicableChannels); + + if (currentVersion) { + createdAtFilter = { + '>': currentVersion.createdAt + }; + } else { + sails.log.debug('The specified \`version\` does not exist'); + } + + sails.log.debug('Time Filter', createdAtFilter); + + return Version + .find(UtilityService.getTruthyObject({ + channel: applicableChannels, + createdAt: createdAtFilter, + availability: availabilityFilter(), + flavor + })) + .populate('assets', { + platform: platforms + }) + .then(function (newerVersions) { + // Sort versions which were added after the current one by semver in + // descending order. + newerVersions.sort(UtilityService.compareVersion); + + var latestVersion; + sails.log.debug('Newer Versions', newerVersions); + + // Generate the combined release notes for the newer versions while simultaneously filtering out + // inapplicable versions and finding the latest version. + var releaseNotes = _.reduce( + newerVersions, + function (prevNotes, newVersion) { + // Filter out assets that are not zip files since we only + // support zip files for auto-updates. + newVersion.assets = _.filter(newVersion.assets, function (asset) { + return asset.filetype === '.zip'; + }); + + // If one of the assets for this verison apply to our desired + // platform then we will skip this version + if (!newVersion.assets.length) { + return prevNotes; + } + + // If this is the first version we've found that is newer than + // the current version, then we will use it as the latest. + if (!latestVersion && semver.lt(version, newVersion.name)) { + latestVersion = newVersion; + } + + // Skip if no notes available for this version + if (!newVersion.notes || !newVersion.notes.length) { + return prevNotes; + } + + // If not the first changenote, prefix with new line + var newChangeNote = !prevNotes.length ? '' : ' + '; + + // Add the version name and notes + newChangeNote += '## ' + newVersion.name + ' + ' + newVersion.notes; + + // Add the new changenote to the previous ones + return prevNotes + newChangeNote; + }, + ''); + + var currentVersionName = _.get(currentVersion, 'name'); + + sails.log.debug('Version candidate', latestVersion); + sails.log.debug('Current version', currentVersionName); + + if (!latestVersion || latestVersion.name === currentVersionName) { + sails.log.debug('Version candidate denied'); + return res.status(204).send('No updates.'); + } + + sails.log.debug('Version candidate accepted'); + + return res.ok({ + url: url.resolve( + sails.config.appUrl, + \`/download/flavor/\${flavor}/\${latestVersion.name}/\` + + latestVersion.assets[0].platform + '?filetype=zip' + ), + name: latestVersion.name, + notes: releaseNotes, + pub_date: new Date(latestVersion.availability).toISOString() + }); + }); + }) + .catch(res.negotiate); + }, + + /** + * Serves auto-updates: Squirrel.Windows: serve RELEASES from latest version + * Currently, it will only serve a full.nupkg of the latest release with a + * normalized filename (for pre-release) + * + * (GET /update/:platform/:version/:channel/RELEASES) + * (GET /update/flavor/:flavor/:platform/:version/:channel/RELEASES) + */ + windows: function (req, res) { + var platform = req.param('platform'); + var version = req.param('version'); + var channel = req.param('channel') || 'stable'; + const flavor = req.params.flavor || 'default'; + + if (!version) { + return res.badRequest('Requires \`version\` parameter'); + } + + if (!platform) { + return res.badRequest('Requires \`platform\` parameter'); + } + + var platforms = PlatformService.detect(platform, true); + + sails.log.debug('Windows Update Search Query', { + platform: platforms, + version: version, + channel: channel, + flavor + }); + + // Get specified version object, it's time will be used for the general + // cutoff. + Version + .findOne({ + name: version, + flavor + }) + .then(function (currentVersion) { + var applicableChannels, createdAtFilter; + + applicableChannels = ChannelService.getApplicableChannels(channel); + sails.log.debug('Applicable Channels', applicableChannels); + + if (currentVersion) { + createdAtFilter = { + '>=': currentVersion.createdAt + }; + } else { + sails.log.debug('The specified \`version\` does not exist'); + } + + sails.log.debug('Time Filter', createdAtFilter); + + return Version + .find(UtilityService.getTruthyObject({ + channel: applicableChannels, + createdAt: createdAtFilter, + availability: availabilityFilter(), + flavor + })) + .populate('assets', { + platform: platforms + }) + .then(function (newerVersions) { + // Sort versions which were added after the current one by semver in + // descending order. + newerVersions.sort(UtilityService.compareVersion); + + var latestVersion = _.find( + newerVersions, + function (newVersion) { + _.remove(newVersion.assets, function (o) { + return o.filetype !== '.nupkg' || !o.hash; + }); + + // Make sure the last version is a version with full asset + // so RELEASES contains at least one full asset (which is mandatory for Squirrel.Windows) + let v = _.filter( + newVersion.assets, + function (o) { + return _.includes(o.name.toLowerCase(), '-full'); + } + ); + return v.length && semver.lte( + version, newVersion.name + ); + }); + + if (!latestVersion) { + sails.log.debug('Version not found'); + return res.status(500).send('Version not found'); + } + + // Add Delta assets from other versions + var deltaAssets = _.reduce( + newerVersions, + function (assets, newVersion) { + return assets.concat( + _.filter( + newVersion.assets, + function (asset) { + return asset.filetype === '.nupkg' + && _.includes(asset.name.toLowerCase(), '-delta') + && semver.lte(version, newVersion.name) + && semver.gt(latestVersion.name, newVersion.name); + })); + }, []); + + Array.prototype.unshift.apply(latestVersion.assets, deltaAssets); + + sails.log.debug('Latest Windows Version', latestVersion); + + // Change asset name to use full download link + const assets = _.map(latestVersion.assets, function (asset) { + asset.name = url.resolve( + sails.config.appUrl, + \`/download/flavor/\${flavor}/\${latestVersion.name}/\${asset.platform}/\` + + asset.name + ); + + return asset; + }); + + var output = WindowsReleaseService.generate(assets); + + res.header('Content-Length', output.length); + res.attachment('RELEASES'); + return res.send(output); + }); + }) + .catch(res.negotiate); + }, + + /** + * Get electron-updater win yml for a specific channel + * (GET /update/:platform/latest.yml) + * (GET /update/:platform/:channel.yml) + * (GET /update/:platform/:channel/latest.yml) + * (GET /update/flavor/:flavor/:platform/latest.yml) + * (GET /update/flavor/:flavor/:platform/:channel.yml) + * (GET /update/flavor/:flavor/:platform/:channel/latest.yml) + */ + electronUpdaterWin: function (req, res) { + var platform = req.param('platform'); + var channel = req.param('channel') || 'stable'; + const flavor = req.params.flavor || 'default'; + + if (!platform) { + return res.badRequest('Requires \`platform\` parameter'); + } + + var platforms = PlatformService.detect(platform, true); + + sails.log.debug('NSIS electron-updater Search Query', { + platform: platforms, + channel: channel, + flavor + }); + + var applicableChannels = ChannelService.getApplicableChannels(channel); + sails.log.debug('Applicable Channels', applicableChannels); + + // Get latest version that has a windows asset + Version + .find({ + channel: applicableChannels, + availability: availabilityFilter(), + flavor + }) + .populate('assets') + .then(function (versions) { + // TODO: Implement method to get latest version with available asset + var sortedVersions = versions.sort(UtilityService.compareVersion); + var latestVersion = null; + var asset = null; + for (var i = 0; i < sortedVersions.length; i++) { + var currentVersion = sortedVersions[i]; + if (currentVersion.assets) { + for (var j = 0; j < currentVersion.assets.length; j++) { + var currentAsset = currentVersion.assets[j]; + // Find the first asset that is a exe file and matches the desired platform. + // Note that only exe files are supported for win autoupdates through this API (not nupkg). + // Nupkg files are supported through the Squirrel.Windows API. + if (currentAsset.filetype === '.exe' && _.includes(platforms, currentAsset.platform)) { + latestVersion = currentVersion; + asset = currentAsset; + break; + } + } + + if (latestVersion) { + break; + } + } + } + + if (latestVersion) { + var downloadPath = url.resolve( + "", + \`/download/flavor/\${flavor}/\${latestVersion.name}/\${asset.platform}/\` + + asset.name + ); + + const sha512 = asset.hash ? asset.hash : null; + + var latestYml = "version: " + latestVersion.name + + "\\nfiles:" + + "\\n - url: " + downloadPath + + "\\n sha512: " + sha512 + + "\\n size: " + asset.size + + "\\nreleaseDate: " + latestVersion.updatedAt + + "\\npath: " + downloadPath + + "\\nsha512: " + sha512 + + "\\nsize: " + asset.size; + + res.send(latestYml); + } else { + res.notFound(); + } + }); + }, + + /** + * Get electron-updater mac yml for a specific channel + * (GET /update/:platform/latest-mac.yml) + * (GET /update/:platform/:channel-mac.yml) + * (GET /update/:platform/:channel/latest-mac.yml) + * (GET /update/flavor/:flavor/:platform/latest-mac.yml) + * (GET /update/flavor/:flavor/:platform/:channel-mac.yml) + * (GET /update/flavor/:flavor/:platform/:channel/latest-mac.yml) + */ + electronUpdaterMac: function (req, res) { + var platform = req.param('platform'); + var channel = req.param('channel') || 'stable'; + const flavor = req.params.flavor || 'default'; + + if (!platform) { + return res.badRequest('Requires \`platform\` parameter'); + } + + var platforms = PlatformService.detect(platform, true); + + sails.log.debug('Mac electron-updater Search Query', { + platform: platforms, + channel: channel, + flavor + }); + + var applicableChannels = ChannelService.getApplicableChannels(channel); + sails.log.debug('Applicable Channels', applicableChannels); + + // Get latest version that has a mac asset + Version + .find({ + channel: applicableChannels, + availability: availabilityFilter(), + flavor + }) + .populate('assets') + .then(function (versions) { + // TODO: Implement method to get latest version with available asset + var sortedVersions = versions.sort(UtilityService.compareVersion); + var latestVersion = null; + var asset = null; + for (var i = 0; i < sortedVersions.length; i++) { + var currentVersion = sortedVersions[i]; + if (currentVersion.assets) { + for (var j = 0; j < currentVersion.assets.length; j++) { + var currentAsset = currentVersion.assets[j]; + // Find the first asset that is a zip file and matches the desired platform. + // Note that only zip files are supported for mac autoupdates. + if (currentAsset.filetype === '.zip' && _.includes(platforms, currentAsset.platform)) { + latestVersion = currentVersion; + asset = currentAsset; + break; + } + } + + if (latestVersion) { + break; + } + } + } + + if (latestVersion) { + var downloadPath = url.resolve( + "", + \`/download/flavor/\${flavor}/\${latestVersion.name}/\${asset.platform}/\` + + asset.name + ); + + const sha512 = asset.hash ? asset.hash : null; + + var latestYml = "version: " + latestVersion.name + + "\\nfiles:" + + "\\n - url: " + downloadPath + + "\\n sha512: " + sha512 + + "\\n size: " + asset.size + + "\\nreleaseDate: " + latestVersion.updatedAt + + "\\npath: " + downloadPath + + "\\nsha512: " + sha512 + + "\\nsize: " + asset.size; + res.send(latestYml); + } else { + res.notFound(); + } + }); + }, + + /** + * Get release notes for a specific version + * (GET /notes/:version/:flavor?) + */ + releaseNotes: function (req, res) { + var version = req.params.version; + const flavor = req.params.flavor || 'default'; + + Version + .findOne({ + name: version, + availability: availabilityFilter(), + flavor + }) + .then(function (currentVersion) { + if (!currentVersion) { + return res.notFound('The specified version does not exist'); + } + + return res.format({ + 'application/json': function () { + res.send({ + 'notes': currentVersion.notes, + 'pub_date': new Date(currentVersion.availability).toISOString() + }); + }, + 'default': function () { + res.send(currentVersion.notes); + } + }); + }) + .catch(res.negotiate); + }, + + /** + * Overloaded blueprint function + * Changes: + * - Delete all associated assets & their files + */ + destroy: function (req, res) { + var pk = actionUtil.requirePk(req); + + var query = Version.findOne(pk); + query.populate('assets'); + query.exec(function foundRecord(err, record) { + if (err) return res.serverError(err); + if (!record) return res.notFound( + 'No record found with the specified \`name\`.' + ); + + var deletePromises = _.map(record.assets, function (asset) { + return Promise.join( + AssetService.destroy(asset, req), + AssetService.deleteFile(asset), + function () { + sails.log.info('Destroyed asset: ', asset); + }); + }); + + Promise.all(deletePromises) + .then(function allDeleted() { + return Version.destroy(pk) + .then(function destroyedRecord() { + + if (sails.hooks.pubsub) { + Version.publish( + [pk], { + verb: 'destroyed', + previous: record + }, !req._sails.config.blueprints.mirror && req + ); + + if (req.isSocket) { + Version.unsubscribe(req, record); + Version.retire(record); + } + } + + sails.log.info('Destroyed version: ', record); + + return res.ok(record); + }); + }) + .error(res.negotiate); + }); + } + }; + + `) + ); + }); +}); diff --git a/openrewrite/test/javascript/e2e/twenty.files.test.ts b/openrewrite/test/javascript/e2e/twenty.files.test.ts index a74f2bbf..d15a9358 100644 --- a/openrewrite/test/javascript/e2e/twenty.files.test.ts +++ b/openrewrite/test/javascript/e2e/twenty.files.test.ts @@ -1,6 +1,6 @@ import {connect, disconnect, rewriteRun, rewriteRunWithOptions, typeScript} from '../testHarness'; -describe('highlight.js files tests', () => { +describe('twentyhq/twenty files tests', () => { beforeAll(() => connect()); afterAll(() => disconnect()); diff --git a/openrewrite/test/javascript/parser/binary.test.ts b/openrewrite/test/javascript/parser/binary.test.ts index f77068ea..ce5e50ce 100644 --- a/openrewrite/test/javascript/parser/binary.test.ts +++ b/openrewrite/test/javascript/parser/binary.test.ts @@ -229,3 +229,31 @@ describe('comma operator mapping', () => { ); }); }); + + +describe('generic binary tests', () => { + beforeAll(() => connect()); + afterAll(() => disconnect()); + + test('multiple cases', () => { + rewriteRun( + //language=typescript + typeScript(` + var _ = {} as any; + var PRERELEASE_CHANNEL_MAGINITUDE = 1000; + var PRERELEASE_CHANNELS = (({} as any).availableChannels) + .without('stable') + .reverse() + .value(); + + function hashPrerelease(s) { + if (_.isString(s[0])) { + return (_.indexOf(PRERELEASE_CHANNELS, s[0]) + 1) * PRERELEASE_CHANNEL_MAGINITUDE + (s[1] || 0); + } else { + return s[0]; + } + } + `) + ); + }) +}); diff --git a/openrewrite/test/javascript/parser/class.test.ts b/openrewrite/test/javascript/parser/class.test.ts index 90940704..1655f2d5 100644 --- a/openrewrite/test/javascript/parser/class.test.ts +++ b/openrewrite/test/javascript/parser/class.test.ts @@ -270,6 +270,9 @@ describe('class mapping', () => { //language=typescript typeScript(` class OuterClass extends (class extends Number { + constructor() { + /*1*/ super /*2*/ () /*3*/; + } }) { constructor() { /*1*/ super /*2*/ () /*3*/; 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 48fefdc0..5d2065f7 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 @@ -41,6 +41,7 @@ import java.nio.file.Path; import java.util.List; import java.util.UUID; +import java.util.function.Function; @Value public class JavaScriptReceiver implements Receiver { @@ -705,6 +706,15 @@ public JS.JsAssignmentOperation visitJsAssignmentOperation(JS.JsAssignmentOperat return jsAssignmentOperation; } + @Override + public JS.TypeTreeExpression visitTypeTreeExpression(JS.TypeTreeExpression typeTreeExpression, ReceiverContext ctx) { + typeTreeExpression = typeTreeExpression.withId(ctx.receiveNonNullValue(typeTreeExpression.getId(), UUID.class)); + typeTreeExpression = typeTreeExpression.withPrefix(ctx.receiveNonNullNode(typeTreeExpression.getPrefix(), JavaScriptReceiver::receiveSpace)); + typeTreeExpression = typeTreeExpression.withMarkers(ctx.receiveNonNullNode(typeTreeExpression.getMarkers(), ctx::receiveMarkers)); + typeTreeExpression = typeTreeExpression.withExpression(ctx.receiveNonNullNode(typeTreeExpression.getExpression(), ctx::receiveTree)); + return typeTreeExpression; + } + @Override public J.AnnotatedType visitAnnotatedType(J.AnnotatedType annotatedType, ReceiverContext ctx) { annotatedType = annotatedType.withId(ctx.receiveNonNullValue(annotatedType.getId(), UUID.class)); @@ -1402,11 +1412,146 @@ public J.Unknown.Source visitUnknownSource(J.Unknown.Source source, ReceiverCont private static class Factory implements ReceiverFactory { + private final ClassValue> factories = new ClassValue>() { + @Override + protected Function computeValue(Class type) { + if (type == JS.CompilationUnit.class) return Factory::createJSCompilationUnit; + if (type == JS.Alias.class) return Factory::createJSAlias; + if (type == JS.ArrowFunction.class) return Factory::createJSArrowFunction; + if (type == JS.Await.class) return Factory::createJSAwait; + if (type == JS.ConditionalType.class) return Factory::createJSConditionalType; + if (type == JS.DefaultType.class) return Factory::createJSDefaultType; + if (type == JS.Delete.class) return Factory::createJSDelete; + if (type == JS.Export.class) return Factory::createJSExport; + if (type == JS.ExpressionStatement.class) return Factory::createJSExpressionStatement; + if (type == JS.ExpressionWithTypeArguments.class) return Factory::createJSExpressionWithTypeArguments; + if (type == JS.FunctionType.class) return Factory::createJSFunctionType; + if (type == JS.InferType.class) return Factory::createJSInferType; + if (type == JS.ImportType.class) return Factory::createJSImportType; + if (type == JS.JsImport.class) return Factory::createJSJsImport; + if (type == JS.JsImportSpecifier.class) return Factory::createJSJsImportSpecifier; + if (type == JS.JsBinary.class) return Factory::createJSJsBinary; + if (type == JS.LiteralType.class) return Factory::createJSLiteralType; + if (type == JS.ObjectBindingDeclarations.class) return Factory::createJSObjectBindingDeclarations; + if (type == JS.PropertyAssignment.class) return Factory::createJSPropertyAssignment; + if (type == JS.SatisfiesExpression.class) return Factory::createJSSatisfiesExpression; + if (type == JS.ScopedVariableDeclarations.class) return Factory::createJSScopedVariableDeclarations; + if (type == JS.StatementExpression.class) return Factory::createJSStatementExpression; + if (type == JS.TaggedTemplateExpression.class) return Factory::createJSTaggedTemplateExpression; + if (type == JS.TemplateExpression.class) return Factory::createJSTemplateExpression; + if (type == JS.TemplateExpression.TemplateSpan.class) return Factory::createJSTemplateExpressionTemplateSpan; + if (type == JS.Tuple.class) return Factory::createJSTuple; + if (type == JS.TypeDeclaration.class) return Factory::createJSTypeDeclaration; + if (type == JS.TypeOf.class) return Factory::createJSTypeOf; + if (type == JS.TypeQuery.class) return Factory::createJSTypeQuery; + if (type == JS.TypeOperator.class) return Factory::createJSTypeOperator; + if (type == JS.TypePredicate.class) return Factory::createJSTypePredicate; + if (type == JS.Unary.class) return Factory::createJSUnary; + if (type == JS.Union.class) return Factory::createJSUnion; + if (type == JS.Intersection.class) return Factory::createJSIntersection; + if (type == JS.Void.class) return Factory::createJSVoid; + if (type == JS.Yield.class) return Factory::createJSYield; + if (type == JS.TypeInfo.class) return Factory::createJSTypeInfo; + if (type == JS.JSVariableDeclarations.class) return Factory::createJSJSVariableDeclarations; + if (type == JS.JSVariableDeclarations.JSNamedVariable.class) return Factory::createJSJSVariableDeclarationsJSNamedVariable; + if (type == JS.JSMethodDeclaration.class) return Factory::createJSJSMethodDeclaration; + if (type == JS.JSForOfLoop.class) return Factory::createJSJSForOfLoop; + if (type == JS.JSForInLoop.class) return Factory::createJSJSForInLoop; + if (type == JS.JSForInOfLoopControl.class) return Factory::createJSJSForInOfLoopControl; + if (type == JS.NamespaceDeclaration.class) return Factory::createJSNamespaceDeclaration; + if (type == JS.FunctionDeclaration.class) return Factory::createJSFunctionDeclaration; + if (type == JS.TypeLiteral.class) return Factory::createJSTypeLiteral; + if (type == JS.IndexSignatureDeclaration.class) return Factory::createJSIndexSignatureDeclaration; + if (type == JS.ArrayBindingPattern.class) return Factory::createJSArrayBindingPattern; + if (type == JS.BindingElement.class) return Factory::createJSBindingElement; + if (type == JS.ExportDeclaration.class) return Factory::createJSExportDeclaration; + if (type == JS.ExportAssignment.class) return Factory::createJSExportAssignment; + if (type == JS.NamedExports.class) return Factory::createJSNamedExports; + if (type == JS.ExportSpecifier.class) return Factory::createJSExportSpecifier; + if (type == JS.IndexedAccessType.class) return Factory::createJSIndexedAccessType; + if (type == JS.IndexedAccessType.IndexType.class) return Factory::createJSIndexedAccessTypeIndexType; + if (type == JS.JsAssignmentOperation.class) return Factory::createJSJsAssignmentOperation; + if (type == JS.TypeTreeExpression.class) return Factory::createJSTypeTreeExpression; + if (type == J.AnnotatedType.class) return Factory::createJAnnotatedType; + if (type == J.Annotation.class) return Factory::createJAnnotation; + if (type == J.ArrayAccess.class) return Factory::createJArrayAccess; + if (type == J.ArrayType.class) return Factory::createJArrayType; + if (type == J.Assert.class) return Factory::createJAssert; + if (type == J.Assignment.class) return Factory::createJAssignment; + if (type == J.AssignmentOperation.class) return Factory::createJAssignmentOperation; + if (type == J.Binary.class) return Factory::createJBinary; + if (type == J.Block.class) return Factory::createJBlock; + if (type == J.Break.class) return Factory::createJBreak; + if (type == J.Case.class) return Factory::createJCase; + if (type == J.ClassDeclaration.class) return Factory::createJClassDeclaration; + if (type == J.ClassDeclaration.Kind.class) return Factory::createJClassDeclarationKind; + if (type == J.Continue.class) return Factory::createJContinue; + if (type == J.DoWhileLoop.class) return Factory::createJDoWhileLoop; + if (type == J.Empty.class) return Factory::createJEmpty; + if (type == J.EnumValue.class) return Factory::createJEnumValue; + if (type == J.EnumValueSet.class) return Factory::createJEnumValueSet; + if (type == J.FieldAccess.class) return Factory::createJFieldAccess; + if (type == J.ForEachLoop.class) return Factory::createJForEachLoop; + if (type == J.ForEachLoop.Control.class) return Factory::createJForEachLoopControl; + if (type == J.ForLoop.class) return Factory::createJForLoop; + if (type == J.ForLoop.Control.class) return Factory::createJForLoopControl; + if (type == J.ParenthesizedTypeTree.class) return Factory::createJParenthesizedTypeTree; + if (type == J.Identifier.class) return Factory::createJIdentifier; + if (type == J.If.class) return Factory::createJIf; + if (type == J.If.Else.class) return Factory::createJIfElse; + if (type == J.Import.class) return Factory::createJImport; + if (type == J.InstanceOf.class) return Factory::createJInstanceOf; + if (type == J.IntersectionType.class) return Factory::createJIntersectionType; + if (type == J.Label.class) return Factory::createJLabel; + if (type == J.Lambda.class) return Factory::createJLambda; + if (type == J.Lambda.Parameters.class) return Factory::createJLambdaParameters; + if (type == J.Literal.class) return Factory::createJLiteral; + if (type == J.MemberReference.class) return Factory::createJMemberReference; + if (type == J.MethodDeclaration.class) return Factory::createJMethodDeclaration; + if (type == J.MethodInvocation.class) return Factory::createJMethodInvocation; + if (type == J.Modifier.class) return Factory::createJModifier; + if (type == J.MultiCatch.class) return Factory::createJMultiCatch; + if (type == J.NewArray.class) return Factory::createJNewArray; + if (type == J.ArrayDimension.class) return Factory::createJArrayDimension; + if (type == J.NewClass.class) return Factory::createJNewClass; + if (type == J.NullableType.class) return Factory::createJNullableType; + if (type == J.Package.class) return Factory::createJPackage; + if (type == J.ParameterizedType.class) return Factory::createJParameterizedType; + if (type == J.Parentheses.class) return Factory::createJParentheses; + if (type == J.ControlParentheses.class) return Factory::createJControlParentheses; + if (type == J.Primitive.class) return Factory::createJPrimitive; + if (type == J.Return.class) return Factory::createJReturn; + if (type == J.Switch.class) return Factory::createJSwitch; + if (type == J.SwitchExpression.class) return Factory::createJSwitchExpression; + if (type == J.Synchronized.class) return Factory::createJSynchronized; + if (type == J.Ternary.class) return Factory::createJTernary; + if (type == J.Throw.class) return Factory::createJThrow; + if (type == J.Try.class) return Factory::createJTry; + if (type == J.Try.Resource.class) return Factory::createJTryResource; + if (type == J.Try.Catch.class) return Factory::createJTryCatch; + if (type == J.TypeCast.class) return Factory::createJTypeCast; + if (type == J.TypeParameter.class) return Factory::createJTypeParameter; + if (type == J.TypeParameters.class) return Factory::createJTypeParameters; + if (type == J.Unary.class) return Factory::createJUnary; + if (type == J.VariableDeclarations.class) return Factory::createJVariableDeclarations; + if (type == J.VariableDeclarations.NamedVariable.class) return Factory::createJVariableDeclarationsNamedVariable; + if (type == J.WhileLoop.class) return Factory::createJWhileLoop; + if (type == J.Wildcard.class) return Factory::createJWildcard; + if (type == J.Yield.class) return Factory::createJYield; + if (type == J.Unknown.class) return Factory::createJUnknown; + if (type == J.Unknown.Source.class) return Factory::createJUnknownSource; + throw new IllegalArgumentException("Unknown type: " + type); + } + }; + @Override @SuppressWarnings("unchecked") public T create(Class type, ReceiverContext ctx) { - if (type == JS.CompilationUnit.class) { - return (T) new JS.CompilationUnit( + return (T) factories.get(type).apply(ctx); + } + + private static JS.CompilationUnit createJSCompilationUnit(ReceiverContext ctx) { + return new JS.CompilationUnit( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -1418,21 +1563,21 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNonNullNodes(null, JavaScriptReceiver::receiveRightPaddedTree), ctx.receiveNonNullNodes(null, JavaScriptReceiver::receiveRightPaddedTree), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace) - ); - } + ); + } - if (type == JS.Alias.class) { - return (T) new JS.Alias( + private static JS.Alias createJSAlias(ReceiverContext ctx) { + return new JS.Alias( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveRightPaddedTree), ctx.receiveNonNullNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == JS.ArrowFunction.class) { - return (T) new JS.ArrowFunction( + private static JS.ArrowFunction createJSArrowFunction(ReceiverContext ctx) { + return new JS.ArrowFunction( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -1444,32 +1589,32 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.Await.class) { - return (T) new JS.Await( + private static JS.Await createJSAwait(ReceiverContext ctx) { + return new JS.Await( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.ConditionalType.class) { - return (T) new JS.ConditionalType( + private static JS.ConditionalType createJSConditionalType(ReceiverContext ctx) { + return new JS.ConditionalType( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveContainer), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.DefaultType.class) { - return (T) new JS.DefaultType( + private static JS.DefaultType createJSDefaultType(ReceiverContext ctx) { + return new JS.DefaultType( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -1477,21 +1622,21 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.Delete.class) { - return (T) new JS.Delete( + private static JS.Delete createJSDelete(ReceiverContext ctx) { + return new JS.Delete( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.Export.class) { - return (T) new JS.Export( + private static JS.Export createJSExport(ReceiverContext ctx) { + return new JS.Export( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -1499,29 +1644,29 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNode(null, ctx::receiveTree), ctx.receiveNode(null, JavaScriptReceiver::receiveLeftPaddedTree) - ); - } + ); + } - if (type == JS.ExpressionStatement.class) { - return (T) new JS.ExpressionStatement( + private static JS.ExpressionStatement createJSExpressionStatement(ReceiverContext ctx) { + return new JS.ExpressionStatement( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == JS.ExpressionWithTypeArguments.class) { - return (T) new JS.ExpressionWithTypeArguments( + private static JS.ExpressionWithTypeArguments createJSExpressionWithTypeArguments(ReceiverContext ctx) { + return new JS.ExpressionWithTypeArguments( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNode(null, JavaScriptReceiver::receiveContainer), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.FunctionType.class) { - return (T) new JS.FunctionType( + private static JS.FunctionType createJSFunctionType(ReceiverContext ctx) { + return new JS.FunctionType( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -1531,21 +1676,21 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.InferType.class) { - return (T) new JS.InferType( + private static JS.InferType createJSInferType(ReceiverContext ctx) { + return new JS.InferType( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveLeftPaddedTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.ImportType.class) { - return (T) new JS.ImportType( + private static JS.ImportType createJSImportType(ReceiverContext ctx) { + return new JS.ImportType( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -1554,11 +1699,11 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNode(null, JavaScriptReceiver::receiveLeftPaddedTree), ctx.receiveNode(null, JavaScriptReceiver::receiveContainer), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.JsImport.class) { - return (T) new JS.JsImport( + private static JS.JsImport createJSJsImport(ReceiverContext ctx) { + return new JS.JsImport( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -1568,22 +1713,22 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNode(null, ctx::receiveTree), ctx.receiveNode(null, JavaScriptReceiver::receiveLeftPaddedTree) - ); - } + ); + } - if (type == JS.JsImportSpecifier.class) { - return (T) new JS.JsImportSpecifier( + private static JS.JsImportSpecifier createJSJsImportSpecifier(ReceiverContext ctx) { + return new JS.JsImportSpecifier( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, leftPaddedValueReceiver(java.lang.Boolean.class)), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.JsBinary.class) { - return (T) new JS.JsBinary( + private static JS.JsBinary createJSJsBinary(ReceiverContext ctx) { + return new JS.JsBinary( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -1591,21 +1736,21 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNonNullNode(null, leftPaddedValueReceiver(org.openrewrite.javascript.tree.JS.JsBinary.Type.class)), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.LiteralType.class) { - return (T) new JS.LiteralType( + private static JS.LiteralType createJSLiteralType(ReceiverContext ctx) { + return new JS.LiteralType( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.ObjectBindingDeclarations.class) { - return (T) new JS.ObjectBindingDeclarations( + private static JS.ObjectBindingDeclarations createJSObjectBindingDeclarations(ReceiverContext ctx) { + return new JS.ObjectBindingDeclarations( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -1614,50 +1759,50 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNode(null, ctx::receiveTree), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveContainer), ctx.receiveNode(null, JavaScriptReceiver::receiveLeftPaddedTree) - ); - } + ); + } - if (type == JS.PropertyAssignment.class) { - return (T) new JS.PropertyAssignment( + private static JS.PropertyAssignment createJSPropertyAssignment(ReceiverContext ctx) { + return new JS.PropertyAssignment( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveRightPaddedTree), ctx.receiveNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == JS.SatisfiesExpression.class) { - return (T) new JS.SatisfiesExpression( + private static JS.SatisfiesExpression createJSSatisfiesExpression(ReceiverContext ctx) { + return new JS.SatisfiesExpression( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveLeftPaddedTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.ScopedVariableDeclarations.class) { - return (T) new JS.ScopedVariableDeclarations( + private static JS.ScopedVariableDeclarations createJSScopedVariableDeclarations(ReceiverContext ctx) { + return new JS.ScopedVariableDeclarations( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNodes(null, ctx::receiveTree), ctx.receiveNode(null, leftPaddedValueReceiver(org.openrewrite.javascript.tree.JS.ScopedVariableDeclarations.Scope.class)), ctx.receiveNonNullNodes(null, JavaScriptReceiver::receiveRightPaddedTree) - ); - } + ); + } - if (type == JS.StatementExpression.class) { - return (T) new JS.StatementExpression( + private static JS.StatementExpression createJSStatementExpression(ReceiverContext ctx) { + return new JS.StatementExpression( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == JS.TaggedTemplateExpression.class) { - return (T) new JS.TaggedTemplateExpression( + private static JS.TaggedTemplateExpression createJSTaggedTemplateExpression(ReceiverContext ctx) { + return new JS.TaggedTemplateExpression( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -1665,42 +1810,42 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNode(null, JavaScriptReceiver::receiveContainer), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.TemplateExpression.class) { - return (T) new JS.TemplateExpression( + private static JS.TemplateExpression createJSTemplateExpression(ReceiverContext ctx) { + return new JS.TemplateExpression( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNonNullNodes(null, JavaScriptReceiver::receiveRightPaddedTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.TemplateExpression.TemplateSpan.class) { - return (T) new JS.TemplateExpression.TemplateSpan( + private static JS.TemplateExpression.TemplateSpan createJSTemplateExpressionTemplateSpan(ReceiverContext ctx) { + return new JS.TemplateExpression.TemplateSpan( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNonNullNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == JS.Tuple.class) { - return (T) new JS.Tuple( + private static JS.Tuple createJSTuple(ReceiverContext ctx) { + return new JS.Tuple( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveContainer), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.TypeDeclaration.class) { - return (T) new JS.TypeDeclaration( + private static JS.TypeDeclaration createJSTypeDeclaration(ReceiverContext ctx) { + return new JS.TypeDeclaration( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -1709,41 +1854,41 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNode(null, ctx::receiveTree), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveLeftPaddedTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.TypeOf.class) { - return (T) new JS.TypeOf( + private static JS.TypeOf createJSTypeOf(ReceiverContext ctx) { + return new JS.TypeOf( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.TypeQuery.class) { - return (T) new JS.TypeQuery( + private static JS.TypeQuery createJSTypeQuery(ReceiverContext ctx) { + return new JS.TypeQuery( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.TypeOperator.class) { - return (T) new JS.TypeOperator( + private static JS.TypeOperator createJSTypeOperator(ReceiverContext ctx) { + return new JS.TypeOperator( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullValue(null, JS.TypeOperator.Type.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveLeftPaddedTree) - ); - } + ); + } - if (type == JS.TypePredicate.class) { - return (T) new JS.TypePredicate( + private static JS.TypePredicate createJSTypePredicate(ReceiverContext ctx) { + return new JS.TypePredicate( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -1751,71 +1896,71 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNode(null, JavaScriptReceiver::receiveLeftPaddedTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.Unary.class) { - return (T) new JS.Unary( + private static JS.Unary createJSUnary(ReceiverContext ctx) { + return new JS.Unary( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, leftPaddedValueReceiver(org.openrewrite.javascript.tree.JS.Unary.Type.class)), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.Union.class) { - return (T) new JS.Union( + private static JS.Union createJSUnion(ReceiverContext ctx) { + return new JS.Union( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNodes(null, JavaScriptReceiver::receiveRightPaddedTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.Intersection.class) { - return (T) new JS.Intersection( + private static JS.Intersection createJSIntersection(ReceiverContext ctx) { + return new JS.Intersection( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNodes(null, JavaScriptReceiver::receiveRightPaddedTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.Void.class) { - return (T) new JS.Void( + private static JS.Void createJSVoid(ReceiverContext ctx) { + return new JS.Void( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == JS.Yield.class) { - return (T) new JS.Yield( + private static JS.Yield createJSYield(ReceiverContext ctx) { + return new JS.Yield( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullValue(null, boolean.class), ctx.receiveNode(null, ctx::receiveTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.TypeInfo.class) { - return (T) new JS.TypeInfo( + private static JS.TypeInfo createJSTypeInfo(ReceiverContext ctx) { + return new JS.TypeInfo( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == JS.JSVariableDeclarations.class) { - return (T) new JS.JSVariableDeclarations( + private static JS.JSVariableDeclarations createJSJSVariableDeclarations(ReceiverContext ctx) { + return new JS.JSVariableDeclarations( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -1824,11 +1969,11 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNode(null, ctx::receiveTree), ctx.receiveNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNodes(null, JavaScriptReceiver::receiveRightPaddedTree) - ); - } + ); + } - if (type == JS.JSVariableDeclarations.JSNamedVariable.class) { - return (T) new JS.JSVariableDeclarations.JSNamedVariable( + private static JS.JSVariableDeclarations.JSNamedVariable createJSJSVariableDeclarationsJSNamedVariable(ReceiverContext ctx) { + return new JS.JSVariableDeclarations.JSNamedVariable( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -1836,11 +1981,11 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNonNullNodes(null, leftPaddedNodeReceiver(org.openrewrite.java.tree.Space.class)), ctx.receiveNode(null, JavaScriptReceiver::receiveLeftPaddedTree), ctx.receiveValue(null, JavaType.Variable.class) - ); - } + ); + } - if (type == JS.JSMethodDeclaration.class) { - return (T) new JS.JSMethodDeclaration( + private static JS.JSMethodDeclaration createJSJSMethodDeclaration(ReceiverContext ctx) { + return new JS.JSMethodDeclaration( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -1854,42 +1999,42 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNode(null, ctx::receiveTree), ctx.receiveNode(null, JavaScriptReceiver::receiveLeftPaddedTree), ctx.receiveValue(null, JavaType.Method.class) - ); - } + ); + } - if (type == JS.JSForOfLoop.class) { - return (T) new JS.JSForOfLoop( + private static JS.JSForOfLoop createJSJSForOfLoop(ReceiverContext ctx) { + return new JS.JSForOfLoop( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, leftPaddedValueReceiver(java.lang.Boolean.class)), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveRightPaddedTree) - ); - } + ); + } - if (type == JS.JSForInLoop.class) { - return (T) new JS.JSForInLoop( + private static JS.JSForInLoop createJSJSForInLoop(ReceiverContext ctx) { + return new JS.JSForInLoop( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveRightPaddedTree) - ); - } + ); + } - if (type == JS.JSForInOfLoopControl.class) { - return (T) new JS.JSForInOfLoopControl( + private static JS.JSForInOfLoopControl createJSJSForInOfLoopControl(ReceiverContext ctx) { + return new JS.JSForInOfLoopControl( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveRightPaddedTree), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveRightPaddedTree) - ); - } + ); + } - if (type == JS.NamespaceDeclaration.class) { - return (T) new JS.NamespaceDeclaration( + private static JS.NamespaceDeclaration createJSNamespaceDeclaration(ReceiverContext ctx) { + return new JS.NamespaceDeclaration( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -1897,11 +2042,11 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNonNullNode(null, leftPaddedValueReceiver(org.openrewrite.javascript.tree.JS.NamespaceDeclaration.KeywordType.class)), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveRightPaddedTree), ctx.receiveNonNullNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == JS.FunctionDeclaration.class) { - return (T) new JS.FunctionDeclaration( + private static JS.FunctionDeclaration createJSFunctionDeclaration(ReceiverContext ctx) { + return new JS.FunctionDeclaration( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -1913,21 +2058,21 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNode(null, ctx::receiveTree), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.TypeLiteral.class) { - return (T) new JS.TypeLiteral( + private static JS.TypeLiteral createJSTypeLiteral(ReceiverContext ctx) { + return new JS.TypeLiteral( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.IndexSignatureDeclaration.class) { - return (T) new JS.IndexSignatureDeclaration( + private static JS.IndexSignatureDeclaration createJSIndexSignatureDeclaration(ReceiverContext ctx) { + return new JS.IndexSignatureDeclaration( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -1935,21 +2080,21 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveContainer), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveLeftPaddedTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.ArrayBindingPattern.class) { - return (T) new JS.ArrayBindingPattern( + private static JS.ArrayBindingPattern createJSArrayBindingPattern(ReceiverContext ctx) { + return new JS.ArrayBindingPattern( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveContainer), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.BindingElement.class) { - return (T) new JS.BindingElement( + private static JS.BindingElement createJSBindingElement(ReceiverContext ctx) { + return new JS.BindingElement( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -1957,11 +2102,11 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNode(null, JavaScriptReceiver::receiveLeftPaddedTree), ctx.receiveValue(null, JavaType.Variable.class) - ); - } + ); + } - if (type == JS.ExportDeclaration.class) { - return (T) new JS.ExportDeclaration( + private static JS.ExportDeclaration createJSExportDeclaration(ReceiverContext ctx) { + return new JS.ExportDeclaration( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -1969,64 +2114,64 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNonNullNode(null, leftPaddedValueReceiver(java.lang.Boolean.class)), ctx.receiveNode(null, ctx::receiveTree), ctx.receiveNode(null, JavaScriptReceiver::receiveLeftPaddedTree) - ); - } + ); + } - if (type == JS.ExportAssignment.class) { - return (T) new JS.ExportAssignment( + private static JS.ExportAssignment createJSExportAssignment(ReceiverContext ctx) { + return new JS.ExportAssignment( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNodes(null, ctx::receiveTree), ctx.receiveNonNullNode(null, leftPaddedValueReceiver(java.lang.Boolean.class)), ctx.receiveNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == JS.NamedExports.class) { - return (T) new JS.NamedExports( + private static JS.NamedExports createJSNamedExports(ReceiverContext ctx) { + return new JS.NamedExports( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveContainer), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.ExportSpecifier.class) { - return (T) new JS.ExportSpecifier( + private static JS.ExportSpecifier createJSExportSpecifier(ReceiverContext ctx) { + return new JS.ExportSpecifier( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, leftPaddedValueReceiver(java.lang.Boolean.class)), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.IndexedAccessType.class) { - return (T) new JS.IndexedAccessType( + private static JS.IndexedAccessType createJSIndexedAccessType(ReceiverContext ctx) { + return new JS.IndexedAccessType( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveRightPaddedTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.IndexedAccessType.IndexType.class) { - return (T) new JS.IndexedAccessType.IndexType( + private static JS.IndexedAccessType.IndexType createJSIndexedAccessTypeIndexType(ReceiverContext ctx) { + return new JS.IndexedAccessType.IndexType( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveRightPaddedTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == JS.JsAssignmentOperation.class) { - return (T) new JS.JsAssignmentOperation( + private static JS.JsAssignmentOperation createJSJsAssignmentOperation(ReceiverContext ctx) { + return new JS.JsAssignmentOperation( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -2034,42 +2179,51 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNonNullNode(null, leftPaddedValueReceiver(org.openrewrite.javascript.tree.JS.JsAssignmentOperation.Type.class)), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } + + private static JS.TypeTreeExpression createJSTypeTreeExpression(ReceiverContext ctx) { + return new JS.TypeTreeExpression( + ctx.receiveNonNullValue(null, UUID.class), + ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), + ctx.receiveNonNullNode(null, ctx::receiveMarkers), + ctx.receiveNonNullNode(null, ctx::receiveTree) + ); + } - if (type == J.AnnotatedType.class) { - return (T) new J.AnnotatedType( + private static J.AnnotatedType createJAnnotatedType(ReceiverContext ctx) { + return new J.AnnotatedType( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNodes(null, ctx::receiveTree), ctx.receiveNonNullNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == J.Annotation.class) { - return (T) new J.Annotation( + private static J.Annotation createJAnnotation(ReceiverContext ctx) { + return new J.Annotation( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNode(null, JavaScriptReceiver::receiveContainer) - ); - } + ); + } - if (type == J.ArrayAccess.class) { - return (T) new J.ArrayAccess( + private static J.ArrayAccess createJArrayAccess(ReceiverContext ctx) { + return new J.ArrayAccess( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == J.ArrayType.class) { - return (T) new J.ArrayType( + private static J.ArrayType createJArrayType(ReceiverContext ctx) { + return new J.ArrayType( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -2077,32 +2231,32 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNodes(null, ctx::receiveTree), ctx.receiveNode(null, leftPaddedNodeReceiver(org.openrewrite.java.tree.Space.class)), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == J.Assert.class) { - return (T) new J.Assert( + private static J.Assert createJAssert(ReceiverContext ctx) { + return new J.Assert( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNode(null, JavaScriptReceiver::receiveLeftPaddedTree) - ); - } + ); + } - if (type == J.Assignment.class) { - return (T) new J.Assignment( + private static J.Assignment createJAssignment(ReceiverContext ctx) { + return new J.Assignment( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveLeftPaddedTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == J.AssignmentOperation.class) { - return (T) new J.AssignmentOperation( + private static J.AssignmentOperation createJAssignmentOperation(ReceiverContext ctx) { + return new J.AssignmentOperation( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -2110,11 +2264,11 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNonNullNode(null, leftPaddedValueReceiver(org.openrewrite.java.tree.J.AssignmentOperation.Type.class)), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == J.Binary.class) { - return (T) new J.Binary( + private static J.Binary createJBinary(ReceiverContext ctx) { + return new J.Binary( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -2122,31 +2276,31 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNonNullNode(null, leftPaddedValueReceiver(org.openrewrite.java.tree.J.Binary.Type.class)), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == J.Block.class) { - return (T) new J.Block( + private static J.Block createJBlock(ReceiverContext ctx) { + return new J.Block( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, rightPaddedValueReceiver(java.lang.Boolean.class)), ctx.receiveNonNullNodes(null, JavaScriptReceiver::receiveRightPaddedTree), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace) - ); - } + ); + } - if (type == J.Break.class) { - return (T) new J.Break( + private static J.Break createJBreak(ReceiverContext ctx) { + return new J.Break( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == J.Case.class) { - return (T) new J.Case( + private static J.Case createJCase(ReceiverContext ctx) { + return new J.Case( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -2154,11 +2308,11 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveContainer), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveContainer), ctx.receiveNode(null, JavaScriptReceiver::receiveRightPaddedTree) - ); - } + ); + } - if (type == J.ClassDeclaration.class) { - return (T) new J.ClassDeclaration( + private static J.ClassDeclaration createJClassDeclaration(ReceiverContext ctx) { + return new J.ClassDeclaration( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -2173,131 +2327,131 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNode(null, JavaScriptReceiver::receiveContainer), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveValue(null, JavaType.FullyQualified.class) - ); - } + ); + } - if (type == J.ClassDeclaration.Kind.class) { - return (T) new J.ClassDeclaration.Kind( + private static J.ClassDeclaration.Kind createJClassDeclarationKind(ReceiverContext ctx) { + return new J.ClassDeclaration.Kind( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNodes(null, ctx::receiveTree), ctx.receiveNonNullValue(null, J.ClassDeclaration.Kind.Type.class) - ); - } + ); + } - if (type == J.Continue.class) { - return (T) new J.Continue( + private static J.Continue createJContinue(ReceiverContext ctx) { + return new J.Continue( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == J.DoWhileLoop.class) { - return (T) new J.DoWhileLoop( + private static J.DoWhileLoop createJDoWhileLoop(ReceiverContext ctx) { + return new J.DoWhileLoop( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveRightPaddedTree), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveLeftPaddedTree) - ); - } + ); + } - if (type == J.Empty.class) { - return (T) new J.Empty( + private static J.Empty createJEmpty(ReceiverContext ctx) { + return new J.Empty( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers) - ); - } + ); + } - if (type == J.EnumValue.class) { - return (T) new J.EnumValue( + private static J.EnumValue createJEnumValue(ReceiverContext ctx) { + return new J.EnumValue( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNodes(null, ctx::receiveTree), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == J.EnumValueSet.class) { - return (T) new J.EnumValueSet( + private static J.EnumValueSet createJEnumValueSet(ReceiverContext ctx) { + return new J.EnumValueSet( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNodes(null, JavaScriptReceiver::receiveRightPaddedTree), ctx.receiveNonNullValue(null, boolean.class) - ); - } + ); + } - if (type == J.FieldAccess.class) { - return (T) new J.FieldAccess( + private static J.FieldAccess createJFieldAccess(ReceiverContext ctx) { + return new J.FieldAccess( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveLeftPaddedTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == J.ForEachLoop.class) { - return (T) new J.ForEachLoop( + private static J.ForEachLoop createJForEachLoop(ReceiverContext ctx) { + return new J.ForEachLoop( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveRightPaddedTree) - ); - } + ); + } - if (type == J.ForEachLoop.Control.class) { - return (T) new J.ForEachLoop.Control( + private static J.ForEachLoop.Control createJForEachLoopControl(ReceiverContext ctx) { + return new J.ForEachLoop.Control( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveRightPaddedTree), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveRightPaddedTree) - ); - } + ); + } - if (type == J.ForLoop.class) { - return (T) new J.ForLoop( + private static J.ForLoop createJForLoop(ReceiverContext ctx) { + return new J.ForLoop( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveRightPaddedTree) - ); - } + ); + } - if (type == J.ForLoop.Control.class) { - return (T) new J.ForLoop.Control( + private static J.ForLoop.Control createJForLoopControl(ReceiverContext ctx) { + return new J.ForLoop.Control( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNodes(null, JavaScriptReceiver::receiveRightPaddedTree), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveRightPaddedTree), ctx.receiveNonNullNodes(null, JavaScriptReceiver::receiveRightPaddedTree) - ); - } + ); + } - if (type == J.ParenthesizedTypeTree.class) { - return (T) new J.ParenthesizedTypeTree( + private static J.ParenthesizedTypeTree createJParenthesizedTypeTree(ReceiverContext ctx) { + return new J.ParenthesizedTypeTree( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNodes(null, ctx::receiveTree), ctx.receiveNonNullNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == J.Identifier.class) { - return (T) new J.Identifier( + private static J.Identifier createJIdentifier(ReceiverContext ctx) { + return new J.Identifier( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -2305,42 +2459,42 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNonNullValue(null, String.class), ctx.receiveValue(null, JavaType.class), ctx.receiveValue(null, JavaType.Variable.class) - ); - } + ); + } - if (type == J.If.class) { - return (T) new J.If( + private static J.If createJIf(ReceiverContext ctx) { + return new J.If( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveRightPaddedTree), ctx.receiveNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == J.If.Else.class) { - return (T) new J.If.Else( + private static J.If.Else createJIfElse(ReceiverContext ctx) { + return new J.If.Else( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveRightPaddedTree) - ); - } + ); + } - if (type == J.Import.class) { - return (T) new J.Import( + private static J.Import createJImport(ReceiverContext ctx) { + return new J.Import( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, leftPaddedValueReceiver(java.lang.Boolean.class)), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNode(null, JavaScriptReceiver::receiveLeftPaddedTree) - ); - } + ); + } - if (type == J.InstanceOf.class) { - return (T) new J.InstanceOf( + private static J.InstanceOf createJInstanceOf(ReceiverContext ctx) { + return new J.InstanceOf( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -2348,30 +2502,30 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNode(null, ctx::receiveTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == J.IntersectionType.class) { - return (T) new J.IntersectionType( + private static J.IntersectionType createJIntersectionType(ReceiverContext ctx) { + return new J.IntersectionType( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveContainer) - ); - } + ); + } - if (type == J.Label.class) { - return (T) new J.Label( + private static J.Label createJLabel(ReceiverContext ctx) { + return new J.Label( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveRightPaddedTree), ctx.receiveNonNullNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == J.Lambda.class) { - return (T) new J.Lambda( + private static J.Lambda createJLambda(ReceiverContext ctx) { + return new J.Lambda( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -2379,21 +2533,21 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == J.Lambda.Parameters.class) { - return (T) new J.Lambda.Parameters( + private static J.Lambda.Parameters createJLambdaParameters(ReceiverContext ctx) { + return new J.Lambda.Parameters( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullValue(null, boolean.class), ctx.receiveNonNullNodes(null, JavaScriptReceiver::receiveRightPaddedTree) - ); - } + ); + } - if (type == J.Literal.class) { - return (T) new J.Literal( + private static J.Literal createJLiteral(ReceiverContext ctx) { + return new J.Literal( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -2401,11 +2555,11 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveValue(null, String.class), ctx.receiveValues(null, J.Literal.UnicodeEscape.class), ctx.receiveValue(null, JavaType.Primitive.class) - ); - } + ); + } - if (type == J.MemberReference.class) { - return (T) new J.MemberReference( + private static J.MemberReference createJMemberReference(ReceiverContext ctx) { + return new J.MemberReference( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -2415,11 +2569,11 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveValue(null, JavaType.class), ctx.receiveValue(null, JavaType.Method.class), ctx.receiveValue(null, JavaType.Variable.class) - ); - } + ); + } - if (type == J.MethodDeclaration.class) { - return (T) new J.MethodDeclaration( + private static J.MethodDeclaration createJMethodDeclaration(ReceiverContext ctx) { + return new J.MethodDeclaration( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -2433,11 +2587,11 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNode(null, ctx::receiveTree), ctx.receiveNode(null, JavaScriptReceiver::receiveLeftPaddedTree), ctx.receiveValue(null, JavaType.Method.class) - ); - } + ); + } - if (type == J.MethodInvocation.class) { - return (T) new J.MethodInvocation( + private static J.MethodInvocation createJMethodInvocation(ReceiverContext ctx) { + return new J.MethodInvocation( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -2446,31 +2600,31 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveContainer), ctx.receiveValue(null, JavaType.Method.class) - ); - } + ); + } - if (type == J.Modifier.class) { - return (T) new J.Modifier( + private static J.Modifier createJModifier(ReceiverContext ctx) { + return new J.Modifier( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveValue(null, String.class), ctx.receiveNonNullValue(null, J.Modifier.Type.class), ctx.receiveNonNullNodes(null, ctx::receiveTree) - ); - } + ); + } - if (type == J.MultiCatch.class) { - return (T) new J.MultiCatch( + private static J.MultiCatch createJMultiCatch(ReceiverContext ctx) { + return new J.MultiCatch( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNodes(null, JavaScriptReceiver::receiveRightPaddedTree) - ); - } + ); + } - if (type == J.NewArray.class) { - return (T) new J.NewArray( + private static J.NewArray createJNewArray(ReceiverContext ctx) { + return new J.NewArray( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -2478,20 +2632,20 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNonNullNodes(null, ctx::receiveTree), ctx.receiveNode(null, JavaScriptReceiver::receiveContainer), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == J.ArrayDimension.class) { - return (T) new J.ArrayDimension( + private static J.ArrayDimension createJArrayDimension(ReceiverContext ctx) { + return new J.ArrayDimension( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveRightPaddedTree) - ); - } + ); + } - if (type == J.NewClass.class) { - return (T) new J.NewClass( + private static J.NewClass createJNewClass(ReceiverContext ctx) { + return new J.NewClass( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -2501,108 +2655,108 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveContainer), ctx.receiveNode(null, ctx::receiveTree), ctx.receiveValue(null, JavaType.Method.class) - ); - } + ); + } - if (type == J.NullableType.class) { - return (T) new J.NullableType( + private static J.NullableType createJNullableType(ReceiverContext ctx) { + return new J.NullableType( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNodes(null, ctx::receiveTree), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveRightPaddedTree) - ); - } + ); + } - if (type == J.Package.class) { - return (T) new J.Package( + private static J.Package createJPackage(ReceiverContext ctx) { + return new J.Package( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNonNullNodes(null, ctx::receiveTree) - ); - } + ); + } - if (type == J.ParameterizedType.class) { - return (T) new J.ParameterizedType( + private static J.ParameterizedType createJParameterizedType(ReceiverContext ctx) { + return new J.ParameterizedType( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNode(null, JavaScriptReceiver::receiveContainer), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == J.Parentheses.class) { - return (T) new J.Parentheses( + private static J.Parentheses createJParentheses(ReceiverContext ctx) { + return new J.Parentheses( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveRightPaddedTree) - ); - } + ); + } - if (type == J.ControlParentheses.class) { - return (T) new J.ControlParentheses( + private static J.ControlParentheses createJControlParentheses(ReceiverContext ctx) { + return new J.ControlParentheses( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveRightPaddedTree) - ); - } + ); + } - if (type == J.Primitive.class) { - return (T) new J.Primitive( + private static J.Primitive createJPrimitive(ReceiverContext ctx) { + return new J.Primitive( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveValue(null, JavaType.Primitive.class) - ); - } + ); + } - if (type == J.Return.class) { - return (T) new J.Return( + private static J.Return createJReturn(ReceiverContext ctx) { + return new J.Return( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == J.Switch.class) { - return (T) new J.Switch( + private static J.Switch createJSwitch(ReceiverContext ctx) { + return new J.Switch( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNonNullNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == J.SwitchExpression.class) { - return (T) new J.SwitchExpression( + private static J.SwitchExpression createJSwitchExpression(ReceiverContext ctx) { + return new J.SwitchExpression( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNonNullNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == J.Synchronized.class) { - return (T) new J.Synchronized( + private static J.Synchronized createJSynchronized(ReceiverContext ctx) { + return new J.Synchronized( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNonNullNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == J.Ternary.class) { - return (T) new J.Ternary( + private static J.Ternary createJTernary(ReceiverContext ctx) { + return new J.Ternary( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -2610,20 +2764,20 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveLeftPaddedTree), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveLeftPaddedTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == J.Throw.class) { - return (T) new J.Throw( + private static J.Throw createJThrow(ReceiverContext ctx) { + return new J.Throw( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == J.Try.class) { - return (T) new J.Try( + private static J.Try createJTry(ReceiverContext ctx) { + return new J.Try( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -2631,41 +2785,41 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNonNullNodes(null, ctx::receiveTree), ctx.receiveNode(null, JavaScriptReceiver::receiveLeftPaddedTree) - ); - } + ); + } - if (type == J.Try.Resource.class) { - return (T) new J.Try.Resource( + private static J.Try.Resource createJTryResource(ReceiverContext ctx) { + return new J.Try.Resource( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNonNullValue(null, boolean.class) - ); - } + ); + } - if (type == J.Try.Catch.class) { - return (T) new J.Try.Catch( + private static J.Try.Catch createJTryCatch(ReceiverContext ctx) { + return new J.Try.Catch( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNonNullNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == J.TypeCast.class) { - return (T) new J.TypeCast( + private static J.TypeCast createJTypeCast(ReceiverContext ctx) { + return new J.TypeCast( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNonNullNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == J.TypeParameter.class) { - return (T) new J.TypeParameter( + private static J.TypeParameter createJTypeParameter(ReceiverContext ctx) { + return new J.TypeParameter( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -2673,32 +2827,32 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNonNullNodes(null, JavaScriptReceiver::receiveModifier), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNode(null, JavaScriptReceiver::receiveContainer) - ); - } + ); + } - if (type == J.TypeParameters.class) { - return (T) new J.TypeParameters( + private static J.TypeParameters createJTypeParameters(ReceiverContext ctx) { + return new J.TypeParameters( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNodes(null, ctx::receiveTree), ctx.receiveNonNullNodes(null, JavaScriptReceiver::receiveRightPaddedTree) - ); - } + ); + } - if (type == J.Unary.class) { - return (T) new J.Unary( + private static J.Unary createJUnary(ReceiverContext ctx) { + return new J.Unary( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, leftPaddedValueReceiver(org.openrewrite.java.tree.J.Unary.Type.class)), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveValue(null, JavaType.class) - ); - } + ); + } - if (type == J.VariableDeclarations.class) { - return (T) new J.VariableDeclarations( + private static J.VariableDeclarations createJVariableDeclarations(ReceiverContext ctx) { + return new J.VariableDeclarations( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -2708,11 +2862,11 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNodes(null, leftPaddedNodeReceiver(org.openrewrite.java.tree.Space.class)), ctx.receiveNonNullNodes(null, JavaScriptReceiver::receiveRightPaddedTree) - ); - } + ); + } - if (type == J.VariableDeclarations.NamedVariable.class) { - return (T) new J.VariableDeclarations.NamedVariable( + private static J.VariableDeclarations.NamedVariable createJVariableDeclarationsNamedVariable(ReceiverContext ctx) { + return new J.VariableDeclarations.NamedVariable( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), @@ -2720,59 +2874,57 @@ public T create(Class type, ReceiverContext ctx) { ctx.receiveNonNullNodes(null, leftPaddedNodeReceiver(org.openrewrite.java.tree.Space.class)), ctx.receiveNode(null, JavaScriptReceiver::receiveLeftPaddedTree), ctx.receiveValue(null, JavaType.Variable.class) - ); - } + ); + } - if (type == J.WhileLoop.class) { - return (T) new J.WhileLoop( + private static J.WhileLoop createJWhileLoop(ReceiverContext ctx) { + return new J.WhileLoop( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveRightPaddedTree) - ); - } + ); + } - if (type == J.Wildcard.class) { - return (T) new J.Wildcard( + private static J.Wildcard createJWildcard(ReceiverContext ctx) { + return new J.Wildcard( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNode(null, leftPaddedValueReceiver(org.openrewrite.java.tree.J.Wildcard.Bound.class)), ctx.receiveNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == J.Yield.class) { - return (T) new J.Yield( + private static J.Yield createJYield(ReceiverContext ctx) { + return new J.Yield( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullValue(null, boolean.class), ctx.receiveNonNullNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == J.Unknown.class) { - return (T) new J.Unknown( + private static J.Unknown createJUnknown(ReceiverContext ctx) { + return new J.Unknown( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullNode(null, ctx::receiveTree) - ); - } + ); + } - if (type == J.Unknown.Source.class) { - return (T) new J.Unknown.Source( + private static J.Unknown.Source createJUnknownSource(ReceiverContext ctx) { + return new J.Unknown.Source( ctx.receiveNonNullValue(null, UUID.class), ctx.receiveNonNullNode(null, JavaScriptReceiver::receiveSpace), ctx.receiveNonNullNode(null, ctx::receiveMarkers), ctx.receiveNonNullValue(null, String.class) - ); - } - - throw new IllegalArgumentException("Unknown type: " + type); + ); } + } private static J.ClassDeclaration.Kind receiveClassDeclarationKind(J.ClassDeclaration.@Nullable Kind kind, @Nullable Class type, ReceiverContext ctx) { 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 9f0e0eb1..1e268f97 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 @@ -688,6 +688,15 @@ public JS.JsAssignmentOperation visitJsAssignmentOperation(JS.JsAssignmentOperat return jsAssignmentOperation; } + @Override + public JS.TypeTreeExpression visitTypeTreeExpression(JS.TypeTreeExpression typeTreeExpression, SenderContext ctx) { + ctx.sendValue(typeTreeExpression, JS.TypeTreeExpression::getId); + ctx.sendNode(typeTreeExpression, JS.TypeTreeExpression::getPrefix, JavaScriptSender::sendSpace); + ctx.sendNode(typeTreeExpression, JS.TypeTreeExpression::getMarkers, ctx::sendMarkers); + ctx.sendNode(typeTreeExpression, JS.TypeTreeExpression::getExpression, ctx::sendTree); + return typeTreeExpression; + } + @Override public J.AnnotatedType visitAnnotatedType(J.AnnotatedType annotatedType, SenderContext ctx) { ctx.sendValue(annotatedType, J.AnnotatedType::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 a4a0962b..04e23eb2 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 @@ -33,6 +33,7 @@ import org.openrewrite.javascript.tree.*; import java.util.List; +import java.util.Objects; class JavaScriptValidator

extends JavaScriptIsoVisitor

{ @@ -44,58 +45,67 @@ class JavaScriptValidator

extends JavaScriptIsoVisitor

{ return (T) visit(tree, p); } - private @Nullable List visitAndValidate(@Nullable List<@Nullable T> list, Class expected, P p) { - return list == null ? null : ListUtils.map(list, e -> visitAndValidate(e, expected, p)); + private T visitAndValidateNonNull(@Nullable T tree, Class expected, P p) { + Objects.requireNonNull(tree); + if (!expected.isInstance(tree)) { + throw new ClassCastException("Type " + tree.getClass() + " is not assignable to " + expected); + } + // noinspection unchecked + return (T) visitNonNull(tree, p); + } + + private @Nullable List visitAndValidate(@Nullable List list, Class expected, P p) { + return list == null ? null : ListUtils.map(list, e -> visitAndValidateNonNull(e, expected, p)); } @Override public JS.CompilationUnit visitCompilationUnit(JS.CompilationUnit compilationUnit, P p) { - ListUtils.map(compilationUnit.getImports(), el -> visitAndValidate(el, J.Import.class, p)); - ListUtils.map(compilationUnit.getStatements(), el -> visitAndValidate(el, Statement.class, p)); + ListUtils.map(compilationUnit.getImports(), el -> visitAndValidateNonNull(el, J.Import.class, p)); + ListUtils.map(compilationUnit.getStatements(), el -> visitAndValidateNonNull(el, Statement.class, p)); return compilationUnit; } @Override public JS.Alias visitAlias(JS.Alias alias, P p) { - visitAndValidate(alias.getPropertyName(), J.Identifier.class, p); - visitAndValidate(alias.getAlias(), Expression.class, p); + visitAndValidateNonNull(alias.getPropertyName(), J.Identifier.class, p); + visitAndValidateNonNull(alias.getAlias(), Expression.class, p); return alias; } @Override public JS.ArrowFunction visitArrowFunction(JS.ArrowFunction arrowFunction, P p) { - ListUtils.map(arrowFunction.getLeadingAnnotations(), el -> visitAndValidate(el, J.Annotation.class, p)); - ListUtils.map(arrowFunction.getModifiers(), el -> visitAndValidate(el, J.Modifier.class, p)); + ListUtils.map(arrowFunction.getLeadingAnnotations(), el -> visitAndValidateNonNull(el, J.Annotation.class, p)); + ListUtils.map(arrowFunction.getModifiers(), el -> visitAndValidateNonNull(el, J.Modifier.class, p)); visitAndValidate(arrowFunction.getTypeParameters(), J.TypeParameters.class, p); - visitAndValidate(arrowFunction.getParameters(), J.Lambda.Parameters.class, p); + visitAndValidateNonNull(arrowFunction.getParameters(), J.Lambda.Parameters.class, p); visitAndValidate(arrowFunction.getReturnTypeExpression(), TypeTree.class, p); - visitAndValidate(arrowFunction.getBody(), J.class, p); + visitAndValidateNonNull(arrowFunction.getBody(), J.class, p); return arrowFunction; } @Override public JS.Await visitAwait(JS.Await await, P p) { - visitAndValidate(await.getExpression(), Expression.class, p); + visitAndValidateNonNull(await.getExpression(), Expression.class, p); return await; } @Override public JS.ConditionalType visitConditionalType(JS.ConditionalType conditionalType, P p) { - visitAndValidate(conditionalType.getCheckType(), Expression.class, p); + visitAndValidateNonNull(conditionalType.getCheckType(), Expression.class, p); visitAndValidate(conditionalType.getCondition(), TypedTree.class, p); return conditionalType; } @Override public JS.DefaultType visitDefaultType(JS.DefaultType defaultType, P p) { - visitAndValidate(defaultType.getLeft(), Expression.class, p); - visitAndValidate(defaultType.getRight(), Expression.class, p); + visitAndValidateNonNull(defaultType.getLeft(), Expression.class, p); + visitAndValidateNonNull(defaultType.getRight(), Expression.class, p); return defaultType; } @Override public JS.Delete visitDelete(JS.Delete delete, P p) { - visitAndValidate(delete.getExpression(), Expression.class, p); + visitAndValidateNonNull(delete.getExpression(), Expression.class, p); return delete; } @@ -109,13 +119,13 @@ public JS.Export visitExport(JS.Export export, P p) { @Override public JS.ExpressionStatement visitExpressionStatement(JS.ExpressionStatement expressionStatement, P p) { - visitAndValidate(expressionStatement.getExpression(), Expression.class, p); + visitAndValidateNonNull(expressionStatement.getExpression(), Expression.class, p); return expressionStatement; } @Override public JS.ExpressionWithTypeArguments visitExpressionWithTypeArguments(JS.ExpressionWithTypeArguments expressionWithTypeArguments, P p) { - visitAndValidate(expressionWithTypeArguments.getClazz(), NameTree.class, p); + visitAndValidateNonNull(expressionWithTypeArguments.getClazz(), NameTree.class, p); visitAndValidate(expressionWithTypeArguments.getTypeArguments(), Expression.class, p); return expressionWithTypeArguments; } @@ -124,19 +134,19 @@ public JS.ExpressionWithTypeArguments visitExpressionWithTypeArguments(JS.Expres public JS.FunctionType visitFunctionType(JS.FunctionType functionType, P p) { visitAndValidate(functionType.getTypeParameters(), J.TypeParameters.class, p); visitAndValidate(functionType.getParameters(), Statement.class, p); - visitAndValidate(functionType.getReturnType(), Expression.class, p); + visitAndValidateNonNull(functionType.getReturnType(), Expression.class, p); return functionType; } @Override public JS.InferType visitInferType(JS.InferType inferType, P p) { - visitAndValidate(inferType.getTypeParameter(), J.class, p); + visitAndValidateNonNull(inferType.getTypeParameter(), J.class, p); return inferType; } @Override public JS.ImportType visitImportType(JS.ImportType importType, P p) { - visitAndValidate(importType.getImportArgument(), J.ParenthesizedTypeTree.class, p); + visitAndValidateNonNull(importType.getImportArgument(), J.ParenthesizedTypeTree.class, p); visitAndValidate(importType.getQualifier(), Expression.class, p); visitAndValidate(importType.getTypeArguments(), Expression.class, p); return importType; @@ -153,27 +163,27 @@ public JS.JsImport visitJsImport(JS.JsImport jsImport, P p) { @Override public JS.JsImportSpecifier visitJsImportSpecifier(JS.JsImportSpecifier jsImportSpecifier, P p) { - visitAndValidate(jsImportSpecifier.getSpecifier(), Expression.class, p); + visitAndValidateNonNull(jsImportSpecifier.getSpecifier(), Expression.class, p); return jsImportSpecifier; } @Override public JS.JsBinary visitJsBinary(JS.JsBinary jsBinary, P p) { - visitAndValidate(jsBinary.getLeft(), Expression.class, p); - visitAndValidate(jsBinary.getRight(), Expression.class, p); + visitAndValidateNonNull(jsBinary.getLeft(), Expression.class, p); + visitAndValidateNonNull(jsBinary.getRight(), Expression.class, p); return jsBinary; } @Override public JS.LiteralType visitLiteralType(JS.LiteralType literalType, P p) { - visitAndValidate(literalType.getLiteral(), Expression.class, p); + visitAndValidateNonNull(literalType.getLiteral(), Expression.class, p); return literalType; } @Override public JS.ObjectBindingDeclarations visitObjectBindingDeclarations(JS.ObjectBindingDeclarations objectBindingDeclarations, P p) { - ListUtils.map(objectBindingDeclarations.getLeadingAnnotations(), el -> visitAndValidate(el, J.Annotation.class, p)); - ListUtils.map(objectBindingDeclarations.getModifiers(), el -> visitAndValidate(el, J.Modifier.class, p)); + ListUtils.map(objectBindingDeclarations.getLeadingAnnotations(), el -> visitAndValidateNonNull(el, J.Annotation.class, p)); + ListUtils.map(objectBindingDeclarations.getModifiers(), el -> visitAndValidateNonNull(el, J.Modifier.class, p)); visitAndValidate(objectBindingDeclarations.getTypeExpression(), TypeTree.class, p); visitAndValidate(objectBindingDeclarations.getBindings(), JS.BindingElement.class, p); visitAndValidate(objectBindingDeclarations.getInitializer(), Expression.class, p); @@ -182,28 +192,28 @@ public JS.ObjectBindingDeclarations visitObjectBindingDeclarations(JS.ObjectBind @Override public JS.PropertyAssignment visitPropertyAssignment(JS.PropertyAssignment propertyAssignment, P p) { - visitAndValidate(propertyAssignment.getName(), Expression.class, p); + visitAndValidateNonNull(propertyAssignment.getName(), Expression.class, p); visitAndValidate(propertyAssignment.getInitializer(), Expression.class, p); return propertyAssignment; } @Override public JS.SatisfiesExpression visitSatisfiesExpression(JS.SatisfiesExpression satisfiesExpression, P p) { - visitAndValidate(satisfiesExpression.getExpression(), J.class, p); - visitAndValidate(satisfiesExpression.getSatisfiesType(), Expression.class, p); + visitAndValidateNonNull(satisfiesExpression.getExpression(), J.class, p); + visitAndValidateNonNull(satisfiesExpression.getSatisfiesType(), Expression.class, p); return satisfiesExpression; } @Override public JS.ScopedVariableDeclarations visitScopedVariableDeclarations(JS.ScopedVariableDeclarations scopedVariableDeclarations, P p) { - ListUtils.map(scopedVariableDeclarations.getModifiers(), el -> visitAndValidate(el, J.Modifier.class, p)); - ListUtils.map(scopedVariableDeclarations.getVariables(), el -> visitAndValidate(el, J.class, p)); + ListUtils.map(scopedVariableDeclarations.getModifiers(), el -> visitAndValidateNonNull(el, J.Modifier.class, p)); + ListUtils.map(scopedVariableDeclarations.getVariables(), el -> visitAndValidateNonNull(el, J.class, p)); return scopedVariableDeclarations; } @Override public JS.StatementExpression visitStatementExpression(JS.StatementExpression statementExpression, P p) { - visitAndValidate(statementExpression.getStatement(), Statement.class, p); + visitAndValidateNonNull(statementExpression.getStatement(), Statement.class, p); return statementExpression; } @@ -211,21 +221,21 @@ public JS.StatementExpression visitStatementExpression(JS.StatementExpression st public JS.TaggedTemplateExpression visitTaggedTemplateExpression(JS.TaggedTemplateExpression taggedTemplateExpression, P p) { visitAndValidate(taggedTemplateExpression.getTag(), Expression.class, p); visitAndValidate(taggedTemplateExpression.getTypeArguments(), Expression.class, p); - visitAndValidate(taggedTemplateExpression.getTemplateExpression(), JS.TemplateExpression.class, p); + visitAndValidateNonNull(taggedTemplateExpression.getTemplateExpression(), JS.TemplateExpression.class, p); return taggedTemplateExpression; } @Override public JS.TemplateExpression visitTemplateExpression(JS.TemplateExpression templateExpression, P p) { - visitAndValidate(templateExpression.getHead(), J.Literal.class, p); - ListUtils.map(templateExpression.getTemplateSpans(), el -> visitAndValidate(el, JS.TemplateExpression.TemplateSpan.class, p)); + visitAndValidateNonNull(templateExpression.getHead(), J.Literal.class, p); + ListUtils.map(templateExpression.getTemplateSpans(), el -> visitAndValidateNonNull(el, JS.TemplateExpression.TemplateSpan.class, p)); return templateExpression; } @Override public JS.TemplateExpression.TemplateSpan visitTemplateExpressionTemplateSpan(JS.TemplateExpression.TemplateSpan templateSpan, P p) { - visitAndValidate(templateSpan.getExpression(), J.class, p); - visitAndValidate(templateSpan.getTail(), J.Literal.class, p); + visitAndValidateNonNull(templateSpan.getExpression(), J.class, p); + visitAndValidateNonNull(templateSpan.getTail(), J.Literal.class, p); return templateSpan; } @@ -237,59 +247,59 @@ public JS.Tuple visitTuple(JS.Tuple tuple, P p) { @Override public JS.TypeDeclaration visitTypeDeclaration(JS.TypeDeclaration typeDeclaration, P p) { - ListUtils.map(typeDeclaration.getModifiers(), el -> visitAndValidate(el, J.Modifier.class, p)); - visitAndValidate(typeDeclaration.getName(), J.Identifier.class, p); + ListUtils.map(typeDeclaration.getModifiers(), el -> visitAndValidateNonNull(el, J.Modifier.class, p)); + visitAndValidateNonNull(typeDeclaration.getName(), J.Identifier.class, p); visitAndValidate(typeDeclaration.getTypeParameters(), J.TypeParameters.class, p); - visitAndValidate(typeDeclaration.getInitializer(), Expression.class, p); + visitAndValidateNonNull(typeDeclaration.getInitializer(), Expression.class, p); return typeDeclaration; } @Override public JS.TypeOf visitTypeOf(JS.TypeOf typeOf, P p) { - visitAndValidate(typeOf.getExpression(), Expression.class, p); + visitAndValidateNonNull(typeOf.getExpression(), Expression.class, p); return typeOf; } @Override public JS.TypeQuery visitTypeQuery(JS.TypeQuery typeQuery, P p) { - visitAndValidate(typeQuery.getTypeExpression(), TypeTree.class, p); + visitAndValidateNonNull(typeQuery.getTypeExpression(), TypeTree.class, p); return typeQuery; } @Override public JS.TypeOperator visitTypeOperator(JS.TypeOperator typeOperator, P p) { - visitAndValidate(typeOperator.getExpression(), Expression.class, p); + visitAndValidateNonNull(typeOperator.getExpression(), Expression.class, p); return typeOperator; } @Override public JS.TypePredicate visitTypePredicate(JS.TypePredicate typePredicate, P p) { - visitAndValidate(typePredicate.getParameterName(), J.Identifier.class, p); + visitAndValidateNonNull(typePredicate.getParameterName(), J.Identifier.class, p); visitAndValidate(typePredicate.getExpression(), Expression.class, p); return typePredicate; } @Override public JS.Unary visitUnary(JS.Unary unary, P p) { - visitAndValidate(unary.getExpression(), Expression.class, p); + visitAndValidateNonNull(unary.getExpression(), Expression.class, p); return unary; } @Override public JS.Union visitUnion(JS.Union union, P p) { - ListUtils.map(union.getTypes(), el -> visitAndValidate(el, Expression.class, p)); + ListUtils.map(union.getTypes(), el -> visitAndValidateNonNull(el, Expression.class, p)); return union; } @Override public JS.Intersection visitIntersection(JS.Intersection intersection, P p) { - ListUtils.map(intersection.getTypes(), el -> visitAndValidate(el, Expression.class, p)); + ListUtils.map(intersection.getTypes(), el -> visitAndValidateNonNull(el, Expression.class, p)); return intersection; } @Override public JS.Void visitVoid(JS.Void void_, P p) { - visitAndValidate(void_.getExpression(), Expression.class, p); + visitAndValidateNonNull(void_.getExpression(), Expression.class, p); return void_; } @@ -301,33 +311,33 @@ public JS.Yield visitYield(JS.Yield yield, P p) { @Override public JS.TypeInfo visitTypeInfo(JS.TypeInfo typeInfo, P p) { - visitAndValidate(typeInfo.getTypeIdentifier(), TypeTree.class, p); + visitAndValidateNonNull(typeInfo.getTypeIdentifier(), TypeTree.class, p); return typeInfo; } @Override public JS.JSVariableDeclarations visitJSVariableDeclarations(JS.JSVariableDeclarations jSVariableDeclarations, P p) { - ListUtils.map(jSVariableDeclarations.getLeadingAnnotations(), el -> visitAndValidate(el, J.Annotation.class, p)); - ListUtils.map(jSVariableDeclarations.getModifiers(), el -> visitAndValidate(el, J.Modifier.class, p)); + ListUtils.map(jSVariableDeclarations.getLeadingAnnotations(), el -> visitAndValidateNonNull(el, J.Annotation.class, p)); + ListUtils.map(jSVariableDeclarations.getModifiers(), el -> visitAndValidateNonNull(el, J.Modifier.class, p)); visitAndValidate(jSVariableDeclarations.getTypeExpression(), TypeTree.class, p); - ListUtils.map(jSVariableDeclarations.getVariables(), el -> visitAndValidate(el, JS.JSVariableDeclarations.JSNamedVariable.class, p)); + ListUtils.map(jSVariableDeclarations.getVariables(), el -> visitAndValidateNonNull(el, JS.JSVariableDeclarations.JSNamedVariable.class, p)); return jSVariableDeclarations; } @Override public JS.JSVariableDeclarations.JSNamedVariable visitJSVariableDeclarationsJSNamedVariable(JS.JSVariableDeclarations.JSNamedVariable jSNamedVariable, P p) { - visitAndValidate(jSNamedVariable.getName(), Expression.class, p); + visitAndValidateNonNull(jSNamedVariable.getName(), Expression.class, p); visitAndValidate(jSNamedVariable.getInitializer(), Expression.class, p); return jSNamedVariable; } @Override public JS.JSMethodDeclaration visitJSMethodDeclaration(JS.JSMethodDeclaration jSMethodDeclaration, P p) { - ListUtils.map(jSMethodDeclaration.getLeadingAnnotations(), el -> visitAndValidate(el, J.Annotation.class, p)); - ListUtils.map(jSMethodDeclaration.getModifiers(), el -> visitAndValidate(el, J.Modifier.class, p)); + ListUtils.map(jSMethodDeclaration.getLeadingAnnotations(), el -> visitAndValidateNonNull(el, J.Annotation.class, p)); + ListUtils.map(jSMethodDeclaration.getModifiers(), el -> visitAndValidateNonNull(el, J.Modifier.class, p)); visitAndValidate(jSMethodDeclaration.getTypeParameters(), J.TypeParameters.class, p); visitAndValidate(jSMethodDeclaration.getReturnTypeExpression(), TypeTree.class, p); - visitAndValidate(jSMethodDeclaration.getName(), Expression.class, p); + visitAndValidateNonNull(jSMethodDeclaration.getName(), Expression.class, p); visitAndValidate(jSMethodDeclaration.getParameters(), Statement.class, p); visitAndValidate(jSMethodDeclaration.getThrowz(), NameTree.class, p); visitAndValidate(jSMethodDeclaration.getBody(), J.Block.class, p); @@ -337,55 +347,55 @@ public JS.JSMethodDeclaration visitJSMethodDeclaration(JS.JSMethodDeclaration jS @Override public JS.JSForOfLoop visitJSForOfLoop(JS.JSForOfLoop jSForOfLoop, P p) { - visitAndValidate(jSForOfLoop.getControl(), JS.JSForInOfLoopControl.class, p); - visitAndValidate(jSForOfLoop.getBody(), Statement.class, p); + visitAndValidateNonNull(jSForOfLoop.getControl(), JS.JSForInOfLoopControl.class, p); + visitAndValidateNonNull(jSForOfLoop.getBody(), Statement.class, p); return jSForOfLoop; } @Override public JS.JSForInLoop visitJSForInLoop(JS.JSForInLoop jSForInLoop, P p) { - visitAndValidate(jSForInLoop.getControl(), JS.JSForInOfLoopControl.class, p); - visitAndValidate(jSForInLoop.getBody(), Statement.class, p); + visitAndValidateNonNull(jSForInLoop.getControl(), JS.JSForInOfLoopControl.class, p); + visitAndValidateNonNull(jSForInLoop.getBody(), Statement.class, p); return jSForInLoop; } @Override public JS.JSForInOfLoopControl visitJSForInOfLoopControl(JS.JSForInOfLoopControl jSForInOfLoopControl, P p) { - visitAndValidate(jSForInOfLoopControl.getVariable(), J.class, p); - visitAndValidate(jSForInOfLoopControl.getIterable(), Expression.class, p); + visitAndValidateNonNull(jSForInOfLoopControl.getVariable(), J.class, p); + visitAndValidateNonNull(jSForInOfLoopControl.getIterable(), Expression.class, p); return jSForInOfLoopControl; } @Override public JS.NamespaceDeclaration visitNamespaceDeclaration(JS.NamespaceDeclaration namespaceDeclaration, P p) { - ListUtils.map(namespaceDeclaration.getModifiers(), el -> visitAndValidate(el, J.Modifier.class, p)); - visitAndValidate(namespaceDeclaration.getName(), Expression.class, p); - visitAndValidate(namespaceDeclaration.getBody(), J.Block.class, p); + ListUtils.map(namespaceDeclaration.getModifiers(), el -> visitAndValidateNonNull(el, J.Modifier.class, p)); + visitAndValidateNonNull(namespaceDeclaration.getName(), Expression.class, p); + visitAndValidateNonNull(namespaceDeclaration.getBody(), J.Block.class, p); return namespaceDeclaration; } @Override public JS.FunctionDeclaration visitFunctionDeclaration(JS.FunctionDeclaration functionDeclaration, P p) { - ListUtils.map(functionDeclaration.getModifiers(), el -> visitAndValidate(el, J.Modifier.class, p)); - visitAndValidate(functionDeclaration.getName(), J.Identifier.class, p); + ListUtils.map(functionDeclaration.getModifiers(), el -> visitAndValidateNonNull(el, J.Modifier.class, p)); + visitAndValidateNonNull(functionDeclaration.getName(), J.Identifier.class, p); visitAndValidate(functionDeclaration.getTypeParameters(), J.TypeParameters.class, p); visitAndValidate(functionDeclaration.getParameters(), Statement.class, p); visitAndValidate(functionDeclaration.getReturnTypeExpression(), TypeTree.class, p); - visitAndValidate(functionDeclaration.getBody(), J.class, p); + visitAndValidateNonNull(functionDeclaration.getBody(), J.class, p); return functionDeclaration; } @Override public JS.TypeLiteral visitTypeLiteral(JS.TypeLiteral typeLiteral, P p) { - visitAndValidate(typeLiteral.getMembers(), J.Block.class, p); + visitAndValidateNonNull(typeLiteral.getMembers(), J.Block.class, p); return typeLiteral; } @Override public JS.IndexSignatureDeclaration visitIndexSignatureDeclaration(JS.IndexSignatureDeclaration indexSignatureDeclaration, P p) { - ListUtils.map(indexSignatureDeclaration.getModifiers(), el -> visitAndValidate(el, J.Modifier.class, p)); + ListUtils.map(indexSignatureDeclaration.getModifiers(), el -> visitAndValidateNonNull(el, J.Modifier.class, p)); visitAndValidate(indexSignatureDeclaration.getParameters(), J.class, p); - visitAndValidate(indexSignatureDeclaration.getTypeExpression(), Expression.class, p); + visitAndValidateNonNull(indexSignatureDeclaration.getTypeExpression(), Expression.class, p); return indexSignatureDeclaration; } @@ -398,14 +408,14 @@ public JS.ArrayBindingPattern visitArrayBindingPattern(JS.ArrayBindingPattern ar @Override public JS.BindingElement visitBindingElement(JS.BindingElement bindingElement, P p) { visitAndValidate(bindingElement.getPropertyName(), Expression.class, p); - visitAndValidate(bindingElement.getName(), TypedTree.class, p); + visitAndValidateNonNull(bindingElement.getName(), TypedTree.class, p); visitAndValidate(bindingElement.getInitializer(), Expression.class, p); return bindingElement; } @Override public JS.ExportDeclaration visitExportDeclaration(JS.ExportDeclaration exportDeclaration, P p) { - ListUtils.map(exportDeclaration.getModifiers(), el -> visitAndValidate(el, J.Modifier.class, p)); + ListUtils.map(exportDeclaration.getModifiers(), el -> visitAndValidateNonNull(el, J.Modifier.class, p)); visitAndValidate(exportDeclaration.getExportClause(), Expression.class, p); visitAndValidate(exportDeclaration.getModuleSpecifier(), Expression.class, p); return exportDeclaration; @@ -413,7 +423,7 @@ public JS.ExportDeclaration visitExportDeclaration(JS.ExportDeclaration exportDe @Override public JS.ExportAssignment visitExportAssignment(JS.ExportAssignment exportAssignment, P p) { - ListUtils.map(exportAssignment.getModifiers(), el -> visitAndValidate(el, J.Modifier.class, p)); + ListUtils.map(exportAssignment.getModifiers(), el -> visitAndValidateNonNull(el, J.Modifier.class, p)); visitAndValidate(exportAssignment.getExpression(), Expression.class, p); return exportAssignment; } @@ -426,89 +436,95 @@ public JS.NamedExports visitNamedExports(JS.NamedExports namedExports, P p) { @Override public JS.ExportSpecifier visitExportSpecifier(JS.ExportSpecifier exportSpecifier, P p) { - visitAndValidate(exportSpecifier.getSpecifier(), Expression.class, p); + visitAndValidateNonNull(exportSpecifier.getSpecifier(), Expression.class, p); return exportSpecifier; } @Override public JS.IndexedAccessType visitIndexedAccessType(JS.IndexedAccessType indexedAccessType, P p) { - visitAndValidate(indexedAccessType.getObjectType(), TypeTree.class, p); - visitAndValidate(indexedAccessType.getIndexType(), TypeTree.class, p); + visitAndValidateNonNull(indexedAccessType.getObjectType(), TypeTree.class, p); + visitAndValidateNonNull(indexedAccessType.getIndexType(), TypeTree.class, p); return indexedAccessType; } @Override public JS.IndexedAccessType.IndexType visitIndexedAccessTypeIndexType(JS.IndexedAccessType.IndexType indexType, P p) { - visitAndValidate(indexType.getElement(), TypeTree.class, p); + visitAndValidateNonNull(indexType.getElement(), TypeTree.class, p); return indexType; } @Override public JS.JsAssignmentOperation visitJsAssignmentOperation(JS.JsAssignmentOperation jsAssignmentOperation, P p) { - visitAndValidate(jsAssignmentOperation.getVariable(), Expression.class, p); - visitAndValidate(jsAssignmentOperation.getAssignment(), Expression.class, p); + visitAndValidateNonNull(jsAssignmentOperation.getVariable(), Expression.class, p); + visitAndValidateNonNull(jsAssignmentOperation.getAssignment(), Expression.class, p); return jsAssignmentOperation; } + @Override + public JS.TypeTreeExpression visitTypeTreeExpression(JS.TypeTreeExpression typeTreeExpression, P p) { + visitAndValidateNonNull(typeTreeExpression.getExpression(), Expression.class, p); + return typeTreeExpression; + } + @Override public J.AnnotatedType visitAnnotatedType(J.AnnotatedType annotatedType, P p) { - ListUtils.map(annotatedType.getAnnotations(), el -> visitAndValidate(el, J.Annotation.class, p)); - visitAndValidate(annotatedType.getTypeExpression(), TypeTree.class, p); + ListUtils.map(annotatedType.getAnnotations(), el -> visitAndValidateNonNull(el, J.Annotation.class, p)); + visitAndValidateNonNull(annotatedType.getTypeExpression(), TypeTree.class, p); return annotatedType; } @Override public J.Annotation visitAnnotation(J.Annotation annotation, P p) { - visitAndValidate(annotation.getAnnotationType(), NameTree.class, p); + visitAndValidateNonNull(annotation.getAnnotationType(), NameTree.class, p); visitAndValidate(annotation.getArguments(), Expression.class, p); return annotation; } @Override public J.ArrayAccess visitArrayAccess(J.ArrayAccess arrayAccess, P p) { - visitAndValidate(arrayAccess.getIndexed(), Expression.class, p); - visitAndValidate(arrayAccess.getDimension(), J.ArrayDimension.class, p); + visitAndValidateNonNull(arrayAccess.getIndexed(), Expression.class, p); + visitAndValidateNonNull(arrayAccess.getDimension(), J.ArrayDimension.class, p); return arrayAccess; } @Override public J.ArrayType visitArrayType(J.ArrayType arrayType, P p) { - visitAndValidate(arrayType.getElementType(), TypeTree.class, p); - ListUtils.map(arrayType.getAnnotations(), el -> visitAndValidate(el, J.Annotation.class, p)); + visitAndValidateNonNull(arrayType.getElementType(), TypeTree.class, p); + ListUtils.map(arrayType.getAnnotations(), el -> visitAndValidateNonNull(el, J.Annotation.class, p)); return arrayType; } @Override public J.Assert visitAssert(J.Assert assert_, P p) { - visitAndValidate(assert_.getCondition(), Expression.class, p); + visitAndValidateNonNull(assert_.getCondition(), Expression.class, p); visitAndValidate(assert_.getDetail() != null ? assert_.getDetail().getElement() : null, Expression.class, p); return assert_; } @Override public J.Assignment visitAssignment(J.Assignment assignment, P p) { - visitAndValidate(assignment.getVariable(), Expression.class, p); - visitAndValidate(assignment.getAssignment(), Expression.class, p); + visitAndValidateNonNull(assignment.getVariable(), Expression.class, p); + visitAndValidateNonNull(assignment.getAssignment(), Expression.class, p); return assignment; } @Override public J.AssignmentOperation visitAssignmentOperation(J.AssignmentOperation assignmentOperation, P p) { - visitAndValidate(assignmentOperation.getVariable(), Expression.class, p); - visitAndValidate(assignmentOperation.getAssignment(), Expression.class, p); + visitAndValidateNonNull(assignmentOperation.getVariable(), Expression.class, p); + visitAndValidateNonNull(assignmentOperation.getAssignment(), Expression.class, p); return assignmentOperation; } @Override public J.Binary visitBinary(J.Binary binary, P p) { - visitAndValidate(binary.getLeft(), Expression.class, p); - visitAndValidate(binary.getRight(), Expression.class, p); + visitAndValidateNonNull(binary.getLeft(), Expression.class, p); + visitAndValidateNonNull(binary.getRight(), Expression.class, p); return binary; } @Override public J.Block visitBlock(J.Block block, P p) { - ListUtils.map(block.getStatements(), el -> visitAndValidate(el, Statement.class, p)); + ListUtils.map(block.getStatements(), el -> visitAndValidateNonNull(el, Statement.class, p)); return block; } @@ -528,16 +544,16 @@ public J.Case visitCase(J.Case case_, P p) { @Override public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDeclaration, P p) { - ListUtils.map(classDeclaration.getLeadingAnnotations(), el -> visitAndValidate(el, J.Annotation.class, p)); - ListUtils.map(classDeclaration.getModifiers(), el -> visitAndValidate(el, J.Modifier.class, p)); + ListUtils.map(classDeclaration.getLeadingAnnotations(), el -> visitAndValidateNonNull(el, J.Annotation.class, p)); + ListUtils.map(classDeclaration.getModifiers(), el -> visitAndValidateNonNull(el, J.Modifier.class, p)); visit(classDeclaration.getPadding().getKind(), p); - visitAndValidate(classDeclaration.getName(), J.Identifier.class, p); + visitAndValidateNonNull(classDeclaration.getName(), J.Identifier.class, p); visitAndValidate(classDeclaration.getTypeParameters(), J.TypeParameter.class, p); visitAndValidate(classDeclaration.getPrimaryConstructor(), Statement.class, p); visitAndValidate(classDeclaration.getExtends(), TypeTree.class, p); visitAndValidate(classDeclaration.getImplements(), TypeTree.class, p); visitAndValidate(classDeclaration.getPermits(), TypeTree.class, p); - visitAndValidate(classDeclaration.getBody(), J.Block.class, p); + visitAndValidateNonNull(classDeclaration.getBody(), J.Block.class, p); return classDeclaration; } @@ -549,8 +565,8 @@ public J.Continue visitContinue(J.Continue continue_, P p) { @Override public J.DoWhileLoop visitDoWhileLoop(J.DoWhileLoop doWhileLoop, P p) { - visitAndValidate(doWhileLoop.getBody(), Statement.class, p); - visitAndValidate(doWhileLoop.getWhileCondition(), Expression.class, p); + visitAndValidateNonNull(doWhileLoop.getBody(), Statement.class, p); + visitAndValidateNonNull(doWhileLoop.getWhileCondition(), Expression.class, p); return doWhileLoop; } @@ -561,92 +577,92 @@ public J.Empty visitEmpty(J.Empty empty, P p) { @Override public J.EnumValue visitEnumValue(J.EnumValue enumValue, P p) { - ListUtils.map(enumValue.getAnnotations(), el -> visitAndValidate(el, J.Annotation.class, p)); - visitAndValidate(enumValue.getName(), J.Identifier.class, p); + ListUtils.map(enumValue.getAnnotations(), el -> visitAndValidateNonNull(el, J.Annotation.class, p)); + visitAndValidateNonNull(enumValue.getName(), J.Identifier.class, p); visitAndValidate(enumValue.getInitializer(), J.NewClass.class, p); return enumValue; } @Override public J.EnumValueSet visitEnumValueSet(J.EnumValueSet enumValueSet, P p) { - ListUtils.map(enumValueSet.getEnums(), el -> visitAndValidate(el, J.EnumValue.class, p)); + ListUtils.map(enumValueSet.getEnums(), el -> visitAndValidateNonNull(el, J.EnumValue.class, p)); return enumValueSet; } @Override public J.FieldAccess visitFieldAccess(J.FieldAccess fieldAccess, P p) { - visitAndValidate(fieldAccess.getTarget(), Expression.class, p); - visitAndValidate(fieldAccess.getName(), J.Identifier.class, p); + visitAndValidateNonNull(fieldAccess.getTarget(), Expression.class, p); + visitAndValidateNonNull(fieldAccess.getName(), J.Identifier.class, p); return fieldAccess; } @Override public J.ForEachLoop visitForEachLoop(J.ForEachLoop forEachLoop, P p) { - visitAndValidate(forEachLoop.getControl(), J.ForEachLoop.Control.class, p); - visitAndValidate(forEachLoop.getBody(), Statement.class, p); + visitAndValidateNonNull(forEachLoop.getControl(), J.ForEachLoop.Control.class, p); + visitAndValidateNonNull(forEachLoop.getBody(), Statement.class, p); return forEachLoop; } @Override public J.ForEachLoop.Control visitForEachControl(J.ForEachLoop.Control control, P p) { - visitAndValidate(control.getVariable(), J.VariableDeclarations.class, p); - visitAndValidate(control.getIterable(), Expression.class, p); + visitAndValidateNonNull(control.getVariable(), J.VariableDeclarations.class, p); + visitAndValidateNonNull(control.getIterable(), Expression.class, p); return control; } @Override public J.ForLoop visitForLoop(J.ForLoop forLoop, P p) { - visitAndValidate(forLoop.getControl(), J.ForLoop.Control.class, p); - visitAndValidate(forLoop.getBody(), Statement.class, p); + visitAndValidateNonNull(forLoop.getControl(), J.ForLoop.Control.class, p); + visitAndValidateNonNull(forLoop.getBody(), Statement.class, p); return forLoop; } @Override public J.ForLoop.Control visitForControl(J.ForLoop.Control control, P p) { - ListUtils.map(control.getInit(), el -> visitAndValidate(el, Statement.class, p)); - visitAndValidate(control.getCondition(), Expression.class, p); - ListUtils.map(control.getUpdate(), el -> visitAndValidate(el, Statement.class, p)); + ListUtils.map(control.getInit(), el -> visitAndValidateNonNull(el, Statement.class, p)); + visitAndValidateNonNull(control.getCondition(), Expression.class, p); + ListUtils.map(control.getUpdate(), el -> visitAndValidateNonNull(el, Statement.class, p)); return control; } @Override public J.ParenthesizedTypeTree visitParenthesizedTypeTree(J.ParenthesizedTypeTree parenthesizedTypeTree, P p) { - ListUtils.map(parenthesizedTypeTree.getAnnotations(), el -> visitAndValidate(el, J.Annotation.class, p)); - visitAndValidate(parenthesizedTypeTree.getParenthesizedType(), J.Parentheses.class, p); + ListUtils.map(parenthesizedTypeTree.getAnnotations(), el -> visitAndValidateNonNull(el, J.Annotation.class, p)); + visitAndValidateNonNull(parenthesizedTypeTree.getParenthesizedType(), J.Parentheses.class, p); return parenthesizedTypeTree; } @Override public J.Identifier visitIdentifier(J.Identifier identifier, P p) { - ListUtils.map(identifier.getAnnotations(), el -> visitAndValidate(el, J.Annotation.class, p)); + ListUtils.map(identifier.getAnnotations(), el -> visitAndValidateNonNull(el, J.Annotation.class, p)); return identifier; } @Override public J.If visitIf(J.If if_, P p) { - visitAndValidate(if_.getIfCondition(), J.ControlParentheses.class, p); - visitAndValidate(if_.getThenPart(), Statement.class, p); + visitAndValidateNonNull(if_.getIfCondition(), J.ControlParentheses.class, p); + visitAndValidateNonNull(if_.getThenPart(), Statement.class, p); visitAndValidate(if_.getElsePart(), J.If.Else.class, p); return if_; } @Override public J.If.Else visitElse(J.If.Else else_, P p) { - visitAndValidate(else_.getBody(), Statement.class, p); + visitAndValidateNonNull(else_.getBody(), Statement.class, p); return else_; } @Override public J.Import visitImport(J.Import import_, P p) { - visitAndValidate(import_.getQualid(), J.FieldAccess.class, p); + visitAndValidateNonNull(import_.getQualid(), J.FieldAccess.class, p); visitAndValidate(import_.getAlias(), J.Identifier.class, p); return import_; } @Override public J.InstanceOf visitInstanceOf(J.InstanceOf instanceOf, P p) { - visitAndValidate(instanceOf.getExpression(), Expression.class, p); - visitAndValidate(instanceOf.getClazz(), J.class, p); + visitAndValidateNonNull(instanceOf.getExpression(), Expression.class, p); + visitAndValidateNonNull(instanceOf.getClazz(), J.class, p); visitAndValidate(instanceOf.getPattern(), J.class, p); return instanceOf; } @@ -659,15 +675,15 @@ public J.IntersectionType visitIntersectionType(J.IntersectionType intersectionT @Override public J.Label visitLabel(J.Label label, P p) { - visitAndValidate(label.getLabel(), J.Identifier.class, p); - visitAndValidate(label.getStatement(), Statement.class, p); + visitAndValidateNonNull(label.getLabel(), J.Identifier.class, p); + visitAndValidateNonNull(label.getStatement(), Statement.class, p); return label; } @Override public J.Lambda visitLambda(J.Lambda lambda, P p) { visitAndValidate(lambda.getParameters().getParameters(), J.class, p); - visitAndValidate(lambda.getBody(), J.class, p); + visitAndValidateNonNull(lambda.getBody(), J.class, p); return lambda; } @@ -678,16 +694,16 @@ public J.Literal visitLiteral(J.Literal literal, P p) { @Override public J.MemberReference visitMemberReference(J.MemberReference memberReference, P p) { - visitAndValidate(memberReference.getContaining(), Expression.class, p); + visitAndValidateNonNull(memberReference.getContaining(), Expression.class, p); visitAndValidate(memberReference.getTypeParameters(), Expression.class, p); - visitAndValidate(memberReference.getReference(), J.Identifier.class, p); + visitAndValidateNonNull(memberReference.getReference(), J.Identifier.class, p); return memberReference; } @Override public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration methodDeclaration, P p) { - ListUtils.map(methodDeclaration.getLeadingAnnotations(), el -> visitAndValidate(el, J.Annotation.class, p)); - ListUtils.map(methodDeclaration.getModifiers(), el -> visitAndValidate(el, J.Modifier.class, p)); + ListUtils.map(methodDeclaration.getLeadingAnnotations(), el -> visitAndValidateNonNull(el, J.Annotation.class, p)); + ListUtils.map(methodDeclaration.getModifiers(), el -> visitAndValidateNonNull(el, J.Modifier.class, p)); visitAndValidate(methodDeclaration.getPadding().getTypeParameters(), J.TypeParameters.class, p); visitAndValidate(methodDeclaration.getReturnTypeExpression(), TypeTree.class, p); visitAndValidate(methodDeclaration.getParameters(), Statement.class, p); @@ -701,28 +717,28 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration methodDecl public J.MethodInvocation visitMethodInvocation(J.MethodInvocation methodInvocation, P p) { visitAndValidate(methodInvocation.getSelect(), Expression.class, p); visitAndValidate(methodInvocation.getTypeParameters(), Expression.class, p); - visitAndValidate(methodInvocation.getName(), J.Identifier.class, p); + visitAndValidateNonNull(methodInvocation.getName(), J.Identifier.class, p); visitAndValidate(methodInvocation.getArguments(), Expression.class, p); return methodInvocation; } @Override public J.MultiCatch visitMultiCatch(J.MultiCatch multiCatch, P p) { - ListUtils.map(multiCatch.getAlternatives(), el -> visitAndValidate(el, NameTree.class, p)); + ListUtils.map(multiCatch.getAlternatives(), el -> visitAndValidateNonNull(el, NameTree.class, p)); return multiCatch; } @Override public J.NewArray visitNewArray(J.NewArray newArray, P p) { visitAndValidate(newArray.getTypeExpression(), TypeTree.class, p); - ListUtils.map(newArray.getDimensions(), el -> visitAndValidate(el, J.ArrayDimension.class, p)); + ListUtils.map(newArray.getDimensions(), el -> visitAndValidateNonNull(el, J.ArrayDimension.class, p)); visitAndValidate(newArray.getInitializer(), Expression.class, p); return newArray; } @Override public J.ArrayDimension visitArrayDimension(J.ArrayDimension arrayDimension, P p) { - visitAndValidate(arrayDimension.getIndex(), Expression.class, p); + visitAndValidateNonNull(arrayDimension.getIndex(), Expression.class, p); return arrayDimension; } @@ -737,34 +753,34 @@ public J.NewClass visitNewClass(J.NewClass newClass, P p) { @Override public J.NullableType visitNullableType(J.NullableType nullableType, P p) { - ListUtils.map(nullableType.getAnnotations(), el -> visitAndValidate(el, J.Annotation.class, p)); - visitAndValidate(nullableType.getTypeTree(), TypeTree.class, p); + ListUtils.map(nullableType.getAnnotations(), el -> visitAndValidateNonNull(el, J.Annotation.class, p)); + visitAndValidateNonNull(nullableType.getTypeTree(), TypeTree.class, p); return nullableType; } @Override public J.Package visitPackage(J.Package package_, P p) { - visitAndValidate(package_.getExpression(), Expression.class, p); - ListUtils.map(package_.getAnnotations(), el -> visitAndValidate(el, J.Annotation.class, p)); + visitAndValidateNonNull(package_.getExpression(), Expression.class, p); + ListUtils.map(package_.getAnnotations(), el -> visitAndValidateNonNull(el, J.Annotation.class, p)); return package_; } @Override public J.ParameterizedType visitParameterizedType(J.ParameterizedType parameterizedType, P p) { - visitAndValidate(parameterizedType.getClazz(), NameTree.class, p); + visitAndValidateNonNull(parameterizedType.getClazz(), NameTree.class, p); visitAndValidate(parameterizedType.getTypeParameters(), Expression.class, p); return parameterizedType; } @Override public J.Parentheses visitParentheses(J.Parentheses parentheses, P p) { - visitAndValidate(parentheses.getTree(), J.class, p); + visitAndValidateNonNull(parentheses.getTree(), J.class, p); return parentheses; } @Override public J.ControlParentheses visitControlParentheses(J.ControlParentheses controlParentheses, P p) { - visitAndValidate(controlParentheses.getTree(), J.class, p); + visitAndValidateNonNull(controlParentheses.getTree(), J.class, p); return controlParentheses; } @@ -781,103 +797,103 @@ public J.Return visitReturn(J.Return return_, P p) { @Override public J.Switch visitSwitch(J.Switch switch_, P p) { - visitAndValidate(switch_.getSelector(), J.ControlParentheses.class, p); - visitAndValidate(switch_.getCases(), J.Block.class, p); + visitAndValidateNonNull(switch_.getSelector(), J.ControlParentheses.class, p); + visitAndValidateNonNull(switch_.getCases(), J.Block.class, p); return switch_; } @Override public J.SwitchExpression visitSwitchExpression(J.SwitchExpression switchExpression, P p) { - visitAndValidate(switchExpression.getSelector(), J.ControlParentheses.class, p); - visitAndValidate(switchExpression.getCases(), J.Block.class, p); + visitAndValidateNonNull(switchExpression.getSelector(), J.ControlParentheses.class, p); + visitAndValidateNonNull(switchExpression.getCases(), J.Block.class, p); return switchExpression; } @Override public J.Synchronized visitSynchronized(J.Synchronized synchronized_, P p) { - visitAndValidate(synchronized_.getLock(), J.ControlParentheses.class, p); - visitAndValidate(synchronized_.getBody(), J.Block.class, p); + visitAndValidateNonNull(synchronized_.getLock(), J.ControlParentheses.class, p); + visitAndValidateNonNull(synchronized_.getBody(), J.Block.class, p); return synchronized_; } @Override public J.Ternary visitTernary(J.Ternary ternary, P p) { - visitAndValidate(ternary.getCondition(), Expression.class, p); - visitAndValidate(ternary.getTruePart(), Expression.class, p); - visitAndValidate(ternary.getFalsePart(), Expression.class, p); + visitAndValidateNonNull(ternary.getCondition(), Expression.class, p); + visitAndValidateNonNull(ternary.getTruePart(), Expression.class, p); + visitAndValidateNonNull(ternary.getFalsePart(), Expression.class, p); return ternary; } @Override public J.Throw visitThrow(J.Throw throw_, P p) { - visitAndValidate(throw_.getException(), Expression.class, p); + visitAndValidateNonNull(throw_.getException(), Expression.class, p); return throw_; } @Override public J.Try visitTry(J.Try try_, P p) { visitAndValidate(try_.getResources(), J.Try.Resource.class, p); - visitAndValidate(try_.getBody(), J.Block.class, p); - ListUtils.map(try_.getCatches(), el -> visitAndValidate(el, J.Try.Catch.class, p)); + visitAndValidateNonNull(try_.getBody(), J.Block.class, p); + ListUtils.map(try_.getCatches(), el -> visitAndValidateNonNull(el, J.Try.Catch.class, p)); visitAndValidate(try_.getFinally(), J.Block.class, p); return try_; } @Override public J.Try.Resource visitTryResource(J.Try.Resource resource, P p) { - visitAndValidate(resource.getVariableDeclarations(), TypedTree.class, p); + visitAndValidateNonNull(resource.getVariableDeclarations(), TypedTree.class, p); return resource; } @Override public J.Try.Catch visitCatch(J.Try.Catch catch_, P p) { - visitAndValidate(catch_.getParameter(), J.ControlParentheses.class, p); - visitAndValidate(catch_.getBody(), J.Block.class, p); + visitAndValidateNonNull(catch_.getParameter(), J.ControlParentheses.class, p); + visitAndValidateNonNull(catch_.getBody(), J.Block.class, p); return catch_; } @Override public J.TypeCast visitTypeCast(J.TypeCast typeCast, P p) { - visitAndValidate(typeCast.getClazz(), J.ControlParentheses.class, p); - visitAndValidate(typeCast.getExpression(), Expression.class, p); + visitAndValidateNonNull(typeCast.getClazz(), J.ControlParentheses.class, p); + visitAndValidateNonNull(typeCast.getExpression(), Expression.class, p); return typeCast; } @Override public J.TypeParameter visitTypeParameter(J.TypeParameter typeParameter, P p) { - ListUtils.map(typeParameter.getAnnotations(), el -> visitAndValidate(el, J.Annotation.class, p)); - ListUtils.map(typeParameter.getModifiers(), el -> visitAndValidate(el, J.Modifier.class, p)); - visitAndValidate(typeParameter.getName(), Expression.class, p); + ListUtils.map(typeParameter.getAnnotations(), el -> visitAndValidateNonNull(el, J.Annotation.class, p)); + ListUtils.map(typeParameter.getModifiers(), el -> visitAndValidateNonNull(el, J.Modifier.class, p)); + visitAndValidateNonNull(typeParameter.getName(), Expression.class, p); visitAndValidate(typeParameter.getBounds(), TypeTree.class, p); return typeParameter; } @Override public J.Unary visitUnary(J.Unary unary, P p) { - visitAndValidate(unary.getExpression(), Expression.class, p); + visitAndValidateNonNull(unary.getExpression(), Expression.class, p); return unary; } @Override public J.VariableDeclarations visitVariableDeclarations(J.VariableDeclarations variableDeclarations, P p) { - ListUtils.map(variableDeclarations.getLeadingAnnotations(), el -> visitAndValidate(el, J.Annotation.class, p)); - ListUtils.map(variableDeclarations.getModifiers(), el -> visitAndValidate(el, J.Modifier.class, p)); + ListUtils.map(variableDeclarations.getLeadingAnnotations(), el -> visitAndValidateNonNull(el, J.Annotation.class, p)); + ListUtils.map(variableDeclarations.getModifiers(), el -> visitAndValidateNonNull(el, J.Modifier.class, p)); visitAndValidate(variableDeclarations.getTypeExpression(), TypeTree.class, p); - ListUtils.map(variableDeclarations.getVariables(), el -> visitAndValidate(el, J.VariableDeclarations.NamedVariable.class, p)); + ListUtils.map(variableDeclarations.getVariables(), el -> visitAndValidateNonNull(el, J.VariableDeclarations.NamedVariable.class, p)); return variableDeclarations; } @Override public J.VariableDeclarations.NamedVariable visitVariable(J.VariableDeclarations.NamedVariable namedVariable, P p) { - visitAndValidate(namedVariable.getName(), J.Identifier.class, p); + visitAndValidateNonNull(namedVariable.getName(), J.Identifier.class, p); visitAndValidate(namedVariable.getInitializer(), Expression.class, p); return namedVariable; } @Override public J.WhileLoop visitWhileLoop(J.WhileLoop whileLoop, P p) { - visitAndValidate(whileLoop.getCondition(), J.ControlParentheses.class, p); - visitAndValidate(whileLoop.getBody(), Statement.class, p); + visitAndValidateNonNull(whileLoop.getCondition(), J.ControlParentheses.class, p); + visitAndValidateNonNull(whileLoop.getBody(), Statement.class, p); return whileLoop; } @@ -889,13 +905,13 @@ public J.Wildcard visitWildcard(J.Wildcard wildcard, P p) { @Override public J.Yield visitYield(J.Yield yield, P p) { - visitAndValidate(yield.getValue(), Expression.class, p); + visitAndValidateNonNull(yield.getValue(), Expression.class, p); return yield; } @Override public J.Unknown visitUnknown(J.Unknown unknown, P p) { - visitAndValidate(unknown.getSource(), J.Unknown.Source.class, p); + visitAndValidateNonNull(unknown.getSource(), J.Unknown.Source.class, p); return unknown; } 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 6a040463..fbd9d5aa 100644 --- a/rewrite-javascript/src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java +++ b/rewrite-javascript/src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java @@ -83,8 +83,8 @@ public J visitArrowFunction(JS.ArrowFunction arrowFunction, P p) { a = (JS.ArrowFunction) temp; } - a = a.withLeadingAnnotations(ListUtils.map(a.getLeadingAnnotations(), ann -> visitAndCast(ann, p))); - a = a.withModifiers(ListUtils.map(a.getModifiers(), m -> visitAndCast(m, p))); + a = a.withLeadingAnnotations(Objects.requireNonNull(ListUtils.map(a.getLeadingAnnotations(), ann -> visitAndCast(ann, p)))); + a = a.withModifiers(Objects.requireNonNull(ListUtils.map(a.getModifiers(), m -> visitAndCast(m, p)))); a = a.withTypeParameters(visitAndCast(a.getTypeParameters(), p)); a = a.withParameters( @@ -94,9 +94,9 @@ public J visitArrowFunction(JS.ArrowFunction arrowFunction, P p) { ); a = a.withParameters( a.getParameters().getPadding().withParams( - ListUtils.map(a.getParameters().getPadding().getParams(), + Objects.requireNonNull(ListUtils.map(a.getParameters().getPadding().getParams(), param -> visitRightPadded(param, JRightPadded.Location.LAMBDA_PARAM, p) - ) + )) ) ); a = a.withParameters(Objects.requireNonNull(visitAndCast(a.getParameters(), p))); @@ -1066,4 +1066,20 @@ public J visitJsAssignmentOperation(JS.JsAssignmentOperation assignOp, P p) { a = a.withType(visitType(a.getType(), p)); return a; } + + public J visitTypeTreeExpression(JS.TypeTreeExpression typeTreeExpression, P p) { + JS.TypeTreeExpression a = typeTreeExpression; + a = a.withPrefix(visitSpace(a.getPrefix(), JsSpace.Location.TYPE_TREE_EXPRESSION_PREFIX, p)); + a = a.withMarkers(visitMarkers(a.getMarkers(), p)); + Expression temp = (Expression) visitExpression(a, p); + if (!(temp instanceof JS.TypeTreeExpression)) { + return temp; + } else { + a = (JS.TypeTreeExpression) temp; + } + + a = a.withExpression(Objects.requireNonNull(visitAndCast(a.getExpression(), p))); + a = a.withType(visitType(a.getType(), p)); + return a; + } } 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 ab8ea7fd..73939288 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 @@ -320,39 +320,6 @@ public J visitJsBinary(JS.JsBinary binary, PrintOutputCapture

p) { public J visitJsAssignmentOperation(JS.JsAssignmentOperation assignOp, PrintOutputCapture

p) { String keyword = ""; switch (assignOp.getOperator()) { -// case Addition: -// keyword = "+="; -// break; -// case Subtraction: -// keyword = "-="; -// break; -// case Multiplication: -// keyword = "*="; -// break; -// case Division: -// keyword = "/="; -// break; -// case Modulo: -// keyword = "%="; -// break; -// case BitAnd: -// keyword = "&="; -// break; -// case BitOr: -// keyword = "|="; -// break; -// case BitXor: -// keyword = "^="; -// break; -// case LeftShift: -// keyword = "<<="; -// break; -// case RightShift: -// keyword = ">>="; -// break; -// case UnsignedRightShift: -// keyword = ">>>="; -// break; case QuestionQuestion: keyword = "??="; break; @@ -372,6 +339,14 @@ public J visitJsAssignmentOperation(JS.JsAssignmentOperation assignOp, PrintOutp return assignOp; } + @Override + public J visitTypeTreeExpression(JS.TypeTreeExpression typeTreeExpression, PrintOutputCapture

p) { + beforeSyntax(typeTreeExpression, JsSpace.Location.TYPE_TREE_EXPRESSION_PREFIX, p); + visit(typeTreeExpression.getExpression(), p); + afterSyntax(typeTreeExpression, p); + return typeTreeExpression; + } + @Override public J visitPropertyAssignment(JS.PropertyAssignment propertyAssignment, PrintOutputCapture

p) { beforeSyntax(propertyAssignment, JsSpace.Location.PROPERTY_ASSIGNMENT_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 38abc781..ad2bafa6 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 @@ -4814,4 +4814,45 @@ public JsAssignmentOperation withOperator(JLeftPadded J acceptJavaScript(JavaScriptVisitor

v, P p) { + return v.visitTypeTreeExpression(this, p); + } + + @Override + @Transient + public CoordinateBuilder.Expression getCoordinates() { + return new CoordinateBuilder.Expression(this); + } + } } 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 4942c27f..d992bc12 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 @@ -151,5 +151,6 @@ public enum Location { ASSIGNMENT_OPERATION_PREFIX, ASSIGNMENT_OPERATION_OPERATOR_PREFIX, ASSIGNMENT_OPERATION_OPERATOR, + TYPE_TREE_EXPRESSION_PREFIX, } }