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(); }
@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 getRawTypeReference() { if (isAllRawType()) { return this; } CompoundTypeReference result = getOwner().newCompoundTypeReference(isSynonym()); for(LightweightTypeReference component: expose(components)) { result.addComponent(component.getRawTypeReference()); } 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(); }
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); } }
return parameterType; ITypeReferenceOwner owner = compoundResult.getOwner(); LightweightTypeReference iterableOrArray = null; LightweightTypeReference addAsArrayComponentAndIterable = null;