Exemplo n.º 1
0
  public JParameterizedType asParameterizationOf(JGenericType type) {
    Set<JClassType> supertypes = getFlattenedSuperTypeHierarchy(this);
    for (JClassType supertype : supertypes) {
      JParameterizedType isParameterized = supertype.isParameterized();
      if (isParameterized != null && isParameterized.getBaseType() == type) {
        return isParameterized;
      }

      JRawType isRaw = supertype.isRawType();
      if (isRaw != null && isRaw.getBaseType() == type) {
        return isRaw.asParameterizedByWildcards();
      }
    }

    return null;
  }
Exemplo n.º 2
0
  public String init(
      TypeOracle oracle,
      JField targetWidgetField,
      JType targetType,
      JField targetEntityMember,
      JField targetEntityField,
      String variable,
      List<JField> fields) {
    JClassType widgetCollectionType = targetWidgetField.getType().isClassOrInterface();
    JClassType entityCollectionType = targetEntityMember.getType().isClassOrInterface();

    JParameterizedType paramaterizedType = widgetCollectionType.isParameterized();

    if (paramaterizedType == null) {
      throw new RuntimeException(
          "cannot generateGetField mappers for collection of widgets (the collection is not properly parameterized: eg. List<Widget>)");
    }

    JClassType widgetType = paramaterizedType.getTypeArgs()[0];
    varName =
        targetEntityField.getType().isClassOrInterface().getName()
            + targetWidgetField.getName()
            + "Mapper";

    if (compiledTemplate == null) {
      InputStream istream = this.getClass().getResourceAsStream("CollectionFMGenerator.mv");
      compiledTemplate = TemplateCompiler.compileTemplate(istream, null);
    }

    Map vars = new HashMap();
    vars.put("typeOracle", oracle);
    vars.put("targetWidgetField", targetWidgetField);
    vars.put("targetEntityField", targetEntityField);
    vars.put("targetEntityMember", targetEntityMember);
    vars.put("widgetType", widgetType);
    vars.put("entityCollectionType", entityCollectionType);
    vars.put("widgetCollectionType", widgetCollectionType);
    vars.put("varName", varName);

    return String.valueOf(TemplateRuntime.execute(compiledTemplate, vars));
  }
Exemplo n.º 3
0
  /**
   * Returns <code>true</code> if the type arguments of the rhs parameterized type are assignable to
   * the type arguments of the lhs parameterized type.
   */
  private static boolean areTypeArgumentsAssignable(
      JParameterizedType lhsType, JParameterizedType rhsType) {
    // areClassTypesAssignable should prevent us from getting here if the types
    // are referentially equal.
    assert (lhsType != rhsType);
    assert (lhsType.getBaseType() == rhsType.getBaseType());

    JClassType[] lhsTypeArgs = lhsType.getTypeArgs();
    JClassType[] rhsTypeArgs = rhsType.getTypeArgs();
    JGenericType lhsBaseType = lhsType.getBaseType();

    // Compare at least as many formal type parameters as are declared on the
    // generic base type. gwt.typeArgs could cause more types to be included.

    JTypeParameter[] lhsTypeParams = lhsBaseType.getTypeParameters();
    for (int i = 0; i < lhsTypeParams.length; ++i) {
      if (!doesTypeArgumentContain(lhsTypeArgs[i], rhsTypeArgs[i])) {
        return false;
      }
    }

    return true;
  }