Package com.google.gwt.core.ext.typeinfo

Examples of com.google.gwt.core.ext.typeinfo.JMethod


  public void shouldFailOnInvalidParameter() throws Exception {
    JClassType paramType = mock(JClassType.class);
    when(paramType.isAssignableTo(genericEventType)).thenReturn(false);
    when(paramType.isClassOrInterface()).thenReturn(paramType);

    JMethod method = newMethod("myMethod", paramType);
    when(target.getInheritableMethods()).thenReturn(new JMethod[] {method});

    try {
      writer.writeDoBindEventHandlers(target, output, typeOracle);
      fail("Exception not thrown");
View Full Code Here


  @Test
  public void shouldFailForEventWhichIsNotAssignableToParameter() throws Exception {
    JClassType eventType1 = getEventType(MyEvent1.class);

    JMethod method = newMethod("myMethod", new JType[] {eventType1}, new Class[] {MyEvent2.class});
    when(target.getInheritableMethods()).thenReturn(new JMethod[] {method});

    try {
      writer.writeDoBindEventHandlers(target, output, typeOracle);
      fail("Exception not thrown");
View Full Code Here

  @Test
  public void shouldFailOnPrimitiveParameter() throws Exception {
    JClassType paramType = mock(JClassType.class);
    when(paramType.isClassOrInterface()).thenReturn(null);

    JMethod method = newMethod("myMethod", paramType);
    when(target.getInheritableMethods()).thenReturn(new JMethod[] {method});

    try {
      writer.writeDoBindEventHandlers(target, output, typeOracle);
      fail("Exception not thrown");
View Full Code Here

  @Test
  public void shouldFailOnAbstractParameter() throws Exception {
    JClassType paramType = getEventType(AbstractEvent.class);
    when(paramType.isAbstract()).thenReturn(true);
   
    JMethod method = newMethod("myMethod", paramType);
    when(target.getInheritableMethods()).thenReturn(new JMethod[] {method});
   
    try {
      writer.writeDoBindEventHandlers(target, output, typeOracle);
      fail("Exception not thrown");
View Full Code Here

  @SuppressWarnings("unchecked")
  private JMethod newMethod(String name, JType[] params, Class[] events) {
    EventHandler eventHandler = mock(EventHandler.class);
    when(eventHandler.handles()).thenReturn(events);

    JMethod method = mock(JMethod.class);
    when(method.getAnnotation(EventHandler.class)).thenReturn(eventHandler);
    when(method.getName()).thenReturn(name);
    when(method.getParameterTypes()).thenReturn(params);
    return method;
  }
View Full Code Here

  @Test
  public void shouldWriteDoBindEventHandler() throws Exception {
    JClassType eventType1 = getEventType(MyEvent1.class);
    JClassType eventType2 = getEventType(MyEvent2.class);
    JMethod method1 = newMethod("method1", eventType1);
    JMethod method2 = newMethod("method2", eventType2);
    JMethod method3 = newMethod("method3", new JType[] {genericEventType},
        new Class[] {MyEvent1.class, MyEvent2.class});
    JMethod method4 = newMethod("method4", new JType[] {},
        new Class[] {MyEvent1.class});

    when(target.getQualifiedSourceName()).thenReturn("MyTarget");
    when(target.getInheritableMethods()).thenReturn(new JMethod[] {method1, method2, method3, method4});
View Full Code Here

        "}"), output.toString());
  }

  @Test
  public void shouldFailOnZeroParametersWithoutEvents() throws Exception {
    JMethod method = newMethod("myMethod");
    when(target.getInheritableMethods()).thenReturn(new JMethod[] {method});

    try {
      writer.writeDoBindEventHandlers(target, output, typeOracle);
      fail("Exception not thrown");
View Full Code Here

   */
  private static JMethod[] findEventMethods(JClassType type) {
    List<JMethod> methods = new ArrayList<JMethod>(Arrays.asList(type.getInheritableMethods()));

    for (Iterator<JMethod> iterator = methods.iterator(); iterator.hasNext();) {
      JMethod jMethod = iterator.next();
      if (!jMethod.getName().equals("onBrowserEvent")) {
        iterator.remove();
      }
    }

    return methods.toArray(new JMethod[methods.size()]);
View Full Code Here

   * for the first one. See {@link #validateRenderParameters(JClassType)} for a
   * method that guarantees this method will succeed.
   */
  private static JParameter[] findRenderParameters(JClassType owner) {
    JMethod[] methods = owner.getInheritableMethods();
    JMethod renderMethod = null;

    for (JMethod jMethod : methods) {
      if (jMethod.getName().equals("render")) {
        renderMethod = jMethod;
      }
    }

    JParameter[] parameters = renderMethod.getParameters();
    return Arrays.copyOfRange(parameters, 1, parameters.length);
  }
View Full Code Here

   * which has a {@code void} return type, and its first parameter is of type
   * {@code SafeHtmlBuilder}.
   */
  private void validateRenderParameters(JClassType owner) throws UnableToCompleteException {
    JMethod[] methods = owner.getInheritableMethods();
    JMethod renderMethod = null;

    for (JMethod jMethod : methods) {
      if (jMethod.getName().equals("render")) {
        if (renderMethod == null) {
          renderMethod = jMethod;
        } else {
          die("%s declares more than one method named render", owner.getQualifiedSourceName());
        }
      }
    }

    if (renderMethod == null
        || renderMethod.getParameterTypes().length < 1
        || !renderMethod.getParameterTypes()[0].getErasedType().getQualifiedSourceName().equals(
            SafeHtmlBuilder.class.getCanonicalName())) {
      die("%s does not declare a render(SafeHtmlBuilder ...) method",
          owner.getQualifiedSourceName());
    }
    if (!JPrimitiveType.VOID.equals(renderMethod.getReturnType())) {
      die("%s#render(SafeHtmlBuilder ...) does not return void", owner.getQualifiedSourceName());
    }
  }
View Full Code Here

TOP

Related Classes of com.google.gwt.core.ext.typeinfo.JMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.