Examples of JMethod


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

          branchedLogger.log(TreeLogger.ERROR,
              "A Feature interface must define no more then one method", null);
          throw new UnableToCompleteException();
        }

        JMethod m = methods[0];
        JParameter[] params = m.getParameters();

        if (params.length != 1) {
          branchedLogger.log(TreeLogger.ERROR, m.getName()
              + " must have exactly one parameter", null);
          throw new UnableToCompleteException();
        }

        JClassType featureClass = params[0].getType().isClassOrInterface();

        if (featureClass == null) {
          branchedLogger.log(TreeLogger.ERROR, "The parameter "
              + params[0].getName() + " must be a class or interface", null);
          throw new UnableToCompleteException();

        } else if (featureClass.isInterface() != null
            || featureClass.isAbstract()) {
          deferredFeatures.put(featureClass, m.getName());
        } else {
          try {
            featureClass.getConstructor(new JType[0]);
          } catch (NotFoundException e) {
            branchedLogger.log(TreeLogger.ERROR, "The "
                + featureClass.getName()
                + " type must have a zero-arg constructor", e);
            throw new UnableToCompleteException();
          }
          if (!gadgetFeatureType.isAssignableFrom(featureClass)) {
            branchedLogger.log(TreeLogger.ERROR, "The parameter "
                + params[0].getName() + " must be assignable to GadgetFeature",
                null);
            throw new UnableToCompleteException();
          }
          concreteFeatures.put(featureClass, m.getName());
        }
      }
    }
    // Writing initializing code
    // Features instantiated with deferred bindings are created in Java
View Full Code Here

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

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

    /** 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

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

    /** 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

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

        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

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

          /*
           * 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

Examples of com.google.gwt.dev.javac.typemodel.JMethod

    parser.addSourceForType(bar, BAR);
    JClassType baz = state.getTypeOracle().getType("test.Baz");
    parser.addSourceForType(baz, BAZ);
    JClassType baz1 = state.getTypeOracle().getType("test.Baz.Baz1");
    JClassType baz2 = state.getTypeOracle().getType("test.Baz.Baz2");
    JMethod method = foo.getMethod("value", new JType[]{
        string, JPrimitiveType.INT});
    String[] arguments = parser.getArguments(method);
    assertNotNull(arguments);
    assertEquals(2, arguments.length);
    assertEquals("a", arguments[0]);
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JMethod

      logger.log(TreeLogger.ERROR, "Module entry point class '"
          + originalMainClassName + "' must not be abstract", null);
      throw new UnableToCompleteException();
    }

    JMethod entryMethod = findMainMethodRecurse(reboundEntryType);
    if (entryMethod == null) {
      logger.log(TreeLogger.ERROR,
          "Could not find entry method 'onModuleLoad()' method in entry point class '"
              + originalMainClassName + "'", null);
      throw new UnableToCompleteException();
    }

    if (entryMethod.isAbstract()) {
      logger.log(TreeLogger.ERROR,
          "Entry method 'onModuleLoad' in entry point class '"
              + originalMainClassName + "' must not be abstract", null);
      throw new UnableToCompleteException();
    }
    SourceInfo sourceInfo = reboundEntryType.getSourceInfo().makeChild(
        JavaToJavaScriptCompiler.class, "Rebound entry point");

    JExpression qualifier = null;
    if (!entryMethod.isStatic()) {
      qualifier = JGwtCreate.createInstantiationExpression(sourceInfo,
          entryClass);

      if (qualifier == null) {
        logger.log(
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JMethod

  private static void findEntryPoints(TreeLogger logger,
      RebindPermutationOracle rpo, String[] mainClassNames, JProgram program)
      throws UnableToCompleteException {
    SourceInfo sourceInfo = program.createSourceInfoSynthetic(
        JavaToJavaScriptCompiler.class, "Bootstrap method");
    JMethod bootStrapMethod = program.createMethod(sourceInfo,
        "init".toCharArray(), program.getIndexedType("EntryMethodHolder"),
        program.getTypeVoid(), false, true, true, false, false);
    bootStrapMethod.freezeParamTypes();

    JMethodBody body = (JMethodBody) bootStrapMethod.getBody();
    JBlock block = body.getBlock();

    // Also remember $entry, which we'll handle specially in GenerateJsAst
    JMethod registerEntry = program.getIndexedMethod("Impl.registerEntry");
    program.addEntryMethod(registerEntry);

    for (String mainClassName : mainClassNames) {
      block.addStmt(makeStatsCalls(program, mainClassName));
      JDeclaredType mainType = program.getFromTypeMap(mainClassName);

      if (mainType == null) {
        logger.log(TreeLogger.ERROR,
            "Could not find module entry point class '" + mainClassName + "'",
            null);
        throw new UnableToCompleteException();
      }

      JMethod mainMethod = findMainMethod(mainType);
      if (mainMethod != null && mainMethod.isStatic()) {
        JMethodCall onModuleLoadCall = new JMethodCall(null, null, mainMethod);
        block.addStmt(onModuleLoadCall.makeStatement());
        continue;
      }
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JMethod

    return null;
  }

  private static JMethod findMainMethodRecurse(JDeclaredType declaredType) {
    for (JDeclaredType it = declaredType; it != null; it = it.getSuperClass()) {
      JMethod result = findMainMethod(it);
      if (result != null) {
        return result;
      }
    }
    return null;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.