openrewrite / rewrite

Automated mass refactoring of source code.

Home Page:https://docs.openrewrite.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

There were problems parsing Inner Class

Jnb1234 opened this issue · comments

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?

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
        }
    }
}