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

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


          params.add(expr.append(")").toString());
        } else if (contentChunk.type == ContentType.REFERENCE) {
          sb.append("{").append(argCount++).append("}");

          JType argType = scopeContext.getType(contentChunk.content);
          if (argType == null) {
            logger.log(Type.ERROR, "Reference could not be found: '" + contentChunk.content + "'. Please fix the expression in your template.");
            throw new UnableToCompleteException();
          }
          paramTypes.add(argType.getParameterizedQualifiedSourceName());
          params.add(scopeContext.deref(contentChunk.content));

        } else {
          assert false : "Content type not supported + " + contentChunk.type;
        }

      } else if (chunk instanceof ControlChunk) {
        ControlChunk controlChunk = (ControlChunk) chunk;
        // build logic, get scoped name
        boolean hasIf = controlChunk.controls.containsKey("if");
        boolean hasFor = controlChunk.controls.containsKey("for");

        if (!hasIf && !hasFor) {
          logger.log(Type.ERROR, "<tpl> tag did not define a 'for' or 'if' attribute!");
          throw new UnableToCompleteException();
        }

        // declare a sub-template, and stash content in there, interleaving it
        // into the current template
        String subTemplate = scopeContext.declareLocalVariable("subTemplate");
        String templateInBlock = scopeContext.declareLocalVariable("innerTemplate");
        sb.append("{").append(argCount++).append("}");
        paramTypes.add("com.google.gwt.safehtml.shared.SafeHtml");
        params.add(subTemplate);
        sw.println("SafeHtml %1$s;", subTemplate);
        sw.println("SafeHtmlBuilder %1$s_builder = new SafeHtmlBuilder();", subTemplate);

        // find the context that should be passed to the child template
        final Context childScope;

        // if we have both for and if, if needs to wrap the for
        if (hasIf) {
          ConditionParser p = new ConditionParser(logger);
          List<Token> tokens = p.parse(controlChunk.controls.get("if"));
          StringBuilder condition = new StringBuilder();
          for (Token t : tokens) {
            switch (t.type) {
              case ExpressionLiteral:
                condition.append(t.contents);
                break;
              case MethodInvocation:
                Matcher invoke = Pattern.compile("([a-zA-Z0-9\\._]+)\\:([a-zA-Z0-9_]+)\\(([^\\)]*)\\)").matcher(
                    t.contents);
                invoke.matches();
                String deref = scopeContext.deref(invoke.group(1));
                String methodName = invoke.group(2);
                String args = "";
                for (String a : invoke.group(3).split(",")) {
                  String possible = scopeContext.deref(a);
                  args += possible == null ? a : possible;
                }

                condition.append(invokables.getMethodInvocation(methodName, deref, args));
                break;
              case Reference:
                condition.append("(").append(scopeContext.deref(t.contents)).append(")");
                break;
              default:
                logger.log(Type.ERROR, "Unexpected token type: " + t.type);
                throw new UnableToCompleteException();
            }
          }
          sw.println("if (%1$s) {", condition.toString());
          sw.indent();
        }
        // if there is a for, print it out, and change scope
        if (hasFor) {
          String loopRef = controlChunk.controls.get("for");

          JType collectionType = scopeContext.getType(loopRef);
          final JType localType;// type accessed within the loop
          final String localAccessor;// expr to access looped instance, where
                                     // %1$s is the loop obj, and %2$s is the
                                     // int index
          if (collectionType.isArray() != null) {
            localType = collectionType.isArray().getComponentType();
View Full Code Here


      getterExpression = this.scopedVarDeref;
    } else {
      // look in local context
      List<String> path = new LinkedList<String>(Arrays.asList(localName.split("\\.")));
      if (knownValues.containsKey(path.get(0))) {
        final JType pathRootType;
        final String pathRootAccessor;
        if (isRoot()) {
          pathRootType = knownValues.get(path.get(0));
          pathRootAccessor = path.get(0);
          path.remove(0);
        } else {// else we are scoped, and need to get data in some other way
          pathRootType = this.scopedVarType;
          pathRootAccessor = this.scopedVarDeref;
        }
        JType valueType = getType(localName);
        JClassType valueClassType = valueType.isClassOrInterface();
        if (valueClassType == null) {
          if (valueType.isArray() != null) {
            // array, use it
            valueClassType = valueType.isArray();
          } else if (valueType.isPrimitive() != null) {
            // primitive, box it
            valueClassType = getContext().getTypeOracle().findType(
                valueType.isPrimitive().getQualifiedBoxedSourceName());
          }
        }
        // if the data can be accessed directly, do that
        if (path.size() == 0) {
          getterExpression = pathRootAccessor;
View Full Code Here

   * @throws UnableToCompleteException if the number of items cannot be returned
   */
  public String derefCount(String localName) throws UnableToCompleteException {
    // assert getType(localName) is array or list
    // count is from 2.x's xcount
    JType container = getType(localName);
    if (container.isArray() != null) {
      return deref(localName) + ".length";
    } else {// assert List
      return deref(localName) + ".size()";
    }
  }
View Full Code Here

    // look in local context
    String[] localPath = localName.split("\\.");
    if (knownValues.containsKey(localPath[0])) {
      // if we have the key, then run with it -
      JType type = knownValues.get(localPath[0]);
      for (int i = 1; i < localPath.length; i++) {
        // TODO field

        JMethod[] possibleGetters = type.isClassOrInterface().getInheritableMethods();
        for (JMethod possible : possibleGetters) {
          // TODO this is wrong, if we intend to support getProperty() and
          // property(), and evaluate to the most specific method
          if (isMatchingGetter(possible, localPath[i])) {
            type = possible.getReturnType();
            break;
          }
        }
      }
      return type;
    }

    // ask parent, if any
    if (!isRoot()) {
      JType possibleType = parent.getType(localName);
      if (possibleType != null) {
        return possibleType;
      }
    }
View Full Code Here

      if (methodName.startsWith("get")) {
        String propertyName = methodName.substring(3)// getId() is reserved.
        if (propertyName.equals("Id")) {
          continue;
        }
        JType returnType = method.getReturnType();
        String returnTypeName = returnType.getSimpleSourceName();
        if (returnType.isPrimitive() != null && !returnTypeName.equals("long")
            || returnTypeName.equals("String")
            || returnTypeName.equals("Date")
            || isSubclassOf(returnType, "JSONValue")) {
          getters.add(method);
          continue;
View Full Code Here

      for (Annotation annotation : annotations)
      {
        if ((annotation instanceof QueryParam) || (annotation instanceof PathParam))
        {
          JParameter parameter = parameters[i];
          JType parameterType = parameter.getType();
          String parameterName = getParameterName(annotation);
          String parameterExpression = parameter.getName();
          if (JClassUtils.isSimpleType(parameterType))
          {
            generateMethodParamToCodeForSimpleType(srcWriter, parameterStringVariable, parameterType, parameterName,
                parameterExpression, (parameterType.isPrimitive() != null?"true":parameterExpression+"!=null"),
                annotation);
          }
          else
          {
            generateMethodParamToCodeForComplexType(srcWriter, parameterStringVariable, parameterType,
View Full Code Here

    {
      JMethod syncMethod = getSyncMethodFromAsync(asyncMethod);
     
      if (syncMethod.getAnnotation(UseSynchronizerToken.class) != null)
      {
        JType asyncReturnType = asyncMethod.getReturnType().getErasedType();
        List<JParameter> parameters = generateProxyWrapperMethodDeclaration(srcWriter, asyncMethod, asyncReturnType);

        generateProxyWrapperMethodCall(srcWriter, syncMethod, asyncMethod, asyncReturnType, parameters);

        srcWriter.outdent();
View Full Code Here

      else
      {
        needsComma = true;
      }

      JType paramType = param.getType();
      if (i == (asyncParams.length-1))
      {
        srcWriter.print("final ");
      }
      srcWriter.print(paramType.getQualifiedSourceName());
      srcWriter.print(" ");

      String paramName = param.getName();
      parameters.add(param);
      srcWriter.print(paramName);
View Full Code Here

  }

  private void generateDecodeStringForArrayType(SourcePrinter srcWriter, JArrayType objectArrayType, String jsonValueVar,
      String resultObjectVar, String resultSourceName)
    {
    JType targetObjectType = objectArrayType.getComponentType();
    String jsonCollectionVar = generateJSONValueCollectionForDecode(srcWriter, jsonValueVar, true);
   
    srcWriter.println(resultObjectVar+" = new "+targetObjectType.getParameterizedQualifiedSourceName()+"["+jsonCollectionVar+".size()];");
   
    String loopIndexVar = nameFactory.createName("i");
    String loopJsonVar = nameFactory.createName("loopJsonVar");
   
    srcWriter.println("for (int "+loopIndexVar+"=0; "+loopIndexVar+" < "+jsonCollectionVar+".size(); "+loopIndexVar+"++){");
View Full Code Here

    return resultJSONValueVar;
  }

  private void generateEncodeStringForArrayType(SourcePrinter srcWriter, JArrayType objectArrayType, String objectVar, String resultJSONValueVar)
    {
    JType targetObjectType = objectArrayType.getComponentType();
    generateJSONValueCollectionForEncode(srcWriter, resultJSONValueVar, true);

    String loopObjVar = nameFactory.createName("loopObjVar");
    srcWriter.println("for ("+targetObjectType.getParameterizedQualifiedSourceName()+" "+loopObjVar+": "+objectVar+"){");
    String encodedObjectVar = generateEncodeObject(srcWriter, targetObjectType, loopObjVar);
    srcWriter.println(resultJSONValueVar+".isArray().set("+resultJSONValueVar+".isArray().size(), "+encodedObjectVar+");");
    srcWriter.println("}");
  }
View Full Code Here

TOP

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

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.