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

Tue, 09 Oct 2012 19:10:00 -0700

author
jjg
date
Tue, 09 Oct 2012 19:10:00 -0700
changeset 1357
c75be5bc5283
parent 581
f2fdd52e4e87
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8000663: clean up langtools imports
Reviewed-by: darcy

duke@1 1 /*
jjg@1357 2 * Copyright (c) 2006, 2012, Oracle and/or its affiliates. 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
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle 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 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * 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;
jjg@1357 34
jjg@1357 35 import javax.tools.*;
duke@1 36 import javax.tools.JavaFileObject.Kind;
duke@1 37
duke@1 38 /**
duke@1 39 * Wraps all calls to a given file manager. Subclasses of this class
duke@1 40 * might override some of these methods and might also provide
duke@1 41 * additional fields and methods.
duke@1 42 *
duke@1 43 * <p>This class might be moved to {@link javax.tools} in a future
duke@1 44 * release.
duke@1 45 *
jjg@581 46 * <p><b>This is NOT part of any supported API.
duke@1 47 * If you write code that depends on this, you do so at your own
duke@1 48 * risk. This code and its internal interfaces are subject to change
duke@1 49 * or deletion without notice.</b></p>
duke@1 50 *
duke@1 51 * @param <M> the type of file manager wrapped to by this object
duke@1 52 *
duke@1 53 * @author Peter von der Ah&eacute;
duke@1 54 * @since 1.6
duke@1 55 */
duke@1 56 public class WrappingJavaFileManager<M extends JavaFileManager> extends ForwardingJavaFileManager<M> {
duke@1 57
duke@1 58 /**
duke@1 59 * Creates a new instance of WrappingJavaFileManager.
duke@1 60 * @param fileManager file manager to be wrapped
duke@1 61 */
duke@1 62 protected WrappingJavaFileManager(M fileManager) {
duke@1 63 super(fileManager);
duke@1 64 }
duke@1 65
duke@1 66 /**
duke@1 67 * This implementation returns the given file object. Subclasses
duke@1 68 * may override this behavior.
duke@1 69 *
duke@1 70 * @param fileObject a file object
duke@1 71 */
duke@1 72 protected FileObject wrap(FileObject fileObject) {
duke@1 73 return fileObject;
duke@1 74 }
duke@1 75
duke@1 76 /**
duke@1 77 * This implementation forwards to {@link #wrap(FileObject)}.
duke@1 78 * Subclasses may override this behavior.
duke@1 79 *
duke@1 80 * @param fileObject a file object
duke@1 81 * @throws ClassCastException if the file object returned from the
duke@1 82 * forwarded call is not a subtype of {@linkplain JavaFileObject}
duke@1 83 */
duke@1 84 protected JavaFileObject wrap(JavaFileObject fileObject) {
duke@1 85 return (JavaFileObject)wrap((FileObject)fileObject);
duke@1 86 }
duke@1 87
duke@1 88 /**
duke@1 89 * This implementation returns the given file object. Subclasses
duke@1 90 * may override this behavior.
duke@1 91 *
duke@1 92 * @param fileObject a file object
duke@1 93 */
duke@1 94 protected FileObject unwrap(FileObject fileObject) {
duke@1 95 return fileObject;
duke@1 96 }
duke@1 97
duke@1 98 /**
duke@1 99 * This implementation forwards to {@link #unwrap(FileObject)}.
duke@1 100 * Subclasses may override this behavior.
duke@1 101 *
duke@1 102 * @param fileObject a file object
duke@1 103 * @throws ClassCastException if the file object returned from the
duke@1 104 * forwarded call is not a subtype of {@linkplain JavaFileObject}
duke@1 105 */
duke@1 106 protected JavaFileObject unwrap(JavaFileObject fileObject) {
duke@1 107 return (JavaFileObject)unwrap((FileObject)fileObject);
duke@1 108 }
duke@1 109
duke@1 110 /**
duke@1 111 * This implementation maps the given list of file objects by
duke@1 112 * calling wrap on each. Subclasses may override this behavior.
duke@1 113 *
duke@1 114 * @param fileObjects a list of file objects
duke@1 115 * @return the mapping
duke@1 116 */
duke@1 117 protected Iterable<JavaFileObject> wrap(Iterable<JavaFileObject> fileObjects) {
duke@1 118 List<JavaFileObject> mapped = new ArrayList<JavaFileObject>();
duke@1 119 for (JavaFileObject fileObject : fileObjects)
duke@1 120 mapped.add(wrap(fileObject));
duke@1 121 return Collections.unmodifiableList(mapped);
duke@1 122 }
duke@1 123
duke@1 124 /**
duke@1 125 * This implementation returns the given URI. Subclasses may
duke@1 126 * override this behavior.
duke@1 127 *
duke@1 128 * @param uri a URI
duke@1 129 */
duke@1 130 protected URI unwrap(URI uri) {
duke@1 131 return uri;
duke@1 132 }
duke@1 133
duke@1 134 /**
duke@1 135 * @throws IllegalStateException {@inheritDoc}
duke@1 136 */
duke@1 137 public Iterable<JavaFileObject> list(Location location,
duke@1 138 String packageName,
duke@1 139 Set<Kind> kinds,
duke@1 140 boolean recurse)
duke@1 141 throws IOException
duke@1 142 {
duke@1 143 return wrap(super.list(location, packageName, kinds, recurse));
duke@1 144 }
duke@1 145
duke@1 146 /**
duke@1 147 * @throws IllegalStateException {@inheritDoc}
duke@1 148 */
duke@1 149 public String inferBinaryName(Location location, JavaFileObject file) {
duke@1 150 return super.inferBinaryName(location, unwrap(file));
duke@1 151 }
duke@1 152
duke@1 153 /**
duke@1 154 * @throws IllegalArgumentException {@inheritDoc}
duke@1 155 * @throws UnsupportedOperationException {@inheritDoc}
duke@1 156 * @throws IllegalStateException {@inheritDoc}
duke@1 157 */
duke@1 158 public JavaFileObject getJavaFileForInput(Location location,
duke@1 159 String className,
duke@1 160 Kind kind)
duke@1 161 throws IOException
duke@1 162 {
duke@1 163 return wrap(super.getJavaFileForInput(location, className, kind));
duke@1 164 }
duke@1 165
duke@1 166 /**
duke@1 167 * @throws IllegalArgumentException {@inheritDoc}
duke@1 168 * @throws UnsupportedOperationException {@inheritDoc}
duke@1 169 * @throws IllegalStateException {@inheritDoc}
duke@1 170 */
duke@1 171 public JavaFileObject getJavaFileForOutput(Location location,
duke@1 172 String className,
duke@1 173 Kind kind,
duke@1 174 FileObject sibling)
duke@1 175 throws IOException
duke@1 176 {
duke@1 177 return wrap(super.getJavaFileForOutput(location, className, kind, unwrap(sibling)));
duke@1 178 }
duke@1 179
duke@1 180 /**
duke@1 181 * @throws IllegalArgumentException {@inheritDoc}
duke@1 182 * @throws IllegalStateException {@inheritDoc}
duke@1 183 */
duke@1 184 public FileObject getFileForInput(Location location,
duke@1 185 String packageName,
duke@1 186 String relativeName)
duke@1 187 throws IOException
duke@1 188 {
duke@1 189 return wrap(super.getFileForInput(location, packageName, relativeName));
duke@1 190 }
duke@1 191
duke@1 192 /**
duke@1 193 * @throws IllegalArgumentException {@inheritDoc}
duke@1 194 * @throws IllegalStateException {@inheritDoc}
duke@1 195 */
duke@1 196 public FileObject getFileForOutput(Location location,
duke@1 197 String packageName,
duke@1 198 String relativeName,
duke@1 199 FileObject sibling)
duke@1 200 throws IOException
duke@1 201 {
duke@1 202 return wrap(super.getFileForOutput(location,
duke@1 203 packageName,
duke@1 204 relativeName,
duke@1 205 unwrap(sibling)));
duke@1 206 }
duke@1 207
duke@1 208 }

mercurial