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) }
}
}
public fun asMapOfSingleValues(): Map<String, String?> {
return directives.entries.associate { it.key to it.value?.single() }
}
}
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false
// !specifyLocalVariableTypeByDefault: true
// !FORCE_NOT_NULL_TYPES: false
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
package test;
import org.jetbrains.annotations.NotNull;
+2 -2
View File
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false
// !specifyLocalVariableTypeByDefault: true
// !FORCE_NOT_NULL_TYPES: false
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
package test
class Test(str: String) {
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false
// !specifyLocalVariableTypeByDefault: true
// !FORCE_NOT_NULL_TYPES: false
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
package test;
import org.jetbrains.annotations.NotNull;
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false
// !specifyLocalVariableTypeByDefault: true
// !FORCE_NOT_NULL_TYPES: false
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
package test
internal class Foo {
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
package test;
import org.jetbrains.annotations.Nullable;
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
package test
class Test(str: String?) {
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false
// !specifyLocalVariableTypeByDefault: true
// !FORCE_NOT_NULL_TYPES: false
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
import java.util.HashSet;
class Foo {
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false
// !specifyLocalVariableTypeByDefault: true
// !FORCE_NOT_NULL_TYPES: false
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
import java.util.HashSet
internal class Foo {
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false
// !specifyLocalVariableTypeByDefault: true
// !FORCE_NOT_NULL_TYPES: false
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
class Library {
void call() {}
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false
// !specifyLocalVariableTypeByDefault: true
// !FORCE_NOT_NULL_TYPES: false
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
internal class Library {
val string: String
@@ -1,4 +1,4 @@
// !forceNotNullTypes: false
// !FORCE_NOT_NULL_TYPES: false
//file
public class A {
public static void main(String[] args) {
@@ -1,4 +1,4 @@
// !forceNotNullTypes: false
// !FORCE_NOT_NULL_TYPES: false
object A {
@JvmStatic
fun main(args: Array<String>) {
@@ -1,5 +1,5 @@
//method
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
void foo(boolean b) {
String s = "abc";
if (b) {
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
fun foo(b: Boolean) {
var s: String? = "abc"
if (b) {
@@ -1,5 +1,5 @@
//method
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
void foo() {
String s = bar();
if (s != null) {
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
fun foo() {
val s: String? = bar()
if (s != null) {
@@ -1,5 +1,5 @@
//method
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
void foo(boolean b) {
String s = null;
if (b) {
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
fun foo(b: Boolean) {
var s: String? = null
if (b) {
@@ -1,5 +1,5 @@
//method
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
void foo(boolean b) {
String s = (b ? "abc" : null);
}
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
fun foo(b: Boolean) {
val s: String? = if (b) "abc" else null
}
+1 -1
View File
@@ -1,5 +1,5 @@
//file
// !openByDefault: true
// !OPEN_BY_DEFAULT: true
class A {
void foo1() { }
+1 -1
View File
@@ -1,4 +1,4 @@
// !openByDefault: true
// !OPEN_BY_DEFAULT: true
internal open class A {
internal open fun foo1() {}
@@ -1,5 +1,5 @@
//file
// !specifyFieldTypeByDefault: true
// !SPECIFY_FIELD_TYPE_BY_DEFAULT: true
import org.jetbrains.annotations.Nullable;
import java.util.*;
@@ -1,4 +1,4 @@
// !specifyFieldTypeByDefault: true
// !SPECIFY_FIELD_TYPE_BY_DEFAULT: true
import java.util.*
internal class A {
@@ -1,5 +1,5 @@
//method
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
public void foo() {
int i = 1;
String s = "";
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
fun foo() {
val i: Int = 1
val s: String = ""
@@ -1,5 +1,5 @@
//method
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
public void foo(List<String> list) {
int[] array = new int[10];
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>) {
val array: IntArray = IntArray(10)
for (i: Int in 0..9) {
@@ -1,4 +1,4 @@
//statement
// !forceNotNullTypes: false
// !specifyLocalVariableTypeByDefault: true
// !FORCE_NOT_NULL_TYPES: false
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
List<T> l;
@@ -1,3 +1,3 @@
// !forceNotNullTypes: false
// !specifyLocalVariableTypeByDefault: true
// !FORCE_NOT_NULL_TYPES: false
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
val l: List<T?>?
@@ -37,14 +37,17 @@ abstract class AbstractJavaToKotlinConverterSingleFileTest : AbstractJavaToKotli
val settings = ConverterSettings.defaultSettings.copy()
val directives = KotlinTestUtils.parseDirectives(javaCode)
for ((name, value) in directives.asMapOfSingleValues()) {
when (name) {
"forceNotNullTypes" -> settings.forceNotNullTypes = value.toBoolean()
"specifyLocalVariableTypeByDefault" -> settings.specifyLocalVariableTypeByDefault = value.toBoolean()
"specifyFieldTypeByDefault" -> settings.specifyFieldTypeByDefault = value.toBoolean()
"openByDefault" -> settings.openByDefault = value.toBoolean()
else -> throw IllegalArgumentException("Unknown option: $name")
}
directives["FORCE_NOT_NULL_TYPES"]?.let {
settings.forceNotNullTypes = it.toBoolean()
}
directives["SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT"]?.let {
settings.specifyLocalVariableTypeByDefault = it.toBoolean()
}
directives["SPECIFY_FIELD_TYPE_BY_DEFAULT"]?.let {
settings.specifyFieldTypeByDefault = it.toBoolean()
}
directives["OPEN_BY_DEFAULT"]?.let {
settings.openByDefault = it.toBoolean()
}
val rawConverted = when (prefix) {
+2 -2
View File
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false
// !specifyLocalVariableTypeByDefault: true
// !FORCE_NOT_NULL_TYPES: false
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
package test;
import org.jetbrains.annotations.NotNull;
+2 -2
View File
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false
// !specifyLocalVariableTypeByDefault: true
// !FORCE_NOT_NULL_TYPES: false
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
package test
class Test(str: String) {
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false
// !specifyLocalVariableTypeByDefault: true
// !FORCE_NOT_NULL_TYPES: false
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
package test;
import org.jetbrains.annotations.NotNull;
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false
// !specifyLocalVariableTypeByDefault: true
// !FORCE_NOT_NULL_TYPES: false
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
package test
internal class Foo {
+1 -1
View File
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
package test;
import org.jetbrains.annotations.Nullable;
+1 -1
View File
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
package test
class Test(str: String?) {
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false
// !specifyLocalVariableTypeByDefault: true
// !FORCE_NOT_NULL_TYPES: false
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
import java.util.HashSet;
class Foo {
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false
// !specifyLocalVariableTypeByDefault: true
// !FORCE_NOT_NULL_TYPES: false
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
class Library {
void call() {}
@@ -1,5 +1,5 @@
// !forceNotNullTypes: false
// !specifyLocalVariableTypeByDefault: true
// !FORCE_NOT_NULL_TYPES: false
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
internal class Library {
fun call() {}
val string: String
@@ -1,4 +1,4 @@
// !forceNotNullTypes: false
// !FORCE_NOT_NULL_TYPES: false
//file
public class A {
public static void main(String[] args) {
+1 -1
View File
@@ -1,4 +1,4 @@
// !forceNotNullTypes: false
// !FORCE_NOT_NULL_TYPES: false
object A {
@JvmStatic
fun main(args: Array<String>) {
@@ -1,5 +1,5 @@
//method
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
void foo(boolean b) {
String s = "abc";
if (b) {
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
fun foo(b: Boolean) {
var s: String? = "abc"
if (b) {
@@ -1,5 +1,5 @@
//method
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
String bar() {
return null;
}
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
fun bar(): String? {
return null
}
@@ -1,5 +1,5 @@
//method
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
void foo(boolean b) {
String s = null;
if (b) {
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
fun foo(b: Boolean) {
var s: String? = null
if (b) {
@@ -1,5 +1,5 @@
//method
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
void foo(boolean b) {
String s = (b ? "abc" : null);
}
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
fun foo(b: Boolean) {
val s: String? = if (b) "abc" else null
}
+1 -1
View File
@@ -1,5 +1,5 @@
//file
// !openByDefault: true
// !OPEN_BY_DEFAULT: true
class A {
void foo1() { }
+1 -1
View File
@@ -1,4 +1,4 @@
// !openByDefault: true
// !OPEN_BY_DEFAULT: true
internal open class A {
open fun foo1() {}
private fun foo2() {}
@@ -1,5 +1,5 @@
//file
// !specifyFieldTypeByDefault: true
// !SPECIFY_FIELD_TYPE_BY_DEFAULT: true
import org.jetbrains.annotations.Nullable;
import java.util.*;
@@ -1,5 +1,5 @@
//method
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
public void foo() {
int i = 1;
String s = "";
@@ -1,4 +1,4 @@
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
fun foo() {
val i = 1
val s = ""
@@ -1,5 +1,5 @@
//method
// !specifyLocalVariableTypeByDefault: true
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
public void foo(List<String> list) {
int[] array = new int[10];
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?>) {
val array: IntArray = IntArray(10)
for (i: Int in 0..9) {
@@ -1,4 +1,4 @@
//statement
// !forceNotNullTypes: false
// !specifyLocalVariableTypeByDefault: true
// !FORCE_NOT_NULL_TYPES: false
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
List<T> l;
@@ -1,3 +1,3 @@
// !forceNotNullTypes: false
// !specifyLocalVariableTypeByDefault: true
// !FORCE_NOT_NULL_TYPES: false
// !SPECIFY_LOCAL_VARIABLE_TYPE_BY_DEFAULT: true
var l: List<T?>