3434 * @author Cause Chung
3535 */
3636@ SupportedAnnotationTypes ("online.sharedtype.SharedType" )
37- @ SupportedOptions ({"sharedtype.propsFile" })
37+ @ SupportedOptions ({"sharedtype.propsFile" , "sharedtype.enabled" })
3838@ AutoService (Processor .class )
3939public final class AnnotationProcessorImpl extends AbstractProcessor {
4040 private static final String PROPS_FILE_OPTION_NAME = "sharedtype.propsFile" ;
4141 private static final String DEFAULT_USER_PROPS_FILE = "sharedtype.properties" ;
4242 private static final boolean ANNOTATION_CONSUMED = true ;
43+ private boolean enabled ;
4344 Context ctx ;
4445 TypeDefParser parser ;
4546 TypeResolver resolver ;
@@ -54,15 +55,18 @@ public SourceVersion getSupportedSourceVersion() {
5455 public synchronized void init (ProcessingEnvironment processingEnv ) {
5556 super .init (processingEnv );
5657 String configFile = processingEnv .getOptions ().getOrDefault (PROPS_FILE_OPTION_NAME , DEFAULT_USER_PROPS_FILE );
57- ctx = new Context (processingEnv , PropsFactory .loadProps (Paths .get (configFile )));
58- parser = TypeDefParser .create (ctx );
59- resolver = TypeResolver .create (ctx , parser );
60- writer = TypeWriter .create (ctx );
58+ enabled = isEnabled (processingEnv );
59+ if (enabled ) {
60+ ctx = new Context (processingEnv , PropsFactory .loadProps (Paths .get (configFile )));
61+ parser = TypeDefParser .create (ctx );
62+ resolver = TypeResolver .create (ctx , parser );
63+ writer = TypeWriter .create (ctx );
64+ }
6165 }
6266
6367 @ Override
6468 public boolean process (Set <? extends TypeElement > annotations , RoundEnvironment roundEnv ) {
65- if (annotations .isEmpty ()) {
69+ if (! enabled || annotations .isEmpty ()) {
6670 return ANNOTATION_CONSUMED ;
6771 }
6872 if (annotations .size () > 1 ) {
@@ -97,4 +101,9 @@ void doProcess(Set<? extends Element> elements) {
97101 throw new SharedTypeException ("Failed to write," , e );
98102 }
99103 }
104+
105+ private static boolean isEnabled (ProcessingEnvironment processingEnv ) {
106+ String enabledExpr = processingEnv .getOptions ().getOrDefault ("sharedtype.enabled" , "false" );
107+ return enabledExpr .equalsIgnoreCase ("true" ) || enabledExpr .equalsIgnoreCase ("yes" );
108+ }
100109}
0 commit comments