-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a way to override how the @generated(date=?) is rendered
- Loading branch information
1 parent
2cb2a12
commit 1159677
Showing
3 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...src/main/java/org/jboss/logging/processor/generator/model/GeneratedDateValueProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.jboss.logging.processor.generator.model; | ||
|
||
import java.util.Locale; | ||
import java.util.Map; | ||
|
||
import org.jboss.logging.processor.apt.LoggingToolsProcessor; | ||
|
||
public abstract class GeneratedDateValueProvider { | ||
enum Type { | ||
DEFAULT, | ||
NONE, | ||
FIXED; | ||
} | ||
|
||
abstract String date(); | ||
|
||
public static GeneratedDateValueProvider of(Map<String, String> options) { | ||
Type type = Type.valueOf(options.getOrDefault(LoggingToolsProcessor.GENERATED_DATE_VALUE_PROVIDER, Type.DEFAULT.name()) | ||
.toUpperCase(Locale.ROOT)); | ||
switch (type) { | ||
case DEFAULT: | ||
return DefaultGeneratedDateValueProvider.INSTANCE; | ||
case NONE: | ||
return NoneGeneratedDateValueProvider.INSTANCE; | ||
case FIXED: | ||
String date = options.get(LoggingToolsProcessor.GENERATED_DATE_VALUE_PROVIDER_DATE); | ||
if (date == null) { | ||
throw new IllegalArgumentException( | ||
"Fixed date generated date value provider is requested, but the date is not specified. " | ||
+ "Use " + LoggingToolsProcessor.GENERATED_DATE_VALUE_PROVIDER_DATE | ||
+ " annotation processor option to provide the date."); | ||
} | ||
return new FixedGeneratedDateValueProvider(date); | ||
default: | ||
throw new IllegalStateException("Unknown generated date value provider type: " + type); | ||
} | ||
} | ||
|
||
private static class DefaultGeneratedDateValueProvider extends GeneratedDateValueProvider { | ||
|
||
private static final DefaultGeneratedDateValueProvider INSTANCE = new DefaultGeneratedDateValueProvider(); | ||
|
||
@Override | ||
String date() { | ||
return ClassModelHelper.generatedDateValue(); | ||
} | ||
} | ||
|
||
private static class NoneGeneratedDateValueProvider extends GeneratedDateValueProvider { | ||
|
||
private static final NoneGeneratedDateValueProvider INSTANCE = new NoneGeneratedDateValueProvider(); | ||
|
||
@Override | ||
String date() { | ||
return ""; | ||
} | ||
} | ||
|
||
private static class FixedGeneratedDateValueProvider extends GeneratedDateValueProvider { | ||
|
||
private final String date; | ||
|
||
private FixedGeneratedDateValueProvider(String date) { | ||
this.date = date; | ||
} | ||
|
||
@Override | ||
String date() { | ||
return date; | ||
} | ||
} | ||
} |