@Override public MutableTypeKind getKind() { return ensureDelegateType().getKind(); }
private Set<? extends MutableTypeMirror> stripTypeParametersTypes(Set<? extends MutableTypeMirror> bounds) { for (MutableTypeMirror bound: bounds) { if (bound.getKind().equals(MutableTypeKind.CLASS) || bound.getKind().equals(MutableTypeKind.INTERFACE)) { ((MutableDeclaredType)bound).stripTypeParametersTypes(); } } return bounds; }
protected MutableTypeMirror getDataObject(MutableTypeMirror type) { switch (type.getKind()) { case CLASS: case INTERFACE: return getDataObject((MutableDeclaredType)type); case TYPEVAR: return getDataObject((MutableTypeVariable)type); } return type; }
protected List<ConfigurationTypeElement> getConfigurations(MutableTypeMirror domainType) { List<ConfigurationTypeElement> domainConfigurations = super.getConfigurations(domainType); if (domainType.getKind().equals(MutableTypeKind.CLASS) || domainType.getKind().equals(MutableTypeKind.INTERFACE)) { List<MutableDeclaredType> domainData = dataTypeResolver.getDomainData((MutableDeclaredType)domainType); if (domainData.size() > 0) { List<ConfigurationTypeElement> dataConfigurations = super.getConfigurations(domainData.get(0)); if (domainConfigurations != null && domainConfigurations.size() > 0) { List<ConfigurationTypeElement> result = new ArrayList<ConfigurationTypeElement>(); result.addAll(domainConfigurations); result.addAll(dataConfigurations); return result; } return dataConfigurations; } } return domainConfigurations; }
public MutableTypeVariable getTypeVariable(String name, MutableTypeMirror... upperBounds) { MutableVariable typeVariable = new MutableVariable(); typeVariable.setVariable(name); Set<MutableTypeMirror> bounds = new HashSet<MutableTypeMirror>(); for (MutableTypeMirror bound: upperBounds) { if (bound != null) { if (bound != null && (!bound.getKind().isDeclared() || name == null || !bound.toString().equals(Object.class.getCanonicalName()))) { bounds.add(bound); } } } typeVariable.setUpperBounds(bounds); return typeVariable; }
private boolean stripWildcardTypeVariables(MutableTypeMirror type) { if (type == null) { return false; } switch (type.getKind()) { case CLASS: case INTERFACE: List<? extends MutableTypeVariable> typeVariables = ((MutableDeclaredType)type).getTypeVariables(); if (typeVariables != null) { for (MutableTypeVariable typeVariable: typeVariables) { if (stripWildcardTypeVariables((MutableDeclaredType)type, typeVariable)) { return true; } } } default: } return false; }
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; }
protected MutableTypeMirror toPrintableType(MutableTypeMirror mutableType) { if (mutableType.getKind().isDeclared()) { MutableDeclaredType declaredType = (MutableDeclaredType)mutableType; return declaredType.clone().stripTypeParametersTypes(); } return mutableType; } }
public MutableTypeMirror toReturnType(MutableTypeMirror type) { switch (type.getKind()) { case PRIMITIVE: return type; case VOID: return toReturnType(((MutableDeclaredType)type).asType()); case ARRAY: case TYPEVAR: return toParamType(type); default: return stripTypeParametersTypes((MutableDeclaredType)type); } }
public MapBasedType(TypeElement mapBasedElement, MutableProcessingEnvironment processingEnv) { this.mapBasedElement = mapBasedElement; this.processingEnv = processingEnv; setSuperClass(processingEnv.getTypeUtils().toMutableType(MapBasedObject.class)); List<MutableDeclaredType> interfaces = new ArrayList<MutableDeclaredType>(); for (TypeMirror interfaceElementMirror : mapBasedElement.getInterfaces()) { MutableTypeMirror mutableInterface = processingEnv.getTypeUtils().toMutableType(interfaceElementMirror); if (mutableInterface.getKind().isDeclared()) { interfaces.add((MutableDeclaredType)mutableInterface); } } setInterfaces(interfaces); setKind(MutableTypeKind.CLASS); }
protected void printCastLocalMethodResult(FormattedPrintWriter pw, MutableTypeMirror returnLocalType, ServiceConverterPrinterContext context) { if (returnLocalType == null) { return; } switch (returnLocalType.getKind()) { case CLASS: case INTERFACE: if (stripWildcardTypeVariables(((MutableDeclaredType)returnLocalType))) { pw.print("(", ((MutableDeclaredType)returnLocalType).clone().stripTypeParameters(), ")"); } default: } }
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 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); } } }
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; } }
public boolean isAssignable(MutableTypeMirror t1, MutableTypeMirror t2) { if (isSameType(t1, t2)) { return true; } if (implementsType(t1, t2)) { return true; } if (t1.getKind().isDeclared()) { if (((MutableDeclaredType)t1).getSuperClass() == null) { return false; } return isAssignable(((MutableDeclaredType)t1).getSuperClass(), t2); } 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 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 }
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; } }