protected String processMethodBody(String body) { Set<? extends Element> configurations = getClassPathTypes().getElementsAnnotatedWith(TransferObjectMapping.class, roundEnv);//processingEnv.getEnvironmentContext().getRoundEnv().getElementsAnnotatedWith(TransferObjectMapping.class); for (Element configuration: configurations) { if (configuration.getAnnotation(Generated.class) == null && (configuration.getKind().isClass() || configuration.getKind().isInterface())) { ConfigurationContext configurationContext = new ConfigurationContext(processingEnv.getEnvironmentContext().getConfigurationEnv()); ConfigurationTypeElement configurationTypeElement = new ConfigurationTypeElement(configuration, processingEnv.getEnvironmentContext(), configurationContext); configurationContext.addConfiguration(configurationTypeElement); String domainElementName = configurationTypeElement.getInstantiableDomainSpecified() == null ? null : configurationTypeElement.getInstantiableDomainSpecified().getSimpleName().toString(); if (domainElementName != null) { body = replaceDomainType(domainElementName, configurationTypeElement.getDto(), body); } domainElementName = configurationTypeElement.getDomain().getSimpleName(); body = replaceDomainType(domainElementName, configurationTypeElement.getDto(), body); } } return body; }
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; } }
if (superClassConfigutation.getDelegateConfigurationTypeElement() != null) { superClassConfigutation = superClassConfigutation.getDelegateConfigurationTypeElement(); MappingType superMappingType = getConfigurationMappingType(superClassConfigutation.asConfigurationElement());
@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(); }
ConfigurationTypeElement configurationTypeElement = new ConfigurationTypeElement(element, envContext, configurationContext); if (configurationTypeElement.isValid()) { configurationContext.addConfiguration(configurationTypeElement); result.add(configurationTypeElement);
DtoDeclaredType dtoType = configurationElement.getDto(); DomainDeclaredType domainType = configurationElement.getDomain(); domainIdMethod = configurationElement.getInstantiableDomain().getIdMethod(entityResolver); if (domainIdMethod == null && entityResolver.shouldHaveIdMethod(configurationElement.getInstantiableDomain())) { processingEnv.getMessager().printMessage(Kind.ERROR, "[ERROR] Unable to find id method for " + configurationElement.toString(), configurationElement.asConfigurationElement()); return; printDomainInstancer(pw, configurationElement.getInstantiableDomain()); pw.println("}"); pw.println(); pw.println(); MutableExecutableElement dtoIdMethod = configurationElement.getDto().getIdMethod(entityResolver); if (dtoIdMethod == null && entityResolver.shouldHaveIdMethod(configurationElement.getInstantiableDomain())) { processingEnv.getMessager().printMessage(Kind.ERROR, "[ERROR] Unable to find id method for DTO class " + dtoType.getCanonicalName(), configurationElement.asConfigurationElement()); return; converterProviderPrinter.printObtainConverterFromCache(pw, ConverterTargetType.DTO, dtoIdType.getDomainDefinitionConfiguration().getInstantiableDomain(), field, domainIdMethod, true); pw.print(".fromDto("); useIdConverter = true; DtoDeclaredType dtoSuperClass = configurationElement.getDto().getSuperClass(); dtoSuperClass = dtoSuperClass.getDomainDefinitionConfiguration().getDto();
DomainDeclaredType superClass = context.getConfigurationTypeElement().getInstantiableDomain().getSuperClass(); if (superClass == null || ConverterProcessingHelper.isConverterGenerated(superClass.getDomainDefinitionConfiguration().asConfigurationElement(), processingEnv)) { return; String previousPath = TransferObjectElementPrinter.RESULT_NAME; DomainDeclaredType domainTypeElement = context.getConfigurationTypeElement().getDomain(); DomainDeclaredType instantiableDomainTypeElement = context.getConfigurationTypeElement().getInstantiableDomain(); if (nested && context.getConfigurationTypeElement().getDomain() != null) { processingEnv.getMessager().printMessage(Kind.ERROR, "[ERROR] Unable to find getter method for the field " + currentPath + " in the " + domainTypeElement.toString(), context.getConfigurationTypeElement().asConfigurationElement()); return; domainReference = domainReference.getConfigurations().get(0).getDomain(); "[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());
/** * 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;"); } }
@Override protected void printAnnotations(ProcessorContext context) { FormattedPrintWriter pw = context.getPrintWriter(); pw.println("@SuppressWarnings(\"serial\")"); ConfigurationTypeElement configurationTypeElement = getConfigurationElement(context); pw.print("@", TransferObjectMapping.class, "("); pw.println("dtoClass = " + configurationTypeElement.getDto().getSimpleName() + ".class,"); pw.println(" domainClassName = \"" + configurationTypeElement.getInstantiableDomainSpecified().getQualifiedName().toString() + "\", "); pw.println(" configurationClassName = \"" + context.getTypeElement().toString() + "\", "); pw.print(" generateConverter = false, generateDto = false"); if (configurationTypeElement.getConverter() != null) { pw.println(", "); pw.print(" converterClassName = \""); pw.print(configurationTypeElement.getConverter().getCanonicalName()); pw.print("\""); } pw.println(")"); super.printAnnotations(context); }
if (!processedConfigurations.contains(availableConfiguration.getCanonicalName())) { List<ConfigurationTypeElement> configurationsForDomain = configurationProvider.getConfigurationsForDomain(availableConfiguration.getInstantiableDomain()); if (!processedConfigurations.contains(configurationForDomain.getCanonicalName())) { processedConfigurations.add(configurationForDomain.getCanonicalName()); if (configurationForDomain.getConverter() != null) { ConverterProviderPrinterContext printerContext = new ConverterProviderPrinterContext(configurationForDomain.getDto(), configurationForDomain); nestedElementPrinter.print(printerContext);
List<ExecutableElement> overridenMethods = ElementFilter.methodsIn(configurationTypeElement.asConfigurationElement().getEnclosedElements()); DomainDeclaredType domainTypeElement = configurationTypeElement.getInstantiableDomain(); DomainDeclaredType processingElement = domainTypeElement; 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())) { TransferObjectContext context = transferObjectContextProvider.get(configurationTypeElement, Modifier.PROTECTED, idMethod, idMethod, false); if (context != null) {
MutableDeclaredType domainType = configurationTypeElement.getDomain().stripTypeParametersTypes().clone().stripTypeParameters(); MutableDeclaredType dtoType = configurationTypeElement.getDto().stripTypeParametersTypes().clone().stripTypeParameters(); if (entityResolver.shouldHaveIdMethod(configurationTypeElement.getInstantiableDomain())) { DomainType domainId = configurationTypeElement.getDomain().getId(entityResolver); DomainType instantiableDomainId = configurationTypeElement.getInstantiableDomain().getId(entityResolver); ExecutableElement domainIdMethod = configurationTypeElement.getInstantiableDomain().getIdMethod(entityResolver); processingEnv.getMessager().printMessage(Kind.ERROR, configurationTypeElement.getInstantiableDomain().getCanonicalName() + " does not have an ID method implemented. Please implement ID method so equals method should be implemented."); return; ExecutableElement getterMethod = configurationTypeElement.getDomain().getGetterMethod(MethodHelper.toField(domainIdMethod)); ProcessorUtils.erasure(processingEnv.getElementUtils().getTypeElement(configurationTypeElement.getDomain().getCanonicalName()), (TypeVariable)returnIdType); processingEnv.getMessager().printMessage(Kind.ERROR, configurationTypeElement.getDomain().getCanonicalName() + " has ID that does not implement serializable! ID method should implement serializable interface."); String methodName = getDomainType(configurationTypeElement.getInstantiableDomain(), isCastRequired) + methodNameSuffix; converterProviderPrinter.printDomainGetConverterMethodName(domainId, field, configurationTypeElement.getInstantiableDomain().getIdMethod(entityResolver), pw, false); pw.print(".toDto("); } else { printDomainType(configurationTypeElement.getInstantiableDomain(), isCastRequired, pw); pw.print(methodNameSuffix);
@Override protected List<ConfigurationTypeElement> getConfigurationElementsForType(TargetType targetType, MutableTypeMirror type, ConfigurationContext context) { List<ConfigurationTypeElement> configurationElementsForType = super.getConfigurationElementsForType(targetType, type, context); List<ConfigurationTypeElement> result = new ArrayList<ConfigurationTypeElement>(); for (ConfigurationTypeElement configurationElement: configurationElementsForType) { if (configurationElement.getInstantiableDomainSpecified() != null && configurationElement.getInstantiableDomainSpecified().getQualifiedName().toString().equals(type.toString(ClassSerializer.QUALIFIED, false))) { //if this is configuration exactly for this type, use it result.add(configurationElement); } } if (result.size() > 0) { return result; } return configurationElementsForType; } }
protected ConfigurationTypeElement createTypeElement(TypeElement typeElement) { ConfigurationContext configurationContext = new ConfigurationContext(environmentContext.getConfigurationEnv()); ConfigurationTypeElement configurationTypeElement = new ConfigurationTypeElement(typeElement, getEnvironmentContext(), configurationContext); configurationContext.addConfiguration(configurationTypeElement); return configurationTypeElement; }
TypeElement typeElement = processingEnv.getElementUtils().getTypeElement(configurationTypeElement.getInstantiableDomain().getCanonicalName()); configurationTypeElement.getInstantiableDomain().getCanonicalName() + ". Please add source class on the classpath also."); } else { MethodOwner domainMethodOwner = configurationTypeElement.getInstantiableDomain().getMethodOwnerByName(overridenMethod.getSimpleName().toString()); configurationTypeElement.getInstantiableDomain().getCanonicalName() + ". Please check your configuration " + configurationTypeElement.toString(ClassSerializer.SIMPLE) + "."); return; configurationTypeElement.getInstantiableDomain().getCanonicalName() + ". Please add source class on the classpath also."); } else { configurationTypeElement.getInstantiableDomain().getCanonicalName() + ". Please check your configuration " + configurationTypeElement.toString(ClassSerializer.SIMPLE) + "."); return;
protected ExecutableElement getSetterMethod(TransferObjectContext context, PathResolver domainPathResolver) { TypeElement typeElement = processingEnv.getElementUtils().getTypeElement(context.getConfigurationTypeElement().getDomain().getCanonicalName()); return getSetterMethod(typeElement, domainPathResolver); //return ProcessorUtils.getMethod(MethodHelper.toSetter(domainPathResolver.getPath()), typeElement)); }
DtoDeclaredType rawDto = returnDtoType.getConverter().getConfiguration().getRawDto(); nestedPrinter.print(new ServiceConverterProviderPrinterContext(rawDto, localMethod, returnDtoType.getConverter().getConfiguration())); DtoType parameterDtoType = processingEnv.getTransferObjectUtils().getDtoType(dtoType); if (parameterDtoType.getConverter() != null) { DomainDeclaredType rawDomain = parameterDtoType.getConverter().getConfiguration().getRawDomain(); nestedPrinter.print(new ServiceConverterProviderPrinterContext(rawDomain, localMethod));
protected MutableDeclaredType[] getTargetClassNames(ConfigurationTypeElement configurationTypeElement) { return new MutableDeclaredType[] { configurationTypeElement.getDto() }; }
protected boolean checkPreconditions(ProcessorContext context, boolean alreadyExists) { return getConfigurationElement(context).getDelegateConfigurationTypeElement() == null; }
protected boolean isId(TransferObjectContext context) { return (processingEnv.getTypeUtils().isAssignable(processingEnv.getElementUtils().getTypeElement(context.getConfigurationTypeElement().getInstantiableDomain().getCanonicalName()).asType(), context.getDomainMethod().getEnclosingElement().asType()) && isIdField(context.getConfigurationTypeElement().getInstantiableDomain(), context.getDomainMethod().getSimpleName().toString())); }