本文整理汇总了Java中com.sun.tools.javac.api.BasicJavacTask.getContext方法的典型用法代码示例。如果您正苦于以下问题:Java BasicJavacTask.getContext方法的具体用法?Java BasicJavacTask.getContext怎么用?Java BasicJavacTask.getContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.tools.javac.api.BasicJavacTask
的用法示例。
在下文中一共展示了BasicJavacTask.getContext方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: AbstractCodingRulesAnalyzer
import com.sun.tools.javac.api.BasicJavacTask; //导入方法依赖的package包/类
public AbstractCodingRulesAnalyzer(JavacTask task) {
BasicJavacTask impl = (BasicJavacTask)task;
Context context = impl.getContext();
log = Log.instance(context);
options = Options.instance(context);
rawDiagnostics = options.isSet("rawDiagnostics");
diags = JCDiagnostic.Factory.instance(context);
messages = new Messages();
syms = Symtab.instance(context);
elements = JavacElements.instance(context);
types = JavacTypes.instance(context);
}
示例2: init
import com.sun.tools.javac.api.BasicJavacTask; //导入方法依赖的package包/类
@DefinedBy(Api.COMPILER_TREE)
public void init(JavacTask task, String... args) {
BasicJavacTask impl = (BasicJavacTask)task;
Context context = impl.getContext();
log = Log.instance(context);
trees = Trees.instance(task);
task.addTaskListener(new PostAnalyzeTaskListener(
new MutableFieldsAnalyzer(task),
new AssertCheckAnalyzer(task),
new DefinedByAnalyzer(task),
new LegacyLogMethodAnalyzer(task)
));
}
示例3: init
import com.sun.tools.javac.api.BasicJavacTask; //导入方法依赖的package包/类
@DefinedBy(Api.COMPILER_TREE)
public void init(JavacTask task, String... args) {
BasicJavacTask impl = (BasicJavacTask)task;
Context context = impl.getContext();
log = Log.instance(context);
trees = Trees.instance(task);
task.addTaskListener(new PostAnalyzeTaskListener(
new MutableFieldsAnalyzer(task),
new AssertCheckAnalyzer(task),
new DefinedByAnalyzer(task)
));
}
示例4: init
import com.sun.tools.javac.api.BasicJavacTask; //导入方法依赖的package包/类
public void init(JavacTask task, String... args) {
BasicJavacTask impl = (BasicJavacTask)task;
Context context = impl.getContext();
log = Log.instance(context);
trees = Trees.instance(task);
messages = new Messages();
task.addTaskListener(new PostAnalyzeTaskListener());
}
示例5: clearPendingUnits
import com.sun.tools.javac.api.BasicJavacTask; //导入方法依赖的package包/类
protected void clearPendingUnits(BasicJavacTask task) {
List<CompilationUnitTaskList> missing = new ArrayList<>();
cups.values()
.stream()
.filter(pcu -> pcu.getUnit() == null)
.forEach(missing::add);
if (!missing.isEmpty()) {
Context ctx = new Context(task.getContext());
ctx.put(JavacService.class, service);
MultiTaskListener tasks = MultiTaskListener.instance(ctx);
tasks.add(getTaskListener(task));
JavacProcessingEnvironment env = JavacProcessingEnvironment.instance(ctx);
try (
JavacFileManager jfm = new JavacFileManager(ctx, false, Charset.forName("UTF-8"))
) {
List<JavaFileObject> missingFiles = new ArrayList<>();
missing.forEach(pcu -> {
String name = pcu.getName();
TypeElement element = task.getElements().getTypeElement(name);
if (element == null) {
X_Log.info(getClass(), "No element found for ", name);
} else {
final javax.lang.model.element.Name qualified = element.getQualifiedName();
Name binary = env.getElementUtils().getBinaryName(element);
String relativeName = binary.toString().split("[$]")[0];// TODO check for enclosing types instead of this nasty hack
JavaFileObject javaFile;
try {
javaFile = jfm.getJavaFileForInput(StandardLocation.SOURCE_OUTPUT, relativeName, JavaFileObject.Kind.SOURCE);
if (javaFile == null) {
javaFile = jfm.getJavaFileForInput(StandardLocation.SOURCE_PATH, relativeName, JavaFileObject.Kind.SOURCE);
if (javaFile == null) {
javaFile = jfm.getJavaFileForInput(StandardLocation.CLASS_PATH, relativeName, JavaFileObject.Kind.SOURCE);
if (javaFile == null) {
X_Log.warn(getClass(), "Unable to find file ", relativeName, " to recompile...");
}
}
}
if (javaFile != null){
missingFiles.add(javaFile);
}
} catch (Throwable e) {
X_Log.warn(getClass(), "Unable to compile source for "+binary, e);
throw X_Debug.rethrow(e);
}
// pcu.setUnit(cu);
// pcu.finish();
}
});
JavaCompiler compiler = JavaCompiler.instance(ctx);
final com.sun.tools.javac.util.List<JavaFileObject> javaFiles = com.sun.tools.javac.util.List.from(missingFiles.toArray(new JavaFileObject[missingFiles.size()]));
compiler.compile(javaFiles);
} catch (Throwable throwable) {
throw X_Debug.rethrow(throwable);
}
}
doFinish();
}