Martinho0330 / javaparser

Automatically exported from code.google.com/p/javaparser
0 stars 0 forks source link

Parsing arrays of the form "Type id[]" produces incorrect AST #24

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Japa does not seem to parse arrays of the form

Type id[]

correctly. It seems to discard the array brackets and just returns the 
AST  for "Type id".

E.g. in class java.lang.StringBuffer there is the following method:

public synchronized StringBuffer insert(int index, char str[], int 
offset, int len)

The "char str[]" is parsed as a simple PrimitiveType(type=char), not as a 
ReferenceType(arraycount=1,type=PrimitiveType(type=char)), as it should 
be.

I guess this case (array brackets after, not in front of the identifier) 
is just missing from java_1_5.jj and I would appreciate it if you could 
add support for these arrays as they are even - as you can see above - 
used in the standard Java libraries...

Thank you very much!
Martin

Original issue reported on code.google.com by martin.p...@gmail.com on 8 Sep 2009 at 1:11

GoogleCodeExporter commented 9 years ago
Do you know where I could start to work on it myself? Where in java_1_5.jj 
should I 
add a new production? It seems "Type" and "id" are separated quite early...

Original comment by martin.p...@gmail.com on 26 Sep 2009 at 9:00

GoogleCodeExporter commented 9 years ago
Martin,

actually it is working as it should be.
There is no problem in parsing arrays with brackets in the variable id. The 
problem
is you are waiting for something in one way and the parser is returning in 
other way.
The brackets in this case are stored in the variable id, and not in the type id.

E.g. in class java.lang.StringBuffer there is the following method:

public synchronized StringBuffer insert(int index, char str[], int offset, int 
len)

The "char str[]" is parsed as
Parameter(type=PrimitiveType(byte), id=VariableDeclaratorId(name=arr, 
arrayCount=1))
exactly as it should be. 

Look at the atribute "arrayCount" in the VariableDeclaratorId, here are the lost
brackets. When a array is declare in this form, the VariableDeclaratorId will 
always
carry the array count.

Case solved, issue closed.

Original comment by jges...@gmail.com on 29 Sep 2009 at 2:27

GoogleCodeExporter commented 9 years ago
Thank you very much for your explanation! Now I changed the output to also use 
VariableId.arrayCount and it works perfectly!

Original comment by martin.p...@gmail.com on 30 Sep 2009 at 8:33