/** * 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; } }
/** * 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; } }
/** * 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]; }
@Override public JCDiagnostic rewriteDiagnostic(JCDiagnostic.Factory diags, DiagnosticPosition preferedPos, DiagnosticSource preferredSource, DiagnosticType preferredKind, JCDiagnostic d) { JCDiagnostic cause = (JCDiagnostic)d.getArgs()[0]; return diags.create(preferredKind, preferredSource, d.getDiagnosticPosition(), "prob.found.req", cause); } });
private static void getNestedDiagnostics(Diagnostic<?> d, List<Diagnostic> diags) { JCDiagnostic jcd = getJCDiagnostic(d); if (jcd == null) { return; } Object[] args = jcd.getArgs(); if (args == null || args.length == 0) { return; } for (Object o : args) { if (o instanceof Diagnostic) { diags.add((Diagnostic)o); getNestedDiagnostics((Diagnostic)o, diags); break; } } }
@Override public JCDiagnostic rewriteDiagnostic(JCDiagnostic.Factory diags, DiagnosticPosition preferedPos, DiagnosticSource preferredSource, DiagnosticType preferredKind, JCDiagnostic d) { JCDiagnostic cause = (JCDiagnostic)d.getArgs()[0]; DiagnosticPosition pos = d.getDiagnosticPosition(); if (pos == null) { pos = preferedPos; } return diags.create(preferredKind, preferredSource, pos, "prob.found.req", cause); } });
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(); }
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 BaseFileObject) sb.append(((BaseFileObject) arg).getShortName()); else if (arg instanceof JavaFileObject) sb.append(BaseFileObject.getSimpleName((JavaFileObject) arg)); else sb.append(arg); sep = ", "; } return sb.toString(); }
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; }
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; }
/** * Format the arguments of a given diagnostic. * * @param d diagnostic whose arguments are to be formatted * @param l locale object to be used for i18n * @return a Collection whose elements are the formatted arguments of the diagnostic */ protected Collection<String> formatArguments(JCDiagnostic d, Locale l) { ListBuffer<String> buf = new ListBuffer<String>(); for (Object o : d.getArgs()) { buf.append(formatArgument(d, o, l)); } return buf.toList(); }
/** * Format the arguments of a given diagnostic. * * @param d diagnostic whose arguments are to be formatted * @param l locale object to be used for i18n * @return a Collection whose elements are the formatted arguments of the diagnostic */ protected Collection<String> formatArguments(JCDiagnostic d, Locale l) { ListBuffer<String> buf = new ListBuffer<String>(); for (Object o : d.getArgs()) { buf.append(formatArgument(d, o, l)); } return buf.toList(); }
/** * 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); } }
/** * 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); } }
private boolean transferParseErrors( int literalOffset, StringLiteralTemplateParser.Expr comp, JCTree.JCExpression expr, DiagnosticCollector<JavaFileObject> errorHandler ) { if( expr == null || errorHandler.getDiagnostics().stream().anyMatch( e -> e.getKind() == Diagnostic.Kind.ERROR ) ) { for( Diagnostic<? extends JavaFileObject> diag : errorHandler.getDiagnostics() ) { if( diag.getKind() == Diagnostic.Kind.ERROR ) { JCDiagnostic jcDiag = ((ClientCodeWrapper.DiagnosticSourceUnwrapper)diag).d; String code = debaseMsgCode( diag ); IDynamicJdk.instance().logError( Log.instance( _javacTask.getContext() ), new JCDiagnostic.SimpleDiagnosticPosition( literalOffset + 1 + comp.getOffset() ), code, jcDiag.getArgs() ); } } return true; } return false; }