generator
generator copied to clipboard
TopLevelEnumeration and eclipse generator merge, getting "No types defined in the file"
I created a plugin which generates Enum files based on database tables using the method:
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles( IntrospectedTable introspectedTable )
This plugin works perfectly for generating the Enums. However, when the Enums already exist and the eclipse generator tries to merge these files, I'm getting the error "No types defined in the file".
The error is coming from JavaFileMerger.getMergedSource()
. It seems visitor.getTypeDeclaration()
is returning null if it is an Enum. If I change these to be regular java classes, I don't get this error.
Thanks for reporting. I'll take a look at this.
I know what the issue is. The AST visitors work for enums within classes or interfaces, but not top level enums. I never accounted for this case - probably because the generator doesn't produce enums except through plugins like yours. I'll fix it, but it will take a bit of time as I'll have to restructure the visitors. I've been meaning to do that anyway, so this is the motivation!
Thanks for taking a look...we have a workaround by first manually deleting the Enum or Enums for the tables we're re-generating. This is a little tedious so I started looking into whether there was a way for my plugin to delete the Enum file first before generating but haven't been able to successfully do so yet when running through the Eclipse generator.
You could script that with Ant. In eclipse the generator is using Ant under the covers anyway, so no loss of function there.
Thanks for the tip, I'll see if I can get that approach working. The tricky part is that I still need to use the eclipse generator for its merge feature since I need all the Java Model, Mappers, etc... to be merged but only overwrite the Enums being generated by my plugin since the merge is failing on those.
If you use the new launcher to run the generator in eclipse, then it is creating an Ant file and running it in the background. It uses the eclipse enabled Ant task for the generator, so it supports merging. You could use that Ant file as a starting point for building your own (you still need to run Ant in eclipse and in the workspace JRE). You can see the file that gets created in the directory
<
I created my own ant file and used the eclipse enabled Ant task as you suggested and was able to accomplish what I needed (Merging files and deleting the Enums). Thanks again for your help.
I'm also getting the same problem with enum generation, and would appreciate a fix. Thanks.
I'm working on it. I am building a test strategy for this code before I start mucking around in it.