summaryrefslogtreecommitdiff
path: root/tools/codegen
diff options
context:
space:
mode:
authorEugene Susla <eugenesusla@google.com>2020-10-27 14:33:39 -0700
committerEugene Susla <eugenesusla@google.com>2020-10-27 15:21:13 -0700
commit4150960e2dc514213f14749f1080df68335a3081 (patch)
treed5521d9b76e5d33bc9ce6bf35cb501af42d3060f /tools/codegen
parent7e56edb84fda6785832cc5a7c21c078b526a5edf (diff)
Relax literal initializer requirement when codegen detects constants
Test: . frameworks/base/tests/Codegen/runTest.sh Fixes: 158195639 Change-Id: I93bdea18f348aeca896a9fd619bef2d65704bb41
Diffstat (limited to 'tools/codegen')
-rw-r--r--tools/codegen/src/com/android/codegen/Debug.kt39
-rw-r--r--tools/codegen/src/com/android/codegen/Generators.kt5
-rw-r--r--tools/codegen/src/com/android/codegen/SharedConstants.kt2
3 files changed, 41 insertions, 5 deletions
diff --git a/tools/codegen/src/com/android/codegen/Debug.kt b/tools/codegen/src/com/android/codegen/Debug.kt
new file mode 100644
index 000000000000..de3184468540
--- /dev/null
+++ b/tools/codegen/src/com/android/codegen/Debug.kt
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2020 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.codegen
+
+import com.github.javaparser.ast.Node
+
+fun Node.dump(indent: String = ""): String {
+ return buildString {
+ append(indent)
+ appendln(dumpOneLineNoChildren())
+ childNodes.forEach { child ->
+ append(child.dump(indent + " "))
+ }
+ }
+}
+
+private fun Node.dumpOneLineNoChildren(): String {
+ val node = this
+ return buildString {
+ append(node::class.java.simpleName)
+ if (childNodes.isEmpty()) {
+ append(": ").append(node.toString())
+ }
+ }
+}
diff --git a/tools/codegen/src/com/android/codegen/Generators.kt b/tools/codegen/src/com/android/codegen/Generators.kt
index 6e1ab5944eb6..6c6d011cfede 100644
--- a/tools/codegen/src/com/android/codegen/Generators.kt
+++ b/tools/codegen/src/com/android/codegen/Generators.kt
@@ -16,10 +16,7 @@ import java.io.File
fun ClassPrinter.generateConstDefs() {
val consts = classAst.fields.filter {
it.isStatic && it.isFinal && it.variables.all { variable ->
- val initializer = variable.initializer.orElse(null)
- val isLiteral = initializer is LiteralExpr
- || (initializer is UnaryExpr && initializer.expression is LiteralExpr)
- isLiteral && variable.type.asString() in listOf("int", "String")
+ variable.type.asString() in listOf("int", "String")
} && it.annotations.none { it.nameAsString == DataClassSuppressConstDefs }
}.flatMap { field -> field.variables.map { it to field } }
val intConsts = consts.filter { it.first.type.asString() == "int" }
diff --git a/tools/codegen/src/com/android/codegen/SharedConstants.kt b/tools/codegen/src/com/android/codegen/SharedConstants.kt
index 785aa9107f90..ca658a972209 100644
--- a/tools/codegen/src/com/android/codegen/SharedConstants.kt
+++ b/tools/codegen/src/com/android/codegen/SharedConstants.kt
@@ -1,7 +1,7 @@
package com.android.codegen
const val CODEGEN_NAME = "codegen"
-const val CODEGEN_VERSION = "1.0.17"
+const val CODEGEN_VERSION = "1.0.18"
const val CANONICAL_BUILDER_CLASS = "Builder"
const val BASE_BUILDER_CLASS = "BaseBuilder"