Java Reference
In-Depth Information
The specific parser for the Java language is implemented by JavaLanguage .
This class implements the method parse() . It is a very simple parser that
recognizes the name of the class and the signatures of the public members.
Whenever the parser method recognizes an entity, it notifies the docu-
menter using a new JavaParseEvent object. To make the code more compact
the notification is performed by the two methods doNotify() .
public class JavaLanguage extends Parser {
public void parse (StringTokenizer scanner){
doNotify(JavaParseEvent.BEGIN_PARSING);
// define and initialize flags
boolean classNameFound # false ;
boolean nextIsName # false ;
boolean publicMember # false ;
StringBuffer member # null ;
while (scanner.hasMoreTokens()){
String token # scanner.nextToken();
// Initially seek for the name of the class
if (!classNameFound){
if (token.equals("class"))
nextIsName # true ;
else if (nextIsName){
doNotify(JavaParseEvent.FOUND_CLASS,token);
nextIsName # false ;
classNameFound # true ;
}
} else // then starts looking for public members
if (token.equals("public")){
publicMember # true ;
member # new StringBuffer();
} else if (publicMember){
if (token.indexOf(";")> # 0){
member.append(token.substring(0,token.indexOf
(";")));
doNotify(JavaParseEvent.FOUND_MEMBER,
member.toString());
publicMember # false ;
} else if (token.indexOf("{")> # 0){
member.append(token.substring(0,token.indexOf
("{")));
doNotify(JavaParseEvent.FOUND_MEMBER,
member.toString());
publicMember # false ;
} else {
member.append(token);
member.append(" ");
}
}
}
doNotify(JavaParseEvent.END_PARSING);
}
Search WWH ::




Custom Search