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

com.exadatum.xsuite.xmaven.bash.doc.DocBlock Maven / Gradle / Ivy

Go to download

Bash Maven Plugin is used to generate documentation as well as to run unit test for bash scripts.

The newest version!
package com.exadatum.xsuite.xmaven.bash.doc;

/*-
 * #%L
 * Bash Unit Test Plugin
 * %%
 * Copyright (C) 2016 - 2017 Exadatum Software Services Pvt. Ltd.
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import java.util.ArrayList;

/**
 * Documentation block that contains information about target which could be a
 * bash function or constant.
 */
public class DocBlock {

  /**
   * Class to store annotations.
   */
  public static class Annotation {

    /**
     * Key of annotation.
     */
    private String key;

    /**
     * Value of annotation.
     */
    private String value;

    /**
     * Default constructor.
     */
    public Annotation() {
    }

    /**
     *
     * @param key
     *          Key of annotation
     * @param value
     *          Value of annotation
     */
    public Annotation(final String key, final String value) {
      this.key = key;
      this.value = value;
    }

    /**
     *
     * @return Key
     */
    public String getKey() {
      return key;
    }

    /**
     *
     * @param key
     *          key of annotation
     */
    public void setKey(final String key) {
      this.key = key;
    }

    /**
     *
     * @return Value of annotation
     */
    public String getValue() {
      return value.split(" ")[0];
    }

    /**
     *
     * @param value
     *          Value of annotation
     */
    public void setValue(final String value) {
      this.value = value;
    }

    /**
     *
     * @return name for annotation
     */
    public String getName() {

      return value.split(" ")[0];
    }

    /**
     *
     * @return Description of annotation
     */
    public String getDescription() {
      StringBuffer result = new StringBuffer();
      String[] wordArray = value.split(" ");
      if (wordArray.length > 1) {
        for (int i = 1; i < wordArray.length; i++) {
          result.append(" " + wordArray[i]);
        }
      }

      return result.toString();
    }

    @Override
    public String toString() {
      return String.format("%s: %s %s", getKey(), getName(),
          getDescription());
    }
  }

  /**
   * Function or Constant name.
   */
  private String target;

  /**
   * Description of target.
   */
  private StringBuilder description = new StringBuilder();

  /**
   * Annotations used on target.
   */
  private ArrayList annotations = new ArrayList<>();

  /**
   *
   * @return count of Constants.
   */
  public int getConstantSize() {
    return constantSize;
  }

  /**
   *
   * @param constantSize
   *          count of Constants.
   */
  public void setConstantSize(final int constantSize) {
    this.constantSize = constantSize;
  }

  /**
   * Count of constants in a script.
   */
  private int constantSize;

  /**
   * Getter for target.
   *
   * @return target
   */
  public String getTarget() {
    return target;
  }

  /**
   * Setter for target.
   *
   * @param target
   *          accepts the target
   */
  public void setTarget(final String target) {
    this.target = target;
  }

  /**
   * Getter for description.
   *
   * @return description
   */
  public String getDescription() {
    return description.toString();
  }

  /**
   * Append the new description line to current description.
   *
   * @param descriptionLine
   *          parameter to append
   */
  public void appendToDescription(final String descriptionLine) {
    this.description.append(descriptionLine);
  }

  /**
   * Getter for annotations.
   *
   * @return annotations
   */
  public ArrayList getAnnotations() {
    return annotations;
  }

  /**
   * Setter for annotations.
   *
   * @param annotations
   *          parameter ro set
   */
  public void setAnnotations(final ArrayList annotations) {
    this.annotations = annotations;
  }

  /**
   * Add annotations of doc block to Map.
   *
   * @param name
   *          name that describes annotation
   * @param value
   *          value of the annotation
   */
  public void addAnnotation(final String name, final String value) {
    this.annotations.add(new Annotation(name, value));
  }

  /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#hashCode()
   */
  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result
        + ((annotations == null) ? 0 : annotations.hashCode());
    result = prime * result
        + ((description == null) ? 0 : description.hashCode());
    result = prime * result + ((target == null) ? 0 : target.hashCode());
    return result;
  }

  /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#equals(java.lang.Object)
   */
  @Override
  public boolean equals(final Object obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (getClass() != obj.getClass())
      return false;
    DocBlock other = (DocBlock) obj;
    if (annotations == null) {
      if (other.annotations != null)
        return false;
    } else if (!annotations.equals(other.annotations))
      return false;
    if (description == null) {
      if (other.description != null)
        return false;
    } else if (!description.equals(other.description))
      return false;
    if (target == null) {
      if (other.target != null)
        return false;
    } else if (!target.equals(other.target))
      return false;
    return true;
  }

  /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
  @Override
  public String toString() {
    return "DocBlock [target=" + target + ", description=" + description
        + ", annotations=" + annotations.toString().replace(",", "\n") + "]";
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy