protected final MutableReferenceType getThisReference() { return processingEnv.getTypeUtils().getReference(null, ConverterConstructorParametersResolver.THIS); }
protected MutableTypeMirror getParameterType(TransferObjectContext context, PathResolver domainPathResolver) { return processingEnv.getTypeUtils().toMutableType(getSetterMethod(context, domainPathResolver).getParameters().get(0).asType()); }
private ConverterConstructorParameter getSameByType(MutableTypeMirror typeParameter, Collection<ConverterConstructorParameter> parameters) { for (ConverterConstructorParameter parameter : parameters) { if (processingEnv.getTypeUtils().isAssignable(parameter.getType(), typeParameter)) { //if (parameter.getType().toString(ClassSerializer.CANONICAL).equals(typeParameter.toString(ClassSerializer.CANONICAL))) { return parameter; } } return null; } }
private Element toElement(MutableDeclaredType type) { Element domainElement = type.asElement(); if (domainElement == null) { TypeMirror fromMutableType = envContext.getProcessingEnv().getTypeUtils().fromMutableType(type); domainElement = ((DeclaredType)fromMutableType).asElement(); } return domainElement; }
private void collectTypeConverters(TypeMirror type, Set<ConverterTypeElement> converters, List<ConverterConstructorParameter> parameters) { collectTypeConverters(processingEnv.getTypeUtils().toMutableType(type), converters, parameters); }
@Override public void initialize(final ConverterProviderContextType contextType) { // final MutableExecutableType converterProviderContextMethod = processingEnv.getTypeUtils().getExecutable(context.getConvertProviderContextType(), HibernateServiceConverterProviderParameterResolver.GET_CONVERTER_PROVIDER_CONTEXT_METHOD); // converterProviderContextMethod.addModifier(Modifier.PROTECTED); // serviceTypeElement.getServiceConverter().addMethod(converterProviderContextMethod); // HierarchyPrintWriter methodPrinter = converterProviderContextMethod.getPrintWriter(); this.contextType = contextType; initializeContextMethod = processingEnv.getTypeUtils().getExecutable(processingEnv.getTypeUtils().toMutableType(Void.class), "initialize"); initializeContextMethod.addModifier(Modifier.PUBLIC); contextType.addMethod(initializeContextMethod); super.initialize(contextType); }
protected void printResultConverter(ConverterProviderPrinterContext context) { pw.print("return (", getTypedDtoConverter(), ") "); MutableDeclaredType fieldType = processingEnv.getTypeUtils().getDeclaredType(processingEnv.getTypeUtils().toMutableType(Class.class), processingEnv.getTypeUtils().getTypeVariable(ConverterTypeElement.DOMAIN_TYPE_ARGUMENT_PREFIX)); Field field = new Field(DOMAIN_CLASS_PARAMETER_NAME, fieldType); field.setCastType(processingEnv.getTypeUtils().getDeclaredType(processingEnv.getTypeUtils().toMutableType(Class.class), new MutableDeclaredType[] { context.getRawDomain() })); converterProviderPrinter.printDomainGetConverterMethodName(context.getRawDomain(), field, ((ServiceConverterProviderPrinterContext)context).getLocalMethod(), pw, false); }
@Override protected void printResultConverter(ConverterProviderPrinterContext context) { pw.print("return (", getTypedDtoConverter(), ") "); MutableDeclaredType fieldType = processingEnv.getTypeUtils().getDeclaredType(processingEnv.getTypeUtils().toMutableType(Class.class), processingEnv.getTypeUtils().getTypeVariable(ConverterTypeElement.DTO_TYPE_ARGUMENT_PREFIX)); Field field = new Field(DTO_CLASS_PARAMETER_NAME, fieldType); field.setCastType(processingEnv.getTypeUtils().getDeclaredType(processingEnv.getTypeUtils().toMutableType(Class.class), new MutableDeclaredType[] { context.getDto() })); converterProviderPrinter.printDtoGetConverterMethodName(context.getRawDto(), field, ((ServiceConverterProviderPrinterContext)context).getLocalMethod(), pw, false); }
private boolean containsField(TypeElement superClassElement, ParameterElement constructorAdditionalParameter) { if (superClassElement == null) { return false; } List<VariableElement> fields = ElementFilter.fieldsIn(superClassElement.getEnclosedElements()); for (VariableElement field: fields) { if (constructorAdditionalParameter.getType().isSameType(processingEnv.getTypeUtils().toMutableType(field.asType()))) { return true; } } if (superClassElement.getSuperclass().getKind().equals(TypeKind.DECLARED)) { return containsField((TypeElement)((DeclaredType)superClassElement.getSuperclass()).asElement(), constructorAdditionalParameter); } return false; } }
private MutableTypeMirror getBoundType(MutableTypeVariable typeVariable, ExecutableElement ownerElement) { Set<? extends MutableTypeMirror> lowerBounds = typeVariable.getLowerBounds(); if (lowerBounds != null && lowerBounds.size() > 0) { return lowerBounds.iterator().next(); } Set<? extends MutableTypeMirror> upperBounds = typeVariable.getUpperBounds(); if (upperBounds != null && upperBounds.size() > 0) { return upperBounds.iterator().next(); } List<? extends TypeParameterElement> typeParameters = ownerElement.getTypeParameters(); for (TypeParameterElement typeParameter: typeParameters) { if (typeParameter.getSimpleName().toString().equals(typeVariable.getVariable())) { if (typeParameter.getBounds().size() > 0) { return processingEnv.getTypeUtils().toMutableType(typeParameter.getBounds().iterator().next()); } } } return null; }
private List<MutableTypeVariable> getSubtypesForWildcards(MutableDeclaredType ownerType, List<? extends MutableTypeVariable> typeVariables, ExecutableElement ownerMethod) { List<MutableTypeVariable> result = new ArrayList<MutableTypeVariable>(); int i = 0; for (MutableTypeVariable typeVariable: typeVariables) { if (typeVariable.getVariable() != null && typeVariable.getVariable().equals(MutableWildcardType.WILDCARD_NAME)) { Set<? extends MutableTypeMirror> lowerBounds = typeVariable.getLowerBounds(); Set<? extends MutableTypeMirror> upperBounds = typeVariable.getUpperBounds(); int size = (lowerBounds == null ? 0 : lowerBounds.size()) + (upperBounds == null ? 0 : upperBounds.size()); if (size == 0) { //it is only wildcard so try to identify type from owner result.add(processingEnv.getTypeUtils().getTypeVariable(null, getBoundType(ownerType.getTypeVariables().get(i), ownerMethod))); } else { result.add(processingEnv.getTypeUtils().getTypeVariable(null, typeVariable)); } } else { result.add(typeVariable); } i++; } return result; }
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; } }
DomainType parameterDomainType = parameterDtoType.getDomain(); if (!processingEnv.getTypeUtils().isSameType(parameterDomainType, processingEnv.getTypeUtils().toMutableType(overriderMethod.getParameters().get(index).asType()))) { pairMethod = false; break; DtoType returnDtoType = returnDomainType.getDto(); MutableTypeMirror mutableRemoteReturnType = processingEnv.getTypeUtils().toMutableType(remoteMethod.getReturnType()); if (processingEnv.getTypeUtils().isSameType(returnDtoType, mutableRemoteReturnType)) { return overriderMethod;
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 DomainType getDomainForType(TypeMirror type) { if (type.getKind().equals(TypeKind.DECLARED)) { List<MutableDeclaredType> domainDataTypes = new DataTypeResolver(environmentContext).getDomainData((MutableDeclaredType) environmentContext.getProcessingEnv().getTypeUtils().toMutableType(type)); if (domainDataTypes.size() > 0) { return super.getDomainForType(environmentContext.getProcessingEnv().getElementUtils().getTypeElement(domainDataTypes.get(0).getCanonicalName()).asType()); } } return super.getDomainForType(type); }
protected MutableTypeMirror getWildcardDelegate(MutableTypeMirror domainDelegate) { if (domainDelegate.getKind().isDeclared() && ((MutableDeclaredType)domainDelegate).getTypeVariables().size() == 1) { return ((MutableDeclaredType)domainDelegate).clone().setTypeVariables(processingEnv.getTypeUtils().getWildcardType((MutableTypeMirror)null, (MutableTypeMirror)null)); } return domainDelegate; }
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 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); }
private MutableTypeMirror findSubtypesForWildcards(MutableTypeMirror type, ExecutableElement ownerMethod) { if (type == null) { return null; } switch (type.getKind()) { case CLASS: case INTERFACE: MutableDeclaredType clone = ((MutableDeclaredType)type).clone(); List<? extends MutableTypeVariable> typeVariables = clone.getTypeVariables(); clone.setTypeVariables(getSubtypesForWildcards((MutableDeclaredType)processingEnv.getTypeUtils().toMutableType(processingEnv.getElementUtils().getTypeElement(((MutableDeclaredType)type).getCanonicalName())), typeVariables, ownerMethod).toArray(new MutableTypeVariable[] {})); return clone; case TYPEVAR: if (((MutableTypeVariable)type).getVariable() != null && ((MutableTypeVariable)type).getVariable() == MutableWildcardType.WILDCARD_NAME) { return getBoundType(((MutableTypeVariable)type).clone(), ownerMethod); } default: return type; } }
@Override protected void processElement(ProcessorContext context) { FormattedPrintWriter pw = context.getPrintWriter(); converterProviderPrinter = getConverterProviderPrinter(pw); TypeElement cachedConverterType = processingEnv.getElementUtils().getTypeElement(BasicCachedConverter.class.getCanonicalName()); ParameterElement[] constructorAdditionalParameters = getParametersResolverProvider().getParameterResolver(UsageType.DEFINITION).getConstructorAditionalParameters(); ConstructorPrinter constructorPrinter = new ConstructorPrinter(context.getOutputType(), processingEnv); constructorPrinter.printConstructors(cachedConverterType, constructorAdditionalParameters); TypeElement superClassElement = context.getOutputType().getSuperClass() != null ? context.getOutputType().getSuperClass().asElement() : null; for (ParameterElement constructorAdditionalParameter: constructorAdditionalParameters) { String parameterName = constructorAdditionalParameter.getName().toString(); if (constructorAdditionalParameter.getPropagationType().equals(PropagationType.PROPAGATED_MUTABLE) && !containsField(superClassElement, constructorAdditionalParameter)) { MutableVariableElement field = processingEnv.getElementUtils().getParameterElement(constructorAdditionalParameter.getType(), parameterName); context.getOutputType().addField((MutableVariableElement) field.addModifier(Modifier.PROTECTED)); MutableExecutableType setterMethod = processingEnv.getTypeUtils().getExecutable( processingEnv.getTypeUtils().toMutableType(processingEnv.getTypeUtils().getNoType(TypeKind.VOID)), MethodHelper.toSetter(parameterName)). addParameter(processingEnv.getElementUtils().getParameterElement(constructorAdditionalParameter.getType(), parameterName)).addModifier(Modifier.PUBLIC); context.getOutputType().addMethod(setterMethod); setterMethod.getPrintWriter().println("this." + parameterName + " = " + parameterName + ";"); } } super.processElement(context); converterProviderPrinter.printConverterMethods(context.getOutputType(), false, ConverterInstancerType.REFERENCED_CONVERTER_INSTANCER); }