Java Code Examples for com.sun.tools.javac.processing.JavacProcessingEnvironment#instance()

The following examples show how to use com.sun.tools.javac.processing.JavacProcessingEnvironment#instance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataFlow.java    From NullAway with MIT License 6 votes vote down vote up
/**
 * Run the {@code transfer} dataflow analysis over the method, lambda or initializer which is the
 * leaf of the {@code path}.
 *
 * <p>For caching, we make the following assumptions: - if two paths to methods are {@code equal},
 * their control flow graph is the same. - if two transfer functions are {@code equal}, and are
 * run over the same control flow graph, the analysis result is the same. - for all contexts, the
 * analysis result is the same.
 */
private <A extends AbstractValue<A>, S extends Store<S>, T extends TransferFunction<A, S>>
    Result<A, S, T> dataflow(TreePath path, Context context, T transfer) {
  final ProcessingEnvironment env = JavacProcessingEnvironment.instance(context);
  final ControlFlowGraph cfg = cfgCache.getUnchecked(CfgParams.create(path, env));
  final AnalysisParams aparams = AnalysisParams.create(transfer, cfg, env);
  @SuppressWarnings("unchecked")
  final Analysis<A, S, T> analysis = (Analysis<A, S, T>) analysisCache.getUnchecked(aparams);

  return new Result<A, S, T>() {
    @Override
    public Analysis<A, S, T> getAnalysis() {
      return analysis;
    }

    @Override
    public ControlFlowGraph getControlFlowGraph() {
      return cfg;
    }
  };
}
 
Example 2
Source File: JavacPlugin.java    From manifold with Apache License 2.0 6 votes vote down vote up
@Override
public void init( JavacTask task, String... args )
{
  INSTANCE = this;

  // calling this here because the line below this references the type `BasicJavacTask`, which is in a jdk module needing exposure
  NecessaryEvilUtil.bypassJava9Security();

  _javacTask = (BasicJavacTask)task;

  JavacProcessingEnvironment jpe = JavacProcessingEnvironment.instance( _javacTask.getContext() );
  IS_JAVA_8 = jpe.getSourceVersion() == SourceVersion.RELEASE_8;

  processArgs( jpe, args );

  _host = new JavacManifoldHost();
  _fileFragmentResources = new ArrayList<>();
  _javaSourcePath = Collections.emptySet();
  assignBootclasspath();
  hijackJavacFileManager();
  task.addTaskListener( this );
}
 
Example 3
Source File: JavaCompiler.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Check if we should process annotations.
 * If so, and if no scanner is yet registered, then set up the DocCommentScanner
 * to catch doc comments, and set keepComments so the parser records them in
 * the compilation unit.
 *
 * @param processors user provided annotation processors to bypass
 * discovery, {@code null} means that no processors were provided
 */
public void initProcessAnnotations(Iterable<? extends Processor> processors,
                                   Collection<? extends JavaFileObject> initialFiles,
                                   Collection<String> initialClassNames) {
    // Process annotations if processing is not disabled and there
    // is at least one Processor available.
    if (options.isSet(PROC, "none")) {
        processAnnotations = false;
    } else if (procEnvImpl == null) {
        procEnvImpl = JavacProcessingEnvironment.instance(context);
        procEnvImpl.setProcessors(processors);
        processAnnotations = procEnvImpl.atLeastOneProcessor();

        if (processAnnotations) {
            options.put("parameters", "parameters");
            reader.saveParameterNames = true;
            keepComments = true;
            genEndPos = true;
            if (!taskListener.isEmpty())
                taskListener.started(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING));
            deferredDiagnosticHandler = new Log.DeferredDiagnosticHandler(log);
            procEnvImpl.getFiler().setInitialState(initialFiles, initialClassNames);
        } else { // free resources
            procEnvImpl.close();
        }
    }
}
 
Example 4
Source File: EnvironmentDefinitions.java    From manifold with Apache License 2.0 5 votes vote down vote up
protected void addJavacEnvironment( Map<String, String> map )
{
  if( JavacPlugin.instance() == null )
  {
    return ;
  }

  JavacProcessingEnvironment jpe = JavacProcessingEnvironment.instance( JavacPlugin.instance().getContext() );
  addJavaVersion( map, jpe );
  addAnnotationOptions( map, jpe );
}