generators: cleanup 'public', property access syntax
This commit is contained in:
@@ -29,7 +29,7 @@ import java.io.File
|
||||
import java.io.PrintWriter
|
||||
|
||||
fun assertExists(file: File) {
|
||||
if (!file.exists()) error("Output dir does not exist: ${file.getAbsolutePath()}")
|
||||
if (!file.exists()) error("Output dir does not exist: ${file.absolutePath}")
|
||||
}
|
||||
|
||||
val BUILT_INS_NATIVE_DIR = File("core/builtins/native/")
|
||||
@@ -81,7 +81,7 @@ fun generateBuiltIns(generate: (File, (PrintWriter) -> BuiltInsSourceGenerator)
|
||||
fun main(args: Array<String>) {
|
||||
generateBuiltIns { file, generator ->
|
||||
println("generating $file")
|
||||
file.getParentFile()?.mkdirs()
|
||||
file.parentFile?.mkdirs()
|
||||
PrintWriter(file).use {
|
||||
generator(it).generate()
|
||||
}
|
||||
|
||||
@@ -52,10 +52,10 @@ fun generate(): String {
|
||||
|
||||
val builtIns = TargetPlatform.Default.builtIns
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val allPrimitiveTypes = builtIns.getBuiltInsPackageScope().getContributedDescriptors()
|
||||
.filter { it is ClassDescriptor && KotlinBuiltIns.isPrimitiveType(it.getDefaultType()) } as List<ClassDescriptor>
|
||||
val allPrimitiveTypes = builtIns.builtInsPackageScope.getContributedDescriptors()
|
||||
.filter { it is ClassDescriptor && KotlinBuiltIns.isPrimitiveType(it.defaultType) } as List<ClassDescriptor>
|
||||
|
||||
for (descriptor in allPrimitiveTypes + builtIns.getString()) {
|
||||
for (descriptor in allPrimitiveTypes + builtIns.string) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val functions = descriptor.getMemberScope(listOf()).getContributedDescriptors()
|
||||
.filter { it is CallableDescriptor && !EXCLUDED_FUNCTIONS.contains(it.getName().asString()) } as List<CallableDescriptor>
|
||||
@@ -64,9 +64,9 @@ fun generate(): String {
|
||||
val parametersTypes = function.getParametersTypes()
|
||||
|
||||
when (parametersTypes.size) {
|
||||
1 -> unaryOperationsMap.add(Triple(function.getName().asString(), parametersTypes, function is FunctionDescriptor))
|
||||
2 -> binaryOperationsMap.add(function.getName().asString() to parametersTypes)
|
||||
else -> throw IllegalStateException("Couldn't add following method from builtins to operations map: ${function.getName()} in class ${descriptor.getName()}")
|
||||
1 -> unaryOperationsMap.add(Triple(function.name.asString(), parametersTypes, function is FunctionDescriptor))
|
||||
2 -> binaryOperationsMap.add(function.name.asString() to parametersTypes)
|
||||
else -> throw IllegalStateException("Couldn't add following method from builtins to operations map: ${function.name} in class ${descriptor.name}")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -162,11 +162,11 @@ private fun KotlinType.isIntegerType(): Boolean {
|
||||
|
||||
|
||||
private fun CallableDescriptor.getParametersTypes(): List<KotlinType> {
|
||||
val list = arrayListOf((getContainingDeclaration() as ClassDescriptor).getDefaultType())
|
||||
getValueParameters().map { it.getType() }.forEach {
|
||||
val list = arrayListOf((containingDeclaration as ClassDescriptor).defaultType)
|
||||
valueParameters.map { it.type }.forEach {
|
||||
list.add(TypeUtils.makeNotNullable(it))
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
private fun KotlinType.asString(): String = getConstructor().getDeclarationDescriptor()!!.getName().asString().toUpperCase()
|
||||
private fun KotlinType.asString(): String = constructor.declarationDescriptor!!.name.asString().toUpperCase()
|
||||
|
||||
@@ -31,11 +31,11 @@ import java.util.regex.Pattern
|
||||
// You may need to provide custom path to protoc executable, just modify this constant:
|
||||
val PROTOC_EXE = "protoc"
|
||||
|
||||
public class ProtoPath(public val file: String) {
|
||||
public val outPath: String = File(file).getParent()
|
||||
public val packageName: String = findFirst(Pattern.compile("package (.+);"))
|
||||
public val className: String = findFirst(Pattern.compile("option java_outer_classname = \"(.+)\";"))
|
||||
public val debugClassName: String = "Debug$className"
|
||||
class ProtoPath(val file: String) {
|
||||
val outPath: String = File(file).parent
|
||||
val packageName: String = findFirst(Pattern.compile("package (.+);"))
|
||||
val className: String = findFirst(Pattern.compile("option java_outer_classname = \"(.+)\";"))
|
||||
val debugClassName: String = "Debug$className"
|
||||
|
||||
private fun findFirst(pattern: Pattern): String {
|
||||
for (line in File(file).readLines()) {
|
||||
@@ -46,7 +46,7 @@ public class ProtoPath(public val file: String) {
|
||||
}
|
||||
}
|
||||
|
||||
public val PROTO_PATHS: List<ProtoPath> = listOf(
|
||||
val PROTO_PATHS: List<ProtoPath> = listOf(
|
||||
ProtoPath("core/deserialization/src/descriptors.proto"),
|
||||
ProtoPath("core/deserialization/src/builtins.proto"),
|
||||
ProtoPath("js/js.serializer/src/js.proto"),
|
||||
@@ -105,7 +105,7 @@ fun modifyAndExecProtoc(protoPath: ProtoPath) {
|
||||
debugProtoFile.writeText(modifyForDebug(protoPath))
|
||||
debugProtoFile.deleteOnExit()
|
||||
|
||||
execProtoc(debugProtoFile.getPath(), "compiler/tests")
|
||||
execProtoc(debugProtoFile.path, "compiler/tests")
|
||||
}
|
||||
|
||||
fun modifyForDebug(protoPath: ProtoPath): String {
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.renderer.KeywordStringsGenerated
|
||||
import java.io.File
|
||||
|
||||
val MODIFIER_KEYWORDS = KtTokens.MODIFIER_KEYWORDS_ARRAY.map { it.getValue() }.toSet()
|
||||
val MODIFIER_KEYWORDS = KtTokens.MODIFIER_KEYWORDS_ARRAY.map { it.value }.toSet()
|
||||
|
||||
val commonCases: CaseBuilder.(String, String) -> Unit = { testByName, testByRef ->
|
||||
case("val", "val $KEYWORD_MARKER: Int", " = 0", testByName)
|
||||
|
||||
+2
-2
@@ -21,8 +21,8 @@ import org.jetbrains.kotlin.generators.evaluate.DEST_FILE
|
||||
import org.jetbrains.kotlin.generators.evaluate.generate
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
|
||||
public class GenerateOperationsMapTest : UsefulTestCase() {
|
||||
public fun testGeneratedDataIsUpToDate(): Unit {
|
||||
class GenerateOperationsMapTest : UsefulTestCase() {
|
||||
fun testGeneratedDataIsUpToDate(): Unit {
|
||||
val text = generate()
|
||||
KotlinTestUtils.assertEqualsToFile(DEST_FILE, text)
|
||||
}
|
||||
|
||||
+2
-2
@@ -21,8 +21,8 @@ import com.intellij.testFramework.UsefulTestCase
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import java.io.File
|
||||
|
||||
public class ProtoBufCompareConsistencyTest : UsefulTestCase() {
|
||||
public fun testAlreadyGenerated() {
|
||||
class ProtoBufCompareConsistencyTest : UsefulTestCase() {
|
||||
fun testAlreadyGenerated() {
|
||||
val testDir = KotlinTestUtils.tmpDir("testDirectory")
|
||||
val newFile = File(testDir, "ProtoCompareGenerated.kt")
|
||||
GenerateProtoBufCompare.generate(newFile)
|
||||
|
||||
+10
-10
@@ -24,23 +24,23 @@ import kotlin.test.fail
|
||||
import com.google.common.collect.LinkedHashMultimap
|
||||
import java.lang.reflect.Modifier
|
||||
|
||||
public class ProtoBufConsistencyTest : TestCase() {
|
||||
public fun testExtensionNumbersDoNotIntersect() {
|
||||
class ProtoBufConsistencyTest : TestCase() {
|
||||
fun testExtensionNumbersDoNotIntersect() {
|
||||
data class Key(val messageType: Class<*>, val index: Int)
|
||||
|
||||
val extensions = LinkedHashMultimap.create<Key, Descriptors.FieldDescriptor>()
|
||||
|
||||
for (protoPath in PROTO_PATHS) {
|
||||
val classFqName = protoPath.packageName + "." + protoPath.debugClassName
|
||||
val klass = javaClass.getClassLoader().loadClass(classFqName) ?: error("Class not found: $classFqName")
|
||||
for (field in klass.getDeclaredFields()) {
|
||||
if (Modifier.isStatic(field.getModifiers()) && field.getType() == GeneratedExtension::class.java) {
|
||||
val klass = javaClass.classLoader.loadClass(classFqName) ?: error("Class not found: $classFqName")
|
||||
for (field in klass.declaredFields) {
|
||||
if (Modifier.isStatic(field.modifiers) && field.type == GeneratedExtension::class.java) {
|
||||
// The only place where type information for an extension is stored is the field's declared generic type.
|
||||
// The message type which this extension extends is the first argument to GeneratedExtension<*, *>
|
||||
val containingType = (field.getGenericType() as ParameterizedType).getActualTypeArguments().first() as Class<*>
|
||||
val containingType = (field.genericType as ParameterizedType).actualTypeArguments.first() as Class<*>
|
||||
val value = field.get(null) as GeneratedExtension<*, *>
|
||||
val desc = value.getDescriptor()
|
||||
extensions.put(Key(containingType, desc.getNumber()), desc)
|
||||
val desc = value.descriptor
|
||||
extensions.put(Key(containingType, desc.number), desc)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,9 +51,9 @@ public class ProtoBufConsistencyTest : TestCase() {
|
||||
Several extensions to the same message type with the same index were found.
|
||||
This will cause different hard-to-debug problems if these extensions are used at the same time during (de-)serialization of the message.
|
||||
Consider changing the indices in the corresponding .proto definition files.
|
||||
Message type: ${key.messageType.getSimpleName()}
|
||||
Message type: ${key.messageType.simpleName}
|
||||
Index: ${key.index}
|
||||
Extensions found: ${descriptors.map { it.getName() }}
|
||||
Extensions found: ${descriptors.map { it.name }}
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user