JClass listGenericType = ((JClass) fieldType).getTypeParameters().get(0);
JClass setGenericType = ((JClass) fieldType).getTypeParameters().get(0);
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; }
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; }
/** * 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); }
/** * 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); }
static public JType getElementType(JType collectionType){ JClass collectionClazz = (JClass)collectionType; List<JClass> elementTypes = collectionClazz.getTypeParameters(); return elementTypes.get(0); } }
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); } }
@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 ); }
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(); }
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(); }
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(); }
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(); }
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; }
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; }
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)))); } }
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); }
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); }
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; } }
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); }