jsinterop.annotations.JsMethod Java Examples

The following examples show how to use jsinterop.annotations.JsMethod. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestingPredicates.java    From j2cl with Apache License 2.0 6 votes vote down vote up
private static final boolean isThenable(TypeElement type) {
  if (type == null) {
    return false;
  }

  Predicate<ExecutableElement> isJsMethod =
      method ->
          (isAnnotationPresent(method.getEnclosingElement(), JsType.class)
                  && !isAnnotationPresent(method, JsIgnore.class))
              || isAnnotationPresent(method, JsMethod.class);

  return MoreApt.getTypeHierarchy(type).stream()
      .flatMap(t -> ElementFilter.methodsIn(t.getEnclosedElements()).stream())
      .filter(m -> !m.getModifiers().contains(Modifier.STATIC))
      .filter(TestingPredicates::isThenMethod)
      .filter(m -> m.getParameters().size() == 1 || m.getParameters().size() == 2)
      .filter(isJsMethod)
      .anyMatch(
          m ->
              m.getParameters().stream()
                  .map(ve -> MoreApt.asTypeElement(ve.asType()))
                  .allMatch(t -> t != null && isAnnotationPresent(t, JsFunction.class)));
}
 
Example #2
Source File: Main.java    From j2cl with Apache License 2.0 5 votes vote down vote up
@JsAsync
@JsMethod
private static Promise<Integer> fifteen() {
  int a = await(five());
  assertTrue(a == 5);
  JsIntFunction asyncFunction =
      () -> {
        int ten = await(ten());
        return Promise.resolve(ten);
      };
  int b = await(asyncFunction.get());
  assertTrue(b == 10);
  return Promise.resolve(a + b);
}
 
Example #3
Source File: CompilerMiscRegressionTest.java    From j2cl with Apache License 2.0 5 votes vote down vote up
@JsMethod
@SuppressWarnings("unused")
private static List<String> argumentsVariableClasher(int i, String... others) {
  // Make the second parameter varargs and pass it as a whole to trigger the arguments copying
  // preamble.
  {
    int arguments = 3;
  }
  return Arrays.asList(others).subList(0, i);
}
 
Example #4
Source File: StaticPropertiesAccessor.java    From j2cl with Apache License 2.0 5 votes vote down vote up
@JsMethod
public static void entryPoint() {
  int primitive = 5;
  Object object = new Object();
  StaticPrimitiveProperties.unreadAssignedProperty = primitive;
  primitive = StaticPrimitiveProperties.readUnassignedProperty;
  StaticPrimitiveProperties.readAssignedProperty = primitive;
  primitive = StaticPrimitiveProperties.readAssignedProperty;
  StaticObjectProperties.unreadAssignedProperty = object;
  object = StaticObjectProperties.readUnassignedProperty;
  StaticObjectProperties.readAssignedProperty = object;
  object = StaticObjectProperties.readAssignedProperty;
}
 
Example #5
Source File: AnyOptimizationTest.java    From jsinterop-base with Apache License 2.0 5 votes vote down vote up
@JsMethod @SuppressWarnings("unused")
private void asPrimitive(String objectField) {
  double d = Js.asAny(objectField).asDouble();
  float f = Js.asAny(objectField).asFloat();
  long l = Js.asAny(objectField).asLong();
  int x = Js.asAny(objectField).asInt();
  short s = Js.asAny(objectField).asShort();
  char c = Js.asAny(objectField).asChar();
  byte b = Js.asAny(objectField).asByte();
  boolean bool = Js.asAny(objectField).asBoolean();
}
 
Example #6
Source File: Main.java    From j2cl with Apache License 2.0 5 votes vote down vote up
@JsMethod
private static double sumWithoutBoxingJsVarargs(@DoNotAutobox Object... numbers) {
  double sum = 0;
  for (Object number : numbers) {
    sum += (Double) number;
  }
  return sum;
}
 
Example #7
Source File: Main.java    From j2cl with Apache License 2.0 5 votes vote down vote up
@JsMethod
public static void entryPoint() {
  new Main().execute();

  Function jsFunction = new FunctionImpl();
  jsFunction = s -> log(s);
  jsFunction.apply("foo");

  new MyJsType();

  new Object() {
    @JsMethod
    void foo() {}
  };
}
 
Example #8
Source File: Lambdas.java    From j2cl with Apache License 2.0 4 votes vote down vote up
@JsMethod
T get();
 
Example #9
Source File: JsPropertyTest.java    From j2cl with Apache License 2.0 4 votes vote down vote up
@JsMethod
private static native int getProperty(Object object, String name);
 
Example #10
Source File: JsExportTest.java    From j2cl with Apache License 2.0 4 votes vote down vote up
@JsMethod(
    namespace = "woo.MyClassExportsMethodWithoutReference", name = "onlyCalledFromJs")
private static native int onlyCalledFromJs();
 
Example #11
Source File: JsFunctionTest.java    From j2cl with Apache License 2.0 4 votes vote down vote up
@JsMethod
public static native int getField(Object object, String fieldName);
 
Example #12
Source File: EnumOptimizationTest.java    From j2cl with Apache License 2.0 4 votes vote down vote up
@JsMethod
private void unusedJsEnumBoxes() {
  Object o1 = MyJsEnum.ONE;
  Object o2 = MyJsEnum.TWO;
}
 
Example #13
Source File: JsTypeVarargsTest.java    From j2cl with Apache License 2.0 4 votes vote down vote up
@JsMethod
private static Class<?> getVarargsArrayClass(String... varargs) {
  return varargs.getClass();
}
 
Example #14
Source File: InternalType2.java    From j2cl with Apache License 2.0 4 votes vote down vote up
@JsMethod
void foo() {}
 
Example #15
Source File: PropertyUtils.java    From j2cl with Apache License 2.0 4 votes vote down vote up
@JsMethod
public static native boolean hasOwnPropertyMine(Object obj);
 
Example #16
Source File: Number.java    From j2cl with Apache License 2.0 4 votes vote down vote up
@JsMethod(name = "Number.isInteger", namespace = GLOBAL)
public static native boolean fun(double x);
 
Example #17
Source File: Main.java    From j2cl with Apache License 2.0 4 votes vote down vote up
@JsMethod
private static native void createFoo();
 
Example #18
Source File: JsMethodExample.java    From j2cl with Apache License 2.0 4 votes vote down vote up
@JsMethod
public void m(T t) {}
 
Example #19
Source File: JsTypeArrayTest.java    From j2cl with Apache License 2.0 4 votes vote down vote up
@JsMethod
private static native void fillArrayField(SimpleJsTypeAsAFieldHolder holder);
 
Example #20
Source File: InternalType.java    From j2cl with Apache License 2.0 4 votes vote down vote up
@JsMethod
void foo() {}
 
Example #21
Source File: JsTypeArrayTest.java    From j2cl with Apache License 2.0 4 votes vote down vote up
@JsMethod
private static native Object returnSomeFunction();
 
Example #22
Source File: JsPropertyTest.java    From j2cl with Apache License 2.0 4 votes vote down vote up
@JsMethod
private static native boolean isUndefined(int value);
 
Example #23
Source File: Main.java    From j2cl with Apache License 2.0 4 votes vote down vote up
@JsMethod
public static native int callChildBar(Child c, int a, int b);
 
Example #24
Source File: Main.java    From j2cl with Apache License 2.0 4 votes vote down vote up
@JsMethod
public static native int callChildFun(Child c, int a, int b);
 
Example #25
Source File: Main.java    From j2cl with Apache License 2.0 4 votes vote down vote up
@JsMethod
public static native int callParentFoo(Parent p, int a);
 
Example #26
Source File: Main.java    From j2cl with Apache License 2.0 4 votes vote down vote up
@JsMethod
private static native Object callFun(Object o, Object arg);
 
Example #27
Source File: Main.java    From j2cl with Apache License 2.0 4 votes vote down vote up
@JsMethod
private static native int callF1();
 
Example #28
Source File: Parent.java    From j2cl with Apache License 2.0 4 votes vote down vote up
/**
 * JsMethod that overrides a non-JsMethod without renaming.
 */
@Override
@JsMethod
public int bar(int a, int b) {
  return a * b;
}
 
Example #29
Source File: Parent.java    From j2cl with Apache License 2.0 4 votes vote down vote up
/**
 * JsMethod that overrides a non-JsMethod with renaming.
 */
@Override
@JsMethod(name = "sum")
public int fun(int a, int b) {
  return a + b;
}
 
Example #30
Source File: ValueType.java    From j2cl with Apache License 2.0 4 votes vote down vote up
@JsMethod(namespace = JsPackage.GLOBAL, name = "Object.values")
private static native Object[] values(Object a);