< 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  *

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











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

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