1 /* 2 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.tools.javac.util; 27 28 import java.util.Set; 29 import java.util.Locale; 30 import javax.tools.Diagnostic; 31 32 import com.sun.tools.javac.api.DiagnosticFormatter; 33 import com.sun.tools.javac.api.DiagnosticFormatter.Configuration; 34 import com.sun.tools.javac.api.DiagnosticFormatter.Configuration.DiagnosticPart; 35 import com.sun.tools.javac.api.DiagnosticFormatter.Configuration.MultilineLimit; 36 import com.sun.tools.javac.api.DiagnosticFormatter.PositionKind; 37 38 /** 39 * A delegated diagnostic formatter delegates all formatting 40 * actions to an underlying formatter (aka the delegated formatter). 41 * 42 * <p><b>This is NOT part of any supported API. 43 * If you write code that depends on this, you do so at your own risk. 44 * This code and its internal interfaces are subject to change or 45 * deletion without notice.</b> 46 */ 47 public class ForwardingDiagnosticFormatter<D extends Diagnostic<?>, F extends DiagnosticFormatter<D>> 48 implements DiagnosticFormatter<D> { 49 50 /** 51 * The delegated formatter 52 */ 53 protected F formatter; 54 55 /* 56 * configuration object used by this formatter 57 */ 58 protected ForwardingConfiguration configuration; 59 60 public ForwardingDiagnosticFormatter(F formatter) { 61 this.formatter = formatter; 62 this.configuration = new ForwardingConfiguration(formatter.getConfiguration()); 63 } 64 65 /** 66 * Returns the underlying delegated formatter 67 * @return delegate formatter 68 */ 69 public F getDelegatedFormatter() { 70 return formatter; 71 } 72 73 public Configuration getConfiguration() { 74 return configuration; 75 } 76 77 public boolean displaySource(D diag) { 78 return formatter.displaySource(diag); 79 } 80 81 public String format(D diag, Locale l) { 82 return formatter.format(diag, l); 83 } 84 85 public String formatKind(D diag, Locale l) { 86 return formatter.formatKind(diag, l); 87 } 88 89 public String formatMessage(D diag, Locale l) { 90 return formatter.formatMessage(diag, l); 91 } 92 93 public String formatPosition(D diag, PositionKind pk, Locale l) { 94 return formatter.formatPosition(diag, pk, l); 95 } 96 97 public String formatSource(D diag, boolean fullname, Locale l) { 98 return formatter.formatSource(diag, fullname, l); 99 } 100 101 /** 102 * A delegated formatter configuration delegates all configurations settings 103 * to an underlying configuration object (aka the delegated configuration). 104 */ 105 public static class ForwardingConfiguration implements DiagnosticFormatter.Configuration { 106 107 /** The configurationr object to which the forwarding configuration delegates some settings */ 108 protected Configuration configuration; 109 110 public ForwardingConfiguration(Configuration configuration) { 111 this.configuration = configuration; 112 } 113 114 /** 115 * Returns the underlying delegated configuration. 116 * @return delegated configuration 117 */ 118 public Configuration getDelegatedConfiguration() { 119 return configuration; 120 } 121 122 public int getMultilineLimit(MultilineLimit limit) { 123 return configuration.getMultilineLimit(limit); 124 } 125 126 public Set<DiagnosticPart> getVisible() { 127 return configuration.getVisible(); 128 } 129 130 public void setMultilineLimit(MultilineLimit limit, int value) { 131 configuration.setMultilineLimit(limit, value); 132 } 133 134 public void setVisible(Set<DiagnosticPart> diagParts) { 135 configuration.setVisible(diagParts); 136 } 137 } 138 }