Skip to content
New issue

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

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

Already on GitHub? # to your account

WIP: feat(CtArrayTypeReference): store printing information of array declaration in AST #4344

Closed

Conversation

algomaster99
Copy link
Contributor

This PR adds another meta-model information to CtArrayTypeReference - ARRAY_DECLARATION_KIND. Java has two ways to place [] for array declaration.

  1. int[] array
  2. int array[]

Although the convention discourages the latter form of declaration, it is still allowed.

Currently, Spoon is unable to print [] after the variable name. See #4315 . Storing this information in the meta-model is a nice solution to it, but I also agree with @slarse here. Printing information has always been kept out of AST and that's why we have implemented a sniper printer in the first place.

Another solution is to add a function called printBracketsIfRequired here in DJPP::visitCtField. See "how it prints identifier".

@algomaster99 algomaster99 force-pushed the add-array-declaration-kind branch from 2b89d38 to 69a4c03 Compare December 10, 2021 09:48
@algomaster99 algomaster99 force-pushed the add-array-declaration-kind branch from 69a4c03 to d5f67a5 Compare December 10, 2021 12:28
@algomaster99
Copy link
Contributor Author

I tried to modify the printers to incorporate for printing [] based on array declaration and it works for simpler cases like the ones in #4341 - int x[] and String x[][][].

However, I came to know about the fact that Java also compiles the following declaration 😠 :

int[] x[] = new int[42][10]

This really points to the fact that we should not store this information in the AST because the possibility of bracket placement goes factorially high as the dimensions increase. Moreover, if we proceed to store such information in the AST, it might just pollute it with formatting information and it no longer will be abstract syntax tree . A better way is to let the sniper printer deal with this. I am not sure how it will happen, but I can look for a fix; hopefully, by next week.

P.S. curse the people who declare multi-dimensional arrays like that.

@algomaster99 algomaster99 deleted the add-array-declaration-kind branch December 10, 2021 14:50
@algomaster99 algomaster99 restored the add-array-declaration-kind branch December 23, 2021 09:30
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant