Martinho0330 / javaparser

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

simple names with parenthesis around get recognized as CastExpr #19

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When recognizing an expression like the following the AST contains a
ClassCastExpr of type "foo".

int a = (foo)+bar;

I don't know if this is fixable in the AST parser because it needs semantic
knowledge. And its not that easy to check if "foo" is REALLY no type in
current scope. This behavior should at least be documented.

Original issue reported on code.google.com by michaelkoch6@googlemail.com on 9 Mar 2009 at 9:57

GoogleCodeExporter commented 9 years ago
this kind of expression shouldn't be parsed to CastExpr

Original comment by jges...@gmail.com on 1 Apr 2009 at 2:20

GoogleCodeExporter commented 9 years ago
I see currently no way to do that easily in the parser without a complete 
semantic
analysis. Tell me if I'm wrong. If you point me into the right direction I'm 
willing
to do the needed coding to implement it correctly in javaparser.

Original comment by michaelkoch6@googlemail.com on 6 Apr 2009 at 5:55

GoogleCodeExporter commented 9 years ago
I haven't found a way to determine this kind of expression in the parser.
There is no syntax difference between
  int a = (foo)+bar;
and
  byte a = (byte)+bar;
where the second expression is indeed a CastExpr. Semantics should be used to
determine if it is a Cast or not. But, if the expression looks like this:
int a = (+foo)+bar;
the parser will recognize it as a simple BinaryExpr with parenthesis in the 
left operand.

What I think you could do is add a specific semantic for this case in your 
visitor.
It will isn't be a simple task, I will research a little more to check if there 
is
any other solution, if I find anything I will reopen this issue.

Original comment by jges...@gmail.com on 13 Apr 2009 at 12:39

GoogleCodeExporter commented 9 years ago
I have found a way to solve this issue in the Java Language Specification. But 
to
solve this I will need to make a lot of changes in the parser, I have starter 
the
changes now.

Original comment by jges...@gmail.com on 13 Apr 2009 at 12:56

GoogleCodeExporter commented 9 years ago
Issue solved, released in 1.0.7.

thanks!

Original comment by jges...@gmail.com on 13 Apr 2009 at 1:48