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);
}
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();
}
Aggregations