My .java file consists of a series of codes and each line is of variable size. The .java file is shown below:
public class MyC{
public void MyMethod()
{
System.out.println("My method has been accessed");
System.out.println("hi");
String l;
int x=0;
}
}
Briefly, what i want to do is to scan the .java file for errors and capture the errors in a string. I have used a diagnostic collector to capture the start and end positions of the error.
Suppose I've made an error at line 7: in x=0; The diagnostic collector will return me the positions for example 143-145 error has occurred.
I also get the line numbers but the positions returned are relative to the whole .java file. Thus using the line numbers would be pointless as each line is of variable length and the positions are relative to the whole file. It will be difficult to compute the actual position of the error at a line.
And there is no way for me to get the end position of the last character in the previous line if there is no error at the last character of the previous line(e.g: error at line 7: previous line = line 6).
Is there a way for me to get a string by using its position(start and end) from a java file?