How to identify all classes implementing a specific interface that do NOT extend some base class?

Viewed 213

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".

1 Answers

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
Related