com.sun.tools.javac.processing.JavacProcessingEnvironment Java Examples

The following examples show how to use com.sun.tools.javac.processing.JavacProcessingEnvironment. 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: TestContext.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    round++;

    JavacProcessingEnvironment jpe = (JavacProcessingEnvironment) processingEnv;
    Context c = jpe.getContext();
    check(c.get(JavacElements.class), eltUtils);
    check(c.get(JavacTypes.class), typeUtils);
    check(c.get(JavacTrees.class), treeUtils);

    final int MAXROUNDS = 3;
    if (round < MAXROUNDS)
        generateSource("Gen" + round);

    return true;
}
 
Example #2
Source File: TestContext.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    round++;

    JavacProcessingEnvironment jpe = (JavacProcessingEnvironment) processingEnv;
    Context c = jpe.getContext();
    check(c.get(JavacElements.class), eltUtils);
    check(c.get(JavacTypes.class), typeUtils);
    check(c.get(JavacTrees.class), treeUtils);

    final int MAXROUNDS = 3;
    if (round < MAXROUNDS)
        generateSource("Gen" + round);

    return true;
}
 
Example #3
Source File: T7018098.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    Context context = ((JavacProcessingEnvironment) processingEnv).getContext();
    FSInfo fsInfo = context.get(FSInfo.class);

    round++;
    if (round == 1) {
        boolean expect = Boolean.valueOf(options.get("expect"));
        checkEqual("cache result", fsInfo.isDirectory(testDir), expect);
        initialFSInfo = fsInfo;
    } else {
        checkEqual("fsInfo", fsInfo, initialFSInfo);
    }

    return true;
}
 
Example #4
Source File: T7018098.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    Context context = ((JavacProcessingEnvironment) processingEnv).getContext();
    FSInfo fsInfo = context.get(FSInfo.class);

    round++;
    if (round == 1) {
        boolean expect = Boolean.valueOf(options.get("expect"));
        checkEqual("cache result", fsInfo.isDirectory(testDir), expect);
        initialFSInfo = fsInfo;
    } else {
        checkEqual("fsInfo", fsInfo, initialFSInfo);
    }

    return true;
}
 
Example #5
Source File: TestContext.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    round++;

    JavacProcessingEnvironment jpe = (JavacProcessingEnvironment) processingEnv;
    Context c = jpe.getContext();
    check(c.get(JavacElements.class), eltUtils);
    check(c.get(JavacTypes.class), typeUtils);
    check(c.get(JavacTrees.class), treeUtils);

    final int MAXROUNDS = 3;
    if (round < MAXROUNDS)
        generateSource("Gen" + round);

    return true;
}
 
Example #6
Source File: TestContext.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    round++;

    JavacProcessingEnvironment jpe = (JavacProcessingEnvironment) processingEnv;
    Context c = jpe.getContext();
    check(c.get(JavacElements.class), eltUtils);
    check(c.get(JavacTypes.class), typeUtils);
    check(c.get(JavacTrees.class), treeUtils);

    final int MAXROUNDS = 3;
    if (round < MAXROUNDS)
        generateSource("Gen" + round);

    return true;
}
 
Example #7
Source File: TestContext.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    round++;

    JavacProcessingEnvironment jpe = (JavacProcessingEnvironment) processingEnv;
    Context c = jpe.getContext();
    check(c.get(JavacElements.class), eltUtils);
    check(c.get(JavacTypes.class), typeUtils);
    check(c.get(JavacTrees.class), treeUtils);

    final int MAXROUNDS = 3;
    if (round < MAXROUNDS)
        generateSource("Gen" + round);

    return true;
}
 
Example #8
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 #9
Source File: AccessPathNullnessPropagation.java    From NullAway with MIT License 6 votes vote down vote up
@Nullable
private ClassTree findEnclosingLocalOrAnonymousClass(ClassTree classTree) {
  Symbol.ClassSymbol symbol = ASTHelpers.getSymbol(classTree);
  // we need this while loop since we can have a NestingKind.NESTED class (i.e., a nested
  // class declared at the top-level within its enclosing class) nested (possibly deeply)
  // within a NestingKind.ANONYMOUS or NestingKind.LOCAL class
  while (symbol.getNestingKind().isNested()) {
    if (symbol.getNestingKind().equals(NestingKind.ANONYMOUS)
        || symbol.getNestingKind().equals(NestingKind.LOCAL)) {
      return Trees.instance(JavacProcessingEnvironment.instance(context)).getTree(symbol);
    } else {
      // symbol.owner is the enclosing element, which could be a class or a method.
      // if it's a class, the enclClass() method will (surprisingly) return the class itself,
      // so this works
      symbol = symbol.owner.enclClass();
    }
  }
  return null;
}
 
Example #10
Source File: T7018098.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    Context context = ((JavacProcessingEnvironment) processingEnv).getContext();
    FSInfo fsInfo = context.get(FSInfo.class);

    round++;
    if (round == 1) {
        boolean expect = Boolean.valueOf(options.get("expect"));
        checkEqual("cache result", fsInfo.isDirectory(testDir.toPath()), expect);
        initialFSInfo = fsInfo;
    } else {
        checkEqual("fsInfo", fsInfo, initialFSInfo);
    }

    return true;
}
 
Example #11
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 #12
Source File: TestContext.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    round++;

    JavacProcessingEnvironment jpe = (JavacProcessingEnvironment) processingEnv;
    Context c = jpe.getContext();
    check(c.get(JavacElements.class), eltUtils);
    check(c.get(JavacTypes.class), typeUtils);
    check(c.get(JavacTrees.class), treeUtils);

    final int MAXROUNDS = 3;
    if (round < MAXROUNDS)
        generateSource("Gen" + round);

    return true;
}
 
Example #13
Source File: T7018098.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    Context context = ((JavacProcessingEnvironment) processingEnv).getContext();
    FSInfo fsInfo = context.get(FSInfo.class);

    round++;
    if (round == 1) {
        boolean expect = Boolean.valueOf(options.get("expect"));
        checkEqual("cache result", fsInfo.isDirectory(testDir), expect);
        initialFSInfo = fsInfo;
    } else {
        checkEqual("fsInfo", fsInfo, initialFSInfo);
    }

    return true;
}
 
Example #14
Source File: T7018098.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    Context context = ((JavacProcessingEnvironment) processingEnv).getContext();
    FSInfo fsInfo = context.get(FSInfo.class);

    round++;
    if (round == 1) {
        boolean expect = Boolean.valueOf(options.get("expect"));
        checkEqual("cache result", fsInfo.isDirectory(testDir), expect);
        initialFSInfo = fsInfo;
    } else {
        checkEqual("fsInfo", fsInfo, initialFSInfo);
    }

    return true;
}
 
Example #15
Source File: CodeTranslator.java    From vertx-codetrans with Apache License 2.0 6 votes vote down vote up
public CodeTranslator(ProcessingEnvironment processingEnv) {
  this.trees = Trees.instance(processingEnv);
  this.SystemType = (DeclaredType) processingEnv.getElementUtils().getTypeElement(System.class.getName()).asType();
  this.ThrowableType = (DeclaredType) processingEnv.getElementUtils().getTypeElement(Throwable.class.getName()).asType();
  Context context = ((JavacProcessingEnvironment)processingEnv).getContext();
  this.attr = Attr.instance(context);
  this.typeUtils = processingEnv.getTypeUtils();
  this.factory = new TypeMirrorFactory(processingEnv.getElementUtils(), processingEnv.getTypeUtils()) {
    @Override
    public TypeInfo create(TypeUse use, TypeMirror type) {
      if (type.getKind() == TypeKind.WILDCARD) {
        WildcardType wildcardType = (WildcardType) type;
        if (wildcardType.getExtendsBound() != null) {
          return super.create(wildcardType.getExtendsBound());
        } else if (wildcardType.getSuperBound() != null) {
          return super.create(use, wildcardType.getSuperBound());
        }
      }
      return super.create(use, type);
    }
  };
}
 
Example #16
Source File: T6597678.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    Context context = ((JavacProcessingEnvironment) processingEnv).getContext();
    Log log = Log.instance(context);
    PrintWriter noteOut = log.getWriter(Log.WriterKind.NOTICE);
    PrintWriter warnOut = log.getWriter(Log.WriterKind.WARNING);
    PrintWriter errOut  = log.getWriter(Log.WriterKind.ERROR);
    Locale locale = context.get(Locale.class);
    JavacMessages messages = context.get(JavacMessages.messagesKey);

    round++;
    if (round == 1) {
        initialLocale = locale;
        initialMessages = messages;
        initialNoteWriter = noteOut;
        initialWarnWriter = warnOut;
        initialErrWriter  = errOut;

        String writerStringOpt = options.get("WriterString").intern();
        checkEqual("noteWriterString", noteOut.toString().intern(), writerStringOpt);
        checkEqual("warnWriterString", warnOut.toString().intern(), writerStringOpt);
        checkEqual("errWriterString",  errOut.toString().intern(),  writerStringOpt);
    } else {
        checkEqual("locale", locale, initialLocale);
        checkEqual("messages", messages, initialMessages);
        checkEqual("noteWriter", noteOut, initialNoteWriter);
        checkEqual("warnWriter", warnOut, initialWarnWriter);
        checkEqual("errWriter",  errOut,  initialErrWriter);
    }

    return true;
}
 
Example #17
Source File: TypeProcOnly.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final void init(ProcessingEnvironment env) {
    super.init(env);
    JavacTask.instance(env).addTaskListener(listener);
    Context ctx = ((JavacProcessingEnvironment)processingEnv).getContext();
    JavaCompiler compiler = JavaCompiler.instance(ctx);
    compiler.shouldStopPolicyIfNoError = CompileState.max(
            compiler.shouldStopPolicyIfNoError,
            CompileState.FLOW);
}
 
Example #18
Source File: T6597678.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    Context context = ((JavacProcessingEnvironment) processingEnv).getContext();
    Log log = Log.instance(context);
    PrintWriter noteOut = log.getWriter(Log.WriterKind.NOTICE);
    PrintWriter warnOut = log.getWriter(Log.WriterKind.WARNING);
    PrintWriter errOut  = log.getWriter(Log.WriterKind.ERROR);
    Locale locale = context.get(Locale.class);
    JavacMessages messages = context.get(JavacMessages.messagesKey);

    round++;
    if (round == 1) {
        initialLocale = locale;
        initialMessages = messages;
        initialNoteWriter = noteOut;
        initialWarnWriter = warnOut;
        initialErrWriter  = errOut;

        String writerStringOpt = options.get("WriterString").intern();
        checkEqual("noteWriterString", noteOut.toString().intern(), writerStringOpt);
        checkEqual("warnWriterString", warnOut.toString().intern(), writerStringOpt);
        checkEqual("errWriterString",  errOut.toString().intern(),  writerStringOpt);
    } else {
        checkEqual("locale", locale, initialLocale);
        checkEqual("messages", messages, initialMessages);
        checkEqual("noteWriter", noteOut, initialNoteWriter);
        checkEqual("warnWriter", warnOut, initialWarnWriter);
        checkEqual("errWriter",  errOut,  initialErrWriter);
    }

    return true;
}
 
Example #19
Source File: T7021650.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    round++;

    Context context = ((JavacProcessingEnvironment) processingEnv).getContext();

    // verify items in context as expected
    check("Demo", Demo.instance(context), Demo.class);
    check("Attr", Attr.instance(context), MyAttr.class);

    // For a few rounds, generate new source files, so that we can check whether
    // values in the context are correctly handled in subsequent processing rounds
    if (round <= MAX_ROUNDS) {
        String pkg = "p";
        String currClass = "Gen" + round;
        String curr = pkg + "." + currClass;
        String next = (pkg + ".Gen" + (round + 1));
        StringBuilder text = new StringBuilder();
        text.append("package ").append(pkg).append(";\n");
        text.append("public class ").append(currClass).append(" {\n");
        if (round < MAX_ROUNDS)
            text.append("    ").append(next).append(" x;\n");
        text.append("}\n");

        try {
            JavaFileObject fo = filer.createSourceFile(curr);
            Writer out = fo.openWriter();
            try {
                out.write(text.toString());
            } finally {
                out.close();
            }
        } catch (IOException e) {
            throw new Error(e);
        }
    }

    return true;
}
 
Example #20
Source File: GenerateGetMethodProcessor.java    From java-master with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);
    this.processingEnv = processingEnv;
    this.elementUtils = processingEnv.getElementUtils();
    this.typeUtils = processingEnv.getTypeUtils();
    this.filer = processingEnv.getFiler();
    this.trees = JavacTrees.instance(processingEnv);
    Context context = ((JavacProcessingEnvironment) processingEnv).getContext();
    this.treeMaker = TreeMaker.instance(context);
    this.names = Names.instance(context);
}
 
Example #21
Source File: CompileModulePatchTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    Symtab syms = Symtab.instance(((JavacProcessingEnvironment) processingEnv).getContext());
    Elements elements = processingEnv.getElementUtils();
    ModuleElement unnamedModule = syms.unnamedModule;
    ModuleElement mModule = elements.getModuleElement("m");

    assertNonNull("mModule found", mModule);
    assertNonNull("src.Src from m", elements.getTypeElement(mModule, "src.Src"));
    assertNull("cp.CP not from m", elements.getTypeElement(mModule, "cp.CP"));
    assertNull("src.Src not from unnamed", elements.getTypeElement(unnamedModule, "src.Src"));
    assertNonNull("cp.CP from unnamed", elements.getTypeElement(unnamedModule, "cp.CP"));

    return false;
}
 
Example #22
Source File: TypeProcOnly.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final void init(ProcessingEnvironment env) {
    super.init(env);
    JavacTask.instance(env).addTaskListener(listener);
    Context ctx = ((JavacProcessingEnvironment)processingEnv).getContext();
    JavaCompiler compiler = JavaCompiler.instance(ctx);
    compiler.shouldStopPolicyIfNoError = CompileState.max(
            compiler.shouldStopPolicyIfNoError,
            CompileState.FLOW);
}
 
Example #23
Source File: PackageProcessor.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final void init(ProcessingEnvironment env) {
    super.init(env);
    JavacTask.instance(env).addTaskListener(listener);
    Context ctx = ((JavacProcessingEnvironment)processingEnv).getContext();
    JavaCompiler compiler = JavaCompiler.instance(ctx);
    compiler.shouldStopPolicyIfNoError = CompileState.max(compiler.shouldStopPolicyIfNoError,
            CompileState.FLOW);
}
 
Example #24
Source File: T6597678.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    Context context = ((JavacProcessingEnvironment) processingEnv).getContext();
    Log log = Log.instance(context);
    PrintWriter noteOut = log.getWriter(Log.WriterKind.NOTICE);
    PrintWriter warnOut = log.getWriter(Log.WriterKind.WARNING);
    PrintWriter errOut  = log.getWriter(Log.WriterKind.ERROR);
    Locale locale = context.get(Locale.class);
    JavacMessages messages = context.get(JavacMessages.messagesKey);

    round++;
    if (round == 1) {
        initialLocale = locale;
        initialMessages = messages;
        initialNoteWriter = noteOut;
        initialWarnWriter = warnOut;
        initialErrWriter  = errOut;

        String writerStringOpt = options.get("WriterString").intern();
        checkEqual("noteWriterString", noteOut.toString().intern(), writerStringOpt);
        checkEqual("warnWriterString", warnOut.toString().intern(), writerStringOpt);
        checkEqual("errWriterString",  errOut.toString().intern(),  writerStringOpt);
    } else {
        checkEqual("locale", locale, initialLocale);
        checkEqual("messages", messages, initialMessages);
        checkEqual("noteWriter", noteOut, initialNoteWriter);
        checkEqual("warnWriter", warnOut, initialWarnWriter);
        checkEqual("errWriter",  errOut,  initialErrWriter);
    }

    return true;
}
 
Example #25
Source File: PackageProcessor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final void init(ProcessingEnvironment env) {
    super.init(env);
    JavacTask.instance(env).addTaskListener(listener);
    Context ctx = ((JavacProcessingEnvironment)processingEnv).getContext();
    JavaCompiler compiler = JavaCompiler.instance(ctx);
    compiler.shouldStopPolicyIfNoError = CompileState.max(compiler.shouldStopPolicyIfNoError,
            CompileState.FLOW);
}
 
Example #26
Source File: T6597678.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    Context context = ((JavacProcessingEnvironment) processingEnv).getContext();
    Log log = Log.instance(context);
    PrintWriter noteOut = log.getWriter(Log.WriterKind.NOTICE);
    PrintWriter warnOut = log.getWriter(Log.WriterKind.WARNING);
    PrintWriter errOut  = log.getWriter(Log.WriterKind.ERROR);
    Locale locale = context.get(Locale.class);
    JavacMessages messages = context.get(JavacMessages.messagesKey);

    round++;
    if (round == 1) {
        initialLocale = locale;
        initialMessages = messages;
        initialNoteWriter = noteOut;
        initialWarnWriter = warnOut;
        initialErrWriter  = errOut;

        String writerStringOpt = options.get("WriterString").intern();
        checkEqual("noteWriterString", noteOut.toString().intern(), writerStringOpt);
        checkEqual("warnWriterString", warnOut.toString().intern(), writerStringOpt);
        checkEqual("errWriterString",  errOut.toString().intern(),  writerStringOpt);
    } else {
        checkEqual("locale", locale, initialLocale);
        checkEqual("messages", messages, initialMessages);
        checkEqual("noteWriter", noteOut, initialNoteWriter);
        checkEqual("warnWriter", warnOut, initialWarnWriter);
        checkEqual("errWriter",  errOut,  initialErrWriter);
    }

    return true;
}
 
Example #27
Source File: PackageProcessor.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final void init(ProcessingEnvironment env) {
    super.init(env);
    JavacTask.instance(env).addTaskListener(listener);
    Context ctx = ((JavacProcessingEnvironment)processingEnv).getContext();
    JavaCompiler compiler = JavaCompiler.instance(ctx);
    compiler.shouldStopPolicyIfNoError = CompileState.max(compiler.shouldStopPolicyIfNoError,
            CompileState.FLOW);
}
 
Example #28
Source File: TypeProcOnly.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final void init(ProcessingEnvironment env) {
    super.init(env);
    JavacTask.instance(env).addTaskListener(listener);
    Context ctx = ((JavacProcessingEnvironment)processingEnv).getContext();
    JavaCompiler compiler = JavaCompiler.instance(ctx);
    compiler.shouldStopPolicyIfNoError = CompileState.max(
            compiler.shouldStopPolicyIfNoError,
            CompileState.FLOW);
}
 
Example #29
Source File: Processor.java    From EasyMPermission with MIT License 5 votes vote down vote up
private void stopJavacProcessingEnvironmentFromClosingOurClassloader() {
	try {
		Field f = JavacProcessingEnvironment.class.getDeclaredField("processorClassLoader");
		f.setAccessible(true);
		ClassLoader unwrapped = (ClassLoader) f.get(processingEnv);
		if (unwrapped == null) return;
		ClassLoader wrapped = wrapClassLoader(unwrapped);
		f.set(processingEnv, wrapped);
	} catch (NoSuchFieldException e) {
		// Some versions of javac have this (and call close on it), some don't. I guess this one doesn't have it.
	} catch (Throwable t) {
		throw Lombok.sneakyThrow(t);
	}
}
 
Example #30
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();
        }
    }
}