jQAssistant / jqassistant

Your Software. Your Structures. Your Rules.
https://jqassistant.org/
GNU General Public License v3.0
189 stars 34 forks source link

DEPENDS_ON relationship is not generated in case of shared constants #453

Open vprudnikov opened 6 years ago

vprudnikov commented 6 years ago

Hello,

I'm trying to detect dependencies between classes from different packages.

I have to classes:

  1. com.example.controller.Controller
    public class Controller {
    String CONST = "qwe";
    }
  2. com.example.domain.Entity
    public class Entity2 {
    private static final String ENTITY_CONST = Controller.CONST;
    }

When I run a query for collecting all dependencies MATCH (type1:Type)-[:DEPENDS_ON]->(type2:Type) RETURN type1,type2

...I see that both Controller and Entity depend on java.lang.String. Entity doesn't depend on Controller.

But it doesn't help me to resolve the introduced dependency between domain and controller layers.

Any workaround?

Thank you.

DirkMahler commented 6 years ago

That's a limitation deriving from the fact that jQA uses Java bytecode for scanning: the Java compiler inlines constant values into the compiled files so the scanner cannot see that there has been a dependency in the source code.

vprudnikov commented 6 years ago

Thank you for your reply. Can you suggest anything to overcome this issue?

DirkMahler commented 6 years ago

Sadly I have no idea without affecting the source code:

public class Controller {
    String CONST = "qwe".intern();
}

In this case you'll see the dependency it's strange for the devs and furthermore you cannot see the constant's value in the graph.

vprudnikov commented 6 years ago

OK, thank you! At least this information would be helpful for others :)

DirkMahler commented 5 years ago

This is a documenation issue, need to identify a place where this fits bests in. It should be mentioned in the Java scanner but maybe its also an worth pointing this out in a 101 tutorial that handles dependencies, e.g. https://101.jqassistant.org/manage-package-dependencies/index.html