Beispiel #1
0
  @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;
  }
Beispiel #2
0
 @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;
 }
Beispiel #3
0
 @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;
 }