cqfn / jpeek

Hosted and command-line calculator of cohesion metrics for Java code
https://i.jpeek.org
MIT License
209 stars 81 forks source link

XmlGraph issue #553

Closed starkda closed 7 months ago

starkda commented 7 months ago

XmlGraph (https://github.com/cqfn/jpeek/blob/master/src/main/java/org/jpeek/graph/XmlGraph.java) is used to represent methods and their relations for each class from input skeleton. But current implementation ignores constructors and static methods: https://github.com/cqfn/jpeek/blob/9f4fc55048c2af466d5f81ca01a6f36f41537fa9/src/main/java/org/jpeek/graph/XmlGraph.java#L97C13-L99C14 Therefore, resulting graph may be incorrect for cases when we want to include constructors or static methods in metric calculation. For example, we want to include constructor and input class is:

public final class Bar {
    private final Object key;
    private final Object value;
    private static String singleton = "";
    private static final String NAME = "hey";
    public Bar(final Object keyy, final Object val) {
        this.key = keyy;
        this.value = val;
        Bar.singleton = "hi";
    }
    public Object getKey() {
        Bar.singleton = "bye";
        Bar.NAME.length();
        return this.key;
    }
    public Object getValue() {
        Bar.NAME.length();
        return this.value;
    }
    public Object setValue(final Object val) {
        throw new UnsupportedOperationException("This object is immutable.");
    }
}

the code that finds nodes of graph:

final List<Node> nodes = new XmlGraph(
            new Skeleton(new FakeBase(XmlGraphTest.CLASS_NAME)),
            "", XmlGraphTest.CLASS_NAME
        ).nodes();

Size of nodes would be 3, while it should be 4.

starkda commented 7 months ago

@yegor256 what do you think? Can I take that issue?

yegor256 commented 7 months ago

@starkda this is done for a reason. I don't remember, what is the reason, but we should find out. It doesn't look like a bug to me, but as a feature. just removing it -- is not a solution.

starkda commented 7 months ago

@yegor256 i do not want to remove it but support parameters, more specifically, i want to add one more constructor with parameters

I am planning to use XmlGraph in https://github.com/cqfn/jpeek/issues/522 but without support of parameters it can be impossible

starkda commented 7 months ago

After some investigation, I found out that project already has xsl templates to get rid of constructors/static methods. Closing issue