JS: replace all usages of @native annotation with external modifier, in tests, stdlib, etc

This commit is contained in:
Alexey Andreev
2016-11-25 12:36:47 +03:00
parent e0cb56b3c3
commit 68412ae94f
173 changed files with 486 additions and 651 deletions
+1 -2
View File
@@ -16,6 +16,5 @@
package kotlin.js.internal
@native
@JsName("Error")
public open class JsError(message: String?)
public external open class JsError(message: String?)
+3 -3
View File
@@ -20,8 +20,8 @@ import kotlin.annotation.AnnotationTarget.*
@Retention(AnnotationRetention.BINARY)
@Target(CLASS, FUNCTION, PROPERTY, CONSTRUCTOR, PROPERTY_GETTER, PROPERTY_SETTER)
@native internal annotation class JsName(val name: String)
internal external annotation class JsName(val name: String)
@native internal annotation class native
internal external annotation class native
@native internal fun js(code: String): dynamic
internal external fun js(code: String): dynamic
+10 -17
View File
@@ -18,37 +18,30 @@ package kotlin.js
import kotlin.annotation.AnnotationTarget.*
@native
@Target(CLASS, FUNCTION, PROPERTY, CONSTRUCTOR, VALUE_PARAMETER, PROPERTY_GETTER, PROPERTY_SETTER)
@Deprecated("Use `external` modifier instead")
public annotation class native(@Deprecated public val name: String = "")
public external annotation class native(@Deprecated public val name: String = "")
@native
@Target(FUNCTION)
@Deprecated
public annotation class nativeGetter
@Deprecated("Use inline extension function with body using dynamic")
public external annotation class nativeGetter
@native
@Target(FUNCTION)
@Deprecated
public annotation class nativeSetter
@Deprecated("Use inline extension function with body using dynamic")
public external annotation class nativeSetter
@native
@Target(FUNCTION)
@Deprecated
public annotation class nativeInvoke
@Deprecated("Use inline extension function with body using dynamic")
public external annotation class nativeInvoke
@native
@Target(CLASS, FUNCTION, PROPERTY)
internal annotation class library(public val name: String = "")
internal external annotation class library(public val name: String = "")
@native
@Target(PROPERTY)
public annotation class enumerable()
public external annotation class enumerable()
@native
@Target(CLASS)
internal annotation class marker
internal external annotation class marker
@Retention(AnnotationRetention.BINARY)
@Target(CLASS, FUNCTION, PROPERTY, CONSTRUCTOR, PROPERTY_GETTER, PROPERTY_SETTER)
+2 -2
View File
@@ -19,9 +19,9 @@ package kotlin.text
// actually \s is enough to match all whitespace, but \xA0 added because of different regexp behavior of Rhino used in Selenium tests
public fun Char.isWhitespace(): Boolean = toString().matches("[\\s\\xA0]")
@native public fun Char.toLowerCase(): Char = noImpl
public external fun Char.toLowerCase(): Char = noImpl
@native public fun Char.toUpperCase(): Char = noImpl
public external fun Char.toUpperCase(): Char = noImpl
/**
* Returns `true` if this character is a Unicode high-surrogate code unit (also known as leading-surrogate code unit).
+4 -4
View File
@@ -19,7 +19,7 @@ package kotlin
// Note:
// Right now we don't want to have neither 'volatile' nor 'synchronized' at runtime,
// so they annotated as 'native' to avoid warnings/errors from some minifiers.
// so they annotated as `external` to avoid warnings/errors from some minifiers.
// They was reserved word in ECMAScript 2, but is not since ECMAScript 5.
// Additional note:
@@ -29,10 +29,10 @@ package kotlin
@Target(AnnotationTarget.PROPERTY, AnnotationTarget.FIELD)
@Retention(AnnotationRetention.SOURCE)
public annotation class Volatile
public external annotation class Volatile
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER)
@Retention(AnnotationRetention.SOURCE)
public annotation class Synchronized
public external annotation class Synchronized
public inline fun <R> synchronized(lock: Any, crossinline block: () -> R): R = block()
public external inline fun <R> synchronized(lock: Any, crossinline block: () -> R): R = block()
+6 -11
View File
@@ -1,16 +1,13 @@
package kotlin.js
@native
public val noImpl: Nothing
public external val noImpl: Nothing
get() = throw Exception()
@native
public fun eval(expr: String): dynamic = noImpl
public external fun eval(expr: String): dynamic = noImpl
@native
public val undefined: Nothing? = noImpl
public external val undefined: Nothing? = noImpl
@native operator fun <K, V> MutableMap<K, V>.set(key: K, value: V): V? = noImpl
external operator fun <K, V> MutableMap<K, V>.set(key: K, value: V): V? = noImpl
@library
public fun println() {}
@@ -22,8 +19,7 @@ public fun println(s: Any?) {}
public fun print(s: Any?) {}
//TODO: consistent parseInt
@native
public fun parseInt(s: String, radix: Int = 10): Int = noImpl
public external fun parseInt(s: String, radix: Int = 10): Int = noImpl
@library
public fun safeParseInt(s: String): Int? = noImpl
@@ -31,8 +27,7 @@ public fun safeParseInt(s: String): Int? = noImpl
@library
public fun safeParseDouble(s: String): Double? = noImpl
@native
public fun js(code: String): dynamic = noImpl
public external fun js(code: String): dynamic = noImpl
/**
* Function corresponding to JavaScript's `typeof` operator
+1 -2
View File
@@ -1,6 +1,5 @@
package kotlin.js
@native
public class Date() {
public external class Date() {
public fun getTime(): Int = noImpl
}
+7 -8
View File
@@ -1,13 +1,12 @@
package kotlin.js
// https://developer.mozilla.org/en/DOM/console
@native public interface Console {
@native public fun dir(o: Any): Unit = noImpl
@native public fun error(vararg o: Any?): Unit = noImpl
@native public fun info(vararg o: Any?): Unit = noImpl
@native public fun log(vararg o: Any?): Unit = noImpl
@native public fun warn(vararg o: Any?): Unit = noImpl
external public interface Console {
public fun dir(o: Any): Unit = noImpl
public fun error(vararg o: Any?): Unit = noImpl
public fun info(vararg o: Any?): Unit = noImpl
public fun log(vararg o: Any?): Unit = noImpl
public fun warn(vararg o: Any?): Unit = noImpl
}
@native
public val console: Console = noImpl
public external val console: Console = noImpl
+1 -2
View File
@@ -21,8 +21,7 @@ package java.util
// typealias Date = kotlin.js.Date
@Deprecated("Use kotlin.js.Date instead", ReplaceWith("kotlin.js.Date"))
@native
public class Date() {
public external class Date() {
public fun getTime(): Int = noImpl
}
+3 -5
View File
@@ -1,6 +1,6 @@
package kotlin.js
@native public class Json() {
public external class Json() {
operator fun get(propertyName: String): Any? = noImpl
operator fun set(propertyName: String, value: Any?): Unit = noImpl
}
@@ -16,8 +16,7 @@ public fun json(vararg pairs: Pair<String, Any?>): Json {
@library("jsonAddProperties")
public fun Json.add(other: Json): Json = noImpl
@native
public interface JsonClass {
public external interface JsonClass {
public fun stringify(o: Any): String
public fun stringify(o: Any, replacer: (key: String, value: Any?) -> Any?): String
public fun stringify(o: Any, replacer: (key: String, value: Any?) -> Any?, space: Int): String
@@ -30,5 +29,4 @@ public interface JsonClass {
public fun <T> parse(text: String, reviver: ((key: String, value: Any?) -> Any?)): T
}
@native
public val JSON: JsonClass = noImpl
public external val JSON: JsonClass = noImpl
+2 -4
View File
@@ -1,8 +1,7 @@
package kotlin.js
//TODO: declare using number
@native
public class MathClass() {
public external class MathClass() {
public val PI: Double = noImpl
public fun random(): Double = noImpl
public fun abs(value: Double): Double = noImpl
@@ -26,5 +25,4 @@ public class MathClass() {
public fun ceil(value: Number): Int = noImpl
}
@native
public val Math: MathClass = MathClass()
public external val Math: MathClass = MathClass()
+2 -2
View File
@@ -17,7 +17,7 @@
package kotlin.text.js
@native public class RegExp(pattern: String, flags: String? = null) {
public external class RegExp(pattern: String, flags: String? = null) {
public fun test(str: String): Boolean = noImpl
@@ -40,7 +40,7 @@ public fun RegExp.reset() {
}
// TODO: Inherit from array or introduce asArray() extension
@native public interface RegExpMatch {
public external interface RegExpMatch {
public val index: Int
public val input: String
public val length: Int
+17 -18
View File
@@ -2,21 +2,21 @@ package kotlin.text
import kotlin.text.js.RegExp
@native public fun String.toUpperCase(): String = noImpl
public external fun String.toUpperCase(): String = noImpl
@native public fun String.toLowerCase(): String = noImpl
public external fun String.toLowerCase(): String = noImpl
@native("indexOf")
internal fun String.nativeIndexOf(str: String, fromIndex: Int): Int = noImpl
@JsName("indexOf")
internal external fun String.nativeIndexOf(str: String, fromIndex: Int): Int = noImpl
@native("lastIndexOf")
internal fun String.nativeLastIndexOf(str: String, fromIndex: Int): Int = noImpl
@JsName("lastIndexOf")
internal external fun String.nativeLastIndexOf(str: String, fromIndex: Int): Int = noImpl
@native("startsWith")
internal fun String.nativeStartsWith(s: String, position: Int): Boolean = noImpl
@JsName("startsWith")
internal external fun String.nativeStartsWith(s: String, position: Int): Boolean = noImpl
@native("endsWith")
internal fun String.nativeEndsWith(s: String): Boolean = noImpl
@JsName("endsWith")
internal external fun String.nativeEndsWith(s: String): Boolean = noImpl
@Deprecated("Use split(Regex) instead.", ReplaceWith("split(regex.toRegex()).toTypedArray()"))
@library("splitString")
@@ -26,19 +26,18 @@ public fun String.splitWithRegex(regex: String): Array<String> = noImpl
@library("splitString")
public fun String.splitWithRegex(regex: String, limit: Int): Array<String> = noImpl
@native public fun String.substring(startIndex: Int): String = noImpl
public external fun String.substring(startIndex: Int): String = noImpl
@native public fun String.substring(startIndex: Int, endIndex: Int): String = noImpl
public external fun String.substring(startIndex: Int, endIndex: Int): String = noImpl
@native public fun String.concat(str: String): String = noImpl
public external fun String.concat(str: String): String = noImpl
@native public fun String.match(regex: String): Array<String> = noImpl
public external fun String.match(regex: String): Array<String> = noImpl
//native public fun String.trim() : String = noImpl
//TODO: String.replace to implement effective trimLeading and trimTrailing
@native("length")
public val CharSequence.size: Int get() = noImpl
public inline val CharSequence.size: Int get() = asDynamic().length
@native("replace")
internal fun String.nativeReplace(pattern: RegExp, replacement: String): String = noImpl
@JsName("replace")
internal external fun String.nativeReplace(pattern: RegExp, replacement: String): String = noImpl
+15 -18
View File
@@ -2,8 +2,7 @@ package jquery
import org.w3c.dom.Element
@native
public class JQuery() {
public external class JQuery() {
public fun addClass(className: String): JQuery = noImpl;
public fun addClass(f: Element.(Int, String) -> String): JQuery = noImpl;
@@ -43,8 +42,7 @@ public class JQuery() {
public fun `val`(): String? = noImpl
}
@native
open public class MouseEvent() {
open public external class MouseEvent() {
public val pageX: Double = 0.0;
public val pageY: Double = 0.0;
public fun preventDefault() {
@@ -52,20 +50,19 @@ open public class MouseEvent() {
public fun isDefaultPrevented(): Boolean = true;
}
@native
public class MouseClickEvent() : MouseEvent() {
public external class MouseClickEvent() : MouseEvent() {
public val which: Int = 0;
}
@native("$")
public fun jq(selector: String): JQuery = JQuery();
@native("$")
public fun jq(selector: String, context: Element): JQuery = JQuery();
@native("$")
public fun jq(callback: () -> Unit): JQuery = JQuery();
@native("$")
public fun jq(obj: JQuery): JQuery = JQuery();
@native("$")
public fun jq(el: Element): JQuery = JQuery();
@native("$")
public fun jq(): JQuery = JQuery();
@JsName("$")
public external fun jq(selector: String): JQuery = JQuery();
@JsName("$")
public external fun jq(selector: String, context: Element): JQuery = JQuery();
@JsName("$")
public external fun jq(callback: () -> Unit): JQuery = JQuery();
@JsName("$")
public external fun jq(obj: JQuery): JQuery = JQuery();
@JsName("$")
public external fun jq(el: Element): JQuery = JQuery();
@JsName("$")
public external fun jq(): JQuery = JQuery();
+19 -20
View File
@@ -4,23 +4,22 @@ package jquery.ui
//jquery UI
import jquery.JQuery
@native
public fun JQuery.buttonset() : JQuery = noImpl;
@native
public fun JQuery.dialog() : JQuery = noImpl;
@native
public fun JQuery.dialog(params : Json) : JQuery = noImpl
@native
public fun JQuery.dialog(mode : String, param : String) : Any? = noImpl
@native
public fun JQuery.dialog(mode : String) : JQuery = noImpl
@native
public fun JQuery.dialog(mode : String, param : String, value : Any?) : JQuery = noImpl
@native
public fun JQuery.button() : JQuery = noImpl;
@native
public fun JQuery.accordion() : JQuery = noImpl
@native
public fun JQuery.draggable(params : Json) : JQuery = noImpl
@native
public fun JQuery.selectable() : JQuery = noImpl
public external fun JQuery.buttonset() : JQuery = noImpl;
public external fun JQuery.dialog() : JQuery = noImpl;
public external fun JQuery.dialog(params : Json) : JQuery = noImpl
public external fun JQuery.dialog(mode : String, param : String) : Any? = noImpl
public external fun JQuery.dialog(mode : String) : JQuery = noImpl
public external fun JQuery.dialog(mode : String, param : String, value : Any?) : JQuery = noImpl
public external fun JQuery.button() : JQuery = noImpl;
public external fun JQuery.accordion() : JQuery = noImpl
public external fun JQuery.draggable(params : Json) : JQuery = noImpl
public external fun JQuery.selectable() : JQuery = noImpl
+1 -2
View File
@@ -1,4 +1,3 @@
package org.junit
@native
public annotation class Test(val name: String = "")
public external annotation class Test(val name: String = "")
+1 -2
View File
@@ -4,6 +4,5 @@ package QUnit
* The [QUnit](http://qunitjs.com/) API
*/
@native
public fun ok(actual: Boolean, message: String?): Unit = noImpl
public external fun ok(actual: Boolean, message: String?): Unit = noImpl
+2 -4
View File
@@ -20,14 +20,12 @@ import getKClass
import kotlin.reflect.KClass
import kotlin.reflect.js.internal.KClassImpl
@native
interface JsClass<T : Any> {
external interface JsClass<T : Any> {
val name: String
}
@native
@Deprecated("Use class literal and extension property `js` instead.", replaceWith = ReplaceWith("T::class.js"))
fun <T : Any> jsClass(): JsClass<T> = noImpl
external fun <T : Any> jsClass(): JsClass<T> = noImpl
@Deprecated("Use class literal and extension property `js` instead.", replaceWith = ReplaceWith("this::class.js"))
val <T : Any> T.jsClass: JsClass<T>
+4 -8
View File
@@ -2,15 +2,11 @@ package kotlin.browser
import org.w3c.dom.*
@native
public val window: Window = noImpl
public external val window: Window = noImpl
@native
public val document: Document = noImpl
public external val document: Document = noImpl
@native
public val localStorage: Storage = noImpl
public external val localStorage: Storage = noImpl
@native
public val sessionStorage: Storage = noImpl
public external val sessionStorage: Storage = noImpl
+1 -1
View File
@@ -7,7 +7,7 @@ import org.w3c.dom.Node
public fun createDocument(): Document = Document()
@Deprecated("use member property outerHTML of Element class instead")
@native public val Node.outerHTML: String get() = noImpl
public external val Node.outerHTML: String get() = noImpl
/** Converts the node to an XML String */
@Deprecated("use outerHTML directly")