示例#1
0
 @Override
 public MetaType[] getTypeParameters() {
   final List<MetaType> types = new ArrayList<MetaType>();
   for (final JClassType parm : parameterizedType.getTypeArgs()) {
     if (parm.isWildcard() != null) {
       types.add(new GWTWildcardType(oracle, parm.isWildcard()));
     } else if (parm.isTypeParameter() != null) {
       types.add(new GWTTypeVariable(oracle, parm.isTypeParameter()));
     } else if (parm.isClassOrInterface() != null
         || parm.isEnum() != null
         || parm.isPrimitive() != null
         || parm.isRawType() != null
         || parm.isArray() != null
         || parm.isAnnotation() != null) {
       types.add(GWTClass.newInstance(oracle, parm));
     } else {
       throw new IllegalArgumentException(
           "Unsupported kind of type parameter "
               + parm
               + " in type "
               + parameterizedType.getName());
     }
   }
   return types.toArray(new MetaType[types.size()]);
 }
示例#2
0
  @Override
  public MetaMethod[] getMethods() {
    final Set<MetaMethod> meths = new LinkedHashSet<MetaMethod>();
    meths.addAll(getSpecialTypeMethods());

    JClassType type = getEnclosedMetaObject().isClassOrInterface();
    if (type == null) {
      return null;
    }

    do {
      for (final JMethod jMethod : type.getMethods()) {
        if (!jMethod.isPrivate()) {
          meths.add(new GWTMethod(oracle, jMethod));
        }
      }

      for (final JClassType interfaceType : type.getImplementedInterfaces()) {
        meths.addAll(Arrays.asList(GWTClass.newInstance(oracle, interfaceType).getMethods()));
      }
    } while ((type = type.getSuperclass()) != null
        && !type.getQualifiedSourceName().equals("java.lang.Object"));
    meths.addAll(overrideMethods);

    return meths.toArray(new MetaMethod[meths.size()]);
  }
示例#3
0
 @Override
 public MetaClass[] getDeclaredClasses() {
   final JClassType[] nestedTypes = getEnclosedMetaObject().isClassOrInterface().getNestedTypes();
   final MetaClass[] declaredClasses = new MetaClass[nestedTypes.length];
   int i = 0;
   for (JClassType type : nestedTypes) {
     declaredClasses[i++] = GWTClass.newInstance(oracle, type);
   }
   return declaredClasses;
 }
示例#4
0
文件: GWTUtil.java 项目: snjeza/errai
  /**
   * Erases the {@link MetaClassFactory} cache, then populates it with types discovered via GWT's
   * TypeOracle. The reason for the initial flush of the MetaClassFactory is to support hot redeploy
   * in Dev Mode. The reason for doing this operation at all is so that the overridden class
   * definitions (super-source classes) are used in preference to the Java reflection based class
   * definitions.
   *
   * @param context The GeneratorContext supplied by the GWT compiler. Not null.
   * @param logger The TreeLogger supplied by the GWT compiler. Not null.
   */
  public static void populateMetaClassFactoryFromTypeOracle(
      final GeneratorContext context, final TreeLogger logger) {

    // if we're in production mode -- it means we're compiling, and we do not need to accommodate
    // dynamically
    // changing classes. Therefore, do a NOOP after the first successful call.
    if (typeOraclePopulated && (context.equals(populatedFrom.get()) || EnvUtil.isProdMode())) {
      return;
    }

    final TypeOracle typeOracle = context.getTypeOracle();
    MetaClassFactory.emptyCache();
    if (typeOracle != null) {
      final Set<String> translatable =
          new HashSet<String>(RebindUtils.findTranslatablePackages(context));
      translatable.remove("java.lang");
      translatable.remove("java.lang.annotation");

      for (final JClassType type : typeOracle.getTypes()) {
        if (!translatable.contains(type.getPackage().getName())) {
          logger.log(
              com.google.gwt.core.ext.TreeLogger.Type.DEBUG,
              "Skipping non-translatable " + type.getQualifiedSourceName());
          continue;
        }

        if (type.isAnnotation() != null
            || type.getQualifiedSourceName().equals("java.lang.annotation.Annotation")) {
          logger.log(
              com.google.gwt.core.ext.TreeLogger.Type.DEBUG,
              "Caching annotation type " + type.getQualifiedSourceName());

          if (!MetaClassFactory.canLoadClass(type.getQualifiedBinaryName())) {
            throw new RuntimeException(
                "a new annotation has been introduced ("
                    + type.getQualifiedSourceName()
                    + "); "
                    + "you cannot currently introduce new annotations in devmode. Please restart.");
          }

          MetaClassFactory.pushCache(
              JavaReflectionClass.newUncachedInstance(
                  MetaClassFactory.loadClass(type.getQualifiedBinaryName())));
        } else {
          logger.log(
              com.google.gwt.core.ext.TreeLogger.Type.DEBUG,
              "Caching translatable type " + type.getQualifiedSourceName());
          MetaClassFactory.pushCache(GWTClass.newInstance(typeOracle, type));
        }
      }
    }
    typeOraclePopulated = true;
    populatedFrom = new SoftReference<GeneratorContext>(context);
  }
示例#5
0
文件: GWTUtil.java 项目: snjeza/errai
  public static MetaClass eraseOrReturn(final TypeOracle oracle, final JType t) {

    if (t.isArray() != null) {
      final JType root = getRootComponentType(t.isArray());
      if (root.isTypeParameter() != null) {
        return MetaClassFactory.get(Object.class);
      }
    }
    if (t.isTypeParameter() != null) {
      return MetaClassFactory.get(Object.class);
    } else {
      return GWTClass.newInstance(oracle, t);
    }
  }
示例#6
0
文件: GWTUtil.java 项目: snjeza/errai
 public static MetaType fromType(final TypeOracle oracle, final JType t) {
   if (t.isTypeParameter() != null) {
     return new GWTTypeVariable(oracle, t.isTypeParameter());
   } else if (t.isGenericType() != null) {
     if (t.isArray() != null) {
       return new GWTGenericArrayType(oracle, t.isGenericType());
     } else {
       return new GWTGenericDeclaration(oracle, t.isGenericType());
     }
   } else if (t.isParameterized() != null) {
     return new GWTParameterizedType(oracle, t.isParameterized());
   } else if (t.isWildcard() != null) {
     return new GWTWildcardType(oracle, t.isWildcard());
   } else if (t.isClassOrInterface() != null) {
     return GWTClass.newInstance(oracle, t.isClassOrInterface());
   } else {
     return null;
   }
 }
示例#7
0
 @Override
 public MetaType getRawType() {
   return GWTClass.newInstance(oracle, parameterizedType.getRawType());
 }
示例#8
0
 @Override
 public MetaType getOwnerType() {
   return GWTClass.newInstance(oracle, parameterizedType.getEnclosingType());
 }