/** * returns all the compile_time fields of a template representing a template parameter */ public static List<CtField<?>> getAllTemplateParameterFields(Class<? extends Template<?>> clazz, Factory factory) { CtClass<?> c = factory.Class().get(clazz); if (c == null) { throw new IllegalArgumentException("Template not in template classpath"); } List<CtField<?>> result = new ArrayList<>(); for (Field f : getAllTemplateParameterFields(clazz)) { result.add(c.getField(f.getName())); } return result; }
/** * Gets a default expression from a template field with all the template * parameters substituted. * * @param targetType * the target type * @param template * the template that holds the field * @param fieldName * the template source field * @return the expression of the template source field with all the template * parameters substituted */ public static CtExpression<?> substituteFieldDefaultExpression(CtType<?> targetType, Template<?> template, String fieldName) { CtClass<?> sourceClass = getTemplateCtClass(targetType, template); CtField<?> sourceField = sourceClass.getField(fieldName); return substitute(targetType, template, sourceField.getDefaultExpression()); }
/** * returns all the compile_time fields of a template representing a template parameter */ public static List<CtField<?>> getAllTemplateParameterFields(Class<? extends Template<?>> clazz, Factory factory) { CtClass<?> c = factory.Class().get(clazz); if (c == null) { throw new IllegalArgumentException("Template not in template classpath"); } List<CtField<?>> result = new ArrayList<CtField<?>>(); for (Field f : getAllTemplateParameterFields(clazz)) { result.add(c.getField(f.getName())); } return result; }
private static CtFieldRead getCtFieldRead(Object value, Factory factory) { final CtFieldRead fieldRead = factory.createFieldRead(); final CtClass<?> doubleClass = factory.Class().get(value.getClass()); final CtField<?> field = doubleClass.getField(getRightField(value, factory)); final CtFieldReference<?> reference = field.getReference(); fieldRead.setVariable(reference); return fieldRead; }
/** * Gets a default expression from a template field with all the template * parameters substituted. * * @param targetType * the target type * @param template * the template that holds the field * @param fieldName * the template source field * @return the expression of the template source field with all the template * parameters substituted */ public static CtExpression<?> substituteFieldDefaultExpression(CtType<?> targetType, Template<?> template, String fieldName) { CtClass<?> sourceClass = targetType.getFactory().Class().get(template.getClass()); CtField<?> sourceField = sourceClass.getField(fieldName); return substitute(targetType, template, sourceField.getDefaultExpression()); }
private static CtFieldRead<Number> getCtFieldRead(Class<?> clazz, String fieldName, Factory factory) { final CtFieldRead<Number> fieldRead = factory.createFieldRead(); final CtClass<?> doubleClass = factory.Class().get(clazz); final CtField<Number> field = (CtField<Number>) doubleClass.getField(fieldName); final CtFieldReference<Number> reference = field.getReference(); fieldRead.setVariable(reference); return fieldRead; }
final CtFieldRead<Double> fieldNegativeInfinity = factory.createFieldRead(); fieldNegativeInfinity.setType(factory.createCtTypeReference(Double.class)); final CtField<Double> negative_infinity = (CtField<Double>) factory.Class().get(Double.class).getField("NEGATIVE_INFINITY"); fieldNegativeInfinity.setVariable(negative_infinity.getReference()); fieldNegativeInfinity.setFactory(factory); final CtFieldRead<Double> fieldPositiveInfinity = factory.createFieldRead(); fieldPositiveInfinity.setType(factory.createCtTypeReference(Double.class)); final CtField<Double> positive_infinity = (CtField<Double>) factory.Class().get(Double.class).getField("POSITIVE_INFINITY"); fieldPositiveInfinity.setVariable(positive_infinity.getReference()); fieldPositiveInfinity.setFactory(factory);