Menu

Access to Import Declarations

Help
2008-07-10
2013-04-08
  • Sebastian Herold

    Hi there,

    I use JQuery to detect undesirable dependencies between Java classes. Is it correct that there is no possibility to access the import declaration statements in Java files? I've found an imports(?cu,?el) predicate in the core predicate file but it seems that the corresponding facts are not generated - at least the visit(ImportDeclaration node) method of the ca.ubc.jquery.engine.tyruba.java.FactsGenerator class doesn't seem to create any facts at all.

    If it isn't supported, is it planned to "implement" the imports predicate?

    If not, is there an easy way to retrieve all elements that a compilation unit (or class, interface, package,...) depends on?

    Best regards,

    Sebastian.

     
    • Lloyd Markle

      Lloyd Markle - 2008-07-14

      I believe we did have an implementation for the visit(ImportDeclaration node) method but stopped using it because we weren't querying that information.  We do not have any plans to add it back in at the moment so you are welcome to add it back.

      As for retrieving all elements that a compilation unit depends on: this too may be a little tricky at the moment.  You can write a query to gather information about a compilation unit by finding out the method return types or any instanceof tests, etc.  This would get close to an accurate picture.  The problem is again, the JQuery factbase does not store information about local variable declarations so if you use a particular type only as a local variable in a method, you would not be able to detect this dependency.

      You are welcome to change the AST visitor to generate the facts that you need.  We have built this factbase based on our needs and unfortunately it does not represent a Java program in entirety.  Another solution would be to install the JTransformer plugin as a backend for JQuery because it has a complete representation of the Java program.

      Hope this helps.
      Lloyd

       
      • Sebastian Herold

        Thanks for your reply. I've changed the AST visitor and it seems to work fine.

         
        • Dirk Faulhaber

          Dirk Faulhaber - 2008-07-23

          fine. i like the tool very much. it does cut down some of my daily work from hours to quarters of hours. i look forward to the next version.

           
    • Lloyd Markle

      Lloyd Markle - 2008-07-18

      I would also like to say that as a result of your comments (and others as well) the next version of JQuery (hopefully available next week) will include an extension point for extending the JQuery Java AST visitor.  This will allow you to easily insert your own import facts if you so desire.  We will also include a small tutorial on the wiki to demonstrate how this can be done.

       
      • Sebastian Herold

        This sounds great. A tutorial would be great, since I don't know HOW quick and dirty my solution is ;-)

         
        • Dirk Faulhaber

          Dirk Faulhaber - 2008-07-23

          what kind of tutorial do you have in mind ?

           
          • Lloyd Markle

            Lloyd Markle - 2008-07-23

            The tutorial would be an example of how to extend the Java visitor.  I see a simple extension as adding facts for local variables or adding facts for import declarations.  This should give a good feel for how the factbase is built and how it can be extended.

            I suppose we'll also have to cover some basics about Extension points.

             

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.