1package com.github.javaparser.ast.nodeTypes;
2
3import java.util.List;
4
5import com.github.javaparser.ast.Node;
6import com.github.javaparser.ast.type.ClassOrInterfaceType;
7
8public interface NodeWithExtends<T> {
9    public List<ClassOrInterfaceType> getExtends();
10
11    public T setExtends(final List<ClassOrInterfaceType> extendsList);
12
13    /**
14     * Add an extends to this and automatically add the import
15     *
16     * @param clazz the class to extand from
17     * @return this
18     */
19    public default T addExtends(Class<?> clazz) {
20        ((Node) this).tryAddImportToParentCompilationUnit(clazz);
21        return addExtends(clazz.getSimpleName());
22    }
23
24    /**
25     * Add an extends to this
26     *
27     * @param name the name of the type to extends from
28     * @return this
29     */
30    @SuppressWarnings("unchecked")
31    public default T addExtends(String name) {
32        ClassOrInterfaceType classOrInterfaceType = new ClassOrInterfaceType(name);
33        getExtends().add(classOrInterfaceType);
34        classOrInterfaceType.setParentNode((Node) this);
35        return (T) this;
36    }
37}
38