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

ListFirstAndLast skips methodCall().get(0) #423

Closed
timo-abele opened this issue Feb 21, 2024 · 4 comments · Fixed by #424
Closed

ListFirstAndLast skips methodCall().get(0) #423

timo-abele opened this issue Feb 21, 2024 · 4 comments · Fixed by #424
Assignees
Labels
bug Something isn't working

Comments

@timo-abele
Copy link

timo-abele commented Feb 21, 2024

What version of OpenRewrite are you using?

see below

How are you running OpenRewrite?

I am using the Maven plugin, and my project is a single module project.

      <plugin>
        <groupId>org.openrewrite.maven</groupId>
        <artifactId>rewrite-maven-plugin</artifactId>
        <version>5.22.0</version>
        <configuration>
          <activeRecipes>
            <recipe>org.openrewrite.java.migrate.UpgradeToJava21</recipe>
          </activeRecipes>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>org.openrewrite.recipe</groupId>
            <artifactId>rewrite-migrate-java</artifactId>
            <version>2.8.0</version>
          </dependency>
        </dependencies>
      </plugin>

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

class A {
  class Inner {

    @Getter
    private List<String> listOne = new ArrayList<>();

  }

  void getFirst(){
    Inner inner = new Inner();
    inner.getListOne().get(0);
  }
}

It doesn't have to be an inner class, I'm just not sure if a sequence of classes as a string works in tests.

What did you expect to see?

class A {
  class Inner {

    @Getter
    private List<String> listOne = new ArrayList<>();

  }

  void getFirst(){
    Inner inner = new Inner();
    inner.getListOne().getFirst();
  }
}

What did you see instead?

no change

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

stacktrace output here

Are you interested in contributing a fix to OpenRewrite?

@timo-abele timo-abele added the bug Something isn't working label Feb 21, 2024
@timtebeek
Copy link
Contributor

Ah yes those will have missing type information unfortunately, as we don't yet support Lombok annotations:

Not something specific to this recipe, so perhaps best tracked in the above issue.

@timo-abele
Copy link
Author

timo-abele commented Feb 21, 2024

Correction: It's not about lombok! Explicit getters don't work either:

class A{
  class Inner {

    public List<String> getListOne() {
      return listOne;
    }

    private List<String> listOne = new ArrayList<>();

  }

  void getFirst(){
    Inner inner = new Inner();
    inner.getListOne().get(0); //is ignored
    List<String> other = inner.getListOne();
    other.get(0); //is converted

  }

}

Skimming through my code everytime it is converted the pattern is variable.get(0).
And every time it is not converted the pattern is .methodCall().get(0).

@timo-abele timo-abele changed the title ListFirstAndLast skips Lists from a Lombok @Getter ListFirstAndLast skips methodCall().get(0) Feb 21, 2024
@timtebeek
Copy link
Contributor

Ah that's helpful, thanks! We should be able to create a test from your example above and then work out the steps needed to make this work.

@timtebeek
Copy link
Contributor

You're right; there's a strong overfit on the recipe to particular cases; this expands that a bit with more overfit, but we likely can relax the constraints a bit to cover more cases. Thanks for chiming in!

@timtebeek timtebeek self-assigned this Feb 22, 2024
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
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants