Search in sources :

Example 1 with JCDiagnostic

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!
    }
}
Also used : Field(java.lang.reflect.Field) JCDiagnostic(com.sun.tools.javac.util.JCDiagnostic) ListBuffer(com.sun.tools.javac.util.ListBuffer) JavaFileObject(javax.tools.JavaFileObject) IOException(java.io.IOException)

Example 2 with JCDiagnostic

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);
        }
    }
}
Also used : ClassType(com.sun.tools.javac.code.Type.ClassType) MethodType(com.sun.tools.javac.code.Type.MethodType) WildcardType(com.sun.tools.javac.code.Type.WildcardType) Type(com.sun.tools.javac.code.Type) ArrayType(com.sun.tools.javac.code.Type.ArrayType) UnionClassType(com.sun.tools.javac.code.Type.UnionClassType) JCDiagnostic(com.sun.tools.javac.util.JCDiagnostic) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol) Symbol(com.sun.tools.javac.code.Symbol) PackageSymbol(com.sun.tools.javac.code.Symbol.PackageSymbol) VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol) DynamicMethodSymbol(com.sun.tools.javac.code.Symbol.DynamicMethodSymbol) MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) OperatorSymbol(com.sun.tools.javac.code.Symbol.OperatorSymbol)

Example 3 with JCDiagnostic

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);
        }
    }
}
Also used : FatalError(com.sun.tools.javac.util.FatalError) JCDiagnostic(com.sun.tools.javac.util.JCDiagnostic) Closeable(java.io.Closeable) IOException(java.io.IOException)

Aggregations

JCDiagnostic (com.sun.tools.javac.util.JCDiagnostic)3 IOException (java.io.IOException)2 Symbol (com.sun.tools.javac.code.Symbol)1 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)1 DynamicMethodSymbol (com.sun.tools.javac.code.Symbol.DynamicMethodSymbol)1 MethodSymbol (com.sun.tools.javac.code.Symbol.MethodSymbol)1 OperatorSymbol (com.sun.tools.javac.code.Symbol.OperatorSymbol)1 PackageSymbol (com.sun.tools.javac.code.Symbol.PackageSymbol)1 TypeSymbol (com.sun.tools.javac.code.Symbol.TypeSymbol)1 VarSymbol (com.sun.tools.javac.code.Symbol.VarSymbol)1 Type (com.sun.tools.javac.code.Type)1 ArrayType (com.sun.tools.javac.code.Type.ArrayType)1 ClassType (com.sun.tools.javac.code.Type.ClassType)1 MethodType (com.sun.tools.javac.code.Type.MethodType)1 UnionClassType (com.sun.tools.javac.code.Type.UnionClassType)1 WildcardType (com.sun.tools.javac.code.Type.WildcardType)1 FatalError (com.sun.tools.javac.util.FatalError)1 ListBuffer (com.sun.tools.javac.util.ListBuffer)1 Closeable (java.io.Closeable)1 Field (java.lang.reflect.Field)1