generator icon indicating copy to clipboard operation
generator copied to clipboard

TopLevelEnumeration and eclipse generator merge, getting "No types defined in the file"

Open dldeveloper21 opened this issue 8 years ago • 9 comments

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.

dldeveloper21 avatar Aug 22 '16 19:08 dldeveloper21

Thanks for reporting. I'll take a look at this.

jeffgbutler avatar Aug 23 '16 00:08 jeffgbutler

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!

jeffgbutler avatar Aug 24 '16 00:08 jeffgbutler

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.

dldeveloper21 avatar Aug 24 '16 14:08 dldeveloper21

You could script that with Ant. In eclipse the generator is using Ant under the covers anyway, so no loss of function there.

jeffgbutler avatar Aug 24 '16 14:08 jeffgbutler

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.

dldeveloper21 avatar Aug 24 '16 18:08 dldeveloper21

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

<>.metadata.plugins\org.mybatis.generator.eclipse.ui.generatedAntScripts

jeffgbutler avatar Aug 24 '16 21:08 jeffgbutler

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.

dldeveloper21 avatar Aug 25 '16 15:08 dldeveloper21

I'm also getting the same problem with enum generation, and would appreciate a fix. Thanks.

afielden avatar Sep 12 '16 13:09 afielden

I'm working on it. I am building a test strategy for this code before I start mucking around in it.

jeffgbutler avatar Sep 13 '16 13:09 jeffgbutler