Le 13/08/2020 à 12:26, Neil C Smith a écrit :

Yes, I'm using annotation processing. ;-) And across modules. But not sure specifically what you meant by all modules together there? Do you have an example?

If we have 3 modules, using the annotation processor with Maven will cause javac to be executed 3 times, is that right? If we execute javac from the command line instead, we can compile the 3 modules in a single javac invocation. I presume (but did not tested) that it results in the same processor instance, or at least the same JVM instance, processing the annotations of all modules in a single run. For many tasks it makes no practical difference. But for tasks wanting to do some kind of aggregation of information collected from all modules (such as javadoc), this is helpful.

Use case that I'm really considering to do: there is more than 6000 Coordinate Reference Systems (map projections) in use around the world. Those reference systems are identified by codes in a database known as "the EPSG geodetic dataset". We may not want to bundle the EPSG database in end user applications, because that database is relatively big, using it forces application to bundle also an engine such as Derby or HSQL, and is generally an overkill because an application for a specific user will typically uses only a few (less than 5) Coordinate Reference Systems among the 6000. It is a little bit like localization: a software may be provided in 50 languages, but an application for a specific user will typically needs only one of those 50 languages. So I'm considering to define an annotation like that:

   @InjectCRS(code = "EPSG::2138")
   CoordinateReferenceSystem myMapProjection;

("EPSG::2138" is the identifier for "NAD27(CGQ77) / Quebec Lambert"). The annotation processor would fetch required data from an EPSG database (which must exist on the developer machine) and generate all necessary Java code for initializing the myMapProjection field with hard-coded values so that we don't need anymore to bundle the EPSG database with that application.

So far, no need to "process all modules together". But there is a complication: the information that we attach to the myMapProjection field may depend on other occurrences of the @InjectCRS annotation. If there is a @InjectCRS(code = "EPSG::32198") somewhere else in the code ("EPSG::32198" is the identifier for "NAD83 / Quebec Lambert"), then the annotation processor needs to inject additional Java code and data not only for "EPSG::2138" and "EPSG::32198" taken separately, but also for data about how to convert from "NAD27" to "NAD83" and conversely. Those data may be large, so we want them only if needed. Consequently the annotation processor would need to know all occurrences of all @InjectCRS annotations in all modules; the code and data injected at a given @InjectCRS can not be determined in isolation of other @InjectCRS annotations.

Above use case, if I'm understanding correctly, would be difficult to implement in a Maven build, unless Maven provides for annotation processor a workaround similar to what they did for javadoc.

    Martin


Reply via email to