cqfn / jpeek

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

XmlGraph builds graph with redundant nodes. #556

Open starkda opened 5 months ago

starkda commented 5 months ago

During application of XmlGraph, I noticed that the graph built using XmlGraph.build() method may generate multiple nodes with the same name. Such problem arises when initial skeleton has more than one classes. For example, if we have 2 classes in skeleton:

<?xml version="1.0" encoding="UTF-8"?>
<skeleton date="2024-04-18T16:18:26.737175379Z"
          schema="xsd/skeleton.xsd"
          version="1.0-SNAPSHOT">
   <app id="/home/djovi/IdeaProjects/untitled17">
      <package id="org.example.memer">
         <class id="Memer"><!--Package: org.example.memer; name: org.example.memer.Memer; file: org.example.memer.Memer-->
            <attributes>
               <attribute final="false" public="false" static="false" type="I">kek</attribute>
               <attribute final="false"
                          public="false"
                          static="false"
                          type="Ljava/lang/String">name</attribute>
            </attributes>
            <methods>

               <method abstract="false"
                       bridge="false"
                       ctor="false"
                       desc="()V"
                       name="four"
                       static="false"
                       visibility="public">
                  <args/>
                  <return>V</return>
               </method>
               <method abstract="false"
                       bridge="false"
                       ctor="false"
                       desc="()V"
                       name="five"
                       static="false"
                       visibility="public">
                  <args/>
                  <return>V</return>
                  <ops>
                     <op code="put">name</op>
                  </ops>
               </method>
            </methods>
         </class>
      </package>
      <package id="org.example">
         <class id="Worker"><!--Package: org.example; name: org.example.Worker; file: org.example.Worker-->
            <attributes>
               <attribute final="false"
                          public="false"
                          static="false"
                          type="Ljava/lang/String">name</attribute>
               <attribute final="false"
                          public="false"
                          static="false"
                          type="Ljava/lang/String">kek</attribute>
            </attributes>
            <methods>

               <method abstract="false"
                       bridge="false"
                       ctor="false"
                       desc="()V"
                       name="one"
                       static="false"
                       visibility="public">
                  <args/>
                  <return>V</return>
                  <ops>
                     <op code="put">name</op>
                  </ops>
               </method>
               <method abstract="false"
                       bridge="false"
                       ctor="false"
                       desc="()V"
                       name="two"
                       static="false"
                       visibility="public">
                  <args/>
                  <return>V</return>
                  <ops>
                     <op code="put">name</op>
                  </ops>
               </method>
               <method abstract="false"
                       bridge="false"
                       ctor="false"
                       desc="()V"
                       name="three"
                       static="false"
                       visibility="public">
                  <args/>
                  <return>V</return>
                  <ops>
                     <op code="put">name</op>
                  </ops>
               </method>
               <method abstract="false"
                       bridge="false"
                       ctor="false"
                       desc="()V"
                       name="four"
                       static="false"
                       visibility="public">
                  <args/>
                  <return>V</return>
                  <ops>
                     <op code="put">kek</op>
                  </ops>
               </method>
               <method abstract="false"
                       bridge="false"
                       ctor="false"
                       desc="()V"
                       name="five"
                       static="false"
                       visibility="public">
                  <args/>
                  <return>V</return>
                  <ops>
                     <op code="put">kek</op>
                  </ops>
               </method>
            </methods>
         </class>
      </package>
   </app>
</skeleton>

XmlGraph.build(skeleton, "org.example.memer", "Memer") will build graph with 5 nodes instead of 2.

starkda commented 5 months ago

@yegor256 what do you think?