3

I have some interface Action, and most of the classes implementing that interface are derived from some base AbstractAction. But I assume there are some classes that implement that interface, but that do not extend that base class.

Is there a way using IntelliJ to identify such classes? (ideally: using the community edition)

Edit: this is not a duplicate of How to show all parents and subclasses of a class in IntelliJ IDEA?, as I am looking to combine a condition like "implements X and NOT extends Y".

GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • 1
    Sir, I do not think this option is available in Intellij community edition, I don't know about ultimate edition. – Sambit Jun 19 '19 at 09:23
  • 1
    Any comments by the downvoters? – GhostCat Jun 19 '19 at 09:23
  • I think no IDE like Eclipse and Idea provides this feature. I think this kind of feature should be added to the IDEs for more analysis. – Sambit Jun 19 '19 at 09:35
  • Can I ask what your use case is? Maybe you can use a checkstyle configuration to warn if a class implements X and does not extend Y? – sfiss Jun 19 '19 at 09:46
  • @sfiss I want to add a custom toString() method to all Actions. I will put it in the base class, but for sure, it also needs to go into any other class implementing the interface but not inheriting from the base class. – GhostCat Jun 19 '19 at 10:15
  • BTW: there is this incredibly powerful Live Plugin https://github.com/dkandalov/live-plugin which can pimp IDEA e.g. in a way to write the lookups in Groovy and use the Find tool window to Display the results. So only the sky is the limit in finding stuff ;) – Jens Nerche Jun 20 '19 at 06:08

1 Answers1

3

Works only in Intellij IDEA Ultimate Edition:
The only thing that comes into my mind to sort of solve your problem directly with Intellij IDEA is to generate the uml class diagramm of your Action interface.

This lets you search visually for hierarchy patterns.

Here is a diagramm for the JTextComponent as an example:

enter image description here

Another approach - Using the right tool for the job

jqassistant is a tool that analyses your java code and its relations and stores that into a neo4j database. This enables you to describe your problem as graph query with cypher.

The easiest way to get started is to

Example: The query for finding all classes implementing aInteface would look like

MATCH (i:Interface {name:"aIntefaces"}  )<-[:IMPLEMENTS]- (c) RETURN i,c

A query to your problem would look like:

MATCH 
   (i:Interface {name:'Action'}  )<-[:IMPLEMENTS|EXTENDS*1..10]- (class), 
   (abstractAction:Class {name:'AbstractAction'}) 
   where not (class)-->(abstractAction)   
RETURN class
Peter
  • 4,752
  • 2
  • 20
  • 32
  • 1
    JetBrains support told me to look into "structural search/replace", but for now, I like the idea of using jQasssistant. – GhostCat Jun 19 '19 at 12:10
  • In case you want to earn another accept today ... maybe checkout https://stackoverflow.com/questions/56667478/how-to-include-package-into-query ;-) – GhostCat Jun 19 '19 at 12:19