org.jvnet.tiger_types.Types类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(158)

本文整理了Java中org.jvnet.tiger_types.Types类的一些代码示例,展示了Types类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Types类的具体详情如下:
包路径:org.jvnet.tiger_types.Types
类名称:Types

Types介绍

[英]Type arithmetic functions.
[中]输入算术函数。

代码示例

代码示例来源:origin: jenkinsci/jenkins

/**
 * For which context type does this annotator work?
 */
public Class<?> type() {
  Type type = Types.getBaseClass(getClass(), ConsoleAnnotatorFactory.class);
  if (type instanceof ParameterizedType)
    return Types.erasure(Types.getTypeArgument(type,0));
  else
    return Object.class;
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Configured instances of {@link ToolInstallation}s.
 *
 * @return read-only list of installations;
 *      can be empty but never null.
 */
@SuppressWarnings("unchecked")
public T[] getInstallations() {
  if (installations != null)
    return installations.clone();
  Type bt = Types.getBaseClass(getClass(), ToolDescriptor.class);
  if (bt instanceof ParameterizedType) {
    ParameterizedType pt = (ParameterizedType) bt;
    // this 't' is the closest approximation of T of Descriptor<T>.
    Class t = Types.erasure(pt.getActualTypeArguments()[0]);
    return (T[])Array.newInstance(t,0);
  } else {
    // can't infer the type. Fallback
    return emptyArray_unsafeCast();
  }
}

代码示例来源:origin: jenkinsci/configuration-as-code-plugin

private Configurator internalLookup(Type type) {
  Class clazz = Types.erasure(type);

代码示例来源:origin: javaee/glassfish

public Object get(final Dom dom, Type returnType) {
  // TODO: perhaps support more collection types?
  final List<String> v = dom.leafElements(xmlName);
  if(!(returnType instanceof ParameterizedType))
    throw new IllegalArgumentException("List needs to be parameterized");
  final Class itemType = Types.erasure(Types.getTypeArgument(returnType,0));
  // return a live list
  return new AbstractList<Object>() {
    public Object get(int index) {
      return convertLeafValue(dom, itemType, v.get(index));
    }
    public void add(int index, Object element) {
      // update the master children list, as well as this view 'v'
      dom.addLeafElement(xmlName, elementValue(element));
      v.add(index, element.toString());
    }
    public Object remove(int index) {
      dom.removeLeafElement(xmlName, v.get(index));
      return v.remove(index);
    }
    public Object set(int index, Object element) {
      dom.changeLeafElement(xmlName, v.get(index), elementValue(element));
      return v.set(index, element.toString());
    }
    public int size() {
      return v.size();
    }
  };
}

代码示例来源:origin: javaee/glassfish

/**
 * Gets the i-th type argument from a parameterized type.
 *
 * <p>
 * Unlike {@link #getTypeArgument(Type, int, Type)}, this method
 * throws {@link IllegalArgumentException} if the given type is
 * not parameterized.
 */
public static Type getTypeArgument(Type type, int i) {
  Type r = getTypeArgument(type, i, null);
  if(r==null)
    throw new IllegalArgumentException();
  return r;
}

代码示例来源:origin: javaee/glassfish

/**
 * Gets the display name of the type object
 *
 * @return
 *      a human-readable name that the type represents.
 */
public static String getTypeName(Type type) {
  if (type instanceof Class) {
    Class c = (Class) type;
    if(c.isArray())
      return getTypeName(c.getComponentType())+"[]";
    return c.getName();
  }
  return type.toString();
}

代码示例来源:origin: javaee/glassfish

/**
 * Gets the i-th type argument from a parameterized type.
 *
 * <p>
 * For example, {@code getTypeArgument([Map<Integer,String>],0)=Integer}
 * If the given type is not a parameterized type, returns the specified
 * default value.
 *
 * <p>
 * This is convenient for handling raw types and parameterized types uniformly.
 *
 * @throws IndexOutOfBoundsException
 *      If i is out of range.
 */
public static Type getTypeArgument(Type type, int i, Type defaultValue) {
  if (type instanceof ParameterizedType) {
    ParameterizedType p = (ParameterizedType) type;
    return fix(p.getActualTypeArguments()[i]);
  } else
    return defaultValue;
}

代码示例来源:origin: javaee/glassfish

/**
 * Checks if {@code sub} is a sub-type of {@code sup}.
 */
public static boolean isSubClassOf(Type sub, Type sup) {
  return erasure(sup).isAssignableFrom(erasure(sub));
}

代码示例来源:origin: javaee/glassfish

final Class itemType = Types.erasure(Types.getTypeArgument(returnType,0));

代码示例来源:origin: jenkinsci/jenkins

Type bt = Types.getBaseClass(getClass(), Descriptor.class);
if (bt instanceof ParameterizedType) {
  ParameterizedType pt = (ParameterizedType) bt;
  Class t = Types.erasure(pt.getActualTypeArguments()[0]);
  if(!t.isAssignableFrom(clazz))
    throw new AssertionError("Outer class "+clazz+" of "+getClass()+" is not assignable to "+t+". Perhaps wrong outer class?");

代码示例来源:origin: org.jvnet/tiger-types

/**
 * Gets the i-th type argument from a parameterized type.
 *
 * <p>
 * Unlike {@link #getTypeArgument(Type, int, Type)}, this method
 * throws {@link IllegalArgumentException} if the given type is
 * not parameterized.
 */
public static Type getTypeArgument(Type type, int i) {
  Type r = getTypeArgument(type, i, null);
  if(r==null)
    throw new IllegalArgumentException();
  return r;
}

代码示例来源:origin: org.jvnet/tiger-types

/**
 * Gets the display name of the type object
 *
 * @return
 *      a human-readable name that the type represents.
 */
public static String getTypeName(Type type) {
  if (type instanceof Class) {
    Class c = (Class) type;
    if(c.isArray())
      return getTypeName(c.getComponentType())+"[]";
    return c.getName();
  }
  return type.toString();
}

代码示例来源:origin: org.jvnet/tiger-types

/**
 * Gets the i-th type argument from a parameterized type.
 *
 * <p>
 * For example, {@code getTypeArgument([Map<Integer,String>],0)=Integer}
 * If the given type is not a parameterized type, returns the specified
 * default value.
 *
 * <p>
 * This is convenient for handling raw types and parameterized types uniformly.
 *
 * @throws IndexOutOfBoundsException
 *      If i is out of range.
 */
public static Type getTypeArgument(Type type, int i, Type defaultValue) {
  if (type instanceof ParameterizedType) {
    ParameterizedType p = (ParameterizedType) type;
    return fix(p.getActualTypeArguments()[i]);
  } else
    return defaultValue;
}

代码示例来源:origin: jenkinsci/jenkins

protected RunListener() {
  Type type = Types.getBaseClass(getClass(), RunListener.class);
  if (type instanceof ParameterizedType)
    targetType = Types.erasure(Types.getTypeArgument(type,0));
  else
    throw new IllegalStateException(getClass()+" uses the raw type for extending RunListener");
}

代码示例来源:origin: javaee/glassfish

/**
 * Creates a {@link Lister} instance that produces the given type.
 */
public static Lister create(Type t) {
  return create(Types.erasure(t),t);
}

代码示例来源:origin: javaee/glassfish

final Class itemType = Types.erasure(Types.getTypeArgument(m.getGenericReturnType(), 0));
if (itemType.isAssignableFrom(childType)) {
  List list = null;

代码示例来源:origin: jenkinsci/gitea-plugin

protected GiteaWebhookHandler(String eventName) {
  this.eventName = eventName;
  Type bt = Types.getBaseClass(getClass(), GiteaWebhookHandler.class);
  if (bt instanceof ParameterizedType) {
    ParameterizedType pt = (ParameterizedType) bt;
    // this 'p' is the closest approximation of P of GiteadSCMEventHandler
    Class e = Types.erasure(pt.getActualTypeArguments()[0]);
    if (!SCMEvent.class.isAssignableFrom(e)) {
      throw new AssertionError(
          "Could not determine the " + SCMEvent.class + " event class generic parameter of "
              + getClass() + " best guess was " + e);
    }
    Class p = Types.erasure(pt.getActualTypeArguments()[1]);
    if (!GiteaEvent.class.isAssignableFrom(p)) {
      throw new AssertionError(
          "Could not determine the " + GiteaEvent.class + " payload class generic parameter of "
              + getClass() + " best guess was " + p);
    }
    this.eventClass = e;
    this.payloadClass = p;
  } else {
    throw new AssertionError("Type inferrence failure for subclass " + getClass()
        + " of parameterized type " + GiteaWebhookHandler.class
        + ". Use the constructor that takes the Class objects explicitly.");
  }
}

代码示例来源:origin: eclipse-ee4j/glassfish

/**
 * Gets the i-th type argument from a parameterized type.
 *
 * <p>
 * Unlike {@link #getTypeArgument(Type, int, Type)}, this method
 * throws {@link IllegalArgumentException} if the given type is
 * not parameterized.
 */
public static Type getTypeArgument(Type type, int i) {
  Type r = getTypeArgument(type, i, null);
  if(r==null)
    throw new IllegalArgumentException();
  return r;
}

代码示例来源:origin: eclipse-ee4j/glassfish

/**
 * Gets the display name of the type object
 *
 * @return
 *      a human-readable name that the type represents.
 */
public static String getTypeName(Type type) {
  if (type instanceof Class) {
    Class c = (Class) type;
    if(c.isArray())
      return getTypeName(c.getComponentType())+"[]";
    return c.getName();
  }
  return type.toString();
}

代码示例来源:origin: eclipse-ee4j/glassfish

/**
 * Gets the i-th type argument from a parameterized type.
 *
 * <p>
 * For example, {@code getTypeArgument([Map<Integer,String>],0)=Integer}
 * If the given type is not a parameterized type, returns the specified
 * default value.
 *
 * <p>
 * This is convenient for handling raw types and parameterized types uniformly.
 *
 * @throws IndexOutOfBoundsException
 *      If i is out of range.
 */
public static Type getTypeArgument(Type type, int i, Type defaultValue) {
  if (type instanceof ParameterizedType) {
    ParameterizedType p = (ParameterizedType) type;
    return fix(p.getActualTypeArguments()[i]);
  } else
    return defaultValue;
}

相关文章