Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » FIELD_ACCESS in org.eclipse.jdt.core.dom.FieldAccess *Strange behaviour
FIELD_ACCESS in org.eclipse.jdt.core.dom.FieldAccess *Strange behaviour [message #705381] Fri, 29 July 2011 20:07 Go to next message
john doe is currently offline john doeFriend
Messages: 74
Registered: June 2011
Member
I am parsing a method using AST (dom).
I take an expression from the method body and I check if it's ASTNode type is FIELD_ACCESS. I only get 'true' if I refer to an instance variable using 'this'.

For example, if I have
public class Foo {
   private int x = 10;

   public void bar() {
      x = 9;
   }
}


If I create a visitor for MethodDeclarations, when my code is passed the body of method 'bar' above, I can get the x assignment statement, but the left hand operand (x) is of type 'SimpleName' whatever that is. It's type is not FIELD_ACCESS. However, if I change the statement to 'this.x = 9;' then the left hand operand is of type FIELD_ACCESS. This means that anytime I reference an instance variable in my code, I MUST prefix it with 'this' to have it recognized by my code as a FIELD_ACCESS. Is there a way around this? Thanks

[Updated on: Fri, 29 July 2011 20:08]

Report message to a moderator

Re: FIELD_ACCESS in org.eclipse.jdt.core.dom.FieldAccess *Strange behaviour [message #707022 is a reply to message #705381] Mon, 01 August 2011 06:09 Go to previous message
Satyam Kandula is currently offline Satyam KandulaFriend
Messages: 444
Registered: July 2009
Senior Member
FieldAccess is used mostly when used in conjuction with 'this'. For more info, look at the javadoc associated with it.
If you want to find out if a given name reference is a field, you would have to do something like SimpleName.resolveBinding().isField().
ASTView (http://www.eclipse.org/jdt/ui/astview/index.php) is a nice plugin to show the DOM/AST of a given program. You can use this to find out means to get hold of any information of a program.
Previous Topic:Viewer Contribution
Next Topic:Java 6 method not being recognised
Goto Forum:
  


Current Time: Thu Apr 25 20:41:07 GMT 2024

Powered by FUDForum. Page generated in 0.02639 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top