Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have the following txt fil, I'm wondering how can I pars it and search for Cell And Engin words, what I want is to print out the method name that contains Cell, Engine words. the following is the txt file don't look at it as java code since I already moved it to txt file for parsing purposes.

@Test
public void testGetMonsters() {
Cell cell11 = aBoard.getCell(1, 1);
theEngine = new Engine(theGame);
}

@Test
public void testDxDyPossibleMove() {
Cell cell11 = aBoard.getCell(1, 1);
}
the output of parsing looks like: testGetMonsters method contains Cell and Engine words
testDxDyPossibleMove method contains Cell word
Posted
Updated 25-Oct-11 8:09am
v4
Comments
Manfred Rudolf Bihy 25-Oct-11 13:35pm    
testGetMonsters and testDxDyPossibleMove are not classes, but they are methods. Are you sure of what you're what trying to achieve?
medoded2009 25-Oct-11 13:59pm    
sorry yes you are right

1 solution

If the words Cell and Engine have to be Java types[^], as your usage sample suggests, there is no way around using a real parser that can parse the Java language. If the words can appear in any context you could go after them with regular expressions[^] making sure that the words you are searching for are delimited by word boundary characters ("\b").

This site can help you build a Java parser as there are already samples for the complete Java grammar: http://www.antlr.org/[^].

If you have any doubts or questions, feel free to leave a comment.

Cheers!

—MRB
 
Share this answer
 
v2
Comments
medoded2009 25-Oct-11 14:01pm    
Dear Manfred the that code above is a text, sine i have already written a code to copy the java code to test.txt file

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900