⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jcdiagnostic.java

📁 是一款用JAVA 编写的编译器 具有很强的编译功能
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            this.pos = pos;        }                public JCTree getTree() {            return null;        }                public int getStartPosition() {            return pos;        }                public int getPreferredPosition() {            return pos;        }                public int getEndPosition(Map<JCTree, Integer> endPosTable) {            return pos;        }                private final int pos;    }    private final Messages messages;    private final DiagnosticType type;    private final DiagnosticSource source;    private final DiagnosticPosition position;    private final int line;    private final int column;    private final String key;    private final Object[] args;    private boolean mandatory;    /**     * Create a diagnostic object.     * @param messages the resource for localized messages     * @param dt the type of diagnostic     * @param name the name of the source file, or null if none.     * @param pos the character offset within the source file, if given.     * @param key a resource key to identify the text of the diagnostic     * @param args arguments to be included in the text of the diagnostic     */    protected JCDiagnostic(Messages messages, 		       DiagnosticType dt, 		       boolean mandatory, 		       DiagnosticSource source, 		       DiagnosticPosition pos, 		       String key, 		       Object ... args) {	if (source == null && pos != null && pos.getPreferredPosition() != Position.NOPOS)	    throw new IllegalArgumentException();	this.messages = messages;	this.type = dt;	this.mandatory = mandatory;	this.source = source;	this.position = pos;	this.key = key;	this.args = args;        int n = (pos == null ? Position.NOPOS : pos.getPreferredPosition());	if (n == Position.NOPOS || source == null)	    line = column = -1;	else {	    line = source.getLineNumber(n);	    column = source.getColumnNumber(n);	}    }    /**     * Get the type of this diagnostic.     * @return the type of this diagnostic     */    public DiagnosticType getType() {	return type;    }    /**     * Check whether or not this diagnostic is required to be shown.     * @return true if this diagnostic is required to be shown.     */    public boolean isMandatory() {	return mandatory;    }    /**     * Get the name of the source file referred to by this diagnostic.     * @return the name of the source referred to with this diagnostic, or null if none     */    public JavaFileObject getSource() {        if (source == null)            return null;        else            return source.getFile();    }    /**     * Get the name of the source file referred to by this diagnostic.     * @return the name of the source referred to with this diagnostic, or null if none     */    public String getSourceName() {	JavaFileObject s = getSource();        return s == null ? null : JavacFileManager.getJavacFileName(s);    }    /**     * Get the source referred to by this diagnostic.     * @return the source referred to with this diagnostic, or null if none     */    public DiagnosticSource getDiagnosticSource() {	return source;    }    protected int getIntStartPosition() {        return (position == null ? Position.NOPOS : position.getStartPosition());    }    protected int getIntPosition() {	return (position == null ? Position.NOPOS : position.getPreferredPosition());    }    protected int getIntEndPosition() {        return (position == null ? Position.NOPOS : position.getEndPosition(source.getEndPosTable()));    }    public long getStartPosition() {        return getIntStartPosition();    }    public long getPosition() {	return getIntPosition();    }    public long getEndPosition() {        return getIntEndPosition();    }    /**     * Get the line number within the source referred to by this diagnostic.     * @return  the line number within the source referred to by this diagnostic     */    public long getLineNumber() {	return line;    }    /**     * Get the column number within the line of source referred to by this diagnostic.     * @return  the column number within the line of source referred to by this diagnostic     */    public long getColumnNumber() {	return column;    }    /**     * Get the arguments to be included in the text of the diagnostic.     * @return  the arguments to be included in the text of the diagnostic     */    public Object[] getArgs() {	return args;    }    /**     * Get the prefix string associated with this type of diagnostic.     * @return the prefix string associated with this type of diagnostic     */    public String getPrefix() {	return getPrefix(type);    }    /**     * Get the prefix string associated with a particular type of diagnostic.     * @return the prefix string associated with a particular type of diagnostic     */    public String getPrefix(DiagnosticType dt) {	switch (dt) {	case FRAGMENT: return "";	case NOTE:     return getLocalizedString("compiler.note.note");	case WARNING:  return getLocalizedString("compiler.warn.warning");	case ERROR:    return getLocalizedString("compiler.err.error");	default:	    throw new AssertionError("Unknown diagnostic type: " + dt);	}    }    /**     * Return the standard presentation of this diagnostic.     */    public String toString() {        if (defaultFormatter == null) {            defaultFormatter =                new DiagnosticFormatter();        }        return defaultFormatter.format(this);    }    private static DiagnosticFormatter defaultFormatter;    private static final String messageBundleName =	"com.sun.tools.javac.resources.compiler";    private String getLocalizedString(String key, Object... args) {	String[] strings = new String[args.length];	for (int i = 0; i < strings.length; i++) {	    Object arg = args[i];	    if (arg == null)		strings[i] = null;	    else if (arg instanceof JCDiagnostic)		strings[i] = ((JCDiagnostic) arg).getMessage(null);	    else		strings[i] = arg.toString();	}	return messages.getLocalizedString(key, (Object[]) strings);    }    // Methods for javax.tools.Diagnostic    public Diagnostic.Kind getKind() {	switch (type) {	case NOTE:            return Diagnostic.Kind.NOTE;	case WARNING:            return mandatory ? Diagnostic.Kind.MANDATORY_WARNING                             : Diagnostic.Kind.WARNING;	case ERROR:            return Diagnostic.Kind.ERROR;	default:            return Diagnostic.Kind.OTHER;	}    }    public String getCode() {	return key;    }    public String getMessage(Locale locale) {        // RFE 6406133: JCDiagnostic.getMessage ignores locale argument        return getLocalizedString(key, args);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -