Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JdtVisitor ignores optionalTagName for javadocs #355

Closed
pouryafard75 opened this issue May 30, 2024 · 10 comments
Closed

JdtVisitor ignores optionalTagName for javadocs #355

pouryafard75 opened this issue May 30, 2024 · 10 comments
Assignees
Labels

Comments

@pouryafard75
Copy link
Contributor

pouryafard75 commented May 30, 2024

Hello,
I just realized JdtVisitor ignores the optionalTagName while visiting TagElement.

Code:

/** @author john */
class C {}

Generated tree:

CompilationUnit [0,31]
    TypeDeclaration [0,31]
        Javadoc [0,19]
            TagElement [4,17]
                TextElement:  john  [11,17]
        TYPE_DECLARATION_KIND: class [21,26]
        SimpleName: C [27,28]

author is not part of the generated tree.

Since Eclipse JDT, reports this as the optionalTagName, I assume there's no need to create a seperate node for it.
image

However, it's still possible to concatenate it with the TextElement that comes after and generate the following:

CompilationUnit [0,30]
    TypeDeclaration [0,30]
        Javadoc [0,19]
            TagElement [4,17]
                TextElement: @author john  [11,17]
        TYPE_DECLARATION_KIND: class [20,25]
        SimpleName: C [26,27]

You can find my implementation here. This is a very naive implementation, and I am not sure if this covers all the cases. If TagElement can contain multiple TextElement, it will be problematic. Also, it assumes, that there will be always a TextElement as a child which comes after.

@tsantalis Are there any other possible scenarios?
@jrfaller Please share your thoughts.

@pouryafard75 pouryafard75 changed the title JdtVisitor ignores optionalTagElement for javadocs JdtVisitor ignores optionalTagName for javadocs May 30, 2024
@tsantalis
Copy link

tsantalis commented May 30, 2024

@pouryafard75
According to Eclipse JDT documentation

getTagName
Returns this node's tag name, or null if none.

So, this a property of the TagElement

CompilationUnit [0,30]
    TypeDeclaration [0,30]
        Javadoc [0,19]
            TagElement [4,17]
                Identifier: @author [4, 11]
                TextElement:  john  [12,17]
        TYPE_DECLARATION_KIND: class [20,25]
        SimpleName: C [26,27]

We should update the Visitor to generate the tree as shown above.
The identifier is optional, because it can be null.
It is wrong to add the identifier in the TextElement

The optionalTageName seems a bit strange. I cannot find it in the documentation.
The list of all tags is available in class TagElement

@jrfaller
Copy link
Member

jrfaller commented Jun 8, 2024

Hello @pouryafard75 and @tsantalis ! Thanks a lot for the detailed bug report. I tend to agree with @tsantalis it should be a separate child of a TagElement. Identifier is a good idea maybe TagName also to avoid allowing a variable identifier to move to a javadoc tag :). When you have a good implementation, don't hesitate to send a PR!

Cheers!

@jrfaller jrfaller self-assigned this Jun 8, 2024
@jrfaller jrfaller added the bug label Jun 8, 2024
@tsantalis
Copy link

@pouryafard75
We can check if
getTagName
returns something, and if not we can check the optionalTagName property.
We will use TagName as the label for this kind of nodes.

@jrfaller
Please give us some time to get this change in the final 4.0.0 release of GumTree

@jrfaller
Copy link
Member

jrfaller commented Jun 9, 2024

@tsantalis sure!

@pouryafard75
Copy link
Contributor Author

@tsantalis @jrfaller
Is this structure acceptable? Please share your thoughts.

CompilationUnit [0,34]
    TypeDeclaration [0,34]
        Javadoc [0,19]
            TagElement [4,17]
                TAG_NAME: @author [4,11]
                TextElement:  john  [11,17]
        TYPE_DECLARATION_KIND: class [24,29]
        SimpleName: C [30,31]

@pouryafard75
Copy link
Contributor Author

@jrfaller

  • I think the original implementation has some minor issues regarding the offests of the TextElement (which now came to surface because of the optionalTagName 😄), for instance TextElement: john [11,17] begins from 11 even though it seems 12 is the correct beginning offset. Please confirm this.

  • Shall I remove @ symbol from the TAG_NAME label?

I am using the following code snipet to test (in case you want to examine the offsets on your own)

/** @author john */
    class C {}

@tsantalis
Copy link

@pouryafard75
Is it a convention to use upper case names for AST node properties?
TAG_NAME TYPE_DECLARATION_KIND

@pouryafard75
Copy link
Contributor Author

pouryafard75 commented Jun 19, 2024

@tsantalis Yes, I tried to be consistent with the codebase.

@jrfaller
Copy link
Member

jrfaller commented Jul 1, 2024

Hi all! Uppercase is for types that are not directly converted from the JDT AST therefore it's perfect for this case! @pouryafard75 I think the structure is good!

@pouryafard75
Copy link
Contributor Author

pouryafard75 commented Sep 14, 2024

@jrfaller You can close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants