本文整理汇总了Java中com.sun.tools.javac.api.BasicJavacTask类的典型用法代码示例。如果您正苦于以下问题:Java BasicJavacTask类的具体用法?Java BasicJavacTask怎么用?Java BasicJavacTask使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BasicJavacTask类属于com.sun.tools.javac.api包,在下文中一共展示了BasicJavacTask类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import com.sun.tools.javac.api.BasicJavacTask; //导入依赖的package包/类
/*****************************************
* Add task to the javac compilation process
* @param pe the processing environment
****************************************/
@Override
public synchronized void init(ProcessingEnvironment pe) {
JavacTask task = JavacTask.instance(pe);
if (!(task instanceof BasicJavacTask)) {
pe.getMessager()
.printMessage(Diagnostic.Kind.WARNING,
"Unfortunately you are using an incompatible " +
"version of the javac. Please report this at " +
"https://github.com/prestongarno/trywithres-compat/issues. Thank you.");
return;
}
super.init(pe);
task.addTaskListener(new Loader.TaskListenerImpl(task));
String v = Options.instance(((BasicJavacTask) task).getContext()).get("-g:source");
INJECT_STDOUT_STATEMENT = v != null;
}
示例2: add
import com.sun.tools.javac.api.BasicJavacTask; //导入依赖的package包/类
public static void add(ProcessingEnvironment env, Runnable r) {
// ensure this class in this class loader can access javac internals
try {
JavacTask task = JavacTask.instance(env);
TaskListener l = ((BasicJavacTask) task).getTaskListeners().iterator().next();
// The TaskListener is an instanceof TestClose, but when using the
// default class loaders. the taskListener uses a different
// instance of Class<TestClose> than the anno processor.
// If you try to evaluate
// TestClose tc = (TestClose) (l).
// you get the following somewhat confusing error:
// java.lang.ClassCastException: TestClose cannot be cast to TestClose
// The workaround is to access the fields of TestClose with reflection.
Field f = l.getClass().getField("runnables");
@SuppressWarnings("unchecked")
List<Runnable> runnables = (List<Runnable>) f.get(l);
runnables.add(r);
} catch (Throwable t) {
t.printStackTrace();
}
}
示例3: replaceExtCall
import com.sun.tools.javac.api.BasicJavacTask; //导入依赖的package包/类
private void replaceExtCall( JCTree.JCMethodInvocation tree, Symbol.MethodSymbol method )
{
JCExpression methodSelect = tree.getMethodSelect();
if( methodSelect instanceof JCTree.JCFieldAccess )
{
JCTree.JCFieldAccess m = (JCTree.JCFieldAccess)methodSelect;
boolean isStatic = m.sym.getModifiers().contains( javax.lang.model.element.Modifier.STATIC );
TreeMaker make = _tp.getTreeMaker();
JavacElements javacElems = _tp.getElementUtil();
JCExpression thisArg = m.selected;
String extensionFqn = method.getEnclosingElement().asType().tsym.toString();
m.selected = memberAccess( make, javacElems, extensionFqn );
BasicJavacTask javacTask = ClassSymbols.instance( _sp.getTypeLoader().getModule() ).getJavacTask();
Symbol.ClassSymbol extensionClassSym = ClassSymbols.instance( _sp.getTypeLoader().getModule() ).getClassSymbol( javacTask, extensionFqn ).getFirst();
assignTypes( m.selected, extensionClassSym );
m.sym = method;
m.type = method.type;
if( !isStatic )
{
ArrayList<JCExpression> newArgs = new ArrayList<>( tree.args );
newArgs.add( 0, thisArg );
tree.args = List.from( newArgs );
}
}
}
示例4: CompiledTypeProcessor
import com.sun.tools.javac.api.BasicJavacTask; //导入依赖的package包/类
CompiledTypeProcessor( JavacTask javacTask )
{
_javacTask = javacTask;
javacTask.addTaskListener( this );
Context context = ((BasicJavacTask)javacTask).getContext();
JavaCompiler compiler = JavaCompiler.instance( context );
compiler.shouldStopPolicyIfNoError = CompileState.max( compiler.shouldStopPolicyIfNoError, CompileState.FLOW );
_issueReporter = new IssueReporter<>( Log.instance( context ) );
_types = Types.instance( context );
// DiagnosticListener dl = context.get( DiagnosticListener.class );
// context.put( DiagnosticListener.class, (DiagnosticListener)null );
// context.put( DiagnosticListener.class, new WrappedDiagnosticListener( dl ) );
_typesToProcess = new HashMap<>();
_innerClassForGeneration = new HashMap<>();
}
示例5: init
import com.sun.tools.javac.api.BasicJavacTask; //导入依赖的package包/类
@Override
public void init( JavacTask task, String... args )
{
_javacTask = (BasicJavacTask)task;
if( isCompilingCore() )
{
// Do not apply the plugin on Manifold core itself
// Note this can only happen during incremental compile when JavacPlugin.class was previously compiled and in
// the classpath but other parts of core manifold were changed and need compilation (the placeholder plugin is'nt
// used in this case).
JavacProcessingEnvironment.instance( getContext() ).getMessager().printMessage( Diagnostic.Kind.NOTE, "Bypassing JavacPlugin during incremental compilation of Manifold core" );
return;
}
hijackJavacFileManager();
task.addTaskListener( this );
}
示例6: genSuperCtorCall
import com.sun.tools.javac.api.BasicJavacTask; //导入依赖的package包/类
private String genSuperCtorCall( IModule module, SrcClass srcClass, BasicJavacTask javacTask )
{
String bodyStmt;SrcType superClass = srcClass.getSuperClass();
if( superClass == null )
{
bodyStmt = "";
}
else
{
Symbol.MethodSymbol superCtor = findConstructor( module, superClass.getFqName(), javacTask );
if( superCtor == null )
{
bodyStmt = "";
}
else
{
bodyStmt = genSuperCtorCall( superCtor );
}
}
return bodyStmt;
}
示例7: findConstructor
import com.sun.tools.javac.api.BasicJavacTask; //导入依赖的package包/类
private Symbol.MethodSymbol findConstructor( IModule module, String fqn, BasicJavacTask javacTask )
{
manifold.util.Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> classSymbol = ClassSymbols.instance( module ).getClassSymbol( javacTask, fqn );
Symbol.ClassSymbol cs = classSymbol.getFirst();
Symbol.MethodSymbol ctor = null;
for( Symbol sym : cs.getEnclosedElements() )
{
if( sym instanceof Symbol.MethodSymbol && sym.flatName().toString().equals( "<init>" ) )
{
if( ctor == null )
{
ctor = (Symbol.MethodSymbol)sym;
}
else
{
ctor = mostAccessible( ctor, (Symbol.MethodSymbol)sym );
}
if( Modifier.isPublic( (int)ctor.flags() ) )
{
return ctor;
}
}
}
return ctor;
}
示例8: getClassSymbol
import com.sun.tools.javac.api.BasicJavacTask; //导入依赖的package包/类
public Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> getClassSymbol( BasicJavacTask javacTask, String fqn )
{
JavacElements elementUtils = JavacElements.instance( javacTask.getContext() );
Symbol.ClassSymbol typeElement = elementUtils.getTypeElement( fqn );
JavacTrees trees = JavacTrees.instance( javacTask.getContext() );
TreePath path = trees.getPath( typeElement );
if( path != null )
{
return new Pair<>( typeElement, (JCTree.JCCompilationUnit)path.getCompilationUnit() );
}
else
{
// TreePath is only applicable to a source file;
// if fqn is not a source file, there is no compilation unit available
return new Pair<>( typeElement, null );
}
}
示例9: add
import com.sun.tools.javac.api.BasicJavacTask; //导入依赖的package包/类
public static void add(ProcessingEnvironment env, Runnable r) {
try {
JavacTask task = JavacTask.instance(env);
TaskListener l = ((BasicJavacTask) task).getTaskListeners().iterator().next();
// The TaskListener is an instanceof TestClose, but when using the
// default class loaders. the taskListener uses a different
// instance of Class<TestClose> than the anno processor.
// If you try to evaluate
// TestClose tc = (TestClose) (l).
// you get the following somewhat confusing error:
// java.lang.ClassCastException: TestClose cannot be cast to TestClose
// The workaround is to access the fields of TestClose with reflection.
Field f = l.getClass().getField("runnables");
@SuppressWarnings("unchecked")
List<Runnable> runnables = (List<Runnable>) f.get(l);
runnables.add(r);
} catch (Throwable t) {
t.printStackTrace();
}
}
示例10: init
import com.sun.tools.javac.api.BasicJavacTask; //导入依赖的package包/类
@Override
public void init(JavacTask javacTask, String... args) {
Iterator<String> itr = Arrays.asList(args).iterator();
String path = null;
while (itr.hasNext()) {
if (itr.next().equals("--out")) {
path = itr.next();
break;
}
}
checkArgument(path != null, "No --out specified");
javacTask.addTaskListener(
new RefasterRuleCompilerAnalyzer(
((BasicJavacTask) javacTask).getContext(), FileSystems.getDefault().getPath(path)));
}
示例11: init
import com.sun.tools.javac.api.BasicJavacTask; //导入依赖的package包/类
@Override
public void init(JavacTask javacTask, String... args) {
Context context = ((BasicJavacTask) javacTask).getContext();
BaseErrorProneJavaCompiler.checkCompilePolicy(Options.instance(context).get("compilePolicy"));
BaseErrorProneJavaCompiler.setupMessageBundle(context);
RefactoringCollection[] refactoringCollection = {null};
javacTask.addTaskListener(
BaseErrorProneJavaCompiler.createAnalyzer(
BuiltInCheckerSuppliers.defaultChecks(),
ErrorProneOptions.processArgs(args),
context,
refactoringCollection));
if (refactoringCollection[0] != null) {
javacTask.addTaskListener(new RefactoringTask(context, refactoringCollection[0]));
}
}
示例12: TreeScannerStateful
import com.sun.tools.javac.api.BasicJavacTask; //导入依赖的package包/类
public TreeScannerStateful(CompilationTask task, JCCompilationUnit jcc) {
this.jcc = jcc ;
trees = Trees.instance(task);
treesC = (JavacTrees)trees;
//Rabbit hole to Wonderland
context = ((BasicJavacTask)task).getContext() ;
this.task = ((BasicJavacTask)task) ;
//Initialize magical classes !
make = TreeMaker.instance(context) ;
names = Names.instance(context) ;
syms = Symtab.instance(context);
types = Types.instance(context) ;
typesC = JavacTypes.instance(context) ;
attr = Attr.instance(context) ;
enter = Enter.instance(context) ;
resolve = Resolve.instance(context) ;
memberEnter = MemberEnter.instance(context) ;
javacElements = JavacElements.instance(context) ;
info = TreeInfo.instance(context) ;
sourcePositions = trees.getSourcePositions();
elements = ((JavacTask)task).getElements();
elementsC = (JavacElements)elements;
}
示例13: initDoclint
import com.sun.tools.javac.api.BasicJavacTask; //导入依赖的package包/类
void initDoclint(Collection<String> opts, Collection<String> customTagNames) {
ArrayList<String> doclintOpts = new ArrayList<String>();
for (String opt: opts) {
doclintOpts.add(opt == null ? DocLint.XMSGS_OPTION : DocLint.XMSGS_CUSTOM_PREFIX + opt);
}
if (doclintOpts.isEmpty()) {
doclintOpts.add(DocLint.XMSGS_OPTION);
} else if (doclintOpts.size() == 1
&& doclintOpts.get(0).equals(DocLint.XMSGS_CUSTOM_PREFIX + "none")) {
return;
}
String sep = "";
StringBuilder customTags = new StringBuilder();
for (String customTag : customTagNames) {
customTags.append(sep);
customTags.append(customTag);
sep = DocLint.TAGS_SEPARATOR;
}
doclintOpts.add(DocLint.XCUSTOM_TAGS_PREFIX + customTags.toString());
JavacTask t = BasicJavacTask.instance(context);
doclint = new DocLint();
// standard doclet normally generates H1, H2
doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2");
doclint.init(t, doclintOpts.toArray(new String[doclintOpts.size()]), false);
}
示例14: 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);
}
示例15: 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)
));
}