< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java

Print this page

  54 import java.util.Collection;
  55 import java.util.Collections;
  56 import java.util.Comparator;
  57 import java.util.HashMap;
  58 import java.util.Iterator;
  59 import java.util.Map;
  60 import java.util.Objects;
  61 import java.util.ServiceLoader;
  62 import java.util.Set;
  63 import java.util.stream.Stream;
  64 import java.util.zip.ZipException;
  65 
  66 import javax.lang.model.SourceVersion;
  67 import javax.tools.FileObject;
  68 import javax.tools.JavaFileManager;
  69 import javax.tools.JavaFileObject;
  70 import javax.tools.StandardJavaFileManager;
  71 
  72 import com.sun.tools.javac.file.RelativePath.RelativeDirectory;
  73 import com.sun.tools.javac.file.RelativePath.RelativeFile;


  74 import com.sun.tools.javac.main.Option;
  75 import com.sun.tools.javac.resources.CompilerProperties.Errors;
  76 import com.sun.tools.javac.util.Assert;
  77 import com.sun.tools.javac.util.Context;
  78 import com.sun.tools.javac.util.Context.Factory;
  79 import com.sun.tools.javac.util.DefinedBy;
  80 import com.sun.tools.javac.util.DefinedBy.Api;
  81 import com.sun.tools.javac.util.List;
  82 import com.sun.tools.javac.util.ListBuffer;
  83 import com.sun.tools.javac.util.Options;
  84 
  85 import static java.nio.charset.StandardCharsets.US_ASCII;
  86 import static java.nio.file.FileVisitOption.FOLLOW_LINKS;
  87 
  88 import static javax.tools.StandardLocation.*;
  89 
  90 /**
  91  * This class provides access to the source, class and other files
  92  * used by the compiler and related tools.
  93  *

1147     }
1148 
1149     @Override @DefinedBy(Api.COMPILER)
1150     public Location getLocationForModule(Location location, String moduleName) throws IOException {
1151         checkModuleOrientedOrOutputLocation(location);
1152         nullCheck(moduleName);
1153         if (location == SOURCE_OUTPUT && getSourceOutDir() == null)
1154             location = CLASS_OUTPUT;
1155         return locations.getLocationForModule(location, moduleName);
1156     }
1157 
1158     @Override @DefinedBy(Api.COMPILER)
1159     public <S> ServiceLoader<S> getServiceLoader(Location location, Class<S> service) throws IOException {
1160         nullCheck(location);
1161         nullCheck(service);
1162         getClass().getModule().addUses(service);
1163         if (location.isModuleOrientedLocation()) {
1164             Collection<Path> paths = locations.getLocation(location);
1165             ModuleFinder finder = ModuleFinder.of(paths.toArray(new Path[paths.size()]));
1166             ModuleLayer bootLayer = ModuleLayer.boot();
1167             Configuration cf = bootLayer.configuration().resolveAndBind(ModuleFinder.of(), finder, Collections.emptySet());
1168             ModuleLayer layer = bootLayer.defineModulesWithOneLoader(cf, ClassLoader.getSystemClassLoader());











1169             return ServiceLoader.load(layer, service);
1170         } else {
1171             return ServiceLoader.load(service, getClassLoader(location));
1172         }
1173     }
1174 
1175     @Override @DefinedBy(Api.COMPILER)
1176     public Location getLocationForModule(Location location, JavaFileObject fo) throws IOException {
1177         checkModuleOrientedOrOutputLocation(location);
1178         if (!(fo instanceof PathFileObject pathFileObject))
1179             return null;
1180         Path p = Locations.normalize(pathFileObject.path);
1181             // need to find p in location
1182         return locations.getLocationForModule(location, p);
1183     }
1184 
1185     @Override @DefinedBy(Api.COMPILER)
1186     public void setLocationForModule(Location location, String moduleName, Collection<? extends Path> paths)
1187             throws IOException {
1188         nullCheck(location);

  54 import java.util.Collection;
  55 import java.util.Collections;
  56 import java.util.Comparator;
  57 import java.util.HashMap;
  58 import java.util.Iterator;
  59 import java.util.Map;
  60 import java.util.Objects;
  61 import java.util.ServiceLoader;
  62 import java.util.Set;
  63 import java.util.stream.Stream;
  64 import java.util.zip.ZipException;
  65 
  66 import javax.lang.model.SourceVersion;
  67 import javax.tools.FileObject;
  68 import javax.tools.JavaFileManager;
  69 import javax.tools.JavaFileObject;
  70 import javax.tools.StandardJavaFileManager;
  71 
  72 import com.sun.tools.javac.file.RelativePath.RelativeDirectory;
  73 import com.sun.tools.javac.file.RelativePath.RelativeFile;
  74 import com.sun.tools.javac.main.JavaCompiler;
  75 import com.sun.tools.javac.main.JavaCompiler.CodeReflectionSupport;
  76 import com.sun.tools.javac.main.Option;
  77 import com.sun.tools.javac.resources.CompilerProperties.Errors;
  78 import com.sun.tools.javac.util.Assert;
  79 import com.sun.tools.javac.util.Context;
  80 import com.sun.tools.javac.util.Context.Factory;
  81 import com.sun.tools.javac.util.DefinedBy;
  82 import com.sun.tools.javac.util.DefinedBy.Api;
  83 import com.sun.tools.javac.util.List;
  84 import com.sun.tools.javac.util.ListBuffer;
  85 import com.sun.tools.javac.util.Options;
  86 
  87 import static java.nio.charset.StandardCharsets.US_ASCII;
  88 import static java.nio.file.FileVisitOption.FOLLOW_LINKS;
  89 
  90 import static javax.tools.StandardLocation.*;
  91 
  92 /**
  93  * This class provides access to the source, class and other files
  94  * used by the compiler and related tools.
  95  *

1149     }
1150 
1151     @Override @DefinedBy(Api.COMPILER)
1152     public Location getLocationForModule(Location location, String moduleName) throws IOException {
1153         checkModuleOrientedOrOutputLocation(location);
1154         nullCheck(moduleName);
1155         if (location == SOURCE_OUTPUT && getSourceOutDir() == null)
1156             location = CLASS_OUTPUT;
1157         return locations.getLocationForModule(location, moduleName);
1158     }
1159 
1160     @Override @DefinedBy(Api.COMPILER)
1161     public <S> ServiceLoader<S> getServiceLoader(Location location, Class<S> service) throws IOException {
1162         nullCheck(location);
1163         nullCheck(service);
1164         getClass().getModule().addUses(service);
1165         if (location.isModuleOrientedLocation()) {
1166             Collection<Path> paths = locations.getLocation(location);
1167             ModuleFinder finder = ModuleFinder.of(paths.toArray(new Path[paths.size()]));
1168             ModuleLayer bootLayer = ModuleLayer.boot();
1169             ModuleLayer augmentedModuleLayer;
1170             ClassLoader parentCL;
1171             if (CodeReflectionSupport.CODE_LAYER != null) {
1172                 // create a layer whose parent is Babylon's code layer
1173                 augmentedModuleLayer = CodeReflectionSupport.CODE_LAYER;
1174                 parentCL = CodeReflectionSupport.CODE_LAYER.findLoader("jdk.incubator.code");
1175             } else {
1176                 augmentedModuleLayer = bootLayer;
1177                 parentCL = ClassLoader.getSystemClassLoader();
1178             }
1179             Configuration cf = augmentedModuleLayer.configuration()
1180                     .resolveAndBind(ModuleFinder.of(), finder, Collections.emptySet());
1181             ModuleLayer layer = augmentedModuleLayer.defineModulesWithOneLoader(cf, parentCL);
1182             return ServiceLoader.load(layer, service);
1183         } else {
1184             return ServiceLoader.load(service, getClassLoader(location));
1185         }
1186     }
1187 
1188     @Override @DefinedBy(Api.COMPILER)
1189     public Location getLocationForModule(Location location, JavaFileObject fo) throws IOException {
1190         checkModuleOrientedOrOutputLocation(location);
1191         if (!(fo instanceof PathFileObject pathFileObject))
1192             return null;
1193         Path p = Locations.normalize(pathFileObject.path);
1194             // need to find p in location
1195         return locations.getLocationForModule(location, p);
1196     }
1197 
1198     @Override @DefinedBy(Api.COMPILER)
1199     public void setLocationForModule(Location location, String moduleName, Collection<? extends Path> paths)
1200             throws IOException {
1201         nullCheck(location);
< prev index next >