langtools/src/java.compiler/share/classes/javax/tools/JavaFileManager.java
changeset 36526 3b41f1c69604
parent 25874 83c19f00452c
child 42261 bb52b5514ad5
equal deleted inserted replaced
36525:4caf88912b7f 36526:3b41f1c69604
     1 /*
     1 /*
     2  * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
     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.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    27 
    27 
    28 import java.io.Closeable;
    28 import java.io.Closeable;
    29 import java.io.Flushable;
    29 import java.io.Flushable;
    30 import java.io.IOException;
    30 import java.io.IOException;
    31 import java.util.Iterator;
    31 import java.util.Iterator;
       
    32 import java.util.ServiceLoader;
    32 import java.util.Set;
    33 import java.util.Set;
       
    34 
    33 import static javax.tools.JavaFileObject.Kind;
    35 import static javax.tools.JavaFileObject.Kind;
    34 
    36 
    35 /**
    37 /**
    36  * File manager for tools operating on Java™ programming language
    38  * File manager for tools operating on Java™ programming language
    37  * source and class files.  In this context, <em>file</em> means an
    39  * source and class files.  In this context, <em>file</em> means an
   122          * output.
   124          * output.
   123          *
   125          *
   124          * @return true if this is an output location, false otherwise
   126          * @return true if this is an output location, false otherwise
   125          */
   127          */
   126         boolean isOutputLocation();
   128         boolean isOutputLocation();
       
   129 
       
   130         /**
       
   131          * Indicates if this location is expected to contain modules,
       
   132          * as compared to a location which contains packages and classes.
       
   133          *
       
   134          * @return true if this location is expected to contain modules
       
   135          * @since 9
       
   136          */
       
   137         default boolean isModuleLocation() {
       
   138             return false;
       
   139         }
   127     }
   140     }
   128 
   141 
   129     /**
   142     /**
   130      * Returns a class loader for loading plug-ins from the given
   143      * Returns a class loader for loading plug-ins from the given
   131      * location.  For example, to load annotation processors, a
   144      * location.  For example, to load annotation processors, a
   383      * effect.
   396      * effect.
   384      *
   397      *
   385      * @throws IOException if an I/O error occurred
   398      * @throws IOException if an I/O error occurred
   386      * @see #close
   399      * @see #close
   387      */
   400      */
       
   401     @Override
   388     void flush() throws IOException;
   402     void flush() throws IOException;
   389 
   403 
   390     /**
   404     /**
   391      * Releases any resources opened by this file manager directly or
   405      * Releases any resources opened by this file manager directly or
   392      * indirectly.  This might render this file manager useless and
   406      * indirectly.  This might render this file manager useless and
   396      * already been closed has no effect.
   410      * already been closed has no effect.
   397      *
   411      *
   398      * @throws IOException if an I/O error occurred
   412      * @throws IOException if an I/O error occurred
   399      * @see #flush
   413      * @see #flush
   400      */
   414      */
       
   415     @Override
   401     void close() throws IOException;
   416     void close() throws IOException;
       
   417 
       
   418     /**
       
   419      * Gets a location for a named module within a module-oriented location.
       
   420      *
       
   421      * @param location the module-oriented location
       
   422      * @param moduleName the name of the module to be found
       
   423      * @return the location for the named module
       
   424      *
       
   425      * @throws IOException if an I/O error occurred
       
   426      * @throws UnsupportedOperationException if this operation if not supported by this file manager
       
   427      * @since 9
       
   428      */ // TODO: describe failure modes
       
   429     default Location getModuleLocation(Location location, String moduleName) throws IOException {
       
   430         throw new UnsupportedOperationException();
       
   431     }
       
   432 
       
   433     /**
       
   434      * Gets a location for the module containing a specific file representing a Java
       
   435      * source or class.
       
   436      *
       
   437      * @param location a module-oriented location
       
   438      * @param fo the file
       
   439      * @param pkgName the package name for the class(es) defined in this file
       
   440      * @return the module containing the file
       
   441      *
       
   442      * @throws IOException if an I/O error occurred
       
   443      * @throws UnsupportedOperationException if this operation if not supported by this file manager
       
   444      * @since 9
       
   445      */ // TODO: describe failure modes
       
   446     default Location getModuleLocation(Location location, JavaFileObject fo, String pkgName) throws IOException {
       
   447         throw new UnsupportedOperationException();
       
   448     }
       
   449 
       
   450     /**
       
   451      * Get a service loader for a specific service class from a given location.
       
   452      *
       
   453      * @param location the location
       
   454      * @param service  the {@code Class} object of the service class
       
   455      * @param <S> the service class
       
   456      * @return a service loader for the given service class
       
   457      *
       
   458      * @throws IOException if an I/O error occurred
       
   459      * @throws UnsupportedOperationException if this operation if not supported by this file manager
       
   460      * @since 9
       
   461      */ // TODO: describe failure modes
       
   462     default <S> ServiceLoader<S> getServiceLoader(Location location, Class<S> service) throws  IOException {
       
   463         throw new UnsupportedOperationException();
       
   464     }
       
   465 
       
   466     /**
       
   467      * Infer the name of the module from its location, as returned by
       
   468      * getModuleLocation or listModuleLocations.
       
   469      *
       
   470      * @param location a location representing a module
       
   471      * @return the name of the module
       
   472      *
       
   473      * @throws IOException if an I/O error occurred
       
   474      * @throws UnsupportedOperationException if this operation if not supported by this file manager
       
   475      * @since 9
       
   476      */ // TODO: describe failure modes
       
   477     default String inferModuleName(Location location) throws IOException {
       
   478         throw new UnsupportedOperationException();
       
   479     }
       
   480 
       
   481     /**
       
   482      * Lists the modules in a module-oriented location.
       
   483      *
       
   484      * @param location  the location for which to list the modules
       
   485      * @return  a series of sets of locations containing modules
       
   486      *
       
   487      * @throws IOException if an I/O error occurred
       
   488      * @throws UnsupportedOperationException if this operation if not supported by this file manager
       
   489      * @since 9
       
   490      */ // TODO: describe failure modes
       
   491     default Iterable<Set<Location>> listModuleLocations(Location location) throws IOException {
       
   492         throw new UnsupportedOperationException();
       
   493     }
       
   494 
   402 }
   495 }