use of com.sun.tools.javac.processing.JavacProcessingEnvironment in project lombok by rzwitserloot.
the class Processor method listOptions.
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");
}
}
use of com.sun.tools.javac.processing.JavacProcessingEnvironment in project bazel by bazelbuild.
the class InternalUtils method leastUpperBound.
/**
* Returns the least upper bound of two {@link TypeMirror}s.
*
* @param processingEnv The {@link ProcessingEnvironment} to use.
* @param tm1 A {@link TypeMirror}.
* @param tm2 A {@link TypeMirror}.
* @return The least upper bound of {@code tm1} and {@code tm2}.
*/
public static TypeMirror leastUpperBound(ProcessingEnvironment processingEnv, TypeMirror tm1, TypeMirror tm2) {
Type t1 = (Type) tm1;
Type t2 = (Type) tm2;
JavacProcessingEnvironment javacEnv = (JavacProcessingEnvironment) processingEnv;
Types types = Types.instance(javacEnv.getContext());
if (types.isSameType(t1, t2)) {
// Special case if the two types are equal.
return t1;
}
// Handle the 'null' type manually (not done by types.lub).
if (t1.getKind() == TypeKind.NULL) {
return t2;
}
if (t2.getKind() == TypeKind.NULL) {
return t1;
}
// Special case for primitives.
if (TypesUtils.isPrimitive(t1) || TypesUtils.isPrimitive(t2)) {
if (types.isAssignable(t1, t2)) {
return t2;
} else if (types.isAssignable(t2, t1)) {
return t1;
} else {
return processingEnv.getTypeUtils().getNoType(TypeKind.NONE);
}
}
if (t1.getKind() == TypeKind.WILDCARD) {
WildcardType wc1 = (WildcardType) t1;
Type bound = (Type) wc1.getExtendsBound();
if (bound == null) {
// Implicit upper bound of java.lang.Object
Elements elements = processingEnv.getElementUtils();
return elements.getTypeElement("java.lang.Object").asType();
}
t1 = bound;
}
if (t2.getKind() == TypeKind.WILDCARD) {
WildcardType wc2 = (WildcardType) t2;
Type bound = (Type) wc2.getExtendsBound();
if (bound == null) {
// Implicit upper bound of java.lang.Object
Elements elements = processingEnv.getElementUtils();
return elements.getTypeElement("java.lang.Object").asType();
}
t2 = bound;
}
return types.lub(t1, t2);
}
use of com.sun.tools.javac.processing.JavacProcessingEnvironment in project bazel by bazelbuild.
the class AbstractTypeProcessor method init.
/**
* {@inheritDoc}
*
* Register a TaskListener that will get called after FLOW.
*/
@Override
public 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);
}
use of com.sun.tools.javac.processing.JavacProcessingEnvironment in project error-prone by google.
the class FieldMissingNullable method findDeclaration.
@Nullable
private VariableTree findDeclaration(VisitorState state, Symbol field) {
JavacProcessingEnvironment javacEnv = JavacProcessingEnvironment.instance(state.context);
TreePath fieldDeclPath = Trees.instance(javacEnv).getPath(field);
// Skip fields declared in other compilation units since we can't make a fix for them here.
if (fieldDeclPath != null && fieldDeclPath.getCompilationUnit() == state.getPath().getCompilationUnit() && (fieldDeclPath.getLeaf() instanceof VariableTree)) {
return (VariableTree) fieldDeclPath.getLeaf();
}
return null;
}
use of com.sun.tools.javac.processing.JavacProcessingEnvironment in project error-prone by google.
the class ParameterNotNullable method findDeclaration.
@Nullable
private VariableTree findDeclaration(VisitorState state, Symbol parameter) {
JavacProcessingEnvironment javacEnv = JavacProcessingEnvironment.instance(state.context);
TreePath declPath = Trees.instance(javacEnv).getPath(parameter);
if (declPath != null && declPath.getCompilationUnit() == state.getPath().getCompilationUnit() && (declPath.getLeaf() instanceof VariableTree)) {
return (VariableTree) declPath.getLeaf();
}
return null;
}
Aggregations