Comments (9)
i want to include the class with specify super class
May I confirm your intention here? Do you want to
- Include the fields of the super class(of current class)?
- Or include the fields of the class whose super class is specified by name?
If possible please provide an example to explain what you want. Thanks!
from codegenerator.
好尴尬好尴尬,竟然写了半吊子的英文给会中文的人提问 (lll¬ω¬)
我是希望这样子的。有一个类A,我想在Member Selection Dialog中列出所有继承A类的成员变量。type、typeName、typeQualifyName,这三个是类型,能获得变量类型,我知道typeName就是类型名称,而type和typeQualifyName好像都是包含路径的(不明白有什么区别),我从这三个返回里面无法得到父类名称进行匹配。
请问有什么办法可以实现我想要的过滤效果吗?
from codegenerator.
@zii4914 关于需求,再问得详细一点:
- 是说当前光标在类 A,然后想找到 A 类中继承自 A 的父类的字段吗?
- 还是说当前在类 A,想找到 A 的子类(可能有多个)中继承父类的字段?
不知道跟这个问题( #9 )的需求是否类似
from codegenerator.
@lotabout
那个问题,我看过,不一样。
我希望是这样的。
当前光标在Sample.class,在Sample.class中有一些字段,我希望在Sample.class中能够找出所有继承了A.class的字段。
因为我需要生成的代码里面,所使用到的方法,只有A.class才拥有这个方法,所以我想找出所有继承或实现了A的这种类型字段。
from codegenerator.
@zii4914 参考下面的代码,可以判断当前类(Sample.class)里的所有字段中,类型为 List
或它的子类(如 ArrayList
)的字段。
#set($availableMembers = $class0.members)
#set($javaPsiFacade = $JavaPsiFacade.getInstance($project))
#set($global = $GlobalSearchScope.allScope($project))
#set($listtype = $javaPsiFacade.findClass("java.util.List", $global))
#set($availableMembers = [])
#set($methodNames = [])
#foreach($member in $class0.members)
#set($memberType = $member.type.split("<").get(0))
#set($type = $javaPsiFacade.findClass($memberType, $global))
#if ($type.qualifiedName == "java.util.List" || $type.isInheritor($listtype, false))
$availableMembers.add($member)
#end
#end
- 其中
javaPsiFacade.findClass
可以用来在全局中搜索类,得到的类型为PsiClass
- 它包含的 isInheritor 方法可以用来判断“是否继承自”某个类。
member.type
返回的是诸如List<String>
这样的类型。
from codegenerator.
@lotabout
谢谢,这个方法可用,但是他只能找出只有一层继承关系以内的字段。如果两层及以上就无效了。
如C 继承 B,B继承A,当查找A时候,能够找出A、B类型的字段,但是无法找到C。
from codegenerator.
@zii4914 试试 isInheritor(..., true)
第二个参数是 isDeep
应该是支持多层级的。
from codegenerator.
@lotabout
完美解决,非常感谢!
另外问一下,Member Selection Dialog能否支持列出方法?或者后面是否会考虑支持。
from codegenerator.
@zii4914 现在就支持,勾选 Member Selection Dialog 下方的 Enable Method Selection
即可
from codegenerator.
Related Issues (17)
- 添加新的模板出错 HOT 1
- Language HOT 3
- Instructions for building from source HOT 2
- Unable to load settings pane HOT 2
- MethodEntry provide properties to get method param Type and name HOT 1
- Static Imports
- Materials for version 1.3 HOT 4
- Would be an useful utility class: DateTool (and maybe a random generator)
- Cannot add own suffix to generated class - default package names starts with redundant '\n' HOT 4
- How to get annotations in classes?
- Not compatible with IntelliJ IDEA 2023.2.1 HOT 4
- Use default generate menu HOT 1
- The plugin gets stuck in loading. HOT 4
- Debug / Development cycle HOT 2
- 新增的Member,再次打开后无缘无故就消失了 HOT 3
- 设置Member时,如何拿到当前class的父类的fields HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from codegenerator.