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

Support for inner classes in Groovy #4063

Closed
Jnb1234 opened this issue Mar 1, 2024 · 1 comment · Fixed by #4825
Closed

Support for inner classes in Groovy #4063

Jnb1234 opened this issue Mar 1, 2024 · 1 comment · Fixed by #4825
Assignees
Labels
bug Something isn't working parser-groovy

Comments

@Jnb1234
Copy link

Jnb1234 commented Mar 1, 2024

What version of OpenRewrite are you using?

I am using id 'org.openrewrite.rewrite' version '6.8.4'

  • Gradle plugin 6.8.4

How are you running OpenRewrite?

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

plugins {
    id 'maven-publish'
    id 'groovy'
    id 'idea'
    id 'net.researchgate.release' version '2.8.1'
    id "com.github.ben-manes.versions" version "0.36.0"
    id "com.gorylenko.gradle-git-properties" version "2.3.2"
    id 'java-library'
    id 'org.openrewrite.rewrite' version '6.8.4'
}
rewrite {
    activeRecipe("org.openrewrite.java.RemoveUnusedImports")
    }

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

package com.gaic.bue.uwd.ra.common.dataaccess

class JnbInnerClassIssue
{

    class ShowParseIssue {
        String a

//        String getA() {
//            return a
//        }

        ShowParseIssue(String a) {
            this.a = a
        }

//Moving getA() before the constructor or after the setter setA(String a) seems to resolve the parsing issue
        String getA() {
            return a
        }

        void setA(String a) {
            this.a = a
        }

//        String getA() {
//            return a
//        }
    }
}

What did you expect to see?

No parsing errors

What did you see instead?

There were problems parsing src\test\java\com\gaic\bue\uwd\ra\common\dataaccess\JnbInnerClassIssue.groovy

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

There were problems parsing some source files, run with --info to see full stack traces
There were problems parsing src\test\java\com\gaic\bue\uwd\ra\common\dataaccess\JnbInnerClassIssue.groovy
Error during rewrite dry run
No further details 

Note there are other groovy classes with parsing issues which I am trying to create small examples since the code is private

Are you interested in contributing a fix to OpenRewrite?

@Jnb1234 Jnb1234 added the bug Something isn't working label Mar 1, 2024
@timtebeek
Copy link
Contributor

Confirmed with a unit test in

class ClassDeclarationTest implements RewriteTest {

@Test
@Issue("https://github.com/openrewrite/rewrite/issues/4063")
void nestedClass() {
    rewriteRun(
      groovy(
        """
          package com.gaic.bue.uwd.ra.common.dataaccess

          class JnbInnerClassIssue{
              class ShowParseIssue {
                  String a
          
                  ShowParseIssue(String a) {
                      this.a = a
                  }
          
                  String getA() {
                      return a
                  }
          
                  void setA(String a) {
                      this.a = a
                  }
              }
          }
          """
      )
    );
}

Which results in

package com.gaic.bue.uwd.ra.common.dataaccess

class JnbInnerClassIssue{
    class ShowParseIssue {
        String a

        ShowParseIssue(String agetAa           this.a = a
        }

        String getA() {
            return a
        }

        void setA(String a) {
            this.a = a
        }
    }
}

@timtebeek timtebeek moved this to Backlog in OpenRewrite Mar 1, 2024
@jevanlingen jevanlingen self-assigned this Dec 31, 2024
@jevanlingen jevanlingen changed the title There were problems parsing Inner Class Support for inner classes in Groovy Dec 31, 2024
@jevanlingen jevanlingen linked a pull request Dec 31, 2024 that will close this issue
3 tasks
@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenRewrite Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parser-groovy
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants