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

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


    if (asClass != null) {
      return getBinaryName(asClass);
    } else if (asPrimitive != null) {
      return asPrimitive.getQualifiedSourceName();
    } else if (asArray != null) {
      JType componentType = asArray.getComponentType();
      return getBinaryOrPrimitiveName(componentType) + "[]";
    } else {
      throw new InternalCompilerException("Cannot create binary name for "
          + type.getQualifiedSourceName());
    }
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++) {
        JType nextType = null;
        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])) {
            nextType = possible.getReturnType();
            break;
          }
        }

        if (nextType == null) {
          for (JClassType superType : type.isClassOrInterface().getFlattenedSupertypeHierarchy()) {
            JField field = superType.isClassOrInterface().findField(localPath[i]);
            if (field != null && field.isPublic()) {
              nextType = field.getType();
              break;
            }
          }
        }
        type = nextType;
        if (type == null) {
          return null;
        }
      }
      return type;
    }

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

          params.add(expr.append(")").toString());
          code.log(Type.DEBUG, "Final compiled expression: " + expr);
        } 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);
          if (collectionType == null) {
            logger.log(Type.ERROR, "Reference in 'for' attribute could not be found: '" + loopRef + "'. Please fix the expression in your template.");
            throw new UnableToCompleteException();
          }
          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

      return primitiveType.getJNISignature();
    }

    JArrayType arrayType = type.isArray();
    if (arrayType != null) {
      JType component = arrayType.getComponentType();
      if (component.isClassOrInterface() != null) {
        return "[L" + computeBinaryClassName(arrayType.getComponentType())
            + ";";
      } else {
        return "[" + computeBinaryClassName(arrayType.getComponentType());
      }
View Full Code Here

    }
  }

  private JType resolveArray(Type type) {
    assert type.getSort() == Type.ARRAY;
    JType resolvedType = resolveType(type.getElementType());
    int dims = type.getDimensions();
    for (int i = 0; i < dims; ++i) {
      resolvedType = typeOracle.getArrayType(resolvedType);
    }
    return resolvedType;
View Full Code Here

    // Get modifiers.
    //
    jfield.addModifierBits(mapBits(ASM_TO_SHARED_MODIFIERS, field.getAccess()));

    String signature = field.getSignature();
    JType fieldType;
    if (signature != null) {
      SignatureReader reader = new SignatureReader(signature);
      JType[] fieldTypeRef = new JType[1];
      reader.acceptType(new ResolveTypeSignature(resolver, binaryMapper,
          logger, fieldTypeRef, typeParamLookup, null));
View Full Code Here

        return false;
      }
    } else {
      if (hasReturnType) {
        Type returnType = Type.getReturnType(methodData.getDesc());
        JType returnJType = resolveType(returnType);
        if (returnJType == null) {
          return false;
        }
        ((JMethod) method).setReturnType(returnJType);
      }
View Full Code Here

    Type[] argTypes = methodData.getArgTypes();
    String[] argNames = methodData.getArgNames();
    boolean argNamesAreReal = methodData.hasActualArgNames();
    List<CollectAnnotationData>[] paramAnnot = methodData.getArgAnnotations();
    for (int i = 0; i < argTypes.length; ++i) {
      JType argType = resolveType(argTypes[i]);
      if (argType == null) {
        return false;
      }
      // Try to resolve annotations, ignore any that fail.
      Map<Class<? extends Annotation>, Annotation> declaredAnnotations = new HashMap<Class<? extends Annotation>, Annotation>();
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.