package ch.usi.inf.sp.callgraph.renderer;

import ch.usi.inf.sp.callgraph.Method;

import java.util.Objects;

public abstract class MethodLike {
    public String getVerboseModifiers() {
        return "";
    }

    public Method getMethod() {
        return null;
    }

    public abstract String getDeclaringClass();

    public abstract String getName();

    public abstract String getDescriptor();

    public String prettyName() {
        return (getVerboseModifiers() + " " +
                getName().replaceAll("<", "&lt;").replaceAll(">", "&gt;") +
                getDescriptor()).trim();
    }

    private String toSerializedString() {
        return String.format("%s.%s %s", getDeclaringClass(), getName(), getDescriptor());
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(toSerializedString());
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof MethodLike)) return false;
        final MethodLike m = (MethodLike) obj;
        return Objects.equals(toSerializedString(), m.toSerializedString());
    }
}
