microsoft / vscode-java-dependency

Manage Java projects in Visual Studio Code.
https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-dependency
MIT License
152 stars 74 forks source link

Support scaffold Spring Boot components #767

Open jdneo opened 1 year ago

jdneo commented 1 year ago

i.e.

Automatically command palette/modal triggers and ask you for the entity name which will be applied in the following generated files inside they respective folders: Controllers/[EntityNameController.java] || BusinessLogic/Services/ServiceImpl [EntityNameServiceImpl.java] || BusinessLogic/Services/ServiceInterfaces[EntityNameService.java] || Models/Repositories/[EntityNameDao.java] || Models/Entities/[EntityName.java]

Maybe need some integration tasks to do with the spring extension.

BizarreBoy commented 1 year ago

Hi!

Following with the scaffold idea, I would like to attach some screenshots.

In the first picture I created by hand a sample bunch of directories with one file inside each one related to the function they were created for. (Imagine it has been generated with a context menu item named for example "Generate Initial Java Scaffold API" supposing I right-clicked in the named "rest" folder of the following image example):

image

The feature should open a command palette modal and ask to the user what will be the entity name to be applied in any related file generated, for example: SampleNameEntity, SampleNameController, SampleNameService, SampleNameDTO,...

ss02

The initial code by default could be empty methods with the params names replaced by the required entity name from before:

NOTE: In the following pictures you will see default templates generated by the plugin Spring Code Generator developed by the author Sonal Sithara. His plugin saves a lot of time typing general methods and let user focus on the logic development and not in the code structure.

CONTROLLER:

image

SERVICE IMPLEMENTATION:

image

SERVICE INTERFACE:

image

REPOSITORY:

image

ENTITY:

image

RESUME: The idea would be a context menu option which open a command palette modal to insert the shared EntityName. Then the tool will create the required mkdirs and generate inside of each one the file templates according to each folder functionality.

BONUS: Would be great a second modal question for the user before to start generating the scaffold (optional) which ask for Lombok Dependency integration and generates the initial entity template according to this choice. I mean: [NO] getters and setters generated typed in the code || [YES] just lombok annotation like @Data/@Getter/@Setter/@AllArgsConstructor.

jdneo commented 1 year ago

Thank you @BizarreBoy for providing those detailed information.

BTW, just for asking, do other Java IDEs/tools provide feature similar to this one? If there is, we can take a look and make it as a reference.

BizarreBoy commented 1 year ago

Glad to help you, @jdneo !

In my experience I have been a user of Eclipse IDE, Vscode and IntelliJ and I didn't find any similar tool.

However the idea is not too different from the initial "java create project" feature where the palette command makes few questions before to start generating.

The main idea of feature I suggested you is based on a vscode plugin dedicated to Angular developers named "Angular Schematics" developed by Cyrille Tuzi.

image

It works exactly how I described you in my first comment and makes sure the user respect a logic project structure from begining to end. Generates the minimun and necessary starter templates to develop from zero just right clicking in the choosen root directory.

image

image

Let me know if the attached references could help you.

jdneo commented 1 year ago

Thank you. The idea is clear. But we need to think more about how to make the generated structure be suitable to users project as much as possible. (or, make it be easy to configure/customize)

BizarreBoy commented 1 year ago

I agree, in my opinion we could take the angular schematics plugin as reference. With just one click and a command palette question it quickly creates the starter scaffold of a new component with a few files related with each other.

jdneo commented 1 year ago

There are two options in my mind now:

  1. You mentioned the extension Spring Code Generator, which I took a very quick glance on that and looks very nice. We can consider contributing to that extension and let it hook those command to the Java Project explorer, then as long as user installs the Project Manager extension and Spring Code Generator, they can see those actions in the context menu.

  2. Leverage Copilot to scaffold the template. I just tried it in Copilot Chat and the result looks promising 😁 image

BizarreBoy commented 1 year ago

Wow!!! Amazing job by copilot!

And yes, Spring Code Generator works similar, the only thing it doesn't create is the folder structure and only generates files one by one which is comfortable in most scenarios but a bit annoying when user has to create a full APIREST from zero.

This is the reason why I focus on Angular Schematics reference. But it's true that Java Scaffold should work different because Springboot users need the main scaffold just one by project/microservice: Controllers | BussinesLogic [ Services | Interfaces ] | Models [ Entities | DTO | DAO(Repositories) ].

Once the main scaffold is created, the tool should work exactly as Spring Code Generator plugin and add the other templates one by one as the user needs.

Let me know your opinion about the functionality/workflow I described you.