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

Sat, 07 Nov 2020 10:30:02 +0800

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 3938
93012e2a5d1d
parent 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset eb6ee6a5f2fe

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

mercurial