本文整理汇总了Java中javax.tools.JavaFileManager.getClassLoader方法的典型用法代码示例。如果您正苦于以下问题:Java JavaFileManager.getClassLoader方法的具体用法?Java JavaFileManager.getClassLoader怎么用?Java JavaFileManager.getClassLoader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.tools.JavaFileManager
的用法示例。
在下文中一共展示了JavaFileManager.getClassLoader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initProcessorClassLoader
import javax.tools.JavaFileManager; //导入方法依赖的package包/类
private void initProcessorClassLoader() {
JavaFileManager fileManager = context.get(JavaFileManager.class);
try {
// If processorpath is not explicitly set, use the classpath.
processorClassLoader = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH)
? fileManager.getClassLoader(ANNOTATION_PROCESSOR_PATH)
: fileManager.getClassLoader(CLASS_PATH);
if (processorClassLoader != null && processorClassLoader instanceof Closeable) {
JavaCompiler compiler = JavaCompiler.instance(context);
compiler.closeables = compiler.closeables.prepend((Closeable) processorClassLoader);
}
} catch (SecurityException e) {
processorClassLoaderException = e;
}
}
示例2: addCustomTag
import javax.tools.JavaFileManager; //导入方法依赖的package包/类
/**
* Add a new <code>Taglet</code>. Print a message to indicate whether or not
* the Taglet was registered properly.
* @param classname the name of the class representing the custom tag.
* @param fileManager the filemanager to load classes and resources.
* @param tagletPath the path to the class representing the custom tag.
*/
public void addCustomTag(String classname, JavaFileManager fileManager, String tagletPath) {
try {
ClassLoader tagClassLoader;
if (!fileManager.hasLocation(TAGLET_PATH)) {
List<File> paths = new ArrayList<>();
if (tagletPath != null) {
for (String pathname : tagletPath.split(File.pathSeparator)) {
paths.add(new File(pathname));
}
}
if (fileManager instanceof StandardJavaFileManager) {
((StandardJavaFileManager) fileManager).setLocation(TAGLET_PATH, paths);
}
}
tagClassLoader = fileManager.getClassLoader(TAGLET_PATH);
Class<? extends jdk.javadoc.doclet.Taglet> customTagClass =
tagClassLoader.loadClass(classname).asSubclass(jdk.javadoc.doclet.Taglet.class);
jdk.javadoc.doclet.Taglet instance = customTagClass.getConstructor().newInstance();
instance.init(docEnv, doclet);
Taglet newLegacy = new UserTaglet(instance);
String tname = newLegacy.getName();
Taglet t = customTags.get(tname);
if (t != null) {
customTags.remove(tname);
}
customTags.put(tname, newLegacy);
messages.notice("doclet.Notice_taglet_registered", classname);
} catch (Exception exc) {
messages.error("doclet.Error_taglet_not_registered", exc.getClass().getName(), classname);
}
}
示例3: initProcessorIterator
import javax.tools.JavaFileManager; //导入方法依赖的package包/类
private void initProcessorIterator(Context context, Iterable<? extends Processor> processors) {
Log log = Log.instance(context);
Iterator<? extends Processor> processorIterator;
if (options.isSet(XPRINT)) {
try {
Processor processor = PrintingProcessor.class.newInstance();
processorIterator = List.of(processor).iterator();
} catch (Throwable t) {
AssertionError assertError =
new AssertionError("Problem instantiating PrintingProcessor.");
assertError.initCause(t);
throw assertError;
}
} else if (processors != null) {
processorIterator = processors.iterator();
} else {
String processorNames = options.get(PROCESSOR);
JavaFileManager fileManager = context.get(JavaFileManager.class);
try {
// If processorpath is not explicitly set, use the classpath.
processorClassLoader = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH)
? fileManager.getClassLoader(ANNOTATION_PROCESSOR_PATH)
: fileManager.getClassLoader(CLASS_PATH);
/*
* If the "-processor" option is used, search the appropriate
* path for the named class. Otherwise, use a service
* provider mechanism to create the processor iterator.
*/
if (processorNames != null) {
processorIterator = new NameProcessIterator(processorNames, processorClassLoader, log);
} else {
processorIterator = new ServiceIterator(processorClassLoader, log);
}
} catch (SecurityException e) {
/*
* A security exception will occur if we can't create a classloader.
* Ignore the exception if, with hindsight, we didn't need it anyway
* (i.e. no processor was specified either explicitly, or implicitly,
* in service configuration file.) Otherwise, we cannot continue.
*/
processorIterator = handleServiceLoaderUnavailability("proc.cant.create.loader", e);
}
}
discoveredProcs = new DiscoveredProcessors(processorIterator);
}
示例4: addCustomTag
import javax.tools.JavaFileManager; //导入方法依赖的package包/类
/**
* Add a new <code>Taglet</code>. Print a message to indicate whether or not
* the Taglet was registered properly.
* @param classname the name of the class representing the custom tag.
* @param tagletPath the path to the class representing the custom tag.
*/
public void addCustomTag(String classname, JavaFileManager fileManager, String tagletPath) {
try {
Class<?> customTagClass = null;
// construct class loader
String cpString = null; // make sure env.class.path defaults to dot
ClassLoader tagClassLoader;
if (fileManager != null && fileManager.hasLocation(DocumentationTool.Location.TAGLET_PATH)) {
tagClassLoader = fileManager.getClassLoader(DocumentationTool.Location.TAGLET_PATH);
} else {
// do prepends to get correct ordering
cpString = appendPath(System.getProperty("env.class.path"), cpString);
cpString = appendPath(System.getProperty("java.class.path"), cpString);
cpString = appendPath(tagletPath, cpString);
tagClassLoader = new URLClassLoader(pathToURLs(cpString));
}
customTagClass = tagClassLoader.loadClass(classname);
Method meth = customTagClass.getMethod("register",
new Class<?>[] {java.util.Map.class});
Object[] list = customTags.values().toArray();
Taglet lastTag = (list != null && list.length > 0)
? (Taglet) list[list.length-1] : null;
meth.invoke(null, new Object[] {customTags});
list = customTags.values().toArray();
Object newLastTag = (list != null&& list.length > 0)
? list[list.length-1] : null;
if (lastTag != newLastTag) {
//New taglets must always be added to the end of the LinkedHashMap.
//If the current and previous last taglet are not equal, that
//means a new Taglet has been added.
message.notice("doclet.Notice_taglet_registered", classname);
if (newLastTag != null) {
checkTaglet(newLastTag);
}
}
} catch (Exception exc) {
message.error("doclet.Error_taglet_not_registered", exc.getClass().getName(), classname);
}
}