@Override public String format(JCDiagnostic diagnostic, Locale locale) { if (diagnostic.getKind() == Kind.ERROR) { if (!(context.options.isIgnoreJavaFileNameError() && "compiler.err.class.public.should.be.in.file".equals(diagnostic.getCode()))) { reportJavaError(diagnostic, locale); } } switch (diagnostic.getKind()) { case ERROR: logger.error(diagnostic); break; case WARNING: case MANDATORY_WARNING: logger.debug(diagnostic); break; case NOTE: case OTHER: default: logger.trace(diagnostic); break; } if (diagnostic.getSource() != null) { return diagnostic.getMessage(locale) + " at " + diagnostic.getSource().getName() + "(" + diagnostic.getLineNumber() + ")"; } else { return diagnostic.getMessage(locale); } }
public MultilineDiagnostic(JCDiagnostic other, List<JCDiagnostic> subdiagnostics) { super(other.defaultFormatter, other.getType(), other.getLintCategory(), other.flags, other.getDiagnosticSource(), other.position, other.getCode(), other.getArgs()); this.subdiagnostics = subdiagnostics; }
/** * Override this method to tune how JSweet reports the errors. * * @param diagnostic * a Java-reported diagnostic (errors, warning, etc.) * @param locale * a locale */ protected void reportJavaError(JCDiagnostic diagnostic, Locale locale) { transpilationHandler.report( JSweetProblem.INTERNAL_JAVA_ERROR, new SourcePosition(new File(diagnostic.getSource().getName()), null, (int) diagnostic.getLineNumber(), (int) diagnostic.getColumnNumber()), diagnostic.getMessage(locale)); }
@Override public long getEndPosition() { long ret = this.delegate.getEndPosition(); if (delegate.hasFixedPositions()) { ret+=currentDelta; } return ret; }
private String format_std(JCDiagnostic d) { DiagnosticSource source = d.getDiagnosticSource(); DiagnosticType type = d.getType(); int position = d.getIntPosition(); sb.append(position == Position.NOPOS ? "-" : String.valueOf(d.getEndPosition())); break; sb.append(source == null ? "-" : d.getSourceName()); break; sb.append(position == Position.NOPOS ? "-" : String.valueOf(d.getLineNumber())); break; sb.append(position == Position.NOPOS ? "-" : String.valueOf(d.getColumnNumber())); break; sb.append(d.getPrefix()); break; sb.append(position == Position.NOPOS ? "-" : String.valueOf(d.getStartPosition())); break; sb.append(d.getPrefix()); break; sb.append(d.getMessage(null)); break;
public void report(JCDiagnostic diagnostic) { if (expectDiagKeys != null) expectDiagKeys.remove(diagnostic.getCode()); switch (diagnostic.getType()) { case FRAGMENT: throw new IllegalArgumentException(); if ((emitWarnings || diagnostic.isMandatory()) && !suppressNotes) { writeDiagnostic(diagnostic); if (emitWarnings || diagnostic.isMandatory()) { if (nwarnings < MaxWarnings) { writeDiagnostic(diagnostic); && shouldReport(diagnostic.getSource(), diagnostic.getIntPosition())) { writeDiagnostic(diagnostic); nerrors++; if (diagnostic.isFlagSet(JCDiagnostic.DiagnosticFlag.COMPRESSED)) { compressedOutput = true;
private long getPosition(JCDiagnostic d, PositionKind pk) { switch (pk) { case START: return d.getIntStartPosition(); case END: return d.getIntEndPosition(); case LINE: return d.getLineNumber(); case COLUMN: return d.getColumnNumber(); case OFFSET: return d.getIntPosition(); default: throw new AssertionError("Unknown diagnostic position: " + pk); } }
private String format_raw(JCDiagnostic d) { DiagnosticSource source = d.getDiagnosticSource(); int position = d.getIntPosition(); StringBuilder sb = new StringBuilder(); if (position == Position.NOPOS) sb.append("-"); else { sb.append(source.getName() + ":" + source.getLineNumber(position) + ":" + source.getColumnNumber(position) + ":"); } sb.append(" "); sb.append(d.getCode()); String sep = ": "; for (Object arg: d.getArgs()) { sb.append(sep); if (arg instanceof JCDiagnostic) { sb.append('('); sb.append(format_raw((JCDiagnostic) arg)); sb.append(')'); } else if (arg instanceof JavaFileObject) sb.append(JavacFileManager.getJavacBaseFileName((JavaFileObject) arg)); else sb.append(arg); sep = ", "; } return sb.toString(); }
switch (diagnostic.getType()) { case FRAGMENT: throw new IllegalArgumentException(); if (emitWarnings || diagnostic.isMandatory()) { writeDiagnostic(diagnostic); if (emitWarnings || diagnostic.isMandatory()) { if (nwarnings < MaxWarnings) { writeDiagnostic(diagnostic); && shouldReport(diagnostic.getSource(), diagnostic.getIntPosition())) { writeDiagnostic(diagnostic); nerrors++;
PrintWriter writer = getWriterForDiagnosticType(diag.getType()); int pos = diag.getIntPosition(); if (pos != Position.NOPOS) { JavaFileObject prev = useSource(diag.getSource()); printErrLine(pos, writer); useSource(prev); switch (diag.getType()) { case ERROR: case WARNING:
@Override public Object getSource() { return this.delegate.getSource(); }
public String formatMessage(JCDiagnostic d, Locale l) { StringBuilder buf = new StringBuilder(); Collection<String> args = formatArguments(d, l); buf.append(localize(null, d.getCode(), args.toArray())); if (d.isMultiline() && getConfiguration().getVisible().contains(DiagnosticPart.SUBDIAGNOSTICS)) { List<String> subDiags = formatSubdiagnostics(d, null); if (subDiags.nonEmpty()) { String sep = ""; buf.append(",{"); for (String sub : formatSubdiagnostics(d, null)) { buf.append(sep); buf.append("("); buf.append(sub); buf.append(")"); sep = ","; } buf.append('}'); } } return buf.toString(); }
/** * Returns true if the regex matches the diagnostic key and if * all diagnostic arguments are matches by corresponding sub-templates. */ boolean matches(Object o) { JCDiagnostic d = (JCDiagnostic)o; Object[] args = d.getArgs(); if (!d.getCode().matches(regex) || subTemplates.length != d.getArgs().length) { return false; } for (int i = 0; i < args.length ; i++) { if (!subTemplates[i].matches(args[i])) { return false; } } return true; } }
@Override public Void visitErroneous(ErroneousTree erroneousTree, Void unused) { JCDiagnostic diagnostic = ((DCErroneous) erroneousTree).diag; if (!diagnostic.getCode().equals("compiler.err.dc.bad.inline.tag")) { return null; } JavadocTag tag = inlineTag(erroneousTree.toString().replace("@", "")); SuggestedFix fix = validTags.contains(tag) ? replace(erroneousTree, String.format("{%s}", erroneousTree), state) : SuggestedFix.builder().build(); String message = String.format( "%s is not a valid block tag. Should it be an inline tag instead?", erroneousTree); state.reportMatch( buildDescription(diagnosticPosition(getCurrentPath(), state)) .setMessage(message) .addFix(fix) .build()); return null; }
/** * Create a note diagnostic. * @param source The source of the compilation unit, if any, in which to report the note. * @param pos The source position at which to report the note. * @param key The key for the localized error message. * @param args Fields of the error message. */ public JCDiagnostic note( DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { return new JCDiagnostic(messages, NOTE, false, source, pos, qualify(NOTE, key), args); }
@Override public String getMessage() { if (diag != null) return diag.getMessage(null); else return errmsg; }
public String formatDiagnostic(JCDiagnostic d, Locale l) { try { StringBuilder buf = new StringBuilder(); if (d.getPosition() != Position.NOPOS) { buf.append(formatSource(d, false, null)); buf.append(':'); buf.append(formatPosition(d, LINE, null)); buf.append(':'); buf.append(formatPosition(d, COLUMN, null)); buf.append(':'); } else if (d.getSource() != null && d.getSource().getKind() == JavaFileObject.Kind.CLASS) { buf.append(formatSource(d, false, null)); buf.append(":-:-:"); } else buf.append('-'); buf.append(' '); buf.append(formatMessage(d, null)); if (displaySource(d)) { buf.append("\n"); buf.append(formatSourceLine(d, 0)); } return buf.toString(); } catch (Exception e) { //e.printStackTrace(); return null; } }
/** Construct a <code>FatalError</code> with the specified detail message. * @param d A diagnostic containing the reason for failure. */ public FatalError(JCDiagnostic d) { super(d.toString()); }
/** * Preprocess a given diagnostic by looking both into its arguments and into * its subdiagnostics (if any). This preprocessing is responsible for * generating info corresponding to features like where clauses, name * simplification, etc. * * @param diag the diagnostic to be preprocessed */ protected void preprocessDiagnostic(JCDiagnostic diag) { for (Object o : diag.getArgs()) { if (o != null) { preprocessArgument(o); } } if (diag.isMultiline()) { for (JCDiagnostic d : diag.getSubdiagnostics()) preprocessDiagnostic(d); } }
/** * Extracts diagnostic params from a diagnostic. Gets under hood of Javac * Diagnostic objects and extracts parameters which are otherwise just used * to produce a message. <b>Keep in mind that the positions and types of parameters * may change in each nbjavac update!</b> * @param d diagnostic * @param index parameter index to extract * @return parameter value, null if index is out of range */ public static Object getDiagnosticParam(Diagnostic<?> d, int index) { JCDiagnostic jcd = getJCDiagnostic(d); if (jcd == null) { return null; } Object[] args = jcd.getArgs(); if (args == null || args.length <= index) { return null; } return args[index]; }