public static JMethod getGetter(JClassType beanType, String fieldName) throws NotFoundException { JMethod method = null; try { try { method = beanType.getMethod("get" + getterSetterDeterminator(fieldName), new JType[0]); } catch (NotFoundException e) { method = beanType.getMethod("is" + getterSetterDeterminator(fieldName), new JType[0]); } } catch (NotFoundException e) { JClassType superClass = beanType.getSuperclass(); if (superClass != null) { try { method = getGetter(superClass, fieldName); } catch (NotFoundException e1) { JClassType[] interfaces = beanType.getImplementedInterfaces(); if (interfaces != null && interfaces.length > 0) { for (JClassType intrface : interfaces) { method = getGetter(intrface, fieldName); if (method != null) { break; } } } } } } return method; }
/** * Will it comment later :) * * @throws NotFoundException */ public static JClassType getDeclaredFieldClassType(JClassType classType, String property) throws NotFoundException { JType fieldType = getDeclaredFieldType(classType, property); if (fieldType instanceof JClassType) { return ((JClassType) fieldType); } return null; }
/** * Tries to find parametrized type in interface of a class. * * @param classType * A class having parametrized interface. * @param parametrizedType * Interface where parametrized type is present. * @param position * Position in a list of parametrized types in interface. * @return Generics type in interface implemented by a class type. * @throws NotFoundException */ public static JClassType getGenericsFromInterfaceType(JClassType classType, JClassType parametrizedType, int position) throws NotFoundException { JClassType type = getGenericsFromInterfaceHierarchy(classType, parametrizedType, position); if (type != null) return type; if (classType.getSuperclass() != null) { return getGenericsFromInterfaceType(classType.getSuperclass(), parametrizedType, position); } throw new NotFoundException("Unable to find generics in type " + classType + ", where parametrized type is " + parametrizedType + " on position " + position); }
public static JMethod getSetter(JClassType beanType, String fieldName, JType fieldType) throws NotFoundException { JMethod method = null; try { method = beanType.getMethod("set" + getterSetterDeterminator(fieldName), new JType[] { fieldType }); if (method.isPrivate()) method = null; } catch (NotFoundException e) { JClassType superClass = beanType.getSuperclass(); if (superClass != null) { try { method = getSetter(superClass, fieldName, fieldType); } catch (NotFoundException e1) { JClassType[] interfaces = beanType.getImplementedInterfaces(); if (interfaces != null && interfaces.length > 0) { for (JClassType intrface : interfaces) { method = getSetter(intrface, fieldName, fieldType); if (method != null) { break; } } } } } } return method; }
field = directField; fieldType = RebindUtils.getDeclaredFieldType(beanType, specColumn.field()); } else { fieldType = RebindUtils.getDeclaredFieldType(beanType, field); JMethod setter = null; try { getter = RebindUtils.getGetter(beanType, field); setter = RebindUtils.getSetter(beanType, field, fieldType); } catch (NotFoundException e) { throw new RuntimeException("Unable to retrieve getter for field = " + field, e); String propertyFieldGetter = null; try { propertyFieldGetter = RebindUtils.getGetterForMoreDotsInBeanTable(beanType, specColumn .field()); } catch (NotFoundException e) {
/** * recursively calls {@link RebindUtils#getGetter(JClassType, String)} to * handle "more-dots strings"<br /> * e.g.: address.street returns getAddress().getStreet * * @param beanType * @param fieldName * @return string - chain of getter methods * @throws NotFoundException */ public static String getGetterForMoreDotsInBeanTable(JClassType beanType, String fieldName) throws NotFoundException { JMethod method = null; int dotIndex = fieldName.indexOf("."); if (dotIndex == -1) { method = getGetter(beanType, fieldName); if (method == null) throw new NotFoundException(); return method.getName(); } else { method = getGetter(beanType, fieldName.substring(0, dotIndex)); return method.getName() + "()." + getGetterForMoreDotsInBeanTable(method.getReturnType().isClass(), fieldName .substring(dotIndex + 1)); } }
/** * Searches class and all its superclasses for a field. * * @param classType * @param fieldName * @return field or method containing representing the field * @throws NotFoundException */ public static Object getDeclaredDirectField(JClassType classType, String fieldName) throws NotFoundException { JField field = classType.getField(fieldName); JClassType superClass = classType.getSuperclass(); JMethod getter = null; if (field == null) { try { getter = getGetter(classType, fieldName); } catch (Exception e) {} } if (field == null && getter == null && superClass != null) { return getDeclaredDirectField(superClass, fieldName); } if (field != null) { return field; } else if (getter != null) { return getter; } throw new NotFoundException( "Unable to identify a property descriptor (field or method) for classType = " + classType + ", field = " + fieldName); }
String fieldName = RebindUtils.toFieldName(beanMethod.getName()); JMethod getter = RebindUtils.getGetter(classType, fieldName); if (getter == null) {
@Override public String doGenerate(TreeLogger logger, GeneratorContext context, String typeClass) throws UnableToCompleteException { this.logger = logger; this.context = context; typeOracle = context.getTypeOracle(); type = typeOracle.findType(typeClass); JClassType beanWrapperType = typeOracle.findType(BEAN_WRAPPER_FQN); JClassType[] directImplementors = beanWrapperType.getSubtypes(); List<JClassType> beanList = new ArrayList<JClassType>(); for (JClassType wrapper : directImplementors) { try { beanList.add(RebindUtils.getGenericsFromInterfaceType(wrapper, beanWrapperType, 0)); } catch (NotFoundException e) { logger.log(Type.WARN, "Skipping wrapper = " + wrapper + " because cannot get generics argument"); } } String packageName = type.getPackage().getName(); String genTypeName = type.getSimpleSourceName() + "Generated"; String fqn = packageName + "." + genTypeName; SourceWriter sourceWriter = getSourceWriter(packageName, genTypeName, type); if (sourceWriter == null) { return fqn; } BeanPropertyDescriptorCreator creator = new BeanPropertyDescriptorCreator(); creator.write(logger, sourceWriter, beanList); sourceWriter.commit(logger); return fqn; }
return getGenericsFromSuperclassType(superclassType/*
int dotIndex = property.indexOf("."); if (dotIndex == -1) { return getDeclaredDirectField(classType, property); } else { Object propertyRepresentation = getDeclaredDirectField(classType, property.substring(0, dotIndex)); JClassType propertyType; if (propertyRepresentation instanceof JField) { + ", property = " + property); return getDeclaredField(propertyType, property.substring(dotIndex + 1));
/** * Will it comment it aprox. 2 minutes before getDeclaredFieldClassType * method * * @throws NotFoundException */ public static JType getDeclaredFieldType(JClassType classType, String property) throws NotFoundException { Object propertyRepresentation = RebindUtils.getDeclaredField(classType, property); if (propertyRepresentation == null) { return null; } if (propertyRepresentation instanceof JField) { return ((JField) propertyRepresentation).getType(); } else if (propertyRepresentation instanceof JMethod) { return ((JMethod) propertyRepresentation).getReturnType(); } else { throw new NotFoundException("Unsupported property type = " + propertyRepresentation.getClass().getName() + ", classType = " + classType + ", property = " + property); } }
if (RebindUtils.getComparableMethodDeclaration(allMethod).compareTo(RebindUtils.getComparableMethodDeclaration(method)) == 0) { found = true;
@Override protected boolean initialize() throws UnableToCompleteException { try { bindingBeanClassType = RebindUtils.getGenericsFromInterfaceType(classType, typeOracle .findType(IBeanBindingHolder.class.getName()), 0); } catch (NotFoundException e) { logger.log(Type.ERROR, "Unable to extract generic type class from interface"); throw new UnableToCompleteException(); } // initialize binding context for all related creators BindingCreatorFactory.setBindingContext(bindingBeanClassType, packageName, namingStrategy); BindingFieldsBase bindingFieldsBaseAnnotation = classType.getAnnotation(BindingFieldsBase.class); if (bindingFieldsBaseAnnotation == null) { return false; } validationEnabled = isValidationEnabled(bindingFieldsBaseAnnotation); setDefaultLoaderCreator(); try { BindingCreatorFactory.fillSupportedTypes(context.getTypeOracle()); } catch (GeneratorException e) { logger.log(Type.ERROR, e.getMessage()); throw new UnableToCompleteException(); } return true; }
widgetClassType = RebindUtils.getGenericsFromSuperclassType(classType, 0);
String setterName = "set" + getterSetterDeterminator(fieldName); fd.getterMethod = getGetter(beanType, fieldName); } catch (NotFoundException e) {