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