diff --git a/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptSenderReceiverProvider.java b/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptSenderReceiverProvider.java index 0a2426f6..2c8393d2 100644 --- a/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptSenderReceiverProvider.java +++ b/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptSenderReceiverProvider.java @@ -20,6 +20,7 @@ import org.openrewrite.remote.Receiver; import org.openrewrite.remote.Sender; import org.openrewrite.remote.SenderReceiverProvider; +import org.openrewrite.remote.Validator; @AutoService(SenderReceiverProvider.class) public class JavaScriptSenderReceiverProvider implements SenderReceiverProvider { @@ -37,4 +38,9 @@ public Sender newSender() { public Receiver newReceiver() { return new JavaScriptReceiver(); } + + @Override + public Validator newValidator() { + return Validator.fromVisitor(new JavaScriptValidator<>()); + } } diff --git a/rewrite-javascript/src/main/java/org/openrewrite/javascript/JavaScriptValidator.java b/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptValidator.java similarity index 98% rename from rewrite-javascript/src/main/java/org/openrewrite/javascript/JavaScriptValidator.java rename to rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptValidator.java index e3cbd294..ced300da 100644 --- a/rewrite-javascript/src/main/java/org/openrewrite/javascript/JavaScriptValidator.java +++ b/rewrite-javascript-remote/src/main/java/org/openrewrite/javascript/remote/JavaScriptValidator.java @@ -20,13 +20,17 @@ * the code is regenerated. */ -package org.openrewrite.javascript; +package org.openrewrite.javascript.remote; import org.jspecify.annotations.Nullable; -import org.openrewrite.Tree; +import org.openrewrite.*; import org.openrewrite.internal.ListUtils; +import org.openrewrite.marker.Markers; +import org.openrewrite.tree.*; +import org.openrewrite.java.JavaVisitor; import org.openrewrite.java.tree.*; -import org.openrewrite.javascript.tree.JS; +import org.openrewrite.javascript.JavaScriptIsoVisitor; +import org.openrewrite.javascript.tree.*; import java.util.List; @@ -34,7 +38,7 @@ class JavaScriptValidator

extends JavaScriptIsoVisitor

{ private @Nullable T visitAndValidate(@Nullable T tree, Class expected, P p) { if (tree != null && !expected.isInstance(tree)) { - throw new IllegalStateException("Type " + tree.getClass() + " is not assignable to " + expected); + throw new ClassCastException("Type " + tree.getClass() + " is not assignable to " + expected); } // noinspection unchecked return (T) visit(tree, p); diff --git a/rewrite-javascript/src/main/java/org/openrewrite/javascript/JavaScriptParser.java b/rewrite-javascript/src/main/java/org/openrewrite/javascript/JavaScriptParser.java index 3e7a0e19..112f0e80 100644 --- a/rewrite-javascript/src/main/java/org/openrewrite/javascript/JavaScriptParser.java +++ b/rewrite-javascript/src/main/java/org/openrewrite/javascript/JavaScriptParser.java @@ -25,6 +25,7 @@ import org.openrewrite.remote.RemotingContext; import org.openrewrite.remote.RemotingExecutionContextView; import org.openrewrite.remote.RemotingMessenger; +import org.openrewrite.remote.Validator; import org.openrewrite.remote.java.RemotingClient; import org.openrewrite.style.NamedStyles; import org.openrewrite.text.PlainTextParser; @@ -135,13 +136,14 @@ public Stream parseInputs(Iterable inputs, @Nullable Path rel } private SourceFile validate(JS.CompilationUnit sourceFile, Input input, @Nullable Path relativeTo, ExecutionContext ctx) { - JavaScriptValidator typeValidator = new JavaScriptValidator<>(); + assert remotingContext != null; + Validator validator = remotingContext.getProvider(sourceFile.getClass()).newValidator(); try { - typeValidator.visit(sourceFile, 0); - return requirePrintEqualsInput(sourceFile, input, relativeTo, ctx); + validator.validate(sourceFile, ctx); } catch (Exception e) { return ParseError.build(this, input, relativeTo, ctx, new IllegalStateException("LST model has type validation errors", e)); } + return requirePrintEqualsInput(sourceFile, input, relativeTo, ctx); } private final static List EXTENSIONS = Collections.unmodifiableList(Arrays.asList(