@Override protected MutableTypeVariable getTypeVariable(MutableTypeVariable variable) { if (variable.getVariable() != null && variable.getVariable().length() > 0) { return variable.clone().setVariable(ConverterTypeElement.DOMAIN_TYPE_ARGUMENT_PREFIX + "_" + variable.getVariable()); } return variable; } }
public MutableTypeVariable[] getVariableParameterTypes() { List<MutableTypeVariable> result = new ArrayList<MutableTypeVariable>(); for (MutableTypeVariable typeParameter: getTypeVariables()) { if (typeParameter.getVariable() != null && typeParameter.getVariable().length() > 0) { result.add(typeParameter); } } return result.toArray(new MutableTypeVariable[] {}); }
@Override public String getVariable() { return ensureDelegateType().getVariable(); }
public boolean hasVariableParameterTypes() { if (!hasTypeParameters()) { return false; } if (typeVariables != null) { for (MutableTypeVariable typeParameter: getTypeVariables()) { if (typeParameter.getVariable() != null && typeParameter.getVariable().length() > 0 && !typeParameter.getVariable().equals(MutableWildcard.WILDCARD_NAME)) { return true; } } } else if (type != null && type.getKind().equals(TypeKind.DECLARED)) { for (TypeMirror typeArgument: ((DeclaredType)type).getTypeArguments()) { switch (typeArgument.getKind()) { case TYPEVAR: String variableName = ((TypeVariable)typeArgument).asElement().getSimpleName().toString(); if (variableName != null && variableName.length() > 0 && !variableName.equals(MutableWildcard.WILDCARD_NAME)) { return true; } default: break; } } } return false; }
@Override public boolean isSameType(MutableTypeMirror type) { if (type == null) { return false; } if (!type.getKind().equals(MutableTypeKind.TYPEVAR)) { return false; } MutableTypeVariable typeVariable = (MutableTypeVariable)type; if (getVariable() != null && typeVariable.getVariable() != null) { if (!typeVariable.getVariable().equals(getVariable())) { return false; } } else if (getVariable() == null) { if (typeVariable.getVariable() != null) { return false; } } else { if (typeVariable.getVariable() == null) { return false; } } return true; //TODO validate also bounds }
public static MutableTypeMirror stripTypeParametersVariables(MutableTypeMirror parameterType) { switch (parameterType.getKind()) { case CLASS: case INTERFACE: return ((MutableDeclaredType)parameterType).clone().stripTypeParametersVariables(); case TYPEVAR: if (((MutableTypeVariable)parameterType).getVariable() != null && ((MutableTypeVariable)parameterType).getVariable() != MutableWildcardType.WILDCARD_NAME) { return ((MutableTypeVariable)parameterType).clone().setVariable(null); } default: return parameterType; } }
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; }
protected void setDataTypeVariables() { List<? extends MutableTypeVariable> typeVariables = getTypeVariables(); List<MutableTypeVariable> dataTypeVariables = new ArrayList<MutableTypeVariable>(); for (MutableTypeVariable typeVariable: typeVariables) { dataTypeVariables.add(processingEnv.getTypeUtils().getTypeVariable(typeVariable.getVariable(), getDataTypes(typeVariable.getUpperBounds()).toArray(new MutableTypeMirror[] {}), getDataTypes(typeVariable.getLowerBounds()).toArray(new MutableTypeMirror[] {}))); } setTypeVariables(dataTypeVariables.toArray(new MutableTypeVariable[] {})); } }
public static MutableTypeMirror stripTypeParametersTypes(MutableTypeMirror parameterType) { switch (parameterType.getKind()) { case CLASS: case INTERFACE: return ((MutableDeclaredType)parameterType).clone().stripTypeParametersTypes(); case TYPEVAR: if (((MutableTypeVariable)parameterType).getVariable() != null && ((MutableTypeVariable)parameterType).getVariable() != MutableWildcardType.WILDCARD_NAME) { return ((MutableTypeVariable)parameterType).clone().setLowerBounds(null).setUpperBounds(null); } default: return parameterType; } }
protected MutableTypeVariable getDataObject(MutableTypeVariable typeVariable) { Set<? extends MutableTypeMirror> lowerBounds = getDataBounds(typeVariable.getLowerBounds()); Set<? extends MutableTypeMirror> upperBounds = getDataBounds(typeVariable.getUpperBounds()); return processingEnv.getTypeUtils().getTypeVariable(typeVariable.getVariable(), lowerBounds.toArray(new MutableTypeMirror[] {}), upperBounds.toArray(new MutableTypeMirror[] {})); }
private boolean stripWildcardTypeVariables(MutableDeclaredType owner, MutableTypeVariable typeVariable) { if (typeVariable.getVariable() != null && typeVariable.getVariable() == MutableWildcardType.WILDCARD_NAME) { return true; } if (typeVariable.getLowerBounds() != null) { for (MutableTypeMirror lowerBound: typeVariable.getLowerBounds()) { if (stripWildcardTypeVariables(lowerBound)) { return true; } } } if (typeVariable.getUpperBounds() != null) { for (MutableTypeMirror upperBound: typeVariable.getUpperBounds()) { if (stripWildcardTypeVariables(upperBound)) { return true; } } } return false; }
if (parameterElement.getVariable().toString().equals(typeVariable.getVariable())) { found = true; break;
public static MutableDeclaredType replaceTypeVariablesByWildcards(MutableDeclaredType type) { if (type.getTypeVariables() == null || type.getTypeVariables().size() == 0) { return type; } for (MutableTypeVariable typeVariable: type.getTypeVariables()) { if (typeVariable.getVariable() != null) { typeVariable.setLowerBounds(null); typeVariable.setUpperBounds(null); typeVariable.setVariable(MutableWildcardType.WILDCARD_NAME); } else { //TODO process bounds } } return type; }
public MutableDeclaredType stripWildcards() { boolean invalidate = false; MutableTypeVariable[] variables = new MutableTypeVariable[getTypeVariables().size()]; int i = 0; for (MutableTypeVariable typeParameter: getTypeVariables()) { if (typeParameter.getVariable() != null && typeParameter.getVariable().equals(MutableWildcardType.WILDCARD_NAME) && (typeParameter.getLowerBounds().size() + typeParameter.getUpperBounds().size()) > 0) { MutableVariable typeVariable = new MutableVariable(); typeVariable.setLowerBounds(stripTypeParametersTypes(typeParameter.getLowerBounds())); typeVariable.setUpperBounds(stripTypeParametersTypes(typeParameter.getUpperBounds())); typeVariable.setVariable(null); variables[i] = typeVariable; invalidate = true; } else { variables[i] = typeParameter; } i++; } if (invalidate) { dirty(); } return setTypeVariables(variables); }
public MutableDeclaredType renameTypeParameter(RenameActionType actionType, String parameter, String oldName, boolean recursive) { if (getTypeVariables() == null || getTypeVariables().size() == 0) { return this; } dirty(); for (MutableTypeVariable typeParameter: this.getTypeVariables()) { String variable = typeParameter.getVariable(); if (variable != null && !variable.equals(MutableWildcardType.WILDCARD_NAME)) { if (oldName == null || oldName.equals(variable)) { variable = actionType.apply(variable, parameter); } typeParameter.setVariable(variable); } else if (recursive) { renameBounds(typeParameter.getUpperBounds(), actionType, parameter, oldName, recursive); renameBounds(typeParameter.getLowerBounds(), actionType, parameter, oldName, recursive); } } return this; }
public MutableTypeMirror toParamType(MutableTypeMirror type) { switch (type.getKind()) { case TYPEVAR: return processingEnv.getTypeUtils().getTypeVariable(((MutableTypeVariable)type).getVariable().toString()); case ARRAY: return processingEnv.getTypeUtils().getArrayType(toParamType(((MutableArrayType)type).getComponentType())); default: return processingEnv.getTypeUtils().toMutableType(type); } } }
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; } }
protected void printCopyByLocalConverter(String domainField, DomainType domainMethodReturnType, String dtoField, FormattedPrintWriter pw) { pw.println("} else {"); pw.print(TransferObjectElementPrinter.RESULT_NAME + "." + MethodHelper.toSetter(dtoField)); if (domainMethodReturnType.getKind().equals(MutableTypeKind.TYPEVAR)) { pw.print("((" + ConverterTypeElement.DTO_TYPE_ARGUMENT_PREFIX + "_" + ((MutableTypeVariable)domainMethodReturnType).getVariable() + ")"); } else { pw.print("((", domainMethodReturnType.getDto(), ")"); } pw.print(TransferObjectElementPrinter.DOMAIN_NAME + "." + domainField); pw.println(");"); pw.println("}"); } }
protected void printCopyByLocalConverter(String localConverterName, PathResolver domainPathResolver, DomainType domainMethodReturnType, String dtoField, FormattedPrintWriter pw) { pw.println("if (" + localConverterName + " != null) {"); pw.print(TransferObjectElementPrinter.RESULT_NAME + "." + MethodHelper.toSetter(domainPathResolver.getPath()) + "(" + localConverterName + ".fromDto(" + TransferObjectElementPrinter.DTO_NAME + "." + MethodHelper.toGetter(dtoField) + ")"); pw.println(");"); pw.println("} else {"); pw.print(TransferObjectElementPrinter.RESULT_NAME + "." + MethodHelper.toSetter(domainPathResolver.getPath())); if (domainMethodReturnType.getKind().equals(MutableTypeKind.TYPEVAR)) { pw.print("((" + ConverterTypeElement.DOMAIN_TYPE_ARGUMENT_PREFIX + "_" + ((MutableTypeVariable) domainMethodReturnType).getVariable() + ")"); } else { pw.print("((" + domainMethodReturnType + ")"); } pw.print(TransferObjectElementPrinter.DTO_NAME + "." + MethodHelper.toGetter(dtoField)); pw.println(");"); pw.println("}"); } }