public boolean hasCustomerConstructorDefined(ConfigurationTypeElement configurationTypeElement) { //TODO handle superclass configuration also List<ExecutableElement> methods = ElementFilter.methodsIn(configurationTypeElement.asConfigurationElement().getEnclosedElements()); for (ExecutableElement method: methods) { if (new ConstructorParameterAccessor(method, processingEnv).isValid()) { return true; } } return false; } }
@Override protected void printContexts(ConfigurationTypeElement configurationTypeElement, List<TransferObjectContext> contexts, List<String> generated, TransferObjectElementPrinter printer) { if (configurationTypeElement.asConfigurationElement() != null && configurationTypeElement.asConfigurationElement().asType().getKind().equals(TypeKind.DECLARED)) { TypeElement configurationType = (TypeElement) configurationTypeElement.asConfigurationElement(); List<? extends TypeMirror> interfaces = configurationType.getInterfaces(); for (TypeMirror interfaceType: interfaces) { if (interfaceType.getKind().equals(TypeKind.DECLARED)) { for (ExecutableElement method: ElementFilter.methodsIn(((DeclaredType)interfaceType).asElement().getEnclosedElements())) { if (MethodHelper.isGetterMethod(method)) { String fieldName = TransferObjectHelper.getFieldPath(method); if (!contains(generated, fieldName)) { TransferObjectContext context = transferObjectContextProvider.get(configurationTypeElement, Modifier.PUBLIC, method, null, false); if (context == null) { continue; } contexts.add(context); } } } } } } super.printContexts(configurationTypeElement, contexts, generated, printer); }
@Override protected List<ConfigurationTypeElement> getConfigurationElementsForType(TargetType targetType, MutableTypeMirror type, ConfigurationContext context) { List<ConfigurationTypeElement> result = new ArrayList<ConfigurationTypeElement>(); if (!isSupportedType(type)) { return result; }; for (ConfigurationTypeElement configurationTypeElement : collectConfigurations()) { if (targetType.appliesForType(type, configurationTypeElement)) { result.add(targetType.getConfiguration(type, configurationTypeElement.asConfigurationElement(), this, context)); } } result.addAll(super.getConfigurationElementsForType(targetType, type, context)); return result; } }
@Override public void initialize(ConfigurationTypeElement configurationTypeElement, MutableDeclaredType outputName) { active = new GenerateCloneAccessor(configurationTypeElement.asConfigurationElement(), processingEnv).generate(); if (!active) { return; } DtoDeclaredType dto = configurationTypeElement.getDto(); pw.println("public ", dto, " clone() {"); pw.println(dto, " " + RESULT_NAME + " = new ", dto, "();"); pw.println(); }
MappingType superMappingType = getConfigurationMappingType(superClassConfigutation.asConfigurationElement());
List<ExecutableElement> overridenMethods = ElementFilter.methodsIn(configurationTypeElement.asConfigurationElement().getEnclosedElements()); processingEnv.getMessager().printMessage(Kind.ERROR, "[ERROR] " + fieldName + " is not defined in " + configurationTypeElement.getInstantiableDomain() + ".", configurationTypeElement.asConfigurationElement()); return; processingEnv.getMessager().printMessage(Kind.ERROR, "[ERROR] Id method can't be ignored. There should be an id method available for merging purposes.", configurationTypeElement.asConfigurationElement()); return; " in the domain class " + domainTypeElement.getCanonicalName(), configurationTypeElement.asConfigurationElement()); continue; Id.class.getCanonicalName() + " annotation.", configurationTypeElement.asConfigurationElement()); } else { if (nestedIdMethod != null) { processingEnv.getMessager().printMessage(Kind.ERROR, "[ERROR] Invalid mapping specified in the field " + fieldName + ". Current path (" + currentPath + ") address getter type that is not class/interfaces." + "You probably mistyped this field in the configuration.", configurationTypeElement.asConfigurationElement()); Id.class.getSimpleName() + " annotation or just specify id as a method name.", configurationTypeElement.asConfigurationElement()); return; } else if (idMethod != null && !contains(generated, MethodHelper.toField(idMethod)) && !isInSuperclassConfiguration(idMethod, configurationTypeElement.getInstantiableDomain())) {
methods = ElementFilter.methodsIn(processingElement.asConfigurationElement().getEnclosedElements()); } else { methods = ElementFilter.methodsIn(configurationTypeElement.asConfigurationElement().getEnclosedElements()); MappingType superMappingType = getConfigurationMappingType(superClassConfigutation.asConfigurationElement());
context.getDtoFieldType() + ". Using first one!", context.getConfigurationTypeElement().asConfigurationElement()); if (lowerBounds.size() > 1) { processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, "[WARNING] More type variables are defined in iterable implementation " + context.getDtoFieldType() + ". Using first one!", context.getConfigurationTypeElement().asConfigurationElement()); if (lowerBounds.size() > 1) { processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, "[WARNING] More type variables are defined in iterable implementation " + context.getDtoFieldType() + ". Using first one!", context.getConfigurationTypeElement().asConfigurationElement()); dtoHasClone = new GenerateCloneAccessor(domain.getDomainDefinitionConfiguration().asConfigurationElement(), processingEnv).generate(); dtoHasClone = new GenerateCloneAccessor(context.getDomainMethodReturnType().getDomainDefinitionConfiguration().asConfigurationElement(), processingEnv).generate(); context.getConfigurationTypeElement().asConfigurationElement()); return; case WILDCARD: case TYPEVAR: processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, "[WARNING] Unsupported type " + context.getDtoFieldName() + " (" + context.getDtoFieldType().getKind() + ") in the " + context.getConfigurationTypeElement().asConfigurationElement(), context.getConfigurationTypeElement().asConfigurationElement()); return;
/** * Prints the definition of the hashCode method with the initial prechecks */ @Override public void initialize(ConfigurationTypeElement configurationTypeElement, MutableDeclaredType outputType) { this.outputType = outputType; GenerateHashcodeAccessor generateHashcodeAccessor = new GenerateHashcodeAccessor(configurationTypeElement.asConfigurationElement(), processingEnv); active = generateHashcodeAccessor.generate(); equalsType = generateHashcodeAccessor.getType(); hasKey = configurationTypeElement.hasKey(); if (!active) { return; } if (equalsType.equals(TraversalType.CYCLIC_SAFE)) { pw.println("private boolean processingHashCode = false;"); } pw.println(""); pw.println("@Override"); pw.println("public int hashCode() {"); pw.println("final int prime = 31;"); //TODO we should call also super.hashcode - but only when there is any superclass with implemented hashcode method DomainDeclaredType superClass = configurationTypeElement.getInstantiableDomain().getSuperClass(); if (superClass != null && superClass.getDomainDefinitionConfiguration() != null && new GenerateEqualsAccessor(superClass.getDomainDefinitionConfiguration().asConfigurationElement(), processingEnv).generate()) { pw.println("int result = super.hashCode();"); } else { pw.println("int result = 1;"); } }
case TYPEVAR: processingEnv.getMessager().printMessage(Kind.WARNING, "[WARNING] Unsupported type " + context.getDtoFieldName() + " (" + context.getDtoFieldType().getKind() + ") in the " + context.getConfigurationTypeElement().asConfigurationElement(), context.getConfigurationTypeElement().asConfigurationElement()); return;
if (superClass == null || ConverterProcessingHelper.isConverterGenerated(superClass.getDomainDefinitionConfiguration().asConfigurationElement(), processingEnv)) { return; processingEnv.getMessager().printMessage(Kind.ERROR, "[ERROR] Unable to find getter method for the field " + currentPath + " in the " + domainTypeElement.toString(), context.getConfigurationTypeElement().asConfigurationElement()); return; "[ERROR] Invalid mapping specified in the field " + currentPath + ". Current path (" + fullPath + ") address getter type that is not class/interfaces." + "You probably mistyped this field in the configuration.", context.getConfigurationTypeElement().asConfigurationElement()); processingEnv.getMessager().printMessage(Kind.ERROR, "[ERROR] Setter is not available for the field " + currentPath + " in the class " + instantiableDomainTypeElement.toString(), context.getConfigurationTypeElement().asConfigurationElement());
GenerateEqualsAccessor generateEqualsAccessor = new GenerateEqualsAccessor(configurationTypeElement.asConfigurationElement(), processingEnv); new GenerateEqualsAccessor(superClass.getDomainDefinitionConfiguration().asConfigurationElement(), processingEnv).generate()) { pw.println("if (!super.equals(obj))"); pw.println(" return false;");
protected List<AnnotationMirror> getSupportedAnnotations(TransferObjectContext context) { if (typeCopyAccessor == null) { typeCopyAccessor = new CopyAccessor(context.getConfigurationTypeElement().asConfigurationElement(), processingEnv); } CopyAccessor methodCopyAccessor = new CopyAccessor(context.getDtoMethod(), processingEnv); List<AnnotationMirror> supportedAnnotations = new ArrayList<AnnotationMirror>(); if (context.getDomainMethod() != null) { add(supportedAnnotations, methodCopyAccessor.getSupportedAnnotations(context.getInstantiableDomainMethod())); add(supportedAnnotations, methodCopyAccessor.getSupportedAnnotations(MethodHelper.getField(context.getDomainMethod()))); } add(supportedAnnotations, methodCopyAccessor.getSupportedAnnotations(context.getDtoMethod())); if (context.getDomainMethod() != null) { add(supportedAnnotations, typeCopyAccessor.getSupportedAnnotations(context.getInstantiableDomainMethod())); add(supportedAnnotations, typeCopyAccessor.getSupportedAnnotations(MethodHelper.getField(context.getDomainMethod()))); } add(supportedAnnotations, typeCopyAccessor.getSupportedAnnotations(context.getDtoMethod())); return supportedAnnotations; }
case TYPEVAR: processingEnv.getMessager().printMessage(Kind.WARNING, "[WARNING] Unsupported type " + context.getDtoFieldName() + " (" + context.getDtoFieldType().getKind() + ") in the " + context.getConfigurationTypeElement().asConfigurationElement(), context.getConfigurationTypeElement().asConfigurationElement()); return;
case TYPEVAR: processingEnv.getMessager().printMessage(Kind.WARNING, "[WARNING] Unsupported type " + context.getDtoFieldName() + " (" + context.getDtoFieldType().getKind() + ") in the " + context.getConfigurationTypeElement().asConfigurationElement(), context.getConfigurationTypeElement().asConfigurationElement()); return; case CLASS:
processingEnv.getMessager().printMessage(Kind.ERROR, "[ERROR] Setter is not available for the field " + domainPathResolver.getCurrent() + " in the class " + domainTypeElement.toString(), configurationTypeElement.asConfigurationElement()); return;
processingEnv.getMessager().printMessage(Kind.ERROR, "[ERROR] Unable to find id method for " + configurationElement.toString(), configurationElement.asConfigurationElement()); return;
processingEnv.getMessager().printMessage(Kind.ERROR, "[ERROR] Unable to find id method for " + configurationElement.toString(), configurationElement.asConfigurationElement()); return; processingEnv.getMessager().printMessage(Kind.ERROR, "[ERROR] Unable to find id method for DTO class " + dtoType.getCanonicalName(), configurationElement.asConfigurationElement()); return;
if (superClass == null || ConverterProcessingHelper.isConverterGenerated(superClass.getDomainDefinitionConfiguration().asConfigurationElement(), processingEnv)) { return;