codemod/spring7-requestcontext-jstl-present
Rename Java references to Spring Web MVC RequestContext.jstPresent so they use RequestContext.JSTL_PRESENT for Spring Framework 7.
# @codemod/spring7-requestcontext-jstl-present
Rename Java references to Spring Web MVC `RequestContext.jstPresent` so they use `RequestContext.JSTL_PRESENT` for Spring Framework 7.
## Installation
```bash
# Install from registry
codemod run @codemod/spring7-requestcontext-jstl-present
# Or run locally
pnpm dlx codemod@latest workflow run -w . --target <path-to-your-repo>
```
## Usage
This codemod targets Java source files and renames only AST-backed member references that can be confidently matched to Spring's `org.springframework.web.servlet.support.RequestContext.jstPresent` field.
It rewrites:
- `RequestContext.jstPresent` when `RequestContext` is imported from Spring Web MVC
- `org.springframework.web.servlet.support.RequestContext.jstPresent`
- `SomeSubclass.jstPresent` when `SomeSubclass` is a uniquely resolvable in-file subclass of Spring's `RequestContext`
- inherited bare accesses like `jstPresent`, `this.jstPresent`, and `super.jstPresent` inside confidently resolvable subclasses, including nested, local, and anonymous classes
- exact static imports of `org.springframework.web.servlet.support.RequestContext.jstPresent` and matching bare usages
It does not rewrite:
- string literals, comments, Javadoc, or reflection strings like `"jstPresent"`
- unrelated classes or user-defined fields named `jstPresent`
- ambiguous bare identifiers when the enclosing class hierarchy or symbol target cannot be resolved conservatively from the current file
- non-Java files
By default the workflow excludes common generated-source directories. To include them, run the workflow with `--param includeGeneratedSources=true`.
Examples:
```java
boolean available = RequestContext.jstPresent;
```
becomes:
```java
boolean available = RequestContext.JSTL_PRESENT;
```
```java
import static org.springframework.web.servlet.support.RequestContext.jstPresent;
class A {
boolean f() {
return jstPresent;
}
}
```
becomes:
```java
import static org.springframework.web.servlet.support.RequestContext.JSTL_PRESENT;
class A {
boolean f() {
return JSTL_PRESENT;
}
}
```
## Development
```bash
# Test the transformation
pnpm test
# Typecheck the codemod
pnpm check-types
# Validate the package and workflow
pnpm dlx codemod@latest workflow validate -w .
# Publish to registry
codemod login
codemod publish
```
## License
MIT