下面列出了javax.annotation.processing.AbstractProcessor#javax.annotation.processing.ProcessingEnvironment 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/** {@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();
}
}
/**
* Private constructor, get instances using {@link #getMixinsForEnvironment}
*/
private AnnotatedMixins(ProcessingEnvironment processingEnv) {
this.env = this.detectEnvironment(processingEnv);
this.processingEnv = processingEnv;
MessageRouter.setMessager(processingEnv.getMessager());
String pluginVersion = this.checkPluginVersion(this.getOption(SupportedOptions.PLUGIN_VERSION));
String pluginVersionString = pluginVersion != null ? String.format(" (MixinGradle Version=%s)", pluginVersion) : "";
this.printMessage(Kind.NOTE, "SpongePowered MIXIN Annotation Processor Version=" + MixinBootstrap.VERSION + pluginVersionString);
this.targets = this.initTargetMap();
this.obf = new ObfuscationManager(this);
this.obf.init();
this.validators = ImmutableList.<IMixinValidator>of(
new ParentValidator(this),
new TargetValidator(this)
);
this.initTokenCache(this.getOption(SupportedOptions.TOKENS));
}
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
Types = processingEnv.getTypeUtils();
Elts = processingEnv.getElementUtils();
Messager = processingEnv.getMessager();
JdkSpecificApi = jdkSpecificApi(processingEnv);
__Elt = Elts.getTypeElement(__.class.getCanonicalName());
GenCode = new GenCode(Elts, Types, processingEnv.getFiler(), __Elt);
HktConfigElt = Elts.getTypeElement(HktConfig.class.getName());
witnessTypeNameConfMethod = unsafeGetExecutableElement(HktConfigElt, "witnessTypeName");
generateInConfMethod = unsafeGetExecutableElement(HktConfigElt, "generateIn");
withVisibilityConfMethod = unsafeGetExecutableElement(HktConfigElt, "withVisibility");
coerceMethodNameConfMethod = unsafeGetExecutableElement(HktConfigElt, "coerceMethodName");
typeEqMethodNameConfMethod = unsafeGetExecutableElement(HktConfigElt, "typeEqMethodName");
}
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
mFiler = processingEnv.getFiler();
mElements = processingEnv.getElementUtils();
mLog = new Logger(processingEnv.getMessager());
mContext = TypeName.get(mElements.getTypeElement(Constants.CONTEXT_TYPE).asType());
mCollectionUtils = TypeName.get(mElements.getTypeElement(Constants.COLLECTION_UTIL_TYPE).asType());
mOnRegisterType = TypeName.get(mElements.getTypeElement(Constants.ON_REGISTER_TYPE).asType());
mRegisterType = TypeName.get(mElements.getTypeElement(Constants.REGISTER_TYPE).asType());
mConfig = TypeName.get(mElements.getTypeElement(Constants.CONFIG_TYPE).asType());
mDelegate = TypeName.get(mElements.getTypeElement(Constants.CONFIG_DELEGATE_TYPE).asType());
mWebsite = TypeName.get(mElements.getTypeElement(Constants.WEBSITE_TYPE).asType());
mMultipart = TypeName.get(mElements.getTypeElement(Constants.CONFIG_MULTIPART_TYPE).asType());
mString = TypeName.get(String.class);
}
private ElementValidator validateCollectionType(ProcessingEnvironment processingEnvironment) {
Types types = processingEnvironment.getTypeUtils();
TypeElement collectionElement = (TypeElement) types.asElement(typeMirror());
if (collectionElement != null) {
ElementValidator validator = new ElementValidator(collectionElement, processingEnvironment);
if (Mirrors.isInstance(types, collectionElement, List.class)) {
builderClass = ListAttributeBuilder.class;
} else if (Mirrors.isInstance(types, collectionElement, Set.class)) {
builderClass = SetAttributeBuilder.class;
} else if (Mirrors.isInstance(types, collectionElement, Iterable.class)) {
builderClass = ResultAttributeBuilder.class;
} else {
validator.error("Invalid collection type, must be Set, List or Iterable");
}
return validator;
}
return null;
}
private static void logError(
ProcessingEnvironment processingEnv,
RoundEnvironment roundEnv,
Class<?> processorClass,
int round) {
processingEnv
.getMessager()
.printMessage(
Diagnostic.Kind.ERROR,
String.format(
"%d: %s {errorRaised=%s, processingOver=%s}",
round,
processorClass.getSimpleName(),
roundEnv.errorRaised(),
roundEnv.processingOver()));
}
@Override
public void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
this.processingEnv = processingEnv;
errorListener = new ErrorReceiverImpl(
processingEnv.getMessager(),
processingEnv.getOptions().containsKey(Const.DEBUG_OPTION.getValue())
);
}
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
mMessager = processingEnv.getMessager();
elementUtils = processingEnv.getElementUtils();
filer = processingEnv.getFiler();
}
ProcessorState(Processor p, Log log, Source source, boolean allowModules, ProcessingEnvironment env) {
processor = p;
contributed = false;
try {
processor.init(env);
checkSourceVersionCompatibility(source, log);
supportedAnnotationPatterns = new ArrayList<>();
for (String importString : processor.getSupportedAnnotationTypes()) {
supportedAnnotationPatterns.add(importStringToPattern(allowModules,
importString,
processor,
log));
}
supportedOptionNames = new ArrayList<>();
for (String optionName : processor.getSupportedOptions() ) {
if (checkOptionName(optionName, log))
supportedOptionNames.add(optionName);
}
} catch (ClientCodeException e) {
throw e;
} catch (Throwable t) {
throw new AnnotationProcessingError(t);
}
}
@Override
public void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
this.processingEnv = processingEnv;
errorListener = new ErrorReceiverImpl(
processingEnv.getMessager(),
processingEnv.getOptions().containsKey(Const.DEBUG_OPTION.getValue())
);
}
/**
* Returns a string representation of the given annotation value, suitable for inclusion in a Java
* source file as the initializer of a variable of the appropriate type.
*/
String sourceFormForInitializer(
AnnotationValue annotationValue,
ProcessingEnvironment processingEnv,
String memberName,
Element context) {
SourceFormVisitor visitor =
new InitializerSourceFormVisitor(processingEnv, memberName, context);
StringBuilder sb = new StringBuilder();
visitor.visit(annotationValue, sb);
return sb.toString();
}
/**
* Initializes the processor by loading the device configuration.
*
* {@inheritDoc}
*/
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
try {
String deviceOption = processingEnv.getOptions().get(DEVICE_OPTION);
device = (Device) JAXBContext.newInstance(Device.class)
.createUnmarshaller().unmarshal(new File(deviceOption));
} catch (JAXBException e) {
throw new RuntimeException(
"Please specify device by -Adevice=device.xml\n"
+ e.toString(), e);
}
}
Property(
String name,
String identifier,
ExecutableElement method,
String type,
TypeSimplifier typeSimplifier,
ProcessingEnvironment processingEnv
) {
this.name = name;
this.identifier = identifier;
this.method = method;
this.type = type;
this.typeSimplifier = typeSimplifier;
this.processingEnv = processingEnv;
this.annotations = buildAnnotations(typeSimplifier);
this.args = formalTypeArgsString(method);
this.path = buildPath(method);
this.typeArgs = buildTypeArguments(type);
this.queries = buildQueries(method);
this.queryMaps = buildQueryMaps(method);
this.queryBundles = buildQueryBundles(method);
this.isGet = buildIsGet(method);
this.isPost = buildIsPost(method);
this.isDelete = buildIsDelete(method);
this.body = buildBody(method);
this.callbackType = buildCallbackType(method);
this.callbackArg = buildCallbackArg(method);
if ("".equals(typeArgs)) typeArgs = callbackType;
this.permissions = buildPermissions(method);
}
public TypeUse.TypeInternal forParam(ProcessingEnvironment env, ExecutableElement methodElt, int paramIndex) {
Method methodRef = getMethod(env, methodElt);
if (methodRef == null) {
return null;
}
AnnotatedType annotated = methodRef.getAnnotatedParameterTypes()[paramIndex];
return new ReflectType(annotated);
}
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
annotatedEntityMap = new HashMap<>();
annotatedEntityNameMap = new HashMap<>();
annotatedComponentList = new ArrayList<>();
messager = processingEnv.getMessager();
}
@Override
public void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
this.processingEnv = processingEnv;
errorListener = new ErrorReceiverImpl(
processingEnv.getMessager(),
processingEnv.getOptions().containsKey(Const.DEBUG_OPTION.getValue())
);
}
@Override
public synchronized void init(ProcessingEnvironment processingEnvironment) {
super.init(processingEnvironment);
elements = processingEnvironment.getElementUtils();
types = processingEnvironment.getTypeUtils();
getterFactory = new GetterFactory(types, elements, processingEnvironment.getMessager());
}
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
mFiler = processingEnv.getFiler();
mElements = processingEnv.getElementUtils();
mLog = new Logger(processingEnv.getMessager());
mContext = TypeName.get(mElements.getTypeElement(Constants.CONTEXT_TYPE).asType());
mOnRegisterType = TypeName.get(mElements.getTypeElement(Constants.ON_REGISTER_TYPE).asType());
mRegisterType = TypeName.get(mElements.getTypeElement(Constants.REGISTER_TYPE).asType());
mConverter = TypeName.get(mElements.getTypeElement(Constants.CONVERTER_TYPE).asType());
mString = TypeName.get(String.class);
}
@Override
public synchronized void init(ProcessingEnvironment processingEnvironment) {
super.init(processingEnvironment);
filer = processingEnv.getFiler();
messager = processingEnv.getMessager();
elementUtils = processingEnv.getElementUtils();
typeUtils = processingEnv.getTypeUtils();
}
@Override
public synchronized void init(ProcessingEnvironment env) {
super.init(env);
filer = env.getFiler();
elementUtils = env.getElementUtils();
typeUtils = env.getTypeUtils();
messager = env.getMessager();
}
@Override
public void generate(AbstractModel<T> model, ProcessingEnvironment processingEnv) {
logger = Logger.getInstance(processingEnv.getMessager());
processingEnvironment = processingEnv;
//realModel is initialized by AbstractModel
realModel = model.getRealModel();
if (realModel == null) {
logger.log(Diagnostic.Kind.NOTE, "readModel is null,aborted");
return;
}
//load template
logger.log(Diagnostic.Kind.NOTE, "load template file...");
String template = loadTemplate();
if ("".equals(template)) {
return;
}
//logger.log(Diagnostic.Kind.NOTE, "template file:" + template);
//create file
logger.log(Diagnostic.Kind.NOTE, "create source file...");
JavaFileObject jfo = createFile();
if (jfo == null) {
logger.log(Diagnostic.Kind.NOTE, "create java file failed,aborted");
return;
}
//write file
logger.log(Diagnostic.Kind.NOTE, "write source file...");
try {
writeFile(template, jfo.openWriter());
String sourceFileName = getModelClassName();
logger.log(Diagnostic.Kind.NOTE, "generate source file successful:" + sourceFileName);
} catch (IOException e) {
logger.log(Diagnostic.Kind.ERROR, "create file failed");
e.printStackTrace();
}
}
/**
* {@inheritDoc}
*/
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
typeUtils = processingEnv.getTypeUtils();
elementUtils = processingEnv.getElementUtils();
filer = processingEnv.getFiler();
messager = processingEnv.getMessager();
}
public void detectLibraryFeatures(ProcessingEnvironment env, Names names) {
Collection<FeatureNode> featureNodes = new ArrayList<>(getFeatureNodes());
for (FeatureNode featureNode : featureNodes) {
TypeMirror superType = featureNode.getElement().getSuperclass();
if (superType.getKind() == TypeKind.NONE) {
continue;
}
FeatureNode superNode = findFetureNode(superType, env.getTypeUtils());
if (superNode != null) {
// node already exists
continue;
}
TypeMirror featureType = env.getElementUtils().getTypeElement(
names.getFeatureClassName().toString()).asType();
if (env.getTypeUtils().isSameType(superType, featureType)) {
continue;
}
if (env.getTypeUtils().isSubtype(superType, featureType)) {
// create library node
TypeElement superTypeElement = (TypeElement)
env.getTypeUtils().asElement(superType);
String name = superTypeElement.getQualifiedName().toString();
FeatureNode node = new FeatureNode(name, superTypeElement, true);
putFeatureNode(node);
}
}
}
static void checkExtendsActivityPage(ProcessingEnvironment environment, TypeElement element, TypeElement valueElement) {
boolean isSuper = isSuperClass(environment, valueElement.getQualifiedName().toString(), "bamboo.component.page.ActivityPage");
if (!isSuper) {
StringBuilder sb = new StringBuilder("@Exported error : ");
sb.append("at ");
sb.append(element.getQualifiedName());
sb.append(" @Exported's value ");
sb.append(valueElement.getQualifiedName());
sb.append(" must be extends from bamboo.component.page.ActivityPage;");
throw new IllegalStateException(sb.toString());
}
}
@Override
public synchronized void init(ProcessingEnvironment processingEnvironment) {
super.init(processingEnvironment);
mFiler = processingEnv.getFiler(); // Generate class.
types = processingEnv.getTypeUtils(); // Get type utils.
elements = processingEnv.getElementUtils(); // Get class meta.
typeUtils = new TypeUtils(types, elements);
logger = new Logger(processingEnv.getMessager()); // Package the log utils.
logger.info(">>> AutowiredProcessor init. <<<");
}
private Method getMethod(ProcessingEnvironment env, ExecutableElement methodElt) {
Method methodRef = Helper.getReflectMethod(Thread.currentThread().getContextClassLoader(), methodElt);
if (methodRef == null) {
methodRef = Helper.getReflectMethod(env, methodElt);
}
return methodRef;
}
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
mFiler = processingEnv.getFiler();
mMessager = processingEnv.getMessager();
mElements = processingEnv.getElementUtils();
mTypes = processingEnv.getTypeUtils();
}
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
filer = processingEnv.getFiler();
messager = processingEnv.getMessager();
elementUtils = processingEnv.getElementUtils();
typeUtils = processingEnv.getTypeUtils();
}
@Override
public synchronized void init(ProcessingEnvironment env) {
super.init(env);
Elements elementUtils = env.getElementUtils();
typeUtils = env.getTypeUtils();
filer = env.getFiler();
TYPE_FRAGMENT = elementUtils.getTypeElement("android.app.Fragment");
TYPE_SUPPORT_FRAGMENT =
elementUtils.getTypeElement("android.support.v4.app.Fragment");
TYPE_ANDROIDX_FRAGMENT =
elementUtils.getTypeElement("androidx.fragment.app.Fragment");
}
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
mFiler = processingEnv.getFiler();
mElements = processingEnv.getElementUtils();
mMessager = processingEnv.getMessager();
mTypes = processingEnv.getTypeUtils();
}