Search in sources :

Example 1 with DerivedProperty

use of spoon.support.DerivedProperty in project spoon by INRIA.

the class CtCatchVariableImpl method getType.

@SuppressWarnings("unchecked")
@Override
@DerivedProperty
public CtTypeReference<T> getType() {
    if (types.isEmpty()) {
        return null;
    } else if (types.size() == 1) {
        return (CtTypeReference<T>) types.get(0);
    }
    // compute common super type of exceptions
    List<CtTypeReference<?>> superTypesOfFirst = types.get(0).map(new SuperInheritanceHierarchyFunction().includingInterfaces(false).includingSelf(true).returnTypeReferences(true)).list();
    if (superTypesOfFirst.isEmpty()) {
        return null;
    }
    int commonSuperTypeIdx = 0;
    // index of Throwable. Last is Object
    int throwableIdx = superTypesOfFirst.size() - 2;
    for (int i = 1; i < types.size() && commonSuperTypeIdx != throwableIdx; i++) {
        CtTypeReference<?> nextException = types.get(i);
        while (commonSuperTypeIdx < throwableIdx) {
            if (nextException.isSubtypeOf(superTypesOfFirst.get(commonSuperTypeIdx))) {
                // nextException is sub type of actually selected commonSuperType
                break;
            }
            // try next super type
            commonSuperTypeIdx++;
        }
    }
    return (CtTypeReference<T>) superTypesOfFirst.get(commonSuperTypeIdx);
}
Also used : SuperInheritanceHierarchyFunction(spoon.reflect.visitor.filter.SuperInheritanceHierarchyFunction) CtTypeReference(spoon.reflect.reference.CtTypeReference) DerivedProperty(spoon.support.DerivedProperty)

Example 2 with DerivedProperty

use of spoon.support.DerivedProperty in project spoon by INRIA.

the class CtElementImpl method getReferencedTypes.

@DerivedProperty
public Set<CtTypeReference<?>> getReferencedTypes() {
    TypeReferenceScanner s = new TypeReferenceScanner();
    s.scan(this);
    return s.getReferences();
}
Also used : TypeReferenceScanner(spoon.support.visitor.TypeReferenceScanner) DerivedProperty(spoon.support.DerivedProperty)

Aggregations

DerivedProperty (spoon.support.DerivedProperty)2 CtTypeReference (spoon.reflect.reference.CtTypeReference)1 SuperInheritanceHierarchyFunction (spoon.reflect.visitor.filter.SuperInheritanceHierarchyFunction)1 TypeReferenceScanner (spoon.support.visitor.TypeReferenceScanner)1