1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.codegentest;
17 
18 import android.annotation.IntRange;
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.content.pm.PackageManager;
22 
23 import com.android.internal.util.DataClass;
24 
25 import java.util.List;
26 import java.util.Set;
27 
28 /**
29  * Test for some false positive pitfalls for
30  * {@link android.processor.staledataclass.StaleDataclassProcessor}
31  *
32  * Relies on the detector being run, failing the build should any of things here falsely
33  * register as stale.
34  */
35 @DataClass(genConstructor = false, genBuilder = false)
36 public class StaleDataclassDetectorFalsePositivesTest {
37 
38     /** Interfaces should be ignored */
39     public interface SomeListener {
onEvent()40         void onEvent();
41     }
42 
43     /** Enums should be ignored */
44     private enum SomeEnum { ONE, TWO }
45 
46     /** Annotations should be ignored */
47     public @interface SomeAnnotation {}
48 
49     /* Static initializers should be ignored */
50     static {}
51 
52     /* Initializers should be ignored */
53     {}
54 
55     /* Wildcard type argument should work correctly */
56     @Nullable
57     private List<Set<?>> mUsesWildcards = null;
58 
59     /** Unrelated methods should be noted, without triggering staleness false positives */
someMethod(int param)60     public @NonNull String someMethod(int param) { return null; }
61 
62     /** Inlined constants in annotation args should be fine */
annotatedWithConstArg()63     private @IntRange(from = PackageManager.PERMISSION_GRANTED) void annotatedWithConstArg() {}
64 
65 
66 
67     // Code below generated by codegen v1.0.23.
68     //
69     // DO NOT MODIFY!
70     // CHECKSTYLE:OFF Generated code
71     //
72     // To regenerate run:
73     // $ codegen $ANDROID_BUILD_TOP/frameworks/base/tests/Codegen/src/com/android/codegentest/StaleDataclassDetectorFalsePositivesTest.java
74     //
75     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
76     //   Settings > Editor > Code Style > Formatter Control
77     //@formatter:off
78 
79 
80     @DataClass.Generated.Member
getUsesWildcards()81     public @Nullable List<Set<?>> getUsesWildcards() {
82         return mUsesWildcards;
83     }
84 
85     @DataClass.Generated.Member
setUsesWildcards(@onNull List<Set<?>> value)86     public @NonNull StaleDataclassDetectorFalsePositivesTest setUsesWildcards(@NonNull List<Set<?>> value) {
87         mUsesWildcards = value;
88         return this;
89     }
90 
91     @DataClass.Generated(
92             time = 1616541544639L,
93             codegenVersion = "1.0.23",
94             sourceFile = "frameworks/base/tests/Codegen/src/com/android/codegentest/StaleDataclassDetectorFalsePositivesTest.java",
95             inputSignatures = "private @android.annotation.Nullable java.util.List<java.util.Set<?>> mUsesWildcards\npublic @android.annotation.NonNull java.lang.String someMethod(int)\nprivate @android.annotation.IntRange void annotatedWithConstArg()\nclass StaleDataclassDetectorFalsePositivesTest extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genConstructor=false, genBuilder=false)")
96     @Deprecated
__metadata()97     private void __metadata() {}
98 
99 
100     //@formatter:on
101     // End of generated code
102 
103 }
104