diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2018-03-26 19:33:54 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-03-26 19:33:54 +0000 |
commit | 0dcbfd3d1ccdde2ba1e3a582c9aac97aa242f972 (patch) | |
tree | a00af97c94375f26b2d353251cc85aab57bfd041 /java/com/android/dialer/rootcomponentgenerator/annotation | |
parent | 2aea5b1df52c9f15e551006a46743e792b71cb51 (diff) | |
parent | cac4acd257f66c2639c4daa26be72484d9865ef6 (diff) |
Merge "Add RootComponentGenerator to auto-generate root components for different dialer variants."
Diffstat (limited to 'java/com/android/dialer/rootcomponentgenerator/annotation')
5 files changed, 202 insertions, 0 deletions
diff --git a/java/com/android/dialer/rootcomponentgenerator/annotation/DialerComponent.java b/java/com/android/dialer/rootcomponentgenerator/annotation/DialerComponent.java new file mode 100644 index 000000000..573abae7f --- /dev/null +++ b/java/com/android/dialer/rootcomponentgenerator/annotation/DialerComponent.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.dialer.rootcomponentgenerator.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +/** + * Annotates a type equivalent to {@link dagger.Subcomponent}. + * + * <p>The annotation processor will generate a new type file with some prefix, which contains public + * static XXX get(Context context) method and HasComponent interface like: + * + * <p> + * + * <pre> + * <code> + * public static SimulatorComponent get(Context context) { + * HasRootComponent hasRootComponent = (HasRootComponent) context.getApplicationContext(); + * return ((HasComponent)(hasRootComponent.component()).simulatorComponent(); + * } + * public interface HasComponent { + * SimulatorComponent simulatorComponent(); + * } + * </code> + * </pre> + */ +@Target(ElementType.TYPE) +public @interface DialerComponent { + Class<?>[] modules() default {}; +} diff --git a/java/com/android/dialer/rootcomponentgenerator/annotation/DialerRootComponent.java b/java/com/android/dialer/rootcomponentgenerator/annotation/DialerRootComponent.java new file mode 100644 index 000000000..b6bf22efb --- /dev/null +++ b/java/com/android/dialer/rootcomponentgenerator/annotation/DialerRootComponent.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.dialer.rootcomponentgenerator.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotates the place with this annotation when a RootComponent is needed. + * + * <p>Usually users put this annotation on application class that is root of dependencies (the last + * thing to compile). The annotation processor will figure out what it needs to generate a variant + * root through dependencies. + * + * <p>Example: + * + * <pre> + * <code> + * @DialerRootComponent(variant = DialerVariant.DIALER_AOSP) + * public class RootDialerAosp {} + * </code> + * </pre> + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.SOURCE) +public @interface DialerRootComponent { + DialerVariant variant(); +} diff --git a/java/com/android/dialer/rootcomponentgenerator/annotation/DialerVariant.java b/java/com/android/dialer/rootcomponentgenerator/annotation/DialerVariant.java new file mode 100644 index 000000000..0bb185296 --- /dev/null +++ b/java/com/android/dialer/rootcomponentgenerator/annotation/DialerVariant.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.dialer.rootcomponentgenerator.annotation; + +/** Represents all dialer variants. */ +public enum DialerVariant { + // AOSP Dialer variants + DIALER_AOSP("DialerAosp"), + DIALER_AOSP_ESPRESSO("DialerAospEspresso"), + DIALER_ROBOLECTRIC("DialerRobolectric"), + + + + // TEST variant will be used in situations where we need create in-test application class which + // doesn't belong to any variants listed above + DIALER_TEST("DialerTest"); + + private final String variant; + + DialerVariant(String variant) { + this.variant = variant; + } + + @Override + public String toString() { + return variant; + } +} diff --git a/java/com/android/dialer/rootcomponentgenerator/annotation/InstallIn.java b/java/com/android/dialer/rootcomponentgenerator/annotation/InstallIn.java new file mode 100644 index 000000000..01a7873b0 --- /dev/null +++ b/java/com/android/dialer/rootcomponentgenerator/annotation/InstallIn.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.dialer.rootcomponentgenerator.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +/** + * Annotation for {@link dagger.Module dagger.Modules} which causes them to be installed in the + * specified variants. + * + * <p>It has a parameter for users to enter on which variants annotated module will be installed and + * also must be non-empty. Example: + * + * <pre> + * <code> + * @InstallIn(variants = {DialerVariant.DIALER_AOSP, DialerVariant.DIALER_TEST}) + * public class Module1 {} + * + * </code> + * </pre> + */ +@Target(ElementType.TYPE) +public @interface InstallIn { + DialerVariant[] variants(); +} diff --git a/java/com/android/dialer/rootcomponentgenerator/annotation/RootComponentGeneratorMetadata.java b/java/com/android/dialer/rootcomponentgenerator/annotation/RootComponentGeneratorMetadata.java new file mode 100644 index 000000000..070cc7350 --- /dev/null +++ b/java/com/android/dialer/rootcomponentgenerator/annotation/RootComponentGeneratorMetadata.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.dialer.rootcomponentgenerator.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +/** + * Only used by rootcomponent generator to store metadata for locating annotated + * (@DialerComponent, @InstallIn) class. + */ +@Target(ElementType.TYPE) +public @interface RootComponentGeneratorMetadata { + String tag(); + + Class<?> annotatedClass(); +} |