hi, I am new here... I am currently facing some trouble in pulling out the Attribute as in its types and names.
My program purpose is to read the Java file and display all the String into tokens. Then, it must be able to pull out the class name, attribute names and methods name. I manage to pull out the class name but now i dont know how to pull out (retrieve) attributes and methods.
Below are my source code so far...hope any expert can help me solve this problem...
import java.util.*;
import java.io.*;
public class Java2UML {
private static final int INITIAL = 0;
private static final int COMMENT = 1;
private static final int SCANNED_CLASS = 2;
private static final int SCANNED_ATTRIBUTE = 3;
private static final int SCANNED_METHOD = 4;
private static final int READING_CURLYBRACKET = 5;
private static final int READING_ATTRIBUTES = 6;
private String filename; //declare the variable filename of type String
private Scanner sc;
String className;
Java2UML ( String name ) {
filename = name;
}
public void openFile() throws IOException {
System.out.println( "File: " + filename );
sc = new Scanner( new File ( filename ) );
}
public void readFile() {
while (sc.hasNextLine() ) {
String line;
line = sc.nextLine();
tokenize(line);
}
}
/************************
* tokenizes a single line, which is passed in as a parameter.
*/
public void tokenize(String line) {
String token;
int scanState = INITIAL;
StringTokenizer st = new StringTokenizer( line, "; " );
while (st.hasMoreTokens()) {
token = st.nextToken();
if (token.equalsIgnoreCase( "//" )) {
// we've seen the beginning of comment.
scanState = COMMENT;
} else if (token.equalsIgnoreCase( "CLASS" )) {
scanState = SCANNED_CLASS;
continue;
}
switch (scanState) {
case Java2UML.COMMENT: continue;
case Java2UML.SCANNED_CLASS:
className = token;
drawClass(className);
scanState = READING_CURLYBRACKET;
continue;
case Java2UML.SCANNED_ATTRIBUTE:
}
System.out.println("This is a token <" + token + ">");
}
}
public void drawClass(String className) {
System.out.println( "---------------------------" );
System.out.println( "CLASS NAME IS : " + className );
System.out.println( "---------------------------" );
}
public static void main (String args [])throws Exception{
Java2UML x;
x = new Java2UML ( "Java2UML.java" );
x.openFile();
x.readFile();
}
}