diff options
Diffstat (limited to 'tools/codegen/src/com')
5 files changed, 44 insertions, 6 deletions
diff --git a/tools/codegen/src/com/android/codegen/ClassInfo.kt b/tools/codegen/src/com/android/codegen/ClassInfo.kt index bf95a2eb2193..056898c9eca1 100644 --- a/tools/codegen/src/com/android/codegen/ClassInfo.kt +++ b/tools/codegen/src/com/android/codegen/ClassInfo.kt @@ -1,12 +1,14 @@ package com.android.codegen import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration +import com.github.javaparser.ast.body.TypeDeclaration open class ClassInfo(val classAst: ClassOrInterfaceDeclaration, val fileInfo: FileInfo) { val fileAst = fileInfo.fileAst val nestedClasses = classAst.members.filterIsInstance<ClassOrInterfaceDeclaration>() + val nestedTypes = classAst.members.filterIsInstance<TypeDeclaration<*>>() val superInterfaces = classAst.implementedTypes.map { it.asString() } val superClass = classAst.extendedTypes.getOrNull(0) 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/InputSignaturesComputation.kt b/tools/codegen/src/com/android/codegen/InputSignaturesComputation.kt index 69ff18d3f6ab..1aea57514855 100644 --- a/tools/codegen/src/com/android/codegen/InputSignaturesComputation.kt +++ b/tools/codegen/src/com/android/codegen/InputSignaturesComputation.kt @@ -128,7 +128,7 @@ private fun ClassPrinter.getFullClassName(className: String): String { if (classAst.nameAsString == className) return thisPackagePrefix + classAst.nameAsString - nestedClasses.find { + nestedTypes.find { it.nameAsString == className }?.let { return thisClassPrefix + it.nameAsString } diff --git a/tools/codegen/src/com/android/codegen/SharedConstants.kt b/tools/codegen/src/com/android/codegen/SharedConstants.kt index 785aa9107f90..147f18c35e5c 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.19" const val CANONICAL_BUILDER_CLASS = "Builder" const val BASE_BUILDER_CLASS = "BaseBuilder" |