com.sun.tools.javac.util.JCDiagnostic Java Examples

The following examples show how to use com.sun.tools.javac.util.JCDiagnostic. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: TencentKona-8   Author: Tencent   File: JavacProcessingEnvironment.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** Return whether or not an unrecoverable error has occurred. */
boolean unrecoverableError() {
    if (messager.errorRaised())
        return true;

    for (JCDiagnostic d: deferredDiagnosticHandler.getDiagnostics()) {
        switch (d.getKind()) {
            case WARNING:
                if (werror)
                    return true;
                break;

            case ERROR:
                if (fatalErrors || !d.isFlagSet(RECOVERABLE))
                    return true;
                break;
        }
    }

    return false;
}
 
Example #2
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: BadClassfile.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static void test(String classname, String expected) throws Exception {
    File classfile = new File(System.getProperty("test.classes", "."), classname + ".class");
    ClassFile cf = ClassFile.read(classfile);

    cf = new ClassFile(cf.magic, Target.JDK1_7.minorVersion,
             Target.JDK1_7.majorVersion, cf.constant_pool, cf.access_flags,
            cf.this_class, cf.super_class, cf.interfaces, cf.fields,
            cf.methods, cf.attributes);

    new ClassWriter().write(cf, classfile);

    JavaCompiler c = ToolProvider.getSystemJavaCompiler();
    JavacTaskImpl task = (JavacTaskImpl) c.getTask(null, null, null, Arrays.asList("-classpath", System.getProperty("test.classes", ".")), null, null);

    try {
        Symbol clazz = com.sun.tools.javac.main.JavaCompiler.instance(task.getContext()).resolveIdent(classname);

        clazz.complete();
    } catch (BadClassFile f) {
        JCDiagnostic embeddedDiag = (JCDiagnostic) f.diag.getArgs()[1];
        assertEquals(expected, embeddedDiag.getCode());
        assertEquals(Integer.toString(Target.JDK1_7.majorVersion), embeddedDiag.getArgs()[0]);
        assertEquals(Integer.toString(Target.JDK1_7.minorVersion), embeddedDiag.getArgs()[1]);
    }
}
 
Example #3
Source Project: TencentKona-8   Author: Tencent   File: ResolveHarness.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
void process(Diagnostic<? extends JavaFileObject> diagnostic) {
    Element siteSym = getSiteSym(diagnostic);
    if (siteSym.getSimpleName().length() != 0 &&
            ((Symbol)siteSym).outermostClass().getAnnotation(TraceResolve.class) == null) {
        return;
    }
    int candidateIdx = 0;
    for (JCDiagnostic d : subDiagnostics(diagnostic)) {
        boolean isMostSpecific = candidateIdx++ == mostSpecific(diagnostic);
        VerboseCandidateSubdiagProcessor subProc =
                new VerboseCandidateSubdiagProcessor(isMostSpecific, phase(diagnostic), success(diagnostic));
        if (subProc.matches(d)) {
            subProc.process(d);
        } else {
            throw new AssertionError("Bad subdiagnostic: " + d.getCode());
        }
    }
}
 
Example #4
Source Project: lua-for-android   Author: qtiuto   File: StringConcat.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Item makeConcat(JCTree.JCBinary tree) {
    JCDiagnostic.DiagnosticPosition pos = tree.pos();

    // Create a string builder.
    newStringBuilder(tree);

    // Append all strings to builder.
    List<JCTree> args = collectAll(tree);
    for (JCTree t : args) {
        gen.genExpr(t, t.type).load();
        appendString(t);
    }

    // Convert builder to string.
    builderToString(pos);

    return gen.getItems().makeStackItem(syms.stringType);
}
 
Example #5
Source Project: manifold   Author: manifold-systems   File: StringLiteralTemplateProcessor.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #6
Source Project: openjdk-8-source   Author: keerath   File: JavacProcessingEnvironment.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** Return whether or not an unrecoverable error has occurred. */
boolean unrecoverableError() {
    if (messager.errorRaised())
        return true;

    for (JCDiagnostic d: deferredDiagnosticHandler.getDiagnostics()) {
        switch (d.getKind()) {
            case WARNING:
                if (werror)
                    return true;
                break;

            case ERROR:
                if (fatalErrors || !d.isFlagSet(RECOVERABLE))
                    return true;
                break;
        }
    }

    return false;
}
 
Example #7
Source Project: jdk8u60   Author: chenghanpeng   File: StructuralMostSpecificTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
    try {
        if (diagnostic.getKind() == Diagnostic.Kind.ERROR &&
                diagnostic.getCode().equals("compiler.err.ref.ambiguous")) {
            ambiguityFound = true;
        } else if (diagnostic.getKind() == Diagnostic.Kind.NOTE &&
                diagnostic.getCode()
                .equals("compiler.note.verbose.resolve.multi")) {
            ClientCodeWrapper.DiagnosticSourceUnwrapper dsu =
                (ClientCodeWrapper.DiagnosticSourceUnwrapper)diagnostic;
            JCDiagnostic.MultilineDiagnostic mdiag =
                (JCDiagnostic.MultilineDiagnostic)dsu.d;
            int mostSpecificIndex = (Integer)mdiag.getArgs()[2];
            mostSpecificSig =
                ((JCDiagnostic)mdiag.getSubdiagnostics()
                    .get(mostSpecificIndex)).getArgs()[1].toString();
        }
    } catch (RuntimeException t) {
        t.printStackTrace();
        throw t;
    }
}
 
Example #8
Source Project: jdk8u60   Author: chenghanpeng   File: ResolveHarness.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
void process(Diagnostic<? extends JavaFileObject> diagnostic) {
    Element siteSym = getSiteSym(diagnostic);
    if (siteSym.getSimpleName().length() != 0 &&
            ((Symbol)siteSym).outermostClass().getAnnotation(TraceResolve.class) == null) {
        return;
    }
    int candidateIdx = 0;
    for (JCDiagnostic d : subDiagnostics(diagnostic)) {
        boolean isMostSpecific = candidateIdx++ == mostSpecific(diagnostic);
        VerboseCandidateSubdiagProcessor subProc =
                new VerboseCandidateSubdiagProcessor(isMostSpecific, phase(diagnostic), success(diagnostic));
        if (subProc.matches(d)) {
            subProc.process(d);
        } else {
            throw new AssertionError("Bad subdiagnostic: " + d.getCode());
        }
    }
}
 
Example #9
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: JavacProcessingEnvironment.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** Return whether or not an unrecoverable error has occurred. */
boolean unrecoverableError() {
    if (messager.errorRaised())
        return true;

    for (JCDiagnostic d: deferredDiagnosticHandler.getDiagnostics()) {
        switch (d.getKind()) {
            case WARNING:
                if (werror)
                    return true;
                break;

            case ERROR:
                if (fatalErrors || !d.isFlagSet(RECOVERABLE))
                    return true;
                break;
        }
    }

    return false;
}
 
Example #10
Source Project: openjdk-8   Author: bpupadhyaya   File: StructuralMostSpecificTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
    try {
        if (diagnostic.getKind() == Diagnostic.Kind.ERROR &&
                diagnostic.getCode().equals("compiler.err.ref.ambiguous")) {
            ambiguityFound = true;
        } else if (diagnostic.getKind() == Diagnostic.Kind.NOTE &&
                diagnostic.getCode()
                .equals("compiler.note.verbose.resolve.multi")) {
            ClientCodeWrapper.DiagnosticSourceUnwrapper dsu =
                (ClientCodeWrapper.DiagnosticSourceUnwrapper)diagnostic;
            JCDiagnostic.MultilineDiagnostic mdiag =
                (JCDiagnostic.MultilineDiagnostic)dsu.d;
            int mostSpecificIndex = (Integer)mdiag.getArgs()[2];
            mostSpecificSig =
                ((JCDiagnostic)mdiag.getSubdiagnostics()
                    .get(mostSpecificIndex)).getArgs()[1].toString();
        }
    } catch (RuntimeException t) {
        t.printStackTrace();
        throw t;
    }
}
 
Example #11
Source Project: lua-for-android   Author: qtiuto   File: LambdaToMethod.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private LambdaToMethod(Context context) {
    context.put(unlambdaKey, this);
    diags = JCDiagnostic.Factory.instance(context);
    log = Log.instance(context);
    lower = Lower.instance(context);
    names = Names.instance(context);
    syms = Symtab.instance(context);
    rs = Resolve.instance(context);
    operators = Operators.instance(context);
    make = TreeMaker.instance(context);
    types = Types.instance(context);
    transTypes = TransTypes.instance(context);
    analyzer = new LambdaAnalyzerPreprocessor();
    Options options = Options.instance(context);
    dumpLambdaToMethodStats = options.isSet("debug.dumpLambdaToMethodStats");
    attr = Attr.instance(context);
    forceSerializable = options.isSet("forceSerializable");
}
 
Example #12
Source Project: javaide   Author: tranleduy2000   File: JavacProcessingEnvironment.java    License: GNU General Public License v3.0 6 votes vote down vote up
/** Return whether or not an unrecoverable error has occurred. */
boolean unrecoverableError() {
    if (messager.errorRaised())
        return true;

    for (JCDiagnostic d: log.deferredDiagnostics) {
        switch (d.getKind()) {
            case WARNING:
                if (werror)
                    return true;
                break;

            case ERROR:
                if (fatalErrors || !d.isFlagSet(RECOVERABLE))
                    return true;
                break;
        }
    }

    return false;
}
 
Example #13
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: ResolveHarness.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
void process(Diagnostic<? extends JavaFileObject> diagnostic) {
    Element siteSym = getSiteSym(diagnostic);
    if (siteSym.getSimpleName().length() != 0 &&
            ((Symbol)siteSym).outermostClass().getAnnotation(TraceResolve.class) == null) {
        return;
    }
    int candidateIdx = 0;
    for (JCDiagnostic d : subDiagnostics(diagnostic)) {
        boolean isMostSpecific = candidateIdx++ == mostSpecific(diagnostic);
        VerboseCandidateSubdiagProcessor subProc =
                new VerboseCandidateSubdiagProcessor(isMostSpecific, phase(diagnostic), success(diagnostic));
        if (subProc.matches(d)) {
            subProc.process(d);
        } else {
            throw new AssertionError("Bad subdiagnostic: " + d.getCode());
        }
    }
}
 
Example #14
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: ResolveHarness.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
void process(Diagnostic<? extends JavaFileObject> diagnostic) {
    Element siteSym = getSiteSym(diagnostic);
    if (siteSym.getSimpleName().length() != 0 &&
            ((Symbol)siteSym).outermostClass().getAnnotation(TraceResolve.class) == null) {
        return;
    }
    int candidateIdx = 0;
    for (JCDiagnostic d : subDiagnostics(diagnostic)) {
        boolean isMostSpecific = candidateIdx++ == mostSpecific(diagnostic);
        VerboseCandidateSubdiagProcessor subProc =
                new VerboseCandidateSubdiagProcessor(isMostSpecific, phase(diagnostic), success(diagnostic));
        if (subProc.matches(d)) {
            subProc.process(d);
        } else {
            throw new AssertionError("Bad subdiagnostic: " + d.getCode());
        }
    }
}
 
Example #15
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: T7086261.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void report(Diagnostic message) {
    if (!(message instanceof DiagnosticSourceUnwrapper)) {
        throw new AssertionError("Wrapped diagnostic expected!");
    }
    String actual = message.toString();
    JCDiagnostic jd = (JCDiagnostic)((DiagnosticSourceUnwrapper)message).d;
    String expected = jd.toString();
    if (!actual.equals(expected)) {
        throw new AssertionError("expected = " + expected + "\nfound = " + actual);
    }
}
 
Example #16
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: Example.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Scan a diagnostic for resource keys.  This will not detect additional
 * sub diagnostics that might be generated by a rich diagnostic formatter.
 */
private static void scanForKeys(JCDiagnostic d, Set<String> keys) {
    keys.add(d.getCode());
    for (Object o: d.getArgs()) {
        if (o instanceof JCDiagnostic) {
            scanForKeys((JCDiagnostic) o, keys);
        }
    }
    for (JCDiagnostic sd: d.getSubdiagnostics())
        scanForKeys(sd, keys);
}
 
Example #17
Source Project: lua-for-android   Author: qtiuto   File: ClassFinder.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Static factory for CompletionFailure objects.
 *  In practice, only one can be used at a time, so we share one
 *  to reduce the expense of allocating new exception objects.
 */
private CompletionFailure newCompletionFailure(TypeSymbol c,
                                               JCDiagnostic diag) {
    if (!cacheCompletionFailure) {
        // log.warning("proc.messager",
        //             Log.getLocalizedString("class.file.not.found", c.flatname));
        // c.debug.printStackTrace();
        return new CompletionFailure(c, diag);
    } else {
        CompletionFailure result = cachedCompletionFailure;
        result.sym = c;
        result.diag = diag;
        return result;
    }
}
 
Example #18
Source Project: openjdk-8-source   Author: keerath   File: TestMetafactoryBridges.java    License: GNU General Public License v2.0 5 votes vote down vote up
JCDiagnostic asJCDiagnostic(Diagnostic<? extends JavaFileObject> diagnostic) {
    if (diagnostic instanceof JCDiagnostic) {
        return (JCDiagnostic)diagnostic;
    } else if (diagnostic instanceof DiagnosticSourceUnwrapper) {
        return ((DiagnosticSourceUnwrapper)diagnostic).d;
    } else {
        throw new AssertionError("Cannot convert diagnostic to JCDiagnostic: " + diagnostic.getClass().getName());
    }
}
 
Example #19
Source Project: TencentKona-8   Author: Tencent   File: JavacTrees.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void printMessage(Diagnostic.Kind kind, CharSequence msg,
        JCDiagnostic.DiagnosticPosition pos,
        com.sun.source.tree.CompilationUnitTree root) {
    JavaFileObject oldSource = null;
    JavaFileObject newSource = null;

    newSource = root.getSourceFile();
    if (newSource == null) {
        pos = null;
    } else {
        oldSource = log.useSource(newSource);
    }

    try {
        switch (kind) {
        case ERROR:
            boolean prev = log.multipleErrors;
            try {
                log.error(pos, "proc.messager", msg.toString());
            } finally {
                log.multipleErrors = prev;
            }
            break;

        case WARNING:
            log.warning(pos, "proc.messager", msg.toString());
            break;

        case MANDATORY_WARNING:
            log.mandatoryWarning(pos, "proc.messager", msg.toString());
            break;

        default:
            log.note(pos, "proc.messager", msg.toString());
        }
    } finally {
        if (oldSource != null)
            log.useSource(oldSource);
    }
}
 
Example #20
Source Project: netbeans   Author: apache   File: Utilities.java    License: Apache License 2.0 5 votes vote down vote up
private static TypeMirror attributeTree(JavacTaskImpl jti, Tree tree, Scope scope, 
            final List<Diagnostic<? extends JavaFileObject>> errors, @NullAllowed final Diagnostic.Kind filter) {
        Log log = Log.instance(jti.getContext());
        JavaFileObject prev = log.useSource(new DummyJFO());
        Enter enter = Enter.instance(jti.getContext());
        
        Log.DiagnosticHandler discardHandler = new Log.DiscardDiagnosticHandler(log) {
            private Diagnostic.Kind f = filter == null ? Diagnostic.Kind.ERROR : filter;
            @Override
            public void report(JCDiagnostic diag) {
                if (diag.getKind().compareTo(f) >= 0) {
                    errors.add(diag);
                }
            }            
        };
//        ArgumentAttr argumentAttr = ArgumentAttr.instance(jti.getContext());
//        ArgumentAttr.LocalCacheContext cacheContext = argumentAttr.withLocalCacheContext();
        try {
//            enter.shadowTypeEnvs(true);
            Attr attr = Attr.instance(jti.getContext());
            Env<AttrContext> env = ((JavacScope) scope).getEnv();
            if (tree instanceof JCTree.JCExpression) {
                return attr.attribExpr((JCTree) tree,env, Type.noType);
            }
            return attr.attribStat((JCTree) tree,env);
        } finally {
//            cacheContext.leave();
            log.useSource(prev);
            log.popDiagnosticHandler(discardHandler);
//            enter.shadowTypeEnvs(false);
        }
    }
 
Example #21
Source Project: openjdk-8   Author: bpupadhyaya   File: T7116676.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void testThroughFormatterFormat() throws IOException {
    final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    DiagnosticChecker dc = new DiagnosticChecker("compiler.err.prob.found.req");
    JavacTask ct = (JavacTask)tool.getTask(null, null, dc, null, null, Arrays.asList(new JavaSource()));
    ct.analyze();
    DiagnosticFormatter<JCDiagnostic> formatter =
            Log.instance(((JavacTaskImpl) ct).getContext()).getDiagnosticFormatter();
    String msg = formatter.formatMessage(dc.diag, Locale.getDefault());
    //no redundant package qualifiers
    Assert.check(msg.indexOf("java.") == -1, msg);
}
 
Example #22
Source Project: TencentKona-8   Author: Tencent   File: TestMetafactoryBridges.java    License: GNU General Public License v2.0 5 votes vote down vote up
JCDiagnostic asJCDiagnostic(Diagnostic<? extends JavaFileObject> diagnostic) {
    if (diagnostic instanceof JCDiagnostic) {
        return (JCDiagnostic)diagnostic;
    } else if (diagnostic instanceof DiagnosticSourceUnwrapper) {
        return ((DiagnosticSourceUnwrapper)diagnostic).d;
    } else {
        throw new AssertionError("Cannot convert diagnostic to JCDiagnostic: " + diagnostic.getClass().getName());
    }
}
 
Example #23
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: T7116676.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
    JCDiagnostic diag = (JCDiagnostic)diagnostic;
    if (diagnostic.getCode().equals(expectedKey)) {
        this.diag = diag;
    }
}
 
Example #24
Source Project: openjdk-8   Author: bpupadhyaya   File: JavacProcessingEnvironment.java    License: GNU General Public License v2.0 5 votes vote down vote up
void showDiagnostics(boolean showAll) {
    Set<JCDiagnostic.Kind> kinds = EnumSet.allOf(JCDiagnostic.Kind.class);
    if (!showAll) {
        // suppress errors, which are all presumed to be transient resolve errors
        kinds.remove(JCDiagnostic.Kind.ERROR);
    }
    deferredDiagnosticHandler.reportDeferredDiagnostics(kinds);
    log.popDiagnosticHandler(deferredDiagnosticHandler);
}
 
Example #25
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: Modules.java    License: GNU General Public License v2.0 5 votes vote down vote up
private boolean enter(List<JCCompilationUnit> trees, Consumer<Set<ModuleSymbol>> init, ClassSymbol c) {
    if (!allowModules) {
        for (JCCompilationUnit tree: trees) {
            tree.modle = syms.noModule;
        }
        defaultModule = syms.noModule;
        return true;
    }

    int startErrors = log.nerrors;

    depth++;
    try {
        // scan trees for module defs
        Set<ModuleSymbol> roots = enterModules(trees, c);

        setCompilationUnitModules(trees, roots, c);

        init.accept(roots);

        for (ModuleSymbol msym: roots) {
            msym.complete();
        }
    } catch (CompletionFailure ex) {
        log.error(JCDiagnostic.DiagnosticFlag.NON_DEFERRABLE, Position.NOPOS, "cant.access", ex.sym, ex.getDetailValue());
        if (ex instanceof ClassFinder.BadClassFile) throw new Abort();
    } finally {
        depth--;
    }

    return (log.nerrors == startErrors);
}
 
Example #26
Source Project: lua-for-android   Author: qtiuto   File: Check.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** 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, JCDiagnostic required, Object found) {
    // this error used to be raised by the parser,
    // but has been delayed to this point:
    if (found instanceof Type && ((Type)found).hasTag(VOID)) {
        log.error(pos, Errors.IllegalStartOfType);
        return syms.errType;
    }
    log.error(pos, Errors.TypeFoundReq(found, required));
    return types.createErrorType(found instanceof Type ? (Type)found : syms.errType);
}
 
Example #27
Source Project: TencentKona-8   Author: Tencent   File: T7116676.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void testThroughFormatterFormat() throws IOException {
    final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    DiagnosticChecker dc = new DiagnosticChecker("compiler.err.prob.found.req");
    JavacTask ct = (JavacTask)tool.getTask(null, null, dc, null, null, Arrays.asList(new JavaSource()));
    ct.analyze();
    DiagnosticFormatter<JCDiagnostic> formatter =
            Log.instance(((JavacTaskImpl) ct).getContext()).getDiagnosticFormatter();
    String msg = formatter.formatMessage(dc.diag, Locale.getDefault());
    //no redundant package qualifiers
    Assert.check(msg.indexOf("java.") == -1, msg);
}
 
Example #28
Source Project: openjdk-8   Author: bpupadhyaya   File: JavacTrees.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void printMessage(Diagnostic.Kind kind, CharSequence msg,
        JCDiagnostic.DiagnosticPosition pos,
        com.sun.source.tree.CompilationUnitTree root) {
    JavaFileObject oldSource = null;
    JavaFileObject newSource = null;

    newSource = root.getSourceFile();
    if (newSource == null) {
        pos = null;
    } else {
        oldSource = log.useSource(newSource);
    }

    try {
        switch (kind) {
        case ERROR:
            boolean prev = log.multipleErrors;
            try {
                log.error(pos, "proc.messager", msg.toString());
            } finally {
                log.multipleErrors = prev;
            }
            break;

        case WARNING:
            log.warning(pos, "proc.messager", msg.toString());
            break;

        case MANDATORY_WARNING:
            log.mandatoryWarning(pos, "proc.messager", msg.toString());
            break;

        default:
            log.note(pos, "proc.messager", msg.toString());
        }
    } finally {
        if (oldSource != null)
            log.useSource(oldSource);
    }
}
 
Example #29
Source Project: jdk8u60   Author: chenghanpeng   File: Messager.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor
 * @param programName  Name of the program (for error messages).
 * @param errWriter    Stream for error messages
 * @param warnWriter   Stream for warnings
 * @param noticeWriter Stream for other messages
 */
@SuppressWarnings("deprecation")
protected Messager(Context context,
                   String programName,
                   PrintWriter errWriter,
                   PrintWriter warnWriter,
                   PrintWriter noticeWriter) {
    super(context, errWriter, warnWriter, noticeWriter);
    messages = JavacMessages.instance(context);
    messages.add("com.sun.tools.javadoc.resources.javadoc");
    javadocDiags = new JCDiagnostic.Factory(messages, "javadoc");
    this.programName = programName;
}
 
Example #30
void showDiagnostics(boolean showAll) {
    Set<JCDiagnostic.Kind> kinds = EnumSet.allOf(JCDiagnostic.Kind.class);
    if (!showAll) {
        // suppress errors, which are all presumed to be transient resolve errors
        kinds.remove(JCDiagnostic.Kind.ERROR);
    }
    deferredDiagnosticHandler.reportDeferredDiagnostics(kinds);
    log.popDiagnosticHandler(deferredDiagnosticHandler);
    compiler.setDeferredDiagnosticHandler(null);
}