gejun123456 / intellij-generateallsetmethod Goto Github PK
View Code? Open in Web Editor NEWIntellij plugin to generate call to setter method value for class
License: GNU General Public License v2.0
Intellij plugin to generate call to setter method value for class
License: GNU General Public License v2.0
For data type LocalDateTime is generated "new LocalDateTime()" instead "LocalDateTime.now()".
For example:
someDto.setLocalDateTime(new LocalDateTime());
之前我有给作者发过一份Email,想提出了想自动添加上注释,但是迟迟没有收到回复,今天我把代码拉取下来进行查看,折腾了许久,想自己动手,结果发现maven源不存在,作者请更新一下代码哦
建议最好尽量用 JDK 内置的功能来构造默认参数值。
For data type LocalDate is generated "new LocalDate()" instead "Localdate.now()".
For example:
someDto.setLocalDate(new LocalDate());
IDEA 2017.3.2 Ultimate Edition
OS: High Sierra
I install this plug-in and restart Intellij
but I press alt + enter, nothing happened...
then I check the "preference"->"keymap"->"plugin"
can't find anything about this plug in.
any one could give me some tips ? many thanks
really like to use this wonderful plug in
Builder pattern is very common to make an immutable bean object. Lombok even has an @Builder
annotation https://projectlombok.org/features/Builder.
Will this plugin support generation of all builder methods? Thank you.
alt_enter not show menu of generate all setter
The objects that we are mapping don't always have the same types of fields.
For example, sometimes it's needed to perform type conversions:
Would be best if such mappings would be configurable either in project properties (settings) or using some configuration file (whatever is easier)
Adding any default values in setters may lead to error when programmer forget replace value in one of setters. Instead it would be useful to generate setters without values. All of this setters will be highlighted as error while it not filled - wonderful anti error indicator.
就是生成这种代码:User.builder().name("").age("").build();
IJ 2016.3.4
Plugin 1.0.0
The error occurs randomly
null
java.lang.NullPointerException
at com.bruce.intellijplugin.generatesetter.utils.PsiToolUtils.extractParamInfo(PsiToolUtils.java:36)
at com.bruce.intellijplugin.generatesetter.GenerateAllSetterAction.isAvailable(GenerateAllSetterAction.java:381)
at com.intellij.codeInsight.intention.PsiElementBaseIntentionAction.isAvailable(PsiElementBaseIntentionAction.java:64)
at com.intellij.codeInsight.intention.impl.config.IntentionActionWrapper.isAvailable(IntentionActionWrapper.java:59)
at com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler.availableFor(ShowIntentionActionsHandler.java:132)
at com.intellij.codeInsight.daemon.impl.ShowIntentionsPass.a(ShowIntentionsPass.java:312)
at com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler.chooseBetweenHostAndInjected(ShowIntentionActionsHandler.java:157)
at com.intellij.codeInsight.daemon.impl.ShowIntentionsPass.getActionsToShow(ShowIntentionsPass.java:311)
at com.intellij.codeInsight.daemon.impl.ShowIntentionsPass.a(ShowIntentionsPass.java:243)
at com.intellij.codeInsight.daemon.impl.ShowIntentionsPass.doCollectInformation(ShowIntentionsPass.java:219)
at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:70)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.a(PassExecutorService.java:433)
at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1061)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.b(PassExecutorService.java:426)
at com.intellij.openapi.progress.impl.CoreProgressManager.a(CoreProgressManager.java:568)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:519)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.c(PassExecutorService.java:425)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:405)
at com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask$1.exec(JobLauncherImpl.java:155)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
when two field has different type, like string and integer, create a basic converter for them.
IDEA 版本:2019.3.3
插件版本:2.4
感谢辛勤付出!
现在遇到这个问题,生成的 setter 没有当前类声明的属性的 setter,只有父类属性的 setter。
Problem seen in 2.3 (I think it worked in 2.1)
If I have a new method:
private SubscriptionFile convertFromFile(final File file) {
return null;
}
where File and SubscriptionFile has the same members.
I used to be able to place the cursor on return type and get the "generate all setters" context option . The result would be:
private SubscriptionFile convertFromFile(final File file) {
SubscriptionFile subscriptionFile = new SubscriptionFile();
subscriptionFile.setX(file.getX());
subscriptionFile.setY(file.getY());
subscriptionFile.setZ(file.getZ());
return subscriptionFile;
return null;
}
Where I have to remove the return null; line
I particularly liked the automatic matching of the setter and getter methods.
But this no longer works. Is it supposed to?
Please also consider generating get methods.
Use case: I have a class with >30 fields (don't ask..) and I want to write a unit test that verify stuff. To do that I will write
assertThat(myObject.getXXXX()).isEqualTo(...);
It would help a lot if I could generate all get calls. Then the next step would simple to "column selection mode" and add 'assertThat( ).isEqualTo()' around them.
For data type Short is generated "0" instead "(short)0" or new Short("0") or ....
For example:
someDto.setShort(0);
"assert all getters" generates a long "assertThat(xx.getxx()).isEqualTo();" list.
"assertThat" is not anymore in JUnit 5.
Please use something dependent on the getter return type or simply use
"assertEquals(xx expected, xx actual)"
such as:
member.setMemberType(new MemberType());
i think may be better!
member.setMemberType(MemberType.);
generate in builder pattern.
after generate put cursor on the variable name.
Hi. This is a convenient plugin. I am pointing issue with generated code.
For example, generated line for class Foo
would be
Foo name= new Foo()
instead of
Foo name = Foo()
. It's missing a space before =
.
I reckon that the problem is here.
Fix would really save additional step of manual formatting or hitting shortcut for formatter.
昨天把代码拉下来后已经编译通过,目前完成了无参数使用this
来赋值的逻辑,也就是支持构造方法。后续想要改进:
this
属性遍历查找相似的赋值想请问作者有什么功能是考虑接受的吗?有的话可以一起沟通,刚刚尝试写插件,很多类不熟悉,可以请教下大佬,我也可以贡献一定代码。
Plugin is great and it works with setter that starts with name set. On the other hand I got a Builder to a class and would be great to have all builder with* methods calls generated as well.
generate with random value.
that would be nice
the code generate via 'generate List Set Map return value' now using guava framework,can support via
standard jdk collection?
like a.UserVo b.UserVo convert them.
in testcase, build some default value for user to input
If you for example want to write a copy constructor, it would be nice if you can use the plugin.
Currently you would have to do MyClass instance = this;
to use the plugin.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.