src/share/classes/com/sun/tools/javac/api/WrappingJavaFileManager.java

Thu, 02 Oct 2008 19:58:40 -0700

author
xdono
date
Thu, 02 Oct 2008 19:58:40 -0700
changeset 117
24a47c3062fe
parent 104
5e89c4ca637c
child 554
9d9f26857129
permissions
-rw-r--r--

6754988: Update copyright year
Summary: Update for files that have been modified starting July 2008
Reviewed-by: ohair, tbell

duke@1 1 /*
xdono@117 2 * Copyright 2006-2008 Sun Microsystems, Inc. All Rights Reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation. Sun designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
duke@1 9 * by Sun in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
duke@1 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@1 22 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@1 23 * have any questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.javac.api;
duke@1 27
duke@1 28 import java.io.IOException;
duke@1 29 import java.net.URI;
duke@1 30 import java.util.ArrayList;
duke@1 31 import java.util.Collections;
duke@1 32 import java.util.List;
duke@1 33 import java.util.Set;
duke@1 34 import javax.tools.JavaFileObject.Kind;
duke@1 35 import javax.tools.*;
duke@1 36
duke@1 37 /**
duke@1 38 * Wraps all calls to a given file manager. Subclasses of this class
duke@1 39 * might override some of these methods and might also provide
duke@1 40 * additional fields and methods.
duke@1 41 *
duke@1 42 * <p>This class might be moved to {@link javax.tools} in a future
duke@1 43 * release.
duke@1 44 *
duke@1 45 * <p><b>This is NOT part of any API supported by Sun Microsystems.
duke@1 46 * If you write code that depends on this, you do so at your own
duke@1 47 * risk. This code and its internal interfaces are subject to change
duke@1 48 * or deletion without notice.</b></p>
duke@1 49 *
duke@1 50 * @param <M> the type of file manager wrapped to by this object
duke@1 51 *
duke@1 52 * @author Peter von der Ah&eacute;
duke@1 53 * @since 1.6
duke@1 54 */
duke@1 55 public class WrappingJavaFileManager<M extends JavaFileManager> extends ForwardingJavaFileManager<M> {
duke@1 56
duke@1 57 /**
duke@1 58 * Creates a new instance of WrappingJavaFileManager.
duke@1 59 * @param fileManager file manager to be wrapped
duke@1 60 */
duke@1 61 protected WrappingJavaFileManager(M fileManager) {
duke@1 62 super(fileManager);
duke@1 63 }
duke@1 64
duke@1 65 /**
duke@1 66 * This implementation returns the given file object. Subclasses
duke@1 67 * may override this behavior.
duke@1 68 *
duke@1 69 * @param fileObject a file object
duke@1 70 */
duke@1 71 protected FileObject wrap(FileObject fileObject) {
duke@1 72 return fileObject;
duke@1 73 }
duke@1 74
duke@1 75 /**
duke@1 76 * This implementation forwards to {@link #wrap(FileObject)}.
duke@1 77 * Subclasses may override this behavior.
duke@1 78 *
duke@1 79 * @param fileObject a file object
duke@1 80 * @throws ClassCastException if the file object returned from the
duke@1 81 * forwarded call is not a subtype of {@linkplain JavaFileObject}
duke@1 82 */
duke@1 83 protected JavaFileObject wrap(JavaFileObject fileObject) {
duke@1 84 return (JavaFileObject)wrap((FileObject)fileObject);
duke@1 85 }
duke@1 86
duke@1 87 /**
duke@1 88 * This implementation returns the given file object. Subclasses
duke@1 89 * may override this behavior.
duke@1 90 *
duke@1 91 * @param fileObject a file object
duke@1 92 */
duke@1 93 protected FileObject unwrap(FileObject fileObject) {
duke@1 94 return fileObject;
duke@1 95 }
duke@1 96
duke@1 97 /**
duke@1 98 * This implementation forwards to {@link #unwrap(FileObject)}.
duke@1 99 * Subclasses may override this behavior.
duke@1 100 *
duke@1 101 * @param fileObject a file object
duke@1 102 * @throws ClassCastException if the file object returned from the
duke@1 103 * forwarded call is not a subtype of {@linkplain JavaFileObject}
duke@1 104 */
duke@1 105 protected JavaFileObject unwrap(JavaFileObject fileObject) {
duke@1 106 return (JavaFileObject)unwrap((FileObject)fileObject);
duke@1 107 }
duke@1 108
duke@1 109 /**
duke@1 110 * This implementation maps the given list of file objects by
duke@1 111 * calling wrap on each. Subclasses may override this behavior.
duke@1 112 *
duke@1 113 * @param fileObjects a list of file objects
duke@1 114 * @return the mapping
duke@1 115 */
duke@1 116 protected Iterable<JavaFileObject> wrap(Iterable<JavaFileObject> fileObjects) {
duke@1 117 List<JavaFileObject> mapped = new ArrayList<JavaFileObject>();
duke@1 118 for (JavaFileObject fileObject : fileObjects)
duke@1 119 mapped.add(wrap(fileObject));
duke@1 120 return Collections.unmodifiableList(mapped);
duke@1 121 }
duke@1 122
duke@1 123 /**
duke@1 124 * This implementation returns the given URI. Subclasses may
duke@1 125 * override this behavior.
duke@1 126 *
duke@1 127 * @param uri a URI
duke@1 128 */
duke@1 129 protected URI unwrap(URI uri) {
duke@1 130 return uri;
duke@1 131 }
duke@1 132
duke@1 133 /**
duke@1 134 * @throws IllegalStateException {@inheritDoc}
duke@1 135 */
duke@1 136 public Iterable<JavaFileObject> list(Location location,
duke@1 137 String packageName,
duke@1 138 Set<Kind> kinds,
duke@1 139 boolean recurse)
duke@1 140 throws IOException
duke@1 141 {
duke@1 142 return wrap(super.list(location, packageName, kinds, recurse));
duke@1 143 }
duke@1 144
duke@1 145 /**
duke@1 146 * @throws IllegalStateException {@inheritDoc}
duke@1 147 */
duke@1 148 public String inferBinaryName(Location location, JavaFileObject file) {
duke@1 149 return super.inferBinaryName(location, unwrap(file));
duke@1 150 }
duke@1 151
duke@1 152 /**
duke@1 153 * @throws IllegalArgumentException {@inheritDoc}
duke@1 154 * @throws UnsupportedOperationException {@inheritDoc}
duke@1 155 * @throws IllegalStateException {@inheritDoc}
duke@1 156 */
duke@1 157 public JavaFileObject getJavaFileForInput(Location location,
duke@1 158 String className,
duke@1 159 Kind kind)
duke@1 160 throws IOException
duke@1 161 {
duke@1 162 return wrap(super.getJavaFileForInput(location, className, kind));
duke@1 163 }
duke@1 164
duke@1 165 /**
duke@1 166 * @throws IllegalArgumentException {@inheritDoc}
duke@1 167 * @throws UnsupportedOperationException {@inheritDoc}
duke@1 168 * @throws IllegalStateException {@inheritDoc}
duke@1 169 */
duke@1 170 public JavaFileObject getJavaFileForOutput(Location location,
duke@1 171 String className,
duke@1 172 Kind kind,
duke@1 173 FileObject sibling)
duke@1 174 throws IOException
duke@1 175 {
duke@1 176 return wrap(super.getJavaFileForOutput(location, className, kind, unwrap(sibling)));
duke@1 177 }
duke@1 178
duke@1 179 /**
duke@1 180 * @throws IllegalArgumentException {@inheritDoc}
duke@1 181 * @throws IllegalStateException {@inheritDoc}
duke@1 182 */
duke@1 183 public FileObject getFileForInput(Location location,
duke@1 184 String packageName,
duke@1 185 String relativeName)
duke@1 186 throws IOException
duke@1 187 {
duke@1 188 return wrap(super.getFileForInput(location, packageName, relativeName));
duke@1 189 }
duke@1 190
duke@1 191 /**
duke@1 192 * @throws IllegalArgumentException {@inheritDoc}
duke@1 193 * @throws IllegalStateException {@inheritDoc}
duke@1 194 */
duke@1 195 public FileObject getFileForOutput(Location location,
duke@1 196 String packageName,
duke@1 197 String relativeName,
duke@1 198 FileObject sibling)
duke@1 199 throws IOException
duke@1 200 {
duke@1 201 return wrap(super.getFileForOutput(location,
duke@1 202 packageName,
duke@1 203 relativeName,
duke@1 204 unwrap(sibling)));
duke@1 205 }
duke@1 206
duke@1 207 }

mercurial