antlr / intellij-plugin-v4

An IntelliJ plugin for ANTLR v4
https://plugins.jetbrains.com/plugin/7358-antlr-v4
BSD 3-Clause "New" or "Revised" License
462 stars 103 forks source link

The generator should allow more control over the target folder structure #314

Open nekomatic opened 7 years ago

nekomatic commented 7 years ago

When the 'Package/namespace for the generated code' is set in 'Per file ANTLR configuration' the generator creates package folder structure which is not desirable when working i.e with C# target. Apart from current behavour I need the generator to be able to:

ccleve commented 7 years ago

Yes, we need more control over the output directory. See also #306.

I want to put my .g4 files in the main java source tree and put the generated files in a subpackage. For example, the .g4 file goes in com.foo.parsers, and the output goes in com.foo.parsers.generated. This is the correct way to do it if you want to keep generated files separate from source files, want to keep all your code together in the same neighborhood, want your generated .java files to be in a proper java source directory, and keep everything in version control.

With the current plugin this is impossible. If you say the output is ./src/main/java, it puts it in the same directory as the .g4. It doesn't look at the @header { package } option to locate the correct output directory.

It is a very, very bad idea to put the output in /target/generated-sources, because then they don't get versioned, and the source doesn't end up in the source .jar attachment, which makes debugging by third parties impossible.

It's also a bad idea to put it in /gen because this is a non-standard directory structure, doesn't work well with Maven, and forces you to add a new source directory in your IDE. If people clone your project and try to build it, it fails.

Consider having the plugin look at the @header { package } option and put the generated files in the correct directory.

Consider also having the configuration dialog use a directory relative to the project or to the source file.