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