ForwardingJavaFileManager.java revision 3770:d813bfb238a9
1/*
2 * Copyright (c) 2005, 2016, 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
26package javax.tools;
27
28import java.io.IOException;
29import java.util.Iterator;
30import java.util.Objects;
31import java.util.ServiceLoader;
32import java.util.Set;
33import javax.tools.JavaFileObject.Kind;
34
35/**
36 * Forwards calls to a given file manager.  Subclasses of this class
37 * might override some of these methods and might also provide
38 * additional fields and methods.
39 *
40 * @param <M> the kind of file manager forwarded to by this object
41 * @author Peter von der Ah&eacute;
42 * @since 1.6
43 */
44public class ForwardingJavaFileManager<M extends JavaFileManager> implements JavaFileManager {
45
46    /**
47     * The file manager which all methods are delegated to.
48     */
49    protected final M fileManager;
50
51    /**
52     * Creates a new instance of ForwardingJavaFileManager.
53     * @param fileManager delegate to this file manager
54     */
55    protected ForwardingJavaFileManager(M fileManager) {
56        this.fileManager = Objects.requireNonNull(fileManager);
57    }
58
59    /**
60     * @throws SecurityException {@inheritDoc}
61     * @throws IllegalStateException {@inheritDoc}
62     */
63    public ClassLoader getClassLoader(Location location) {
64        return fileManager.getClassLoader(location);
65    }
66
67    /**
68     * @throws IOException {@inheritDoc}
69     * @throws IllegalStateException {@inheritDoc}
70     */
71    public Iterable<JavaFileObject> list(Location location,
72                                         String packageName,
73                                         Set<Kind> kinds,
74                                         boolean recurse)
75        throws IOException
76    {
77        return fileManager.list(location, packageName, kinds, recurse);
78    }
79
80    /**
81     * @throws IllegalStateException {@inheritDoc}
82     */
83    public String inferBinaryName(Location location, JavaFileObject file) {
84        return fileManager.inferBinaryName(location, file);
85    }
86
87    /**
88     * @throws IllegalArgumentException {@inheritDoc}
89     */
90    public boolean isSameFile(FileObject a, FileObject b) {
91        return fileManager.isSameFile(a, b);
92    }
93
94    /**
95     * @throws IllegalArgumentException {@inheritDoc}
96     * @throws IllegalStateException {@inheritDoc}
97     */
98    public boolean handleOption(String current, Iterator<String> remaining) {
99        return fileManager.handleOption(current, remaining);
100    }
101
102    public boolean hasLocation(Location location) {
103        return fileManager.hasLocation(location);
104    }
105
106    public int isSupportedOption(String option) {
107        return fileManager.isSupportedOption(option);
108    }
109
110    /**
111     * @throws IllegalArgumentException {@inheritDoc}
112     * @throws IllegalStateException {@inheritDoc}
113     */
114    public JavaFileObject getJavaFileForInput(Location location,
115                                              String className,
116                                              Kind kind)
117        throws IOException
118    {
119        return fileManager.getJavaFileForInput(location, className, kind);
120    }
121
122    /**
123     * @throws IllegalArgumentException {@inheritDoc}
124     * @throws IllegalStateException {@inheritDoc}
125     */
126    public JavaFileObject getJavaFileForOutput(Location location,
127                                               String className,
128                                               Kind kind,
129                                               FileObject sibling)
130        throws IOException
131    {
132        return fileManager.getJavaFileForOutput(location, className, kind, sibling);
133    }
134
135    /**
136     * @throws IllegalArgumentException {@inheritDoc}
137     * @throws IllegalStateException {@inheritDoc}
138     */
139    public FileObject getFileForInput(Location location,
140                                      String packageName,
141                                      String relativeName)
142        throws IOException
143    {
144        return fileManager.getFileForInput(location, packageName, relativeName);
145    }
146
147    /**
148     * @throws IllegalArgumentException {@inheritDoc}
149     * @throws IllegalStateException {@inheritDoc}
150     */
151    public FileObject getFileForOutput(Location location,
152                                       String packageName,
153                                       String relativeName,
154                                       FileObject sibling)
155        throws IOException
156    {
157        return fileManager.getFileForOutput(location, packageName, relativeName, sibling);
158    }
159
160    public void flush() throws IOException {
161        fileManager.flush();
162    }
163
164    public void close() throws IOException {
165        fileManager.close();
166    }
167
168    public Location getLocationForModule(Location location, String moduleName) throws IOException {
169        return fileManager.getLocationForModule(location, moduleName);
170    }
171
172    public Location getLocationForModule(Location location, JavaFileObject fo, String pkgName) throws IOException {
173        return fileManager.getLocationForModule(location, fo, pkgName);
174    }
175
176    public <S> ServiceLoader<S> getServiceLoader(Location location, Class<S> service) throws  IOException {
177        return fileManager.getServiceLoader(location, service);
178    }
179
180    public String inferModuleName(Location location) throws IOException {
181        return fileManager.inferModuleName(location);
182    }
183
184    public Iterable<Set<Location>> listLocationsForModules(Location location) throws IOException {
185        return fileManager.listLocationsForModules(location);
186    }
187}
188