/**
  * Format the faulty source code line and point to the error.
  *
  * @param d The diagnostic for which the error line should be printed
  */
 protected String formatSourceLine(JCDiagnostic d, int nSpaces) {
   StringBuilder buf = new StringBuilder();
   DiagnosticSource source = d.getDiagnosticSource();
   int pos = d.getIntPosition();
   if (d.getIntPosition() == Position.NOPOS) throw new AssertionError();
   String line = (source == null ? null : source.getLine(pos));
   if (line == null) return "";
   buf.append(indent(line, nSpaces));
   int col = source.getColumnNumber(pos, false);
   if (config.isCaretEnabled()) {
     buf.append("\n");
     for (int i = 0; i < col - 1; i++) {
       buf.append((line.charAt(i) == '\t') ? "\t" : " ");
     }
     buf.append(indent("^", nSpaces));
   }
   return buf.toString();
 }
Пример #2
0
 protected int getIntEndPosition() {
   return (position == null ? Position.NOPOS : position.getEndPosition(source.getEndPosTable()));
 }
Пример #3
0
 /**
  * Get the name of the source file referred to by this diagnostic.
  *
  * @return the name of the source referred to with this diagnostic, or null if none
  */
 @DefinedBy(Api.COMPILER)
 public JavaFileObject getSource() {
   if (source == null) return null;
   else return source.getFile();
 }