- /**
- * Adds to the <code>methods</code> set all the methods of the <code>implementedIfcs</code>
- * and recursively their implemented interfaces.
- *
- * @param methods set of method signatures
- * @param implementedIfcs list of implemented interfaces
- */
- def private void collectImplementedMethods(Set<MethodSignature> methods, List<Type> implementedIfcs) {
- if (implementedIfcs === null || implementedIfcs.empty) {
- return
- }
- for (implementedIfc : implementedIfcs) {
- if ((implementedIfc instanceof GeneratedType && !(implementedIfc instanceof GeneratedTransferObject))) {
- val ifc = implementedIfc as GeneratedType
- methods.addAll(ifc.methodDefinitions)
- collectImplementedMethods(methods, ifc.implements)
- } else if (implementedIfc.fullyQualifiedName == Augmentable.name) {
- for (m : Augmentable.methods) {
- if (m.name == GET_AUGMENTATION_METHOD_NAME) {
- val fullyQualifiedName = m.returnType.name
- val pkg = fullyQualifiedName.package
- val name = fullyQualifiedName.name
- val tmpGenTO = new GeneratedTOBuilderImpl(pkg, name)
- val refType = new ReferencedTypeImpl(pkg, name)
- val generic = new ReferencedTypeImpl(type.packageName, type.name)
- val parametrizedReturnType = Types.parameterizedTypeFor(refType, generic)
- tmpGenTO.addMethod(m.name).setReturnType(parametrizedReturnType)
- augmentField = tmpGenTO.toInstance.methodDefinitions.first.propertyFromGetter
- }
- }
- }
- }
- }
-
- /**
- * Returns the first element of the list <code>elements</code>.
- *
- * @param list of elements
- */
- def private <E> first(List<E> elements) {
- elements.get(0)
- }
-
- /**
- * Returns the name of the package from <code>fullyQualifiedName</code>.
- *
- * @param fullyQualifiedName string with fully qualified type name (package + type)
- * @return string with the package name
- */
- def private String getPackage(String fullyQualifiedName) {
- val lastDotIndex = fullyQualifiedName.lastIndexOf(Constants.DOT)
- return if (lastDotIndex == -1) "" else fullyQualifiedName.substring(0, lastDotIndex)
- }
-
- /**
- * Returns the name of tye type from <code>fullyQualifiedName</code>
- *
- * @param fullyQualifiedName string with fully qualified type name (package + type)
- * @return string with the name of the type
- */
- def private String getName(String fullyQualifiedName) {
- val lastDotIndex = fullyQualifiedName.lastIndexOf(Constants.DOT)
- return if (lastDotIndex == -1) fullyQualifiedName else fullyQualifiedName.substring(lastDotIndex + 1)
- }
-
- /**
- * Creates set of generated property instances from getter <code>methods</code>.
- *
- * @param set of method signature instances which should be transformed to list of properties
- * @return set of generated property instances which represents the getter <code>methods</code>
- */
- def private propertiesFromMethods(Collection<MethodSignature> methods) {
- if (methods === null || methods.isEmpty()) {
- return Collections.emptySet
- }
- val Set<GeneratedProperty> result = new LinkedHashSet
- for (m : methods) {
- val createdField = m.propertyFromGetter
- if (createdField !== null) {
- result.add(createdField)
- }
- }
- return result
- }
-
- /**
- * Creates generated property instance from the getter <code>method</code> name and return type.
- *
- * @param method method signature from which is the method name and return type obtained
- * @return generated property instance for the getter <code>method</code>
- * @throws IllegalArgumentException<ul>
- * <li>if the <code>method</code> equals <code>null</code></li>
- * <li>if the name of the <code>method</code> equals <code>null</code></li>
- * <li>if the name of the <code>method</code> is empty</li>
- * <li>if the return type of the <code>method</code> equals <code>null</code></li>
- * </ul>
- */
- def private GeneratedProperty propertyFromGetter(MethodSignature method) {
- if (method === null || method.name === null || method.name.empty || method.returnType === null) {
- throw new IllegalArgumentException("Method, method name, method return type reference cannot be NULL or empty!")
- }
- var prefix = "get";
- if (Types.BOOLEAN.equals(method.returnType)) {
- prefix = "is";
- }
- if (method.name.startsWith(prefix)) {
- val fieldName = method.getName().substring(prefix.length()).toFirstLower
- val tmpGenTO = new GeneratedTOBuilderImpl("foo", "foo")
- tmpGenTO.addProperty(fieldName).setReturnType(method.returnType)
- return tmpGenTO.toInstance.properties.first
- }