luontola / jumi-actors

Actor library for Java to support concurrency and asynchronous event-driven programming.
http://jumi.fi/actors.html
Apache License 2.0
79 stars 14 forks source link

Primitive types in Actor interfaces not supported by APT proxy compiler #4

Open mttkay opened 9 years ago

mttkay commented 9 years ago

I was declaring an Actor interface like so:

interface MyActor {
    void action(int count);
}

This fails the annotation processor with the message:

Error:(7, 8) error: Failed to generate eventizers for com.github.mttkay.actors.EventLog
java.lang.IllegalArgumentException: unsupported kind INT
at fi.jumi.actors.generator.codegen.JavaType.of(JavaType.java:26)
at fi.jumi.actors.generator.codegen.JavaVar$AstJavaVar.getType(JavaVar.java:61)
at fi.jumi.actors.generator.codegen.JavaVar.toFormalArguments(JavaVar.java:29)
at fi.jumi.actors.generator.EventStubGenerator.getFrontend(EventStubGenerator.java:101)
at fi.jumi.actors.generator.EventStubGenerator.getGeneratedClasses(EventStubGenerator.java:56)
at fi.jumi.actors.generator.AnnotationProcessor.generateEventizers(AnnotationProcessor.java:75)
at fi.jumi.actors.generator.AnnotationProcessor.process(AnnotationProcessor.java:30)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
...

Is there any reason why primitive types are not supported?

It works when changing the formal parameter type to Integer.

mttkay commented 9 years ago

I think the JavaType helper is missing a case for PrimitiveType. What's the reason for using so much custom code around dealing with types? The Types class and related in the JDK should cover all you need? You can obtain a Types instance from the processing environment which you can use to enumerate types, no need to re-implement all this?

luontola commented 9 years ago

Thanks for telling about javax.lang.model.util.Types, it simplifies things considerably. :) This is my first experiment of using APT and I couldn't find much learning material online (all the articles I found were far too basic), so a code review from someone with more experience is welcome. I figured there should be a simpler way for handling types, because that custom code would have gotten a roadblock sooner or later.

I'll look into this bug probably this Friday. Maybe switching to use Types will solve it as a side effect.

mttkay commented 9 years ago

:+1: Yeah the docs are definitely scarce around APT. I always found it useful to look at projects like Dagger or auto to see how they do it, especially around unit testing (they use Google Compile Testing which works pretty well)