Exemple #1
0
  @Override
  public String resolveType(final String type) {
    String original = type;
    String result = type;

    // Strip away any characters that might hinder the type matching process
    if (Types.isArray(result)) {
      original = Types.stripArray(result);
      result = Types.stripArray(result);
    }

    if (Types.isGeneric(result)) {
      original = Types.stripGenerics(result);
      result = Types.stripGenerics(result);
    }

    if (Types.isPrimitive(result)) {
      return result;
    }

    // Check for direct import matches first since they are the fastest and least work-intensive
    if (Types.isSimpleName(result)) {
      if (!hasImport(type) && Types.isJavaLang(type)) {
        result = "java.lang." + result;
      }

      if (result.equals(original)) {
        for (Import imprt : getImports()) {
          if (Types.areEquivalent(result, imprt.getQualifiedName())) {
            result = imprt.getQualifiedName();
            break;
          }
        }
      }
    }

    // If we didn't match any imports directly, we might have a wild-card/on-demand import.
    if (Types.isSimpleName(result)) {
      for (Import imprt : getImports()) {
        if (imprt.isWildcard()) {
          // TODO warn if no wild-card resolvers are configured
          // TODO Test wild-card/on-demand import resolving
          for (WildcardImportResolver r : getImportResolvers()) {
            result = r.resolve(this, result);
            if (Types.isQualified(result)) break;
          }
        }
      }
    }

    // No import matches and no wild-card/on-demand import matches means this class is in the same
    // package.
    if (Types.isSimpleName(result)) {
      if (getPackage() != null) result = getPackage() + "." + result;
    }

    return result;
  }
Exemple #2
0
 private boolean validImport(final String type) {
   return !Strings.isNullOrEmpty(type) && !Types.isPrimitive(type);
 }