Switch converter test to new directive scheme

This commit is contained in:
Mikhail Bogdanov
2020-03-17 18:44:00 +01:00
parent d793fea8d2
commit 3f87899014
60 changed files with 88 additions and 89 deletions
@@ -35,8 +35,4 @@ class Directives {
values.flatMap { InTextDirectivesUtils.splitValues(arrayListOf(), it) } values.flatMap { InTextDirectivesUtils.splitValues(arrayListOf(), it) }
} }
} }
public fun asMapOfSingleValues(): Map<String, String?> {
return directives.entries.associate { it.key to it.value?.single() }
}
} }
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false // !FORCE_NOT_NULL_TYPES: false
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
package test; package test;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
+2 -2
View File
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false // !FORCE_NOT_NULL_TYPES: false
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
package test package test
class Test(str: String) { class Test(str: String) {
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false // !FORCE_NOT_NULL_TYPES: false
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
package test; package test;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false // !FORCE_NOT_NULL_TYPES: false
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
package test package test
internal class Foo { internal class Foo {
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
package test; package test;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
package test package test
class Test(str: String?) { class Test(str: String?) {
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false // !FORCE_NOT_NULL_TYPES: false
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
import java.util.HashSet; import java.util.HashSet;
class Foo { class Foo {
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false // !FORCE_NOT_NULL_TYPES: false
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
import java.util.HashSet import java.util.HashSet
internal class Foo { internal class Foo {
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false // !FORCE_NOT_NULL_TYPES: false
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
class Library { class Library {
void call() {} void call() {}
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false // !FORCE_NOT_NULL_TYPES: false
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
internal class Library { internal class Library {
val string: String val string: String
@@ -1,4 +1,4 @@
// !forceNotNullTypes: false // !FORCE_NOT_NULL_TYPES: false
//file //file
public class A { public class A {
public static void main(String[] args) { public static void main(String[] args) {
@@ -1,4 +1,4 @@
// !forceNotNullTypes: false // !FORCE_NOT_NULL_TYPES: false
object A { object A {
@JvmStatic @JvmStatic
fun main(args: Array<String>) { fun main(args: Array<String>) {
@@ -1,5 +1,5 @@
//method //method
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
void foo(boolean b) { void foo(boolean b) {
String s = "abc"; String s = "abc";
if (b) { if (b) {
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
fun foo(b: Boolean) { fun foo(b: Boolean) {
var s: String? = "abc" var s: String? = "abc"
if (b) { if (b) {
@@ -1,5 +1,5 @@
//method //method
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
void foo() { void foo() {
String s = bar(); String s = bar();
if (s != null) { if (s != null) {
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
fun foo() { fun foo() {
val s: String? = bar() val s: String? = bar()
if (s != null) { if (s != null) {
@@ -1,5 +1,5 @@
//method //method
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
void foo(boolean b) { void foo(boolean b) {
String s = null; String s = null;
if (b) { if (b) {
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
fun foo(b: Boolean) { fun foo(b: Boolean) {
var s: String? = null var s: String? = null
if (b) { if (b) {
@@ -1,5 +1,5 @@
//method //method
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
void foo(boolean b) { void foo(boolean b) {
String s = (b ? "abc" : null); String s = (b ? "abc" : null);
} }
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
fun foo(b: Boolean) { fun foo(b: Boolean) {
val s: String? = if (b) "abc" else null val s: String? = if (b) "abc" else null
} }
+1 -1
View File
@@ -1,5 +1,5 @@
//file //file
// !openByDefault: true // !OPEN_BY_DEFAULT: true
class A { class A {
void foo1() { } void foo1() { }
+1 -1
View File
@@ -1,4 +1,4 @@
// !openByDefault: true // !OPEN_BY_DEFAULT: true
internal open class A { internal open class A {
internal open fun foo1() {} internal open fun foo1() {}
@@ -1,5 +1,5 @@
//file //file
// !specifyFieldTypeByDefault: true // !SPECIFY_FIELD_TYPE_BY_DEFAULT: true
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.*; import java.util.*;
@@ -1,4 +1,4 @@
// !specifyFieldTypeByDefault: true // !SPECIFY_FIELD_TYPE_BY_DEFAULT: true
import java.util.* import java.util.*
internal class A { internal class A {
@@ -1,5 +1,5 @@
//method //method
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
public void foo() { public void foo() {
int i = 1; int i = 1;
String s = ""; String s = "";
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
fun foo() { fun foo() {
val i: Int = 1 val i: Int = 1
val s: String = "" val s: String = ""
@@ -1,5 +1,5 @@
//method //method
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
public void foo(List<String> list) { public void foo(List<String> list) {
int[] array = new int[10]; int[] array = new int[10];
for (int i = 0; i < 10; i++){ for (int i = 0; i < 10; i++){
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
fun foo(list: List<String>) { fun foo(list: List<String>) {
val array: IntArray = IntArray(10) val array: IntArray = IntArray(10)
for (i: Int in 0..9) { for (i: Int in 0..9) {
@@ -1,4 +1,4 @@
//statement //statement
// !forceNotNullTypes: false // !FORCE_NOT_NULL_TYPES: false
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
List<T> l; List<T> l;
@@ -1,3 +1,3 @@
// !forceNotNullTypes: false // !FORCE_NOT_NULL_TYPES: false
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
val l: List<T?>? val l: List<T?>?
@@ -37,14 +37,17 @@ abstract class AbstractJavaToKotlinConverterSingleFileTest : AbstractJavaToKotli
val settings = ConverterSettings.defaultSettings.copy() val settings = ConverterSettings.defaultSettings.copy()
val directives = KotlinTestUtils.parseDirectives(javaCode) val directives = KotlinTestUtils.parseDirectives(javaCode)
for ((name, value) in directives.asMapOfSingleValues()) { directives["FORCE_NOT_NULL_TYPES"]?.let {
when (name) { settings.forceNotNullTypes = it.toBoolean()
"forceNotNullTypes" -> settings.forceNotNullTypes = value.toBoolean() }
"specifyLocalVariableTypeByDefault" -> settings.specifyLocalVariableTypeByDefault = value.toBoolean() directives["SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT"]?.let {
"specifyFieldTypeByDefault" -> settings.specifyFieldTypeByDefault = value.toBoolean() settings.specifyLocalVariableTypeByDefault = it.toBoolean()
"openByDefault" -> settings.openByDefault = value.toBoolean() }
else -> throw IllegalArgumentException("Unknown option: $name") directives["SPECIFY_FIELD_TYPE_BY_DEFAULT"]?.let {
} settings.specifyFieldTypeByDefault = it.toBoolean()
}
directives["OPEN_BY_DEFAULT"]?.let {
settings.openByDefault = it.toBoolean()
} }
val rawConverted = when (prefix) { val rawConverted = when (prefix) {
+2 -2
View File
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false // !FORCE_NOT_NULL_TYPES: false
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
package test; package test;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
+2 -2
View File
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false // !FORCE_NOT_NULL_TYPES: false
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
package test package test
class Test(str: String) { class Test(str: String) {
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false // !FORCE_NOT_NULL_TYPES: false
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
package test; package test;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false // !FORCE_NOT_NULL_TYPES: false
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
package test package test
internal class Foo { internal class Foo {
+1 -1
View File
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
package test; package test;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
+1 -1
View File
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
package test package test
class Test(str: String?) { class Test(str: String?) {
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false // !FORCE_NOT_NULL_TYPES: false
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
import java.util.HashSet; import java.util.HashSet;
class Foo { class Foo {
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false // !FORCE_NOT_NULL_TYPES: false
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
class Library { class Library {
void call() {} void call() {}
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false // !FORCE_NOT_NULL_TYPES: false
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
internal class Library { internal class Library {
fun call() {} fun call() {}
val string: String val string: String
@@ -1,4 +1,4 @@
// !forceNotNullTypes: false // !FORCE_NOT_NULL_TYPES: false
//file //file
public class A { public class A {
public static void main(String[] args) { public static void main(String[] args) {
+1 -1
View File
@@ -1,4 +1,4 @@
// !forceNotNullTypes: false // !FORCE_NOT_NULL_TYPES: false
object A { object A {
@JvmStatic @JvmStatic
fun main(args: Array<String>) { fun main(args: Array<String>) {
@@ -1,5 +1,5 @@
//method //method
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
void foo(boolean b) { void foo(boolean b) {
String s = "abc"; String s = "abc";
if (b) { if (b) {
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
fun foo(b: Boolean) { fun foo(b: Boolean) {
var s: String? = "abc" var s: String? = "abc"
if (b) { if (b) {
@@ -1,5 +1,5 @@
//method //method
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
String bar() { String bar() {
return null; return null;
} }
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
fun bar(): String? { fun bar(): String? {
return null return null
} }
@@ -1,5 +1,5 @@
//method //method
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
void foo(boolean b) { void foo(boolean b) {
String s = null; String s = null;
if (b) { if (b) {
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
fun foo(b: Boolean) { fun foo(b: Boolean) {
var s: String? = null var s: String? = null
if (b) { if (b) {
@@ -1,5 +1,5 @@
//method //method
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
void foo(boolean b) { void foo(boolean b) {
String s = (b ? "abc" : null); String s = (b ? "abc" : null);
} }
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
fun foo(b: Boolean) { fun foo(b: Boolean) {
val s: String? = if (b) "abc" else null val s: String? = if (b) "abc" else null
} }
+1 -1
View File
@@ -1,5 +1,5 @@
//file //file
// !openByDefault: true // !OPEN_BY_DEFAULT: true
class A { class A {
void foo1() { } void foo1() { }
+1 -1
View File
@@ -1,4 +1,4 @@
// !openByDefault: true // !OPEN_BY_DEFAULT: true
internal open class A { internal open class A {
open fun foo1() {} open fun foo1() {}
private fun foo2() {} private fun foo2() {}
@@ -1,5 +1,5 @@
//file //file
// !specifyFieldTypeByDefault: true // !SPECIFY_FIELD_TYPE_BY_DEFAULT: true
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.*; import java.util.*;
@@ -1,5 +1,5 @@
//method //method
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
public void foo() { public void foo() {
int i = 1; int i = 1;
String s = ""; String s = "";
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
fun foo() { fun foo() {
val i = 1 val i = 1
val s = "" val s = ""
@@ -1,5 +1,5 @@
//method //method
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
public void foo(List<String> list) { public void foo(List<String> list) {
int[] array = new int[10]; int[] array = new int[10];
for (int i = 0; i < 10; i++){ for (int i = 0; i < 10; i++){
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
fun foo(list: List<String?>) { fun foo(list: List<String?>) {
val array: IntArray = IntArray(10) val array: IntArray = IntArray(10)
for (i: Int in 0..9) { for (i: Int in 0..9) {
@@ -1,4 +1,4 @@
//statement //statement
// !forceNotNullTypes: false // !FORCE_NOT_NULL_TYPES: false
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
List<T> l; List<T> l;
@@ -1,3 +1,3 @@
// !forceNotNullTypes: false // !FORCE_NOT_NULL_TYPES: false
// !specifyLocalVariableTypeByDefault: true // !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
var l: List<T?> var l: List<T?>