Diagnostic: getLineNumber() : Diagnostic « javax.tools « Java by API






Diagnostic: getLineNumber()

     

import javax.tools.Diagnostic;
import javax.tools.DiagnosticCollector;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;

public class Main {
  public static void main(String[] args) {
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    DiagnosticCollector<JavaFileObject> dc = new DiagnosticCollector<JavaFileObject>();
    StandardJavaFileManager sjfm = compiler.getStandardFileManager(dc, null, null);
    Iterable<? extends JavaFileObject> fileObjects = sjfm.getJavaFileObjects(args);
    compiler.getTask(null, sjfm, dc, null, null, fileObjects).call();
    for (Diagnostic d : dc.getDiagnostics()) {
      System.out.println(d.getMessage(null));
      System.out.printf("Line number = %d\n", d.getLineNumber());
      System.out.printf("File = %s\n", d.getSource());
    }
  }
}

   
    
    
    
    
  








Related examples in the same category

1.Diagnostic: getCode()
2.Diagnostic: getEndPosition()
3.Diagnostic: getKind()
4.Diagnostic: getMessage(Locale locale)
5.Diagnostic: getPosition()
6.Diagnostic: getSource()
7.Diagnostic: getStartPosition()