KT-5287 J2K: Convert class with private constructor and static functions to "object" instead of class with "class object"
#KT-5287 Fixed
This commit is contained in:
@@ -49,14 +49,15 @@ enum class AccessorKind {
|
|||||||
|
|
||||||
class ClassBodyConverter(private val psiClass: PsiClass,
|
class ClassBodyConverter(private val psiClass: PsiClass,
|
||||||
private val converter: Converter,
|
private val converter: Converter,
|
||||||
private val isOpenClass: Boolean) {
|
private val isOpenClass: Boolean,
|
||||||
|
private val isObject: Boolean) {
|
||||||
private val membersToRemove = HashSet<PsiMember>()
|
private val membersToRemove = HashSet<PsiMember>()
|
||||||
private val fieldCorrections = HashMap<PsiField, FieldCorrectionInfo>()
|
private val fieldCorrections = HashMap<PsiField, FieldCorrectionInfo>()
|
||||||
|
|
||||||
public fun convertBody(): ClassBody {
|
public fun convertBody(): ClassBody {
|
||||||
processAccessorsToDrop()
|
processAccessorsToDrop()
|
||||||
|
|
||||||
val constructorConverter = if (psiClass.getName() != null)
|
val constructorConverter = if (psiClass.getName() != null && !isObject)
|
||||||
ConstructorConverter(psiClass, converter, fieldCorrections)
|
ConstructorConverter(psiClass, converter, fieldCorrections)
|
||||||
else
|
else
|
||||||
null
|
null
|
||||||
@@ -65,9 +66,10 @@ class ClassBodyConverter(private val psiClass: PsiClass,
|
|||||||
for (element in psiClass.getChildren()) {
|
for (element in psiClass.getChildren()) {
|
||||||
if (element is PsiMember) {
|
if (element is PsiMember) {
|
||||||
if (element is PsiAnnotationMethod) continue // converted in convertAnnotationType()
|
if (element is PsiAnnotationMethod) continue // converted in convertAnnotationType()
|
||||||
|
if (isObject && element.isConstructor()) continue // no constructor in object
|
||||||
|
|
||||||
val converted = converter.convertMember(element, membersToRemove, constructorConverter)
|
val converted = converter.convertMember(element, membersToRemove, constructorConverter)
|
||||||
if (converted != null/* && !converted.isEmpty()*/) {
|
if (converted != null) {
|
||||||
convertedMembers.put(element, converted)
|
convertedMembers.put(element, converted)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,6 +79,13 @@ class ClassBodyConverter(private val psiClass: PsiClass,
|
|||||||
convertedMembers.remove(member)
|
convertedMembers.remove(member)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val lBrace = LBrace().assignPrototype(psiClass.getLBrace())
|
||||||
|
val rBrace = RBrace().assignPrototype(psiClass.getRBrace())
|
||||||
|
|
||||||
|
if (isObject) {
|
||||||
|
return ClassBody(null, emptyList(), convertedMembers.values().toList(), emptyList(), lBrace, rBrace)
|
||||||
|
}
|
||||||
|
|
||||||
val useCompanionObject = shouldGenerateCompanionObject(convertedMembers)
|
val useCompanionObject = shouldGenerateCompanionObject(convertedMembers)
|
||||||
|
|
||||||
val members = ArrayList<Member>()
|
val members = ArrayList<Member>()
|
||||||
@@ -105,9 +114,6 @@ class ClassBodyConverter(private val psiClass: PsiClass,
|
|||||||
primaryConstructorSignature = null // no "()" after class name is needed in this case
|
primaryConstructorSignature = null // no "()" after class name is needed in this case
|
||||||
}
|
}
|
||||||
|
|
||||||
val lBrace = LBrace().assignPrototype(psiClass.getLBrace())
|
|
||||||
val rBrace = RBrace().assignPrototype(psiClass.getRBrace())
|
|
||||||
|
|
||||||
return ClassBody(primaryConstructorSignature, constructorConverter?.baseClassParams ?: listOf(), members, companionObjectMembers, lBrace, rBrace)
|
return ClassBody(primaryConstructorSignature, constructorConverter?.baseClassParams ?: listOf(), members, companionObjectMembers, lBrace, rBrace)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ class CodeConverter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
public fun convertAnonymousClassBody(anonymousClass: PsiAnonymousClass): AnonymousClassBody {
|
public fun convertAnonymousClassBody(anonymousClass: PsiAnonymousClass): AnonymousClassBody {
|
||||||
return AnonymousClassBody(ClassBodyConverter(anonymousClass, converter, false).convertBody(),
|
return AnonymousClassBody(ClassBodyConverter(anonymousClass, converter, isOpenClass = false, isObject = false).convertBody(),
|
||||||
anonymousClass.getBaseClassType().resolve()?.isInterface() ?: false).assignPrototype(anonymousClass)
|
anonymousClass.getBaseClassType().resolve()?.isInterface() ?: false).assignPrototype(anonymousClass)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,20 +16,21 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.j2k
|
package org.jetbrains.kotlin.j2k
|
||||||
|
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.psi.*
|
import com.intellij.psi.*
|
||||||
|
import com.intellij.psi.CommonClassNames.*
|
||||||
|
import com.intellij.psi.util.PsiMethodUtil
|
||||||
|
import com.intellij.psi.util.PsiTreeUtil
|
||||||
import org.jetbrains.kotlin.j2k.ast.*
|
import org.jetbrains.kotlin.j2k.ast.*
|
||||||
import org.jetbrains.kotlin.j2k.ast.Annotation
|
import org.jetbrains.kotlin.j2k.ast.Annotation
|
||||||
import org.jetbrains.kotlin.j2k.ast.Class
|
import org.jetbrains.kotlin.j2k.ast.Class
|
||||||
import org.jetbrains.kotlin.j2k.ast.Enum
|
import org.jetbrains.kotlin.j2k.ast.Enum
|
||||||
import java.util.*
|
import org.jetbrains.kotlin.j2k.ast.Object
|
||||||
import com.intellij.psi.CommonClassNames.*
|
|
||||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions.*
|
|
||||||
import com.intellij.openapi.project.Project
|
|
||||||
import com.intellij.psi.util.PsiMethodUtil
|
|
||||||
import com.intellij.psi.util.PsiTreeUtil
|
|
||||||
import org.jetbrains.kotlin.j2k.usageProcessing.UsageProcessing
|
|
||||||
import org.jetbrains.kotlin.j2k.usageProcessing.FieldToPropertyProcessing
|
import org.jetbrains.kotlin.j2k.usageProcessing.FieldToPropertyProcessing
|
||||||
|
import org.jetbrains.kotlin.j2k.usageProcessing.UsageProcessing
|
||||||
import org.jetbrains.kotlin.j2k.usageProcessing.UsageProcessingExpressionConverter
|
import org.jetbrains.kotlin.j2k.usageProcessing.UsageProcessingExpressionConverter
|
||||||
|
import org.jetbrains.kotlin.types.expressions.OperatorConventions.*
|
||||||
|
import java.util.ArrayList
|
||||||
|
|
||||||
class Converter private(
|
class Converter private(
|
||||||
private val elementToConvert: PsiElement,
|
private val elementToConvert: PsiElement,
|
||||||
@@ -150,42 +151,71 @@ class Converter private(
|
|||||||
val annotations = convertAnnotations(psiClass)
|
val annotations = convertAnnotations(psiClass)
|
||||||
var modifiers = convertModifiers(psiClass)
|
var modifiers = convertModifiers(psiClass)
|
||||||
val typeParameters = convertTypeParameterList(psiClass.getTypeParameterList())
|
val typeParameters = convertTypeParameterList(psiClass.getTypeParameterList())
|
||||||
val implementsTypes = convertToNotNullableTypes(psiClass.getImplementsListTypes())
|
|
||||||
val extendsTypes = convertToNotNullableTypes(psiClass.getExtendsListTypes())
|
val extendsTypes = convertToNotNullableTypes(psiClass.getExtendsListTypes())
|
||||||
|
val implementsTypes = convertToNotNullableTypes(psiClass.getImplementsListTypes())
|
||||||
val name = psiClass.declarationIdentifier()
|
val name = psiClass.declarationIdentifier()
|
||||||
|
|
||||||
return when {
|
return when {
|
||||||
psiClass.isInterface() -> {
|
psiClass.isInterface() -> {
|
||||||
var classBody = ClassBodyConverter(psiClass, this, false).convertBody()
|
val classBody = ClassBodyConverter(psiClass, this, isOpenClass = false, isObject = false).convertBody()
|
||||||
Trait(name, annotations, modifiers, typeParameters, extendsTypes, listOf(), implementsTypes, classBody)
|
Trait(name, annotations, modifiers, typeParameters, extendsTypes, listOf(), implementsTypes, classBody)
|
||||||
}
|
}
|
||||||
|
|
||||||
psiClass.isEnum() -> {
|
psiClass.isEnum() -> {
|
||||||
var classBody = ClassBodyConverter(psiClass, this, false).convertBody()
|
val classBody = ClassBodyConverter(psiClass, this, isOpenClass = false, isObject = false).convertBody()
|
||||||
Enum(name, annotations, modifiers, typeParameters, listOf(), listOf(), implementsTypes, classBody)
|
Enum(name, annotations, modifiers, typeParameters, listOf(), listOf(), implementsTypes, classBody)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
if (needOpenModifier(psiClass)) {
|
if (shouldConvertIntoObject(psiClass)) {
|
||||||
modifiers = modifiers.with(Modifier.OPEN)
|
val classBody = ClassBodyConverter(psiClass, this, isOpenClass = false, isObject = true).convertBody()
|
||||||
|
Object(name, annotations, modifiers.without(Modifier.ABSTRACT), classBody)
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
if (psiClass.getContainingClass() != null && !psiClass.hasModifierProperty(PsiModifier.STATIC)) {
|
||||||
|
modifiers = modifiers.with(Modifier.INNER)
|
||||||
|
}
|
||||||
|
|
||||||
if (psiClass.getContainingClass() != null && !psiClass.hasModifierProperty(PsiModifier.STATIC)) {
|
val openModifier = if (psiClass.hasModifierProperty(PsiModifier.FINAL) || psiClass.hasModifierProperty(PsiModifier.ABSTRACT))
|
||||||
modifiers = modifiers.with(Modifier.INNER)
|
false
|
||||||
|
else
|
||||||
|
settings.openByDefault || referenceSearcher.hasInheritors(psiClass)
|
||||||
|
|
||||||
|
if (openModifier) {
|
||||||
|
modifiers = modifiers.with(Modifier.OPEN)
|
||||||
|
}
|
||||||
|
|
||||||
|
val classBody = ClassBodyConverter(psiClass, this, modifiers.contains(Modifier.OPEN) || modifiers.contains(Modifier.ABSTRACT), isObject = false).convertBody()
|
||||||
|
Class(name, annotations, modifiers, typeParameters, extendsTypes, classBody.baseClassParams, implementsTypes, classBody)
|
||||||
}
|
}
|
||||||
|
|
||||||
var classBody = ClassBodyConverter(psiClass, this, modifiers.contains(Modifier.OPEN)).convertBody()
|
|
||||||
|
|
||||||
Class(name, annotations, modifiers, typeParameters, extendsTypes, classBody.baseClassParams, implementsTypes, classBody)
|
|
||||||
}
|
}
|
||||||
}.assignPrototype(psiClass)
|
}.assignPrototype(psiClass)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun needOpenModifier(psiClass: PsiClass): Boolean {
|
private fun shouldConvertIntoObject(psiClass: PsiClass): Boolean {
|
||||||
return if (settings.openByDefault)
|
val methods = psiClass.getMethods()
|
||||||
!psiClass.hasModifierProperty(PsiModifier.FINAL) && !psiClass.hasModifierProperty(PsiModifier.ABSTRACT)
|
val fields = psiClass.getFields()
|
||||||
else
|
val classes = psiClass.getInnerClasses()
|
||||||
referenceSearcher.hasInheritors(psiClass)
|
if (methods.isEmpty() && fields.isEmpty()) return false
|
||||||
|
fun isStatic(member: PsiMember) = member.hasModifierProperty(PsiModifier.STATIC)
|
||||||
|
if (!methods.all { isStatic(it) || it.isConstructor() } || !fields.all(::isStatic) || !classes.all(::isStatic)) return false
|
||||||
|
|
||||||
|
val constructors = psiClass.getConstructors()
|
||||||
|
if (constructors.size() > 1) return false
|
||||||
|
val constructor = constructors.singleOrNull()
|
||||||
|
if (constructor != null) {
|
||||||
|
if (!constructor.hasModifierProperty(PsiModifier.PRIVATE)) return false
|
||||||
|
if (constructor.getParameterList().getParameters().isNotEmpty()) return false
|
||||||
|
if (constructor.getBody()?.getStatements()?.isNotEmpty() ?: false) return false
|
||||||
|
if (constructor.getModifierList().getAnnotations().isNotEmpty()) return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (psiClass.getExtendsListTypes().isNotEmpty() || psiClass.getImplementsListTypes().isNotEmpty()) return false
|
||||||
|
if (psiClass.getTypeParameters().isNotEmpty()) return false
|
||||||
|
|
||||||
|
if (referenceSearcher.hasInheritors(psiClass)) return false
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertAnnotationType(psiClass: PsiClass): Class {
|
private fun convertAnnotationType(psiClass: PsiClass): Class {
|
||||||
@@ -215,7 +245,7 @@ class Converter private(
|
|||||||
null
|
null
|
||||||
|
|
||||||
// to convert fields and nested types - they are not allowed in Kotlin but we convert them and let user refactor code
|
// to convert fields and nested types - they are not allowed in Kotlin but we convert them and let user refactor code
|
||||||
var classBody = ClassBodyConverter(psiClass, this, false).convertBody()
|
var classBody = ClassBodyConverter(psiClass, this, isOpenClass = false, isObject = false).convertBody()
|
||||||
classBody = ClassBody(constructorSignature, classBody.baseClassParams, classBody.members, classBody.companionObjectMembers, classBody.lBrace, classBody.rBrace)
|
classBody = ClassBody(constructorSignature, classBody.baseClassParams, classBody.members, classBody.companionObjectMembers, classBody.lBrace, classBody.rBrace)
|
||||||
|
|
||||||
val annotationAnnotation = Annotation(Identifier("annotation").assignNoPrototype(), listOf(), false, false).assignNoPrototype()
|
val annotationAnnotation = Annotation(Identifier("annotation").assignNoPrototype(), listOf(), false, false).assignNoPrototype()
|
||||||
|
|||||||
@@ -16,7 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.j2k.ast
|
package org.jetbrains.kotlin.j2k.ast
|
||||||
|
|
||||||
import org.jetbrains.kotlin.j2k.*
|
import org.jetbrains.kotlin.j2k.CodeBuilder
|
||||||
|
import org.jetbrains.kotlin.j2k.append
|
||||||
|
|
||||||
open class Class(
|
open class Class(
|
||||||
val name: Identifier,
|
val name: Identifier,
|
||||||
@@ -68,3 +69,14 @@ open class Class(
|
|||||||
protected open fun presentationModifiers(): Modifiers
|
protected open fun presentationModifiers(): Modifiers
|
||||||
= if (modifiers.contains(Modifier.ABSTRACT)) modifiers.without(Modifier.OPEN) else modifiers
|
= if (modifiers.contains(Modifier.ABSTRACT)) modifiers.without(Modifier.OPEN) else modifiers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Object(
|
||||||
|
name: Identifier,
|
||||||
|
annotations: Annotations,
|
||||||
|
modifiers: Modifiers,
|
||||||
|
body: ClassBody
|
||||||
|
) : Class(name, annotations, modifiers, TypeParameterList.Empty, emptyList(), emptyList(), emptyList(), body) {
|
||||||
|
|
||||||
|
override val keyword: String
|
||||||
|
get() = "object"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
class Test {
|
object Test {
|
||||||
companion object {
|
var str: String
|
||||||
var str: String
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
str = "Ola"
|
str = "Ola"
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
// ERROR: Property must be initialized or be abstract
|
// ERROR: Property must be initialized or be abstract
|
||||||
class Library {
|
object Library {
|
||||||
companion object {
|
val ourOut: java.io.PrintStream
|
||||||
val ourOut: java.io.PrintStream
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class User {
|
class User {
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
class Library {
|
object Library {
|
||||||
companion object {
|
fun call() {
|
||||||
fun call() {
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun getString(): String {
|
fun getString(): String {
|
||||||
return ""
|
return ""
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package test;
|
package test;
|
||||||
|
|
||||||
|
import java.lang.String;
|
||||||
|
|
||||||
public class Short {
|
public class Short {
|
||||||
public static Short valueOf(String value) {return new Short();}
|
public Short(String s){}
|
||||||
|
public static Short valueOf(String value) {return new Short(value);}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Test {
|
class Test {
|
||||||
|
|||||||
@@ -1,19 +1,17 @@
|
|||||||
package test
|
package test
|
||||||
|
|
||||||
public class Short {
|
public class Short(s: String) {
|
||||||
companion object {
|
companion object {
|
||||||
public fun valueOf(value: String): Short {
|
public fun valueOf(value: String): Short {
|
||||||
return Short()
|
return Short(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Test {
|
object Test {
|
||||||
companion object {
|
public fun test() {
|
||||||
public fun test() {
|
test.Short.valueOf("1")
|
||||||
test.Short.valueOf("1")
|
test.Short.valueOf("1")
|
||||||
test.Short.valueOf("1")
|
java.lang.Short.valueOf("1")
|
||||||
java.lang.Short.valueOf("1")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
class Base {
|
||||||
|
public static final int CONSTANT = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Derived extends Base {
|
||||||
|
void foo(){}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
open class Base {
|
||||||
|
companion object {
|
||||||
|
public val CONSTANT: Int = 10
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Derived : Base() {
|
||||||
|
fun foo() {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
class S {
|
object S {
|
||||||
companion object {
|
fun staticF(): Boolean {
|
||||||
fun staticF(): Boolean {
|
return true
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,9 @@
|
|||||||
class S {
|
object S {
|
||||||
companion object {
|
fun sB(): Boolean {
|
||||||
fun sB(): Boolean {
|
return true
|
||||||
return true
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun sI(): Int {
|
fun sI(): Int {
|
||||||
return 1
|
return 1
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
class Util {
|
||||||
|
public static void util1() {}
|
||||||
|
public static void util2() {}
|
||||||
|
|
||||||
|
public static final int CONSTANT = 10;
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
object Util {
|
||||||
|
public fun util1() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun util2() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public val CONSTANT: Int = 10
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
class Util {
|
||||||
|
private Util(){}
|
||||||
|
|
||||||
|
public static void util1() {}
|
||||||
|
public static void util2() {}
|
||||||
|
|
||||||
|
public static final int CONSTANT = 10;
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
object Util {
|
||||||
|
|
||||||
|
public fun util1() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun util2() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public val CONSTANT: Int = 10
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
abstract class Util {
|
||||||
|
public static void util1() {}
|
||||||
|
public static void util2() {}
|
||||||
|
|
||||||
|
public static final int CONSTANT = 10;
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
object Util {
|
||||||
|
public fun util1() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun util2() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public val CONSTANT: Int = 10
|
||||||
|
}
|
||||||
@@ -1,13 +1,11 @@
|
|||||||
public class A {
|
public object A {
|
||||||
companion object {
|
public fun main(args: Array<String>) {
|
||||||
public fun main(args: Array<String>) {
|
System.out.println(Void.TYPE)
|
||||||
System.out.println(Void.TYPE)
|
System.out.println(Integer.TYPE)
|
||||||
System.out.println(Integer.TYPE)
|
System.out.println(java.lang.Double.TYPE)
|
||||||
System.out.println(java.lang.Double.TYPE)
|
System.out.println(javaClass<IntArray>())
|
||||||
System.out.println(javaClass<IntArray>())
|
System.out.println(javaClass<Array<Any>>())
|
||||||
System.out.println(javaClass<Array<Any>>())
|
System.out.println(javaClass<Array<Array<Any>>>())
|
||||||
System.out.println(javaClass<Array<Array<Any>>>())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,10 @@ package pack
|
|||||||
|
|
||||||
class C(arg1: Int, arg2: Int = 0, arg3: Int = 0)
|
class C(arg1: Int, arg2: Int = 0, arg3: Int = 0)
|
||||||
|
|
||||||
public class User {
|
public object User {
|
||||||
companion object {
|
public fun main() {
|
||||||
public fun main() {
|
val c1 = C(100, 100, 100)
|
||||||
val c1 = C(100, 100, 100)
|
val c2 = C(100, 100)
|
||||||
val c2 = C(100, 100)
|
val c3 = C(100)
|
||||||
val c3 = C(100)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,12 +18,10 @@ class C(val myArg1: Int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class User {
|
public object User {
|
||||||
companion object {
|
public fun main() {
|
||||||
public fun main() {
|
val c1 = C(100, 100, 100)
|
||||||
val c1 = C(100, 100, 100)
|
val c2 = C(100, 100)
|
||||||
val c2 = C(100, 100)
|
val c3 = C(100)
|
||||||
val c3 = C(100)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,12 +9,10 @@ class C(arg1: Int, arg2: Int, arg3: Int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class User {
|
public object User {
|
||||||
companion object {
|
public fun main() {
|
||||||
public fun main() {
|
val c1 = C(1, 2, 3)
|
||||||
val c1 = C(1, 2, 3)
|
val c2 = C(5, 6)
|
||||||
val c2 = C(5, 6)
|
val c3 = C(7)
|
||||||
val c3 = C(7)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -33,12 +33,10 @@ class CustomerBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class User {
|
public object User {
|
||||||
companion object {
|
public fun main() {
|
||||||
public fun main() {
|
val customer = CustomerBuilder().WithFirstName("Homer").WithLastName("Simpson").Build()
|
||||||
val customer = CustomerBuilder().WithFirstName("Homer").WithLastName("Simpson").Build()
|
System.out.println(customer.firstName)
|
||||||
System.out.println(customer.firstName)
|
System.out.println(customer.lastName)
|
||||||
System.out.println(customer.lastName)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,12 +20,10 @@ public class Identifier<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class User {
|
public object User {
|
||||||
companion object {
|
public fun main() {
|
||||||
public fun main() {
|
val i1 = Identifier("name", false, true)
|
||||||
val i1 = Identifier("name", false, true)
|
val i2 = Identifier("name", false)
|
||||||
val i2 = Identifier("name", false)
|
val i3 = Identifier("name")
|
||||||
val i3 = Identifier("name")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,12 +20,10 @@ public class Identifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class User {
|
public object User {
|
||||||
companion object {
|
public fun main() {
|
||||||
public fun main() {
|
val i1 = Identifier("name", false, true)
|
||||||
val i1 = Identifier("name", false, true)
|
val i2 = Identifier("name", false)
|
||||||
val i2 = Identifier("name", false)
|
val i3 = Identifier("name")
|
||||||
val i3 = Identifier("name")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,12 +11,10 @@ class C {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class User {
|
public object User {
|
||||||
companion object {
|
public fun main() {
|
||||||
public fun main() {
|
val c1 = C(1, 2, 3)
|
||||||
val c1 = C(1, 2, 3)
|
val c2 = C(5, 6)
|
||||||
val c2 = C(5, 6)
|
val c3 = C(7)
|
||||||
val c3 = C(7)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,12 +17,10 @@ class C(arg1: Int, arg2: Int = 0, arg3: Int = 0) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class User {
|
public object User {
|
||||||
companion object {
|
public fun main() {
|
||||||
public fun main() {
|
val c1 = C(100, 100, 100)
|
||||||
val c1 = C(100, 100, 100)
|
val c2 = C(100, 100)
|
||||||
val c2 = C(100, 100)
|
val c3 = C(100)
|
||||||
val c3 = C(100)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
class Outer {
|
object Outer {
|
||||||
private class Nested1() {
|
private class Nested1() {
|
||||||
|
|
||||||
public constructor(a: Int) : this() {
|
public constructor(a: Int) : this() {
|
||||||
@@ -48,13 +48,10 @@ class Outer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
fun foo() {
|
||||||
|
val nested1 = Nested1(1)
|
||||||
fun foo() {
|
val nested2 = Nested2(2)
|
||||||
val nested1 = Nested1(1)
|
val nested3 = Nested3(3)
|
||||||
val nested2 = Nested2(2)
|
val nested4 = Nested4(4)
|
||||||
val nested3 = Nested3(3)
|
|
||||||
val nested4 = Nested4(4)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,10 +24,8 @@ public class Test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class User {
|
public object User {
|
||||||
companion object {
|
public fun main() {
|
||||||
public fun main() {
|
val t = Test("name")
|
||||||
val t = Test("name")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,14 @@
|
|||||||
public class TestClass {
|
public object TestClass {
|
||||||
companion object {
|
public fun main(args: Array<String>) {
|
||||||
public fun main(args: Array<String>) {
|
var i = 0
|
||||||
var i = 0
|
while (i < 10) {
|
||||||
while (i < 10) {
|
if (i == 4 || i == 8) {
|
||||||
if (i == 4 || i == 8) {
|
i++
|
||||||
i++
|
|
||||||
++i
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
System.err.println(i)
|
|
||||||
++i
|
++i
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
System.err.println(i)
|
||||||
|
++i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,17 @@
|
|||||||
public class TestClass {
|
public object TestClass {
|
||||||
companion object {
|
public fun main(args: Array<String>) {
|
||||||
public fun main(args: Array<String>) {
|
var i = 0
|
||||||
var i = 0
|
var j = 1
|
||||||
var j = 1
|
while (i < 10) {
|
||||||
while (i < 10) {
|
if (i == 4 || i == 8) {
|
||||||
if (i == 4 || i == 8) {
|
i++
|
||||||
i++
|
|
||||||
++i
|
|
||||||
j *= 2
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
System.err.println(j)
|
|
||||||
++i
|
++i
|
||||||
j *= 2
|
j *= 2
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
System.err.println(j)
|
||||||
|
++i
|
||||||
|
j *= 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
public class TestClass {
|
public object TestClass {
|
||||||
companion object {
|
public fun main(args: Array<String>) {
|
||||||
public fun main(args: Array<String>) {
|
var i = 1
|
||||||
var i = 1
|
while (i < 1000) {
|
||||||
while (i < 1000) {
|
if (i == 4 || i == 8) {
|
||||||
if (i == 4 || i == 8) {
|
|
||||||
i *= 2
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
System.err.println(i)
|
|
||||||
i *= 2
|
i *= 2
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
System.err.println(i)
|
||||||
|
i *= 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,26 @@
|
|||||||
// ERROR: The label '@OuterLoop1' does not denote a loop
|
// ERROR: The label '@OuterLoop1' does not denote a loop
|
||||||
public class TestClass {
|
public object TestClass {
|
||||||
companion object {
|
public fun main(args: Array<String>) {
|
||||||
public fun main(args: Array<String>) {
|
var i = 1
|
||||||
var i = 1
|
@OuterLoop1 @OuterLoop2 while (i < 1000) {
|
||||||
@OuterLoop1 @OuterLoop2 while (i < 1000) {
|
var j = 1
|
||||||
var j = 1
|
@InnerLoop while (j < 100) {
|
||||||
@InnerLoop while (j < 100) {
|
if (j == 3) {
|
||||||
if (j == 3) {
|
|
||||||
j *= 3
|
|
||||||
continue@InnerLoop
|
|
||||||
}
|
|
||||||
if (i == j) {
|
|
||||||
i *= 2
|
|
||||||
continue@OuterLoop1
|
|
||||||
}
|
|
||||||
System.err.println(j)
|
|
||||||
if (j == 9) {
|
|
||||||
j *= 3
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
j *= 3
|
j *= 3
|
||||||
|
continue@InnerLoop
|
||||||
}
|
}
|
||||||
i *= 2
|
if (i == j) {
|
||||||
|
i *= 2
|
||||||
|
continue@OuterLoop1
|
||||||
|
}
|
||||||
|
System.err.println(j)
|
||||||
|
if (j == 9) {
|
||||||
|
j *= 3
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
j *= 3
|
||||||
}
|
}
|
||||||
|
i *= 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,26 @@
|
|||||||
class F {
|
object F {
|
||||||
companion object {
|
|
||||||
|
|
||||||
//c1
|
//c1
|
||||||
|
|
||||||
/*c2*/
|
/*c2*/
|
||||||
|
|
||||||
fun f1() {
|
fun f1() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//c3
|
//c3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//c4
|
//c4
|
||||||
|
|
||||||
fun f2() {
|
fun f2() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var i: Int? = 0
|
var i: Int? = 0
|
||||||
|
|
||||||
fun f3() {
|
fun f3() {
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//c5
|
//c5
|
||||||
|
|||||||
@@ -1,4 +1,2 @@
|
|||||||
companion object {
|
public fun main(args: Array<String>) {
|
||||||
public fun main(args: Array<String>) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
public class A {
|
public object A {
|
||||||
companion object {
|
public fun main(args: Array<String>) {
|
||||||
public fun main(args: Array<String>) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
// !forceNotNullTypes: false
|
// !forceNotNullTypes: false
|
||||||
public class A {
|
public object A {
|
||||||
companion object {
|
public fun main(args: Array<String>) {
|
||||||
public fun main(args: Array<String>) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
class Test {
|
object Test {
|
||||||
companion object {
|
public fun foo(args: Array<String>): Int {
|
||||||
public fun foo(args: Array<String>): Int {
|
return args.size()
|
||||||
return args.size()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
class Outer {
|
object Outer {
|
||||||
|
public var o: Any? = Object()
|
||||||
|
|
||||||
public class Nested {
|
public class Nested {
|
||||||
public fun foo() {
|
public fun foo() {
|
||||||
o = null
|
o = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
|
||||||
public var o: Any? = Object()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,12 @@
|
|||||||
package demo
|
package demo
|
||||||
|
|
||||||
class Test {
|
object Test {
|
||||||
companion object {
|
fun subListRangeCheck(fromIndex: Int, toIndex: Int, size: Int) {
|
||||||
fun subListRangeCheck(fromIndex: Int, toIndex: Int, size: Int) {
|
if (fromIndex < 0)
|
||||||
if (fromIndex < 0)
|
throw IndexOutOfBoundsException("fromIndex = " + fromIndex)
|
||||||
throw IndexOutOfBoundsException("fromIndex = " + fromIndex)
|
if (toIndex > size)
|
||||||
if (toIndex > size)
|
throw IndexOutOfBoundsException("toIndex = " + toIndex)
|
||||||
throw IndexOutOfBoundsException("toIndex = " + toIndex)
|
if (fromIndex > toIndex)
|
||||||
if (fromIndex > toIndex)
|
throw IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")")
|
||||||
throw IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,13 +20,11 @@ public class Identifier<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class User {
|
public object User {
|
||||||
companion object {
|
public fun main(args: Array<String>) {
|
||||||
public fun main(args: Array<String>) {
|
val i1 = Identifier("name", false, true)
|
||||||
val i1 = Identifier("name", false, true)
|
val i2 = Identifier("name", false)
|
||||||
val i2 = Identifier("name", false)
|
val i3 = Identifier("name")
|
||||||
val i3 = Identifier("name")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,23 +4,21 @@
|
|||||||
// ERROR: Unresolved reference: close
|
// ERROR: Unresolved reference: close
|
||||||
import java.io.*
|
import java.io.*
|
||||||
|
|
||||||
class FileRead {
|
object FileRead {
|
||||||
companion object {
|
public fun main(args: Array<String>) {
|
||||||
public fun main(args: Array<String>) {
|
try {
|
||||||
try {
|
val fstream = FileInputStream()
|
||||||
val fstream = FileInputStream()
|
val `in` = DataInputStream(fstream)
|
||||||
val `in` = DataInputStream(fstream)
|
val br = BufferedReader(InputStreamReader(`in`))
|
||||||
val br = BufferedReader(InputStreamReader(`in`))
|
val strLine: String
|
||||||
val strLine: String
|
while ((strLine = br.readLine()) != null) {
|
||||||
while ((strLine = br.readLine()) != null) {
|
System.out.println(strLine)
|
||||||
System.out.println(strLine)
|
|
||||||
}
|
|
||||||
`in`.close()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
System.err.println("Error: " + e.getMessage())
|
|
||||||
}
|
}
|
||||||
|
`in`.close()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
System.err.println("Error: " + e.getMessage())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,8 @@ class Container {
|
|||||||
var myString = "1"
|
var myString = "1"
|
||||||
}
|
}
|
||||||
|
|
||||||
class One {
|
object One {
|
||||||
companion object {
|
var myContainer = Container()
|
||||||
var myContainer = Container()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class StringContainer(s: String)
|
class StringContainer(s: String)
|
||||||
|
|||||||
@@ -4,10 +4,8 @@ class Container {
|
|||||||
var myInt = 1
|
var myInt = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
class One {
|
object One {
|
||||||
companion object {
|
var myContainer = Container()
|
||||||
var myContainer = Container()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class IntContainer(i: Int)
|
class IntContainer(i: Int)
|
||||||
|
|||||||
@@ -4,10 +4,8 @@ class Container {
|
|||||||
var myInt = 1
|
var myInt = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
class One {
|
object One {
|
||||||
companion object {
|
var myContainer = Container()
|
||||||
var myContainer = Container()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Test {
|
class Test {
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
class Test {
|
object Test {
|
||||||
companion object {
|
public fun toFileSystemSafeName(name: String): String {
|
||||||
public fun toFileSystemSafeName(name: String): String {
|
val size = name.length()
|
||||||
val size = name.length()
|
return name
|
||||||
return name
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,10 +4,8 @@ class Container {
|
|||||||
var myInt = 1
|
var myInt = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
class One {
|
object One {
|
||||||
companion object {
|
var myContainer = Container()
|
||||||
var myContainer = Container()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Test {
|
class Test {
|
||||||
|
|||||||
@@ -5,17 +5,15 @@ import java.io.File
|
|||||||
/**
|
/**
|
||||||
* User: ignatov
|
* User: ignatov
|
||||||
*/
|
*/
|
||||||
public class Test {
|
public object Test {
|
||||||
companion object {
|
public fun isDir(parent: File?): Boolean {
|
||||||
public fun isDir(parent: File?): Boolean {
|
if (parent == null || !parent.exists()) {
|
||||||
if (parent == null || !parent.exists()) {
|
return false
|
||||||
return false
|
|
||||||
}
|
|
||||||
val result = true
|
|
||||||
if (parent.isDirectory()) {
|
|
||||||
return true
|
|
||||||
} else
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
val result = true
|
||||||
|
if (parent.isDirectory()) {
|
||||||
|
return true
|
||||||
|
} else
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,10 +4,8 @@ class Container {
|
|||||||
var myBoolean = true
|
var myBoolean = true
|
||||||
}
|
}
|
||||||
|
|
||||||
class One {
|
object One {
|
||||||
companion object {
|
var myContainer = Container()
|
||||||
var myContainer = Container()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Test {
|
class Test {
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
package demo
|
package demo
|
||||||
|
|
||||||
class Program {
|
object Program {
|
||||||
companion object {
|
public fun main(args: Array<String>) {
|
||||||
public fun main(args: Array<String>) {
|
System.out.println("Halo!")
|
||||||
System.out.println("Halo!")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
class Test {
|
object Test {
|
||||||
companion object {
|
public fun getInt(i: Int): Int {
|
||||||
public fun getInt(i: Int): Int {
|
when (i) {
|
||||||
when (i) {
|
0 -> return 0
|
||||||
0 -> return 0
|
1 -> return 1
|
||||||
1 -> return 1
|
2 -> return 2
|
||||||
2 -> return 2
|
3 -> return 3
|
||||||
3 -> return 3
|
else -> return -1
|
||||||
else -> return -1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,9 @@
|
|||||||
import java.lang.reflect.Constructor
|
import java.lang.reflect.Constructor
|
||||||
|
|
||||||
class X {
|
object X {
|
||||||
companion object {
|
throws(javaClass<Exception>())
|
||||||
throws(javaClass<Exception>())
|
fun <T> foo(constructor: Constructor<T>, args1: Array<Any>, args2: Array<Any>) {
|
||||||
fun <T> foo(constructor: Constructor<T>, args1: Array<Any>, args2: Array<Any>) {
|
constructor.newInstance(*args1)
|
||||||
constructor.newInstance(*args1)
|
constructor.newInstance(args1, args2)
|
||||||
constructor.newInstance(args1, args2)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,86 +1,84 @@
|
|||||||
package demo
|
package demo
|
||||||
|
|
||||||
public class SwitchDemo {
|
public object SwitchDemo {
|
||||||
companion object {
|
public fun print(o: Any) {
|
||||||
public fun print(o: Any) {
|
System.out.println(o)
|
||||||
System.out.println(o)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public fun test(i: Int) {
|
public fun test(i: Int) {
|
||||||
var monthString = "<empty>"
|
var monthString = "<empty>"
|
||||||
when (i) {
|
when (i) {
|
||||||
1 -> {
|
1 -> {
|
||||||
print(1)
|
print(1)
|
||||||
print(2)
|
print(2)
|
||||||
print(3)
|
print(3)
|
||||||
print(4)
|
print(4)
|
||||||
print(5)
|
print(5)
|
||||||
}
|
|
||||||
2 -> {
|
|
||||||
print(2)
|
|
||||||
print(3)
|
|
||||||
print(4)
|
|
||||||
print(5)
|
|
||||||
}
|
|
||||||
3 -> {
|
|
||||||
print(3)
|
|
||||||
print(4)
|
|
||||||
print(5)
|
|
||||||
}
|
|
||||||
4 -> {
|
|
||||||
print(4)
|
|
||||||
print(5)
|
|
||||||
}
|
|
||||||
5 -> print(5)
|
|
||||||
6 -> {
|
|
||||||
print(6)
|
|
||||||
print(7)
|
|
||||||
print(8)
|
|
||||||
print(9)
|
|
||||||
print(10)
|
|
||||||
print(11)
|
|
||||||
monthString = "December"
|
|
||||||
}
|
|
||||||
7 -> {
|
|
||||||
print(7)
|
|
||||||
print(8)
|
|
||||||
print(9)
|
|
||||||
print(10)
|
|
||||||
print(11)
|
|
||||||
monthString = "December"
|
|
||||||
}
|
|
||||||
8 -> {
|
|
||||||
print(8)
|
|
||||||
print(9)
|
|
||||||
print(10)
|
|
||||||
print(11)
|
|
||||||
monthString = "December"
|
|
||||||
}
|
|
||||||
9 -> {
|
|
||||||
print(9)
|
|
||||||
print(10)
|
|
||||||
print(11)
|
|
||||||
monthString = "December"
|
|
||||||
}
|
|
||||||
10 -> {
|
|
||||||
print(10)
|
|
||||||
print(11)
|
|
||||||
monthString = "December"
|
|
||||||
}
|
|
||||||
11 -> {
|
|
||||||
print(11)
|
|
||||||
monthString = "December"
|
|
||||||
}
|
|
||||||
12 -> monthString = "December"
|
|
||||||
else -> monthString = "Invalid month"
|
|
||||||
}
|
}
|
||||||
System.out.println(monthString)
|
2 -> {
|
||||||
|
print(2)
|
||||||
|
print(3)
|
||||||
|
print(4)
|
||||||
|
print(5)
|
||||||
|
}
|
||||||
|
3 -> {
|
||||||
|
print(3)
|
||||||
|
print(4)
|
||||||
|
print(5)
|
||||||
|
}
|
||||||
|
4 -> {
|
||||||
|
print(4)
|
||||||
|
print(5)
|
||||||
|
}
|
||||||
|
5 -> print(5)
|
||||||
|
6 -> {
|
||||||
|
print(6)
|
||||||
|
print(7)
|
||||||
|
print(8)
|
||||||
|
print(9)
|
||||||
|
print(10)
|
||||||
|
print(11)
|
||||||
|
monthString = "December"
|
||||||
|
}
|
||||||
|
7 -> {
|
||||||
|
print(7)
|
||||||
|
print(8)
|
||||||
|
print(9)
|
||||||
|
print(10)
|
||||||
|
print(11)
|
||||||
|
monthString = "December"
|
||||||
|
}
|
||||||
|
8 -> {
|
||||||
|
print(8)
|
||||||
|
print(9)
|
||||||
|
print(10)
|
||||||
|
print(11)
|
||||||
|
monthString = "December"
|
||||||
|
}
|
||||||
|
9 -> {
|
||||||
|
print(9)
|
||||||
|
print(10)
|
||||||
|
print(11)
|
||||||
|
monthString = "December"
|
||||||
|
}
|
||||||
|
10 -> {
|
||||||
|
print(10)
|
||||||
|
print(11)
|
||||||
|
monthString = "December"
|
||||||
|
}
|
||||||
|
11 -> {
|
||||||
|
print(11)
|
||||||
|
monthString = "December"
|
||||||
|
}
|
||||||
|
12 -> monthString = "December"
|
||||||
|
else -> monthString = "Invalid month"
|
||||||
}
|
}
|
||||||
|
System.out.println(monthString)
|
||||||
|
}
|
||||||
|
|
||||||
public fun main(args: Array<String>) {
|
public fun main(args: Array<String>) {
|
||||||
for (i in 1..12)
|
for (i in 1..12)
|
||||||
test(i)
|
test(i)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
public class NonDefault {
|
public object NonDefault {
|
||||||
companion object {
|
public fun main(args: Array<String>) {
|
||||||
public fun main(args: Array<String>) {
|
|
||||||
|
|
||||||
val value = 3
|
val value = 3
|
||||||
val valueString = ""
|
val valueString = ""
|
||||||
when (value) {
|
when (value) {
|
||||||
|
|
||||||
}
|
|
||||||
System.out.println(valueString)
|
|
||||||
}
|
}
|
||||||
|
System.out.println(valueString)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,14 @@
|
|||||||
package switch_demo
|
package switch_demo
|
||||||
|
|
||||||
public class SwitchDemo {
|
public object SwitchDemo {
|
||||||
companion object {
|
public fun main(args: Array<String>) {
|
||||||
public fun main(args: Array<String>) {
|
val month = 8
|
||||||
val month = 8
|
val monthString: String
|
||||||
val monthString: String
|
when (month) {
|
||||||
when (month) {
|
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 -> monthString = "December"
|
||||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 -> monthString = "December"
|
else -> monthString = "Invalid month"
|
||||||
else -> monthString = "Invalid month"
|
|
||||||
}
|
|
||||||
System.out.println(monthString)
|
|
||||||
}
|
}
|
||||||
|
System.out.println(monthString)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,21 @@
|
|||||||
public class C {
|
public object C {
|
||||||
companion object {
|
public fun main(args: Array<String>) {
|
||||||
public fun main(args: Array<String>) {
|
when (args.size()) {
|
||||||
when (args.size()) {
|
1 -> {
|
||||||
1 -> {
|
run {
|
||||||
run {
|
val a = 1
|
||||||
val a = 1
|
System.out.print("1")
|
||||||
System.out.print("1")
|
|
||||||
}
|
|
||||||
run {
|
|
||||||
val a = 2
|
|
||||||
System.out.print("2")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
run {
|
||||||
2 -> {
|
|
||||||
val a = 2
|
val a = 2
|
||||||
System.out.print("2")
|
System.out.print("2")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2 -> {
|
||||||
|
val a = 2
|
||||||
|
System.out.print("2")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,26 @@
|
|||||||
package switch_demo
|
package switch_demo
|
||||||
|
|
||||||
public class SwitchDemo {
|
public object SwitchDemo {
|
||||||
companion object {
|
public fun main(args: Array<String>) {
|
||||||
public fun main(args: Array<String>) {
|
|
||||||
|
|
||||||
val month = 8
|
val month = 8
|
||||||
val monthString: String
|
val monthString: String
|
||||||
when (month) {
|
when (month) {
|
||||||
1 -> monthString = "January"
|
1 -> monthString = "January"
|
||||||
2 -> monthString = "February"
|
2 -> monthString = "February"
|
||||||
3 -> monthString = "March"
|
3 -> monthString = "March"
|
||||||
4 -> monthString = "April"
|
4 -> monthString = "April"
|
||||||
5 -> monthString = "May"
|
5 -> monthString = "May"
|
||||||
6 -> monthString = "June"
|
6 -> monthString = "June"
|
||||||
7 -> monthString = "July"
|
7 -> monthString = "July"
|
||||||
8 -> monthString = "August"
|
8 -> monthString = "August"
|
||||||
9 -> monthString = "September"
|
9 -> monthString = "September"
|
||||||
10 -> monthString = "October"
|
10 -> monthString = "October"
|
||||||
11 -> monthString = "November"
|
11 -> monthString = "November"
|
||||||
12 -> monthString = "December"
|
12 -> monthString = "December"
|
||||||
else -> monthString = "Invalid month"
|
else -> monthString = "Invalid month"
|
||||||
}
|
|
||||||
System.out.println(monthString)
|
|
||||||
}
|
}
|
||||||
|
System.out.println(monthString)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,14 @@
|
|||||||
public class NonDefault {
|
public object NonDefault {
|
||||||
companion object {
|
public fun main(args: Array<String>) {
|
||||||
public fun main(args: Array<String>) {
|
|
||||||
|
|
||||||
val value = 3
|
val value = 3
|
||||||
var valueString = ""
|
var valueString = ""
|
||||||
when (value) {
|
when (value) {
|
||||||
1 -> valueString = "ONE"
|
1 -> valueString = "ONE"
|
||||||
2 -> valueString = "TWO"
|
2 -> valueString = "TWO"
|
||||||
3 -> valueString = "THREE"
|
3 -> valueString = "THREE"
|
||||||
}
|
|
||||||
System.out.println(valueString)
|
|
||||||
}
|
}
|
||||||
|
System.out.println(valueString)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
// ERROR: Type inference failed. Expected type mismatch: found: java.util.HashMap<kotlin.Any!, kotlin.Any!> required: kotlin.Map<kotlin.String, kotlin.String>
|
// ERROR: Type inference failed. Expected type mismatch: found: java.util.HashMap<kotlin.Any!, kotlin.Any!> required: kotlin.Map<kotlin.String, kotlin.String>
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class A {
|
object A {
|
||||||
companion object {
|
public fun foo(): Map<String, String> {
|
||||||
public fun foo(): Map<String, String> {
|
val props = Properties()
|
||||||
val props = Properties()
|
return HashMap(props as Map<Any, Any>)
|
||||||
return HashMap(props as Map<Any, Any>)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,7 +119,7 @@ public abstract class AbstractJavaToKotlinConverterSingleFileTest : AbstractJava
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun methodToKotlin(text: String, settings: ConverterSettings, project: Project): String {
|
private fun methodToKotlin(text: String, settings: ConverterSettings, project: Project): String {
|
||||||
val result = fileToKotlin("final class C {" + text + "}", settings, project).replaceAll("class C \\{", "")
|
val result = fileToKotlin("final class C {" + text + "}", settings, project).replaceAll("class C \\{", "").replaceAll("object C \\{", "")
|
||||||
return result.substring(0, (result.lastIndexOf("}"))).trim()
|
return result.substring(0, (result.lastIndexOf("}"))).trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -886,6 +886,12 @@ public class JavaToKotlinConverterForWebDemoTestGenerated extends AbstractJavaTo
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("notUtilityClass.java")
|
||||||
|
public void testNotUtilityClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/class/notUtilityClass.java");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("oneStaticFieldOneNonStatic.java")
|
@TestMetadata("oneStaticFieldOneNonStatic.java")
|
||||||
public void testOneStaticFieldOneNonStatic() throws Exception {
|
public void testOneStaticFieldOneNonStatic() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/class/oneStaticFieldOneNonStatic.java");
|
String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/class/oneStaticFieldOneNonStatic.java");
|
||||||
@@ -939,6 +945,24 @@ public class JavaToKotlinConverterForWebDemoTestGenerated extends AbstractJavaTo
|
|||||||
String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/class/twoStaticMethod.java");
|
String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/class/twoStaticMethod.java");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("utilityClass1.java")
|
||||||
|
public void testUtilityClass1() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/class/utilityClass1.java");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("utilityClass2.java")
|
||||||
|
public void testUtilityClass2() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/class/utilityClass2.java");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("utilityClass3.java")
|
||||||
|
public void testUtilityClass3() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/class/utilityClass3.java");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("j2k/testData/fileOrElement/classExpression")
|
@TestMetadata("j2k/testData/fileOrElement/classExpression")
|
||||||
|
|||||||
@@ -886,6 +886,12 @@ public class JavaToKotlinConverterSingleFileTestGenerated extends AbstractJavaTo
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("notUtilityClass.java")
|
||||||
|
public void testNotUtilityClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/class/notUtilityClass.java");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("oneStaticFieldOneNonStatic.java")
|
@TestMetadata("oneStaticFieldOneNonStatic.java")
|
||||||
public void testOneStaticFieldOneNonStatic() throws Exception {
|
public void testOneStaticFieldOneNonStatic() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/class/oneStaticFieldOneNonStatic.java");
|
String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/class/oneStaticFieldOneNonStatic.java");
|
||||||
@@ -939,6 +945,24 @@ public class JavaToKotlinConverterSingleFileTestGenerated extends AbstractJavaTo
|
|||||||
String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/class/twoStaticMethod.java");
|
String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/class/twoStaticMethod.java");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("utilityClass1.java")
|
||||||
|
public void testUtilityClass1() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/class/utilityClass1.java");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("utilityClass2.java")
|
||||||
|
public void testUtilityClass2() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/class/utilityClass2.java");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("utilityClass3.java")
|
||||||
|
public void testUtilityClass3() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/class/utilityClass3.java");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("j2k/testData/fileOrElement/classExpression")
|
@TestMetadata("j2k/testData/fileOrElement/classExpression")
|
||||||
|
|||||||
Reference in New Issue
Block a user