@Override protected LightweightTypeReference doCopyInto(ITypeReferenceOwner owner) { LightweightTypeReference copiedComponent = component.copyInto(owner); return owner.newArrayTypeReference(copiedComponent); }
@Override public LightweightTypeReference getRawTypeReference() { LightweightTypeReference rawComponent = component.getRawTypeReference(); if (rawComponent == component) { return this; } return getOwner().newArrayTypeReference(rawComponent); }
@Override protected List<LightweightTypeReference> getSuperTypes(TypeParameterSubstitutor<?> substitutor) { List<LightweightTypeReference> componentSuperTypes = component.getSuperTypes(substitutor); ITypeReferenceOwner owner = getOwner(); if (!componentSuperTypes.isEmpty()) { List<LightweightTypeReference> result = Lists.newArrayListWithCapacity(componentSuperTypes.size()); for(LightweightTypeReference componentSuperType: componentSuperTypes) { result.add(owner.newArrayTypeReference(componentSuperType)); } return result; } List<LightweightTypeReference> result = Lists.newArrayListWithCapacity(2); result.add(owner.newParameterizedTypeReference(findNonNullType(Cloneable.class))); result.add(owner.newParameterizedTypeReference(findNonNullType(Serializable.class))); return result; }
@Override /* @Nullable */ public LightweightTypeReference getSuperType(Class<?> rawType) { if (isType(rawType)) { return this; } Class<?> rawComponentType = rawType.getComponentType(); if (rawComponentType == null) { if (Object.class.equals(rawType) || Cloneable.class.equals(rawType) || Serializable.class.equals(rawType)) { return internalFindTopLevelType(rawType); } return null; } LightweightTypeReference resultComponent = component.getSuperType(rawComponentType); if (resultComponent == null) { return null; } return getOwner().newArrayTypeReference(resultComponent); }
private ArrayTypeReference doTryConvertToArray(ParameterizedTypeReference typeReference) { LightweightTypeReference parameterizedIterable = typeReference.getSuperType(Iterable.class); if (parameterizedIterable != null) { ITypeReferenceOwner owner = typeReference.getOwner(); if (parameterizedIterable.isRawType()) { // return Object[] List<LightweightTypeReference> superTypes = parameterizedIterable.getSuperTypes(); if (superTypes.isEmpty()) { return null; } LightweightTypeReference objectType = superTypes.get(0); ArrayTypeReference array = owner.newArrayTypeReference(objectType); return array; } else { LightweightTypeReference componentType = parameterizedIterable.getTypeArguments().get(0).getUpperBoundSubstitute(); ArrayTypeReference array = owner.newArrayTypeReference(componentType); return array; } } return null; }
protected LightweightTypeReference doGetTypeParametersForSuperType( final Multimap<JvmType, LightweightTypeReference> all, JvmArrayType rawType, ITypeReferenceOwner owner, List<LightweightTypeReference> types) { JvmComponentType componentType = rawType.getComponentType(); Multimap<JvmType, LightweightTypeReference> copiedMultimap = LinkedHashMultimap.create(all); Collection<LightweightTypeReference> originalReferences = all.get(rawType); List<LightweightTypeReference> componentReferences = Lists.newArrayListWithCapacity(originalReferences.size()); for(LightweightTypeReference originalReference: originalReferences) { addComponentType(originalReference, componentReferences); } copiedMultimap.replaceValues(componentType, componentReferences); List<LightweightTypeReference> componentRequests = Lists.newArrayListWithCapacity(types.size()); for(LightweightTypeReference type: types) { addComponentType(type, componentRequests); } LightweightTypeReference componentTypeReference = getTypeParametersForSuperType( copiedMultimap, componentType, owner, componentRequests); if (componentTypeReference != null) { return owner.newArrayTypeReference(componentTypeReference); } return null; }
public LightweightTypeReference toPlainTypeReference(JvmType type) { if (type.eClass() == TypesPackage.Literals.JVM_ARRAY_TYPE) { JvmComponentType componentType = ((JvmArrayType) type).getComponentType(); LightweightTypeReference componentTypeReference = toPlainTypeReference(componentType); return owner.newArrayTypeReference(componentTypeReference); } return owner.newParameterizedTypeReference(type); }
@Override public LightweightTypeReference getNamedType() { if (isAnonymous()) { return getOwner().newArrayTypeReference(component.getNamedType()); } return super.getNamedType(); }
@Override protected ArrayTypeReference doVisitArrayTypeReference(ArrayTypeReference reference, ResourceSet resourceSet) { if (reference.isRawType()) return reference; LightweightTypeReference componentType = reference.getComponentType(); LightweightTypeReference rawComponentType = componentType.accept(this, resourceSet); return reference.getOwner().newArrayTypeReference(rawComponentType); }
@Override protected LocalTypeSubstitutor.SubstitutionResult doVisitArrayTypeReference(ArrayTypeReference reference, VarianceInfo varianceInfo) { SubstitutionResult visited = reference.getComponentType().accept(this, varianceInfo); if (visited.didSubstitute) { return new SubstitutionResult(owner.newArrayTypeReference(visited.typeReference), true); } return new SubstitutionResult(reference, false); }
@Override /* @Nullable */ public LightweightTypeReference getSuperType(JvmType rawType) { if (rawType.eClass() == TypesPackage.Literals.JVM_ARRAY_TYPE) { JvmComponentType rawComponentType = ((JvmArrayType) rawType).getComponentType(); LightweightTypeReference result = component.getSuperType(rawComponentType); if (result == null) { return null; } if (result == component) return this; return getOwner().newArrayTypeReference(result); } else if (rawType.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE) { String identifier = rawType.getIdentifier(); if (Object.class.getName().equals(identifier) || Cloneable.class.getName().equals(identifier) || Serializable.class.getName().equals(identifier)) { return getOwner().newParameterizedTypeReference(rawType); } } return null; }
@Override public LightweightTypeReference doVisitGenericArrayTypeReference(JvmGenericArrayTypeReference reference) { JvmTypeReference originalComponentType = reference.getComponentType(); LightweightTypeReference lightweightComponentType = null; if (originalComponentType != null) { lightweightComponentType = visit(originalComponentType); if (lightweightComponentType.isAny()) return lightweightComponentType; } else { lightweightComponentType = getObjectReference(); } return owner.newArrayTypeReference(lightweightComponentType); }
@Override protected LightweightTypeReference doVisitArrayTypeReference(ArrayTypeReference reference, Visiting visiting) { if (reference.isResolved() && reference.isOwnedBy(getOwner())) return reference; LightweightTypeReference component = visitTypeArgument(reference.getComponentType(), visiting); component = component.getUpperBoundSubstitute(); return getOwner().newArrayTypeReference(component); }
LightweightTypeReference addAsArrayComponentAndIterable = null; if (parameterType.isPrimitive()) { iterableOrArray = owner.newArrayTypeReference(parameterType); compoundResult.addComponent(iterableOrArray); addAsArrayComponentAndIterable = parameterType.getWrapperTypeIfPrimitive(); 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 {
public LightweightTypeReference toLightweightReference(JvmType type) { if (type.eClass() == TypesPackage.Literals.JVM_ARRAY_TYPE) { JvmComponentType componentType = ((JvmArrayType) type).getComponentType(); LightweightTypeReference componentTypeReference = toLightweightReference(componentType); return owner.newArrayTypeReference(componentTypeReference); } ParameterizedTypeReference result = owner.newParameterizedTypeReference(type); if (type.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE) { result.accept(new TypeReferenceVisitor() { @Override protected void doVisitInnerTypeReference(InnerTypeReference reference) { reference.getOuter().accept(this); super.doVisitInnerTypeReference(reference); } @Override protected void doVisitParameterizedTypeReference(ParameterizedTypeReference reference) { JvmType rawType = reference.getType(); if (rawType.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE) { List<JvmTypeParameter> typeParameters = ((JvmTypeParameterDeclarator) rawType).getTypeParameters(); for(int i = 0, size = typeParameters.size(); i < size; i++) { JvmTypeParameter typeParameter = typeParameters.get(i); reference.addTypeArgument(owner.newParameterizedTypeReference(typeParameter)); } } } }); } return result; }
protected void _computeTypes(XTypeLiteral object, ITypeComputationState state) { JvmType type = object.getType(); if (type == null) { return; } checkTypeParameterNotAllowedAsLiteral(object, type, state); ITypeReferenceOwner owner = state.getReferenceOwner(); LightweightTypeReference clazz = owner.newParameterizedTypeReference(type); for (int i = 0; i < object.getArrayDimensions().size(); i++) { clazz = owner.newArrayTypeReference(clazz); } if (object.getArrayDimensions().isEmpty()) { if (clazz.isPrimitiveVoid()) { clazz = state.getReferenceOwner().newReferenceTo(Void.class); } else { clazz = clazz.getWrapperTypeIfPrimitive(); } } LightweightTypeReference result = owner.newReferenceTo(Class.class); if (result instanceof ParameterizedTypeReference) { ParameterizedTypeReference parameterizedTypeReference = (ParameterizedTypeReference) result; parameterizedTypeReference.addTypeArgument(clazz); } state.acceptActualType(result); }
LightweightTypeReference primitiveComponentType = componentType.getPrimitiveIfWrapperType(); if (primitiveComponentType != componentType) { ArrayTypeReference primitiveArray = type.getOwner().newArrayTypeReference(primitiveComponentType); if (!acceptor.accept(primitiveArray, ConformanceFlags.CHECKED_SUCCESS | ConformanceFlags.DEMAND_CONVERSION | ConformanceFlags.UNBOXING)) { return false;
ArrayTypeReference arrayTypeReference = substitutedComponentType.getOwner().newArrayTypeReference(substitutedComponentType); ArgumentTypeComputationState second = createLinkingTypeComputationState(arrayTypeReference); argumentState = new CompoundTypeComputationState(substitutedComponentType.getOwner(), first, second);
@Override public LightweightTypeReference substitute(LightweightTypeReference original) { if (original instanceof ArrayTypeReference) { LightweightTypeReference componentType = original.getComponentType(); if (componentType instanceof UnboundTypeReference) { LightweightTypeReference substitutedComponentType = substitute(componentType); return getOwner().newArrayTypeReference(substitutedComponentType); } } if (original instanceof UnboundTypeReference) { ConstraintVisitingInfo visitingInfo = createVisiting(); JvmTypeParameter typeParameter = ((UnboundTypeReference) original).getTypeParameter(); JvmTypeParameterDeclarator declarator = typeParameter.getDeclarator(); visitingInfo.pushInfo(declarator, declarator.getTypeParameters().indexOf(typeParameter)); LightweightTypeReference result = visitTypeArgument(original, visitingInfo); return result; } else { LightweightTypeReference result = original.accept(this, createVisiting()); return result; } }
null, -1, null)); state.refineExpectedType(value, array.getOwner().newArrayTypeReference(primitiveComponentType));