Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » Statement break down(Seperating a statement in different parts)
Statement break down [message #1387749] Wed, 25 June 2014 14:36 Go to next message
Kris Ram is currently offline Kris RamFriend
Messages: 11
Registered: July 2012
Junior Member
Hi guys,

I have am developing a small eclipse plugin which will be reading a method and then performing a small processing on various parts of the method.

An example of a method that the plugin would be processing


@Test
	public void testDoSometingSuccessfully() {
		
		InputParameter inputParameter = new InputParameter();
		inputParameter.setInputParameterFieldOne("something");
		
		OutputParameter outputParameter = sample.doSomething(inputParameter );
		
		assertTrue(true);
	}


So far I have been able to break down the method with the code below

		ASTParser parser = ASTParser.newParser(AST.JLS4);
		parser.setSource(source.toCharArray());
		parser.setKind(ASTParser.K_STATEMENTS);
		Block block = (Block) parser.createAST(null);

		//here can access the first element of the returned statement list
		List<Statement> statements = block.statements();
 
		for (int i = 0; i < statements.size(); i++) {
			System.out.println("statement : " + statements.get(i).toString());
		}
		


I wanted to process the statements further, but I could not find a suitable way yet.

For instance, how do I get the separate parts for the Statement 'assertTrue(true);'



Best regards
Kris
Re: Statement break down [message #1387826 is a reply to message #1387749] Wed, 25 June 2014 16:47 Go to previous messageGo to next message
David Wegener is currently offline David WegenerFriend
Messages: 1445
Registered: July 2009
Senior Member
You can get the nodeType for each statement (a Statement is a subclass of ASTNode) and then cast accordingly to be able pull the details out. Checkout the JavaDoc for ASTNode and look at its class hierarchy to learn what types of nodes are available.
Re: Statement break down [message #1388472 is a reply to message #1387826] Thu, 26 June 2014 13:49 Go to previous message
Kris Ram is currently offline Kris RamFriend
Messages: 11
Registered: July 2012
Junior Member
Hi David,

thanks for the reply.
I used visitors to get the expressions.

public class AssertVisitor extends ASTVisitor {
	
	private int assertRating;
	
	private static int numberOfAsserts;
	
	@Override
	public boolean visit(MethodInvocation node) {
		 
		System.out.println("Expression : " + node.getName());
		System.out.println("Node type : " + node.getNodeType());
		
		if (node.getName().toString().startsWith("assert")) {
			numberOfAsserts = numberOfAsserts + 1;
		}
		
	
		
		return true;
	}




I am still investigating how I can determine the depth of assert. By that I mean
to determine how many fields in OutputParameter have been asserted

Any advice you can provide is appreciated.

Cheers
Kris




Previous Topic:Not able to register javax.xml.bind jar
Next Topic:Early startup after workbench was initialized
Goto Forum:
  


Current Time: Tue Apr 16 21:08:41 GMT 2024

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

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

Back to the top