rename platformStatic to jvmStatic

This commit is contained in:
Dmitry Jemerov
2015-08-21 12:57:54 +02:00
parent 4053c19260
commit 341f09afd3
51 changed files with 145 additions and 181 deletions
@@ -45,8 +45,8 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
static {
MAP.put(ErrorsJvm.CONFLICTING_JVM_DECLARATIONS, "Platform declaration clash: {0}", CONFLICTING_JVM_DECLARATIONS_DATA);
MAP.put(ErrorsJvm.ACCIDENTAL_OVERRIDE, "Accidental override: {0}", CONFLICTING_JVM_DECLARATIONS_DATA);
MAP.put(ErrorsJvm.PLATFORM_STATIC_NOT_IN_OBJECT, "Only functions in named objects and companion objects of classes can be annotated with 'platformStatic'");
MAP.put(ErrorsJvm.OVERRIDE_CANNOT_BE_STATIC, "Override member cannot be 'platformStatic' in object");
MAP.put(ErrorsJvm.JVM_STATIC_NOT_IN_OBJECT, "Only functions in named objects and companion objects of classes can be annotated with 'jvmStatic'");
MAP.put(ErrorsJvm.OVERRIDE_CANNOT_BE_STATIC, "Override member cannot be 'jvmStatic' in object");
MAP.put(ErrorsJvm.OVERLOADS_WITHOUT_DEFAULT_ARGUMENTS, "''jvmOverloads'' annotation has no effect for methods without default arguments");
MAP.put(ErrorsJvm.OVERLOADS_ABSTRACT, "''jvmOverloads'' annotation cannot be used on abstract methods");
MAP.put(ErrorsJvm.OVERLOADS_PRIVATE, "''jvmOverloads'' annotation has no effect on private and local declarations");
@@ -18,8 +18,6 @@ package org.jetbrains.kotlin.resolve.jvm.diagnostics;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory0;
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory1;
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory2;
@@ -42,7 +40,7 @@ public interface ErrorsJvm {
DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
DiagnosticFactory0<JetDeclaration> OVERRIDE_CANNOT_BE_STATIC = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
DiagnosticFactory0<JetDeclaration> PLATFORM_STATIC_NOT_IN_OBJECT = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
DiagnosticFactory0<JetDeclaration> JVM_STATIC_NOT_IN_OBJECT = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
DiagnosticFactory0<JetDeclaration> OVERLOADS_WITHOUT_DEFAULT_ARGUMENTS = DiagnosticFactory0.create(WARNING, DECLARATION_SIGNATURE);
DiagnosticFactory0<JetDeclaration> OVERLOADS_ABSTRACT = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
@@ -150,7 +150,7 @@ public class PlatformStaticAnnotationChecker : DeclarationChecker {
container.getContainingDeclaration().let { DescriptorUtils.isClass(it) || DescriptorUtils.isEnumClass(it) }
if (!insideObject && !insideCompanionObjectInClass) {
diagnosticHolder.report(ErrorsJvm.PLATFORM_STATIC_NOT_IN_OBJECT.on(declaration))
diagnosticHolder.report(ErrorsJvm.JVM_STATIC_NOT_IN_OBJECT.on(declaration))
}
val checkDeclaration = when(declaration) {
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorUtils
public fun DeclarationDescriptor.hasInlineAnnotation(): Boolean {
@@ -29,7 +28,8 @@ public fun DeclarationDescriptor.hasInlineAnnotation(): Boolean {
}
public fun DeclarationDescriptor.hasPlatformStaticAnnotation(): Boolean {
return getAnnotations().findAnnotation(FqName("kotlin.platform.platformStatic")) != null
return getAnnotations().findAnnotation(FqName("kotlin.platform.platformStatic")) != null ||
getAnnotations().findAnnotation(FqName("kotlin.jvm.jvmStatic")) != null
}
public fun DeclarationDescriptor.findPublicFieldAnnotation(): AnnotationDescriptor? {
@@ -1,4 +1,4 @@
import kotlin.platform.platformStatic
import kotlin.jvm.jvmStatic
annotation(retention = AnnotationRetention.RUNTIME) class testAnnotation
@@ -7,14 +7,14 @@ class A {
companion object {
val b: String = "OK"
platformStatic testAnnotation fun test1() = b
jvmStatic testAnnotation fun test1() = b
}
}
object B {
val b: String = "OK"
platformStatic testAnnotation fun test1() = b
jvmStatic testAnnotation fun test1() = b
}
fun box(): String {
@@ -1,17 +1,17 @@
import kotlin.platform.platformStatic
import kotlin.jvm.jvmStatic
class A {
companion object {
val b: String = "OK"
platformStatic val c: String = "OK"
jvmStatic val c: String = "OK"
platformStatic fun test1() = b
jvmStatic fun test1() = b
platformStatic fun test2() = b
jvmStatic fun test2() = b
platformStatic fun String.test3() = this + b
jvmStatic fun String.test3() = this + b
}
}
@@ -1,13 +1,13 @@
import kotlin.platform.platformStatic
import kotlin.jvm.jvmStatic
enum class A {
;
companion object {
val foo: String = "OK"
platformStatic val bar: String = "OK"
jvmStatic val bar: String = "OK"
platformStatic fun baz() = foo
jvmStatic fun baz() = foo
}
}
@@ -1,16 +1,16 @@
import kotlin.platform.platformStatic
import kotlin.jvm.jvmStatic
object A {
val b: String = "OK"
platformStatic val c: String = "OK"
jvmStatic val c: String = "OK"
platformStatic fun test1() = b
jvmStatic fun test1() = b
platformStatic fun test2() = b
jvmStatic fun test2() = b
platformStatic fun String.test3() = this + b
jvmStatic fun String.test3() = this + b
}
fun box(): String {
@@ -1,9 +1,9 @@
import kotlin.platform.platformStatic
import kotlin.jvm.jvmStatic
class A {
<!WRONG_ANNOTATION_TARGET!>platformStatic<!> constructor() {}
<!WRONG_ANNOTATION_TARGET!>jvmStatic<!> constructor() {}
inner class B {
<!WRONG_ANNOTATION_TARGET!>platformStatic<!> constructor() {}
<!WRONG_ANNOTATION_TARGET!>jvmStatic<!> constructor() {}
}
}
class C <!WRONG_ANNOTATION_TARGET!>platformStatic<!> constructor()
class C <!WRONG_ANNOTATION_TARGET!>jvmStatic<!> constructor()
@@ -1,13 +1,13 @@
package
internal final class A {
kotlin.platform.platformStatic() public constructor A()
kotlin.jvm.jvmStatic() public constructor A()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
internal final inner class B {
kotlin.platform.platformStatic() public constructor B()
kotlin.jvm.jvmStatic() public constructor B()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
@@ -15,7 +15,7 @@ internal final class A {
}
internal final class C {
kotlin.platform.platformStatic() public constructor C()
kotlin.jvm.jvmStatic() public constructor C()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
@@ -1,5 +1,5 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
import kotlin.platform.platformStatic
import kotlin.jvm.jvmStatic
abstract class A {
@@ -12,24 +12,24 @@ abstract class A {
object B: A() {
<!OVERRIDE_CANNOT_BE_STATIC!>@platformStatic override fun a()<!> {}
<!OVERRIDE_CANNOT_BE_STATIC!>@jvmStatic override fun a()<!> {}
<!OVERRIDE_CANNOT_BE_STATIC!>@platformStatic override fun b()<!> {}
<!OVERRIDE_CANNOT_BE_STATIC!>@jvmStatic override fun b()<!> {}
<!OVERRIDE_CANNOT_BE_STATIC!>@platformStatic final override fun c()<!> {}
<!OVERRIDE_CANNOT_BE_STATIC!>@jvmStatic final override fun c()<!> {}
@platformStatic open fun d() {}
@jvmStatic open fun d() {}
}
class C {
companion object: A() {
@platformStatic override fun a() {}
@jvmStatic override fun a() {}
@platformStatic override fun b() {}
@jvmStatic override fun b() {}
@platformStatic final override fun c() {}
@jvmStatic final override fun c() {}
@platformStatic open fun d() {}
@jvmStatic open fun d() {}
}
}
@@ -12,10 +12,10 @@ internal abstract class A {
internal object B : A {
private constructor B()
kotlin.platform.platformStatic() internal open override /*1*/ fun a(): kotlin.Unit
kotlin.platform.platformStatic() internal open override /*1*/ fun b(): kotlin.Unit
kotlin.platform.platformStatic() internal final override /*1*/ fun c(): kotlin.Unit
kotlin.platform.platformStatic() internal open fun d(): kotlin.Unit
kotlin.jvm.jvmStatic() internal open override /*1*/ fun a(): kotlin.Unit
kotlin.jvm.jvmStatic() internal open override /*1*/ fun b(): kotlin.Unit
kotlin.jvm.jvmStatic() internal final override /*1*/ fun c(): kotlin.Unit
kotlin.jvm.jvmStatic() internal open fun d(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
@@ -29,10 +29,10 @@ internal final class C {
public companion object Companion : A {
private constructor Companion()
kotlin.platform.platformStatic() internal open override /*1*/ fun a(): kotlin.Unit
kotlin.platform.platformStatic() internal open override /*1*/ fun b(): kotlin.Unit
kotlin.platform.platformStatic() internal final override /*1*/ fun c(): kotlin.Unit
kotlin.platform.platformStatic() internal open fun d(): kotlin.Unit
kotlin.jvm.jvmStatic() internal open override /*1*/ fun a(): kotlin.Unit
kotlin.jvm.jvmStatic() internal open override /*1*/ fun b(): kotlin.Unit
kotlin.jvm.jvmStatic() internal final override /*1*/ fun c(): kotlin.Unit
kotlin.jvm.jvmStatic() internal open fun d(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
@@ -1,54 +1,54 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
import kotlin.platform.platformStatic
import kotlin.jvm.jvmStatic
class A {
companion object {
platformStatic fun a1() {
jvmStatic fun a1() {
}
}
object A {
platformStatic fun a2() {
jvmStatic fun a2() {
}
}
fun test() {
val s = object {
<!PLATFORM_STATIC_NOT_IN_OBJECT!>platformStatic fun a3()<!> {
<!JVM_STATIC_NOT_IN_OBJECT!>jvmStatic fun a3()<!> {
}
}
}
<!PLATFORM_STATIC_NOT_IN_OBJECT!>platformStatic fun a4()<!> {
<!JVM_STATIC_NOT_IN_OBJECT!>jvmStatic fun a4()<!> {
}
}
interface B {
companion object {
<!PLATFORM_STATIC_NOT_IN_OBJECT!>platformStatic fun a1()<!> {
<!JVM_STATIC_NOT_IN_OBJECT!>jvmStatic fun a1()<!> {
}
}
object A {
platformStatic fun a2() {
jvmStatic fun a2() {
}
}
fun test() {
val s = object {
<!PLATFORM_STATIC_NOT_IN_OBJECT!>platformStatic fun a3()<!> {
<!JVM_STATIC_NOT_IN_OBJECT!>jvmStatic fun a3()<!> {
}
}
}
<!PLATFORM_STATIC_NOT_IN_OBJECT!>platformStatic fun a4()<!> {
<!JVM_STATIC_NOT_IN_OBJECT!>jvmStatic fun a4()<!> {
}
}
@@ -2,7 +2,7 @@ package
internal final class A {
public constructor A()
kotlin.platform.platformStatic() internal final fun a4(): kotlin.Unit
kotlin.jvm.jvmStatic() internal final fun a4(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
internal final fun test(): kotlin.Unit
@@ -10,7 +10,7 @@ internal final class A {
internal object A {
private constructor A()
kotlin.platform.platformStatic() internal final fun a2(): kotlin.Unit
kotlin.jvm.jvmStatic() internal final fun a2(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
@@ -18,7 +18,7 @@ internal final class A {
public companion object Companion {
private constructor Companion()
kotlin.platform.platformStatic() internal final fun a1(): kotlin.Unit
kotlin.jvm.jvmStatic() internal final fun a1(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
@@ -26,7 +26,7 @@ internal final class A {
}
internal interface B {
kotlin.platform.platformStatic() internal open fun a4(): kotlin.Unit
kotlin.jvm.jvmStatic() internal open fun a4(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
internal open fun test(): kotlin.Unit
@@ -34,7 +34,7 @@ internal interface B {
internal object A {
private constructor A()
kotlin.platform.platformStatic() internal final fun a2(): kotlin.Unit
kotlin.jvm.jvmStatic() internal final fun a2(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
@@ -42,7 +42,7 @@ internal interface B {
public companion object Companion {
private constructor Companion()
kotlin.platform.platformStatic() internal final fun a1(): kotlin.Unit
kotlin.jvm.jvmStatic() internal final fun a1(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
@@ -1,8 +1,8 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
import kotlin.platform.platformStatic
import kotlin.jvm.jvmStatic
fun main(args: Array<String>) {
<!PLATFORM_STATIC_NOT_IN_OBJECT!>@platformStatic fun a()<!>{
<!JVM_STATIC_NOT_IN_OBJECT!>@jvmStatic fun a()<!>{
}
}
@@ -1,5 +1,5 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
import kotlin.platform.platformStatic
import kotlin.jvm.jvmStatic
open class B {
public open val base1 : Int = 1
@@ -9,38 +9,38 @@ open class B {
class A {
companion object : B() {
var p1:Int = 1
@platformStatic set(p: Int) {
@jvmStatic set(p: Int) {
p1 = 1
}
@platformStatic val z = 1;
@jvmStatic val z = 1;
@platformStatic override val base1: Int = 0
@jvmStatic override val base1: Int = 0
override val base2: Int = 0
@platformStatic get
@jvmStatic get
}
object A : B() {
var p:Int = 1
@platformStatic set(p1: Int) {
@jvmStatic set(p1: Int) {
p = 1
}
@platformStatic val z = 1;
@jvmStatic val z = 1;
<!OVERRIDE_CANNOT_BE_STATIC!>@platformStatic override val base1: Int<!> = 0
<!OVERRIDE_CANNOT_BE_STATIC!>@jvmStatic override val base1: Int<!> = 0
platformStatic open fun f() {}
jvmStatic open fun f() {}
override val base2: Int = 0
<!OVERRIDE_CANNOT_BE_STATIC!>@platformStatic get<!>
<!OVERRIDE_CANNOT_BE_STATIC!>@jvmStatic get<!>
}
var p:Int = 1
<!PLATFORM_STATIC_NOT_IN_OBJECT!>@platformStatic set(p1: Int)<!> {
<!JVM_STATIC_NOT_IN_OBJECT!>@jvmStatic set(p1: Int)<!> {
p = 1
}
<!PLATFORM_STATIC_NOT_IN_OBJECT!>@platformStatic val z2<!> = 1;
<!JVM_STATIC_NOT_IN_OBJECT!>@jvmStatic val z2<!> = 1;
}
@@ -3,29 +3,29 @@ package
internal final class A {
public constructor A()
internal final var p: kotlin.Int
kotlin.platform.platformStatic() internal final val z2: kotlin.Int = 1
kotlin.jvm.jvmStatic() internal final val z2: kotlin.Int = 1
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
internal object A : B {
private constructor A()
kotlin.platform.platformStatic() public open override /*1*/ val base1: kotlin.Int = 0
kotlin.jvm.jvmStatic() public open override /*1*/ val base1: kotlin.Int = 0
public open override /*1*/ val base2: kotlin.Int = 0
internal final var p: kotlin.Int
kotlin.platform.platformStatic() internal final val z: kotlin.Int = 1
kotlin.jvm.jvmStatic() internal final val z: kotlin.Int = 1
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
kotlin.platform.platformStatic() internal open fun f(): kotlin.Unit
kotlin.jvm.jvmStatic() internal open fun f(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public companion object Companion : B {
private constructor Companion()
kotlin.platform.platformStatic() public open override /*1*/ val base1: kotlin.Int = 0
kotlin.jvm.jvmStatic() public open override /*1*/ val base1: kotlin.Int = 0
public open override /*1*/ val base2: kotlin.Int = 0
internal final var p1: kotlin.Int
kotlin.platform.platformStatic() internal final val z: kotlin.Int = 1
kotlin.jvm.jvmStatic() internal final val z: kotlin.Int = 1
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
@@ -1,4 +1,4 @@
import kotlin.platform.platformStatic
import kotlin.jvm.jvmStatic
open class Base {
fun foo() {}
@@ -6,6 +6,6 @@ open class Base {
class Derived : Base() {
companion object {
<!ACCIDENTAL_OVERRIDE!>platformStatic fun foo()<!> {}
<!ACCIDENTAL_OVERRIDE!>jvmStatic fun foo()<!> {}
}
}
@@ -18,7 +18,7 @@ internal final class Derived : Base {
public companion object Companion {
private constructor Companion()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
kotlin.platform.platformStatic() internal final fun foo(): kotlin.Unit
kotlin.jvm.jvmStatic() internal final fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -1,10 +1,10 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.platform.platformStatic
import kotlin.jvm.jvmStatic
open class Base {
fun `foo$default`(i: Int, mask: Int) {}
}
object Derived : Base() {
<!ACCIDENTAL_OVERRIDE!>platformStatic fun foo(i: Int = 0)<!> {}
<!ACCIDENTAL_OVERRIDE!>jvmStatic fun foo(i: Int = 0)<!> {}
}
@@ -11,7 +11,7 @@ internal open class Base {
internal object Derived : Base {
private constructor Derived()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
kotlin.platform.platformStatic() internal final fun foo(/*0*/ i: kotlin.Int = ...): kotlin.Unit
kotlin.jvm.jvmStatic() internal final fun foo(/*0*/ i: kotlin.Int = ...): kotlin.Unit
internal final override /*1*/ /*fake_override*/ fun `foo$default`(/*0*/ i: kotlin.Int, /*1*/ mask: kotlin.Int): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
@@ -66,7 +66,11 @@ open class KFunctionImpl protected constructor(
is Constructor<*> -> FunctionCaller.Constructor(member)
is Method -> when {
!Modifier.isStatic(member.modifiers) -> FunctionCaller.InstanceMethod(member)
descriptor.annotations.findAnnotation(PLATFORM_STATIC) != null -> FunctionCaller.PlatformStaticInObject(member)
descriptor.annotations.findAnnotation(PLATFORM_STATIC) != null,
descriptor.annotations.findAnnotation(JVM_STATIC) != null->
FunctionCaller.PlatformStaticInObject(member)
else -> FunctionCaller.StaticMethod(member)
}
else -> throw KotlinReflectionInternalError("Call is not yet supported for this function: $descriptor")
@@ -80,7 +80,8 @@ interface KMutablePropertyImpl<R> : KMutableProperty<R>, KPropertyImpl<R> {
private fun KPropertyImpl.Accessor<*>.computeCallerForAccessor(isGetter: Boolean): FunctionCaller<*> {
fun isPlatformStaticProperty() =
property.descriptor.annotations.findAnnotation(PLATFORM_STATIC) != null
property.descriptor.annotations.findAnnotation(PLATFORM_STATIC) != null ||
property.descriptor.annotations.findAnnotation(JVM_STATIC) != null
fun isNotNullProperty() =
!TypeUtils.isNullableType(property.descriptor.type)
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.name.FqName
import kotlin.reflect.IllegalCallableAccessException
internal val PLATFORM_STATIC = FqName("kotlin.platform.platformStatic")
internal val JVM_STATIC = FqName("kotlin.jvm.jvmStatic")
// TODO: wrap other exceptions
internal inline fun <R> reflectionCall(block: () -> R): R =
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.idea.refactoring.safeDelete.removeOverrideModifier
import org.jetbrains.kotlin.lexer.JetTokens
import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.psi.*
import java.util.HashMap
import java.util.*
public class JavaToKotlinPreconversionPullUpHelper(
private val data: PullUpData,
@@ -58,7 +58,7 @@ public class JavaToKotlinPreconversionPullUpHelper(
private val fieldsToUsages = HashMap<PsiField, List<EncapsulateFieldUsageInfo>>()
private val dummyAccessorByName = HashMap<String, PsiMethod>()
private val platformStaticAnnotation = JetPsiFactory(data.sourceClass.project).createAnnotationEntry("kotlin.platform.platformStatic")
private val jvmStaticAnnotation = JetPsiFactory(data.sourceClass.project).createAnnotationEntry("kotlin.jvm.jvmStatic")
companion object {
private var PsiMember.originalMember: PsiMember? by CopyableUserDataProperty(Key.create("ORIGINAL_MEMBER"))
@@ -147,7 +147,7 @@ public class JavaToKotlinPreconversionPullUpHelper(
newDeclaration.removeModifier(JetTokens.ABSTRACT_KEYWORD)
}
if (member.hasModifierProperty(PsiModifier.STATIC) && newDeclaration is JetNamedFunction) {
newDeclaration.addAnnotationWithSpace(platformStaticAnnotation).addToShorteningWaitSet()
newDeclaration.addAnnotationWithSpace(jvmStaticAnnotation).addToShorteningWaitSet()
}
if (originalMember is PsiField) {
+13 -13
View File
@@ -1,57 +1,57 @@
import kotlin.platform.platformStatic
import kotlin.jvm.jvmStatic
<error descr="[WRONG_ANNOTATION_TARGET] This annotation is not applicable to target 'class'">platformStatic</error>
<error descr="[WRONG_ANNOTATION_TARGET] This annotation is not applicable to target 'class'">jvmStatic</error>
class A {
<error descr="[WRONG_ANNOTATION_TARGET] This annotation is not applicable to target 'object'">platformStatic</error>
<error descr="[WRONG_ANNOTATION_TARGET] This annotation is not applicable to target 'object'">jvmStatic</error>
companion object {
platformStatic fun a1() {
jvmStatic fun a1() {
}
}
<error descr="[WRONG_ANNOTATION_TARGET] This annotation is not applicable to target 'object'">platformStatic</error>
<error descr="[WRONG_ANNOTATION_TARGET] This annotation is not applicable to target 'object'">jvmStatic</error>
object A {
platformStatic fun a2() {
jvmStatic fun a2() {
}
}
fun test() {
val <warning descr="[UNUSED_VARIABLE] Variable 's' is never used">s</warning> = object {
<error descr="[PLATFORM_STATIC_NOT_IN_OBJECT] Only functions in named objects and companion objects of classes can be annotated with 'platformStatic'">platformStatic fun a3()</error> {
<error descr="[JVM_STATIC_NOT_IN_OBJECT] Only functions in named objects and companion objects of classes can be annotated with 'jvmStatic'">jvmStatic fun a3()</error> {
}
}
}
<error descr="[PLATFORM_STATIC_NOT_IN_OBJECT] Only functions in named objects and companion objects of classes can be annotated with 'platformStatic'">platformStatic fun a4()</error> {
<error descr="[JVM_STATIC_NOT_IN_OBJECT] Only functions in named objects and companion objects of classes can be annotated with 'jvmStatic'">jvmStatic fun a4()</error> {
}
}
<error descr="[WRONG_ANNOTATION_TARGET] This annotation is not applicable to target 'interface'">platformStatic</error>
<error descr="[WRONG_ANNOTATION_TARGET] This annotation is not applicable to target 'interface'">jvmStatic</error>
interface B {
companion object {
<error descr="[PLATFORM_STATIC_NOT_IN_OBJECT] Only functions in named objects and companion objects of classes can be annotated with 'platformStatic'">platformStatic fun a1()</error> {
<error descr="[JVM_STATIC_NOT_IN_OBJECT] Only functions in named objects and companion objects of classes can be annotated with 'jvmStatic'">jvmStatic fun a1()</error> {
}
}
object A {
platformStatic fun a2() {
jvmStatic fun a2() {
}
}
fun test() {
val <warning descr="[UNUSED_VARIABLE] Variable 's' is never used">s</warning> = object {
<error descr="[PLATFORM_STATIC_NOT_IN_OBJECT] Only functions in named objects and companion objects of classes can be annotated with 'platformStatic'">platformStatic fun a3()</error> {
<error descr="[JVM_STATIC_NOT_IN_OBJECT] Only functions in named objects and companion objects of classes can be annotated with 'jvmStatic'">jvmStatic fun a3()</error> {
}
}
}
<error descr="[PLATFORM_STATIC_NOT_IN_OBJECT] Only functions in named objects and companion objects of classes can be annotated with 'platformStatic'">platformStatic fun a4()</error> {
<error descr="[JVM_STATIC_NOT_IN_OBJECT] Only functions in named objects and companion objects of classes can be annotated with 'jvmStatic'">jvmStatic fun a4()</error> {
}
}
@@ -1,9 +1,7 @@
package to
import kotlin.platform.platformStatic
public object JavaClass {
platformStatic public fun main(args: Array<String>) {
jvmStatic public fun main(args: Array<String>) {
println("Hello, world!")
}
}
@@ -1,5 +1,3 @@
import kotlin.platform.platformStatic
abstract class A {
// INFO: {"checked": "true"}
var x = 2 * 3
@@ -23,7 +21,7 @@ abstract class A {
var X = "1" + "2"
// INFO: {"checked": "true"}
platformStatic fun foo2(n: Int): String {
jvmStatic fun foo2(n: Int): String {
return "_" + n + "_"
}
}
@@ -1,5 +1,3 @@
import kotlin.platform.platformStatic
abstract class A {
// INFO: {"checked": "true", "toAbstract": "true"}
var x = 2 * 3
@@ -21,7 +19,7 @@ abstract class A {
var X = "1" + "2"
// INFO: {"checked": "true", "toAbstract": "true"}
platformStatic fun foo2(n: Int): String {
jvmStatic fun foo2(n: Int): String {
return "_" + n + "_"
}
}
@@ -1,5 +1,3 @@
import kotlin.platform.platformStatic
interface A {
// INFO: {"checked": "true"}
class Y
@@ -17,7 +15,7 @@ interface A {
var X = "1" + "2"
// INFO: {"checked": "true"}
platformStatic fun foo2(n: Int): String {
jvmStatic fun foo2(n: Int): String {
return "_" + n + "_"
}
}
@@ -1,5 +1,3 @@
import kotlin.platform.platformStatic
class T {
class U {
abstract class A {
@@ -25,7 +23,7 @@ class T {
var X = "1" + "2"
// INFO: {"checked": "true"}
platformStatic fun foo2(n: Int): String {
jvmStatic fun foo2(n: Int): String {
return "_" + n + "_"
}
}
@@ -32,8 +32,7 @@ import org.jetbrains.kotlin.j2k.usageProcessing.UsageProcessing
import org.jetbrains.kotlin.j2k.usageProcessing.UsageProcessingExpressionConverter
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.types.expressions.OperatorConventions.*
import java.util.ArrayList
import java.util.HashMap
import java.util.*
class Converter private constructor(
private val elementToConvert: PsiElement,
@@ -424,7 +423,7 @@ class Converter private constructor(
if (function == null) return null
if (PsiMethodUtil.isMainMethod(method)) {
val fqName = FqName("kotlin.platform.platformStatic")
val fqName = FqName("kotlin.jvm.jvmStatic")
val identifier = Identifier(fqName.shortName().identifier, imports = listOf(fqName)).assignNoPrototype()
function.annotations += Annotations(
@@ -1,7 +1,5 @@
import kotlin.platform.platformStatic
public object A {
platformStatic public fun main(args: Array<String>) {
jvmStatic public fun main(args: Array<String>) {
println(Void.TYPE)
println(Integer.TYPE)
println(java.lang.Double.TYPE)
+1 -3
View File
@@ -1,7 +1,5 @@
import kotlin.platform.platformStatic
public object TestClass {
platformStatic public fun main(args: Array<String>) {
jvmStatic public fun main(args: Array<String>) {
var i = 0
while (i < 10) {
if (i == 4 || i == 8) {
+1 -3
View File
@@ -1,7 +1,5 @@
import kotlin.platform.platformStatic
public object TestClass {
platformStatic public fun main(args: Array<String>) {
jvmStatic public fun main(args: Array<String>) {
var i = 0
var j = 1
while (i < 10) {
+1 -3
View File
@@ -1,7 +1,5 @@
import kotlin.platform.platformStatic
public object TestClass {
platformStatic public fun main(args: Array<String>) {
jvmStatic public fun main(args: Array<String>) {
var i = 1
while (i < 1000) {
if (i == 4 || i == 8) {
+1 -3
View File
@@ -1,7 +1,5 @@
import kotlin.platform.platformStatic
public object TestClass {
platformStatic public fun main(args: Array<String>) {
jvmStatic public fun main(args: Array<String>) {
var i = 1
OuterLoop1@ OuterLoop2@ while (i < 1000) {
var j = 1
+1 -4
View File
@@ -1,5 +1,2 @@
import kotlin.platform.platformStatic
platformStatic public fun main(args: Array<String>) {
jvmStatic public fun main(args: Array<String>) {
}
+1 -3
View File
@@ -1,6 +1,4 @@
import kotlin.platform.platformStatic
public object A {
platformStatic public fun main(args: Array<String>) {
jvmStatic public fun main(args: Array<String>) {
}
}
@@ -1,7 +1,5 @@
import kotlin.platform.platformStatic
// !forceNotNullTypes: false
public object A {
platformStatic public fun main(args: Array<String>) {
jvmStatic public fun main(args: Array<String>) {
}
}
+1 -3
View File
@@ -1,6 +1,4 @@
// ERROR: Property must be initialized or be abstract
import kotlin.platform.platformStatic
public class Identifier<T> {
public val name: T
private val myHasDollar: Boolean
@@ -23,7 +21,7 @@ public class Identifier<T> {
}
public object User {
platformStatic public fun main(args: Array<String>) {
jvmStatic public fun main(args: Array<String>) {
val i1 = Identifier("name", false, true)
val i2 = Identifier("name", false)
val i3 = Identifier("name")
+1 -2
View File
@@ -3,10 +3,9 @@
// 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 {
platformStatic public fun main(args: Array<String>) {
jvmStatic public fun main(args: Array<String>) {
try {
val fstream = FileInputStream()
val `in` = DataInputStream(fstream)
+1 -3
View File
@@ -1,9 +1,7 @@
package demo
import kotlin.platform.platformStatic
object Program {
platformStatic public fun main(args: Array<String>) {
jvmStatic public fun main(args: Array<String>) {
println("Halo!")
}
}
+1 -3
View File
@@ -1,7 +1,5 @@
package demo
import kotlin.platform.platformStatic
public object SwitchDemo {
public fun print(o: Any) {
println(o)
@@ -78,7 +76,7 @@ public object SwitchDemo {
println(monthString)
}
platformStatic public fun main(args: Array<String>) {
jvmStatic public fun main(args: Array<String>) {
for (i in 1..12)
test(i)
}
+1 -3
View File
@@ -1,7 +1,5 @@
import kotlin.platform.platformStatic
public object NonDefault {
platformStatic public fun main(args: Array<String>) {
jvmStatic public fun main(args: Array<String>) {
val value = 3
val valueString = ""
+1 -3
View File
@@ -1,9 +1,7 @@
package switch_demo
import kotlin.platform.platformStatic
public object SwitchDemo {
platformStatic public fun main(args: Array<String>) {
jvmStatic public fun main(args: Array<String>) {
val month = 8
val monthString: String
when (month) {
+1 -3
View File
@@ -1,7 +1,5 @@
import kotlin.platform.platformStatic
public object C {
platformStatic public fun main(args: Array<String>) {
jvmStatic public fun main(args: Array<String>) {
when (args.size()) {
1 -> {
run {
+1 -3
View File
@@ -1,9 +1,7 @@
package switch_demo
import kotlin.platform.platformStatic
public object SwitchDemo {
platformStatic public fun main(args: Array<String>) {
jvmStatic public fun main(args: Array<String>) {
val month = 8
val monthString: String
+1 -3
View File
@@ -1,7 +1,5 @@
import kotlin.platform.platformStatic
public object NonDefault {
platformStatic public fun main(args: Array<String>) {
jvmStatic public fun main(args: Array<String>) {
val value = 3
var valueString = ""
@@ -25,6 +25,15 @@ package kotlin.jvm
target(AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR)
public annotation(retention = AnnotationRetention.BINARY, mustBeDocumented = true) class jvmOverloads
/**
* Specifies that a static method or field needs to be generated from this element.
* See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/java-interop.html#static-methods-and-fields)
* for more information.
*/
target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.FIELD, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER)
public annotation(retention = AnnotationRetention.RUNTIME, mustBeDocumented = true) class jvmStatic
/**
* Instructs the Kotlin compiler to generate a public backing field for this property.
*/
@@ -28,10 +28,6 @@ import kotlin.annotation.AnnotationTarget.*
target(FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER)
public annotation(retention = AnnotationRetention.RUNTIME, mustBeDocumented = true) class platformName(public val name: String)
/**
* Specifies that a static method or field needs to be generated from this element.
* See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/java-interop.html#static-methods-and-fields)
* for more information.
*/
target(FUNCTION, PROPERTY, FIELD, PROPERTY_GETTER, PROPERTY_SETTER)
deprecated("Use kotlin.jvm.jvmStatic instead", ReplaceWith("kotlin.jvm.jvmStatic"))
public annotation(retention = AnnotationRetention.RUNTIME, mustBeDocumented = true) class platformStatic