mcimadamore@288: /*
ohair@554: * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
mcimadamore@288: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
mcimadamore@288: *
mcimadamore@288: * This code is free software; you can redistribute it and/or modify it
mcimadamore@288: * under the terms of the GNU General Public License version 2 only, as
ohair@554: * published by the Free Software Foundation. Oracle designates this
mcimadamore@288: * particular file as subject to the "Classpath" exception as provided
ohair@554: * by Oracle in the LICENSE file that accompanied this code.
mcimadamore@288: *
mcimadamore@288: * This code is distributed in the hope that it will be useful, but WITHOUT
mcimadamore@288: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
mcimadamore@288: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
mcimadamore@288: * version 2 for more details (a copy is included in the LICENSE file that
mcimadamore@288: * accompanied this code).
mcimadamore@288: *
mcimadamore@288: * You should have received a copy of the GNU General Public License version
mcimadamore@288: * 2 along with this work; if not, write to the Free Software Foundation,
mcimadamore@288: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
mcimadamore@288: *
ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554: * or visit www.oracle.com if you need additional information or have any
ohair@554: * questions.
mcimadamore@288: */
mcimadamore@288: package com.sun.tools.javac.util;
mcimadamore@288:
mcimadamore@288: import java.util.Set;
mcimadamore@288: import java.util.Locale;
mcimadamore@288: import javax.tools.Diagnostic;
mcimadamore@288:
mcimadamore@288: import com.sun.tools.javac.api.DiagnosticFormatter;
mcimadamore@288: import com.sun.tools.javac.api.DiagnosticFormatter.Configuration;
mcimadamore@288: import com.sun.tools.javac.api.DiagnosticFormatter.Configuration.DiagnosticPart;
mcimadamore@288: import com.sun.tools.javac.api.DiagnosticFormatter.Configuration.MultilineLimit;
mcimadamore@288: import com.sun.tools.javac.api.DiagnosticFormatter.PositionKind;
mcimadamore@288:
mcimadamore@288: /**
mcimadamore@288: * A delegated diagnostic formatter delegates all formatting
mcimadamore@288: * actions to an underlying formatter (aka the delegated formatter).
jjg@333: *
jjg@581: *
This is NOT part of any supported API.
jjg@333: * If you write code that depends on this, you do so at your own risk.
jjg@333: * This code and its internal interfaces are subject to change or
jjg@333: * deletion without notice.
mcimadamore@288: */
mcimadamore@288: public class ForwardingDiagnosticFormatter, F extends DiagnosticFormatter>
mcimadamore@288: implements DiagnosticFormatter {
mcimadamore@288:
mcimadamore@288: /**
mcimadamore@288: * The delegated formatter
mcimadamore@288: */
mcimadamore@288: protected F formatter;
mcimadamore@288:
mcimadamore@288: /*
mcimadamore@288: * configuration object used by this formatter
mcimadamore@288: */
mcimadamore@288: protected ForwardingConfiguration configuration;
mcimadamore@288:
mcimadamore@288: public ForwardingDiagnosticFormatter(F formatter) {
mcimadamore@288: this.formatter = formatter;
mcimadamore@288: this.configuration = new ForwardingConfiguration(formatter.getConfiguration());
mcimadamore@288: }
mcimadamore@288:
mcimadamore@288: /**
mcimadamore@288: * Returns the underlying delegated formatter
mcimadamore@288: * @return delegate formatter
mcimadamore@288: */
mcimadamore@288: public F getDelegatedFormatter() {
mcimadamore@288: return formatter;
mcimadamore@288: }
mcimadamore@288:
mcimadamore@288: public Configuration getConfiguration() {
mcimadamore@288: return configuration;
mcimadamore@288: }
mcimadamore@288:
mcimadamore@288: public boolean displaySource(D diag) {
mcimadamore@288: return formatter.displaySource(diag);
mcimadamore@288: }
mcimadamore@288:
mcimadamore@288: public String format(D diag, Locale l) {
mcimadamore@288: return formatter.format(diag, l);
mcimadamore@288: }
mcimadamore@288:
mcimadamore@288: public String formatKind(D diag, Locale l) {
mcimadamore@288: return formatter.formatKind(diag, l);
mcimadamore@288: }
mcimadamore@288:
mcimadamore@288: public String formatMessage(D diag, Locale l) {
mcimadamore@288: return formatter.formatMessage(diag, l);
mcimadamore@288: }
mcimadamore@288:
mcimadamore@288: public String formatPosition(D diag, PositionKind pk, Locale l) {
mcimadamore@288: return formatter.formatPosition(diag, pk, l);
mcimadamore@288: }
mcimadamore@288:
mcimadamore@288: public String formatSource(D diag, boolean fullname, Locale l) {
mcimadamore@288: return formatter.formatSource(diag, fullname, l);
mcimadamore@288: }
mcimadamore@288:
mcimadamore@288: /**
mcimadamore@288: * A delegated formatter configuration delegates all configurations settings
mcimadamore@288: * to an underlying configuration object (aka the delegated configuration).
mcimadamore@288: */
mcimadamore@288: public static class ForwardingConfiguration implements DiagnosticFormatter.Configuration {
mcimadamore@288:
mcimadamore@288: /** The configurationr object to which the forwarding configuration delegates some settings */
mcimadamore@288: protected Configuration configuration;
mcimadamore@288:
mcimadamore@288: public ForwardingConfiguration(Configuration configuration) {
mcimadamore@288: this.configuration = configuration;
mcimadamore@288: }
mcimadamore@288:
mcimadamore@288: /**
mcimadamore@288: * Returns the underlying delegated configuration.
mcimadamore@288: * @return delegated configuration
mcimadamore@288: */
mcimadamore@288: public Configuration getDelegatedConfiguration() {
mcimadamore@288: return configuration;
mcimadamore@288: }
mcimadamore@288:
mcimadamore@288: public int getMultilineLimit(MultilineLimit limit) {
mcimadamore@288: return configuration.getMultilineLimit(limit);
mcimadamore@288: }
mcimadamore@288:
mcimadamore@288: public Set getVisible() {
mcimadamore@288: return configuration.getVisible();
mcimadamore@288: }
mcimadamore@288:
mcimadamore@288: public void setMultilineLimit(MultilineLimit limit, int value) {
mcimadamore@288: configuration.setMultilineLimit(limit, value);
mcimadamore@288: }
mcimadamore@288:
mcimadamore@288: public void setVisible(Set diagParts) {
mcimadamore@288: configuration.setVisible(diagParts);
mcimadamore@288: }
mcimadamore@288: }
mcimadamore@288: }