Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CommonStaticAnalysis recipe does not change calls to getter/setters on camel casing changes. #189

Open
Murtuza24 opened this issue Oct 11, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@Murtuza24
Copy link

What version of OpenRewrite are you using?

I am using

rewrite-static-analysis_ v1.0.8

How are you running OpenRewrite?

I am using the Moderne CLI v 1.1.0.

mod build .
mod run . --recipe=CommonStaticAnalysis
mod apply . --last-recipe-run

What is the smallest, simplest way to reproduce the problem?

// lombok annotation
@Data
class A {
private String variable_name1;
private String variable_name2;
    // do something
}

class B {
  void setAData (){
     A a = new A();
     a.setvariable_name1("some value 1");
     a.setvariable_name2("some value 2");
   }
}

class C {
  void retreiveAData(A a) {
   String data1 = a.getvariable_name1();
   String data2 = a.getvariable_name2();
  }
}

What did you expect to see?

// lombok annotation
@Data
class A {
private String variableName1;
private String variableName2;
    // do something
}

class B {
  void setAData (){
     A a = new A();
     a.setVariableName1("some value 1");
     a.setVariableName2("some value 2");
   }
}

class C {
  void retreiveAData(A a) {
   String data1 = a.getVariableName1();
   String data2 = a.getVariableName2();
  }
}

What did you see instead?

// lombok annotation
@Data
class A {
private String variableName1;
private String variableName2;
    // do something
}

class B {
  void setAData (){
     A a = new A();
     a.setvariable_name1("some value 1");
     a.setvariable_name2("some value 2");
   }
}

class C {
  void retreiveAData(A a) {
   String data1 = a.getvariable_name1();
   String data2 = a.getvariable_name2();
  }
}

What is the full stack trace of any errors you encountered?

There are no errors while running the CommonStaticAnalysis v1.0.8 recipe.

Are you interested in contributing a fix to OpenRewrite?

@timtebeek
Copy link
Contributor

Hi @Murtuza24 ; thanks for the detailed report, and using the Moderne CLI. Sorry to hear to output does not match what you had hoped for; that's down to OpenRewrite not yet supporting Lombok annotations. You can follow along to efforts there in this issue, but it's not an easy case to fix for us, due to the way Lombok is implemented

What we can do however, and would fit in with our principle to "do no harm" is to make the recipe not rename any variables in the presence of lombok annotations. We already have such exceptions elsewhere I believe, and I imagine it would be fairly easy to add here as well.

Would you be open to start a draft pull request for this that adds tests that assert we don't make any changes when lombok annotations are present? That'd be the quickest way to get started on a fix. Such a test would be similar to this one here:

@Test
void doNotRenameUnderscoreNumber() {
rewriteRun(
//language=java
java(
"""
class A {
private boolean _20th;
public boolean method() {
return _20th;
}
}
"""
)
);
}

@timtebeek timtebeek moved this to Backlog in OpenRewrite Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

2 participants