QDox
  1. QDox
  2. QDOX-83

Access to method body at runtime

    Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.6.1
    • Component/s: Parser
    • Labels:
      None
    • Number of attachments :
      2

      Description

      There are some cases when accessing the bodies of methods is essential at runtime (such as code browsing tools).

      To get at these, Ideally there should be a method like 'String getBody()' available on JavaMethod and JavaField.

      No attempt to parse the body of the method is necessary - it should just be made available as a single string.

      Because this adds a memory overhead, it should ideally be optional and disabled by default. Maybe a method like JavaDocBuilder.setExposeBody(boolean) to enable it.

      Attached are some modifications by Shawn Chain that can help implement this.

      ---- From Shawn Chain ----

      (1) lexer.flex
      added StringBuffer codeBody in class JFlexLexer to read the body of
      CODEBLOCK.

      (2) parser.y
      added type memberend so that the "codeBody" can be passed to the
      MethodDef's body field .

      (3) Lexer.java
      added method getCodeBody():String

      (4) MethodDef.java
      added public field body

      (5) JavaMethod.java
      added property codeBody and the setter/getter methods modified the method
      writeBody() to dump the codeBody

      (6) ModelBuilder.java
      modified the method addMethod(MethodDef) to pass the codeBody to the
      instance of JavaMethod

      TODO
      Support the static codeblock

        Activity

        Hide
        Joe Walnes added a comment -

        Shawn's changes

        Show
        Joe Walnes added a comment - Shawn's changes
        Joe Walnes made changes -
        Field Original Value New Value
        Attachment qdox-method-body-patch.zip [ 13924 ]
        Hide
        Shawn Chain added a comment -

        updated patch to support initial value of fields and the static initializer.

        Show
        Shawn Chain added a comment - updated patch to support initial value of fields and the static initializer.
        Shawn Chain made changes -
        Attachment qdox-1.6-codebody-patch-u.txt [ 13925 ]
        Hide
        Shawn Chain added a comment -

        Hi all,
        I just attached the latest patch for QDox1.6
        Change:
        (1) use JavaField::getBody() to retrive the initialValue of a field
        (2) static initializer in Java class now loaded as a constructor method with flag "staticInitializer" marked "true"
        Thanks
        Shawn Chain

        Show
        Shawn Chain added a comment - Hi all, I just attached the latest patch for QDox1.6 Change: (1) use JavaField::getBody() to retrive the initialValue of a field (2) static initializer in Java class now loaded as a constructor method with flag "staticInitializer" marked "true" Thanks Shawn Chain
        Hide
        Jim Cook added a comment -

        Looking forward to getting this in the HEAD.

        Short of writing my own parser, I couldn't find a decent tool that can extract a single method (source and all) from a Java source file. I was hoping that JavaMethod.toString() would do the trick, but alas, only the method signature.

        Show
        Jim Cook added a comment - Looking forward to getting this in the HEAD. Short of writing my own parser, I couldn't find a decent tool that can extract a single method (source and all) from a Java source file. I was hoping that JavaMethod.toString() would do the trick, but alas, only the method signature.
        Hide
        Aslak Hellesøy added a comment -

        Shawn,

        The link to qdox-1.6-codebody-patch-u.txt is not working (yeah, this is a JIRA bug). Could you attach it again without dashes in the name? I think that's what makes JIRA choke on it.

        Show
        Aslak Hellesøy added a comment - Shawn, The link to qdox-1.6-codebody-patch-u.txt is not working (yeah, this is a JIRA bug). Could you attach it again without dashes in the name? I think that's what makes JIRA choke on it.
        Hide
        Aslak Hellesøy added a comment -

        Never mind. It's working now. (But I swear JIRA choked on me several times 2 minutes ago when I tried to download the patch).

        Show
        Aslak Hellesøy added a comment - Never mind. It's working now. (But I swear JIRA choked on me several times 2 minutes ago when I tried to download the patch).
        Hide
        Bruce Fancher added a comment -

        Any chance this will make it into Qdox proper?

        Any instructions on applything these?

        Thanks

        Show
        Bruce Fancher added a comment - Any chance this will make it into Qdox proper? Any instructions on applything these? Thanks
        Hide
        Dennis Sosnoski added a comment -

        I'd also love to see this.

        Show
        Dennis Sosnoski added a comment - I'd also love to see this.
        Hide
        Mauro Talevi added a comment -

        Changed fix version to 1.7

        Show
        Mauro Talevi added a comment - Changed fix version to 1.7
        Mauro Talevi made changes -
        Fix Version/s 1.6 [ 10814 ]
        Fix Version/s 1.7 [ 11160 ]
        Hide
        Paul Hammant added a comment -

        Can someone update this patch to 'svn diff' please, and try against latest Svn before uploading again

        Show
        Paul Hammant added a comment - Can someone update this patch to 'svn diff' please, and try against latest Svn before uploading again
        Hide
        Dennis Lundberg added a comment -

        If I'm reading the svn commits correctly, Joe committed Shawn's first round of patches in r451. That was released in version 1.6.1 according to the changes.xml file, but this issue is still open.

        For proper housekeeping in JIRA, a new issue should be opened for Shawn's second patch, if it's still viable.

        Show
        Dennis Lundberg added a comment - If I'm reading the svn commits correctly, Joe committed Shawn's first round of patches in r451. That was released in version 1.6.1 according to the changes.xml file, but this issue is still open. For proper housekeeping in JIRA, a new issue should be opened for Shawn's second patch, if it's still viable.
        Hide
        Dennis Lundberg added a comment -

        First round of patches applied in r451.

        Show
        Dennis Lundberg added a comment - First round of patches applied in r451.
        Dennis Lundberg made changes -
        Assignee Joe Walnes [ jwalnes1 ]
        Status Open [ 1 ] Closed [ 6 ]
        Resolution Fixed [ 1 ]
        Fix Version/s 1.6.1 [ 14090 ]
        Fix Version/s 1.7 [ 11160 ]

          People

          • Assignee:
            Joe Walnes
            Reporter:
            Joe Walnes
          • Votes:
            4 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: