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 Project: TencentKona-8   Author: Tencent   File: TestContext.java    License: 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 Project: TencentKona-8   Author: Tencent   File: T7018098.java    License: 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 #3
Source Project: jdk8u60   Author: chenghanpeng   File: TestContext.java    License: 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 #4
Source Project: openjdk-8   Author: bpupadhyaya   File: T7018098.java    License: 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 Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: TestContext.java    License: 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 Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: T7018098.java    License: 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 #7
Source Project: NullAway   Author: uber   File: AccessPathNullnessPropagation.java    License: 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 #8
Source Project: NullAway   Author: uber   File: DataFlow.java    License: 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 Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: TestContext.java    License: 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 #10
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: T7018098.java    License: 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 #11
Source Project: openjdk-8   Author: bpupadhyaya   File: TestContext.java    License: 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 #12
Source Project: openjdk-8-source   Author: keerath   File: TestContext.java    License: 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 Project: openjdk-jdk9   Author: AdoptOpenJDK   File: T7018098.java    License: 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 #14
Source Project: vertx-codetrans   Author: vert-x3   File: CodeTranslator.java    License: 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 #15
Source Project: manifold   Author: manifold-systems   File: JavacPlugin.java    License: 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 #16
Source Project: openjdk-8   Author: bpupadhyaya   File: PackageProcessor.java    License: 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 #17
Source Project: java-master   Author: jufeng98   File: GenerateGetMethodProcessor.java    License: 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 #18
Source Project: openjdk-8   Author: bpupadhyaya   File: T7021650.java    License: 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 #19
Source Project: TencentKona-8   Author: Tencent   File: T7021650.java    License: 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 Project: TencentKona-8   Author: Tencent   File: T6597678.java    License: 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 #21
Source Project: TencentKona-8   Author: Tencent   File: PackageProcessor.java    License: 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 #22
Source Project: TencentKona-8   Author: Tencent   File: TypeProcOnly.java    License: 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 Project: openjdk-8-source   Author: keerath   File: T7021650.java    License: 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 #24
Source Project: openjdk-8-source   Author: keerath   File: PackageProcessor.java    License: 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 #25
Source Project: jdk8u60   Author: chenghanpeng   File: T6597678.java    License: 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 #26
Source Project: jdk8u60   Author: chenghanpeng   File: PackageProcessor.java    License: 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 #27
Source Project: jdk8u60   Author: chenghanpeng   File: TypeProcOnly.java    License: 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 Project: hottub   Author: dsrg-uoft   File: T7021650.java    License: 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 #29
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: T6597678.java    License: 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 #30
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: PackageProcessor.java    License: 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);
}