Search in sources :

Example 1 with RecursionGuard

use of org.eclipse.xtext.xbase.typesystem.util.RecursionGuard in project xtext-xtend by eclipse.

the class XtendValidator method contributesToConflict.

/**
 * 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);
    }
}
Also used : JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) RecursionGuard(org.eclipse.xtext.xbase.typesystem.util.RecursionGuard) JvmType(org.eclipse.xtext.common.types.JvmType) IResolvedOperation(org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation)

Aggregations

JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)1 JvmType (org.eclipse.xtext.common.types.JvmType)1 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)1 IResolvedOperation (org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation)1 RecursionGuard (org.eclipse.xtext.xbase.typesystem.util.RecursionGuard)1