Coder Social home page Coder Social logo

Comments (9)

lotabout avatar lotabout commented on July 21, 2024

@zii4914

i want to include the class with specify super class
May I confirm your intention here? Do you want to

  1. Include the fields of the super class(of current class)?
  2. 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.

zii4914 avatar zii4914 commented on July 21, 2024

好尴尬好尴尬,竟然写了半吊子的英文给会中文的人提问 (lll¬ω¬)
我是希望这样子的。有一个类A,我想在Member Selection Dialog中列出所有继承A类的成员变量。type、typeName、typeQualifyName,这三个是类型,能获得变量类型,我知道typeName就是类型名称,而type和typeQualifyName好像都是包含路径的(不明白有什么区别),我从这三个返回里面无法得到父类名称进行匹配。
请问有什么办法可以实现我想要的过滤效果吗?

from codegenerator.

lotabout avatar lotabout commented on July 21, 2024

@zii4914 关于需求,再问得详细一点:

  1. 是说当前光标在类 A,然后想找到 A 类中继承自 A 的父类的字段吗?
  2. 还是说当前在类 A,想找到 A 的子类(可能有多个)中继承父类的字段?

不知道跟这个问题( #9 )的需求是否类似

from codegenerator.

zii4914 avatar zii4914 commented on July 21, 2024

@lotabout
那个问题,我看过,不一样。
我希望是这样的。
当前光标在Sample.class,在Sample.class中有一些字段,我希望在Sample.class中能够找出所有继承了A.class的字段。
因为我需要生成的代码里面,所使用到的方法,只有A.class才拥有这个方法,所以我想找出所有继承或实现了A的这种类型字段。

from codegenerator.

lotabout avatar lotabout commented on July 21, 2024

@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
  1. 其中 javaPsiFacade.findClass 可以用来在全局中搜索类,得到的类型为 PsiClass
  2. 它包含的 isInheritor 方法可以用来判断“是否继承自”某个类。
  3. member.type 返回的是诸如 List<String> 这样的类型。

from codegenerator.

zii4914 avatar zii4914 commented on July 21, 2024

@lotabout
谢谢,这个方法可用,但是他只能找出只有一层继承关系以内的字段。如果两层及以上就无效了。
如C 继承 B,B继承A,当查找A时候,能够找出A、B类型的字段,但是无法找到C。

from codegenerator.

lotabout avatar lotabout commented on July 21, 2024

@zii4914 试试 isInheritor(..., true) 第二个参数是 isDeep 应该是支持多层级的。

from codegenerator.

zii4914 avatar zii4914 commented on July 21, 2024

@lotabout
完美解决,非常感谢!
另外问一下,Member Selection Dialog能否支持列出方法?或者后面是否会考虑支持。

from codegenerator.

lotabout avatar lotabout commented on July 21, 2024

@zii4914 现在就支持,勾选 Member Selection Dialog 下方的 Enable Method Selection 即可

from codegenerator.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.