openrewrite / openrewrite/rewrite-static-analysis

Enhance InstanceOfPatternMatch to cover method invocations as well

Open
#275 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
62
Forks
112
Avg merge
1d 19h
Merged PRs (30d)
40

Description

What problem are you trying to solve?

I've come across

if (authentication.getPrincipal() instanceof UserDetails) {
    UserDetails springSecurityUser = (UserDetails) authentication.getPrincipal();
    return springSecurityUser.getUsername();
}

which is currently not covered

Describe the solution you'd like

if (authentication.getPrincipal() instanceof UserDetails springSecurityUser) {
    return springSecurityUser.getUsername();
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the InstanceOfPatternMatch recipe and its existing tests, then inspect how it handles instanceof expressions involving local variables. Add coverage for the authentication.getPrincipal() method-invocation example and verify that the transformation produces pattern matching with the bound UserDetails variable.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.