dengzii / GenerateModuleFromTemplate

An IntelliJ platform IDEs plugin use for create module from a highly customizable template
50 stars 8 forks source link

[Bug fix request] Files that use Apache Velocity for name generation create empty files instead of mapping to file templates #20

Open iwb-cgalvarez opened 9 months ago

iwb-cgalvarez commented 9 months ago

First of all, I would like to thank you for your reactivity and for implementing the feature requested in our previous issue.

After updating to the latest version of the plugin 1.6.6, we noticed that the splitting of the folders based on the folder name generation through apache velocity works fine now (which is the request feature, thank you for that๐Ÿ™) but the files that use apache velocity create now empty files.

Steps to reproduce

Given the following file template:

Screenshot 2024-02-23 at 15 08 45

Given the following module template:

Screenshot 2024-02-23 at 15 16 40

When I create a module using the file and module templates and the configuration shown below

Screenshot 2024-02-23 at 15 18 20

I want to see the Hello, World! shown in the template but it's empty instead:

Screenshot 2024-02-23 at 15 28 42

Please find attached here the file and module templates to reproduce the issue: module_templates_files.zip

Thank you very much in advance and please don't hesitate to ask if you need further clarifications ๐Ÿ™

dengzii commented 8 months ago

Hello,

whether all file templates are unavailable or this one alone ?

The statement

${StringUtils.removeAndHump(${FEATURE_NAME.replaceAll("[^\w]", "_")})}Module.kt

reported an error when I reproduced the problem, but I tried fix it in v1.6.7.

iwb-cgalvarez commented 8 months ago

Hello,

Thank you for your response. It happens to all the files that use Apache Velocity on the name definition.

dengzii commented 8 months ago

I apologize, but this nested ApacheVelocity statement has been consistently causing errors and preventing file creation on my end. Non-nested structures seem to work fine. Please consider using an alternative approach, such as employing a new placeholder. ๐Ÿ™‡โ€โ™‚๏ธ

iwb-cgalvarez commented 8 months ago

Hello @dengzii,

Thank you for the suggestion. The problem is that placeholders cannot use apache velocity, do they?

This used to work fine before the fix for this issue, so I think the problem is the mapping between the file name using apache velocity between the realChildren and the fileTemplates keys in the moduleTemplate json configuration.

I think the mapping is happening between the result of the apache velocity function on the file names under realChildren against the unprocessed value of the key under fileTemplates.

To give you an example:

Imagine that we have a the module template definition that I posted in the issue:

${StringUtils.removeAndHump(${FEATURE_NAME.replaceAll("[^\w]", "_")})}Module.kt

This same file name definition is used in the file name under the folder example in the screenshot of the issue and under one of the keys under fileTemplates pointing to the file template Example.

I think in the code, when trying to find which file template you need to use, the program is using the processed value of the file (TestDemoModule.kt) against the key which is unprocessed (${StringUtils.removeAndHump(${FEATURE_NAME.replaceAll("[^\w]", "_")})}Module.kt) and they are indeed not equal.

If you are busy, I can try to fix it on my side when I have a bit of time. Would you accept an external pull request?

dengzii commented 8 months ago

Hello! Yes, Iโ€™ve been quite busy lately. Iโ€™ve already considered the points you mentioned. The crucial issue is that the results of running ApacheVelocity statements in unit tests differ from run compile plugin in the IDEA.

This is the code for simulating the parsing of a node tree in unit tests:

image

If you could help fix with this, I would greatly appreciate it. ๐Ÿ˜Š