use of javax.annotation.processing.Messager in project lombok by rzwitserloot.
the class LombokProcessor method placePostCompileAndDontMakeForceRoundDummiesHook.
private void placePostCompileAndDontMakeForceRoundDummiesHook() {
stopJavacProcessingEnvironmentFromClosingOurClassloader();
forceMultipleRoundsInNetBeansEditor();
Context context = processingEnv.getContext();
disablePartialReparseInNetBeansEditor(context);
try {
Method keyMethod = Context.class.getDeclaredMethod("key", Class.class);
keyMethod.setAccessible(true);
Object key = keyMethod.invoke(context, JavaFileManager.class);
Field htField = Context.class.getDeclaredField("ht");
htField.setAccessible(true);
@SuppressWarnings("unchecked") Map<Object, Object> ht = (Map<Object, Object>) htField.get(context);
final JavaFileManager originalFiler = (JavaFileManager) ht.get(key);
if (!(originalFiler instanceof InterceptingJavaFileManager)) {
final Messager messager = processingEnv.getMessager();
DiagnosticsReceiver receiver = new MessagerDiagnosticsReceiver(messager);
JavaFileManager newFiler = new InterceptingJavaFileManager(originalFiler, receiver);
ht.put(key, newFiler);
Field filerFileManagerField = JavacFiler.class.getDeclaredField("fileManager");
filerFileManagerField.setAccessible(true);
filerFileManagerField.set(processingEnv.getFiler(), newFiler);
}
} catch (Exception e) {
throw Lombok.sneakyThrow(e);
}
}
use of javax.annotation.processing.Messager in project androidannotations by androidannotations.
the class FileAppender method resolveLogFile.
private void resolveLogFile(AndroidAnnotationsEnvironment environment) {
String logFile = environment.getOptionValue(OPTION_LOG_FILE);
try {
if (logFile != null) {
file = resolveLogFileInSpecifiedPath(logFile);
} else {
file = resolveLogFileInParentsDirectories();
}
} catch (FileNotFoundException exception) {
file = null;
}
Level logLevel = LoggerContext.getInstance().getCurrentLevel();
Messager messager = processingEnv.getMessager();
if (file == null) {
if (Level.WARN.isGreaterOrEquals(logLevel)) {
messager.printMessage(Kind.WARNING, "Can't resolve log file");
}
} else if (Level.INFO.isGreaterOrEquals(logLevel)) {
messager.printMessage(Kind.NOTE, "Resolve log file to " + file.getAbsolutePath());
}
}
use of javax.annotation.processing.Messager in project EventBus by greenrobot.
the class EventBusAnnotationProcessor method process.
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment env) {
Messager messager = processingEnv.getMessager();
try {
String index = processingEnv.getOptions().get(OPTION_EVENT_BUS_INDEX);
if (index == null) {
messager.printMessage(Diagnostic.Kind.ERROR, "No option " + OPTION_EVENT_BUS_INDEX + " passed to annotation processor");
return false;
}
verbose = Boolean.parseBoolean(processingEnv.getOptions().get(OPTION_VERBOSE));
int lastPeriod = index.lastIndexOf('.');
String indexPackage = lastPeriod != -1 ? index.substring(0, lastPeriod) : null;
round++;
if (verbose) {
messager.printMessage(Diagnostic.Kind.NOTE, "Processing round " + round + ", new annotations: " + !annotations.isEmpty() + ", processingOver: " + env.processingOver());
}
if (env.processingOver()) {
if (!annotations.isEmpty()) {
messager.printMessage(Diagnostic.Kind.ERROR, "Unexpected processing state: annotations still available after processing over");
return false;
}
}
if (annotations.isEmpty()) {
return false;
}
if (writerRoundDone) {
messager.printMessage(Diagnostic.Kind.ERROR, "Unexpected processing state: annotations still available after writing.");
}
collectSubscribers(annotations, env, messager);
checkForSubscribersToSkip(messager, indexPackage);
if (!methodsByClass.isEmpty()) {
createInfoIndexFile(index);
} else {
messager.printMessage(Diagnostic.Kind.WARNING, "No @Subscribe annotations found");
}
writerRoundDone = true;
} catch (RuntimeException e) {
// IntelliJ does not handle exceptions nicely, so log and print a message
e.printStackTrace();
messager.printMessage(Diagnostic.Kind.ERROR, "Unexpected error in EventBusAnnotationProcessor: " + e);
}
return true;
}
use of javax.annotation.processing.Messager in project javaslang by javaslang.
the class PatternsProcessor method transform.
// Verify correct usage of annotations @Patterns and @Unapply
private Set<ClassModel> transform(Set<TypeElement> typeElements) {
final Set<ClassModel> classModels = new HashSet<>();
final javax.lang.model.util.Elements elementUtils = processingEnv.getElementUtils();
final Messager messager = processingEnv.getMessager();
for (TypeElement typeElement : typeElements) {
final ClassModel classModel = ClassModel.of(elementUtils, typeElement);
final List<MethodModel> methodModels = classModel.getMethods().stream().filter(method -> method.isAnnotatedWith(Unapply.class)).collect(toList());
if (methodModels.isEmpty()) {
messager.printMessage(Diagnostic.Kind.WARNING, "No @Unapply methods found.", classModel.typeElement());
} else {
final boolean methodsValid = methodModels.stream().reduce(true, (bool, method) -> bool && UnapplyChecker.isValid(method.getExecutableElement(), messager), (b1, b2) -> b1 && b2);
if (methodsValid) {
classModels.add(classModel);
}
}
}
return classModels;
}
use of javax.annotation.processing.Messager in project maven-plugins by apache.
the class MCompiler224AnnotationProcessor method process.
@Override
public boolean process(final Set<? extends TypeElement> elts, final RoundEnvironment env) {
if (elts.isEmpty()) {
return true;
}
final Messager messager = this.processingEnv.getMessager();
for (final Kind kind : Kind.values()) {
if (Kind.ERROR == kind) {
continue;
}
System.out.println("Testing message for: " + kind);
messager.printMessage(kind, kind + " Test message.");
}
return true;
}
Aggregations