use of com.sun.tools.javac.util.JCDiagnostic in project lombok by rzwitserloot.
the class CompilerMessageSuppressor method removeAllBetween.
public void removeAllBetween(JavaFileObject sourcefile, int startPos, int endPos) {
DiagnosticListener<?> listener = context.get(DiagnosticListener.class);
if (listener instanceof CapturingDiagnosticListener) {
((CapturingDiagnosticListener) listener).suppress(startPos, endPos);
}
Field field = null;
Object receiver = null;
if (deferDiagnosticsField != null)
try {
if (Boolean.TRUE.equals(deferDiagnosticsField.get(log))) {
field = deferredDiagnosticsField;
receiver = log;
}
} catch (Exception e) {
}
if (diagnosticHandlerField != null)
try {
Object handler = diagnosticHandlerField.get(log);
field = getDeferredField(handler);
receiver = handler;
} catch (Exception e) {
}
if (field == null || receiver == null)
return;
try {
ListBuffer<?> deferredDiagnostics = (ListBuffer<?>) field.get(receiver);
ListBuffer<Object> newDeferredDiagnostics = new ListBuffer<Object>();
for (Object diag_ : deferredDiagnostics) {
if (!(diag_ instanceof JCDiagnostic)) {
newDeferredDiagnostics.add(diag_);
continue;
}
JCDiagnostic diag = (JCDiagnostic) diag_;
long here = diag.getStartPosition();
if (here >= startPos && here < endPos && diag.getSource() == sourcefile) {
// We eliminate it
} else {
newDeferredDiagnostics.add(diag);
}
}
field.set(receiver, newDeferredDiagnostics);
} catch (Exception e) {
// We do not expect failure here; if failure does occur, the best course of action is to silently continue; the result will be that the error output of
// javac will contain rather a lot of messages, but this is a lot better than just crashing during compilation!
}
}
use of com.sun.tools.javac.util.JCDiagnostic in project ceylon-compiler by ceylon.
the class Attr method checkAutoCloseable.
void checkAutoCloseable(DiagnosticPosition pos, Env<AttrContext> env, Type resource) {
if (!resource.isErroneous() && types.asSuper(resource, syms.autoCloseableType.tsym) != null) {
Symbol close = syms.noSymbol;
boolean prevDeferDiags = log.deferDiagnostics;
Queue<JCDiagnostic> prevDeferredDiags = log.deferredDiagnostics;
try {
log.deferDiagnostics = true;
log.deferredDiagnostics = ListBuffer.lb();
close = rs.resolveQualifiedMethod(pos, env, resource, names.close, List.<Type>nil(), List.<Type>nil());
} finally {
log.deferDiagnostics = prevDeferDiags;
log.deferredDiagnostics = prevDeferredDiags;
}
if (close.kind == MTH && close.overrides(syms.autoCloseableClose, resource.tsym, types, true) && chk.isHandled(syms.interruptedExceptionType, types.memberType(resource, close).getThrownTypes()) && env.info.lint.isEnabled(LintCategory.TRY)) {
log.warning(LintCategory.TRY, pos, "try.resource.throws.interrupted.exc", resource);
}
}
}
use of com.sun.tools.javac.util.JCDiagnostic in project ceylon-compiler by ceylon.
the class JavacProcessingEnvironment method close.
/**
* Free resources related to annotation processing.
*/
public void close() {
filer.close();
if (// Make calling close idempotent
discoveredProcs != null)
discoveredProcs.close();
discoveredProcs = null;
if (processorClassLoader != null && processorClassLoader instanceof Closeable) {
try {
((Closeable) processorClassLoader).close();
} catch (IOException e) {
JCDiagnostic msg = diags.fragment("fatal.err.cant.close.loader");
throw new FatalError(msg, e);
}
}
}
Aggregations