use of org.codehaus.groovy.transform.stc.StaticTypesMarker.INFERRED_RETURN_TYPE in project groovy by apache.
the class StaticTypeCheckingVisitor method findMethodsWithGenerated.
/**
* Returns methods defined for the specified receiver and adds "non-existing"
* methods that will be generated afterwards by the compiler; for example if
* a method is using default values and the class node isn't compiled yet.
*
* @param receiver the receiver where to find methods
* @param name the name of the methods to return
* @return the methods that are defined on the receiver completed with stubs for future methods
*/
protected List<MethodNode> findMethodsWithGenerated(final ClassNode receiver, final String name) {
if (receiver.isArray()) {
if (name.equals("clone")) {
// GROOVY-10319: array clone -- <https://docs.oracle.com/javase/specs/jls/se8/html/jls-10.html#jls-10.7>
MethodNode clone = new MethodNode("clone", Opcodes.ACC_PUBLIC, OBJECT_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, null);
// retain Object for declaringClass and returnType
clone.setDeclaringClass(OBJECT_TYPE);
clone.setNodeMetaData(INFERRED_RETURN_TYPE, receiver);
return Collections.singletonList(clone);
} else {
return OBJECT_TYPE.getMethods(name);
}
}
List<MethodNode> methods = receiver.getMethods(name);
if (receiver.isAbstract()) {
collectAllInterfaceMethodsByName(receiver, name, methods);
} else {
// GROOVY-9890: always search for default methods
List<MethodNode> interfaceMethods = new ArrayList<>();
collectAllInterfaceMethodsByName(receiver, name, interfaceMethods);
interfaceMethods.stream().filter(mn -> mn.isDefault() || (mn.isPublic() && !mn.isStatic() && !mn.isAbstract() && Traits.isTrait(mn.getDeclaringClass()))).forEach(methods::add);
}
if (receiver.isInterface()) {
methods.addAll(OBJECT_TYPE.getMethods(name));
}
if (methods.isEmpty() || receiver.isResolved()) {
return methods;
}
return addGeneratedMethods(receiver, methods);
}
Aggregations