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

ast transformation doesn't work in groovy-java project #178

Closed
originalrusyn opened this issue May 11, 2016 · 10 comments
Closed

ast transformation doesn't work in groovy-java project #178

originalrusyn opened this issue May 11, 2016 · 10 comments

Comments

@originalrusyn
Copy link

Can't compile my project

https://github.com/originalrusyn/mix/tree/greclipse

➜  mix git:(greclipse) ✗ mvn clean install
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building mix 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mix ---
[INFO] Deleting /Users/m/git_repo/mix/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mix ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ mix ---
[INFO] Changes detected - recompiling the module!
[INFO] Using Groovy-Eclipse compiler to compile both Java and Groovy files
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /Users/m/git_repo/mix/src/main/java/B.java:[7,1] 1. ERROR in /Users/m/git_repo/mix/src/main/java/B.java (at line 7)
        F.FBuilder builder = F.builder();
        ^^^^^^^^^^
F.FBuilder cannot be resolved to a type

[ERROR] /Users/m/git_repo/mix/src/main/java/B.java:[7,24] 2. ERROR in /Users/m/git_repo/mix/src/main/java/B.java (at line 7)
        F.FBuilder builder = F.builder();
                               ^^^^^^^
The method builder() is undefined for the type F
[ERROR] Found 2 errors and 0 warnings.
[INFO] 3 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.532 s
[INFO] Finished at: 2016-05-11T09:13:09+02:00
[INFO] Final Memory: 13M/76M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project mix: Compilation failure: Compilation failure:
[ERROR] /Users/m/git_repo/mix/src/main/java/B.java:[7,1] 1. ERROR in /Users/m/git_repo/mix/src/main/java/B.java (at line 7)
[ERROR] F.FBuilder builder = F.builder();
[ERROR] ^^^^^^^^^^
[ERROR] F.FBuilder cannot be resolved to a type
[ERROR] 
[ERROR] /Users/m/git_repo/mix/src/main/java/B.java:[7,24] 2. ERROR in /Users/m/git_repo/mix/src/main/java/B.java (at line 7)
[ERROR] F.FBuilder builder = F.builder();
[ERROR] ^^^^^^^
[ERROR] The method builder() is undefined for the type F
[ERROR] 
[ERROR] Found 2 errors and 0 warnings.
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
@eric-milles
Copy link
Member

This type of interoperability is not possible with current Groovy. Even if you compiled with bare groovyc it should fail. AST transforms that add methods late (I think after semantic analysis phase) like @builder, @TupleConstructor, @singleton and many others can only be used within the same project by Groovy sources. Your example would work if you split the builder into a separate project, so the Java source was forced to work with the .class of the builder.

@Blacktiger
Copy link

@eric-milles the groovy docs for @builder indicate that this is supposed to work so should this be considered a compiler bug or a documentation bug?

But if you need Java integration or in some cases improved type safety, the @builder transform might prove very useful.

@eric-milles
Copy link
Member

A lot of transforms like @builder are described in a purely Groovy context. They do certainly work as described Groovy to Groovy. But Groovy to Java interoperability does not work as you may intuit it does. I wish it worked as you described. And there is certainly a path in Groovy-Eclipse to make it work that way. The trouble is if we did something that the vanilla groovyc did not support, there would be a lot of problems.

@Blacktiger
Copy link

@eric-milles thanks, I guess I'll open an issue against the groovy project to fix the documentation then since it specifically suggests using the @builder transform for Java interop.

@eric-milles
Copy link
Member

eric-milles commented Mar 2, 2017 via email

@Blacktiger
Copy link

Thanks @eric-milles, that is one of the options we were considering.

@blackdrag
Copy link
Member

@eric-milles when you say "The trouble is if we did something that the vanilla groovyc did not support, there would be a lot of problems." then I say that it depends if that is trouble or not. I am working, with very low priority, on a compiler that can solve this kind of issue, but this would be also more than pure groovyc can do. And just because of that I don´t consider that compiler trouble.

@eric-milles
Copy link
Member

eric-milles commented Mar 7, 2017 via email

@blackdrag
Copy link
Member

The problem is that our current joint compilation approach solves a lot of problems, but it is not a satisfying solution to me at all.

  • We have to create stubs in which we write unresolved class names for example. It could happen, that Groovy and Java disagree about the meaning here for example.
  • Sometimes the stubs fail compilation because the stubs cannot always contain enough information to make javac happy. Which means the user has to adapt perfectly valid groovy files to satisfy a downstream javac.
  • And the biggest point is the ast transforms issue of course.

All of those I see as solvable doing a tighter integration with something that understands Java source code or can teach a Java compiler some Groovy. So really, if the differing feature is that groovy-eclipse supports transforms better than groovyc for joint compilation I am more than happy... of course only as long the compiler is also supported outside the IDE, yes.

@eric-milles
Copy link
Member

eric-milles commented Mar 7, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants