本文整理汇总了Java中com.sun.tools.javac.file.JavacFileManager类的典型用法代码示例。如果您正苦于以下问题:Java JavacFileManager类的具体用法?Java JavacFileManager怎么用?Java JavacFileManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JavacFileManager类属于com.sun.tools.javac.file包,在下文中一共展示了JavacFileManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDirectAccess1
import com.sun.tools.javac.file.JavacFileManager; //导入依赖的package包/类
@Test
public void testDirectAccess1() throws Exception {
JavaFileObject srcFile = createSimpleJavaFileObject();
Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
Context c = new Context();
Messager.preRegister(c, "javadoc");
try (StandardJavaFileManager fm = new JavacFileManager(c, true, null)) {
File outDir = getOutDir();
fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
DocumentationTask t = new JavadocTaskImpl(c, null, null, files);
if (t.call()) {
System.err.println("task succeeded");
} else {
throw new Exception("task failed");
}
}
}
示例2: testDirectAccess2
import com.sun.tools.javac.file.JavacFileManager; //导入依赖的package包/类
@Test
public void testDirectAccess2() throws Exception {
JavaFileObject srcFile = null; // error, provokes NPE
Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
Context c = new Context();
Messager.preRegister(c, "javadoc");
try (StandardJavaFileManager fm = new JavacFileManager(c, true, null)) {
File outDir = getOutDir();
fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
try {
DocumentationTask t = new JavadocTaskImpl(c, null, null, files);;
error("getTask succeeded, no exception thrown");
} catch (NullPointerException e) {
System.err.println("exception caught as expected: " + e);
}
}
}
示例3: handleServiceLoaderUnavailability
import com.sun.tools.javac.file.JavacFileManager; //导入依赖的package包/类
/**
* Returns an empty processor iterator if no processors are on the
* relevant path, otherwise if processors are present, logs an
* error. Called when a service loader is unavailable for some
* reason, either because a service loader class cannot be found
* or because a security policy prevents class loaders from being
* created.
*
* @param key The resource key to use to log an error message
* @param e If non-null, pass this exception to Abort
*/
private Iterator<Processor> handleServiceLoaderUnavailability(String key, Exception e) {
JavaFileManager fileManager = context.get(JavaFileManager.class);
if (fileManager instanceof JavacFileManager) {
StandardJavaFileManager standardFileManager = (JavacFileManager) fileManager;
Iterable<? extends File> workingPath = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH)
? standardFileManager.getLocation(ANNOTATION_PROCESSOR_PATH)
: standardFileManager.getLocation(CLASS_PATH);
if (needClassLoader(options.get(PROCESSOR), workingPath) )
handleException(key, e);
} else {
handleException(key, e);
}
java.util.List<Processor> pl = Collections.emptyList();
return pl.iterator();
}
示例4: DocEnv
import com.sun.tools.javac.file.JavacFileManager; //导入依赖的package包/类
/**
* Constructor
*
* @param context Context for this javadoc instance.
*/
protected DocEnv(Context context) {
context.put(docEnvKey, this);
this.context = context;
messager = Messager.instance0(context);
syms = Symtab.instance(context);
reader = JavadocClassReader.instance0(context);
enter = JavadocEnter.instance0(context);
names = Names.instance(context);
externalizableSym = reader.enterClass(names.fromString("java.io.Externalizable"));
chk = Check.instance(context);
types = Types.instance(context);
fileManager = context.get(JavaFileManager.class);
if (fileManager instanceof JavacFileManager) {
((JavacFileManager)fileManager).setSymbolFileEnabled(false);
}
// Default. Should normally be reset with setLocale.
this.doclocale = new DocLocale(this, "", breakiterator);
source = Source.instance(context);
}
示例5: handleServiceLoaderUnavailability
import com.sun.tools.javac.file.JavacFileManager; //导入依赖的package包/类
/**
* Returns an empty processor iterator if no processors are on the
* relevant path, otherwise if processors are present, logs an
* error. Called when a service loader is unavailable for some
* reason, either because a service loader class cannot be found
* or because a security policy prevents class loaders from being
* created.
*
* @param key The resource key to use to log an error message
* @param e If non-null, pass this exception to Abort
*/
private Iterator<Processor> handleServiceLoaderUnavailability(String key, Exception e) {
if (fileManager instanceof JavacFileManager) {
StandardJavaFileManager standardFileManager = (JavacFileManager) fileManager;
Iterable<? extends Path> workingPath = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH)
? standardFileManager.getLocationAsPaths(ANNOTATION_PROCESSOR_PATH)
: standardFileManager.getLocationAsPaths(CLASS_PATH);
if (needClassLoader(options.get(Option.PROCESSOR), workingPath) )
handleException(key, e);
} else {
handleException(key, e);
}
java.util.List<Processor> pl = Collections.emptyList();
return pl.iterator();
}
示例6: getStandardFileManager
import com.sun.tools.javac.file.JavacFileManager; //导入依赖的package包/类
@Override @DefinedBy(Api.COMPILER)
public JavacFileManager getStandardFileManager(
DiagnosticListener<? super JavaFileObject> diagnosticListener,
Locale locale,
Charset charset) {
Context context = new Context();
context.put(Locale.class, locale);
if (diagnosticListener != null)
context.put(DiagnosticListener.class, diagnosticListener);
PrintWriter pw = (charset == null)
? new PrintWriter(System.err, true)
: new PrintWriter(new OutputStreamWriter(System.err, charset), true);
context.put(Log.errKey, pw);
CacheFSInfo.preRegister(context);
return new JavacFileManager(context, true, charset);
}
示例7: ToolEnvironment
import com.sun.tools.javac.file.JavacFileManager; //导入依赖的package包/类
/**
* Constructor
*
* @param context Context for this javadoc instance.
*/
protected ToolEnvironment(Context context) {
context.put(ToolEnvKey, this);
this.context = context;
messager = Messager.instance0(context);
syms = Symtab.instance(context);
finder = JavadocClassFinder.instance(context);
enter = JavadocEnter.instance(context);
names = Names.instance(context);
externalizableSym = syms.enterClass(syms.java_base, names.fromString("java.io.Externalizable"));
chk = Check.instance(context);
types = com.sun.tools.javac.code.Types.instance(context);
fileManager = context.get(JavaFileManager.class);
if (fileManager instanceof JavacFileManager) {
((JavacFileManager)fileManager).setSymbolFileEnabled(false);
}
docTrees = JavacTrees.instance(context);
source = Source.instance(context);
elements = JavacElements.instance(context);
typeutils = JavacTypes.instance(context);
elementToTreePath = new HashMap<>();
}
示例8: DocEnv
import com.sun.tools.javac.file.JavacFileManager; //导入依赖的package包/类
/**
* Constructor
*
* @param context Context for this javadoc instance.
*/
protected DocEnv(Context context) {
context.put(docEnvKey, this);
this.context = context;
messager = Messager.instance0(context);
syms = Symtab.instance(context);
finder = JavadocClassFinder.instance(context);
enter = JavadocEnter.instance(context);
names = Names.instance(context);
externalizableSym = syms.enterClass(syms.java_base, names.fromString("java.io.Externalizable"));
chk = Check.instance(context);
types = Types.instance(context);
fileManager = context.get(JavaFileManager.class);
if (fileManager instanceof JavacFileManager) {
((JavacFileManager)fileManager).setSymbolFileEnabled(false);
}
// Default. Should normally be reset with setLocale.
this.doclocale = new DocLocale(this, "", breakiterator);
source = Source.instance(context);
}
示例9: run
import com.sun.tools.javac.file.JavacFileManager; //导入依赖的package包/类
void run() throws Exception {
RelativeFile TEST_ENTRY_NAME = new RelativeFile("java/lang/String.class");
File testJar = createJar("test.jar", "java.lang.*");
try (JarFile j = new JarFile(testJar)) {
JarEntry je = j.getJarEntry(TEST_ENTRY_NAME.getPath());
long jarEntryTime = je.getTime();
Context context = new Context();
JavacFileManager fm = new JavacFileManager(context, false, null);
fm.setLocation(StandardLocation.CLASS_PATH, Collections.singletonList(testJar));
FileObject fo =
fm.getFileForInput(StandardLocation.CLASS_PATH, "", TEST_ENTRY_NAME.getPath());
long jfoTime = fo.getLastModified();
check(je, jarEntryTime, fo, jfoTime);
if (errors > 0)
throw new Exception(errors + " occurred");
}
}
示例10: main
import com.sun.tools.javac.file.JavacFileManager; //导入依赖的package包/类
public static void main(String... args) throws Throwable {
String self = T6358166.class.getName();
String testSrc = System.getProperty("test.src");
JavacFileManager fm = new JavacFileManager(new Context(), false, null);
JavaFileObject f = fm.getJavaFileObject(testSrc + File.separatorChar + self + ".java");
List<String> addExports = Arrays.asList(
"--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"--add-exports", "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
"--add-exports", "jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
"--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED");
test(fm, f, addExports, "-verbose", "-d", ".");
test(fm, f, addExports, "-verbose", "-d", ".", "-XprintRounds", "-processorpath", ".", "-processor", self);
}
示例11: test
import com.sun.tools.javac.file.JavacFileManager; //导入依赖的package包/类
static void test(JavacFileManager fm, JavaFileObject f, List<String> addExports, String... args) throws Throwable {
List<String> allArgs = new ArrayList<>();
allArgs.addAll(addExports);
allArgs.addAll(Arrays.asList(args));
Context context = new Context();
JavacTool tool = JavacTool.create();
JavacTaskImpl task = (JavacTaskImpl) tool.getTask(null, fm, null, allArgs, null, List.of(f), context);
task.call();
JavaCompiler c = JavaCompiler.instance(context);
if (c.errorCount() != 0)
throw new AssertionError("compilation failed");
long msec = c.elapsed_msec;
if (msec < 0 || msec > 5 * 60 * 1000) // allow test 5 mins to execute, should be more than enough!
throw new AssertionError("elapsed time is suspect: " + msec);
}
示例12: main
import com.sun.tools.javac.file.JavacFileManager; //导入依赖的package包/类
public static void main(String... args) {
JavaCompiler compiler = JavaCompiler.instance(new Context());
compiler.keepComments = true;
String testSrc = System.getProperty("test.src");
JavacFileManager fm = new JavacFileManager(new Context(), false, null);
JavaFileObject f = fm.getJavaFileObject(testSrc + File.separatorChar + "T4910483.java");
JCTree.JCCompilationUnit cu = compiler.parse(f);
JCTree classDef = cu.getTypeDecls().head;
String commentText = cu.docComments.getCommentText(classDef);
String expected = "Test comment abc*\\\\def"; // 4 '\' escapes to 2 in a string literal
if (!expected.equals(commentText)) {
throw new AssertionError("Incorrect comment text: [" + commentText + "], expected [" + expected + "]");
}
}
示例13: run
import com.sun.tools.javac.file.JavacFileManager; //导入依赖的package包/类
void run() throws Exception {
Context context = new Context();
JavacFileManager.preRegister(context);
Symtab syms = Symtab.instance(context);
maker = TreeMaker.instance(context);
types = Types.instance(context);
test("abc", CLASS, syms.stringType, "abc");
test(Boolean.FALSE, BOOLEAN, syms.booleanType, Integer.valueOf(0));
test(Boolean.TRUE, BOOLEAN, syms.booleanType, Integer.valueOf(1));
test(Byte.valueOf((byte) 1), BYTE, syms.byteType, Byte.valueOf((byte) 1));
test(Character.valueOf('a'), CHAR, syms.charType, Integer.valueOf('a'));
test(Double.valueOf(1d), DOUBLE, syms.doubleType, Double.valueOf(1d));
test(Float.valueOf(1f), FLOAT, syms.floatType, Float.valueOf(1f));
test(Integer.valueOf(1), INT, syms.intType, Integer.valueOf(1));
test(Long.valueOf(1), LONG, syms.longType, Long.valueOf(1));
test(Short.valueOf((short) 1), SHORT, syms.shortType, Short.valueOf((short) 1));
if (errors > 0)
throw new Exception(errors + " errors found");
}
示例14: run
import com.sun.tools.javac.file.JavacFileManager; //导入依赖的package包/类
void run() throws Exception {
Context context = new Context();
JavacFileManager.preRegister(context);
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
JavacTask ct = (JavacTask)tool.getTask(null, null, null, null, null, Arrays.asList(new JavaSource()));
Iterable<? extends CompilationUnitTree> elements = ct.parse();
ct.analyze();
Assert.check(elements.iterator().hasNext());
JCTree topLevel = (JCTree)elements.iterator().next();
new TreeScanner() {
@Override
public void visitReference(JCMemberReference tree) {
Assert.check(tree.getOverloadKind() != null);
}
}.scan(topLevel);
}
示例15: main
import com.sun.tools.javac.file.JavacFileManager; //导入依赖的package包/类
public static void main(String... args) throws Throwable {
JavacFileManager fm = new JavacFileManager(new Context(), false, null);
List<JavaFileObject> files = toList(fm.getJavaFileObjects(new File(testSrc, self + ".java")));
try {
// first, test case with no annotation processing
testNoAnnotationProcessing(fm, files);
// now, test case with annotation processing
testAnnotationProcessing(fm, files);
}
catch (Throwable t) {
throw new AssertionError(t);
}
}