Add platformStatic annotation to main method from java
#KT-8219 Fixed
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package to
|
||||
|
||||
import kotlin.platform.platformStatic
|
||||
|
||||
public object JavaClass {
|
||||
public fun main(args: Array<String>) {
|
||||
platformStatic public fun main(args: Array<String>) {
|
||||
println("Hello, world!")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -148,17 +148,7 @@ class Converter private constructor(
|
||||
|
||||
private fun convertFile(javaFile: PsiJavaFile): File {
|
||||
var convertedChildren = javaFile.getChildren().map { convertTopElement(it) }.filterNotNull()
|
||||
return File(convertedChildren, createMainFunction(javaFile)).assignPrototype(javaFile)
|
||||
}
|
||||
|
||||
private fun createMainFunction(file: PsiJavaFile): String? {
|
||||
for (`class` in file.getClasses()) {
|
||||
val mainMethod = PsiMethodUtil.findMainMethod(`class`)
|
||||
if (mainMethod != null) {
|
||||
return "fun main(args: Array<String>) = ${`class`.getName()}.${mainMethod.getName()}(args)"
|
||||
}
|
||||
}
|
||||
return null
|
||||
return File(convertedChildren).assignPrototype(javaFile)
|
||||
}
|
||||
|
||||
public fun convertAnnotations(owner: PsiModifierListOwner): Annotations
|
||||
@@ -428,6 +418,17 @@ class Converter private constructor(
|
||||
|
||||
if (function == null) return null
|
||||
|
||||
if (PsiMethodUtil.isMainMethod(method)) {
|
||||
val fqName = FqName("kotlin.platform.platformStatic")
|
||||
val identifier = Identifier(fqName.shortName().identifier, imports = listOf(fqName)).assignNoPrototype()
|
||||
|
||||
function.annotations += Annotations(
|
||||
listOf(Annotation(identifier,
|
||||
listOf(),
|
||||
withAt = false,
|
||||
newLineAfter = false).assignNoPrototype())).assignNoPrototype()
|
||||
}
|
||||
|
||||
if (function.parameterList.parameters.any { it.defaultValue != null } && !function.modifiers.isPrivate) {
|
||||
function.annotations += Annotations(
|
||||
listOf(Annotation(Identifier("jvmOverloads").assignNoPrototype(),
|
||||
|
||||
@@ -25,11 +25,8 @@ class PackageStatement(val packageName: String) : Element() {
|
||||
}
|
||||
}
|
||||
|
||||
class File(val elements: List<Element>, val mainFunction: String?) : Element() {
|
||||
class File(val elements: List<Element>) : Element() {
|
||||
override fun generateCode(builder: CodeBuilder) {
|
||||
builder.append(elements, "\n")
|
||||
if (mainFunction != null) {
|
||||
builder append "\n\n" append mainFunction
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import kotlin.platform.platformStatic
|
||||
|
||||
public object A {
|
||||
public fun main(args: Array<String>) {
|
||||
platformStatic public fun main(args: Array<String>) {
|
||||
println(Void.TYPE)
|
||||
println(Integer.TYPE)
|
||||
println(java.lang.Double.TYPE)
|
||||
@@ -8,5 +10,3 @@ public object A {
|
||||
println(javaClass<Array<Array<Any>>>())
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) = A.main(args)
|
||||
+4
-4
@@ -1,5 +1,7 @@
|
||||
import kotlin.platform.platformStatic
|
||||
|
||||
public object TestClass {
|
||||
public fun main(args: Array<String>) {
|
||||
platformStatic public fun main(args: Array<String>) {
|
||||
var i = 0
|
||||
while (i < 10) {
|
||||
if (i == 4 || i == 8) {
|
||||
@@ -11,6 +13,4 @@ public object TestClass {
|
||||
++i
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) = TestClass.main(args)
|
||||
}
|
||||
+4
-4
@@ -1,5 +1,7 @@
|
||||
import kotlin.platform.platformStatic
|
||||
|
||||
public object TestClass {
|
||||
public fun main(args: Array<String>) {
|
||||
platformStatic public fun main(args: Array<String>) {
|
||||
var i = 0
|
||||
var j = 1
|
||||
while (i < 10) {
|
||||
@@ -14,6 +16,4 @@ public object TestClass {
|
||||
j *= 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) = TestClass.main(args)
|
||||
}
|
||||
+4
-4
@@ -1,5 +1,7 @@
|
||||
import kotlin.platform.platformStatic
|
||||
|
||||
public object TestClass {
|
||||
public fun main(args: Array<String>) {
|
||||
platformStatic public fun main(args: Array<String>) {
|
||||
var i = 1
|
||||
while (i < 1000) {
|
||||
if (i == 4 || i == 8) {
|
||||
@@ -10,6 +12,4 @@ public object TestClass {
|
||||
i *= 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) = TestClass.main(args)
|
||||
}
|
||||
+4
-4
@@ -1,5 +1,7 @@
|
||||
import kotlin.platform.platformStatic
|
||||
|
||||
public object TestClass {
|
||||
public fun main(args: Array<String>) {
|
||||
platformStatic public fun main(args: Array<String>) {
|
||||
var i = 1
|
||||
OuterLoop1@ OuterLoop2@ while (i < 1000) {
|
||||
var j = 1
|
||||
@@ -22,6 +24,4 @@ public object TestClass {
|
||||
i *= 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) = TestClass.main(args)
|
||||
}
|
||||
+4
-1
@@ -1,2 +1,5 @@
|
||||
public fun main(args: Array<String>) {
|
||||
import kotlin.platform.platformStatic
|
||||
|
||||
|
||||
platformStatic public fun main(args: Array<String>) {
|
||||
}
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
public object A {
|
||||
public fun main(args: Array<String>) {
|
||||
}
|
||||
}
|
||||
import kotlin.platform.platformStatic
|
||||
|
||||
fun main(args: Array<String>) = A.main(args)
|
||||
public object A {
|
||||
platformStatic public fun main(args: Array<String>) {
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import kotlin.platform.platformStatic
|
||||
|
||||
// !forceNotNullTypes: false
|
||||
public object A {
|
||||
public fun main(args: Array<String>) {
|
||||
platformStatic public fun main(args: Array<String>) {
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) = A.main(args)
|
||||
}
|
||||
+4
-4
@@ -1,4 +1,6 @@
|
||||
// ERROR: Property must be initialized or be abstract
|
||||
import kotlin.platform.platformStatic
|
||||
|
||||
public class Identifier<T> {
|
||||
public val name: T
|
||||
private val myHasDollar: Boolean
|
||||
@@ -21,11 +23,9 @@ public class Identifier<T> {
|
||||
}
|
||||
|
||||
public object User {
|
||||
public fun main(args: Array<String>) {
|
||||
platformStatic public fun main(args: Array<String>) {
|
||||
val i1 = Identifier("name", false, true)
|
||||
val i2 = Identifier("name", false)
|
||||
val i3 = Identifier("name")
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) = User.main(args)
|
||||
}
|
||||
+3
-4
@@ -3,9 +3,10 @@
|
||||
// ERROR: Assignments are not expressions, and only expressions are allowed in this context
|
||||
// ERROR: Unresolved reference: close
|
||||
import java.io.*
|
||||
import kotlin.platform.platformStatic
|
||||
|
||||
object FileRead {
|
||||
public fun main(args: Array<String>) {
|
||||
platformStatic public fun main(args: Array<String>) {
|
||||
try {
|
||||
val fstream = FileInputStream()
|
||||
val `in` = DataInputStream(fstream)
|
||||
@@ -20,6 +21,4 @@ object FileRead {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) = FileRead.main(args)
|
||||
}
|
||||
+4
-4
@@ -1,9 +1,9 @@
|
||||
package demo
|
||||
|
||||
import kotlin.platform.platformStatic
|
||||
|
||||
object Program {
|
||||
public fun main(args: Array<String>) {
|
||||
platformStatic public fun main(args: Array<String>) {
|
||||
println("Halo!")
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) = Program.main(args)
|
||||
}
|
||||
+4
-4
@@ -1,5 +1,7 @@
|
||||
package demo
|
||||
|
||||
import kotlin.platform.platformStatic
|
||||
|
||||
public object SwitchDemo {
|
||||
public fun print(o: Any) {
|
||||
println(o)
|
||||
@@ -76,10 +78,8 @@ public object SwitchDemo {
|
||||
println(monthString)
|
||||
}
|
||||
|
||||
public fun main(args: Array<String>) {
|
||||
platformStatic public fun main(args: Array<String>) {
|
||||
for (i in 1..12)
|
||||
test(i)
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) = SwitchDemo.main(args)
|
||||
}
|
||||
+4
-4
@@ -1,5 +1,7 @@
|
||||
import kotlin.platform.platformStatic
|
||||
|
||||
public object NonDefault {
|
||||
public fun main(args: Array<String>) {
|
||||
platformStatic public fun main(args: Array<String>) {
|
||||
|
||||
val value = 3
|
||||
val valueString = ""
|
||||
@@ -8,6 +10,4 @@ public object NonDefault {
|
||||
}
|
||||
println(valueString)
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) = NonDefault.main(args)
|
||||
}
|
||||
+4
-4
@@ -1,7 +1,9 @@
|
||||
package switch_demo
|
||||
|
||||
import kotlin.platform.platformStatic
|
||||
|
||||
public object SwitchDemo {
|
||||
public fun main(args: Array<String>) {
|
||||
platformStatic public fun main(args: Array<String>) {
|
||||
val month = 8
|
||||
val monthString: String
|
||||
when (month) {
|
||||
@@ -10,6 +12,4 @@ public object SwitchDemo {
|
||||
}
|
||||
println(monthString)
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) = SwitchDemo.main(args)
|
||||
}
|
||||
+4
-4
@@ -1,5 +1,7 @@
|
||||
import kotlin.platform.platformStatic
|
||||
|
||||
public object C {
|
||||
public fun main(args: Array<String>) {
|
||||
platformStatic public fun main(args: Array<String>) {
|
||||
when (args.size()) {
|
||||
1 -> {
|
||||
run {
|
||||
@@ -18,6 +20,4 @@ public object C {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) = C.main(args)
|
||||
}
|
||||
+4
-4
@@ -1,7 +1,9 @@
|
||||
package switch_demo
|
||||
|
||||
import kotlin.platform.platformStatic
|
||||
|
||||
public object SwitchDemo {
|
||||
public fun main(args: Array<String>) {
|
||||
platformStatic public fun main(args: Array<String>) {
|
||||
|
||||
val month = 8
|
||||
val monthString: String
|
||||
@@ -22,6 +24,4 @@ public object SwitchDemo {
|
||||
}
|
||||
println(monthString)
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) = SwitchDemo.main(args)
|
||||
}
|
||||
+4
-4
@@ -1,5 +1,7 @@
|
||||
import kotlin.platform.platformStatic
|
||||
|
||||
public object NonDefault {
|
||||
public fun main(args: Array<String>) {
|
||||
platformStatic public fun main(args: Array<String>) {
|
||||
|
||||
val value = 3
|
||||
var valueString = ""
|
||||
@@ -10,6 +12,4 @@ public object NonDefault {
|
||||
}
|
||||
println(valueString)
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) = NonDefault.main(args)
|
||||
}
|
||||
Reference in New Issue
Block a user