org.jvnet.tiger_types.Types.getTypeArgument()方法的使用及代码示例

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

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

Types.getTypeArgument介绍

[英]Gets the i-th type argument from a parameterized type.

Unlike #getTypeArgument(Type,int,Type), this method throws IllegalArgumentException if the given type is not parameterized.
[中]从参数化类型获取第i个类型参数。
与#getTypeArgument(Type,int,Type)不同,如果给定类型未参数化,此方法将抛出IllegalArgumentException。

代码示例

代码示例来源: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: jenkinsci/jenkins

private Class computeItemType() {
  if(clazz.isArray()) {
    return clazz.getComponentType();
  }
  if(Collection.class.isAssignableFrom(clazz)) {
    Type col = Types.getBaseClass(type, Collection.class);
    if (col instanceof ParameterizedType)
      return Types.erasure(Types.getTypeArgument(col,0));
    else
      return Object.class;
  }
  return null;
}

代码示例来源: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

/**
 * Unlike {@link #clazz}, return the parameter type 'T', which determines
 * the {@link DescriptorExtensionList} that this goes to.
 *
 * <p>
 * In those situations where subtypes cannot provide the type parameter,
 * this method can be overridden to provide it.
 */
public Class<T> getT() {
  Type subTyping = Types.getBaseClass(getClass(), Descriptor.class);
  if (!(subTyping instanceof ParameterizedType)) {
    throw new IllegalStateException(getClass()+" doesn't extend Descriptor with a type parameter.");
  }
  return Types.erasure(Types.getTypeArgument(subTyping, 0));
}

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

/**
 * Returns true if this {@link JobProperty} type is applicable to the
 * given job type.
 * 
 * <p>
 * The default implementation of this method checks if the given job type is assignable to {@code J} of
 * {@link JobProperty}{@code <J>}, but subtypes can extend this to change this behavior.
 *
 * @return
 *      true to indicate applicable, in which case the property will be
 *      displayed in the configuration screen of this job.
 */
public boolean isApplicable(Class<? extends Job> jobType) {
  Type parameterization = Types.getBaseClass(clazz, JobProperty.class);
  if (parameterization instanceof ParameterizedType) {
    ParameterizedType pt = (ParameterizedType) parameterization;
    Class applicable = Types.erasure(Types.getTypeArgument(pt, 0));
    return applicable.isAssignableFrom(jobType);
  } else {
    throw new AssertionError(clazz+" doesn't properly parameterize JobProperty. The isApplicable() method must be overridden.");
  }
}

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

/**
 * Given {@code c=MyList (extends ArrayList<Foo>), base=List}, compute the parameterization of 'base'
 * that's assignable from 'c' (in this case {@code List<Foo>}), and return its n-th type parameter
 * (n=0 would return {@code Foo}).
 *
 * <p>
 * This method is useful for doing type arithmetic.
 *
 * @throws AssertionError
 *      if c' is not parameterized.
 */
public static <B> Class getTypeParameter(Class<? extends B> c, Class<B> base, int n) {
  Type parameterization = Types.getBaseClass(c,base);
  if (parameterization instanceof ParameterizedType) {
    ParameterizedType pt = (ParameterizedType) parameterization;
    return Types.erasure(Types.getTypeArgument(pt,n));
  } else {
    throw new AssertionError(c+" doesn't properly parameterize "+base);
  }
}

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

/**
 * Auto-discovers {@link OptionHandler}s and add them to the given command line parser.
 */
protected void registerOptionHandlers() {
  try {
    for (Class c : Index.list(OptionHandlerExtension.class, Jenkins.getActiveInstance().pluginManager.uberClassLoader,Class.class)) {
      Type t = Types.getBaseClass(c, OptionHandler.class);
      CmdLineParser.registerHandler(Types.erasure(Types.getTypeArgument(t,0)), c);
    }
  } catch (IOException e) {
    throw new Error(e);
  }
}

代码示例来源: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

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

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

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

itemType = Types.getTypeArgument(col, 0);
else
  itemType = Object.class;

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

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

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

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

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

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: org.eclipse.hudson.main/hudson-core

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: org.jvnet.hudson.main/hudson-core

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: org.jvnet.hudson.main/hudson-core

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

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

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

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

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

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

/**
 * Auto-discovers {@link OptionHandler}s and add them to the given command line parser.
 */
protected void registerOptionHandlers() {
  try {
    for (Class c : Index.list(OptionHandlerExtension.class, Jenkins.getActiveInstance().pluginManager.uberClassLoader,Class.class)) {
      Type t = Types.getBaseClass(c, OptionHandler.class);
      CmdLineParser.registerHandler(Types.erasure(Types.getTypeArgument(t,0)), c);
    }
  } catch (IOException e) {
    throw new Error(e);
  }
}

相关文章