本文整理了Java中com.sun.codemodel.JClass.getTypeParameters()
方法的一些代码示例,展示了JClass.getTypeParameters()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JClass.getTypeParameters()
方法的具体详情如下:
包路径:com.sun.codemodel.JClass
类名称:JClass
方法名:getTypeParameters
[英]If this class is parameterized, return the type parameter of the given index.
[中]如果此类已参数化,则返回给定索引的类型参数。
代码示例来源:origin: joelittlejohn/jsonschema2pojo
JClass listGenericType = ((JClass) fieldType).getTypeParameters().get(0);
代码示例来源:origin: joelittlejohn/jsonschema2pojo
JClass setGenericType = ((JClass) fieldType).getTypeParameters().get(0);
代码示例来源:origin: joelittlejohn/jsonschema2pojo
private JMethod addPublicSetMethod(JDefinedClass jclass, JMethod internalSetMethod) {
JMethod method = jclass.method(PUBLIC, jclass.owner().VOID, SETTER_NAME);
JVar nameParam = method.param(String.class, "name");
JVar valueParam = method.param(Object.class, "value");
JBlock body = method.body();
JBlock notFound = body._if(JOp.not(invoke(internalSetMethod).arg(nameParam).arg(valueParam)))._then();
// if we have additional properties, then put value.
JMethod getAdditionalProperties = jclass.getMethod("getAdditionalProperties", new JType[] {});
if (getAdditionalProperties != null) {
JType additionalPropertiesType = ((JClass) (getAdditionalProperties.type())).getTypeParameters().get(1);
notFound.add(invoke(getAdditionalProperties).invoke("put").arg(nameParam)
.arg(cast(additionalPropertiesType, valueParam)));
}
// else throw exception.
else {
notFound._throw(illegalArgumentInvocation(jclass, nameParam));
}
return method;
}
代码示例来源:origin: joelittlejohn/jsonschema2pojo
private JMethod addPublicWithMethod(JDefinedClass jclass, JMethod internalSetMethod) {
JMethod method = jclass.method(PUBLIC, jclass, BUILDER_NAME);
JVar nameParam = method.param(String.class, "name");
JVar valueParam = method.param(Object.class, "value");
JBlock body = method.body();
JBlock notFound = body._if(JOp.not(invoke(internalSetMethod).arg(nameParam).arg(valueParam)))._then();
// if we have additional properties, then put value.
JMethod getAdditionalProperties = jclass.getMethod("getAdditionalProperties", new JType[] {});
if (getAdditionalProperties != null) {
JType additionalPropertiesType = ((JClass) (getAdditionalProperties.type())).getTypeParameters().get(1);
notFound.add(invoke(getAdditionalProperties).invoke("put").arg(nameParam)
.arg(cast(additionalPropertiesType, valueParam)));
}
// else throw exception.
else {
notFound._throw(illegalArgumentInvocation(jclass, nameParam));
}
body._return(_this());
return method;
}
代码示例来源:origin: com.github.jaxb-xew-plugin/jaxb-xew-plugin
/**
* Returns <code>true</code> of the given <code>type</code> is {@link JClass} and contains <code>classToCheck</code>
* in the list of parametrisations.
*/
public static boolean isListedAsParametrisation(JClass classToCheck, JType type) {
return type instanceof JClass && ((JClass) type).getTypeParameters().contains(classToCheck);
}
代码示例来源:origin: dmak/jaxb-xew-plugin
/**
* Returns <code>true</code> of the given <code>type</code> is {@link JClass} and contains <code>classToCheck</code>
* in the list of parametrisations.
*/
public static boolean isListedAsParametrisation(JClass classToCheck, JType type) {
return type instanceof JClass && ((JClass) type).getTypeParameters().contains(classToCheck);
}
代码示例来源:origin: jpmml/jpmml
static
public JType getElementType(JType collectionType){
JClass collectionClazz = (JClass)collectionType;
List<JClass> elementTypes = collectionClazz.getTypeParameters();
return elementTypes.get(0);
}
}
代码示例来源:origin: jpmml/jpmml-model
static
public JType getElementType(JType collectionType){
JClass collectionClazz = (JClass)collectionType;
List<JClass> elementTypes = collectionClazz.getTypeParameters();
if(elementTypes.size() != 1){
throw new IllegalArgumentException();
}
return elementTypes.get(0);
}
}
代码示例来源:origin: com.cedarsoft.commons/codegen
@Nonnull
public static JClass getCollectionParam( @Nonnull JClass type ) {
if ( !isCollectionType( type ) ) {
throw new IllegalArgumentException( type + " is not a collection type" );
}
List<JClass> params = type.getTypeParameters();
if ( params.size() != 1 ) {
throw new IllegalArgumentException( "Invalid type parameters cound for " + type );
}
return params.get( 0 );
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.jaxb-xjc
public NType getTypeArgument(NType nt, int i) {
if (nt instanceof EagerNType) {
EagerNType ent = (EagerNType) nt;
return create(Utils.REFLECTION_NAVIGATOR.getTypeArgument(ent.t,i));
}
if (nt instanceof NClassByJClass) {
NClassByJClass nnt = (NClassByJClass) nt;
return ref(nnt.clazz.getTypeParameters().get(i));
}
throw new UnsupportedOperationException();
}
代码示例来源:origin: sun-jaxb/jaxb-xjc
public NType getTypeArgument(NType nt, int i) {
if (nt instanceof EagerNType) {
EagerNType ent = (EagerNType) nt;
return create(REFLECTION.getTypeArgument(ent.t,i));
}
if (nt instanceof NClassByJClass) {
NClassByJClass nnt = (NClassByJClass) nt;
return ref(nnt.clazz.getTypeParameters().get(i));
}
throw new UnsupportedOperationException();
}
代码示例来源:origin: org.andromda.thirdparty.jaxb2_commons/jaxb-xjc
public NType getTypeArgument(NType nt, int i) {
if (nt instanceof EagerNType) {
EagerNType ent = (EagerNType) nt;
return create(REFLECTION.getTypeArgument(ent.t,i));
}
if (nt instanceof NClassByJClass) {
NClassByJClass nnt = (NClassByJClass) nt;
return ref(nnt.clazz.getTypeParameters().get(i));
}
throw new UnsupportedOperationException();
}
代码示例来源:origin: org.glassfish.metro/webservices-tools
public NType getTypeArgument(NType nt, int i) {
if (nt instanceof EagerNType) {
EagerNType ent = (EagerNType) nt;
return create(Utils.REFLECTION_NAVIGATOR.getTypeArgument(ent.t,i));
}
if (nt instanceof NClassByJClass) {
NClassByJClass nnt = (NClassByJClass) nt;
return ref(nnt.clazz.getTypeParameters().get(i));
}
throw new UnsupportedOperationException();
}
代码示例来源:origin: Evolveum/midpoint
private JType getContentType(JFieldVar field) {
boolean multi = isList(field.type());
JType valueClass;
if (multi) {
valueClass = ((JClass) field.type()).getTypeParameters().get(0);
} else {
valueClass = field.type();
}
return valueClass;
}
代码示例来源:origin: Evolveum/midpoint
private boolean isFieldTypeContainer(JType type, ClassOutline classOutline) {
if (type instanceof JDefinedClass) {
return isContainer((JDefinedClass) type, classOutline.parent());
} else if (isList(type)) {
JClass clazz = (JClass) type;
return isFieldTypeContainer(clazz.getTypeParameters().get(0), classOutline);
}
return false;
}
代码示例来源:origin: mklemm/jaxb2-rich-contract-plugin
public void immutableInit(final PluginContext pluginContext, final JBlock body, final JExpression instanceRef, final JFieldVar declaredField) {
if(!this.fake) {
body.assign(instanceRef.ref(getImmutableFieldName(declaredField)), PluginUtil.nullSafe(declaredField, generateImmutableListInstantiation(pluginContext, instanceRef.ref(declaredField), ((JClass)declaredField.type()).getTypeParameters().get(0))));
}
}
代码示例来源:origin: Evolveum/midpoint
private void createFieldReferenceCreateItemBody(JFieldVar field, JMethod method) {
JClass type = ((JClass) field.type()).getTypeParameters().get(0);
JBlock body = method.body();
JExpression initExpr;
initExpr = constructorExpression(method, type);
JVar decl = body.decl(type, field.name(), initExpr);
JInvocation invocation = body.invoke(decl, METHOD_SETUP_REFERENCE_VALUE);
invocation.arg(method.listParams()[0]);
body._return(decl);
}
代码示例来源:origin: Evolveum/midpoint
private void createFieldContainerCreateItemBody(JFieldVar field, JMethod method) {
JClass list = (JClass) field.type();
JClass listType = list.getTypeParameters().get(0);
JBlock body = method.body();
JVar decl = body.decl(listType, field.name(), constructorExpression(method, listType));
JInvocation invocation = body.invoke(decl, METHOD_SETUP_CONTAINER_VALUE);
invocation.arg(method.listParams()[0]);
body._return(decl);
}
代码示例来源:origin: mklemm/jaxb2-rich-contract-plugin
public static JType getElementType(final FieldOutline fieldOutline) {
final JFieldVar definedField = PluginUtil.getDeclaredField(fieldOutline);
if (definedField != null) {
if (fieldOutline.getPropertyInfo().isCollection()) {
return definedField.type().isArray() ? definedField.type().elementType() : ((JClass) definedField.type()).getTypeParameters().get(0);
} else {
return definedField.type();
}
} else {
return null;
}
}
代码示例来源:origin: Evolveum/midpoint
private void createFieldReferenceUseCreateItemBody(JFieldVar field, JMethod method) {
JClass type = ((JClass) field.type()).getTypeParameters().get(0);
JBlock body = method.body();
JExpression initExpr;
initExpr = constructorExpression(method, type);
JVar decl = body.decl(type, field.name(), initExpr);
JInvocation invocation = body.invoke(decl, METHOD_SETUP_CONTAINER);
invocation.arg(JExpr.invoke(method.listParams()[0], "getObject"));
body._return(decl);
}
内容来源于网络,如有侵权,请联系作者删除!