当前位置: 首页>>代码示例>>Java>>正文


Java ParameterizedType.getOwnerType方法代码示例

本文整理汇总了Java中java.lang.reflect.ParameterizedType.getOwnerType方法的典型用法代码示例。如果您正苦于以下问题:Java ParameterizedType.getOwnerType方法的具体用法?Java ParameterizedType.getOwnerType怎么用?Java ParameterizedType.getOwnerType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.reflect.ParameterizedType的用法示例。


在下文中一共展示了ParameterizedType.getOwnerType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: canonicalize

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
/**
 * Returns a type that is functionally equal but not necessarily equal according to {@link
 * Object#equals(Object) Object.equals()}.
 */
static Type canonicalize(Type type) {
  if (type instanceof Class) {
    Class<?> c = (Class<?>) type;
    return c.isArray() ? new GenericArrayTypeImpl(canonicalize(c.getComponentType())) : c;

  } else if (type instanceof ParameterizedType) {
    if (type instanceof ParameterizedTypeImpl) return type;
    ParameterizedType p = (ParameterizedType) type;
    return new ParameterizedTypeImpl(p.getOwnerType(),
        p.getRawType(), p.getActualTypeArguments());

  } else if (type instanceof GenericArrayType) {
    if (type instanceof GenericArrayTypeImpl) return type;
    GenericArrayType g = (GenericArrayType) type;
    return new GenericArrayTypeImpl(g.getGenericComponentType());

  } else if (type instanceof WildcardType) {
    if (type instanceof WildcardTypeImpl) return type;
    WildcardType w = (WildcardType) type;
    return new WildcardTypeImpl(w.getUpperBounds(), w.getLowerBounds());

  } else {
    return type; // This type is unsupported!
  }
}
 
开发者ID:hzsweers,项目名称:inspector,代码行数:30,代码来源:Types.java

示例2: toStringPT

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
static String toStringPT(ParameterizedType pt) {
    StringBuilder sb = new StringBuilder();
    Type ownerType = pt.getOwnerType();
    Class<?> rawType = (Class<?>) pt.getRawType();
    Type[] actualTypeArguments = pt.getActualTypeArguments();
    sb.append(rawType.getName().replace('$', '.'));

    if (actualTypeArguments != null && actualTypeArguments.length > 0) {
        sb.append("<");
        boolean first = true;
        for (Type t : actualTypeArguments) {
            if (!first)
                sb.append(", ");
            sb.append(((Class<?>) t).getName());
            first = false;
        }
        sb.append(">");
    }

    return sb.toString();
}
 
开发者ID:sap-nocops,项目名称:Jerkoff,代码行数:22,代码来源:GsonTest.java

示例3: onParameterizdType

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
public Type onParameterizdType(ParameterizedType p, BinderArg args) {
    Type[] params = p.getActualTypeArguments();

    boolean different = false;
    for (int i = 0; i < params.length; i++) {
        Type t = params[i];
        params[i] = visit(t, args);
        different |= t != params[i];
    }

    Type newOwner = p.getOwnerType();
    if (newOwner != null) {
        newOwner = visit(newOwner, args);
    }
    different |= p.getOwnerType() != newOwner;

    if (!different) {
        return p;
    }

    return new ParameterizedTypeImpl((Class<?>) p.getRawType(), params, newOwner);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:ReflectionNavigator.java

示例4: canonicalize

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
/**
 * Returns a type that is functionally equal but not necessarily equal according to {@link
 * Object#equals(Object) Object.equals()}.
 */
private static Type canonicalize(Type type) {
  if (type instanceof Class) {
    Class<?> c = (Class<?>) type;
    return c.isArray() ? new GenericArrayTypeImpl(canonicalize(c.getComponentType())) : c;
  } else if (type instanceof ParameterizedType) {
    if (type instanceof ParameterizedTypeImpl) return type;
    ParameterizedType p = (ParameterizedType) type;
    return new ParameterizedTypeImpl(p.getOwnerType(),
      p.getRawType(), p.getActualTypeArguments());
  } else if (type instanceof GenericArrayType) {
    if (type instanceof GenericArrayTypeImpl) return type;
    GenericArrayType g = (GenericArrayType) type;
    return new GenericArrayTypeImpl(g.getGenericComponentType());
  } else if (type instanceof WildcardType) {
    if (type instanceof WildcardTypeImpl) return type;
    WildcardType w = (WildcardType) type;
    return new WildcardTypeImpl(w.getUpperBounds(), w.getLowerBounds());
  } else {
    return type; // This type is unsupported!
  }
}
 
开发者ID:rogues-dev,项目名称:hoard,代码行数:26,代码来源:Types.java

示例5: testGetSubtype_recursiveTypeBoundInSubtypeTranslatedAsIs

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
public void testGetSubtype_recursiveTypeBoundInSubtypeTranslatedAsIs() {
  class BaseWithTypeVar<T> {}
  class Outer<O> {
    class Sub<X> extends BaseWithTypeVar<List<X>> {}
    class Sub2<Y extends Sub2<Y>> extends BaseWithTypeVar<List<Y>> {}
  }
  ParameterizedType subtype = (ParameterizedType) new TypeToken<BaseWithTypeVar<List<?>>>() {}
          .getSubtype(Outer.Sub.class)
          .getType();
  assertEquals(Outer.Sub.class, subtype.getRawType());
  assertThat(subtype.getActualTypeArguments()[0]).isInstanceOf(WildcardType.class);
  ParameterizedType owner = (ParameterizedType) subtype.getOwnerType();
  assertEquals(Outer.class, owner.getRawType());
  // This returns a strange ? extends Sub2<Y> type, which isn't ideal.
  TypeToken<?> unused = new TypeToken<BaseWithTypeVar<List<?>>>() {}.getSubtype(Outer.Sub2.class);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:17,代码来源:TypeTokenTest.java

示例6: isFullySpecified

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
public static boolean isFullySpecified(Type type) {
    checkNotNull(type);
    if(type instanceof Class) {
        return true;
    } else if(type instanceof TypeVariable) {
        return false;
    } else if(type instanceof GenericArrayType) {
        return isFullySpecified(((GenericArrayType) type).getGenericComponentType());
    } else if(type instanceof WildcardType) {
        final WildcardType wildcard = (WildcardType) type;
        return Stream.of(wildcard.getLowerBounds()).allMatch(Types::isFullySpecified) &&
               Stream.of(wildcard.getUpperBounds()).allMatch(Types::isFullySpecified);
    } else if(type instanceof ParameterizedType) {
        final ParameterizedType parameterized = (ParameterizedType) type;
        return isFullySpecified(parameterized.getRawType()) &&
               (parameterized.getOwnerType() == null || isFullySpecified(parameterized.getOwnerType())) &&
               Stream.of(parameterized.getActualTypeArguments()).allMatch(Types::isFullySpecified);
    } else {
        throw new IllegalArgumentException("Unhandled metatype " + type.getClass());
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:22,代码来源:Types.java

示例7: canonicalize

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
public static Type canonicalize(Type type) {
    if (type instanceof Class) {
        Class<?> c = (Class) type;
        return c.isArray() ? new GenericArrayTypeImpl(C$Gson$Types.canonicalize(c.getComponentType())) : c;
    } else if (type instanceof ParameterizedType) {
        ParameterizedType p = (ParameterizedType) type;
        return new ParameterizedTypeImpl(p.getOwnerType(), p.getRawType(), p.getActualTypeArguments());
    } else if (type instanceof GenericArrayType) {
        return new GenericArrayTypeImpl(((GenericArrayType) type).getGenericComponentType());
    } else {
        if (!(type instanceof WildcardType)) {
            return type;
        }
        WildcardType w = (WildcardType) type;
        return new WildcardTypeImpl(w.getUpperBounds(), w.getLowerBounds());
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:18,代码来源:C$Gson$Types.java

示例8: isSubtypeOfParameterizedType

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
private boolean isSubtypeOfParameterizedType(ParameterizedType supertype) {
  Class<?> matchedClass = of(supertype).getRawType();
  if (!someRawTypeIsSubclassOf(matchedClass)) {
    return false;
  }
  Type[] typeParams = matchedClass.getTypeParameters();
  Type[] toTypeArgs = supertype.getActualTypeArguments();
  for (int i = 0; i < typeParams.length; i++) {
    // If 'supertype' is "List<? extends CharSequence>"
    // and 'this' is StringArrayList,
    // First step is to figure out StringArrayList "is-a" List<E> and <E> is
    // String.
    // typeParams[0] is E and fromTypeToken.get(typeParams[0]) will resolve to
    // String.
    // String is then matched against <? extends CharSequence>.
    if (!resolveType(typeParams[i]).is(toTypeArgs[i])) {
      return false;
    }
  }
  // We only care about the case when the supertype is a non-static inner class
  // in which case we need to make sure the subclass's owner type is a subtype of the
  // supertype's owner.
  return Modifier.isStatic(((Class<?>) supertype.getRawType()).getModifiers())
      || supertype.getOwnerType() == null
      || isOwnedBySubtypeOf(supertype.getOwnerType());
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:27,代码来源:TypeToken.java

示例9: canonicalize

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
/**
 * Returns a type that is functionally equal but not necessarily equal
 * according to {@link Object#equals(Object) Object.equals()}. The returned
 * type is {@link java.io.Serializable}.
 */
public static Type canonicalize(Type type) {
  if (type instanceof Class) {
    Class<?> c = (Class<?>) type;
    return c.isArray() ? new GenericArrayTypeImpl(canonicalize(c.getComponentType())) : c;

  } else if (type instanceof ParameterizedType) {
    ParameterizedType p = (ParameterizedType) type;
    return new ParameterizedTypeImpl(p.getOwnerType(),
        p.getRawType(), p.getActualTypeArguments());

  } else if (type instanceof GenericArrayType) {
    GenericArrayType g = (GenericArrayType) type;
    return new GenericArrayTypeImpl(g.getGenericComponentType());

  } else if (type instanceof WildcardType) {
    WildcardType w = (WildcardType) type;
    return new WildcardTypeImpl(w.getUpperBounds(), w.getLowerBounds());

  } else {
    // type is either serializable as-is or unsupported
    return type;
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:$Gson$Types.java

示例10: getArgument

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
private static boolean getArgument(Type[] typeArgs, TypeVariable[] typeVariables, Type[] arguments) {
    if (arguments == null || typeVariables.length == 0) {
        return false;
    }

    boolean changed = false;
    for (int i = 0; i < typeArgs.length; ++i) {
        Type typeArg = typeArgs[i];
        if (typeArg instanceof ParameterizedType) {
            ParameterizedType p_typeArg = (ParameterizedType) typeArg;
            Type[] p_typeArg_args = p_typeArg.getActualTypeArguments();
            boolean p_changed = getArgument(p_typeArg_args, typeVariables, arguments);
            if (p_changed) {
                typeArgs[i] = new ParameterizedTypeImpl(p_typeArg_args, p_typeArg.getOwnerType(), p_typeArg.getRawType());
                changed = true;
            }
        } else if (typeArg instanceof TypeVariable) {
            for (int j = 0; j < typeVariables.length; ++j) {
                if (typeArg.equals(typeVariables[j])) {
                    typeArgs[i] = arguments[j];
                    changed = true;
                }
            }
        }
    }

    return changed;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:29,代码来源:FieldInfo.java

示例11: detectJvmBehavior

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
private static ClassOwnership detectJvmBehavior() {
  class LocalClass<T> {}
  Class<?> subclass = new LocalClass<String>() {}.getClass();
  ParameterizedType parameterizedType = (ParameterizedType) subclass.getGenericSuperclass();
  for (ClassOwnership behavior : ClassOwnership.values()) {
    if (behavior.getOwnerType(LocalClass.class) == parameterizedType.getOwnerType()) {
      return behavior;
    }
  }
  throw new AssertionError();
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:12,代码来源:Types.java

示例12: resolveParameterizedType

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
private ParameterizedType resolveParameterizedType(ParameterizedType type) {
  Type owner = type.getOwnerType();
  Type resolvedOwner = (owner == null) ? null : resolveType(owner);
  Type resolvedRawType = resolveType(type.getRawType());

  Type[] args = type.getActualTypeArguments();
  Type[] resolvedArgs = resolveTypes(args);
  return Types.newParameterizedTypeWithOwner(
      resolvedOwner, (Class<?>) resolvedRawType, resolvedArgs);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:11,代码来源:TypeResolver.java

示例13: testGetSubtype_innerTypeOfGenericClassTranslatesOwnerTypeVars

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
public void testGetSubtype_innerTypeOfGenericClassTranslatesOwnerTypeVars() {
  TypeToken<TwoTypeArgs<?, ?>.InnerType<?, ?>> supertype =
      new TypeToken<TwoTypeArgs<?, ?>.InnerType<?, ?>>() {};
  TypeToken<StringForFirstTypeArg<Integer>.StringInnerType<Long>> subtype =
      new TypeToken<StringForFirstTypeArg<Integer>.StringInnerType<Long>>() {};
  assertTrue(subtype.isSubtypeOf(supertype));
  ParameterizedType actualSubtype = (ParameterizedType)
      supertype.getSubtype(subtype.getRawType()).getType();
  assertEquals(StringForFirstTypeArg.StringInnerType.class, actualSubtype.getRawType());
  assertThat(actualSubtype.getActualTypeArguments()[0]).isInstanceOf(WildcardType.class);
  ParameterizedType actualOwnerType = (ParameterizedType) actualSubtype.getOwnerType();
  assertEquals(StringForFirstTypeArg.class, actualOwnerType.getRawType());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:14,代码来源:TypeTokenTest.java

示例14: equals

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
@Override
public boolean equals(Object o) {
    if (o instanceof ParameterizedType) {
        // Check that information is equivalent
        ParameterizedType that = (ParameterizedType) o;

        if (this == that)
            return true;

        Type thatOwner   = that.getOwnerType();
        Type thatRawType = that.getRawType();

        if (false) { // Debugging
            boolean ownerEquality = (ownerType == null ?
                                     thatOwner == null :
                                     ownerType.equals(thatOwner));
            boolean rawEquality = (rawType == null ?
                                   thatRawType == null :
                                   rawType.equals(thatRawType));

            boolean typeArgEquality = Arrays.equals(actualTypeArguments, // avoid clone
                                                    that.getActualTypeArguments());
            for (Type t : actualTypeArguments) {
                System.out.printf("\t\t%s%s%n", t, t.getClass());
            }

            System.out.printf("\towner %s\traw %s\ttypeArg %s%n",
                              ownerEquality, rawEquality, typeArgEquality);
            return ownerEquality && rawEquality && typeArgEquality;
        }

        return
            Objects.equals(ownerType, thatOwner) &&
            Objects.equals(rawType, thatRawType) &&
            Arrays.equals(actualTypeArguments, // avoid clone
                          that.getActualTypeArguments());
    } else
        return false;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:40,代码来源:ParameterizedTypeImpl.java

示例15: canonicalize

import java.lang.reflect.ParameterizedType; //导入方法依赖的package包/类
/**
 * Returns a type that is functionally equal but not necessarily equal
 * according to {@link Object#equals(Object) Object.equals()}. The returned
 * type is {@link Serializable}.
 */
public static Type canonicalize(Type type) {
  if (type instanceof Class) {
    Class<?> c = (Class<?>) type;
    return c.isArray() ? new GenericArrayTypeImpl(canonicalize(c.getComponentType())) : c;

  } else if (type instanceof CompositeType) {
    return type;

  } else if (type instanceof ParameterizedType) {
    ParameterizedType p = (ParameterizedType) type;
    return new ParameterizedTypeImpl(p.getOwnerType(),
        p.getRawType(), p.getActualTypeArguments());

  } else if (type instanceof GenericArrayType) {
    GenericArrayType g = (GenericArrayType) type;
    return new GenericArrayTypeImpl(g.getGenericComponentType());

  } else if (type instanceof WildcardType) {
    WildcardType w = (WildcardType) type;
    return new WildcardTypeImpl(w.getUpperBounds(), w.getLowerBounds());

  } else {
    // type is either serializable as-is or unsupported
    return type;
  }
}
 
开发者ID:maetrive,项目名称:businessworks,代码行数:32,代码来源:MoreTypes.java


注:本文中的java.lang.reflect.ParameterizedType.getOwnerType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。