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; }
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; } }
@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; } }
MutableTypeVariable mutableTypeVariable = ((MutableTypeVariable)mutableType); if (mutableTypeVariable.getVariable() != null && mutableTypeVariable.getVariable().length() > 0) { TypeMirror erasuredTypeVariable = ProcessorUtils.erasure(owner, mutableTypeVariable.getVariable()); if (erasuredTypeVariable != null) { return processingEnv.getTypeUtils().getTypeVariable(null, processingEnv.getTypeUtils().toMutableType(erasuredTypeVariable)); return processingEnv.getTypeUtils().getTypeVariable(mutableTypeVariable.getVariable()); if (mutableTypeVariable.getUpperBounds().size() > 0 || mutableTypeVariable.getLowerBounds().size() > 0) { mutableTypeVariable = mutableTypeVariable.clone(); if (mutableTypeVariable.getLowerBounds().size() > 0) { mutableTypeVariable.setLowerBounds(toPrintableTypes(owner, mutableTypeVariable.getLowerBounds())); if (mutableTypeVariable.getUpperBounds().size() > 0) { mutableTypeVariable.setUpperBounds(toPrintableTypes(owner, mutableTypeVariable.getUpperBounds()));
protected MutableTypeMirror getTypeParameter(MutableDeclaredType type) { if (!type.hasTypeParameters()) { return null; } MutableTypeVariable mutableTypeVariable = type.getTypeVariables().get(0); if (mutableTypeVariable.getUpperBounds() != null && mutableTypeVariable.getUpperBounds().size() > 0) { return mutableTypeVariable.getUpperBounds().iterator().next(); } if (mutableTypeVariable.getLowerBounds() != null && mutableTypeVariable.getLowerBounds().size() > 0) { return mutableTypeVariable.getLowerBounds().iterator().next(); } return null; }
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 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[] {}); }
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; }
for (MutableTypeVariable typeParameter: ((MutableDeclaredType)domainNamedType).getTypeVariables()) { if (typeParameter.getUpperBounds().size() > 0) { MutableTypeMirror[] convertedBounds = new MutableTypeMirror[typeParameter.getUpperBounds().size()]; Iterator<? extends MutableTypeMirror> iterator = typeParameter.getUpperBounds().iterator(); if (typeParameter.getVariable() != null && typeParameter.getVariable().equals(MutableWildcardType.WILDCARD_NAME) && stripWildcard) { convertedParameters[j++] = processingEnv.getTypeUtils().getTypeVariable(null, convertedBounds); } else { convertedParameters[j++] = processingEnv.getTypeUtils().getTypeVariable(typeParameter.getVariable(), convertedBounds); convertedParameters[j++] = processingEnv.getTypeUtils().getTypeVariable(typeParameter.getVariable());
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 public MutableDeclaredType cloneTypeVariables(MutableDeclaredType declaredType) { // dirty(); this.typeVariables = new LinkedList<MutableTypeVariable>(); for (MutableTypeVariable typeVariable: declaredType.getTypeVariables()) { this.typeVariables.add(typeVariable.clone()); } return this; }
@Override public Set<? extends MutableTypeMirror> getLowerBounds() { return ensureDelegateType().getLowerBounds(); }
@Override public Set<? extends MutableTypeMirror> getUpperBounds() { return ensureDelegateType().getUpperBounds(); }
public MutableTypeMirror stripTypeVariableTypes(MutableTypeMirror mutableType) { if (mutableType instanceof MutableDeclaredType) { ((MutableDeclaredType)mutableType).stripTypeParametersTypes(); return mutableType; } if (mutableType instanceof MutableTypeVariable) { ((MutableTypeVariable)mutableType).setLowerBounds(null); ((MutableTypeVariable)mutableType).setUpperBounds(null); return mutableType; } if (mutableType instanceof MutableWildcardType) { ((MutableWildcardType)mutableType).setSuperBound(null); ((MutableWildcardType)mutableType).setExtendsBound(null); } if (mutableType instanceof MutableArrayType) { stripTypeVariableTypes(((MutableArrayType)mutableType).getComponentType()); } return mutableType; }
@Override public MutableTypeVariable setVariable(String variable) { return ensureDelegateType().setVariable(variable); }
@Override public MutableTypeVariable setUpperBounds(Set<? extends MutableTypeMirror> bounds) { return ensureDelegateType().setUpperBounds(bounds); }
@Override public MutableTypeVariable setLowerBounds(Set<? extends MutableTypeMirror> bounds) { return ensureDelegateType().setLowerBounds(bounds); }
protected MutableTypeMirror getTypeVariableDelegate(MutableTypeMirror domainDelegate) { if (domainDelegate.getKind().isDeclared() && ((MutableDeclaredType)domainDelegate).getTypeVariables().size() == 1) { MutableTypeVariable mutableTypeVariable = ((MutableDeclaredType)domainDelegate).getTypeVariables().get(0); if (mutableTypeVariable.getUpperBounds().size() == 1) { return mutableTypeVariable.getUpperBounds().iterator().next(); } if (mutableTypeVariable.getLowerBounds().size() == 1) { return mutableTypeVariable.getLowerBounds().iterator().next(); } return mutableTypeVariable; } if (domainDelegate.getKind().isDeclared()) { return ((MutableDeclaredType)domainDelegate).clone().setTypeVariables(); } return domainDelegate; }
@Override public String getVariable() { return ensureDelegateType().getVariable(); }
@Override public MutableTypeVariable clone() { return ensureDelegateType().clone(); } }