use of javax.annotation.processing.ProcessingEnvironment in project checker-framework by typetools.
the class SourceChecker method unwrapIntelliJ.
/**
* Tries to unwrap ProcessingEnvironment from proxy in IntelliJ 2020.3 or later.
*
* @param env possibly a dynamic proxy wrapping processing environment
* @return unwrapped processing environment, null if not successful
*/
@Nullable
private static ProcessingEnvironment unwrapIntelliJ(ProcessingEnvironment env) {
if (!Proxy.isProxyClass(env.getClass())) {
return null;
}
InvocationHandler handler = Proxy.getInvocationHandler(env);
try {
Field field = handler.getClass().getDeclaredField("val$delegateTo");
field.setAccessible(true);
Object o = field.get(handler);
if (o instanceof ProcessingEnvironment) {
return (ProcessingEnvironment) o;
}
return null;
} catch (NoSuchFieldException | IllegalAccessException e) {
return null;
}
}
use of javax.annotation.processing.ProcessingEnvironment in project checker-framework by typetools.
the class CFAbstractValue method upperBound.
private V upperBound(@Nullable V other, boolean shouldWiden) {
if (other == null) {
@SuppressWarnings("unchecked") V v = (V) this;
return v;
}
ProcessingEnvironment processingEnv = analysis.getTypeFactory().getProcessingEnv();
TypeMirror lubTypeMirror = TypesUtils.leastUpperBound(this.getUnderlyingType(), other.getUnderlyingType(), processingEnv);
ValueLub valueLub = new ValueLub(shouldWiden);
Set<AnnotationMirror> lub = valueLub.combineSets(this.getUnderlyingType(), this.getAnnotations(), other.getUnderlyingType(), other.getAnnotations(), canBeMissingAnnotations(lubTypeMirror));
return analysis.createAbstractValue(lub, lubTypeMirror);
}
use of javax.annotation.processing.ProcessingEnvironment in project checker-framework by typetools.
the class CFAbstractValue method greatestLowerBound.
/**
* Compute the greatest lower bound of two values.
*
* <p><em>Important</em>: This method must fulfill the following contract:
*
* <ul>
* <li>Does not change {@code this}.
* <li>Does not change {@code other}.
* <li>Returns a fresh object which is not aliased yet.
* <li>Returns an object of the same (dynamic) type as {@code this}, even if the signature is
* more permissive.
* <li>Is commutative.
* </ul>
*
* @param other another value
* @return the greatest lower bound of two values
*/
public V greatestLowerBound(@Nullable V other) {
if (other == null) {
@SuppressWarnings("unchecked") V v = (V) this;
return v;
}
ProcessingEnvironment processingEnv = analysis.getTypeFactory().getProcessingEnv();
TypeMirror glbTypeMirror = TypesUtils.greatestLowerBound(this.getUnderlyingType(), other.getUnderlyingType(), processingEnv);
ValueGlb valueGlb = new ValueGlb();
Set<AnnotationMirror> glb = valueGlb.combineSets(this.getUnderlyingType(), this.getAnnotations(), other.getUnderlyingType(), other.getAnnotations(), canBeMissingAnnotations(glbTypeMirror));
return analysis.createAbstractValue(glb, glbTypeMirror);
}
use of javax.annotation.processing.ProcessingEnvironment in project checker-framework by typetools.
the class SourceChecker method unwrapGradle.
/**
* Tries to unwrap processing environment in Gradle incremental processing. Inspired by project
* Lombok.
*
* @param delegateClass a class in which to find a {@code delegate} field
* @param env a processing environment wrapper
* @return unwrapped processing environment, null if not successful
*/
@Nullable
private static ProcessingEnvironment unwrapGradle(Class<?> delegateClass, ProcessingEnvironment env) {
try {
Field field = delegateClass.getDeclaredField("delegate");
field.setAccessible(true);
Object o = field.get(env);
if (o instanceof ProcessingEnvironment) {
return (ProcessingEnvironment) o;
}
return null;
} catch (NoSuchFieldException | IllegalAccessException e) {
return null;
}
}
use of javax.annotation.processing.ProcessingEnvironment in project butterknife by JakeWharton.
the class ButterKnifeProcessor method init.
@Override
public synchronized void init(ProcessingEnvironment env) {
super.init(env);
String sdk = env.getOptions().get(OPTION_SDK_INT);
if (sdk != null) {
try {
this.sdk = Integer.parseInt(sdk);
} catch (NumberFormatException e) {
env.getMessager().printMessage(Kind.WARNING, "Unable to parse supplied minSdk option '" + sdk + "'. Falling back to API 1 support.");
}
}
debuggable = !"false".equals(env.getOptions().get(OPTION_DEBUGGABLE));
typeUtils = env.getTypeUtils();
filer = env.getFiler();
try {
trees = Trees.instance(processingEnv);
} catch (IllegalArgumentException ignored) {
try {
// Get original ProcessingEnvironment from Gradle-wrapped one or KAPT-wrapped one.
for (Field field : processingEnv.getClass().getDeclaredFields()) {
if (field.getName().equals("delegate") || field.getName().equals("processingEnv")) {
field.setAccessible(true);
ProcessingEnvironment javacEnv = (ProcessingEnvironment) field.get(processingEnv);
trees = Trees.instance(javacEnv);
break;
}
}
} catch (Throwable ignored2) {
}
}
}
Aggregations