Package java.lang.reflect

Examples of java.lang.reflect.GenericDeclaration


        }

        if (methodActualTypeArgument instanceof TypeVariable) {

            TypeVariable<?> methodTypeVariable = (TypeVariable<?>) methodActualTypeArgument;
            final GenericDeclaration methodGenericClassDeclaration = methodTypeVariable.getGenericDeclaration();
           
            // try to match up with the actual type argument of the generic superclass.
            final Type genericSuperclass = processMethodContext.getCls().getGenericSuperclass();
            if(genericSuperclass instanceof ParameterizedType) {
                final ParameterizedType parameterizedTypeOfSuperclass = (ParameterizedType)genericSuperclass;
View Full Code Here


   *         or generic array type, but not wildcard type) or {@code null} if unable to resolve at
   *         all
   */
  public static Type resolveTypeVariable(List<Type> context, TypeVariable<?> typeVariable) {
    // determine where the type variable was declared
    GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
    if (genericDeclaration instanceof Class<?>) {
      Class<?> rawGenericDeclaration = (Class<?>) genericDeclaration;
      // check if the context extends that declaration
      int contextIndex = context.size();
      ParameterizedType parameterizedType = null;
      while (parameterizedType == null && --contextIndex >= 0) {
        parameterizedType =
            getSuperParameterizedType(context.get(contextIndex), rawGenericDeclaration);
      }
      if (parameterizedType != null) {
        // find the type variable's index in the declaration's type parameters
        TypeVariable<?>[] typeParameters = genericDeclaration.getTypeParameters();
        int index = 0;
        for (; index < typeParameters.length; index++) {
          TypeVariable<?> typeParameter = typeParameters[index];
          if (typeParameter.equals(typeVariable)) {
            break;
View Full Code Here

     * @since 3.2
     */
    public static String toLongString(TypeVariable<?> var) {
        Validate.notNull(var, "var is null");
        final StringBuilder buf = new StringBuilder();
        final GenericDeclaration d = ((TypeVariable<?>) var).getGenericDeclaration();
        if (d instanceof Class<?>) {
            Class<?> c = (Class<?>) d;
            while (true) {
                if (c.getEnclosingClass() == null) {
                    buf.insert(0, c.getName());
View Full Code Here

     * @since 3.2
     */
    public static String toLongString(TypeVariable<?> var) {
        Validate.notNull(var, "var is null");
        final StringBuilder buf = new StringBuilder();
        final GenericDeclaration d = ((TypeVariable<?>) var).getGenericDeclaration();
        if (d instanceof Class<?>) {
            Class<?> c = (Class<?>) d;
            while (true) {
                if (c.getEnclosingClass() == null) {
                    buf.insert(0, c.getName());
View Full Code Here

        return fieldType;
    }

    public static Type getInheritGenericType(Class<?> clazz, TypeVariable<?> tv) {
        Type type = null;
        GenericDeclaration gd = tv.getGenericDeclaration();
        do {
            type = clazz.getGenericSuperclass();
            if (type == null) {
                return null;
            }
            if (type instanceof ParameterizedType) {
                ParameterizedType ptype = (ParameterizedType) type;
                if (ptype.getRawType() == gd) {
                    TypeVariable<?>[] tvs = gd.getTypeParameters();
                    Type[] types = ptype.getActualTypeArguments();
                    for (int i = 0; i < tvs.length; i++) {
                        if (tvs[i] == tv) return types[i];
                    }
                    return null;
View Full Code Here

  /**
   * Returns the declaring class of {@code typeVariable}, or {@code null} if it was not declared by
   * a class.
   */
  private static Class<?> declaringClassOf(TypeVariable typeVariable) {
    GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
    return genericDeclaration instanceof Class
        ? (Class<?>) genericDeclaration
        : null;
  }
View Full Code Here

        return fieldType;
    }

    public static Type getInheritGenericType(Class<?> clazz, TypeVariable<?> tv) {
        Type type = null;
        GenericDeclaration gd = tv.getGenericDeclaration();
        do {
            type = clazz.getGenericSuperclass();
            if (type == null) {
                return null;
            }
            if (type instanceof ParameterizedType) {
                ParameterizedType ptype = (ParameterizedType) type;
                if (ptype.getRawType() == gd) {
                    TypeVariable<?>[] tvs = gd.getTypeParameters();
                    Type[] types = ptype.getActualTypeArguments();
                    for (int i = 0; i < tvs.length; i++) {
                        if (tvs[i] == tv) return types[i];
                    }
                    return null;
View Full Code Here

    return fieldType;
  }

  public static Type getInheritGenericType(Class<?> clazz, TypeVariable<?> tv) {
    Type type = null;
    GenericDeclaration gd = tv.getGenericDeclaration();
    do {
      type = clazz.getGenericSuperclass();
      if (type == null) {
        return null;
      }
      if (type instanceof ParameterizedType) {
        ParameterizedType ptype = (ParameterizedType) type;
        if (ptype.getRawType() == gd) {
          TypeVariable<?>[] tvs = gd.getTypeParameters();
          Type[] types = ptype.getActualTypeArguments();
          for (int i = 0; i < tvs.length; i++) {
            if (tvs[i] == tv)
              return types[i];
          }
View Full Code Here

        return fieldType;
    }

    public static Type getInheritGenericType(Class<?> clazz, TypeVariable<?> tv) {
        Type type = null;
        GenericDeclaration gd = tv.getGenericDeclaration();
        do {
            type = clazz.getGenericSuperclass();
            if (type == null) {
                return null;
            }
            if (type instanceof ParameterizedType) {
                ParameterizedType ptype = (ParameterizedType) type;
                if (ptype.getRawType() == gd) {
                    TypeVariable<?>[] tvs = gd.getTypeParameters();
                    Type[] types = ptype.getActualTypeArguments();
                    for (int i = 0; i < tvs.length; i++) {
                        if (tvs[i] == tv) return types[i];
                    }
                    return null;
View Full Code Here

     * @since 3.2
     */
    public static String toLongString(TypeVariable<?> var) {
        Validate.notNull(var, "var is null");
        final StringBuilder buf = new StringBuilder();
        final GenericDeclaration d = ((TypeVariable<?>) var).getGenericDeclaration();
        if (d instanceof Class<?>) {
            Class<?> c = (Class<?>) d;
            while (true) {
                if (c.getEnclosingClass() == null) {
                    buf.insert(0, c.getName());
View Full Code Here

TOP

Related Classes of java.lang.reflect.GenericDeclaration

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.