IDL2K better dictionary support: generate interfaces with builder function

This commit is contained in:
Sergey Mashkov
2015-06-17 13:45:21 +03:00
parent c4d53e1e16
commit 8238883ac4
11 changed files with 886 additions and 179 deletions
@@ -20,15 +20,30 @@ import org.w3c.performance.*
import org.w3c.workers.*
import org.w3c.xhr.*
native public open class WebGLContextAttributes {
var alpha: Boolean = true
var depth: Boolean = true
var stencil: Boolean = false
var antialias: Boolean = true
var premultipliedAlpha: Boolean = true
var preserveDrawingBuffer: Boolean = false
var preferLowPowerToHighPerformance: Boolean = false
var failIfMajorPerformanceCaveat: Boolean = false
native public interface WebGLContextAttributes {
var alpha: Boolean
var depth: Boolean
var stencil: Boolean
var antialias: Boolean
var premultipliedAlpha: Boolean
var preserveDrawingBuffer: Boolean
var preferLowPowerToHighPerformance: Boolean
var failIfMajorPerformanceCaveat: Boolean
}
inline fun WebGLContextAttributes(alpha: Boolean = true, depth: Boolean = true, stencil: Boolean = false, antialias: Boolean = true, premultipliedAlpha: Boolean = true, preserveDrawingBuffer: Boolean = false, preferLowPowerToHighPerformance: Boolean = false, failIfMajorPerformanceCaveat: Boolean = false): WebGLContextAttributes {
val o = js("({})") as WebGLContextAttributes
o.`alpha` = alpha
o.`depth` = depth
o.`stencil` = stencil
o.`antialias` = antialias
o.`premultipliedAlpha` = premultipliedAlpha
o.`preserveDrawingBuffer` = preserveDrawingBuffer
o.`preferLowPowerToHighPerformance` = preferLowPowerToHighPerformance
o.`failIfMajorPerformanceCaveat` = failIfMajorPerformanceCaveat
return o
}
native public interface WebGLObject {
@@ -541,10 +556,20 @@ native public open class WebGLContextEvent(type: String, eventInit: WebGLContext
get() = noImpl
}
native public open class WebGLContextEventInit : EventInit() {
native public interface WebGLContextEventInit : EventInit {
var statusMessage: String
}
inline fun WebGLContextEventInit(statusMessage: String, bubbles: Boolean = false, cancelable: Boolean = false): WebGLContextEventInit {
val o = js("({})") as WebGLContextEventInit
o.`statusMessage` = statusMessage
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public open class ArrayBuffer(length: Int) : Transferable {
open val byteLength: Int
get() = noImpl
@@ -121,9 +121,20 @@ native public open class UIEvent(type: String, eventInitDict: UIEventInit = noIm
fun initUIEvent(typeArg: String, bubblesArg: Boolean, cancelableArg: Boolean, viewArg: Window?, detailArg: Int): Unit = noImpl
}
native public open class UIEventInit : EventInit() {
var view: Window? = null
var detail: Int = 0
native public interface UIEventInit : EventInit {
var view: Window?
var detail: Int
}
inline fun UIEventInit(view: Window? = null, detail: Int = 0, bubbles: Boolean = false, cancelable: Boolean = false): UIEventInit {
val o = js("({})") as UIEventInit
o.`view` = view
o.`detail` = detail
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public open class FocusEvent(typeArg: String, focusEventInitDict: FocusEventInit = noImpl) : UIEvent(noImpl, noImpl) {
@@ -132,36 +143,107 @@ native public open class FocusEvent(typeArg: String, focusEventInitDict: FocusEv
fun initFocusEvent(typeArg: String, bubblesArg: Boolean, cancelableArg: Boolean, viewArg: Window?, detailArg: Int, relatedTargetArg: EventTarget?): Unit = noImpl
}
native public open class FocusEventInit : UIEventInit() {
var relatedTarget: EventTarget? = null
native public interface FocusEventInit : UIEventInit {
var relatedTarget: EventTarget?
}
native public open class MouseEventInit : EventModifierInit() {
var screenX: Int = 0
var screenY: Int = 0
var clientX: Int = 0
var clientY: Int = 0
var button: Short = 0
var buttons: Short = 0
var relatedTarget: EventTarget? = null
inline fun FocusEventInit(relatedTarget: EventTarget? = null, view: Window? = null, detail: Int = 0, bubbles: Boolean = false, cancelable: Boolean = false): FocusEventInit {
val o = js("({})") as FocusEventInit
o.`relatedTarget` = relatedTarget
o.`view` = view
o.`detail` = detail
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public open class EventModifierInit : UIEventInit() {
var ctrlKey: Boolean = false
var shiftKey: Boolean = false
var altKey: Boolean = false
var metaKey: Boolean = false
var modifierAltGraph: Boolean = false
var modifierCapsLock: Boolean = false
var modifierFn: Boolean = false
var modifierFnLock: Boolean = false
var modifierHyper: Boolean = false
var modifierNumLock: Boolean = false
var modifierOS: Boolean = false
var modifierScrollLock: Boolean = false
var modifierSuper: Boolean = false
var modifierSymbol: Boolean = false
var modifierSymbolLock: Boolean = false
native public interface MouseEventInit : EventModifierInit {
var screenX: Int
var screenY: Int
var clientX: Int
var clientY: Int
var button: Short
var buttons: Short
var relatedTarget: EventTarget?
}
inline fun MouseEventInit(screenX: Int = 0, screenY: Int = 0, clientX: Int = 0, clientY: Int = 0, button: Short = 0, buttons: Short = 0, relatedTarget: EventTarget? = null, ctrlKey: Boolean = false, shiftKey: Boolean = false, altKey: Boolean = false, metaKey: Boolean = false, modifierAltGraph: Boolean = false, modifierCapsLock: Boolean = false, modifierFn: Boolean = false, modifierFnLock: Boolean = false, modifierHyper: Boolean = false, modifierNumLock: Boolean = false, modifierOS: Boolean = false, modifierScrollLock: Boolean = false, modifierSuper: Boolean = false, modifierSymbol: Boolean = false, modifierSymbolLock: Boolean = false, view: Window? = null, detail: Int = 0, bubbles: Boolean = false, cancelable: Boolean = false): MouseEventInit {
val o = js("({})") as MouseEventInit
o.`screenX` = screenX
o.`screenY` = screenY
o.`clientX` = clientX
o.`clientY` = clientY
o.`button` = button
o.`buttons` = buttons
o.`relatedTarget` = relatedTarget
o.`ctrlKey` = ctrlKey
o.`shiftKey` = shiftKey
o.`altKey` = altKey
o.`metaKey` = metaKey
o.`modifierAltGraph` = modifierAltGraph
o.`modifierCapsLock` = modifierCapsLock
o.`modifierFn` = modifierFn
o.`modifierFnLock` = modifierFnLock
o.`modifierHyper` = modifierHyper
o.`modifierNumLock` = modifierNumLock
o.`modifierOS` = modifierOS
o.`modifierScrollLock` = modifierScrollLock
o.`modifierSuper` = modifierSuper
o.`modifierSymbol` = modifierSymbol
o.`modifierSymbolLock` = modifierSymbolLock
o.`view` = view
o.`detail` = detail
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public interface EventModifierInit : UIEventInit {
var ctrlKey: Boolean
var shiftKey: Boolean
var altKey: Boolean
var metaKey: Boolean
var modifierAltGraph: Boolean
var modifierCapsLock: Boolean
var modifierFn: Boolean
var modifierFnLock: Boolean
var modifierHyper: Boolean
var modifierNumLock: Boolean
var modifierOS: Boolean
var modifierScrollLock: Boolean
var modifierSuper: Boolean
var modifierSymbol: Boolean
var modifierSymbolLock: Boolean
}
inline fun EventModifierInit(ctrlKey: Boolean = false, shiftKey: Boolean = false, altKey: Boolean = false, metaKey: Boolean = false, modifierAltGraph: Boolean = false, modifierCapsLock: Boolean = false, modifierFn: Boolean = false, modifierFnLock: Boolean = false, modifierHyper: Boolean = false, modifierNumLock: Boolean = false, modifierOS: Boolean = false, modifierScrollLock: Boolean = false, modifierSuper: Boolean = false, modifierSymbol: Boolean = false, modifierSymbolLock: Boolean = false, view: Window? = null, detail: Int = 0, bubbles: Boolean = false, cancelable: Boolean = false): EventModifierInit {
val o = js("({})") as EventModifierInit
o.`ctrlKey` = ctrlKey
o.`shiftKey` = shiftKey
o.`altKey` = altKey
o.`metaKey` = metaKey
o.`modifierAltGraph` = modifierAltGraph
o.`modifierCapsLock` = modifierCapsLock
o.`modifierFn` = modifierFn
o.`modifierFnLock` = modifierFnLock
o.`modifierHyper` = modifierHyper
o.`modifierNumLock` = modifierNumLock
o.`modifierOS` = modifierOS
o.`modifierScrollLock` = modifierScrollLock
o.`modifierSuper` = modifierSuper
o.`modifierSymbol` = modifierSymbol
o.`modifierSymbolLock` = modifierSymbolLock
o.`view` = view
o.`detail` = detail
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public open class WheelEvent(typeArg: String, wheelEventInitDict: WheelEventInit = noImpl) : MouseEvent(typeArg, noImpl) {
@@ -182,11 +264,48 @@ native public open class WheelEvent(typeArg: String, wheelEventInitDict: WheelEv
}
}
native public open class WheelEventInit : MouseEventInit() {
var deltaX: Double = 0.0
var deltaY: Double = 0.0
var deltaZ: Double = 0.0
var deltaMode: Int = 0
native public interface WheelEventInit : MouseEventInit {
var deltaX: Double
var deltaY: Double
var deltaZ: Double
var deltaMode: Int
}
inline fun WheelEventInit(deltaX: Double = 0.0, deltaY: Double = 0.0, deltaZ: Double = 0.0, deltaMode: Int = 0, screenX: Int = 0, screenY: Int = 0, clientX: Int = 0, clientY: Int = 0, button: Short = 0, buttons: Short = 0, relatedTarget: EventTarget? = null, ctrlKey: Boolean = false, shiftKey: Boolean = false, altKey: Boolean = false, metaKey: Boolean = false, modifierAltGraph: Boolean = false, modifierCapsLock: Boolean = false, modifierFn: Boolean = false, modifierFnLock: Boolean = false, modifierHyper: Boolean = false, modifierNumLock: Boolean = false, modifierOS: Boolean = false, modifierScrollLock: Boolean = false, modifierSuper: Boolean = false, modifierSymbol: Boolean = false, modifierSymbolLock: Boolean = false, view: Window? = null, detail: Int = 0, bubbles: Boolean = false, cancelable: Boolean = false): WheelEventInit {
val o = js("({})") as WheelEventInit
o.`deltaX` = deltaX
o.`deltaY` = deltaY
o.`deltaZ` = deltaZ
o.`deltaMode` = deltaMode
o.`screenX` = screenX
o.`screenY` = screenY
o.`clientX` = clientX
o.`clientY` = clientY
o.`button` = button
o.`buttons` = buttons
o.`relatedTarget` = relatedTarget
o.`ctrlKey` = ctrlKey
o.`shiftKey` = shiftKey
o.`altKey` = altKey
o.`metaKey` = metaKey
o.`modifierAltGraph` = modifierAltGraph
o.`modifierCapsLock` = modifierCapsLock
o.`modifierFn` = modifierFn
o.`modifierFnLock` = modifierFnLock
o.`modifierHyper` = modifierHyper
o.`modifierNumLock` = modifierNumLock
o.`modifierOS` = modifierOS
o.`modifierScrollLock` = modifierScrollLock
o.`modifierSuper` = modifierSuper
o.`modifierSymbol` = modifierSymbol
o.`modifierSymbolLock` = modifierSymbolLock
o.`view` = view
o.`detail` = detail
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public open class KeyboardEvent(typeArg: String, keyboardEventInitDict: KeyboardEventInit = noImpl) : UIEvent(noImpl, noImpl) {
@@ -225,12 +344,43 @@ native public open class KeyboardEvent(typeArg: String, keyboardEventInitDict: K
}
}
native public open class KeyboardEventInit : EventModifierInit() {
var key: String = ""
var code: String = ""
var location: Int = 0
var repeat: Boolean = false
var isComposing: Boolean = false
native public interface KeyboardEventInit : EventModifierInit {
var key: String
var code: String
var location: Int
var repeat: Boolean
var isComposing: Boolean
}
inline fun KeyboardEventInit(key: String = "", code: String = "", location: Int = 0, repeat: Boolean = false, isComposing: Boolean = false, ctrlKey: Boolean = false, shiftKey: Boolean = false, altKey: Boolean = false, metaKey: Boolean = false, modifierAltGraph: Boolean = false, modifierCapsLock: Boolean = false, modifierFn: Boolean = false, modifierFnLock: Boolean = false, modifierHyper: Boolean = false, modifierNumLock: Boolean = false, modifierOS: Boolean = false, modifierScrollLock: Boolean = false, modifierSuper: Boolean = false, modifierSymbol: Boolean = false, modifierSymbolLock: Boolean = false, view: Window? = null, detail: Int = 0, bubbles: Boolean = false, cancelable: Boolean = false): KeyboardEventInit {
val o = js("({})") as KeyboardEventInit
o.`key` = key
o.`code` = code
o.`location` = location
o.`repeat` = repeat
o.`isComposing` = isComposing
o.`ctrlKey` = ctrlKey
o.`shiftKey` = shiftKey
o.`altKey` = altKey
o.`metaKey` = metaKey
o.`modifierAltGraph` = modifierAltGraph
o.`modifierCapsLock` = modifierCapsLock
o.`modifierFn` = modifierFn
o.`modifierFnLock` = modifierFnLock
o.`modifierHyper` = modifierHyper
o.`modifierNumLock` = modifierNumLock
o.`modifierOS` = modifierOS
o.`modifierScrollLock` = modifierScrollLock
o.`modifierSuper` = modifierSuper
o.`modifierSymbol` = modifierSymbol
o.`modifierSymbolLock` = modifierSymbolLock
o.`view` = view
o.`detail` = detail
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public open class CompositionEvent(typeArg: String, compositionEventInitDict: CompositionEventInit = noImpl) : UIEvent(noImpl, noImpl) {
@@ -239,8 +389,20 @@ native public open class CompositionEvent(typeArg: String, compositionEventInitD
fun initCompositionEvent(typeArg: String, bubblesArg: Boolean, cancelableArg: Boolean, viewArg: Window?, dataArg: String, locale: String): Unit = noImpl
}
native public open class CompositionEventInit : UIEventInit() {
var data: String = ""
native public interface CompositionEventInit : UIEventInit {
var data: String
}
inline fun CompositionEventInit(data: String = "", view: Window? = null, detail: Int = 0, bubbles: Boolean = false, cancelable: Boolean = false): CompositionEventInit {
val o = js("({})") as CompositionEventInit
o.`data` = data
o.`view` = view
o.`detail` = detail
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public open class MutationEvent : Event(noImpl, noImpl) {
+354 -53
View File
@@ -1617,10 +1617,20 @@ native public open class TrackEvent(type: String, eventInitDict: TrackEventInit
get() = noImpl
}
native public open class TrackEventInit : EventInit() {
native public interface TrackEventInit : EventInit {
var track: UnionAudioTrackOrTextTrackOrVideoTrack?
}
inline fun TrackEventInit(track: UnionAudioTrackOrTextTrackOrVideoTrack?, bubbles: Boolean = false, cancelable: Boolean = false): TrackEventInit {
val o = js("({})") as TrackEventInit
o.`track` = track
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public interface HTMLMapElement : HTMLElement {
var name: String
get() = noImpl
@@ -2453,10 +2463,20 @@ native public open class AutocompleteErrorEvent(type: String, eventInitDict: Aut
get() = noImpl
}
native public open class AutocompleteErrorEventInit : EventInit() {
native public interface AutocompleteErrorEventInit : EventInit {
var reason: String
}
inline fun AutocompleteErrorEventInit(reason: String, bubbles: Boolean = false, cancelable: Boolean = false): AutocompleteErrorEventInit {
val o = js("({})") as AutocompleteErrorEventInit
o.`reason` = reason
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public interface ValidityState {
val valueMissing: Boolean
get() = noImpl
@@ -2531,10 +2551,20 @@ native public open class RelatedEvent(type: String, eventInitDict: RelatedEventI
get() = noImpl
}
native public open class RelatedEventInit : EventInit() {
native public interface RelatedEventInit : EventInit {
var relatedTarget: EventTarget?
}
inline fun RelatedEventInit(relatedTarget: EventTarget?, bubbles: Boolean = false, cancelable: Boolean = false): RelatedEventInit {
val o = js("({})") as RelatedEventInit
o.`relatedTarget` = relatedTarget
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public interface HTMLDialogElement : HTMLElement {
var open: Boolean
get() = noImpl
@@ -2601,8 +2631,16 @@ native public interface CanvasProxy : Transferable {
fun setContext(context: RenderingContext): Unit = noImpl
}
native public open class CanvasRenderingContext2DSettings {
var alpha: Boolean = true
native public interface CanvasRenderingContext2DSettings {
var alpha: Boolean
}
inline fun CanvasRenderingContext2DSettings(alpha: Boolean = true): CanvasRenderingContext2DSettings {
val o = js("({})") as CanvasRenderingContext2DSettings
o.`alpha` = alpha
return o
}
native public open class CanvasRenderingContext2D() : RenderingContext, CanvasImageSource, ImageBitmapSource {
@@ -2766,15 +2804,30 @@ native public interface TextMetrics {
get() = noImpl
}
native public open class HitRegionOptions {
var path: Path2D? = null
var fillRule: String = "nonzero"
var id: String = ""
var parentID: String? = null
var cursor: String = "inherit"
var control: Element? = null
var label: String? = null
var role: String? = null
native public interface HitRegionOptions {
var path: Path2D?
var fillRule: String
var id: String
var parentID: String?
var cursor: String
var control: Element?
var label: String?
var role: String?
}
inline fun HitRegionOptions(path: Path2D? = null, fillRule: String = "nonzero", id: String = "", parentID: String? = null, cursor: String = "inherit", control: Element? = null, label: String? = null, role: String? = null): HitRegionOptions {
val o = js("({})") as HitRegionOptions
o.`path` = path
o.`fillRule` = fillRule
o.`id` = id
o.`parentID` = parentID
o.`cursor` = cursor
o.`control` = control
o.`label` = label
o.`role` = role
return o
}
native public open class ImageData : ImageBitmapSource {
@@ -2890,10 +2943,44 @@ native public open class DragEvent(type: String, eventInitDict: DragEventInit =
get() = noImpl
}
native public open class DragEventInit : MouseEventInit() {
native public interface DragEventInit : MouseEventInit {
var dataTransfer: DataTransfer?
}
inline fun DragEventInit(dataTransfer: DataTransfer?, screenX: Int = 0, screenY: Int = 0, clientX: Int = 0, clientY: Int = 0, button: Short = 0, buttons: Short = 0, relatedTarget: EventTarget? = null, ctrlKey: Boolean = false, shiftKey: Boolean = false, altKey: Boolean = false, metaKey: Boolean = false, modifierAltGraph: Boolean = false, modifierCapsLock: Boolean = false, modifierFn: Boolean = false, modifierFnLock: Boolean = false, modifierHyper: Boolean = false, modifierNumLock: Boolean = false, modifierOS: Boolean = false, modifierScrollLock: Boolean = false, modifierSuper: Boolean = false, modifierSymbol: Boolean = false, modifierSymbolLock: Boolean = false, view: Window? = null, detail: Int = 0, bubbles: Boolean = false, cancelable: Boolean = false): DragEventInit {
val o = js("({})") as DragEventInit
o.`dataTransfer` = dataTransfer
o.`screenX` = screenX
o.`screenY` = screenY
o.`clientX` = clientX
o.`clientY` = clientY
o.`button` = button
o.`buttons` = buttons
o.`relatedTarget` = relatedTarget
o.`ctrlKey` = ctrlKey
o.`shiftKey` = shiftKey
o.`altKey` = altKey
o.`metaKey` = metaKey
o.`modifierAltGraph` = modifierAltGraph
o.`modifierCapsLock` = modifierCapsLock
o.`modifierFn` = modifierFn
o.`modifierFnLock` = modifierFnLock
o.`modifierHyper` = modifierHyper
o.`modifierNumLock` = modifierNumLock
o.`modifierOS` = modifierOS
o.`modifierScrollLock` = modifierScrollLock
o.`modifierSuper` = modifierSuper
o.`modifierSymbol` = modifierSymbol
o.`modifierSymbolLock` = modifierSymbolLock
o.`view` = view
o.`detail` = detail
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public interface Window : EventTarget, UnionMessagePortOrWindow {
val caches: CacheStorage
get() = noImpl
@@ -3311,10 +3398,20 @@ native public open class PopStateEvent(type: String, eventInitDict: PopStateEven
get() = noImpl
}
native public open class PopStateEventInit : EventInit() {
native public interface PopStateEventInit : EventInit {
var state: Any?
}
inline fun PopStateEventInit(state: Any?, bubbles: Boolean = false, cancelable: Boolean = false): PopStateEventInit {
val o = js("({})") as PopStateEventInit
o.`state` = state
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public open class HashChangeEvent(type: String, eventInitDict: HashChangeEventInit = noImpl) : Event(type, eventInitDict) {
open val oldURL: String
get() = noImpl
@@ -3322,20 +3419,41 @@ native public open class HashChangeEvent(type: String, eventInitDict: HashChange
get() = noImpl
}
native public open class HashChangeEventInit : EventInit() {
native public interface HashChangeEventInit : EventInit {
var oldURL: String
var newURL: String
}
inline fun HashChangeEventInit(oldURL: String, newURL: String, bubbles: Boolean = false, cancelable: Boolean = false): HashChangeEventInit {
val o = js("({})") as HashChangeEventInit
o.`oldURL` = oldURL
o.`newURL` = newURL
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public open class PageTransitionEvent(type: String, eventInitDict: PageTransitionEventInit = noImpl) : Event(type, eventInitDict) {
open val persisted: Boolean
get() = noImpl
}
native public open class PageTransitionEventInit : EventInit() {
native public interface PageTransitionEventInit : EventInit {
var persisted: Boolean
}
inline fun PageTransitionEventInit(persisted: Boolean, bubbles: Boolean = false, cancelable: Boolean = false): PageTransitionEventInit {
val o = js("({})") as PageTransitionEventInit
o.`persisted` = persisted
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public open class BeforeUnloadEvent : Event(noImpl, noImpl) {
var returnValue: String
get() = noImpl
@@ -3396,7 +3514,7 @@ native public open class ErrorEvent(type: String, eventInitDict: ErrorEventInit
get() = noImpl
}
native public open class ErrorEventInit : EventInit() {
native public interface ErrorEventInit : EventInit {
var message: String
var filename: String
var lineno: Int
@@ -3404,6 +3522,20 @@ native public open class ErrorEventInit : EventInit() {
var error: Any?
}
inline fun ErrorEventInit(message: String, filename: String, lineno: Int, colno: Int, error: Any?, bubbles: Boolean = false, cancelable: Boolean = false): ErrorEventInit {
val o = js("({})") as ErrorEventInit
o.`message` = message
o.`filename` = filename
o.`lineno` = lineno
o.`colno` = colno
o.`error` = error
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public interface Navigator {
val serviceWorker: ServiceWorkerContainer
get() = noImpl
@@ -3517,7 +3649,7 @@ native public open class MessageEvent(type: String, eventInitDict: MessageEventI
fun initMessageEvent(typeArg: String, canBubbleArg: Boolean, cancelableArg: Boolean, dataArg: Any?, originArg: String, lastEventIdArg: String, sourceArg: UnionMessagePortOrWindow, portsArg: Array<MessagePort>?): Unit = noImpl
}
native public open class MessageEventInit : EventInit() {
native public interface MessageEventInit : EventInit {
var data: Any?
var origin: String
var lastEventId: String
@@ -3525,6 +3657,20 @@ native public open class MessageEventInit : EventInit() {
var ports: Array<MessagePort>
}
inline fun MessageEventInit(data: Any?, origin: String, lastEventId: String, source: UnionMessagePortOrWindow?, ports: Array<MessagePort>, bubbles: Boolean = false, cancelable: Boolean = false): MessageEventInit {
val o = js("({})") as MessageEventInit
o.`data` = data
o.`origin` = origin
o.`lastEventId` = lastEventId
o.`source` = source
o.`ports` = ports
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public open class EventSource(url: String, eventSourceInitDict: EventSourceInit = noImpl) : EventTarget {
open val url: String
get() = noImpl
@@ -3550,8 +3696,16 @@ native public open class EventSource(url: String, eventSourceInitDict: EventSour
}
}
native public open class EventSourceInit {
var withCredentials: Boolean = false
native public interface EventSourceInit {
var withCredentials: Boolean
}
inline fun EventSourceInit(withCredentials: Boolean = false): EventSourceInit {
val o = js("({})") as EventSourceInit
o.`withCredentials` = withCredentials
return o
}
native public open class WebSocket(url: String, protocols: dynamic = noImpl) : EventTarget {
@@ -3603,12 +3757,24 @@ native public open class CloseEvent(type: String, eventInitDict: CloseEventInit
get() = noImpl
}
native public open class CloseEventInit : EventInit() {
native public interface CloseEventInit : EventInit {
var wasClean: Boolean
var code: Short
var reason: String
}
inline fun CloseEventInit(wasClean: Boolean, code: Short, reason: String, bubbles: Boolean = false, cancelable: Boolean = false): CloseEventInit {
val o = js("({})") as CloseEventInit
o.`wasClean` = wasClean
o.`code` = code
o.`reason` = reason
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public open class MessageChannel {
open val port1: MessagePort
get() = noImpl
@@ -3787,7 +3953,7 @@ native public open class StorageEvent(type: String, eventInitDict: StorageEventI
get() = noImpl
}
native public open class StorageEventInit : EventInit() {
native public interface StorageEventInit : EventInit {
var key: String?
var oldValue: String?
var newValue: String?
@@ -3795,6 +3961,20 @@ native public open class StorageEventInit : EventInit() {
var storageArea: Storage?
}
inline fun StorageEventInit(key: String?, oldValue: String?, newValue: String?, url: String, storageArea: Storage?, bubbles: Boolean = false, cancelable: Boolean = false): StorageEventInit {
val o = js("({})") as StorageEventInit
o.`key` = key
o.`oldValue` = oldValue
o.`newValue` = newValue
o.`url` = url
o.`storageArea` = storageArea
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public interface HTMLAppletElement : HTMLElement {
var align: String
get() = noImpl
@@ -4041,9 +4221,18 @@ native public interface HTMLImageElement : HTMLElement, CanvasImageSource, Image
native public interface HTMLPictureElement : HTMLElement {
}
native public open class EventInit {
var bubbles: Boolean = false
var cancelable: Boolean = false
native public interface EventInit {
var bubbles: Boolean
var cancelable: Boolean
}
inline fun EventInit(bubbles: Boolean = false, cancelable: Boolean = false): EventInit {
val o = js("({})") as EventInit
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public open class CustomEvent(type: String, eventInitDict: CustomEventInit = noImpl) : Event(type, eventInitDict) {
@@ -4052,8 +4241,18 @@ native public open class CustomEvent(type: String, eventInitDict: CustomEventIni
fun initCustomEvent(type: String, bubbles: Boolean, cancelable: Boolean, detail: Any?): Unit = noImpl
}
native public open class CustomEventInit : EventInit() {
var detail: Any? = null
native public interface CustomEventInit : EventInit {
var detail: Any?
}
inline fun CustomEventInit(detail: Any? = null, bubbles: Boolean = false, cancelable: Boolean = false): CustomEventInit {
val o = js("({})") as CustomEventInit
o.`detail` = detail
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public interface NodeList {
@@ -4078,16 +4277,30 @@ native public open class MutationObserver(callback: (Array<MutationRecord>, Muta
fun takeRecords(): Array<MutationRecord> = noImpl
}
native public open class MutationObserverInit {
var childList: Boolean = false
native public interface MutationObserverInit {
var childList: Boolean
var attributes: Boolean
var characterData: Boolean
var subtree: Boolean = false
var subtree: Boolean
var attributeOldValue: Boolean
var characterDataOldValue: Boolean
var attributeFilter: Array<String>
}
inline fun MutationObserverInit(childList: Boolean = false, attributes: Boolean, characterData: Boolean, subtree: Boolean = false, attributeOldValue: Boolean, characterDataOldValue: Boolean, attributeFilter: Array<String>): MutationObserverInit {
val o = js("({})") as MutationObserverInit
o.`childList` = childList
o.`attributes` = attributes
o.`characterData` = characterData
o.`subtree` = subtree
o.`attributeOldValue` = attributeOldValue
o.`characterDataOldValue` = characterDataOldValue
o.`attributeFilter` = attributeFilter
return o
}
native public interface MutationRecord {
val type: String
get() = noImpl
@@ -4548,11 +4761,22 @@ native public open class EditingBeforeInputEvent(type: String, eventInitDict: Ed
get() = noImpl
}
native public open class EditingBeforeInputEventInit : EventInit() {
native public interface EditingBeforeInputEventInit : EventInit {
var command: String
var value: String
}
inline fun EditingBeforeInputEventInit(command: String, value: String, bubbles: Boolean = false, cancelable: Boolean = false): EditingBeforeInputEventInit {
val o = js("({})") as EditingBeforeInputEventInit
o.`command` = command
o.`value` = value
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public open class EditingInputEvent(type: String, eventInitDict: EditingInputEventInit = noImpl) : Event(type, eventInitDict) {
open val command: String
get() = noImpl
@@ -4560,11 +4784,22 @@ native public open class EditingInputEvent(type: String, eventInitDict: EditingI
get() = noImpl
}
native public open class EditingInputEventInit : EventInit() {
native public interface EditingInputEventInit : EventInit {
var command: String
var value: String
}
inline fun EditingInputEventInit(command: String, value: String, bubbles: Boolean = false, cancelable: Boolean = false): EditingInputEventInit {
val o = js("({})") as EditingInputEventInit
o.`command` = command
o.`value` = value
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public open class DOMPointReadOnly(x: Double, y: Double, z: Double, w: Double) {
open val x: Double
get() = noImpl
@@ -4594,11 +4829,22 @@ native public open class DOMPoint : DOMPointReadOnly {
set(value) = noImpl
}
native public open class DOMPointInit {
var x: Double = 0.0
var y: Double = 0.0
var z: Double = 0.0
var w: Double = 1.0
native public interface DOMPointInit {
var x: Double
var y: Double
var z: Double
var w: Double
}
inline fun DOMPointInit(x: Double = 0.0, y: Double = 0.0, z: Double = 0.0, w: Double = 1.0): DOMPointInit {
val o = js("({})") as DOMPointInit
o.`x` = x
o.`y` = y
o.`z` = z
o.`w` = w
return o
}
native public open class DOMRect(x: Double = 0.0, y: Double = 0.0, width: Double = 0.0, height: Double = 0.0) : DOMRectReadOnly(x, y, width, height) {
@@ -4635,11 +4881,22 @@ native public open class DOMRectReadOnly(x: Double, y: Double, width: Double, he
get() = noImpl
}
native public open class DOMRectInit {
var x: Double = 0.0
var y: Double = 0.0
var width: Double = 0.0
var height: Double = 0.0
native public interface DOMRectInit {
var x: Double
var y: Double
var width: Double
var height: Double
}
inline fun DOMRectInit(x: Double = 0.0, y: Double = 0.0, width: Double = 0.0, height: Double = 0.0): DOMRectInit {
val o = js("({})") as DOMRectInit
o.`x` = x
o.`y` = y
o.`width` = width
o.`height` = height
return o
}
native public open class DOMQuad {
@@ -4811,8 +5068,16 @@ native public open class DOMMatrix() : DOMMatrixReadOnly(noImpl) {
fun setMatrixValue(transformList: String): DOMMatrix = noImpl
}
native public open class ScrollOptions {
var behavior: String = "auto"
native public interface ScrollOptions {
var behavior: String
}
inline fun ScrollOptions(behavior: String = "auto"): ScrollOptions {
val o = js("({})") as ScrollOptions
o.`behavior` = behavior
return o
}
native public interface MediaQueryList {
@@ -4847,22 +5112,58 @@ native public interface CaretPosition {
fun getClientRect(): DOMRect? = noImpl
}
native public open class ScrollOptionsHorizontal : ScrollOptions() {
native public interface ScrollOptionsHorizontal : ScrollOptions {
var x: Double
}
native public open class ScrollOptionsVertical : ScrollOptions() {
inline fun ScrollOptionsHorizontal(x: Double, behavior: String = "auto"): ScrollOptionsHorizontal {
val o = js("({})") as ScrollOptionsHorizontal
o.`x` = x
o.`behavior` = behavior
return o
}
native public interface ScrollOptionsVertical : ScrollOptions {
var y: Double
}
native public open class BoxQuadOptions {
var box: String = "border"
inline fun ScrollOptionsVertical(y: Double, behavior: String = "auto"): ScrollOptionsVertical {
val o = js("({})") as ScrollOptionsVertical
o.`y` = y
o.`behavior` = behavior
return o
}
native public interface BoxQuadOptions {
var box: String
var relativeTo: GeometryNode
}
native public open class ConvertCoordinateOptions {
var fromBox: String = "border"
var toBox: String = "border"
inline fun BoxQuadOptions(box: String = "border", relativeTo: GeometryNode): BoxQuadOptions {
val o = js("({})") as BoxQuadOptions
o.`box` = box
o.`relativeTo` = relativeTo
return o
}
native public interface ConvertCoordinateOptions {
var fromBox: String
var toBox: String
}
inline fun ConvertCoordinateOptions(fromBox: String = "border", toBox: String = "border"): ConvertCoordinateOptions {
val o = js("({})") as ConvertCoordinateOptions
o.`fromBox` = fromBox
o.`toBox` = toBox
return o
}
native public marker interface UnionElementOrHTMLCollection {
+28 -4
View File
@@ -58,7 +58,7 @@ native public open class Request(input: dynamic, init: RequestInit = noImpl) {
fun text(): dynamic = noImpl
}
native public open class RequestInit {
native public interface RequestInit {
var method: String
var headers: dynamic
var body: dynamic
@@ -68,6 +68,20 @@ native public open class RequestInit {
var redirect: String
}
inline fun RequestInit(method: String, headers: dynamic, body: dynamic, mode: String, credentials: String, cache: String, redirect: String): RequestInit {
val o = js("({})") as RequestInit
o.`method` = method
o.`headers` = headers
o.`body` = body
o.`mode` = mode
o.`credentials` = credentials
o.`cache` = cache
o.`redirect` = redirect
return o
}
native public open class Response(body: dynamic = noImpl, init: ResponseInit = noImpl) {
open val type: String
get() = noImpl
@@ -96,9 +110,19 @@ native public open class Response(body: dynamic = noImpl, init: ResponseInit = n
}
}
native public open class ResponseInit {
var status: Short = 200
var statusText: String = "OK"
native public interface ResponseInit {
var status: Short
var statusText: String
var headers: dynamic
}
inline fun ResponseInit(status: Short = 200, statusText: String = "OK", headers: dynamic): ResponseInit {
val o = js("({})") as ResponseInit
o.`status` = status
o.`statusText` = statusText
o.`headers` = headers
return o
}
+21 -4
View File
@@ -32,8 +32,16 @@ native public open class Blob() : ImageBitmapSource {
fun close(): Unit = noImpl
}
native public open class BlobPropertyBag {
var type: String = ""
native public interface BlobPropertyBag {
var type: String
}
inline fun BlobPropertyBag(type: String = ""): BlobPropertyBag {
val o = js("({})") as BlobPropertyBag
o.`type` = type
return o
}
native public open class File(fileBits: Array<dynamic>, fileName: String, options: FilePropertyBag = noImpl) : Blob() {
@@ -43,11 +51,20 @@ native public open class File(fileBits: Array<dynamic>, fileName: String, option
get() = noImpl
}
native public open class FilePropertyBag {
var type: String = ""
native public interface FilePropertyBag {
var type: String
var lastModified: Long
}
inline fun FilePropertyBag(type: String = "", lastModified: Long): FilePropertyBag {
val o = js("({})") as FilePropertyBag
o.`type` = type
o.`lastModified` = lastModified
return o
}
native public interface FileList {
val length: Int
get() = noImpl
@@ -61,23 +61,50 @@ native public open class Notification(title: String, options: NotificationOption
}
}
native public open class NotificationOptions {
var dir: String = "auto"
var lang: String = ""
var body: String = ""
var tag: String = ""
native public interface NotificationOptions {
var dir: String
var lang: String
var body: String
var tag: String
var icon: String
var sound: String
var vibrate: dynamic
var renotify: Boolean = false
var silent: Boolean = false
var noscreen: Boolean = false
var sticky: Boolean = false
var data: Any? = null
var renotify: Boolean
var silent: Boolean
var noscreen: Boolean
var sticky: Boolean
var data: Any?
}
native public open class GetNotificationOptions {
var tag: String = ""
inline fun NotificationOptions(dir: String = "auto", lang: String = "", body: String = "", tag: String = "", icon: String, sound: String, vibrate: dynamic, renotify: Boolean = false, silent: Boolean = false, noscreen: Boolean = false, sticky: Boolean = false, data: Any? = null): NotificationOptions {
val o = js("({})") as NotificationOptions
o.`dir` = dir
o.`lang` = lang
o.`body` = body
o.`tag` = tag
o.`icon` = icon
o.`sound` = sound
o.`vibrate` = vibrate
o.`renotify` = renotify
o.`silent` = silent
o.`noscreen` = noscreen
o.`sticky` = sticky
o.`data` = data
return o
}
native public interface GetNotificationOptions {
var tag: String
}
inline fun GetNotificationOptions(tag: String = ""): GetNotificationOptions {
val o = js("({})") as GetNotificationOptions
o.`tag` = tag
return o
}
native public open class NotificationEvent(type: String, eventInitDict: NotificationEventInit = noImpl) : ExtendableEvent(type, eventInitDict) {
@@ -85,7 +112,17 @@ native public open class NotificationEvent(type: String, eventInitDict: Notifica
get() = noImpl
}
native public open class NotificationEventInit : ExtendableEventInit() {
native public interface NotificationEventInit : ExtendableEventInit {
var notification: Notification
}
inline fun NotificationEventInit(notification: Notification, bubbles: Boolean = false, cancelable: Boolean = false): NotificationEventInit {
val o = js("({})") as NotificationEventInit
o.`notification` = notification
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
+102 -14
View File
@@ -102,10 +102,18 @@ native public interface ServiceWorkerContainer : EventTarget {
fun getRegistrations(): dynamic = noImpl
}
native public open class RegistrationOptions {
native public interface RegistrationOptions {
var scope: String
}
inline fun RegistrationOptions(scope: String): RegistrationOptions {
val o = js("({})") as RegistrationOptions
o.`scope` = scope
return o
}
native public open class ServiceWorkerMessageEvent(type: String, eventInitDict: ServiceWorkerMessageEventInit = noImpl) : Event(type, eventInitDict) {
open val data: Any?
get() = noImpl
@@ -120,7 +128,7 @@ native public open class ServiceWorkerMessageEvent(type: String, eventInitDict:
fun initServiceWorkerMessageEvent(typeArg: String, canBubbleArg: Boolean, cancelableArg: Boolean, dataArg: Any?, originArg: String, lastEventIdArg: String, sourceArg: UnionMessagePortOrServiceWorker, portsArg: Array<MessagePort>?): Unit = noImpl
}
native public open class ServiceWorkerMessageEventInit : EventInit() {
native public interface ServiceWorkerMessageEventInit : EventInit {
var data: Any?
var origin: String
var lastEventId: String
@@ -128,6 +136,20 @@ native public open class ServiceWorkerMessageEventInit : EventInit() {
var ports: Array<MessagePort>
}
inline fun ServiceWorkerMessageEventInit(data: Any?, origin: String, lastEventId: String, source: UnionMessagePortOrServiceWorker?, ports: Array<MessagePort>, bubbles: Boolean = false, cancelable: Boolean = false): ServiceWorkerMessageEventInit {
val o = js("({})") as ServiceWorkerMessageEventInit
o.`data` = data
o.`origin` = origin
o.`lastEventId` = lastEventId
o.`source` = source
o.`ports` = ports
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public interface Client : UnionClientOrMessagePortOrServiceWorker {
val url: String
get() = noImpl
@@ -152,16 +174,34 @@ native public interface Clients {
fun claim(): dynamic = noImpl
}
native public open class ClientQueryOptions {
var includeUncontrolled: Boolean = false
var type: String = "window"
native public interface ClientQueryOptions {
var includeUncontrolled: Boolean
var type: String
}
inline fun ClientQueryOptions(includeUncontrolled: Boolean = false, type: String = "window"): ClientQueryOptions {
val o = js("({})") as ClientQueryOptions
o.`includeUncontrolled` = includeUncontrolled
o.`type` = type
return o
}
native public open class ExtendableEvent(type: String, eventInitDict: ExtendableEventInit = noImpl) : Event(type, eventInitDict) {
fun waitUntil(f: dynamic): Unit = noImpl
}
native public open class ExtendableEventInit : EventInit() {
native public interface ExtendableEventInit : EventInit {
}
inline fun ExtendableEventInit(bubbles: Boolean = false, cancelable: Boolean = false): ExtendableEventInit {
val o = js("({})") as ExtendableEventInit
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public open class FetchEvent(type: String, eventInitDict: FetchEventInit = noImpl) : ExtendableEvent(type, eventInitDict) {
@@ -174,10 +214,22 @@ native public open class FetchEvent(type: String, eventInitDict: FetchEventInit
fun respondWith(r: dynamic): Unit = noImpl
}
native public open class FetchEventInit : ExtendableEventInit() {
native public interface FetchEventInit : ExtendableEventInit {
var request: Request
var client: Client
var isReload: Boolean = false
var isReload: Boolean
}
inline fun FetchEventInit(request: Request, client: Client, isReload: Boolean = false, bubbles: Boolean = false, cancelable: Boolean = false): FetchEventInit {
val o = js("({})") as FetchEventInit
o.`request` = request
o.`client` = client
o.`isReload` = isReload
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public open class ExtendableMessageEvent(type: String, eventInitDict: ExtendableMessageEventInit = noImpl) : ExtendableEvent(type, eventInitDict) {
@@ -194,7 +246,7 @@ native public open class ExtendableMessageEvent(type: String, eventInitDict: Ext
fun initExtendableMessageEvent(typeArg: String, canBubbleArg: Boolean, cancelableArg: Boolean, dataArg: Any?, originArg: String, lastEventIdArg: String, sourceArg: UnionClientOrMessagePortOrServiceWorker, portsArg: Array<MessagePort>?): Unit = noImpl
}
native public open class ExtendableMessageEventInit : ExtendableEventInit() {
native public interface ExtendableMessageEventInit : ExtendableEventInit {
var data: Any?
var origin: String
var lastEventId: String
@@ -202,6 +254,20 @@ native public open class ExtendableMessageEventInit : ExtendableEventInit() {
var ports: Array<MessagePort>
}
inline fun ExtendableMessageEventInit(data: Any?, origin: String, lastEventId: String, source: UnionClientOrMessagePortOrServiceWorker?, ports: Array<MessagePort>, bubbles: Boolean = false, cancelable: Boolean = false): ExtendableMessageEventInit {
val o = js("({})") as ExtendableMessageEventInit
o.`data` = data
o.`origin` = origin
o.`lastEventId` = lastEventId
o.`source` = source
o.`ports` = ports
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
native public interface Cache {
fun match(request: dynamic, options: CacheQueryOptions = noImpl): dynamic = noImpl
fun matchAll(request: dynamic = noImpl, options: CacheQueryOptions = noImpl): dynamic = noImpl
@@ -212,20 +278,42 @@ native public interface Cache {
fun keys(request: dynamic = noImpl, options: CacheQueryOptions = noImpl): dynamic = noImpl
}
native public open class CacheQueryOptions {
var ignoreSearch: Boolean = false
var ignoreMethod: Boolean = false
var ignoreVary: Boolean = false
native public interface CacheQueryOptions {
var ignoreSearch: Boolean
var ignoreMethod: Boolean
var ignoreVary: Boolean
var cacheName: String
}
native public open class CacheBatchOperation {
inline fun CacheQueryOptions(ignoreSearch: Boolean = false, ignoreMethod: Boolean = false, ignoreVary: Boolean = false, cacheName: String): CacheQueryOptions {
val o = js("({})") as CacheQueryOptions
o.`ignoreSearch` = ignoreSearch
o.`ignoreMethod` = ignoreMethod
o.`ignoreVary` = ignoreVary
o.`cacheName` = cacheName
return o
}
native public interface CacheBatchOperation {
var type: String
var request: Request
var response: Response
var options: CacheQueryOptions
}
inline fun CacheBatchOperation(type: String, request: Request, response: Response, options: CacheQueryOptions): CacheBatchOperation {
val o = js("({})") as CacheBatchOperation
o.`type` = type
o.`request` = request
o.`response` = response
o.`options` = options
return o
}
native public interface CacheStorage {
fun match(request: dynamic, options: CacheQueryOptions = noImpl): dynamic = noImpl
fun has(cacheName: String): dynamic = noImpl
+16 -4
View File
@@ -112,9 +112,21 @@ native public open class ProgressEvent(type: String, eventInitDict: ProgressEven
get() = noImpl
}
native public open class ProgressEventInit : EventInit() {
var lengthComputable: Boolean = false
var loaded: Long = 0
var total: Long = 0
native public interface ProgressEventInit : EventInit {
var lengthComputable: Boolean
var loaded: Long
var total: Long
}
inline fun ProgressEventInit(lengthComputable: Boolean = false, loaded: Long = 0, total: Long = 0, bubbles: Boolean = false, cancelable: Boolean = false): ProgressEventInit {
val o = js("({})") as ProgressEventInit
o.`lengthComputable` = lengthComputable
o.`loaded` = loaded
o.`total` = total
o.`bubbles` = bubbles
o.`cancelable` = cancelable
return o
}
+9 -6
View File
@@ -1,5 +1,6 @@
package org.jetbrains.idl2k
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ
import java.util.*
private fun Operation.getterOrSetter() = this.attributes.map { it.call }.toSet().let { attributes ->
@@ -22,7 +23,7 @@ fun generateFunction(repository: Repository, function: Operation, functionName:
initializer = it.defaultValue,
getterSetterNoImpl = false,
override = false,
readOnly = true,
kind = AttributeKind.ARGUMENT,
vararg = it.vararg,
static = it.static
)
@@ -66,7 +67,7 @@ fun generateAttribute(putNoImpl: Boolean, repository: Repository, attribute: Att
type = mapType(repository, attribute.type),
initializer = attribute.defaultValue,
getterSetterNoImpl = putNoImpl,
readOnly = attribute.readOnly,
kind = if (attribute.readOnly) AttributeKind.VAL else AttributeKind.VAR,
override = false,
vararg = attribute.vararg,
static = attribute.static
@@ -74,7 +75,7 @@ fun generateAttribute(putNoImpl: Boolean, repository: Repository, attribute: Att
private fun InterfaceDefinition.superTypes(repository: Repository) = superTypes.map { repository.interfaces[it] }.filterNotNull()
private fun resolveDefinitionKind(repository: Repository, iface: InterfaceDefinition, constructors: List<ExtendedAttribute> = iface.findConstructors()): GenerateDefinitionKind =
if (iface.dictionary || constructors.isNotEmpty() || iface.superTypes(repository).any { resolveDefinitionKind(repository, it) == GenerateDefinitionKind.CLASS }) {
if (constructors.isNotEmpty() || iface.superTypes(repository).any { resolveDefinitionKind(repository, it) == GenerateDefinitionKind.CLASS }) {
GenerateDefinitionKind.CLASS
} else {
GenerateDefinitionKind.TRAIT
@@ -82,7 +83,7 @@ private fun resolveDefinitionKind(repository: Repository, iface: InterfaceDefini
private fun InterfaceDefinition.mapAttributes(repository: Repository) = attributes.map { generateAttribute(!dictionary, repository, it) }
private fun InterfaceDefinition.mapOperations(repository: Repository) = operations.flatMap { generateFunctions(repository, it) }
private fun Constant.mapConstant(repository : Repository) = GenerateAttribute(name, mapType(repository, type), value, false, true, false, false, true)
private fun Constant.mapConstant(repository : Repository) = GenerateAttribute(name, mapType(repository, type), value, false, AttributeKind.VAL, false, false, true)
private val EMPTY_CONSTRUCTOR = ExtendedAttribute(null, "Constructor", emptyList())
fun generateTrait(repository: Repository, iface: InterfaceDefinition): GenerateTraitOrClass {
@@ -132,7 +133,8 @@ fun generateTrait(repository: Repository, iface: InterfaceDefinition): GenerateT
memberFunctions = (iface.mapOperations(repository) + extensions.flatMap { it.mapOperations(repository) }).distinct().toList(),
constants = (iface.constants.map { it.mapConstant(repository) } + extensions.flatMap { it.constants.map { it.mapConstant(repository) } }.distinct().toList()),
primaryConstructor = primaryConstructorWithCall,
secondaryConstructors = secondaryConstructorsWithCall
secondaryConstructors = secondaryConstructorsWithCall,
generateBuilderFunction = iface.dictionary
)
}
@@ -161,7 +163,8 @@ fun mapUnionType(it: UnionType) = GenerateTraitOrClass(
memberFunctions = emptyList(),
constants = emptyList(),
primaryConstructor = null,
secondaryConstructors = emptyList()
secondaryConstructors = emptyList(),
generateBuilderFunction = false
)
fun generateUnionTypeTraits(allUnionTypes: Sequence<UnionType>): Sequence<GenerateTraitOrClass> = allUnionTypes.map(::mapUnionType)
+11 -3
View File
@@ -25,12 +25,19 @@ data class Repository(
val enums: Map<String, EnumDefinition>
)
data class GenerateAttribute(val name: String, val type: Type, val initializer: String?, val getterSetterNoImpl: Boolean, val readOnly: Boolean, val override: Boolean, var vararg: Boolean, val static: Boolean)
enum class AttributeKind {
VAL, VAR, ARGUMENT
}
data class GenerateAttribute(val name: String, val type: Type, val initializer: String?, val getterSetterNoImpl: Boolean, val kind: AttributeKind, val override: Boolean, var vararg: Boolean, val static: Boolean)
val GenerateAttribute.getterNoImpl: Boolean
get() = getterSetterNoImpl
val GenerateAttribute.setterNoImpl: Boolean
get() = getterSetterNoImpl && !readOnly
get() = getterSetterNoImpl && kind == AttributeKind.VAR
val GenerateAttribute.isVal: Boolean
get() = kind == AttributeKind.VAL
val GenerateAttribute.isVar: Boolean
get() = kind == AttributeKind.VAR
val Type.typeSignature: String
get() = when {
@@ -74,7 +81,8 @@ data class GenerateTraitOrClass(
val memberFunctions: List<GenerateFunction>,
val constants: List<GenerateAttribute>,
val primaryConstructor: ConstructorWithSuperTypeCall?,
val secondaryConstructors: List<ConstructorWithSuperTypeCall>
val secondaryConstructors: List<ConstructorWithSuperTypeCall>,
val generateBuilderFunction: Boolean
)
val GenerateFunction.signature: String
+56 -26
View File
@@ -2,7 +2,7 @@ package org.jetbrains.idl2k
import java.math.BigInteger
private fun <O : Appendable> O.indent(commented: Boolean, level: Int) {
private fun <O : Appendable> O.indent(commented: Boolean = false, level: Int) {
if (commented) {
append("//")
}
@@ -11,23 +11,31 @@ private fun <O : Appendable> O.indent(commented: Boolean, level: Int) {
}
}
private fun Appendable.renderAttributeDeclaration(arg: GenerateAttribute, override: Boolean, open: Boolean, commented: Boolean, level: Int = 1) {
indent(commented, level)
private fun Appendable.renderAttributeDeclaration(arg: GenerateAttribute, override: Boolean, open: Boolean, omitDefaults: Boolean = false) {
when {
override -> append("override ")
open -> append("open ")
arg.vararg -> append("vararg ")
}
append(if (arg.readOnly) "val" else "var")
append(" ")
append(arg.name)
append(when(arg.kind) {
AttributeKind.VAL -> "val "
AttributeKind.VAR -> "var "
AttributeKind.ARGUMENT -> ""
})
append(arg.name.replaceKeywords())
append(": ")
append(arg.type.render())
if (arg.initializer != null) {
if (arg.initializer != null && !omitDefaults) {
append(" = ")
append(arg.initializer.replaceWrongConstants(arg.type))
}
}
private fun Appendable.renderAttributeDeclarationAsProperty(arg: GenerateAttribute, override: Boolean, open: Boolean, commented: Boolean, level: Int, omitDefaults: Boolean) {
indent(commented, level)
renderAttributeDeclaration(arg, override, open, omitDefaults)
appendln()
if (arg.getterNoImpl) {
@@ -50,19 +58,10 @@ private fun String.replaceWrongConstants(type: Type) = when {
}
private fun String.replaceKeywords() = if (this in keywords) this + "_" else this
private fun Appendable.renderArgumentsDeclaration(args: List<GenerateAttribute>, omitDefaults: Boolean) =
private fun Appendable.renderArgumentsDeclaration(args: List<GenerateAttribute>, omitDefaults: Boolean = false) =
args.map {
StringBuilder {
if (it.vararg) {
append("vararg ")
}
append(it.name.replaceKeywords())
append(": ")
append(it.type.render())
if (!omitDefaults && it.initializer != null && it.initializer != "") {
append(" = ")
append(it.initializer.replaceWrongConstants(it.type))
}
renderAttributeDeclaration(it, it.override, false, omitDefaults)
}
}.joinTo(this, ", ", "(", ")")
@@ -90,10 +89,6 @@ private fun Appendable.renderFunctionDeclaration(f: GenerateFunction, override:
}
private fun List<GenerateAttribute>.hasNoVars() = none { it.isVar }
private val GenerateAttribute.isVal: Boolean
get() = readOnly
private val GenerateAttribute.isVar: Boolean
get() = !readOnly
private fun GenerateAttribute.isCommented(parent: String) = "$parent.$name" in commentOutDeclarations || "$parent.$name: ${type.render()}" in commentOutDeclarations
private fun GenerateFunction.isCommented(parent: String) =
@@ -154,7 +149,13 @@ fun Appendable.render(allTypes: Map<String, GenerateTraitOrClass>, typeNamesToUn
.filter { it !in superAttributes && !it.static && (it.isVar || (it.isVal && superAttributesByName[it.name]?.hasNoVars() ?: true)) }
.map { it.dynamicIfUnknownType(allTypes.keySet()) }
.groupBy { it.signature }.reduceValues().values().forEach { arg ->
renderAttributeDeclaration(arg, override = arg.signature in superSignatures, open = iface.kind == GenerateDefinitionKind.CLASS && arg.readOnly, commented = arg.isCommented(iface.name))
renderAttributeDeclarationAsProperty(arg,
override = arg.signature in superSignatures,
open = iface.kind == GenerateDefinitionKind.CLASS && arg.isVal,
commented = arg.isCommented(iface.name),
omitDefaults = iface.kind == GenerateDefinitionKind.TRAIT,
level = 1
)
}
iface.memberFunctions.filter { it !in superFunctions && !it.static }.map { it.dynamicIfUnknownType(allTypes.keySet()) }.groupBy { it.signature }.reduceValues(::betterFunction).values().forEach {
renderFunctionDeclaration(it.fixRequiredArguments(iface.name), it.signature in superSignatures, commented = it.isCommented(iface.name))
@@ -168,10 +169,10 @@ fun Appendable.render(allTypes: Map<String, GenerateTraitOrClass>, typeNamesToUn
indent(false, 1)
appendln("companion object {")
iface.constants.forEach {
renderAttributeDeclaration(it, override = false, open = false, level = 2, commented = it.isCommented(iface.name))
renderAttributeDeclarationAsProperty(it, override = false, open = false, level = 2, commented = it.isCommented(iface.name), omitDefaults = false)
}
staticAttributes.forEach {
renderAttributeDeclaration(it, override = false, open = false, level = 2, commented = it.isCommented(iface.name))
renderAttributeDeclarationAsProperty(it, override = false, open = false, level = 2, commented = it.isCommented(iface.name), omitDefaults = false)
}
staticFunctions.forEach {
renderFunctionDeclaration(it.fixRequiredArguments(iface.name), override = false, level = 2, commented = it.isCommented(iface.name))
@@ -182,6 +183,35 @@ fun Appendable.render(allTypes: Map<String, GenerateTraitOrClass>, typeNamesToUn
appendln("}")
appendln()
if (iface.generateBuilderFunction) {
renderBuilderFunction(iface, allSuperTypes, allTypes.keySet())
}
}
fun Appendable.renderBuilderFunction(dictionary: GenerateTraitOrClass, allSuperTypes: List<GenerateTraitOrClass>, allTypes: Set<String>) {
val fields = (dictionary.memberAttributes + allSuperTypes.flatMap { it.memberAttributes }).distinctBy { it.signature }.map { it.copy(kind = AttributeKind.ARGUMENT) }.dynamicIfUnknownType(allTypes)
append("inline fun ${dictionary.name}")
renderArgumentsDeclaration(fields)
appendln(": ${dictionary.name} {")
indent(level = 1)
appendln("val o = js(\"({})\") as ${dictionary.name}")
appendln()
for (field in fields) {
indent(level = 1)
appendln("o.`${field.name}` = ${field.name.replaceKeywords()}")
}
appendln()
indent(level = 1)
appendln("return o")
appendln("}")
appendln()
}
fun betterFunction(f1: GenerateFunction, f2: GenerateFunction): GenerateFunction =