
hi, I have done a program whereby it can read a Java file and then tokenize them into tokens. However, I am facing one problem which is retrieve the Class Name, Attributes Name and Methods Names only from the source code. Can anyone help me to solve it? Below are my portion of codes. Thx!
import java.util.*;
import java.io.*;
public class Abc {
private String filename;
private int count;
Abc( String name ) {
filename = name;
count = 0;
}
public void readFile() throws IOException{
String line;
System.out.println( "File: " + filename );
Scanner sc = new Scanner( new File ( filename ) );
while (sc.hasNextLine() ) {
line = sc.nextLine();
count++;
tokenize(line);
}
}
public void tokenize(String line) throws IOException {
StringTokenizer st = new StringTokenizer( line, "; " );
while (st.hasMoreTokens()) {
System.out.println("This is a token <" + st.nextToken() + ">");
}
}
public static void main (String args [])throws Exception{
Abc x;
x = new Abc ( "Abc.java" );
x.readFile();
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.