private boolean isWrapper(JvmTypeParameter typeParameter, /* @Nullable */ RecursionGuard<JvmTypeParameter> stack) { for(JvmTypeConstraint constraint: typeParameter.getConstraints()) { if (constraint.eClass() == TypesPackage.Literals.JVM_UPPER_BOUND) { JvmTypeReference upperBound = constraint.getTypeReference(); if (upperBound != null) { JvmType upperBoundType = upperBound.getType(); if (upperBoundType == null) { return false; } if (upperBoundType.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE) { return isWrapper((JvmGenericType)upperBoundType); } // guard against recursive deps if (upperBoundType.eClass() == TypesPackage.Literals.JVM_TYPE_PARAMETER) { if (typeParameter == upperBoundType || stack != null && !stack.tryNext((JvmTypeParameter) upperBoundType)) { return false; } if (stack == null) { stack = new RecursionGuard<JvmTypeParameter>(); stack.tryNext(typeParameter); stack.tryNext((JvmTypeParameter) upperBoundType); } return isWrapper((JvmTypeParameter) upperBoundType, stack); } } } } return false; } private boolean isWrapper(JvmGenericType type) {
public void done(final XExpression expression) { this.resolvedTypesStack.pop(); this.visiting.done(expression); } }
public boolean tryNext(final XExpression expression) { boolean _tryNext = this.visiting.tryNext(expression); if (_tryNext) { this.resolveTypes(expression); return true; } return false; }
@Override public boolean isRawType() { EClass typeClass = type.eClass(); if (typeClass == TypesPackage.Literals.JVM_GENERIC_TYPE && typeArguments == null) { return ((InternalEObject)type).eIsSet(TypesPackage.JVM_GENERIC_TYPE__TYPE_PARAMETERS); } else if (typeClass == TypesPackage.Literals.JVM_TYPE_PARAMETER) { JvmTypeParameter typeParameter = (JvmTypeParameter) type; return isRawType(typeParameter, new RecursionGuard<JvmTypeParameter>()); } return false; }
private boolean contributesToConflict(JvmDeclaredType type, Set<JvmDeclaredType> involvedInterfaces, RecursionGuard<JvmDeclaredType> guard) { if (!guard.tryNext(type)) { return false; } if (involvedInterfaces.contains(type)) { return true; } for (JvmTypeReference typeRef : type.getExtendedInterfaces()) { JvmType rawType = typeRef.getType(); if (rawType instanceof JvmDeclaredType && contributesToConflict((JvmDeclaredType) rawType, involvedInterfaces, guard)) { return true; } } return false; }
/** * Returns the array representation of this reference if its represents a sub-type of {@link Iterable}. * If the iterable's type is a primitive wrapper, the array is <em>not</em> the primitive array but * the wrapper array. May return <code>null</code> if the conversion is not possible. * * This is the externalized and thereby * exchangeable implementation of {@link ParameterizedTypeReference#tryConvertToArray()}. * * @param typeReference the to-be-converted reference. * @return an equivalent {@link ArrayTypeReference} or <code>null</code>. */ /* @Nullable */ public ArrayTypeReference tryConvertToArray(ParameterizedTypeReference typeReference) { ArrayTypeReference result = doTryConvertToArray(typeReference); if (result != null) { return result; } else { JvmType type = typeReference.getType(); if (type.eClass() == TypesPackage.Literals.JVM_TYPE_PARAMETER) { return doTryConvertToArray(typeReference, new RecursionGuard<JvmTypeParameter>()); } } return null; }
JvmTypeParameter upperBoundTypeParameter = (JvmTypeParameter) upperBoundType; if (guard == null) { guard = new RecursionGuard<JvmTypeParameter>(); guard.tryNext(type); if (guard.tryNext(upperBoundTypeParameter)) { return getPrimitiveKind(upperBoundTypeParameter, guard);
return null; if (!guard.tryNext(thisType)) { return null;
/** * Determine whether the given type contributes to the conflict caused by the given default interface implementation. */ private boolean contributesToConflict(JvmGenericType rootType, ConflictingDefaultOperation conflictingDefaultOperation) { Set<JvmDeclaredType> involvedInterfaces = Sets.newHashSet(); involvedInterfaces.add(conflictingDefaultOperation.getDeclaration().getDeclaringType()); for (IResolvedOperation conflictingOperation : conflictingDefaultOperation.getConflictingOperations()) { involvedInterfaces.add(conflictingOperation.getDeclaration().getDeclaringType()); } RecursionGuard<JvmDeclaredType> recursionGuard = new RecursionGuard<JvmDeclaredType>(); if (rootType.isInterface()) { int contributingCount = 0; for (JvmTypeReference typeRef : rootType.getExtendedInterfaces()) { JvmType rawType = typeRef.getType(); if (rawType instanceof JvmDeclaredType && contributesToConflict((JvmDeclaredType) rawType, involvedInterfaces, recursionGuard)) { contributingCount++; } } return contributingCount >= 2; } else { return contributesToConflict(rootType, involvedInterfaces, recursionGuard); } }
JvmTypeParameter upperBoundTypeParameter = (JvmTypeParameter) upperBoundType; if (guard == null) { guard = new RecursionGuard<JvmTypeParameter>(); guard.tryNext(type); if (guard.tryNext(upperBoundTypeParameter)) { return internalGetPrimitiveKindFromWrapper(upperBoundTypeParameter, guard);
if (recursionGuard.tryNext((JvmTypeParameter) type)) { List<LightweightTypeReference> superTypes = typeReference.getSuperTypes(); for(int i = 0, size = superTypes.size(); i < size; i++) {
JvmTypeReference superType = getSuperType(rawType, interfaceType, type, new RecursionGuard<JvmType>()); return superType;
private boolean isRawType(JvmTypeParameter current, RecursionGuard<JvmTypeParameter> guard) { if (guard.tryNext(current)) { List<JvmTypeConstraint> constraints = current.getConstraints(); for(int i = 0, size = constraints.size(); i < size; i++) {
private LightweightTypeReference getSuperTypeByName(String typeName, boolean interfaceType) { JvmTypeReference superType = getSuperTypeByName(typeName, interfaceType, type, new RecursionGuard<JvmType>()); if (superType != null) { JvmType rawType = superType.getType(); if (isRawType()) { return createRawTypeReference(rawType); } if (superType.eClass() == TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE) { if (((JvmParameterizedTypeReference) superType).getArguments().isEmpty()) { return getOwner().newParameterizedTypeReference(rawType); } } LightweightTypeReference unresolved = getOwner().toLightweightTypeReference(rawType); TypeParameterSubstitutor<?> substitutor = createSubstitutor(); LightweightTypeReference result = substitutor.substitute(unresolved); return result; } return null; }
return null; if (typeName.equals(thisType.getIdentifier()) || !guard.tryNext(thisType)) { return null;