Intellij caller, method and type hierarchy + UML classes diagram

public interface MyIface {
    Number getNumericValue() throws RuntimeException;
}

public class MyIfaceImpl implements MyIface {
    @Override
    public Number getNumericValue() throws RuntimeException {
        System.out.println("MyIfaceImpl: in getNumericValue");
        return null;
    }
}

public abstract class MyAbstractClass implements MyIface {
    public abstract Number doInGet();

    @Override
    public Integer getNumericValue() throws IllegalArgumentException { // OK
        System.out.println("MyAbstractClass: in getNumericValue");
        doInGet();
        return null;
    }

    /*@Override
    public Long getNumericValue() { // OK (neither RuntimeException nor Exception does not need to included in overriding method signature)
        return null;
    }*/

    /*@Override
    public Number getNumericValue() throws Exception {  //Error:(7, 20) java: getNumericValue() in myhierarchy.MyAbstractClass cannot implement getNumericValue() in myhierarchy.MyIface overridden method does not throw java.lang.Exception
        return null;
    }*/

    /*@Override
    public Object getNumericValue() throws RuntimeException {  //Error:(17, 19) java: getNumericValue() in myhierarchy.MyAbstractClass cannot implement getNumericValue() in myhierarchy.MyIface         return type java.lang.Object is not compatible with java.lang.Number
        return null;
    }*/
}

public class MyAbstractClassImpl extends MyAbstractClass {
    @Override
    public Number doInGet() {
        System.out.println("MyImpl: in doInGet");
        return null;
    }
}

public class AllCaller {
    public static void main(String[] args) {
        MyIface myIface = new MyIfaceImpl();
        myIface.getNumericValue();
        MyAbstractClass myAbstractClass = new MyAbstractClassImpl();
        myAbstractClass.getNumericValue();
    }
}

import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.function.Supplier;

public class RandomCallerApp {
    public static void main(String[] args) {
        Supplier myIfaceSupplier = get();
        System.out.println("supplier created, value lazy");
        myIfaceSupplier.get().getNumericValue();
    }

    private static Supplier get() {
        List myIfaces = Arrays.asList(new MyIfaceImpl(), new MyAbstractClassImpl());
        int i = new Random().nextInt(myIfaces.size());
        return () -> myIfaces.get(i);
    }
}

 

Ctrl+Alt+Shift+U – generate UML

Screenshot 2020-04-26 at 08.18.55

My shortcut:
F3 – go to declaration or view usages
Ctrl+Shift+C – caller hierarchy

Screenshot 2020-04-26 at 08.14.51

My shortcut:
F4 or Ctrl+Shift+I – navigate/choose method implementations
Ctrl+Shift+M – method hierarchy

Screenshot 2020-04-26 at 08.12.15

My shortcut: Ctrl+Shift+G – find usages:

Screenshot 2020-04-26 at 08.43.13

 

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s