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

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


        JClassType bothAnnotationType = mock(JClassType.class);
        when(bothAnnotationType.isAnnotationPresent(XsrfProtect.class)).thenReturn(true);
        when(bothAnnotationType.isAnnotationPresent(NoXsrfProtect.class)).thenReturn(true);

        // Declare some standard methods
        JMethod protectedMethod = mock(JMethod.class);
        when(protectedMethod.isAnnotationPresent(XsrfProtect.class)).thenReturn(true);
        when(protectedMethod.isAnnotationPresent(NoXsrfProtect.class)).thenReturn(false);

        JMethod notProtectedMethod = mock(JMethod.class);
        when(notProtectedMethod.isAnnotationPresent(XsrfProtect.class)).thenReturn(false);
        when(notProtectedMethod.isAnnotationPresent(NoXsrfProtect.class)).thenReturn(true);

        JMethod noAnnotationMethod = mock(JMethod.class);
        when(noAnnotationMethod.isAnnotationPresent(XsrfProtect.class)).thenReturn(false);
        when(noAnnotationMethod.isAnnotationPresent(NoXsrfProtect.class)).thenReturn(false);

        JMethod bothAnnotationMethod = mock(JMethod.class);
        when(bothAnnotationMethod.isAnnotationPresent(XsrfProtect.class)).thenReturn(true);
        when(bothAnnotationMethod.isAnnotationPresent(NoXsrfProtect.class)).thenReturn(true);

        // Test a protected method
        when(protectedMethod.getEnclosingType()).thenReturn(protectedType);
        assertTrue(XsrfRpcProxyCreator.isMethodXsrfProtected(protectedMethod));

        when(protectedMethod.getEnclosingType()).thenReturn(notProtectedType);
        assertTrue(XsrfRpcProxyCreator.isMethodXsrfProtected(protectedMethod));

        when(protectedMethod.getEnclosingType()).thenReturn(noAnnotationType);
        assertTrue(XsrfRpcProxyCreator.isMethodXsrfProtected(protectedMethod));

        when(protectedMethod.getEnclosingType()).thenReturn(bothAnnotationType);
        assertTrue(XsrfRpcProxyCreator.isMethodXsrfProtected(protectedMethod));

        // Test a method that is explicitly not protected
        when(notProtectedMethod.getEnclosingType()).thenReturn(protectedType);
        assertFalse(XsrfRpcProxyCreator.isMethodXsrfProtected(notProtectedMethod));

        when(notProtectedMethod.getEnclosingType()).thenReturn(notProtectedType);
        assertFalse(XsrfRpcProxyCreator.isMethodXsrfProtected(notProtectedMethod));

        when(notProtectedMethod.getEnclosingType()).thenReturn(noAnnotationType);
        assertFalse(XsrfRpcProxyCreator.isMethodXsrfProtected(notProtectedMethod));

        when(notProtectedMethod.getEnclosingType()).thenReturn(bothAnnotationType);
        assertFalse(XsrfRpcProxyCreator.isMethodXsrfProtected(notProtectedMethod));

        // Test a method that is explicitly not annotated at all
        when(noAnnotationMethod.getEnclosingType()).thenReturn(protectedType);
        assertTrue(XsrfRpcProxyCreator.isMethodXsrfProtected(noAnnotationMethod));

        when(noAnnotationMethod.getEnclosingType()).thenReturn(notProtectedType);
        assertFalse(XsrfRpcProxyCreator.isMethodXsrfProtected(noAnnotationMethod));

        when(noAnnotationMethod.getEnclosingType()).thenReturn(noAnnotationType);
        assertFalse(XsrfRpcProxyCreator.isMethodXsrfProtected(noAnnotationMethod));

        when(noAnnotationMethod.getEnclosingType()).thenReturn(bothAnnotationType);
        assertTrue(XsrfRpcProxyCreator.isMethodXsrfProtected(noAnnotationMethod));

        // Test a method that is annotated with both annotations
        when(bothAnnotationMethod.getEnclosingType()).thenReturn(protectedType);
        assertTrue(XsrfRpcProxyCreator.isMethodXsrfProtected(bothAnnotationMethod));

        when(bothAnnotationMethod.getEnclosingType()).thenReturn(notProtectedType);
        assertTrue(XsrfRpcProxyCreator.isMethodXsrfProtected(bothAnnotationMethod));

        when(bothAnnotationMethod.getEnclosingType()).thenReturn(noAnnotationType);
        assertTrue(XsrfRpcProxyCreator.isMethodXsrfProtected(bothAnnotationMethod));

        when(bothAnnotationMethod.getEnclosingType()).thenReturn(bothAnnotationType);
        assertTrue(XsrfRpcProxyCreator.isMethodXsrfProtected(bothAnnotationMethod));
    }
View Full Code Here


    /** Test generateInterfaceRpcMethod(). */
    @Test public void testGenerateInterfaceRpcMethod() {
        XsrfRpcProxyCreator creator = createMockedCreator();

        StringSourceWriter writer = new StringSourceWriter();
        JMethod asyncMethod = createMockedAsyncMethod();

        String sequence = "XXXX";
        creator.generateInterfaceRpcMethod(writer, asyncMethod, sequence);
        String actual = writer.toString();

View Full Code Here

    /** Test generateTokenCallback(). */
    @Test public void testGenerateTokenCallback() {
        XsrfRpcProxyCreator creator = createMockedCreator();

        StringSourceWriter writer = new StringSourceWriter();
        JMethod asyncMethod = createMockedAsyncMethod();

        String sequence = "XXXX";
        creator.generateTokenCallback(writer, asyncMethod, sequence);
        String actual = writer.toString();

View Full Code Here

        when(callback.getType().getErasedType().getQualifiedSourceName()).thenReturn("com.google.gwt.user.client.rpc.AsyncCallback");
        when(callback.getName()).thenReturn("callback");

        JParameter[] parameters = new JParameter[] { name, callback, };

        JMethod asyncMethod = mock(JMethod.class, Mockito.RETURNS_DEEP_STUBS);
        when(asyncMethod.getReturnType().getErasedType().getQualifiedSourceName()).thenReturn("void");
        when(asyncMethod.getName()).thenReturn("createExchange");
        when(asyncMethod.getParameters()).thenReturn(parameters);
        return asyncMethod;
    }
View Full Code Here

          /*
           * Handle virtual overrides by finding the method that we would
           * normally invoke and using its declaring class as the dispatch
           * target.
           */
          JMethod implementingMethod;
          while ((implementingMethod = findOverloadUsingErasure(
              implementingType, intfMethod)) == null) {
            implementingType = implementingType.getSuperclass();
          }
          // implementingmethod and implementingType cannot be null here

          /*
           * Create a pseudo-method declaration for the interface method. This
           * should look something like
           *
           * ReturnType method$ (ParamType, ParamType)
           *
           * This must be kept in sync with the WriteJsoImpl class.
           */
          {
            String decl = getBinaryOrPrimitiveName(intfMethod.getReturnType().getErasedType())
                + " " + intfMethod.getName() + "(";
            for (JParameter param : intfMethod.getParameters()) {
              decl += ",";
              decl += getBinaryOrPrimitiveName(param.getType().getErasedType());
            }
            decl += ")";

            com.google.gwt.dev.asm.commons.Method declaration = com.google.gwt.dev.asm.commons.Method.getMethod(decl);
            addToMap(mangledNamesToDeclarations, mangledName, declaration);
          }

          /*
           * Cook up the a pseudo-method declaration for the concrete type. This
           * should look something like
           *
           * ReturnType method$ (JsoType, ParamType, ParamType)
           *
           * This must be kept in sync with the WriteJsoImpl class.
           */
          {
            String returnName = getBinaryOrPrimitiveName(implementingMethod.getReturnType().getErasedType());
            String jsoName = getBinaryOrPrimitiveName(implementingType);

            String decl = returnName + " " + intfMethod.getName() + "$ ("
                + jsoName;
            for (JParameter param : implementingMethod.getParameters()) {
              decl += ",";
              decl += getBinaryOrPrimitiveName(param.getType().getErasedType());
            }
            decl += ")";

View Full Code Here

      if (type.isAnnotation() != null) {
        // TODO(jat): !! anything else to do here?
        method = new JAnnotationMethod(type, name, typeParams,
            declaredAnnotations);
      } else {
        method = new JMethod(type, name, declaredAnnotations, typeParams);
      }
    }

    // Copy modifier flags
    method.addModifierBits(mapBits(ASM_TO_SHARED_MODIFIERS,
View Full Code Here

      }
    }

    /* Nope. Maybe a @UiFactory will make it */

    JMethod factoryMethod = writer.getOwnerClass().getUiFactoryMethod(
        resourceType);
    if (factoryMethod != null) {
      fieldWriter.setInitializer(String.format("owner.%s()",
          factoryMethod.getName()));
    }

    /*
     * If neither of the above, the FieldWriter's default GWT.create call will
     * do just fine.
View Full Code Here

      SerializableTypeOracle serializableTypeOracle,
      Map<JMethod, JMethod> syncMethToAsyncMethMap) {
    JMethod[] syncMethods = serviceIntf.getOverridableMethods();
    for (JMethod syncMethod : syncMethods) {

      JMethod asyncMethod = syncMethToAsyncMethMap.get(syncMethod);
      assert (asyncMethod != null);

      JClassType enclosingType = syncMethod.getEnclosingType();
      JParameterizedType isParameterizedType = enclosingType.isParameterized();
      if (isParameterizedType != null) {
View Full Code Here

        }

        requiredValues.put(key, value);
        unfilledRequiredParams.remove(key);
      } else {
        JMethod setter = ownerFieldClass.getSetter(key);
        JParameter[] params = setter == null ? null : setter.getParameters();

        if (setter == null || !(params.length == 1)
            || !isString(writer, params[0].getType())) {
          writer.die(elem, "No method found to apply message attribute %s",
              key);
        } else {
          setterValues.put(key, value);
        }
      }
    }

    // Now go through the element and dispatch its attributes, remembering
    // that constructor arguments get first dibs
    for (int i = elem.getAttributeCount() - 1; i >= 0; i--) {
      // Backward traversal b/c we're deleting attributes from the xml element

      XMLAttribute attribute = elem.getAttribute(i);

      // Ignore xmlns attributes
      if (attribute.getName().startsWith("xmlns:")) {
        continue;
      }

      String propertyName = attribute.getLocalName();
      if (setterValues.keySet().contains(propertyName)
          || requiredValues.containsKey(propertyName)) {
        writer.die(elem, "Duplicate attribute name: %s", propertyName);
      }

      if (unfilledRequiredParams.keySet().contains(propertyName)) {
        JType paramType = unfilledRequiredParams.get(propertyName);
        String value = elem.consumeAttributeWithDefault(attribute.getName(),
            null, paramType);
        if (value == null) {
          writer.die(elem, "Unable to parse %s as constructor argument "
              + "of type %s", attribute, paramType.getSimpleSourceName());
        }
        requiredValues.put(propertyName, value);
        unfilledRequiredParams.remove(propertyName);
      } else {
        JMethod setter = ownerFieldClass.getSetter(propertyName);
        if (setter == null) {
          writer.die(elem, "Class %s has no appropriate set%s() method",
              elem.getLocalName(), initialCap(propertyName));
        }
        String n = attribute.getName();
View Full Code Here

        eq(Type.ERROR), contains("myMethod"), isNull(Throwable.class), isNull(HelpInfo.class));
  }

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

    try {
      writer.writeDoBindEventHandlers(target, output, typeOracle);
      fail("Exception not thrown");
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.