@Override public O addInterface(final String type) { if (!this.hasInterface(type)) { Type interfaceType = JDTHelper.getInterfaces( JavaParser.parse( JavaInterfaceImpl.class, "public interface Mock extends " + Types.toSimpleName(type) + " {}") .getBodyDeclaration()) .get(0); if (this.hasInterface(Types.toSimpleName(type)) || this.hasImport(Types.toSimpleName(type))) { interfaceType = JDTHelper.getInterfaces( JavaParser.parse( JavaInterfaceImpl.class, "public interface Mock extends " + type + " {}") .getBodyDeclaration()) .get(0); } this.addImport(type); ASTNode node = ASTNode.copySubtree(unit.getAST(), interfaceType); JDTHelper.getInterfaces(getBodyDeclaration()).add((Type) node); } return (O) this; }
@Override public O removeInterface(final String type) { List<Type> interfaces = JDTHelper.getInterfaces(getBodyDeclaration()); for (Type i : interfaces) { if (Types.areEquivalent(i.toString(), type)) { interfaces.remove(i); break; } } return (O) this; }
@Override public List<String> getInterfaces() { List<String> result = new ArrayList<String>(); List<Type> superTypes = JDTHelper.getInterfaces(getBodyDeclaration()); for (Type type : superTypes) { String name = JDTHelper.getTypeName(type); if (Types.isSimpleName(name) && this.hasImport(name)) { Import imprt = this.getImport(name); String pkg = imprt.getPackage(); if (!Strings.isNullOrEmpty(pkg)) { name = pkg + "." + name; } } result.add(name); } return result; }