• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package android.processor.compat.changeid;
18 
19 /**
20  * Simple data class that represents a change, built from the code annotations.
21  */
22 final class Change {
23     final Long id;
24     final String name;
25     final boolean disabled;
26     final boolean loggingOnly;
27     final Integer enabledAfter;
28     final Integer enabledSince;
29     final String description;
30     final boolean overridable;
31     /**
32      * Package name that the change is defined in.
33      */
34     final String javaPackage;
35     /**
36      * Name of the class within it's package that the change is defined in.
37      */
38     final String className;
39     /**
40      * Fully qualified class name (including the package) that the change is defined in.
41      */
42     final String qualifiedClass;
43     /**
44      * Source position, in the form path/to/File.java:line
45      */
46     final String sourcePosition;
47 
Change(Long id, String name, boolean disabled, boolean loggingOnly, Integer enabledAfter, Integer enabledSince, String description, boolean overridable, String javaPackage, String className, String qualifiedClass, String sourcePosition)48      Change(Long id, String name, boolean disabled, boolean loggingOnly, Integer enabledAfter,
49              Integer enabledSince, String description, boolean overridable, String javaPackage,
50              String className,
51              String qualifiedClass, String sourcePosition) {
52         this.id = id;
53         this.name = name;
54         this.disabled = disabled;
55         this.loggingOnly = loggingOnly;
56         this.enabledAfter = enabledAfter;
57         this.enabledSince = enabledSince;
58         this.description = description;
59         this.overridable = overridable;
60         this.javaPackage = javaPackage;
61         this.className = className;
62         this.qualifiedClass = qualifiedClass;
63         this.sourcePosition = sourcePosition;
64     }
65 
66     public static class Builder {
67         Long id;
68         String name;
69         boolean disabled;
70         boolean loggingOnly;
71         Integer enabledAfter;
72         Integer enabledSince;
73         String description;
74         boolean overridable;
75         String javaPackage;
76         String javaClass;
77         String qualifiedClass;
78         String sourcePosition;
79 
Builder()80         Builder() {
81         }
82 
id(long id)83         public Builder id(long id) {
84             this.id = id;
85             return this;
86         }
87 
name(String name)88         public Builder name(String name) {
89             this.name = name;
90             return this;
91         }
92 
disabled()93         public Builder disabled() {
94             this.disabled = true;
95             return this;
96         }
97 
loggingOnly()98         public Builder loggingOnly() {
99             this.loggingOnly = true;
100             return this;
101         }
102 
enabledAfter(int sdkVersion)103         public Builder enabledAfter(int sdkVersion) {
104             this.enabledAfter = sdkVersion;
105             return this;
106         }
107 
enabledSince(int sdkVersion)108         public Builder enabledSince(int sdkVersion) {
109             this.enabledSince = sdkVersion;
110             return this;
111         }
112 
description(String description)113         public Builder description(String description) {
114             this.description = description;
115             return this;
116         }
117 
overridable()118         public Builder overridable() {
119             this.overridable = true;
120             return this;
121         }
122 
javaPackage(String javaPackage)123         public Builder javaPackage(String javaPackage) {
124             this.javaPackage = javaPackage;
125             return this;
126         }
127 
javaClass(String javaClass)128         public Builder javaClass(String javaClass) {
129             this.javaClass = javaClass;
130             return this;
131         }
132 
qualifiedClass(String className)133         public Builder qualifiedClass(String className) {
134             this.qualifiedClass = className;
135             return this;
136         }
137 
sourcePosition(String sourcePosition)138         public Builder sourcePosition(String sourcePosition) {
139             this.sourcePosition = sourcePosition;
140             return this;
141         }
142 
build()143         public Change build() {
144             return new Change(id, name, disabled, loggingOnly, enabledAfter, enabledSince,
145                     description, overridable, javaPackage, javaClass, qualifiedClass, sourcePosition);
146         }
147     }
148 }
149