本文整理匯總了Java中com.sun.tools.javac.processing.JavacProcessingEnvironment類的典型用法代碼示例。如果您正苦於以下問題:Java JavacProcessingEnvironment類的具體用法?Java JavacProcessingEnvironment怎麽用?Java JavacProcessingEnvironment使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JavacProcessingEnvironment類屬於com.sun.tools.javac.processing包,在下文中一共展示了JavacProcessingEnvironment類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: dataflow
import com.sun.tools.javac.processing.JavacProcessingEnvironment; //導入依賴的package包/類
/**
* 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;
}
};
}
示例2: checkConstructorInitialization
import com.sun.tools.javac.processing.JavacProcessingEnvironment; //導入依賴的package包/類
/**
* @param entities field init info
* @param state visitor state
* @return a map from each constructor C to the nonnull fields that C does *not* initialize
*/
private SetMultimap<MethodTree, Symbol> checkConstructorInitialization(
FieldInitEntities entities, VisitorState state) {
SetMultimap<MethodTree, Symbol> result = LinkedHashMultimap.create();
Set<Symbol> nonnullInstanceFields = entities.nonnullInstanceFields();
Trees trees = Trees.instance(JavacProcessingEnvironment.instance(state.context));
for (MethodTree constructor : entities.constructors()) {
if (constructorInvokesAnother(constructor, state)) {
continue;
}
Set<Element> guaranteedNonNull =
guaranteedNonNullForConstructor(entities, state, trees, constructor);
for (Symbol fieldSymbol : nonnullInstanceFields) {
if (!guaranteedNonNull.contains(fieldSymbol)) {
result.put(constructor, fieldSymbol);
}
}
}
return result;
}
示例3: process
import com.sun.tools.javac.processing.JavacProcessingEnvironment; //導入依賴的package包/類
@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;
}
示例4: process
import com.sun.tools.javac.processing.JavacProcessingEnvironment; //導入依賴的package包/類
@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;
}
示例5: init
import com.sun.tools.javac.processing.JavacProcessingEnvironment; //導入依賴的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: init
import com.sun.tools.javac.processing.JavacProcessingEnvironment; //導入依賴的package包/類
/** {@inheritDoc} */
@Override public void init(ProcessingEnvironment procEnv) {
super.init(procEnv);
if (System.getProperty("lombok.disable") != null) {
lombokDisabled = true;
return;
}
this.processingEnv = (JavacProcessingEnvironment) procEnv;
placePostCompileAndDontMakeForceRoundDummiesHook();
transformer = new JavacTransformer(procEnv.getMessager());
trees = Trees.instance(procEnv);
SortedSet<Long> p = transformer.getPriorities();
if (p.isEmpty()) {
this.priorityLevels = new long[] {0L};
this.priorityLevelsRequiringResolutionReset = new HashSet<Long>();
} else {
this.priorityLevels = new long[p.size()];
int i = 0;
for (Long prio : p) this.priorityLevels[i++] = prio;
this.priorityLevelsRequiringResolutionReset = transformer.getPrioritiesRequiringResolutionReset();
}
}
示例7: listOptions
import com.sun.tools.javac.processing.JavacProcessingEnvironment; //導入依賴的package包/類
private void listOptions(StringBuilder message, ProcessingEnvironment procEnv) {
try {
JavacProcessingEnvironment environment = (JavacProcessingEnvironment) procEnv;
Options instance = Options.instance(environment.getContext());
Field field = Options.class.getDeclaredField("values");
field.setAccessible(true);
@SuppressWarnings("unchecked") Map<String, String> values = (Map<String, String>) field.get(instance);
if (values.isEmpty()) {
message.append("Options: empty\n\n");
return;
}
message.append("Compiler Options:\n");
for (Map.Entry<String, String> value : values.entrySet()) {
message.append("- ");
string(message, value.getKey());
message.append(" = ");
string(message, value.getValue());
message.append("\n");
}
message.append("\n");
} catch (Exception e) {
message.append("No options available\n\n");
}
}
示例8: process
import com.sun.tools.javac.processing.JavacProcessingEnvironment; //導入依賴的package包/類
@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;
}
示例9: init
import com.sun.tools.javac.processing.JavacProcessingEnvironment; //導入依賴的package包/類
@Override // from AbstractProcessor
public void init (ProcessingEnvironment procenv)
{
super.init(procenv);
if (!(procenv instanceof JavacProcessingEnvironment)) {
procenv.getMessager().printMessage(
Diagnostic.Kind.WARNING, "Immuter requires javac v1.6.");
return;
}
Context ctx = ((JavacProcessingEnvironment)procenv).getContext();
_trees = Trees.instance(procenv);
_procenv = procenv;
// note our options
_handleStar = "true".equalsIgnoreCase(procenv.getOptions().get(HANDLE_STAR));
// procenv.getMessager().printMessage(
// Diagnostic.Kind.NOTE, "Immuter running [src=" + procenv.getSourceVersion() + "]");
}
示例10: init
import com.sun.tools.javac.processing.JavacProcessingEnvironment; //導入依賴的package包/類
@Override // from AbstractProcessor
public void init (ProcessingEnvironment procenv)
{
super.init(procenv);
if (!(procenv instanceof JavacProcessingEnvironment)) {
procenv.getMessager().printMessage(
Diagnostic.Kind.WARNING, "Imferrer requires javac v1.6.");
return;
}
Context ctx = ((JavacProcessingEnvironment)procenv).getContext();
_trees = Trees.instance(procenv);
_imfer = Imfer.instance(ctx);
_procenv = procenv;
// procenv.getMessager().printMessage(
// Diagnostic.Kind.NOTE, "Imferrer running [vers=" + procenv.getSourceVersion() + "]");
}
示例11: init
import com.sun.tools.javac.processing.JavacProcessingEnvironment; //導入依賴的package包/類
public void init(ProcessingEnvironment procEnv) {
javacProcessingEnv = (JavacProcessingEnvironment) procEnv;
maker = TreeMaker.instance(javacProcessingEnv.getContext());
parserFactory = ParserFactory.instance(javacProcessingEnv.getContext());
utils = javacProcessingEnv.getElementUtils();
typeUtils = javacProcessingEnv.getTypeUtils();
trees = JavacTrees.instance(javacProcessingEnv);
types = Types.instance(javacProcessingEnv.getContext());
voidType = maker.Type((Type) typeUtils.getNoType(TypeKind.VOID));
objectClass = utils.getTypeElement("java.lang.Object");
debugMode = Boolean.parseBoolean(getOption(DEBUG_MODE_OPTION_NAME));
// reflection
try {
newParserMethod = ParserFactory.class.getMethod("newParser", CharSequence.class, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE);
} catch (NoSuchMethodException ignored) {
}
}
示例12: loadPlugins
import com.sun.tools.javac.processing.JavacProcessingEnvironment; //導入依賴的package包/類
public static ScannerSupplier loadPlugins(ScannerSupplier scannerSupplier, Context context) {
JavaFileManager fileManager = context.get(JavaFileManager.class);
// Unlike in annotation processor discovery, we never search CLASS_PATH if
// ANNOTATION_PROCESSOR_PATH is unavailable.
if (!fileManager.hasLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH)) {
return scannerSupplier;
}
// Use the same classloader that Error Prone was loaded from to avoid classloader skew
// when using Error Prone plugins together with the Error Prone javac plugin.
JavacProcessingEnvironment processingEnvironment = JavacProcessingEnvironment.instance(context);
ClassLoader loader = processingEnvironment.getProcessorClassLoader();
Iterable<BugChecker> extraBugCheckers = ServiceLoader.load(BugChecker.class, loader);
if (Iterables.isEmpty(extraBugCheckers)) {
return scannerSupplier;
}
return scannerSupplier.plus(
ScannerSupplier.fromBugCheckerClasses(
Iterables.transform(extraBugCheckers, BugChecker::getClass)));
}
示例13: process
import com.sun.tools.javac.processing.JavacProcessingEnvironment; //導入依賴的package包/類
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
Context context = ((JavacProcessingEnvironment) processingEnv).getContext();
Locale locale = context.get(Locale.class);
JavacMessages messages = context.get(JavacMessages.messagesKey);
round++;
if (round == 1) {
initialLocale = locale;
initialMessages = messages;
} else {
checkEqual("locale", locale, initialLocale);
checkEqual("messages", messages, initialMessages);
}
return true;
}
示例14: typeProcess
import com.sun.tools.javac.processing.JavacProcessingEnvironment; //導入依賴的package包/類
@Override
public final void typeProcess(TypeElement element, TreePath tree) {
Context context = ((JavacProcessingEnvironment)processingEnv).getContext();
Log log = Log.instance(context);
if (log.nerrors > this.errsOnLastExit) {
// If there is a Java error, do not perform any
// of the component type checks, but come back
// for the next compilation unit.
this.errsOnLastExit = log.nerrors;
return;
}
if (!allCheckersInited) {
// If there was an initialization problem, an
// error was already output. Just quit.
return;
}
for (SourceChecker checker : checkers) {
checker.errsOnLastExit = this.errsOnLastExit;
checker.typeProcess(element, tree);
this.errsOnLastExit = checker.errsOnLastExit;
}
}
示例15: main
import com.sun.tools.javac.processing.JavacProcessingEnvironment; //導入依賴的package包/類
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("Usage:");
System.out.println(" java IndexGenerator [class or package name]");
return;
}
Context context = new Context();
ProcessingEnvironment env = JavacProcessingEnvironment.instance(context);
StubGenerator generator = new StubGenerator();
if (env.getElementUtils().getPackageElement(args[0]) != null)
generator.skeletonFromPackage(env.getElementUtils().getPackageElement(args[0]));
else if (env.getElementUtils().getTypeElement(args[0]) != null)
generator.skeletonFromType(env.getElementUtils().getTypeElement(args[0]));
else
System.err.println("Couldn't find a package or a class named " + args[0]);
}