Martinho0330 / javaparser

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

Wrong Code generated for "this" and "super" #25

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
For "this":
run this code:
    FieldDeclaration field = new FieldDeclaration(
                                      ModifierSet.PRIVATE, 
                                      new
PrimitiveType(PrimitiveType.Primitive.Boolean), 
                                      new VariableDeclarator(new
VariableDeclaratorId("isWorking")));

    MethodDeclaration getter = new MethodDeclaration(
                                     ModifierSet.PUBLIC, 
                                     field.getType(), 
                                     "get" + /*StringUtils.capitalize(*/
field.getVariables().get(0).getId().getName()/*)*/);

    BlockStmt block = new BlockStmt();
    ReturnStmt ret = new ReturnStmt(new ThisExpr(
             new NameExpr(field.getVariables().get(0).getId().getName())));
//ReturnStmt ret = new ReturnStmt(new SuperExpr(new
NameExpr(field.getVariables().get(0).getId().getName())));

    List<Statement> statements = new ArrayList<Statement>();
    statements.add(ret);
    block.setStmts(statements);
    getter.setBody(block);
    System.out.println(getter);

What is the expected output? What do you see instead?
Expected output:
public boolean getIsWorking() {
    return this.isWorking;
}

What's produced is:
public boolean getIsWorking() {
    return isWorking.this;
}
What version of the product are you using? On what operating system?
Latest. Mac OSX

Please provide any additional information below.
I played with the DumpVisitor class to get it fixed.. but I dont know if I
broke something else.. the unit tests failed for some reason..

Original issue reported on code.google.com by same%nan...@gtempaccount.com on 10 Oct 2009 at 8:02

GoogleCodeExporter commented 9 years ago
The output is correct for your code, its just hat your code is wrong.

new ThisExpr(new NameExpr(...)

should be something like

new FieldAccessExpr(new ThisExpr(), "isWorking");

Original comment by michaelkoch6@googlemail.com on 9 Nov 2009 at 5:17

GoogleCodeExporter commented 9 years ago
Great thanks.. that worked fine ..

Original comment by same%nan...@gtempaccount.com on 9 Nov 2009 at 9:57

GoogleCodeExporter commented 9 years ago
Thank you Machael!

Issue closed.

Original comment by jges...@gmail.com on 9 Nov 2009 at 11:21