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

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

Open
dldeveloper21 opened this issue Aug 22, 2016 · 9 comments
Assignees

Comments

@dldeveloper21
Copy link

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.

@jeffgbutler
Copy link
Member

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

@jeffgbutler
Copy link
Member

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!

@dldeveloper21
Copy link
Author

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.

@jeffgbutler
Copy link
Member

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

@dldeveloper21
Copy link
Author

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.

@jeffgbutler
Copy link
Member

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

@dldeveloper21
Copy link
Author

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.

@afielden
Copy link

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

@jeffgbutler jeffgbutler self-assigned this Sep 13, 2016
@jeffgbutler
Copy link
Member

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

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

3 participants