All Downloads are FREE. Search and download functionalities are using the official Maven repository.

elemental2.core.Reflect Maven / Gradle / Ivy

There is a newer version: 1.0.7
Show newest version
/*
 * Copyright 2018 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package elemental2.core;

import jsinterop.annotations.JsFunction;
import jsinterop.annotations.JsOverlay;
import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsType;
import jsinterop.base.Js;
import jsinterop.base.JsConstructorFn;

@JsType(isNative = true, namespace = JsPackage.GLOBAL)
public class Reflect {
  @JsFunction
  public interface ApplyTargetFn {
    RESULT onInvoke(Object... p0);
  }

  @JsType(isNative = true, name = "?", namespace = JsPackage.GLOBAL)
  public interface OwnKeysArrayUnionType {
    @JsOverlay
    static Reflect.OwnKeysArrayUnionType of(Object o) {
      return Js.cast(o);
    }

    @JsOverlay
    default Object asObject() {
      return Js.cast(this);
    }

    @JsOverlay
    default String asString() {
      return Js.asString(this);
    }

    @JsOverlay
    default boolean isObject() {
      return (Object) this instanceof Object;
    }

    @JsOverlay
    default boolean isString() {
      return (Object) this instanceof String;
    }
  }

  public static native  RESULT apply(
      Reflect.ApplyTargetFn targetFn, THIS thisArg, JsArray argList);

  @JsOverlay
  public static final  RESULT apply(
      Reflect.ApplyTargetFn targetFn, THIS thisArg, Object[] argList) {
    return apply(targetFn, thisArg, Js.>uncheckedCast(argList));
  }

  @JsOverlay
  public static final  TARGET construct(
      Class targetConstructorFn,
      JsArray argList,
      Class newTargetConstructorFn) {
    return construct(
        Js.asConstructorFn(targetConstructorFn),
        argList,
        Js.asConstructorFn(newTargetConstructorFn));
  }

  @JsOverlay
  public static final  TARGET construct(
      Class targetConstructorFn, JsArray argList) {
    return construct(Js.asConstructorFn(targetConstructorFn), argList);
  }

  @JsOverlay
  public static final  TARGET construct(
      Class targetConstructorFn,
      Object[] argList,
      Class newTargetConstructorFn) {
    return construct(
        targetConstructorFn, Js.>uncheckedCast(argList), newTargetConstructorFn);
  }

  @JsOverlay
  public static final  TARGET construct(Class targetConstructorFn, Object[] argList) {
    return construct(targetConstructorFn, Js.>uncheckedCast(argList));
  }

  public static native  TARGET construct(
      JsConstructorFn targetConstructorFn,
      JsArray argList,
      JsConstructorFn newTargetConstructorFn);

  public static native  TARGET construct(
      JsConstructorFn targetConstructorFn, JsArray argList);

  @JsOverlay
  public static final  TARGET construct(
      JsConstructorFn targetConstructorFn,
      Object[] argList,
      JsConstructorFn newTargetConstructorFn) {
    return construct(
        targetConstructorFn, Js.>uncheckedCast(argList), newTargetConstructorFn);
  }

  @JsOverlay
  public static final  TARGET construct(
      JsConstructorFn targetConstructorFn, Object[] argList) {
    return construct(targetConstructorFn, Js.>uncheckedCast(argList));
  }

  public static native boolean defineProperty(
      JsObject target, String propertyKey, ObjectPropertyDescriptor attributes);

  @JsOverlay
  public static final boolean defineProperty(
      Object target, String propertyKey, ObjectPropertyDescriptor attributes) {
    return defineProperty(Js.uncheckedCast(target), propertyKey, attributes);
  }

  public static native boolean deleteProperty(JsObject target, String propertyKey);

  @JsOverlay
  public static final boolean deleteProperty(Object target, String propertyKey) {
    return deleteProperty(Js.uncheckedCast(target), propertyKey);
  }

  public static native Object get(JsObject target, String propertyKey, JsObject receiver);

  public static native Object get(JsObject target, String propertyKey);

  @JsOverlay
  public static final Object get(Object target, String propertyKey, Object receiver) {
    return get(
        Js.uncheckedCast(target), propertyKey, Js.uncheckedCast(receiver));
  }

  @JsOverlay
  public static final Object get(Object target, String propertyKey) {
    return get(Js.uncheckedCast(target), propertyKey);
  }

  public static native ObjectPropertyDescriptor getOwnPropertyDescriptor(
      JsObject target, String propertyKey);

  @JsOverlay
  public static final ObjectPropertyDescriptor getOwnPropertyDescriptor(
      Object target, String propertyKey) {
    return getOwnPropertyDescriptor(Js.uncheckedCast(target), propertyKey);
  }

  public static native JsObject getPrototypeOf(JsObject target);

  @JsOverlay
  public static final JsObject getPrototypeOf(Object target) {
    return getPrototypeOf(Js.uncheckedCast(target));
  }

  public static native boolean has(JsObject target, String propertyKey);

  @JsOverlay
  public static final boolean has(Object target, String propertyKey) {
    return has(Js.uncheckedCast(target), propertyKey);
  }

  public static native boolean isExtensible(JsObject target);

  @JsOverlay
  public static final boolean isExtensible(Object target) {
    return isExtensible(Js.uncheckedCast(target));
  }

  public static native JsArray ownKeys(JsObject target);

  @JsOverlay
  public static final JsArray ownKeys(Object target) {
    return ownKeys(Js.uncheckedCast(target));
  }

  public static native boolean preventExtensions(JsObject target);

  @JsOverlay
  public static final boolean preventExtensions(Object target) {
    return preventExtensions(Js.uncheckedCast(target));
  }

  public static native boolean set(
      JsObject target, String propertyKey, Object value, JsObject receiver);

  public static native boolean set(JsObject target, String propertyKey, Object value);

  @JsOverlay
  public static final boolean set(
      Object target, String propertyKey, Object value, Object receiver) {
    return set(
        Js.uncheckedCast(target),
        propertyKey,
        value,
        Js.uncheckedCast(receiver));
  }

  @JsOverlay
  public static final boolean set(Object target, String propertyKey, Object value) {
    return set(Js.uncheckedCast(target), propertyKey, value);
  }

  public static native boolean setPrototypeOf(JsObject target, JsObject proto);

  @JsOverlay
  public static final boolean setPrototypeOf(Object target, Object proto) {
    return setPrototypeOf(Js.uncheckedCast(target), Js.uncheckedCast(proto));
  }
}