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