use of spoon.reflect.visitor.filter.AllTypeMembersFunction in project spoon by INRIA.
the class CtMethodImpl method getTopDefinitions.
@Override
public Collection<CtMethod<?>> getTopDefinitions() {
List<CtMethod<?>> s = new ArrayList<>();
// first collect potential declarations of this method in the type hierarchy
ClassTypingContext context = new ClassTypingContext(this.getDeclaringType());
getDeclaringType().map(new AllTypeMembersFunction(CtMethod.class)).forEach((CtMethod<?> m) -> {
if (m != this && context.isOverriding(this, m)) {
s.add(m);
}
});
// now removing the intermediate methods for which there exists a definition upper in the hierarchy
List<CtMethod<?>> finalMeths = new ArrayList<>(s);
for (CtMethod m1 : s) {
boolean m1IsIntermediate = false;
for (CtMethod m2 : s) {
if (context.isOverriding(m1, m2)) {
m1IsIntermediate = true;
}
}
if (!m1IsIntermediate) {
finalMeths.add(m1);
}
}
return finalMeths;
}
use of spoon.reflect.visitor.filter.AllTypeMembersFunction in project spoon by INRIA.
the class CtTypeImpl method getAllMethods.
@Override
public Set<CtMethod<?>> getAllMethods() {
final Set<CtMethod<?>> l = new HashSet<>();
final ClassTypingContext ctc = new ClassTypingContext(this);
map(new AllTypeMembersFunction(CtMethod.class)).forEach(new CtConsumer<CtMethod<?>>() {
@Override
public void accept(CtMethod<?> currentMethod) {
for (CtMethod<?> alreadyVisitedMethod : l) {
if (ctc.isSameSignature(currentMethod, alreadyVisitedMethod)) {
return;
}
}
l.add(currentMethod);
}
});
return Collections.unmodifiableSet(l);
}
use of spoon.reflect.visitor.filter.AllTypeMembersFunction in project spoon by INRIA.
the class SpoonMetaModel method getInheritedAnnotation.
/**
* @param method a start method
* @param annotationType a searched annotation type
* @return annotation from the first method in superClass and superInterface hierarchy for the method with required annotationType
*/
private static <A extends Annotation> CtAnnotation<A> getInheritedAnnotation(CtMethod<?> method, CtTypeReference<A> annotationType) {
CtAnnotation<A> annotation = method.getAnnotation(annotationType);
if (annotation == null) {
CtType<?> declType = method.getDeclaringType();
final ClassTypingContext ctc = new ClassTypingContext(declType);
annotation = declType.map(new AllTypeMembersFunction(CtMethod.class)).map((CtMethod<?> currentMethod) -> {
if (method == currentMethod) {
return null;
}
if (ctc.isSameSignature(method, currentMethod)) {
CtAnnotation<A> annotation2 = currentMethod.getAnnotation(annotationType);
if (annotation2 != null) {
return annotation2;
}
}
return null;
}).first();
}
return annotation;
}
Aggregations