-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
JavaTemplate
engine extensible (#3475)
* Add new `JvmParser` as supertype to `JavaParser` To allow the `JavaTemplate` mechanism to be used for other languages like Kotlin, the provided parser builder must provide a way to add a classpath entry. This is because the internal `__M__` and `__P__` types are required for the parameter substitution and rather than including them as source code in the compilation unit, the parser will load them from the classpath. To this end this PR introduces new `JvmParser` and `JvmParser.Builder` types and the `JavaParser.Builder#classpath()` methods are moved to `JvmParser.Builder`. In order to not increase the API surface area, no corresponding getter was added to `JvmParser.Builder`. Instead, there is a new `Internals` class providing a static `getClasspath(JvmParser.Builder)` method. Issue: openrewrite/rewrite-kotlin#218 * Correct bounds on `JvmParser.Builder` * Make `JvmParser.Builder` constructor protected * No need for initializer block when templating context-free expression * Expose more of `JavaTemplate` engine API for extension * Remove `JvmParser` and `Internals` again * Make `Substitutions` extensible * Lazily initialize `TEMPLATE_CLASSPATH_DIR` at runtime * Add `BlockStatementTemplateGenerator#TEMPLATE_INTERNAL_IMPORTS` * Correction to `Substitutions` after merging * Rename new `addClasspath()` to `classpathEntry()` * Remove unused `JavaTemplate#parameterCount` * Update rewrite-java/src/main/java/org/openrewrite/java/internal/template/__M__.java * Update rewrite-java/src/main/java/org/openrewrite/java/internal/template/__P__.java * Revert accidental visibility change * Fix problem with classpath in `JavaParser.Builder`
- Loading branch information
1 parent
675f9d5
commit 3936ba1
Showing
7 changed files
with
177 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
rewrite-java/src/main/java/org/openrewrite/java/internal/template/__M__.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2023 the original author or authors. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.openrewrite.java.internal.template; | ||
|
||
public class __M__ { | ||
public static native Object any(Object o); | ||
|
||
public static native Object any(java.util.function.Predicate<Boolean> o); | ||
|
||
public static native <T> Object anyT(); | ||
} |
Oops, something went wrong.