Context subContext = new SubContext(context); subContext.put(ErrorProneOptions.class, errorProneOptions); Log log = Log.instance(context); JCCompilationUnit compilation = (JCCompilationUnit) path.getCompilationUnit(); DescriptionListener descriptionListener = JavaFileObject originalSource = log.useSource(compilation.getSourceFile()); try { if (shouldExcludeSourceFile(compilation)) { log.error("error.prone.crash", getStackTraceAsString(e), version, "(see stack trace)"); throw e; } catch (CompletionFailure e) { log.error("proc.cant.access", e.sym, e.getDetailValue(), getStackTraceAsString(e)); } finally { log.useSource(originalSource);
public void logFatalError(Log log, Context context) { String version = ErrorProneVersion.loadVersionFromPom().or("unknown version"); JavaFileObject originalSource = log.useSource(source); Factory factory = Factory.instance(context); try { log.report( factory.create( DiagnosticType.ERROR, log.currentSource(), pos, "error.prone.crash", Throwables.getStackTraceAsString(cause), version, checkName)); } finally { log.useSource(originalSource); } }
Resolve resolve = Resolve.instance(state.context); Enter enter = Enter.instance(state.context); Log log = Log.instance(state.context); DeferredDiagnosticHandler handler = new DeferredDiagnosticHandler(log); try { log.popDiagnosticHandler(handler);
/** @deprecated prefer {@link #logFatalError(Log, Context)} */ @Deprecated public void logFatalError(Log log) { String version = ErrorProneVersion.loadVersionFromPom().or("unknown version"); JavaFileObject prev = log.currentSourceFile(); try { log.useSource(source); // use reflection since this overload of error doesn't exist in JDK >= 11 Method m = Log.class.getMethod("error", DiagnosticPosition.class, String.class, Object[].class); m.invoke( log, pos, "error.prone.crash", Throwables.getStackTraceAsString(cause), version, checkName); } catch (ReflectiveOperationException e) { throw new LinkageError(e.getMessage(), e); } finally { log.useSource(prev); } }
@Override public void finished(TaskEvent event) { if (event.getKind() != Kind.GENERATE) { return; } RefactoringResult refactoringResult; try { refactoringResult = refactoringCollection.applyChanges(event.getSourceFile().toUri()); } catch (Exception e) { PrintWriter out = Log.instance(context).getWriter(WriterKind.ERROR); out.println(e.getMessage()); out.flush(); return; } if (refactoringResult.type() == RefactoringCollection.RefactoringResultType.CHANGED) { PrintWriter out = Log.instance(context).getWriter(WriterKind.NOTICE); out.println(refactoringResult.message()); out.flush(); } } }
pos = null; } else { oldSource = log.useSource(newSource); boolean prev = log.multipleErrors; try { log.error(pos, "proc.messager", msg.toString()); } finally { log.multipleErrors = prev; log.warning(pos, "proc.messager", msg.toString()); break; log.mandatoryWarning(pos, "proc.messager", msg.toString()); break; log.note(pos, "proc.messager", msg.toString()); log.useSource(oldSource);
/** report an error: */ public void rawError(int pos, String msg) { if (nerrors < MaxErrors && shouldReport(currentSource(), pos)) { printRawError(pos, msg); prompt(); nerrors++; } errWriter.flush(); }
/** Report an error that wrong type tag was found. * @param pos Position to be used for error reporting. * @param required An internationalized string describing the type tag * required. * @param found The type that was found. */ Type typeTagError(DiagnosticPosition pos, Object required, Object found) { log.error(pos, "type.found.req", found, required); return syms.errType; }
/** * Sets the compilation unit to be scanned. */ protected final void setCompilationUnit(JCCompilationUnit compilationUnit) { if (compilationUnit != null) { this.compilationUnit = compilationUnit; for (JCImport i : this.compilationUnit.getImports()) { if (i.staticImport) { staticImports.put(i.qualid.toString().substring(i.qualid.toString().lastIndexOf(".") + 1), i); } } this.diagnosticSource = new DiagnosticSource(compilationUnit.sourcefile, Log.instance(context)); } else { this.compilationUnit = null; this.diagnosticSource = null; } }
/** * Reports a mandatory warning to the log. If mandatory warnings * are not being enforced, treat this as an ordinary warning. */ private void logMandatoryWarning(DiagnosticPosition pos, String msg, Object... args) { // Note: the following log methods are safe if lintCategory is null. if (enforceMandatory) log.mandatoryWarning(lintCategory, pos, msg, args); else log.warning(lintCategory, pos, msg, args); }
/** * Reports a mandatory note to the log. If mandatory notes are * not being enforced, treat this as an ordinary note. */ private void logMandatoryNote(JavaFileObject file, String msg, Object... args) { if (enforceMandatory) log.mandatoryNote(file, msg, args); else log.note(file, msg, args); } }
@Override public void popDiagnosticHandler( DiagnosticHandler handler ) { super.popDiagnosticHandler( handler ); _suspendedIssues.remove( handler ); }
/** print an error or warning message: */ private void printRawError(int pos, String msg) { if (!findLine(pos)) { printLines(errWriter, "error: " + msg); } else { JavaFileObject file = currentSource(); if (file != null) printLines(errWriter, JavacFileManager.getJavacFileName(file) + ":" + line + ": " + msg); printErrLine(pos, errWriter); } errWriter.flush(); }
public void note(String key, Object... params) { // no "raw" API for producing notes; so omitting them on Java 8 if (registeredResourceBundle) { log.note(new Note("compiler", key, params)); } }
compiler.genEndPos = true; compiler.keepComments = true; log = Log.instance(context); log.dumpOnError = false; log.emitWarnings = false; log.setWriters(new PrintWriter(new StringWriter() { @Override public void write(String str) { log.setDiagnosticFormatter(factory.createDiagnosticHandler(transpilationHandler, context));
private void java2ts(ErrorCountTranspilationHandler transpilationHandler, SourceFile[] files) throws IOException { List<JCCompilationUnit> compilationUnits = setupCompiler(Arrays.asList(SourceFile.toFiles(files)), transpilationHandler); if (compilationUnits == null) { return; } if (candiesProcessor.hasDeprecatedCandy()) { context.deprecatedApply = true; logger.warn("\n\n\n*********************************************************************\n" // + "*********************************************************************\n" // + " YOUR CLASSPATH CONTAINS JSweet v1.x CANDIES \n" // + " This can lead to unexpected behaviors, please contribute to https://github.com/jsweet-candies \n" // + " to add your library's typings \n" // + "*********************************************************************\n" // + "*********************************************************************\n\n"); } context.sourceFiles = files; factory.createBeforeTranslationScanner(transpilationHandler, context).process(compilationUnits); if (context.useModules) { generateTsFiles(transpilationHandler, files, compilationUnits); } else { if (bundle) { generateTsBundle(transpilationHandler, files, compilationUnits); } else { generateTsFiles(transpilationHandler, files, compilationUnits); } } log.flush(); }
/** Report an error, unless another error was already reported at same * source position. * @param pos The source position at which to report the error. * @param key The key for the localized error message. * @param args Fields of the error message. */ public void error(DiagnosticPosition pos, String key, Object ... args) { report(diags.error(source, pos, key, args)); }
LazyDocCommentTable(ParserFactory fac) { this.fac = fac; diagSource = fac.log.currentSource(); table = new HashMap<JCTree, Entry>(); }
private void warnIfUnmatchedOptions() { if (!unmatchedProcessorOptions.isEmpty()) { log.warning("proc.unmatched.processor.options", unmatchedProcessorOptions.toString()); } }