|
Java example source code file (Messages.java)
The Messages.java Java example source code/* * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.tools.doclint; import java.io.PrintWriter; import java.text.MessageFormat; import java.util.Comparator; import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.MissingResourceException; import java.util.ResourceBundle; import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; import javax.tools.Diagnostic; import com.sun.source.doctree.DocTree; import com.sun.source.tree.Tree; import com.sun.tools.doclint.Env.AccessKind; /** * Message reporting for DocLint. * * Options are used to filter out messages based on group and access level. * Support can be enabled for accumulating statistics of different kinds of * messages. * * <p>This is NOT part of any supported API. * If you write code that depends on this, you do so at your own * risk. This code and its internal interfaces are subject to change * or deletion without notice.</b> */ public class Messages { /** * Groups used to categorize messages, so that messages in each group * can be enabled or disabled via options. */ public enum Group { ACCESSIBILITY, HTML, MISSING, SYNTAX, REFERENCE; String optName() { return name().toLowerCase(); } String notOptName() { return "-" + optName(); } static boolean accepts(String opt) { for (Group g: values()) if (opt.equals(g.optName())) return true; return false; } }; private final Options options; private final Stats stats; ResourceBundle bundle; Env env; Messages(Env env) { this.env = env; String name = getClass().getPackage().getName() + ".resources.doclint"; bundle = ResourceBundle.getBundle(name, Locale.ENGLISH); stats = new Stats(bundle); options = new Options(stats); } void error(Group group, DocTree tree, String code, Object... args) { report(group, Diagnostic.Kind.ERROR, tree, code, args); } void warning(Group group, DocTree tree, String code, Object... args) { report(group, Diagnostic.Kind.WARNING, tree, code, args); } void setOptions(String opts) { options.setOptions(opts); } void setStatsEnabled(boolean b) { stats.setEnabled(b); } void reportStats(PrintWriter out) { stats.report(out); } protected void report(Group group, Diagnostic.Kind dkind, DocTree tree, String code, Object... args) { if (options.isEnabled(group, env.currAccess)) { String msg = (code == null) ? (String) args[0] : localize(code, args); env.trees.printMessage(dkind, msg, tree, env.currDocComment, env.currPath.getCompilationUnit()); stats.record(group, dkind, code); } } protected void report(Group group, Diagnostic.Kind dkind, Tree tree, String code, Object... args) { if (options.isEnabled(group, env.currAccess)) { String msg = localize(code, args); env.trees.printMessage(dkind, msg, tree, env.currPath.getCompilationUnit()); stats.record(group, dkind, code); } } String localize(String code, Object... args) { String msg = bundle.getString(code); if (msg == null) { StringBuilder sb = new StringBuilder(); sb.append("message file broken: code=").append(code); if (args.length > 0) { sb.append(" arguments={0}"); for (int i = 1; i < args.length; i++) { sb.append(", {").append(i).append("}"); } } msg = sb.toString(); } return MessageFormat.format(msg, args); } // <editor-fold defaultstate="collapsed" desc="Options"> /** * Handler for (sub)options specific to message handling. */ static class Options { Map<String, Env.AccessKind> map = new HashMap Other Java examples (source code examples)Here is a short list of links related to this Java Messages.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.