revelc / formatter-maven-plugin

Formatter Maven Plugin
https://code.revelc.net/formatter-maven-plugin
Apache License 2.0
291 stars 91 forks source link

Add support for groovy #132

Open AlexanderZobkov opened 8 years ago

AlexanderZobkov commented 8 years ago

It would be great if the plugin can format sources that contain groovy code as well. Probably DefaultGroovyFormatter from https://github.com/groovy/groovy-eclipse can be used for that purpose: groovy-eclipse/ide/org.codehaus.groovy.eclipse.refactoring/src/org/codehaus/groovy/eclipse/refactoring/formatter/DefaultGroovyFormatter.java

hazendaz commented 8 years ago

Any chance you might be able to build the groovy support and submit a PR?

Get Outlook for Androidhttps://aka.ms/ghei36

On Sun, Aug 21, 2016 at 3:02 AM -0400, "Alexander" notifications@github.com<mailto:notifications@github.com> wrote:

It would be great if the plugin can format sources that contain groovy code as well. Probably DefaultGroovyFormatter from https://github.com/groovy/groovy-eclipse can be used for that purpose: groovy-eclipse/ide/org.codehaus.groovy.eclipse.refactoring/src/org/codehaus/groovy/eclipse/refactoring/formatter/DefaultGroovyFormatter.java

You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/revelc/formatter-maven-plugin/issues/132, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AA7ho-7NhRXm-l_STy1vfS6TU4VQdzYOks5qh_f0gaJpZM4JpPa3.

hazendaz commented 4 years ago

I'm looking into this. First try was to use the java formatter as we have it for java. That really has issues with groovy, mostly due to missing semi colon but also seems to squash weirdly. So it is clear portions of the jdt patch that groovy has is needed. Now I need to look into possibility they released that to central. If not, we may need a module like jdst-core to pull that information and then use that to process groovy. It appears it is just a super set and there is a small subset of additional settings users can choose over the inherited java version.

hazendaz commented 4 years ago

For reference, need this code https://github.com/groovy/groovy-eclipse/tree/9cbb8c65f89f3ce679b1ffe718266bb405e8a408/ide/org.codehaus.groovy.eclipse.refactoring/src/org/codehaus/groovy/eclipse/refactoring/formatter

However, it is not exposed currently.

hazendaz commented 4 years ago

This is likely to be complicated. After much digging, I need patches that groovy-eclipse has but doesn't appear to publish outside of the build. In order for this to work, it needs those groovy patches. I'm not clear really on how eclipse even works with this. More specifically the CompilationUnit class has 2 additional parameters for eclipse only. However it also contains a copy of groovy untouched along with full copy of various patches they are doing. I suspect some strange reflection usage and this is only needed at build time. However, when trying to run a solution similar to what we did with jsdt-core, it fails due to this class being necessary.

So, at the moment, I'm going to try to build out their project and if that works, take the JAR I need and some how integrate that into the solution. Even if this works, it effectively means the entire jdt we use now is a waste. This is a complete copy of it to allow groovy to work. My gut tells me all other languages that run on the jvm are doing something similar and the weight is not really worth it here.

I'll keep looking into this but not expecting that this will end up working. Even if it does, I think maybe it warrants a separate plugin as it is not light weight by any means and seriously high on duplication. This is probalby why upon every eclipse upgrade, groovy has to be uninstalled before the upgrade can work.