Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » [Help] About ASTNode
[Help] About ASTNode [message #639255] Mon, 15 November 2010 18:34 Go to next message
Kam Ng is currently offline Kam NgFriend
Messages: 13
Registered: November 2010
Location: Hong Kong
Junior Member
Hello,

public void getInvokingMethode(String code) {
	ASTParser parser = ASTParser.newParser(AST.JLS3);
	parser.setSource(code.toCharArray());
	parser.setKind(ASTParser.K_EXPRESSION);
	ASTNode node = parser.createAST(null);
	
	if (node.getNodeType() == ASTNode.METHOD_INVOCATION) {
		MethodInvocation methodInvocation = (MethodInvocation) node;
		System.out.println("Invoking method : "+ methodInvocation.getName());
	}
}


I am using the code above and I am tring to get the API usage inside a method.
Since the parameter that I input is a java file, so I can only get the ASTNode.COMPILATION_UNIT.
How can I change the node position? For example, change to ASTNode.METHOD_INVOCATION
or somewhere else.


Kam

[Updated on: Mon, 15 November 2010 18:35]

Report message to a moderator

Re: [Help] About ASTNode [message #639260 is a reply to message #639255] Mon, 15 November 2010 19:03 Go to previous messageGo to next message
Olivier Thomann is currently offline Olivier ThomannFriend
Messages: 518
Registered: July 2009
Senior Member
What is the source that you are passing in?
Does it contain syntax errors ?
--
Olivier
Re: [Help] About ASTNode [message #639393 is a reply to message #639260] Tue, 16 November 2010 11:47 Go to previous messageGo to next message
Kam Ng is currently offline Kam NgFriend
Messages: 13
Registered: November 2010
Location: Hong Kong
Junior Member
Actually, I am using the java file which contain the code above. I am using the program to analyze the code belongs to itself. The program runs successfully, so I think there is no error.

[Updated on: Tue, 16 November 2010 11:48]

Report message to a moderator

Re: [Help] About ASTNode [message #639537 is a reply to message #639393] Tue, 16 November 2010 20:16 Go to previous message
Olivier Thomann is currently offline Olivier ThomannFriend
Messages: 518
Registered: July 2009
Senior Member
If you provide the kind K_EXPRESSION, then you need to pass in only an expression.
If you provide a compilation unit, then you should specify the kind to be a K_COMPILATION_UNIT and you can then simply use a NodeFinder call to find the corresponding expression if you know at what position the expression is located.

HTH,
--
Olivier

Previous Topic:Java editing: The popup menu while hovering over the red squiggle.
Next Topic:Finding out changes to methods?
Goto Forum:
  


Current Time: Fri Apr 19 13:16:30 GMT 2024

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

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

Back to the top