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


Java TypeVariable.getGenericDeclaration方法代码示例

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


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

示例1: getInheritGenericType

import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
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;
            }
        }
        clazz = TypeUtils.getClass(type);
    } while (type != null);
    return null;
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:24,代码来源:FieldInfo.java

示例2: createByParamName

import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
private static JavaType createByParamName(final ImplementClass implementClass, final TypeVariable<?> variable) {
	GenericDeclaration declaration = variable.getGenericDeclaration();
	String name = variable.getName();
	TypeVariable<?>[] typeParameters = declaration.getTypeParameters();
	for (int index = 0; index < typeParameters.length; index++) {
		TypeVariable<?> type = typeParameters[index];
		if (name.equals(type.getName())) {
			if (declaration instanceof Class) {
				Class<?> declarationClass = (Class<?>) declaration;
				Class<?> sub = implementClass.getSubclass(declarationClass);
				if (sub != null) {
					Type genericSuperclass = implementClass.getGenericParentClass(declarationClass);
					if (genericSuperclass instanceof ParameterizedType) {
						ParameterizedType parameterizedType = (ParameterizedType) genericSuperclass;
						return create(implementClass, parameterizedType.getActualTypeArguments()[index]);
					}
					// Generics未指定
				}
				return new VariableJavaType(implementClass, type);
			} else if (declaration instanceof Executable) {
				return new VariableJavaType(implementClass, type);
			}
		}
	}
	throw new IllegalArgumentException();
}
 
开发者ID:future-architect,项目名称:uroborosql,代码行数:27,代码来源:JavaType.java

示例3: equals

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

        GenericDeclaration thatDecl = that.getGenericDeclaration();
        String thatName = that.getName();

        return
            (genericDeclaration == null ?
             thatDecl == null :
             genericDeclaration.equals(thatDecl)) &&
            (name == null ?
             thatName == null :
             name.equals(thatName));

    } else
        return false;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:20,代码来源:TypeVariableImpl.java

示例4: translateTypeVariable

import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
private static Type translateTypeVariable(Map<String, Type> lookup, TypeVariable var) {
    GenericDeclaration declaredBy = var.getGenericDeclaration();
    if (!(declaredBy instanceof Class)) {
        // if the <T> is not defined by class, there is no way to get the actual type
        return Object.class;
    }
    Class clazz = (Class) declaredBy;
    Type actualType = lookup.get(var.getName() + "@" + clazz.getCanonicalName());
    if (actualType == null) {
        // should not happen
        return Object.class;
    }
    if (actualType instanceof TypeVariable) {
        // translate to another variable, try again
        return translateTypeVariable(lookup, (TypeVariable) actualType);
    }
    return actualType;
}
 
开发者ID:zdongcoding,项目名称:jsouplib,代码行数:19,代码来源:Resource.java

示例5: equals

import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
@Override
public boolean equals(Object o) {
    if (o instanceof TypeVariable &&
            o.getClass() == TypeVariableImpl.class) {
        TypeVariable<?> that = (TypeVariable<?>) o;

        GenericDeclaration thatDecl = that.getGenericDeclaration();
        String thatName = that.getName();

        return Objects.equals(genericDeclaration, thatDecl) &&
            Objects.equals(name, thatName);

    } else
        return false;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:TypeVariableImpl.java

示例6: check2

import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
private static void check2(Type t, String what) {
    if (t instanceof ParameterizedType) {
        ParameterizedType pt = (ParameterizedType) t;
        check(pt.getActualTypeArguments(), "type argument", what);
    } else if (t instanceof TypeVariable) {
        TypeVariable<?> tv = (TypeVariable<?>) t;
        check(tv.getBounds(), "bound", what);
        GenericDeclaration gd = tv.getGenericDeclaration();
        if (gd instanceof Type)
            check((Type) gd, "declaration containing " + what);
    } else if (t instanceof WildcardType) {
        WildcardType wt = (WildcardType) t;
        check(wt.getLowerBounds(), "lower bound", "wildcard type in " + what);
        check(wt.getUpperBounds(), "upper bound", "wildcard type in " + what);
    } else if (t instanceof Class<?>) {
        Class<?> c = (Class<?>) t;
        check(c.getGenericInterfaces(), "superinterface", c.toString());
        check(c.getGenericSuperclass(), "superclass of " + c);
        check(c.getTypeParameters(), "type parameter", c.toString());
    } else if (t instanceof GenericArrayType) {
        GenericArrayType gat = (GenericArrayType) t;
        Type comp = gat.getGenericComponentType();
        if (comp instanceof Class) {
            fail("Type " + t + " uses GenericArrayType when plain " +
                    "array would do, in " + what);
        } else
            check(comp, "component type of " + what);
    } else {
        fail("TEST BUG: mutant Type " + t + " (a " + t.getClass().getName() + ")");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:32,代码来源:TestPlainArrayNotGeneric.java

示例7: declaringClassOf

import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:MoreTypes.java

示例8: equals

import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
/**
 * Returns true if {@code a} and {@code b} are equal.
 */
static boolean equals(Type a, Type b) {
    if (a == b) {
        return true; // Also handles (a == null && b == null).

    } else if (a instanceof Class) {
        return a.equals(b); // Class already specifies equals().

    } else if (a instanceof ParameterizedType) {
        if (!(b instanceof ParameterizedType)) return false;
        ParameterizedType pa = (ParameterizedType) a;
        ParameterizedType pb = (ParameterizedType) b;
        return equal(pa.getOwnerType(), pb.getOwnerType())
                && pa.getRawType().equals(pb.getRawType())
                && Arrays.equals(pa.getActualTypeArguments(), pb.getActualTypeArguments());

    } else if (a instanceof GenericArrayType) {
        if (!(b instanceof GenericArrayType)) return false;
        GenericArrayType ga = (GenericArrayType) a;
        GenericArrayType gb = (GenericArrayType) b;
        return equals(ga.getGenericComponentType(), gb.getGenericComponentType());

    } else if (a instanceof WildcardType) {
        if (!(b instanceof WildcardType)) return false;
        WildcardType wa = (WildcardType) a;
        WildcardType wb = (WildcardType) b;
        return Arrays.equals(wa.getUpperBounds(), wb.getUpperBounds())
                && Arrays.equals(wa.getLowerBounds(), wb.getLowerBounds());

    } else if (a instanceof TypeVariable) {
        if (!(b instanceof TypeVariable)) return false;
        TypeVariable<?> va = (TypeVariable<?>) a;
        TypeVariable<?> vb = (TypeVariable<?>) b;
        return va.getGenericDeclaration() == vb.getGenericDeclaration()
                && va.getName().equals(vb.getName());

    } else {
        return false; // This isn't a type we support!
    }
}
 
开发者ID:octaware,项目名称:super-volley,代码行数:43,代码来源:Utils.java

示例9: declaringClassOf

import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:maetrive,项目名称:businessworks,代码行数:11,代码来源:MoreTypes.java

示例10: declaringClassOf

import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:$Gson$Types.java

示例11: declaringClassOf

import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
private static Class<?> declaringClassOf(TypeVariable<?> typeVariable) {
    GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
    return genericDeclaration instanceof Class ? (Class) genericDeclaration : null;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:5,代码来源:C$Gson$Types.java

示例12: declaringClassOf

import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
/**
 * Returns the declaring class of {@code typeVariable}, or {@code null} if it was not declared by
 * a class.
 */
private static @Nullable Class<?> declaringClassOf(TypeVariable<?> typeVariable) {
  GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
  return genericDeclaration instanceof Class ? (Class<?>) genericDeclaration : null;
}
 
开发者ID:hzsweers,项目名称:inspector,代码行数:9,代码来源:Types.java

示例13: declaringClassOf

import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:Utils.java

示例14: declaringClassOf

import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:pCloud,项目名称:pcloud-networking-java,代码行数:9,代码来源:Types.java

示例15: equals

import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
/**
 * Returns true if {@code a} and {@code b} are equal.
 */
public static boolean equals(Type a, Type b) {
    if (a == b) {
        // also handles (a == null && b == null)
        return true;

    } else if (a instanceof Class) {
        // Class already specifies equals().
        return a.equals(b);

    } else if (a instanceof ParameterizedType) {
        if (!(b instanceof ParameterizedType)) {
            return false;
        }

        // TODO: save a .clone() call
        ParameterizedType pa = (ParameterizedType) a;
        ParameterizedType pb = (ParameterizedType) b;
        return Objects.equals(pa.getOwnerType(), pb.getOwnerType())
                && pa.getRawType().equals(pb.getRawType())
                && Arrays.equals(pa.getActualTypeArguments(), pb.getActualTypeArguments());

    } else if (a instanceof GenericArrayType) {
        if (!(b instanceof GenericArrayType)) {
            return false;
        }

        GenericArrayType ga = (GenericArrayType) a;
        GenericArrayType gb = (GenericArrayType) b;
        return equals(ga.getGenericComponentType(), gb.getGenericComponentType());

    } else if (a instanceof WildcardType) {
        if (!(b instanceof WildcardType)) {
            return false;
        }

        WildcardType wa = (WildcardType) a;
        WildcardType wb = (WildcardType) b;
        return Arrays.equals(wa.getUpperBounds(), wb.getUpperBounds())
                && Arrays.equals(wa.getLowerBounds(), wb.getLowerBounds());

    } else if (a instanceof TypeVariable) {
        if (!(b instanceof TypeVariable)) {
            return false;
        }
        TypeVariable<?> va = (TypeVariable) a;
        TypeVariable<?> vb = (TypeVariable) b;
        return va.getGenericDeclaration() == vb.getGenericDeclaration()
                && va.getName().equals(vb.getName());

    } else {
        // This isn't a type we support. Could be a generic array type, wildcard type, etc.
        return false;
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:58,代码来源:MoreTypes.java


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