Search in sources :

Example 1 with Messager

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);
    }
}
Also used : Context(com.sun.tools.javac.util.Context) Messager(javax.annotation.processing.Messager) JavaFileManager(javax.tools.JavaFileManager) Method(java.lang.reflect.Method) IOException(java.io.IOException) Field(java.lang.reflect.Field) DiagnosticsReceiver(lombok.core.DiagnosticsReceiver) JavaFileObject(javax.tools.JavaFileObject) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap)

Example 2 with Messager

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());
    }
}
Also used : Messager(javax.annotation.processing.Messager) FileNotFoundException(java.io.FileNotFoundException) Level(org.androidannotations.logger.Level)

Example 3 with Messager

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;
}
Also used : Messager(javax.annotation.processing.Messager)

Example 4 with Messager

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;
}
Also used : AbstractProcessor(javax.annotation.processing.AbstractProcessor) Patterns(javaslang.match.annotation.Patterns) Set(java.util.Set) TypeElement(javax.lang.model.element.TypeElement) IOException(java.io.IOException) Unapply(javaslang.match.annotation.Unapply) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) SourceVersion(javax.lang.model.SourceVersion) MethodModel(javaslang.match.model.MethodModel) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) RoundEnvironment(javax.annotation.processing.RoundEnvironment) Diagnostic(javax.tools.Diagnostic) Filer(javax.annotation.processing.Filer) Writer(java.io.Writer) Collections(java.util.Collections) Generator(javaslang.match.generator.Generator) Messager(javax.annotation.processing.Messager) ClassModel(javaslang.match.model.ClassModel) MethodModel(javaslang.match.model.MethodModel) Messager(javax.annotation.processing.Messager) ClassModel(javaslang.match.model.ClassModel) TypeElement(javax.lang.model.element.TypeElement) HashSet(java.util.HashSet)

Example 5 with Messager

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;
}
Also used : Messager(javax.annotation.processing.Messager) Kind(javax.tools.Diagnostic.Kind)

Aggregations

Messager (javax.annotation.processing.Messager)5 IOException (java.io.IOException)2 Context (com.sun.tools.javac.util.Context)1 FileNotFoundException (java.io.FileNotFoundException)1 Writer (java.io.Writer)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 IdentityHashMap (java.util.IdentityHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 Patterns (javaslang.match.annotation.Patterns)1 Unapply (javaslang.match.annotation.Unapply)1 Generator (javaslang.match.generator.Generator)1 ClassModel (javaslang.match.model.ClassModel)1 MethodModel (javaslang.match.model.MethodModel)1