You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
135 lines
2.4 KiB
135 lines
2.4 KiB
8 years ago
|
/*
|
||
6 years ago
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||
8 years ago
|
*
|
||
7 years ago
|
* This source code is licensed under the MIT license found in the
|
||
|
* LICENSE file in the root directory of this source tree.
|
||
8 years ago
|
*/
|
||
|
|
||
|
package codetoanalyze.java.checkers;
|
||
|
|
||
5 years ago
|
import android.support.annotation.MainThread;
|
||
8 years ago
|
import android.support.annotation.UiThread;
|
||
5 years ago
|
import android.support.annotation.WorkerThread;
|
||
8 years ago
|
import java.lang.annotation.ElementType;
|
||
|
import java.lang.annotation.Retention;
|
||
|
import java.lang.annotation.RetentionPolicy;
|
||
|
import java.lang.annotation.Target;
|
||
|
|
||
|
@Target({ElementType.METHOD})
|
||
|
@Retention(RetentionPolicy.CLASS)
|
||
6 years ago
|
@interface AnyThread {}
|
||
8 years ago
|
|
||
|
@Target({ElementType.METHOD})
|
||
|
@Retention(RetentionPolicy.CLASS)
|
||
6 years ago
|
@interface ForUiThread {}
|
||
8 years ago
|
|
||
|
@Target({ElementType.METHOD})
|
||
|
@Retention(RetentionPolicy.CLASS)
|
||
6 years ago
|
@interface ForNonUiThread {}
|
||
8 years ago
|
|
||
|
public class UiThreads {
|
||
|
|
||
|
@UiThread
|
||
|
void uiThread() {}
|
||
|
|
||
5 years ago
|
@MainThread
|
||
|
void mainThread() {}
|
||
|
|
||
8 years ago
|
@AnyThread
|
||
|
void anyThread() {}
|
||
|
|
||
|
@ForUiThread
|
||
|
void forUiThread() {}
|
||
|
|
||
|
@ForNonUiThread
|
||
|
void forNonUiThread() {}
|
||
|
|
||
5 years ago
|
@WorkerThread
|
||
|
void workerThread() {}
|
||
|
|
||
|
void unannotated() {}
|
||
|
|
||
|
void callUiThreadMethod() {
|
||
|
uiThread();
|
||
|
mainThread();
|
||
|
forUiThread();
|
||
8 years ago
|
}
|
||
|
|
||
5 years ago
|
void callNonUiThreadMethod() {
|
||
8 years ago
|
forNonUiThread();
|
||
5 years ago
|
workerThread();
|
||
8 years ago
|
}
|
||
|
|
||
5 years ago
|
@UiThread
|
||
|
void callsFromUiThreadBad() {
|
||
|
callNonUiThreadMethod();
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
@UiThread
|
||
|
void callsFromUiThreadOk() {
|
||
|
callUiThreadMethod();
|
||
|
anyThread();
|
||
|
unannotated();
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
@MainThread
|
||
|
void callsFromMainThreadBad() {
|
||
|
callNonUiThreadMethod();
|
||
8 years ago
|
}
|
||
|
|
||
5 years ago
|
@MainThread
|
||
|
void callsFromMainThreadOk() {
|
||
|
callUiThreadMethod();
|
||
|
anyThread();
|
||
|
unannotated();
|
||
8 years ago
|
}
|
||
|
|
||
5 years ago
|
@ForUiThread
|
||
|
void callsFromForUiThreadBad() {
|
||
|
callNonUiThreadMethod();
|
||
5 years ago
|
}
|
||
|
|
||
8 years ago
|
@ForUiThread
|
||
5 years ago
|
void callsFromForUiThreadOk() {
|
||
|
callUiThreadMethod();
|
||
|
anyThread();
|
||
|
unannotated();
|
||
8 years ago
|
}
|
||
|
|
||
5 years ago
|
@ForNonUiThread
|
||
|
void callsFromNonUiThreadBad() {
|
||
|
callUiThreadMethod();
|
||
8 years ago
|
}
|
||
|
|
||
|
@ForNonUiThread
|
||
5 years ago
|
void callsFromNonUiThreadOk() {
|
||
|
callNonUiThreadMethod();
|
||
8 years ago
|
anyThread();
|
||
5 years ago
|
unannotated();
|
||
8 years ago
|
}
|
||
|
|
||
5 years ago
|
@WorkerThread
|
||
|
void callsFromWorkerThreadBad() {
|
||
|
callUiThreadMethod();
|
||
|
}
|
||
|
|
||
|
@WorkerThread
|
||
|
void callsFromWorkerThreadOk() {
|
||
|
callNonUiThreadMethod();
|
||
8 years ago
|
anyThread();
|
||
5 years ago
|
unannotated();
|
||
8 years ago
|
}
|
||
|
|
||
5 years ago
|
@AnyThread
|
||
|
void callsFromAnyThreadBad() {
|
||
|
callUiThreadMethod();
|
||
|
callNonUiThreadMethod();
|
||
|
}
|
||
|
|
||
|
@AnyThread
|
||
|
void callsFromAnyThreadOk() {
|
||
8 years ago
|
anyThread();
|
||
5 years ago
|
unannotated();
|
||
8 years ago
|
}
|
||
|
}
|