X Tutup
Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
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 @@ -27,4 +27,6 @@ public interface AnnotationHandler<T extends GeneratedClassHolder> {
ElementValidation validate(Element element);

void process(Element element, T holder) throws Exception;

boolean isEnabled();
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public ElementValidation validate(Element element) {
return validation;
}

public boolean isEnabled() {
return true;
}

protected abstract void validate(Element element, ElementValidation validation);

protected AndroidAnnotationsEnvironment getEnvironment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
import org.androidannotations.internal.core.handler.ServiceActionHandler;
import org.androidannotations.internal.core.handler.SharedPrefHandler;
import org.androidannotations.internal.core.handler.SupposeBackgroundHandler;
import org.androidannotations.internal.core.handler.SupposeThreadHandler;
import org.androidannotations.internal.core.handler.SupposeUiThreadHandler;
import org.androidannotations.internal.core.handler.SystemServiceHandler;
import org.androidannotations.internal.core.handler.TextChangeHandler;
Expand All @@ -112,17 +113,14 @@ public class CorePlugin extends AndroidAnnotationsPlugin {

private static final String NAME = "AndroidAnnotations";

private static final Option OPTION_TRACE = new Option("trace", "false");
private static final Option OPTION_THREAD_CONTROL = new Option("threadControl", "true");

@Override
public String getName() {
return NAME;
}

@Override
public List<Option> getSupportedOptions() {
return Arrays.asList(OPTION_TRACE, OPTION_THREAD_CONTROL);
return Arrays.asList(TraceHandler.OPTION_TRACE, SupposeThreadHandler.OPTION_THREAD_CONTROL);
}

@Override
Expand Down Expand Up @@ -219,9 +217,7 @@ public List<AnnotationHandler<?>> getHandlers(AndroidAnnotationsEnvironment andr
annotationHandlers.add(new PreferenceClickHandler(androidAnnotationEnv));
annotationHandlers.add(new AfterPreferencesHandler(androidAnnotationEnv));

if (androidAnnotationEnv.getOptionBooleanValue(OPTION_TRACE)) {
annotationHandlers.add(new TraceHandler(androidAnnotationEnv));
}
annotationHandlers.add(new TraceHandler(androidAnnotationEnv));

/*
* WakeLockHandler must be after TraceHandler but before UiThreadHandler
Expand All @@ -240,10 +236,8 @@ public List<AnnotationHandler<?>> getHandlers(AndroidAnnotationsEnvironment andr
* SupposeUiThreadHandler and SupposeBackgroundHandler must be after all
* handlers that modifies generated method body
*/
if (androidAnnotationEnv.getOptionBooleanValue(OPTION_THREAD_CONTROL)) {
annotationHandlers.add(new SupposeUiThreadHandler(androidAnnotationEnv));
annotationHandlers.add(new SupposeBackgroundHandler(androidAnnotationEnv));
}
annotationHandlers.add(new SupposeUiThreadHandler(androidAnnotationEnv));
annotationHandlers.add(new SupposeBackgroundHandler(androidAnnotationEnv));

return annotationHandlers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,23 @@

import org.androidannotations.AndroidAnnotationsEnvironment;
import org.androidannotations.ElementValidation;
import org.androidannotations.Option;
import org.androidannotations.handler.BaseAnnotationHandler;
import org.androidannotations.holder.EComponentHolder;

public abstract class SupposeThreadHandler extends BaseAnnotationHandler<EComponentHolder> {

public static final Option OPTION_THREAD_CONTROL = new Option("threadControl", "true");

public SupposeThreadHandler(Class<?> targetClass, AndroidAnnotationsEnvironment environment) {
super(targetClass, environment);
}

@Override
public boolean isEnabled() {
return getEnvironment().getOptionBooleanValue(OPTION_THREAD_CONTROL);
}

@Override
protected void validate(Element element, ElementValidation valid) {
validatorHelper.enclosingElementHasEnhancedComponentAnnotation(element, valid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import org.androidannotations.AndroidAnnotationsEnvironment;
import org.androidannotations.ElementValidation;
import org.androidannotations.Option;
import org.androidannotations.annotations.Trace;
import org.androidannotations.handler.BaseAnnotationHandler;
import org.androidannotations.holder.EComponentHolder;
Expand All @@ -48,10 +49,17 @@

public class TraceHandler extends BaseAnnotationHandler<EComponentHolder> {

public static final Option OPTION_TRACE = new Option("trace", "false");

public TraceHandler(AndroidAnnotationsEnvironment environment) {
super(Trace.class, environment);
}

@Override
public boolean isEnabled() {
return getEnvironment().getOptionBooleanValue(OPTION_TRACE);
}

@Override
public void validate(Element element, ElementValidation validation) {
validatorHelper.enclosingElementHasEnhancedComponentAnnotation(element, validation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public ProcessResult process(AnnotationElements validatedModel) throws Exception
LOGGER.info("Processing enclosed elements");

for (AnnotationHandler annotationHandler : environment.getDecoratingHandlers()) {
if (!annotationHandler.isEnabled()) {
continue;
}
String annotationName = annotationHandler.getTarget();

/*
Expand Down Expand Up @@ -167,6 +170,9 @@ private boolean isAbstractClass(Element annotatedElement) {
private boolean generateElements(AnnotationElements validatedModel, ProcessHolder processHolder) throws Exception {
boolean isElementRemaining = false;
for (GeneratingAnnotationHandler generatingAnnotationHandler : environment.getGeneratingHandlers()) {
if (!generatingAnnotationHandler.isEnabled()) {
continue;
}
String annotationName = generatingAnnotationHandler.getTarget();
Set<? extends Element> annotatedElements = validatedModel.getRootAnnotatedElements(annotationName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public AnnotationElements validate(AnnotationElements extractedModel, Annotation
*/

for (AnnotationHandler annotationHandler : environment.getHandlers()) {
if (!annotationHandler.isEnabled()) {
continue;
}
String validatorSimpleName = annotationHandler.getClass().getSimpleName();
String annotationName = annotationHandler.getTarget();

Expand Down
X Tutup