All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.pageseeder.xmldoclet.options.ImplementsOption Maven / Gradle / Ivy

The newest version!
package org.pageseeder.xmldoclet.options;

import jdk.javadoc.doclet.Reporter;

import javax.lang.model.element.TypeElement;
import javax.lang.model.type.TypeMirror;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Option to filter classes implementing the specified class.
 */
public class ImplementsOption extends XMLDocletOptionBase {

  public List interfaces = new ArrayList<>();

  public ImplementsOption(Reporter reporter) {
    super(reporter);
  }

  @Override
  public int getArgumentCount() {
    return 1;
  }

  @Override
  public String getDescription() {
    return "filter classes implementing the specified interface";
  }

  @Override
  public Kind getKind() {
    return Kind.STANDARD;
  }

  @Override
  public List getNames() {
    return Collections.singletonList("-implements");
  }

  @Override
  public String getParameters() {
    return "";
  }

  @Override
  public boolean process(String option, List arguments) {
    String interfaceName = arguments.get(0);
    note("Filtering classes implementing: "+interfaceName);
    this.interfaces.add(interfaceName);
    return true;
  }

  public List getInterfaces() {
    return this.interfaces;
  }

  public boolean hasFilter() {
    return this.interfaces.size() > 0;
  }


  /**
   * Filters the included set of classes by checking whether the given class matches
   * one of the specified qualified interface names.
   *
   * @param element the class documentation.
   * @return true if the class should be included; false otherwise.
   */
  public boolean matches(TypeElement element) {
    if (this.interfaces.isEmpty()) return true;
    List interfaces = element.getInterfaces();
    for (TypeMirror i : interfaces) {
      if (this.interfaces.contains(i.toString())) return true;
    }
    return false;
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy