Skip to content

Commit

Permalink
Add the doma.trace option (#1246)
Browse files Browse the repository at this point in the history
  • Loading branch information
nakamura-to authored Dec 28, 2024
2 parents 61a0a4c + d4d44ab commit 71da5df
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,7 @@ public enum Message implements MessageResource {
"If a method annotated with @MultiInsert targets immutable entities for insertion, the return type must be org.seasar.doma.jdbc.MultiResult."
+ "The type argument of org.seasar.doma.jdbc.MultiResult must be the immutable entity class."),
DOMA4462("The property \"{0}\" is not found in the entity class \"{1}\"."),
DOMA4463("'{'\"execTimeMillis\": {0}, \"processor\": \"{1}\", \"element\": \"{2}\"'}'"),

// other
DOMA5001(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public final class Options {

public static final String DEBUG = "doma.debug";

public static final String TRACE = "doma.trace";

public static final String DAO_PACKAGE = "doma.dao.package";

public static final String DAO_SUBPACKAGE = "doma.dao.subpackage";
Expand Down Expand Up @@ -122,6 +124,11 @@ public Date getDate() {
return new Date();
}

public boolean isTraceEnabled() {
String trace = getOption(TRACE);
return Boolean.parseBoolean(trace);
}

public boolean isDebugEnabled() {
String debug = getOption(DEBUG);
return Boolean.parseBoolean(debug);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.StringWriter;
import java.io.Writer;
import java.lang.annotation.Annotation;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Supplier;
import javax.annotation.processing.ProcessingEnvironment;
Expand Down Expand Up @@ -63,7 +64,18 @@ private <E extends Element> void handleElement(
.debug(Message.DOMA4090, new Object[] {getClass().getName(), elementNameSupplier.get()});
}
try {
handler.accept(element);
if (ctx.getOptions().isTraceEnabled()) {
long startTime = System.nanoTime();
handler.accept(element);
long endTime = System.nanoTime();
long execTimeMillis = TimeUnit.NANOSECONDS.toMillis(endTime - startTime);
ctx.getReporter()
.debug(
Message.DOMA4463,
new Object[] {execTimeMillis, getClass().getName(), elementNameSupplier.get()});
} else {
handler.accept(element);
}
} catch (AptException e) {
ctx.getReporter().report(e);
} catch (AptIllegalOptionException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
@SupportedAnnotationTypes({"org.seasar.doma.Dao"})
@SupportedOptions({
Options.TEST,
Options.TRACE,
Options.DEBUG,
Options.DAO_PACKAGE,
Options.DAO_SUBPACKAGE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Options.VERSION_VALIDATION,
Options.RESOURCES_DIR,
Options.TEST,
Options.TRACE,
Options.DEBUG,
Options.CONFIG_PATH
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@
* @since 1.25.0
*/
@SupportedAnnotationTypes({"org.seasar.doma.DomainConverters"})
@SupportedOptions({Options.RESOURCES_DIR, Options.TEST, Options.DEBUG, Options.CONFIG_PATH})
@SupportedOptions({
Options.RESOURCES_DIR,
Options.TEST,
Options.TRACE,
Options.DEBUG,
Options.CONFIG_PATH
})
public class DomainConvertersProcessor extends AbstractProcessor {

public DomainConvertersProcessor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Options.RESOURCES_DIR,
Options.LOMBOK_VALUE,
Options.TEST,
Options.TRACE,
Options.DEBUG,
Options.CONFIG_PATH
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
Options.LOMBOK_VALUE,
Options.LOMBOK_ALL_ARGS_CONSTRUCTOR,
Options.TEST,
Options.TRACE,
Options.DEBUG,
Options.CONFIG_PATH,
Options.METAMODEL_ENABLED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
Options.LOMBOK_VALUE,
Options.LOMBOK_ALL_ARGS_CONSTRUCTOR,
Options.TEST,
Options.TRACE,
Options.DEBUG,
Options.CONFIG_PATH,
Options.METAMODEL_ENABLED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
Options.VERSION_VALIDATION,
Options.RESOURCES_DIR,
Options.TEST,
Options.TRACE,
Options.DEBUG,
Options.CONFIG_PATH
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
import org.seasar.doma.message.Message;

@SupportedAnnotationTypes({"org.seasar.doma.Scope"})
@SupportedOptions({Options.RESOURCES_DIR, Options.TEST, Options.DEBUG, Options.CONFIG_PATH})
@SupportedOptions({
Options.RESOURCES_DIR,
Options.TEST,
Options.TRACE,
Options.DEBUG,
Options.CONFIG_PATH
})
public class ScopeProcessor extends AbstractProcessor {

public ScopeProcessor() {
Expand Down

0 comments on commit 71da5df

Please sign in to comment.