@Override public void print(ConverterProviderPrinterContext context) { if (types.size() == 0) { initializeDomainConverterMethod(); } if (!types.contains(context.getRawDomain().getCanonicalName())) { types.add(context.getRawDomain().getCanonicalName()); } } }
List<MutableTypeVariable> typeParams = new LinkedList<MutableTypeVariable>(); for (MutableTypeVariable typeVariable: domainType.getTypeVariables()) { DomainDeclaredType superClass = domainType.getSuperClass(); List<? extends MutableTypeMirror> interfaces = domainDeclared.getInterfaces(); domainType.setTypeVariables(typeParams.toArray(new MutableTypeVariable[typeParams.size()])); domainType.setSuperClass(superClass); domainDeclared.setInterfaces(interfaces);
methods = ElementFilter.methodsIn(processingElement.asConfigurationElement().getEnclosedElements()); } else { methods = ElementFilter.methodsIn(configurationTypeElement.asConfigurationElement().getEnclosedElements()); PojoElement pojoElement = new PojoElement(domainTypeElement.asConfigurationElement(), processingEnv); method = processingElement.getGetterMethod(fieldName); result.add(method); } else if (!isProcessed && isGetter && !hasSetter && isPublic) { processingEnv.getMessager().printMessage(Kind.WARNING, "Method " + method.getSimpleName() + " does not have setter, type = " + processingElement.asConfigurationElement()); if (processingElement.getSuperClass() == null && processingElement.asConfigurationElement() != null) { TypeMirror superclass = processingElement.asConfigurationElement().getSuperclass(); if (superclass.getKind().equals(TypeKind.DECLARED)) { result.addAll(getMethodsForProcessings(configurationTypeElement, mappingType, (DomainDeclaredType) processingEnv.getTransferObjectUtils().getDomainType(superclass), domainTypeElement, ignored)); } else if (processingElement.getSuperClass() != null) { processingElement.getSuperClass(), domainTypeElement, ignored); result.addAll(superClassMethods); getConfigurationsForDomain(processingElement.getSuperClass()); if (configurationsForDomain != null && configurationsForDomain.size() > 0) { processingElement.getSuperClass(), processingElement.getSuperClass(), ignored);
private DomainDeclaredType replaceTypeParamsByWildcard(DomainDeclaredType domainDeclared) { if (domainDeclared.getTypeVariables().size() > 0) { MutableTypeVariable[] typeVariables = new MutableTypeVariable[domainDeclared.getTypeVariables().size()]; for (int i = 0; i < domainDeclared.getTypeVariables().size(); i++) { typeVariables[i] = envContext.getProcessingEnv().getTypeUtils().getTypeVariable(MutableWildcardType.WILDCARD_NAME); } domainDeclared.setTypeVariables(typeVariables); } return domainDeclared; } }
protected void printDomainInstancer(FormattedPrintWriter pw, DomainDeclaredType domainTypeElement) { if (!entityResolver.shouldHaveIdMethod(domainTypeElement)) { pw.println(" return new ", domainTypeElement, "();"); } else { pw.println(domainTypeElement, " " + RESULT_NAME, " = new ", domainTypeElement, "();"); String setterMethod = MethodHelper.toSetter(domainTypeElement.getIdMethod(entityResolver)); if (ProcessorUtils.hasMethod(setterMethod, domainTypeElement.asElement())) { pw.println(RESULT_NAME + "." + MethodHelper.toSetter(domainTypeElement.getIdMethod(entityResolver)) + "((", domainTypeElement.getId(entityResolver), ")" + "id);"); } else { pw.println("if (id != null) {"); pw.println("throw new ", RuntimeException.class, "(\"Unable to define ID for imutable entity. Please define " + setterMethod + " method for ", domainTypeElement, "!\");"); pw.println("}"); } pw.println("return " + RESULT_NAME + ";"); } } }
DomainDeclaredType superClass = context.getConfigurationTypeElement().getInstantiableDomain().getSuperClass(); if (superClass == null || ConverterProcessingHelper.isConverterGenerated(superClass.getDomainDefinitionConfiguration().asConfigurationElement(), processingEnv)) { return; DomainType instantiableDomainReference = referenceDomainType.getDomainReference(entityResolver, currentPath); if (referenceDomainType.getKind().isDeclared()) { MutableDeclaredType fieldType = processingEnv.getTypeUtils().getDeclaredType(processingEnv.getTypeUtils().toMutableType(Class.class), new MutableDeclaredType[] { referenceDomainType.getDto() }); Field field = new Field("" + referenceDomainType.getDto().getSimpleName() + ".class", fieldType); if (domainTypeElement != null && domainTypeElement.getSetterMethod(context.getDomainFieldPath()) != null) { printCopy(pathResolver, context, pw); } else if (!entityResolver.isImmutable(instantiableDomainTypeElement.asElement())) { ExecutableElement domainGetterMethod = instantiableDomainTypeElement.getGetterMethod(currentPath); VariableElement field = MethodHelper.getField(instantiableDomainTypeElement.asConfigurationElement(), currentPath);
@Override public void initialize(ConfigurationTypeElement configurationTypeElement, MutableDeclaredType outputName) { MutableDeclaredType domainType = configurationTypeElement.getDomain().stripTypeParametersTypes().clone().stripTypeParameters(); MutableDeclaredType dtoType = configurationTypeElement.getDto().stripTypeParametersTypes().clone().stripTypeParameters(); 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.getElementUtils().getTypeElement(Serializable.class.getCanonicalName()).asType())) { processingEnv.getMessager().printMessage(Kind.ERROR, configurationTypeElement.getDomain().getCanonicalName() + " has ID that does not implement serializable! ID method should implement serializable interface."); converterProviderPrinter.printDomainGetConverterMethodName(domainId, field, configurationTypeElement.getInstantiableDomain().getIdMethod(entityResolver), pw, false); pw.print(".toDto("); } else {
DomainDeclaredType superClass = context.getConfigurationTypeElement().getInstantiableDomain().getSuperClass(); if (superClass == null || ConverterProcessingHelper.isConverterGenerated(superClass.getDomainDefinitionConfiguration().asConfigurationElement(), processingEnv)) { return; pw.print(" && "); TypeElement typeElement = processingEnv.getElementUtils().getTypeElement(context.getConfigurationTypeElement().getDomain().getCanonicalName()); methodPath += "." + MethodHelper.toGetterMethod(typeElement, path); TypeElement typeElement = processingEnv.getElementUtils().getTypeElement(context.getConfigurationTypeElement().getInstantiableDomain().getCanonicalName()); if (context.getConfigurationTypeElement().getInstantiableDomain().getGetterMethod(pathResolver.getPath()) != null) { castToInstance = context.getConfigurationTypeElement().getDomain().getGetterMethod(pathResolver.getPath()) == null;
ExecutableElement domainMethod = processingElement.getGetterMethod(fieldName); ExecutableElement domainMethod = domainTypeElement.getGetterMethod(fieldName); " in the domain class " + domainTypeElement.getCanonicalName(), configurationTypeElement.asConfigurationElement()); continue; DomainType domainReference = currentElement.getDomainReference(getEntityResolver(), currentPath); ExecutableElement nestedIdMethod = currentElement.getIdMethod(getEntityResolver()); processingEnv.getMessager().printMessage(Kind.ERROR, "[ERROR] Unable to find id method in the class " + currentElement.getCanonicalName() + ". If the class/interface does not have strictly specified ID, please specify the id in the configuration using " + Id.class.getCanonicalName() + " annotation.", configurationTypeElement.asConfigurationElement()); ExecutableElement idMethod = domainTypeElement.getIdMethod(getEntityResolver());
if (domainTypeElement.asElement() != null && ProcessorUtils.hasMethod(MethodHelper.toMethod(MethodHelper.GETTER_IS_PREFIX, domainPathResolver.getCurrent()), domainTypeElement.asElement())) { isMethod = true; domainGetterMethod = domainTypeElement.getGetterMethod(domainPathResolver.getCurrent()); } else { domainGetterMethod = domainTypeElement.getGetterMethod(domainPathResolver.getCurrent()); if (configurationTypeElement.getInstantiableDomain().getSetterMethod(domainPathResolver.getPath()) != null) { boolean castToInstance = configurationTypeElement.getDomain().getSetterMethod(domainPathResolver.getPath()) == null; } else if (!entityResolver.isImmutable(domainTypeElement.asElement())) { VariableElement field = MethodHelper.getField(domainTypeElement.asConfigurationElement(), domainPathResolver.getCurrent());
/** * 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;"); } }
protected void printCopyNested(PathResolver domainPathResolver, String fullPath, DomainDeclaredType referenceDomainType, ExecutableElement method, FormattedPrintWriter pw, Field field, String dtoName) { DomainDeclaredType instantiableDomain = (DomainDeclaredType)referenceDomainType.getConverter().getInstantiableDomain(); pw.print(referenceDomainType, " " + domainPathResolver.getCurrent() + " = "); if (instantiableDomain.getId(entityResolver) != null) { if (referenceDomainType.getConverter() == null) { processingEnv.getMessager().printMessage(Kind.ERROR, "[ERROR] No converter/configuration for " + referenceDomainType + " was found. Please, define configuration for " + referenceDomainType); } converterProviderPrinter.printObtainConverterFromCache(pw, ConverterTargetType.DTO, referenceDomainType, field, method, true); pw.println(".createDomainInstance(" + dtoName + "." + MethodHelper.toGetter(fullPath + MethodHelper.toMethod(MethodHelper.toField(instantiableDomain.getIdMethod(entityResolver)))) + ");"); } else { pw.println(TransferObjectElementPrinter.RESULT_NAME + "." + MethodHelper.toGetter(domainPathResolver.getCurrent()) + ";"); pw.println("if (" + domainPathResolver.getCurrent() + " == null) {"); pw.print(domainPathResolver.getCurrent() + " = "); // TODO add NPE check converterProviderPrinter.printObtainConverterFromCache(pw, ConverterTargetType.DTO, referenceDomainType, field, method, true); pw.println(".createDomainInstance(null);"); pw.println("}"); } }
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;
private boolean isInSuperclassConfiguration(ExecutableElement method, DomainDeclaredType processingElement) { if (processingElement.getSuperClass() != null) { getConfigurationsForDomain(processingElement.getSuperClass()); if (configurationsForDomain != null && configurationsForDomain.size() > 0) { processingElement.getSuperClass(), processingElement.getSuperClass(), new ArrayList<String>()); if (isInSuperclassConfiguration(method, processingElement.getSuperClass())) { return true;
nestedPrinter.print(new ServiceConverterProviderPrinterContext(rawDto, localMethod, returnDtoType.getConverter().getConfiguration())); if (rawDomain.getTypeVariables().size() > 0) { for (MutableTypeVariable typeVariable: rawDomain.getTypeVariables()) { printDtoTypeVariables(typeVariable.getLowerBounds(), localMethod, nestedPrinter); printDtoTypeVariables(typeVariable.getUpperBounds(), localMethod, nestedPrinter); nestedPrinter.print(new ServiceConverterProviderPrinterContext(rawDomain, localMethod)); if (rawDomain.getTypeVariables().size() > 0) { for (MutableTypeVariable typeVariable: rawDomain.getTypeVariables()) { printDomainTypeVariables(typeVariable.getLowerBounds(), localMethod, nestedPrinter); printDomainTypeVariables(typeVariable.getUpperBounds(), localMethod, nestedPrinter);
DomainDeclaredType replacementType = delegateConfigurationTypeElement.getDomain(); if ((domainNamedType instanceof MutableDeclaredType) && ((MutableDeclaredType)domainNamedType).hasTypeParameters() && replacementType.hasTypeParameters()) { domainNamedType = replacementType.clone().setTypeVariables(((MutableDeclaredType)domainNamedType).getTypeVariables().toArray(new MutableTypeVariable[] {})); } else { domainNamedType = replacementType;
pw.println(" return false;"); DomainDeclaredType superClass = configurationTypeElement.getInstantiableDomain().getSuperClass(); if (superClass != null && superClass.getDomainDefinitionConfiguration() != null && new GenerateEqualsAccessor(superClass.getDomainDefinitionConfiguration().asConfigurationElement(), processingEnv).generate()) { pw.println("if (!super.equals(obj))"); pw.println(" return false;");
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())); }
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)); }
private TransferObjectContext createTOContext(ExecutableElement method, DomainDeclaredType domainTypeElement, boolean superClassMethod, ConfigurationTypeElement configurationTypeElement, List<String> generated) { String fieldName = TransferObjectHelper.getFieldPath(method); if (contains(generated, fieldName)) { return null; } TypeElement domainElement = environmentContext.getProcessingEnv().getElementUtils().getTypeElement(domainTypeElement.getCanonicalName()); ExecutableElement overrider = ProcessorUtils.getOverrider(domainElement, method, processingEnv); if (overrider != null) { method = overrider; } TransferObjectContext context = transferObjectContextProvider.get(configurationTypeElement, Modifier.PUBLIC, method, method, superClassMethod); if (context == null) { return null; } generated.add(fieldName); return context; }