How does sonar lint figure out the scope of patten variable in java?

I was wondering how sonarLint figures out the scope of pattern variables in java Pattern Matching for instanceof.

I was creating a check similar to UnusedLocalVariable and am stuck on identifying the scope of pattern variable, I checked the code of UnusedLocalVariable in but couldn’t find the logic sonar-

If anyone could point the file where scope recognition is done, it would be great.
By scope resolution I mean-

if(o instanceof String s1) {
// s1 can be accessed over here.

if(!(o instanceof String s1)) {
// s1 cannot be accessed over here.
else {
// s1 can be accessed over here.

I couldn’t find the logic corresponding to scope resolution.