Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class Processor extends AbstractProcessor implements Constants {
private ProcessingContext processingContext;
private DtoMappingReader dtoMappingReader;
private boolean wroteDtoMappers;
private SimpleModuleInfoWriter moduleWriter;
private boolean initModuleWriter;

private boolean wroteLookup;

Expand Down Expand Up @@ -59,6 +61,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
final int loaded = processingContext.complete();
dtoMappingReader.collect(roundEnv);
if (!roundEnv.processingOver()) {
initModuleInfoBean();
writeDtoMappers();
}
if (roundEnv.processingOver()) {
Expand Down Expand Up @@ -109,24 +112,33 @@ private void processOthers(RoundEnvironment roundEnv, TypeElement otherType) {
}
}

private void initModuleInfoBean() {
if (initModuleWriter || !processingContext.hasAnyEntitiesOrOther()) {
return;
}
try {
moduleWriter = new SimpleModuleInfoWriter(processingContext);
} catch (FilerException e) {
processingContext.logWarn(null, "FilerException trying to write EntityClassRegister error: " + e);
} catch (Throwable e) {
processingContext.logError(null, "Failed to initialise EntityClassRegister error:" + e + " stack:" + Arrays.toString(e.getStackTrace()));
} finally {
initModuleWriter = true;
}
}

/**
* Write the {@code EbeanEntityRegister} at the end of processing - deferred until there is
* something to actually register (rather than eagerly reserving/creating the source file up
* front), since a compilation unit with no {@code @Entity}/{@code @Embeddable}/{@code @Converter}
* /other classes at all - e.g. a test-source-only module that only declares
* {@code @DtoMapping} - has nothing meaningful to write and no factory package to derive a
* sensible location from.
* Write the {@code EbeanEntityRegister} at the end of processing. The source file is reserved
* during an earlier round by {@link #initModuleInfoBean()} so javac does not warn that it was
* created in the final round.
*/
private void writeModuleInfoBean() {
if (!processingContext.hasAnyEntitiesOrOther()) {
if (moduleWriter == null) {
processingContext.logNote("EbeanEntityRegister skipped - no entities or other classes found");
return;
}
try {
SimpleModuleInfoWriter moduleWriter = new SimpleModuleInfoWriter(processingContext);
moduleWriter.write();
} catch (FilerException e) {
processingContext.logWarn(null, "FilerException trying to write EntityClassRegister error: " + e);
} catch (Throwable e) {
processingContext.logError(null, "Failed to write EntityClassRegister error:" + e + " stack:" + Arrays.toString(e.getStackTrace()));
}
Expand Down
Loading