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())); }
for (VariableElement dtoParameter : remoteMethod.getParameters()) { DtoType parameterDtoType = processingEnv.getTransferObjectUtils().getDtoType(dtoParameter.asType()); DomainType parameterDomainType = parameterDtoType.getDomain(); if (!processingEnv.getTypeUtils().isSameType(parameterDomainType, processingEnv.getTypeUtils().toMutableType(overriderMethod.getParameters().get(index).asType()))) { pairMethod = false; break; DomainType returnDomainType = processingEnv.getTransferObjectUtils().getDomainType(overriderMethod.getReturnType()); DtoType returnDtoType = returnDomainType.getDto(); MutableTypeMirror mutableRemoteReturnType = processingEnv.getTypeUtils().toMutableType(remoteMethod.getReturnType()); if (processingEnv.getTypeUtils().isSameType(returnDtoType, mutableRemoteReturnType)) { return overriderMethod; processingEnv.getMessager().printMessage(Kind.ERROR, "[ERROR] Service method return type does not match the remote interface definition " + remoteMethod.toString() + ". Probably you are using domain entities in remote interface.",
@Override protected void init(Element element, RoundEnvironment roundEnv) { super.init(element, roundEnv); this.processingEnv = new TransferObjectProcessingEnvironment(getProcessingEnv(), roundEnv, getConfigurationCache(), getClass(), getProcessingEnv().getUsedTypes()); this.processingEnv.setConfigurationProviders(getConfigurationProviders()); this.transferObjectContextProvider = getProcessorContextProvider(processingEnv, roundEnv); }
MutableDeclaredType mutableSerializableType = processingEnv.getTypeUtils().toMutableType(Serializable.class); domainId = processingEnv.getTransferObjectUtils().getDomainType(mutableSerializableType); 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; ProcessorUtils.erasure(processingEnv.getElementUtils().getTypeElement(configurationTypeElement.getDomain().getCanonicalName()), (TypeVariable)returnIdType); if (!processingEnv.getTypeUtils().isAssignable(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.");
returnDtoType = processingEnv.getTransferObjectUtils().getDtoType(remoteMethod.getReturnType()); MutableExecutableElement remoteMutableMethod = processingEnv.getElementUtils().toMutableElement(remoteMethod); for (int i = 0; i < localMethod.getParameters().size(); i++) { TypeMirror dtoType = remoteMethod.getParameters().get(i).asType(); DtoType parameterDtoType = processingEnv.getTransferObjectUtils().getDtoType(dtoType); pw.print(returnType = ProcessorUtils.stripTypeParametersVariables(processingEnv.getTypeUtils().toMutableType(localMethod.getReturnType())), " " + RESULT_VARIABLE_NAME + " = "); DtoType parameterDtoType = processingEnv.getTransferObjectUtils().getDtoType(dtoType); final DomainType parameterDomainType = processingEnv.getTransferObjectUtils().getDomainType(ProcessorUtils.stripTypeParametersVariables(parameterDtoType.getDomain())); ProcessorUtils.stripTypeParametersTypes(processingEnv.getTypeUtils().toMutableType(dtoType)), remoteMethod); ProcessorUtils.stripTypeParametersTypes(processingEnv.getTypeUtils().toMutableType(domainType)), localMethod); ProcessorUtils.stripTypeParametersTypes(processingEnv.getTypeUtils().toMutableType(returnType)), remoteMethod); ProcessorUtils.stripTypeParametersTypes(processingEnv.getTypeUtils().toMutableType(localMethod.getReturnType())), localMethod); returnType = ProcessorUtils.stripTypeParametersTypes(processingEnv.getTypeUtils().toMutableType(remoteMethod.getReturnType()));
TypeElement typeElement = processingEnv.getElementUtils().getTypeElement(configurationTypeElement.getInstantiableDomain().getCanonicalName()); processingEnv.getMessager().printMessage(Kind.ERROR, "No source code available for class " + configurationTypeElement.getInstantiableDomain().getCanonicalName() + ". Please add source class on the classpath also."); } else { processingEnv.getMessager().printMessage(Kind.ERROR, "No method '" + overridenMethod.getSimpleName().toString() + "' is available in the class " + configurationTypeElement.getInstantiableDomain().getCanonicalName() + ". Please check your configuration " + configurationTypeElement.toString(ClassSerializer.SIMPLE) + "."); processingEnv.getMessager().printMessage(Kind.ERROR, "No source code available for class " + configurationTypeElement.getInstantiableDomain().getCanonicalName() + ". Please add source class on the classpath also."); } else { processingEnv.getMessager().printMessage(Kind.ERROR, "No method '" + overridenMethod.getSimpleName().toString() + "' is available in the class " + configurationTypeElement.getInstantiableDomain().getCanonicalName() + ". Please check your configuration " + configurationTypeElement.toString(ClassSerializer.SIMPLE) + "."); MutableExecutableType copiedMethod = processingEnv.getElementUtils().toMutableElement(overridenMethod).asType(); copiedMethod.setReturnType(processingEnv.getTransferObjectUtils().getDomainType(domainMethodOwner.getMethod().getReturnType()).getDto()); dto = processingEnv.getTransferObjectUtils().getDomainType(parameter.asType()).getDto(); dto = processingEnv.getTransferObjectUtils().getDomainType(methodParameter.asType()).getDto(); MutableVariableElement parameterElement = processingEnv.getElementUtils().getParameterElement(dto, methodParameter.getSimpleName().toString());
protected final MutableReferenceType getThisReference() { return processingEnv.getTypeUtils().getReference(null, ConverterConstructorParametersResolver.THIS); }
if (envContext.getProcessingEnv().getElementUtils().getPackageOf(element).toString().startsWith("java.")) { return result;
private boolean processBounds(Set<? extends MutableTypeMirror> domainBounds, Set<? extends MutableTypeMirror> dataBounds) { if (domainBounds.size() > 0) { Iterator<? extends MutableTypeMirror> domainIterator = domainBounds.iterator(); Iterator<? extends MutableTypeMirror> dataIterator = dataBounds.iterator(); while (domainIterator.hasNext()) { MutableTypeMirror domain = domainIterator.next(); DomainDeclaredType domainDeclaredType; if (!(domain instanceof DomainDeclaredType)) { domainDeclaredType = (DomainDeclaredType) envContext.getProcessingEnv().getTransferObjectUtils().getDomainType(domain); } else { domainDeclaredType = (DomainDeclaredType) domain; } if (hasCustomProperties(domainDeclaredType, (MutableDeclaredType)dataIterator.next())) { return true; } } } return false; }
public MutableTypeMirror getDelegateCast(TypeMirror domainType) { DomainType domainTypeElement = processingEnv.getTransferObjectUtils().getDomainType(domainType); MutableTypeMirror domainNamedType = processingEnv.getTypeUtils().toMutableType(domainType); return castToDelegate(domainNamedType, domainTypeElement.getDomainDefinitionConfiguration() == null ? null : domainTypeElement.getDomainDefinitionConfiguration().getDelegateConfigurationTypeElement(), true); }
protected void printCastDomainType(TransferObjectContext context, PathResolver domainPathResolver, DomainType inputDomainType, FormattedPrintWriter pw) { MutableTypeMirror parameterType = getParameterType(context, domainPathResolver); MutableTypeMirror domainType = getTypeVariableDelegate(getDelegateCast(inputDomainType, true)); if (!isCastRequired(parameterType)) { pw.print(domainType); } else { MutableDeclaredType declaredParameter = (MutableDeclaredType) parameterType; MutableTypeMirror typeParameter = getTypeParameter(declaredParameter); if (typeParameter == null) { pw.print(domainType); } else { if (typeParameter.isSameType(domainType) || ProcessorUtils.implementsType(processingEnv.getElementUtils().getTypeElement(domainType.toString(ClassSerializer.CANONICAL, false)) .asType(), processingEnv.getElementUtils().getTypeElement(typeParameter.toString(ClassSerializer.CANONICAL, false)).asType())) { pw.print(domainType); } else { processingEnv.getMessager().printMessage(Kind.NOTE, "Params: [1] InputDomainType: " + inputDomainType.toString()); processingEnv.getMessager().printMessage( Kind.ERROR, "Method " + getSetterMethod(context, domainPathResolver).getSimpleName().toString() + " in type " + context.getConfigurationTypeElement().getDomain().getCanonicalName() + " has parameter of type " + typeParameter.toString() + " but " + domainType.toString() + " was expected!"); } } } }
pw.print(" && "); TypeElement typeElement = processingEnv.getElementUtils().getTypeElement(context.getConfigurationTypeElement().getDomain().getCanonicalName()); methodPath += "." + MethodHelper.toGetterMethod(typeElement, path); processingEnv.getUsedTypes().addAll(new TypeExtractor(true).extractDeclaredType(context.getConverter().getConfiguration().getDomain())); Field field = new Field( (context.getDomainMethodReturnType().getKind().equals(MutableTypeKind.TYPEVAR) ? "(" + context.getConverter().getDomain().toString(ClassSerializer.SIMPLE, true) + ")" : "") + TypeElement typeElement = processingEnv.getElementUtils().getTypeElement(context.getConfigurationTypeElement().getInstantiableDomain().getCanonicalName()); pw.print(", " + processingEnv.getTypeUtils().toMutableType(processingEnv.getTypeUtils().erasure(listType)).toString(ClassSerializer.CANONICAL, false) + ".class)"); } else { pw.print(")");
result.add(method); } else if (!isProcessed && isGetter && !hasSetter && isPublic) { processingEnv.getMessager().printMessage(Kind.WARNING, "Method " + method.getSimpleName() + " does not have setter, type = " + processingElement.asConfigurationElement()); TypeMirror superclass = processingElement.asConfigurationElement().getSuperclass(); if (superclass.getKind().equals(TypeKind.DECLARED)) { result.addAll(getMethodsForProcessings(configurationTypeElement, mappingType, (DomainDeclaredType) processingEnv.getTransferObjectUtils().getDomainType(superclass), domainTypeElement, ignored)); result.addAll(superClassMethods); List<ConfigurationTypeElement> configurationsForDomain = processingEnv.getEnvironmentContext().getConfigurationEnv(). getConfigurationsForDomain(processingElement.getSuperClass()); if (configurationsForDomain != null && configurationsForDomain.size() > 0) {
protected void handleRemoteInterface(Element element, ServiceConverterPrinterContext context) { LocalServiceTypeElement localInterface = context.getLocalServiceInterface(); ServiceTypeElement serviceTypeElement = context.getService(); RemoteServiceTypeElement remoteServiceInterface = localInterface.getRemoteServiceInterface(); if (remoteServiceInterface == null) { processingEnv.getMessager().printMessage(Kind.ERROR, "[ERROR] Unable to find remote service pair for the local service definition " + localInterface.toString(), serviceTypeElement.asElement()); return; } List<ExecutableElement> remoteMethods = ElementFilter.methodsIn(element.getEnclosedElements()); for (ExecutableElement remoteMethod : remoteMethods) { ExecutableElement localMethod = getDomainMethodPair(remoteMethod, serviceTypeElement); if (localMethod == null) { processingEnv.getMessager().printMessage(Kind.ERROR, "[ERROR] Service class does not implements local service method " + remoteMethod.toString() + ". Please specify correct service implementation.", serviceTypeElement.asElement()); continue; } handleMethod(context, localMethod, remoteMethod); } TypeElement typeElement = (TypeElement)element; for (TypeMirror interfaceType: typeElement.getInterfaces()) { handleRemoteInterface(((DeclaredType)interfaceType).asElement(), context); } } protected abstract void handleMethod(ServiceConverterPrinterContext context, ExecutableElement localMethod, ExecutableElement remoteMethod);
processingEnv.getMessager().printMessage(Kind.ERROR, "[ERROR] Unable to find id method for " + configurationElement.toString(), configurationElement.asConfigurationElement()); return; MutableTypeMirror dtoIdType = processingEnv.getTypeUtils().toMutableType(idMethod.getReturnType()); DomainType domainIdTypeElement = null; if (domainIdTypeElement.getConverter() != null) { pw.print(dtoIdType, " " + idName + " = "); Field field = new Field(methodName, processingEnv.getTypeUtils().toMutableType(domainIdTypeElement)); MutableDeclaredType fieldType = processingEnv.getTypeUtils().getDeclaredType(processingEnv.getTypeUtils().toMutableType(Class.class), new MutableDeclaredType[] { dtoSuperClass.getDomain() }); processingEnv.getUsedTypes().add(dtoSuperClass);
processingEnv.getMessager().printMessage(Kind.ERROR, "[ERROR] Unable to find getter method for the field " + currentPath + " in the " + domainTypeElement.toString(), context.getConfigurationTypeElement().asConfigurationElement()); processingEnv.getMessager().printMessage( Kind.ERROR, "[ERROR] Invalid mapping specified in the field " + currentPath + ". Current path (" + fullPath MutableDeclaredType fieldType = processingEnv.getTypeUtils().getDeclaredType(processingEnv.getTypeUtils().toMutableType(Class.class), new MutableDeclaredType[] { referenceDomainType.getDto() }); processingEnv.getMessager().printMessage(Kind.ERROR, "[ERROR] Setter is not available for the field " + currentPath + " in the class " + instantiableDomainTypeElement.toString(), context.getConfigurationTypeElement().asConfigurationElement());
protected MutableTypeMirror getParameterType(TransferObjectContext context, PathResolver domainPathResolver) { return processingEnv.getTypeUtils().toMutableType(getSetterMethod(context, domainPathResolver).getParameters().get(0).asType()); }
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 Set<? extends MutableTypeMirror> processBounds(Set<? extends MutableTypeMirror> bounds) { if (bounds.size() > 0) { Set<MutableTypeMirror> newBounds = new HashSet<MutableTypeMirror>(); Iterator<? extends MutableTypeMirror> iterator = bounds.iterator(); while (iterator.hasNext()) { MutableTypeMirror next = iterator.next(); if (next.getKind().isDeclared()) { List<MutableDeclaredType> dataInterfaces = new ArrayList<MutableDeclaredType>(); findDomainData(((MutableDeclaredType)next), dataInterfaces); if (dataInterfaces.size() > 0) { MutableDeclaredType dtoType = (MutableDeclaredType)envContext.getProcessingEnv().getTransferObjectUtils().getDomainType(next).getDto(); DomainDeclaredType domainDeclared = new DataDomainDeclared(dataInterfaces.get(0), dtoType, envContext, null/*, configurationContext*/); domainDeclared.setTypeVariables(new MutableTypeVariable[]{}); if (!hasCustomProperties((MutableDeclaredType) next, dataInterfaces.get(0))) { newBounds.add(domainDeclared); } else { newBounds.add(next); } } else { newBounds.add(next); } } else { newBounds.add(next); } } return newBounds; } return bounds; }
protected MutableTypeMirror getDelegateCast(MutableTypeMirror domainNamedType, boolean stripWildcard) { TypeMirror domainType = processingEnv.getTypeUtils().fromMutableType(domainNamedType); if (domainType == null) { return domainNamedType; } DomainType domainTypeElement = processingEnv.getTransferObjectUtils().getDomainType(domainType); return castToDelegate(domainNamedType, domainTypeElement.getDomainDefinitionConfiguration() == null ? null : domainTypeElement.getDomainDefinitionConfiguration().getDelegateConfigurationTypeElement(), stripWildcard); }