本文整理汇总了Java中com.sun.tools.javac.api.JavacTaskImpl.ensureEntered方法的典型用法代码示例。如果您正苦于以下问题:Java JavacTaskImpl.ensureEntered方法的具体用法?Java JavacTaskImpl.ensureEntered怎么用?Java JavacTaskImpl.ensureEntered使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.tools.javac.api.JavacTaskImpl
的用法示例。
在下文中一共展示了JavacTaskImpl.ensureEntered方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadBadClass
import com.sun.tools.javac.api.JavacTaskImpl; //导入方法依赖的package包/类
private static BadClassFile loadBadClass(String className) {
// load the class, and save the thrown BadClassFile exception
JavaCompiler c = ToolProvider.getSystemJavaCompiler();
JavacTaskImpl task = (JavacTaskImpl) c.getTask(null, null, null,
Arrays.asList("-classpath", classesdir.getPath()), null, null);
Symtab syms = Symtab.instance(task.getContext());
task.ensureEntered();
BadClassFile badClassFile;
try {
com.sun.tools.javac.main.JavaCompiler.instance(task.getContext())
.resolveIdent(syms.unnamedModule, className).complete();
} catch (BadClassFile e) {
return e;
}
return null;
}
示例2: main
import com.sun.tools.javac.api.JavacTaskImpl; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
javax.tools.JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
JavacTaskImpl task = (JavacTaskImpl)tool.getTask(null, null, null, null, null, null);
JavaCompiler compiler = JavaCompiler.instance(task.getContext());
Symtab syms = Symtab.instance(task.getContext());
task.ensureEntered();
System.out.println(compiler.resolveIdent(syms.unnamedModule, getDeprecatedClass().getCanonicalName()));
}
示例3: main
import com.sun.tools.javac.api.JavacTaskImpl; //导入方法依赖的package包/类
public static void main(String... args) {
javax.tools.JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
JavacTaskImpl task = (JavacTaskImpl)tool.getTask(null, null, null, null, null, null);
Symtab syms = Symtab.instance(task.getContext());
task.ensureEntered();
JavaCompiler compiler = JavaCompiler.instance(task.getContext());
try {
compiler.resolveIdent(syms.unnamedModule, "Test$1").complete();
} catch (CompletionFailure ex) {
System.err.println("Got expected completion failure: " + ex.getLocalizedMessage());
return;
}
throw new AssertionError("No error reported");
}
示例4: test
import com.sun.tools.javac.api.JavacTaskImpl; //导入方法依赖的package包/类
private static void test(String classname, String expected) throws Exception {
File classfile = new File(System.getProperty("test.classes", "."), classname + ".class");
ClassFile cf = ClassFile.read(classfile);
cf = new ClassFile(cf.magic, Target.JDK1_7.minorVersion,
Target.JDK1_7.majorVersion, cf.constant_pool, cf.access_flags,
cf.this_class, cf.super_class, cf.interfaces, cf.fields,
cf.methods, cf.attributes);
new ClassWriter().write(cf, classfile);
JavaCompiler c = ToolProvider.getSystemJavaCompiler();
JavacTaskImpl task = (JavacTaskImpl) c.getTask(null, null, null, Arrays.asList("-classpath", System.getProperty("test.classes", ".")), null, null);
Symtab syms = Symtab.instance(task.getContext());
task.ensureEntered();
try {
Symbol clazz = com.sun.tools.javac.main.JavaCompiler.instance(task.getContext()).resolveIdent(syms.unnamedModule, classname);
clazz.complete();
} catch (BadClassFile f) {
JCDiagnostic embeddedDiag = (JCDiagnostic) f.diag.getArgs()[1];
assertEquals(expected, embeddedDiag.getCode());
assertEquals(Integer.toString(Target.JDK1_7.majorVersion), embeddedDiag.getArgs()[0]);
assertEquals(Integer.toString(Target.JDK1_7.minorVersion), embeddedDiag.getArgs()[1]);
}
}