QDox
  1. QDox
  2. QDOX-84

Support annotations within method body

    Details

    • Type: Improvement Improvement
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Parser
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Although not conforming to standard java, we need to determine annotations within a method body. Currently, QDOX is not supporting this in any way (this is my impression, maybe I am wrong?).

      We really need such a feature and I think it would be very useful and inspiring for future uses of annotations!

      Let QDOX be more than one step ahead of other tools

        Activity

        Hide
        Joe Walnes added a comment -

        Klausi,

        Could you provide an example of what you mean.

        Thanks
        -Joe

        Show
        Joe Walnes added a comment - Klausi, Could you provide an example of what you mean. Thanks -Joe
        Hide
        Klausi added a comment -

        Joe,

        for example, take a method that contains annotations:

        public void myMethod(...)

        { ... @annotation_here <annotated_element> ... }

        The <annotated_element> could be an field declaration, a statement, or even an inner class (whereas the latter is not that important as the former two).
        Concretely, <annotated_element> could be (it follows a list of examples):
        anObject.doSomething(...);
        String myString;
        Object result = anObject.aMethod();
        toString();
        return null;//in methods returning something

        Klaus

        Show
        Klausi added a comment - Joe, for example, take a method that contains annotations: public void myMethod(...) { ... @annotation_here <annotated_element> ... } The <annotated_element> could be an field declaration, a statement, or even an inner class (whereas the latter is not that important as the former two). Concretely, <annotated_element> could be (it follows a list of examples): anObject.doSomething(...); String myString; Object result = anObject.aMethod(); toString(); return null;//in methods returning something Klaus
        Hide
        Joe Walnes added a comment -

        I'm still confused. Could you give me a more concrete example filling in the blanks, or point me to some sample code that does this.

        Show
        Joe Walnes added a comment - I'm still confused. Could you give me a more concrete example filling in the blanks, or point me to some sample code that does this.
        Hide
        Klausi added a comment -

        Joe, OK here is a concrete example containing two in-method annotations:

        public void myMethod()

        { MyClass myObject = new MyClass(); @myAnnotation("a_parameter") myObject.doSomething(); @objectcreation Object result = myObject.aProducer(); }

        The first annotation "myAnnotation" is unspecific, it does not matter which custom annotation to use there; it only needs to make sense for a statement and is allowed for a statement (TARGET option of annotations, so to say).

        The second annotation "objectcreation" (self-defined, not Java-Standard, just meant as a more or less meaningful example) could be used to mark a statement as creating an object. With that an annotation parser could find out that the statement has similar characteristics as the object creation via "new" (as in "new Object(), e.g.).

        Klaus

        Show
        Klausi added a comment - Joe, OK here is a concrete example containing two in-method annotations: public void myMethod() { MyClass myObject = new MyClass(); @myAnnotation("a_parameter") myObject.doSomething(); @objectcreation Object result = myObject.aProducer(); } The first annotation "myAnnotation" is unspecific, it does not matter which custom annotation to use there; it only needs to make sense for a statement and is allowed for a statement (TARGET option of annotations, so to say). The second annotation "objectcreation" (self-defined, not Java-Standard, just meant as a more or less meaningful example) could be used to mark a statement as creating an object. With that an annotation parser could find out that the statement has similar characteristics as the object creation via "new" (as in "new Object(), e.g.). Klaus
        Hide
        Aslak Hellesøy added a comment -

        Javac would choke on this. I suppose you also want to complie your sources?

        Show
        Aslak Hellesøy added a comment - Javac would choke on this. I suppose you also want to complie your sources?
        Hide
        Klausi added a comment -

        Aslak, you are right, of course!
        My apologies, I mixed up tags with annotations (because I use tags - in an extended form - as if they were annotations to just avoid what you remarked correctly).

        So what I really meant (sorry again) was:
        Is it possible to parse javadoc-like tags within a method with QDOX?

        Example:

        public void myMethod()

        { MyClass myClass; /**@my_javadoc blabla*/ myClass.doSomething(); }

        Klaus

        Show
        Klausi added a comment - Aslak, you are right, of course! My apologies, I mixed up tags with annotations (because I use tags - in an extended form - as if they were annotations to just avoid what you remarked correctly). So what I really meant (sorry again) was: Is it possible to parse javadoc-like tags within a method with QDOX? Example: public void myMethod() { MyClass myClass; /**@my_javadoc blabla*/ myClass.doSomething(); } Klaus
        Aslak Hellesøy made changes -
        Field Original Value New Value
        Comment [ 31443 ]
        Hide
        Aslak Hellesøy added a comment -

        I think the feature you're asking for would require a major addition to QDox, namely exposing the abstract syntax tree (AST) of the java source in the QDox API.

        I'd like to better understand how you want this to work and an example of how the proposed feature would be useful. What's the problem you're trying to solve?

        How would your code look if you were to access the annotations in your example (imagining that you get to invent new methods in the QDox API)

        Show
        Aslak Hellesøy added a comment - I think the feature you're asking for would require a major addition to QDox, namely exposing the abstract syntax tree (AST) of the java source in the QDox API. I'd like to better understand how you want this to work and an example of how the proposed feature would be useful. What's the problem you're trying to solve? How would your code look if you were to access the annotations in your example (imagining that you get to invent new methods in the QDox API)
        Hide
        Klausi added a comment -

        >>How would your code look if you were to access the annotations in your example (imagining that you get to invent new methods in the QDox API)

        Don't make the same error as I did. I finally meant "tags", not annotations (sorry for the confusion).

        The problem I want to solve is attach semantic information to statements being contained in a method's body.

        I would like to access tags in methods in QDOX in a similar way to standard tags that are already accessible with QDOX. The difference is that I then wouldn't write
        MethodSummary ms = ...
        DocletTag[] tags = ms.getTags();
        but instead
        MethodSummary ms = ...
        DocletTag[] tags = ms.getBodyTags();
        or alternatively (I saw that the receiving of a method's body has been subject to newer development)
        DocletTag[] tags = ms.getBody().getTags();

        Klaus

        Show
        Klausi added a comment - >>How would your code look if you were to access the annotations in your example (imagining that you get to invent new methods in the QDox API) Don't make the same error as I did. I finally meant "tags", not annotations (sorry for the confusion). The problem I want to solve is attach semantic information to statements being contained in a method's body. I would like to access tags in methods in QDOX in a similar way to standard tags that are already accessible with QDOX. The difference is that I then wouldn't write MethodSummary ms = ... DocletTag[] tags = ms.getTags(); but instead MethodSummary ms = ... DocletTag[] tags = ms.getBodyTags(); or alternatively (I saw that the receiving of a method's body has been subject to newer development) DocletTag[] tags = ms.getBody().getTags(); Klaus
        Hide
        Klausi added a comment -

        Correction to my prior comment:
        I meant JavaMethod, not MethodSummary!

        Show
        Klausi added a comment - Correction to my prior comment: I meant JavaMethod, not MethodSummary!
        Hide
        Aslak Hellesøy added a comment -

        OK, let's assume you can get the "body tags". If I understand you correctly, you also want to know what statement a "body tag" belongs to.

        How you model the relationship between a "body tag" and a statement? Unidirectional? What way? Bidirectional? What does a statement look like?

        I still don't understand in what situation meta information about statements would be useful. Can you explain the "why" in addition to the "how"?

        Show
        Aslak Hellesøy added a comment - OK, let's assume you can get the "body tags". If I understand you correctly, you also want to know what statement a "body tag" belongs to. How you model the relationship between a "body tag" and a statement? Unidirectional? What way? Bidirectional? What does a statement look like? I still don't understand in what situation meta information about statements would be useful. Can you explain the "why" in addition to the "how"?
        Hide
        Klausi added a comment -

        Yes, I want to know what statement a "body tag" belongs to. A statement could be virtually any valid java statement.

        The relation between a body tag and a statement is given by the position of the body tag, i.e., the tag is placed just ahead of the statement. I would call the relationship unidirectional, meaning: the tag referrs to the statement, and the statement needn't know about the tag. There is no code generator involved (that would parse the tags and generate code from the information contained in them), nor do I want to use the tags to modify the execution behaviour of the code. I just want to gather information from source code, nothing more (although it may be difficult).

        With a comment, one could give virtually any meta information, just think about a comment written by a human in natural language. Another human knowing the same language could understand it, a computer program could not (nowadays, maybe in 50 years). Because of that I want to have tags with a syntax defined by myself. It is not necessary handling the syntax with QDOX, as I just need the plain text of the tag and then could do anything I want with it (process it).

        The meta information I want to bring in is to describe the semantic aspects of statements. For example: "The following statement is used to notify another objects about an event currently occured". Or: "The following statement is used to create and return a new instance of an object". Of course, one could instead "tag" the called method (if the statement was a method call, which is not always the case), because then we could deduce that a caller of that method wants to do what the method is tagged for. But that's just a special case and it would not be very convenient to always tag the method called instead of being able to tag the calling statement. Additionally, the class in which the method resides, could be contained within a jar file...

        Klaus

        Show
        Klausi added a comment - Yes, I want to know what statement a "body tag" belongs to. A statement could be virtually any valid java statement. The relation between a body tag and a statement is given by the position of the body tag, i.e., the tag is placed just ahead of the statement. I would call the relationship unidirectional, meaning: the tag referrs to the statement, and the statement needn't know about the tag. There is no code generator involved (that would parse the tags and generate code from the information contained in them), nor do I want to use the tags to modify the execution behaviour of the code. I just want to gather information from source code, nothing more (although it may be difficult). With a comment, one could give virtually any meta information, just think about a comment written by a human in natural language. Another human knowing the same language could understand it, a computer program could not (nowadays, maybe in 50 years). Because of that I want to have tags with a syntax defined by myself. It is not necessary handling the syntax with QDOX, as I just need the plain text of the tag and then could do anything I want with it (process it). The meta information I want to bring in is to describe the semantic aspects of statements. For example: "The following statement is used to notify another objects about an event currently occured". Or: "The following statement is used to create and return a new instance of an object". Of course, one could instead "tag" the called method (if the statement was a method call, which is not always the case), because then we could deduce that a caller of that method wants to do what the method is tagged for. But that's just a special case and it would not be very convenient to always tag the method called instead of being able to tag the calling statement. Additionally, the class in which the method resides, could be contained within a jar file... Klaus
        Joe Walnes made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Won't Fix [ 2 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Klausi
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: