@Override public CompoundTypeReference newCompoundTypeReference(boolean synonym) { return new CompoundTypeReference(this, synonym); }
@Override public LightweightTypeReference getRawTypeReference() { if (isAllRawType()) { return this; } CompoundTypeReference result = getOwner().newCompoundTypeReference(isSynonym()); for(LightweightTypeReference component: expose(components)) { result.addComponent(component.getRawTypeReference()); } return result; }
@Override public String getSimpleName() { return getAsString(SimpleNameFunction.INSTANCE); }
/** * {@inheritDoc} * * If this is a multi-type rather than a {@link #isSynonym() synonym}, the Java compliant * type reference is determined from the common super type of all participating, non-interface types. * If there is no such type or this is a synonym, all the component types are used to compute * the common super type and use that one as the type. */ @Override public JvmTypeReference toJavaCompliantTypeReference(IVisibilityHelper visibilityHelper) { if (!isSynonym()) { List<LightweightTypeReference> nonInterfaceTypes = getNonInterfaceTypes(components); if (nonInterfaceTypes != null) { return toJavaCompliantTypeReference(nonInterfaceTypes, visibilityHelper); } } return toJavaCompliantTypeReference(components, visibilityHelper); }
@Override public FunctionTypeKind getFunctionTypeKind() { for(LightweightTypeReference component: expose(components)) { if (component.isFunctionType()) { FunctionTypeKind kind = getFunctionTypeKind(); if (kind != FunctionTypeKind.NONE) { return kind; } } } return FunctionTypeKind.NONE; }
@Override protected LightweightTypeReference doVisitCompoundTypeReference(CompoundTypeReference reference, Visiting visiting) { if (reference.isResolved() && reference.isOwnedBy(getOwner())) return reference; CompoundTypeReference result = getOwner().newCompoundTypeReference(reference.isSynonym()); for(LightweightTypeReference component: reference.getMultiTypeComponents()) { result.addComponent(visitTypeArgument(component, visiting)); } return result; }
@Override protected LightweightTypeReference doVisitCompoundTypeReference(CompoundTypeReference reference, ResourceSet resourceSet) { if (reference.isRawType()) return reference; CompoundTypeReference result = reference.getOwner().newCompoundTypeReference(reference.isSynonym()); enhanceCompoundReference(reference.getMultiTypeComponents(), result, resourceSet); return result; }
@Override public LightweightTypeReference toJavaType() { if (isMultiType()) { LightweightTypeReference result = null; for(LightweightTypeReference component: getMultiTypeComponents()) { if (!component.isInterfaceType()) { if (result != null) { result = null; break; } result = component; } } if (result != null) { return result; } } LightweightTypeReference result = getServices().getTypeConformanceComputer().getCommonSuperType(getMultiTypeComponents(), getOwner()); if (result == null) { throw new IllegalStateException("Cannot expression " + this + " as Java type reference"); } return result.toJavaType(); }
@Override protected LocalTypeSubstitutor.SubstitutionResult doVisitCompoundTypeReference(CompoundTypeReference reference, VarianceInfo varianceInfo) { CompoundTypeReference result = owner.newCompoundTypeReference(reference.isSynonym()); boolean didSubstitute = false; for(LightweightTypeReference component: reference.getMultiTypeComponents()) { SubstitutionResult visited = visitTypeArgument(component, varianceInfo); result.addComponent(visited.typeReference); didSubstitute = didSubstitute || visited.didSubstitute; } return new SubstitutionResult(result, didSubstitute); }
@Override public List<LightweightTypeReference> getMultiTypeComponents() { return expose(components); } }
protected void enhanceCompoundReference(List<LightweightTypeReference> references, CompoundTypeReference result, ResourceSet resourceSet) { if (references.isEmpty()) { throw new IllegalStateException("References may not be empty"); } for(LightweightTypeReference component: references) { result.addComponent(component.accept(this, resourceSet)); } }
@Override protected LightweightTypeReference doVisitCompoundTypeReference(final CompoundTypeReference reference) { return this.visit(reference.getMultiTypeComponents()); }
@Override protected void doVisitMultiTypeReference(CompoundTypeReference reference) { List<LightweightTypeReference> components = reference.getMultiTypeComponents(); for(LightweightTypeReference component: components) { result.addComponent(component.copyInto(owner)); } } @Override
@Override protected Boolean doVisitCompoundTypeReference(CompoundTypeReference reference) { if (reference.isResolved()) { return true; } return visit(reference.getMultiTypeComponents()); }
@Override protected LightweightTypeReference doVisitSynonymTypeReference(CompoundTypeReference reference, ResourceSet resourceSet) { if (reference.isRawType()) return reference; List<LightweightTypeReference> components = reference.getMultiTypeComponents(); return components.get(components.size() - 1).accept(this, resourceSet); }
@Override protected void doVisitCompoundTypeReference(CompoundTypeReference reference, StringBuilder param) { String delimiter; if (reference.isSynonym()) { delimiter = " | "; } else { delimiter = " & "; } List<LightweightTypeReference> components = reference.getMultiTypeComponents(); for(int i = 0; i < components.size(); i++) { if (i != 0) { param.append(delimiter); } components.get(i).accept(this, param); } }
protected LightweightTypeReference getAndEnhanceIterableOrArrayFromComponent(LightweightTypeReference parameterType, JvmGenericType iterableType, final CompoundTypeReference compoundResult) { if (parameterType.isUnknown()) { compoundResult.addComponent(parameterType); return parameterType; ITypeReferenceOwner owner = compoundResult.getOwner(); LightweightTypeReference iterableOrArray = null; LightweightTypeReference addAsArrayComponentAndIterable = null; if (parameterType.isPrimitive()) { iterableOrArray = owner.newArrayTypeReference(parameterType); compoundResult.addComponent(iterableOrArray); addAsArrayComponentAndIterable = parameterType.getWrapperTypeIfPrimitive(); } else if (parameterType.isAny()) { wildcard.addUpperBound(addAsArrayComponentAndIterable); reference.addTypeArgument(wildcard); compoundResult.addComponent(reference); if (iterableOrArray == null) { iterableOrArray = reference; LightweightTypeReference potentialPrimitive = addAsArrayComponentAndIterable.getPrimitiveIfWrapperType(); if (potentialPrimitive != addAsArrayComponentAndIterable) { compoundResult.addComponent(owner.newArrayTypeReference(potentialPrimitive)); compoundResult.addComponent(owner.newArrayTypeReference(addAsArrayComponentAndIterable)); } else if (iterableOrArray == null) { // no JRE on the CP if (addAsArrayComponentAndIterable != null) { iterableOrArray = owner.newArrayTypeReference(addAsArrayComponentAndIterable); compoundResult.addComponent(iterableOrArray); } else {
private void convertMultiType(LightweightTypeReference expectation, CompoundTypeReference multiType, XExpression context, ITreeAppendable b, Later expression) { LightweightTypeReference castTo = null; List<LightweightTypeReference> components = multiType.getMultiTypeComponents(); ITypeReferenceOwner owner = multiType.getOwner(); LightweightTypeReference commonType = owner.getServices().getTypeConformanceComputer().getCommonSuperType(components, owner); if (!isJavaConformant(expectation, commonType)) { for(LightweightTypeReference candidate: multiType.getMultiTypeComponents()) { if (isJavaConformant(expectation, candidate)) { castTo = candidate; break; } } } if (castTo != null && mustInsertTypeCast(context, castTo)) { b.append("(("); b.append(castTo); b.append(")"); expression.exec(b); b.append(")"); } else { expression.exec(b); } }
@Override protected LightweightTypeReference doVisitCompoundTypeReference(CompoundTypeReference reference) { return reference.getComponentType(); }
public void addComponent(LightweightTypeReference component) { if (component == null) { throw new NullPointerException("component may not be null"); } if (!component.isOwnedBy(getOwner())) { throw new NullPointerException("component is not valid in current context"); } if (components == null) components = Lists.newArrayListWithCapacity(2); components.add(component); resolved = resolved && component.isResolved(); }